functions.php 2.1 KB

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