} // options-general.php?page=php-snippets //print '<script type="text/javascript">window.location.replace("'.get_admin_url(false, 'options-general.php?page=php-snippets').'");</script>'; } else { // A little cleanup before we handoff to save_definition_filter $snippet_dirs = Phpsnippets\Base::get_value($_POST, 'snippet_dirs', array()); $snippet_suffix = Phpsnippets\Base::get_value($_POST, 'snippet_suffix'); $show_builtin_snippets = Phpsnippets\Base::get_value($_POST, 'show_builtin_snippets'); $show_tmce_button = Phpsnippets\Base::get_value($_POST, 'show_tmce_button'); $snippet_suffix = !empty($snippet_suffix) ? trim(strip_tags($snippet_suffix)) : '.snippet.php'; foreach ($snippet_dirs as $i => $dir) { // remove empty val if (trim($dir) == '') { unset($snippet_dirs[$i]); } if (!PhpSnippets\Base::dir_exists($dir)) { $warns = PhpSnippets\Base::$warnings; } } $data['msg'] .= sprintf('<div class="updated"><p>%s</p></div>', 'Your settings have been updated!'); $ps_data['snippet_dirs'] = $snippet_dirs; $ps_data['snippet_suffix'] = $snippet_suffix; $ps_data['show_builtin_snippets'] = $show_builtin_snippets; $ps_data['show_tmce_button'] = $show_tmce_button; update_option(Phpsnippets\Base::db_key, $ps_data); $data['snippet_dirs'] = $snippet_dirs; $data['warnings'] = $warns; $data['snippet_suffix'] = $snippet_suffix; $data['show_builtin_snippets'] = $show_builtin_snippets; $data['show_tmce_button'] = $show_tmce_button; }
$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*/
<?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);
<?php /*------------------------------------------------------------------------------ Fires when a user chooses a snippet in the dropdown in the PHP Snippets widget: Given a filepath, this returns the sample shortcode for that snippet. ------------------------------------------------------------------------------*/ 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.'); } if (!isset($_POST['snippet_path']) || empty($_POST['snippet_path'])) { print 'Missing snippet_path.'; return; } $ps_data = get_option(Phpsnippets\Base::db_key, array()); $ext = Phpsnippets\Base::get_value($ps_data, 'snippet_suffix', '.php'); $shortname = Phpsnippets\Base::get_shortname($_POST['snippet_path'], $ext); $info = PhpSnippets\Base::get_snippet_info($_POST['snippet_path']); print PhpSnippets\Base::get_shortcode($info, $shortname); return; /*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*/