TYPO3 API  SVNRelease
class.tx_recycler_helper.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2009-2011 Julian Kleinhans <typo3@kj187.de>
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 ***************************************************************/
00024 /**
00025  * Helper class for the 'recycler' extension.
00026  *
00027  * @author  Julian Kleinhans <typo3@kj187.de>
00028  * @package TYPO3
00029  * @subpackage  tx_recycler
00030  * @version $Id: class.tx_recycler_helper.php 10120 2011-01-18 20:03:36Z ohader $
00031  */
00032 class tx_recycler_helper {
00033 
00034     /************************************************************
00035      * USER ACCESS
00036      *
00037      *
00038      ************************************************************/
00039 
00040     /**
00041      * Checks the page access rights (Code for access check mostly taken from alt_doc.php)
00042      * as well as the table access rights of the user.
00043      *
00044      * @param   string      $cmd: The command that sould be performed ('new' or 'edit')
00045      * @param   string      $table: The table to check access for
00046      * @param   string      $theUid: The record uid of the table
00047      * @return  boolean     Returns true is the user has access, or false if not
00048      */
00049     public static function checkAccess($table, $row) {
00050         // Checking if the user has permissions? (Only working as a precaution, because the final permission check is always down in TCE. But it's good to notify the user on beforehand...)
00051         // First, resetting flags.
00052         $hasAccess = 0;
00053         $deniedAccessReason = '';
00054 
00055         $calcPRec = $row;
00056         t3lib_BEfunc::fixVersioningPid($table,$calcPRec);
00057         if (is_array($calcPRec)) {
00058             if ($table=='pages') {  // If pages:
00059                 $CALC_PERMS = $GLOBALS['BE_USER']->calcPerms($calcPRec);
00060                 $hasAccess = $CALC_PERMS & 2 ? 1 : 0;
00061             } else {
00062                 $CALC_PERMS = $GLOBALS['BE_USER']->calcPerms(t3lib_BEfunc::getRecord('pages',$calcPRec['pid']));    // Fetching pid-record first.
00063                 $hasAccess = $CALC_PERMS & 16 ? 1 : 0;
00064             }
00065                     // Check internals regarding access:
00066             if ($hasAccess) {
00067                 $hasAccess = $GLOBALS['BE_USER']->recordEditAccessInternals($table, $calcPRec);
00068             }
00069         }
00070 
00071 
00072         if (!$GLOBALS['BE_USER']->check('tables_modify', $table)) {
00073             $hasAccess = 0;
00074         }
00075 
00076         if (!$hasAccess) {
00077             $deniedAccessReason = $GLOBALS['BE_USER']->errorMsg;
00078             if ($deniedAccessReason) {
00079                 //fb($deniedAccessReason);
00080             }
00081         }
00082 
00083         return $hasAccess ? true : false;
00084     }
00085 
00086     /**
00087      * Returns the path (visually) of a page $uid, fx. "/First page/Second page/Another subpage"
00088      * Each part of the path will be limited to $titleLimit characters
00089      * Deleted pages are filtered out.
00090      *
00091      * @param   integer     Page uid for which to create record path
00092      * @param   string      $clause is additional where clauses, eg. "
00093      * @param   integer     Title limit
00094      * @param   integer     Title limit of Full title (typ. set to 1000 or so)
00095      * @return  mixed       Path of record (string) OR array with short/long title if $fullTitleLimit is set.
00096      */
00097     public static function getRecordPath($uid, $clause='', $titleLimit=1000, $fullTitleLimit = 0) {
00098         $loopCheck = 100;
00099         $output = $fullOutput = '/';
00100 
00101         while ($uid != 0 && $loopCheck > 0) {
00102             $loopCheck--;
00103             $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00104                 'uid,pid,title,deleted,t3ver_oid,t3ver_wsid,t3ver_swapmode',
00105                 'pages',
00106                 'uid=' . intval($uid) . (strlen(trim($clause)) ? ' AND ' . $clause : '')
00107             );
00108 
00109             if (is_resource($res)) {
00110                 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00111                 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00112 
00113                 t3lib_BEfunc::workspaceOL('pages', $row);
00114                 if (is_array($row)) {
00115                     t3lib_BEfunc::fixVersioningPid('pages', $row);
00116 
00117                     if ($row['_ORIG_pid'] && $row['t3ver_swapmode'] > 0) {  // Branch points
00118                         $output = ' [#VEP#]' . $output;     // Adding visual token - Versioning Entry Point - that tells that THIS position was where the versionized branch got connected to the main tree. I will have to find a better name or something...
00119                     }
00120                     $uid = $row['pid'];
00121                     $output = '/' . t3lib_div::fixed_lgd_cs(strip_tags($row['title']), $titleLimit) . $output;
00122 
00123                     if ($row['deleted']) {
00124                         $output = '<span class="deletedPath">' . $output . '</span>';
00125                     }
00126 
00127                     if ($fullTitleLimit) $fullOutput = '/' . t3lib_div::fixed_lgd_cs(strip_tags($row['title']), $fullTitleLimit) . $fullOutput;
00128                 } else {
00129                     break;
00130                 }
00131             } else {
00132                 break;
00133             }
00134         }
00135 
00136         if ($fullTitleLimit) {
00137             return array($output, $fullOutput);
00138         } else {
00139             return $output;
00140         }
00141     }
00142 
00143     /**
00144      * Gets the name of the field with the information whether a record is deleted.
00145      *
00146      * @param   string      $tableName: Name of the table to get the deleted field for
00147      * @return  string      Name of the field with the information whether a record is deleted
00148      */
00149     public static function getDeletedField($tableName) {
00150         $TCA = self::getTableTCA($tableName);
00151         if ($TCA && isset($TCA['ctrl']['delete']) && $TCA['ctrl']['delete']) {
00152             return $TCA['ctrl']['delete'];
00153         }
00154     }
00155 
00156     /**
00157      * Gets the TCA of the table used in the current context.
00158      *
00159      * @param   string      $tableName: Name of the table to get TCA for
00160      * @return  mixed       TCA of the table used in the current context (array)
00161      *                      or false (boolean) if something went wrong
00162      */
00163     public static function getTableTCA($tableName) {
00164         $TCA = false;
00165         if (isset($GLOBALS['TCA'][$tableName])) {
00166             $TCA = $GLOBALS['TCA'][$tableName];
00167         }
00168         return $TCA;
00169     }
00170 
00171     /**
00172      * Gets the current backend charset.
00173      *
00174      * @return  string      The current backend charset
00175      */
00176     public static function getCurrentCharset() {
00177         return $GLOBALS['LANG']->csConvObj->parse_charset($GLOBALS['LANG']->charSet);
00178     }
00179 
00180     /**
00181      * Determines whether the current charset is not UTF-8
00182      *
00183      * @return  boolean     Whether the current charset is not UTF-8
00184      */
00185     public static function isNotUtf8Charset() {
00186         return (self::getCurrentCharset() !== 'utf-8');
00187     }
00188 
00189     /**
00190      * Gets an UTF-8 encoded string (only if the current charset is not UTF-8!).
00191      *
00192      * @param   string      $string: String to be converted to UTF-8 if required
00193      * @return  string      UTF-8 encoded string
00194      */
00195     public static function getUtf8String($string) {
00196         if (self::isNotUtf8Charset()) {
00197             $string = $GLOBALS['LANG']->csConvObj->utf8_encode(
00198                 $string,
00199                 self::getCurrentCharset()
00200             );
00201         }
00202         return $string;
00203     }
00204 }
00205 
00206 
00207 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/recycler/classes/helper/class.tx_recycler_helper.php'])) {
00208     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/recycler/classes/helper/class.tx_recycler_helper.php']);
00209 }
00210 
00211 ?>