本文整理汇总了PHP中zibo\library\String::looksLikeUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP String::looksLikeUrl方法的具体用法?PHP String::looksLikeUrl怎么用?PHP String::looksLikeUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zibo\library\String
的用法示例。
在下文中一共展示了String::looksLikeUrl方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: smarty_function_scripts_get_url
function smarty_function_scripts_get_url($url, $baseUrl)
{
if (String::looksLikeUrl($url)) {
return $url;
}
return $baseUrl . $url;
}
示例2: processRequest
/**
* Process the request, get the field value
* @return null
*/
public function processRequest()
{
parent::processRequest();
if ($this->value && !String::looksLikeUrl($this->value)) {
$this->value = 'http://' . $this->value;
}
}
示例3: parseTag
/**
* Parses the tag
* @param string $content Content of the tag
* @param array $parameters Parameters of the tag
* @return string HTML replacement for the tag
*/
public function parseTag($content, array $parameters)
{
if (!$content || !String::looksLikeUrl($content)) {
return false;
}
$width = null;
$height = null;
$alt = null;
if (array_key_exists(0, $parameters) && strpos($parameters[0], 'x')) {
// [img=<width>x<height>]url[/img]
list($width, $height) = explode($parameters[0]);
} else {
if (array_key_exists('width', $parameters)) {
// [img width=<width>]url[/img]
$width = $parameters['width'];
} elseif (array_key_exists('w', $parameters)) {
// [img w=<width>]url[/img]
$width = $parameters['w'];
}
if (array_key_exists('height', $parameters)) {
// [img height=<height>]url[/img]
$height = $parameters['height'];
} elseif (array_key_exists('h', $parameters)) {
// [img h=<height>]url[/img]
$height = $parameters['h'];
}
}
if (array_key_exists('alt', $parameters)) {
$alt = $parameters['alt'];
}
return $this->getImageHtml($content, $width, $height, $alt);
}
示例4: getHtml
/**
* Get the html for this menu item
* @return string
*/
public function getHtml()
{
if (String::looksLikeUrl($this->route)) {
$url = $this->route;
} else {
$url = $this->baseUrl . $this->route;
}
return '<li' . $this->getAttributesHtml() . '>' . '<a href="' . $url . '">' . $this->label . '</a>' . '</li>';
}
示例5: getAbsoluteUrl
/**
* Gets the absolute URL of a made reference
* @param string $url The made reference
* @param string $baseUrl The base URL of the node which is linking the URL
* @param string $basePath The base path of the node which is linking the URL
* @return string The absolute URL of the reference
*/
protected function getAbsoluteUrl($url, $baseUrl, $basePath)
{
if (!String::looksLikeUrl($url)) {
if (String::startsWith($url, '/')) {
$url = rtrim($baseUrl, '/') . $url;
} else {
$url = $basePath . $url;
}
}
return $url;
}
示例6: getRedirectUrl
/**
* Gets the redirect url of the provided response
* @param HttpRequest $request The performed request
* @param HttpResponse $response The received response
* @return zibo\library\Url The URL of the redirect location
* @throws zibo\library\network\http\exception\HttpException when the provided response has no Location header
*/
public function getRedirectUrl(HttpRequest $request, HttpResponse $response)
{
$location = $response->getHeader('Location');
if (!$location) {
throw new HttpException('Could not get the redirect URL from the response: no Location header set');
}
if (!String::looksLikeUrl($location)) {
if ($location[0] == '/') {
$base = $request->getUrl()->getBaseUrl();
} else {
$base = $request->getUrl()->getBasePath();
}
$location = rtrim($base, '/') . '/' . ltrim($location, '/');
}
return new Url($location);
}
示例7: getHtml
/**
* Get the html for this image tag
* @return string html of this image tag
*/
public function getHtml()
{
$source = $this->getSource();
if (!String::looksLikeUrl($source)) {
$source = $this->processSource($source);
$request = Zibo::getInstance()->getRequest();
$source = $request->getBaseUrl() . '/' . $source;
$this->setSource($source);
}
$html = '<img' . $this->getAttributeHtml(self::ATTRIBUTE_SRC, $source) . $this->getIdHtml() . $this->getClassHtml() . $this->getAttributesHtml() . ' />';
return $html;
}
示例8: crawl
/**
* Starts the crawling
* @param integer $delay Delay between each page in miliseconds
* @param zibo\library\filesystem\File $statusFile File where the status of the crawling process is written
* @param zibo\library\filesystem\File $cancelFile File which will cancel/stop the crawling process when exists
* @return null
*/
public function crawl($delay = 1000, File $statusFile = null, File $cancelFile = null)
{
$prey = $this->web->resetPrey();
$start = time();
$index = 0;
$isCancelled = false;
while ($prey) {
if ($cancelFile && $cancelFile->exists()) {
$cancelFile->delete();
$isCancelled = true;
break;
}
usleep($delay * 1000);
$index++;
$url = $prey->getUrl();
if ($this->shouldIgnore($url)) {
$prey->addType(WebNode::TYPE_IGNORED);
$prey = $this->web->getNextPrey();
continue;
}
if ($statusFile) {
$status = new SpiderStatus($url, $index, $this->web->countNodes(), $start);
$status->write($statusFile);
}
if (String::startsWith($url, 'mailto:')) {
$prey->addType(WebNode::TYPE_MAILTO);
$prey = $this->web->getNextPrey();
continue;
}
try {
$crawl = new Crawl($url);
$crawl->performCrawl();
$response = $crawl->getResponse();
$prey->setResponse($response);
if ($response->isRedirect()) {
$location = $response->getHeader('Location');
if (!String::looksLikeUrl($location)) {
if ($location[0] == '/') {
$base = $crawl->getBaseUrl();
} else {
$base = $crawl->getBasePath();
}
$location = rtrim($base, '/') . '/' . ltrim($location, '/');
}
if ($url == $location) {
throw new Exception('Redirect loop');
}
$locationNode = $this->web->getNode($location);
$locationNode->addReference($prey);
$prey->addLink($locationNode);
}
if (!String::startsWith($url, $this->baseUrl)) {
$prey->addType(WebNode::TYPE_EXTERNAL);
if (!$this->willBiteExternalNodes) {
$prey = $this->web->getNextPrey();
continue;
}
}
$this->bite($prey, $crawl->getBaseUrl(), $crawl->getBasePath());
} catch (Exception $exception) {
if ($crawl) {
$response = $crawl->getResponse();
if ($response) {
$prey->setResponse($response);
}
}
$prey->setError($exception->getMessage());
}
$prey = $this->web->getNextPrey();
}
if (!$isCancelled) {
if ($statusFile) {
$status = new SpiderStatus("reports", $index, $this->web->countNodes(), $start);
$status->write($statusFile);
}
foreach ($this->reports as $report) {
$report->setWeb($this->web);
}
}
if ($statusFile) {
$status = new SpiderStatus(null, $index, $this->web->countNodes(), $start, time());
$status->write($statusFile);
}
}
示例9: testLooksLikeUrl
/**
* @dataProvider providerLooksLikeUrl
*/
public function testLooksLikeUrl($expected, $value)
{
$result = String::looksLikeUrl($value);
$this->assertEquals($expected, $result);
}