Skip to content

Commit

Permalink
more work on blog
Browse files Browse the repository at this point in the history
  • Loading branch information
aembler committed Aug 4, 2014
1 parent ed53cbf commit 4228908
Show file tree
Hide file tree
Showing 17 changed files with 302 additions and 29 deletions.
6 changes: 5 additions & 1 deletion web/concrete/attributes/topics/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ class Controller extends AttributeTypeController {

public function filterByAttribute(AttributedItemList $list, $value, $comparison = '=')
{
$topic = Node::getByID(intval($value));
if ($value instanceof TreeNode) {
$topic = $value;
} else {
$topic = Node::getByID(intval($value));
}
if (is_object($topic) && $topic instanceof \Concrete\Core\Tree\Node\Type\Topic) {
$column = 'ak_' . $this->attributeKey->getAttributeKeyHandle();
$qb = $list->getQueryObject();
Expand Down
3 changes: 3 additions & 0 deletions web/concrete/blocks/related_pages/add.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php defined('C5_EXECUTE') or die("Access Denied.");
$this->inc('form.php');
?>
88 changes: 88 additions & 0 deletions web/concrete/blocks/related_pages/controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace Concrete\Block\RelatedPages;
defined('C5_EXECUTE') or die("Access Denied.");
use Concrete\Core\Attribute\Key\CollectionKey;
use Concrete\Core\Block\BlockController;
use Concrete\Core\Page\PageList;
use Concrete\Core\Page\Type\Type;
use Concrete\Core\Tree\Tree;
use Concrete\Core\Tree\Type\Topic as TopicTree;
use Concrete\Core\Tree\Type\Topic;
use Core;
use Loader;

class Controller extends BlockController
{

public $helpers = array('form');

protected $btInterfaceWidth = 400;
protected $btCacheBlockOutput = true;
protected $btCacheBlockOutputOnPost = true;
protected $btCacheBlockOutputForRegisteredUsers = true;
protected $btInterfaceHeight = 300;
protected $btTable = 'btRelatedPages';

public function getBlockTypeDescription()
{
return t("Displays a list of pages related to this page. Uses the topic attribute for relation.");
}

public function getBlockTypeName()
{
return t("Related Pages");
}

public function add()
{
$this->edit();
$this->set('maxResults', 3);
$this->set('title', t('Related Pages'));
}

public function edit()
{
$keys = CollectionKey::getList();
foreach($keys as $ak) {
if ($ak->getAttributeTypeHandle() == 'topics') {
$attributeKeys[] = $ak;
}
}
$types = Type::getList();
$this->set('pagetypes', $types);
$this->set('attributeKeys', $attributeKeys);
}

public function view()
{
$ak = CollectionKey::getByHandle($this->topicAttributeKeyHandle);
$pages = array();
$c = \Page::getCurrentPage();
if (is_object($ak)) {
$topics = $c->getAttribute($ak->getAttributeKeyHandle());
if (count($topics)) {
$pl = new PageList();
$pl->setItemsPerPage($this->maxResults);
if ($this->ptID) {
$pl->filterByPageTypeID($this->ptID);
}
if ($this->cParentID) {
$pl->filterByParentID($this->cParentID);
}
$pl->filter('p.cID', $c->getCollectionID(), '<>');
$topic = $topics[array_rand($topics)];
$pl->filterByTopic($topic);
$pl->sortBy('rand()');
$pages = $pl->getPagination()->getCurrentPageResults();
}
}
$this->set('pages', $pages);
}

public function save($data)
{
$data['maxResults'] = intval($data['maxResults']);
parent::save($data);
}
}
29 changes: 29 additions & 0 deletions web/concrete/blocks/related_pages/db.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<schema version="0.3">
<table name="btRelatedPages">
<field name="bID" type="I">
<key />
<unsigned />
</field>
<field name="topicAttributeKeyHandle" type="C" size="255">
<notnull />
<default value="" />
</field>
<field name="title" type="C" size="255">
<notnull />
<default value="" />
</field>
<field name="maxResults" type="I">
<unsigned />
<default value="3" />
</field>
<field name="cParentID" type="I">
<unsigned />
<notnull />
<default value="0" />
</field>
<field name="ptID" type="I2">
<unsigned />
</field>
</table>
</schema>
3 changes: 3 additions & 0 deletions web/concrete/blocks/related_pages/edit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php defined('C5_EXECUTE') or die("Access Denied.");
$this->inc('form.php');
?>
69 changes: 69 additions & 0 deletions web/concrete/blocks/related_pages/form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php defined('C5_EXECUTE') or die("Access Denied."); ?>
<fieldset>
<div class="form-group" data-row="mode-page">
<label class="control-label" for="attributeKeySelect"><?=t('Topic Attribute to Use For Relation')?></label>
<select class="form-control" name="topicAttributeKeyHandle" id="attributeKeySelect">
<? foreach($attributeKeys as $attributeKey) { ?>
<option value="<?=$attributeKey->getAttributeKeyHandle()?>" <? if ($attributeKey->getAttributeKeyHandle() == $topicAttributeKeyHandle) { ?>selected<? } ?>><?=$attributeKey->getAttributeKeyDisplayName()?></option>
<? } ?>
</select>
</div>

<div class='form-group'>
<label for='title' style="margin-bottom: 0px;"><?=t('Parent Page')?>:</label>
<div class="checkbox">
<label>
<input <? if (intval($cParentID) > 0) { ?>checked<? } ?> name="filterByParent" type="checkbox" value="1" />
<?=t('Filter by Parent Page')?>
</label>
</div>
<div id="ccm-block-related-pages-parent-page">
<?
print Loader::helper('form/page_selector')->selectPage('cParentID', $cParentID);
?>
</div>
</div>

<div class="form-group">
<label class="control-label"><?= t('Filter by Page Type') ?></label>
<?php ?>
<select class="form-control" name="ptID" id="selectPTID">
<option value="0">** <?php echo t('All') ?> **</option>
<?php
foreach ($pagetypes as $ct) {
?>
<option
value="<?= $ct->getPageTypeID() ?>" <? if ($ptID == $ct->getPageTypeID()) { ?> selected <? } ?>>
<?= $ct->getPageTypeName() ?>
</option>
<?php
}
?>
</select>
<?php ?>
</div>

<div class="form-group">
<label class="control-label" for="maxResults"><?=t('Number of Pages to Display')?></label>
<input class="form-control" name="maxResults" id="maxResults" value="<?=$maxResults?>" />
</div>

<div class="form-group">
<label class="control-label" for="title"><?=t('Title')?></label>
<input class="form-control" name="title" id="title" value="<?=$title?>" />
</div>

</fieldset>


<script type="text/javascript">
$(function() {
$("input[name=filterByParent]").on('change', function() {
if ($(this).is(":checked")) {
$('#ccm-block-related-pages-parent-page').show();
} else {
$('#ccm-block-related-pages-parent-page').hide();
}
}).trigger('change');
});
</script>
Binary file added web/concrete/blocks/related_pages/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions web/concrete/blocks/related_pages/view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php defined('C5_EXECUTE') or die("Access Denied."); ?>
<? if (count($pages) > 0): ?>

<div class="ccm-block-related-pages-wrapper">

<div class="ccm-block-related-pages-header">
<h5><?=$title?></h5>
</div>

<? foreach($pages as $page) { ?>

<div class="ccm-block-related-pages-page">
<a href="<?=$page->getCollectionLink()?>"><?=$page->getCollectionName()?></a>
</div>

<? } ?>

</div>


<? endif; ?>
12 changes: 12 additions & 0 deletions web/concrete/blocks/share_this_page/view.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ul.list-inline {
display: inline-block;
margin: 0px;
padding: 0px;
}

ul.list-inline li {
padding: 0px;
list-style-type: none;
margin-right: 10px;
display: inline-block;
}
16 changes: 8 additions & 8 deletions web/concrete/blocks/share_this_page/view.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
defined('C5_EXECUTE') or die("Access Denied.");
foreach($selected as $service) { ?>

<a href="<?=$service->getServiceLink()?>"><?=$service->getServiceIconHTML()?></a>

<?
}
<?php defined('C5_EXECUTE') or die("Access Denied."); ?>

<div class="ccm-block-share-this-page">
<ul class="list-inline">
<? foreach($selected as $service) { ?>
<li><a href="<?=$service->getServiceLink()?>"><?=$service->getServiceIconHTML()?></a></li>
<? } ?>
</ul>
</div>
3 changes: 2 additions & 1 deletion web/concrete/blocks/topic_list/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Controller extends BlockController
protected $btCacheBlockOutput = true;
protected $btCacheBlockOutputOnPost = true;
protected $btCacheBlockOutputForRegisteredUsers = true;
protected $btInterfaceHeight = 300;
protected $btInterfaceHeight = 400;
protected $btTable = 'btTopicList';

public function getBlockTypeDescription()
Expand All @@ -35,6 +35,7 @@ public function getBlockTypeName()
public function add()
{
$this->edit();
$this->set('title', t('Topics'));
}

public function edit()
Expand Down
4 changes: 4 additions & 0 deletions web/concrete/blocks/topic_list/db.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,9 @@
<notnull />
<default value="0" />
</field>
<field name="title" type="C" size="255">
<notnull />
<default value="" />
</field>
</table>
</schema>
5 changes: 5 additions & 0 deletions web/concrete/blocks/topic_list/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
</div>
</div>

<div class="form-group">
<label class="control-label" for="title"><?=t('Title')?></label>
<input class="form-control" name="title" id="title" value="<?=$title?>" />
</div>

</fieldset>

<script type="text/javascript">
Expand Down
17 changes: 12 additions & 5 deletions web/concrete/blocks/topic_list/view.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<?php defined('C5_EXECUTE') or die("Access Denied."); ?>
<?

<div class="ccm-block-topic-list-wrapper">

<div class="ccm-block-topic-list-header">
<h5><?=$title?></h5>
</div>
<?
if ($mode == 'S'):
$node = $tree->getRootTreeNodeObject();
$node->populateChildren();
if (is_object($node)) {
$walk = function($node) use (&$walk, &$view, $selectedTopicID) {
print '<ul class="ccm-block-topic-list">';
print '<ul class="ccm-block-topic-list-list">';
foreach($node->getChildNodes() as $topic) {
if ($topic instanceof \Concrete\Core\Tree\Node\Type\TopicCategory) { ?>
<li><?=$topic->getTreeNodeDisplayName()?></li>
Expand All @@ -28,13 +33,15 @@ class="ccm-block-topic-list-topic-selected"
if ($mode == 'P'): ?>

<? if (count($topics)) { ?>
<ul class="ccm-block-topic-page-topics">
<ul class="ccm-block-topic-list-page-topics">
<? foreach($topics as $topic) { ?>
<li><a href="<?=$view->controller->getTopicLink($topic)?>"><?=$topic->getTreeNodeDisplayName()?></a></li>
<? } ?>
</ul>
<? } else { ?>
<?=t('No topics.')?>
<? } ?>
<?
endif;

<? endif; ?>

</div>
2 changes: 2 additions & 0 deletions web/concrete/config/install/base/blocktypes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<blocktype handle="feature" package=""/>
<blocktype handle="topic_list" package=""/>
<blocktype handle="social_links" package=""/>
<blocktype handle="related_pages" package=""/>
<blocktype handle="share_this_page" package=""/>
<blocktype handle="google_map" package=""/>
<blocktype handle="html" package=""/>
Expand Down Expand Up @@ -76,6 +77,7 @@
<blocktype handle="date_nav"/>
<blocktype handle="tags"/>
<blocktype handle="topic_list"/>
<blocktype handle="related_pages"/>
<blocktype handle="rss_displayer"/>
</blocktypeset>
<blocktypeset handle="form" name="Forms" package="">
Expand Down

0 comments on commit 4228908

Please sign in to comment.