/code/cake/app/webroot/cp/wp-content/plugins/commentpress-core/commentpress-core/class_commentpress_db.php
PHP | 4316 lines | 1358 code | 1731 blank | 1227 comment | 244 complexity | 21ee3acc0aca0c858965c056b799cec3 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, AGPL-1.0, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- <?php /*
- ================================================================================
- Class CommentpressCoreDatabase
- ================================================================================
- AUTHOR: Christian Wach <needle@haystack.co.uk>
- --------------------------------------------------------------------------------
- NOTES
- =====
- This class is a wrapper for the majority of database operations.
- --------------------------------------------------------------------------------
- */
- /*
- ================================================================================
- Class Name
- ================================================================================
- */
- class CommentpressCoreDatabase {
- /*
- ============================================================================
- Properties
- ============================================================================
- */
-
- // parent object reference
- var $parent_obj;
-
- // standard mobile browser
- var $is_mobile = false;
-
- // touch-based mobile browser
- var $is_mobile_touch = false;
-
- // touch-based tablet browser
- var $is_tablet = false;
-
- // ---------- options ----------
- var $commentpress_options = array();
-
- // TOC content ('post' or 'page')
- var $toc_content = 'page';
-
- // TOC chapters are pages by default
- var $toc_chapter_is_page = 1;
- // Show extended TOC content for posts lists
- var $show_extended_toc = 1;
-
- // TOC shows subpages by default
- var $show_subpages = 1;
-
- // show page titles by default
- var $title_visibility = 'show';
-
- // hide page meta by default
- var $page_meta_visibility = 'hide';
-
- // default editor (tinyMCE)
- var $comment_editor = 1;
-
- // promote reading (1) or commenting (0)
- var $promote_reading = 0;
-
- // default excerpt length
- var $excerpt_length = 55;
-
- // default header background colour (hex, same as in layout.css)
- var $header_bg_colour = '2c2622';
-
- // default scroll speed (ms)
- var $js_scroll_speed = '800';
-
- // default type of blog - eg, array('0' => 'Poetry','1' => 'Prose')
- var $blog_type = false;
-
- // default blog workflow (like translation, for example), off by default
- var $blog_workflow = 0;
-
- // default sidebar ('toc' => Contents tab)
- var $sidebar_default = 'toc';
-
- // default minimum page width (px)
- var $min_page_width = '447';
-
- // "live" comment refreshing off by default
- var $para_comments_live = 0;
-
- // prevent save_post hook firing more than once
- var $saved_post = false;
-
- /**
- * @description: initialises this object
- * @param object $parent_obj a reference to the parent object
- * @return object
- * @todo:
- *
- */
- function __construct( $parent_obj ) {
-
- // store reference to parent
- $this->parent_obj = $parent_obj;
-
- // init
- $this->_init();
- // --<
- return $this;
- }
- /**
- * @description: PHP 4 constructor
- */
- function CommentpressCoreDatabase( $parent_obj ) {
-
- // is this php5?
- if ( version_compare( PHP_VERSION, "5.0.0", "<" ) ) {
-
- // call php5 constructor
- $this->__construct( $parent_obj );
-
- }
-
- // --<
- return $this;
- }
- /**
- * @description: set up all items associated with this object
- * @todo:
- *
- */
- function activate() {
-
- // have we already got a modified database?
- $modified = $this->db_is_modified( 'comment_text_signature' ) ? 'y' : 'n';
-
- // if we have an existing comment_text_signature column...
- if ( $modified == 'y' ) {
-
- // upgrade old Commentpress schema to new
- if ( !$this->schema_upgrade() ) {
-
- // kill plugin activation
- _cpdie( 'CommentPress Core Error: could not upgrade the database' );
-
- }
-
- } else {
-
- // update db schema
- $this->schema_update();
-
- }
-
-
-
- // test if we have our version
- if ( !$this->option_wp_get( 'commentpress_version' ) ) {
-
- // store CommentPress Core version
- $this->option_wp_set( 'commentpress_version', COMMENTPRESS_VERSION );
-
- }
-
-
-
- // test that we aren't reactivating
- if ( !$this->option_wp_get( 'commentpress_options' ) ) {
-
- // test if we have a existing pre-3.4 Commentpress instance
- if ( commentpress_is_legacy_plugin_active() ) {
-
- // yes: add options with existing values
- $this->_options_migrate();
-
- } else {
-
- // no: add options with default values
- $this->_options_create();
-
- }
-
- }
-
-
-
- // retrieve data on special pages
- $special_pages = $this->option_get( 'cp_special_pages', array() );
- // if we haven't created any...
- if ( count( $special_pages ) == 0 ) {
- // create special pages
- $this->create_special_pages();
-
- }
-
- // turn comment paging option off
- $this->_cancel_comment_paging();
- // override widgets
- $this->_clear_widgets();
- }
- /**
- * @description: upgrade Commentpress plugin from 3.1 options to latest set
- * @return boolean $result
- * @todo:
- *
- */
- function upgrade() {
-
- // database object
- global $wpdb;
-
- // init return
- $result = false;
- // if we have a commentpress install (or we're forcing)
- if ( $this->check_upgrade() ) {
-
- // are we missing the commentpress_options option?
- if ( !$this->option_wp_exists( 'commentpress_options' ) ) {
-
- // upgrade to the single array
- $this->_options_upgrade();
-
- }
-
-
-
- // checkboxes send no value if not checked, so use a default
- $cp_blog_workflow = $this->blog_workflow;
-
- // default blog type
- $cp_blog_type = $this->blog_type;
-
-
-
- // get variables
- extract( $_POST );
-
-
-
- // Removed in CP 3.4 - do we still have the legacy cp_para_comments_enabled option?
- if ( $this->option_exists( 'cp_para_comments_enabled' ) ) {
-
- // delete old cp_para_comments_enabled option
- $this->option_delete( 'cp_para_comments_enabled' );
-
- }
-
- // Removed in CP 3.4 - do we still have the legacy cp_minimise_sidebar option?
- if ( $this->option_exists( 'cp_minimise_sidebar' ) ) {
-
- // delete old cp_minimise_sidebar option
- $this->option_delete( 'cp_minimise_sidebar' );
-
- }
-
- // New in CP 3.4 - has AJAX "live" comment refreshing been migrated?
- if ( !$this->option_exists( 'cp_para_comments_live' ) ) {
-
- // "live" comment refreshing, off by default
- $this->option_set( 'cp_para_comments_live', $this->para_comments_live );
-
- }
-
-
-
- // New in CP 3.3.3 - changed the way the welcome page works
- if ( $this->option_exists( 'cp_special_pages' ) ) {
-
- // do we have the cp_welcome_page option?
- if ( $this->option_exists( 'cp_welcome_page' ) ) {
-
- // get it
- $page_id = $this->option_get( 'cp_welcome_page' );
-
- // retrieve data on special pages
- $special_pages = $this->option_get( 'cp_special_pages', array() );
-
- // is it in our special pages array?
- if ( in_array( $page_id, $special_pages ) ) {
-
- // remove page id from array
- $special_pages = array_diff( $special_pages, array( $page_id ) );
-
- // reset option
- $this->option_set( 'cp_special_pages', $special_pages );
-
- }
-
- }
-
- }
-
- // New in CP 3.3.3 - are we missing the cp_sidebar_default option?
- if ( !$this->option_exists( 'cp_sidebar_default' ) ) {
-
- // get choice
- $_choice = $wpdb->escape( $cp_sidebar_default );
-
- // add chosen cp_page_meta_visibility option
- $this->option_set( 'cp_sidebar_default', $_choice );
-
- }
-
- // New in CP 3.3.2 - are we missing the cp_page_meta_visibility option?
- if ( !$this->option_exists( 'cp_page_meta_visibility' ) ) {
-
- // get choice
- $_choice = $wpdb->escape( $cp_page_meta_visibility );
-
- // add chosen cp_page_meta_visibility option
- $this->option_set( 'cp_page_meta_visibility', $_choice );
-
- }
-
- // New in CP 3.3.1 - are we missing the cp_blog_workflow option?
- if ( !$this->option_exists( 'cp_blog_workflow' ) ) {
-
- // get choice
- $_choice = $wpdb->escape( $cp_blog_workflow );
-
- // add chosen cp_blog_workflow option
- $this->option_set( 'cp_blog_workflow', $_choice );
-
- }
-
- // New in CP 3.3.1 - are we missing the cp_blog_type option?
- if ( !$this->option_exists( 'cp_blog_type' ) ) {
-
- // get choice
- $_choice = $wpdb->escape( $cp_blog_type );
-
- // add chosen cp_blog_type option
- $this->option_set( 'cp_blog_type', $_choice );
-
- }
-
- // New in CP 3.3 - are we missing the cp_show_extended_toc option?
- if ( !$this->option_exists( 'cp_show_extended_toc' ) ) {
-
- // get choice
- $_choice = $wpdb->escape( $cp_show_extended_toc );
-
- // add chosen cp_show_extended_toc option
- $this->option_set( 'cp_show_extended_toc', $_choice );
-
- }
-
- // are we missing the cp_comment_editor option?
- if ( !$this->option_exists( 'cp_comment_editor' ) ) {
-
- // get choice
- $_choice = $wpdb->escape( $cp_comment_editor );
-
- // add chosen cp_comment_editor option
- $this->option_set( 'cp_comment_editor', $_choice );
-
- }
-
- // are we missing the cp_promote_reading option?
- if ( !$this->option_exists( 'cp_promote_reading' ) ) {
-
- // get choice
- $_choice = $wpdb->escape( $cp_promote_reading );
-
- // add chosen cp_promote_reading option
- $this->option_set( 'cp_promote_reading', $_choice );
-
- }
-
- // are we missing the cp_title_visibility option?
- if ( !$this->option_exists( 'cp_title_visibility' ) ) {
-
- // get choice
- $_choice = $wpdb->escape( $cp_title_visibility );
-
- // add chosen cp_title_visibility option
- $this->option_set( 'cp_title_visibility', $_choice );
-
- }
-
- // are we missing the cp_header_bg_colour option?
- if ( !$this->option_exists( 'cp_header_bg_colour' ) ) {
-
- // get choice
- $_choice = $wpdb->escape( $cp_header_bg_colour );
-
- // strip our rgb #
- if ( stristr( $_choice, '#' ) ) {
- $_choice = substr( $_choice, 1 );
- }
-
- // reset to default if blank
- if ( $_choice == '' ) {
- $_choice = $this->header_bg_colour;
- }
-
- // add chosen cp_header_bg_colour option
- $this->option_set( 'cp_header_bg_colour', $_choice );
-
- }
-
- // are we missing the cp_js_scroll_speed option?
- if ( !$this->option_exists( 'cp_js_scroll_speed' ) ) {
-
- // get choice
- $_choice = $wpdb->escape( $cp_js_scroll_speed );
-
- // add chosen cp_js_scroll_speed option
- $this->option_set( 'cp_js_scroll_speed', $_choice );
-
- }
-
- // are we missing the cp_min_page_width option?
- if ( !$this->option_exists( 'cp_min_page_width' ) ) {
-
- // get choice
- $_choice = $wpdb->escape( $cp_min_page_width );
-
- // add chosen cp_min_page_width option
- $this->option_set( 'cp_min_page_width', $_choice );
-
- }
-
- // do we still have the legacy cp_allow_users_to_minimize option?
- if ( $this->option_exists( 'cp_allow_users_to_minimize' ) ) {
-
- // delete old cp_allow_users_to_minimize option
- $this->option_delete( 'cp_allow_users_to_minimize' );
-
- }
-
- // do we have special pages?
- if ( $this->option_exists( 'cp_special_pages' ) ) {
-
- // if we don't have the toc page...
- if ( !$this->option_exists( 'cp_toc_page' ) ) {
-
- // get special pages array
- $special_pages = $this->option_get( 'cp_special_pages', array() );
-
- // create TOC page -> a convenience, let's us define a logo as attachment
- $special_pages[] = $this->_create_toc_page();
-
- // store the array of page IDs that were created
- $this->option_set( 'cp_special_pages', $special_pages );
-
- }
-
- }
-
- // save new CommentPress Core options
- $this->options_save();
-
- // store new CommentPress Core version
- $this->option_wp_set( 'commentpress_version', COMMENTPRESS_VERSION );
-
- }
-
-
- // --<
- return $result;
- }
-
-
-
-
-
- /**
- * @description: reset Wordpress to prior state, but retain options
- * @todo:
- *
- */
- function deactivate() {
-
- // reset comment paging option
- $this->_reset_comment_paging();
-
- // restore widgets
- $this->_reset_widgets();
-
- // always remove special pages
- $this->delete_special_pages();
-
- }
- //##############################################################################
- /*
- ============================================================================
- PUBLIC METHODS
- ============================================================================
- */
-
- /**
- * @description: update Wordpress database schema
- * @return boolean $result
- * @todo:
- *
- */
- function schema_update() {
-
- // database object
- global $wpdb;
-
- // include Wordpress upgrade script
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
-
- // add the column, if not already there
- $result = maybe_add_column(
-
- $wpdb->comments,
- 'comment_signature',
- "ALTER TABLE `$wpdb->comments` ADD `comment_signature` VARCHAR(255) NULL;"
-
- );
-
- // --<
- return $result;
- }
-
-
-
-
-
- /**
- * @description: upgrade Wordpress database schema
- * @return boolean $result
- * @todo:
- *
- */
- function schema_upgrade() {
-
- // database object
- global $wpdb;
-
- // init
- $return = false;
-
- // construct query
- $query = "ALTER TABLE `$wpdb->comments` CHANGE `comment_text_signature` `comment_signature` VARCHAR(255) NULL;";
-
- // do the query to rename the column
- $wpdb->query( $query );
-
- // test if we now have the correct column name...
- if ( $this->db_is_modified( 'comment_signature' ) ) {
-
- // yes
- $result = true;
-
- }
-
- // --<
- return $result;
- }
-
-
-
-
-
- /**
- * @description: do we have a column in the comments table?
- * @return boolean $result
- * @todo:
- *
- */
- function db_is_modified( $column_name ) {
-
- // database object
- global $wpdb;
-
- // init
- $result = false;
-
-
-
- // define query
- $query = "DESCRIBE $wpdb->comments";
-
- // get columns
- $cols = $wpdb->get_results( $query );
-
- // loop
- foreach( $cols AS $col ) {
-
- // is it our desired column?
- if ( $col->Field == $column_name ) {
-
- // we got it
- $result = true;
- break;
-
- }
-
- }
-
- // --<
- return $result;
- }
-
-
-
-
-
- /**
- * @description: check for plugin upgrade
- * @return boolean $result
- * @todo:
- *
- */
- function check_upgrade() {
-
- // init
- $result = false;
-
- // get installed version cast as string
- $_version = (string) $this->option_wp_get( 'commentpress_version' );
-
- // if we have a commentpress install and it's lower than this one
- if ( $_version !== false AND version_compare( COMMENTPRESS_VERSION, $_version, '>' ) ) {
-
- // override
- $result = true;
- }
-
- // --<
- return $result;
- }
-
-
-
-
-
- /**
- * @description: save the settings set by the administrator
- * @return boolean success or failure
- * @todo: do more error checking?
- *
- */
- function options_update() {
-
- // database object
- global $wpdb;
-
-
-
- // init result
- $result = false;
-
- // was the form submitted?
- if( isset( $_POST[ 'commentpress_submit' ] ) ) {
-
- // check that we trust the source of the data
- check_admin_referer( 'commentpress_admin_action', 'commentpress_nonce' );
-
-
-
- // init vars
- $cp_activate = '0';
- $cp_upgrade = '';
- $cp_reset = '';
- $cp_create_pages = '';
- $cp_delete_pages = '';
- $cp_para_comments_live = 0;
- $cp_show_subpages = 0;
- $cp_show_extended_toc = 0;
- $cp_blog_type = 0;
- $cp_blog_workflow = 0;
- $cp_sidebar_default = 'comments';
-
-
-
- // get variables
- extract( $_POST );
-
-
-
- // hand off to Multisite first, in case we're deactivating
- do_action( 'cpmu_deactivate_commentpress' );
-
- // is Multisite activating CommentPress Core?
- if ( $cp_activate == '1' ) { return true; }
-
-
-
- // did we ask to upgrade CommentPress Core?
- if ( $cp_upgrade == '1' ) {
-
- // do upgrade
- $this->upgrade();
-
- // --<
- return true;
-
- }
-
-
-
- // did we ask to reset?
- if ( $cp_reset == '1' ) {
-
- // reset theme options
- $this->_options_reset();
-
- // --<
- return true;
-
- }
-
- // did we ask to auto-create special pages?
- if ( $cp_create_pages == '1' ) {
-
- // remove any existing special pages
- $this->delete_special_pages();
-
- // create special pages
- $this->create_special_pages();
-
- }
-
-
-
- // did we ask to delete special pages?
- if ( $cp_delete_pages == '1' ) {
-
- // remove special pages
- $this->delete_special_pages();
- }
-
-
-
- // let's deal with our params now
- // individual special pages
- //$cp_welcome_page = $wpdb->escape( $cp_welcome_page );
- //$cp_blog_page = $wpdb->escape( $cp_blog_page );
- //$cp_general_comments_page = $wpdb->escape( $cp_general_comments_page );
- //$cp_all_comments_page = $wpdb->escape( $cp_all_comments_page );
- //$cp_comments_by_page = $wpdb->escape( $cp_comments_by_page );
- //$this->option_set( 'cp_welcome_page', $cp_welcome_page );
- //$this->option_set( 'cp_blog_page', $cp_blog_page );
- //$this->option_set( 'cp_general_comments_page', $cp_general_comments_page );
- //$this->option_set( 'cp_all_comments_page', $cp_all_comments_page );
- //$this->option_set( 'cp_comments_by_page', $cp_comments_by_page );
-
- // TOC content
- $cp_show_posts_or_pages_in_toc = $wpdb->escape( $cp_show_posts_or_pages_in_toc );
- $this->option_set( 'cp_show_posts_or_pages_in_toc', $cp_show_posts_or_pages_in_toc );
-
- // if we have pages in TOC and a value for the next param...
- if ( $cp_show_posts_or_pages_in_toc == 'page' AND isset( $cp_toc_chapter_is_page ) ) {
-
- $cp_toc_chapter_is_page = $wpdb->escape( $cp_toc_chapter_is_page );
- $this->option_set( 'cp_toc_chapter_is_page', $cp_toc_chapter_is_page );
-
- // if chapters are not pages and we have a value for the next param...
- if ( $cp_toc_chapter_is_page == '0' ) {
-
- $cp_show_subpages = $wpdb->escape( $cp_show_subpages );
- $this->option_set( 'cp_show_subpages', ( $cp_show_subpages ? 1 : 0 ) );
- } else {
-
- // always set to show subpages
- $this->option_set( 'cp_show_subpages', 1 );
-
- }
- }
-
- // extended or vanilla posts TOC
- if ( $cp_show_posts_or_pages_in_toc == 'post' ) {
-
- $cp_show_extended_toc = $wpdb->escape( $cp_show_extended_toc );
- $this->option_set( 'cp_show_extended_toc', ( $cp_show_extended_toc ? 1 : 0 ) );
- }
- // excerpt length
- $this->option_set( 'cp_excerpt_length', $cp_excerpt_length );
- $cp_excerpt_length = $wpdb->escape( $cp_excerpt_length );
-
- // comment editor
- $cp_comment_editor = $wpdb->escape( $cp_comment_editor );
- $this->option_set( 'cp_comment_editor', ( $cp_comment_editor ? 1 : 0 ) );
-
- // has AJAX "live" comment refreshing been migrated?
- if ( $this->option_exists( 'cp_para_comments_live' ) ) {
-
- // "live" comment refreshing
- $cp_para_comments_live = $wpdb->escape( $cp_para_comments_live );
- $this->option_set( 'cp_para_comments_live', ( $cp_para_comments_live ? 1 : 0 ) );
-
- }
-
- // behaviour
- $cp_promote_reading = $wpdb->escape( $cp_promote_reading );
- $this->option_set( 'cp_promote_reading', ( $cp_promote_reading ? 1 : 0 ) );
-
- // title visibility
- $cp_title_visibility = $wpdb->escape( $cp_title_visibility );
- $this->option_set( 'cp_title_visibility', $cp_title_visibility );
-
- // page meta visibility
- $cp_page_meta_visibility = $wpdb->escape( $cp_page_meta_visibility );
- $this->option_set( 'cp_page_meta_visibility', $cp_page_meta_visibility );
-
- // header background colour
-
- // strip our rgb #
- if ( stristr( $cp_header_bg_colour, '#' ) ) {
- $cp_header_bg_colour = substr( $cp_header_bg_colour, 1 );
- }
-
- // reset to default if blank
- if ( $cp_header_bg_colour == '' ) {
- $cp_header_bg_colour = $this->header_bg_colour;
- }
-
- // save it
- $cp_header_bg_colour = $wpdb->escape( $cp_header_bg_colour );
- $this->option_set( 'cp_header_bg_colour', $cp_header_bg_colour );
-
- // save scroll speed
- $cp_js_scroll_speed = $wpdb->escape( $cp_js_scroll_speed );
- $this->option_set( 'cp_js_scroll_speed', $cp_js_scroll_speed );
-
- // save min page width
- $cp_min_page_width = $wpdb->escape( $cp_min_page_width );
- $this->option_set( 'cp_min_page_width', $cp_min_page_width );
-
- // save workflow
- $cp_blog_workflow = $wpdb->escape( $cp_blog_workflow );
- $this->option_set( 'cp_blog_workflow', ( $cp_blog_workflow ? 1 : 0 ) );
- // save blog type
- $cp_blog_type = $wpdb->escape( $cp_blog_type );
- $this->option_set( 'cp_blog_type', $cp_blog_type );
-
- // if it's a groupblog
- if ( $this->parent_obj->is_groupblog() ) {
-
- // get the group's id
- $group_id = get_groupblog_group_id( get_current_blog_id() );
- if ( is_numeric( $group_id ) ) {
-
- // allow plugins to override the blog type - for example if workflow is enabled,
- // it might become a new blog type as far as buddypress is concerned
- $_blog_type = apply_filters( 'cp_get_group_meta_for_blog_type', $cp_blog_type, $cp_blog_workflow );
-
- // set the type as group meta info
- groups_update_groupmeta( $group_id, 'groupblogtype', 'groupblogtype-'.$_blog_type );
-
- }
-
- }
- // save default sidebar
- $cp_sidebar_default = $wpdb->escape( $cp_sidebar_default );
- $this->option_set( 'cp_sidebar_default', $cp_sidebar_default );
-
- // save
- $this->options_save();
-
-
- // set flag
- $result = true;
-
- }
-
-
-
- // --<
- return $result;
-
- }
-
-
-
-
-
-
-
- /**
- * @description: upgrade CommentPress Core options to array
- * @todo:
- *
- */
- function options_save() {
-
- // set option
- return $this->option_wp_set( 'commentpress_options', $this->commentpress_options );
-
- }
-
-
-
-
-
- /**
- * @description: return a value for a specified option
- * @todo:
- */
- function option_exists( $option_name = '' ) {
-
- // test for null
- if ( $option_name == '' ) {
-
- // oops
- die( __( 'You must supply an option to option_exists()', 'commentpress-core' ) );
-
- }
-
- // get option with unlikely default
- return array_key_exists( $option_name, $this->commentpress_options );
-
- }
-
-
-
-
-
-
- /**
- * @description: return a value for a specified option
- * @todo:
- */
- function option_get( $option_name = '', $default = false ) {
-
- // test for null
- if ( $option_name == '' ) {
-
- // oops
- die( __( 'You must supply an option to option_get()', 'commentpress-core' ) );
-
- }
-
- // get option
- return ( array_key_exists( $option_name, $this->commentpress_options ) ) ? $this->commentpress_options[ $option_name ] : $default;
-
- }
-
-
-
-
-
-
- /**
- * @description: sets a value for a specified option
- * @todo:
- */
- function option_set( $option_name = '', $value = '' ) {
-
- // test for null
- if ( $option_name == '' ) {
-
- // oops
- die( __( 'You must supply an option to option_set()', 'commentpress-core' ) );
-
- }
-
- // test for other than string
- if ( !is_string( $option_name ) ) {
-
- // oops
- die( __( 'You must supply the option as a string to option_set()', 'commentpress-core' ) );
-
- }
-
- // set option
- $this->commentpress_options[ $option_name ] = $value;
-
- }
-
-
-
-
-
-
- /**
- * @description: deletes a specified option
- * @todo:
- */
- function option_delete( $option_name = '' ) {
-
- // test for null
- if ( $option_name == '' ) {
-
- // oops
- die( __( 'You must supply an option to option_delete()', 'commentpress-core' ) );
-
- }
-
- // unset option
- unset( $this->commentpress_options[ $option_name ] );
-
- }
-
-
-
-
-
-
- /**
- * @description: return a value for a specified option
- * @todo:
- */
- function option_wp_exists( $option_name = '' ) {
-
- // test for null
- if ( $option_name == '' ) {
-
- // oops
- die( __( 'You must supply an option to option_wp_exists()', 'commentpress-core' ) );
-
- }
-
- // get option with unlikely default
- if ( $this->option_wp_get( $option_name, 'fenfgehgejgrkj' ) == 'fenfgehgejgrkj' ) {
-
- // no
- return false;
-
- } else {
-
- // yes
- return true;
-
- }
-
- }
-
-
-
-
-
-
- /**
- * @description: return a value for a specified option
- * @todo:
- */
- function option_wp_get( $option_name = '', $default = false ) {
-
- // test for null
- if ( $option_name == '' ) {
-
- // oops
- die( __( 'You must supply an option to option_wp_get()', 'commentpress-core' ) );
-
- }
-
- // get option
- return get_option( $option_name, $default );
-
- }
-
-
-
-
-
-
- /**
- * @description: sets a value for a specified option
- * @todo:
- */
- function option_wp_set( $option_name = '', $value = null ) {
-
- // test for null
- if ( $option_name == '' ) {
-
- // oops
- die( __( 'You must supply an option to option_wp_set()', 'commentpress-core' ) );
-
- }
-
- // set option
- return update_option( $option_name, $value );
-
- }
-
-
-
-
-
-
- /**
- * @description: get default header bg colour
- * @todo:
- */
- function option_get_header_bg() {
-
- // test for option
- if ( $this->option_exists( 'cp_header_bg_colour' ) ) {
-
- // --<
- return $this->option_get( 'cp_header_bg_colour' );
-
- } else {
-
- // --<
- return $this->header_bg_colour;
-
- }
-
- }
-
-
-
-
-
-
- /**
- * @description: when a page is saved, this also saves the CP options
- * @param object $post_obj the post object
- * @return boolean $result
- * @todo:
- *
- */
- function save_meta( $post_obj ) {
-
- // if no post, kick out
- if ( !$post_obj ) { return; }
-
- // if page...
- if ( $post_obj->post_type == 'page' ) {
-
- $this->save_page_meta( $post_obj );
-
- }
-
- // if post...
- if ( $post_obj->post_type == 'post' ) {
-
- $this->save_post_meta( $post_obj );
-
- }
-
- }
-
-
-
-
-
-
-
- /**
- * @description: when a page is saved, this also saves the CP options
- * @param object $post_obj the post object
- * @return boolean $result
- * @todo:
- *
- */
- function save_page_meta( $post_obj ) {
-
- //print_r( 'data: '.$_data ); die();
- //print_r( '$post_obj->post_type: '.$post_obj->post_type ); die();
- //print_r( '$post_obj->ID: '.$post_obj->ID ); die();
-
- // if no post, kick out
- if ( !$post_obj ) { return; }
-
- // if not page, kick out
- if ( $post_obj->post_type != 'page' ) { return; }
-
-
-
- // authenticate
- $_nonce = isset( $_POST['commentpress_nonce'] ) ? $_POST['commentpress_nonce'] : '';
- if ( !wp_verify_nonce( $_nonce, 'commentpress_page_settings' ) ) { return; }
-
- // is this an auto save routine?
- if ( defined('DOING_AUTOSAVE') AND DOING_AUTOSAVE ) { return; }
-
- // check permissions - 'edit_pages' is available to editor+
- if ( !current_user_can( 'edit_pages' ) ) { return; }
-
-
- // OK, we're authenticated
-
-
-
- // check for revision
- if ( $post_obj->post_type == 'revision' ) {
-
- // get parent
- if ( $post_obj->post_parent != 0 ) {
- $post = get_post( $post_obj->post_parent );
- } else {
- $post = $post_obj;
- }
-
- } else {
- $post = $post_obj;
- }
-
- // database object and post
- global $wpdb;
-
- // ---------------------------------------------------------------------
- // Show or Hide Page Meta
- // ---------------------------------------------------------------------
-
- // find and save the data
- $_data = ( isset( $_POST['cp_page_meta_visibility'] ) ) ? $_POST['cp_page_meta_visibility'] : 'hide';
- //print_r( '$_data: '.$_data ); die();
- //print_r( $post ); die();
- // set key
- $key = '_cp_page_meta_visibility';
-
- // if the custom field already has a value...
- if ( get_post_meta( $post->ID, $key, true ) !== '' ) {
-
- // if empty string...
- if ( $_data === '' ) {
-
- // delete the meta_key
- delete_post_meta( $post->ID, $key );
-
- } else {
-
- // update the data
- update_post_meta( $post->ID, $key, $wpdb->escape( $_data ) );
-
- }
-
- } else {
-
- // add the data
- add_post_meta( $post->ID, $key, $wpdb->escape( $_data ) );
-
- }
- // ---------------------------------------------------------------------
- // Show or Hide Page Title
- // ---------------------------------------------------------------------
-
- // find and save the data
- $_data = ( isset( $_POST['cp_title_visibility'] ) ) ? $_POST['cp_title_visibility'] : 'show';
- //print_r( '$_data: '.$_data ); die();
- //print_r( $post ); die();
- // set key
- $key = '_cp_title_visibility';
-
- // if the custom field already has a value...
- if ( get_post_meta( $post->ID, $key, true ) !== '' ) {
-
- // if empty string...
- if ( $_data === '' ) {
-
- // delete the meta_key
- delete_post_meta( $post->ID, $key );
-
- } else {
-
- // update the data
- update_post_meta( $post->ID, $key, $wpdb->escape( $_data ) );
-
- }
-
- } else {
-
- // add the data
- add_post_meta( $post->ID, $key, $wpdb->escape( $_data ) );
-
- }
- // ---------------------------------------------------------------------
- // Page Numbering - only first top level page is allowed to send this
- // ---------------------------------------------------------------------
-
- // was the value sent?
- if ( isset( $_POST['cp_number_format'] ) ) {
-
- // set meta key
- $key = '_cp_number_format';
-
- if (
-
- // do we need to check this, since only the first top level page
- // can now send this data? doesn't hurt to validate, I guess.
- $post->post_parent == '0' AND
- !$this->is_special_page() AND
- $post->ID == $this->parent_obj->nav->get_first_page()
-
- ) { // -->
-
- // get the data
- $_data = $_POST['cp_number_format'];
-
- //print_r( $post->ID ); die();
-
- // if the custom field already has a value...
- if ( get_post_meta( $post->ID, $key, true ) !== '' ) {
-
- // if empty string...
- if ( $_data === '' ) {
-
- // delete the meta_key
- delete_post_meta( $post->ID, $key );
-
- } else {
-
- // update the data
- update_post_meta( $post->ID, $key, $wpdb->escape( $_data ) );
-
- }
-
- } else {
-
- // add the data
- add_post_meta( $post->ID, $key, $wpdb->escape( $_data ) );
-
- }
- }
-
- // delete this meta value from all other pages, because we may have altered
- // the relationship between pages, thus causing the page numbering to fail
-
- // get all pages including chapters
- $all_pages = $this->parent_obj->nav->get_book_pages( 'structural' );
-
- // if we have any pages...
- if ( count( $all_pages ) > 0 ) {
-
- // loop
- foreach( $all_pages AS $_page ) {
-
- // exclude first top level page
- if ( $post->ID != $_page->ID ) {
-
- // delete the meta value
- delete_post_meta( $_page->ID, $key );
-
- }
-
- }
-
- }
-
- }
-
-
-
- // ---------------------------------------------------------------------
- // Page Layout for Title Page -> to allow for Book Cover image
- // ---------------------------------------------------------------------
-
- // is this the title page?
- if ( $post->ID == $this->option_get( 'cp_welcome_page' ) ) {
-
- // find and save the data
- $_data = ( isset( $_POST['cp_page_layout'] ) ) ? $_POST['cp_page_layout'] : 'text';
-
- // set key
- $key = '_cp_page_layout';
-
- // if the custom field already has a value...
- if ( get_post_meta( $post->ID, $key, true ) !== '' ) {
-
- // if empty string...
- if ( $_data === '' ) {
-
- // delete the meta_key
- delete_post_meta( $post->ID, $key );
-
- } else {
-
- // update the data
- update_post_meta( $post->ID, $key, $wpdb->escape( $_data ) );
-
- }
-
- } else {
-
- // add the data
- add_post_meta( $post->ID, $key, $wpdb->escape( $_data ) );
-
- }
-
- }
- // ---------------------------------------------------------------------
- // Override post formatter (override blog_type)
- // ---------------------------------------------------------------------
-
- // get the data
- $_data = ( isset( $_POST['cp_post_type_override'] ) ) ? $_POST['cp_post_type_override'] : '';
- //print_r( '$_data: '.$_data ); die();
- //print_r( $post ); die();
- // set key
- $key = '_cp_post_type_override';
-
- // if the custom field already has a value...
- if ( get_post_meta( $post->ID, $key, true ) !== '' ) {
-
- // if empty string...
- if ( $_data === '' ) {
-
- // delete the meta_key
- delete_post_meta( $post->ID, $key );
-
- } else {
-
- // update the data
- update_post_meta( $post->ID, $key, $wpdb->escape( $_data ) );
-
- }
-
- } else {
-
- // add the data
- add_post_meta( $post->ID, $key, $wpdb->escape( $_data ) );
-
- }
- // ---------------------------------------------------------------------
- // Default Sidebar
- // ---------------------------------------------------------------------
-
- // do we have the option to choose the default sidebar (new in 3.3.3)?
- if ( $this->option_exists( 'cp_sidebar_default' ) ) {
-
- // find and save the data
- $_data = ( isset( $_POST['cp_sidebar_default'] ) ) ?
- $_POST['cp_sidebar_default'] :
- $this->db->option_get( 'cp_sidebar_default' );
-
- //print_r( '$_data: '.$_data ); die();
- //print_r( $post ); die();
-
- // set key
- $key = '_cp_sidebar_default';
-
- // if the custom field already has a value...
- if ( get_post_meta( $post->ID, $key, true ) !== '' ) {
-
- // if empty string...
- if ( $_data === '' ) {
-
- // delete the meta_key
- delete_post_meta( $post->ID, $key );
-
- } else {
-
- // update the data
- update_post_meta( $post->ID, $key, $wpdb->escape( $_data ) );
-
- }
-
- } else {
-
- // add the data
- add_post_meta( $post->ID, $key, $wpdb->escape( $_data ) );
-
- }
-
- }
- }
-
-
-
-
-
- /**
- * @description: when a post is saved, this also saves the CP options
- * @param object $post_obj the post object
- * @return boolean $result
- * @todo:
- *
- */
- function save_post_meta( $post_obj ) {
-
- //print_r( 'data: '.$_data ); die();
- //print_r( '$post_obj->post_type: '.$post_obj->post_type ); die();
- //print_r( '$post_obj->ID: '.$post_obj->ID ); die();
-
- // if no post, kick out
- if ( !$post_obj ) { return; }
-
- // if not page, kick out
- if ( $post_obj->post_type != 'post' ) { return; }
-
-
-
- // authenticate
- $_nonce = isset( $_POST['commentpress_nonce'] ) ? $_POST['commentpress_nonce'] : '';
- if ( !wp_verify_nonce( $_nonce, 'commentpress_post_settings' ) ) { return; }
-
- // is this an auto save routine?
- if ( defined('DOING_AUTOSAVE') AND DOING_AUTOSAVE ) { return; }
-
- // check permissions - 'edit_posts' is available to contributor+
- if ( !current_user_can( 'edit_posts', $post_obj->ID ) ) { return; }
-
-
- // OK, we're authenticated
-
-
-
- // check for revision
- if ( $post_obj->post_type == 'revision' ) {
-
- // get parent
- if ( $post_obj->post_parent != 0 ) {
- $post = get_post( $post_obj->post_parent );
- } else {
- $post = $post_obj;
- }
-
- } else {
- $post = $post_obj;
- }
-
- // database object and post
- global $wpdb;
-
- // ---------------------------------------------------------------------
- // Override post formatter (override blog_type)
- // ---------------------------------------------------------------------
-
- // get the data
- $_formatter = ( isset( $_POST['cp_post_type_override'] ) ) ? $_POST['cp_post_type_override'] : '';
- //print_r( '$_data: '.$_data ); die();
- //print_r( $post ); die();
- // set key
- $key = '_cp_post_type_override';
-
- // if the custom field already has a value...
- if ( get_post_meta( $post->ID, $key, true ) !== '' ) {
-
- // if empty string...
- if ( $_formatter === '' ) {
-
- // delete the meta_key
- delete_post_meta( $post->ID, $key );
-
- } else {
-
- // update the data
- update_post_meta( $post->ID, $key, $wpdb->escape( $_formatter ) );
-
- }
-
- } else {
-
- // add the data
- add_post_meta( $post->ID, $key, $wpdb->escape( $_formatter ) );
-
- }
- // ---------------------------------------------------------------------
- // Workflow
- // ---------------------------------------------------------------------
-
- // do we have the option to set workflow (new in 3.3.1)?
- if ( $this->option_exists( 'cp_blog_workflow' ) ) {
-
- // get workflow setting for the blog
- $_workflow = $this->option_get( 'cp_blog_workflow' );
-
- /*
- // ----------------
- // WORK IN PROGRESS
-
- // set key
- $key = '_cp_blog_workflow_override';
-
- // if the custom field already has a value...
- if ( get_post_meta( $post->ID, $key, true ) !== '' ) {
-
- // get existing value
- $_workflow = get_post_meta( $post->ID, $key, true );
-
- }
- // ----------------
- */
-
- // if it's enabled for the blog or the post...
- if ( $_workflow == '1' ) {
-
- // notify plugins that workflow stuff needs saving
- do_action( 'cp_workflow_save_post', $post );
-
- }
-
- /*
- // ----------------
- // WORK IN PROGRESS
-
- // get the setting for the post (we do this after saving the extra
- // post data because
- $_formatter = ( isset( $_POST['cp_post_type_override'] ) ) ? $_POST['cp_post_type_override'] : '';
-
- // if the custom field already has a value...
- if ( get_post_meta( $post->ID, $key, true ) !== '' ) {
-
- // if empty string...
- if ( $_data === '' ) {
-
- // delete the meta_key
- delete_post_meta( $post->ID, $key );
-
- } else {
-
- // update the data
- update_post_meta( $post->ID, $key, $wpdb->escape( $_data ) );
-
- }
-
- } else {
-
- // add the data
- add_post_meta( $post->ID, $key, $wpdb->escape( $_data ) );
-
- }
- // ----------------
- */
-
- }
-
- // ---------------------------------------------------------------------
- // Default Sidebar
- // ---------------------------------------------------------------------
-
- // do we have the option to choose the default sidebar (new in 3.3.3)?
- if ( $this->option_exists( 'cp_sidebar_default' ) ) {
-
- // find and save the data
- $_data = ( isset( $_POST['cp_sidebar_default'] ) ) ?
- $_POST['cp_sidebar_default'] :
- $this->db->option_get( 'cp_sidebar_default' );
-
- //print_r( '$_data: '.$_data ); die();
- //print_r( $post ); die();
-
- // set key
- $key = '_cp_sidebar_default';
-
- // if the custom field already has a value...
- if ( get_post_meta( $post->ID, $key, true ) !== '' ) {
-
- // if empty string...
- if ( $_data === '' ) {
-
- // delete the meta_key
- delete_post_meta( $post->ID, $key );
-
- } else {
-
- // update the data
- update_post_meta( $post->ID, $key, $wpdb->escape( $_data ) );
-
- }
-
- } else {
-
- // add the data
- add_post_meta( $post->ID, $key, $wpdb->escape( $_data ) );
-
- }
-
- }
- // ---------------------------------------------------------------------
- // Create new post with content of current
- // ---------------------------------------------------------------------
-
- // find and save the data
- $_data = ( isset( $_POST['commentpress_new_post'] ) ) ? $_POST['commentpress_new_post'] : '0';
-
- /*
- print_r( array(
-
- '$_data' => $_data,
- '$post ' => $post
-
- ) ); die();
- */
-
- // do we want to create a new revision?
- if ( $_data == '0' ) { return; }
-
-
- // we need to make sure this only runs once
- //print_r( $this->saved_post === false ? 'f' : 't' ); die();
- if ( $this->saved_post === false ) {
- $this->saved_post = true;
- } else {
- return;
- }
-
- // ---------------------------------------------------------------------
- // we're through: create it
- $new_post_id = $this->_create_new_post( $post );
-
-
-
- // ---------------------------------------------------------------------
- // Store ID of new version in current version
- // ---------------------------------------------------------------------
-
- // set key
- $key = '_cp_newer_version';
-
- // if the custom field already has a value...
- if ( get_post_meta( $post->ID, $key, true ) !== '' ) {
-
- // if empty string...
- if ( $_data === '' ) {
-
- // delete the meta_key
- delete_post_meta( $post->ID, $key );
-
- } else {
-
- // update the data
- update_post_meta( $post->ID, $key, $new_post_id );
-
- }
-
- } else {
-
- // add the data
- add_post_meta( $post->ID, $key, $new_post_id );
-
- }
- // ---------------------------------------------------------------------
- // Store incremental version number in new version
- // ---------------------------------------------------------------------
-
- // set key
- $key = '_cp_version_count';
-
- // if the custom field of our current post has a value...
- if ( get_post_meta( $post->ID, $key, true ) !== '' ) {
-
- // get current value
- $value = get_post_meta( $post->ID, $key, true );
-
- // increment
- $value++;
-
- } else {
-
- // this must be the first new version (Draft 2)
- $value = 2;
-
- }
- // add the data
- add_post_meta( $new_post_id, $key, $value );
-
-
-
- // ---------------------------------------------------------------------
- // Store formatter in new version
- // ---------------------------------------------------------------------
-
- // set key
- $key = '_cp_post_type_override';
-
- // if we have one set...
- if ( $_formatter != '' ) {
-
- // add the data
- add_post_meta( $new_post_id, $key, $wpdb->escape( $_formatter ) );
-
- }
-
-
-
- // allow plugins to hook into this
- do_action( 'cp_workflow_save_copy', $new_post_id );
-
- // get the edit post link
- //$edit_link = get_edit_post_link( $new_post_id );
-
- // redirect there?
- }
-
-
-
-
-
- /**
- * @description: when a page is deleted, this makes sure that the CP options are synced
- * @param object $post_id the post ID
- * @return none
- * @todo:
- *
- */
- function delete_meta( $post_id ) {
-
- // if no post, kick out
- if ( !$post_id ) { return; }
-
-
-
- // if it's our welcome page...
- if ( $post_id == $this->option_get( 'cp_welcome_page' ) ) {
-
- // delete option
- $this->option_delete( 'cp_welcome_page' );
-
- // save
- $this->options_save();
-
- }
-
-
-
- // for posts with versions, we need to delete the version data for the previous version
-
- // define key
- $key = '_cp_newer_version';
-
- // get posts with the about-to-be-deleted post_id (there will be only one, if at all)
- $previous_versions = get_posts( array(
-
- 'meta_key' => $key,
- 'meta_value' => $post_id
-
- ) );
-
- // did we get one?
- if ( count( $previous_versions ) > 0 ) {
-
- // get it
- $previous_version = $previous_versions[0];
-
- // if the custom field has a value...
- if ( get_post_meta( $previous_version->ID, $key, true ) !== '' ) {
-
- // delete it
- delete_post_meta( $previous_version->ID, $key );
-
- }
-
- }
-
- }
-
-
-
-
-
-
-
- /**
- * @description: create all "special" pages
- * @todo:
- *
- */
- function create_special_pages() {
-
- // one of the CommentPress Core themes MUST be active...
- // or WordPress will fail to set the page templates for the pages that require them.
- // Also, a user must be logged in for these pages to be associated with them.
-
- // get special pages array, if it's there
- $special_pages = $this->option_get( 'cp_special_pages', array() );
-
- // create welcome/title page, but don't add to special pages
- $welcome = $this->_create_title_page();
-
- // create general comments page
- $special_pages[] = $this->_create_general_comments_page();
- // create all comments page
- $special_pages[] = $this->_create_all_comments_page();
-
- // create comments by author page
- $special_pages[] = $this->_create_comments_by_author_page();
- // create blog page
- $special_pages[] = $this->_create_blog_page();
-
- // create blog archive page
- $special_pages[] = $this->_create_blog_archive_page();
-
- // create TOC page -> a convenience, let's us define a logo as attachment
- $special_pages[] = $this->_create_toc_page();
- // store the array of page IDs that were created
- $this->option_set( 'cp_special_pages', $special_pages );
-
- // save changes
- $this->options_save();
- }
-
-
-
-
-
- /**
- * @description: create a particular "special" page
- * @todo:
- *
- */
- function create_special_page( $_page ) {
-
- // init
- $new_id = false;
-
-
-
- // get special pages array, if it's there
- $special_pages = $this->option_get( 'cp_special_pages', array() );
-
- // switch by page
- switch( $_page ) {
-
- case 'title':
-
- // create welcome/title page
- $new_id = $this->_create_title_page();
- break;
-
- case 'general_comments':
-
- // create general comments page
- $new_id = $this->_create_general_comments_page();
- break;
-
- case 'all_comments':
-
- // create all comments page
- $new_id = $this->_create_all_comments_page();
- break;
-
- case 'comments_by_author':
-
- // create comments by author page
- $new_id = $this->_create_comments_by_author_page();
- break;
-
- case 'blog':
-
- // create blog page
- $new_id = $this->_create_blog_page();
- break;
-
- case 'blog_archive':
-
- // create blog page
- $new_id = $this->_create_blog_archive_page();
- break;
-
- case 'toc':
-
- // create TOC page
- $new_id = $this->_create_toc_page();
- break;
-
- }
-
-
-
- // add to special pages
- $special_pages[] = $new_id;
- // reset option
- $this->option_set( 'cp_special_pages', $special_pages );
-
- // save changes
- $this->options_save();
-
- // --<
- return $new_id;
-
- }
-
-
-
-
-
- /**
- * @description: delete "special" pages
- * @return boolean $success
- * @todo:
- *
- */
- function delete_special_pages() {
-
- // init success flag
- $success = true;
-
- // only delete special pages if we have one of the CommentPress Core themes active
- // because other themes may have a totally different way of presenting the
- // content of the blog
- // retrieve data on special pages
- $special_pages = $this->option_get( 'cp_special_pages', array() );
-
- // if we have created any...
- if ( is_array( $special_pages ) AND count( $special_pages ) > 0 ) {
-
- // loop through them
- foreach( $special_pages AS $special_page ) {
-
- // bypass trash
- $force_delete = true;
-
- // try and delete each page...
- if ( !wp_delete_post( $special_page, $force_delete ) ) {
-
- // oops, set success flag to false
- $success = false;
-
- }
-
- }
-
- // delete the corresponding options
- $this->option_delete( 'cp_special_pages' );
- $this->option_delete( 'cp_blog_page' );
- $this->option_delete( 'cp_blog_archive_page' );
- $this->option_delete( 'cp_general_comments_page' );
- $this->option_delete( 'cp_all_comments_page' );
- $this->option_delete( 'cp_comments_by_page' );
- $this->option_delete( 'cp_toc_page' );
-
- // for now, keep welcome page - delete option when page is deleted
- //$this->option_delete( 'cp_welcome_page' );
-
- // save changes
- $this->options_save();
-
- // reset Wordpress internal page references
- $this->_reset_wordpress_option( 'show_on_front' );
- $this->_reset_wordpress_option( 'page_on_front' );
- $this->_reset_wordpress_option( 'page_for_posts' );
-
- }
-
- // --<
- return $success;
- }
-
-
-
-
-
- /**
- * @description: delete a particular "special" page
- * @return boolean $success
- * @todo:
- *
- */
- function delete_special_page( $_page ) {
-
- // init success flag
- $success = true;
-
- // only delete a special page if we have one of the CommentPress Core themes active
- // because other themes may have a totally different way of presenting the
- // content of the blog
-
- // get id of special page
- switch( $_page ) {
-
- case 'title':
-
- // set flag
- $flag = 'cp_welcome_page';
- // reset Wordpress internal page references
- $this->_reset_wordpress_option( 'show_on_front' );
- $this->_reset_wordpress_option( 'page_on_front' );
-
- break;
-
- case 'general_comments':
-
- // set flag
- $flag = 'cp_general_comments_page';
- break;
-
- case 'all_comments':
-
- // set flag
- $flag = 'cp_all_comments_page';
- break;
-
- case 'comments_by_author':
-
- // set flag
- $flag = 'cp_comments_by_page';
- break;
-
- case 'blog':
-
- // set flag
- $flag = 'cp_blog_page';
- // reset Wordpress internal page reference
- $this->_reset_wordpress_option( 'page_for_posts' );
-
- break;
-
- case 'blog_archive':
-
- // set flag
- $flag = 'cp_blog_archive_page';
- break;
-
- case 'toc':
-
- // set flag
- $flag = 'cp_toc_page';
- break;
-
- }
-
- // get page id
- $page_id = $this->option_get( $flag );
-
- // kick out if it doesn't exist
- if ( !$page_id ) { return true; }
- // delete option
- $this->option_delete( $flag );
- // bypass trash
- $force_delete = true;
-
- // try and delete the page...
- if ( !wp_delete_post( $page_id, $force_delete ) ) {
-
- // oops, set success flag to false
- $success = false;
-
- }
-
- // retrieve data on special pages
- $special_pages = $this->option_get( 'cp_special_pages', array() );
-
- // is it in our special pages array?
- if ( in_array( $page_id, $special_pages ) ) {
-
- // remove page id from array
- $special_pages = array_diff( $special_pages, array( $page_id ) );
- // reset option
- $this->option_set( 'cp_special_pages', $special_pages );
-
- }
-
- // save changes
- $this->options_save();
- // --<
- return $success;
- }
-
-
-
-
-
- /**
- * @description: test if a page is a "special" page
- * @return boolean $is_special_page
- * @todo:
- *
- */
- function is_special_page() {
-
- // init flag
- $is_special_page = false;
-
- // access post object
- global $post;
-
- // do we have one?
- if ( !is_object( $post ) ) {
-
- // --<
- return $is_special_page;
-
- }
-
- // get special pages
- $special_pages = $this->option_get( 'cp_special_pages', array() );
-
- // do we have a special page array?
- if ( is_array( $special_pages ) AND count( $special_pages ) > 0 ) {
-
- // is the current page one?
- if ( in_array( $post->ID, $special_pages ) ) {
-
- // it is…
Large files files are truncated, but you can click here to view the full file