Documentation TYPO3 par Ameos

index.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2004-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *
00017 *  This script is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 *  GNU General Public License for more details.
00021 *
00022 *  This copyright notice MUST APPEAR in all copies of the script!
00023 ***************************************************************/
00049         // DEFAULT initialization of a module [BEGIN]
00050 unset($MCONF);
00051 require ("conf.php");
00052 require ($BACK_PATH."init.php");
00053 require ($BACK_PATH."template.php");
00054 $LANG->includeLLFile("EXT:version/cm1/locallang.php");
00055 require_once (PATH_t3lib."class.t3lib_scbase.php");
00056         // ....(But no access check here...)
00057         // DEFAULT initialization of a module [END]
00058 
00059 
00060 
00061 
00062 
00063 require_once(PATH_t3lib.'class.t3lib_diff.php');
00064 
00065 
00073 class tx_version_cm1 extends t3lib_SCbase {
00074 
00080         function main() {
00081                 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
00082 
00083                         // Draw the header.
00084                 $this->doc = t3lib_div::makeInstance("mediumDoc");
00085                 $this->doc->backPath = $BACK_PATH;
00086                 $this->doc->form='<form action="" method="post">';
00087 
00088 
00089                 $this->uid = intval(t3lib_div::_GP('uid'));
00090                 $this->table = t3lib_div::_GP('table');
00091                 $record = t3lib_BEfunc::getRecord($this->table,$this->uid);
00092 
00093                 if (is_array($record) && $TCA[$this->table]['ctrl']['versioning'])      {
00094                                 // Access check!
00095                                 // The page will show only if there is a valid page and if this page may be viewed by the user
00096                         $this->pageinfo = t3lib_BEfunc::readPageAccess($record['pid'],$this->perms_clause);
00097                         $access = is_array($this->pageinfo) ? 1 : 0;
00098 
00099                         if (($record['pid'] && $access) || ($BE_USER->user["admin"] && !$record['pid']))        {
00100 
00101                                         // JavaScript
00102                                 $this->doc->JScode = '
00103                                         <script language="javascript" type="text/javascript">
00104                                                 script_ended = 0;
00105                                                 function jumpToUrl(URL) {
00106                                                         document.location = URL;
00107                                                 }
00108                                         </script>
00109                                 ';
00110 
00111 #                               $headerSection = $this->doc->getHeader("pages",$this->pageinfo,$this->pageinfo["_thePath"])."<br/>".$LANG->sL("LLL:EXT:lang/locallang_core.php:labels.path").": ".t3lib_div::fixed_lgd_pre($this->pageinfo["_thePath"],50);
00112 
00113                                 $this->content.=$this->doc->startPage($LANG->getLL("title"));
00114                                 $this->content.=$this->doc->header($LANG->getLL("title"));
00115 #                               $this->content.=$this->doc->spacer(5);
00116 #                               $this->content.=$this->doc->section('',$headerSection);
00117 #                               $this->content.=$this->doc->divider(5);
00118 
00119 
00120 
00121                                 // Render content:
00122                                 $this->moduleContent();
00123 
00124                                 // ShortCut
00125                                 if ($BE_USER->mayMakeShortcut())        {
00126                                         $this->content.=$this->doc->spacer(20).$this->doc->section("",$this->doc->makeShortcutIcon("id",implode(",",array_keys($this->MOD_MENU)),$this->MCONF["name"]));
00127                                 }
00128                         }
00129 
00130                         $this->content.=$this->doc->spacer(10);
00131                 }
00132         }
00133 
00139         function printContent() {
00140 
00141                 $this->content.=$this->doc->endPage();
00142                 echo $this->content;
00143         }
00144 
00150         function moduleContent()        {
00151                 global $TCA;
00152 
00153                         // Diffing:
00154                 $diff_1 = t3lib_div::_POST('diff_1');
00155                 $diff_2 = t3lib_div::_POST('diff_2');
00156                 if (t3lib_div::_POST('do_diff'))        {
00157                         $content='';
00158                         $content.='<h3>DIFFING:</h3>';
00159                         if ($diff_1 && $diff_2) {
00160                                 $diff_1_record = t3lib_BEfunc::getRecord($this->table, $diff_1);
00161                                 $diff_2_record = t3lib_BEfunc::getRecord($this->table, $diff_2);
00162 
00163                                 if (is_array($diff_1_record) && is_array($diff_2_record))       {
00164                                         t3lib_div::loadTCA($this->table);
00165                                         $t3lib_diff_Obj = t3lib_div::makeInstance('t3lib_diff');
00166 
00167                                         $tRows=array();
00168                                                                 $tRows[] = '
00169                                                                         <tr class="bgColor5 tableheader">
00170                                                                                 <td>Fieldname:</td>
00171                                                                                 <td width="98%">Colored diff-view:</td>
00172                                                                         </tr>
00173                                                                 ';
00174                                         foreach($diff_1_record as $fN => $fV)   {
00175                                                 if ($TCA[$this->table]['columns'][$fN] && $TCA[$this->table]['columns'][$fN]['config']['type']!='passthrough' && !t3lib_div::inList('t3ver_label',$fN)) {
00176                                                         if (strcmp($diff_1_record[$fN],$diff_2_record[$fN]))    {
00177 
00178                                                                 $diffres = $t3lib_diff_Obj->makeDiffDisplay(
00179                                                                         t3lib_BEfunc::getProcessedValue($this->table,$fN,$diff_2_record[$fN],0,1),
00180                                                                         t3lib_BEfunc::getProcessedValue($this->table,$fN,$diff_1_record[$fN],0,1)
00181                                                                 );
00182 
00183                                                                 $tRows[] = '
00184                                                                         <tr class="bgColor4">
00185                                                                                 <td>'.$fN.'</td>
00186                                                                                 <td width="98%">'.$diffres.'</td>
00187                                                                         </tr>
00188                                                                 ';
00189                                                         }
00190                                                 }
00191                                         }
00192 
00193                                         if (count($tRows)>1)    {
00194                                                 $content.='<table border="0" cellpadding="1" cellspacing="1" width="100%">'.implode('',$tRows).'</table><br/><br/>';
00195                                         } else {
00196                                                 $content.='Records matches completely on all editable fields!';
00197                                         }
00198                                 } else $content.='ERROR: Records could strangely not be found!';
00199                         } else {
00200                                 $content.='ERROR: You didn\'t select two sources for diffing!';
00201                         }
00202                 }
00203 
00204                         // Element:
00205                 $record = t3lib_BEfunc::getRecord($this->table,$this->uid);
00206                 $recordIcon = t3lib_iconWorks::getIconImage($this->table,$record,$this->doc->backPath,'class="absmiddle"');
00207                 $recTitle = t3lib_BEfunc::getRecordTitle($this->table,$record,1);
00208 
00209                         // Display versions:
00210                 $content.='
00211                         '.$recordIcon.$recTitle.'
00212                         <form action="'.t3lib_div::getIndpEnv('REQUEST_URI').'" method="post">
00213                         <table border="0" cellspacing="1" cellpadding="1">';
00214                         $content.='
00215                                 <tr class="bgColor5 tableheader">
00216                                         <td>&nbsp;</td>
00217                                         <td>&nbsp;</td>
00218                                         <td>Title</td>
00219                                         <td>UID</td>
00220                                         <td>t3ver_oid</td>
00221                                         <td>t3ver_id</td>
00222                                         <td>pid</td>
00223                                         <td>t3ver_label</td>
00224                                         <td colspan="2"><input type="submit" name="do_diff" value="Diff" /></td>
00225                                 </tr>';
00226 
00227                 $versions = t3lib_BEfunc::selectVersionsOfRecord($this->table, $this->uid);
00228                 foreach($versions as $row)      {
00229                         $adminLinks = $this->adminLinks($this->table,$row);
00230 
00231                         $content.='
00232                                 <tr class="'.($row['uid']!=$this->uid ? 'bgColor4' : 'bgColor2 tableheader').'">
00233                                         <td>'.($row['uid']!=$this->uid ? '<a href="'.$this->doc->issueCommand('&cmd['.$this->table.']['.$this->uid.'][version][swapWith]='.$row['uid'].'&cmd['.$this->table.']['.$this->uid.'][version][action]=swap').'">'.
00234                                                 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/insert1.gif','width="14" height="14"').' alt="" title="SWAP with current" />'.
00235                                                 '</a>'.(
00236                                                         $this->table == 'pages' ?
00237                                                         '<a href="'.$this->doc->issueCommand('&cmd['.$this->table.']['.$this->uid.'][version][action]=swap&cmd['.$this->table.']['.$this->uid.'][version][swapWith]='.$row['uid'].'&cmd['.$this->table.']['.$this->uid.'][version][swapContent]=1').'">'.
00238                                                 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/insert2.gif','width="14" height="14"').' alt="" title="Publish page AND content!" />'.
00239                                                 '</a>'.
00240                                                         '<a href="'.$this->doc->issueCommand('&cmd['.$this->table.']['.$this->uid.'][version][action]=swap&cmd['.$this->table.']['.$this->uid.'][version][swapWith]='.$row['uid'].'&cmd['.$this->table.']['.$this->uid.'][version][swapContent]=ALL').'">'.
00241                                                 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/insert4.gif','width="14" height="14"').' alt="" title="Publish page AND content! - AND ALL SUBPAGES!" />'.
00242                                                 '</a>' : '') : '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/blinkarrow_left.gif','width="5" height="9"').' alt="" title="CURRENT ONLINE VERSION!"/>').'</td>
00243                                         <td>'.$adminLinks.'</td>
00244                                         <td nowrap="nowrap">'.t3lib_BEfunc::getRecordTitle($this->table,$row,1).'</td>
00245                                         <td>'.$row['uid'].'</td>
00246                                         <td>'.$row['t3ver_oid'].'</td>
00247                                         <td>'.$row['t3ver_id'].'</td>
00248                                         <td>'.$row['pid'].'</td>
00249                                         <td nowrap="nowrap"><a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick('&edit['.$this->table.']['.$row['uid'].']=edit&columnsOnly=t3ver_label',$this->doc->backPath)).'"><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/edit2.gif','width="11" height="12"').' alt="" title="Edit"/></a>'.htmlspecialchars($row['t3ver_label']).'</td>
00250                                         <td bgcolor="green"><input type="radio" name="diff_1" value="'.$row['uid'].'"'.($diff_1==$row['uid'] ? ' checked="checked"':'').'/></td>
00251                                         <td bgcolor="red"><input type="radio" name="diff_2" value="'.$row['uid'].'"'.($diff_2==$row['uid'] ? ' checked="checked"':'').'/></td>
00252                                 </tr>';
00253 
00254                         if ($this->table == 'pages')    {       //  && $row['uid']!=$this->uid
00255                                 $sub = $this->pageSubContent($row['uid']);
00256 
00257                                 if ($sub)       {
00258                                         $content.='
00259                                                 <tr>
00260                                                         <td></td>
00261                                                         <td></td>
00262                                                         <td colspan="6">'.$sub.'</td>
00263                                                         <td colspan="2"></td>
00264                                                 </tr>';
00265                                 }
00266                         }
00267                 }
00268                 $content.='</table></form>';
00269 
00270                 $this->content.=$this->doc->section('',$content,0,1);
00271 
00272 
00273                         // Create new:
00274                 $content='
00275 
00276                         <form action="'.$this->doc->backPath.'tce_db.php" method="post">
00277                         Label: <input type="text" name="cmd['.$this->table.']['.$this->uid.'][version][label]" /><br/>
00278                         '.($this->table == 'pages' ? '<select name="cmd['.$this->table.']['.$this->uid.'][version][treeLevels]">
00279                                 <option value="0">Page + content</option>
00280                                 <option value="1">1 level</option>
00281                                 <option value="2">2 levels</option>
00282                                 <option value="3">3 levels</option>
00283                                 <option value="4">4 levels</option>
00284                                 <option value="-1">Just page record</option>
00285                         </select>' : '').'
00286                         <br/><input type="hidden" name="cmd['.$this->table.']['.$this->uid.'][version][action]" value="new" />
00287                         <input type="hidden" name="prErr" value="1" />
00288                         <input type="hidden" name="redirect" value="'.t3lib_div::getIndpEnv('REQUEST_URI').'" />
00289                         <input type="submit" name="_" value="Create new version" />
00290 
00291                         </form>
00292 
00293                 ';
00294 
00295                 $this->content.=$this->doc->spacer(15);
00296                 $this->content.=$this->doc->section("Create new version",$content,0,1);
00297 
00298         }
00299 
00307         function pageSubContent($pid,$c=0)      {
00308                 global $TCA;
00309 
00310                 $tableNames = array_keys($TCA);
00311                 foreach($tableNames as $tN)     {
00312                                 // Basically list ALL tables - not only those being copied might be found!
00313                         #if ($TCA[$tN]['ctrl']['versioning_followPages'] || $tN=='pages')       {
00314                                 $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $tN, 'pid='.intval($pid).t3lib_BEfunc::deleteClause($tN), '', ($TCA[$tN]['ctrl']['sortby'] ? $TCA[$tN]['ctrl']['sortby'] : ''));
00315 
00316                                 if ($GLOBALS['TYPO3_DB']->sql_num_rows($mres))  {
00317                                         $content.='
00318                                                 <tr>
00319                                                         <td colspan="4" class="'.($TCA[$tN]['ctrl']['versioning_followPages'] ? 'bgColor6' : ($tN=='pages' ? 'bgColor5' : 'bgColor-10')).'"'.(!$TCA[$tN]['ctrl']['versioning_followPages'] && $tN!='pages' ? ' style="color: #666666; font-style:italic;"':'').'>'.$tN.'</td>
00320                                                 </tr>';
00321                                         while ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres))  {
00322                                                 $ownVer = $this->lookForOwnVersions($tN,$subrow['uid']);
00323                                                 $content.='
00324                                                         <tr>
00325                                                                 <td>'.$this->adminLinks($tN,$subrow).'</td>
00326                                                                 <td>'.$subrow['uid'].'</td>
00327                                                                 '.($ownVer>1 ? '<td style="font-weight: bold; background-color: yellow;"><a href="index.php?table='.rawurlencode($tN).'&uid='.$subrow['uid'].'">'.($ownVer-1).'</a></td>' : '<td></td>').'
00328                                                                 <td width="98%">'.t3lib_BEfunc::getRecordTitle($tN,$subrow,1).'</td>
00329                                                         </tr>';
00330 
00331                                                 if ($tN == 'pages' && $c<10)    {
00332                                                         $sub = $this->pageSubContent($subrow['uid'],$c+1);
00333 
00334                                                         if ($sub)       {
00335                                                                 $content.='
00336                                                                         <tr>
00337                                                                                 <td></td>
00338                                                                                 <td></td>
00339                                                                                 <td></td>
00340                                                                                 <td width="98%">'.$sub.'</td>
00341                                                                         </tr>';
00342                                                         }
00343                                                 }
00344                                         }
00345                                 }
00346                         #}
00347                 }
00348 
00349                 return $content ? '<table border="1" cellpadding="1" cellspacing="0" width="100%">'.$content.'</table>' : '';
00350         }
00351 
00359         function lookForOwnVersions($table,$uid)        {
00360                 global $TCA;
00361 
00362                 $versions = t3lib_BEfunc::selectVersionsOfRecord($table, $uid, 'uid');
00363                 if (is_array($versions))        {
00364                         return count($versions);
00365                 }
00366                 return FALSE;
00367         }
00368 
00376         function adminLinks($table,$row)        {
00377                 global $BE_USER;
00378 
00379                 $adminLink = '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick('&edit['.$table.']['.$row['uid'].']=edit',$this->doc->backPath)).'">'.
00380                                                 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/edit2.gif','width="11" height="12"').' alt="" title="Edit"/>'.
00381                                                 '</a>';
00382 
00383                 if ($table == 'pages')  {
00384 
00385                                 // If another page module was specified, replace the default Page module with the new one
00386                         $newPageModule = trim($BE_USER->getTSConfigVal('options.overridePageModule'));
00387                         $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
00388 
00389                                 // Perform some acccess checks:
00390                         $a_wl = $BE_USER->check('modules','web_list');
00391                         $a_wp = t3lib_extMgm::isLoaded('cms') && $BE_USER->check('modules',$pageModule);
00392 
00393                         $adminLink.='<a href="#" onclick="top.loadEditId('.$row['uid'].');top.goToModule(\''.$pageModule.'\'); return false;">'.
00394                                                 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,t3lib_extMgm::extRelPath('cms').'layout/layout.gif','width="14" height="12"').' title="" alt="" />'.
00395                                                 '</a>';
00396                         $adminLink.='<a href="#" onclick="top.loadEditId('.$row['uid'].');top.goToModule(\'web_list\'); return false;">'.
00397                                                 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'mod/web/list/list.gif','width="14" height="12"').' title="" alt="" />'.
00398                                                 '</a>';
00399 
00400                                 // "View page" icon is added:
00401                         $adminLink.='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::viewOnClick($row['uid'],$this->doc->backPath,t3lib_BEfunc::BEgetRootLine($row['uid']))).'">'.
00402                                 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/zoom.gif','width="12" height="12"').' title="" alt="" />'.
00403                                 '</a>';
00404                 } else {
00405                         if ($row['pid']==-1)    {
00406                                 $getVars = '&ADMCMD_vPrev['.rawurlencode($table.':'.$row['t3ver_oid']).']='.$row['uid'];
00407 
00408                                         // "View page" icon is added:
00409                                 $adminLink.='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::viewOnClick($row['_REAL_PID'],$this->doc->backPath,t3lib_BEfunc::BEgetRootLine($row['_REAL_PID']),'','',$getVars)).'">'.
00410                                         '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/zoom.gif','width="12" height="12"').' title="" alt="" />'.
00411                                         '</a>';
00412                         }
00413                 }
00414 
00415                 return $adminLink;
00416         }
00417 }
00418 
00419 
00420 
00421 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/version/cm1/index.php"])       {
00422         include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/version/cm1/index.php"]);
00423 }
00424 
00425 
00426 
00427 
00428 // Make instance:
00429 $SOBE = t3lib_div::makeInstance("tx_version_cm1");
00430 $SOBE->init();
00431 
00432 
00433 $SOBE->main();
00434 $SOBE->printContent();
00435 
00436 ?>


Généré par L'expert TYPO3 avec  doxygen 1.4.6