functions.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. if(!isset($_GET['no_state'])){
  9. // State
  10. if(!isset($json['state'])){
  11. $json['state'] = array();
  12. }
  13. unset($_GET['password']);
  14. unset($_GET['password1']);
  15. if(!isset($json['state']['data'])){
  16. $json['state']['data'] = $_GET;
  17. }else{
  18. foreach($_GET as $key => $val){
  19. if(!isset($json['state']['data'][$key])&&$key!='password'){
  20. $json['state']['data'][$key] = $val;
  21. }
  22. }
  23. }
  24. }
  25. // Title
  26. if(is_null($title)){
  27. if(isset($json['title'])){
  28. $title = $json['title'];
  29. }elseif(isset($json['state']['title'])&&!isset($_GET['no_state'])){
  30. $title = $json['state']['title'];
  31. }else{
  32. $title = $_GET['id'];
  33. }
  34. }
  35. if(!isset($_GET['no_state'])){
  36. $json['state']['title'] = $title;
  37. if(!isset($json['state']['url'])){
  38. // URL
  39. switch($type){
  40. case 'user':$url='~'.$id;break;
  41. case 'group':$url='+'.$id;break;
  42. case 'issue':$url='!'.$id;break;
  43. case 'action':$url='';break;
  44. default:$url=$type.'-'.$id;
  45. }
  46. $json['state']['url'] = $url;
  47. }else{
  48. $url = $json['state']['url'];
  49. }
  50. }
  51. if(!isset($_GET['topbar'])){
  52. // Tobar
  53. if($LOGGEDIN){
  54. $context = array(
  55. 'user'=>userObj($_SESSION['username']),
  56. 'key'=>true
  57. );
  58. }else{
  59. $context = array();
  60. }
  61. $context['title'] = $title;
  62. if(!isset($_GET['no_state'])){
  63. $context['url'] = $url;
  64. }
  65. if(file_exists(PATH_DATA.'topbars/'.$type.'-'.$id)){
  66. $topbar = $type.'-'.$id;
  67. }else{
  68. $topbar = 'default';
  69. }
  70. $json['topbar'] = array(
  71. 'template'=>$topbar,
  72. 'context'=>$context
  73. );
  74. }
  75. header('Content-type: application/json');
  76. die(json_encode($json));
  77. }
  78. function is_valid($col,$v=null){
  79. if($v == null){
  80. $v = $_GET;
  81. }
  82. if(isset($v[$col]) && !empty($v[$col])){
  83. $v = $v[$col];
  84. switch($col){
  85. case 'email':
  86. return filter_var($v,FILTER_VALIDATE_EMAIL) != false;
  87. case 'username':
  88. return strip_tags($v) == $v;
  89. default:
  90. return true;
  91. }
  92. }else{
  93. return false;
  94. }
  95. }
  96. function back($ifNotLoggedIn=false){
  97. global $LOGGEDIN;
  98. if($ifNotLoggedIn && $LOGGEDIN){
  99. return false;
  100. }
  101. retj(array(
  102. 'state'=>array(
  103. 'url'=>isset($_GET['back'])?$_GET['back']:'page-index'
  104. )
  105. ));
  106. }
  107. function stateObj($type,$id){
  108. $json = array(
  109. 'data'=>$_GET
  110. );
  111. $title = ucwords($type.' - '.$id);
  112. switch($type){
  113. case 'user':$url='~'.$id;break;
  114. case 'group':$url='+'.$id;break;
  115. case 'issue':$url='!'.$id;break;
  116. case 'page':$url='page-'.$id;break;
  117. case 'project':
  118. $url=$type.'-'.$id;
  119. $title = projectObj($id);
  120. $title = 'Project - '.$title['title'];
  121. break;
  122. default:$url=$type.'-'.$id;
  123. }
  124. $json['url'] = $url;
  125. $json['title'] = $title;
  126. return $json;
  127. }
  128. ?>