PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/html/AppCode/expressionengine/third_party/ndg_flexible_admin/acc.ndg_flexible_admin.php

https://github.com/w3bg/www.hsifin.com
PHP | 204 lines | 160 code | 29 blank | 15 comment | 17 complexity | 69d58233765159de839dae6c269649cb MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * Accessory for NDG Flexible Admin
  4. *
  5. * This file must be in your /system/third_party/ndg_flexible_admin directory of your ExpressionEngine installation
  6. *
  7. * @package NDG Flexible Admin for EE2
  8. * @author Nico De Gols (nicodegols@me.com)
  9. * @copyright Copyright (c) 2010 Nico De Gols
  10. * @version Release: 1.03
  11. * @link http://pixelclub.be
  12. */
  13. class Ndg_flexible_admin_acc
  14. {
  15. var $name = 'NDG Flexible Admin';
  16. var $id = 'ndg_flexible_admin';
  17. var $version = '1.0';
  18. var $description = 'Customize the Control Panel navigation per member group';
  19. var $sections = array();
  20. var $config = array();
  21. var $nav;
  22. var $site_id;
  23. var $group_id;
  24. var $origArray;
  25. var $autopopulate;
  26. /**
  27. * Constructor
  28. */
  29. function Ndg_flexible_admin_acc()
  30. {
  31. $this->EE =& get_instance();
  32. $this->EE->lang->loadfile('ndg_flexible_admin');
  33. }
  34. function set_sections(){
  35. $this->site_id = $this->EE->config->item('site_id');
  36. $this->group_id = $this->EE->session->userdata('group_id');
  37. $ndg_nav = $this->_loadNavigation($this->site_id, $this->group_id);
  38. if($ndg_nav){
  39. $this->nav = $ndg_nav[0];
  40. $this->autopopulate = $ndg_nav[1];
  41. $this->origArray = $this->getOriginalArray($this->nav);
  42. $this->sections[$this->name] = '<a href="'.BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module='.$this->id.'">Go to module control panel</a>';
  43. if($this->nav != ""){
  44. $hide = ($this->group_id != 1)?'$("#accessoryTabs > ul > li > a.ndg_flexible_admin").parent("li").remove()':'';
  45. $toggle = ($this->group_id == 1)?'$("#navigationTabs").append("<li><a class=\'first_level\' id=\'toggle_cpnav\' href=\'#\'>Hide custom menu</a></li>"); $("#toggle_cpnav").click(function() { $("#navigationTabs").html(jQuery.data(document.body, "originalnav")); $("#navigationTabs >li").show(); reloadMenu(); });':'';
  46. $this->EE->cp->add_to_head('
  47. <style type="text/css"> #navigationTabs >li{display:none;}#navigationTabs{height:20px;}</style>');
  48. $this->EE->cp->load_package_js('acc.cpnav');
  49. $this->EE->cp->add_to_foot('
  50. <script type="text/javascript">
  51. '.$hide.'
  52. if($("#origtree")){
  53. $("#origtree").html($("#navigationTabs").html());
  54. }
  55. jQuery.data(document.body, "originalnav", $("#navigationTabs").html());
  56. ndg_msm_sites = $("#navigationTabs").find(".msm_sites").eq(0);
  57. par = ""; if(ndg_msm_sites.find("ul").length > 0){ par = \'parent\';}
  58. $("#navigationTabs").html(\''.$this->nav.'<li class="\'+par+\' msm_sites" style="display:list-item;">\'+ndg_msm_sites.html()+\'</li>\');
  59. '.$toggle.'
  60. // $("#navigationTabs").append(ndg_msm_sites);
  61. $("#navigationTabs >li").show();
  62. if('.$this->autopopulate.' == 1){
  63. if($("#navigationTabs #publishfolder > ul").length == 0){ $("#navigationTabs #publishfolder").append(\'<ul></ul>\'); $("#navigationTabs #publishfolder").addClass(\'parent\')};
  64. $("#navigationTabs #editfolder > ul").html(\''.$this->get_edit_channels().'\');
  65. $("#navigationTabs #publishfolder > ul").html(\''.$this->get_publish_channels().'\');
  66. $("#navigationTabs #modulefolder > ul").html(\''.$this->get_modules().'\');
  67. }
  68. $("#navigationTabs").show();
  69. </script>');
  70. }
  71. }
  72. }
  73. //LOAD THE CUSTOM NAVIGATION FOR THE CURRENTLY LOGGED IN MEMBERGROUP
  74. function _loadNavigation($site_id = "", $group_id = ""){
  75. if($site_id == "" || $group_id == "" || !$this->EE->db->table_exists($this->EE->db->dbprefix('ndg_flexible_admin_menus')) ){
  76. return false;
  77. }else{
  78. $this->EE->db->select('nav, autopopulate');
  79. $this->EE->db->where('group_id', $group_id);
  80. $this->EE->db->where('site_id', $site_id);
  81. $this->EE->db->from($this->EE->db->dbprefix('ndg_flexible_admin_menus'));
  82. $query = $this->EE->db->get();
  83. if ($query->num_rows() == 0)
  84. {
  85. return false;
  86. }else{
  87. return array(str_replace("'",'"',$query->row()->nav), $query->row()->autopopulate);
  88. }
  89. }
  90. }
  91. function getOriginalArray($orig){
  92. $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
  93. if(preg_match_all("/$regexp/siU", $orig, $matches)) {
  94. $names = $matches[3];
  95. $urls = array();
  96. foreach($matches[2] as $match){
  97. array_push($urls,substr($match, strpos($match,"?")+6));
  98. }
  99. }
  100. return array($urls, $names);
  101. }
  102. function get_modules(){
  103. $group_id = $this->EE->session->userdata['group_id'];
  104. if ($group_id == 1){
  105. $query = $this->EE->db->query('SELECT module_name FROM exp_modules WHERE has_cp_backend = "y" ORDER BY module_name');
  106. }else{
  107. $query = $this->EE->db->query('SELECT m.module_name
  108. FROM exp_modules m, exp_module_member_groups mmg
  109. WHERE m.module_id = mmg.module_id
  110. AND mmg.group_id = '.$group_id.'
  111. AND m.has_cp_backend = "y"
  112. ORDER BY m.module_name');
  113. }
  114. $modules = "";
  115. if ($query->num_rows())
  116. {
  117. foreach ($query->result_array() as $row)
  118. {
  119. $class = strtolower($row['module_name']);
  120. $this->EE->lang->loadfile($class);
  121. $name = $this->EE->lang->line($class.'_module_name');
  122. $url = BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module='.$class;
  123. $orignamekey = array_search('C=addons_modules&M=show_module_cp&module='.$class, $this->origArray[0]);
  124. if($orignamekey){
  125. $name = $this->origArray[1][$orignamekey];
  126. }
  127. $name = str_replace("'","&#039;",$name);
  128. $modules .= '<li><a href="'.$url.'">'.$name.'</a>';
  129. }
  130. $modules .= '<li class="bubble_footer"><a href="#"></a>';
  131. }
  132. return $modules;
  133. }
  134. function get_publish_channels($orig = ""){
  135. $channel_data = $this->EE->channel_model->get_channels();
  136. $channels = "";
  137. if($channel_data){
  138. foreach ($channel_data->result() as $channel) {
  139. $url = BASE.AMP.'C=content_publish'.AMP.'M=entry_form'.AMP.'channel_id='.$channel->channel_id;
  140. $name = $channel->channel_title;
  141. $orignamekey = array_search('C=content_publish&M=entry_form&channel_id='.$channel->channel_id, $this->origArray[0]);
  142. if($orignamekey){
  143. $name = $this->origArray[1][$orignamekey];
  144. }
  145. $name = str_replace("'","&#039;",$name);
  146. $channels .= '<li><a href="'.$url.'">'.$name.'</a>';
  147. }
  148. }
  149. $channels .= '<li class="bubble_footer"><a href="#"></a>';
  150. return $channels;
  151. }
  152. function get_edit_channels($list = ""){
  153. $channel_data = $this->EE->channel_model->get_channels();
  154. $channels = "";
  155. if($channel_data){
  156. foreach ($channel_data->result() as $channel) {
  157. $url = BASE . AMP . 'C=content_edit'.AMP.'channel_id=' . $channel->channel_id;
  158. $name = $channel->channel_title;
  159. $orignamekey = array_search('C=content_edit&channel_id=' . $channel->channel_id, $this->origArray[0]);
  160. if($orignamekey){
  161. $name = $this->origArray[1][$orignamekey];
  162. }
  163. $name = str_replace("'","&#039;",$name);
  164. $channels .= '<li><a href="'.$url.'">'.$name.'</a>';
  165. }
  166. }
  167. $channels .= '<li class="bubble_footer"><a href="#"></a>';
  168. return $channels;
  169. }
  170. }