functions.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 'template':$url='page-'.$id;break;
  34. case 'action':$url='';break;
  35. default:$url=$type.'-'.$id;
  36. }
  37. $json['state']['url'] = $url;
  38. // Tobar
  39. if($LOGGEDIN){
  40. $context = Array(
  41. 'user'=>userObj($_SESSION['username']),
  42. 'key'=>true
  43. );
  44. }else{
  45. $context = Array();
  46. }
  47. $context['title'] = $title;
  48. $context['url'] = $url;
  49. $json['topbar'] = Array(
  50. 'template'=>file_get_contents(PATH_DATA.'pages/topbar.template'),
  51. 'context'=>$context
  52. );
  53. die(json_encode($json));
  54. }
  55. ?>