/** * Save post meta. * * @param int $post_id * @param object $post */ public static function save_post($post_id = null, $post = null) { if (!(defined("DOING_AUTOSAVE") && DOING_AUTOSAVE)) { if ($post->post_type == 'camp_bulkposter') { if ($post->post_status != 'auto-draft') { # keyword meta post $keyword = isset($_POST['keyword']) ? trim($_POST['keyword']) : ''; delete_post_meta($post_id, 'keyword'); if (!empty($keyword)) { add_post_meta($post_id, 'keyword', $keyword); } # Count meta post $count = isset($_POST['count']) ? trim($_POST['count']) : ''; delete_post_meta($post_id, 'count'); if (!empty($count)) { add_post_meta($post_id, 'count', $count); } # Category ID $category_id = isset($_POST['category_id']) ? trim($_POST['category_id']) : ''; delete_post_meta($post_id, 'category_id'); if (!empty($category_id)) { add_post_meta($post_id, 'category_id', $category_id); } # Post Status $status = isset($_POST['status']) ? trim($_POST['status']) : ''; delete_post_meta($post_id, 'status'); if (!empty($status)) { add_post_meta($post_id, 'status', $status); } # Post Type $ktzplg_post_type = isset($_POST['ktzplg_post_type']) ? trim($_POST['ktzplg_post_type']) : ''; delete_post_meta($post_id, 'ktzplg_post_type'); if (!empty($ktzplg_post_type)) { add_post_meta($post_id, 'ktzplg_post_type', $ktzplg_post_type); } # Schedule Post $ktzplg_next = isset($_POST['ktzplg_next']) ? trim($_POST['ktzplg_next']) : ''; delete_post_meta($post_id, 'ktzplg_next'); if (!empty($ktzplg_next)) { add_post_meta($post_id, 'ktzplg_next', $ktzplg_next); } $ktzplg_next_time = isset($_POST['ktzplg_next_time']) ? trim($_POST['ktzplg_next_time']) : ''; delete_post_meta($post_id, 'ktzplg_next_time'); if (!empty($ktzplg_next_time)) { add_post_meta($post_id, 'ktzplg_next_time', $ktzplg_next_time); } # Logical insert post after Publish campaign if (!empty($count) && !empty($keyword)) { $keyword = explode("\n", $keyword); # Rand Keyword Submission if (count($keyword > 0)) { shuffle($keyword); $keyword = array_slice($keyword, 0, $count); } foreach ($keyword as $kwd) { $title = sanitize_title($kwd); $title = str_replace('-', ' ', $title); $title = ucwords($title); # https://developer.wordpress.org/reference/functions/post_exists/ $post_id = post_exists($title); $content = Ktzagcplugin_Option::get_option('ktzplg_agc_content'); $replace_with_this = ' keyword="' . $title . '"]'; $content_wow = str_replace(']', $replace_with_this, $content); $content = do_shortcode($content_wow); # if not post same keyword do it.. if (!$post_id) { # Insert post => ktzplg_insert_post ( $post_type='', $title = '', $status = '', $category_id = array() , $content = '', $author = '' ); ktzplg_insert_post($ktzplg_post_type, $title, $status, array($category_id), $content, 1); } } # end if foreach ( $keyword as $kwd ) } # end if !empty( $count ) && !empty( $keyword ) } # end if ( $post->post_status != 'auto-draft' ) } } }
function ktzplg_get_random_term($numb = 10) { # update option from ktzplg_stt2_db_save_searchterms in ktzagcplugin-module-stt2 $data_searchterm = get_option('ktzplg_agcplg_searchterm'); $output = ''; if (!empty($data_searchterm) && count($data_searchterm) >= $numb) { $output .= '<ul class="ktzplg-randomterm">'; foreach ($data_searchterm as $keyword) { $output .= '<li>'; $output .= '<a href="' . ktzplg_permalink($keyword, $choice = 'default') . '" rel="nofollow">' . esc_html($keyword) . '</a>'; $output .= '</li>'; } $output .= '</ul>'; } else { $data_searchterm_fromoption = Ktzagcplugin_Option::get_option('ktzplg_rand_keyword'); if (!empty($data_searchterm_fromoption)) { # This solution for use multiple explode $keyword_fromoption = explode("\n", $data_searchterm_fromoption); shuffle($keyword_fromoption); $keyword_fromoption = array_slice($keyword_fromoption, 0, $numb, true); $output .= '<ul class="ktzplg-randomterm">'; foreach ($keyword_fromoption as $keyword) { $output .= '<li>'; $output .= '<a href="' . ktzplg_permalink($keyword, $choice = 'default') . '">' . $keyword . '</a>'; $output .= '</li>'; } $output .= '</ul>'; } } return $output; }
/** * Add nofollow in head this function will stop search engine to index your website. * https://support.google.com/webmasters/answer/96569?hl=en */ function ktzplg_nofollow_inheader() { # Get nofollow from options $data_nofollow_fromoption = Ktzagcplugin_Option::get_option('ktzplg_nofollow_head'); if ($data_nofollow_fromoption != '') { $ktzplg_nofollow[] = '<!-- Add Nofollow by ktzagcplugin -->'; $ktzplg_nofollow[] = '<meta name="robots" content="nofollow" />'; $ktzplg_nofollow[] = ''; } else { $ktzplg_nofollow[] = ''; } echo implode("\n", $ktzplg_nofollow); }
/** * Check whether the search term contain forbidden word * @return $term **/ function ktzplg_filter_badwords($term) { $option = Ktzagcplugin_Option::get_option('ktzplg_badword'); # if option empty define KTZPLG_BADWORDS (default option in ktzagcplugin.php) $option = empty($option) ? KTZPLG_BADWORDS : $option; $badwords = explode(',', $option); foreach ($badwords as $bad) { $term = str_ireplace($bad . ' ', '', $term); $term = str_ireplace(' ' . $bad . ' ', '', $term); $term = str_ireplace(' ' . $bad, '', $term); $term = str_ireplace($bad, '.', $term); $term = str_ireplace($bad, ',', $term); $term = str_ireplace($bad, '-', $term); } return $term; }
/** * Google API Request * @param boolean $test * @return array */ function ktzplg_search_request($posts, $q) { if ($q->is_single !== true && $q->is_search === true) { global $wp_query; $query = html_entity_decode(get_search_query()); # Set query if any passed $keywords = isset($query) ? str_replace(' ', '+', $query) : ''; /* * @str_get_html Simple HTML DOM and get url via ktzplg_fetch_agc ( curl and fopen ) * ktzplg_fetch_agc find in _functions.php */ # option source AGC in search page $agcsource_option = Ktzagcplugin_Option::get_option('ktzplg_agc_searchresults'); if ($agcsource_option == 'bing') { $fetch = ktzplg_fetch_agc('http://www.bing.com/search?q=' . $keywords); } elseif ($agcsource_option == 'ask') { $fetch = ktzplg_fetch_agc('http://www.ask.com/web?q=' . $keywords); } else { $fetch = ktzplg_fetch_agc('http://www.google.com/search?hl=en&q=' . $keywords); } $html = new simple_html_dom(); $html->load($fetch); //Simple HTML now use the result craped by cURL. $result = array(); if ($html && is_object($html)) { if ($agcsource_option == 'bing') { foreach ($html->find('li.b_algo') as $g) { /* * each search results are in a list item with a class name 'g' * we are seperating each of the elements within, into an array * Summaries are stored in a p * Summaries are stored in h2 a */ $item['title'] = isset($g->find('h2 a', 0)->innertext) ? $g->find('h2 a', 0)->innertext : ''; $item['description'] = isset($g->find('p', 0)->innertext) ? $g->find('p', 0)->innertext : ''; $result[] = $item; } } elseif ($agcsource_option == 'ask') { foreach ($html->find('div.web-result') as $g) { /* * each search results are in a list item with a class name 'g' * we are seperating each of the elements within, into an array * Summaries are stored in a p with a classname of 'web-result-description' * title are stored in a with a classname of 'web-result-title-link' */ $item['title'] = isset($g->find('a.web-result-title-link', 0)->innertext) ? $g->find('a.web-result-title-link', 0)->innertext : ''; $item['description'] = isset($g->find('.web-result-description', 0)->innertext) ? $g->find('.web-result-description', 0)->innertext : ''; $result[] = $item; } } else { foreach ($html->find('div.g') as $g) { /* * each search results are in a list item with a class name 'g' * we are seperating each of the elements within, into an array * Summaries are stored in a span with a classname of 'st' * Title are stored in a h3 with a classname of 'r' */ $item['title'] = isset($g->find('h3.r', 0)->innertext) ? $g->find('h3.r', 0)->innertext : ''; $item['description'] = isset($g->find('span.st', 0)->innertext) ? $g->find('span.st', 0)->innertext : ''; $result[] = $item; } } # endif $agcsource_option // Clean up memory $html->clear(); unset($html); /* * Otherwise it prints out the array structure so that it * is more human readible. You could instead perform a * foreach loop on the variable $result so that you can * organize the html output, or insert the data into a database */ if ($result) { $results = array(); $i = 0; foreach ($result as $r) { $post = get_post($ID); $result_title = ktzplg_filter_badwords($r['title']); $result_title = sanitize_title($result_title); $result_title = str_replace('-', ' ', $result_title); $result_title = ktzplg_plugin_clean_character($result_title); $result_title = ucwords($result_title); $result_desc = ktzplg_filter_badwords($r['description']); $format = get_option('date_format') . ' ' . get_option('time_format'); $post_date = date_i18n($format, current_time('timestamp')); if (empty($post)) { $post = (object) array('post_type' => 'post', 'post_title' => $result_title, 'post_date' => $post_date, 'post_category' => 1, 'post_author' => 1, 'post_status' => 'published', 'post_excerpt' => $result_desc, 'post_content' => $result_desc, 'guid' => ktzplg_permalink($result_title, $choice = 'default'), 'ID' => 0, 'comment_status' => 'closed'); } if (++$i == 8) { break; } $results[] = $post; } $post = ''; // Set results as posts $posts = $results; $results = ''; // Update post count $wp_query->post_count = count($posts); $wp_query->found_posts = 8; // Apply filters add_filter('the_permalink', 'ktzplg_search_permalink'); add_filter('post_link', 'ktzplg_search_permalink'); } } } return $posts; }
/** * Rich Editor Callback * * Renders rich editor fields. * * @since 1.0.0 * @param array $args Arguments passed by the setting * @global $wp_version WordPress Version */ public function rich_editor_callback($args) { global $wp_version; $value = Ktzagcplugin_Option::get_option($args['id'], $args['std']); if ($wp_version >= 3.3 && function_exists('wp_editor')) { ob_start(); wp_editor(stripslashes($value), $this->snake_cased_ktzagcplugin . '_settings_' . $args['id'], array('textarea_name' => $this->snake_cased_ktzagcplugin . '_settings[' . $args['id'] . ']', 'textarea_rows' => 8)); $html = ob_get_clean(); } else { $html = '<textarea' . $this->get_id_and_name_attrubutes($args['id']) . 'class="' . $args['size'] . '-text" rows="5">' . esc_textarea(stripslashes($value)) . '</textarea>'; } $html .= '<br/>'; $html .= $this->get_label_for($args['id'], $args['desc']); $html .= '<br/>'; echo $html; }
/** * Category Select Callback * * Renders select category fields. * * @since 1.0.0 * @param array $args Arguments passed by the setting * @return void */ public function category_select_callback($args) { $value = Ktzagcplugin_Option::get_option($args['id'], $args['std']); $blog_categories = get_categories(array('orderby' => 'id', 'hide_empty' => 0)); $html = '<select ' . $this->get_id_and_name_attrubutes($args['id']) . '/>'; foreach ($blog_categories as $category) { $html .= '<option value="' . $category->term_id . '" ' . selected($category->term_id, $value, false) . '>' . $category->name . '</option>'; } $html .= '</select>'; $html .= '<br />'; $html .= $this->get_label_for($args['id'], $args['desc']); echo $html; }
function ktzplg_lets_start_autopost($camp_id) { $arr = array($camp_id); $args = array('post_type' => 'camp_bulkposter', 'post_status' => 'publish', 'post__in' => $arr); $myposts = get_posts($args); if ($myposts) { foreach ($myposts as $post) { setup_postdata($post); $keyword = get_post_meta($post->ID, 'keyword', true); if (empty($keyword)) { $keyword = ''; } $count = get_post_meta($post->ID, 'count', true); if (empty($count)) { $count = 1; } # get category id meta post $category_id = get_post_meta($post->ID, 'category_id', true); if (empty($category_id)) { $category_id = 1; } # get status meta post $status = get_post_meta($post->ID, 'status', true); if (empty($status)) { $status = 'publish'; } # get post_type meta post $ktzplg_post_type = get_post_meta($post->ID, 'ktzplg_post_type', true); if (empty($ktzplg_post_type)) { $status = 'post'; } # Logical insert post after Publish campaign if (!empty($count) && !empty($keyword)) { $keyword = explode("\n", $keyword); # Rand Keyword Submission if (count($keyword > 0)) { shuffle($keyword); $keyword = array_slice($keyword, 0, $count); } foreach ($keyword as $kwd) { # get title via keyword $title = sanitize_title($kwd); $title = str_replace('-', ' ', $title); $title = ucwords($title); $args = array('post_type' => $ktzplg_post_type, 'post_status' => 'publish'); $myposts = get_posts($args); # get content via plugin settings $content = Ktzagcplugin_Option::get_option('ktzplg_agc_content'); $replace_with_this = ' keyword="' . $title . '"]'; $content_wow = str_replace(']', $replace_with_this, $content); $content = do_shortcode($content_wow); # if not post same keyword do it.. if (!get_page_by_title($title, 'OBJECT', $ktzplg_post_type)) { # Insert post => ktzplg_insert_post ( $post_type='', $title = '', $status = '', $category_id = array() , $content = '', $author = '' ); ktzplg_insert_post($ktzplg_post_type, $title, $status, array($category_id), $content, 1); } } # end if foreach ( $keyword as $kwd ) } # end if !empty( $count ) && !empty( $keyword ) } # end if foreach ( $myposts as $post ) wp_reset_postdata(); } }