PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://github.com/w3bg/www.hsifin.com
PHP | 210 lines | 187 code | 12 blank | 11 comment | 4 complexity | 79dbe0830cb9ab101d911bc4a3096f69 MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. error_reporting(1);
  3. ini_set('display_errors', TRUE);
  4. require('libraries/JSON.php');
  5. /**
  6. * Core Module file for NDG Flexible Admin
  7. *
  8. * This file must be in your /system/third_party/ndg_flexible_admin directory of your ExpressionEngine installation
  9. *
  10. * @package NDG Flexible Admin for EE2
  11. * @author Nico De Gols (nicodegols@me.com)
  12. * @copyright Copyright (c) 2010 Nico De Gols
  13. * @version Release: 1.0
  14. * @link http://pixelclub.be
  15. */
  16. class Ndg_flexible_admin {
  17. function Ndg_flexible_admin()
  18. {
  19. $this->EE =& get_instance();
  20. $this->EE->output->enable_profiler(FALSE);
  21. }
  22. function ajax_preview(){
  23. $this->EE->output->enable_profiler(FALSE);
  24. echo $this->get_tree_html($this->EE->input->post('jsontree'));
  25. }
  26. function my_strip_tags($str) {
  27. $str = strip_tags($str, "<img>");
  28. $pos1 = strpos($str,'<img');
  29. $pos1 = (!$pos1) ? strpos($str,'<IMG'):$pos1;
  30. $pos2 = strpos($str,'>', $pos1);
  31. if($pos1 && $pos2){
  32. $img = "<img src=".$this->EE->config->item('theme_folder_url')."cp_themes/default/images/home_icon.png />";
  33. $str = substr_replace($str, $img, $pos1, $pos2-$pos1+1);
  34. }
  35. return $str;
  36. }
  37. function get_tree_ul($child){
  38. $navhtml = "";
  39. if(count($child->children) > 0){
  40. $navhtml .= '<ul class="">';
  41. foreach($child->children as $subchild){
  42. $navhtml .= '<li class="'.$subchild->className.'" id="'.$subchild->id.'"><a href="'.$subchild->url.'">'.$subchild->title.'</a>';
  43. $navhtml .= $this->get_tree_ul($subchild);
  44. $navhtml .= '</li>';
  45. }
  46. $navhtml .= '</ul>';
  47. }
  48. return $navhtml;
  49. }
  50. function get_tree_html($jsontree){
  51. $this->EE->output->enable_profiler(FALSE);
  52. $cpurl = $this->EE->config->item('cp_url');
  53. $pieces = explode("/",$cpurl);
  54. $cpurl_index = $pieces[count($pieces)-1];
  55. $jsontree = str_replace("'",'"',(string)$jsontree);
  56. $jsontree = $this->my_strip_tags($jsontree);
  57. $jsontree = str_replace('EDIT','',$jsontree);
  58. $jsontree = str_replace('DELETE','',$jsontree);
  59. $jsontree = str_replace('&nbsp;','',$jsontree);
  60. $json = new Services_JSON();
  61. $json_decoded = $json->decode($jsontree);
  62. $navhtml = '';
  63. foreach($json_decoded as $item){
  64. $navhtml .= '<li class="'.$item->className.'" id="'.$item->id.'" ><a href="'.$item->url.'" class="first_level">'.str_replace('"', '\"',$item->title).'</a>';
  65. $navhtml .= $this->get_tree_ul($item);
  66. $navhtml .= '</li>';
  67. }
  68. return $navhtml;
  69. }
  70. function ajax_load_tree()
  71. {
  72. $this->EE->output->enable_profiler(FALSE);
  73. $site_id = ($this->EE->input->post("site_id") != "") ? $this->EE->input->post("site_id") : $this->EE->config->item('site_id');
  74. $this->EE->db->select('nav');
  75. $this->EE->db->where('group_id', $this->EE->input->post("group_id"));
  76. $this->EE->db->where('site_id', $site_id);
  77. $this->EE->db->from($this->EE->db->dbprefix('ndg_flexible_admin_menus'));
  78. $query = $this->EE->db->get();
  79. if ($query->num_rows() == 0)
  80. {
  81. echo "no_nav_found";
  82. }else{
  83. echo strpos($query->row()->nav, "'");
  84. echo str_replace("'",'"',$query->row()->nav);
  85. }
  86. }
  87. function ajax_load_settings()
  88. {
  89. $this->EE->output->enable_profiler(FALSE);
  90. $site_id = ($this->EE->input->post("site_id") != "") ? $this->EE->input->post("site_id") : $this->EE->config->item('site_id');
  91. $this->EE->db->select('nav, autopopulate');
  92. $this->EE->db->where('group_id', $this->EE->input->post("group_id"));
  93. $this->EE->db->where('site_id', $site_id);
  94. $this->EE->db->from($this->EE->db->dbprefix('ndg_flexible_admin_menus'));
  95. $query = $this->EE->db->get();
  96. if ($query->num_rows() == 0)
  97. {
  98. echo '{ "autopopulate" : "false" }';
  99. }else{
  100. echo '{ "autopopulate" : "'.$query->row()->autopopulate.'" }';
  101. }
  102. }
  103. function ajax_save_tree()
  104. {
  105. $this->EE->output->enable_profiler(FALSE);
  106. $new = TRUE;
  107. $site_id = ($this->EE->input->post("site_id") != "") ? $this->EE->input->post("site_id") : $this->EE->config->item('site_id');
  108. $group_id = $this->EE->input->post('group_id');
  109. $autopopulate = ($this->EE->input->post('autopopulate') == "true")? 1 : 0;
  110. $nav_content = $this->get_tree_html($this->EE->input->post('jsontree'));
  111. $nav_content = str_replace('S='.$this->EE->session->userdata("session_id").'&',"",$nav_content);
  112. if ($group_id == '' || $nav_content == '')
  113. {
  114. echo "cannot_save";
  115. }else{
  116. $results = $this->EE->db->query("SELECT group_id FROM ".$this->EE->db->dbprefix('ndg_flexible_admin_menus')." WHERE group_id = '".$group_id."'");
  117. if ($results->num_rows() == 0)
  118. {
  119. $data = array(
  120. 'site_id' => $site_id,
  121. 'group_id' => $group_id,
  122. 'nav' => $nav_content,
  123. 'autopopulate' => $autopopulate
  124. );
  125. $this->EE->db->query($this->EE->db->insert_string($this->EE->db->dbprefix('ndg_flexible_admin_menus'), $data));
  126. $cp_message = 'added';
  127. }
  128. else
  129. {
  130. $data = array(
  131. 'nav' => $nav_content,
  132. 'autopopulate' => $autopopulate
  133. );
  134. $where = array(
  135. 'group_id' => $group_id,
  136. 'site_id' => $site_id
  137. );
  138. $this->EE->db->query($this->EE->db->update_string($this->EE->db->dbprefix('ndg_flexible_admin_menus'), $data, $where));
  139. $cp_message = 'updated';
  140. }
  141. if ($this->EE->db->affected_rows() > 0) {
  142. echo $cp_message;
  143. }else{
  144. echo "no_affected_rows";
  145. }
  146. }
  147. }
  148. function ajax_remove_tree()
  149. {
  150. $this->EE->output->enable_profiler(FALSE);
  151. $site_id = ($this->EE->input->post("site_id") != "") ? $this->EE->input->post("site_id") : $this->EE->config->item('site_id');
  152. $group_id = $this->EE->input->post('group_id');
  153. $this->EE->db->where('site_id', $site_id);
  154. $this->EE->db->where('group_id', $group_id);
  155. $this->EE->db->delete($this->EE->db->dbprefix('ndg_flexible_admin_menus'));
  156. if ($this->EE->db->affected_rows() > 0) {
  157. echo "removed";
  158. }else{
  159. echo "no_affected_rows";
  160. }
  161. }
  162. }
  163. /* End of file mod.ndg_flexible_admin.php */
  164. /* Location: ./system/expressionengine/third_party/Cpnav/mod.ndg_flexible_admin.php */