Google
Edit File: converter.php
<?php /** * Generated by the WordPress Option Page generator * */ function mediawhale_cron_schedules($schedules){ if(!isset($schedules["20sec"])){ $schedules["20sec"] = array( 'interval' => 1*20, 'display' => __('Once every 20 seconds')); } return $schedules; } add_filter('cron_schedules','mediawhale_cron_schedules'); function mediawhale_all_converter_ajax_request() { // The $_REQUEST contains all the data sent via ajax if ( isset($_REQUEST) ) { if (! wp_next_scheduled ( 'mediawhale_converter_event', $args )) { wp_schedule_event( time(), '20sec', 'mediawhale_converter_event' ); update_option('mediawhale_status','started'); } } // Always die in functions echoing ajax content die(); } add_action( 'wp_ajax_mediawhale_all_converter_ajax_request', 'mediawhale_all_converter_ajax_request' ); // If you wanted to also use the function for non-logged in users (in a theme for example) add_action( 'wp_ajax_nopriv_mediawhale_all_converter_ajax_request', 'mediawhale_all_converter_ajax_request' ); function mediawhale_select_converter_ajax_request() { // The $_REQUEST contains all the data sent via ajax if ( isset($_REQUEST) ) { $get_specific_posts = $_REQUEST['post_ids']; if(!empty($get_specific_posts)){ // do something every hour $query = new WP_Query(array('post_type'=>'post','post__in'=> $get_specific_posts)); if($query->have_posts()){ while($query->have_posts()){ $query->the_post(); $data = array(); $data['post_title'] = get_the_title(); $data['post_id'] = get_the_ID(); $data['post_content'] = apply_filters('the_content', get_post_field('post_content', get_the_ID())); error_log(print_r($data, true)); $response = mediawhale_convert_function($data); if ( is_wp_error( $response ) ) { $error_message = $response->get_error_message(); } else { $body_content = json_decode(wp_remote_retrieve_body($response)); if($body_content->type == '200'){ update_post_meta(get_the_ID(),'converted_audio',sanitize_text_field($body_content->postid)); update_post_meta(get_the_ID(),'mediawhaleconvert-to-audio','yes'); } } sleep(2); } } update_option('mediawhale_select_posts',''); wp_clear_scheduled_hook( 'mediawhale_select_converter_event' ); update_option('mediawhale_select_status','stopped'); } wp_reset_postdata(); wp_reset_query(); } // Always die in functions echoing ajax content die(); } add_action( 'wp_ajax_mediawhale_select_converter_ajax_request', 'mediawhale_select_converter_ajax_request' ); // If you wanted to also use the function for non-logged in users (in a theme for example) add_action( 'wp_ajax_nopriv_mediawhale_select_converter_ajax_request', 'mediawhale_select_converter_ajax_request' ); function mediawhale_stop_converter_ajax_request() { // The $_REQUEST contains all the data sent via ajax if ( isset($_REQUEST) ) { if (! wp_next_scheduled ( 'mediawhale_converter_event', $args )) { wp_clear_scheduled_hook( 'mediawhale_converter_event' ); update_option('mediawhale_status','stopped'); } } // Always die in functions echoing ajax content die(); } add_action( 'wp_ajax_mediawhale_stop_converter_ajax_request', 'mediawhale_stop_converter_ajax_request' ); // If you wanted to also use the function for non-logged in users (in a theme for example) add_action( 'wp_ajax_nopriv_mediawhale_stop_converter_ajax_request', 'mediawhale_stop_converter_ajax_request' ); add_action( 'mediawhale_converter_event', 'mediawhale_converter_every_twenty_sec', 10 ); function mediawhale_converter_every_twenty_sec() { // do something every hour $query = new WP_Query(array('post_type'=>'post','posts_per_page'=>3,'meta_query'=>array(array('key'=>'converted_audio','compare'=>'NOT EXISTS')))); while($query->have_posts()){ $query->the_post(); $data = array(); $data['post_title'] = get_the_title(); $data['post_id'] = get_the_ID(); $data['post_content'] = apply_filters('the_content', get_post_field('post_content', get_the_ID())); error_log(print_r($data, true)); $response = mediawhale_convert_function($data); if ( is_wp_error( $response ) ) { $error_message = $response->get_error_message(); } else { $body_content = json_decode(wp_remote_retrieve_body($response)); if($body_content->type == '200'){ update_post_meta(get_the_ID(),'converted_audio',sanitize_text_field($body_content->postid)); update_post_meta(get_the_ID(),'mediawhaleconvert-to-audio','yes'); } } } wp_reset_postdata(); wp_reset_query(); } class MediaWhaleConvertSpecificPosts { private $convert_specific_posts_options; public function __construct() { add_action( 'admin_menu', array( $this, 'convert_specific_posts_add_plugin_page' ) ); add_action( 'admin_init', array( $this, 'convert_specific_posts_page_init' ) ); } public function convert_specific_posts_add_plugin_page() { add_submenu_page( null, 'Convert Specific Posts', // page_title 'Convert Specific Posts', // menu_title 'manage_options', // capability 'convert-specific-posts', // menu_slug array( $this, 'convert_specific_posts_create_admin_page' ) // function ); } public function convert_specific_posts_create_admin_page() { $this->convert_specific_posts_options = get_option( 'convert_specific_posts_option_name' ); $mediawhale_select_status = get_option('mediawhale_select_status'); ?> <? if(!empty(get_option('mediawhale_settings')['voice_name_1']) && !empty(get_option('mediawhale_settings')['language_name_0'])){ ?> <div class="convert_specific_ps_dt"> <div class="wrap"> <h3><?php _e("Convert Specific Posts","mediawhale"); ?></h3> <div class="loading-center-convert"> <div class="animated-progress progress-blue"> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="margin: auto; background: rgb(221, 221, 221); display: block; shape-rendering: auto;" width="200px" height="200px" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid"> <circle cx="30" cy="50" fill="#e90c59" r="20"> <animate attributeName="cx" repeatCount="indefinite" dur="1s" keyTimes="0;0.5;1" values="30;70;30" begin="-0.5s"></animate> </circle> <circle cx="70" cy="50" fill="#ffffff" r="20"> <animate attributeName="cx" repeatCount="indefinite" dur="1s" keyTimes="0;0.5;1" values="30;70;30" begin="0s"></animate> </circle> <circle cx="30" cy="50" fill="#e90c59" r="20"> <animate attributeName="cx" repeatCount="indefinite" dur="1s" keyTimes="0;0.5;1" values="30;70;30" begin="-0.5s"></animate> <animate attributeName="fill-opacity" values="0;0;1;1" calcMode="discrete" keyTimes="0;0.499;0.5;1" dur="1s" repeatCount="indefinite"></animate> </circle> </svg> <span class="span_con_txt"><?php _e("We started the converting process, please don't refresh the page.","mediawhale"); ?></span> </div> </div> <div class="success-message-block"> <?php _e("Success! Posts are converted to audio.","mediawhale"); ?> </div> <p></p> <?php settings_errors(); ?> <form method="post" action="options.php" class="convert_selector"> <div class="convert_selector-main"> <h6><?php _e('Select Posts','mediawhale'); ?></h6> <select data-placeholder="Start typing here..." multiple="multiple" name="convert_specific_posts_option_name[specific_posts_0]" id="specific_posts_0"> <?php $selected = (isset( $this->convert_specific_posts_options['specific_posts_0'] ) && $this->convert_specific_posts_options['specific_posts_0'] === 'Op1') ? 'selected' : '' ; ?> <?php $args = array( 'numberposts' => -1 ); $latest_posts = get_posts( $args ); foreach($latest_posts as $keysingle){ ?> <option value="<?php echo esc_attr($keysingle->ID) ?>" <?php echo esc_html($selected); ?>><?php echo esc_html($keysingle->post_title); ?></option> <?php } ?> </select> <a href="javascript:void(0);" class="convert_these_posts"><?php _e("Convert these posts","mediawhale"); ?></a> </div> </form> </div> </div> <?php } else{ ?> <div class="convert_box_empty_not_sl empty_specific_posts"> <div class="convert_box_empty_s"> <?php _e("You need to select the Voice and Langauge <a href='".get_admin_url()."admin.php?page=mediawhale-settings'>settings.</a>","mediawhale"); ?> </div> </div> <?php } ?> <?php } public function convert_specific_posts_page_init() { register_setting( 'convert_specific_posts_option_group', // option_group 'convert_specific_posts_option_name', // option_name array( $this, 'convert_specific_posts_sanitize' ) // sanitize_callback ); add_settings_section( 'convert_specific_posts_setting_section', // id 'Settings', // title array( $this, 'convert_specific_posts_section_info' ), // callback 'convert-specific-posts-admin' // page ); add_settings_field( 'specific_posts_0', // id 'Specific Posts', // title array( $this, 'specific_posts_0_callback' ), // callback 'convert-specific-posts-admin', // page 'convert_specific_posts_setting_section' // section ); } public function convert_specific_posts_sanitize($input) { $sanitary_values = array(); if ( isset( $input['specific_posts_0'] ) ) { $sanitary_values['specific_posts_0'] = $input['specific_posts_0']; } return $sanitary_values; } public function convert_specific_posts_section_info() { } public function specific_posts_0_callback() { } } if ( is_admin() ) $convert_specific_posts = new MediaWhaleConvertSpecificPosts(); /* * Retrieve this value with: * $convert_specific_posts_options = get_option( 'convert_specific_posts_option_name' ); // Array of All Options * $specific_posts_0 = $convert_specific_posts_options['specific_posts_0']; // Specific Posts */ class MediaWhaleConverter { private $converter_options; public function __construct() { add_action( 'admin_menu', array( $this, 'converter_add_plugin_page' ) ); add_action( 'admin_init', array( $this, 'converter_page_init' ) ); } public function converter_add_plugin_page() { if(get_option('mediawhale_connection')){ add_submenu_page( 'mediawhale', 'Converter', // page_title 'Converter', // menu_title 'manage_options', // capability 'mediawhale-converter', // menu_slug array( $this, 'converter_create_admin_page' ) // function ); } } public function converter_create_admin_page() { $this->converter_options = get_option( 'converter_option_name' ); ?> <div class="wrap"> <div class="converter_box_main"> <div class="converter_box_inner_main"> <div class="converter_give_options"> <h3><?php _e('Audio Posts Converter','mediawhale'); ?></h3> <h6><?php _e('This tool will connect the site with MediaWhale server, and will convert your posts to audio.','mediawhale'); ?></h6> <div class="convert_first_option"> <?php _e('Convert all posts.','mediawhale') ?> </div> <div class="convert_specific_posts" data-link="<?php echo esc_url(get_admin_url()); ?>"> <?php _e('Convert specific posts.','mediawhale'); ?> </div> </div> <div class="converter_box_m_block"> <?php if(!empty(get_option('mediawhale_settings')['voice_name_1']) && !empty(get_option('mediawhale_settings')['language_name_0'])){ ?> <?php if(get_option('mediawhale_status') == 'started'){ $count_total_posts = wp_count_posts()->publish; if($count_total_posts > 0){ $query_count_per = new WP_Query(array('post_type'=>'post','posts_per_page'=>-1,'meta_query' => array(array('key'=>'converted_audio')))); $count_total_cc = $query_count_per->found_posts; $query_count_total = new WP_Query(array('post_type'=>'post','posts_per_page'=>-1)); $count_total_cc_total = $query_count_total->found_posts; $cc_n_b = ($count_total_cc*100)/$count_total_cc_total; ?> <h3>Converter</h3> <div class="convert_every_thing"> <div class="convert_every_loading"> <?php if($cc_n_b == 100){ ?> <?php _e('We have converted all the articles.','mediawhale'); ?> <?php } else{ ?> <?php _e('We have started converting the posts to audio.','mediawhale'); ?> <?php } ?> </div> <div class="loading-center-convert"> <div class="animated-progress progress-blue"> <span data-progress="<?php $cc_n_b = number_format((float)$cc_n_b, 2, '.', ''); if($cc_n_b >= 100 ) { echo esc_attr("100"); } else { echo esc_attr($cc_n_b); } ?>"></span> </div> </div> <a href="javascript:void(0);" id="stop_convert" class="stop_convert_now">Stop Converting</a> </div> <script type="text/javascript"> jQuery(document).ready(function($){ $(".animated-progress span").each(function () { $(this).animate( { width: $(this).attr("data-progress") + "%", }, 1000 ); $(this).text($(this).attr("data-progress") + "%"); }); }); </script> <?php } else{ ?> <h3>Converter</h3> <div class="convert_every_thing"> <div class="convert_every_loading"> <?php _e("It looks like you don't have any article on the site?","mediawhale"); ?> </div> </div> <?php } } else{ ?> <h3><?php _e("Converter","mediawhale"); ?></h3> <div class="convert_every_thing"> <div class="convert_every_txt"> <?php _e("This tool will let you to convert all the posts to audio under just one click.","mediawhale"); ?> </div> <a href="javascript:void(0);" id="convert_box_m" class="convert_box_m"><?php _e("Convert Now","mediawhale"); ?></a> </div> <?php } ?> <?php } else{ ?> <div class="convert_box_empty_not_sl"> <div class="convert_box_empty_s"> <?php _e("You need to select the Voice and Langauge settings.","mediawhale"); ?> </div> </div> <?php } ?> </div> </div> </div> </div> <?php } public function converter_page_init() { register_setting( 'converter_option_group', // option_group 'converter_option_name', // option_name array( $this, 'converter_sanitize' ) // sanitize_callback ); add_settings_section( 'converter_setting_section', // id 'Settings', // title array( $this, 'converter_section_info' ), // callback 'converter-admin' // page ); add_settings_field( 'converter_0', // id 'Converter', // title array( $this, 'converter_0_callback' ), // callback 'converter-admin', // page 'converter_setting_section' // section ); } public function converter_sanitize($input) { $sanitary_values = array(); if ( isset( $input['converter_0'] ) ) { $sanitary_values['converter_0'] = sanitize_text_field( $input['converter_0'] ); } return $sanitary_values; } public function converter_section_info() { } public function converter_0_callback() { printf( '<input class="regular-text" type="text" name="converter_option_name[converter_0]" id="converter_0" value="%s">', isset( $this->converter_options['converter_0'] ) ? esc_attr( $this->converter_options['converter_0']) : '' ); } } if ( is_admin() ) $converter = new MediaWhaleConverter(); /* * Retrieve this value with: * $converter_options = get_option( 'converter_option_name' ); // Array of All Options * $converter_0 = $converter_options['converter_0']; // Converter */