Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #26 from helpfulrobot/convert-to-psr-2
Browse files Browse the repository at this point in the history
Converted to PSR-2
  • Loading branch information
Sam Minnée committed Dec 20, 2015
2 parents 3344f73 + aaf80c5 commit 511d827
Show file tree
Hide file tree
Showing 13 changed files with 1,779 additions and 1,617 deletions.
657 changes: 339 additions & 318 deletions code/StaticSiteContentExtractor.php

Large diffs are not rendered by default.

146 changes: 79 additions & 67 deletions code/StaticSiteContentItem.php
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;
}
}
Loading

0 comments on commit 511d827

Please sign in to comment.