t3blog - how to clear cache when user writes comment? - typo3

When a user writes a comment then it doesn't become visible right away. It becomes visible if I clear the cache manually.
Usually t3blog stores posts and comments within the t3blog page itself and then one should be able to clear the cache this way.
TCEMAIN.clearCacheCmd = all
However in my t3blog setup the posts and comments are in a separate sysfolder. Here is the setup typoscript
plugin.tx_t3blog_pi1.blogPid = 21
Is there a way I can trigger clear cache when the user submits a new comment?

I have unsuccessfully tried installing an 'aftercommentinsertion' hook.
Finally I solved it by modifying t3blog itself, so that you can specify the uid of the pages that needs to be cleared via typoscript.
# my typoscript code
plugin.tx_t3blog_pi1.blogList {
# clear these pages when a visitor writes a new comment to a post
clearCacheForPIDsAfterCommentInsertion = 1,6,8,24
}
// the file: t3blog/pi1/widgets/blogList/class.singleFunctions.php
protected function insertNewComment(array $data) {
$data['pid'] = t3blog_div::getBlogPid();
$data['date'] = $data['crdate'] = $GLOBALS['EXEC_TIME'];
$GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_t3blog_com', $data);
$commendId = $GLOBALS['TYPO3_DB']->sql_insert_id();
$this->updateRefIndex('tx_t3blog_com', $commentId);
// Hook after comment insertion
if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3blog']['aftercommentinsertion'])) {
foreach($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3blog']['aftercommentinsertion'] as $userFunc) {
$params = array(
'data' => &$data,
'table' => 'tx_t3blog_com',
'postUid' => $data['fk_post'],
'commentUid' => $commendId,
);
t3lib_div::callUserFunction($userFunc, $params, $this);
}
}
// ******************* MY CLEAR CACHE CODE *******************
error_log("t3blog inserted new comment");
$pids = $this->conf['clearCacheForPIDsAfterCommentInsertion'];
$pidArray = is_string($pids) ? t3lib_div::trimExplode(',', $pids, 1) : NULL;
error_log("t3blog clearCacheForPIDsAfterCommentInsertion: ".$pids." -- ".print_r($pidArray, true));
if(is_array($pidArray)) {
$tce = t3lib_div::makeInstance('t3lib_TCEmain');
foreach($pidArray as $pid) {
error_log("t3blog clear_cacheCmd: ".$pid);
$tce->clear_cacheCmd((int)$pid);
}
}
}
I have sendt this code to Dmitry Dulepov (the author of t3blog).

You can add this line in your PAGE TS of the sysfolder (uid=21) holding your blog post:
TCEMAIN.clearCacheCmd = 1,6,8,24
That line will tell that new blog posts shall trigger a clear cache of that exact list of pages. I think your users will need rights to clear cache though...
Reason it goes into the PAGE TS of you sysfolder and not one or all of the pages where your blog is inserted is that... they are (probably) all cached. Your sysfolder is not cached and the new record will be noticed by TYPO3 and tricker a clear cache of the cached pages you just defined by your comma separated string.

Did you try to include the clearCacheCmd in the page TSconfig of the sysfolder where the comments are stored? You can use "all", "pages" or the relevant page uids, cf: http://typo3.org/documentation/document-library/core-documentation/doc_core_tsconfig/4.3.2/view/1/5/#id2505694
This should work if the "user" is a backend user with the relevant priveleges - but I guess, when you say "a user writes a comment", it is a front end user you are talking about, and then this will probably not be of much help.
The solution then would be to have the extension clear the cache upon receiving a comment. This might not be possible for you to do, but the quick fix to this is to mark the page as not cacheable ("Disable cache", Behavior tab). Beware, though, this will cause your server to suffer.

Related

Editing Typo3 CMS front-end page

I get a project that used TYPO3 CMS, the task is quite simple, adding cookie usage notice on the header part of the website.
I never working on TYPO3 before, but already reading the documentation. Somehow I can't figure out which file to edit. even the documentation tutorial and file structure is different than the project I handle.
I don't have any project documentation for the project either, and I don't want to ask you to do my task, but I'm blank at the moment and don't know where to find the respective file needed.
Any suggestion or clue how to handle the issue?
my index.php on root folder look like this:
if (defined('E_DEPRECATED')) {
error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
} else {
error_reporting(E_ALL ^ E_NOTICE);
}
// ******************
// Constants defined
// ******************
define('PATH_thisScript', str_replace('//', '/', str_replace('\\', '/',
(PHP_SAPI == 'fpm-fcgi' || PHP_SAPI == 'cgi' || PHP_SAPI == 'isapi' || PHP_SAPI == 'cgi-fcgi') &&
($_SERVER['ORIG_PATH_TRANSLATED'] ? $_SERVER['ORIG_PATH_TRANSLATED'] : $_SERVER['PATH_TRANSLATED']) ?
($_SERVER['ORIG_PATH_TRANSLATED'] ? $_SERVER['ORIG_PATH_TRANSLATED'] : $_SERVER['PATH_TRANSLATED']) :
($_SERVER['ORIG_SCRIPT_FILENAME'] ? $_SERVER['ORIG_SCRIPT_FILENAME'] : $_SERVER['SCRIPT_FILENAME']))));
define('PATH_site', dirname(PATH_thisScript).'/');
if (#is_dir(PATH_site.'typo3/sysext/cms/tslib/')) {
define('PATH_tslib', PATH_site.'typo3/sysext/cms/tslib/');
} elseif (#is_dir(PATH_site.'tslib/')) {
define('PATH_tslib', PATH_site.'tslib/');
} else {
// define path to tslib/ here:
$configured_tslib_path = '';
// example:
// $configured_tslib_path = '/var/www/mysite/typo3/sysext/cms/tslib/';
define('PATH_tslib', $configured_tslib_path);
}
if (PATH_tslib=='') {
die('Cannot find tslib/. Please set path by defining $configured_tslib_path in ' . htmlspecialchars(basename(PATH_thisScript)) . '.');
}
// ******************
// include TSFE
// ******************
require (PATH_tslib.'index_ts.php');
edit: adding screenshot of the interface suggested by #Riccardo (typo3 ver 4.4.4)
Which version of TYPO3 are you running? As Bernd wrote, it is difficult to help you without further information.... I'll try to explain the first passages where you could gather some infos.
1) Access TYPO3 backend with a user with administrative privileges
2) Try to identify the main TypoScript template with this procedure:
click on template (1)
click on the "zero" page with the TYPO3 symbol (2)
you should see on the right a list of the TypoScript templates (3),
click on the one that is marked as "is Root"
2) After that, click on the first dropdown on the right area (with the "info/modify" item and select "TypoScript Object Browser" (a.k.a. TSOB)
3) After you have done that, you should see a "tree" that represents the TypoScript configuration;
be sure to have "setup" selected (1)
search for the object that builds your page, which should most likely be page = PAGE (2)
[answer edited]
I'm afraid I'll have to ask for a survey supplement
Can you identify in which part of the various objects the header of your site is rendered? My suspects would be focused on the [home2] or the [outer_frameset] object;
Hoping that they will contain the usual array with something like:
home2.10 = something
I think that the quickiest (and dirtiest) way to append something before the whole page would be something like
home2.1 = TEXT
home2.1.value = <div>whatever your message would be </div>
I don't know if you need something more complex than that...
Said that, I admit I never worked with frame inside TYPO3 and I think that the last time I did something with frames was...uh... maybe 9 years ago.
Don't change that index.php!!
As it is part of the core which gets overwritten on an update of TYPO3.
As there are very much options for configurating a page there can be no recipe matching all.
My best tip: get a TYPO3 profi to have a look into your installation so he can find which files are responsible for the page rendering and could include the cookie notice.
There also are some extensions which could render such a notice in your pages in a very easy way. But that all depends how your installation is configured. Nothing to say without further knowledge.

Redirect to last page when overlay comment-form is used

I've got a view (phase4) with some custom content type content in it, where the users may comment on.
When the users want to comment, the comment form should appear in a modal form. I solved this by using the admin overlay.
Adding following function to my custom module:
function phase2_admin_paths_alter(&$paths) {
$paths['comment/reply/*'] = TRUE;
}
and using following link:
Comment
to open the comment form in a modal way. So far so good... but....
How do I redirect the user back to the page, the user was coming from.
I know that I have to overwrite the #action of the form in the template_form_FORMID_alter, like
$form['#action'] = $lasturl;
but how do I get the last url, so that it is reusable (so hardcoding the url isn't an option)?
My first idea was that I transfer the last url by adding it to the url as a $_GET-parameter, but it looks like this:
www.example.com/phase4#overlay=comment/reply/161%3Furl%3Dphase4
I also tried it with drupal_get_destination(), but either with no success, because of the tranformation of the "?" and the "=" in the url.
Are there other ways to find out where the user was coming from?
Note: phase4 isn't the alias of node 161. Phase 4 is a view, where node 161 is an element of.
Cheers
Tom
You have to use the drupal_get_destination() function with l() function to create such links.
$destination = drupal_get_destination(); // Store current path
Comment

Joomla: Is there a module render plugin event?

Due to some caching issues, I need to explicitly bypass the cache, for a specific module, if certain URL parameters are present. The workaround I've arrived at is to hack the render() function in libraries/joomla/document/html/renderer/module.php, along the lines of:
function render( $module, $params = array(), $content = null )
{
// Existing code:
$mod_params = new JParameter( $module->params );
// My hack:
if ($module->module == 'mod_foo')
{
if (certain URL parameters are present)
{
$mod_params->set('cache', 0);
}
}
...
}
Of course, hacking the core joomla code is a terrible idea, one which I'd like to avoid if at all possible. So, is there an appropriate hook I can plugin to in order to achieve the same? I don't think I can do anything at the module level, since it won't even be inspected if the renderer has already decided to fetch it from cache.
To answer the first question no there isn't a module render event, here's the plugin doc's and the list of events in Joomla!
Turn off caching for your module.
See this article on The Art Of Joomla, additional articles you could look at:
Using Cache to Speed Up your code
JCache API

Typo3 eID, how to access config

I've just created an eID in Typo3. I can't figure out how to access the config data for my plugin from the Typo3 instance.
I've tried the code from the link but it doesn't want to work. I keep getting an exception "No TypoScript template found! " on the call " $TSFE->getConfigArray(); "
http://lists.typo3.org/pipermail/typo3-dev/2006-December/021392.html
Any ideas?
Thanks.
In eID mode, only a small part of the regular TYPO3 frontend is loaded. Unfortunately TypoScript is not loaded. To still access the TypoScript configuration you need manually load the components it needs to do so. Unfortunately this can be a bit of a pain in the butt. So in some cases it might be easier to just load a page containing a single plugin that doesn't contain anything else (without headers etc.).
If you do want to load the TypoScript templates yourself, you can try something like the following:
require_once(PATH_tslib.'class.tslib_fe.php');
require_once(PATH_t3lib.'class.t3lib_userauth.php' );
require_once(PATH_tslib.'class.tslib_feuserauth.php');
require_once(PATH_t3lib.'class.t3lib_cs.php');
require_once(PATH_tslib.'class.tslib_content.php') ;
require_once(PATH_t3lib.'class.t3lib_tstemplate.php');
require_once(PATH_t3lib.'class.t3lib_page.php');
$TSFEclassName = t3lib_div::makeInstanceClassName('tslib_fe');
$id = isset($HTTP_GET_VARS['id'])?$HTTP_GET_VARS['id']:0;
$GLOBALS['TSFE'] = new $TSFEclassName($TYPO3_CONF_VARS, $id, '0', 1, '','','','');
$GLOBALS['TSFE']->connectToMySQL();
$GLOBALS['TSFE']->initFEuser();
$GLOBALS['TSFE']->fetch_the_id();
$GLOBALS['TSFE']->getPageAndRootline();
$GLOBALS['TSFE']->initTemplate();
$GLOBALS['TSFE']->tmpl->getFileName_backPath = PATH_site;
$GLOBALS['TSFE']->forceTemplateParsing = 1;
$GLOBALS['TSFE']->getConfigArray();
$cObj = t3lib_div::makeInstance('tslib_cObj');
This initializes the TSFE and cObj but is also used to load and parse the TypoScript templates. You might need to make some modifications to (probably kick some things out)
The code came from one of the comments on the following blog post: http://sebastiaandejonge.com/blog/articles/2010/september/21/bringing-ajax-to-your-frontend-plugins/
Good luck!

Best Zend Framework architecture for large reporting site?

I have a site of about 60 tabular report pages. Want to convert this to Zend. The report has two states: empty report and filled in with data report. Each report has its own set of input boxes and select drop downs to narrow down searches. You click on submit and it retrieves the data. Thats all each page does.
Do I create 60 controllers with each one with default index action and getData action? All I have read online do not really describe how to architect a real site.
If the method of fetching and retrieving data is pretty similar as you mention between all 60 reports. It would seem silly to create 60 controllers (+PHP files).
It seems that you are trying to solve this problem with the default rewrite router. You can add a route to the router that will automatically store your report name, and you can abstract and delegate the logic off to some report-runner-business-object-thingy.
$router = $ctrl->getRouter(); // returns a rewrite router by default
$router->addRoute(
'reports',
new Zend_Controller_Router_Route('reports/:report_name/:action',
array('controller' => 'reports',
'action' => 'view'))
);
And then something like this in your controller...
public function viewAction() {
$report = $this->getRequest()->getParam("report_name");
// ... check to see if report name is valid
// ... stuff to set up for viewing report...
}
public function runAction() {
$report = $this->getRequest()->getParam("report_name");
// ... check to see if report name is valid
// Go ahead and pass the array of request params, as your report might need them
$reportRunner = new CustomReportRunner( $report, $this->getRequest()->getParams() );
$reportRunner->run();
}
You get the point; hope this helps!