Browse code

Sanitize the code, adjust the usage of namespaces and add some comments

Benjamin Roth authored on13/07/2016 10:34:22
Showing5 changed files
... ...
@@ -71,7 +71,7 @@ $GLOBALS['TL_DCA']['tl_article']['fields']['es_size'] = array
71 71
  *
72 72
  * @author Benjamin Roth <http://www.esales-media.de>
73 73
  */
74
-class tl_article_eSM_artLayout extends Backend
74
+class tl_article_eSM_artLayout extends \Backend
75 75
 {
76 76
 
77 77
   /**
... ...
@@ -83,6 +83,13 @@ class tl_article_eSM_artLayout extends Backend
83 83
     $this->import('BackendUser', 'User');
84 84
   }
85 85
 
86
+  /**
87
+   * Return article layouts
88
+   *
89
+   * @param DataContainer $dc
90
+   *
91
+   * @return array
92
+   */
86 93
   public function getArticleLayouts(\DataContainer $dc)
87 94
   {
88 95
 
... ...
@@ -97,6 +104,11 @@ class tl_article_eSM_artLayout extends Backend
97 104
     return $arrArticleLayouts;
98 105
   }
99 106
 
107
+  /**
108
+   * Dynamically add subpalettes on runtime
109
+   *
110
+   * @param DataContainer $dc
111
+   */
100 112
   public function registerSubPalettes(\DataContainer $dc)
101 113
   {
102 114
     $Layouts = \Database::getInstance()->execute("SELECT * FROM tl_article_layouts");
... ...
@@ -230,7 +230,7 @@ $GLOBALS['TL_DCA']['tl_article_layouts'] = array
230 230
  *
231 231
  * @author Benjamin Roth <http://www.esales-media.de>
232 232
  */
233
-class tl_article_layouts extends Backend
233
+class tl_article_layouts extends \Backend
234 234
 {
235 235
 
236 236
 	/**
... ...
@@ -270,7 +270,7 @@ class tl_article_layouts extends Backend
270 270
 	 *
271 271
 	 * @throws Exception
272 272
 	 */
273
-	public function generateAlias($varValue, DataContainer $dc)
273
+	public function generateAlias($varValue, \DataContainer $dc)
274 274
 	{
275 275
 		$autoAlias = false;
276 276
 
... ...
@@ -20,7 +20,7 @@ $GLOBALS['TL_DCA']['tl_content']['fields']['type']['options_callback'] = array('
20 20
  *
21 21
  * @author Benjamin Roth <http://www.esales-media.de>
22 22
  */
23
-class tl_content_eSM_artLayout extends Backend
23
+class tl_content_eSM_artLayout extends \Backend
24 24
 {
25 25
 
26 26
   /**
... ...
@@ -32,25 +32,39 @@ class tl_content_eSM_artLayout extends Backend
32 32
     $this->import('BackendUser', 'User');
33 33
   }
34 34
 
35
-  public function getContentElements(DataContainer $dc)
35
+  /**
36
+   * Return all allowed content elements
37
+   *
38
+   * @param DataContainer $dc
39
+   *
40
+   * @return array
41
+   */
42
+  public function getContentElements(\DataContainer $dc)
36 43
   {
37 44
     $groups = array();
38 45
 
46
+    // Get article model
39 47
     $Article = \ArticleModel::findByPk($dc->activeRecord->pid);
40
-    
48
+
49
+    // Check for article layout
41 50
     if ($Article->es_type)
42 51
     {
52
+      // Get layout model
43 53
       $ArticleLayout = \ArticleLayoutsModel::findByPk($Article->es_type);
44 54
 
55
+      // Build array of allowed elements if restriction is set
45 56
       if ($ArticleLayout !== null && $ArticleLayout->restrictContentElements)
46 57
       {
47 58
         $arrAllowedCTE = deserialize($ArticleLayout->allowedElements,true);
48 59
       }
49 60
     }
50 61
 
62
+    // Build elements groups
51 63
     foreach ($GLOBALS['TL_CTE'] as $k => $v)
52 64
     {
53 65
       foreach (array_keys($v) as $kk) {
66
+
67
+        // Skip not allowed elements
54 68
         if (isset($arrAllowedCTE))
55 69
         {
56 70
           if (!in_array($kk, $arrAllowedCTE))
... ...
@@ -29,7 +29,7 @@ array_insert($GLOBALS['TL_DCA']['tl_theme']['list']['operations'],count($GLOBALS
29 29
  *
30 30
  * @author Benjamin Roth <http://www.esales-media.de>
31 31
  */
32
-class tl_theme_eSM_artLayout extends Backend
32
+class tl_theme_eSM_artLayout extends \Backend
33 33
 {
34 34
 
35 35
   /**
... ...
@@ -41,6 +41,18 @@ class tl_theme_eSM_artLayout extends Backend
41 41
     $this->import('BackendUser', 'User');
42 42
   }
43 43
 
44
+  /**
45
+   * Return the "edit article layouts" button
46
+   *
47
+   * @param $row
48
+   * @param $href
49
+   * @param $label
50
+   * @param $title
51
+   * @param $icon
52
+   * @param $attributes
53
+   *
54
+   * @return string
55
+   */
44 56
   public function editArticleLayouts($row, $href, $label, $title, $icon, $attributes)
45 57
   {
46 58
     return $this->User->hasAccess('artLayout', 'themes') ? '<a href="'.$this->addToUrl($href.'&amp;id='.$row['id']).'" title="'.specialchars($title).'"'.$attributes.'>'.Image::getHtml($icon, $label).'</a> ' : Image::getHtml(preg_replace('/\.gif$/i', '_.gif', $icon)).' ';
... ...
@@ -37,55 +37,57 @@ namespace eSM_artLayout;
37 37
 class ModuleArticle extends \Contao\ModuleArticle
38 38
 {
39 39
 
40
-	/**
41
-	 * Add style if needed
42
-	 *
43
-	 * @param boolean $blnNoMarkup
44
-	 *
45
-	 * @return string
46
-	 */
47
-	public function generate($blnNoMarkup=false)
48
-	{
49
-		if ($this->es_type)
50
-		{
51
-			$ArticleLayout = ArticleLayoutsModel::findByPk($this->es_type);
40
+  /**
41
+   * Inject some article layout stuff
42
+   *
43
+   * @param boolean $blnNoMarkup
44
+   *
45
+   * @return string
46
+   */
47
+  public function generate($blnNoMarkup=false)
48
+  {
49
+    if ($this->es_type)
50
+    {
51
+      $ArticleLayout = ArticleLayoutsModel::findByPk($this->es_type);
52 52
 
53
-			if ($ArticleLayout !== null)
54
-			{
53
+      if ($ArticleLayout !== null)
54
+      {
55 55
 
56
-				if ($ArticleLayout->showBackgroundImage)
57
-				{
58
-					$Image = \FilesModel::findByPk($this->es_backgroundSRC);
56
+        // Select background image and add inline styles
57
+        if ($ArticleLayout->showBackgroundImage)
58
+        {
59
+          $Image = \FilesModel::findByPk($this->es_backgroundSRC);
59 60
 
60
-					if (!is_null($Image))
61
-					{
62
-						$arrData = array
63
-						(
64
-							'singleSRC' => $Image->path,
65
-							'size' => $ArticleLayout->bgImageSize
66
-						);
67
-						$objClass = new \stdClass();
61
+          if (!is_null($Image))
62
+          {
63
+            $arrData = array
64
+            (
65
+              'singleSRC' => $Image->path,
66
+              'size' => $ArticleLayout->bgImageSize
67
+            );
68
+            $objClass = new \stdClass();
68 69
 
69
-						$this->addImageToTemplate($objClass, $arrData, \Config::get('maxImageWidth'));
70
+            $this->addImageToTemplate($objClass, $arrData, \Config::get('maxImageWidth'));
70 71
 
71
-						if (trim($ArticleLayout->bgStyle))
72
-						{
73
-							$this->arrStyle[] = str_ireplace('##bg_image##',$objClass->src,$ArticleLayout->bgStyle);
74
-						}
75
-						else
76
-						{
77
-							$this->arrStyle[] = "background: url('".$objClass->src."');";
78
-						}
79
-					}
80
-				}
72
+            if (trim($ArticleLayout->bgStyle))
73
+            {
74
+              $this->arrStyle[] = str_ireplace('##bg_image##',$objClass->src,$ArticleLayout->bgStyle);
75
+            }
76
+            else
77
+            {
78
+              $this->arrStyle[] = "background: url('".$objClass->src."');";
79
+            }
80
+          }
81
+        }
81 82
 
82
-				$this->useHelper = $ArticleLayout->useHelper;
83
-				$this->maxWidth = $ArticleLayout->maxWidth;
84
-				$this->center = $ArticleLayout->center;
85
-				$this->articleLayoutClass = $ArticleLayout->alias;
86
-			}
87
-		}
83
+        // Set article layout related variables to be used in article template
84
+        $this->useHelper = $ArticleLayout->useHelper;
85
+        $this->maxWidth = $ArticleLayout->maxWidth;
86
+        $this->center = $ArticleLayout->center;
87
+        $this->articleLayoutClass = $ArticleLayout->alias;
88
+      }
89
+    }
88 90
 
89
-		return parent::generate($blnNoMarkup);
90
-	}
91
+    return parent::generate($blnNoMarkup);
92
+  }
91 93
 }