functions.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. require_once(realpath(dirname(__FILE__)).'/config.php');
  3. // TODO - create php functions for the api
  4. function retj($json,$title=null){
  5. global $LOGGEDIN;
  6. $type=$_GET['type'];
  7. $id=$_GET['id'];
  8. // State
  9. if(!isset($json['state'])){
  10. $json['state'] = Array();
  11. }
  12. unset($_GET['password']);
  13. unset($_GET['password1']);
  14. if(!isset($json['state']['data'])){
  15. $json['state']['data'] = $_GET;
  16. }else{
  17. foreach($_GET as $key => $val){
  18. if(!isset($json['state']['data'][$key])&&$key!='password'){
  19. $json['state']['data'][$key] = $val;
  20. }
  21. }
  22. }
  23. // Title
  24. if(is_null($title)){
  25. $title = $_GET['id'];
  26. }
  27. $json['state']['title'] = $title;
  28. // URL
  29. switch($type){
  30. case 'user':$url='~'.$id;break;
  31. case 'group':$url='+'.$id;break;
  32. case 'issue':$url='!'.$id;break;
  33. case 'action':$url='';break;
  34. default:$url=$type.'-'.$id;
  35. }
  36. $json['state']['url'] = $url;
  37. // Tobar
  38. if($LOGGEDIN){
  39. $context = Array(
  40. 'user'=>userObj($_SESSION['username']),
  41. 'key'=>true
  42. );
  43. }else{
  44. $context = Array();
  45. }
  46. $context['title'] = $title;
  47. $context['url'] = $url;
  48. $json['topbar'] = Array(
  49. 'template'=>file_get_contents(PATH_DATA.'pages/topbar.template'),
  50. 'context'=>$context
  51. );
  52. die(json_encode($json));
  53. }
  54. function isvalid($col,$v=null){
  55. if($v == null){
  56. $v = $_GET;
  57. }
  58. return isset($v[$col]) && !empty($v[$col]);
  59. }
  60. ?>