Forums / Developer / Contrib : str_replace template operator

Contrib : str_replace template operator

Author Message

Lex 007

Friday 22 April 2005 3:39:56 am

Hi everyone,

Since I didn't find any str_replace template operator (maybe I didn't look right??), I just programmed a small extension for it. Very easy and very usefull (it took me more time to write this topic than programm it lol)

1/ Go to your "extension" folder in your eZ Publish install

2/ Create file str_replace/autoloads/eztemplateautoload.php

<?php

// Operator autoloading

$eZTemplateOperatorArray = array();

$eZTemplateOperatorArray[] =
  array( 'script' => 'extension/str_replace/autoloads/str_replace_controloperator.php',
         'class' => 'MyStrReplaceOperator',
         'operator_names' => array( 'ezstr_replace' ) );

?>

3/ Create file str_replace/autoloads/str_replace_controloperator.php

<?php

class MyStrReplaceOperator
{
    /*!
     Constructor
    */
    function MyStrReplaceOperator()
    {
        $this->Operators = array( 'ezstr_replace');
    }

    /*!
     Returns the operators in this class.
    */
    function &operatorList()
    {
        return $this->Operators;
    }

    /*!
     \return true to tell the template engine that the parameter list
    exists per operator type, this is needed for operator classes
    that have multiple operators.
    */
    function namedParameterPerOperator()
    {
        return true;
    }

    /*!
     The first operator has two parameters, the other has none.
     See eZTemplateOperator::namedParameterList()
    */
    function namedParameterList()
    {
        return array(                      
                      'ezstr_replace' => array('search' => array( 'type' => 'string',
                                                                     'required' => true,
                                                                     'default' => '' ),
                                                'replace' => array( 'type' => 'string',
                                                                     'required' => true,
                                                                     'default' => '' ),
                                                'subject' => array( 'type' => 'string',
                                                                     'required' => true,
                                                                     'default' => '' )
                                            ) );
    }

    /*!
     Executes the needed operator(s).
     Checks operator names, and calls the appropriate functions.
    */
    function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace,
                     &$currentNamespace, &$operatorValue, &$namedParameters )
    {
        switch ( $operatorName )
        {
            case 'ezstr_replace':
            {
                $operatorValue = $this->ezstr_replace( $namedParameters['search'], 
                                                        $namedParameters['replace'], 
                                                        $namedParameters['subject']);
            } break;
        }
    }

    function ezstr_replace( $search, $replace, $subject  )
    { 
        return str_replace( $search, $replace, $subject  );
    }

    /// \privatesection
    var $Operators;
}

?>

4/ Create file str_replace/settings/site.ini.append.php

<?php

[TemplateSettings]
ExtensionAutoloadPath[]=str_replace

?>

5/ Activate the extension in the admin interface

6/ To use it in a template :

{ezstr_replace($search,$replace,$subject)}

Enjoy !

Bruce Morrison

Friday 22 April 2005 8:40:30 pm

This would be good to include in the core distribution!

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

kracker (the)

Friday 22 April 2005 10:49:30 pm

Lex,

Would you package up your operator as an eZ publish extension (packaged in an either zip or tar.gz) and upload it into the contributions section as a new project?

And if your interested in making your operator available for consideration into eZ publish you would want to be sure to clearly assign copyright to eZ systems.

More information on this subject is available on the "Contributing Code" Section (Towards the Bottom, <i>boy, I sure wish more ez.no's content had hidden anchors for direct linking to core information and subjects</i>)
http://ez.no/community/developer/contributing

cheers,
//kracker

sole : selling live water : Respect Pt. 3

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

Lex 007

Monday 25 April 2005 6:36:37 am

OK, why not !
How to you make a *.ezpkg from an extension ?

kracker (the)

Monday 25 April 2005 6:46:29 am

right on,

sorry for the confusion, i don't think you can create an extension as an eZ package. I guess the next best alternative is a documented (zip/tar.gz package).

//kracker
what was I thinking?

<i>counting crows : hey monkey, where you been?</i>

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

Lex 007

Tuesday 26 April 2005 1:52:30 am

That's right ! I'll try to published it soon then.

Lex 007

Wednesday 27 April 2005 8:17:53 am

I've uploaded the files to : http://ez.no/community/contribs/template_plugins/string_replace_operator

Please report any bug.

eZ debug

Timing: Jan 18 2025 18:30:32
Script start
Timing: Jan 18 2025 18:30:32
Module start 'content'
Timing: Jan 18 2025 18:30:33
Module end 'content'
Timing: Jan 18 2025 18:30:34
Script end

Main resources:

Total runtime1.4971 sec
Peak memory usage4,096.0000 KB
Database Queries208

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0075 587.7344180.8281
Module start 'content' 0.00751.3217 768.5625656.5078
Module end 'content' 1.32920.1679 1,425.0703345.0859
Script end 1.4970  1,770.1563 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00450.2991210.0002
Check MTime0.00150.0995210.0001
Mysql Total
Database connection0.00090.060610.0009
Mysqli_queries1.396993.30742080.0067
Looping result0.00300.20212060.0000
Template Total1.466297.920.7331
Template load0.00210.141120.0011
Template processing1.464197.795020.7320
Template load and register function0.00010.006910.0001
states
state_id_array0.00110.074610.0011
state_identifier_array0.00080.055820.0004
Override
Cache load0.00190.1270480.0000
Sytem overhead
Fetch class attribute can translate value0.00170.115640.0004
Fetch class attribute name0.00130.0900100.0001
XML
Image XML parsing0.00200.130840.0005
class_abstraction
Instantiating content class attribute0.00000.0019140.0000
General
dbfile0.00200.1323410.0000
String conversion0.00000.000430.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
7content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
14content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
4content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 38
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs