コード例 #1
0
ファイル: LinkedIn.php プロジェクト: venturepact/blog
 /**
  * {@inheritDoc}
  */
 public function getShares($url)
 {
     $data = xt_get_url_contents(sprintf(self::API_URL, $url));
     if (!empty($data)) {
         return intval($data->count);
     }
     return 0;
 }
コード例 #2
0
ファイル: Facebook.php プロジェクト: venturepact/blog
 /**
  * {@inheritDoc}
  */
 public function getShares($url)
 {
     $data = xt_get_url_contents(sprintf(self::API_URL, $url));
     if (!empty($data)) {
         $data = json_decode($data);
         return intval(isset($data->likes) ? $data->likes : $data->shares);
     }
     return 0;
 }
コード例 #3
0
ファイル: StumbleUpon.php プロジェクト: venturepact/blog
 /**
  * {@inheritDoc}
  */
 public function getShares($url)
 {
     $data = xt_get_url_contents(sprintf(self::API_URL, $url));
     if (!empty($data)) {
         $data = json_decode($data, true);
         return isset($data['result']['views']) ? intval($data['result']['views']) : 0;
     }
     return 0;
 }
コード例 #4
0
ファイル: Pinterest.php プロジェクト: venturepact/blog
 /**
  * {@inheritDoc}
  */
 public function getShares($url)
 {
     $data = xt_get_url_contents(sprintf(self::API_URL, $url));
     if (!empty($data)) {
         $data = json_decode(preg_replace('/^receiveCount\\((.*)\\)$/', "\\1", $data));
         return intval($data->count);
     } else {
         return 0;
     }
 }
コード例 #5
0
ファイル: Google.php プロジェクト: venturepact/blog
 /**
  * {@inheritDoc}
  */
 public function getShares($url)
 {
     $html = xt_get_url_contents(sprintf(self::IFRAME_URL, $url));
     if (!empty($html)) {
         // Disable libxml errors
         libxml_use_internal_errors(true);
         $document = new \DOMDocument();
         $document->loadHTML($html);
         $aggregateCount = $document->getElementById('aggregateCount');
         // Restore libxml errors
         libxml_use_internal_errors();
         // Instead of big numbers, Google returns strings like >10K
         if (preg_match('/>([0-9]+)K/', $aggregateCount->nodeValue, $matches)) {
             return $matches[1] * 1000;
         }
         return intval($aggregateCount->nodeValue);
     }
     return 0;
 }
コード例 #6
0
ファイル: functions.php プロジェクト: venturepact/blog
function xt_get_google_fonts()
{
    $cache_key = 'xt_google_fonts';
    $cache_expire = 60 * 60 * 24 * 7;
    // 1 week
    $fonts_data = get_transient($cache_key);
    if ($fonts_data !== false) {
        $fonts_data = unserialize($fonts_data);
    } else {
        $url = "https://www.googleapis.com/webfonts/v1/webfonts?key=" . XT_GOOGLE_API_KEY;
        $json = xt_get_url_contents($url);
        $fonts_data = json_decode($json);
        if (!empty($fonts_data->items)) {
            $fonts_data = $fonts_data->items;
            set_transient($cache_key, serialize($fonts_data), $cache_expire);
        } else {
            $fonts_data = array();
        }
    }
    if (empty($fonts_data)) {
        return array();
    }
    return $fonts_data;
}
コード例 #7
0
ファイル: import.php プロジェクト: venturepact/blog
 function get_and_save($url)
 {
     global $wpdb;
     $data = xt_get_url_contents($url);
     if (!empty($data)) {
         $data = json_decode($data, true);
         foreach ($data as $table => $rows) {
             $wpdb->query($wpdb->prepare("TRUNCATE TABLE %s", $wpdb->prefix . $table));
             if (!empty($rows)) {
                 foreach ($rows as $row) {
                     $wpdb->insert($wpdb->prefix . $table, $row);
                 }
             }
         }
     }
 }
コード例 #8
0
ファイル: parsers.class.php プロジェクト: venturepact/blog
 function parse($file)
 {
     $this->wxr_version = $this->in_post = $this->cdata = $this->data = $this->sub_data = $this->in_tag = $this->in_sub_tag = false;
     $this->authors = $this->posts = $this->term = $this->category = $this->tag = array();
     $xml = xml_parser_create('UTF-8');
     xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1);
     xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, 0);
     xml_set_object($xml, $this);
     xml_set_character_data_handler($xml, 'cdata');
     xml_set_element_handler($xml, 'tag_open', 'tag_close');
     if (!xml_parse($xml, xt_get_url_contents($file), true)) {
         $current_line = xml_get_current_line_number($xml);
         $current_column = xml_get_current_column_number($xml);
         $error_code = xml_get_error_code($xml);
         $error_string = xml_error_string($error_code);
         return new WP_Error('XML_parse_error', 'There was an error when reading this WXR file', array($current_line, $current_column, $error_string));
     }
     xml_parser_free($xml);
     if (!preg_match('/^\\d+\\.\\d+$/', $this->wxr_version)) {
         return new WP_Error('WXR_parse_error', __('This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer'));
     }
     return array('authors' => $this->authors, 'posts' => $this->posts, 'categories' => $this->category, 'tags' => $this->tag, 'terms' => $this->term, 'base_url' => $this->base_url, 'version' => $this->wxr_version);
 }