functions.php 2.7 KB

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