Пример #1
0
 public function get_array_for_db()
 {
     return array('name' => $this->get_name(), 'description' => $this->get_description(), 'code' => PhpCodeForPosts_Snippet::hash_code($this->get_code()), 'shared' => $this->get_shared());
 }
Пример #2
0
 private static function _update_snippet(PhpCodeForPosts_Snippet $snippet)
 {
     $db = self::get_db();
     return $db->update(self::get_full_table_name(), $snippet->get_array_for_db(), $snippet->get_where_for_update(), $snippet->get_array_format_for_db(), $snippet->get_where_format_for_update()) !== false;
 }
 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;
     }
 }