Documentation TYPO3 par Ameos |
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-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 * 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 ***************************************************************/ 00033 class freesite_admin { 00034 00035 // internal 00036 var $data = array(); // Incoming data 00037 var $check = array(); // Tells which fields are still not OK. 00038 var $fieldsArray=array(); 00039 var $HIDDEN_FIELDS=""; // Used to accumulate hidden-fields 00040 var $ALL_OK=""; // This flag is set IF data has been input and they verify OK! 00041 var $verificationOK=""; // If this flag is set, then we're going to create the user!!! 00042 var $verificationCode=""; 00043 var $noDomainURL=""; // noDomainUrl is now the url (without http://) to the site. It's prepended with a slash. 00044 00045 // Internal - create 00046 var $groupTemplate = ""; // The users own group will be modelled after this group (be a copy) 00047 var $groupGeneral = ""; // The user becomes a member of this group, which should be about general configuration for all users. 00048 var $newsite_page = ""; 00049 var $groupData=array(); 00050 var $userData=array(); 00051 var $user_uid = ""; 00052 var $userGroup_uid = ""; 00053 00054 // *********************** 00055 // Default Configuration: 00056 // *********************** 00057 var $sysConfig = Array ( 00058 "backendOnly" => 1, // Boolean: If set, then the module will check for a backend login. If false, everyone can create a new site with the module at typo3conf/freesite/ 00059 "emailHeader" => "From: TYPO3 Freesite Creator <>", // Header data for the emails send from the Freesite module 00060 // ********************************** 00061 // ENTERING DATA: 00062 // ********************************** 00063 // Configuration of features and how data is processed. 00064 "pid_templateArchive" => 0, // PID: The PID (pages-uid) of the template archive. If 0 (zero), no template is created for the new site. If archive has no templates in it, the site gets an empty template. The archive folder should be a "sysFolder" -> In the template archive you should put template-records that you want the new websites to be "based on". Templates in subpages in the archive are also selectable. 00065 "pid_dummyPagesArchive" => 0, // PID: The PID of the dummy page archive. If 0 (zero), no dummy pages are created for the new site. REMEMBER that the user MUST have read access to the dummy pages. Any pages, the user cannot read are (of course) not copied! The archive folder should be a "sysFolder" -> In the dummy page archive you should create pages with subpages that represent initial page structures for new sites created. Every page in the root of the dummy page archive represents a page-structure, and only sub- and subsub-pages are copied. 00066 "exclude_templateSelect" => 0, // Boolean: If set, you will NOT be able to select a template with this module. The default template however will be the first template found in the archive. 00067 "exclude_dummyPages" => 0, // Boolean: If set, you will NOT be able to select a dummy page set with this module. The default dummy page set will be the first set found in the archive. 00068 "previewData" => 0, // Boolean: If set, the data entered in the module will be displayed for preview first! Previewing the entered data is a state between creation and modification of data, where the data is not editable and presented as ordinary text on the screen before final approval. Preview ENABLES the use of emailVerification... + the label "label_Preview" 00069 "emailVerification" => 1, // Boolean: If set AND if previewData is enabled, the preview state of the module will send an email to the entered email-address with a verification-code. This code must be copy/pasted into a form-field and if the code is correct, the site will be created. This feature provides a way to verify the email-address of the user that is creating a website. 00070 "emailVerificationSubject" => "Freesite Verification Code", // String: Subject of the verification code email 00071 "emailVerificationMessage" => "This is the verification code from the automatic site-creation tool. Just enter this code into the code-field on the website.", // String: Body of the verification code email 00072 "virtualDirRequired" => 0, // Boolean: If set, virtual directory MUST be entered! 00073 "defaultLanguage" => "", // Default value for the language if not sent with form. Values must be from the current selection of TYPO3 language keys. 00074 00075 "defaultFormField_sitetitle" => "TITLE", // Name of the form-field (eg. "TITLE" for the default field), which content should be made the site-title of the template in case it's not set. 00076 00077 // Template, HTML-formatting, messages and labels 00078 "templateFile" => "", // Filereference: (relative to sitePath) reference to a custom html-file to use as template. Default is "template.html". Look in this file to see how it works... (###.....### marks are substituted) 00079 "templateFile_selectTemplate" => "", // Filereference: (relative to sitePath) reference to a custom html-file to use as template for display of template options. Default is "template.html". Look in this file to see how it works... (###.....### marks are substituted) 00080 "templateFile_selectPages" => "", // Filereference: (relative to sitePath) reference to a custom html-file to use as template for display of page options. Default is "template.html". Look in this file to see how it works... (###.....### marks are substituted) 00081 "inputFieldParams" => 'size=55', // String: HTML <input>-tag parameters for the form. Primarily used to set the size/max of all the form-fields. 00082 "notCorrectHTML" => '<BR><img src="../../../t3lib/gfx/icon_fatalerror.gif" width=18 height=16 align=top> ', // HTML-code that displays a warning that this field has not been correctly filled 00083 "msgBadUsername" => 'The username is too short or it exists allready. Please enter another one.', 00084 "msgBadPassword" => 'The password is too short.', 00085 "msgBadEmail" => 'This is not a valid email address.', 00086 "msgBadPath" => 'This directory is in use allready (or not allowed).', 00087 "msgBadDomain" => 'This domain-name is not valid.', 00088 "msgBadDomain_used" => 'The domain is allready used in TYPO3', 00089 "msgBadValue" => 'This field is required!', 00090 "msgEmailVerificationCode" => '<B>EMAIL Verification:</b><BR>A verification code has been send to <i>%s</i>. Read your mail and enter the code in this field in order to continue!<BR>', // String: The content of this variable is displayed as a message before the field in which the code should be entered. 00091 "label_Update" => 'Update information', 00092 "label_Return" => 'Make changes', 00093 "label_Preview" => 'Freeze information', 00094 "label_Create" => 'Create site!', 00095 00096 "templateFile_selectTemplate" => "", // Filereference: (relative to sitePath) reference to a custom html-file to use as template for display of template options. Default is "template.html". Look in this file to see how it works... (###.....### marks are substituted) 00097 "templateFile_selectPages" => "", // Filereference: (relative to sitePath) reference to a custom html-file to use as template for display of page options. Default is "template.html". Look in this file to see how it works... (###.....### marks are substituted) 00098 "templateSelect_noInfoLink" => 0, // Boolean: If set, there will be NO info-link at each of the templates in the list. 00099 00100 // ********************************** 00101 // CREATE SITE: 00102 // ********************************** 00103 // ID's 00104 "testingOnly" => 0, // Boolean. If set, NOTHING is put in the database and no directories are created. Just testing the submitted values (which are printed with the debug()-function) 00105 "pid_newsite" => 0, // PID: The pages-uid under which new sites are created! If this is NOT set and valid, users will not get a new site!! (So this affects everything). Users will just be created with their group and any optional user-/groupHomeDir 00106 "uid_templateGroup" => 0, // be_groups-UID, Optional: The user-group to use as a model for the created usergroups! What this means is that certain fields from this groups is directly copied to the created groups! The fields are: (inc_access_lists,non_exclude_fields,pagetypes_select,tables_select,tables_modify,groupMods,db_mountpoints,db_mountpoints,file_mountpoints). See tables.php for further information. 00107 "uid_generalGroup" => 0, // be_groups-UID, Optional: The user-group to use as a secondary group for all created users. New users will be a member of their own group + this group (if it exists). Good trick is to include this general group as a subgroup of the template group. This way new users to the site needs only being members of the template group and not both... 00108 // Create features: 00109 "create_lockToDomain" => 1, // Boolean: If set, the users and groups are locked to their domains, if domain is entered. LockToDomain is a feature that lets users login (and groups be enabled) only from that domain! 00110 "create_fileoper_perms_default" => 7, // Integer/Bits: Default value for the be_users.fileoper_perms field. See the item in tables.php for further details. "7" enables the user to do most basic fileoperations. 00111 "createDomains" => 1, // Boolean. If set, a sys_domain record will be created for the site IF either a domain-name or virtual-directory is given. 00112 "createVirtualDirs" => 0, // Boolean. If set, a virtual-directory in the root of the typo3-site is created. This REQUIRES a domain-record and therefore "createDomains" must be enabled for this feature to work. Does not work on Windows. -> A virtual directory is a directory that consists of softlinks to the majority of files/folders in the root of the typo3-site. This feature provides a way to let "http://www.typo3.com/man_uk/" go to a specific page (site) in the page-structure. 00113 "createNewGroupDir" => 0, // Boolean. If set and $TYPO3_CONF_VARS["BE"]["groupHomePath"] is set and valid, a new directory for the group is created here! (that is a directory with the number "be_groups.uid" of the usergroup) 00114 "createNewUserDir" => 0, // Boolean. If set and $TYPO3_CONF_VARS["BE"]["userHomePath"] is set, a new directory for the user is created here! NORMALLY just create a group-dir. Should be sufficient for most cases. (that is a directory with the number "be_users.uid" of the new user) 00115 // Messages, template 00116 "templateFile_created" => "", // Filereference: (relative to PATH_site) reference to a custom html-file to use as template after the site has been created. Default is "template_created.html". Look in this file to see how it works... (###.....### marks are substituted) 00117 "notify_email" => "", // Email-addr: Enter email-adress to be notified when a site is created. (admin notification) 00118 "notifyUser_email" => 1, // Boolean. Sends username and password to the user when site is created! 00119 "notifyUser_emailSubject" => 'TYPO3 Freesite Created', 00120 "notifyUser_emailMessage" => ' 00121 The new TYPO3 site has been created for you! 00122 00123 The website is found at: ###WEBSITE_URL### 00124 00125 Username: ###USERNAME### 00126 Password: ###PASSWORD### 00127 00128 You enter the administration site at : 00129 ###LINK_URL### 00130 00131 Kind regards. 00132 ' 00133 ); 00134 00135 var $backPath = ""; 00136 var $genTree_HTML = ""; 00137 00138 00139 00143 function freesite_admin () { 00144 $this->backPath = $GLOBALS["BACK_PATH"]; 00145 00146 $extConf = unserialize($GLOBALS["TYPO3_CONF_VARS"]["EXT"]["extConf"]["freesite"]); 00147 if (!is_array($extConf)) { 00148 t3lib_BEfunc::typo3PrintError ("Configuration Error","No configuration found written to localconf.php. Please go to the Extension Manager, click the title of the Freesite extension and configure this module with the form in the bottom of the page!",0); 00149 exit; 00150 } 00151 00152 $this->sysConfig = array_merge($this->sysConfig,$extConf); // Candidate for t3lib_div::array_merge() if integer-keys will some day make trouble... 00153 if (!$this->sysConfig["notify_email"]) $this->sysConfig["notify_email"] = $TYPO3_CONF_VARS["BE"]["warning_email_addr"]; 00154 00155 00156 // If windows, createVirtualDirs is disabled. Filesystem specific. 00157 if (TYPO3_OS=="WIN") { 00158 $this->sysConfig["createVirtualDirs"]==0; // Virtual dirs does not work on windows as we're using softlinks (UNIX-thing) 00159 } 00160 00161 00162 // ****************************** 00163 // Checking backend user login? 00164 // ****************************** 00165 if ($this->sysConfig["backendOnly"]) { 00166 if (!$GLOBALS["BE_USER"]->user["uid"]) { 00167 t3lib_BEfunc::typo3PrintError ("Login-error","No user logged in! Sorry, I can't proceed then!",0); 00168 exit; 00169 } 00170 $GLOBALS["BE_USER"]->modAccess($GLOBALS["MCONF"],1); 00171 } 00172 } 00173 00174 00178 function genTree($theID, $depthData) { 00179 // Generates a list of Page-uid's that corresponds to the tables in the tree. This list should ideally include all records in the pages-table. 00180 $a=0; 00181 00182 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,title,doktype,hidden,deleted', 'pages', 'pid='.intval($theID).' AND NOT deleted', '', 'sorting'); 00183 $c = $GLOBALS['TYPO3_DB']->sql_num_rows($res); 00184 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00185 $a++; 00186 $newID =$row[uid]; 00187 00188 $this->genTree_HTML.="\n<DIV><NOBR>"; 00189 $PM = "join"; 00190 $LN = ($a==$c)?"blank":"line"; 00191 $BTM = ($a==$c)?"bottom":""; 00192 $this->genTree_HTML.= $depthData.'<IMG src="'.$this->backPath.'t3lib/gfx/ol/'.$PM.$BTM.'.gif" width="18" height="16" align="top"><IMG src="'.$this->backPath.'gfx/i/pages.gif" width="18" height="16" align="top">'.t3lib_div::fixed_lgd(strip_tags($row[title]),50).'</NOBR></DIV>'; 00193 $this->genTree($newID,$this->genTree_HTML ? $depthData.'<IMG src="'.$this->backPath.'t3lib/gfx/ol/'.$LN.'.gif" width="18" height="16" align="top">' : ''); 00194 } 00195 } 00196 00200 function doesExist($table,$field,$value) { 00201 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, $field.'="'.$GLOBALS['TYPO3_DB']->quoteStr($value, $table).'"'); 00202 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00203 return $row; 00204 } 00205 } 00206 00210 function getInputData($fieldName,$hsc=0) { 00211 $out = $this->data[$fieldName]; 00212 if ($hsc) { 00213 $out=htmlspecialchars($out); 00214 } 00215 return $out; 00216 } 00217 00221 function isCorrect($fieldName) { 00222 if (isset($this->check[$fieldName])) { 00223 return $this->sysConfig["notCorrectHTML"].$this->check[$fieldName].'<BR>'; 00224 } 00225 } 00226 00230 function cleanFileName($fileName) { 00231 // Returns a string where any character not matching [a-zA-Z0-9_-] is substituted by "_" 00232 $theNewName = ereg_replace("[^\.[:alnum:]_-]","_",trim($fileName)); 00233 return substr($theNewName,0,50); 00234 } 00235 00239 function rmSlash($string) { 00240 return ereg_replace("\/$","",$string); 00241 } 00242 00246 function rmDoubleSlash($string) { 00247 return str_replace("//","/",$string); 00248 } 00249 00250 00254 function getSubpart($content, $marker) { 00255 if ($marker && strstr($content,$marker)) { 00256 $start = strpos($content, $marker)+strlen($marker); 00257 $stop = @strpos($content, $marker, $start+1); 00258 $sub = substr($content, $start, $stop-$start); 00259 00260 $reg=Array(); 00261 ereg("^[^<]*-->",$sub,$reg); 00262 $start+=strlen($reg[0]); 00263 00264 $reg=Array(); 00265 ereg("<!--[^>]*$",$sub,$reg); 00266 $stop-=strlen($reg[0]); 00267 00268 return substr($content, $start, $stop-$start); 00269 } 00270 } 00271 00275 function substituteSubpart($content,$marker,$subpartContent,$recursive=1) { 00276 // This function substitutes a subpart in $content with the content of $subpartContent. 00277 // If $recursive is set, the function calls itself with the content set to the remaining part of the content after the second marker. This means that proceding subparts are ALSO substituted! 00278 // If $subpartContent happens to be an array, it's [0] and [1] elements are wrapped around the content of the subpart (fetched by $this->getSubpart()) 00279 $start = strpos($content, $marker); 00280 $stop = @strpos($content, $marker, $start+1)+strlen($marker); 00281 if ($start && $stop>$start) { 00282 // code before 00283 $before = substr($content, 0, $start); 00284 $reg=Array(); 00285 ereg("<!--[^>]*$",$before,$reg); 00286 $start-=strlen($reg[0]); 00287 $before = substr($content, 0, $start); 00288 // code after 00289 $after = substr($content, $stop); 00290 $reg=Array(); 00291 ereg("^[^<]*-->",$after,$reg); 00292 $stop+=strlen($reg[0]); 00293 $after = substr($content, $stop); 00294 // replace? 00295 if (is_array($subpartContent)) { 00296 $substContent=$subpartContent[0].$this->getSubpart($content,$marker).$subpartContent[1]; 00297 } else { 00298 $substContent=$subpartContent; 00299 } 00300 00301 if ($recursive && strpos($after, $marker)) { 00302 return $before.$substContent.$this->substituteSubpart($after,$marker,$subpartContent); 00303 } else { 00304 return $before.$substContent.$after; 00305 } 00306 } else { 00307 return $content; 00308 } 00309 } 00310 00314 function insertInDatabase($table,$data,$uid=0) { 00315 if ($table && is_array($data)) { 00316 unset($data["uid"]); 00317 00318 if (count($data)) { 00319 if ($this->sysConfig["testingOnly"]) { 00320 debug($table); 00321 debug($data); 00322 00323 if ($uid) { 00324 $query = $GLOBALS['TYPO3_DB']->UPDATEquery($table, 'uid='.intval($uid), $data); 00325 } else { 00326 $query = $GLOBALS['TYPO3_DB']->INSERTquery($table, $data); 00327 } 00328 debug($query,1); 00329 00330 return "99999"; 00331 } else { 00332 if ($uid) { 00333 $res = $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($uid), $data); 00334 } else { 00335 $res = $GLOBALS['TYPO3_DB']->exec_INSERTquery($table, $data); 00336 } 00337 $err = $GLOBALS['TYPO3_DB']->sql_error(); 00338 if ($err) { 00339 debug($err,1); 00340 debug($table,1); 00341 debug($query,1); 00342 00343 exit; 00344 } 00345 return $GLOBALS['TYPO3_DB']->sql_insert_id(); 00346 } 00347 } 00348 } 00349 die("The record could not be inserted or updated! ".$table); 00350 } 00351 00352 00353 00354 00355 00356 00357 00358 00359 00360 00361 00362 00363 00364 00368 function main() { 00369 00370 $this->data = t3lib_div::_POST("data"); 00371 $this->verifyData(); 00372 $this->isReady(); 00373 00374 // *********************** 00375 // Enter/Check data: 00376 // *********************** 00377 if (!$this->verificationOK) { // That is, we're still entering data... opposed to creating the site and records. 00378 $templateCode = $this->enteringData(); 00379 } else { 00380 $templateCode = $this->creatingData(); 00381 } 00382 00383 echo $templateCode; 00384 00385 if ($this->sysConfig["testingOnly"]) { 00386 echo "<HR>"; 00387 debug("DATA:"); 00388 debug($this->data); 00389 } 00390 } 00391 00395 function verifyData() { 00396 // ********************************************* 00397 // Processing Incoming data: 00398 // 00399 // If there has been some incoming data: 00400 // Stripslashes + check the content! 00401 // ********************************************** 00402 if (is_array($this->data)) { 00403 reset($this->data); 00404 while(list($k,$v)=each($this->data)) { 00405 $v=trim($v); 00406 $ok=0; // flag that if set allows a field to be blank. 00407 switch($k) { 00408 case "FIELD_username": 00409 $v=strtolower($v); // Lowercase 00410 $v=$this->cleanFileName($v); // No space 00411 $v=substr($v,0,20); 00412 if (strlen($v)<5 || $this->doesExist("be_users","username",$v)) { 00413 $this->check[$k]=$this->sysConfig["msgBadUsername"]; 00414 } 00415 break; 00416 case "FIELD_email": 00417 if (!ereg("^[A-Za-z0-9\._-]*[@][A-Za-z0-9\._-]*[\.].[A-Za-z0-9]*$",$v)) { 00418 $this->check[$k]=$this->sysConfig["msgBadEmail"]; 00419 } 00420 break; 00421 case "FIELD_password": 00422 if (strlen($v)<5) { 00423 $this->check[$k]=$this->sysConfig["msgBadPassword"]; 00424 } 00425 break; 00426 case "FIELD_lang": 00427 if (!$v) { 00428 $v=$this->sysConfig["defaultLanguage"]; 00429 } 00430 break; 00431 case "TEMPLATE": 00432 case "DUMMY_PAGES": 00433 $v=intval($v); 00434 $ok=1; 00435 break; 00436 case "FOLDER": 00437 $v=str_replace("å","aa",$v); 00438 $v=str_replace("Å","AA",$v); 00439 $v=strtr($v, "áéúíâêûôîæøÁÉÚÍÄËÜÖÏÆØ", "aeuiaeuoieoAEUIAEUOIEO"); 00440 00441 $v=$this->cleanFileName($v); 00442 if ($v && (@file_exists(PATH_site.$v) || ereg("^typo|file|upload|media|t3lib|tslib",$v))) { 00443 $this->check[$k]=$this->sysConfig["msgBadPath"]; 00444 } 00445 if (!$this->sysConfig["virtualDirRequired"]) { 00446 $ok=1; 00447 } 00448 break; 00449 case "DOMAIN": 00450 $v=strtolower($v); 00451 if ($v) { 00452 if (ereg("[^\.a-z0-9_-]",$v) || !strstr($v,".")) { 00453 $this->check[$k]=$this->sysConfig["msgBadDomain"]; 00454 } else { 00455 if ($this->doesExist("sys_domain","domainName",$v)) { 00456 $this->check[$k]=$this->sysConfig["msgBadDomain_used"]; 00457 } 00458 } 00459 } 00460 $ok=1; 00461 break; 00462 CASE "TITLE": 00463 $ok=1; 00464 break; 00465 default: 00466 break; 00467 } 00468 $this->data[$k]=$v; 00469 if (!$this->data[$k] && !$ok) { 00470 $this->check[$k]=$this->sysConfig["msgBadValue"]; 00471 } 00472 } 00473 } 00474 } 00475 00479 function isReady() { 00480 // ******************************************************* 00481 // Verifying if data entering is done 00482 // If $this->verificationOK is set, then the site is created 00483 // ******************************************************* 00484 $this->ALL_OK= (is_array($this->data) && !count($this->check)); // This flag is set IF data has been input and they verify OK! 00485 // Verification code is calculated 00486 $this->verificationOK=""; // If this flag is set, then we're going to create the user!!! 00487 if ($this->ALL_OK) { 00488 ksort($this->data); 00489 $this->verificationCode = strtoupper(substr(md5(serialize($this->data)),0,10)); 00490 00491 $VERIFICATION_CODE = strtoupper(trim(t3lib_div::_POST("VERIFICATION_CODE"))); // The sent ver-code 00492 if (t3lib_div::_POST("createButton")) { // Must press the createButton! 00493 $this->verificationOK = ($VERIFICATION_CODE && !strcmp($VERIFICATION_CODE,$this->verificationCode)); 00494 } 00495 } 00496 } 00497 00498 00499 00500 00501 00502 00503 00504 00505 // ************************** 00506 // 00507 // ENTERING DATA 00508 // 00509 // ************************** 00510 00511 00515 function enteringData() { 00516 // **************** 00517 // Get the template file 00518 // **************** 00519 $templateFile= $this->sysConfig["templateFile"] ? PATH_site.$this->sysConfig["templateFile"] : "template.html"; 00520 $templateCode = t3lib_div::getURL($templateFile); 00521 if (!$templateCode) die("No template file!! (".$templateFile.")"); 00522 00523 00524 $this->fieldsArray["BACK_PATH"]=$this->backPath."../"; 00525 00526 // ************************************ 00527 // Preview of template and page set 00528 // ************************************ 00529 $this->fieldsArray["TEMPLATE_VIEW"]=""; 00530 if ($this->data["TEMPLATE"] && !$this->check["TEMPLATE"]) { 00531 $fN="tmplimages/".$this->data["TEMPLATE"]; 00532 $file=""; 00533 if (@is_file($fN.".gif")) { 00534 $file=$fN.".gif"; 00535 } elseif (@is_file($fN.".jpg")) { 00536 $file=$fN.".jpg"; 00537 } 00538 if (@is_file($file)) { 00539 $fI = @getimagesize($file); 00540 if (is_array($fI)) { 00541 $this->fieldsArray["TEMPLATE_VIEW"]='<BR><img src="'.$file.'" '.$fI[3].'><BR>'; 00542 } 00543 } 00544 } 00545 $this->fieldsArray["DUMMY_PAGES_VIEW"]=""; 00546 if ($this->data["DUMMY_PAGES"] && !$this->check["DUMMY_PAGES"]) { 00547 $this->genTree($this->data["DUMMY_PAGES"],""); 00548 $this->fieldsArray["DUMMY_PAGES_VIEW"]="<BR><BR>".$this->genTree_HTML."<BR>"; 00549 } 00550 00551 00552 00553 if (!$this->ALL_OK || t3lib_div::_POST("updateButton")) { 00554 // If everything is NOT OK or if the updateButton is still pushed: 00555 $this->displayDataForms(); 00556 } else { 00557 // If everything is OK and createButton is pushed: 00558 $this->previewData(); 00559 } 00560 00561 00562 00563 // ***************************** 00564 // Substitute template markers 00565 // ***************************** 00566 $this->fieldsArray["UPDATE_CREATE"].=$this->HIDDEN_FIELDS; 00567 reset($this->fieldsArray); 00568 while(list($key,$content)=each($this->fieldsArray)) { 00569 $templateCode = str_replace("###".$key."###",$content,$templateCode); 00570 } 00571 return $templateCode; 00572 } 00573 00577 function displayDataForms() { 00578 global $TCA; 00579 // ***************************** 00580 // Getting language array 00581 // ***************************** 00582 $languages=array(); 00583 t3lib_div::loadTCA("be_users"); 00584 if ($TCA["be_users"]["columns"]["lang"]) { 00585 reset($TCA["be_users"]["columns"]["lang"]["config"]["items"]); 00586 while(list(,$k)=each($TCA["be_users"]["columns"]["lang"]["config"]["items"])) { 00587 $theK = $k[1] ? $k[1] : "default"; 00588 $languages[$theK]=$GLOBALS["LANG"]->sL($k[0]); 00589 } 00590 } 00591 00592 // ***************************** 00593 // Setting form-field extras 00594 // ***************************** 00595 $params=($this->sysConfig["inputFieldParams"] ? " ".$this->sysConfig["inputFieldParams"] : "") ; 00596 00597 // ***************************** 00598 // Personal information 00599 // ***************************** 00600 $this->fieldsArray["FIELD_realName"]='<input type="Text" name="data[FIELD_realName]" value="'.$this->getInputData("FIELD_realName",1).'"'.$params.'>'.$this->isCorrect("FIELD_realName"); 00601 $this->fieldsArray["FIELD_email"]='<input type="Text" name="data[FIELD_email]" value="'.$this->getInputData("FIELD_email",1).'"'.$params.'>'.$this->isCorrect("FIELD_email"); 00602 $this->fieldsArray["FIELD_username"]='<input type="Text" name="data[FIELD_username]" value="'.$this->getInputData("FIELD_username",1).'"'.$params.'>'.$this->isCorrect("FIELD_username"); 00603 $this->fieldsArray["FIELD_password"]='<input type="Text" name="data[FIELD_password]" value="'.$this->getInputData("FIELD_password",1).'"'.$params.'>'.$this->isCorrect("FIELD_password"); 00604 00605 $oTags=""; 00606 reset($languages); 00607 $cmpValue = $this->getInputData("FIELD_lang") ? $this->getInputData("FIELD_lang") : $this->sysConfig["defaultLanguage"]; 00608 while(list($key,$val)=each($languages)) { 00609 $oTags.='<option value="'.$key.'"'.($key==$cmpValue?' selected':'').'>'.$val.'</option>'; 00610 } 00611 $this->fieldsArray["FIELD_lang"]='<select name="data[FIELD_lang]">'.$oTags.'</select>'.$this->isCorrect("FIELD_lang"); 00612 00613 // ***************************** 00614 // Website specific: 00615 // ***************************** 00616 $this->fieldsArray["TITLE"]='<input type="Text" name="data[TITLE]" value="'.$this->getInputData("TITLE",1).'"'.$params.'>'.$this->isCorrect("TITLE"); 00617 $this->fieldsArray["FOLDER"]='<input type="Text" name="data[FOLDER]" value="'.$this->getInputData("FOLDER",1).'"'.$params.'>'.$this->isCorrect("FOLDER"); 00618 $this->fieldsArray["DOMAIN"]='<input type="Text" name="data[DOMAIN]" value="'.$this->getInputData("DOMAIN",1).'"'.$params.'>'.$this->isCorrect("DOMAIN"); 00619 00620 00621 // ***************************** 00622 // Template 00623 // ***************************** 00624 $pid = intval($this->sysConfig["pid_templateArchive"]); 00625 $oTags=""; 00626 $firstUID=0; 00627 if ($pid) { 00628 // Select templates in root 00629 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($pid).' AND NOT deleted AND NOT hidden AND NOT starttime AND NOT endtime', '', 'sorting'); 00630 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00631 if (!$firstUID) $firstUID=$row[uid]; 00632 $key=$row["uid"]; 00633 $val=$row["title"]; 00634 $oTags.='<option value="'.$key.'"'.($key==$this->getInputData("TEMPLATE")?' selected':'').'>'.$val.'</option>'; 00635 } 00636 // Select subcategories of template folder. 00637 $page_res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'pid='.intval($pid).' AND NOT deleted AND NOT hidden AND NOT starttime AND NOT endtime AND NOT fe_group', '', 'sorting'); 00638 while($page_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($page_res)) { 00639 // Subcategory templates 00640 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($page_row['uid']).' AND NOT deleted AND NOT hidden AND NOT starttime AND NOT endtime', '', 'sorting'); 00641 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00642 if (!$firstUID) $firstUID=$row[uid]; 00643 $key=$row["uid"]; 00644 $val=$page_row["title"]." / ".$row["title"]; 00645 $oTags.='<option value="'.$key.'"'.($key==$this->getInputData("TEMPLATE")?' selected':'').'>'.$val.'</option>'; 00646 } 00647 } 00648 $this->fieldsArray["TEMPLATE"]='<select name="data[TEMPLATE]">'.$oTags.'</select>'.$this->isCorrect("TEMPLATE"); 00649 if ($this->sysConfig["exclude_templateSelect"]) { 00650 $this->fieldsArray["TEMPLATE"]=""; 00651 $this->HIDDEN_FIELDS.='<input type="hidden" name="data[TEMPLATE]" value="'.$firstUID.'">'; 00652 } 00653 } else { 00654 $this->fieldsArray["TEMPLATE"]=""; 00655 } 00656 00657 // ***************************** 00658 // Dummy Pages 00659 // ***************************** 00660 $pid = intval($this->sysConfig["pid_dummyPagesArchive"]); 00661 $oTags=""; 00662 $firstUID=0; 00663 if ($pid) { 00664 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'pid='.intval($pid).' AND NOT deleted AND NOT hidden AND NOT starttime AND NOT endtime AND NOT fe_group', '', 'sorting'); 00665 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00666 if (!$firstUID) $firstUID=$row[uid]; 00667 $key=$row["uid"]; 00668 $val=$row["title"]; 00669 $oTags.='<option value="'.$key.'"'.($key==$this->getInputData("DUMMY_PAGES")?' selected':'').'>'.$val.'</option>'; 00670 } 00671 $this->fieldsArray["DUMMY_PAGES"]='<select name="data[DUMMY_PAGES]">'.$oTags.'</select>'.$this->isCorrect("DUMMY_PAGES"); 00672 if ($this->sysConfig["exclude_dummyPages"]) { 00673 $this->fieldsArray["DUMMY_PAGES"]=''; 00674 $this->HIDDEN_FIELDS.='<input type="Hidden" name="data[DUMMY_PAGES]" value="'.$firstUID.'">'; 00675 } 00676 } else { 00677 $this->fieldsArray["DUMMY_PAGES"]=''; 00678 } 00679 00680 // ***************************** 00681 // UPDATE_CREATE 00682 // ***************************** 00683 $this->fieldsArray["UPDATE_CREATE"]='<input type="Submit" name="updateButton" value="'.$this->sysConfig["label_Update"].'">'; 00684 if ($this->ALL_OK) { // If every thing is OK! 00685 if ($this->sysConfig["previewData"]) { 00686 $this->fieldsArray["UPDATE_CREATE"].=' <input type="Submit" name="previewButton" value="'.$this->sysConfig["label_Preview"].'">'; 00687 } else { 00688 $this->fieldsArray["UPDATE_CREATE"].=' <input type="Submit" name="createButton" value="'.$this->sysConfig["label_Create"].'">'; 00689 $this->HIDDEN_FIELDS.='<input type="Hidden" name="VERIFICATION_CODE" value="'.$this->verificationCode.'">'.chr(10); 00690 } 00691 } 00692 } 00693 00697 function previewData() { 00698 $fields=explode(",","FIELD_realName,FIELD_email,FIELD_username,FIELD_password,FIELD_lang,TITLE,FOLDER,DOMAIN,DUMMY_PAGES,TEMPLATE"); 00699 while(list(,$v)=each($fields)) { 00700 switch($v) { 00701 case "DOMAIN": 00702 if ($this->data["FOLDER"] && !$this->data["DOMAIN"]) { // If the folder is given, but the domain is not... 00703 $p=parse_url(t3lib_div::getIndpEnv("TYPO3_REQUEST_SCRIPT")); 00704 $dir=dirname($p["path"]); // Strip file 00705 $path=dirname(dirname($dir)); // strip the ../../ dirs 00706 $this->fieldsArray[$v]="<b>".$path."</b>"; 00707 } else { 00708 $this->fieldsArray[$v]="<b>".$this->data[$v]."</b>"; 00709 } 00710 break; 00711 default: 00712 $this->fieldsArray[$v]="<b>".$this->data[$v]."</b>"; 00713 break; 00714 } 00715 $this->HIDDEN_FIELDS.='<input type="Hidden" name="data['.$v.']" value="'.htmlspecialchars($this->data[$v]).'">'.chr(10); 00716 } 00717 00718 // ************************** 00719 // UPDATE_CREATE 00720 // ************************** 00721 if ($this->sysConfig["emailVerification"] && $this->sysConfig["previewData"]) { 00722 $this->fieldsArray["UPDATE_CREATE"]=sprintf($this->sysConfig["msgEmailVerificationCode"],$this->data["FIELD_email"]); 00723 $msg=$this->sysConfig["emailVerificationMessage"]; 00724 00725 // if (!$this->sysConfig["testingOnly"]) { 00726 mail ($this->data["FIELD_email"], 00727 $this->sysConfig["emailVerificationSubject"], 00728 $msg.chr(10).chr(10).$this->verificationCode, 00729 $this->sysConfig["emailHeader"]); 00730 // } 00731 $this->fieldsArray["UPDATE_CREATE"].='<input type="Text" name="VERIFICATION_CODE" value=""><BR><BR>'.chr(10); 00732 } else { 00733 $this->HIDDEN_FIELDS.='<input type="Hidden" name="VERIFICATION_CODE" value="'.$this->verificationCode.'">'.chr(10); 00734 } 00735 00736 $this->fieldsArray["UPDATE_CREATE"].='<input type="Submit" name="updateButton" value="'.$this->sysConfig["label_Return"].'">'; 00737 $this->fieldsArray["UPDATE_CREATE"].=' <input type="Submit" name="createButton" value="'.$this->sysConfig["label_Create"].'">'; 00738 } 00739 00740 00741 00742 00743 00744 // ******************************** 00745 // 00746 // Creating the template 00747 // 00748 // ******************************** 00749 function creatingData () { 00750 00751 // ********************************************************* 00752 // Get template, general group, newsite page. 00753 // ********************************************************* 00754 $this->groupTemplate = $this->doesExist("be_groups","uid",$this->sysConfig["uid_templateGroup"]); // The users own group will be modelled after this group (be a copy) 00755 $this->groupGeneral = $this->doesExist("be_groups","uid",$this->sysConfig["uid_generalGroup"]); // The user becomes a member of this group, which should be about general configuration for all users. 00756 $this->newsite_page = $this->doesExist("pages","uid",$this->sysConfig["pid_newsite"]); 00757 00758 00759 // *************************** 00760 // Setting new group defaults 00761 // *************************** 00762 // Standard data. 00763 $this->groupData=array(); 00764 $this->groupData["pid"]=0; 00765 $this->groupData["tstamp"]=time(); 00766 $this->groupData["hidden"]=0; 00767 $this->groupData["crdate"]=time(); 00768 $this->groupData["cruser_id"]=0; 00769 $this->groupData["deleted"]=0; 00770 // $this->groupData["starttime"]=0; 00771 // $this->groupData["endtime"]=0; 00772 00773 // User specific 00774 $this->groupData["title"]=$this->data["FIELD_username"]; 00775 $this->groupData["description"]= 00776 "Sitetitle: ".$this->data["TITLE"].chr(10). 00777 "Name: ".$this->data["FIELD_realName"].chr(10). 00778 "Domain: ".$this->data["DOMAIN"].chr(10). 00779 "Folder: ".$this->data["FOLDER"].chr(10); 00780 00781 // From template group: 00782 $this->groupData["inc_access_lists"]= $this->groupTemplate["inc_access_lists"]; 00783 $this->groupData["non_exclude_fields"]= $this->groupTemplate["non_exclude_fields"]; 00784 $this->groupData["pagetypes_select"]= $this->groupTemplate["pagetypes_select"]; 00785 $this->groupData["tables_select"]= $this->groupTemplate["tables_select"]; 00786 $this->groupData["tables_modify"]= $this->groupTemplate["tables_modify"]; 00787 $this->groupData["groupMods"]= $this->groupTemplate["groupMods"]; 00788 $this->groupData["db_mountpoints"]= $this->groupTemplate["db_mountpoints"]; // The newsite pid is added to this! 00789 $this->groupData["file_mountpoints"]= $this->groupTemplate["file_mountpoints"]; 00790 $this->groupData["subgroup"]= $this->groupTemplate["subgroup"]; 00791 00792 // Lock To Domain? 00793 if ($this->sysConfig["create_lockToDomain"]) { 00794 $this->groupData["lockToDomain"]=$this->data["DOMAIN"]; 00795 } else { 00796 $this->groupData["lockToDomain"]=""; 00797 } 00798 00799 00800 00801 00802 // *************************** 00803 // Setting new user defaults 00804 // *************************** 00805 // standard data. 00806 $this->userData=array(); 00807 $this->userData["pid"]=0; 00808 $this->userData["tstamp"]=time(); 00809 $this->userData["admin"]=0; 00810 $this->userData["disable"]=0; 00811 $this->userData["starttime"]=0; 00812 $this->userData["endtime"]=0; 00813 $this->userData["crdate"]=time(); 00814 $this->userData["cruser_id"]=0; 00815 $this->userData["deleted"]=0; 00816 00817 // user specific 00818 $this->userData["username"]=$this->data["FIELD_username"]; 00819 $this->userData["password"]=md5($this->data["FIELD_password"]); 00820 $this->userData["email"]=$this->data["FIELD_email"]; 00821 $this->userData["realName"]=$this->data["FIELD_realName"]; 00822 00823 $this->data["FIELD_lang"] = $this->data["FIELD_lang"] ? $this->data["FIELD_lang"] : $this->sysConfig["defaultLanguage"]; 00824 $this->userData["lang"]=$this->data["FIELD_lang"]=="default" ? "" : $this->data["FIELD_lang"]; 00825 00826 // This sets the mountpoints of the user to empty. Also it's configure (options) that the user should get his mountpoints from the groups. 00827 $this->userData["db_mountpoints"]=""; 00828 $this->userData["file_mountpoints"]=""; 00829 $this->userData["options"]=3; 00830 00831 // Lock To Domain? 00832 if ($this->sysConfig["create_lockToDomain"]) { 00833 $this->userData["lockToDomain"]=$this->data["DOMAIN"]; 00834 } else { 00835 $this->userData["lockToDomain"]=""; 00836 } 00837 00838 // Other options 00839 $this->userData["uc"]=""; // No preconfiguration for the user. 00840 $this->userData["userMods"]=""; // No special modules for the user. 00841 $this->userData["fileoper_perms"]=$this->sysConfig["create_fileoper_perms_default"]; 00842 00843 // ************************************************************************ 00844 // Checking (again) if the username is valid (that is, not used already) 00845 // ************************************************************************ 00846 if (!$this->doesExist("be_users","username",$this->userData["username"])) { 00847 return $this->startCreate(); 00848 } else { 00849 // SOMETHING WENT WRONG, probably the user did suddenly exist. 00850 die("Some error occurred! (the user did exist for some reason!)"); 00851 } 00852 00853 } 00854 00858 function startCreate() { 00859 $this->setNoDomainUrl(); // Setting the no domain url 00860 $this->notifyAdmin(); // Notify admin of this creation 00861 $this->addUserAndGroup(); 00862 $this->createDirs(); 00863 00864 // *************************************** 00865 // Create a user-object with the new user 00866 // *************************************** 00867 $new_BE_USER = t3lib_div::makeInstance("t3lib_beUserAuth"); // New backend user object 00868 $new_BE_USER->OS = TYPO3_OS; 00869 if (!$this->sysConfig["testingOnly"]) { 00870 $new_BE_USER->setBeUserByUid($this->user_uid); 00871 $new_BE_USER->fetchGroupData(); 00872 } 00873 00874 // ******************************************************************************** 00875 // If the newsite_pid existed, the whole process of setting up the site is begun. 00876 // ******************************************************************************** 00877 if (($new_BE_USER->user["uid"] || $this->sysConfig["testingOnly"]) && is_array($this->newsite_page)) { 00878 // copy pages... 00879 $dummyPage_row=$this->doesExist("pages","uid",$this->data["DUMMY_PAGES"]); 00880 if ($this->sysConfig["pid_dummyPagesArchive"] && is_array($dummyPage_row) && $this->sysConfig["pid_dummyPagesArchive"]==$dummyPage_row["pid"]) { 00881 $root_page_pid = $this->copyDummyPages($dummyPage_row["uid"],$new_BE_USER); 00882 if ($root_page_pid) { 00883 $this->setGroupMountPoint($root_page_pid); 00884 $this->setRootPageProperties($root_page_pid); 00885 $virtualDir = $this->createVirtualDir(); 00886 $domainData = $this->createDomainRecord($root_page_pid,$virtualDir); 00887 $this->createTemplateRecord($root_page_pid,$this->getRootPageTitle()); 00888 } else die ("No pages copied"); 00889 } else die("no dummy page archive."); 00890 } else die ("new_BE_USER did not exist OR newsite_page didn't exist"); 00891 00892 $out = $this->createdOutput($domainData); 00893 $this->sendNotifyEmailToUser(); 00894 return $out; 00895 } 00896 00900 function setNoDomainUrl() { 00901 $p=parse_url(t3lib_div::getIndpEnv("TYPO3_REQUEST_SCRIPT")); // Url of this script 00902 $dir=dirname($p["path"]); // Strip file 00903 $sitedirname = dirname(dirname(dirname(dirname($dir)))); 00904 if (substr($sitedirname,-1)!="/") { 00905 $sitedirname.="/"; 00906 } 00907 $this->noDomainURL=$this->rmDoubleSlash($p["host"].$sitedirname); // strip the dir of this tool 00908 } 00909 00913 function notifyAdmin() { 00914 $subject=$this->sysConfig["notifyUser_emailSubject"]; 00915 if ($this->sysConfig["notify_email"]) { 00916 mail ($this->sysConfig["notify_email"], 00917 $subject." (admin-note)", 00918 "New site is created by ".$this->data["FIELD_realName"]." (".$this->data["FIELD_email"].") at http://".$this->noDomainURL.chr(10).chr(10). 00919 "Username: ".$this->userData["username"].chr(10). 00920 "Password: ".$this->data["FIELD_password"].chr(10), 00921 $this->sysConfig["emailHeader"]); 00922 } 00923 } 00924 00928 function addUserAndGroup() { 00929 // Save the new usergroup to database 00930 $this->testHeader("Add group"); 00931 $this->userGroup_uid=$this->insertInDatabase("be_groups",$this->groupData); 00932 00933 // Save the new user to database 00934 // If there is a generalGroup, put it in the list 00935 $this->userData["usergroup"]=$this->userGroup_uid; 00936 if ($this->groupGeneral) { 00937 $this->userData["usergroup"].=",".$this->groupGeneral["uid"]; 00938 } 00939 $this->testHeader("Add user"); 00940 $this->user_uid = $this->insertInDatabase("be_users",$this->userData); 00941 } 00942 00946 function createDirs() { 00947 global $TYPO3_CONF_VARS; 00948 // ***************************************************************** 00949 // Create USER and GROUP directories, if required 00950 // ***************************************************************** 00951 if ($this->sysConfig["createNewUserDir"] 00952 && t3lib_div::isFirstPartOfStr($TYPO3_CONF_VARS["BE"]["userHomePath"],$TYPO3_CONF_VARS["BE"]["lockRootPath"]) 00953 && @is_dir($TYPO3_CONF_VARS["BE"]["userHomePath"])) { 00954 $folder=$this->rmDoubleSlash($TYPO3_CONF_VARS["BE"]["userHomePath"]."/".$this->user_uid); 00955 if (!$this->sysConfig["testingOnly"]) { 00956 mkdir ($folder, 0700); 00957 mkdir ($folder."/_temp_", 0700); 00958 } else { 00959 debug("CREATE user home dir: ".$folder,1); 00960 } 00961 } 00962 if ($this->sysConfig["createNewGroupDir"] 00963 && t3lib_div::isFirstPartOfStr($TYPO3_CONF_VARS["BE"]["groupHomePath"],$TYPO3_CONF_VARS["BE"]["lockRootPath"]) 00964 && @is_dir($TYPO3_CONF_VARS["BE"]["groupHomePath"])) { 00965 $folder=$this->rmDoubleSlash($TYPO3_CONF_VARS["BE"]["groupHomePath"]."/".$this->userGroup_uid); 00966 if (!$this->sysConfig["testingOnly"]) { 00967 mkdir ($folder, 0700); 00968 mkdir ($folder."/_temp_", 0700); 00969 } else { 00970 debug("CREATE group home dir: ".$folder,1); 00971 } 00972 } 00973 } 00974 00978 function createVirtualDir() { 00979 $virtualDir=0; // Boolean flag, that indicates if a folder has been created 00980 $newFolder=PATH_site.$this->data["FOLDER"]; 00981 00982 if (TYPO3_OS!="WIN" && $this->sysConfig["createVirtualDirs"] && $this->sysConfig["createDomains"] && $this->data["FOLDER"]) { 00983 if (!@file_exists($newFolder)) { 00984 if (!$this->sysConfig["testingOnly"]) { 00985 mkdir ($newFolder, 0700); 00986 $thelinks=explode(",","clear.gif,.htaccess,fileadmin,index.php,media,showpic.php,typo3,t3lib,tslib,typo3conf,typo3temp,uploads"); 00987 while(list(,$target)=each($thelinks)) { 00988 $dest=$newFolder."/".$target; 00989 $target=PATH_site.$target; 00990 if (@file_exists($target)) { 00991 symlink ($target,$dest); 00992 } 00993 } 00994 } else { 00995 debug("CREATE VIRTUAL FOLDER: ".$newFolder,1); 00996 } 00997 $virtualDir=1; 00998 } else { 00999 die("This folder did exist allready! ".$newFolder); 01000 } 01001 } 01002 return $virtualDir; 01003 } 01004 01008 function copyDummyPages($src_uid,$new_BE_USER) { 01009 if (!$this->sysConfig["testingOnly"]) { 01010 $tce = t3lib_div::makeInstance("t3lib_TCEmain"); 01011 $tce->stripslashes_values=0; 01012 $tce->copyTree=2; 01013 $tce->neverHideAtCopy=1; 01014 01015 // setting the user to admin rights temporarily during copy. The reason is that everything must be copied fully! 01016 $new_BE_USER->user["admin"]=1; 01017 01018 // Making copy-command 01019 $cmd=array(); 01020 $cmd["pages"][$src_uid]["copy"]=$this->sysConfig["pid_newsite"]; 01021 $tce->start(array(),$cmd,$new_BE_USER); 01022 $tce->process_cmdmap(); 01023 01024 // Unsetting the user. 01025 unset($new_BE_USER); 01026 01027 // Getting the new root page id. 01028 $root_page_pid = $tce->copyMappingArray["pages"][$src_uid]; 01029 return $root_page_pid; 01030 } else { 01031 debug("COPY page structure: pid=".$src_uid,1); 01032 return 99999; 01033 } 01034 } 01035 01039 function setGroupMountPoint($root_page_pid) { 01040 $groupUpdate=array(); 01041 if ($this->groupData["db_mountpoints"]) { 01042 $groupUpdate["db_mountpoints"] = $root_page_pid.",".$this->groupData["db_mountpoints"]; 01043 } else { 01044 $groupUpdate["db_mountpoints"]=$root_page_pid; 01045 } 01046 01047 $this->testHeader("Group Update"); 01048 $this->insertInDatabase("be_groups",$groupUpdate,$this->userGroup_uid); 01049 } 01050 01054 function setRootPageProperties($root_page_pid) { 01055 $pageData=array(); 01056 $pageData["alias"]=$this->data["FIELD_username"]; 01057 $pageData["title"]= $this->getRootPageTitle(); 01058 $pageData["perms_userid"]=0; // The root page should not be owned (and thereby deleteable) by the user 01059 01060 $this->testHeader("page Data update"); 01061 $this->insertInDatabase("pages",$pageData,$root_page_pid); 01062 } 01063 01067 function getRootPageTitle() { 01068 return $this->data["TITLE"]?$this->data["TITLE"]:($this->data["DOMAIN"]?$this->data["DOMAIN"]:($this->data["FOLDER"]?$this->data["FOLDER"]:$this->data["FIELD_username"])); 01069 } 01070 01074 function createDomainRecord($root_page_pid,$virtualDir) { 01075 if (($virtualDir || $this->data["DOMAIN"]) && $this->sysConfig["createDomains"]) { 01076 if (!$this->data["DOMAIN"]) { 01077 $path=$this->noDomainURL; 01078 } else { 01079 $path=$this->data["DOMAIN"]."/"; 01080 } 01081 if ($virtualDir) { // Only prepend virtual dir if it's set! 01082 $path.=$this->data["FOLDER"]; 01083 } 01084 $path = $this->rmSlash($path); // In any case, remove the last slash of the string. 01085 01086 $domainData=array(); 01087 $domainData["pid"]=$root_page_pid; 01088 $domainData["tstamp"]=time(); 01089 $domainData["hidden"]=0; 01090 $domainData["domainName"]=$path; 01091 $domainData["redirectTo"]=""; 01092 01093 if (!$this->doesExist("sys_domain","domainName",$path)) { 01094 $this->testHeader("sys_domain record"); 01095 $this->insertInDatabase("sys_domain",$domainData); 01096 } 01097 } 01098 return $domainData; 01099 } 01100 01104 function createTemplateRecord($root_page_pid,$title) { 01105 if ($this->sysConfig["pid_templateArchive"]) { 01106 // ************************ 01107 // Template data 01108 // ************************ 01109 $templateData=array(); 01110 // standard data 01111 $templateData["pid"]=$root_page_pid; 01112 $templateData["tstamp"]=time(); 01113 $templateData["sorting"]=0; 01114 $templateData["crdate"]=time(); 01115 $templateData["cruser_id"]=0; 01116 $templateData["deleted"]=0; 01117 $templateData["hidden"]=0; 01118 $templateData["starttime"]=0; 01119 $templateData["endtime"]=0; 01120 01121 // standard config 01122 $templateData["root"]=1; 01123 $templateData["clear"]=3; 01124 $templateData["include_static"]=""; 01125 $templateData["constants"]=""; 01126 $templateData["config"]=""; 01127 $templateData["resources"]=""; 01128 $templateData["nextLevel"]=""; 01129 $templateData["description"]="[AUTO-GENERATED TEMPLATE - ".date("d-m-Y")."]".chr(10); 01130 01131 // User specific: 01132 $templateData["title"]=$title; 01133 $templateData["sitetitle"]=$this->data[$this->sysConfig["defaultFormField_sitetitle"]]; 01134 $templateData["basedOn"]=intval($this->data["TEMPLATE"]); 01135 01136 $this->testHeader("sys_template"); 01137 $this->insertInDatabase("sys_template",$templateData); 01138 } 01139 } 01140 01144 function createdOutput($domainData) { 01145 // Get the template file 01146 $templateFile= $this->sysConfig["templateFile_created"] ? PATH_site.$this->sysConfig["templateFile_created"] : "template_created.html"; 01147 $templateCode = t3lib_div::getURL($templateFile); 01148 if (!$templateCode) die("No template file!! (".$templateFile.")"); 01149 01150 // ************************************************ 01151 // Output congratulation text: 01152 // ************************************************ 01153 $this->fieldsArray["USERNAME"]=$this->userData["username"]; 01154 $this->fieldsArray["PASSWORD"]=$this->data["FIELD_password"]; 01155 $this->fieldsArray["WEBSITE_URL"]="http://".$this->rmSlash($domainData["domainName"]?$domainData["domainName"]:$this->noDomainURL)."/"; 01156 $this->fieldsArray["ADMIN_URL"]=$this->fieldsArray["WEBSITE_URL"].TYPO3_mainDir; 01157 $this->fieldsArray["LINK_URL"]=$this->fieldsArray["ADMIN_URL"]."index.php?u=".rawurlencode($this->fieldsArray["USERNAME"])."&p=".rawurlencode($this->fieldsArray["PASSWORD"]); 01158 $this->fieldsArray["EMAIL"]=$this->data["FIELD_email"]; 01159 if (!$domainData["domainName"]) {$this->fieldsArray["WEBSITE_URL"].='?'.$this->data["FIELD_username"];} // Add alias for frontpage if not domain is set. 01160 01161 reset($this->fieldsArray); 01162 while(list($key,$content)=each($this->fieldsArray)) { 01163 $templateCode = str_replace("###".$key."###",$content,$templateCode); 01164 } 01165 return $templateCode; 01166 } 01167 01171 function sendNotifyEmailToUser() { 01172 $msg=$this->sysConfig["notifyUser_emailMessage"]; 01173 $subject=$this->sysConfig["notifyUser_emailSubject"]; 01174 reset($this->fieldsArray); 01175 while(list($key,$content)=each($this->fieldsArray)) { 01176 $msg = str_replace("###".$key."###",$content,$msg); 01177 } 01178 if ($this->sysConfig["notifyUser_email"]) { 01179 mail ($this->data["FIELD_email"], 01180 $subject, 01181 $msg, 01182 $this->sysConfig["emailHeader"]); 01183 } 01184 } 01185 01189 function testHeader($label) { 01190 if ($this->sysConfig["testingOnly"]) { 01191 echo '<HR>'; 01192 debug($label,1); 01193 } 01194 } 01195 01196 01197 01198 // ****************************** 01199 // 01200 // SELECTING TEMPLATES / PAGES 01201 // 01202 // ****************************** 01203 01204 function getTemplateHTML($uid,$title,$template) { 01205 $fN="tmplimages/".$uid; 01206 $file=""; 01207 if (@is_file($fN.".gif")) { 01208 $file=$fN.".gif"; 01209 } elseif (@is_file($fN.".jpg")) { 01210 $file=$fN.".jpg"; 01211 } 01212 if (@is_file($file)) { 01213 $fI = @getimagesize($file); 01214 if (is_array($fI)) { 01215 $image='<img src="'.$file.'" '.$fI[3].' border=0>'; 01216 $image='<a href="#" onClick="select('.$uid.'); return false;">'.$image.'</a>'; 01217 } 01218 } 01219 01220 $msg = $template; 01221 $msg = str_replace("###TITLE###",$title,$msg); 01222 $msg = str_replace("###IMAGE###",$image,$msg); 01223 return $msg; 01224 } 01225 function getPagesHTML($uid,$title,$template) { 01226 $admin = t3lib_div::makeInstance("freesite_admin"); 01227 $admin->genTree($uid,""); 01228 01229 $pages=$admin->genTree_HTML; 01230 $title='<a href="#" onClick="select('.$uid.'); return false;">'.$title.'</a>'; 01231 01232 $msg = $template; 01233 $msg = str_replace("###TITLE###",$title,$msg); 01234 $msg = str_replace("###PAGES###",$pages,$msg); 01235 return $msg; 01236 } 01237 01238 01239 01240 01241 // ************************************ 01242 // Get the list of templates or pages: 01243 // ************************************ 01244 01245 function printSelect($theType) { 01246 // Get the template file 01247 $theKey = "templateFile_".$theType; 01248 $templateFile= $this->sysConfig[$theKey] ? PATH_site.$this->sysConfig[$theKey] : "template_".$theType.".html"; 01249 $templateCode = t3lib_div::getURL($templateFile); 01250 if (!$templateCode) die("No template file!! (".$templateFile.")"); 01251 01252 01253 $itemPart = $this->getSubpart($templateCode, "###TEMPLATE_ITEM###"); 01254 $out=""; 01255 01256 switch($theType) { 01257 case "selectTemplate": 01258 // Template 01259 $infoUid = t3lib_div::_GP("infoUid"); 01260 if ($infoUid && !$GLOBALS["TYPO3_CONF_VARS"]["BE"]["EXTERNAL"]["FREESITE"]["templateSelect_noInfoLink"]) { 01261 // Get template record: 01262 $tRec = t3lib_BEfunc::getRecord("sys_template",$infoUid); 01263 if (is_array($tRec)) { 01264 $existTemplate = $this->initialize_editor($tRec["pid"],$tRec["uid"]); // initialize 01265 $out.="<HR><h3>Template Information:</h3>"; 01266 $out.='<a href="index.php?script=template&infoUid='.$infoUid.'&allDetails=1">Show all categories</a><BR>'; 01267 $out.=$this->displayExample(""); 01268 } 01269 // $out.='<HR><a href="index.php?script=template#T'.$infoUid.'">BACK</a>'; 01270 } else { 01271 $pid = intval($this->sysConfig["pid_templateArchive"]); 01272 $oTags=""; 01273 $firstUID=0; 01274 if ($pid) { 01275 // Select templates in root 01276 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($pid).' AND NOT deleted AND NOT hidden AND NOT starttime AND NOT endtime', '', 'sorting'); 01277 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 01278 if (!$firstUID) $firstUID=$row[uid]; 01279 $key=$row["uid"]; 01280 $val=$row["title"]; 01281 $out.=$this->getTemplateHTML($key,$val,$itemPart); 01282 } 01283 // Select subcategories of template folder. 01284 $page_res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'pid='.intval($pid).' AND NOT deleted AND NOT hidden AND NOT starttime AND NOT endtime AND NOT fe_group', '', 'sorting'); 01285 while($page_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($page_res)) { 01286 // Subcategory templates 01287 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'pid='.intval($page_row['uid']).' AND NOT deleted AND NOT hidden AND NOT starttime AND NOT endtime', '', 'sorting'); 01288 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 01289 if (!$firstUID) $firstUID=$row[uid]; 01290 $key=$row['uid']; 01291 $val=$page_row['title'].' / '.$row['title']; 01292 if (!$GLOBALS['TYPO3_CONF_VARS']['BE']['EXTERNAL']['FREESITE']['templateSelect_noInfoLink']) { 01293 $out.='<a name="T'.$key.'"></a>'; 01294 $out.='<a href="index.php?script=template&infoUid='.$key.'" target="template_infowindow"><img src="'.$GLOBALS["BACK_PATH"].'t3lib/gfx/icon_note.gif" class="absmiddle" width=18 height=16 border=0></a>'; 01295 } 01296 $out.=$this->getTemplateHTML($key,$val,$itemPart); 01297 } 01298 } 01299 } 01300 } 01301 break; 01302 case "selectPages": 01303 // Dummy Pages 01304 $pid = intval($this->sysConfig["pid_dummyPagesArchive"]); 01305 $oTags=""; 01306 $firstUID=0; 01307 if ($pid) { 01308 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', 'pid='.intval($pid).' AND NOT deleted AND NOT hidden AND NOT starttime AND NOT endtime AND NOT fe_group', '', 'sorting'); 01309 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 01310 if (!$firstUID) $firstUID = $row[uid]; 01311 $key = $row["uid"]; 01312 $val = $row["title"]; 01313 $out.= $this->getPagesHTML($key,$val,$itemPart); 01314 } 01315 } 01316 break; 01317 } 01318 echo $this->substituteSubpart($templateCode, "###TEMPLATE_ITEM###", $out); 01319 } 01320 01321 01322 // USED TO DISPLAY TEMPLATE DETAILS: 01323 function displayExample($theOutput) { 01324 global $tmpl,$theConstants; 01325 $categories = $tmpl->ext_getCategoryLabelArray(); 01326 $allDetails = t3lib_div::_GP("allDetails"); 01327 if (is_array($categories)) { 01328 // debug($categories); 01329 // debug($tmpl->categories); 01330 reset($categories); 01331 $tmpl->ext_localGfxPrefix=t3lib_extMgm::extPath("tstemplate_ceditor"); 01332 $tmpl->ext_localWebGfxPrefix=$this->backPath.t3lib_extMgm::extRelPath("tstemplate_ceditor"); 01333 while(list($category,$label)=each($categories)) { 01334 $tmpl->helpConfig=array(); 01335 $tmpl->ext_getTSCE_config($category); 01336 // debug($tmpl->helpConfig); 01337 $detailFlag = $tmpl->helpConfig["imagetag"] || $tmpl->helpConfig["description"] || $tmpl->helpConfig["header"]; 01338 if ($allDetails || $detailFlag) { 01339 $theOutput.="<HR>"; 01340 $theOutput.="<h3>".$label.": ".$tmpl->helpConfig["header"]."</h3>"; 01341 } 01342 if ($detailFlag) { 01343 $theOutput.='<div align="center">'.$tmpl->helpConfig["imagetag"].'</div><BR>'. 01344 ($tmpl->helpConfig["description"] ? implode(explode("//",$tmpl->helpConfig["description"]),"<BR>")."<BR>" : ""). 01345 ($tmpl->helpConfig["bulletlist"] ? "<ul><li>".implode(explode("//",$tmpl->helpConfig["bulletlist"]),"<li>")."</ul>" : "<BR>"); 01346 } 01347 if ($allDetails || $detailFlag) { 01348 $theOutput.=$this->getTemplateDetails($category); 01349 } 01350 } 01351 } 01352 01353 return $theOutput; 01354 } 01355 function getTemplateDetails($category) { 01356 global $tmpl,$theConstants; 01357 01358 // Details: 01359 $subcat=""; 01360 $subcat_name=""; 01361 asort($tmpl->categories[$category]); 01362 while(list($name,$type)=each($tmpl->categories[$category])) { 01363 $params = $theConstants[$name]; 01364 if (is_array($params)) { 01365 if ($subcat!=$params["subcat_name"]) { 01366 $subcat=$params["subcat_name"]; 01367 $subcat_name = $params["subcat_name"] ? $tmpl->subCategories[$params["subcat_name"]][0] : "Others"; 01368 01369 $out.='<tr><td colspan=3><img src=clear.gif height=10 width=1></td></tr>'; 01370 $out.='<tr><td colspan=3 bgcolor="#cccccc"><strong>'.fw(strtoupper(htmlspecialchars($subcat_name))).'</strong></td></tr>'; 01371 } 01372 01373 list($label)=explode("|",$params["label"]); 01374 $label_parts = explode(":",$label,2); 01375 if (count($label_parts)==2) { 01376 $head=trim($label_parts[0]); 01377 $body=trim($label_parts[1]); 01378 } else { 01379 $head=trim($label_parts[0]); 01380 $body=""; 01381 } 01382 if (strlen($head)>35) { 01383 if (!$body) {$body=$head;} 01384 $head=t3lib_div::fixed_lgd($head,35); 01385 } 01386 $typeDat=$tmpl->ext_getTypeData($params["type"]); 01387 01388 $p_name = '<font color="#666666">['.$params["name"].']</font><BR>'; 01389 $p_dlabel='<font color="#666666"><b>Default:</b> '.htmlspecialchars($params["default_value"]).'</font><BR>'; 01390 $p_label = '<b>'.htmlspecialchars($head).'</b>'; 01391 $p_descrip = $body ? htmlspecialchars($body)."<BR>" : ""; 01392 // debug($typeDat); 01393 01394 $out.='<tr><td nowrap valign=top>'.fw($tmpl->helpConfig["constants"][$params["name"]].$p_label).'<BR><font color="#666666">'.fw(t3lib_div::fixed_lgd(htmlspecialchars($params["type"]),20)).'</font></td><td><img src=clear.gif width=10 height=1></td><td valign=top>'.fw($p_descrip).'</td></tr>'; 01395 // debug($typeDat); 01396 } 01397 } 01398 $out='<table border=0 cellpadding=0 cellspacing=0>'.$out.'</table>'; 01399 return $out; 01400 } 01401 function initialize_editor($pageId,$template_uid=0) { 01402 // Initializes the module. Done in this function because we may need to re-initialize if data is submitted! 01403 global $tmpl,$tplRow,$theConstants; 01404 01405 $tmpl = t3lib_div::makeInstance("t3lib_tsparser_ext"); // Defined global here! 01406 $tmpl->tt_track = 0; // Do not log time-performance information 01407 $tmpl->init(); 01408 $tmpl->fieldCompensation = (($GLOBALS["CLIENT"]["BROWSER"]=="net") ? "1" : "1.15"); 01409 01410 $tplRow = $tmpl->ext_getFirstTemplate($pageId,$template_uid); // Get the row of the first VISIBLE template of the page. whereclause like the frontend. 01411 if (is_array($tplRow)) { // IF there was a template... 01412 // Gets the rootLine 01413 $sys_page = t3lib_div::makeInstance("t3lib_pageSelect"); 01414 $rootLine = $sys_page->getRootLine($pageId); 01415 $tmpl->runThroughTemplates($rootLine,$template_uid); // This generates the constants/config + hierarchy info for the template. 01416 $theConstants = $tmpl->generateConfig_constants(); // The editable constants are returned in an array. 01417 $tmpl->ext_categorizeEditableConstants($theConstants); // The returned constants are sorted in categories, that goes into the $tmpl->categories array 01418 $tmpl->ext_regObjectPositions($tplRow["constants"]); // This array will contain key=[expanded constantname], value=linenumber in template. (after edit_divider, if any) 01419 return 1; 01420 } 01421 } 01422 } 01423 01424 01425 // Include extension? 01426 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/freesite/mod/class.freesite.php"]) { 01427 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/freesite/mod/class.freesite.php"]); 01428 } 01429 01430 01431 ?>