strpos( $name, "display_settings_page_" ) === 0 ) return $this->display_settings_page( $this->substr( $name, 22 ) ); $error = __( sprintf( "Method %s doesn't exist", $name ), 'all_in_one_seo_pack' ); if ( class_exists( 'BadMethodCallException' ) ) throw new BadMethodCallException( $error ); throw new Exception( $error ); } function __construct() { if ( empty( $this->file ) ) $this->file = __FILE__; $this->plugin_name = AIOSEOP_PLUGIN_NAME; $this->plugin_path = Array(); // $this->plugin_path['dir'] = plugin_dir_path( $this->file ); $this->plugin_path['basename'] = plugin_basename( $this->file ); $this->plugin_path['dirname'] = dirname( $this->plugin_path['basename'] ); $this->plugin_path['url'] = plugin_dir_url( $this->file ); $this->plugin_path['images_url'] = $this->plugin_path['url'] . 'images'; $this->script_data['plugin_path'] = $this->plugin_path; } /** * Get options for module, stored individually or together. */ function get_class_option( ) { $option_name = $this->get_option_name(); if ( $this->store_option || $option_name == $this->parent_option ) { return get_option( $option_name ); } else { $option = get_option( $this->parent_option ); if ( isset( $option['modules'] ) && isset( $option['modules'][$option_name] ) ) return $option['modules'][$option_name]; } return false; } /** * Update options for module, stored individually or together. */ function update_class_option( $option_data, $option_name = false ) { if ( $option_name == false ) $option_name = $this->get_option_name(); if ( $this->store_option || $option_name == $this->parent_option ) { return update_option( $option_name, $option_data ); } else { $option = get_option( $this->parent_option ); if ( !isset( $option['modules'] ) ) $option['modules'] = Array(); $option['modules'][$option_name] = $option_data; return update_option( $this->parent_option, $option ); } } /** * Delete options for module, stored individually or together. */ function delete_class_option( $delete = false ) { $option_name = $this->get_option_name(); if ( $this->store_option || $delete ) { delete_option( $option_name ); } else { $option = get_option( $this->parent_option ); if ( isset( $option['modules'] ) && isset( $option['modules'][$option_name] ) ) { unset( $option['modules'][$option_name] ); return update_option( $this->parent_option, $option ); } } return false; } /** * Get the option name with prefix. */ function get_option_name() { if ( !isset( $this->option_name ) || empty( $this->option_name ) ) $this->option_name = $this->prefix . 'options'; return $this->option_name; } /** * Convenience function to see if an option is set. */ function option_isset( $option, $location = null ) { $prefix = $this->get_prefix( $location ); $opt = $prefix . $option; return ( ( isset( $this->options[$opt] ) ) && $this->options[$opt] ); } /*** Case conversion; handle non UTF-8 encodings and fallback ***/ function convert_case( $str, $mode = 'upper' ) { static $charset = null; if ( $charset == null ) $charset = get_bloginfo( 'charset' ); if ( $mode == 'title' ) { if ( function_exists( 'mb_convert_case' ) ) return mb_convert_case( $str, MB_CASE_TITLE, $charset ); else return ucwords( $str ); } if ( $charset == 'UTF-8' ) { global $UTF8_TABLES; include_once( 'aioseop_utility.php' ); if ( is_array( $UTF8_TABLES ) ) { if ( $mode == 'upper' ) return strtr( $str, $UTF8_TABLES['strtoupper'] ); if ( $mode == 'lower' ) return strtr( $str, $UTF8_TABLES['strtolower'] ); } } if ( $mode == 'upper' ) { if ( function_exists( 'mb_strtoupper' ) ) return mb_strtoupper( $str, $charset ); else return strtoupper( $str ); } if ( $mode == 'lower' ) { if ( function_exists( 'mb_strtolower' ) ) return mb_strtolower( $str, $charset ); else return strtolower( $str ); } return $str; } /** * Convert a string to lower case * Compatible with mb_strtolower(), an UTF-8 friendly replacement for strtolower() */ function strtolower( $str ) { return $this->convert_case( $str, 'lower' ); } /** * Convert a string to upper case * Compatible with mb_strtoupper(), an UTF-8 friendly replacement for strtoupper() */ function strtoupper( $str ) { return $this->convert_case( $str, 'upper' ); } /** * Convert a string to title case * Compatible with mb_convert_case(), an UTF-8 friendly replacement for ucwords() */ function ucwords( $str ) { return $this->convert_case( $str, 'title' ); } /** * Wrapper for strlen() - uses mb_strlen() if possible. */ function strlen( $string ) { if ( function_exists( 'mb_strlen' ) ) return mb_strlen( $string ); return strlen( $string ); } /** * Wrapper for substr() - uses mb_substr() if possible. */ function substr( $string, $start = 0, $length = 2147483647 ) { $args = func_get_args(); if ( function_exists( 'mb_substr' ) ) return call_user_func_array( 'mb_substr', $args ); return call_user_func_array( 'substr', $args ); } /** * Wrapper for strpos() - uses mb_strpos() if possible. */ function strpos( $haystack, $needle, $offset = 0 ) { if ( function_exists( 'mb_strpos' ) ) return mb_strpos( $haystack, $needle, $offset ); return strpos( $haystack, $needle, $offset ); } /** * Wrapper for strrpos() - uses mb_strrpos() if possible. */ function strrpos( $haystack, $needle, $offset = 0 ) { if ( function_exists( 'mb_strrpos' ) ) return mb_strrpos( $haystack, $needle, $offset ); return strrpos( $haystack, $needle, $offset ); } /** * convert xml string to php array - useful to get a serializable value * * @param string $xmlstr * @return array * * @author Adrien aka Gaarf & contributors * @see http://gaarf.info/2009/08/13/xml-string-to-php-array/ */ function html_string_to_array( $xmlstr ) { if ( !class_exists( 'DOMDocument' ) ) { return Array(); } else { $doc = new DOMDocument(); $doc->loadHTML( $xmlstr ); return $this->domnode_to_array( $doc->documentElement ); } } function xml_string_to_array( $xmlstr ) { if ( !class_exists( 'DOMDocument' ) ) { return Array(); } else { $doc = new DOMDocument(); $doc->loadXML( $xmlstr ); return $this->domnode_to_array( $doc->documentElement ); } } function domnode_to_array( $node ) { switch ( $node->nodeType ) { case XML_CDATA_SECTION_NODE: case XML_TEXT_NODE: return trim( $node->textContent ); break; case XML_ELEMENT_NODE: $output = array(); for ($i=0, $m=$node->childNodes->length; $i<$m; $i++) { $child = $node->childNodes->item($i); $v = $this->domnode_to_array($child); if(isset($child->tagName)) { $t = $child->tagName; if(!isset($output[$t])) $output[$t] = array(); if ( is_array($output) ) $output[$t][] = $v; } elseif($v || $v === '0') $output = (string) $v; } if($node->attributes->length && !is_array($output)) //Has attributes but isn't an array $output = array('@content'=>$output); //Change output into an array. if(is_array($output)) { if($node->attributes->length) { $a = array(); foreach($node->attributes as $attrName => $attrNode) $a[$attrName] = (string) $attrNode->value; $output['@attributes'] = $a; } foreach ($output as $t => $v) if(is_array($v) && count($v)==1 && $t!='@attributes') $output[$t] = $v[0]; } } if ( empty( $output ) ) return ''; return $output; } /*** adds support for using %cf_(name of field)% for using custom fields / Advanced Custom Fields in titles / descriptions etc. ***/ function apply_cf_fields( $format ) { return preg_replace_callback( '/%cf_([^%]*?)%/', Array( $this, 'cf_field_replace' ), $format ); } function cf_field_replace( $matches ) { $result = ''; if ( !empty( $matches ) ) { if ( !empty( $matches[1] ) ) { if ( function_exists( 'get_field' ) ) $result = get_field( $matches[1] ); if ( empty( $result ) ) { global $post; if ( !empty( $post ) ) $result = get_post_meta( $post->ID, $matches[1], true ); } if ( empty( $result ) ) $result = $matches[0]; } else $result = $matches[0]; } $result = strip_tags( $result ); return $result; } /** * Returns child blogs of parent in a multisite. */ function get_child_blogs() { global $wpdb, $blog_id; $site_id = $wpdb->siteid; if ( is_multisite() ) { if ( $site_id != $blog_id ) return false; return $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = {$blog_id} AND site_id != blog_id" ); } return false; } /** * Checks if the plugin is active on a given blog by blogid on a multisite. */ function is_aioseop_active_on_blog( $bid = false ) { global $blog_id; if ( empty( $bid ) || ( $bid == $blog_id ) || !is_multisite() ) return true; if ( ! function_exists( 'is_plugin_active_for_network' ) ) require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); if ( is_plugin_active_for_network( AIOSEOP_PLUGIN_BASENAME ) ) return true; return in_array( AIOSEOP_PLUGIN_BASENAME, (array) get_blog_option( $bid, 'active_plugins', array() ) ); } /** * Displays tabs for tabbed locations on a settings page. */ function display_tabs( $location ) { if ( ( $location != null ) && isset( $locations[$location]['tabs'] ) ) $tabs = $locations['location']['tabs']; else $tabs = $this->tabs; if ( !empty( $tabs ) ) { ?>
label ) ) $post_types[$p] = $post_objs[$p]->label; else $post_types[$p] = $p; return $post_types; } function get_term_labels( $post_objs ) { $post_types = Array(); foreach ( $post_objs as $p ) if ( !empty( $p->name ) ) $post_types[$p->term_id] = $p->name; return $post_types; } function get_post_type_titles( $args = Array() ) { return $this->get_object_labels( get_post_types( $args, 'objects' ) ); } function get_taxonomy_titles( $args = Array() ) { return $this->get_object_labels( get_taxonomies( $args, 'objects' ) ); } function get_category_titles( $args = Array() ) { return $this->get_term_labels( get_categories( $args ) ); } /** * Helper function for exporting settings on post data. */ function post_data_export( $prefix = '_aioseop', $query = Array( 'posts_per_page' => -1 ) ) { $buf = ''; $posts_query = new WP_Query( $query ); while ($posts_query->have_posts() ) { $posts_query->the_post(); global $post; $guid = $post->guid; $type = $post->post_type; $title = $post->post_title; $date = $post->post_date; $data = ''; $post_custom_fields = get_post_custom( $post->ID ); $has_data = null; if( is_array( $post_custom_fields ) ) { foreach( $post_custom_fields as $field_name => $field ){ if( ( $this->strpos( $field_name, $prefix ) === 0 ) && ( $field[0] ) ) { $has_data = true; $data .= $field_name . " = '" . $field[0] . "'\n"; } } } if ( !empty( $data ) ) $has_data = true; if( $has_data != null ){ $post_info = "\n[post_data]\n\n"; $post_info .= "post_title = '" . $title . "'\n"; $post_info .= "post_guid = '" . $guid . "'\n"; $post_info .= "post_date = '" . $date . "'\n"; $post_info .= "post_type = '" . $type . "'\n"; if ( $data ) $buf .= $post_info . $data . "\n"; } } wp_reset_postdata(); return $buf; } /** * Handles exporting settings data for a module. */ function settings_export( $buf ) { global $aiosp; $post_types = null; $has_data = null; $general_settings = null; $exporter_choices = ''; if ( !empty( $_REQUEST[ 'aiosp_importer_exporter_export_choices' ] ) ) $exporter_choices = $_REQUEST[ 'aiosp_importer_exporter_export_choices' ]; if ( !empty( $exporter_choices ) && is_array( $exporter_choices ) ) { foreach( $exporter_choices as $ex ) { if ( $ex == 1 ) $general_settings = true; if ( $ex == 2 ) { if ( isset( $_REQUEST[ 'aiosp_importer_exporter_export_post_types' ] ) ) $post_types = $_REQUEST[ 'aiosp_importer_exporter_export_post_types' ]; } } } if ( ( $post_types != null ) && ( $this === $aiosp ) ) $buf .= $this->post_data_export( '_aioseop', Array( 'posts_per_page' => -1, 'post_type' => $post_types ) ); /* Add all active settings to settings file */ $name = $this->get_option_name(); $options = $this->get_class_option(); if( !empty( $options ) && $general_settings != null ) { $buf .= "\n[$name]\n\n"; foreach ( $options as $key => $value ) { if ( ( $name == $this->parent_option ) && ( $key == 'modules' ) ) continue; // don't re-export all module settings -- pdb if ( is_array($value) ) $value = "'" . str_replace( Array( "'", "\n", "\r" ), Array( "\'", '\n', '\r' ), trim( serialize( $value ) ) ) . "'"; else $value = str_replace( Array( "\n", "\r" ), Array( '\n', '\r' ), trim( var_export($value, true) ) ); $buf .= "$key = $value\n"; } } return $buf; } /** * Order for adding the menus for the aioseop_modules_add_menus hook. */ function menu_order() { return 10; } /** * Print a basic error message. */ function output_error( $error ) { echo "$message