options = get_option("pw-mobile-app"); $this->accountOptions = get_option("androapp_account_settings"); $this->scriptsOptions = get_option("androapp_scripts_detected"); $this->buildOptions = get_option("pw-mobile-build-options"); } // Add checkboxes function androapp_notification_settings() { global $post; $prevSelectedValue = get_post_meta($post->ID, "androapp_post_notify", true); $dont_send_push_notification = ($prevSelectedValue == 'on' ? ' checked' : ''); if(!$prevSelectedValue){ $dont_send_push_notification = ($this->accountOptions[pw_mobile_app_settings::$defaultPostPushNotification] == '1' ? ' checked': ''); } ?>
/>
ID, "androapp_post_notify", $_POST["androapp_post_notify"]); }else{ if($new_status != 'auto-draft'){ update_post_meta($post->ID, "androapp_post_notify", 'off'); } } if (($old_status != 'publish') && ($new_status == 'publish') && ($post->post_type == "post" || $post->post_type == "page")){ $dont_send_push_notification = get_post_meta($post->ID, "androapp_post_notify", true); if(empty($dont_send_push_notification) || $dont_send_push_notification == 'off') { $this->schedule_push_notification($post); } } } function schedule_push_notification_save(){ global $post; $this->schedule_push_notification($post); } function schedule_push_notification($post){ wp_schedule_single_event( time()+ 10*30 , 'send_push_notification_after_publish', array ($post->ID, $post->post_title, $this->accountOptions[ANDROAPP_GCM_API_KEY] , $this->accountOptions[ANDROAPP_NOTIFICATION_TYPE_KEY] )); } function send_push_notification_after_publish($post_id, $post_title, $google_api_key, $notification_type) { require_once PW_MOBILE_PATH.'gcm/send_message.php'; sendPushNotification(array("post_id" => $post_id, "title" => $post_title, "notification_type" => $notification_type), $google_api_key); } function removeShortcodes($shortcodes){ global $shortcode_tags; $shortCodesFunctionArray = array(); foreach($shortcodes as $shortcode){ if(!empty($shortcode_tags[$shortcode])){ $shortCodesFunctionArray[$shortcode] = $shortcode_tags[$shortcode]; unset($shortcode_tags[$shortcode]); } } return $shortCodesFunctionArray; } function addShortcodesBack($shortCodesFunctionArray){ global $shortcode_tags; foreach($shortCodesFunctionArray as $key => $shortcode){ $shortcode_tags[$key] = $shortcode; } } function getScripts(){ $out = ""; if(!empty($this->scriptsOptions) && !empty($this->options[pw_mobile_app_settings::$selectedScripts])){ $scripts = $this->scriptsOptions['scripts']; $selectedScripts = explode("\n", $this->options[pw_mobile_app_settings::$selectedScripts]); foreach($selectedScripts as $handle){ $handle = trim($handle); if($scripts[$handle]){ $out .= ""; } } } if(!empty($this->options[pw_mobile_app_settings::$postProcessedCss])){ $out .= ""; } return $out; } function getShareText($post, $data, $key){ if($key == "TITLE"){ return $data['title']; } else if($key == "EXCERPT"){ return strip_tags($data['excerpt']); } else if($key == "SEO"){ $wpseo_metadesc = get_post_meta($post['ID'], '_yoast_wpseo_metadesc', true); if(!empty($wpseo_metadesc)){ return $wpseo_metadesc; } else{ if (class_exists('WPSEO_Meta')) { return $this->get_seo_description($post_array['ID']); } } return $data['title']; }else if($key == "FULL"){ return wpautop($post['post_content']); } return ""; } function androapp_woocommerce_api_product_response($data, $product, $fields, $server){ global $wp_query; global $post; $orig_post = $post; $prev_ishome = $wp_query->is_home; $wp_query->is_home = false; $post_obj = get_post($post_array['ID']); $post = $post_obj; setup_postdata( $post_obj ); $data['pwapp_feed_image_dimension_type'] = $this->options['image_dimension']; $share_text_fn = $this->options['share_function_name']; $firstImage = $data['featured_src']; if($this->options['image_dimension'] != 'noimage'){ $data['pwapp_post_image'] = $firstImage; } if($this->options['share_image_preference'] != 'noimage'){ $data['share_image'] = $firstImage; } $preview = ""; if($this->options['excerpt_preference'] == 'seo_meta_desc'){ $wpseo_metadesc = get_post_meta($post['ID'], '_yoast_wpseo_metadesc', true); if(!empty($wpseo_metadesc)){ $preview = html_entity_decode($wpseo_metadesc,null,'UTF-8'); } else{ if (class_exists('WPSEO_Meta')) { $preview = $this->get_seo_description($post['ID']); } } }else if($this->options['excerpt_preference'] == 'none'){ $preview = ""; }else{ $this->options['excerpt_preference'] = "excerpt"; $preview = $data['description']; } $data['pwapp_excerpt'] = $preview; $data['excerpt'] = $preview; $postcontent = ""; if($this->options['post_content'] == 'preprocessed'){ $shortcodesToRemove = array('caption', 'wp_caption', 'gallery', 'playlist', 'audio','video'); $shortcodesArray = $this->removeShortcodes($shortcodesToRemove); $stripped_content = strip_shortcodes(wpautop($post['post_content'])); $this->addShortcodesBack($shortcodesArray); $postcontent = do_shortcode($stripped_content); }else if($this->options['post_content'] == 'postprocessed'){ $postcontent = $this->getScripts()."
".$data['content']."
"; } $data['pwapp_post_content'] = $postcontent; $data['pwapp_post_content_type'] = $this->options['post_content']; $data['pwapp_preview_type'] = $this->options['excerpt_preference']; $data['share_text'] = ""; if(!empty($share_text_fn) && function_exists($share_text_fn) ){ $data['share_text'] = $share_text_fn($product, $data['link']); } if(empty($data['share_text'])){ if(empty($data['share_image'])){ $data['share_text'] = $this->getShareText($product, $data, $this->options[pw_mobile_app_settings::$sharePreference]); }else{ $data['share_text'] = $this->getShareText($product, $data, $this->options[pw_mobile_app_settings::$shareTextWithImage]); } if(!empty($this->options[pw_mobile_app_settings::$shareSuffixText])){ $data['share_text'] .= "\n".$this->options[pw_mobile_app_settings::$shareSuffixText]; } if($this->options[pw_mobile_app_settings::$shareSuffixLink] == "HOME"){ $data['share_text'] .= " ".get_bloginfo('url'); } else if($this->options[pw_mobile_app_settings::$shareSuffixLink] == "POST"){ $data['share_text'] .= " ". $data['permalink']; } }else{ if($this->options[pw_mobile_app_settings::$shareImageWithCustomFunction] == "1"){ $data['share_image'] = null; } } if($this->options[pw_mobile_app_settings::$showCommentsCount] == "1" && $this->options[pw_mobile_app_settings::$commentsProvider] == "wordpress"){ $comments_count = wp_count_comments( $post['ID']); $data['androapp_comments_count'] = $comments_count->approved; } //$data['supercache'] = "androappsupercache"; $post = $orig_post; wp_reset_postdata(); $wp_query->is_home = $prev_ishome; return $data; } function pw_mobile_prepare_post($data, $post_array, $context) { if(!($data['type'] == "post" || $data['type'] == "page")){ return $data; } global $wp_query; global $post; $orig_post = $post; $prev_ishome = $wp_query->is_home; $wp_query->is_home = false; $post_obj = get_post($post_array['ID']); $post = $post_obj; setup_postdata( $post_obj ); $data['pwapp_feed_image_dimension_type'] = $this->options['image_dimension']; $share_text_fn = $this->options['share_function_name']; $firstImage = null; if(has_post_thumbnail( $post_array['ID'] )){ $imagesize = 'full'; if($this->buildOptions['androapp_theme'] == 'compact'){ $imagesize = 'thumbnail'; } $attch = wp_get_attachment_image_src( get_post_thumbnail_id( $post_array['ID'] ), $imagesize); if(is_array($attch) && count($attch) > 0){ $firstImage = $attch[0]; $data['featuredimage'] = $attch[0]; } } if(empty($firstImage)){ if(empty($this->options[pw_mobile_app_settings::$useOnlyFeaturedImage]) || $this->options[pw_mobile_app_settings::$useOnlyFeaturedImage] != 1){ $firstImage = androapp_get_first_image($post_array['post_content']); } } if($this->options['image_dimension'] != 'noimage'){ $data['pwapp_post_image'] = $firstImage; } if($this->options['share_image_preference'] != 'noimage'){ $data['share_image'] = $firstImage; } $preview = ""; if($this->options['excerpt_preference'] == 'seo_meta_desc'){ $wpseo_metadesc = get_post_meta($post_array['ID'], '_yoast_wpseo_metadesc', true); if(!empty($wpseo_metadesc)){ $preview = html_entity_decode($wpseo_metadesc,null,'UTF-8'); }else{ if (class_exists('WPSEO_Meta')) { $preview = $this->get_seo_description($post_array['ID']); } } }else if($this->options['excerpt_preference'] == 'none'){ $preview = ""; }else{ $this->options['excerpt_preference'] = "excerpt"; $preview = $data['excerpt']; } $data['pwapp_excerpt'] = $preview; $postcontent = ""; if (array_key_exists('pwapp_before_post_content', $data)){ $postcontent = $data['pwapp_before_post_content']; } $after_post_content = ""; if (array_key_exists('pwapp_after_post_content', $data)){ $after_post_content = $data['pwapp_after_post_content']; } if($this->options['post_content'] == 'preprocessed'){ $shortcodesToRemove = array('caption', 'wp_caption', 'gallery', 'playlist', 'audio','video'); $shortcodesArray = $this->removeShortcodes($shortcodesToRemove); $stripped_content = strip_shortcodes(wpautop($post_array['post_content'])); $this->addShortcodesBack($shortcodesArray); $stripped_content .= $after_post_content; $postcontent .= do_shortcode($stripped_content); }else if($this->options['post_content'] == 'postprocessed'){ //using $data['content'] for instagram video for autostrada.tv $content = do_shortcode($postcontent).$data['content'].do_shortcode($after_post_content); $content = apply_filters( 'the_content', $content );//apply filters for related posts $postcontent = $this->getScripts()."
".$content."
"; } if(isset($this->accountOptions[pw_mobile_app_settings::$stripAdsenseUnits]) && $this->accountOptions[pw_mobile_app_settings::$stripAdsenseUnits] == '1'){ $data['pwapp_post_content'] = $this->stripAdsense($postcontent); }else{ $data['pwapp_post_content'] = $postcontent; } $data['pwapp_post_content_type'] = $this->options['post_content']; $data['pwapp_preview_type'] = $this->options['excerpt_preference']; $data['share_text'] = ""; if(!empty($share_text_fn) && function_exists($share_text_fn) ){ $data['share_text'] = $share_text_fn($post_array, $data['link']); } if(empty($data['share_text'])){ if(empty($data['share_image'])){ $data['share_text'] = $this->getShareText($post_array, $data, $this->options[pw_mobile_app_settings::$sharePreference]); }else{ $data['share_text'] = $this->getShareText($post_array, $data, $this->options[pw_mobile_app_settings::$shareTextWithImage]); } if(!empty($this->options[pw_mobile_app_settings::$shareSuffixText])){ $data['share_text'] .= "\n".$this->options[pw_mobile_app_settings::$shareSuffixText]; } if($this->options[pw_mobile_app_settings::$shareSuffixLink] == "HOME"){ $data['share_text'] .= " ".get_bloginfo('url'); } else if($this->options[pw_mobile_app_settings::$shareSuffixLink] == "POST"){ $data['share_text'] .= " ". $data['link']; } }else{ if($this->options[pw_mobile_app_settings::$shareImageWithCustomFunction] == "1"){ $data['share_image'] = null; } } if($this->options[pw_mobile_app_settings::$showCommentsCount] == "1" && $this->options[pw_mobile_app_settings::$commentsProvider] == "wordpress"){ $comments_count = wp_count_comments( $post_array['ID']); $data['androapp_comments_count'] = $comments_count->approved; } $data['supercache'] = "androappsupercache"; $post = $orig_post; wp_reset_postdata(); $wp_query->is_home = $prev_ishome; return $data; } function myplugin_api_init( $server ) { global $myplugin_api_mytype; require_once dirname( __FILE__ ) . '/class-pw-wp-menu.php'; $myplugin_api_mytype = new Pw_Wp_Menu( $server ); add_filter( 'json_endpoints', array( $myplugin_api_mytype, 'register_routes'), 0); require_once dirname( __FILE__ ) . '/class-pw-wp-posts.php'; $pwapp_posts = new Pw_Wp_Posts( $server ); add_filter( 'json_endpoints', array( $pwapp_posts, 'register_routes'), 0); require_once dirname( __FILE__ ) . '/class-pw-wp-gcm-register.php'; $pwapp_gcm = new Pw_Wp_Gcm_Register( $server ); add_filter( 'json_endpoints', array( $pwapp_gcm, 'register_routes'), 0); require_once dirname( __FILE__ ) . '/class-pw-wp-woocommerce.php'; $pwapp_woo = new Pw_Wp_Woocommerce( $server ); add_filter( 'json_endpoints', array( $pwapp_woo, 'register_routes'), 0); require_once dirname( __FILE__ ) . '/class-pw-wp-woo.php'; $pwapp_woo_post = new Pw_Wp_Woo( $server ); add_filter( 'json_endpoints', array( $pwapp_woo_post, 'register_routes'), 0); } function get_seo_description($post_id){ global $post; $ogdesc = ""; if (class_exists('WPSEO_Meta')){ $ogdesc = WPSEO_Meta::get_value( 'opengraph-description', $post_id ); // Replace Yoast SEO Variables. $ogdesc = wpseo_replace_vars( $ogdesc, $post ); // Use metadesc if $ogdesc is empty. if ( $ogdesc === '' ) { $frontend = WPSEO_Frontend::get_instance(); $ogdesc = $frontend->metadesc( false ); } } // Tag og:description is still blank so grab it from get_the_excerpt(). if ( ! is_string( $ogdesc ) || ( is_string( $ogdesc ) && $ogdesc === '' ) ) { $ogdesc = $this->my_excerpt($post); } return html_entity_decode($ogdesc,null,'UTF-8'); } function my_excerpt($post) { if ($post->post_excerpt) { // excerpt set, return it return apply_filters('the_excerpt', $post->post_excerpt); } else { // setup_postdata( $post ); $excerpt = get_the_excerpt(); //wp_reset_postdata(); return $excerpt; } } function add_css_bottom() { if(isAndroAppRequest()) { echo ''; } } function endswith($string, $test) { $strlen = strlen($string); $testlen = strlen($test); if ($testlen > $strlen) return false; $substr = substr($string, $strlen - $testlen-1, $testlen); return $substr == $test; } function stripAdsense($html){ try{ $html = "".$html.""; $domDocument = new DOMDocument(); // modify state $libxml_previous_state = libxml_use_internal_errors(true); // parse $domDocument->loadHTML('' . $html); // handle errors libxml_clear_errors(); // restore libxml_use_internal_errors($libxml_previous_state); $domNodeList = $domDocument->getElementsByTagname('script'); foreach ( $domNodeList as $domElement ) { $src = $domElement->getAttribute('src'); if (strpos($src, 'adsbygoogle.js') !== false) { $domElement->parentNode->removeChild($domElement); } if (strpos($src, 'show_ads.js') !== false) { $domElement->parentNode->removeChild($domElement); } } $html = $domDocument->saveHTML(); $bodyPos = strpos($html, '') ; if($bodyPos !== false){ $html = substr($html, $bodyPos+6); $end = ""; if($this->endswith($html, $end)){ $html = substr($html, 0, strlen($html) - strlen($end) -1); } } } catch(Exception $e) { //echo 'Message: ' .$e->getMessage(); } return $html; } }