PageRenderTime 59ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/controller/CMSBaseComponent.php

https://github.com/phpwax/wildfire
PHP | 137 lines | 106 code | 20 blank | 11 comment | 11 complexity | a2d238755444dc33623c2f743e4d8487 MD5 | raw file
  1. <?php
  2. /**
  3. * Class defining basic building blocks of a CMS component
  4. * Uses database to provide authentication
  5. * @package PHP-WAX CMS
  6. */
  7. class CMSBaseComponent extends WaxController {
  8. public $allowed_modules = array(); //all available modules for this user (ie this is just top level name)
  9. public $module_name = null; //the name of this module
  10. public $model = false; //the actuall database model to use
  11. public $model_class; //the class name - ie WildfireContent
  12. public $model_scope = false;
  13. public $tree_scope = false;
  14. public $user_model_class = "WildfireUser";
  15. public $redirects = array('unauthorised'=> "/admin/login",
  16. 'authorised' => "/admin/home/",
  17. 'install'=> "/admin/install/",
  18. 'logout'=>"/admin/logout"
  19. );
  20. public $use_plugin = "cms";
  21. public $display_name = 'CMS'; //display name of the module
  22. public $use_layout = "admin"; //the default layout to use
  23. public $per_page = 20; //the limit to use in lists
  24. public $this_page = 1;
  25. public $session; //session object
  26. public $user_session_name = "wf_v6_user";
  27. public $user_session_var_name = "user_id";
  28. public static $logged_in_user = false;
  29. public $filter_fields=array();
  30. public $model_filters=array();
  31. public $operation_actions = array(
  32. 'edit'=>array('action'=>'edit', 'name'=>'<b>✎</b>Edit %s')
  33. );
  34. public $quick_links = array();
  35. public $uploads = false;
  36. public $preview_hover = false;
  37. public $preview_click = false;
  38. public $dashboard = false;
  39. public $sort_scope = "";
  40. public $export_scope = "";
  41. public $exportable = false;
  42. public $export_group = false; //splits the results by this field, make multiple csv files and zips them
  43. public $sortable = false;
  44. public $scaffold_columns = false;
  45. public $search_results = array();
  46. public $use_cache = false;
  47. public $use_format = false;
  48. public $messages = array();
  49. public $file_system_model = "WildfireMedia";
  50. public static $restricted_tree = false;
  51. public static $default_format = "json";
  52. function __construct($application = false, $init=true) {
  53. parent::__construct($application);
  54. if($application) $this->events();
  55. WaxEvent::run("cms.session.setup", $this);
  56. if($init) $this->initialise();
  57. }
  58. public function controller_global(){
  59. parent::controller_global();
  60. WaxEvent::run("cms.layout.set", $this);
  61. WaxEvent::run("cms.format.set", $this);
  62. }
  63. public function __destruct(){
  64. WaxEvent::run("cms.destruct", $this);
  65. }
  66. public function user_from_session($session_name="wf_v6_user"){
  67. //echo "<a href='/admin/home/?".$this->session->name."=".$this->session->id."'>login</a>";
  68. //exit;
  69. $user_model = new $this->user_model_class;
  70. if($id = $this->session->get($session_name)){
  71. if(self::$logged_in_user) return self::$logged_in_user;
  72. if(($model = new $this->user_model_class($id)) && $model->primval == $id) return self::$logged_in_user = $model;
  73. }
  74. //token based auth
  75. elseif(($auth = Request::param('auth_token')) && ($found = $user_model->filter("auth_token", $auth)->first())){
  76. return self::$logged_in_user = $found;
  77. }
  78. return false;
  79. }
  80. protected function events(){
  81. WaxEvent::add("cms.session.setup", function(){
  82. $controller = WaxEvent::data();
  83. $controller->session = new WaxSession(array("name"=>$controller->user_session_name,"lifetime"=>60*60*24*30));
  84. });
  85. WaxEvent::add("cms.layout.set", function(){
  86. $obj = WaxEvent::data();
  87. $obj->use_layout = "login";
  88. });
  89. WaxEvent::add("cms.format.set", function(){
  90. $obj = WaxEvent::data();
  91. if(!$obj->use_format) $obj->use_format = CMSBaseComponent::$default_format;
  92. });
  93. WaxEvent::add("cms.layout.sublinks", function(){});
  94. WaxEvent::add('cms.search.'.$this->module_name, function(){});
  95. }
  96. /**
  97. * initialises authentication, default model and menu items
  98. **/
  99. protected function initialise(){}
  100. public function sync($path, $filename=""){}
  101. protected function add_file($folderpath,$filename,$rpath,$fileid){}
  102. public function add_message($message, $class){
  103. $messages = $this->session->get("messages");
  104. $messages[] = array('message'=>$message, 'class'=>$class);
  105. $this->session->set("messages", $messages);
  106. }
  107. static function form_group_partial_check($partial_paths, $name){
  108. $tabhash = Inflections::to_url($name);
  109. $partial_name = "_".Inflections::underscore(Inflections::to_url($name));
  110. $readable = false;
  111. foreach($partial_paths as $possible){
  112. if(($path = str_replace("%s%", $partial_name, $possible)) && is_readable($path)) return basename($path);
  113. }
  114. return false;
  115. }
  116. }
  117. ?>