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

/application/controllers/page.php

https://github.com/be3/ionize
PHP | 173 lines | 80 code | 39 blank | 54 comment | 15 complexity | bed9ab5a8046fd74eda9bc2dd243cd95 MD5 | raw file
  1. <?php
  2. /*
  3. * Created by Martin Wernståhl on 2010-01-02.
  4. * Copyright (c) 2010 Martin Wernståhl.
  5. * All rights reserved.
  6. */
  7. /**
  8. *
  9. */
  10. class Page extends Base_Controller
  11. {
  12. // Current user
  13. public $user = false;
  14. // All groups
  15. protected $groups = false;
  16. protected $installed_tagmanagers = array(
  17. 'Pages',
  18. 'Archives',
  19. 'Category',
  20. );
  21. // protected $default_page_view = 'default/page';
  22. // protected $default_navigation_view = 'default/navigation';
  23. // protected $default_categories_view = 'default/categories';
  24. // protected $default_archives_view = 'default/archives';
  25. public $uri_segment;
  26. function index()
  27. {
  28. // Real URI segments : See URI problem below
  29. $this->uri_segment = func_get_args();
  30. // URI SEGMENT PROBLEM
  31. // trace($this->uri_segment[1]);
  32. // trace($this->uri->segment(4));
  33. // END URI SEG PROB
  34. $this->load->model('page_model');
  35. require_once APPPATH.'libraries/ftl/parser.php';
  36. require_once APPPATH.'libraries/ftl/arraycontext.php';
  37. require_once APPPATH.'libraries/Tagmanager.php';
  38. require_once APPPATH.'libraries/Tagmanager/Page.php';
  39. require_once APPPATH.'libraries/Tagmanager/Element.php';
  40. require_once APPPATH.'libraries/Tagmanager/Form.php';
  41. require_once APPPATH.'libraries/Tagmanager/Login.php';
  42. // Context
  43. $c = new FTL_ArrayContext();
  44. // Get all groups
  45. $this->groups = $this->connect->model->get_groups();
  46. // Get the current user (used by autorization filtering)
  47. if ($this->connect->logged_in())
  48. $this->user = $this->connect->get_current_user();
  49. /* Add all pages to the context : Usefull for having just one request for Pages result
  50. * wich will be used by Page Tag manager and Navigation manager.
  51. */
  52. $pages = $this->page_model->get_lang_list(false, Settings::get_lang());
  53. /* Spread authorizations from parents pages to chidrens.
  54. * This adds the group ID to the childrens pages of a protected page
  55. * If you don't want this, just uncomment this line.
  56. */
  57. $this->page_model->spread_authorizations($pages);
  58. // Not needed for the moment.
  59. // Think about a further implementation.
  60. // $this->access->restrict();
  61. // Filter pages regarding the authorizations
  62. $pages = array_values(array_filter($pages, array($this, '_filter_authorization')));
  63. // get special tag manager:
  64. if(in_array($file = ucfirst(strtolower($this->uri->segment(3))), $this->installed_tagmanagers))
  65. {
  66. if (is_file(APPPATH.'libraries/Tagmanager/'.$file.EXT))
  67. {
  68. require_once APPPATH.'libraries/Tagmanager/'.$file.EXT;
  69. $class = 'TagManager_'.$file;
  70. $m = new $class($this, $c, $pages);
  71. }
  72. }
  73. // Standard page tag manager
  74. else
  75. {
  76. // Page tag manager
  77. $m = new TagManager_Page($this, $c, $pages);
  78. $m->add_globals($c);
  79. $m->add_tags($c);
  80. // Element tag manager
  81. $f = new TagManager_Element($this);
  82. $f->add_globals($c);
  83. $f->add_tags($c);
  84. // Form tag manager
  85. $f = new TagManager_Form($this);
  86. $f->add_globals($c);
  87. $f->add_tags($c);
  88. // Login tag manager
  89. $l = new TagManager_Login($this);
  90. $l->add_globals($c);
  91. $l->add_tags($c);
  92. }
  93. // Add tags from modules
  94. // Automatically add each function of the class [Your_module]_Tags defined in the [your_module]/libraries/tags.php
  95. TagManager::add_plugin_tags($c);
  96. // Get the asked page
  97. $page = $c->globals->page;
  98. /*
  99. * If asked page is a link to another page, redirect to the linked one
  100. */
  101. if ( ! empty($c->globals->page['link']))
  102. {
  103. // Online languages are defined by MY_Controller
  104. $lang = (count(Settings::get_online_languages()) > 1 ) ? Settings::get_lang('current').'/' : '';
  105. $domain = (!empty($c->globals->page['link_type']) && $c->globals->page['link_type'] == 'external') ? '' : base_url();
  106. redirect($domain.$lang.$c->globals->page['link']);
  107. }
  108. // Get the page view
  109. $view = ($c->globals->page['view'] != false) ? $c->globals->page['view'] : Theme::get_default_view('page');
  110. // Outputs the page view with Base_Controller2->render()
  111. $this->render($view, $c);
  112. }
  113. private function _filter_authorization($row)
  114. {
  115. // If the page group != 0, then get the page group and check the restriction
  116. if($row['id_group'] != 0)
  117. {
  118. $page_group = false;
  119. // Get the page group
  120. foreach($this->groups as $group)
  121. {
  122. if ($group['id_group'] == $row['id_group']) $page_group = $group;
  123. }
  124. // If the current connected user has access to the page return true
  125. if ($this->user !== false && $page_group != false && $this->user['group']['level'] >= $page_group['level'])
  126. return true;
  127. // If nothing found, return false
  128. return false;
  129. }
  130. return true;
  131. }
  132. }
  133. /* End of file page.php */
  134. /* Location: ./application/controllers/page.php */