예제 #1
0
 public static function handle_multisite_shortcode($attributes)
 {
     $arguments = array('snippet' => 0, 'param' => '', 'blog_id' => 1);
     $attributes = shortcode_atts($arguments, $attributes);
     $snippet_id = intval($attributes['snippet']);
     if ($snippet_id == 0) {
         return '';
     }
     $blog_id = max(0, intval($attributes['blog_id']));
     if (!PhpCodeForPosts::$options->get_multisite_option('crosssite_snippets') && $blog_id > 1) {
         return '';
     }
     $snippet = PhpCodeForPosts_Database::load_single_snippet($snippet_id, $blog_id);
     if (!$snippet->is_loaded()) {
         return '';
     }
     return self::do_shortcode($snippet, $attributes);
 }
예제 #2
0
 public static function save_posted_snippet($post_fields)
 {
     $snippet_id = isset($post_fields['item']) ? $post_fields['item'] : 0;
     $snippet = $snippet_id > 0 ? PhpCodeForPosts_Database::load_single_snippet($snippet_id) : new PhpCodeForPosts_Snippet();
     $snippet->set_name(stripslashes($post_fields['name']));
     $snippet->set_code($post_fields['code']);
     $snippet->set_description(stripcslashes($post_fields['description']));
     $snippet->set_shared(intval($post_fields['shared']));
     PhpCodeForPosts_Snippet::$last_saved_snippet = $snippet;
     return PhpCodeForPosts_Database::save_snippet($snippet);
 }
예제 #3
0
 public static function show_menu_page_edit()
 {
     if (!PhpCodeForPosts::check_nonce($_REQUEST['actioncode'], $_REQUEST['item'], $_REQUEST['action'])) {
         echo 'An Error Occured';
         return;
     }
     if ($_REQUEST['item'] == 0) {
         $snippet = new PhpCodeForPosts_Snippet();
     } else {
         $snippet = PhpCodeForPosts_Database::load_single_snippet($_REQUEST['item']);
     }
     include PhpCodeForPosts::directory_path_it('templates/admin-index-edit.tpl');
 }
예제 #4
0
 private static function get_database_table_name()
 {
     return PhpCodeForPosts_Database::get_full_table_name();
 }
 private static function check_actions($post, $ajax = false)
 {
     switch ($post['action']) {
         case 'updateoptions':
             $state = PhpCodeForPosts::$options->save_posted_options($post);
             if ($ajax) {
                 echo (int) $state;
                 exit;
             }
             if ($state) {
                 PhpCodeForPosts_Messages::add_success_message(__('Options saved', "phpcodeforposts"));
             } else {
                 PhpCodeForPosts_Messages::add_error_message(__('Failed to save options - have they changed?', "phpcodeforposts"));
             }
             break;
         case 'save':
             $state = PhpCodeForPosts_Snippet::save_posted_snippet($post);
             if ($ajax) {
                 echo (int) $state;
                 exit;
             }
             if ($state) {
                 $shortcode = '[' . PhpCodeForPosts_Shortcode::get_shortcode() . ' snippet=' . PhpCodeForPosts_Snippet::$last_saved_snippet->get_id() . ']';
                 PhpCodeForPosts_Messages::add_success_message(__('Snippet saved', "phpcodeforposts") . ' - ' . $shortcode);
             } else {
                 PhpCodeForPosts_Messages::add_error_message(__('Failed to save snippet - has it changed?', "phpcodeforposts"));
             }
             header('location:admin.php' . html_entity_decode(PhpCodeForPosts_Snippet::$last_saved_snippet->get_snippet_edit_link()));
             exit;
             break;
         case 'delete':
             $state = PhpCodeForPosts_Database::delete_snippet_by_id($post['item']);
             if ($ajax) {
                 $msg = $state ? __('Snippet Deleted', "phpcodeforposts") : __('Failed to delete snippet - it may not exist', "phpcodeforposts");
                 self::send_json_response($state ? 1 : 0, $msg);
             }
             if ($state) {
                 PhpCodeForPosts_Messages::add_success_message(__('Snippet deleted', "phpcodeforposts"));
             } else {
                 PhpCodeForPosts_Messages::add_error_message(__('Failed to delete snippet - it may not exist', "phpcodeforposts"));
             }
             break;
         case 'bulkdelete':
             $snippets_to_delete = $post['delete'];
             if (count($snippets_to_delete) == 0) {
                 if ($ajax) {
                     self::send_json_response(true, __('Nothing To Delete', "phpcodeforposts"));
                 }
                 break;
                 //do nothing.
             }
             $deleted_count = 0;
             foreach ($snippets_to_delete as $record => $one) {
                 try {
                     if (PhpCodeForPosts_Database::delete_snippet_by_id(intval($record))) {
                         $deleted_count++;
                     }
                 } catch (InvalidArgumentException $e) {
                     //do nothing.
                 }
             }
             if ($deleted_count > 0) {
                 $msg = sprintf(_n('%d Snippet deleted', '%d Snippets deleted', $deleted_count, "phpcodeforposts"), $deleted_count);
                 if ($ajax) {
                     self::send_json_response(true, $msg);
                 } else {
                     PhpCodeForPosts_Messages::add_success_message($msg);
                 }
             } else {
                 $msg = __('Failed to delete snippets', "phpcodeforposts");
                 if ($ajax) {
                     self::send_json_response(false, $msg);
                 } else {
                     PhpCodeForPosts_Messages::add_error_message($msg);
                 }
             }
             break;
     }
 }