本文整理汇总了PHP中HTTP::getLinksIn方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP::getLinksIn方法的具体用法?PHP HTTP::getLinksIn怎么用?PHP HTTP::getLinksIn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTP
的用法示例。
在下文中一共展示了HTTP::getLinksIn方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetLinksIn
/**
* Tests {@link HTTP::getLinksIn()}
*/
public function testGetLinksIn()
{
$content = '
<h2><a href="/">My Cool Site</a></h2>
<p>
A boy went <a href="home/">home</a> to see his <span><a href="mother/">mother</a></span>. This
involved a short <a href="$Journey">journey</a>, as well as some <a href="space travel">space travel</a>
and <a href=unquoted>unquoted</a> events, as well as a <a href=\'single quote\'>single quote</a> from
his <a href="/father">father</a>.
</p>
<p>
There were also some elements with extra <a class=attribute href=\'attributes\'>attributes</a> which
played a part in his <a href=journey"extra id="JourneyLink">journey</a>. HE ALSO DISCOVERED THE
<A HREF="CAPS LOCK">KEY</a>. Later he got his <a href="quotes \'mixed\' up">mixed up</a>.
</p>
';
$expected = array('/', 'home/', 'mother/', '$Journey', 'space travel', 'unquoted', 'single quote', '/father', 'attributes', 'journey', 'CAPS LOCK', 'quotes \'mixed\' up');
$result = HTTP::getLinksIn($content);
// Results don't neccesarily come out in the order they are in the $content param.
sort($result);
sort($expected);
$this->assertTrue(is_array($result));
$this->assertEquals($expected, $result, 'Test that all links within the content are found.');
}
示例2: testShowInMenusRespected
public function testShowInMenusRespected()
{
$sitemap = new SitemapPage();
$homePage = $this->objFromFixture('SiteTree', 'home');
$this->assertContains($homePage->Link(), HTTP::getLinksIn($sitemap->getSitemap()), 'The page is displayed by default.');
$homePage->ShowInMenus = false;
$homePage->write();
$this->assertNotContains($homePage->Link(), HTTP::getLinksIn($sitemap->getSitemap()), 'The page is displayed by default.');
}
示例3: testGetLinksIn
/**
* Tests {@link HTTP::getLinksIn()}
*/
public function testGetLinksIn()
{
$content = '
<h2>My page</h2>
<p>A boy went <a href="home/">home</a> to see his <span><a href="mother/">mother</a></span>.</p>
';
$links = HTTP::getLinksIn($content);
$this->assertTrue(is_array($links));
$this->assertTrue(count($links) == 2);
}
示例4: testPublishingPageWithModifiedLinksRewritesLinks
function testPublishingPageWithModifiedLinksRewritesLinks() {
// publish page 1 & 3
$page1 = $this->objFromFixture('Page', 'page1');
$page3 = $this->objFromFixture('Page', 'page3');
$this->assertTrue($page1->doPublish());
$this->assertTrue($page3->doPublish());
// assert hyperlink to page 1's current url exists
$links = HTTP::getLinksIn($page3->obj('Content')->forTemplate());
$this->assertContains(Director::baseURL().'page1/', $links, 'Assert hyperlink to page 1\'s current published url exists on page 3');
// change page 1 url on draft
$page1->URLSegment = 'new-url-segment';
// save page 1
$page1->write();
// assert page 3 on draft contains new page 1 url
$page3 = $this->objFromFixture('Page', 'page3');
$links = HTTP::getLinksIn($page3->obj('Content')->forTemplate());
$this->assertContains(Director::baseURL().'new-url-segment/', $links, 'Assert hyperlink to page 1\'s current draft url exists on page 3');
// publish page 3
$this->assertTrue($page3->doPublish());
// assert page 3 on published site contains old page 1 url
$page3live = Versioned::get_one_by_stage('Page', 'Live', '"SiteTree"."ID" = ' . $page3->ID);
Versioned::reading_stage('Live');
$links = HTTP::getLinksIn($page3live->obj('Content')->forTemplate());
$this->assertContains(Director::baseURL().'page1/', $links, 'Assert hyperlink to page 1\'s current published url exists on page 3');
// publish page 1
$this->assertTrue($page1->doPublish());
// assert page 3 on published site contains new page 1 url
$page3live = Versioned::get_one_by_stage('Page', 'Live', '"SiteTree"."ID" = ' . $page3->ID);
$links = HTTP::getLinksIn($page3live->obj('Content')->forTemplate());
$this->assertContains(Director::baseURL().'new-url-segment/', $links, 'Assert hyperlink to page 1\'s current published url exists on page 3');
}
示例5: augmentSyncLinkTracking
public function augmentSyncLinkTracking()
{
// Set LinkTracking appropriately
$links = HTTP::getLinksIn($this->owner->Content);
$linkedPages = array();
if ($links) {
foreach ($links as $link) {
if (substr($link, 0, strlen('http://')) == 'http://') {
$withoutHttp = substr($link, strlen('http://'));
if (strpos($withoutHttp, '/') && strpos($withoutHttp, '/') < strlen($withoutHttp)) {
$domain = substr($withoutHttp, 0, strpos($withoutHttp, '/'));
$rest = substr($withoutHttp, strpos($withoutHttp, '/') + 1);
$subsiteID = Subsite::getSubsiteIDForDomain($domain);
if ($subsiteID == 0) {
continue;
}
// We have no idea what the domain for the main site is, so cant track links to it
$origDisableSubsiteFilter = Subsite::$disable_subsite_filter;
Subsite::disable_subsite_filter(true);
$candidatePage = DataObject::get_one("SiteTree", "\"URLSegment\" = '" . Convert::raw2sql(urldecode($rest)) . "' AND \"SubsiteID\" = " . $subsiteID, false);
Subsite::disable_subsite_filter($origDisableSubsiteFilter);
if ($candidatePage) {
$linkedPages[] = $candidatePage->ID;
} else {
$this->owner->HasBrokenLink = true;
}
}
}
}
}
$this->owner->CrossSubsiteLinkTracking()->setByIDList($linkedPages);
}
示例6: saveInto
function saveInto($record) {
if($record->escapeTypeForField($this->name) != 'xml') {
user_error("HTMLEditorField should save into an HTMLText or HTMLVarchar field.
If you don't, your template won't display properly.
This changed in version 2.2.2, so please update
your database field '$this->name'",
E_USER_WARNING
);
}
$content = $this->value;
$content = preg_replace('/mce_real_src="[^"]+"/i', "", $content);
$content = eregi_replace('(<img[^>]* )width=([0-9]+)( [^>]*>|>)','\\1width="\\2"\\3', $content);
$content = eregi_replace('(<img[^>]* )height=([0-9]+)( [^>]*>|>)','\\1height="\\2"\\3', $content);
$content = eregi_replace('src="([^\?]*)\?r=[0-9]+"','src="\\1"', $content);
$content = eregi_replace('mce_src="([^\?]*)\?r=[0-9]+"','mce_src="\\1"', $content);
$content = preg_replace_callback('/(<img[^>]* )(width="|height="|src=")([^"]+)("[^>]* )(width="|height="|src=")([^"]+)("[^>]* )(width="|height="|src=")([^"]+)("[^>]*>)/i', "HtmlEditorField_dataValue_processImage", $content);
// If we don't have a containing block element, add a p tag.
if(!ereg("^[ \t\r\n]*<", $content)) $content = "<p>$content</p>";
$links = HTTP::getLinksIn($content);
$linkedPages = array();
if($links) foreach($links as $link) {
$link = Director::makeRelative($link);
if(preg_match('/^([A-Za-z0-9_-]+)\/?(#.*)?$/', $link, $parts)) {
$candidatePage = DataObject::get_one("SiteTree", "URLSegment = '" . urldecode( $parts[1] ). "'", false);
if($candidatePage) {
$linkedPages[] = $candidatePage->ID;
// This caused bugs in the publication script
// $candidatePage->destroy();
} else {
$record->HasBrokenLink = 1;
}
} else if($link{0} == '/') {
$record->HasBrokenLink = 1;
} else if($candidateFile = DataObject::get_one("File", "Filename = '" . Convert::raw2sql(urldecode($link)) . "'", false)) {
$linkedFiles[] = $candidateFile->ID;
// $candidateFile->destroy();
}
}
$images = HTTP::getImagesIn($content);
if($images) {
foreach($images as $image) {
$image = Director::makeRelative($image);
if(substr($image,0,7) == 'assets/') {
$candidateImage = DataObject::get_one("File", "Filename = '$image'");
if($candidateImage) $linkedFiles[] = $candidateImage->ID;
else $record->HasBrokenFile = 1;
}
}
}
$fieldName = $this->name;
if($record->ID && $record->hasMethod('LinkTracking') && $linkTracking = $record->LinkTracking()) {
$linkTracking->removeByFilter("\"FieldName\" = '$fieldName' AND \"SiteTreeID\" = $record->ID");
if(isset($linkedPages)) foreach($linkedPages as $item) {
$linkTracking->add($item, array("FieldName" => $fieldName));
}
// $linkTracking->destroy();
}
if($record->ID && $record->hasMethod('ImageTracking') && $imageTracking = $record->ImageTracking()) {
$imageTracking->removeByFilter("FieldName = '$fieldName'");
if(isset($linkedFiles)) foreach($linkedFiles as $item) {
$imageTracking->add($item, array("FieldName" => $fieldName));
}
// $imageTracking->destroy();
}
// Sometimes clients will double-escape %20. Fix this up with this dirty hack
$content = str_replace('%2520', '%20', $content);
$record->$fieldName = $content;
}