We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1113
    • 11 Posts
    Hello everyone!
    I have a serious problems with Ditto snippet.
    Now I’m working on site with catalog of places for children and their parents.
    I’m using Ditto to display pages. Every page is a MODx resource with TV-params:
    adrtype - type of address - street, square, avenue, etc. (DropDown List menu, possible values are "Street||Square||Avenue||.....", default value is "Street");
    bld - building # (text);
    city - city name (text, default value is "Moscow");
    country - country name (DropDown List menu, possible values are "Russia||Ukraine", default value is "Russia");
    email - object’s official e-mail address (text);
    img1 - photo 1 (image);
    img2 - photo 2 (image);
    lat - lattitude for Google Maps (text);
    lng - lengtitude for Google Maps (text);
    phone - phone number (text);
    placetype - type of place - cinema, aquapark, restaurant, etc. (DropDown List menu, possible values are "any type||Aquapark||......", default value is "any type");
    strName - street/square/avenue/... name (text);
    www - Website URL (text).

    Ditto is called from my own snippet. The call contains &filter field:
    $filter="country,$country,1|city,$city,1";
    if($adrstreet!="") $filter.="|strName,$adrstreet,1";
    if($adrtype!="") $filter.="|adrtype,$adrtype,1";
    if($bld!="") $filter.="|bld,$bld,1";
    if($placetype!="") $filter.="|placetype,$placetype,1";
    $out=$modx->runSnippet("Ditto",array("tpl"=>"placesRow",
    					"filter"=>$filter,
    					"startID"=>$places_root_page,
    					"display"=>"all",
    					"noResults"=>"<h2>Nothing was found :(...</h2>"
    					));
    


    New places (i.e. new resources) are being added by web-users using docManager (document.class.php). TVs are also added in this way.
    THE PROBLEM IS that I can add ONLY ONE place for every city. When the next place is added to resources tree via my docManager call, the page with Ditto crashes.
    Fatal error: Cannot redeclare inputclean() (previously declared in Z:\home\r0\www\manager\includes\document.parser.class.inc.php(814) : eval()'d code:34) in Z:\home\r0\www\manager\includes\document.parser.class.inc.php(814) : eval()'d code on line 57
    
    (By the way, what the hell does inputclean() have to my snippet???)
    If I try to set last added place to unpublished or deleted (via phpMyAdmin, setting published or deleted field to zero) - everything works fine.

    MODx info:
    MODx Evolution 1.0.5 @ Apache(WIN7)+PHP5.2+MySQL5 (Denwer v.3)
    • A function "inputclean" doesn’t appear to be in any of the default MODx codebase, nor is it part of the docmanager.class.php. What other custom snippets or plugins are you using that might have this function? The error indicates that it is part of a snippet or plugin. Are you using a snippet or TV with @EVAL in the Ditto tpl?
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 1113
        • 11 Posts
        No, @EVALed statements are not used in TVs or Ditto TPLs.
        It looks like I found the reason.
        But first I must say that not only "Cannot redeclare inputclean()" error occurs. My snippet is also used for resource editing and when more than one place per city added to resource tree this part (editor) also crashes. But this time error is "Fatal error. Cannot redeclare showLargeForm()". showLargeForm is a function that declared inside my snippet. And I cannot understand what’s going on? why my snippet is being called more than one time? I’ve crawled my code byte by byte and did not found no places where re-declaration may occur.
        Back to the first error, I have found inputclean() function in my other snippet - custom comment system (in some way similar to Jot, but much more simple). And I don’t think of anything more clever than just close conflict functions with "function_exists()".
        if(!function_exists("inputclean"))
        {
        	function inputclean($txt)
        	{
        		.........
        	};
        };
        

        Stupid method, I know... but it works fine.
        And now I have another question: could it be possible that Ditto processes page with ALL snippet calls on it? Because my commentIt snippet is being called inside the template assigned to "place"-pages. So every time Ditto processes the query it returns pages and the same snippet runs for many-many times. Sorry if my question is too foolish...