From a7aca3825b3814365c46e11cf9234602cb60f759 Mon Sep 17 00:00:00 2001 From: olivier <> Date: Mon, 13 Apr 2009 13:11:33 +0000 Subject: [PATCH] eztelemeta: only load the player js and css deps if needed --- tools/eztelemeta/autoloads/eztelemetadata.php | 143 ++++++++++++++++++ .../autoloads/eztemplateautoload.php | 31 ++++ .../templates/embed/eztelemetaitem.tpl | 4 +- .../standard/templates/eztelemeta_head.tpl | 26 ++++ tools/eztelemeta/settings/design.ini.append | 8 - tools/eztelemeta/settings/site.ini.append | 3 + 6 files changed, 204 insertions(+), 11 deletions(-) create mode 100644 tools/eztelemeta/autoloads/eztelemetadata.php create mode 100644 tools/eztelemeta/autoloads/eztemplateautoload.php create mode 100644 tools/eztelemeta/design/standard/templates/eztelemeta_head.tpl create mode 100644 tools/eztelemeta/settings/site.ini.append diff --git a/tools/eztelemeta/autoloads/eztelemetadata.php b/tools/eztelemeta/autoloads/eztelemetadata.php new file mode 100644 index 00000000..bc3fec02 --- /dev/null +++ b/tools/eztelemeta/autoloads/eztelemetadata.php @@ -0,0 +1,143 @@ + +// +// ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## +// SOFTWARE NAME: eZ Publish Website Interface +// SOFTWARE RELEASE: 1.4-0 +// COPYRIGHT NOTICE: Copyright (C) 1999-2009 eZ Systems AS +// SOFTWARE LICENSE: GNU General Public License v2.0 +// NOTICE: > +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2.0 of the GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of version 2.0 of the GNU General +// Public License along with this program; if not, write to the Free +// Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +// MA 02110-1301, USA. +// +// +// ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## +// + +/* + Template operator to speed up page settings and style init time + Gets its parameters directly from template. + module_result.path | content_info | persistant_variable | menu.ini ++ + are all used to generate page data, what menues to show + and so on. + +*/ + +class eZTelemetaData +{ + function eZTelemetaData() + { + } + + function operatorList() + { + return array( 'eztelemetadata_set', 'eztelemetadata_append' ); + } + + function namedParameterPerOperator() + { + return true; + } + + function namedParameterList() + { + return array( 'eztelemetadata_set' => array( + 'key' => array( 'type' => 'string', + 'required' => true, + 'default' => false ), + 'value' => array( 'type' => 'mixed', + 'required' => true, + 'default' => false ) ), + 'eztelemetadata_append' => array( + 'key' => array( 'type' => 'string', + 'required' => true, + 'default' => false ), + 'value' => array( 'type' => 'mixed', + 'required' => true, + 'default' => false ) ) ); + } + + function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters ) + { + switch ( $operatorName ) + { + // note: these functions are not cache-block safe + // as in: if called inside a cache-block then they will not be called when cache is used. + case 'eztelemetadata_set': + case 'eztelemetadata_append': + { + self::setPersistentVariable( $namedParameters['key'], $namedParameters['value'], $tpl, $operatorName === 'eztelemetadata_append' ); + }break; + } + } + + // reusable function for setting persistent_variable + static public function setPersistentVariable( $key, $value, $tpl, $append = false ) + { + $persistentVariable = array(); + if ( $tpl->hasVariable('persistent_variable') && is_array( $tpl->variable('persistent_variable') ) ) + { + $persistentVariable = $tpl->variable('persistent_variable'); + } + else if ( self::$persistentVariable !== null && is_array( self::$persistentVariable ) ) + { + $persistentVariable = self::$persistentVariable; + } + + if ( $append ) + { + if ( isset( $persistentVariable[ $key ] ) && is_array( $persistentVariable[ $key ] ) ) + { + $persistentVariable[ $key ][] = $value; + } + else + { + $persistentVariable[ $key ] = array( $value ); + } + } + else + { + $persistentVariable[ $key ] = $value; + } + + // set the finnished array in the template + $tpl->setVariable('persistent_variable', $persistentVariable); + + // storing the value internally as well in case this is not a view that supports persistent_variable (eztelemetadata will look for it) + self::$persistentVariable = $persistentVariable; + } + + // reusable function for getting persistent_variable + static public function getPersistentVariable( $key = null ) + { + if ( $key !== null ) + { + if ( isset( self::$persistentVariable[ $key ] ) ) + return self::$persistentVariable[ $key ]; + return null; + } + return self::$persistentVariable; + } + + // Internal version of the $persistent_variable used on view that don't support it + static protected $persistentVariable = null; + +} + +?> diff --git a/tools/eztelemeta/autoloads/eztemplateautoload.php b/tools/eztelemeta/autoloads/eztemplateautoload.php new file mode 100644 index 00000000..b222f886 --- /dev/null +++ b/tools/eztelemeta/autoloads/eztemplateautoload.php @@ -0,0 +1,31 @@ + +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2.0 of the GNU General +// Public License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of version 2.0 of the GNU General +// Public License along with this program; if not, write to the Free +// Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +// MA 02110-1301, USA. +// +// +// ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## +// + +$eZTemplateOperatorArray = array(); +$eZTemplateOperatorArray[] = array( 'script' => 'extension/eztelemeta/autoloads/eztelemetadata.php', + 'class' => 'eZTelemetaData', + 'operator_names' => array( 'eztelemetadata_set', 'eztelemetadata_append' ) ); +?> diff --git a/tools/eztelemeta/design/standard/override/templates/embed/eztelemetaitem.tpl b/tools/eztelemeta/design/standard/override/templates/embed/eztelemetaitem.tpl index a1cbabef..ee7b9067 100755 --- a/tools/eztelemeta/design/standard/override/templates/embed/eztelemetaitem.tpl +++ b/tools/eztelemeta/design/standard/override/templates/embed/eztelemetaitem.tpl @@ -1,6 +1,4 @@ - +{eztelemetadata_set('eztelemeta_player', true)}
{let attribute=$object.data_map.item} diff --git a/tools/eztelemeta/design/standard/templates/eztelemeta_head.tpl b/tools/eztelemeta/design/standard/templates/eztelemeta_head.tpl new file mode 100644 index 00000000..4aa0a406 --- /dev/null +++ b/tools/eztelemeta/design/standard/templates/eztelemeta_head.tpl @@ -0,0 +1,26 @@ +{if is_set( $module_result.content_info.persistent_variable.eztelemeta_player )} + + + + +{/if} diff --git a/tools/eztelemeta/settings/design.ini.append b/tools/eztelemeta/settings/design.ini.append index 4473da94..9243943a 100644 --- a/tools/eztelemeta/settings/design.ini.append +++ b/tools/eztelemeta/settings/design.ini.append @@ -1,11 +1,3 @@ [ExtensionSettings] DesignExtensions[]=eztelemeta -[StylesheetSettings] -CSSFileList[]=eztelemeta.css -CSSFileList[]=page-player.css - -[JavaScriptSettings] -JavaScriptList[]=soundmanager2.js -JavaScriptList[]=init.js -JavaScriptList[]=page-player.js diff --git a/tools/eztelemeta/settings/site.ini.append b/tools/eztelemeta/settings/site.ini.append new file mode 100644 index 00000000..d3394863 --- /dev/null +++ b/tools/eztelemeta/settings/site.ini.append @@ -0,0 +1,3 @@ +[TemplateSettings] +ExtensionAutoloadPath[]=eztelemeta + -- 2.39.5