Documentation TYPO3 par Ameos

index.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2004 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 ***************************************************************/
00032         // DEFAULT initialization of a module [BEGIN]
00033 unset($MCONF);
00034 require ("conf.php");
00035 require ($BACK_PATH."init.php");
00036 require ($BACK_PATH."template.php");
00037 $LANG->includeLLFile("EXT:version/cm1/locallang.php");
00038 #include ("locallang.php");
00039 require_once (PATH_t3lib."class.t3lib_scbase.php");
00040         // ....(But no access check here...)
00041         // DEFAULT initialization of a module [END]
00042 
00043 
00044 
00045 
00046 
00047 require_once(PATH_t3lib.'class.t3lib_diff.php');
00048 
00049 
00050 
00051 class tx_version_cm1 extends t3lib_SCbase {
00052 
00056         function main() {
00057                 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
00058 
00059                         // Draw the header.
00060                 $this->doc = t3lib_div::makeInstance("mediumDoc");
00061                 $this->doc->backPath = $BACK_PATH;
00062                 $this->doc->form='<form action="" method="post">';
00063 
00064 
00065                 $this->uid = intval(t3lib_div::_GP('uid'));
00066                 $this->table = t3lib_div::_GP('table');
00067                 $record = t3lib_BEfunc::getRecord($this->table,$this->uid);
00068 
00069                 if (is_array($record) && $TCA[$this->table]['ctrl']['versioning'])      {
00070                                 // Access check!
00071                                 // The page will show only if there is a valid page and if this page may be viewed by the user
00072                         $this->pageinfo = t3lib_BEfunc::readPageAccess($record['pid'],$this->perms_clause);
00073                         $access = is_array($this->pageinfo) ? 1 : 0;
00074 
00075                         if (($record['pid'] && $access) || ($BE_USER->user["admin"] && !$record['pid']))        {
00076 
00077                                         // JavaScript
00078                                 $this->doc->JScode = '
00079                                         <script language="javascript" type="text/javascript">
00080                                                 script_ended = 0;
00081                                                 function jumpToUrl(URL) {
00082                                                         document.location = URL;
00083                                                 }
00084                                         </script>
00085                                 ';
00086 
00087 #                               $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);
00088 
00089                                 $this->content.=$this->doc->startPage($LANG->getLL("title"));
00090                                 $this->content.=$this->doc->header($LANG->getLL("title"));
00091 #                               $this->content.=$this->doc->spacer(5);
00092 #                               $this->content.=$this->doc->section('',$headerSection);
00093 #                               $this->content.=$this->doc->divider(5);
00094 
00095 
00096 
00097                                 // Render content:
00098                                 $this->moduleContent();
00099 
00100                                 // ShortCut
00101                                 if ($BE_USER->mayMakeShortcut())        {
00102                                         $this->content.=$this->doc->spacer(20).$this->doc->section("",$this->doc->makeShortcutIcon("id",implode(",",array_keys($this->MOD_MENU)),$this->MCONF["name"]));
00103                                 }
00104                         }
00105 
00106                         $this->content.=$this->doc->spacer(10);
00107                 }
00108         }
00109         function printContent() {
00110 
00111                 $this->content.=$this->doc->endPage();
00112                 echo $this->content;
00113         }
00114 
00115         function moduleContent()        {
00116                 global $TCA;
00117 
00118                         // Diffing:
00119                 $diff_1 = t3lib_div::_POST('diff_1');
00120                 $diff_2 = t3lib_div::_POST('diff_2');
00121                 if (t3lib_div::_POST('do_diff'))        {
00122                         $content='';
00123                         $content.='<h3>DIFFING:</h3>';
00124                         if ($diff_1 && $diff_2) {
00125                                 $diff_1_record = t3lib_BEfunc::getRecord($this->table, $diff_1);
00126                                 $diff_2_record = t3lib_BEfunc::getRecord($this->table, $diff_2);
00127 
00128                                 if (is_array($diff_1_record) && is_array($diff_2_record))       {
00129                                         t3lib_div::loadTCA($this->table);
00130                                         $t3lib_diff_Obj = t3lib_div::makeInstance('t3lib_diff');
00131 
00132                                         $tRows=array();
00133                                                                 $tRows[] = '
00134                                                                         <tr class="bgColor5 tableheader">
00135                                                                                 <td>Fieldname:</td>
00136                                                                                 <td width="98%">Colored diff-view:</td>
00137                                                                         </tr>
00138                                                                 ';
00139                                         foreach($diff_1_record as $fN => $fV)   {
00140                                                 if ($TCA[$this->table]['columns'][$fN] && $TCA[$this->table]['columns'][$fN]['config']['type']!='passthrough' && !t3lib_div::inList('t3ver_label',$fN)) {
00141                                                         if (strcmp($diff_1_record[$fN],$diff_2_record[$fN]))    {
00142 
00143                                                                 $diffres = $t3lib_diff_Obj->makeDiffDisplay(
00144                                                                         t3lib_BEfunc::getProcessedValue($this->table,$fN,$diff_2_record[$fN],0,1),
00145                                                                         t3lib_BEfunc::getProcessedValue($this->table,$fN,$diff_1_record[$fN],0,1)
00146                                                                 );
00147 
00148                                                                 $tRows[] = '
00149                                                                         <tr class="bgColor4">
00150                                                                                 <td>'.$fN.'</td>
00151                                                                                 <td width="98%">'.$diffres.'</td>
00152                                                                         </tr>
00153                                                                 ';
00154                                                         }
00155                                                 }
00156                                         }
00157 
00158                                         if (count($tRows)>1)    {
00159                                                 $content.='<table border="0" cellpadding="1" cellspacing="1" width="100%">'.implode('',$tRows).'</table><br/><br/>';
00160                                         } else {
00161                                                 $content.='Records matches completely on all editable fields!';
00162                                         }
00163                                 } else $content.='ERROR: Records could strangely not be found!';
00164                         } else {
00165                                 $content.='ERROR: You didn\'t select two sources for diffing!';
00166                         }
00167                 }
00168 
00169                         // Element:
00170                 $record = t3lib_BEfunc::getRecord($this->table,$this->uid);
00171                 $recordIcon = t3lib_iconWorks::getIconImage($this->table,$record,$this->doc->backPath,'class="absmiddle"');
00172                 $recTitle = t3lib_BEfunc::getRecordTitle($this->table,$record,1);
00173 
00174                         // Display versions:
00175                 $content.='
00176                         '.$recordIcon.$recTitle.'
00177                         <form action="'.t3lib_div::getIndpEnv('REQUEST_URI').'" method="post">
00178                         <table border="0" cellspacing="1" cellpadding="1">';
00179                         $content.='
00180                                 <tr class="bgColor5 tableheader">
00181                                         <td>&nbsp;</td>
00182                                         <td>&nbsp;</td>
00183                                         <td>Title</td>
00184                                         <td>UID</td>
00185                                         <td>t3ver_oid</td>
00186                                         <td>t3ver_id</td>
00187                                         <td>pid</td>
00188                                         <td>t3ver_label</td>
00189                                         <td colspan="2"><input type="submit" name="do_diff" value="Diff" /></td>
00190                                 </tr>';
00191 
00192                 $versions = t3lib_BEfunc::selectVersionsOfRecord($this->table, $this->uid);
00193                 foreach($versions as $row)      {
00194                         $adminLinks = $this->adminLinks($this->table,$row);
00195 
00196                         $content.='
00197                                 <tr class="'.($row['uid']!=$this->uid ? 'bgColor4' : 'bgColor2 tableheader').'">
00198                                         <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').'">'.
00199                                                 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/insert1.gif','width="14" height="14"').' alt="" title="SWAP with current" />'.
00200                                                 '</a>'.(
00201                                                         $this->table == 'pages' ?
00202                                                         '<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').'">'.
00203                                                 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/insert2.gif','width="14" height="14"').' alt="" title="Publish page AND content!" />'.
00204                                                 '</a>'.
00205                                                         '<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').'">'.
00206                                                 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/insert4.gif','width="14" height="14"').' alt="" title="Publish page AND content! - AND ALL SUBPAGES!" />'.
00207                                                 '</a>' : '') : '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/blinkarrow_left.gif','width="5" height="9"').' alt="" title="CURRENT ONLINE VERSION!"/>').'</td>
00208                                         <td>'.$adminLinks.'</td>
00209                                         <td nowrap="nowrap">'.t3lib_BEfunc::getRecordTitle($this->table,$row,1).'</td>
00210                                         <td>'.$row['uid'].'</td>
00211                                         <td>'.$row['t3ver_oid'].'</td>
00212                                         <td>'.$row['t3ver_id'].'</td>
00213                                         <td>'.$row['pid'].'</td>
00214                                         <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>
00215                                         <td bgcolor="green"><input type="radio" name="diff_1" value="'.$row['uid'].'"'.($diff_1==$row['uid'] ? ' checked="checked"':'').'/></td>
00216                                         <td bgcolor="red"><input type="radio" name="diff_2" value="'.$row['uid'].'"'.($diff_2==$row['uid'] ? ' checked="checked"':'').'/></td>
00217                                 </tr>';
00218 
00219                         if ($this->table == 'pages')    {       //  && $row['uid']!=$this->uid
00220                                 $sub = $this->pageSubContent($row['uid']);
00221 
00222                                 if ($sub)       {
00223                                         $content.='
00224                                                 <tr>
00225                                                         <td></td>
00226                                                         <td></td>
00227                                                         <td colspan="6">'.$sub.'</td>
00228                                                         <td colspan="2"></td>
00229                                                 </tr>';
00230                                 }
00231                         }
00232                 }
00233                 $content.='</table></form>';
00234 
00235                 $this->content.=$this->doc->section('',$content,0,1);
00236 
00237 
00238                         // Create new:
00239                 $content='
00240 
00241                         <form action="'.$this->doc->backPath.'tce_db.php" method="post">
00242                         Label: <input type="text" name="cmd['.$this->table.']['.$this->uid.'][version][label]" /><br/>
00243                         '.($this->table == 'pages' ? '<select name="cmd['.$this->table.']['.$this->uid.'][version][treeLevels]">
00244                                 <option value="0">Page + content</option>
00245                                 <option value="1">1 level</option>
00246                                 <option value="2">2 levels</option>
00247                                 <option value="3">3 levels</option>
00248                                 <option value="4">4 levels</option>
00249                                 <option value="-1">Just page record</option>
00250                         </select>' : '').'
00251                         <br/><input type="hidden" name="cmd['.$this->table.']['.$this->uid.'][version][action]" value="new" />
00252                         <input type="hidden" name="prErr" value="1" />
00253                         <input type="hidden" name="redirect" value="'.t3lib_div::getIndpEnv('REQUEST_URI').'" />
00254                         <input type="submit" name="_" value="Create new version" />
00255 
00256                         </form>
00257 
00258                 ';
00259 
00260                 $this->content.=$this->doc->spacer(15);
00261                 $this->content.=$this->doc->section("Create new version",$content,0,1);
00262 
00263         }
00264 
00265         function pageSubContent($pid,$c=0)      {
00266                 global $TCA;
00267 
00268                 $tableNames = array_keys($TCA);
00269                 foreach($tableNames as $tN)     {
00270                                 // Basically list ALL tables - not only those being copied might be found!
00271                         #if ($TCA[$tN]['ctrl']['versioning_followPages'] || $tN=='pages')       {
00272                                 $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $tN, 'pid='.intval($pid).t3lib_BEfunc::deleteClause($tN), '', ($TCA[$tN]['ctrl']['sortby'] ? $TCA[$tN]['ctrl']['sortby'] : ''));
00273 
00274                                 if ($GLOBALS['TYPO3_DB']->sql_num_rows($mres))  {
00275                                         $content.='
00276                                                 <tr>
00277                                                         <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>
00278                                                 </tr>';
00279                                         while ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres))  {
00280                                                 $ownVer = $this->lookForOwnVersions($tN,$subrow['uid']);
00281                                                 $content.='
00282                                                         <tr>
00283                                                                 <td>'.$this->adminLinks($tN,$subrow).'</td>
00284                                                                 <td>'.$subrow['uid'].'</td>
00285                                                                 '.($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>').'
00286                                                                 <td width="98%">'.t3lib_BEfunc::getRecordTitle($tN,$subrow,1).'</td>
00287                                                         </tr>';
00288 
00289                                                 if ($tN == 'pages' && $c<10)    {
00290                                                         $sub = $this->pageSubContent($subrow['uid'],$c+1);
00291 
00292                                                         if ($sub)       {
00293                                                                 $content.='
00294                                                                         <tr>
00295                                                                                 <td></td>
00296                                                                                 <td></td>
00297                                                                                 <td></td>
00298                                                                                 <td width="98%">'.$sub.'</td>
00299                                                                         </tr>';
00300                                                         }
00301                                                 }
00302                                         }
00303                                 }
00304                         #}
00305                 }
00306 
00307                 return $content ? '<table border="1" cellpadding="1" cellspacing="0" width="100%">'.$content.'</table>' : '';
00308         }
00309 
00310         function lookForOwnVersions($table,$uid)        {
00311                 global $TCA;
00312 
00313                 $versions = t3lib_BEfunc::selectVersionsOfRecord($table, $uid, 'uid');
00314                 if (is_array($versions))        {
00315                         return count($versions);
00316                 }
00317                 return FALSE;
00318         }
00319 
00320         function adminLinks($table,$row)        {
00321                 global $BE_USER;
00322 
00323                 $adminLink = '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick('&edit['.$table.']['.$row['uid'].']=edit',$this->doc->backPath)).'">'.
00324                                                 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/edit2.gif','width="11" height="12"').' alt="" title="Edit"/>'.
00325                                                 '</a>';
00326 
00327                 if ($table == 'pages')  {
00328 
00329                                 // If another page module was specified, replace the default Page module with the new one
00330                         $newPageModule = trim($BE_USER->getTSConfigVal('options.overridePageModule'));
00331                         $pageModule = t3lib_BEfunc::isModuleSetInTBE_MODULES($newPageModule) ? $newPageModule : 'web_layout';
00332 
00333                                 // Perform some acccess checks:
00334                         $a_wl = $BE_USER->check('modules','web_list');
00335                         $a_wp = t3lib_extMgm::isLoaded('cms') && $BE_USER->check('modules',$pageModule);
00336 
00337                         $adminLink.='<a href="#" onclick="top.loadEditId('.$row['uid'].');top.goToModule(\''.$pageModule.'\'); return false;">'.
00338                                                 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,t3lib_extMgm::extRelPath('cms').'layout/layout.gif','width="14" height="12"').' title="" alt="" />'.
00339                                                 '</a>';
00340                         $adminLink.='<a href="#" onclick="top.loadEditId('.$row['uid'].');top.goToModule(\'web_list\'); return false;">'.
00341                                                 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'mod/web/list/list.gif','width="14" height="12"').' title="" alt="" />'.
00342                                                 '</a>';
00343 
00344                                 // "View page" icon is added:
00345                         $adminLink.='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::viewOnClick($row['uid'],$this->doc->backPath,t3lib_BEfunc::BEgetRootLine($row['uid']))).'">'.
00346                                 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/zoom.gif','width="12" height="12"').' title="" alt="" />'.
00347                                 '</a>';
00348                 } else {
00349                         if ($row['pid']==-1)    {
00350                                 $getVars = '&ADMCMD_vPrev['.rawurlencode($table.':'.$row['t3ver_oid']).']='.$row['uid'];
00351 
00352                                         // "View page" icon is added:
00353                                 $adminLink.='<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::viewOnClick($row['_REAL_PID'],$this->doc->backPath,t3lib_BEfunc::BEgetRootLine($row['_REAL_PID']),'','',$getVars)).'">'.
00354                                         '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/zoom.gif','width="12" height="12"').' title="" alt="" />'.
00355                                         '</a>';
00356                         }
00357                 }
00358 
00359                 return $adminLink;
00360         }
00361 }
00362 
00363 
00364 
00365 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/version/cm1/index.php"])       {
00366         include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/version/cm1/index.php"]);
00367 }
00368 
00369 
00370 
00371 
00372 // Make instance:
00373 $SOBE = t3lib_div::makeInstance("tx_version_cm1");
00374 $SOBE->init();
00375 
00376 
00377 $SOBE->main();
00378 $SOBE->printContent();
00379 
00380 ?>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6