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