Skip to content

Commit

Permalink
Updated copyright info, and code styling
Browse files Browse the repository at this point in the history
  • Loading branch information
kozi committed Jul 31, 2015
1 parent c744e7b commit 174720b
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 162 deletions.
2 changes: 1 addition & 1 deletion contao/assets/style.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* additional_metafields (Martin Kozianka 2013-2014 <http://kozianka.de/>)
/* additional_metafields (Martin Kozianka 2013-2015 <http://kozianka.de/>)
---------------------------------------------------------------------------------*/

.tl_metawizard_plus label.tl_metafields {
Expand Down
108 changes: 70 additions & 38 deletions contao/classes/MetafieldsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

/**
* Contao Open Source CMS
* Copyright (C) 2005-2014 Leo Feyer
* Copyright (C) 2005-2015 Leo Feyer
*
*
* PHP version 5
* @copyright Martin Kozianka 2013-2014 <http://kozianka.de/>
* @copyright Martin Kozianka 2013-2015 <http://kozianka.de/>
* @author Martin Kozianka <http://kozianka.de/>
* @package additional_metafields
* @package contao-metafields
* @license LGPL
* @filesource
*/
Expand All @@ -20,12 +20,13 @@
* Class MetafieldsHelper
*
* Provides some helper functions
* @copyright Martin Kozianka 2013-2014 <http://kozianka.de/>
* @copyright Martin Kozianka 2013-2015 <http://kozianka.de/>
* @author Martin Kozianka <http://kozianka.de/>
* @package additional_metafields
* @package contao-metafields
*/

class MetafieldsHelper extends \Frontend {
class MetafieldsHelper extends \Frontend
{

const TYPE_FOLDER = '__TYPE_FOLDER__';

Expand All @@ -42,41 +43,48 @@ class MetafieldsHelper extends \Frontend {
*
* @return MetafieldsHelper The MetafieldsHelper object
*/
static public function getInstance() {

if (static::$instance === null) {
static public function getInstance()
{
if (static::$instance === null)
{
static::$instance = new static();
}

return static::$instance;
}

public function getFields($activeRecord) {
public function getFields($activeRecord)
{
$arrMetafields = $this->loadFields();
$strType = ($activeRecord->type !== 'folder') ? $activeRecord->extension : self::TYPE_FOLDER;

if (!array_key_exists($strType, $arrMetafields) ) {
if (!array_key_exists($strType, $arrMetafields) )
{
return null;
}

return $arrMetafields[$strType];
}

public function injectMetaData($objRow, $strBuffer, $objElement) {
public function injectMetaData($objRow, $strBuffer, $objElement)
{
global $objPage;

if (!in_array($objRow->type, array('text', 'image', 'gallery', 'accordionSingle'))) {
if (!in_array($objRow->type, array('text', 'image', 'gallery', 'accordionSingle')))
{
return $strBuffer;
}

if ($objRow->type === 'gallery') {
if ($objRow->type === 'gallery')
{
$objElement->__set('metadata', $this->getMultiMetaData($objRow->multiSRC));
$strBuffer = $objElement->generate();
}

if ($objRow->type === 'image'
|| ($objRow->type === 'text' && $objRow->addImage === '1')
|| ($objRow->type === 'accordionSingle' && $objRow->addImage === '1')) {
|| ($objRow->type === 'accordionSingle' && $objRow->addImage === '1'))
{
$objFile = \FilesModel::findByUuid($objRow->singleSRC);
$objElement->__set('singleSRC', $objFile->uuid);
$objElement->__set('metadata', $this->getMetaData($objFile->meta, $objPage->language));
Expand All @@ -87,14 +95,16 @@ public function injectMetaData($objRow, $strBuffer, $objElement) {
return $strBuffer;
}

public function injectMetaDataArticleImage(&$objTmpl, $row, $obj) {
public function injectMetaDataArticleImage(&$objTmpl, $row, $obj)
{
global $objPage;

$objFile = \FilesModel::findByUuid($row['singleSRC']);
$objTmpl->metadata = $this->getMetaData($objFile->meta, $objPage->language);
}

private function getMultiMetaData($multiSRC) {
private function getMultiMetaData($multiSRC)
{
global $objPage;

$images = array();
Expand All @@ -103,29 +113,38 @@ private function getMultiMetaData($multiSRC) {
if($objFiles !== null) {
while ($objFiles->next()) {
// Continue if the files has been processed or does not exist
if (isset($images[$objFiles->path]) || !file_exists(TL_ROOT . '/' . $objFiles->path)) {
if (isset($images[$objFiles->path]) || !file_exists(TL_ROOT . '/' . $objFiles->path))
{
continue;
}
// Single files
if ($objFiles->type == 'file') {
if ($objFiles->type == 'file')
{
$objFile = new \File($objFiles->path, true);
if (!$objFile->isGdImage) {
if (!$objFile->isGdImage)
{
continue;
}
$images[$objFiles->path] = $this->getMetaData($objFiles->meta, $objPage->language);
} else {
}
else
{
$objSubfiles = \FilesModel::findByPid($objFiles->uuid);
if ($objSubfiles === null) {
if ($objSubfiles === null)
{
continue;
}
while ($objSubfiles->next()) {
while ($objSubfiles->next())
{
// Skip subfolders
if ($objSubfiles->type == 'folder') {
if ($objSubfiles->type == 'folder')
{
continue;
}
$objFile = new \File($objSubfiles->path, true);

if (!$objFile->isGdImage) {
if (!$objFile->isGdImage)
{
continue;
}

Expand All @@ -138,47 +157,60 @@ private function getMultiMetaData($multiSRC) {
return $images;
}

public static function embedData(&$body, $metadata) {
if (!is_array($metadata)) {
public static function embedData(&$body, $metadata)
{
if (!is_array($metadata))
{
return false;
}

foreach($body as $class => $row) {
foreach($row as $key => $col) {
if (array_key_exists($col->singleSRC, $metadata) && sizeof($metadata[$col->singleSRC]) > 0) {
foreach($body as $class => $row)
{
foreach($row as $key => $col)
{
if (array_key_exists($col->singleSRC, $metadata) && sizeof($metadata[$col->singleSRC]) > 0)
{
$body[$class][$key]->metadata = $metadata[$col->singleSRC];
}
}
}
return true;
}

private function loadFields() {
if($this->arrMetafields !== null) {
private function loadFields()
{
if($this->arrMetafields !== null)
{
return $this->arrMetafields;
}
$this->arrMetafields = array();
// Todo label translation
$collection = MetafieldsModel::findAll();

if ($collection === null) {
if ($collection === null)
{
return $this->arrMetafields;
}

foreach($collection as $objField) {
foreach($collection as $objField)
{
$extensions = array_map('trim', explode(',', $objField->extensions));
$alias = $objField->alias;
$label = $objField->label;
$folderAttr = ($objField->folder === '1');

foreach($extensions as $ext) {
if (!is_array($this->arrMetafields[$ext])) {
foreach($extensions as $ext)
{
if (!is_array($this->arrMetafields[$ext]))
{
$this->arrMetafields[$ext] = array();
}
$this->arrMetafields[$ext][$alias] = $label;

if ($folderAttr) {
if (!is_array($this->arrMetafields[static::TYPE_FOLDER])) {
if ($folderAttr)
{
if (!is_array($this->arrMetafields[static::TYPE_FOLDER]))
{
$this->arrMetafields[static::TYPE_FOLDER] = array();
}
$this->arrMetafields[static::TYPE_FOLDER][$alias] = $label;
Expand Down
16 changes: 8 additions & 8 deletions contao/config/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

/**
* Contao Open Source CMS
* Copyright (C) 2005-2014 Leo Feyer
* Copyright (C) 2005-2015 Leo Feyer
*
*
* PHP version 5
* @copyright Martin Kozianka 2013-2014 <http://kozianka.de/>
* @copyright Martin Kozianka 2013-2015 <http://kozianka.de/>
* @author Martin Kozianka <http://kozianka.de/>
* @package additional_metafields
* @package contao-metafields
* @license LGPL
* @filesource
*/
ClassLoader::addNamespace('AdditionalMetafields');

ClassLoader::addClasses(array(
'AdditionalMetafields\MetafieldsHelper' => 'system/modules/metafields/classes/MetafieldsHelper.php',
'AdditionalMetafields\MetaWizardPlus' => 'system/modules/metafields/widgets/MetaWizardPlus.php',
'AdditionalMetafields\MetafieldsModel' => 'system/modules/metafields/models/MetafieldsModel.php',
));
ClassLoader::addClasses([
'AdditionalMetafields\MetafieldsHelper' => 'system/modules/metafields/classes/MetafieldsHelper.php',
'AdditionalMetafields\MetaWizardPlus' => 'system/modules/metafields/widgets/MetaWizardPlus.php',
'AdditionalMetafields\MetafieldsModel' => 'system/modules/metafields/models/MetafieldsModel.php',
]);


6 changes: 3 additions & 3 deletions contao/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

/**
* Contao Open Source CMS
* Copyright (C) 2005-2014 Leo Feyer
* Copyright (C) 2005-2015 Leo Feyer
*
*
* PHP version 5
* @copyright Martin Kozianka 2013-2014 <http://kozianka.de/>
* @copyright Martin Kozianka 2013-2015 <http://kozianka.de/>
* @author Martin Kozianka <http://kozianka.de/>
* @package additional_metafields
* @package contao-metafields
* @license LGPL
* @filesource
*/
Expand Down
6 changes: 3 additions & 3 deletions contao/config/runonce.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

/**
* Contao Open Source CMS
* Copyright (C) 2005-2014 Leo Feyer
* Copyright (C) 2005-2015 Leo Feyer
*
*
* PHP version 5
* @copyright Martin Kozianka 2013-2014 <http://kozianka.de/>
* @copyright Martin Kozianka 2013-2015 <http://kozianka.de/>
* @author Martin Kozianka <http://kozianka.de/>
* @package additional_metafields
* @package contao-metafields
* @license LGPL
* @filesource
*/
Expand Down
6 changes: 3 additions & 3 deletions contao/dca/tl_files.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

/**
* Contao Open Source CMS
* Copyright (C) 2005-2014 Leo Feyer
* Copyright (C) 2005-2015 Leo Feyer
*
*
* PHP version 5
* @copyright Martin Kozianka 2013-2014 <http://kozianka.de/>
* @copyright Martin Kozianka 2013-2015 <http://kozianka.de/>
* @author Martin Kozianka <http://kozianka.de/>
* @package additional_metafields
* @package contao-metafields
* @license LGPL
* @filesource
*/
Expand Down
Loading

0 comments on commit 174720b

Please sign in to comment.