function send() { $this->_buildXML(); $d = new Hyp_HTTP_Request(); foreach ($this->sendTo as $sendTo) { $d->init(); $d->url = $sendTo['url']; $d->method = 'POST'; $d->headers = "Content-Type: text/xml\r\n"; $d->post = $sendTo['extended'] ? $this->xml_extended : $this->xml_normal; $d->connect_timeout = $this->connect_timeout; $d->read_timeout = $this->read_timeout; $d->blocking = $this->blocking; $d->get(); if ($this->debug) { $this->querys[$d->url] = $d->query; } $this->results[$d->url]['query'] = $d->query; $this->results[$d->url]['rc'] = $d->rc; $this->results[$d->url]['header'] = $d->header; $this->results[$d->url]['data'] = $d->data; } $d = NULL; unset($d); }
function get_url_info($url) { $ttl = 60 * 60 * 24; // 1day $cachepath = XOOPS_ROOT_PATH . '/class/hyp_common/cache'; $cache = $cachepath . '/' . md5($url) . '.rdi'; if (is_file($cache) && filemtime($cache) + $ttl > UNIX_TIME) { $ret = unserialize(file_get_contents($cache)); if (isset($ret['lasturl'])) { return $ret; } } include_once XOOPS_TRUST_PATH . '/class/hyp_common/hyp_common_func.php'; // GC $gc = $cachepath . '/rdi.gc'; if (!is_file($gc) || filemtime($gc) < UNIX_TIME - 86400) { GC_rdi($cachepath, 86400 * 30); } $h = new Hyp_HTTP_Request(); $h->url = $url; $h->getSize = 4096; $h->get(); $ret = array('header' => '', 'handheld' => '', 'lasturl' => ''); if ($h->rc === 200 || $h->rc === 206) { $html = $h->data; $ret['header'] = $h->header; $ret['lasturl'] = $url === $h->url ? '' : $h->url; if (strpos($html, '<body') !== FALSE) { list($head, $dum) = explode('<body', $html, 2); if (preg_match_all('/<link [^>]*?rel=(\'|")alternate\\1[^>]*?>/i', $head, $match)) { foreach ($match[0] as $rel) { if (preg_match('/media=(\'|")handheld\\1/i', $rel) && preg_match('/href=(\'|")(.+)?\\1/i', $rel, $link)) { $ret['handheld'] = str_replace('&', '&', $link[2]); } } } } } if ($fp = fopen($cache, 'wb')) { fwrite($fp, serialize($ret)); fclose($fp); } return $ret; }
function plugin_urlbookmark_get_title($url) { $ht = new Hyp_HTTP_Request(); $ht->init(); $ht->ua = 'Mozilla/5.0'; $ht->url = $url; $ht->get(); if ($ht->rc !== 200) { return 'The page not found. (' . $ht->rc . ')'; } $data = $ht->data; $ht = NULL; $buf = preg_replace('/[\\x00\\r\\n]+/', '', $data); if (preg_match('/<title[^>]*>(.+?)<\\/title>/i', $buf, $tmpary)) { $title = trim($tmpary[1]); } else { $title = rawurldecode($url); } $title = str_replace(array('<', '>'), array('<', '>'), $title); $enc = $this->get_encoding($buf); if ($enc !== 'auto') { $this->func->encode_numericentity($title, $this->cont['SOURCE_ENCODING'], $enc); $title = mb_convert_encoding($title, $this->cont['SOURCE_ENCODING'], $enc); } else { if (extension_loaded('mbstring')) { $enc = $this->get_encoding($buf); if (strtoupper($this->cont['SOURCE_ENCODING']) === 'UTF-8') { $title = mb_convert_encoding($title, $this->cont['SOURCE_ENCODING'], $enc); } else { $_sub = mb_substitute_character(); mb_substitute_character(0x3c); $_title = @mb_convert_encoding($title, $this->cont['SOURCE_ENCODING'], $enc); if (strpos($_title, '<') !== FALSE) { $title = @mb_convert_encoding($title, 'UTF-8', $enc); $title = mb_convert_encoding($title, 'HTML-ENTITIES', 'UTF-8'); } else { $title = $_title; } mb_substitute_character($_sub); } } } return trim($title); }
function make_thumbnail($url, $prms) { static $count = 0; if (!preg_match('#^https?://#', $url)) { $url = 'http://' . $url; } $target = $this->func->htmlspecialchars($prms['target']); $nolink = $prms['nolink']; $thumburl = $this->fetch_url . $url; $sha1 = sha1($thumburl); $prm_size = strtolower($prms['size']); if (!preg_match('/[sml]/', $prm_size)) { $prm_size = 's'; } $thumb_size = $this->thumb_size[$prm_size]; $size = $thumb_size['width'] . 'x' . $thumb_size['height']; $thumb_file = $this->cont['CACHE_DIR'] . 'ASIN_SITEIMAGE_' . $sha1 . '_' . $prm_size . '.jpg'; $cache = $this->cont['CACHE_DIR'] . 'plugin/' . $sha1 . '.siteimage'; $is_new = !is_file($cache); if ($is_new || $count < $this->get_max_once && filemtime($cache) + $this->cache_day * 86400 < $this->cont['UTC']) { $count++; $ht = new Hyp_HTTP_Request(); $ht->init(); $ht->ua = 'Mozilla/5.0'; $ht->url = $thumburl; $ht->get(); $image = ''; if ($ht->rc === 200) { $image = $ht->data; } $ht = NULL; if ($image && ($fp = fopen($cache, 'wb'))) { fwrite($fp, $image); fclose($fp); foreach (array('s', 'm', 'l') as $_size) { @unlink($this->cont['CACHE_DIR'] . 'ASIN_SITEIMAGE_' . $sha1 . '_' . $_size . '.jpg'); } if ($is_new) { $this->func->pkwk_touch_file($cache, $this->cont['UTC'] - $this->cache_day * 86400 + $this->cache1st_min * 60); } } } if (!is_file($thumb_file)) { copy($cache, $thumb_file); HypCommonFunc::ImageResize($thumb_file, $size); HypCommonFunc::ImageMagickRoundCorner($thumb_file, '', 5, 2); } $cache_url = str_replace($this->cont['DATA_HOME'], $this->cont['HOME_URL'], $thumb_file); $url = $this->func->htmlspecialchars($url); $title = preg_replace('#^https?://#i', '', $url); $ret = "<img src=\"" . $cache_url . "\" width=\"{$thumb_size['width']}\" height=\"{$thumb_size['height']}\" alt=\"{$title}\">"; if (!$nolink) { $ret = "<a class=\"siteimage\" href=\"{$url}\" target=\"{$target}\" title=\"{$title}\">" . $ret . "</a>"; } return $ret; }
function _sendQuery($params) { $url = $this->_getUrl($params); $timer = $this->cacheDir . 'hyp_hsa_' . $this->AccessKeyId . '.timer'; $loop = 0; if ($this->OneRequestPerSec) { while ($loop < $this->retry_count && is_file($timer) && filemtime($timer) >= time()) { $loop++; clearstatcache(); usleep($this->retry_interval * 1000); // 250ms } } if ($this->OneRequestPerSec && $loop >= $this->retry_count) { $this->xml = ''; $this->error = 'Request Error: Too busy.'; } else { if ($this->OneRequestPerSec) { HypCommonFunc::touch($timer); } $ht = new Hyp_HTTP_Request(); $ht->init(); $this->url = $ht->url = $url; $ht->get(); if ($ht->rc === 200 || $ht->rc === 403) { $data = $ht->data; $xm = new HypSimpleXML(); $this->xml = $xm->XMLstr_in($data); //var_dump($this->xml);exit(); if ($xm->error) { $this->error = $xm->error; } else { if ($error = @$this->xml['Items']['Request']['Errors']['Error']) { $this->error = mb_convert_encoding($error['Message'], $this->encoding, 'UTF-8'); } else { if ($error = @$this->xml['Items'][0]['Request']['Errors']['Error']) { $this->error = mb_convert_encoding($error['Message'], $this->encoding, 'UTF-8'); } else { if ($error = @$this->xml['OperationRequest']['Errors']['Error']) { $this->error = $error['Code'] . ': ' . mb_convert_encoding($error['Message'], $this->encoding, 'UTF-8'); } else { if ($error = @$this->xml['Error']) { $this->error = $error['Code'] . ': ' . mb_convert_encoding($error['Message'], $this->encoding, 'UTF-8'); } } } } } } else { $this->xml = ''; $this->error = 'HTTP Error: ' . $ht->rc; } } }
function cache_image_fetch(&$lvar) { $parse = parse_url($lvar['name']); $query = isset($parse['query']) ? $parse['query'] : ''; if ($query) { if ($pos = strrpos($query, '=')) { $query = substr($query, $pos + 1); } } $name = $parse['host'] . '_' . ($query ? $query : basename($parse['path'])); $filename = $this->cont['UPLOAD_DIR'] . $this->func->encode($lvar['page']) . "_" . $this->func->encode($name); $cache = FALSE; $size = array(); if (!is_file($filename)) { $ht = new Hyp_HTTP_Request(); $ht->init(); $ht->ua = 'Mozilla/5.0'; $ht->url = $lvar['name']; $ht->get(); if ($ht->rc == 200 && $ht->data) { $dat['data'] = $ht->data; // 自サイト外のファイルは著作権保護する $copyright = !($this->func->refcheck(0, $lvar['name']) || preg_match($this->cont['NO_REF_EXTIMG_REG'], $lvar['name'])); } else { // ファイルが取得できないので noimage とする $copyright = 0; $dat['data'] = file_get_contents($this->cont['IMAGE_DIR'] . 'noimage.png'); } if ($this->cache_image_save($dat['data'], $lvar['page'], $filename, $name, $copyright)) { $cache = TRUE; } } else { // すでにキャッシュ済み $cache = TRUE; } if ($cache) { $lvar['name'] = $name; $lvar['file'] = $filename; // ログファイル取得 $lvar['status'] = $this->get_fileinfo($lvar['file']); } else { $lvar['file'] = ''; } return; }
HypCommonFunc::readfile($file); exit; } else { header('HTTP/1.1 301 Moved Permanently'); header('Status: 301 Moved Permanently'); header('Location: ' . $url); } exit; } include_once $trustpath . '/class/hyp_common/hyp_common_func.php'; // GC $gc = $cachepath . '/i4k.gc'; if (!is_file($gc) || filemtime($gc) < UNIX_TIME - $maxage) { GC_i4k($cachepath, $TTL); } $h = new Hyp_HTTP_Request(); $h->url = $url; $h->connect_timeout = 3; $h->read_timeout = 5; $h->get(); if ($h->rc === 200) { if (!HypCommonFunc::flock_put_contents($file, $h->data)) { header('Location: ' . $url); exit; } clearstatcache(); $org_size = getimagesize($file); if ($org_size) { $mime = isset($org_size['mime']) ? $org_size['mime'] : 'image/' . $org_size[2]; save_i4ks($size_file, $org_size, $mime); $quality = 50;
function googleAnalyticsGetImgSrc($id, $title = '-') { $url = 'http://www.google-analytics.com/__utm.gif?'; $version = '4.4sh'; $cookie_name = '__utmmobile'; $cookie_path = '/'; $cookie_ttl = 63072000; if (substr($id, 0, 2) === 'UA') { $id = 'MO' . substr($id, 2); } $parsedUrl = parse_url($this->myRoot); $time = time(); $rand = rand(0, 0x7fffffff); $domainName = $parsedUrl['host']; $documentReferer = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '-'; $documentPath = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; if ($documentPath) { $documentPath = urldecode($documentPath); } $ip = preg_match('/^([0-9]+\\.[0-9]+\\.[0-9]+.).*$/', $_SERVER['REMOTE_ADDR'], $match) ? $match[1] . '0' : ''; $title = rawurlencode(mb_convert_encoding($title, 'UTF-8', $this->inputEncode)); $model = ''; if (!empty($this->vars['ua']['model'])) { $model = str_replace(array(';', '='), array('%3B', '%3D'), $this->vars['ua']['model']); } $userVar = $this->vars['ua']['carrier']; if ($model) { $userVar .= ' ' . $model; } $coustomVar = '8(Carrier*2!Model)9(' . $this->_crop_urlencode($this->vars['ua']['carrier'], 57) . '*2!' . $this->_crop_urlencode($model, 59) . ')11(1*2!1)'; $vid = ''; if (isset($_COOKIE[$cookie_name])) { $vid = $_COOKIE[$cookie_name]; } else { if (isset($_SESSION[$cookie_name])) { $vid = $_SESSION[$cookie_name]; } } if (!$vid || !preg_match('/^0x[0-9a-f]{16}$/i', $vid)) { if ($this->vars['ua']['uid']) { $md5key = $this->vars['ua']['uid'] . $id; } else { $md5key = $this->vars['ua']['agent'] . uniqid($rand, true); } $vid = '0x' . substr(md5($md5key), 0, 16); } $_SESSION[$cookie_name] = $vid; setcookie($cookie_name, $vid, $time + $cookie_ttl, $cookie_path); $query = array(); $query[] = 'utmwv=' . $version; $query[] = 'utmn=' . $rand; $query[] = 'utmhn=' . urlencode($domainName); $query[] = 'utmr=' . urlencode($documentReferer); $query[] = 'utmp=' . urlencode($documentPath); $query[] = 'utmac=' . $id; $query[] = 'utmcc=' . '__utma%3D999.999.999.999.999.1%3B__utmv%3D999.' . urlencode($userVar) . '%3B'; $query[] = 'utmvid=' . $vid; $query[] = 'utmip=' . $ip; $query[] = 'utme=' . $coustomVar; $query[] = 'utmdt=' . $title; $url .= join('&', $query); // SSL 環境 or URL文字数制限 1024 bytes amp;[3]*9 = 27, 1024 - 27 = 997 // サーバで代理送信 if (strtolower($parsedUrl['scheme']) === 'https' || strlen($url) > 997) { $ht = new Hyp_HTTP_Request(); $ht->init(); $ht->url = $url; $ht->headers = 'Accepts-Language: ' . $_SERVER['HTTP_ACCEPT_LANGUAGE'] . "\r\n"; $ht->ua = $_SERVER['HTTP_USER_AGENT']; $ht->blocking = FALSE; $ht->get(); $url = ''; } return $url; }
function twitter_post($username, $password, $msg, $link = '', $convert = TRUE) { if ($link) { $link = ' ' . $this->bitly($link); } $max = $link ? 140 - strlen($link) : 140; if ($convert) { $page = isset($this->root->vars['page']) ? $this->root->vars['page'] : ''; $msg = strip_tags($this->convert_html($msg, $page)); } //$msg = preg_replace('/(https?:\/\/[\w\/\@\$()!?&%#:;.,~\'=*+-]+)/ie', "\$this->bitly('$1')", $msg); if (mb_strlen($msg) > $max) { $msg = mb_substr($msg, 0, $max - 3) . '...'; } if ($link) { $msg .= $link; } $url = 'http://' . $username . ':' . $password . '@' . 'twitter.com/statuses/update.xml?'; $url .= 'status=' . rawurlencode(mb_convert_encoding($msg, 'UTF-8', $this->cont['SOURCE_ENCODING'])); $url .= '&source=xpWiki'; $d = new Hyp_HTTP_Request(); $d->url = $url; $d->method = 'POST'; $d->blocking = FALSE; $d->get(); $q = $d->query; $d = NULL; }
function http_get_contents(&$url, $size = 0) { file_put_contents(get_url_filename($url), 'DefaultIcon'); include_once dirname(dirname(__FILE__)) . '/hyp_common_func.php'; $ht = new Hyp_HTTP_Request(); $ht->init(); $ht->url = $url; if ($size) { $ht->getSize = $size; } $ht->ua = 'Mozilla/5.0'; $ht->connect_timeout = 2; $ht->read_timeout = 5; $ht->get(); if ($size) { $url = $ht->url; } return $ht->rc == 404 || $ht->rc == 410 || $ht->rc > 600 || $ht->rc < 100 ? null : $ht->data; }
function _sendQuery($params) { $this->url = $this->_getUrl($params); $this->data = null; $timer = $this->cacheDir . 'hyp_hsr_' . $this->DevId . '.timer'; $loop = 0; if ($this->OneRequestPerSec) { while ($loop < $this->retry_count && is_file($timer) && filemtime($timer) >= time()) { $loop++; clearstatcache(); usleep($this->retry_interval * 1000); // 250ms } } if ($this->OneRequestPerSec && $loop >= $this->retry_count) { $this->xml = ''; $this->error = 'Request Error: Too busy.'; } else { if ($this->OneRequestPerSec) { HypCommonFunc::touch($timer); } $ht = new Hyp_HTTP_Request(); $ht->init(); $ht->url = $this->url; $ht->get(); if ($ht->rc === 200) { if (!$this->parseXml) { $this->xml = ''; } else { $this->data = $ht->data; $xm = new HypSimpleXML(); $this->xml = $xm->XMLstr_in($this->data); } } else { $this->xml = ''; $this->error = 'HTTP Error: ' . $ht->rc; } } }