示例#1
0
 function load()
 {
     parent::load();
     if (is_network_admin()) {
         wp_redirect(code_snippets_get_menu_url('settings', 'admin'));
         exit;
     }
 }
示例#2
0
/**
 * Register and handle the help tabs for the import snippets admin page
 */
function code_snippets_load_import_help()
{
    $screen = get_current_screen();
    $manage_url = code_snippets_get_menu_url('manage');
    code_snippets_load_help_sidebar($screen);
    $screen->add_help_tab(array('id' => 'overview', 'title' => __('Overview', 'code-snippets'), 'content' => '<p>' . __('Snippets are similar to plugins - they both extend and expand the functionality of WordPress. Snippets are more light-weight, just a few lines of code, and do not put as much load on your server. Here you can load snippets from a Code Snippets (.xml) import file into the database with your existing snippets.', 'code-snippets') . '</p>'));
    $screen->add_help_tab(array('id' => 'import', 'title' => __('Importing', 'code-snippets'), 'content' => '<p>' . __('You can load your snippets from a code snippets (.xml) export file using this page.', 'code-snippets') . sprintf(__('Snippets will be added to the database along with your existing snippets. Regardless of whether the snippets were active on the previous site, imported snippets are always inactive until activated using the <a href="%s">Manage Snippets</a> page.</p>', 'code-snippets'), $manage_url) . '</p>'));
    $screen->add_help_tab(array('id' => 'export', 'title' => __('Exporting', 'code-snippets'), 'content' => '<p>' . sprintf(__('You can save your snippets to a Code Snippets (.xml) export file using the <a href="%s">Manage Snippets</a> page.', 'code-snippets'), $manage_url) . '</p>'));
}
示例#3
0
 /**
  * Print the status and error messages
  */
 protected function print_messages()
 {
     if (isset($_REQUEST['imported'])) {
         echo '<div id="message" class="updated fade"><p>';
         printf(_n('Successfully imported <strong>%d</strong> snippet. <a href="%s">Have fun!</a>', 'Successfully imported <strong>%d</strong> snippets. <a href="%s">Have fun!</a>', count($_REQUEST['imported']), 'code-snippets'), $_REQUEST['imported'], code_snippets_get_menu_url('manage'));
         echo '</p></div>';
     } elseif (isset($_REQUEST['error']) && $_REQUEST['error']) {
         echo '<div id="message" class="error fade"><p>';
         _e('An error occurred when processing the import file.', 'code-snippets');
         echo '</p></div>';
     }
 }
示例#4
0
文件: edit.php 项目: jamokop/openwine
 * @subpackage Views
 */
/* Bail if accessed directly */
if (!defined('ABSPATH')) {
    return;
}
global $pagenow;
$table = get_snippets_table_name();
$edit_id = code_snippets_get_menu_slug('edit') === $_REQUEST['page'] ? absint($_REQUEST['id']) : 0;
$snippet = get_snippet($edit_id);
?>
<div class="wrap">
	<h1><?php 
if ($edit_id) {
    esc_html_e('Edit Snippet', 'code-snippets');
    printf(' <a href="%1$s" class="page-title-action add-new-h2">%2$s</a>', code_snippets_get_menu_url('add'), esc_html_x('Add New', 'snippet', 'code-snippets'));
} else {
    esc_html_e('Add New Snippet', 'code-snippets');
}
?>
</h1>

	<form method="post" action="" style="margin-top: 10px;">
		<?php 
/* Output the hidden fields */
if (0 !== $snippet->id) {
    printf('<input type="hidden" name="snippet_id" value="%d" />', $snippet->id);
}
printf('<input type="hidden" name="snippet_active" value="%d" />', $snippet->active);
?>
		<div id="titlediv">
 /**
  * Message to display if no snippets are found
  */
 function no_items()
 {
     printf(__('You do not appear to have any snippets available at this time. <a href="%s">Add New&rarr;</a>', 'code-snippets'), code_snippets_get_menu_url('add'));
 }
示例#6
0
 /**
  * Save the posted snippet data to the database and redirect
  */
 private function save_posted_snippet()
 {
     /* Build snippet object from fields with 'snippet_' prefix */
     $snippet = new Snippet();
     foreach ($_POST as $field => $value) {
         if ('snippet_' === substr($field, 0, 8)) {
             /* Remove 'snippet_' prefix from field name */
             $field = substr($field, 8);
             $snippet->{$field} = stripslashes($value);
         }
     }
     /* Activate or deactivate the snippet before saving if we clicked the button */
     // Shared network snippets cannot be network activated
     if (isset($_POST['snippet_sharing']) && 'on' === $_POST['snippet_sharing']) {
         $snippet->active = 0;
         unset($_POST['save_snippet_activate'], $_POST['save_snippet_deactivate']);
     } elseif (isset($_POST['save_snippet_activate'])) {
         $snippet->active = 1;
     } elseif (isset($_POST['save_snippet_deactivate'])) {
         $snippet->active = 0;
     }
     /* Deactivate snippet if code contains errors */
     if ($snippet->active) {
         if ($code_error = $this->validate_code($snippet)) {
             $snippet->active = 0;
         }
     }
     /* Save the snippet to the database */
     $snippet_id = save_snippet($snippet);
     /* Update the shared network snippets if necessary */
     if ($snippet_id && get_current_screen()->in_admin('network')) {
         if (isset($_POST['snippet_sharing']) && 'on' === $_POST['snippet_sharing']) {
             $shared_snippets = get_site_option('shared_network_snippets', array());
             /* Add the snippet ID to the array if it isn't already */
             if (!in_array($snippet_id, $shared_snippets)) {
                 $shared_snippets[] = $snippet_id;
                 update_site_option('shared_network_snippets', array_values($shared_snippets));
             }
         } else {
             $this->unshare_network_snippet($snippet_id);
         }
     }
     /* If the saved snippet ID is invalid, display an error message */
     if (!$snippet_id || $snippet_id < 1) {
         /* An error occurred */
         wp_redirect(add_query_arg('result', 'save-error', code_snippets_get_menu_url('add')));
         exit;
     }
     /* Display message if a parse error occurred */
     if (isset($code_error) && $code_error) {
         wp_redirect(add_query_arg(array('id' => $snippet_id, 'result' => 'code-error'), code_snippets_get_menu_url('edit')));
         exit;
     }
     /* Set the result depending on if the snippet was just added */
     $result = isset($_POST['snippet_id']) ? 'updated' : 'added';
     /* Append a suffix if the snippet was activated or deactivated */
     if (isset($_POST['save_snippet_activate'])) {
         $result .= '-and-activated';
     } elseif (isset($_POST['save_snippet_deactivate'])) {
         $result .= '-and-deactivated';
     }
     /* Redirect to edit snippet page */
     wp_redirect(add_query_arg(array('id' => $snippet_id, 'result' => $result), code_snippets_get_menu_url('edit')));
     exit;
 }
示例#7
0
?>
<div class="wrap">
	<h1><?php 
_e('Import Snippets', 'code-snippets');
?>
</h1>

	<div class="narrow">

		<p><?php 
_e('Howdy! Upload your Code Snippets export file and we&#8217;ll import the snippets to this site.', 'code-snippets');
?>
</p>

		<p><?php 
printf(__('You will need to go to the <a href="%s">Manage Snippets</a> page to activate the imported snippets.', 'code-snippets'), code_snippets_get_menu_url('manage'));
?>
</p>

		<p><?php 
_e('Choose a Code Snippets (.xml) file to upload, then click Upload file and import.', 'code-snippets');
?>
</p>

		<form enctype="multipart/form-data" method="post" action="" id="import-upload-form" name="code_snippets_import">
			<p>
				<input type="hidden" name="action" value="save" />
				<input type="hidden" name="max_file_size" value="8388608" />

				<label for="upload"><?php 
_e('Choose a file from your computer:', 'code-snippets');
示例#8
0
/**
 * Loads the help tabs for the Edit Snippets page
 *
 * @since 1.0
 * @access private
 * @uses wp_redirect To pass the results to the page
 */
function code_snippets_load_single_menu()
{
    /* Make sure the user has permission to be here */
    if (!current_user_can(get_snippets_cap())) {
        wp_die(__('You are not authorized to access this page.', 'code-snippets'));
    }
    /* Create the snippet tables if they don't exist */
    create_code_snippets_tables();
    /* Load the screen help tabs */
    require plugin_dir_path(__FILE__) . 'admin-help.php';
    /* Enqueue the code editor and other scripts and styles */
    add_action('admin_enqueue_scripts', 'code_snippets_enqueue_codemirror', 9);
    /* Don't allow visiting the edit snippet page without a valid ID */
    if (code_snippets_get_menu_slug('edit') === $_REQUEST['page']) {
        if (!isset($_REQUEST['id']) || 0 == $_REQUEST['id']) {
            wp_redirect(code_snippets_get_menu_url('add'));
            exit;
        }
    }
    /* Make sure the nonce validates before we do any snippet ops */
    if (!isset($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'], 'save_snippet')) {
        return;
    }
    /* Save the snippet if one has been submitted */
    if (isset($_POST['save_snippet']) || isset($_POST['save_snippet_activate']) || isset($_POST['save_snippet_deactivate'])) {
        /* Activate or deactivate the snippet before saving if we clicked the button */
        if (isset($_POST['save_snippet_activate'])) {
            $_POST['snippet_active'] = 1;
        } elseif (isset($_POST['save_snippet_deactivate'])) {
            $_POST['snippet_active'] = 0;
        }
        /* Save the snippet to the database */
        $result = save_snippet(stripslashes_deep($_POST));
        /* Build the status message and redirect */
        $query_args = array();
        if ($result && isset($_POST['save_snippet_activate'])) {
            /* Snippet was activated addition to saving*/
            $query_args['activated'] = true;
        } elseif ($result && isset($_POST['save_snippet_deactivate'])) {
            /* Snippet was deactivated addition to saving*/
            $query_args['deactivated'] = true;
        }
        if (!$result || $result < 1) {
            /* An error occurred */
            $query_args['invalid'] = true;
        } elseif (isset($_POST['snippet_id'])) {
            /* Existing snippet was updated */
            $query_args['id'] = $result;
            $query_args['updated'] = true;
        } else {
            /* New snippet was added */
            $query_args['id'] = $result;
            $query_args['added'] = true;
        }
        /* Redirect to edit snippet page */
        wp_redirect(add_query_arg($query_args, code_snippets_get_menu_url('edit')));
    } elseif (isset($_POST['snippet_id'], $_POST['delete_snippet'])) {
        delete_snippet($_POST['snippet_id']);
        wp_redirect(add_query_arg('delete', true, code_snippets_get_menu_url('manage')));
    } elseif (isset($_POST['snippet_id'], $_POST['export_snippet'])) {
        export_snippets($_POST['snippet_id']);
    }
}
示例#9
0
/**
 * Fetch the admin menu slug for a snippets menu
 * @param  int    $snippet_id The snippet
 * @param  string $context    The URL scheme to use
 * @return string             The URL to the edit snippet page for that snippet
 */
function get_snippet_edit_url($snippet_id, $context = 'self')
{
    return add_query_arg('id', absint($snippet_id), code_snippets_get_menu_url('edit', $context));
}
<?php

/**
 * Status and error messages for the import snippets page
 *
 * @package    Code_Snippets
 * @subpackage Admin_Messages
 */
if (isset($_REQUEST['imported']) && 0 !== intval($_REQUEST['imported'])) {
    echo '<div id="message" class="updated fade"><p>';
    printf(_n('Successfully imported <strong>%d</strong> snippet. <a href="%s">Have fun!</a>', 'Successfully imported <strong>%d</strong> snippets. <a href="%s">Have fun!</a>', $_REQUEST['imported'], 'code-snippets'), $_REQUEST['imported'], code_snippets_get_menu_url('manage'));
    echo '</p></div>';
} elseif (isset($_REQUEST['error']) && $_REQUEST['error']) {
    printf('<div id="message" class="error fade"><p>%s</p></div>', __('An error occurred when processing the import file.', 'code-snippets'));
}
示例#11
0
<?php

/**
 * Register and handle the help tabs for the
 * import snippets admin page
 *
 * @package Code_Snippets
 * @subpackage Import
 */
$screen = get_current_screen();
$manage_url = code_snippets_get_menu_url('manage');
$screen->add_help_tab(array('id' => 'overview', 'title' => __('Overview', 'code-snippets'), 'content' => '<p>' . __('Snippets are similar to plugins - they both extend and expand the functionality of WordPress. Snippets are more light-weight, just a few lines of code, and do not put as much load on your server. Here you can load snippets from a Code Snippets (.xml) import file into the database with your existing snippets.', 'code-snippets') . '</p>'));
$screen->add_help_tab(array('id' => 'import', 'title' => __('Importing', 'code-snippets'), 'content' => '<p>' . __('You can load your snippets from a code snippets (.xml) export file using this page.', 'code-snippets') . sprintf(__('Snippets will be added to the database along with your existing snippets. Regardless of whether the snippets were active on the previous site, imported snippets are always inactive until activated using the <a href="%s">Manage Snippets</a> page.</p>', 'code-snippets'), $manage_url) . '</p>'));
$screen->add_help_tab(array('id' => 'export', 'title' => __('Exporting', 'code-snippets'), 'content' => '<p>' . sprintf(__('You can save your snippets to a Code Snippets (.xml) export file using the <a href="%s">Manage Snippets</a> page.', 'code-snippets'), $manage_url) . '</p>'));
$screen->set_help_sidebar('<p><strong>' . __('For more information:', 'code-snippets') . '</strong></p>' . '<p>' . __('<a href="http://wordpress.org/plugins/code-snippets" target="_blank">WordPress Extend</a>', 'code-snippets') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/plugin/code-snippets" target="_blank">Support Forums</a>', 'code-snippets') . '</p>' . '<p>' . __('<a href="http://bungeshea.com/plugins/code-snippets/" target="_blank">Project Website</a>', 'code-snippets') . '</p>');
示例#12
0
/**
 * Adds a link pointing to the Manage Snippets page
 *
 * @since 2.0
 * @access private
 * @param array $links The existing plugin action links
 * @return array The modified plugin action links
 */
function code_snippets_plugin_settings_link($links)
{
    array_unshift($links, sprintf('<a href="%1$s" title="%2$s">%3$s</a>', code_snippets_get_menu_url(), __('Manage your existing snippets', 'code-snippets'), __('Manage', 'code-snippets')));
    return $links;
}
示例#13
0
 /**
  * Save the posted snippet to the database
  * @uses wp_redirect() to pass the results to the page
  * @uses save_snippet() to save the snippet to the database
  */
 private function save_posted_snippet()
 {
     /* Make sure the nonce validates before we do any snippet ops */
     if (!isset($_REQUEST['_wpnonce']) || !wp_verify_nonce($_REQUEST['_wpnonce'], 'save_snippet')) {
         return;
     }
     /* Save the snippet if one has been submitted */
     if (isset($_POST['save_snippet']) || isset($_POST['save_snippet_activate']) || isset($_POST['save_snippet_deactivate'])) {
         /* Build snippet object from fields with 'snippet_' prefix */
         $snippet = new Snippet();
         foreach ($_POST as $field => $value) {
             if ('snippet_' === substr($field, 0, 8)) {
                 /* Remove 'snippet_' prefix from field name */
                 $field = substr($field, 8);
                 $snippet->{$field} = stripslashes($value);
             }
         }
         /* Activate or deactivate the snippet before saving if we clicked the button */
         // Shared network snippets cannot be network activated
         if (isset($_POST['snippet_sharing']) && 'on' === $_POST['snippet_sharing']) {
             $snippet->active = 0;
             unset($_POST['save_snippet_activate'], $_POST['save_snippet_deactivate']);
         } elseif (isset($_POST['save_snippet_activate'])) {
             $snippet->active = 1;
         } elseif (isset($_POST['save_snippet_deactivate'])) {
             $snippet->active = 0;
         }
         /* Save the snippet to the database */
         $snippet_id = save_snippet($snippet);
         /* Update the shared network snippets if necessary */
         if ($snippet_id && get_current_screen()->in_admin('network')) {
             $shared_snippets = get_site_option('shared_network_snippets', array());
             if (isset($_POST['snippet_sharing']) && 'on' === $_POST['snippet_sharing']) {
                 /* Add the snippet ID to the array if it isn't already */
                 if (!in_array($snippet_id, $shared_snippets)) {
                     $shared_snippets[] = $snippet_id;
                     update_site_option('shared_network_snippets', array_values($shared_snippets));
                 }
             } elseif (in_array($snippet_id, $shared_snippets)) {
                 /* Remove the snippet ID from the array */
                 $shared_snippets = array_diff($shared_snippets, array($snippet_id));
                 update_site_option('shared_network_snippets', array_values($shared_snippets));
                 /* Deactivate on all sites */
                 global $wpdb;
                 if ($sites = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}")) {
                     foreach ($sites as $site) {
                         switch_to_blog($site);
                         $active_shared_snippets = get_option('active_shared_network_snippets');
                         if (is_array($active_shared_snippets)) {
                             $active_shared_snippets = array_diff($active_shared_snippets, array($snippet_id));
                             update_option('active_shared_network_snippets', $active_shared_snippets);
                         }
                     }
                     restore_current_blog();
                 }
             }
         }
         /* If the saved snippet ID is invalid, display an error message */
         if (!$snippet_id || $snippet_id < 1) {
             /* An error occurred */
             wp_redirect(add_query_arg('result', 'error', code_snippets_get_menu_url('add')));
             exit;
         }
         /* Set the result depending on if the snippet was just added */
         $result = isset($_POST['snippet_id']) ? 'updated' : 'added';
         /* Append a suffix if the snippet was activated or deactivated */
         if (isset($_POST['save_snippet_activate'])) {
             $result .= '-and-activated';
         } elseif (isset($_POST['save_snippet_deactivate'])) {
             $result .= '-and-deactivated';
         }
         /* Redirect to edit snippet page */
         wp_redirect(add_query_arg(array('id' => $snippet_id, 'result' => $result), code_snippets_get_menu_url('edit')));
         exit;
     } elseif (isset($_POST['snippet_id'], $_POST['delete_snippet'])) {
         delete_snippet($_POST['snippet_id']);
         wp_redirect(add_query_arg('result', 'delete', code_snippets_get_menu_url('manage')));
         exit;
     } elseif (isset($_POST['snippet_id'], $_POST['export_snippet'])) {
         export_snippets($_POST['snippet_id']);
     }
 }
示例#14
0
 * @subpackage Manage
 */
/* Bail if accessed directly */
if (!defined('ABSPATH')) {
    return;
}
global $code_snippets_list_table;
?>

<div class="wrap">
	<?php 
screen_icon();
?>
	<h2><?php 
esc_html_e('Snippets', 'code-snippets');
printf('<a href="%2$s" class="add-new-h2">%1$s</a>', esc_html_x('Add New', 'snippet', 'code-snippets'), code_snippets_get_menu_url('add'));
$code_snippets_list_table->search_notice();
?>
</h2>

	<?php 
$code_snippets_list_table->views();
?>

	<form method="get" action="">
		<?php 
$code_snippets_list_table->required_form_fields('search_box');
$code_snippets_list_table->search_box(__('Search Installed Snippets', 'code-snippets'), 'search_id');
?>
	</form>
	<form method="post" action="">