Documentation TYPO3 par Ameos

db_new.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-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 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00067 $BACK_PATH='';
00068 require('init.php');
00069 require('template.php');
00070 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
00071 
00072 // ***************************
00073 // Including classes
00074 // ***************************
00075 require_once(PATH_t3lib.'class.t3lib_page.php');
00076 require_once(PATH_t3lib.'class.t3lib_positionmap.php');
00077 require_once(PATH_t3lib.'class.t3lib_pagetree.php');
00078 
00079 
00080 
00081 
00082 
00090 class localPageTree extends t3lib_pageTree {
00091 
00099         function wrapIcon($icon,$row)   {
00100                 return $this->addTagAttributes($icon,' title="id='.htmlspecialchars($row['uid']).'"');
00101         }
00102 
00110         function expandNext($id)        {
00111                 return $id==$GLOBALS['SOBE']->id ? 1 : 0;
00112         }
00113 }
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00128 class SC_db_new {
00129         var $pageinfo;
00130         var $pidInfo;
00131         var $newPagesInto;
00132         var $newContentInto;
00133         var $newPagesAfter;
00134         var $web_list_modTSconfig;
00135         var $allowedNewTables;
00136         var $web_list_modTSconfig_pid;
00137         var $allowedNewTables_pid;
00138         var $code;
00139         var $R_URI;
00140 
00141                 // Internal, static: GPvar
00142         var $id;                        // see init()
00143         var $returnUrl;         // Return url.
00144         var $pagesOnly;         // pagesOnly flag.
00145 
00146                 // Internal
00147         var $perms_clause;      // see init()
00148         var $doc;                       // see init()
00149         var $content;           // Accumulated HTML output
00150 
00151 
00157         function init() {
00158                 global $BE_USER,$LANG,$BACK_PATH;
00159 
00160                         // page-selection permission clause (reading)
00161                 $this->perms_clause = $BE_USER->getPagePermsClause(1);
00162 
00163                         // Setting GPvars:
00164                 $this->id = intval(t3lib_div::_GP('id'));       // The page id to operate from
00165                 $this->returnUrl = t3lib_div::_GP('returnUrl');
00166                 $this->pagesOnly = t3lib_div::_GP('pagesOnly');
00167 
00168                         // Create instance of template class for output
00169                 $this->doc = t3lib_div::makeInstance('mediumDoc');
00170                 $this->doc->backPath = $BACK_PATH;
00171                 $this->doc->docType= 'xhtml_trans';
00172                 $this->doc->JScode='';
00173 
00174                         // Creating content
00175                 $this->content='';
00176                 $this->content.=$this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.pagetitle'));
00177                 $this->content.=$this->doc->header($LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.pagetitle'));
00178 
00179                         // Id a positive id is supplied, ask for the page record with permission information contained:
00180                 if ($this->id > 0)      {
00181                         $this->pageinfo = t3lib_BEfunc::readPageAccess($this->id,$this->perms_clause);
00182                 }
00183 
00184                         // If a page-record was returned, the user had read-access to the page.
00185                 if ($this->pageinfo['uid'])     {
00186                                 // Get record of parent page
00187                         $this->pidInfo=t3lib_BEfunc::getRecord('pages',$this->pageinfo['pid']);
00188                                 // Checking the permissions for the user with regard to the parent page: Can he create new pages, new content record, new page after?
00189                         if ($BE_USER->doesUserHaveAccess($this->pageinfo,8))    {
00190                                 $this->newPagesInto=1;
00191                         }
00192                         if ($BE_USER->doesUserHaveAccess($this->pageinfo,16))   {
00193                                 $this->newContentInto=1;
00194                         }
00195 
00196                         if (($BE_USER->isAdmin()||is_array($this->pidInfo)) && $BE_USER->doesUserHaveAccess($this->pidInfo,8))  {
00197                                 $this->newPagesAfter=1;
00198                         }
00199                 } elseif ($BE_USER->isAdmin())  {
00200                                 // Admins can do it all
00201                         $this->newPagesInto=1;
00202                         $this->newContentInto=1;
00203                         $this->newPagesAfter=0;
00204                 } else {
00205                                 // People with no permission can do nothing
00206                         $this->newPagesInto=0;
00207                         $this->newContentInto=0;
00208                         $this->newPagesAfter=0;
00209                 }
00210         }
00211 
00217         function main() {
00218                 global $BE_USER,$LANG;
00219 
00220                         // If there was a page - or if the user is admin (admins has access to the root) we proceed:
00221                 if ($this->pageinfo['uid'] || $BE_USER->isAdmin())      {
00222                                 // Acquiring TSconfig for this module/current page:
00223                         $this->web_list_modTSconfig = t3lib_BEfunc::getModTSconfig($this->pageinfo['uid'],'mod.web_list');
00224                         $this->allowedNewTables = t3lib_div::trimExplode(',',$this->web_list_modTSconfig['properties']['allowedNewTables'],1);
00225 
00226                                 // Acquiring TSconfig for this module/parent page:
00227                         $this->web_list_modTSconfig_pid = t3lib_BEfunc::getModTSconfig($this->pageinfo['pid'],'mod.web_list');
00228                         $this->allowedNewTables_pid = t3lib_div::trimExplode(',',$this->web_list_modTSconfig_pid['properties']['allowedNewTables'],1);
00229 
00230                                 // More init:
00231                         if (!$this->showNewRecLink('pages'))    {
00232                                 $this->newPagesInto=0;
00233                         }
00234                         if (!$this->showNewRecLink('pages',$this->allowedNewTables_pid))        {
00235                                 $this->newPagesAfter=0;
00236                         }
00237 
00238 
00239                                 // Set header-HTML and return_url
00240                         $this->code=$this->doc->getHeader('pages',$this->pageinfo,$this->pageinfo['_thePath']).'<br />
00241                         ';
00242                         $this->R_URI=$this->returnUrl;
00243 
00244                                 // GENERATE the HTML-output depending on mode (pagesOnly is the page wizard)
00245                         if (!$this->pagesOnly)  {       // Regular new element:
00246                                 $this->regularNew();
00247                         } elseif ($this->showNewRecLink('pages')) {     // Pages only wizard
00248                                 $this->pagesOnly();
00249                         }
00250 
00251                                 // Create go-back link.
00252                         if ($this->R_URI)       {
00253                                 $this->code.='<br />
00254                 <a href="'.htmlspecialchars($this->R_URI).'" class="typo3-goBack">'.
00255                 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/goback.gif','width="14" height="14"').' alt="" />'.
00256                 $LANG->getLL('goBack',1).
00257                 '</a>';
00258                         }
00259                                 // Add all the content to an output section
00260                         $this->content.=$this->doc->section('',$this->code);
00261                 }
00262         }
00263 
00269         function pagesOnly()    {
00270                 global $LANG;
00271 
00272                 $posMap = t3lib_div::makeInstance('t3lib_positionMap');
00273                 $this->code.='
00274                         <h3>'.htmlspecialchars($LANG->getLL('selectPosition')).':</h3>
00275                 ';
00276                 $this->code.= $posMap->positionTree($this->id,$this->pageinfo,$this->perms_clause,$this->R_URI);
00277 
00278                                 // Add CSH:
00279                 $this->code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_pages', $GLOBALS['BACK_PATH'],'<br/>');
00280         }
00281 
00287         function regularNew()   {
00288                 global $BE_USER,$LANG,$BACK_PATH,$TCA;
00289 
00290                 $doNotShowFullDescr = FALSE;
00291 
00292                         // Slight spacer from header:
00293                 $this->code.='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/halfline.gif','width="18" height="8"').' alt="" /><br />';
00294 
00295                         // Initialize array for accumulating table rows:
00296                 $tRows = array();
00297 
00298                         // New pages INSIDE this pages
00299                 if ($this->newPagesInto && $this->isTableAllowedForThisPage($this->pageinfo, 'pages') && $BE_USER->check('tables_modify','pages'))      {
00300 
00301                                 // Create link to new page inside:
00302                         $t = 'pages';
00303                         $v = $TCA[$t];
00304                         $rowContent = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/join.gif','width="18" height="16"').' alt="" />'.
00305                                         $this->linkWrap(
00306                                                 '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/i/'.($v['ctrl']['iconfile'] ? $v['ctrl']['iconfile'] : $t.'.gif'),'width="18" height="16"').' alt="" />'.
00307                                                         $LANG->sL($v['ctrl']['title'],1).' ('.$LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.inside',1).')',
00308                                                 $t,
00309                                                 $this->id).'<br/>';
00310 
00311                                 // Link to page-wizard:
00312                         $rowContent.= '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/line.gif','width="18" height="16"').' alt="" /><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/joinbottom.gif','width="18" height="16"').' alt="" />'.
00313                                 '<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly'=>1))).'">'.
00314                                 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_page.gif','width="13" height="12"').' alt="" /> '.
00315                                 htmlspecialchars($LANG->getLL('clickForWizard')).
00316                                 '</a>';
00317                                 // Half-line:
00318                         $rowContent.= '<br /><img'.t3lib_iconWorks::skinImg('','gfx/ol/halfline.gif','width="18" height="8"').' alt="" />';
00319 
00320                                 // Compile table row:
00321                         $tRows[]='
00322                                 <tr>
00323                                         <td nowrap="nowrap">'.$rowContent.'</td>
00324                                         <td>'.t3lib_BEfunc::cshItem($t,'',$GLOBALS['BACK_PATH'],'',$doNotShowFullDescr).'</td>
00325                                 </tr>
00326                         ';
00327                 }
00328 
00329                         // New tables (but not pages) INSIDE this pages
00330                 if ($this->newContentInto)      {
00331                         if (is_array($TCA))     {
00332                                 foreach($TCA as $t => $v)       {
00333                                         if ($t!='pages'
00334                                                         && $this->showNewRecLink($t)
00335                                                         && $this->isTableAllowedForThisPage($this->pageinfo, $t)
00336                                                         && $BE_USER->check('tables_modify',$t)
00337                                                         && (($v['ctrl']['rootLevel'] xor $this->id) || $v['ctrl']['rootLevel']==-1)
00338                                                         )       {
00339 
00340                                                         // Create new link for record:
00341                                                 $rowContent = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/join.gif','width="18" height="16"').' alt="" />'.
00342                                                                 $this->linkWrap(
00343                                                                 t3lib_iconWorks::getIconImage($t,array(),$BACK_PATH,'').
00344                                                                 $LANG->sL($v['ctrl']['title'],1)
00345                                                         ,$t
00346                                                         ,$this->id);
00347 
00348                                                         // If the table is 'tt_content' (from "cms" extension), create link to wizard
00349                                                 if ($t=='tt_content')   {
00350 
00351                                                                 // If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's wizard instead:
00352                                                         $overrideExt = $this->web_list_modTSconfig['properties']['newContentWiz.']['overrideWithExtension'];
00353                                                         $pathToWizard = (t3lib_extMgm::isLoaded($overrideExt)) ? (t3lib_extMgm::extRelPath($overrideExt).'mod1/db_new_content_el.php') : 'sysext/cms/layout/db_new_content_el.php';
00354 
00355                                                         $href = $pathToWizard.'?id='.$this->id.'&returnUrl='.rawurlencode($this->R_URI);
00356                                                         $rowContent.= '<br /><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/line.gif','width="18" height="16"').' alt="" />'.
00357                                                                                 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/joinbottom.gif','width="18" height="16"').' alt="" />'.
00358                                                                                 '<a href="'.htmlspecialchars($href).'"><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_record.gif','width="16" height="12"').' alt="" /> '.
00359                                                                                 htmlspecialchars($LANG->getLL('clickForWizard')).
00360                                                                                 '</a>';
00361 
00362                                                                 // Half-line added:
00363                                                         $rowContent.= '<br /><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/halfline.gif','width="18" height="8"').' alt="" />';
00364                                                 }
00365 
00366 
00367                                                         // Compile table row:
00368                                                 $tRows[] = '
00369                                 <tr>
00370                                         <td nowrap="nowrap">'.$rowContent.'</td>
00371                                         <td>'.t3lib_BEfunc::cshItem($t,'',$GLOBALS['BACK_PATH'],'',$doNotShowFullDescr).'</td>
00372                                 </tr>
00373                         ';
00374 
00375                                         }
00376                                 }
00377                         }
00378                 }
00379 
00380                         // New pages AFTER this pages
00381                 if ($this->newPagesAfter && $this->isTableAllowedForThisPage($this->pidInfo,'pages') && $BE_USER->check('tables_modify','pages'))       {
00382 
00383                                 // Create link to new page after
00384                         $t = 'pages';
00385                         $v = $TCA[$t];
00386                         $rowContent = $this->linkWrap(
00387                                         t3lib_iconWorks::getIconImage($t,array(),$BACK_PATH,'').
00388                                                 $LANG->sL($v['ctrl']['title'],1).' ('.$LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.after',1).')',
00389                                         'pages',
00390                                         -$this->id
00391                                 );
00392 
00393                                 // Compile table row:
00394                         $tRows[] = '
00395                                 <tr>
00396                                         <td nowrap="nowrap">'.$rowContent.'</td>
00397                                         <td>'.t3lib_BEfunc::cshItem($t,'',$GLOBALS['BACK_PATH'],'',$doNotShowFullDescr).'</td>
00398                                 </tr>
00399                         ';
00400                 } else {
00401                                 // Compile table row:
00402                         $tRows[]='
00403                                 <tr>
00404                                         <td><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/stopper.gif','width="18" height="16"').' alt="" /></td>
00405                                         <td></td>
00406                                 </tr>
00407                         ';
00408                 }
00409 
00410                         // Make table:
00411                 $this->code.='
00412                         <table border="0" cellpadding="0" cellspacing="0" id="typo3-newRecord">
00413                         '.implode('',$tRows).'
00414                         </table>
00415                 ';
00416 
00417                         // Create a link to the new-pages wizard.
00418                 if ($this->showNewRecLink('pages'))     {
00419                         $this->code.='
00420 
00421                                 <!--
00422                                         Link; create new page:
00423                                 -->
00424                                 <div id="typo3-newPageLink">
00425                                         <a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly'=>'1'))).'">'.
00426                                         '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_page.gif','width="13" height="12"').' alt="" />'.
00427                                         htmlspecialchars($LANG->getLL('createNewPage')).
00428                                         '</a>
00429                                 </div>
00430                                 ';
00431                 }
00432 
00433                         // Add CSH:
00434                 $this->code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_regular', $GLOBALS['BACK_PATH'],'<br/>');
00435         }
00436 
00442         function printContent() {
00443                 $this->content.= $this->doc->endPage();
00444                 echo $this->content;
00445         }
00446 
00456         function linkWrap($code,$table,$pid,$addContentTable=0) {
00457                 $params = '&edit['.$table.']['.$pid.']=new'.
00458                         ($table=='pages'
00459                                 && $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']
00460                                 && isset($GLOBALS['TCA'][$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']])
00461                                 && $addContentTable     ?
00462                                 '&edit['.$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'].'][prev]=new&returnNewPageId=1'     :
00463                                 ''
00464                         );
00465                 $onClick = t3lib_BEfunc::editOnClick($params,'',$this->returnUrl);
00466                 return '<a href="#" onclick="'.htmlspecialchars($onClick).'">'.$code.'</a>';
00467         }
00468 
00476         function isTableAllowedForThisPage($pid_row, $checkTable)       {
00477                 global $TCA, $PAGES_TYPES;
00478                 if (!is_array($pid_row))        {
00479                         if ($GLOBALS['BE_USER']->user['admin']) {
00480                                 return true;
00481                         } else {
00482                                 return false;
00483                         }
00484                 }
00485                         // be_users and be_groups may not be created anywhere but in the root.
00486                 if ($checkTable=='be_users' || $checkTable=='be_groups')        {
00487                         return false;
00488                 }
00489                         // Checking doktype:
00490                 $doktype = intval($pid_row['doktype']);
00491                 if (!$allowedTableList = $PAGES_TYPES[$doktype]['allowedTables'])       {
00492                         $allowedTableList = $PAGES_TYPES['default']['allowedTables'];
00493                 }
00494                 if (strstr($allowedTableList,'*') || t3lib_div::inList($allowedTableList,$checkTable))  {               // If all tables or the table is listed as a allowed type, return true
00495                         return true;
00496                 }
00497         }
00498 
00506         function showNewRecLink($table,$allowedNewTables='')    {
00507                 $allowedNewTables = is_array($allowedNewTables) ? $allowedNewTables : $this->allowedNewTables;
00508                 return !count($allowedNewTables) || in_array($table,$allowedNewTables);
00509         }
00510 }
00511 
00512 // Include extension?
00513 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/db_new.php'])        {
00514         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/db_new.php']);
00515 }
00516 
00517 
00518 
00519 
00520 
00521 // Make instance:
00522 $SOBE = t3lib_div::makeInstance('SC_db_new');
00523 $SOBE->init();
00524 $SOBE->main();
00525 $SOBE->printContent();
00526 ?>


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