ImagelistTV and Modx Update
When updating modx, remember to copy over the imagelist.php file that's in this folder: \core\model\modx\processors\element\tv\renders\mgr\input
Upgrade documentation only mentions keeping core/config and core/packages. This shouldn't be an issue if you are not removing the core folder before you upgrade.
Modx, imagelistTV and the disabled save button
The imagelistTV is a great way to have a per page gallery in Modx Revolution.
However there was one problem with it. The save button would not refresh when anything was changed (images added, text updated etc) for this custom TV.
So I added a line of code at line 14 of imagelist.tpl :
Ext.getCmp('modx-panel-resource').markDirty();
now whenever the imagelist TV is present, the content is automatically "dirty".
the other issue I had with it earlier was that I could not get just one image. Rather than having to upload a separate image for a different TV, I've modified the snippet to allow a limit attribute:
/** * getImageList * * Copyright 2009-2010 by Bruno Perner * * getImageList is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 2 of the License, or (at your option) any * later version. * * getImageList 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 the GNU General Public License along with * FormIt; if not, write to the Free Software Foundation, Inc., 59 Temple Place, * Suite 330, Boston, MA 02111-1307 USA * * @package imageListTv */ /** * getImageList * * get Images from TV with custom-input-type imageList for MODx Revolution 2.0. * * @version 1.0a * @author Bruno Perner * @copyright Copyright © 2009-2010 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License * version 2 or (at your option) any later version. * @package imageListTv */ /*example:
-
" />
`]]
Google Analytics for Modx Revolution
I've posted this on the modx forum aswell but here it goes.
This plugin lets you enter the google analytics code to your pages in modx.
1. create a plugin and check "OnWebPagePrerender" and enter this code
2. in the properties assign your google code to 'code'
I know it's very crude, but to those who don't care it might work just fine
the way it works is by replacing </html> tag with the analytics code plus the </html> html
so if there is no closing html tag, there will be no analytics code
I wanted to add the ability to prevent a loged in user (editor/manager) from generating hits, but couldn't get it to work, so I gave up, I haven't tested it again with the newest release.
<?php
/* Handle event */ if ($modx->event->name === 'OnWebPagePrerender') { $jscode = "<script type='text/javascript'> var _gaq = _gaq || []; _gaq.push(['_setAccount','".$scriptProperties['code']."']); _gaq.push(['_trackPageview']);
(function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> </html><!-- $isLoggedIn -->" ; $output = &$modx->resource->_output; $modx->resource->_output= str_replace("</html>",$jscode,$output);
}
modx page errors with split()
From one day to another, two of my modx sites went down. This is around the same time I found out about the phpThumb vulnerability, so I assumed the worst (mostly because after I disabled the phpThumb plugin on one of the sites it looked like it was working) So I did the fi and looked for what could have caused this problem. I went through all the files through the ftp server, and looked through the database. Finally what gave it away was when I was editing a resource, I had a bunch of backslashes multiplying. At first I thought this was the malitious code inerted through the exploit. Looking into this further, I found through phpinfo that the magic quotes were turned on. Modx turns these off automatically, as long as the php version is less than 5.3. The I looked at the build date in phpinfo and found that this was a very new build. That means that the host snuck up on me with an upgrade, without disabling the magic quotes. As far as the pages not rendering goes, that was my bad - I should have used explode instead of split.
So if you are looking for a host with lot's of features and crazy adventures(this is not the first time) that can take up a full day, look no further than http://www.green-light.ca/
eForm data passing in modx
I've spent a lot of time on this issue...
Let's say you have a restricted area on your modx site and an eForm inside there.
And that efrom has only one field that will be emailed to the admin. But in the email you want to display the username.
Seems like this would be simple but simply referencing [+name+] is looking for a field whose name is name. I couldn't have used a hidden input field, because it wasn't parsing [+name+].
So after spending a lot of time of wrestle my variable in there, I've realized what the simplest way to do it is.
The trick is to create a chunk that has the value inside it, that way it is parsed inside the chunk, and doesn't interfere with eForm template.
it's a lot simpler than dealing with eFormOnBeforeFormParse
ParseImages snippet for modx
This modX snippet will grab all the images from a set folder and display them in a chunk
/*
::::::::::::::::::::::::::::::::::::::::
Snippet name: ParseImages
Description:
parses images in &folder in chunk &tpl
::::::::::::::::::::::::::::::::::::::::
Usage:
[!ParseImages? &tpl=`myChunk_tpl` &folder='assets/images/folder'!]
*/
// $folder;
// $tpl;
$output = "";
$filesArray = Array();
$imgDir = opendir ($folder);
while ( $file = readdir( $imgDir ) )
{
//checks that file is an image
$file_type = strrchr( $file, "." );
$is_image = eregi( "jpg|gif|png",$file_type );
if ( $file != '.' && $file != '..' && $is_image )
{
array_push($filesArray,$file);
}
}
rsort($filesArray);
foreach ($filesArray as &$fn) {
// set the placeholder
$params['image']=$modx->config['site_url'].$folder.$fn;
$params['imagefilename']=$fn;
// Parse the chunk
$output .= $modx->parseDocumentSource($modx->parseChunk($tpl, $params, '[+', '+]'));
}
closedir ($imgDir);
return $output;
Ditto iteration start at 1
(modx 1.0.2)
By default the ditto.2 iteration starts at 0,
to have it start at 1 use
[+ditto_iteration:math=`?+1`+]
assuming you have PHx installed, nd you should, this will work,
also use "ditto_iteration" not "iteration", this little ooopsies cost me a bit of time
Just started using PHx in modx, and I'm pretty excited about it.