I completely agree with that. This should be revisited in the future and implemented properly.
It means by end Sunday, or basically within 34 hours of the datestamp of this post, so an internal RC on Monday would be ace.
The template switcher - personally I think it’s a confusing feature. I believe that the intention is that it’s per visitor, but it doesn’t work with caching at all, which is why there was the "disable caching" plugin. Personally I feel the clearer solution is to take out the template switcher and just have a page for each example template.
The reason it says ’Close’ and not ’Cancel’ is that there are parts of the Doc Manager where ’Cancel’ would indicate going back a step (ie. when sorting the menu) and not exiting the module. And, going back to ’Manage Modules’ page is consistent with such processes such as editing a snippet or plugin and being returned to the ’Manage Resources’ page.
I don’t actually understand what the point of "Close Doc Manager" is. No other screen has this, although they do have "Cancel". In other screens, "Cancel" takes you to home/welcome page (although Polls Module goes to the Manage Modules screen). So, it would seem that the most consistent thing is "Cancel" > home/welcome.Fair enough and convinced. Let’s make it consistent across the board though... and remove the close button if possible (but there may be a reason for it?).
If there were cache files present, yes, the plugin would need to nuke ’em before running. But, from what I can tell, in all instances of this plugin running there are no pageCache files that need nuking - if running after an install, the cache is regenerated meaning there would be no pageCache files and if manually activating at a later date, then the cache is cleared on the plugin changes being saved.
Yes, setting the "cacheable" to 0 is necessary to keep a cache file with this template from being saved, but it also needs to delete any existing cache files for this document before the parser goes looking for it.
// TemplateSwitcher - plugin for MODx // [email protected] // released to the Public Domain // uses OnLoadWebDocument event // stores template choice in cookie // add the usecookie argument to the Configuration // &usecookie=Use Cookie;list;no,yes;no // default is 'no' // set Configuration to 'yes' to use cookie // place an HTML comment <!-- donotswitch --> in the content of pages you don't want switched // add template=templatename to the URL if (!function_exists('clearDocCache')) { function clearDocCache($docId) { global $modx; $basepath = $modx->config["base_path"] . "assets/cache"; if (@ $handle = opendir($basepath)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if (preg_match("/docid_" . $docId . "\.pageCache\.php/", $file)) { unlink($basepath . "/" . $file); } } } closedir($handle); return true; } else { return false; } } } // Get a reference to the event $e = & $modx->Event; // Event Actions switch ($e->name) { case 'OnWebPageInit' : clearDocCache($modx->documentIdentifier); break; case 'OnLoadWebDocument' : if (!strstr($modx->documentContent, "donotswitch")) { // this page is not switchable $modx->documentObject['cacheable'] = 0; if (isset ($_GET['template'])) { $overrideTemplate = $_GET['template']; } else if (isset ($_COOKIE['template']) && $usecookie == 'yes') { $overrideTemplate = $_COOKIE['template']; } if (isset ($overrideTemplate)) { $table = $modx->getFullTableName("site_templates"); $result = $modx->db->select("id, content", $table, "templatename = '" . $overrideTemplate . "'"); if ($modx->db->getRecordCount($result) == 1) { $row = $modx->db->getRow($result); $modx->documentObject['template'] = $row['id']; $modx->documentContent = $row['content']; } else { $this->messageQuit("Error retrieving template."); } if ($usecookie == 'yes') { setcookie("template", $overrideTemplate, time() + 604800, "/", "", 0); } } } // end if page is switchable break; default : break; }
Quote from: rthrash at Oct 28, 2006, 08:28 AMThe reason it says ’Close’ and not ’Cancel’ is that there are parts of the Doc Manager where ’Cancel’ would indicate going back a step (ie. when sorting the menu) and not exiting the module. And, going back to ’Manage Modules’ page is consistent with such processes such as editing a snippet or plugin and being returned to the ’Manage Resources’ page.
I don’t actually understand what the point of "Close Doc Manager" is. No other screen has this, although they do have "Cancel". In other screens, "Cancel" takes you to home/welcome page (although Polls Module goes to the Manage Modules screen). So, it would seem that the most consistent thing is "Cancel" > home/welcome.Fair enough and convinced. Let’s make it consistent across the board though... and remove the close button if possible (but there may be a reason for it?).
Feel free to make the change but I’m not convinced and won’t be making the change myself.
Here’s a couple of ideas of how we can proceed with making a proper template switcher without any changes to the core, in current or development versions...
Getting template switching to work would be very very cool. This is a very MODx thing. It would also make it easier to have a parallel mobile/PSP/webTV site from the same document data.
But the caching is also crucial to MODx. So... simple idea.. don’t know how easy it is to code, but it seems the logical solution:
Change the caching to save out on a per-document AND per-template basis. Parser looks for a cached version of that document/template combination; if it’s there, uses it, if it’s not, parses and saves. Simple. Logical. What people might expect. I can’t really see any point expending energy on any bundled solution that isn’t this.
(I know that’s a fairly major change to the core, but it would open up a few things, not least simplifying my upcoming PDF plugin).
This discussion is closed to further replies. Keep calm and carry on.