- Added feature to configure the TTL for preview links in workspaces.
authorKasper Skårhøj <kasper@typo3.org>
Thu, 31 Jan 2008 21:18:43 +0000 (21:18 +0000)
committerKasper Skårhøj <kasper@typo3.org>
Thu, 31 Jan 2008 21:18:43 +0000 (21:18 +0000)
- Added logout button for the preview box in the frontend view when previewing workspaces through preview links.

git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@2999 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/mod/user/ws/index.php
typo3/sysext/cms/tslib/class.tslib_fe.php
typo3/sysext/version/cm1/index.php

index effc1c1..3f022bb 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2008-01-31  Kasper Sk\8crh¿j <kasper2008@typo3.com>
 
+       * - Added feature to configure the TTL for preview links in workspaces.
+       * - Added logout button for the preview box in the frontend view when previewing workspaces through preview links.      
        * - Removed copy/cut/pasteafter/delete from context menu of DB mounts. Could lead to confusing scenarios for admin users in workspaces.
        * - Added TCA feature in [ctrl][versioningWS_alwaysAllowLiveEdit] allowed to permanently set records to be edited directly. This enables that backend users can still be edited while in a workspace. Convenient for admins.
        * - Also, the User Admin module is now available in draft workspaces
index ec01b61..90d62c6 100755 (executable)
@@ -70,7 +70,6 @@
  *
  */
 
-
        // Initialize module:
 unset($MCONF);
 require ('conf.php');
@@ -433,8 +432,10 @@ class SC_mod_user_ws_index extends t3lib_SCbase {
                        
                                // Preview of workspace link
                        if (t3lib_div::_POST('_previewLink'))   {
-                               $previewUrl = t3lib_div::getIndpEnv('TYPO3_SITE_URL').'index.php?ADMCMD_prev='.t3lib_BEfunc::compilePreviewKeyword('', $GLOBALS['BE_USER']->user['uid'],60*60*24*2,$GLOBALS['BE_USER']->workspace);
-                               $actionLinks.=  '<br/>Any user can browse the workspace frontend using this link for the next 48 hours (does not require backend login):<br/><br/><a target="_blank" href="'.htmlspecialchars($previewUrl).'">'.$previewUrl.'</a>';
+                               $ttlHours = intval($GLOBALS['BE_USER']->getTSConfigVal('options.workspaces.previewLinkTTLHours'));
+                               $ttlHours = ($ttlHours ? $ttlHours : 24*2);
+                               $previewUrl = t3lib_div::getIndpEnv('TYPO3_SITE_URL').'index.php?ADMCMD_prev='.t3lib_BEfunc::compilePreviewKeyword('', $GLOBALS['BE_USER']->user['uid'],60*60*$ttlHours,$GLOBALS['BE_USER']->workspace).'&id='.intval($GLOBALS['BE_USER']->workspaceRec['db_mountpoints']);
+                               $actionLinks.=  '<br/>Any user can browse the workspace frontend using this link for the next '.$ttlHours.' hours (does not require backend login):<br/><br/><a target="_blank" href="'.htmlspecialchars($previewUrl).'">'.$previewUrl.'</a>';
                        } else {
                                $actionLinks.= '<input type="submit" name="_previewLink" value="Generate Workspace Preview Link" />';
                        }
index 684bb7d..7bb8ef4 100755 (executable)
        /**
         * Looking for a ADMCMD_prev code, looks it up if found and returns configuration data.
         * Background: From the backend a request to the frontend to show a page, possibly with workspace preview can be "recorded" and associated with a keyword. When the frontend is requested with this keyword the associated request parameters are restored from the database AND the backend user is loaded - only for that request.
-        * The main point is that a special URL valid for a limited time, eg. http://localhost/typo3site/index.php?ADMCMD_prev=035d9bf938bd23cb657735f68a8cedbf will open up for a preview that doesn't require login. Thus its useful for sending an email.
+        * The main point is that a special URL valid for a limited time, eg. http://localhost/typo3site/index.php?ADMCMD_prev=035d9bf938bd23cb657735f68a8cedbf will open up for a preview that doesn't require login. Thus it's useful for sending in an email to someone without backend account.
         * This can also be used to generate previews of hidden pages, start/endtimes, usergroups and those other settings from the Admin Panel - just not implemented yet.
         *
         * @return      array           Preview configuration array from sys_preview record.
         */
        function ADMCMD_preview(){
                $inputCode = t3lib_div::_GP('ADMCMD_prev');
-               $cookieTTL = 60*60;
 
-                       // If cookie is set, see what to do:
-               if ($_COOKIE['ADMCMD_prev'])    {
-
-                               // If no input code is given by GET method, lets look it up in a cookie (for workspace previews not only tied to the page) and update the cookie time:
-                       if (!$inputCode)        {
-                               $inputCode = $_COOKIE['ADMCMD_prev'];
-                               SetCookie('ADMCMD_prev', $inputCode, time()+$cookieTTL);
-                       } else {        // Otherwise "log out":
-                               SetCookie('ADMCMD_prev', '', 0);
-                               die("You logged out from Workspace preview mode. Reload the browser to log in again.");
-                       }
+                       // If no inputcode and a cookie is set, load input code from cookie:
+               if (!$inputCode && $_COOKIE['ADMCMD_prev'])     {
+                       $inputCode = $_COOKIE['ADMCMD_prev'];
                }
 
                        // If inputcode now, look up the settings:
                if ($inputCode) {
 
+                       if ($inputCode=='LOGOUT') {     // "log out":
+                               SetCookie('ADMCMD_prev', '', 0);
+                               die("You logged out from Workspace preview mode. Click the preview link you were given to log in again.");
+                       }
+
                                // Look for keyword configuration record:
                        list($previewData) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
                                '*',
 
                                                        // If ADMCMD_prev is set the $inputCode value cannot come from a cookie and we set that cookie here. Next time it will be found from the cookie if ADMCMD_prev is not set again...
                                                if (t3lib_div::_GP('ADMCMD_prev'))      {
-                                                       SetCookie('ADMCMD_prev', t3lib_div::_GP('ADMCMD_prev'), time()+$cookieTTL);     // Lifetime is 1 hour, does it matter much? Requires the user to click the link from their email again if it expires.
+                                                       SetCookie('ADMCMD_prev', t3lib_div::_GP('ADMCMD_prev'), 0);     // Lifetime is 1 hour, does it matter much? Requires the user to click the link from their email again if it expires.
                                                }
                                                return $previewConfig;
                                        } elseif (t3lib_div::getIndpEnv('TYPO3_SITE_URL').'index.php?ADMCMD_prev='.$inputCode === t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'))   {
@@ -3280,12 +3276,15 @@ if (version == "n3") {
        function previewInfo()  {
                if ($this->fePreview)   {
                                if ($this->fePreview==2)        {
+                                       $onclickForStoppingPreview = 'document.location="'.t3lib_div::getIndpEnv('TYPO3_SITE_URL').'index.php?ADMCMD_prev=LOGOUT";return false;';
                                        $text = 'Preview of workspace "'.$this->whichWorkspace(TRUE).'" ('.$this->whichWorkspace().')';
+                                       $html = $this->doWorkspacePreview() ? '<br/><input name="_" type="submit" value="Stop preview" onclick="'.htmlspecialchars($onclickForStoppingPreview).'" />' : '';
                                } else {
                                        $text = 'PREVIEW!';
+                                       $html = '';
                                }
 
-                               $stdMsg = '<div id="typo3-previewInfo" style="position: absolute; top: 20px; right: 20px; border: 2px solid #000; padding: 5px 150px; background: #f00; font: 1em Verdana; color: #000; font-weight: bold; z-index: 10001">'.htmlspecialchars($text).'</div>';
+                               $stdMsg = '<div id="typo3-previewInfo" style="position: absolute; top: 20px; right: 20px; border: 2px solid #000; padding: 5px 5px; background: #f00; font: 1em Verdana; color: #000; font-weight: bold; z-index: 10001">'.htmlspecialchars($text).$html.'</div>';
 
                                if ($this->fePreview==2)        {
                                        $temp_content = $this->config['config']['message_preview_workspace'] ?
index 71d7673..a37ed23 100755 (executable)
@@ -677,10 +677,13 @@ class tx_version_cm1 extends t3lib_SCbase {
                }
 
                if (t3lib_div::_POST('_previewLink'))   {
+                       $ttlHours = intval($GLOBALS['BE_USER']->getTSConfigVal('options.workspaces.previewLinkTTLHours'));
+                       $ttlHours = ($ttlHours ? $ttlHours : 24*2);
+
                        $params = 'id='.$this->id.'&ADMCMD_previewWS='.$GLOBALS['BE_USER']->workspace;
-                       $previewUrl = t3lib_div::getIndpEnv('TYPO3_SITE_URL').'index.php?ADMCMD_prev='.t3lib_BEfunc::compilePreviewKeyword($params, $GLOBALS['BE_USER']->user['uid']);
+                       $previewUrl = t3lib_div::getIndpEnv('TYPO3_SITE_URL').'index.php?ADMCMD_prev='.t3lib_BEfunc::compilePreviewKeyword($params, $GLOBALS['BE_USER']->user['uid'],$ttlHours);
 
-                       $this->content.= $this->doc->section('Preview Url:','You can preview this page from the workspace using this link for the next 48 hours (does not require backend login):<br/><br/><a target="_blank" href="'.htmlspecialchars($previewUrl).'">'.$previewUrl.'</a>',0,1);
+                       $this->content.= $this->doc->section('Preview Url:','You can preview this page from the workspace using this link for the next '.$ttlHours.' hours (does not require backend login):<br/><br/><a target="_blank" href="'.htmlspecialchars($previewUrl).'">'.$previewUrl.'</a>',0,1);
                }
 
                        // Output overview content: