This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from helpfulrobot/convert-to-psr-2
Converted to PSR-2
- Loading branch information
Showing
13 changed files
with
1,779 additions
and
1,617 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,81 @@ | ||
<?php | ||
|
||
class StaticSiteContentItem extends ExternalContentItem { | ||
public function init() { | ||
$url = $this->externalId; | ||
|
||
$processedURL = $this->source->urlList()->processedURL($url); | ||
$parentURL = $this->source->urlList()->parentProcessedURL($processedURL); | ||
|
||
$subURL = substr($processedURL, strlen($parentURL)); | ||
if($subURL != "/") $subURL = preg_replace('#(^/)|(/$)#','',$subURL); | ||
|
||
$this->Name = $subURL; | ||
$this->Title = $this->Name; | ||
$this->AbsoluteURL = preg_replace('#/$#','', $this->source->BaseUrl) . $this->externalId; | ||
$this->ProcessedURL = $processedURL; | ||
} | ||
|
||
public function stageChildren($showAll = false) { | ||
if(!$this->source->urlList()->hasCrawled()) return new ArrayList; | ||
|
||
$childrenURLs = $this->source->urlList()->getChildren($this->externalId); | ||
|
||
$children = new ArrayList; | ||
foreach($childrenURLs as $child) { | ||
$children->push($this->source->getObject($child)); | ||
} | ||
|
||
return $children; | ||
} | ||
|
||
public function numChildren() { | ||
if(!$this->source->urlList()->hasCrawled()) return 0; | ||
|
||
return sizeof($this->source->urlList()->getChildren($this->externalId)); | ||
} | ||
|
||
public function getType() { | ||
return "sitetree"; | ||
} | ||
|
||
public function getCMSFields() { | ||
$fields = parent::getCMSFields(); | ||
|
||
// Add the preview fields here, including rules used | ||
$t = new StaticSitePageTransformer; | ||
|
||
$urlField = new ReadonlyField("PreviewSourceURL", "Imported from", | ||
"<a href=\"$this->AbsoluteURL\">" . Convert::raw2xml($this->AbsoluteURL) . "</a>"); | ||
$urlField->dontEscape = true; | ||
|
||
$fields->addFieldToTab("Root.Preview", $urlField); | ||
|
||
$content = $t->getContentFieldsAndSelectors($this); | ||
if(count($content) === 0) { | ||
return $fields; | ||
} | ||
foreach($content as $k => $v) { | ||
$readonlyField = new ReadonlyField("Preview$k", "$k<br>\n<em>" . $v['selector'] . "</em>", $v['content']); | ||
$readonlyField->addExtraClass('readonly-click-toggle'); | ||
$fields->addFieldToTab("Root.Preview", $readonlyField); | ||
} | ||
|
||
Requirements::javascript('staticsiteconnector/js/StaticSiteContentItem.js'); | ||
Requirements::css('staticsiteconnector/css/StaticSiteContentItem.css'); | ||
|
||
return $fields; | ||
} | ||
} | ||
class StaticSiteContentItem extends ExternalContentItem | ||
{ | ||
public function init() | ||
{ | ||
$url = $this->externalId; | ||
|
||
$processedURL = $this->source->urlList()->processedURL($url); | ||
$parentURL = $this->source->urlList()->parentProcessedURL($processedURL); | ||
|
||
$subURL = substr($processedURL, strlen($parentURL)); | ||
if ($subURL != "/") { | ||
$subURL = preg_replace('#(^/)|(/$)#', '', $subURL); | ||
} | ||
|
||
$this->Name = $subURL; | ||
$this->Title = $this->Name; | ||
$this->AbsoluteURL = preg_replace('#/$#', '', $this->source->BaseUrl) . $this->externalId; | ||
$this->ProcessedURL = $processedURL; | ||
} | ||
|
||
public function stageChildren($showAll = false) | ||
{ | ||
if (!$this->source->urlList()->hasCrawled()) { | ||
return new ArrayList; | ||
} | ||
|
||
$childrenURLs = $this->source->urlList()->getChildren($this->externalId); | ||
|
||
$children = new ArrayList; | ||
foreach ($childrenURLs as $child) { | ||
$children->push($this->source->getObject($child)); | ||
} | ||
|
||
return $children; | ||
} | ||
|
||
public function numChildren() | ||
{ | ||
if (!$this->source->urlList()->hasCrawled()) { | ||
return 0; | ||
} | ||
|
||
return sizeof($this->source->urlList()->getChildren($this->externalId)); | ||
} | ||
|
||
public function getType() | ||
{ | ||
return "sitetree"; | ||
} | ||
|
||
public function getCMSFields() | ||
{ | ||
$fields = parent::getCMSFields(); | ||
|
||
// Add the preview fields here, including rules used | ||
$t = new StaticSitePageTransformer; | ||
|
||
$urlField = new ReadonlyField("PreviewSourceURL", "Imported from", | ||
"<a href=\"$this->AbsoluteURL\">" . Convert::raw2xml($this->AbsoluteURL) . "</a>"); | ||
$urlField->dontEscape = true; | ||
|
||
$fields->addFieldToTab("Root.Preview", $urlField); | ||
|
||
$content = $t->getContentFieldsAndSelectors($this); | ||
if (count($content) === 0) { | ||
return $fields; | ||
} | ||
foreach ($content as $k => $v) { | ||
$readonlyField = new ReadonlyField("Preview$k", "$k<br>\n<em>" . $v['selector'] . "</em>", $v['content']); | ||
$readonlyField->addExtraClass('readonly-click-toggle'); | ||
$fields->addFieldToTab("Root.Preview", $readonlyField); | ||
} | ||
|
||
Requirements::javascript('staticsiteconnector/js/StaticSiteContentItem.js'); | ||
Requirements::css('staticsiteconnector/css/StaticSiteContentItem.css'); | ||
|
||
return $fields; | ||
} | ||
} |
Oops, something went wrong.