Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bennyborn committed Jul 17, 2014
0 parents commit f5d6866
Show file tree
Hide file tree
Showing 10 changed files with 1,038 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
contao-random-ce
======================

About
-----

Provides a wrapper (like accordion) for content elements to show a different, random element on each reload of the page.


Screenshot
-----------

![Editing a single store](https://contao.org/files/repository/storelocator/10010009/picture.jpg)


Dependencies
-------------------

* [Contao](https://github.com/contao/core) 3.0 or higher
34 changes: 34 additions & 0 deletions system/modules/random_ce/classes/ContentElementTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/**
* Contao Open Source CMS
*
* Copyright (c) 2005-2014 Leo Feyer
*
* @package Random ContentElement
* @author Benny Born <[email protected]>
* @license LGPL
* @copyright 2014 numero2 - Agentur für Internetdienstleistungen
*/


namespace RandomCE;


class ContentElementTest extends \Controller
{

/**
* Check if this content element should be visible this time
* @param $row
* @param $strBuffer
*/
public function checkContentElement( $row, $strBuffer )
{

if( TL_MODE == 'BE' || empty($GLOBALS['random_ce_hide']) || !in_array($row->id,$GLOBALS['random_ce_hide']) )
return $strBuffer;

return '';
}
}
14 changes: 14 additions & 0 deletions system/modules/random_ce/config/autoload.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
;;
; Configure what you want the autoload creator to register
;;
register_namespaces = true
register_classes = true
register_templates = true

;;
; Override the default configuration for certain sub directories
;;
[vendor/*]
register_namespaces = false
register_classes = false
register_templates = false
33 changes: 33 additions & 0 deletions system/modules/random_ce/config/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* Contao Open Source CMS
*
* Copyright (c) 2005-2014 Leo Feyer
*
* @package Random ContentElement
* @author Benny Born <[email protected]>
* @license LGPL
* @copyright 2014 numero2 - Agentur für Internetdienstleistungen
*/


/**
* Register the namespaces
*/
ClassLoader::addNamespaces(array
(
'RandomCE',
));


/**
* Register the classes
*/
ClassLoader::addClasses(array
(
// Elements
'RandomCE\ContentElementTest' => 'system/modules/random_ce/classes/ContentElementTest.php',
'RandomCE\ContentRandomCEStart' => 'system/modules/random_ce/elements/ContentRandomCEStart.php',
'RandomCE\ContentRandomCEStop' => 'system/modules/random_ce/elements/ContentRandomCEStop.php',
));
34 changes: 34 additions & 0 deletions system/modules/random_ce/config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/**
* Contao Open Source CMS
*
* Copyright (c) 2005-2014 Leo Feyer
*
* @package Random ContentElement
* @author Benny Born <[email protected]>
* @license LGPL
* @copyright 2014 numero2 - Agentur für Internetdienstleistungen
*/


/**
* Content elements
*/
$GLOBALS['TL_CTE']['random_ce'] = array(
'randomCEStart' => 'ContentRandomCEStart',
'randomCEStop' => 'ContentRandomCEStop'
);


/**
* Wrapper elements
*/
$GLOBALS['TL_WRAPPERS']['start'][] = 'randomCEStart';
$GLOBALS['TL_WRAPPERS']['stop'][] = 'randomCEStop';


/**
* Hooks
*/
$GLOBALS['TL_HOOKS']['getContentElement'][] = array('ContentElementTest','checkContentElement');
19 changes: 19 additions & 0 deletions system/modules/random_ce/dca/tl_content.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/**
* Contao Open Source CMS
*
* Copyright (c) 2005-2014 Leo Feyer
*
* @package Random ContentElement
* @author Benny Born <[email protected]>
* @license LGPL
* @copyright 2014 numero2 - Agentur für Internetdienstleistungen
*/


/**
* Table tl_content
*/
$GLOBALS['TL_DCA']['tl_content']['palettes']['randomCEStart'] = '{type_legend},type;{expert_legend:hide},guests,cssID,space;{invisible_legend:hide},invisible,start,stop';
$GLOBALS['TL_DCA']['tl_content']['palettes']['randomCEStop'] = '{type_legend},type;{expert_legend:hide},guests,cssID,space;{invisible_legend:hide},invisible,start,stop';
54 changes: 54 additions & 0 deletions system/modules/random_ce/elements/ContentRandomCEStart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/**
* Contao Open Source CMS
*
* Copyright (c) 2005-2014 Leo Feyer
*
* @package Random ContentElement
* @author Benny Born <[email protected]>
* @license LGPL
* @copyright 2014 numero2 - Agentur für Internetdienstleistungen
*/


namespace RandomCE;


class ContentRandomCEStart extends \ContentElement
{

/**
* Generate the content element
*/
protected function compile()
{
if (TL_MODE == 'BE')
{
$this->strTemplate = 'be_wildcard';
$this->Template = new \BackendTemplate($this->strTemplate);

} else {

// determine which element should be shown this time
$closingElement = \Database::getInstance()->prepare("SELECT id,sorting FROM tl_content WHERE pid = ? AND sorting > ? AND type = 'randomCEStop'")->limit(1)->execute( $this->pid, $this->sorting );

if( $closingElement->id ) {

$contentElements = \Database::getInstance()->prepare("SELECT id FROM tl_content WHERE pid = ? AND sorting > ? AND sorting < ?")->execute( $this->pid, $this->sorting, $closingElement->sorting );

$aElementIDs = $contentElements->fetchAllAssoc();
$GLOBALS['random_ce_hide'] = array();

// decide which will be shown
$toBeShown = mt_rand(0, (count($aElementIDs)-1));

foreach( $aElementIDs as $i => $v ) {

if( $i != $toBeShown )
$GLOBALS['random_ce_hide'][] = $v['id'];
}
}
}
}
}
31 changes: 31 additions & 0 deletions system/modules/random_ce/elements/ContentRandomCEStop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
* Contao Open Source CMS
*
* Copyright (c) 2005-2014 Leo Feyer
*
* @package Random ContentElement
* @author Benny Born <[email protected]>
* @license LGPL
* @copyright 2014 numero2 - Agentur für Internetdienstleistungen
*/


namespace RandomCE;


class ContentRandomCEStop extends \ContentElement
{
/**
* Generate the content element
*/
protected function compile()
{
if (TL_MODE == 'BE')
{
$this->strTemplate = 'be_wildcard';
$this->Template = new \BackendTemplate($this->strTemplate);
}
}
}
26 changes: 26 additions & 0 deletions system/modules/random_ce/languages/de/default.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" ?><xliff version="1.1">
<file datatype="php" original="system/modules/core/languages/en/default.php" source-language="en">
<body>
<trans-unit id="CTE.random_ce">
<source>Random Content Element</source>
<target>Zufälliges Inhaltselement</target>
</trans-unit>
<trans-unit id="CTE.randomCEStart.0">
<source>Wrapper start</source>
<target>Umschlag Anfang</target>
</trans-unit>
<trans-unit id="CTE.randomCEStart.1">
<source>Generates the opening part of the random element wrapper.</source>
<target>Erzeugt den öffnenden Teil des zufälligen Inhaltsemenet-Umschlags.</target>
</trans-unit>
<trans-unit id="CTE.randomCEStop.0">
<source>Wrapper stop</source>
<target>Umschlag Ende</target>
</trans-unit>
<trans-unit id="CTE.randomCEStop.1">
<source>Generates the closing part of the random element wrapper.</source>
<target>Erzeugt den schließenden Teil des zufälligen Inhaltsemenet-Umschlags.</target>
</trans-unit>
</body>
</file>
</xliff>
Loading

0 comments on commit f5d6866

Please sign in to comment.