Example #1
0
 function get_wakatigaki(&$str)
 {
     if (!$this->kakasi_path) {
         return false;
     }
     if ($this->tmp_dir) {
         // gc(ガベージコレクト)
         if (mt_rand(1, 100000) <= $this->gc_probability * 100) {
             if ($handle = opendir($this->tmp_dir)) {
                 while (false !== ($file = readdir($handle))) {
                     if (strpos($file, ".") === 0) {
                         continue;
                     }
                     if (filemtime($this->tmp_dir . $file) < time() - $this->cache_expire * 3600) {
                         unlink($this->tmp_dir . $file);
                     }
                 }
                 closedir($handle);
             }
         }
         $tmpfile = $this->tmp_dir . md5($str) . ".tmp";
         // キャッシュ
         if (file_exists($tmpfile)) {
             include_once dirname(__FILE__) . '/hyp_common_func.php';
             HypCommonFunc::touch($tmpfile);
             $str = join("", file($tmpfile));
             return true;
         }
     }
     $put = $str;
     $nwa = "";
     $match = array();
     if (preg_match_all("/((\"|').+?(?:\\2))/", $put, $match, PREG_PATTERN_ORDER)) {
         $match[1] = array_unique($match[1]);
         foreach ($match[1] as $rep) {
             $put = str_replace($rep, " ", $put);
         }
         $put = preg_replace("/ +/", " ", $put);
         $nwa = join(" ", $match[1]) . " ";
     }
     if (!$this->execute($put, "-w -c")) {
         return false;
     }
     $str = $nwa . $put;
     if ($this->tmp_dir) {
         if ($fp = fopen($tmpfile, "wb")) {
             fputs($fp, $str);
             fclose($fp);
         }
     }
     return true;
 }
Example #2
0
function GC_rdi($cachepath, $TTL, $showResult = FALSE)
{
    HypCommonFunc::touch($cachepath . '/rdi.gc');
    $i = 0;
    $i2 = 0;
    if ($handle = opendir($cachepath)) {
        while (false !== ($file = readdir($handle))) {
            if (substr($file, -4) === '.rdi') {
                $i2++;
                $target = $cachepath . '/' . $file;
                if (filemtime($target) < UNIX_TIME - $TTL) {
                    unlink($target);
                    $i++;
                }
            }
        }
        closedir($handle);
    }
    if ($showResult) {
        echo $i . '/' . $i2 . ' files removed.';
    }
}
Example #3
0
 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;
         }
     }
 }
Example #4
0
 function sendMail($spamlev)
 {
     global $xoopsUser;
     $info = array();
     $info['TIME'] = date('r', time());
     if (is_object($xoopsUser)) {
         $info['UID'] = (int) $xoopsUser->uid();
         $info['UNAME'] = $xoopsUser->uname();
     } else {
         $info['UID'] = 0;
         $info['UNAME'] = 'Guest';
     }
     $info['REQUEST_URI'] = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
     $info['HTTP_REFERER'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
     $info['HTTP_USER_AGENT'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
     $info['REMOTE_ADDR'] = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
     $info['SPAM LEVEL'] = $spamlev;
     $_info = '';
     foreach ($info as $key => $value) {
         $_info .= $key . ': ' . $value . "\n";
     }
     $_info .= str_repeat('-', 30) . "\n";
     $post = $_POST;
     // Key:excerpt があればトラックかも->文字コード変換
     if (isset($post['excerpt']) && function_exists('mb_convert_variables')) {
         if (isset($post['charset']) && $post['charset'] != '') {
             // TrackBack Ping で指定されていることがある
             // うまくいかない場合は自動検出に切り替え
             if (mb_convert_variables($this->encode, $post['charset'], $post) !== $post['charset']) {
                 mb_convert_variables($this->encode, 'auto', $post);
             }
         } else {
             if (!empty($post)) {
                 // 全部まとめて、自動検出/変換
                 mb_convert_variables($this->encode, 'auto', $post);
             }
         }
     }
     $message = $_info . '$_POST :' . "\n" . print_r($post, TRUE);
     $message .= "\n" . str_repeat('=', 30) . "\n\n";
     if ($this->send_mail_interval) {
         $mail_tmp = XOOPS_TRUST_PATH . '/uploads/hyp_common/' . str_replace('/', '_', preg_replace('#https?://#i', '', XOOPS_URL)) . '.SPAM.hyp';
         if (!file_exists($mail_tmp)) {
             HypCommonFunc::flock_put_contents($mail_tmp, $message);
             return;
         } else {
             $mtime = filemtime($mail_tmp);
             if ($mtime + $this->send_mail_interval * 60 > time()) {
                 if (HypCommonFunc::flock_put_contents($mail_tmp, $message, 'ab')) {
                     HypCommonFunc::touch($mail_tmp, $mtime);
                 }
                 return;
             } else {
                 $message = HypCommonFunc::flock_get_contents($mail_tmp) . $message;
                 unlink($mail_tmp);
             }
         }
     }
     $config_handler =& xoops_gethandler('config');
     $xoopsConfig =& $config_handler->getConfigsByCat(XOOPS_CONF);
     $subject = '[' . $xoopsConfig['sitename'] . '] POST Spam Report';
     $xoopsMailer =& getMailer();
     $xoopsMailer->useMail();
     $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
     $xoopsMailer->setFromName($xoopsConfig['sitename']);
     $xoopsMailer->setSubject($subject);
     $xoopsMailer->setBody($message);
     $xoopsMailer->setToEmails($xoopsConfig['adminmail']);
     $xoopsMailer->send();
     $xoopsMailer->reset();
 }
Example #5
0
function GC_i4k($cachepath, $TTL, $showResult = FALSE)
{
    HypCommonFunc::touch($cachepath . '/i4k.gc');
    $i = 0;
    $i2 = 0;
    if ($handle = opendir($cachepath)) {
        $iua = ignore_user_abort(true);
        while (false !== ($file = readdir($handle))) {
            if (substr($file, -4) === '.i4k' || substr($file, -5) === '.i4ks') {
                $i2++;
                $target = $cachepath . '/' . $file;
                $del = false;
                if ($del || filemtime($target) < UNIX_TIME - $TTL) {
                    unlink($target);
                    $i++;
                }
            }
        }
        closedir($handle);
        ignore_user_abort($iua);
    }
    if ($showResult) {
        echo $i . '/' . $i2 . ' files removed.';
    }
}
Example #6
0
function update_cache($url)
{
    if (!is_writable(FAVICON_CACHE_DIR)) {
        // cache dir was not writable
        return false;
    }
    // Garbage Collection
    $garbage = FAVICON_CACHE_DIR . '.garbage.time';
    if (!is_file($garbage) || filemtime($garbage) + 86400 < UNIX_TIME) {
        include_once dirname(dirname(__FILE__)) . '/hyp_common_func.php';
        HypCommonFunc::touch($garbage);
        clear_cache();
    }
    $url_org = $url;
    $html = http_get_contents($url, 81920);
    if ($html === false) {
        // connection failed or timed out
        $favicon = 'DefaultIcon';
    } else {
        if ($html === null) {
            // 404 status code or unsupported scheme
            $favicon = 'ErrorIcon';
        } else {
            $url = parse_url($url);
            $base = $url['scheme'] . '://' . $url['host'] . (isset($url['port']) ? ':' . $url['port'] : '');
            $url = $base . (isset($url['path']) ? $url['path'] : '/');
            $html = strtolower($html);
            list($html) = explode('</head>', $html);
            if (preg_match_all('#<link[^>]+?>#', $html, $m)) {
                $html = join(' ', $m[0]);
                if (preg_match('/<link ([^>]*)rel=[\'"]?(?:shortcut )?icon[\'"]?([^>]*)/', $html, $matches)) {
                    $link = implode(' ', $matches);
                    if (preg_match('/href=[\'"]?((?:https?:)?\\/\\/)?([^\'" ]+)/', $link, $matches)) {
                        $favicon = $matches[2];
                        if ($matches[1]) {
                            if ($matches[1][0] === '/') {
                                $matches[1] = $url['scheme'] . ':' . $matches[1];
                            }
                            $favicon = $matches[1] . $favicon;
                        } else {
                            if ($favicon[0] === '/') {
                                $favicon = $base . $favicon;
                            } else {
                                if (substr($url, -1) === '/') {
                                    $favicon = $url . $favicon;
                                } else {
                                    $favicon = dirname($url) . '/' . $favicon;
                                }
                            }
                        }
                        str_replace('/./', '/', $favicon);
                        while (preg_match('#[^/]+/\\.\\./#', $favicon)) {
                            $favicon = preg_replace('#[^/]+/\\.\\./#', '', $favicon);
                        }
                    }
                }
            }
            if (empty($favicon)) {
                $favicon = $base . '/favicon.ico';
            }
            $data = http_get_contents($favicon);
            if ($data === false) {
                // connection failed or timed out
                return false;
            } else {
                if ($ext = get_extention($data)) {
                    $favicon = md5($url) . $ext;
                    $image = get_image_filename($favicon);
                    if (file_put_contents($image, $data) === FALSE) {
                        $favicon = 'ErrorIcon';
                    }
                } else {
                    // no favicon or unknown format
                    $favicon = 'DefaultIcon';
                }
            }
        }
    }
    $filename = get_url_filename($url_org);
    if (file_put_contents($filename, $favicon)) {
        return $favicon;
    } else {
        return false;
    }
}
Example #7
0
 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;
         }
     }
 }