00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00033 require_once(t3lib_extMgm::extPath('kickstarter').'class.tx_kickstarter_compilefiles.php');
00034
00035 class tx_kickstarter_wizard extends tx_kickstarter_compilefiles {
00036 var $varPrefix = 'kickstarter';
00037 var $siteBackPath = '';
00038 var $EMmode=1;
00039
00040 var $wizArray=array();
00041
00042 var $extKey_nusc = 'myext';
00043 var $extKey = 'my_ext';
00044 var $printWOP=0;
00045 var $outputWOP=0;
00046 var $saveKey='';
00047 var $pObj;
00048
00049 var $afterContent;
00050
00051 var $languages = array(
00052 'dk' => 'Danish',
00053 'de' => 'German',
00054 'no' => 'Norwegian',
00055 'it' => 'Italian',
00056 'fr' => 'French',
00057 'es' => 'Spanish',
00058 'nl' => 'Dutch',
00059 'cz' => 'Czech',
00060 'pl' => 'Polish',
00061 'si' => 'Slovenian',
00062 'fi' => 'Finnish',
00063 'tr' => 'Turkish',
00064 'se' => 'Swedish',
00065 'pt' => 'Portuguese',
00066 'ru' => 'Russian',
00067 'ro' => 'Romanian',
00068 'ch' => 'Chinese',
00069 'sk' => 'Slovak',
00070 'lt' => 'Lithuanian',
00071 'is' => 'Icelandic',
00072 'hr' => 'Croatian',
00073 'hu' => 'Hungarian',
00074 'gl' => 'Greenlandic',
00075 'th' => 'Thai',
00076 'gr' => 'Greek',
00077 'hk' => 'Chinese (Trad)',
00078 'eu' => 'Basque',
00079 'bg' => 'Bulgarian',
00080 'br' => 'Brazilian Portuguese',
00081 'et' => 'Estonian',
00082 'ar' => 'Arabic',
00083 'he' => 'Hebrew',
00084 'ua' => 'Ukrainian',
00085 'lv' => 'Latvian',
00086 'jp' => 'Japanese',
00087 'vn' => 'Vietnamese',
00088 'ca' => 'Catalan',
00089 'ba' => 'Bosnian',
00090 'kr' => 'Korean',
00091 'eo' => 'Esperanto',
00092 'my' => 'Bahasa Malaysia',
00093 );
00094 var $reservedTypo3Fields='uid,pid,endtime,starttime,sorting,fe_group,hidden,deleted,cruser_id,crdate,tstamp';
00095 var $mysql_reservedFields='data,table,field,key,desc';
00096
00097
00098 var $selectedLanguages = array();
00099 var $usedNames=array();
00100 var $fileArray=array();
00101 var $ext_tables=array();
00102 var $ext_localconf=array();
00103 var $ext_locallang=array();
00104
00105 var $color = array('#C8D0B3','#FEE7B5','#EEEEEE');
00106
00107 var $modData;
00108
00109 function tx_kickstarter_wizard() {
00110 $this->modData = t3lib_div::_POST($this->varPrefix);
00111 }
00112
00113 function initWizArray() {
00114 $inArray = unserialize(base64_decode($this->modData['wizArray_ser']));
00115 $this->wizArray = is_array($inArray) ? $inArray : array();
00116 if (is_array($this->modData['wizArray_upd'])) {
00117 $this->wizArray = t3lib_div::array_merge_recursive_overrule($this->wizArray,$this->modData['wizArray_upd']);
00118 }
00119
00120 $lA = is_array($this->wizArray['languages']) ? current($this->wizArray['languages']) : '';
00121 if (is_array($lA)) {
00122 foreach($lA as $k => $v) {
00123 if ($v && isset($this->languages[$k])) {
00124 $this->selectedLanguages[$k]=$this->languages[$k];
00125 }
00126 }
00127 }
00128 }
00129
00130 function mgm_wizard() {
00131 $this->wizard =& $this;
00132 $this->initWizArray();
00133 $this->sections = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['kickstarter']['sections'];
00134
00135 foreach($this->sections as $k => $v) {
00136 $this->options[$k] = array($v['title'],$v['description']);
00137 }
00138
00139 $saveKey = $this->saveKey = $this->wizArray['save']['extension_key'] = trim($this->wizArray['save']['extension_key']);
00140 $this->outputWOP = $this->wizArray['save']['print_wop_comments'] ? 1 : 0;
00141
00142 if ($saveKey) {
00143 $this->extKey=$saveKey;
00144 $this->extKey_nusc=str_replace('_','',$saveKey);
00145 }
00146
00147 if ($this->modData['viewResult']) {
00148 $this->modData['wizAction']='';
00149 $this->modData['wizSubCmd']='';
00150 if ($saveKey) {
00151 $content = $this->view_result();
00152 } else $content = $this->fw('<strong>Error:</strong> Please enter an extension key first!<BR><BR>');
00153 } elseif ($this->modData['WRITE']) {
00154 $this->modData['wizAction']='';
00155 $this->modData['wizSubCmd']='';
00156 if ($saveKey) {
00157 $this->makeFilesArray($this->saveKey);
00158 $uploadArray = $this->makeUploadArray($this->saveKey,$this->fileArray);
00159 $this->pObj->importExtFromRep(0,$this->modData['loc'],0,$uploadArray,0,0,1);
00160 } else $content = $this->fw('<strong>Error:</strong> Please enter an extension key first!<BR><BR>');
00161 } elseif ($this->modData['totalForm']) {
00162 $content = $this->totalForm();
00163 } elseif ($this->modData['downloadAsFile']) {
00164 if ($saveKey) {
00165 $this->makeFilesArray($this->saveKey);
00166 $uploadArray = $this->makeUploadArray($this->saveKey,$this->fileArray);
00167 $backUpData = $this->makeUploadDataFromArray($uploadArray);
00168 $filename='T3X_'.$saveKey.'-'.str_replace('.','_','0.0.0').'.t3x';
00169 $mimeType = 'application/octet-stream';
00170 Header('Content-Type: '.$mimeType);
00171 Header('Content-Disposition: attachment; filename='.$filename);
00172 echo $backUpData;
00173 exit;
00174 } else $content = $this->fw('<strong>Error:</strong> Please enter an extension key first!<BR><BR>');
00175 } else {
00176 $action = explode(':',$this->modData['wizAction']);
00177 if ((string)$action[0]=='deleteEl') {
00178 unset($this->wizArray[$action[1]][$action[2]]);
00179 }
00180
00181 $content = $this->getFormContent();
00182 }
00183 $wasContent = $content?1:0;
00184 $content = '
00185 <script language="javascript" type="text/javascript">
00186 function setFormAnchorPoint(anchor) {
00187 document.'.$this->varPrefix.'_wizard.action = unescape("'.rawurlencode($this->linkThisCmd()).'")+"#"+anchor;
00188 }
00189 </script>
00190 <table border="0" cellpadding="0" cellspacing="0">
00191 <form action="' . $this->linkThisCmd() . '" method="POST" name="' . $this->varPrefix . '_wizard">
00192 <tr>
00193 <td valign="top">'.$this->sidemenu().'</td>
00194 <td> </td>
00195 <td valign="top">'.$content.'
00196 <input type="hidden" name="'.$this->piFieldName("wizArray_ser").'" value="'.htmlspecialchars(base64_encode(serialize($this->wizArray))).'" /><BR>';
00197
00198 if ((string)$this->modData['wizSubCmd']) {
00199 if ($wasContent) $content.='<input name="update2" type="submit" value="Update..."> ';
00200 }
00201 $content.='
00202 <input type="hidden" name="'.$this->piFieldName("wizAction").'" value="'.$this->modData["wizAction"].'">
00203 <input type="hidden" name="'.$this->piFieldName("wizSubCmd").'" value="'.$this->modData["wizSubCmd"].'">
00204 '.$this->cmdHiddenField().'
00205 </td>
00206 </tr>
00207 </form>
00208 </table>' . $this->afterContent;
00209
00210 return $content;
00211 }
00212
00216 function getFormContent() {
00217
00218 if($this->sections[$this->modData['wizSubCmd']]) {
00219 $path = t3lib_div::getFileAbsFileName($this->sections[$this->modData['wizSubCmd']]['filepath']);
00220 require_once($path);
00221 $section = t3lib_div::makeInstance($this->sections[$this->modData['wizSubCmd']]['classname']);
00222 $section->wizard = &$this;
00223 return $section->render_wizard();
00224 }
00225 }
00226
00230 function totalForm() {
00231 $buf = array($this->printWOP,$this->dontPrintImages);
00232 $this->printWOP = 1;
00233
00234 $lines=array();
00235 foreach($this->options as $k => $v) {
00236
00237 $items = $this->wizArray[$k];
00238 if (is_array($items)) {
00239 foreach($items as $k2 => $conf) {
00240 $this->modData['wizSubCmd']=$k;
00241 $this->modData['wizAction']='edit:'.$k2;
00242 $lines[]=$this->getFormContent();
00243 }
00244 }
00245 }
00246
00247 $this->modData['wizSubCmd']='';
00248 $this->modData['wizAction']='';
00249 list($this->printWOP,$this->dontPrintImages) = $buf;
00250
00251 $content = implode('<HR>',$lines);
00252 return $content;
00253 }
00254
00258 function sidemenu() {
00259 #debug($this->modData);
00260 $actionType = $this->modData['wizSubCmd'].':'.$this->modData['wizAction'];
00261 $singles = 'emconf,save,ts,TSconfig,languages';
00262 $lines=array();
00263 foreach($this->options as $k => $v) {
00264
00265 $items = $this->wizArray[$k];
00266 $c=0;
00267 $iLines=array();
00268 if (is_array($items)) {
00269 foreach($items as $k2=>$conf) {
00270 $dummyTitle = t3lib_div::inList($singles,$k) ? '[Click to Edit]' : '<em>Item '.$k2.'</em>';
00271 $isActive = !strcmp($k.':edit:'.$k2,$actionType);
00272 $delIcon = $this->linkStr('<img src="'.$this->siteBackPath.'t3lib/gfx/garbage.gif" width="11" height="12" border="0" title="Remove item">','','deleteEl:'.$k.':'.$k2);
00273 $iLines[]='<tr'.($isActive?$this->bgCol(2,-30):$this->bgCol(2)).'><td>'.$this->fw($this->linkStr($this->bwWithFlag($conf['title']?$conf['title']:$dummyTitle,$isActive),$k,'edit:'.$k2)).'</td><td>'.$delIcon.'</td></tr>';
00274 $c=$k2;
00275 }
00276 }
00277 if (!t3lib_div::inList($singles,$k) || !count($iLines)) {
00278 $c++;
00279 $addIcon = $this->linkStr('<img src="'.$this->siteBackPath.'t3lib/gfx/add.gif" width="12" height="12" border="0" title="Add item">',$k,'edit:'.$c);
00280 } else {$addIcon = '';}
00281
00282 $lines[]='<tr'.$this->bgCol(1).'><td nowrap><strong>'.$this->fw($v[0]).'</strong></td><td>'.$addIcon.'</td></tr>';
00283 $lines = array_merge($lines,$iLines);
00284 }
00285
00286 $lines[]='<tr><td> </td><td></td></tr>';
00287
00288 $lines[]='<tr><td width=150>
00289 '.$this->fw('Enter extension key:').'<BR>
00290 <input type="text" name="'.$this->piFieldName('wizArray_upd').'[save][extension_key]" value="'.$this->wizArray['save']['extension_key'].'">
00291 '.($this->wizArray['save']['extension_key']?'':'<BR><a href="http://typo3.org/1382.0.html" target="_blank"><font color=red>Make sure to enter the right extension key from the beginning here!</font> You can register one here.</a>').'
00292 </td><td></td></tr>';
00293 # onClick="setFormAnchorPoint(\'_top\')"
00294 $lines[]='<tr><td><input type="submit" value="Update..."></td><td></td></tr>';
00295 $lines[]='<tr><td><input type="submit" name="'.$this->piFieldName('totalForm').'" value="Total form"></td><td></td></tr>';
00296
00297 if ($this->saveKey) {
00298 $lines[]='<tr><td><input type="submit" name="'.$this->piFieldName('viewResult').'" value="View result"></td><td></td></tr>';
00299 $lines[]='<tr><td><input type="submit" name="'.$this->piFieldName('downloadAsFile').'" value="D/L as file"></td><td></td></tr>';
00300 $lines[]='<tr><td>
00301 <input type="hidden" name="'.$this->piFieldName('wizArray_upd').'[save][print_wop_comments]" value="0"><input type="checkbox" name="'.$this->piFieldName('wizArray_upd').'[save][print_wop_comments]" value="1" '.($this->wizArray['save']['print_wop_comments']?' CHECKED':'').'>'.$this->fw('Print WOP comments').'
00302 </td><td></td></tr>';
00303 }
00304
00305
00306 if(is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['kickstarter']['sidemenu'])) {
00307 foreach($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['kickstarter']['sidemenu'] as $_funcRef) {
00308 $lines = t3lib_div::callUserFunction($_funcRef, $lines, $this);
00309 }
00310 }
00311
00312 $content = '<table border=0 cellpadding=2 cellspacing=2>'.implode('',$lines).'</table>';
00313 return $content;
00314 }
00315
00319 function view_result() {
00320 $this->makeFilesArray($this->saveKey);
00321
00322
00323 $this->wizArray['save']['overwrite_files'] = array();
00324
00325 $keyA = array_keys($this->fileArray);
00326 asort($keyA);
00327
00328 $filesOverview1=array();
00329 $filesOverview2=array();
00330 $filesContent=array();
00331
00332 $filesOverview1[]= '<tr'.$this->bgCol(1).'>
00333 <td><strong>' . $this->fw('Filename:') . '</strong></td>
00334 <td><strong>' . $this->fw('Size:') . '</strong></td>
00335 <td><strong>' . $this->fw(' ') . '</strong></td>
00336 <td><strong>' . $this->fw('Overwrite:') . '</strong></td>
00337 </tr>';
00338
00339 foreach($keyA as $fileName) {
00340 $data = $this->fileArray[$fileName];
00341
00342 $fI = pathinfo($fileName);
00343 if (t3lib_div::inList('php,sql,txt',strtolower($fI['extension']))) {
00344 $linkToFile='<strong><a href="#'.md5($fileName).'">'.$this->fw(" View ").'</a></strong>';
00345 $filesContent[]='<tr' .$this->bgCol(1) .'>
00346 <td><a name="' . md5($fileName) . '"></a><strong>' . $this->fw($fileName) . '</strong></td>
00347 </tr>
00348 <tr>
00349 <td>' . $this->preWrap($data['content']) . '</td>
00350 </tr>';
00351 } else $linkToFile=$this->fw(' ');
00352
00353 $line = '<tr' . $this->bgCol(2) . '>
00354 <td>' . $this->fw($fileName) . '</td>
00355 <td>' . $this->fw(t3lib_div::formatSize($data['size'])) . '</td>
00356 <td>' . $linkToFile . '</td>
00357 <td><input type="checkbox" name="' . $this->piFieldName('wizArray_upd') . '[save][overwrite_files][]" value="' . $fileName . '" checked="checked"></td>
00358 </tr>';
00359 if (strstr($fileName,'/')) {
00360 $filesOverview2[]=$line;
00361 } else {
00362 $filesOverview1[]=$line;
00363 }
00364 }
00365
00366 $content = '<table border=0 cellpadding=1 cellspacing=2>'.implode('',$filesOverview1).implode('',$filesOverview2).'</table>';
00367 $content.= $this->fw('<BR><strong>Author name:</strong> '.$GLOBALS['BE_USER']->user['realName'].'
00368 <BR><strong>Author email:</strong> '.$GLOBALS['BE_USER']->user['email']);
00369
00370
00371 $content.= '<BR><BR>';
00372 if (!$this->EMmode) {
00373 $content.='<input type="submit" name="'.$this->piFieldName('WRITE').'" value="WRITE to \''.$this->saveKey.'\'">';
00374 } else {
00375 $content.='
00376 <strong>'.$this->fw('Write to location:').'</strong><BR>
00377 <select name="'.$this->piFieldName('loc').'">'.
00378 ($this->pObj->importAsType('G')?'<option value="G">Global: '.$this->pObj->typePaths['G'].$this->saveKey.'/'.(@is_dir(PATH_site.$this->pObj->typePaths['G'].$this->saveKey)?' (OVERWRITE)':' (empty)').'</option>':'').
00379 ($this->pObj->importAsType('L')?'<option value="L">Local: '.$this->pObj->typePaths['L'].$this->saveKey.'/'.(@is_dir(PATH_site.$this->pObj->typePaths['L'].$this->saveKey)?' (OVERWRITE)':' (empty)').'</option>':'').
00380 '</select>
00381 <input type="submit" name="'.$this->piFieldName('WRITE').'" value="WRITE" onClick="return confirm(\'If the setting in the selectorbox says OVERWRITE\nthen the current extension in that location WILL be overridden! Totally!\nPlease decide if you want to continue.\n\n(Remember, this is a *kickstarter* - not an editor!)\');">
00382 ';
00383 }
00384
00385
00386 $this->afterContent= '<BR><table border=0 cellpadding=1 cellspacing=2>'.implode('',$filesContent).'</table>';
00387 return $content;
00388 }
00389
00390
00391
00395 function makeUploadDataFromArray($uploadArray) {
00396 if (is_array($uploadArray)) {
00397 $serialized = serialize($uploadArray);
00398 $md5 = md5($serialized);
00399
00400 $content=$md5.':';
00401
00402
00403
00404
00405 $content.=':';
00406 $content.=$serialized;
00407
00408 }
00409 return $content;
00410 }
00414 function makeUploadArray($extKey,$files) {
00415 $uploadArray=array();
00416 $uploadArray['extKey']=$extKey;
00417 $uploadArray['EM_CONF']=Array(
00418 'title' => '[No title]',
00419 'description' => '[Enter description of extension]',
00420 'category' => 'example',
00421 'author' => $this->userfield('name'),
00422 'author_email' => $this->userfield('email'),
00423
00424 );
00425
00426 $uploadArray['EM_CONF'] = array_merge($uploadArray['EM_CONF'],$this->makeEMCONFpreset(''));
00427
00428 if (is_array($this->_addArray)) {
00429 $uploadArray['EM_CONF'] = array_merge($uploadArray['EM_CONF'],$this->_addArray);
00430 }
00431 $uploadArray['misc']['codelines']=0;
00432 $uploadArray['misc']['codebytes']=0;
00433 $uploadArray['techInfo'] = '';
00434
00435
00436
00437 if(is_array($this->wizArray['save']['overwrite_files'])) {
00438 foreach($this->wizArray['save']['overwrite_files'] as $fileName) {
00439 $uploadArray['FILES'][$fileName] = $files[$fileName];
00440 }
00441 }
00442 return $uploadArray;
00443 }
00444
00445
00446 }
00447
00448
00449 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/kickstarter/class.tx_kickstarter_wizard.php']) {
00450 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/kickstarter/class.tx_kickstarter_wizard.php']);
00451 }
00452
00453 ?>