-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
493 additions
and
108 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php | ||
defined('C5_EXECUTE') or die("Access Denied."); | ||
|
||
echo \Concrete\Package\Amp\Amp\Converter::content($controller); |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php defined('C5_EXECUTE') or die("Access Denied."); | ||
|
||
if (is_object($f)) { | ||
$tag = new \Concrete\Package\Amp\Html\Object\AmpImg($f); | ||
if ($altText) { | ||
$tag->alt(h($altText)); | ||
} else { | ||
$tag->alt(''); | ||
} | ||
if ($title) { | ||
$tag->title(h($title)); | ||
} | ||
if ($linkURL) { | ||
print '<a href="' . $linkURL . '">'; | ||
} | ||
|
||
print $tag; | ||
|
||
if ($linkURL) { | ||
print '</a>'; | ||
} | ||
} |
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,4 +1,4 @@ | ||
<? | ||
<?php | ||
defined('C5_EXECUTE') or die("Access Denied."); | ||
|
||
$c = Page::getCurrentPage(); | ||
|
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php defined('C5_EXECUTE') or die("Access Denied."); | ||
$tag = \HtmlObject\Element::create('amp-youtube'); | ||
$tag->setAttribute('data-videoid', h($videoID)); | ||
$tag->setAttribute('layout', 'responsive'); | ||
$width = ($vWidth) ? $vWidth : '480'; | ||
$height = ($vHeight) ? $vHeight : '270'; | ||
$tag->setAttribute('width', h($width)); | ||
$tag->setAttribute('height', h($height)); | ||
echo $tag; |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0"?> | ||
<concrete5-cif version="1.0"> | ||
<themes> | ||
<theme handle="amp" package="amp"/> | ||
</themes> | ||
<singlepages> | ||
<page name="AMP" | ||
path="/dashboard/system/seo/amp" | ||
filename="/dashboard/system/seo/amp.php" | ||
pagetype="" | ||
description="" | ||
package="amp"> | ||
<attributes> | ||
<attributekey handle="meta_keywords"> | ||
<value>Accelerated Mobile Pages, AMP, Analytics</value> | ||
</attributekey> | ||
</attributes> | ||
</page> | ||
</singlepages> | ||
</concrete5-cif> |
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
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
namespace Concrete\Package\Amp\Controller\SinglePage\Dashboard\System\Seo; | ||
|
||
use Core; | ||
use Package; | ||
use PageType; | ||
|
||
class Amp extends \Concrete\Core\Page\Controller\DashboardPageController | ||
{ | ||
public function view() | ||
{ | ||
/** @var \Concrete\Core\Package\Package $pkg */ | ||
$pkg = Package::getByHandle('amp'); | ||
$account = $pkg->getFileConfig()->get('analytics.googleanalytics.account'); | ||
$this->set('account', $account); | ||
|
||
$selectedTypes = $pkg->getFileConfig()->get('types'); | ||
$this->set('types', $selectedTypes); | ||
|
||
$ptIDs = array(); | ||
$pagetypes = PageType::getList(); | ||
/** @var PageType $pt */ | ||
foreach ($pagetypes as $pt) { | ||
$ptIDs[$pt->getPageTypeID()] = $pt->getPageTypeDisplayName(); | ||
} | ||
$this->set('pagetypes', $ptIDs); | ||
|
||
$this->requireAsset('select2'); | ||
|
||
$this->set('pageTitle', t('Accelerated Mobile Pages (AMP)')); | ||
} | ||
|
||
public function settings_saved() | ||
{ | ||
$this->set('message', t('Settings saved.')); | ||
$this->view(); | ||
} | ||
|
||
public function update_settings() | ||
{ | ||
if ($this->token->validate("update_settings")) { | ||
if ($this->isPost()) { | ||
/** @var \Concrete\Core\Package\Package $pkg */ | ||
$pkg = Package::getByHandle('amp'); | ||
$pkg->getFileConfig()->save('analytics.googleanalytics.account', $this->post('account')); | ||
if (is_array($this->post('types'))) { | ||
$pkg->getFileConfig()->save('types', $this->post('types')); | ||
} | ||
$this->redirect('/dashboard/system/seo/amp', 'settings_saved'); | ||
} | ||
} else { | ||
$this->error->add($this->token->getErrorMessage()); | ||
} | ||
$this->view(); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php defined('C5_EXECUTE') or die("Access Denied.");?> | ||
|
||
<form action="<?php echo $this->action('update_settings')?>" method="post"> | ||
<?php echo $this->controller->token->output('update_settings')?> | ||
<fieldset> | ||
<legend><?php echo t('Basic'); ?></legend> | ||
<div class="form-group"> | ||
<?php echo $form->label('types', t('Which Page Types should serve AMP Page?')); ?> | ||
<div style="width: 100%"> | ||
<?php echo $form->selectMultiple('types', $pagetypes, $types, array('style' => 'width: 100%')); ?> | ||
</div> | ||
</div> | ||
</fieldset> | ||
<fieldset> | ||
<legend><?php echo t('Google Analytics'); ?></legend> | ||
<div class="form-group"> | ||
<?php echo $form->label('account', t('Property ID')); ?> | ||
<?php echo $form->text('account', $account, array('placeholder' => 'UA-XXXXX-Y')); ?> | ||
</div> | ||
</fieldset> | ||
<div class="ccm-dashboard-form-actions-wrapper"> | ||
<div class="ccm-dashboard-form-actions"> | ||
<button class="pull-right btn btn-success" type="submit" ><?php echo t('Save')?></button> | ||
</div> | ||
</div> | ||
</form> | ||
<script type="text/javascript"> | ||
$(function() { | ||
$('#types').removeClass('form-control').select2(); | ||
}); | ||
</script> |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
namespace Concrete\Package\Amp\Amp; | ||
|
||
use Concrete\Block\Content\Controller as ContentBlockController; | ||
use Concrete\Core\Editor\LinkAbstractor; | ||
use Concrete\Package\Amp\Html\Object\AmpImg; | ||
use File; | ||
use Sunra\PhpSimple\HtmlDomParser; | ||
|
||
class Converter | ||
{ | ||
public static function content(ContentBlockController $controller) | ||
{ | ||
$content = $controller->getSearchableContent(); | ||
|
||
$dom = new HtmlDomParser(); | ||
$r = $dom->str_get_html($content, true, true, DEFAULT_TARGET_CHARSET, false); | ||
if (is_object($r)) { | ||
foreach ($r->find('concrete-picture') as $picture) { | ||
$fID = $picture->fid; | ||
$fo = File::getByID($fID); | ||
if (is_object($fo)) { | ||
$tag = new AmpImg($fo); | ||
$tag->alt($picture->alt); | ||
$picture->outertext = (string) $tag; | ||
} | ||
} | ||
$content = (string) $r->restore_noise($r); | ||
} | ||
|
||
return LinkAbstractor::translateFrom($content); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
namespace Concrete\Package\Amp\Area; | ||
|
||
use Concrete\Core\Area\Area; | ||
use Concrete\Core\Block\Block; | ||
use Concrete\Package\Amp\View\AmpBlockView; | ||
use Page; | ||
use Permissions; | ||
use View; | ||
|
||
class AmpArea extends Area | ||
{ | ||
private $ampSafeBlockTypes = array('image','content','video','youtube'); | ||
|
||
public function display($c = false, $alternateBlockArray = null) | ||
{ | ||
if (!$c) { | ||
$c = Page::getCurrentPage(); | ||
} | ||
$v = View::getRequestInstance(); | ||
|
||
if (!is_object($c) || $c->isError()) { | ||
return false; | ||
} | ||
|
||
$this->load($c); | ||
$ap = new Permissions($this); | ||
if (!$ap->canViewArea()) { | ||
return false; | ||
} | ||
|
||
$blocksToDisplay = ($alternateBlockArray) ? $alternateBlockArray : $this->getAreaBlocksArray(); | ||
|
||
/** @var Block $b */ | ||
foreach ($blocksToDisplay as $b) { | ||
if (in_array($b->getBlockTypeHandle(), $this->ampSafeBlockTypes)) { | ||
$bv = new AmpBlockView($b); | ||
$bv->setAreaObject($this); | ||
$p = new Permissions($b); | ||
if ($p->canViewBlock()) { | ||
echo $bv->render('view'); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.