Example #1
0
function url_fetch_cached($url, &$data, &$time, $headers = FALSE, $cookiefile = FALSE, $cf_preset = FALSE)
{
    global $url_fetch;
    $cachefile = $url_fetch['cachefile_prefix'] . ($cf_preset ? $cf_preset : md5($url));
    if (!file_exists(dirname($cachefile))) {
        mkdir(dirname($cachefile), 0777, true);
    }
    $data = '';
    if (!preg_match('#^https?://...#', $url)) {
        return "Bad URL {$url}";
    }
    if (file_exists($cachefile) && time() - filectime($cachefile) < $url_fetch['min_time_before_refetch']) {
        $data = file_get_contents($cachefile);
        $time = filectime($cachefile);
        return '';
    }
    $err = url_fetch($url, $data, $headers, $cookiefile);
    if (empty($err)) {
        $time = time();
        return file_put_contents($cachefile, $data) ? '' : "Cache write error to file {$cachefile}";
    } else {
        if (file_exists($cachefile) && time() - filectime($cachefile) <= $url_fetch['max_time_cache_valid']) {
            $data = file_get_contents($cachefile);
            $time = filectime($cachefile);
        }
        return "HTTP error: {$err}";
    }
}
Example #2
0
function gdrive2json($key, $gid = '0', $version = 'ccc')
{
    if (!$key) {
        exit("'key' parameter is required.");
    }
    $url = $version == 'ccc' ? "https://docs.google.com/spreadsheet/ccc?output=csv&key={$key}&gid={$gid}" : "https://docs.google.com/spreadsheets/d/{$key}/export?format=csv&gid={$gid}";
    $rc = url_fetch($url, $csv_str);
    if ($rc) {
        exit("URL fetch error: {$rc}");
    }
    $csv = new parseCSV("{$csv_str}\n");
    $a = $csv->data;
    foreach ($a as &$i) {
        foreach ($i as $k => $v) {
            if (strpos($k, '.')) {
                if ($v && preg_match('/^([^.]+)\\.([^.]+)(\\.([^.]+))?$/', $k, $m)) {
                    if (!isset($i[$m[1]])) {
                        $i[$m[1]] = array();
                    }
                    $x =& $i[$m[1]];
                    if (count($m) >= 5 && $m[4]) {
                        if (!isset($x[$m[2]])) {
                            $x[$m[2]] = array();
                        }
                        $x[$m[2]][$m[4]] = $v;
                    } else {
                        $x[$m[2]] = $v;
                    }
                }
                unset($i[$k]);
            } else {
                if (!$v) {
                    unset($i[$k]);
                }
            }
        }
    }
    return json_encode($a);
}
Example #3
0
function runlike($DB)
{
    $cookie = "";
    $status = getStatus($DB);
    $uid = $status['cur'];
    $user = $DB->Query("tl_sid", "uid", $uid);
    $qq = $user['qq'];
    $sid = $user['sid'];
    $re = '/href="(http:\\/\\/blog[0-9]*?.z.qq.com\\/like.*?)">赞/';
    $url = "http://ish.z.qq.com/infocenter_v2.jsp?B_UID=" . $qq . "&sid=" . $sid . "&g_ut=1";
    $page = url_fetch($url);
    preg_match_all($re, $page, $matches);
    $ia = count($matches[1]);
    for ($i = 0; $i < $ia; $i++) {
        sleep(5);
        $cookie2 = like_click($matches[1][$i], $url, $cookie);
        if (!empty($cookie2)) {
            $cookie = $cookie2;
        }
    }
    echo "ok";
}
Example #4
0
function oembed_embed_thumbnails(&$feed)
{
    foreach ($feed as &$status) {
        // Loop through the feed
        if (stripos($status->text, 'NSFW') === FALSE) {
            // Ignore image fetching for tweets containing NSFW
            if ($status->entities) {
                // If there are entities
                $entities = $status->entities;
                if ($entities->urls) {
                    foreach ($entities->urls as $urls) {
                        // Loop through the URL entities
                        if ($urls->expanded_url != "") {
                            // Use the expanded URL, if it exists, to pass to Oembed provider
                            $url = $urls->expanded_url;
                        } else {
                            $url = $urls->url;
                        }
                        $matched_urls[urlencode($url)][] = $status->id;
                    }
                } else {
                    //	No URLs, do nothing
                    $matched_urls[] = null;
                }
            }
        }
    }
    //	Reduce the array of empty items
    foreach ($matched_urls as $key => $value) {
        if (null == $value) {
            unset($matched_urls[$key]);
        }
    }
    // Make a single API call to Embedkit.
    if (defined('EMBEDKIT_KEY') && EMBEDKIT_KEY != "") {
        //	Only the URLs which we're going to pass to Embedkit
        $justUrls = array_keys($matched_urls);
        $count = count($justUrls);
        if ($count == 0) {
            return;
        }
        // if ($count > 20) {
        // 	// Things can slow down with lots of links.
        // 	$justUrls = array_chunk ($justUrls, 10);
        // 	$justUrls = $justUrls[0];
        // }
        $url = 'https://embedkit.com/api/v1/embed?key=' . EMBEDKIT_KEY . '&urls=' . implode(',', $justUrls) . '&format=json';
        $embedly_json = url_fetch($url);
        $oembeds = json_decode($embedly_json);
        if ($oembeds->type != 'error') {
            //	Single statuses don't come back in an array
            if (!is_array($oembeds)) {
                $temp = array(0 => $oembeds);
                $oembeds = $temp;
            }
            foreach ($justUrls as $index => $url) {
                $thumb = "";
                $title = "";
                if ($oembeds[$index]->thumbnail_url) {
                    //	Direct links to files
                    $thumb = $oembeds[$index]->thumbnail_url;
                }
                if ($oembeds[$index]->title) {
                    //	Direct links to files
                    $title = $oembeds[$index]->title;
                }
                if ($thumb) {
                    //	Embed the thumbnail
                    $html = theme('external_link', urldecode($url), "<img src=\"" . image_proxy($thumb, "") . "\"" . " title=\"{$title}\" alt=\"{$title}\" class=\"embedded\" />");
                    foreach ($matched_urls[$url] as $statusId) {
                        $feed[$statusId]->text = $feed[$statusId]->text . '<br />' . '<span class="embed">' . $html . '</span>';
                    }
                } elseif ($title) {
                    //	Embed a link
                    $html = theme('external_link', urldecode($url), $title);
                    foreach ($matched_urls[$url] as $statusId) {
                        $feed[$statusId]->text = $feed[$statusId]->text . '<br />' . '<span class="embed">' . $html . '</span>';
                    }
                }
            }
        }
    }
}
Example #5
0
function testsid($qq, $sid)
{
    $url = "http://ish.z.qq.com/infocenter_v2.jsp?B_UID=" . $qq . "&sid=" . $sid . "&g_ut=1";
    $page = url_fetch($url);
    if (strpos($page, "赞")) {
        return true;
    } else {
        return false;
    }
}
Example #6
0
function oembed_embed_thumbnails(&$feed)
{
    foreach ($feed as &$status) {
        // Loop through the feed
        if (stripos($status->text, 'NSFW') === FALSE) {
            // Ignore image fetching for tweets containing NSFW
            if ($status->entities) {
                // If there are entities
                $entities = $status->entities;
                if ($entities->urls) {
                    foreach ($entities->urls as $urls) {
                        // Loop through the URL entities
                        if ($urls->expanded_url != "") {
                            // Use the expanded URL, if it exists, to pass to Oembed provider
                            $url = $urls->expanded_url;
                        } else {
                            $url = $urls->url;
                        }
                        $matched_urls[urlencode($url)][] = $status->id;
                    }
                } else {
                    //	No URLs, do nothing
                    $matched_urls[] = null;
                }
            }
        }
    }
    //	Reduce the array of empty items
    foreach ($matched_urls as $key => $value) {
        if (null == $value) {
            unset($matched_urls[$key]);
        }
    }
    // Make a single API call to Embedkit.
    if (defined('EMBEDKIT_KEY') && EMBEDKIT_KEY != "") {
        //	Only the URLs which we're going to pass to Embedkit
        $justUrls = array_keys($matched_urls);
        $count = count($justUrls);
        if ($count == 0) {
            return;
        }
        // if ($count > 20) {
        // 	// Things can slow down with lots of links.
        // 	$justUrls = array_chunk ($justUrls, 10);
        // 	$justUrls = $justUrls[0];
        // }
        $url = 'https://embedkit.com/api/v1/embed?key=' . EMBEDKIT_KEY . '&urls=' . implode(',', $justUrls) . '&format=json';
        $embedly_json = url_fetch($url);
        $oembeds = json_decode($embedly_json);
        $tumblr_js_once = 0;
        if ($oembeds->type != 'error') {
            //	Single statuses don't come back in an array
            if (!is_array($oembeds)) {
                $temp = array(0 => $oembeds);
                $oembeds = $temp;
            }
            foreach ($justUrls as $index => $url) {
                $thumb = "";
                $title = "";
                $html = "";
                $embedHTML = "";
                if ($oembeds[$index]->thumbnail_url) {
                    //	Direct links to files
                    $thumb = $oembeds[$index]->thumbnail_url;
                }
                if ($oembeds[$index]->title) {
                    //	Direct links to files
                    $title = $oembeds[$index]->title;
                }
                if ($oembeds[$index]->html) {
                    //	Direct links to files
                    $embedHTML = $oembeds[$index]->html;
                }
                if ($embedHTML) {
                    //	Embed an HTML fragment
                    $html = $embedHTML;
                    //	Remove embedded Tweets
                    if (strstr($html, "//platform.twitter.com/widgets.js") != FALSE) {
                        $html = "";
                    }
                    //	Stop Tumblr JavaScript duplication
                    if (strstr($html, "secure.assets.tumblr.com/post.js") != FALSE) {
                        if ($tumblr_js_once > 0) {
                            // <script async src=\"https:\/\/secure.assets.tumblr.com\/post.js\"><\/script>
                            $html = str_replace('src="https://secure.assets.tumblr.com/post.js"', '', $html);
                        }
                        $tumblr_js_once++;
                    }
                    foreach ($matched_urls[$url] as $statusId) {
                        if ($html != "") {
                            $feed[$statusId]->text = $feed[$statusId]->text . '<br />' . '<span class="embed">' . $html . '</span>';
                        }
                    }
                } elseif ($thumb) {
                    //	Embed the thumbnail
                    $html = theme('external_link', urldecode($url), "<img src=\"" . image_proxy($thumb, "") . "\"" . " title=\"{$title}\" alt=\"{$title}\" class=\"embedded\" />");
                    foreach ($matched_urls[$url] as $statusId) {
                        //	Do *not* display a thumb if there is a native image attached.
                        //	Not a perfect way to avoid duplication.
                        if ($feed[$statusId]->entities->media) {
                            //	Do nothing
                        } else {
                            $feed[$statusId]->text = $feed[$statusId]->text . '<br>' . '<span class="embed">' . $html . '</span>';
                        }
                    }
                } elseif ($title) {
                    //	Embed a link
                    $html = theme('external_link', urldecode($url), $title);
                    foreach ($matched_urls[$url] as $statusId) {
                        $feed[$statusId]->text = $feed[$statusId]->text . '<br />' . '<span class="embed">' . $html . '</span>';
                    }
                }
            }
        }
    }
}