Feature #13641: Use new TYPO3 4.3 hook for preview images in page module (Thanks...
authorlorenzulrich <lorenzulrich@735d13b6-9817-0410-8766-e36946ffe9aa>
Thu, 20 Jan 2011 16:41:01 +0000 (16:41 +0000)
committerlorenzulrich <lorenzulrich@735d13b6-9817-0410-8766-e36946ffe9aa>
Thu, 20 Jan 2011 16:41:01 +0000 (16:41 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Extensions/dam/dam_ttcontent/trunk@42381 735d13b6-9817-0410-8766-e36946ffe9aa

ChangeLog
ext_localconf.php
hooks/class.tx_damttcontent_tt_content_drawItem.php [new file with mode: 0644]

index 5a58682..097a867 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2011-01-20  Lorenz Ulrich <lorenz.ulrich@visol.ch>
+
+       * Feature #13641: Use new TYPO3 4.3 hook for preview images in page module (Thanks to Dmitry Dulepov)
+
 2011-01-12  Dan Osipov <dosipov@phillyburbs.com>
 
        * Fixed Bug #16349: Adapt dam_tt_content to the TCA changes in TYPO3 4.5 (Thanks Lorenz Ulrich)
index 4745099..e17ee85 100644 (file)
@@ -58,10 +58,7 @@ if ($GLOBALS['T3_VAR']['ext'][$_EXTKEY]['setup']['add_css_styled_hook']) {
 }
 
 
-if ($GLOBALS['T3_VAR']['ext'][$_EXTKEY]['setup']['add_page_mod_xclass']) {
-       $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/layout/class.tx_cms_layout.php'] = $PATH_damttcontent.'class.ux_tx_cms_layout.php';
-}
-
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'][$_EXTKEY] = $PATH_damttcontent . 'hooks/class.tx_damttcontent_tt_content_drawItem.php:tx_damttcontent_tt_content_drawItem';
 
 if ($GLOBALS['T3_VAR']['ext'][$_EXTKEY]['setup']['add_ws_mod_xclass']) {
 
diff --git a/hooks/class.tx_damttcontent_tt_content_drawItem.php b/hooks/class.tx_damttcontent_tt_content_drawItem.php
new file mode 100644 (file)
index 0000000..7cfb6b6
--- /dev/null
@@ -0,0 +1,104 @@
+<?php\r
+/***************************************************************\r
+*  Copyright notice\r
+*\r
+*  (c) 2010 snowflake gmbh <info@snowflake.ch>\r
+*  All rights reserved\r
+*\r
+*  This script is part of the Typo3 project. The Typo3 project is\r
+*  free software; you can redistribute it and/or modify\r
+*  it under the terms of the GNU General Public License as published by\r
+*  the Free Software Foundation; either version 2 of the License, or\r
+*  (at your option) any later version.\r
+*\r
+*  The GNU General Public License can be found at\r
+*  http://www.gnu.org/copyleft/gpl.html.\r
+*\r
+*  This script is distributed in the hope that it will be useful,\r
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*  GNU General Public License for more details.\r
+*\r
+*  This copyright notice MUST APPEAR in all copies of the script!\r
+***************************************************************/\r
+\r
+require_once(PATH_typo3 . 'sysext/cms/layout/interfaces/interface.tx_cms_layout_tt_content_drawitemhook.php');\r
+require_once(PATH_txdam . 'lib/class.tx_dam_image.php');\r
+require_once(PATH_txdam . 'lib/class.tx_dam_tcefunc.php');\r
+require_once(PATH_txdam . 'lib/class.tx_dam_guifunc.php');\r
+\r
+class tx_damttcontent_tt_content_drawItem implements tx_cms_layout_tt_content_drawItemHook  {\r
+\r
+       /**\r
+        * Preprocesses the preview rendering of a content element.\r
+        *\r
+        * @param       tx_cms_layout           $parentObject: Calling parent object\r
+        * @param       boolean                         $drawItem: Whether to draw the item using the default functionalities\r
+        * @param       string                          $headerContent: Header content\r
+        * @param       string                          $itemContent: Item content\r
+        * @param       array                           $row: Record row of tt_content\r
+        * @return      void\r
+        */\r
+       public function preProcess(tx_cms_layout &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row) {\r
+               if ($row['tx_damttcontent_files'])      {\r
+                       $config = &$GLOBALS['TCA']['tt_content']['columns']['tx_damttcontent_files']['config'];\r
+                       $record = $this->determineRecord($row);\r
+\r
+                       $damItems = tx_dam_db::getReferencedFiles('tt_content', $record['uid'], $config['MM_match_fields'], $config['MM'], 'tx_dam.*');\r
+                       if($damItems['rows']) {\r
+                               $itemContent = $this->renderDamItems($damItems['rows']);\r
+                       }\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Determine record to use. Current or workspace record?\r
+        *\r
+        * @param       array                   $row current tt_content record\r
+        * @return      array                   $record to use\r
+        */\r
+       protected function determineRecord(array $row) {\r
+               if ($GLOBALS['BE_USER']->workspace !== 0) {\r
+                       $workspaceRecord = t3lib_BEfunc::getWorkspaceVersionOfRecord(\r
+                               $GLOBALS['BE_USER']->workspace,\r
+                               'tt_content',\r
+                               intval($row['uid'])\r
+                       );\r
+\r
+                       if ($workspaceRecord) {\r
+                               $row = $workspaceRecord;\r
+                       }\r
+               }\r
+\r
+               return $row;\r
+       }\r
+\r
+       /**\r
+        * Creates thumbnail of dam items\r
+        *\r
+        * @param       array                   $row current tt_content record\r
+        * @return      string                  html of thumbnails\r
+        */\r
+       protected function renderDamItems(array $damItems) {\r
+               $itemContent = '';\r
+\r
+               foreach ($damItems as $damItem) {\r
+                       $caption = tx_dam_guiFunc::meta_compileInfoData($damItem, '_caption:truncate:100', 'value-string');\r
+\r
+                       $thumb = tx_dam_guiFunc::thumbnail($damItem);\r
+\r
+                       $thumb = '<div style="float:left;width:56px;overflow:auto;margin:2px 5px 2px 0" title="' .\r
+                               htmlspecialchars($caption) .\r
+                               '">'.$thumb.'</div>';\r
+\r
+                       $itemContent.= $thumb;\r
+               }\r
+\r
+               if ($itemContent != '') {\r
+                       $itemContent = '<div style="clear:left;overflow:hidden">' . $itemContent . '</div>';\r
+               }\r
+\r
+               return $itemContent;\r
+       }\r
+}\r
+?>\r