From: olivier <> Date: Mon, 13 Apr 2009 13:11:33 +0000 (+0000) Subject: eztelemeta: only load the player js and css deps if needed X-Git-Tag: 1.1~676 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=a7aca3825b3814365c46e11cf9234602cb60f759;p=telemeta.git eztelemeta: only load the player js and css deps if needed --- 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)}