// See http://code.google.com/p/wordpress-custom-content-type-manager/issues/detail?id=331 if ('widgets.php' == substr($_SERVER['SCRIPT_NAME'], strrpos($_SERVER['SCRIPT_NAME'], '/') + 1)) { wp_enqueue_script('thickbox'); wp_register_script('PHP_Snippet_Widget', PHP_SNIPPETS_URL . '/js/widget.js', array('jquery')); wp_enqueue_script('PHP_Snippet_Widget'); } } // TODO //load_plugin_textdomain( 'php_snippets', false, PHP_SNIPPETS_PATH.'/lang/' ); global $shortcode_tags; $existing_shortcodes = array_keys($shortcode_tags); // Load up data $ps_data = get_option(Phpsnippets\Base::db_key, array()); $defined_dirs = Phpsnippets\Base::get_value($ps_data, 'snippet_dirs', array()); $ext = Phpsnippets\Base::get_value($ps_data, 'snippet_suffix', '.php'); $include_built_in = Phpsnippets\Base::get_value($ps_data, 'show_builtin_snippets', true); // Set any placeholders we want to support in directory names Phpsnippets\Base::set_placeholder('ABSPATH', ABSPATH); // Get all snippets in all dirs $dirs = Phpsnippets\Base::get_dirs($defined_dirs, $include_built_in); PhpSnippets\Widget::setDirs($dirs); PhpSnippets\Widget::setExt($ext); // Loop thru each dir foreach ($dirs as $d => $d_exists) { $snippets = (array) Phpsnippets\Base::get_snippets($d, $ext); // Loop thru each file foreach ($snippets as $s) { Phpsnippets\Base::add_shortcode($s, $ext); } } // Register Ajax Calls
PhpSnippets\License::get_fields(); $data['licensing_fields'] = ob_get_clean(); } else { $data['msg'] .= sprintf('<div class="error"><p>%s</p></div>', 'There was a problem activating your license. Sorry for the inconvenience.'); ob_start(); PhpSnippets\License::get_fields(); $data['licensing_fields'] = ob_get_clean(); } // 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;
<?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*/