public static each ( $object, $callback, $param1 = null, $param2 = null, $param3 = null ) : unknown_type | ||
$object | ||
$callback | ||
리턴 | unknown_type |
public function loadWP() { if (file_exists($this->wpPath)) { phpQuery::newDocumentFileXML($this->wpPath); $itemArr = pq("channel item"); phpQuery::each($itemArr, "WordPress::parseWpItem"); } else { $this->_error = "wordpress.xml文件不存在"; } }
public function loadWP() { $f*g = false; if (file_exists($this->wpPath)) { phpQuery::newDocumentFileXML($this->wpPath); $itemArr = pq("channel item"); if ($itemArr->size() > 0) { phpQuery::each($itemArr, "WordPress::parseWpItem"); $this->_error = "finish!"; $f*g = true; } else { $this->_error = "not detected data!"; } } else { $this->_error = "wordpress.xml file is not exists!"; } return $f*g; }
} } elseif (isset($Rule['Selector'])) { phpQuery::each(pq($Rule['Selector']), function ($Index, $Element) use(&$Data, $Key, $Rule, $Call) { F::Log('Selector fired ' . $Rule['Selector'], LOG_NOTICE); if (isset($Rule['Text'])) { $Value = preg_replace('/\\s{2,}|\\s{2,}$/Ssm', PHP_EOL, pq($Element)->text()); } elseif (isset($Rule['Attr'])) { $Value = preg_replace('/\\s{2,}|\\s{2,}$/Ssm', PHP_EOL, pq($Element)->attr($Rule['Attr'])); } else { $Value = preg_replace('/\\s{2,}|\\s{2,}$/Ssm', PHP_EOL, pq($Element)->html()); } if (empty($Value)) { F::Log($Key . ' not defined', LOG_INFO); } else { F::Log($Key . '.' . $Index . ' is ' . $Value, LOG_INFO); if (isset($Rule['Regex'])) { if (preg_match($Rule['Regex'], $Value, $Pockets)) { if (isset($Pockets[1])) { $Value = $Pockets[1]; } } else { $Value = null; } } $Value = trim($Value); if (!empty($Value)) { $Data = F::Dot($Data, $Key . '.' . $Index, $Value); } } }); } elseif (isset($Rule['Regex'])) { if (preg_match($Rule['Regex'], $Call['Markup'], $Pockets)) {
setFn('Get Links', function ($Call) { phpQuery::newDocumentHTML($Call['Body']); $URLs = []; phpQuery::each(pq('a'), function ($Index, $Element) use(&$Call, &$URLs) { $URL = parse_url($Element->getAttribute('href')); if (!isset($URL['scheme']) || $URL['scheme'] == 'http') { if (isset($URL['host']) && 'http://' . $URL['host'] != $Call['Host']) { $Decision = false; } else { $Decision = true; } $URL = isset($URL['path']) ? $URL['path'] : ''; if (in_array($URL, $Call['Processed'])) { $Decision = false; } if (isset($Call['White']) && !preg_match($Call['White'], $URL)) { $Decision = false; } if (isset($Call['Black']) && preg_match($Call['Black'], $URL)) { $Decision = false; } if (substr($URL, 0, 1) != '/') { $URL = '/' . $URL; } if ($Decision) { $URLs[] = $URL; } } }); phpQuery::unloadDocuments(); return $URLs; });
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 7.x */ include_once 'phpQuery/phpQuery.php'; setFn('Do', function ($Call) { return F::Run(null, $Call['HTTP']['Method'], $Call); }); setFn('GET', function ($Call) { $Call['Layouts'][] = ['Scope' => 'Parser', 'ID' => 'Spider']; return $Call; }); setFn('POST', function ($Call) { foreach ($Call['Spider']['Tasks'] as $Name => $Task) { $Result = F::Live($Task['Backend'], ['Where' => ['ID' => $Task['URL']]]); $Data = []; $Result = array_pop($Result); phpQuery::newDocumentHTML($Result); phpQuery::each(pq($Task['Selector']), function ($Index, $Element) use(&$Data) { $Data[$Index] = pq($Element)->attr('href'); }); foreach ($Data as $Row) { F::Run('Code.Run.Delayed', 'Run', ['Run' => ['Service' => 'Parser.URL', 'Method' => 'Parse', 'Call' => ['URL' => $Task['Host'] . $Row]]]); } } return $Call; });
setFn('Spider', function ($Call) { phpQuery::newDocumentHTML($Call['Body']); $Call['NL'] = 0; phpQuery::each(pq('a'), function ($Index, $Element) use(&$Call) { $URL = parse_url($Element->getAttribute('href')); if (isset($URL['host']) && $URL['host'] != $Call['Host']) { $Decision = false; } else { $Decision = true; } $URL = (isset($URL['path']) ? $URL['path'] : '') . (isset($URL['query']) ? '?' . $URL['query'] : ''); if (in_array($URL, $Call['Processed']) or in_array($URL, $Call['URLs'])) { $Decision = false; } elseif (isset($Call['Spider']['White']) && !preg_match('@' . $Call['Spider']['White'] . '@', $URL)) { $Decision = false; } elseif (isset($Call['Spider']['Black']) && preg_match('@' . $Call['Spider']['Black'] . '@', $URL)) { $Decision = false; } elseif (file_exists(F::Run(null, 'Select Filename', $Call, ['URL' => $URL]))) { $Decision = false; } if (substr($URL, 0, 1) != '/') { $URL = '/' . $URL; } if ($Decision) { $Call['URLs'][] = 'http://' . $Call['Host'] . $URL; $Call['NL']++; } }); phpQuery::unloadDocuments(); F::Log('New links founded ' . $Call['NL'], LOG_WARNING); return $Call;