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
00060 $BACK_PATH = '';
00061 require('init.php');
00062 require('template.php');
00063 require_once(PATH_t3lib.'class.t3lib_stdgraphic.php');
00064 $LANG->includeLLFile('EXT:lang/locallang_wizards.xml');
00065
00075 class SC_wizard_colorpicker {
00076
00077
00078 var $P;
00079 var $colorValue;
00080 var $fieldChangeFunc;
00081 var $fieldName;
00082 var $formName;
00083 var $md5ID;
00084 var $showPicker;
00085
00086
00087 var $HTMLcolorList = "aqua,black,blue,fuchsia,gray,green,lime,maroon,navy,olive,purple,red,silver,teal,yellow,white";
00088
00089
00090 var $pickerImage = '';
00091 var $imageError = '';
00092 var $doc;
00093 var $content;
00094
00095
00096
00097
00103 function init() {
00104 global $BACK_PATH, $LANG;
00105
00106
00107 $this->P = t3lib_div::_GP('P',1);
00108
00109
00110 $this->colorValue = t3lib_div::_GP('colorValue');
00111 $this->fieldChangeFunc = t3lib_div::_GP('fieldChangeFunc');
00112 $this->fieldName = t3lib_div::_GP('fieldName');
00113 $this->formName = t3lib_div::_GP('formName');
00114 $this->md5ID = t3lib_div::_GP('md5ID');
00115 $this->exampleImg = t3lib_div::_GP('exampleImg');
00116
00117
00118
00119 $this->imageError = '';
00120 if ($this->exampleImg) {
00121 $this->pickerImage = t3lib_div::getFileAbsFileName($this->exampleImg,1,1);
00122 if (!$this->pickerImage || !@is_file($this->pickerImage)) {
00123 $this->imageError = 'ERROR: The image, "'.$this->exampleImg.'", could not be found!';
00124 }
00125 }
00126
00127
00128 $fieldChangeFuncArr = unserialize($this->fieldChangeFunc);
00129 $update = '';
00130 if (is_array($fieldChangeFuncArr)) {
00131 unset($fieldChangeFuncArr['alert']);
00132 foreach($fieldChangeFuncArr as $v) {
00133 $update.= '
00134 parent.opener.'.$v;
00135 }
00136 }
00137
00138
00139 $this->doc = t3lib_div::makeInstance('smallDoc');
00140 $this->doc->backPath = $BACK_PATH;
00141 $this->doc->docType = 'xhtml_trans';
00142 $this->doc->JScode = $this->doc->wrapScriptTags('
00143 function checkReference() {
00144 if (parent.opener && parent.opener.document && parent.opener.document.'.$this->formName.' && parent.opener.document.'.$this->formName.'["'.$this->fieldName.'"]) {
00145 return parent.opener.document.'.$this->formName.'["'.$this->fieldName.'"];
00146 } else {
00147 close();
00148 }
00149 }
00150 function changeBGcolor(color) {
00151 if (parent.opener.document.layers) {
00152 parent.opener.document.layers["'.$this->md5ID.'"].bgColor = color;
00153 } else if (parent.opener.document.all) {
00154 parent.opener.document.all["'.$this->md5ID.'"].style.background = color;
00155 } else if (parent.opener.document.getElementById && parent.opener.document.getElementById("'.$this->md5ID.'")) {
00156 parent.opener.document.getElementById("'.$this->md5ID.'").bgColor = color;
00157 }
00158 }
00159 function setValue(input) {
00160 var field = checkReference();
00161 if (field) {
00162 field.value = input;
00163 '.$update.'
00164 changeBGcolor(input);
00165 }
00166 }
00167 function getValue() {
00168 var field = checkReference();
00169 return field.value;
00170 }
00171 ');
00172
00173
00174 $this->content.=$this->doc->startPage($LANG->getLL('colorpicker_title'));
00175 }
00176
00182 function main() {
00183 global $LANG;
00184
00185 if(!t3lib_div::_GP('showPicker')) {
00186 $this->frameSet();
00187 } else {
00188
00189
00190 $content = '
00191 <form name="colorform" method="post" action="wizard_colorpicker.php">
00192 '.$this->colorMatrix().'
00193 '.$this->colorList().'
00194 '.$this->colorImage().'
00195
00196 <!-- Value box: -->
00197 <p class="c-head">'.$LANG->getLL('colorpicker_colorValue',1).'</p>
00198 <table border="0" cellpadding="0" cellspacing="3">
00199 <tr>
00200 <td><input type="text" '.$this->doc->formWidth(7).' maxlength="10" name="colorValue" value="'.htmlspecialchars($this->colorValue).'" /></td>
00201 <td style="background-color:'.htmlspecialchars($this->colorValue).'; border: 1px solid black;"> <span style="color: black;">'.$LANG->getLL('colorpicker_black',1).'</span> <span style="color: white;">'.$LANG->getLL('colorpicker_white',1).'</span> </td>
00202 <td><input type="submit" name="save_close" value="'.$LANG->getLL('colorpicker_setClose',1).'" /></td>
00203 </tr>
00204 </table>
00205
00206 <!-- Hidden fields with values that has to be kept constant -->
00207 <input type="hidden" name="showPicker" value="1" />
00208 <input type="hidden" name="fieldChangeFunc" value="'.htmlspecialchars($this->fieldChangeFunc).'" />
00209 <input type="hidden" name="fieldName" value="'.htmlspecialchars($this->fieldName).'" />
00210 <input type="hidden" name="formName" value="'.htmlspecialchars($this->formName).'" />
00211 <input type="hidden" name="md5ID" value="'.htmlspecialchars($this->md5ID).'" />
00212 <input type="hidden" name="exampleImg" value="'.htmlspecialchars($this->exampleImg).'" />
00213 </form>';
00214
00215
00216 if(t3lib_div::_GP('save_close')) {
00217 $content.=$this->doc->wrapScriptTags('
00218 setValue(\''.$this->colorValue.'\');
00219 parent.close();
00220 ');
00221 }
00222
00223
00224 $this->content.=$this->doc->section($LANG->getLL('colorpicker_title'), $content, 0,1);
00225 $this->content.=$this->doc->endPage();
00226 }
00227 }
00228
00234 function printContent() {
00235 echo $this->content;
00236 }
00237
00245 function frameSet() {
00246 global $LANG;
00247
00248
00249 $GLOBALS['TBE_TEMPLATE']->docType = 'xhtml_frames';
00250 $GLOBALS['TBE_TEMPLATE']->JScode = $GLOBALS['TBE_TEMPLATE']->wrapScriptTags('
00251 if (!window.opener) {
00252 alert("ERROR: Sorry, no link to main window... Closing");
00253 close();
00254 }
00255 ');
00256
00257 $this->content = $GLOBALS['TBE_TEMPLATE']->startPage($LANG->getLL('colorpicker_title'));
00258
00259
00260 $url = 'wizard_colorpicker.php?showPicker=1'.
00261 '&colorValue='.rawurlencode($this->P['currentValue']).
00262 '&fieldName='.rawurlencode($this->P['itemName']).
00263 '&formName='.rawurlencode($this->P['formName']).
00264 '&exampleImg='.rawurlencode($this->P['exampleImg']).
00265 '&md5ID='.rawurlencode($this->P['md5ID']).
00266 '&fieldChangeFunc='.rawurlencode(serialize($this->P['fieldChangeFunc']));
00267
00268 $this->content.='
00269 <frameset rows="*,1" framespacing="0" frameborder="0" border="0">
00270 <frame name="content" src="'.htmlspecialchars($url).'" marginwidth="0" marginheight="0" frameborder="0" scrolling="auto" noresize="noresize" />
00271 <frame name="menu" src="dummy.php" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" noresize="noresize" />
00272 </frameset>
00273 ';
00274
00275 $this->content.='
00276 </html>';
00277 }
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00304 function colorMatrix() {
00305 global $LANG;
00306
00307 $steps = 51;
00308
00309
00310 $color = array();
00311
00312 for($rr=0;$rr<256;$rr+=$steps) {
00313 for($gg=0;$gg<256;$gg+=$steps) {
00314 for($bb=0;$bb<256;$bb+=$steps) {
00315 $color[] = '#'.
00316 substr('0'.dechex($rr),-2).
00317 substr('0'.dechex($gg),-2).
00318 substr('0'.dechex($bb),-2);
00319 }
00320 }
00321 }
00322
00323
00324 $columns = 24;
00325
00326 $rows = 0;
00327 $tRows = array();
00328 while(isset($color[$columns*$rows])) {
00329 $tCells = array();
00330 for($i=0;$i<$columns;$i++) {
00331 $tCells[] = '
00332 <td bgcolor="'.$color[$columns*$rows+$i].'" onclick="document.colorform.colorValue.value = \''.$color[$columns*$rows+$i].'\'; document.colorform.submit();" title="'.$color[$columns*$rows+$i].'"> </td>';
00333 }
00334 $tRows[] = '
00335 <tr>'.implode('',$tCells).'
00336 </tr>';
00337 $rows++;
00338 }
00339
00340 $table = '
00341 <p class="c-head">'.$LANG->getLL('colorpicker_fromMatrix',1).'</p>
00342 <table border="0" cellpadding="1" cellspacing="1" style="width:100%; border: 1px solid black; cursor:crosshair;">'.implode('',$tRows).'
00343 </table>';
00344
00345 return $table;
00346 }
00347
00353 function colorList() {
00354 global $LANG;
00355
00356
00357 $colors = explode(',',$this->HTMLcolorList);
00358 $currentValue = strtolower($this->colorValue);
00359 $opt = array();
00360 $opt[] = '<option value=""></option>';
00361
00362
00363 foreach($colors as $colorName) {
00364 $opt[] = '<option style="background-color: '.$colorName.';" value="'.htmlspecialchars($colorName).'"'.($currentValue==$colorName ? ' selected="selected"' : '').'>'.htmlspecialchars($colorName).'</option>';
00365 }
00366
00367
00368 $output = '
00369 <p class="c-head">'.$LANG->getLL('colorpicker_fromList',1).'</p>
00370 <select onchange="document.colorform.colorValue.value = this.options[this.selectedIndex].value; document.colorform.submit(); return false;">
00371 '.implode('
00372 ',$opt).'
00373 </select><br/>';
00374
00375 return $output;
00376 }
00377
00383 function colorImage() {
00384 global $LANG;
00385
00386
00387 if (!$this->imageError) {
00388 if ($this->pickerImage) {
00389 if(t3lib_div::_POST('coords_x')) {
00390 $this->colorValue = '#'.$this->getIndex(t3lib_stdgraphic::imageCreateFromGif($this->pickerImage),t3lib_div::_POST('coords_x'),t3lib_div::_POST('coords_y'));
00391 }
00392 $pickerFormImage = '
00393 <p class="c-head">'.$LANG->getLL('colorpicker_fromImage',1).'</p>
00394 <input type="image" src="../'.substr($this->pickerImage,strlen(PATH_site)).'" name="coords" style="cursor:crosshair;" /><br />';
00395 } else {
00396 $pickerFormImage = '';
00397 }
00398 } else {
00399 $pickerFormImage = '
00400 <p class="c-head">'.htmlspecialchars($this->imageError).'</p>';
00401 }
00402
00403 return $pickerFormImage;
00404 }
00405
00416 function getIndex($im,$x,$y) {
00417 $rgb = ImageColorAt($im, $x, $y);
00418 $colorrgb = imagecolorsforindex($im,$rgb);
00419 $index['r'] = dechex($colorrgb['red']);
00420 $index['g'] = dechex($colorrgb['green']);
00421 $index['b'] = dechex($colorrgb['blue']);
00422 foreach ($index as $value) {
00423 if(strlen($value) == 1) {
00424 $hexvalue[] = strtoupper('0'.$value);
00425 } else {
00426 $hexvalue[] = strtoupper($value);
00427 }
00428 }
00429 $hex = implode('',$hexvalue);
00430 return $hex;
00431 }
00432 }
00433
00434
00435 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_colorpicker.php']) {
00436 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_colorpicker.php']);
00437 }
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451 $SOBE = t3lib_div::makeInstance('SC_wizard_colorpicker');
00452 $SOBE->init();
00453 $SOBE->main();
00454 $SOBE->printContent();
00455 ?>