-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit f5d6866
Showing
10 changed files
with
1,038 additions
and
0 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,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 |
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,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 ''; | ||
} | ||
} |
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,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 |
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 | ||
|
||
/** | ||
* 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', | ||
)); |
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,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'); |
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,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
54
system/modules/random_ce/elements/ContentRandomCEStart.php
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,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']; | ||
} | ||
} | ||
} | ||
} | ||
} |
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 | ||
|
||
/** | ||
* 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); | ||
} | ||
} | ||
} |
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,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> |
Oops, something went wrong.