function RefererURLBeautifier_handler($target, $mother) { $keyword = false; if (preg_match('/\\W(q|query|k|keyword|search|stext|nlia|aqa|wd)(?:=|%3D)([^&]+)/i', $mother['url'], $matches)) { $keyword = urldecode(rawurldecode($matches[2])); } else { if (strpos($mother['host'], 'images.google.') !== false && preg_match('/%3Fsearch%3D([^&]+)/i', $mother['url'], $matches)) { $keyword = urldecode(rawurldecode($matches[1])); } else { if (strpos($mother['host'], 'yahoo.') !== false && preg_match('/\\Wp=([^&]+)/i', $mother['url'], $matches)) { $keyword = urldecode(rawurldecode($matches[1])); } else { if (preg_match('@/search/(?:\\w+/)*([^/?]+)@i', $mother['url'], $matches)) { $keyword = urldecode(rawurldecode($matches[1])); } } } } if (!UTF8::validate($keyword)) { $keyword = UTF8::correct(UTF8::bring($keyword)); } $keyword = UTF16UrlDecode($keyword); $url = rawurldecode(substr($mother['url'], 7)); if (!UTF8::validate($url)) { $url = UTF8::correct(UTF8::bring($url)); } //return '<img src="http://'.$mother['host'].'/favicon.ico" width="16" height="16" alt="Favicon" onerror="this.parentNode.removeChild(this)" style="vertical-align: middle"/> ' . (($keyword) ? '<span style="font-weight: bold; color: #594">['.htmlspecialchars($keyword).']</span> ' . UTF8::lessenAsEm($url, 65 - UTF8::lengthAsEm($keyword)) : UTF8::lessenAsEm($url, 65)); return $keyword ? '<span style="font-weight: bold; color: #594">[' . htmlspecialchars($keyword) . ']</span> ' . htmlspecialchars(UTF8::lessenAsEm($url, 70 - UTF8::lengthAsEm($keyword))) : htmlspecialchars(UTF8::lessenAsEm($url, 70)); }
public static function validateArray(&$array, &$rules) { // Workaround for non Fancy-URL user. $cropArray = array(); foreach ($array as $name => $value) { $doesHaveRequest = strpos($name, '?'); if ($doesHaveRequest !== false) { $name = substr($name, $doesHaveRequest + 1); } $cropArray[$name] = $value; } $array = $cropArray; foreach ($rules as $key => $rule) { if (!isset($rule[0])) { trigger_error("Validator: The type of '{$key}' is not defined", E_USER_WARNING); continue; } if (isset($array[$key]) && ($rule[0] == 'file' || strlen($array[$key]) > 0)) { $value =& $array[$key]; if (isset($rule['min'])) { $rule[1] = $rule['min']; } if (isset($rule['max'])) { $rule[2] = $rule['max']; } if (isset($rule['bypass'])) { $rule[3] = $rule['bypass']; } switch ($rule[0]) { case 'any': if (isset($rule[1]) && strlen($value) < $rule[1]) { return false; } if (isset($rule[2]) && strlen($value) > $rule[2]) { return false; } break; case 'bit': $array[$key] = self::getBit($value); break; case 'bool': $array[$key] = self::getBool($value); break; case 'number': if (!self::number($value, isset($rule[1]) ? $rule[1] : null, isset($rule[2]) ? $rule[2] : null, isset($rule[3]) ? $rule[3] : false)) { return false; } break; case 'int': if (!self::isInteger($value, isset($rule[1]) ? $rule[1] : -2147483648, isset($rule[2]) ? $rule[2] : 2147483647, isset($rule[3]) ? $rule[3] : false)) { return false; } break; case 'id': if (!self::id($value, isset($rule[1]) ? $rule[1] : 1, isset($rule[2]) ? $rule[2] : 2147483647)) { return false; } break; case 'url': case 'string': if (!UTF8::validate($value)) { $value = UTF8::bring($value); if (!UTF8::validate($value)) { return false; } } $value = $array[$key] = UTF8::correct($value); if (isset($rule[1]) && UTF8::length($value) < $rule[1]) { return false; } if (isset($rule[2]) && UTF8::length($value) > $rule[2]) { return false; } break; case 'list': if (!self::isList($value)) { return false; } break; case 'timestamp': if (!self::timestamp($value)) { return false; } break; case 'period': if (!self::period($value)) { return false; } break; case 'ip': if (!self::ip($value)) { return false; } break; case 'phone': if (!self::phone($value)) { return false; } break; case 'domain': if (!self::domain($value)) { return false; } break; case 'email': if (!self::email($value)) { return false; } break; case 'language': if (!self::language($value)) { return false; } break; case 'filename': if (!self::filename($value)) { return false; } break; case 'directory': if (!self::directory($value)) { return false; } break; case 'path': if (!self::path($value)) { return false; } break; case 'file': if (!isset($value['name']) || preg_match('@[/\\\\]@', $value['name'])) { return false; } break; default: if (is_array($rule[0])) { if (!in_array($value, $rule[0])) { return false; } } else { trigger_error("Validator: The type of '{$key}' is unknown", E_USER_WARNING); } break; } if (isset($rule['check'])) { $rule[5] = $rule['check']; } if (isset($rule[5])) { if (function_exists($rule[5])) { if (!call_user_func($rule[5], $value)) { return false; } } else { trigger_error("Validator: The check function of '{$key}' is not defined", E_USER_WARNING); } } } else { if (array_key_exists(3, $rule)) { $array[$key] = $rule[3]; } else { if (array_key_exists('default', $rule)) { $array[$key] = $rule['default']; } else { if ((!isset($rule[4]) || $rule[4]) && (!isset($rule['mandatory']) || $rule['mandatory'])) { return false; } } } } } return true; }
function getPostPage($url, $content) { $this->responseText = ''; $this->HTTPRequest('POST', $url); if (!$this->send($content)) { return false; } return trim(UTF8::correct(UTF8::convert($this->responseText))); }
function makeResult($str) { $this->buffer .= UTF8::correct($str).CRLF; }
function saveFeedItem($feedId,$feedVisibility,$item){ global $database, $db, $event; $db->query("SELECT id FROM {$database['prefix']}DeleteHistory WHERE feed='$feedId' and permalink='{$item['permalink']}'"); if ($db->numRows() > 0) return false; if ($item['written']>gmmktime()+86400) return false; $item['title']=$db->escape($db->lessen(UTF8::correct($item['title']))); list($useRssOut) = Settings::gets('useRssOut'); list($feedCreated,$localFilter,$localFilterType) = Feed::gets($feedId, 'created,filter,filterType'); $tagString=$db->escape($db->lessen(UTF8::correct(implode(', ',$item['tags'])))); list($globalFilter,$blackFilter,$globalFilterType,$blackFilterType) = Settings::gets('filter,blackfilter,filterType,blackfilterType'); $filter = empty($globalFilter)?$localFilter:$globalFilter; $filterType = empty($globalFilter)?$localFilterType:$globalFilterType; if (!Validator::is_empty($filter)) { $filtered = true; $allowTags = explode(',', $filter); if($filterType == 'tag' || $filterType == 'tag+title') { foreach ($allowTags as $ftag) { if (Validator::enum($ftag, $tagString)) { $filtered = false; break; } } } if($filtered && ($filterType == 'title' || $filterType == 'tag+title')) { foreach ($allowTags as $ftag) { if(strpos($item['title'],$ftag)!==false) { $filtered = false; break; } } } if ($filtered) return false; } if (!Validator::is_empty($blackFilter)) { $filtered = false; $denyTags = explode(',', $blackFilter); if($blackFilterType == 'tag' || $blackFilterType == 'tag+title') { foreach ($denyTags as $ftag) { if (Validator::enum($ftag, $tagString)) { $filtered = true; break; } } } if($filtered && ($filterType == 'title' || $filterType == 'tag+title')) { foreach ($denyTags as $ftag) { if(strpos($item['title'],$ftag)!==false) { $filtered = true; break; } } } if ($filtered) return false; } if (preg_match('/\((.[^\)]+)\)$/Ui', trim($item['author']), $_matches)) $item['author'] = $_matches[1]; $item['author']=$db->escape($db->lessen(UTF8::correct($item['author']))); $item['permalink']=$db->escape($db->lessen(UTF8::correct($item['permalink']))); $item['description']=$db->escape($db->lessen(UTF8::correct(trim($item['description'])),65535)); $enclosures = array(); foreach($item['enclosures'] as $en) { array_push($enclosures, $en['url']); } $enclosureString=$db->escape($db->lessen(UTF8::correct(implode('|',$enclosures)))); $deadLine=0; $feedLife = Settings::get('archivePeriod'); if ($feedLife > 0) $deadLine=gmmktime()-($feedLife*86400); requireComponent('Bloglounge.Data.FeedItems'); $oldTags = null; $id = FeedItem::getIdByURL($item['permalink']); if($id === false && isset($item['guid'])) { $item['guid']=$db->escape($db->lessen(UTF8::correct($item['guid']))); $id = FeedItem::getIdByURL($item['guid']); } $item['author'] = Feed::getAuthor($item, $feedId, $id); $item['title'] = Feed::getTitle($item, $feedId, $id); $affected = 0; $isRebuildData = false; $summarySave = Settings::get('summarySave'); $description = $item['description']; if(Validator::getBool($summarySave)) { // summarySave $description = func::stripHTML($item['description'].'>'); if (substr($description, -1) == '>') $description = substr($description, 0, strlen($description) - 1); $description = $db->lessen(func::htmltrim($description), 1000, ''); } if (preg_match("/^[0-9]+$/",$id)) { $baseItem = FeedItem::getFeedItem($id); // $baseItem['title']=$db->escape(UTF8::correct($baseItem['title'])); // $baseItem['description']=$db->escape(UTF8::correct(trim($baseItem['description']))); if(($baseItem['title']!=$item['title'])) { $isRebuildData = true; $tags = FeedItem::get($id, 'tags'); requireComponent('LZ.PHP.Media'); Media::delete($id); $oldTags = func::array_trim(explode(',', $tags)); $db->execute("UPDATE {$database['prefix']}FeedItems SET author = '{$item['author']}', title = '{$item['title']}', description = '{$description}', tags = '$tagString', enclosure = '$enclosureString', written = {$item['written']} WHERE id = $id"); } } else { if ($item['written']==0) $item['written']=gmmktime(); if ($item['written']>$deadLine) { $db->execute("INSERT INTO {$database['prefix']}FeedItems (feed, author, permalink, title, description, tags, enclosure, written, feedVisibility) VALUES ($feedId, '{$item['author']}', '{$item['permalink']}', '{$item['title']}', '{$description}', '$tagString', '$enclosureString', {$item['written']},'{$feedVisibility}')"); $id =$db->insertId(); $db->execute('UPDATE '.$database['prefix'].'Feeds SET feedCount=feedCount+1 WHERE id="'.$feedId.'"'); if (isset($this)) $this->updated++; } $isRebuildData = true; } if(Validator::getBool(Settings::get('saveImages'))) { if($description = FeedItem::saveImages($feedId, $id, $item)) { $db->execute("UPDATE {$database['prefix']}FeedItems SET description = '{$description}' WHERE id = $id"); } } $item = $event->on('Add.updateFeedItem', array($feedId, $id, $item)); if(count($item)==3) $item = $item[2]; $result = false; if($isRebuildData) { requireComponent('Bloglounge.Data.Groups'); GroupCategory::buildGroupCategory($id, $feedId, $item['tags']); Tag::buildTagIndex($id, $item['tags'], $oldTags); Category::buildCategoryRelations($id, $item['tags'], $oldTags); $isSaveThumbnail = FeedItem::cacheThumbnail($id, $item); // 썸네일 저장 이벤트 $event->on('Add.thumbnailSave',array($item, $feedId, $id, $isSaveThumbnail)); $result = true; } return $result; }
function getRefererKeywordStatistics() { $more = false; $refereres = getRefererLogsDB(); $keywordlist = array(); $record = array(); for ($i = 0; $i < sizeof($refereres); $i++) { $record = $refereres[$i]; if ($i == 0) { $referredend = $record['referred']; } $keyword = ""; if (preg_match('/\\W(q|query|k|keyword|search|stext|nlia|aqa|wd)(?:=|%3D)([^&]+)/i', $record['url'], $matches)) { $keyword = urldecode(rawurldecode($matches[2])); } else { if (strpos($record['url'], 'yahoo.') !== false && preg_match('/\\Wp=([^&]+)/i', $record['url'], $matches)) { $keyword = urldecode(rawurldecode($matches[1])); } else { if (preg_match('@/search/(?:\\w+/)*([^/?]+)@i', $record['url'], $matches)) { $keyword = urldecode(rawurldecode($matches[1])); } } } if (!UTF8::validate($keyword)) { $keyword = UTF8::correct(UTF8::bring($keyword)); } if (array_key_exists($keyword, $keywordlist)) { $keywordlist[$keyword]++; } elseif ($keyword) { $keywordlist[$keyword] = 1; } } $referredstart = array_key_exists('referred', $record) ? $record['referred'] : ''; $keywordlist = RefererKeywordArraySort($keywordlist, 'desc'); $keywordkeys = array_keys($keywordlist); $beforekeywordvalue = ''; $rank = 0; $keywordArray = array(); for ($i = 0; $i < sizeof($keywordlist); $i++) { $keywordkey = $keywordkeys[$i]; $keywordvalue = $keywordlist[$keywordkey]; $keywordkey = str_replace("\"", """, $keywordkeys[$i]); if ($keywordvalue != $beforekeywordvalue) { $rank++; $beforekeywordvalue = $keywordvalue; } array_push($keywordArray, array('keyword' => $keywordkey, 'count' => $keywordvalue, 'total' => count($keywordlist), 'rank' => $rank, 'dateStart' => Timestamp::formatDate($referredstart), 'dateEnd' => Timestamp::formatDate($referredend))); } return $keywordArray; }
function saveFeedItem($feedId, $item) { global $database; $item = fireEvent('SaveFeedItem', $item); $item['permalink'] = POD::escapeString(UTF8::lessenAsEncoding(UTF8::correct($item['permalink']))); $item['author'] = POD::escapeString(UTF8::lessenAsEncoding(UTF8::correct($item['author']))); $item['title'] = POD::escapeString(UTF8::lessenAsEncoding(UTF8::correct($item['title']))); $item['description'] = POD::escapeString(UTF8::lessenAsEncoding(UTF8::correct($item['description']), 65535)); $tagString = POD::escapeString(UTF8::lessenAsEncoding(UTF8::correct(implode(', ', $item['tags'])))); $enclosureString = POD::escapeString(UTF8::lessenAsEncoding(UTF8::correct(implode('|', $item['enclosures'])))); if ($item['written'] > gmmktime() + 86400) { return false; } $deadLine = 0; $feedlife = POD::queryCell("SELECT feedlife FROM {$database['prefix']}FeedSettings"); if ($feedlife > 0) { $deadLine = gmmktime() - $feedlife * 86400; } if ($id = POD::queryCell("SELECT id FROM {$database['prefix']}FeedItems WHERE permalink='{$item['permalink']}'") && $item['written'] != 0) { $result = POD::query("UPDATE {$database['prefix']}FeedItems SET author = '{$item['author']}', title = '{$item['title']}', description = '{$item['description']}', tags = '{$tagString}', enclosure = '{$enclosureString}', written = {$item['written']} WHERE id = {$id}"); /* TODO : 읽은글이 읽지않은 글로 표시되는 문제 원인이 찾아질때 까지 막아둠 if (POD::num_rows($result) > 0) POD::query("DELETE FROM {$database['prefix']}FeedReads WHERE item = $id"); */ } else { if ($id != null) { return false; } else { if ($item['written'] == 0) { $item['written'] = gmmktime(); } if ($item['written'] > $deadLine) { $id = POD::queryCell("SELECT max(id) FROM {$database['prefix']}FeedItems"); if (!$id) { $id = 0; } $id++; POD::query("INSERT INTO {$database['prefix']}FeedItems VALUES({$id}, {$feedId}, '{$item['author']}', '{$item['permalink']}', '{$item['title']}', '{$item['description']}', '{$tagString}', '{$enclosureString}', {$item['written']})"); } } } return true; }
function openFile($filename, $correct = false) { if (!$fp = fopen($filename, 'r')) return false; $p = xml_parser_create(); xml_set_object($p, $this); xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0); xml_set_element_handler($p, 'o', 'c'); xml_set_character_data_handler($p, 'd'); xml_set_default_handler($p, 'x'); $this->struct = array(); $this->_cursor = &$this->struct; $this->_path = array(''); $this->_cdata = false; if ($correct) { $remains = ''; while (!feof($fp)) { $chunk = $remains . fread($fp, 10240); $remains = ''; if (strlen($chunk) >= 10240) { for ($c = 1; $c <= 4; $c++) { switch ($chunk{strlen($chunk) - $c} & "\xC0") { case "\x00": case "\x40": if ($c > 1) { $remains = substr($chunk, strlen($chunk) - $c + 1); $chunk = substr($chunk, 0, strlen($chunk) - $c + 1); } $c = 5; break; case "\xC0": $remains = substr($chunk, strlen($chunk) - $c); $chunk = substr($chunk, 0, strlen($chunk) - $c); $c = 5; break; } } } $xml = str_replace('&','&',UTF8::correct($chunk, '?')); if (!xml_parse($p, $xml, false)) { fclose($fp); return $this->_error($p); } } } else { while (!feof($fp)) { $xml = str_replace('&','&',fread($fp, 10240)); if (!xml_parse($p, $xml, false)) { fclose($fp); return $this->_error($p); } } } fclose($fp); if (!xml_parse($p, '', true)) return $this->_error($p); unset($this->_cursor); unset($this->_cdata); if (xml_get_error_code($p) != XML_ERROR_NONE) return $this->_error($p); xml_parser_free($p); return true; }