functions.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. // URL
  33. switch($type){
  34. case 'user':$url='~'.$id;break;
  35. case 'group':$url='+'.$id;break;
  36. case 'issue':$url='!'.$id;break;
  37. case 'action':$url='';break;
  38. default:$url=$type.'-'.$id;
  39. }
  40. $json['state']['url'] = $url;
  41. // Tobar
  42. if($LOGGEDIN){
  43. $context = Array(
  44. 'user'=>userObj($_SESSION['username']),
  45. 'key'=>true
  46. );
  47. }else{
  48. $context = Array();
  49. }
  50. $context['title'] = $title;
  51. $context['url'] = $url;
  52. $json['topbar'] = Array(
  53. 'template'=>file_get_contents(PATH_DATA.'pages/topbar.template'),
  54. 'context'=>$context
  55. );
  56. die(json_encode($json));
  57. }
  58. function isvalid($col,$v=null){
  59. if($v == null){
  60. $v = $_GET;
  61. }
  62. if(isset($v[$col]) && !empty($v[$col])){
  63. $v = $v[$col];
  64. switch($col){
  65. case 'email':
  66. return filter_var($v,FILTER_VALIDATE_EMAIL) != false;
  67. case 'username':
  68. return strip_tags($v) == $v;
  69. default:
  70. return true;
  71. }
  72. }else{
  73. return false;
  74. }
  75. }
  76. ?>