functions.php 2.8 KB

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