<?php /*------------------------------------------------------------------------------ Fires when a user clicks the button in the TinyMCE editor: this launches the thickbox pop-up that displays the list of all available snippets. ------------------------------------------------------------------------------*/ if (!defined('PHP_SNIPPETS_PATH')) { exit('No direct script access allowed'); } if (!current_user_can('edit_posts')) { die('You do not have permission to do that.'); } // Template variables $data = array(); $data['pagetitle'] = __('Directory List', 'php_snippets'); $data['content'] = ''; $parent_dir = isset($_POST['parent_dir']) ? $_POST['parent_dir'] : substr(get_home_path(), 0, -1); $dirs = PhpSnippets\Base::list_dirs($parent_dir); // Each Directory gets a heading foreach ($dirs as $i => $dir) { $dir_name = explode('/', $dir); $data['content'] .= sprintf("<li>\n\t\t<a href='#' class='refresh_dir' data-parent_dir='{$dir}'><img class='php_snippets_img' src='" . PHP_SNIPPETS_URL . "/images/dir.png' height='10' width='10'/><strong>%s</strong></a>", array_pop($dir_name)); if ($i !== 0) { $data['content'] .= " : <a href='#' class='select_dir' data-sel_dir='{$dir}'><span class='linklike'>Select</span></li></a>"; } } print PhpSnippets\Base::load_view('directory_list.php', $data);
$dirs = PhpSnippets\Base::get_dirs($snippet_dirs, $show_builtin_snippets); if (!empty(PhpSnippets\Base::$warnings)) { $data['content'] .= '<div id="php-snippets-errors" class="error"><p>Some of the directories you defined do not exist!</p></div><br>'; } // Each Directory gets a heading foreach ($dirs as $dir => $exists) { $class_dir = $exists ? '' : 'snippet_dir_error'; $class_dir_error = $exists ? '' : '<span>: ' . __('Directory Does not Exist', 'php_snippets') . '</span>'; $data['content'] .= "<div class='snippet_dir {$class_dir}'>{$dir} {$class_dir_error}</div>"; if (!$exists) { continue; } $snippets = PhpSnippets\Base::get_snippets($dir, $ext); if (!empty($snippets)) { foreach ($snippets as $shortname => $snippet) { $info = PhpSnippets\Base::get_snippet_info($snippet); //print '<pre>'; print_r($info); print '</pre>'; $info['shortcode'] = PhpSnippets\Base::get_shortcode($info, $shortname); $error_class = ''; if ($info['errors']) { $info['desc'] = $info['errors']; $error_class = ' php_snippets_error warning_field'; } $data['content'] .= sprintf('<li> <strong class="linklike %s">%s</strong> : <span class="php_snippets_desc">%s</span></li>', $error_class, $shortname, $info['desc']); } } } print PhpSnippets\Base::load_view('tb_setting.php', $data); /*EOF*/
$data = array(); $data['pagetitle'] = __('Select a Snippet', 'php_snippets'); $data['content'] = ''; $data['other_shortcodes'] = ''; //$snippets = PhpSnippets\Base::get_snippets(); $ps_data = get_option(PhpSnippets\Base::db_key, array()); $snippet_dirs = PhpSnippets\Base::get_value($ps_data, 'snippet_dirs', array()); $show_builtin_snippets = PhpSnippets\Base::get_value($ps_data, 'show_builtin_snippets', 0); $ext = PhpSnippets\Base::get_value($ps_data, 'snippet_suffix'); $dirs = PhpSnippets\Base::get_dirs($snippet_dirs, $show_builtin_snippets); if (!empty(PhpSnippets\Base::$warnings)) { $data['content'] = '<div id="php-snippets-errors" class="error">'; foreach (PhpSnippets\Base::$warnings as $w => $tmp) { $data['content'] .= sprintf("<p>%s: %s</p>", $w, __('Directory Does not Exist', 'php_snippets')); } $data['content'] .= '</div><br>'; } foreach ($dirs as $dir => $exists) { if ($exists) { $snippets = PhpSnippets\Base::get_snippets($dir, $ext); if (!empty($snippets)) { foreach ($snippets as $shortname => $snippet) { $info = PhpSnippets\Base::get_snippet_info($snippet); $shortcode = PhpSnippets\Base::get_shortcode($info, $shortname); $data['content'] .= sprintf("<li>\n \t\t\t\t<strong class='linklike' onclick='javascript:insert_shortcode(\"%s\");'>%s</strong>\n\t\t\t\t\t: <span class='php_snippets_desc'>%s</span></li>", htmlspecialchars(addslashes($shortcode)), $shortname, $info['desc']); } } } } print PhpSnippets\Base::load_view('thickbox.php', $data); /*EOF*/