[Phpslash-devel] Block, html, and general frustration
Brought to you by:
joestewart,
nhruby
From: Mike G. <mi...@op...> - 2003-12-02 22:35:43
|
Hello, I posted a problem to the BE development list and I believe I have now found the solution to this problem (after posting this). I'm hoping that it might get integrated into PSL (so I'm posting it to the PSL dev list too) I was looking for ideas on how to make the images in the html block in the default install of BE here show up properly: http://www.opensourcecms.com/back-end/ I was trying to add {IMAGEDIR} to this block so I could add sample html that could easily install in a sub-directory (or the root directory) of a site. What I realized is that part of the problem was that the html blocks were being updated in places other than the admin screen. Then it occurred to me that the only place that should be updating the html block should be the admin screen so my problem was simplified by adding a check I added a check for the html type to BE_Block.class's function storeParsed. If something other than the admin function attempts to update the cache of the html block it will return empty (which should save a db call on every html block which is parsed while visiting the site). There needed to be a check to convert the admin DATA to html entities so that it would be visible and editable, so I added the code to convert ('{', '}', '"', '<', '>') to ('{', '}', '"', '<', '>'). Finally, there was some conversion to allow. The cached data to be displayed properly on the page with the proper conversions str_replace is quite resource efficient and this shouldn't be a significantly enhanced load for the db to handle. It could also be expanded to allow other template variables to be added as block options. I'd like to get feedback on this to see if there are problems adding it to the BE code and possibility Mike [mike@office be7]$ cvs diff class/BE_Block.class class/BE_Block_admin.class class/Block_render_html.class Index: class/BE_Block.class =================================================================== RCS file: /cvsroot/back-end/back-end0.7.x/class/BE_Block.class,v retrieving revision 1.3 diff -r1.3 BE_Block.class 636c636,641 < --- > > // html blocks don't need to have their cache refreshed > if ($this->block_info['type_id'] == 1) { > return false; > } > Index: class/BE_Block_admin.class =================================================================== RCS file: /cvsroot/back-end/back-end0.7.x/class/BE_Block_admin.class,v retrieving revision 1.3 diff -r1.3 BE_Block_admin.class 229c229,240 < --- > > if ($this->block_info['type_id'] == 1) { > // Allow for template variables to be edited > $cacheData = str_replace(array('{', '}', '"', '<', '>'), array('{', '}', '"', '<', '>'), $this->block_info['cache_data']); > > } else { > $cacheData = $this->block_info['cache_data']; > } > 233c244 < 'BLOCK_TITLE' => $this->block_info["title"], --- > 'BLOCK_TITLE' => $this->block_info["title"], 237c248 < 'CACHE_DATA' => $this->block_info["cache_data"], --- > 'CACHE_DATA' => $cacheData, Index: class/Block_render_html.class =================================================================== RCS file: /cvsroot/back-end/back-end0.7.x/class/Block_render_html.class,v retrieving revision 1.2 diff -r1.2 Block_render_html.class 26,43c26,43 < < $this->output = $block_info["cache_data"]; < return 1; < < /* < $sl_q = pslNew("slashDB"); < $query = "SELECT cache_data < FROM psl_block < WHERE id = " . $block_info["id"]; < $sl_q->query($query); < if ($sl_q->next_record()) { < $this->output = $sl_q->f("cache_data"); < return 1; < } else { < return 0; < } < unset($db); < */ --- > > if ($_PSL['phpself'] == '/admin/blockAdmin.php') { > > // Return unmodified cache_data for edit mode > > $this->output = $block_info['cache_data']; > > } else { > > global $_PSL; > > // Parse critical template variables > $templateVariables = array('{ROOTDIR}', '{ROOTURL}', '{ABSOLUTEURL}', '{IMAGEDIR}', '{IMAGEURL}'); > $publicValues = array($_PSL['rootdir'], $_PSL['rootdir'], $_PSL['absoluteurl'], $_PSL['imageurl'], $_PSL['imageurl'], ); > $cleanedHTML = str_replace($templateVariables, $publicValues, $block_info['cache_data']); > $this->output = $cleanedHTML; > > } -- Mike Gifford, OpenConcept Consulting Free Software for Social Change -> http://www.openconcept.ca Stop Cdn Pension Plan War Investments -> http://coat.openconcept.ca/ Another world is not only possible, she is on her way -Arundhati Roy |