public function get_page_social_stats($postID, $website_url = '')
 {
     /*
     			$__ = array(
     				'http://mashable.com',
     				'http://facebook.com',
     				'http://stiumuzica.ro',
     				'http://themeforest.net',
     				'http://codecanyon.net'
     			);
     			
     			shuffle($__);
     			$website_url = $__[0];*/
     $cache_life_time = 240 * 10;
     // in seconds
     $the_db_cache = get_post_meta($postID, '_psp_social_stats', true);
     // check if cache NOT expires
     if (isset($the_db_cache['_cache_date']) && time() <= $the_db_cache['_cache_date'] + $cache_life_time) {
         return $the_db_cache;
     }
     $db_cache = array();
     $db_cache['_cache_date'] = time();
     // Facebook
     $fql = "SELECT url, normalized_url, share_count, like_count, comment_count, ";
     $fql .= "total_count, commentsbox_count, comments_fbid, click_count FROM ";
     $fql .= "link_stat WHERE url = '{$website_url}'";
     $apiQuery = "https://api.facebook.com/method/fql.query?format=json&query=" . urlencode($fql);
     $fb_data = $this->getRemote($apiQuery);
     $fb_data = $fb_data[0];
     // Twitter
     $apiQuery = "http://urls.api.twitter.com/1/urls/count.json?url=" . $website_url;
     $tw_data = $this->getRemote($apiQuery);
     // LinkedIn
     $apiQuery = "http://www.linkedin.com/countserv/count/share?format=json&url=" . $website_url;
     $ln_data = $this->getRemote($apiQuery);
     // Pinterest
     $apiQuery = "http://api.pinterest.com/v1/urls/count.json?callback=receiveCount&url=" . $website_url;
     $pn_data = $this->getRemote($apiQuery);
     // StumbledUpon
     $apiQuery = "http://www.stumbleupon.com/services/1.01/badge.getinfo?url=" . $website_url;
     $st_data = $this->getRemote($apiQuery);
     // Delicious
     $apiQuery = "http://feeds.delicious.com/v2/json/urlinfo/data?url=" . $website_url;
     $de_data = $this->getRemote($apiQuery);
     $de_data = $de_data[0];
     // Google Plus
     $apiQuery = "https://plusone.google.com/_/+1/fastbutton?bsv&size=tall&hl=it&url=" . $website_url;
     $go_data = $this->getRemote($apiQuery, false);
     require_once $this->the_plugin->cfg['paths']['scripts_dir_path'] . '/php-query/php-query.php';
     $html = pspphpQuery::newDocumentHTML($go_data);
     $go_data = $html->find("#aggregateCount")->text();
     $db_cache['facebook'] = array('share_count' => $fb_data['share_count'], 'like_count' => $fb_data['like_count'], 'comment_count' => $fb_data['comment_count'], 'click_count' => $fb_data['click_count']);
     $db_cache['google'] = $go_data;
     $db_cache['twitter'] = $tw_data['count'];
     $db_cache['linkedin'] = $ln_data['count'];
     $db_cache['pinterest'] = $pn_data['count'];
     $db_cache['stumbleupon'] = $st_data['result']['views'];
     $db_cache['delicious'] = $de_data['total_posts'];
     // create a DB cache of this
     update_post_meta($postID, '_psp_social_stats', $db_cache);
     return $db_cache;
 }
Exemple #2
0
 public function get_remote_website_content()
 {
     if (isset($_REQUEST['pspGetRemoteWebsite'])) {
         die;
         $url = isset($_REQUEST['url']) && trim($_REQUEST['url']) != "" ? $_REQUEST['url'] : '';
         // !! the best way is to made a duble check if the url is in you web directories DB
         $response = wp_remote_get($url, array('timeout' => 15));
         $html_data = wp_remote_retrieve_body($response);
         require_once $this->the_plugin->cfg['paths']['scripts_dir_path'] . '/php-query/php-query.php';
         $doc = pspphpQuery::newDocument($html_data);
         $the_url = parse_url($url);
         $doc->find('head')->prepend('<base href="' . ($the_url['scheme'] . '://' . $the_url['host']) . '">');
         // try to find the main submit form
         $submit_form = $doc->find('form[method="post"]');
         if ($submit_form->attr('action') == "") {
             $submit_form->attr('action', $url);
         }
         $submit_form->attr('target', "_blank");
         die($doc->html());
     }
 }
Exemple #3
0
 private function getSocialsData($website_url = '', $force_refresh_cache = false)
 {
     $cache_life_time = 60 * 10;
     // in seconds
     $the_db_cache = $this->the_plugin->get_theoption("psp_dashboard_social_statistics");
     // check if cache NOT expires
     if (isset($the_db_cache['_cache_date']) && time() <= $the_db_cache['_cache_date'] + $cache_life_time && $force_refresh_cache == false) {
         return $the_db_cache;
     }
     $db_cache = array();
     $db_cache['_cache_date'] = time();
     // Alexa rank
     $apiQuery = 'http://data.alexa.com/data?cli=10&dat=snbamz&url=' . $website_url;
     $alexa_data = $this->getRemote($apiQuery, false);
     $xml = simplexml_load_string($alexa_data);
     $json = json_encode($xml);
     $array = json_decode($json, TRUE);
     // Facebook
     $fql = "SELECT url, normalized_url, share_count, like_count, comment_count, ";
     $fql .= "total_count, commentsbox_count, comments_fbid, click_count FROM ";
     $fql .= "link_stat WHERE url = '{$website_url}'";
     $apiQuery = "https://api.facebook.com/method/fql.query?format=json&query=" . urlencode($fql);
     $fb_data = $this->getRemote($apiQuery);
     $fb_data = $fb_data[0];
     // Twitter
     $apiQuery = "http://urls.api.twitter.com/1/urls/count.json?url=" . $website_url;
     $tw_data = $this->getRemote($apiQuery);
     // LinkedIn
     $apiQuery = "http://www.linkedin.com/countserv/count/share?format=json&url=" . $website_url;
     $ln_data = $this->getRemote($apiQuery);
     // Pinterest
     $apiQuery = "http://api.pinterest.com/v1/urls/count.json?callback=receiveCount&url=" . $website_url;
     $pn_data = $this->getRemote($apiQuery);
     // StumbledUpon
     $apiQuery = "http://www.stumbleupon.com/services/1.01/badge.getinfo?url=" . $website_url;
     $st_data = $this->getRemote($apiQuery);
     // Delicious
     $apiQuery = "http://feeds.delicious.com/v2/json/urlinfo/data?url=" . $website_url;
     $de_data = $this->getRemote($apiQuery);
     $de_data = $de_data[0];
     // Google Plus
     $apiQuery = "https://plusone.google.com/_/+1/fastbutton?bsv&size=tall&hl=it&url=" . $website_url;
     $go_data = $this->getRemote($apiQuery, false);
     require_once $this->the_plugin->cfg['paths']['scripts_dir_path'] . '/php-query/php-query.php';
     $html = pspphpQuery::newDocumentHTML($go_data);
     $go_data = $html->find("#aggregateCount")->text();
     // store for feature cache
     $db_cache['alexa'] = $array['SD'][1]['POPULARITY']["@attributes"]['TEXT'];
     $db_cache['facebook'] = array('share_count' => $fb_data['share_count'], 'like_count' => $fb_data['like_count'], 'comment_count' => $fb_data['comment_count'], 'click_count' => $fb_data['click_count']);
     $db_cache['google'] = $go_data;
     $db_cache['twitter'] = $tw_data['count'];
     $db_cache['linkedin'] = $ln_data['count'];
     $db_cache['pinterest'] = $pn_data['count'];
     $db_cache['stumbleupon'] = $st_data['result']['views'];
     $db_cache['delicious'] = $de_data['total_posts'];
     // create a DB cache of this
     $this->the_plugin->save_theoption('psp_dashboard_social_statistics', $db_cache);
     return $db_cache;
 }
 public function get_page_meta($url = '')
 {
     $data = array();
     if (trim($url) != "") {
         // try to get page meta
         $response = wp_remote_get($url, array('timeout' => 15));
         // If there's error
         if (is_wp_error($response)) {
             return $data;
         }
         $html_data = wp_remote_retrieve_body($response);
         if (trim($html_data) != "") {
             require_once $this->cfg['paths']['scripts_dir_path'] . '/php-query/php-query.php';
             $doc = pspphpQuery::newDocument($html_data);
             // try to get the page title
             $data['page_title'] = $doc->find('title')->text();
             // try to get the page meta description
             $data['page_meta_description'] = $doc->find('meta[name="description"]')->attr('content');
             // try to get the page meta keywords
             $data['page_meta_keywords'] = $doc->find('meta[name="keywords"]')->attr('content');
         }
         return $data;
     }
 }
Exemple #5
0
 public function add_images_tags($the_content)
 {
     global $post;
     // php query class
     require_once $this->the_plugin->cfg['paths']['scripts_dir_path'] . '/php-query/php-query.php';
     $psp_meta = get_post_meta($post->ID, 'psp_meta', true);
     if (trim($the_content) != "") {
         $doc = pspphpQuery::newDocument($the_content);
         foreach (pspPQ('img') as $img) {
             // cache the img object
             $img = pspPQ($img);
             $url = $img->attr('src');
             $image_name = '';
             if (trim($url) != "") {
                 $image_name = explode('.', end(explode('/', $url)));
                 $image_name = $image_name[0];
             }
             $alt = $img->attr('alt');
             $title = $img->attr('title');
             // setup the default settings
             $new_alt = isset($this->settings["image_alt"]) ? $this->settings["image_alt"] : '';
             $new_title = isset($this->settings["image_title"]) ? $this->settings["image_title"] : '';
             if (isset($this->settings['keep_default_alt']) && trim($this->settings['keep_default_alt']) != "") {
                 $new_alt = $alt . ' ' . $new_alt;
             }
             if (isset($this->settings['keep_default_title']) && trim($this->settings['keep_default_title']) != "") {
                 $new_title = $title . ' ' . $new_title;
             }
             // make the replacements
             foreach ($this->special_tags as $tag) {
                 if ($tag == '{title}') {
                     if (preg_match("/{$tag}/iu", $this->settings["image_alt"])) {
                         $new_alt = str_replace($tag, $post->post_title, $new_alt);
                     }
                     if (preg_match("/{$tag}/iu", $this->settings["image_title"])) {
                         $new_title = str_replace($tag, $post->post_title, $new_title);
                     }
                 } elseif ($tag == '{image_name}') {
                     if (preg_match("/{$tag}/iu", $this->settings["image_alt"])) {
                         $new_alt = str_replace($tag, $image_name, $new_alt);
                     }
                     if (preg_match("/{$tag}/iu", $this->settings["image_title"])) {
                         $new_title = str_replace($tag, $image_name, $new_title);
                     }
                 } elseif ($tag == '{focus_keyword}' && isset($psp_meta['focus_keyword']) && trim($psp_meta['focus_keyword']) != "") {
                     if (preg_match("/{$tag}/iu", $this->settings["image_alt"])) {
                         $new_alt = str_replace($tag, $psp_meta['focus_keyword'], $new_alt);
                     }
                     if (preg_match("/{$tag}/iu", $this->settings["image_title"])) {
                         $new_title = str_replace($tag, $psp_meta['focus_keyword'], $new_title);
                     }
                 } elseif ($tag == '{nice_image_name}') {
                     $image_name = preg_replace("/[^a-zA-Z0-9\\s]/", " ", $image_name);
                     $image_name = preg_replace('/\\d{1,4}x\\d{1,4}/i', '', $image_name);
                     if (preg_match("/{$tag}/iu", $this->settings["image_alt"])) {
                         $new_alt = str_replace($tag, $image_name, $new_alt);
                     }
                     if (preg_match("/{$tag}/iu", $this->settings["image_title"])) {
                         $new_title = str_replace($tag, $image_name, $new_title);
                     }
                 }
             }
             // if the alt / title was changed
             if ($new_alt != $alt) {
                 $img->attr('alt', trim($new_alt));
             }
             if ($new_title != $title) {
                 $img->attr('title', trim($new_title));
             }
         }
         return do_shortcode($doc->html());
     } else {
         return do_shortcode($the_content);
     }
 }
Exemple #6
0
    private function filter_item_video($content)
    {
        if (empty($this->video_include)) {
            return array();
        }
        //$content = $this->strip_shortcode( $content ); // strip shortcodes!
        if (empty($content)) {
            return array();
        }
        // validate content!
        // php query class
        require_once $this->the_plugin->cfg['paths']['scripts_dir_path'] . '/php-query/php-query.php';
        $doc = pspphpQuery::newDocument($content);
        $__founds = array();
        // Video - wp shortcode! - treated in Just Plain Links!
        /*$regex_video = '
        			\[video(?:[^\]]+)?
        				(http(?:s|v|vh|vp|a)?:\/\/(?:www\.)?[^\s"]+)
        			\]\s*\[\/video\]
        		';
        		$regex_video = '/'.$regex_video.'/ixum';
        		preg_match_all( $regex_video, $content, $wpvideos, PREG_SET_ORDER );
        		if ( !empty($wpvideos) ) { foreach ( $wpvideos as $match ) {
        			if ( empty($match[1]) ) continue 1;
        			$__founds[] = $match[1];
        		} }*/
        // Embeds - wp shortcode!
        $regex_embeds = '
			\\[embed(?:[^\\]]+)?\\]
				(http(?:s|v|vh|vp|a)?:\\/\\/(?:www\\.)?[^\\s"]+)
			\\[\\/embed\\]
		';
        $regex_embeds = '/' . $regex_embeds . '/ixum';
        preg_match_all($regex_embeds, $content, $embeds, PREG_SET_ORDER);
        if (!empty($embeds)) {
            foreach ($embeds as $match) {
                if (empty($match[1])) {
                    continue 1;
                }
                $__founds[] = $match[1];
            }
        }
        // Embeds - inside other objects!
        $embeds2 = $doc->find('embed');
        foreach ($embeds2 as $tag) {
            $tag = pspPQ($tag);
            // cache the object
            // special cases!
            //if ( preg_match('/flickr\.com/iu', $tag->attr('src')) > 0 ) {
            //	continue 1;
            //}
            $__founds[] = $tag->attr('src');
        }
        // IFrames!
        $iframes = $doc->find('iframe');
        foreach ($iframes as $tag) {
            $tag = pspPQ($tag);
            // cache the object
            $__founds[] = $tag->attr('src');
        }
        // Objects!
        $objects = $doc->find('object');
        foreach ($objects as $tag) {
            $tag = pspPQ($tag);
            // cache the object
            $tag = $tag->find('param');
            $isSpecial = false;
            $specialVal = '';
            foreach ($tag as $param) {
                $param = pspPQ($param);
                // cache the object
                if (in_array($param->attr('name'), array('src', 'movie'))) {
                    // special cases!
                    if (preg_match('/flickr\\.com/iu', $param->attr('value')) > 0) {
                        $isSpecial = 'flickr.com';
                        //continue 1;
                    }
                    $__founds[] = $param->attr('value');
                }
                if (in_array($param->attr('name'), array('flashvars'))) {
                    if (preg_match('/photo_id=(\\d+)$/iu', $param->attr('value'), $flickrMatch) > 0) {
                        $specialVal = $flickrMatch[1];
                    }
                }
            }
            if ($isSpecial !== false && !empty($specialVal)) {
                if ($isSpecial == 'flickr.com') {
                    $__founds[] = "http://www.flickr.com/__flashvars__/{$specialVal}/";
                }
            }
        }
        // Just Plain Links!
        $regex_links = '
			\\s*
			(http(?:s|v|vh|vp|a)?:\\/\\/(?:www\\.)?[^\\s"]+)
			\\s*
		';
        $regex_links = '/' . $regex_links . '/ixum';
        preg_match_all($regex_links, $content, $links, PREG_SET_ORDER);
        if (!empty($links)) {
            foreach ($links as $match) {
                if (empty($match[1])) {
                    continue 1;
                }
                $__founds[] = $match[1];
            }
        }
        if (empty($__founds)) {
            return array();
        }
        // validate founds!
        // clean duplicates!
        if (!empty($__founds)) {
            $__founds = array_values(array_unique($__founds));
        }
        // allowed video providers
        $allowedVideoProviders = array();
        if (is_array(self::$videoIdentifies) && !empty(self::$videoIdentifies)) {
            foreach (self::$videoIdentifies as $key => $val) {
                if (!in_array($key, (array) $this->video_include)) {
                    continue 1;
                }
                $allowedVideoProviders["{$key}"] = $val;
            }
        }
        // go through found urls!
        $__images = array();
        foreach ($__founds as $found) {
            $found = trim($found);
            if (preg_match('/^http/iu', $found) == 0) {
                $found = 'http:' . $found;
            }
            $parseUrl = parse_url($found);
            $host = $parseUrl['host'];
            if (!isset($host) || empty($host)) {
                continue 1;
            }
            if (is_array($allowedVideoProviders) && !empty($allowedVideoProviders)) {
                foreach ($allowedVideoProviders as $key => $val) {
                    $pattern = '/' . $val['default'] . '/ixu';
                    //if ( $key != 'xyz' ) continue 1;
                    if ($key == 'xyz') {
                        //var_dump('<pre>', $pattern , '</pre>'); die('debug...');
                    }
                    if (preg_match_all($pattern, $found, $matches, PREG_SET_ORDER)) {
                        if ($key == 'xyz') {
                            //var_dump('<pre>',$matches ,'</pre>');
                        }
                        foreach ($matches as $match) {
                            if ($key == 'localhost') {
                                $__images["{$key}"][] = $found;
                                continue 1;
                            }
                            if (empty($match[1])) {
                                continue 1;
                            }
                            if ($key == 'blip' && in_array($match[1], array('api'))) {
                                continue 1;
                            }
                            $__images["{$key}"][] = $match[1];
                        }
                    }
                }
                // end foreach allowed providers!
            }
        }
        // end foreach main!
        // clean duplicates
        if (!empty($__images)) {
            foreach ($__images as $kk => $vv) {
                $__images["{$kk}"] = array_values(array_unique($__images["{$kk}"]));
            }
        }
        //var_dump('<pre>', $__images , '</pre>'); die('debug...');
        return $__images;
    }
Exemple #7
0
 /**
  * Check if the keyword is contained in the HTML italic tag.
  *
  * @param string  $page_content
  * @param string  $focus_kw
  * @return array  $results   The results array.
  */
 function score_html_italic($page_content, $focus_kw)
 {
     $html = pspphpQuery::newDocumentHTML($page_content);
     $msgs = array('missing' => __("Bad, your content has no italic elements.", $this->the_plugin->localizationName), 'less' => __("Bad, your content has %d italic elements and none of this contains your most important keywords.", $this->the_plugin->localizationName), 'good' => __("Great, your content has %d italic elements and at least 1 contains your most important keywords.", $this->the_plugin->localizationName));
     $total_italics = $html->find('em,i')->size();
     if ($total_italics > 0) {
         if (preg_match('/' . preg_quote($focus_kw, '/') . '/i', $html->find('em,i')->text()) == true) {
             return array('score' => 1, 'msg' => sprintf($msgs['good'], $total_italics));
         } else {
             return array('score' => 0, 'msg' => sprintf($msgs['less'], $total_italics));
         }
     } else {
         return array('score' => 0, 'msg' => sprintf($msgs['missing'], $total_italics));
     }
 }