public function editor() { if (isset($_GET['theme']) && !empty($_GET['theme'])) { $themename = trim($_GET['theme']); if (!is_dir(_ROOT . "themes/{$themename}")) { $msg = error("Theme yang Anda maksud tidak ditemukan"); set_msg($msg); redirect('cpanel/theme'); exit; } $themepath = _ROOT . "themes/{$themename}/"; $dir = path_list_r($themepath); $filetree = tree_files($dir); $mode = 'html'; $content = 'layout.html'; if (isset($_GET['file']) && !empty($_GET['file'])) { $filename = trim($_GET['file']); if ($filename != 'layout.html') { list($folder, $file) = explode(':', $filename); } else { $file = $filename; } $extension = strtolower(end(explode('.', $file))); switch ($extension) { case 'js': $mode = 'javascript'; break; case 'css': $mode = 'css'; break; case 'html': $mode = 'html'; break; default: $mode = 'html'; break; } $content = str_replace(':', '/', $filename); } else { $filename = 'layout.html'; } $filecontent = file_read($themepath . $content); $filecontent = htmlentities($filecontent); $data['current_file'] = $filename; $data['file'] = $filetree; $data['mode'] = $mode; $data['content'] = $filecontent; $data['current_theme'] = $themename; $data['page'] = "layout_theme_editor"; $data['module'] = "cpanel"; $data['title'] = "Theme editor"; $this->load->view($this->layout, $data); } }
function path_list_r($path, $top_level_only = FALSE) { if ($fp = @opendir($path)) { $path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; $filedata = $item = array(); while (FALSE !== ($file = readdir($fp))) { if (strncmp($file, '.', 1) == 0) { continue; } if ($top_level_only == FALSE && @is_dir($path . $file)) { $temp_array = array(); $temp_array = path_list_r($path . $file . DIRECTORY_SEPARATOR); $item['name'] = $file; $item['is_folder'] = true; $item['path'] = $path . $file; $item['child'] = $temp_array; $filedata[] = $item; } else { $item['name'] = $file; $item['is_folder'] = false; $item['path'] = $path . $file; $item['child'] = array(); $filedata[] = $item; } } closedir($fp); return $filedata; } return false; }
function find_templates($dir, $prefix = '') { if (!empty($dir)) { if (is_array($dir)) { $output = array(); foreach ($dir as $var => $val) { if (is_array($val)) { $r = call_user_func(__FUNCTION__, $val, $prefix . $var . '/'); if (!empty($r)) { $output = array_merge($output, $r); } } else { if (preg_match('~\\.html\\.php$~s', $val)) { $output[] = $prefix . $val; } } } return $output; } else { if (file_exists($dir)) { $dir .= substr($dir, -1) == '/' ? '' : '/'; return call_user_func(__FUNCTION__, path_list_r($dir), $dir); } } } }