Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Core Class
- *
- * @package Wordpress
- * @subpackage Local Pages
- * @author DA
- * @version 1.06
- * @copyright smp
- */
- class SerpShakerCore {
- /**
- * Constructor.
- */
- function SerpShakerCore() {
- // Plugin Details
- @$this->plugin->name = 'serpshaker';
- @$this->plugin->displayName = 'SERP Shaker';
- @$this->plugin->url = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__));
- @$this->plugin->maxResultsPerAdminPage = 20;
- @$this->plugin->maxPostsToBuild = 3; // If a number is not defined, fallback to this
- @$this->counter = 0;
- // Settings
- $this->settings = get_option($this->plugin->name);
- // Register and load JS and CSS files
- if (is_admin()) {
- @wp_register_script($this->plugin->name.'admin-js', $this->plugin->url.'js/admin.js');
- @wp_enqueue_script($this->plugin->name.'admin-js');
- @wp_register_style($this->plugin->name.'-admin-css', $this->plugin->url.'css/admin.css');
- @wp_enqueue_style($this->plugin->name.'-admin-css');
- }
- // Hooks and filters if licensed
- $status = get_option( 'serp_shaker_license_status' );
- if( $status !== true && $status !== 'valid' ) {
- add_action('init', array(&$this, 'RegisterCustomPostTypes')); // MUST be here for rewrites to work
- if (is_admin()) {
- // Admin
- add_action('admin_notices', array(&$this, 'AdminNotices'));
- add_action('save_post', array(&$this, 'Save'));
- add_action('admin_menu', array(&$this, 'AddAdminPanels'), 99);
- add_action('admin_init', array(&$this, 'AddMetaBoxes'), 99);
- add_action('manage_posts_custom_column', array(&$this, 'ManageAdminColumns'), 10, 2);
- add_action('manage_pages_custom_column', array(&$this, 'ManageAdminColumns'), 10, 2);
- add_filter('manage_posts_columns', array(&$this, 'AddAdminColumns'));
- add_filter('manage_pages_columns', array(&$this, 'AddAdminColumns'));
- ss_preset_options();
- }
- add_action('admin_bar_menu', array(&$this, 'AddAdminBarMenu'), 95);
- add_action('admin_menu', array(&$this, 'AddAdminMenu'));
- add_action('init', array(&$this, 'setupTinyMCEPlugins'));
- // Define sub pages for Admin Menus and Admin Bar
- $this->subPages = array('Shortcodes');
- }
- else {
- // Just display link to licensing screen
- }
- }
- function setupTinyMCEPlugins() {
- if (!current_user_can('edit_posts') && !current_user_can('edit_pages')) return;
- if (get_user_option('rich_editing') == 'true') {
- add_filter('mce_external_plugins', array(&$this, 'addTinyMCEPlugin'));
- add_filter('mce_buttons', array(&$this, 'addTinyMCEButton'));
- }
- }
- function addTinyMCEButton($buttons) {
- array_push($buttons, "|", 'tinyShortCode', 'sslinknext', 'sslinkprev', 'ssweather', 'ssgoogle', 'ssyoutube', 'searchreplace', 'ssnextp', 'ssprevp', 'postsincat');
- return $buttons;
- }
- /**
- * Adds a plugin to the TinyMCE Editor for shortcode inserts
- */
- function addTinyMCEPlugin($plugin_array) {
- $plugin_array['tinyShortCode'] = $this->plugin->url.'js/tinymce-ssShort.js.php';
- $plugin_array['sslinkn'] = $this->plugin->url.'js/tinymce-linknext.js';
- $plugin_array['sslinkp'] = $this->plugin->url.'js/tinymce-linkprev.js';
- $plugin_array['ssweather'] = $this->plugin->url.'js/tinymce-weather.js';
- $plugin_array['ssgoogle'] = $this->plugin->url.'js/tinymce-google-map.js';
- $plugin_array['ssyoutube'] = $this->plugin->url.'js/tinymce-youtube1.js';
- $plugin_array['searchreplace'] = $this->plugin->url.'js/searchreplace/plugin.min.js';
- $plugin_array['ssnextp'] = $this->plugin->url.'js/tinymce-nexpage.js';
- $plugin_array['ssprevp'] = $this->plugin->url.'js/tinymce-prevpage.js';
- // $plugin_array['subpages'] = $this->plugin->url.'js/tinymce-subpages.js';
- $plugin_array['postsincat'] = $this->plugin->url.'js/tinymce-postsincat.js';
- return $plugin_array;
- }
- function AddAdminMenu() {
- // Add menu page for licensing
- }
- function serp_shaker_license_page() {
- $license = get_option( 'serp_shaker_license_key' );
- $status = get_option( 'serp_shaker_license_status' );
- ?>
- <div class="wrap">
- <h2><?php _e('Plugin License Options'); ?></h2>
- <p>Please enter your license key below and hit "Save Changes" and then "Activate License". Your plugin will not be eligible for auto upgrades until you've activated your license</p>
- <form method="post" action="options.php">
- <?php settings_fields('serp_shaker_license'); ?>
- <table class="form-table">
- <tbody>
- <tr valign="top">
- <th scope="row" valign="top">
- <?php _e('License Key'); ?>
- </th>
- <td>
- <input id="serp_shaker_license_key" name="serp_shaker_license_key" type="password" class="regular-text" value="<?php esc_attr_e( $license ); ?>" />
- <label class="description" for="serp_shaker_license_key"><?php _e('Enter your license key'); ?></label>
- </td>
- </tr>
- <?php if( false !== $license ) { ?>
- <tr valign="top">
- <th scope="row" valign="top">
- <?php _e('Activate License'); ?>
- </th>
- <td>
- <?php if( $status !== false && $status == 'valid' ) { ?>
- <span style="color:green;"><?php _e('Your license key has been activated'); ?></span>
- <?php wp_nonce_field( 'serp_shaker_nonce', 'serp_shaker_nonce' ); ?>
- <input type="submit" class="button-secondary" name="edd_license_deactivate" value="<?php _e('Deactivate License'); ?>"/>
- <?php } else {
- wp_nonce_field( 'serp_shaker_nonce', 'serp_shaker_nonce' ); ?>
- <input type="submit" class="button-secondary" name="edd_license_activate" value="<?php _e('Activate License'); ?>"/>
- <?php } ?>
- </td>
- </tr>
- <?php } ?>
- </tbody>
- </table>
- <?php submit_button(); ?>
- </form>
- <?php
- }
- /**
- * Activation Routine. Runs when the Administrator activates the plugin.
- *
- * Creates database tables (if they do not exist)
- */
- function Activate() {
- global $wpdb;
- // Create database tables
- $wpdb->query("CREATE TABLE IF NOT EXISTS ".$wpdb->prefix."ss_shortcodes (
- shortcodeID int(10) NOT NULL AUTO_INCREMENT,
- shortcode varchar(200) NOT NULL,
- shortcodeData longtext,
- PRIMARY KEY (`shortcodeID`),
- UNIQUE KEY (`shortcode`)
- )
- ENGINE=innoDB
- DEFAULT CHARSET=utf8
- AUTO_INCREMENT=1");
- $wpdb->query("CREATE TABLE IF NOT EXISTS ".$wpdb->prefix."ss_dynamicodes (
- shortcodeID int(10) NOT NULL AUTO_INCREMENT,
- shortcode varchar(200) NOT NULL,
- shortcodeData longtext,
- spinnable tinyint(1),
- PRIMARY KEY (`shortcodeID`),
- UNIQUE KEY (`shortcode`)
- )
- ENGINE=innoDB
- DEFAULT CHARSET=utf8
- AUTO_INCREMENT=1");
- $wpdb->query("CREATE TABLE IF NOT EXISTS ".$wpdb->prefix."ss_ads (
- adID int(10) NOT NULL AUTO_INCREMENT,
- adname varchar(200) NOT NULL,
- adData text,
- PRIMARY KEY (`adID`),
- UNIQUE KEY (`adname`)
- )
- ENGINE=innoDB
- DEFAULT CHARSET=utf8
- AUTO_INCREMENT=1");
- $wpdb->query("ALTER TABLE ".$wpdb->prefix."ss_dynamicodes MODIFY shortcodeData longtext");
- $wpdb->query("ALTER TABLE ".$wpdb->prefix."ss_shortcodes MODIFY shortcodeData longtext");
- }
- /**
- * Registers custom post types for Local Pages
- */
- function RegisterCustomPostTypes() {
- // Local Pages
- register_post_type('shaker-page', array(
- 'labels' => array(
- 'name' => _x('Shaker Pages', 'post type general name'),
- 'singular_name' => _x('Shaker Page', 'post type singular name'),
- 'add_new' => _x('Add New', 'shaker-page'),
- 'add_new_item' => __('Add New Shaker Page'),
- 'edit_item' => __('Edit Shaker Page'),
- 'new_item' => __('New Shaker Page'),
- 'view_item' => __('View Shaker Page'),
- 'search_items' => __('Search Shaker Page'),
- 'not_found' => __('No shaker pages found'),
- 'not_found_in_trash' => __('No shaker pages found in Trash'),
- 'parent_item_colon' => ''
- ),
- 'description' => 'Shaker Pages',
- 'public' => true,
- 'publicly_queryable' => true,
- 'exclude_from_search' => true,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'menu_position' => 20,
- 'menu_icon' => $this->plugin->url.'/images/icons/icon.png',
- 'capability_type' => 'post',
- 'hierarchical' => false,
- 'supports' => array('thumbnail', 'title', 'editor', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'post-formats', 'revisions'),//added revisions on 10-6. (test to see if it saves it)
- 'taxonomies' => array('post_tag'),
- 'has_archive' => false,
- 'show_in_nav_menus' => false
- ));
- }
- /**
- * If Local Pages is licensed, adds admin menus
- */
- function AddAdminPanels() {
- add_submenu_page("edit.php?post_type=shaker-page", "Shortcodes", "Shortcodes", "activate_plugins", $this->plugin->name."-shortcodes", array(&$this, "AdminPanel"));
- add_submenu_page("edit.php?post_type=shaker-page", "Dynamic Shortcodes", "Dynamic Shortcodes", "activate_plugins", $this->plugin->name. "-ss-shortcodes", "serp_shaker_shortcodes");
- add_submenu_page("edit.php?post_type=shaker-page", "Ad Manager", "Ad Manager", "activate_plugins", $this->plugin->name. "-ss-ads", "serp_shaker_ads");
- add_submenu_page("edit.php?post_type=shaker-page", "Shaker", "Shaker", "activate_plugins", $this->plugin->name. "-ss-shaker", "serp_shaker_shaker");
- // add_submenu_page("edit.php?post_type=shaker-page", "Plugin License", "Plugin License & Updates", "activate_plugins", $this->plugin->name. "-ss-license", "serp_shaker_license_page");
- // add_submenu_page("edit.php?post_type=shaker-page", "Shaker Interlink", "Shaker Interlink", "activate_plugins", $this->plugin->name. "-ss-silo", "serp_shaker_siloit");
- // add_submenu_page("edit.php?post_type=shaker-page", "FITYMI", "FITYMI", "activate_plugins", $this->plugin->name. "-ss-fakeit", "serp_shaker_fakeit");
- add_submenu_page('edit.php?post_type=shaker-page', 'Extract URLs', 'Extract URLs', 'activate_plugins', 'sscategorymapping_extract_urls', 'sscategorymapping_extract_urls');
- // add_submenu_page("edit.php?post_type=shaker-page", "Updates", "Updates", "activate_plugins", $this->plugin->name. "-ss-updates", "serp_shaker_updates");
- add_submenu_page("edit.php?post_type=shaker-page", "Add Ons", "Add Ons", "activate_plugins", $this->plugin->name. "-ss-addons", "serp_shaker_addons");
- add_submenu_page("edit.php?post_type=shaker-page", 'SS Spinners Add On', 'Spinner Settings', 'activate_plugins', DIRNAME(__FILE__) . '/ss-spinners.php');
- add_submenu_page("edit.php?post_type=shaker-page", 'Settings & Tools', 'Settings & Tools', 'activate_plugins', DIRNAME(__FILE__) . '/ss-tools.php');
- add_submenu_page("edit.php?post_type=shaker-page", 'Advanced SILO Setup', 'Advanced SILO Setup', 'activate_plugins', DIRNAME(__FILE__) . '/ss-advancedsilo.php');
- }
- /**
- * Adds meta boxes
- */
- function AddMetaBoxes() {
- global $wp_meta_boxes;
- // Add a meta box for Page/Post selection
- add_meta_box($this->plugin->name.'-output', 'Output', array(&$this, 'DisplayOutputFields'), 'shaker-page', 'side', 'high');
- // Registers all Page and Post meta boxes for Serp Shaker
- if (@is_array($wp_meta_boxes['page']) AND count($wp_meta_boxes['page']) > 0) {
- foreach ($wp_meta_boxes['page'] as $position=>$arr) {
- foreach ($arr as $importance=>$metaBox) {
- foreach ($metaBox as $pluginName=>$metaBoxAttributes) {
- add_meta_box($pluginName, $metaBoxAttributes['title'], $metaBoxAttributes['callback'], 'shaker-page', $position, $importance);
- }
- }
- }
- }
- if (@is_array($wp_meta_boxes['post']) AND count($wp_meta_boxes['post']) > 0) {
- foreach ($wp_meta_boxes['post'] as $position=>$arr) {
- foreach ($arr as $importance=>$metaBox) {
- foreach ($metaBox as $pluginName=>$metaBoxAttributes) {
- add_meta_box($pluginName, $metaBoxAttributes['title'], $metaBoxAttributes['callback'], 'shaker-page', $position, $importance);
- }
- }
- }
- }
- // Register Page Attributes box. We do this here rather than in the register_post_type function as that function
- // does not display the parent page or template dropdown options that we need.
- add_meta_box($this->plugin->name.'-attributes', 'Page Attributes', array(&$this, 'DisplayPageAttributesFields'), 'shaker-page', 'side', 'low');
- //MetaBox for spinner options
- add_meta_box($this->plugin->name.'-spinner', 'SS Spinner', array(&$this, 'SpinnerOptions'), 'shaker-page', 'side', 'core');
- add_meta_box( $this->plugin->name.'-title', 'Shaker Page SEO Settings', array(&$this, 'ss_title'),'shaker-page','normal','high');
- add_meta_box( $this->plugin->name.'-newcategory', 'Shaker Page Category Shortcode', array(&$this, 'ss_category'),'shaker-page','side','high');
- //add_meta_box( $this->plugin->name.'-page_parent', 'Set Page Parent', array(&$this, 'ss_page_parent'),'shaker-page','side','high');
- }
- /**
- * If Local Pages is NOT licensed, this function is called to add options panels where the
- * Local Pages Custom Post Type would otherwise appear, linking to the license screen.
- */
- /**
- * Outputs a message when editing a Local Page custom post type to notify the
- * user that this Local Page has already been marked as Generated and
- * therefore produced the necessary Pages / Posts.
- */
- function AdminNotices() {
- global $post;
- if (@$_GET['action'] == 'edit') {
- $this->meta = get_post_meta($post->ID, $this->plugin->name, true);
- $type = get_post_type($post->ID);
- if (@$this->meta['built'] && $type == 'shaker-page') {
- echo (' <div class="error"><p>Pages / Posts have been built based on this Shaker Page. Making further changes to this Shaker Page is unecessary. Should you
- wish to amend a specific Page or Post built based on this Shaker Page, please directly edit the Page or Post as necessary.</p></div>');
- return false;
- }
- }
- }
- /**
- * Adds menu entries to the Wordpress 3.1 Admin Bar linking to Administration Panels
- */
- function AddAdminBarMenu() {
- global $wp_admin_bar;
- $wp_admin_bar->add_menu(array('id' => $this->plugin->name, 'title' => $this->plugin->displayName, 'href' => get_admin_url('admin.php?page='.$this->plugin->name)));
- foreach ($this->subPages as $key=>$subPage) {
- $wp_admin_bar->add_menu(array('parent' => $this->plugin->name, 'id' => $this->plugin->name.'-'.strtolower($subPage), 'title' => $subPage, 'href' => get_admin_url('admin.php?page='.$this->plugin->name.'-'.strtolower($subPage))));
- }
- }
- /**
- * Adds columns to the Page and Post lists within Wordpress Administration
- *
- * @param array $defaults Default Columns
- * @return array New Columns
- */
- function AddAdminColumns($defaults) {
- $defaults['localPage'] = __('Shaker Page Generated');
- return $defaults;
- }
- /**
- * Manages the data to be displayed within a column on the Page and Post lists within Wordpress Administration
- *
- * @param string $columnName
- * @param int $ID Post ID
- */
- function ManageAdminColumns($columnName, $ID) {
- // Only run if on the lightbox column
- if ($columnName == 'localPage') {
- $meta = get_post_meta($ID, 'localPageID', true);
- echo (($meta > 0) ? 'Yes' : 'No');
- }
- }
- /**
- * Displays output fields for the meta box for Local Pages custom post
- */
- function DisplayOutputFields() {
- global $post;
- $this->meta = get_post_meta($post->ID, $this->plugin->name, true);
- // Start output
- echo (' <div class="'.$this->plugin->name.'-meta-box">
- <input type="hidden" name="'.$this->plugin->name.'_wpnonce" value="'.wp_create_nonce(plugin_basename(__FILE__)).'" />
- <p>
- <label for="'.$this->plugin->name.'[output]">'.__('Output Type', 'output').'</label>
- <select name="'.$this->plugin->name.'[output]" size="1" id="output">
- <option value="post"'.(@$this->meta['output'] == 'post' ? ' selected' : '').'>Posts</option>
- <option value="page"'.(@$this->meta['output'] == 'page' ? ' selected' : '').'>Pages</option>
- </select>
- </p>
- <p class="description">When <strong>Published</strong> is clicked below, this setting is used to define how the built
- Shaker Pages should be stored: either as Wordpress Pages or Wordpress Posts.</p>
- <p>
- <label for="'.@$this->plugin->name.'[output]">'.__('Number of Posts or Pages (Optional)', 'numberOfPosts').'</label>
- <input type="text" name="'.@$this->plugin->name.'[numberOfPosts]" value="'.@$this->meta['numberOfPosts'].'" />
- </p>
- <p class="description">The number of Pages / Posts to build from this Shaker Page. If blank it will determine the number of lines in the longest shortcode list</p>
- <p>
- <label for="'.@$this->plugin->name.'[randomdate]">'.__('Days in the Future or Past (Optional)', 'numberOfDays').'</label>
- <input type="text" name="'.@$this->plugin->name.'[numberOfDays]" value="'.@$this->meta['numberOfDays'].'" />
- </p>
- <p class="description">The max number of days to future date or back date the posts. Choose below wether to future date or back date. If left blank it will use current date. <a href="http://members.serpshaker.com/members-area/video-18-new-date-feature/" style="color: red" target="_blank">(Help Video)</a></p>
- <p>
- <input type="radio" checked="checked" value="current" name="'.@$this->plugin->name.'[futuredate]">
- <label>Current Date (default)</label>
- <br>
- <input type="radio" value="future" name="'.@$this->plugin->name.'[futuredate]">
- <label>Future Date (scheduled)</label>
- <br>
- <input type="radio" value="past" name="'.@$this->plugin->name.'[futuredate]">
- <label>Back Date (published)</label>
- <br>');
- // Output build button or message to say pages / posts already built
- if (@$this->meta['built']) {
- echo (' <p>
- <input name="unbuild" type="submit" class="button-primary" id="unbuild" value="Delete Built Pages / Posts" />
- </p>
- <p class="description">Click this button if you wish to delete all Pages and Posts built based on this Shaker Page.');
- } else {
- if (isset($_GET['post'])) {
- echo (' <p>
- <input name="build" type="submit" class="button-primary" id="build" value="Build Pages / Posts" />
- </p>
- <p class="description"><strong>Check you are happy with your content first.</strong> This button will build the Pages / Posts
- based on this Shaker Page. Once done, this cannot be done again for this Shaker Page.</p>
- <p class="description"><img src="'.plugin_dir_url(__FILE__).'images/warning.png" width="16" height="16" align="absmiddle" /> Before building make sure you\'ve added the memory lines shown in <strong><a href="http://serp-shaker.s3.amazonaws.com/wp-config-changes.png" target="_blank">this image</a></strong> to the wp-config.php file <img src="'.plugin_dir_url(__FILE__).'/images/warning.png" width="16" height="16" align="absmiddle" /></p>');
- } else {
- echo (' <p>
- <input name="build" type="submit" class="button-primary" id="build" value="Build Pages / Posts" disabled />
- </p>
- <p class="description"><strong>You can build Pages / Posts from this Shaker Page once it\'s saved.</strong></p>');
- }
- }
- echo ' <h2>Shortcode Modifiers</h2>
- <p class="description">
- Using <em>Los Angeles</em> as an example:<br />
- {city_upper} = LOS ANGELES<br />
- {city_lower} = los angeles<br />
- {city_word} = Los Angeles<br />
- {city_url} = los-angeles<br /></p>';
- if ( get_option( 'ss_youtube_api' ) == NULL ) {
- echo '<h2>Youtube API</h2>
- <p class="description">
- You currently have not entered a Youtube API key. If you\'d like to take advantage of our built in Youtube function please enter your API key here:<br />
- <a href="edit.php?post_type=shaker-page&page=serpshaker/ss-tools.php&tab=youtube" target="_blank">API Key Settings</a><br /></p>';
- }
- echo '<h2>Visual Editor Shortcuts</h2>
- <p class="description">See <a href="http://members.serpshaker.com/members-area/video-9-visual-editor-shortcuts/" style="color: red" target="_blank">help video</a></p>';
- echo (' </div>');
- }
- /**
- * Displays Page Attribute fields for the meta box for Local Pages custom post
- */
- function DisplayPageAttributesFields() {
- global $post;
- $this->meta = get_post_meta($post->ID, $this->plugin->name, true);
- $template = get_post_meta($post->ID, '_wp_page_template', true);
- $templates = get_page_templates();
- // Start output
- echo (' <div class="'.$this->plugin->name.'-meta-box">
- <input type="hidden" name="'.$this->plugin->name.'_wpnonce" value="'.wp_create_nonce(plugin_basename(__FILE__)).'" />
- <p><strong>Parent</strong></p>'.
- wp_dropdown_pages(array(
- 'post_type' => 'page',
- 'name' => 'parent_id',
- 'selected' => $post->post_parent,
- 'show_option_none' => '(no parent)' ,
- 'sort_column' => 'menu_order, post_title',
- 'echo' => 0
- )).'
- <p><strong>Template</strong></p>
- <select name="page_template">
- <option value="default"'.(($template == 'default' OR $template == '') ? ' selected' : '').'>Default Template</option>');
- if (is_array($templates) AND count($templates) > 0) {
- foreach ($templates as $name=>$file) {
- echo (' <option value="'.$file.'"'.(($template == $file) ? ' selected' : '').'>'.$name.'</option>');
- }
- }
- echo (' </select>
- </div>');
- }
- function SpinnerOptions() {
- global $post;
- $this->meta = get_post_meta($post->ID, $this->plugin->name, true);
- // Start output
- echo (' <div class="'.$this->plugin->name.'-meta-box">
- <input type="hidden" name="'.$this->plugin->name.'_wpnonce" value="'.wp_create_nonce(plugin_basename(__FILE__)).'" />
- ');
- // Output build button or message to say pages / posts already built
- if (@$this->meta['alreadyspun']) {
- echo ('
- <p class="description">This content has already been used to create a new spun <strong><a href="edit.php?post_type=shaker-page">Shaker Page</a></strong>. If you\'d like to spin again just resave this Shaker Page');
- } else {
- if (isset($_GET['post'])) {
- global $ss_wa_options;
- global $ss_sr_options;
- if($ss_wa_options['email'] === ''){
- $disabledwa = "disabled";}
- if($ss_sr_options['email'] === ''){
- $disabledsr = "disabled";}
- echo (' <p class="description"><strong>Make sure you\'ve added the settings for either <a href="edit.php?post_type=shaker-page&page=serpshaker/ss-spinners.php" target="_blank">SpinRewriter or WordAi</a>.</strong> The buttons below will spin the current content and create a new Shaker Page with spintax.<br />
- <em><a href="http://members.serpshaker.com/members-area/video-14-advanced-spin-settings/" style="color: red" target="_blank">(Help Video)</a></em></p>
- <p>
- <img src="'.plugin_dir_url(__FILE__).'/images/wordai32.png" width="32" height="32" align="absmiddle" /> <input name="spin" type="submit" class="button-primary" id="spin" value="Spin It With WordAi" ' . $disabledwa . '/><BR><BR>
- <img src="'.plugin_dir_url(__FILE__).'/images/spinrewriter32.png" width="32" height="32" align="absmiddle" /> <input name="spin" type="submit" class="button-primary" id="spin" value="Spin It With SpinRewriter" ' . $disabledsr . '/>
- </p>
- ');
- } else {
- echo (' <p>
- <input name="spin" type="submit" class="button-primary" id="spin" value="Spin It" disabled />
- </p>
- <p class="description"><strong>You can spin this Shaker Page once it\'s saved.</strong></p>');
- }
- }
- echo (' </div>');
- }
- function ss_title () {
- // Get the post ID
- global $post ;
- $post_id = $post->ID;
- $ss_title = trim(get_post_meta($post_id, 'ss_title', true));
- $ss_yoast_seo_title = trim(get_post_meta($post_id, '_yoast_wpseo_title', true));
- $ss_yoast_seo_description = trim(get_post_meta($post_id, '_yoast_wpseo_metadesc', true));
- // The actual fields for data entry
- echo '<label for="ss_title">';
- echo 'Enter the title of your post/page below if you\'d like the <strong>Title</strong> and <strong>Permalink/slug</strong> to be different.<br />
- This will be the <strong>H1 Page/Post Title</strong> <em><a href="http://members.serpshaker.com/members-area/video-15-advanced-different-title-url/" style="color: red" target="_blank">(Help Video)</a></em><br />';
- echo '</label>';
- echo '<input type="text" id="ss_title" class="large-text" name="ss_title" value="' . $ss_title . '" /><br /><br />';
- $seooption = get_option( 'serp_shaker_platinum_seo' );
- if( $seooption !== 'on' ) {
- echo '<label for="ss_yoast_seo_title">';
- echo 'If you\'re using <strong>YOAST SEO</strong> you can input the SEO Title and Description Below<br />
- <strong>YOAST SEO Title:</strong><br />';
- echo '</label>';
- echo '<input type="text" id="ss_yoast_seo_title" class="large-text" name="ss_yoast_seo_title" value="' . $ss_yoast_seo_title . '" /><br />';
- echo '<label for="ss_yoast_seo_description">';
- echo '<strong>YOAST SEO Description:</strong>';
- echo '</label><br />';
- echo '<input type="text" id="ss_yoast_seo_description" class="large-text" name="ss_yoast_seo_description" value="' . $ss_yoast_seo_description . '" />';}
- }
- function ss_category () {
- // Get the post ID
- global $post ;
- $post_id = $post->ID;
- $ss_category = trim(get_post_meta($post_id, 'ss_category', true));
- // The actual fields for data entry
- echo '<label for="ss_category">';
- echo 'Enter your category to use with the posts. Shortcodes can be used (eg, <strong>Keyword in {state}</strong>)';
- echo '</label><br />';
- echo '<input type="text" id="ss_category" name="ss_category" value="' . $ss_category . '" size="25" />';
- }
- function ss_page_parent () {
- // Get the post ID
- global $post ;
- $post_id = $post->ID;
- $ss_page_parent = trim(get_post_meta($post_id, 'ss_page_parent', true));
- // The actual fields for data entry
- echo '<label for="ss_page_parent">';
- echo 'If you are using pages to create your SILO, enter the page title that will be the <strong>Parent</strong> to this Shaker Page.<br /><br />
- Keep in mind that in order for it to function correctly, the <strong>parent pages should have been previously created</strong>.<br/>
- <br/>
- Also if you used the <strong>Custom Title</strong> option make sure to put in the full title here.<br/>';
- echo '</label><br />';
- echo '<input type="text" id="ss_page_parent" name="ss_page_parent" value="' . $ss_page_parent . '" class="large-text" />';
- }
- /**
- * Saves Shaker Page Custom Post Type metadata
- *
- * @param int $post_id Post ID
- */
- function Save($post_id) {
- global $ssShortCodes;
- // Only continue if the post type is a shaker page
- $type = get_post_type($post_id);
- if ($type == 'shaker-page') {
- if (@!wp_verify_nonce($_POST[$this->plugin->name.'_wpnonce'], plugin_basename(__FILE__))) return $post_id;
- if (!current_user_can('edit_post', $post_id)) return $post_id;
- // Save post meta for plugin
- $data = $_POST[$this->plugin->name];
- update_post_meta($post_id, $this->plugin->name, $data);
- $ss_title = trim(@$_POST['ss_title']);
- update_post_meta($post_id, 'ss_title', $ss_title);
- $ss_yoast_seo_title = trim(@$_POST['ss_yoast_seo_title']);
- update_post_meta($post_id, '_yoast_wpseo_title', $ss_yoast_seo_title);
- $ss_yoast_seo_description = trim(@$_POST['ss_yoast_seo_description']);
- update_post_meta($post_id, '_yoast_wpseo_metadesc', $ss_yoast_seo_description);
- $ss_page_parent = trim(@$_POST['ss_page_parent']);
- update_post_meta($post_id, 'ss_page_parent', $ss_page_parent);
- $ss_post_category = trim(@$_POST['ss_category']);
- update_post_meta($post_id, 'ss_category', $ss_post_category);
- // Save post meta for Page Attributes
- if ($_POST['page_template'] != '') update_post_meta($post_id, '_wp_page_template', $_POST['page_template']);
- //CHeck if Spin It is pushed
- if (isset($_POST['spin'])) {
- if( !defined('SPUN_EXECUTED') ){
- remove_action('save_post', array(&$this, 'Save'));
- // Use WordAi or SpinRewriter to create a new post with spin syntax
- if ($_POST['spin'] == 'Spin It With WordAi'){
- $spun_content = ss_wordai($_POST['post_content']);}
- elseif ($_POST['spin'] == 'Spin It With SpinRewriter'){
- $spun_content = ss_spinrewriter($_POST['post_content']);}
- $spunPost['post_title'] = $_POST['post_title'];
- $spunPost['post_content'] = $spun_content;
- $spunPost['post_category'] = $_POST['post_category'];
- // Add some other basic details to the post
- $spunPost['post_status'] = 'draft';
- $spunPost['post_author'] = $_POST['post_author'];
- $spunPost['post_type'] = 'shaker-page';
- $spunPost['ping_status'] = 'closed';
- $spunPostID = wp_insert_post($spunPost);
- update_post_meta($spunPostID, 'ss_title', $ss_title);
- switch ($_POST['serpshaker']['output']) {
- case 'post':
- if (trim($_POST['tax_input']['post_tag']) != '') wp_set_post_terms($spunPostID, $_POST['tax_input']['post_tag']); // Set tags, if defined
- set_post_format($spunPostID, $_POST['post_format']); // Set post format
- break;
- case 'page':
- update_post_meta($spunPostID, '_wp_page_template', $_POST['page_template']); // Set page template
- break;
- }
- $data['alreadyspun'] = 1;
- update_post_meta($post_id, $this->plugin->name, $data);
- define('SPUN_EXECUTED', TRUE);
- add_action('save_post', array(&$this, 'Save'));
- }
- }
- // Check if build or unbuild buttons clicked.
- if (isset($_POST['build']) AND $_POST['build'] == 'Build Pages / Posts') {
- // Get shortcodes and spins used across all fields
- $this->FindPostFields($_POST);
- $maxDataEntries = 0;
- $mypostcounter = 0;
- // Get shortcode data for each shortcode found from above
- foreach ($this->shortcodes as $key=>$shortcode) {
- $scData = $ssShortCodes->GetByShortcode($shortcode);
- $shortcodeData[$shortcode] = explode("\n", $scData['shortcodeData']);
- $maxDataEntries = ((count($shortcodeData[$shortcode]) > $maxDataEntries) ? count($shortcodeData[$shortcode]) : $maxDataEntries);
- $shortcodeDataCurrentIndex[$shortcode] = 0;
- $shortcodeDataCeilingIndex[$shortcode] = count($shortcodeData[$shortcode]) - 1;
- }
- global $wp_version;
- if ( $wp_version >= 4.2 ){
- $terms = get_the_terms( $post_id, 'post_tag' );
- $terms = wp_list_pluck( $terms, 'name' );}
- if ($_POST['ss_title'] !== ''){
- $post_title = $_POST['ss_title'];
- }
- else {
- $post_title = $_POST['post_title'];}
- if ($POST['ss_category'] === '') {
- $post_category = $_POST['post_category'];}
- else {
- $post_category = $_POST['ss_category'];}
- $customFields = get_post_custom_keys($post_id);
- // Create a loop for the number of posts we need to build
- $numberOfPosts = ($_POST[$this->plugin->name]['numberOfPosts'] != '' ? $_POST[$this->plugin->name]['numberOfPosts'] : $maxDataEntries);
- @set_time_limit(0);
- for ($i = 0; $i < $numberOfPosts; $i++) {
- // Define the data to use for each shortcode for this Post
- // Increment / reset index for next Post in loop
- unset($replace); // Clear from last run
- foreach ($this->shortcodes as $key=>$shortcode) {
- $replace[$shortcode] = $shortcodeData[$shortcode][$shortcodeDataCurrentIndex[$shortcode]];
- $shortcodeDataCurrentIndex[$shortcode] = (($shortcodeDataCurrentIndex[$shortcode]+1 > $shortcodeDataCeilingIndex[$shortcode]) ? 0 : $shortcodeDataCurrentIndex[$shortcode]+1);
- }
- // Generate new post array with shortcode replacements
- $newPost = $this->ReplacePostFields(array(
- 'post_title' => $this->ConvertWordSpecialChars($post_title),
- 'post_name' => $this->ConvertWordSpecialChars($_POST['post_title']),
- 'post_content' => $this->ConvertWordSpecialChars($_POST['post_content']),
- 'post_category' => $this->ConvertWordSpecialChars($post_category),
- 'post_parent' => $_POST['ss_page_parent'],
- 'post_excerpt' => $_POST['post_excerpt']), $replace); // Replace shortcodes with given array of replacement content / words
- // Spin the title and content
- /* $spintax = new SS_Spintax();
- $newPost['post_title'] = $spintax->process($newPost['post_title']);
- $newPost['post_content'] = $spintax->process($newPost['post_content']);
- $newPost['post_category'] = $spintax->process($newPost['post_category']);
- // Add some other basic details to the post
- $newPost['post_status'] = 'publish';
- $newPost['post_author'] = $_POST['post_author'];
- $newPost['post_name'] = strtolower(str_replace(" ", "-", $spintax->process($newPost['post_name'])));
- $newPost['post_type'] = $_POST['serpshaker']['output'];
- $newPost['ping_status'] = 'closed';*/
- $spintax = new SS_Spintax();
- $newPost['post_title'] = stripslashes($spintax->process($newPost['post_title']));
- $newPost['post_content'] = stripslashes($spintax->process($newPost['post_content']));
- $newPost['post_category'] = $spintax->process($newPost['post_category']);
- // Add some other basic details to the post
- $newPost['post_status'] = 'publish';
- $newPost['post_author'] = $_POST['post_author'];
- $newPost['post_name'] = stripslashes(strtolower(str_replace(" ", "-", $spintax->process($newPost['post_name']))));
- $newPost['post_type'] = $_POST['serpshaker']['output'];
- $newPost['ping_status'] = 'closed';
- $newPost['post_excerpt'] = stripslashes($spintax->process($newPost['post_excerpt']));
- // Depending on whether we are outputting Posts or Pages from this Shaker Page,
- // set some additional fields.
- if ($newPost['post_parent'] === ''){
- $post_parent = $_POST['parent_id'];
- }
- else {
- $page = get_page_by_title($newPost['post_parent']);
- $post_parent = $page->ID;
- }
- switch ($_POST['serpshaker']['output']) {
- case 'post':
- // $newPost['post_category'] = $_POST['post_category']; // Set categories
- break;
- case 'page':
- $newPost['post_parent'] = $post_parent; // Set optional parent Page
- break;
- }
- // Create Page / Post
- // added by don 7-22
- // wp_defer_term_counting( true );
- // wp_defer_comment_counting( true );
- global $wpdb;
- $wpdb->query( 'SET autocommit = 0;' );
- /* $wpdb->query( 'SET unique_checks = 0;' );
- $wpdb->query( 'SET foreign_key_checks = 0;' );*/
- $defaults = array('to_ping' => '');
- $user_ID = get_current_user_id();
- $max_days = $_POST['serpshaker']['numberOfDays'];
- if ($max_days != ''){
- $day = rand(1, $max_days);
- $hour = rand(0, 23);
- $gmt_offset = '-5';}
- if ($_POST['serpshaker']['futuredate'] == 'future' ) {
- $new_post_status = 'future';
- $new_date = date( 'Y-m-d H:i:s', strtotime("+$day day +$hour hour") );
- $gmt_new_date = date( 'Y-m-d H:i:s', strtotime("+$day day +$hour hour +$gmt_offset hour") ); }
- elseif ($_POST['serpshaker']['futuredate'] == 'past' ) {
- $new_post_status = 'publish';
- $new_date = date( 'Y-m-d H:i:s', strtotime("-$day day -$hour hour") );
- $gmt_new_date = date( 'Y-m-d H:i:s', strtotime("-$day day -$hour hour -$gmt_offset hour") );}
- else {
- $new_post_status = 'publish';
- $new_date = current_time('mysql');
- $gmt_new_date = current_time('mysql');
- }
- // $newPostID = wp_insert_post($newPost);
- $wpdb->query( $wpdb->prepare("INSERT IGNORE INTO `".$wpdb->prefix."posts`(post_author,post_content,post_title,comment_status,ping_status,post_name,post_type,post_date,post_date_gmt,post_status,post_parent,post_excerpt) VALUES(%s,%s,%s,'closed','closed',%s,%s,%s,%s,%s,%s,%s)", $user_ID,$newPost['post_content'],$newPost['post_title'],sanitize_title($newPost['post_name']),$newPost['post_type'],$new_date,$gmt_new_date,$new_post_status,$post_parent,$newPost['post_excerpt']));
- $newPostID = $wpdb->insert_id;
- if (!$newPostID) continue; // An error occured
- // Depending on whether we are outputting Posts or Pages from this Local Page,
- // set some additional fields. This is done after the Post / Page creation
- // so we have a valid post ID
- $spintax = new SS_Spintax();
- switch ($_POST['serpshaker']['output']) {
- case 'post':
- /* if (trim($_POST['tax_input']['post_tag']) != '') wp_set_post_terms($newPostID, $spintax->process($this->ReplacePostFields($_POST['tax_input']['post_tag'], $replace))); // Set tags, if defined*/
- $mytagcounter = 0;
- if ( $wp_version >= 4.2 ){
- $dotags = $spintax->process($this->ReplacePostFields($terms, $replace));}
- else {
- $dotags = array();
- $dotags = explode(",",$spintax->process($this->ReplacePostFields($_POST['tax_input']['post_tag'], $replace)));
- }
- // print_r($dotags);
- foreach($dotags as $thenewtag) {
- $theslug = str_replace(" ","-",strtolower($thenewtag));
- $theslug = str_replace("'","",$theslug);
- $thenewtag = addslashes($thenewtag);
- $wpdb->query( "INSERT IGNORE INTO `".$wpdb->prefix."terms`(name,slug) VALUES('" . $thenewtag . "','" . sanitize_title($theslug) . "')");
- $startpoint = $wpdb->insert_id;
- $wpdb->query( "INSERT IGNORE INTO `".$wpdb->prefix."term_taxonomy`(term_taxonomy_id,term_id,taxonomy) VALUES(" . $startpoint . "," . $startpoint . ",'post_tag')");
- $wpdb->query( "INSERT IGNORE INTO `".$wpdb->prefix."term_relationships`(object_id,term_taxonomy_id) VALUES(" . $newPostID . "," . $startpoint . ")");
- $mytagcounter ++;
- if($mytagcounter == 100) {
- $wpdb->query( 'COMMIT;' );
- $mytagcounter = 0;}}
- set_post_format($newPostID, $_POST['post_format']); // Set post format
- $catID = get_cat_ID( $newPost['post_category'] ) ;
- if ($catID == 0) {
- // Create the category
- $catslug = str_replace(" ","-",strtolower($newPost['post_category']));
- $catslug = str_replace("'","",$catslug);
- $wpdb->query( "INSERT IGNORE INTO `".$wpdb->prefix."terms`(name,slug) VALUES('" . $newPost['post_category'] . "','" . sanitize_title($catslug) . "')");
- //$catID = wp_create_category( $newPost['post_category'] );
- $catID = $wpdb->insert_id;
- }
- // wp_set_post_categories( $newPostID, array($catID));
- $wpdb->query( "INSERT IGNORE INTO `".$wpdb->prefix."term_relationships`(object_id,term_taxonomy_id) VALUES (" . $newPostID . "," . $catID . ")" );
- $wpdb->query( "INSERT IGNORE INTO `".$wpdb->prefix."term_taxonomy`(term_taxonomy_id,term_id,taxonomy) VALUES (" . $catID . "," . $catID . ",'category')" );
- break;
- case 'page':
- update_post_meta($newPostID, '_wp_page_template', $_POST['page_template']); // Set page template
- break;
- }
- // Add meta to Post
- //$startmeta = 1000;
- if (is_array($customFields) AND count($customFields) > 0) {
- foreach ($customFields as $k=>$metaKey) {
- $meta = get_post_meta($post_id, $metaKey);
- $spintax = new SS_Spintax();
- $newMeta = $this->ReplacePostFields($meta, $replace); // Replace shortcodes with content
- if (get_option( 'ss_double_agent_issue' ) !== 'on'){
- $newMeta = $spintax->process($newMeta);} // Spin meta fields for meta title and description
- // update_post_meta($newPostID, $metaKey, $newMeta[0]); // Add post meta to newly created post
- $wpdb->query( "INSERT IGNORE INTO `".$wpdb->prefix."postmeta`(post_id,meta_key,meta_value) VALUES (" . $newPostID . ",'" . $metaKey . "','" . addslashes($newMeta[0]) . "')" );
- // $startmeta = $startmeta + 1;
- }
- }
- $featured_image = get_post_thumbnail_id($post_id);
- set_post_thumbnail( $newPostID, $featured_image );
- // Add this post ID to the newly created post, so we can reference it if we need to unbuild / delete later on
- update_post_meta($newPostID, 'localPageID', $post_id);
- $mypostcounter ++;
- if($mypostcounter == 100) {
- $wpdb->query( 'COMMIT;' );
- $mypostcounter = 0;
- }
- }
- $wpdb->query( 'COMMIT;' ); // added for uneven post numbers
- // POST CATEGORY COUNTS UPDATE WAS HERE -- MOVED TO FUNCTION
- serp_shaker_rebuild(); //calls the new rebuild post count function
- $wpdb->query( 'COMMIT;' );
- $wpdb->query( 'SET autocommit = 1;' );
- //$wpdb->query( 'SET unique_checks = 1;' );
- // $wpdb->query( 'SET foreign_key_checks = 1;' );
- // Mark as built
- $data['built'] = 1;
- update_post_meta($post_id, $this->plugin->name, $data);
- } elseif (isset($_POST['unbuild']) AND $_POST['unbuild'] == 'Delete Built Pages / Posts') {
- // Delete Posts and Pages with localPageID matching this Local Page Custom Post ID
- $query['post_type'] = 'any';
- $query['meta_key'] = 'localPageID';
- $query['meta_value'] = $post_id;
- $query['posts_per_page'] = -1;
- $q = new WP_Query($query);
- foreach ($q->posts as $key=>$builtPost) wp_delete_post($builtPost->ID, true);
- unset($q);
- // Mark as not built
- $data['built'] = 0;
- update_post_meta($post_id, $this->plugin->name, $data);
- }
- // wp_defer_term_counting( false );
- // wp_defer_comment_counting( false );
- }
- return $post_id;
- }
- /**
- * Recursively goes through a POST array, replacing shortcodes
- * with those specified in the replacement array.
- *
- * @param mixed $postArr Array or Single Value
- * @param array $replaceArr Array of replacements
- * @return mixed Array or Single Value (end of recursion will return same as put in i.e. array)
- */
- function ReplacePostFields($postArr, $replaceArr) {
- if (!is_array($postArr)) {
- foreach ($replaceArr as $shortcode=>$replacement) {
- $postArr = str_replace('{'.$shortcode.'}', str_replace("\n", "", trim($replacement)), $postArr);
- $postArr = str_replace('{'.$shortcode.'_upper}', strtoupper(str_replace("\n", "", trim($replacement))), $postArr);
- $postArr = str_replace('{'.$shortcode.'_lower}', strtolower(str_replace("\n", "", trim($replacement))), $postArr);
- $postArr = str_replace('{'.$shortcode.'_word}', ucwords(strtolower(str_replace("\n", "", trim($replacement)))), $postArr);
- $createurls = array('\n', ' ');
- $replaceurls = array('', '-');
- $postArr = str_replace('{'.$shortcode.'_url}', sanitize_title(strtolower(str_replace($createurls, $replaceurls, trim($replacement)))), $postArr);
- }
- return $postArr;
- }
- foreach ($postArr as $key=>$value) {
- $newArr[$key] = $this->ReplacePostFields($value, $replaceArr);
- }
- return $newArr;
- }
- /**
- * Recursively goes through a POST array, finding shortcodes
- * within the array content.
- *
- * @param mixed $postArr
- */
- function FindPostFields($postArr) {
- if (!is_array($postArr)) {
- preg_match_all("|{(.+?)}|", $postArr, $matches); // Get shortcodes and spins
- // Build arrays of found shortcodes and spins
- if (is_array($matches) AND count($matches[1]) > 0) {
- foreach ($matches[0] as $mKey=>$shortcode) {
- if (strpos($shortcode, "|") === false) { // Check this is a shortcode and not a spin
- $shortcode = str_replace('_upper', '', $shortcode);
- $shortcode = str_replace('_lower', '', $shortcode);
- $shortcode = str_replace('_word', '', $shortcode);
- $shortcode = str_replace('_url', '', $shortcode);
- if (!is_array($this->shortcodes) OR (is_array($this->shortcodes) AND !in_array(trim($shortcode, "{}"), $this->shortcodes))) $this->shortcodes[] = trim($shortcode, "{}");
- }
- }
- }
- return $postArr;
- }
- foreach ($postArr as $key=>$value) {
- $newArr[$key] = $this->FindPostFields($value);
- }
- return $newArr;
- }
- /**
- * Converts Microsoft Word special characters without affecting the rest
- * of the string (ensuring HTML elements are not encoded)
- *
- * @param string $string String to Convert
- * @return string Converted String
- */
- function ConvertWordSpecialChars($string) {
- $string = str_replace(chr(130), ',', $string); // baseline single quote
- $string = str_replace(chr(132), '"', $string); // baseline double quote
- $string = str_replace(chr(133), '...', $string); // ellipsis
- $string = str_replace(chr(145), "'", $string); // left single quote
- $string = str_replace(chr(146), "'", $string); // right single quote
- $string = str_replace(chr(147), '"', $string); // left double quote
- $string = str_replace(chr(148), '"', $string); // right double quote
- $string = mb_convert_encoding($string, 'HTML-ENTITIES', 'UTF-8');
- return $string;
- }
- /**
- * Spins content.
- *
- * @param mixed $string
- * @param mixed $seedPageName
- * @param mixed $openingConstruct
- * @param mixed $closingConstruct
- */
- function SpinContent($string, $openingConstruct = '{', $closingConstruct = '}') {
- if(strpos($string, $openingConstruct) === false) return $string; // If we have nothing to spin return content
- // Find all positions of the starting and opening braces
- $startPositions = $this->strpos_all($string, $openingConstruct);
- $endPositions = $this->strpos_all($string, $closingConstruct);
- // There must be the same number of opening constructs to closing ones
- if($startPositions === false OR count($startPositions) !== count($endPositions)) return $string;
- $openingConstructLength = mb_strlen($openingConstruct);
- $closingConstructLength = mb_strlen($closingConstruct);
- // Organise the starting and opening values into a simple array showing orders
- foreach($startPositions as $pos) $order[$pos] = 'open';
- foreach($endPositions as $pos) $order[$pos] = 'close';
- ksort($order);
- // Go through the positions to get the depths
- $depth = 0;
- $chunk = 0;
- foreach($order as $position => $state) {
- if($state == 'open') {
- $depth++;
- $history[] = $position;
- } else {
- $lastPosition = end($history);
- $lastKey = key($history);
- unset($history[$lastKey]);
- $store[$depth][] = mb_substr($string, $lastPosition + $openingConstructLength, $position - $lastPosition - $closingConstructLength);
- $depth--;
- }
- }
- krsort($store);
- // Remove the old array and make sure we know what the original state of the top level spin blocks was
- unset($order);
- $original = $store[1];
- // Move through all elements and spin them
- foreach($store as $depth => $values) {
- foreach($values as $key => $spin) {
- # Get the choices
- $choices = explode('|', $store[$depth][$key]);
- $replace = $choices[mt_rand(0, count($choices) - 1)];
- # Move down to the lower levels
- $level = $depth;
- while($level > 0) {
- foreach($store[$level] as $k => $v) {
- $find = $openingConstruct.$store[$depth][$key].$closingConstruct;
- if($level == 1 AND $depth == 1)
- {
- $find = $store[$depth][$key];
- }
- $store[$level][$k] = $this->str_replace_first($find, $replace, $store[$level][$k]);
- }
- $level--;
- }
- }
- }
- // Put the very lowest level back into the original string
- foreach($original as $key => $value) $string = $this->str_replace_first($openingConstruct.$value.$closingConstruct, $store[1][$key], $string);
- return $string;
- }
- /**
- * Similar to str_replace, but only replaces the first instance of the needle
- *
- * @param string $find Find
- * @param string $replace Replace
- * @param string $string Content
- * @return Amended String
- */
- function str_replace_first($find, $replace, $string) {
- if(!is_array($find)) $find = array($find); // Not an array
- if(!is_array($replace)) $replace = array($replace); // Not an array
- foreach($find as $key => $value) {
- if(($pos = strpos($string, $value)) !== false) {
- if(!isset($replace[$key])) $replace[$key] = ''; // If we have no replacement make it empty
- $string = mb_substr($string, 0, $pos).$replace[$key].mb_substr($string, $pos + mb_strlen($value));
- }
- }
- return $string;
- }
- /**
- * Finds all instances of a needle in the haystack and returns the array.
- *
- * @param string $haystack Haystack
- * @param string $needle Needle
- * @return array Positions
- */
- function strpos_all($haystack, $needle) {
- $offset = 0;
- $i = 0;
- $return = false;
- while(is_integer($i)) {
- $i = strpos($haystack, $needle, $offset);
- if(is_integer($i)) {
- $return[] = $i;
- $offset = $i + mb_strlen($needle);
- }
- }
- return $return;
- }
- /**
- * Outputs the plugin Admin Panel in Wordpress Admin
- */
- function AdminPanel() {
- global $ssShortCodes;
- // Get existing settings
- $this->data = get_option($this->plugin->name);
- // Check command to determine what to output
- switch (strtolower(str_replace($this->plugin->name.'-', '', $_GET['page']))) {
- // Licensing / Updates
- case $this->plugin->name:
- $page = 'licensing';
- // Save Settings
- if (isset($_POST['submit'])) {
- $this->data = is_array($this->data) ? array_merge($this->data, $_POST[$this->plugin->name]) : $_POST[$this->plugin->name];
- update_option($this->plugin->name, $this->data);
- $this->message = 'Licensing Settings Updated.';
- }
- // Validate license key
- if (!$ssLum->CheckLicenseKeyIsValid(true)) {
- $this->errorMessage = $ssLum->licenseKeyCodeDescription; // Force License Key Check
- } else {
- $this->message .= 'License key is valid. ';
- }
- // Download and Install Update, if requested
- if (isset($_GET['doUpdate']) AND $_GET['doUpdate'] == 1) {
- if ($ssLum->DownloadAndInstallUpdate()) {
- $this->message .= $this->plugin->displayName.' updated successfully. ';
- $ssLum->CheckForUpdates(); // Force re-check to ensure new version installed
- } else {
- $this->errorMessage .= 'An error occured when attempting to automatically update '.$this->plugin->displayName;
- }
- }
- // Check for updates if required
- if (isset($_GET['checkUpdates']) AND $_GET['checkUpdates'] == 1) {
- $ssLum->CheckForUpdates(true); // Force Update Check
- }
- break;
- // Shortcodes
- case 'shortcodes':
- switch (@$_GET['cmd']) {
- case "add":
- case "edit":
- if (isset($_POST['submit'])) {
- // Check for required fields
- if (trim($_POST['shortcode']) == '') {
- $this->shortcode = $_POST;
- $this->errorMessage = 'Please specify a shortcode.';
- $page = 'shortcodes-form';
- }
- //elseif (trim($_POST['shortcodeData']) == '') {
- // $this->shortcode = $_POST;
- //$this->errorMessage = 'Please specify at least one word / phrase for this shortcode.';
- //$page = 'shortcodes-form';
- // }
- else {
- if ($ssShortCodes->Save($_POST)) {
- $this->message = 'Shortcode '.($_GET['cmd'] == 'add' ? 'created' : 'updated').'.';
- $this->shortcodes = $ssShortCodes->GetAll($_GET['paged']);
- $this->total = $ssShortCodes->GetTotal();
- $page = 'shortcodes';
- } else {
- $this->errorMessage = 'An error occured, please try again.';
- $page = 'shortcodes-form';
- }
- }
- } else {
- if (isset($_GET['pKey'])) {
- $this->shortcode = $ssShortCodes->GetByID($_GET['pKey']);
- }
- $page = 'shortcodes-form';
- }
- break;
- default:
- if (isset($_POST['doAction'])) {
- // Delete checked
- foreach ($_POST['shortcodeID'] as $shortcodeID=>$doDelete) $ssShortCodes->DeleteByID($shortcodeID);
- $this->message = 'Shortcode(s) deleted.';
- }
- // Get shortcodes based on pagination
- $this->shortcodes = $ssShortCodes->GetAll(@$_GET['paged']);
- $this->total = $ssShortCodes->GetTotal();
- $page = 'shortcodes';
- break;
- }
- break;
- }
- // Get most up to date data
- $this->data = get_option($this->plugin->name);
- // Load form
- if (isset($this->errorMessage)) $this->message = '';
- include_once(WP_PLUGIN_DIR.'/'.$this->plugin->name.'/admin/'.$page.'.php');
- }
- }
- function serp_shaker_shortcodes () {
- global $wpdb;
- if(isset($_GET['dynadel'])) {
- $deletedyna = $wpdb->query($wpdb->prepare("DELETE FROM " . $wpdb->prefix . "ss_dynamicodes WHERE shortcodeID = %s",$_GET['dynadel']));
- }
- if(isset($_POST['dynacodename']) && !empty($_POST['updateit'])) {
- $updatedyna = $wpdb->query($wpdb->prepare("UPDATE " . $wpdb->prefix . "ss_dynamicodes SET shortcode = '%s',shortcodeData = '%s',spinnable = %s WHERE shortcodeID = %s",$_POST['dynacodename'],stripslashes($_POST['dynacontent']),$_POST['spinnable'],$_POST['updateit']));
- } elseif(isset($_POST['dynacodename']) && empty($_POST['updateit'])) {
- $insertdyc = $wpdb->query($wpdb->prepare("INSERT INTO " . $wpdb->prefix . "ss_dynamicodes (shortcode,shortcodeData,spinnable) VALUES('%s','%s','%s')",$_POST['dynacodename'],stripslashes($_POST['dynacontent']),$_POST['spinnable']));
- // $wpdb->query($insertdyc);
- }
- $ssrows = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "ss_dynamicodes", ARRAY_A);
- // print_r($ssrows);
- $content = '';
- $editor_id = 'dynacontent';
- if(isset($_GET['dynaedit'])) {
- $editdyna = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "ss_dynamicodes WHERE shortcodeID = " . $_GET['dynaedit'], ARRAY_A);
- $shortname = $editdyna[0]['shortcode'];
- $content = $editdyna[0]['shortcodeData'];
- $shortspin = $editdyna[0]['spinnable'];
- }
- echo '<h1>Shortcodes</h1>';
- echo '<p>Dynamic Shortcodes are codes that are used to insert specific elements in content.<br />
- They can be static elements or they can be spinnable content.</p>
- <form id="form1" name="form1" method="post" action="">
- <p>Shotcode Name:
- <label for="textfield"></label>';
- if(isset($_GET['dynaedit'])) {
- echo '<input type="text" name="dynacodename" value="' . $shortname . '" />';
- } else {
- echo '<input type="text" name="dynacodename" />';
- }
- echo '</p>(When using a dynamic shortcode in your content, always use the shortcode shown in the table below.)<br />
- If inserting code snippets such as Youtube embeds, make sure you use the <strong>TEXT</strong> editor and not VISUAL<br /><br />';
- wp_editor(stripslashes($content), $editor_id, $settings = array('textarea_rows' => 5));
- echo'<p>
- <label for="select"></label>
- Spinnable:
- <select name="spinnable" id="select">';
- if($shortspin == 2) {
- echo '<option value="1">No</option><option value="2" selected="selected">Yes</option>';
- } else {
- echo '<option value="1" selected="selected">No</option><option value="2">Yes</option>';
- }
- echo '</select>
- </p>
- <p>
- <input type="hidden" name="updateit" value="' . $_GET['dynaedit'] . '">
- <input class="button-primary" type="submit" name="button" id="button" value="Create / Update" />';
- if(isset($_POST['dynacodename']) && !empty($_POST['updateit'])) {
- echo ' <a class="button" href="edit.php?post_type=shaker-page&page=serpshaker-ss-shortcodes">Add New</a>';
- }
- echo '</p>
- </form>';
- echo'<table width="80%" border="0" cellpadding="5" cellspacing="0"><tr style="background: #FFF;text-align: left;"><th scope="col">Shotcodes</th><th scope="col">Content Excerpt</th><th scope="col">Spinnable</th><th scope="col">Action</th></tr>';
- foreach($ssrows as $ssdyna) {
- if($ssdyna['spinnable'] == 2) {
- $ssdyna['spinnable'] = "Yes";
- } else {
- $ssdyna['spinnable'] = "No";
- }
- echo '<tr><td nowrap width="20%">[dyna dynami="' . $ssdyna['shortcode'] . '"]</td><td width="40%">' . substr(strip_tags($ssdyna['shortcodeData']),0,50) . '</td><td width="20%">' . $ssdyna['spinnable'] . '</td><td width="20%"><a class="button button-primary" href="edit.php?post_type=shaker-page&page=serpshaker-ss-shortcodes&dynaedit=' . $ssdyna['shortcodeID'] . '"><b>Edit</b></a> <a style="color: red;" class="button" href="edit.php?post_type=shaker-page&page=serpshaker-ss-shortcodes&dynadel=' . $ssdyna['shortcodeID'] . '"><b>Delete</b></a></td></tr>';
- }
- echo '</table>';
- }
- function serp_shaker_ads () {
- global $wpdb;
- $content = '';
- $editor_id = 'addata';
- if(isset($_GET['addel'])) {
- $deletead = $wpdb->query($wpdb->prepare("DELETE FROM " . $wpdb->prefix . "ss_ads WHERE adID = %s",$_GET['addel']));
- }
- if(isset($_POST['adname']) && !empty($_POST['updateit'])) {
- $updatead = $wpdb->query($wpdb->prepare("UPDATE " . $wpdb->prefix . "ss_ads SET adname = '%s',adData = '%s' WHERE adID = %s",$_POST['adname'],$_POST['addata'],$_POST['updateit']));
- } elseif(isset($_POST['adname']) && empty($_POST['updateit'])) {
- $insertad = $wpdb->query($wpdb->prepare("INSERT INTO " . $wpdb->prefix . "ss_ads (adname,addata) VALUES('%s','%s')",$_POST['adname'],$_POST['addata']));
- // $wpdb->query($insertdyc);
- }
- $ssrows = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "ss_ads", ARRAY_A);
- // print_r($ssrows);
- if(isset($_GET['adid'])) {
- $editadd = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "ss_ads WHERE adID = " . $_GET['adid'], ARRAY_A);
- $addname = $editadd[0]['adname'];
- $content = $editadd[0]['adData'];
- $doupdate = 1;
- }
- echo '<h1>SERP Shaker Ads</h1>';
- echo '<form id="shakead" name="shakead" method="post" action="">
- <p>
- Ad Name:<br />';
- if(isset($_GET['adid'])) {
- echo '<input type="text" name="adname" id="adname" value="' . $addname . '" />';
- } else {
- echo '<input type="text" name="adname" id="adname" />';
- }
- echo '</p>';
- wp_editor( stripslashes($content), $editor_id, $settings = array('textarea_rows' => 7) );
- echo ' <p>
- <input type="hidden" name="updateit" value="' . @$_GET['adid'] . '">
- <input class="button-primary" type="submit" name="button" id="button" value="Create/Edit Ad" />';
- if(isset($_POST['adname']) && !empty($_POST['updateit'])) {
- echo ' <a class="button" href="edit.php?post_type=shaker-page&page=serpshaker-ss-ads">Add New</a>';
- }
- echo '</p>
- </form>';
- echo '<table width="80%" border="0" cellpadding="5" cellspacing="0">';
- echo '<tr style="background: #FFF;text-align: left;">
- <th scope="col">Ad Name</th>
- <th scope="col">Ad Content</th>
- <th scope="col">Action</th>
- </tr>';
- foreach($ssrows as $ssads) {
- echo '<tr>
- <td width="20%" nowrap><b>[ssad ssadblk="' . $ssads['adname'] . '"]</b></td>
- <td width="60%">' . stripslashes($ssads['adData']) . '</td>
- <td width="20%"><a class="button button-primary" href="edit.php?post_type=shaker-page&page=serpshaker-ss-ads&adid=' . $ssads['adID'] . '"><b>Edit</b></a> <a style="color: red;" class="button" href="edit.php?post_type=shaker-page&page=serpshaker-ss-ads&addel=' . $ssads['adID'] . '"><b>Delete</b></a></td>
- </tr>';
- }
- echo '</table>';
- }
- class SS_Spintax
- {
- public function process($text)
- {
- return preg_replace_callback(
- '/\{(((?>[^\{\}]+)|(?R))*)\}/x',
- array($this, 'replace'),
- $text
- );
- }
- public function replace($text)
- {
- $text = $this->process($text[1]);
- $parts = explode('|', $text);
- return $parts[array_rand($parts)];
- }
- }
- function ssrandomDate($start_date, $end_date)
- {
- // Convert to timetamps
- $min = strtotime($start_date);
- $max = strtotime($end_date);
- // Generate random number using above bounds
- $val = rand($min, $max);
- // Convert back to desired date format
- return date('Y-m-d H:i:s', $val);
- }
- function serp_shaker_shaker () {
- global $wpdb;
- echo '<h1>The Shaker</h1>';
- echo 'The Shaker takes a start date you specify, and changes the dates of all posts to random dates.<br />These random dates start from the start date you select below.<br /><br />You can also prepend and append "<u>Text or HTML code</u>" to the beginning and end of every post.<br />These fields can take SpinTax';
- wp_enqueue_script('jquery-ui-datepicker');
- wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/themes/smoothness/jquery-ui.css');
- echo '<form id="shakeit" name="shakeit" method="post" action="">
- <p>Earliest Date:</p>
- <p><div class="dashicons dashicons-calendar"></div><input type="text" id="ShakeDate" name="ShakeDate" value=""/><br />(YEAR-MONTH-DATE) Click TextBox to Select Start Date</p>
- <p>Prepend:</p>
- <p>';
- wp_editor("", "ssprepend", $settings = array('textarea_rows' => 5));
- echo '</p>
- <p>Append:</p>
- <p>';
- wp_editor("", "ssappend", $settings = array('textarea_rows' => 5));
- echo '</p>
- <p>
- <input class="button-primary" type="submit" name="button" id="button" value="Submit" />
- </p>
- </form>';
- $ssjs = <<< js_ss_date
- <script>
- jQuery(document).ready(function() {
- jQuery('#ShakeDate').datepicker({
- dateFormat : 'yy-mm-dd'
- });
- });</script>
- js_ss_date;
- echo $ssjs;
- /*
- if(isset($_POST['ShakeDate'])) {
- $spintax = new SS_Spintax();
- $sshaker = $wpdb->get_results("SELECT ID FROM " . $wpdb->prefix . "posts WHERE post_status = 'publish' AND post_type='post'", ARRAY_A);
- // print_r($sshaker);
- } else {
- exit;
- }
- */
- $spintax = new SS_Spintax();
- $sshakerposts = $wpdb->get_results("SELECT ID FROM " . $wpdb->prefix . "posts WHERE post_status = 'publish' AND post_type='post'", ARRAY_A);
- foreach($sshakerposts as $shakerid) {
- $newappend = "";
- $newprepend = "";
- if(isset($_POST['ShakeDate'])) {
- // print_r($sshaker);
- if(isset($_POST['ssappend'])) {
- $newappend = $spintax->process("<br><br>" . $_POST['ssappend']);
- }
- if(isset($_POST['ssprepend'])) {
- $newprepend = $spintax->process($_POST['ssprepend'] . "<br><br>");
- }
- $startdate = $_POST['ShakeDate'] . " 00:00:00";
- $enddate = date('Y-m-d H:i:s');
- $ssgetdate = ssrandomDate($startdate,$enddate);
- $gmt_new_date = get_gmt_from_date($ssgetdate);
- // echo $ssgetdate . "<br>" . $gmt_new_date . "<br>";
- $query = "UPDATE " . $wpdb->prefix . "posts SET post_date = '" . $ssgetdate . "',post_modified = '" . $ssgetdate . "',post_date_gmt = '" . $gmt_new_date . "',post_modified_gmt= '" . $gmt_new_date . "',post_content = concat(post_content,'" . $newappend . "'),post_content = concat('" . $newprepend . "',post_content) WHERE ID = " . $shakerid['ID'];
- $ssupdate = $wpdb->query($query);
- @flush();
- @ob_flush();
- echo "Just updated POST #: " . $shakerid['ID'] . "<br />";
- }
- }
- }
- function serp_shaker_siloit () {
- echo '<h1>SERP Shaker Interlinking</h1>';
- echo 'The Serp Shaker interlinking option is coded directly into Serp Shaker.<br />
- You do not need to change any settings to use it.<br /><br />
- <b>This is for POSTS only, not pages.</b><br /><br />
- <span style="color: red;">DO NOT COPY/PASTE THESE EXAMPLES INTO THE VISUAL POST EDITOR!<br>
- PLEASE PASTE THEM INTO THE TEXT TAB.</span><br><br>
- <a href="[linkprev]">Anchor text</a><br /><br />
- <a href="[linknext]">Anchor text</a><br /><br />
- <b>The anchor text can be in spintax format.</b><br /><br />
- <a href="[linkprev]">{Keyword1|Keyword2|Keyword3}</a><br /><br />
- Add this to your main Shaker Page content, anywhere you would<br />
- like the contextual link to appear. We recommend adding it in the<br />
- content body. Rather then at the beginning or end of the post.<br /><br />
- In future versions, we will be adding more complex interlinking<br />
- structures.<br /><br />
- Why did we do it like this? Because it needs to be kept simple. This<br />
- is how we do it, and it works. You need create relevance in search<br />
- engines for an overall topic. Many people damage their own potential<br />
- rankings, by not following the <b>"less is more"</b> way of doing things.';
- }
- /*function serp_shaker_cleanup () {
- global $wpdb;
- global $seooption;
- if (!empty($text)) {
- echo '<div id="message" class="updated fade"><p>' . $text . '</p></div>';
- }
- echo '<h1>Base Install Cleanup</h1>';
- echo '<span style="color: red">WARNING</span> The button below will delete all posts, pages, categories, and tags. This is usefull if you\'re working on a local install and need a fresh start.<br/>
- Please be sure to <a href="export.php" target="_blank"><strong>export</strong></a> your pages and shaker page if you want to reuse them.<br />
- <form id="Clean-Up" name="Clean-Up" method="post" action="">
- <p>
- <input class="button-primary" type="submit" name="Clean-Up" id="Clean-Up" value="Clean Up" />
- </p>
- </form>'; ?>
- <div class="wrap">
- <div class="metabox-holder postbox-container">
- <h1>SEO Options</h1>
- <form method="post" name="seo_settings">
- <table class="form-table">
- <tr>
- <th align="left">Use Platinum SEO</th>
- <td align="left"><input type="checkbox" name="serp_shaker_platinum_seo"
- <?php
- if ($seooption === 'on') {
- echo "checked";
- }
- ?> /> - enable it if you want to use Platinum SEO. If not you can use any other SEO Plugin but be aware that it may interfere with build time.
- </td>
- </tr>
- </table>
- <input class="button-primary" type="submit" name="SEO-Options" id="SEO-Options" value="Save SEO Options" />
- </form>
- </div>
- </div>
- <?php
- if(isset($_POST['Clean-Up'])) {
- // $tables = array('posts','postmeta','terms','term_relationships','term_taxonomy');
- // foreach ($tables as $table){
- $wpdb->query("TRUNCATE TABLE $wpdb->posts");
- $wpdb->query("TRUNCATE TABLE $wpdb->postmeta");
- $wpdb->query("TRUNCATE TABLE $wpdb->terms");
- $wpdb->query("TRUNCATE TABLE $wpdb->term_relationships");
- $wpdb->query("TRUNCATE TABLE $wpdb->term_taxonomy");
- echo 'Deleted posts, pages, categories and tags. It\'s now ready for a new build<br/>';
- }
- if(isset($_POST['SEO-Options'])) {
- $update_ss_seo_query = update_option('serp_shaker_platinum_seo', $_POST['serp_shaker_platinum_seo']);
- if ($update_ss_seo_query) {
- $text = 'SEO Settings Updated<br />';
- } else {
- $text = __('No Option Updated');
- }
- }
- }*/
- function serp_shaker_updates () {
- echo '<h1>SERP Shaker Updates</h1>';
- echo 'Serp Shaker will be adding Automatic Update ability soon. <br /><br />However, because of the nature of Serp Shaker, we are rolling<br />out updates manually for now. We will be adding the automatic<br />update ability in version 1.08 of Serp Shaker.<br /><br />Please be sure you are on the update list.<br /><br />Serp Shaker will be evolving at a rapid pace until we reach version 1.10.<br />After that, updates will become less frequent and scheduled.<br />We have many more features to add that take time.<br /><br /><b>Please make sure you are on the --> <a href="http://serpshaker.com/updates" target="_blank">Update Notification List</a></b>';
- }
- function serp_shaker_rebuild() { //Contributed by Fever
- //echo "<h1>Updating Category Post Counts</h1>";
- $username = DB_USER; //pulls username from wp-config
- $password = DB_PASSWORD; //pulls password from wp-config
- $server = DB_HOST; //pulls host address from wp-config
- $dB = DB_NAME; //pulls database id from wp-config
- global $wpdb;
- if (function_exists("mysqli_connect")) {
- $connect = mysqli_connect($server, $username, $password,$dB);
- if (!$connect){ //outputs error info should connection fail
- die('Could not connect: ' . mysqli_error($connect));
- } else {
- mysqli_select_db($connect,$dB);
- }
- //DONE CONNECTING
- //Step 2. Recount Posts in Each Category
- $getTaxID = "SELECT * FROM ".$wpdb->prefix."term_taxonomy";
- $getTaxID = mysqli_query($connect,$getTaxID);
- if(!$getTaxID){
- print 'Error: '.mysqli_error($connect);
- }
- while($row = mysqli_fetch_array($getTaxID, MYSQLI_ASSOC)){
- $taxID = $row["term_id"];
- $countTaxPost = "SELECT * FROM ".$wpdb->prefix."term_relationships WHERE term_taxonomy_id = '$taxID'";
- $countTaxPost = mysqli_query($connect,$countTaxPost);
- //Modified to just count the posts using mysqli method.
- $count = mysqli_num_rows($countTaxPost);
- /* $count = 0;
- while($rowCount = mysqli_fetch_array($countTaxPost, MYSQLI_ASSOC)){
- $count++;
- }*/
- $getName = "SELECT * FROM ".$wpdb->prefix."terms WHERE term_id = '$taxID'";
- $getName = mysqli_query($connect,$getName);
- if(!$getName){
- print 'Error: '.mysqli_error($connect);
- }
- $termName;
- while($taxName = mysqli_fetch_array($getName, MYSQLI_ASSOC)){
- $termName = $taxName["name"];
- }
- $updateCount = "UPDATE ".$wpdb->prefix."term_taxonomy SET count = '$count' WHERE term_id = '$taxID'";
- // echo " Category: $termName, $count posts. ";
- $updateCount = mysqli_query($connect,$updateCount);
- if(!$updateCount){
- print "Error: ".mysqli_error($connect);
- }
- }
- echo "<br><br>Update complete.";
- } else {
- $connect = mysql_connect($server, $username, $password);
- if (!$connect){ //outputs error info should connection fail
- die('Could not connect: ' . mysql_error());
- } else {
- mysql_select_db($dB, $connect);
- }
- //DONE CONNECTING
- //Step 2. Recount Posts in Each Category
- $getTaxID = "SELECT * FROM ".$wpdb->prefix."term_taxonomy";
- $getTaxID = mysql_query($getTaxID);
- if(!$getTaxID){
- print 'Error: '.mysql_error();
- }
- while($row = mysql_fetch_array($getTaxID, MYSQL_ASSOC)){
- $taxID = $row["term_id"];
- $countTaxPost = "SELECT * FROM ".$wpdb->prefix."term_relationships WHERE term_taxonomy_id = '$taxID'";
- $countTaxPost = mysql_query($countTaxPost);
- $count = mysql_num_rows($countTaxPost);
- /*while($rowCount = mysql_fetch_array($countTaxPost, MYSQL_ASSOC)){
- $count++;
- } */
- $getName = "SELECT * FROM ".$wpdb->prefix."terms WHERE term_id = '$taxID'";
- $getName = mysql_query($getName);
- if(!$getName){
- print 'Error: '.mysql_error();
- }
- $termName;
- while($taxName = mysql_fetch_array($getName, MYSQL_ASSOC)){
- $termName = $taxName["name"];
- }
- //echo " Category: $termName, $count posts. ";
- $updateCount = "UPDATE ".$wpdb->prefix."term_taxonomy SET count = '$count' WHERE term_id = '$taxID'";
- $updateCount = mysql_query($updateCount);
- if(!$updateCount){
- print "Error: ".mysql_error();
- }
- }
- echo "<br><br>Update complete.";
- }
- }
- function serp_shaker_addons () {
- echo '<h1>SERP ADD ONs</h1>';
- echo '<h1 style="color: red;text-align: center;font-size: 32px;">..:: Coming Soon ::..</h1><br /><br /><br />Serp Shaker is an evergreen product. Add-ons will become available after version 1.10.<br /><br />Serp Shaker is not your typical WordPress plugin...<br /><br />Serp Shaker is going through a process of evolution, to become the top predator in the food chain.';
- }
- // Additional code contributed by Andrew Peacock to the original LPN plugin.
- $sscategorymapping_catName = "";
- $sscategorymapping_postId = 0;
- $sscategorymapping_status = 'future';
- // Add an action to fix "missed schedule" posts
- //add_action('init', 'sscategorymapping_init', 0);
- // Add the meta box in the admin panel
- add_action( 'add_meta_boxes', 'sscategorymapping_add_meta_box' );
- // On save, update the Local Page meta data (which is then used to populate into the individual posts).
- add_action( 'save_post', 'sscategorymapping_save_post', 100);
- // On create SS pages, set the future published date
- add_filter( 'save_post' , 'sscategorymapping_save_post' , 100, 2 );
- //add_filter( 'save_post' , 'sscategorymapping_reset_time', 1, 2);
- add_filter( 'wp_insert_post_data', 'sscategorymapping_wp_insert_post_data', 10, 2); // Only fires when page is manually created
- // Update the post meta data to put the shortcode-base content into each individual post.
- add_action('added_post_meta', 'sscategorymapping_added_post_meta', 100, 4); // Priority 100 so it runs well after SS itself.
- add_action('updated_post_meta', 'sscategorymapping_added_post_meta', 100, 4); // Priority 100 so it runs well after SS itself.
- //function sscategorymapping_init(){
- // global $wpdb;
- //
- // $last = get_option('sscategorymapping_missedchedule', false);
- // if(($last !== false) && ($last > (time() - (2 * 60)))) // Wait 2 minutes of missed schedule before running
- // return;
- //
- // // Update current time
- // update_option('sscategorymapping_missedchedule', time());
- //
- // $missedIDs = $wpdb->get_col(
- // "SELECT `ID` FROM `{$wpdb->posts}` ".
- // "WHERE ( ".
- // " ((`post_date` > 0 )&& (`post_date` <= CURRENT_TIMESTAMP())) OR ".
- // " ((`post_date_gmt` > 0) && (`post_date_gmt` <= UTC_TIMESTAMP())) ".
- // ") AND `post_status` = 'future'"
- // );
- // if(!count($missedIDs)) return;
- // foreach($missedIDs as $missedID){
- // if(!$missedID) continue;
- // wp_publish_post($missedID); //Let's publish missed schedule posts
- // }
- //}
- function sscategorymapping_extract_urls() {
- $txtfile = plugin_dir_path( __FILE__ ) . "output.txt";
- $htmlfile = plugin_dir_path( __FILE__ ) . "output.html";
- $txturl = plugin_dir_url( __FILE__ ) . "output.txt";
- $htmlurl = plugin_dir_url( __FILE__ ) . "output.html";
- if (@$_REQUEST["sscategorymapping_paged"]) {
- $paged = $_REQUEST["sscategorymapping_paged"];
- } else {
- $paged = 1;
- // Empty the output files
- $handle = fopen($txtfile, "w");
- fclose($handle);
- $handle = fopen($htmlfile, "w");
- fclose($handle);
- }
- // Initialise
- $page = 1;
- $txtoutput = "";
- $htmloutput = "";
- // Loop through all published URLs a page at a time till there are no posts.
- do {
- $nextBatch = new WP_Query(array('post_status'=>'publish', 'posts_per_page'=>100, 'paged'=>$page));
- $postsFound = false;
- echo "<BR>Got links " . ((($page-1) * 100)) . " to " . ((($page-1) * 100)+99);
- while ($nextBatch->have_posts()) {
- $postsFound = true;
- $nextBatch->the_post();
- $perm = get_permalink();
- $title = the_title('', '', false);
- // Save the outputs
- $txtoutput .= $perm . "\n";
- $htmloutput .= '<a href="' . $perm . '">' . $title . '</a><br />'. "\n";
- }
- @flush();
- @ob_flush();
- @set_time_limit(0);
- $page++;
- } while($postsFound === true);
- $handle = fopen($txtfile, "a");
- fputs($handle, $txtoutput);
- fclose($handle);
- $handle = fopen($htmlfile, "a");
- fputs($handle, $htmloutput);
- fclose($handle);
- // Echo a link to the file
- echo '<BR /><A href="' . $txturl . '" target="_blank">View results in text format</a>';
- echo '<BR /><A href="' . $htmlurl . '" target="_blank">View results in HTML format</a>';
- // echo '<input class="button-primary" type="submit" name="button" id="button" value="Promote" />';
- /*if (isset($_POST['submit'])){
- $debug = true;
- //read in domain names from doms.txt file:
- $lines = "";
- $file = fopen("$txtfile", "r") or exit("Unable to open doms.txt file!");
- //Output a line of the file until the end is reached:
- $line_no=0;
- while(!feof($file)) {
- $line_no++;
- $line = fgets($file);
- $alllines .= $line."<br>";
- //code to later delete first 100 lines from doms.txt file:
- if($line_no < 100){//if over line 100, store in writelines var to write back to file later.
- /*$writelines .= $line;
- }else{//else line no is NOT over 100, so store line in dom array:*/
- // $uselines .= $line."<br>";
- /* $curURL = trim($line);
- //if cur URL doesn't conain a TLD, add .com
- if(strpos($curURL,".")===false){
- $curURL = $curURL.".com";
- }//end if curURL doesn't have a dot
- $dom_array[] = $curURL;*/
- // }//end else line is under 100 so put in dom array.
- // }//end while reading in lines from doms.txt file
- //fclose($file);
- //if($debug) echo"<h2>Domains taken from dom.txt file:</h2>$uselines<hr>";
- //now rewrite doms.txt file with all but first 100 lines:
- /*$domFile = 'doms.txt';
- $fh = fopen($domFile, 'w') or die("ERROR! Cannot open $domFile file for saving domains back to it!");
- fwrite($fh, $writelines);
- fclose($fh);*/
- //if($debug) echo"Above Domains Deleted from doms.txt file!<hr>";}
- }
- // Priority 1 task to reset the delay each time the "build" button is pressed.
- //function sscategorymapping_reset_time($post_id, $post) {
- // global $sscategorymapping_status;
- //
- // // Only continue if the post type is a local page
- // $type = get_post_type($post_id);
- // if ($type == 'shaker-page') {// Add the delay (in minutes)
- // // Check if build or unbuild buttons clicked.
- // if (isset($_POST['build']) AND $_POST['build'] == 'Build Pages / Posts') {
- // // Get current time
- // $nextPostTime = sscategorymapping_get_local_time(); // 1 minute ago
- //
- // // Save back to the parent localpage
- // update_post_meta($post_id, "ssdelayedpublishlast", $nextPostTime);
- //
- // // Reset the scheduled status
- // $sscategorymapping_status = 'publish';
- // }
- // }
- //}
- /* Adds a box to the main column on the Post and Page edit screens */
- function sscategorymapping_add_meta_box() {
- /* add_meta_box(
- 'sscategorymapping_add_meta_box_category',
- 'SS Category Shortcode',
- 'sscategorymapping_rendermetabox_category',
- 'shaker-page',
- 'side',
- 'high'
- );*/
- // add_meta_box(
- // 'sscategorymapping_add_meta_box_delayedpublish',
- // 'SS Delayed Publish',
- // 'sscategorymapping_rendermetabox_delayedpublish',
- // 'shaker-page',
- // 'side',
- // 'high'
- // );
- add_meta_box(
- 'sscategorymapping_add_meta_box_deletetrash',
- 'SS Delete Trash',
- 'sscategorymapping_rendermetabox_deletetrash',
- 'shaker-page',
- 'side',
- 'high'
- );
- }
- // Save the SSshortcode-based category name and delayed post schedule into the meta data field (for the local page only).
- function sscategorymapping_save_post($post_id, $post) {
- // Only continue if the post type is a local page
- $type = get_post_type($post_id);
- if ($type == 'shaker-page') {
- // Save post meta for plugin
- /* $sscategorymapping_categoryname = trim(@$_POST['sscategorymapping_categoryname']);
- // $sscategorymapping_parentcategoryname = trim(@$_POST['sscategorymapping_parentcategoryname']);
- update_post_meta($post_id, 'sscategoryname', $sscategorymapping_categoryname);
- // update_post_meta($post_id, 'ssparentcategoryname', $sscategorymapping_parentcategoryname);
- //$sscategorymapping_delayedpublish = trim(@$_POST['sscategorymapping_delayedpublish']);
- //update_post_meta($post_id, 'ssdelayedpublish', $sscategorymapping_delayedpublish);*/
- // Do we want to delete the trash?
- if (isset($_POST['deletetrash']) AND $_POST['deletetrash'] == 'Delete Trash') {
- global $wpdb;
- //check_admin_referer('empty_trash_update');
- $result=$wpdb->query("DELETE FROM $wpdb->posts WHERE post_status = 'trash'");
- }
- }
- }
- /*function sscategorymapping_rendermetabox_category() {
- // Get the post ID
- global $post ;
- $post_id = $post->ID;
- $sscategorymapping_categoryname = trim(get_post_meta($post_id, 'sscategoryname', true));
- //$sscategorymapping_parentcategoryname = trim(get_post_meta($post_id, 'ssparentcategoryname', true));
- // The actual fields for data entry
- echo '<label for="sscategorymapping_categoryname">';
- echo 'Enter your shortcode for the category name (eg, <strong>{state}</strong>)';
- echo '</label><br />';
- echo '<input type="text" id="sscategorymapping_categoryname" name="sscategorymapping_categoryname" value="' . $sscategorymapping_categoryname . '" size="25" />';
- /*echo '<br /><br /><strong>Advanced: </strong>If you\'d like a more in-depth SILO, enter the parent category name as well';
- echo '</label><br />';
- echo '<input type="text" id="sscategorymapping_parentcategoryname" name="sscategorymapping_parentcategoryname" value="' . $sscategorymapping_parentcategoryname . '" size="25" />';
- }*/
- //function sscategorymapping_rendermetabox_delayedpublish() {
- // // Get the post ID
- // global $post ;
- // $post_id = $post->ID;
- //
- // $sscategorymapping_delayedpublish = trim(get_post_meta($post_id, 'ssdelayedpublish', true));
- //
- // // The actual fields for data entry
- // echo '<label for="sscategorymapping_delayedpublish">';
- // echo 'Enter the number of minutes delay between each post (eg enter 60 for one every hour)';
- // echo '</label><br />';
- // echo '<input type="text" id="sscategorymapping_delayedpublish" name="sscategorymapping_delayedpublish" value="' . $sscategorymapping_delayedpublish . '" size="25" />';
- //}
- function sscategorymapping_rendermetabox_deletetrash() {
- // The actual fields for data entry
- echo '<label for="sscategorymapping_deletetrash">';
- echo 'Click here to delete the trash posts and pages.';
- echo '<p><input name="deletetrash" type="submit" class="button button-highlighted" id="deletetrash" value="Delete Trash" /></p>';
- }
- // This takes the data from the 'sscategoryname' meta data, which already has the shortcode value turned into the specific text, then
- // creates and/or assigns the category
- function sscategorymapping_added_post_meta($meta_id, $post_id, $meta_key, $meta_value) {
- // Ignore when saving local pages
- $type = get_post_type($post_id);
- if ($type == "shaker-page") return;
- // Ignore if the meta key is not "lnpcategoryname"
- switch ($meta_key) {
- case "sscategoryname":
- // Get the category name and delay
- $sscategorymapping_catName = $meta_value;
- // Do nothing if there is no category name
- if (trim($sscategorymapping_catName) <> "") {
- // Get category ID
- $catID = get_cat_ID( $sscategorymapping_catName ) ;
- if ($catID == 0) {
- // Create the category
- $catID = wp_create_category( $sscategorymapping_catName );
- }
- // Now assign the post to the category
- //wp_set_object_terms($post_id,$catID,'category');
- wp_set_post_categories( $post_id, array($catID));
- }
- break;
- }}
- function sscategorymapping_get_local_time() {
- return strtotime(current_time('mysql')) + 120; // 1 minute from now
- }
- // Update the future scheduled date of newly-generated SS posts
- function sscategorymapping_wp_insert_post_data($data, $postarr) {
- global $sscategorymapping_status;
- // Only continue if the current post type is a local page
- global $post;
- @$submittedPostId = $post->ID;
- $type = get_post_type($submittedPostId);
- // If the user is creating a page, post, or other content, then exit
- if ($type != 'shaker-page') {
- return $data;
- }
- // Check if build or unbuild buttons clicked.
- if (isset($_POST['build']) AND $_POST['build'] == 'Build Pages / Posts') {
- // Now exit if the submitted post is a post or page
- $type = $data["post_type"];
- if ( ($type != "post") && ($type != "page")) return $data;
- // Check if a delay is enabled
- // $sscategorymapping_delay = (int) $_POST["sscategorymapping_delayedpublish"];
- // if ($sscategorymapping_delay > 0) {
- //
- // // Get the latest post time, or set it to now if not available
- // $nextPostTime = get_post_meta($submittedPostId, "ssdelayedpublishlast", true);
- // if ($nextPostTime == "") {
- // $nextPostTime = sscategorymapping_get_local_time(); // time(); //strtotime(gmdate('Y-m-d H:i:s')); // strtotime($data['post_date']); // strtotime(current_time('mysql'));
- // }
- //
- //
- // // Update the actual post data
- // $ds_gmt = get_gmt_from_date(date('Y-n-j G:i:s', $nextPostTime));
- // $data['post_date'] = date_i18n('Y-n-j G:i:s', $nextPostTime);
- // $data['post_date_gmt'] = $ds_gmt;
- // $data['post_status'] = $sscategorymapping_status;
- //
- // // Save the new time back to the parent localpage
- // // Add the delay (in minutes)
- // $nextPostTime = $nextPostTime + ($sscategorymapping_delay * 60);
- // update_post_meta($submittedPostId, "ssdelayedpublishlast", $nextPostTime);
- //
- // // And now we've done at least one post, set the post_status to 'future'
- // $sscategorymapping_status = 'future';
- //
- // }
- }
- return $data;
- }
- // end Andrew Peacock Code
- function ss_linknext() {
- $ssnextpost = get_permalink(ss_adjacent_post(true,'',true));
- return $ssnextpost;
- }
- function ss_linkprev() {
- $ssprevpost = get_permalink(ss_adjacent_post(true,'',false));
- return $ssprevpost;
- }
- function ss_ad_handler( $atts ) {
- global $wpdb;
- $query = "SELECT adData FROM " . $wpdb->prefix . "ss_ads WHERE adname = '" . $atts['ssadblk'] . "'";
- $getad = $wpdb->get_var($query);
- // echo $getad;
- // echo $atts['ssadblk'];
- return stripslashes($getad);
- }
- function ss_dyna_handler( $atts ) {
- global $wpdb;
- $query = "SELECT shortcodeData FROM " . $wpdb->prefix . "ss_dynamicodes WHERE shortcode = '" . $atts['dynami'] . "'";
- $getdynamic = $wpdb->get_var($query);
- $spintax = new SS_Spintax();
- $newdynami = $spintax->process($getdynamic);
- return stripslashes($newdynami);
- }
- /**
- * Google Maps Shortcode
- */
- function SSmapcode($atts) {
- $SScitystate = str_replace(" ", "+", $atts['location']);
- $SSmapcode = <<< SSmap
- <div style="float: left; padding: 10px;"><div style="width:250px;height:250px;margin-left: 10px; margin-right: 10px;"><iframe width="250" height="250" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=$SScitystate&ie=UTF8&z=12&t=m&iwloc=near&output=embed"></iframe><br></div></div>
- SSmap;
- return $SSmapcode;
- }
- function SSWeather( $atts ) {
- // Attributes
- extract( shortcode_atts(
- array(
- 'country' => 'us',
- 'state' => '',
- 'city' => '',
- ), $atts )
- );
- // Code
- $city = urlencode(ucwords($city));
- $state = urlencode(ucwords($state));
- $date = date("Y-m-d");
- $weather = '<script type="text/javascript" src="http://www.showmyweather.com/weather_widget.php?int=0&type=js&country=' . $country . '&state=' . $state . '&city=' . $city . '&smallicon=1¤t=1&forecast=1&background_color=ffffff&color=000000&width=175&padding=10&border_width=1&border_color=000000&font_size=11&font_family=Verdana&showicons=1&measure=F&d=' . $date . '"></script>';
- return $weather;
- }
- // Add Shortcode
- function SSyoutube( $atts ) {
- // Attributes
- extract( shortcode_atts(
- array(
- 'keyword' => '',
- 'title' => '',
- 'width' => '420',
- 'height' => '325',
- ), $atts )
- );
- // Code
- /*$youtubequery = urlencode(strtolower($keyword));
- $youtuberesponse = file_get_contents("http://gdata.youtube.com/feeds/api/videos?q=" . $youtubequery);
- $youtubefeed = simplexml_load_string($youtuberesponse);
- $youtubeitemparts = explode("/",$youtubefeed->entry[rand(1,10)]->id);
- $youtubevideoid = $youtubeitemparts[count($youtubeitemparts) - 1];*/
- $youtube_api_search_url = "https://www.googleapis.com/youtube/v3/search";
- $youtube_api_videos_url = "https://www.googleapis.com/youtube/v3/videos";
- if (get_option( 'ss_youtube_api' ) != NULL ) {
- $apikey = get_option( 'ss_youtube_api' );
- $wp_remote_args = array(
- 'user-agent' => 'Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0',
- 'httpversion' => '1.1',
- );
- # find new video
- $video_id = '';
- # set params
- $params = array(
- 'part' => 'id',
- 'fields' => 'items/id/videoId',
- 'q' => rawurlencode($keyword),
- 'type' => 'video',
- 'videoEmbeddable' => 'true',
- 'maxResults' => 10,
- 'key' => $apikey,
- );
- $content = wp_remote_get(add_query_arg($params, $youtube_api_search_url), $wp_remote_args);
- if (!is_wp_error($content))
- {
- $content = json_decode(wp_remote_retrieve_body($content));
- # if we found video id
- if (isset($content->items[0]->id->videoId))
- {
- $video_id = $content->items[rand(0,10)]->id->videoId;
- }
- }
- $video = '<div itemprop="video" itemscope="" itemtype="http://schema.org/VideoObject">
- <h2>Video: <span itemprop="name">' . $title . '</span></h2>
- <meta itemprop="thumbnailUrl" content="http://i.ytimg.com/vi/' . $video_id . '/hqdefault.jpg">
- <meta itemprop="embedUrl" content="http://www.youtube.com/v/' . $video_id . '">
- <embed src="http://www.youtube.com/v/' . $video_id . '" type="application/x-shockwave-flash" height="' . $height . '" width="' . $width . '">
- <span itemprop="description"></span>
- </div>';
- }
- else {
- $video = NULL;
- }
- return $video;
- }
- function next_page_shortcode($attributes) {
- extract(shortcode_atts(array(
- 'anchor' => '',
- 'loop' => 'cousin',
- 'get_pages_query' => 'sort_column=menu_order&sort_order=asc'
- ), $attributes));
- return next_ss_page($anchor,$loop, $get_pages_query);
- }
- function previous_page_shortcode($attributes) {
- extract(shortcode_atts(array(
- 'anchor' => '',
- 'loop' => 'cousin',
- 'get_pages_query' => 'sort_column=menu_order&sort_order=asc'
- ), $attributes));
- return previous_ss_page($anchor,$loop, $get_pages_query);
- }
- function SSsubpages(){
- global $id;
- $subpages = '<ul>' . wp_list_pages("title_li=&child_of=$id&show_date=modified
- &date_format=$date_format&echo=0") . '</ul>';
- return $subpages;
- }
- /*function SSrelatedpages($attributes){
- extract(shortcode_atts(array(
- 'parent' => ''), $attributes));
- $page = get_page_by_title($parent);
- $post_parent = $page->ID;
- $howmany = 5;
- $pages = wp_list_pages("title_li=&child_of=$post_parent&echo=0");
- $pages_arr = explode("\n", $pages);
- for($i=0;$i<$howmany;$i++){
- $relatedpages .= $pages_arr[$i];
- $pages_arr = explode("\n", $pages);
- for($i=0;$i<$howmany;$i++){
- $relatedpages .= $pages_arr[$i];
- }
- return $relatedpages;
- $ss_page_view = $relatedpages
- $content = $content . "<br><br>" . $ss_page_view;
- return $content;
- }
- }
- add_filter('the_content','SSrelatedpages');*/
- function ss_get_pages($attributes) {
- extract(shortcode_atts(array(
- 'parent' => ''), $attributes));
- $page = get_page_by_title($parent);
- $post_parent = $page->ID;
- $howmany = 5;
- $pages = wp_list_pages("title_li=&child_of=$post_parent&exclude=$id&echo=0");
- $pages_arr = explode("\n", $pages);
- shuffle($pages_arr);
- for($i=0;$i<$howmany;$i++){
- $relatedpages .= $pages_arr[$i];
- }
- return $relatedpages;
- }
- /*function ss_get_pages($attributes) {
- extract(shortcode_atts(array(
- 'parent' => ''), $attributes));
- $page = get_page_by_title($parent);
- $post_parent = $page->ID;
- global $post;
- $query = new WP_Query( array( 'orderby' => 'rand', 'posts_per_page' => 5, 'post_type' => 'page', 'post_parent' => $post_parent )) ;
- if ( $query->have_posts() ) {
- echo '<ul>';
- while ( $query->have_posts() ) {
- $query->the_post();
- echo '<li>' . get_the_title() . '</li>';
- }
- echo '</ul>';
- } else {
- //no posts found
- }
- }*/
- /*function ss_child_pages($content) {
- $ss_page_view = ss_get_pages();
- $content = $content . "<br><br>" . $ss_page_view;
- return $content;
- }
- add_filter('the_content','ss_child_pages');*/
- function ss_register_shortcodes() {
- add_shortcode( 'linknext', 'ss_linknext' );
- add_shortcode( 'linkprev', 'ss_linkprev' );
- add_shortcode( 'ssad', 'ss_ad_handler' );
- add_shortcode( 'dyna', 'ss_dyna_handler' );
- add_shortcode('google-map', 'SSmapcode');
- add_shortcode('subpages', 'SSsubpages');
- add_shortcode('relatedpages', 'ss_get_pages');
- add_shortcode( 'ssvideo', 'SSyoutube' );
- add_shortcode('next_page', 'next_page_shortcode');
- add_shortcode('previous_page', 'previous_page_shortcode');
- add_shortcode('weather', 'SSWeather');
- add_shortcode('sspostsincat', 'ssPagesByCategory');
- }
- function ss_preset_options() {
- if (get_option(SS_WORDAI_OPTIONS) === false) {
- $options = array(
- 'plan' => 'standard',
- 'standard_quality' => '50',
- 'turing_quality' => 'Readable',
- 'email' => '',
- 'pass' => '',
- 'nonested' => '',
- 'sentence' => 'on',
- 'paragraph' => '',
- 'returnspin' => 'true',
- 'nooriginal' => 'on',
- 'protected' => '',
- 'synonyms' => '',
- );
- ss_set_option(SS_WORDAI_OPTIONS, $options, '', 'yes');
- }
- if (get_option(SS_SPIN_REWRITER_OPTIONS) === false) {
- $options = array(
- 'confidence_level' => 'medium',
- 'nested' => 'false',
- 'sentence' => 'false',
- 'email' => '',
- 'apikey' => '',
- 'paragraph' => 'false',
- 'auto_new_paragraphs' => 'false',
- 'auto_sentence_trees' => 'false',
- 'capitalized' => 'false',
- 'protected' => '',
- );
- ss_set_option(SS_SPIN_REWRITER_OPTIONS, $options, '', 'yes');
- }
- }
- function ss_set_option($option_name, $newvalue, $deprecated, $autoload) {
- if (get_option($option_name) === false) {
- add_option($option_name, $newvalue, $deprecated, $autoload);
- } else {
- update_option($option_name, $newvalue);
- }
- }
- $ss_wa_options = get_option(SS_WORDAI_OPTIONS);
- function ss_wordai($content) {
- global $ss_wa_options;
- $text = urlencode($content);
- if ($ss_wa_options['plan'] == 'turing') {
- $ch = curl_init('http://wordai.com/users/turing-api.php');
- $quality = $ss_wa_options['turing_quality'];
- } else {
- $ch = curl_init('http://wordai.com/users/regular-api.php');
- $quality = $ss_wa_options['standard_quality'];
- }
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, "s=$text&quality=$quality&email=" . $ss_wa_options['email'] . "&pass=" . $ss_wa_options['pass'] . "&nonested=" . $ss_wa_options['nonested'] . "&sentence=" . $ss_wa_options['sentence'] . "¶graph=" . $ss_wa_options['returnspin'] .
- "&returnspin=false&nooriginal=" . $ss_wa_options['nooriginal'] .
- "&protected=" . urlencode($ss_wa_options['protected']) . "&synonyms=" . urlencode($ss_wa_options['synonyms']) . "&output=json");
- $response = trim(curl_exec($ch));
- curl_close($ch);
- $api_response_interpreted = json_decode($response, true);
- if ($api_response_interpreted['status'] == 'Success') {
- return $api_response_interpreted['text'];
- }
- return $content;
- }
- $ss_sr_options = get_option(SS_SPIN_REWRITER_OPTIONS);
- add_action('init', 'userID');
- function userID(){
- $user_ID= get_current_user_id();
- }
- function ss_spinrewriter($content) {
- global $ss_sr_options;
- $text = urlencode($content);
- $ch = curl_init('http://www.spinrewriter.com/action/api');
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, "action=text_with_spintax&text=$text&email_address=" . $ss_sr_options['email'] . "&api_key=" . $ss_sr_options['apikey'] . "&confidence_level=" . $ss_sr_options['confidence_level'] . "&nested_spintax=" . $ss_sr_options['nested'] . "&auto_sentences=" . $ss_sr_options['sentence'] .
- "&auto_paragraphs=" . $ss_sr_options['paragraph'] ."&auto_new_paragraphs=" . $ss_sr_options['auto_new_paragraphs'] ."&auto_sentence_trees=" . $ss_sr_options['auto_sentence_trees'] ."&protected_terms=" . urlencode(str_replace("," , "\n" ,$ss_sr_options['protected'])) . "&auto_protected_terms=" . $ss_sr_options['capitalized'] . "");
- $response = trim(curl_exec($ch));
- curl_close($ch);
- $api_response_interpreted = json_decode($response, true);
- if ($api_response_interpreted['status'] == 'OK') {
- return $api_response_interpreted['response'];
- }
- return $content;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement