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 }
00226 }
00227
00233 function printContent() {
00234 $this->content.= $this->doc->endPage();
00235 $this->content = $this->doc->insertStylesAndJS($this->content);
00236 echo $this->content;
00237 }
00238
00246 function frameSet() {
00247 global $LANG;
00248
00249
00250 $GLOBALS['TBE_TEMPLATE']->docType = 'xhtml_frames';
00251 $GLOBALS['TBE_TEMPLATE']->JScode = $GLOBALS['TBE_TEMPLATE']->wrapScriptTags('
00252 if (!window.opener) {
00253 alert("ERROR: Sorry, no link to main window... Closing");
00254 close();
00255 }
00256 ');
00257
00258 $this->content = $GLOBALS['TBE_TEMPLATE']->startPage($LANG->getLL('colorpicker_title'));
00259
00260
00261 $url = 'wizard_colorpicker.php?showPicker=1'.
00262 '&colorValue='.rawurlencode($this->P['currentValue']).
00263 '&fieldName='.rawurlencode($this->P['itemName']).
00264 '&formName='.rawurlencode($this->P['formName']).
00265 '&exampleImg='.rawurlencode($this->P['exampleImg']).
00266 '&md5ID='.rawurlencode($this->P['md5ID']).
00267 '&fieldChangeFunc='.rawurlencode(serialize($this->P['fieldChangeFunc']));
00268
00269 $this->content.='
00270 <frameset rows="*,1" framespacing="0" frameborder="0" border="0">
00271 <frame name="content" src="'.htmlspecialchars($url).'" marginwidth="0" marginheight="0" frameborder="0" scrolling="auto" noresize="noresize" />
00272 <frame name="menu" src="dummy.php" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" noresize="noresize" />
00273 </frameset>
00274 ';
00275
00276 $this->content.='
00277 </html>';
00278 }
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00305 function colorMatrix() {
00306 global $LANG;
00307
00308 $steps = 51;
00309
00310
00311 $color = array();
00312
00313 for($rr=0;$rr<256;$rr+=$steps) {
00314 for($gg=0;$gg<256;$gg+=$steps) {
00315 for($bb=0;$bb<256;$bb+=$steps) {
00316 $color[] = '#'.
00317 substr('0'.dechex($rr),-2).
00318 substr('0'.dechex($gg),-2).
00319 substr('0'.dechex($bb),-2);
00320 }
00321 }
00322 }
00323
00324
00325 $columns = 24;
00326
00327 $rows = 0;
00328 $tRows = array();
00329 while(isset($color[$columns*$rows])) {
00330 $tCells = array();
00331 for($i=0;$i<$columns;$i++) {
00332 $tCells[] = '
00333 <td bgcolor="'.$color[$columns*$rows+$i].'" onclick="document.colorform.colorValue.value = \''.$color[$columns*$rows+$i].'\'; document.colorform.submit();" title="'.$color[$columns*$rows+$i].'"> </td>';
00334 }
00335 $tRows[] = '
00336 <tr>'.implode('',$tCells).'
00337 </tr>';
00338 $rows++;
00339 }
00340
00341 $table = '
00342 <p class="c-head">'.$LANG->getLL('colorpicker_fromMatrix',1).'</p>
00343 <table border="0" cellpadding="1" cellspacing="1" style="width:100%; border: 1px solid black; cursor:crosshair;">'.implode('',$tRows).'
00344 </table>';
00345
00346 return $table;
00347 }
00348
00354 function colorList() {
00355 global $LANG;
00356
00357
00358 $colors = explode(',',$this->HTMLcolorList);
00359 $currentValue = strtolower($this->colorValue);
00360 $opt = array();
00361 $opt[] = '<option value=""></option>';
00362
00363
00364 foreach($colors as $colorName) {
00365 $opt[] = '<option style="background-color: '.$colorName.';" value="'.htmlspecialchars($colorName).'"'.($currentValue==$colorName ? ' selected="selected"' : '').'>'.htmlspecialchars($colorName).'</option>';
00366 }
00367
00368
00369 $output = '
00370 <p class="c-head">'.$LANG->getLL('colorpicker_fromList',1).'</p>
00371 <select onchange="document.colorform.colorValue.value = this.options[this.selectedIndex].value; document.colorform.submit(); return false;">
00372 '.implode('
00373 ',$opt).'
00374 </select><br/>';
00375
00376 return $output;
00377 }
00378
00384 function colorImage() {
00385 global $LANG;
00386
00387
00388 if (!$this->imageError) {
00389 if ($this->pickerImage) {
00390 if(t3lib_div::_POST('coords_x')) {
00391 $this->colorValue = '#'.$this->getIndex(t3lib_stdgraphic::imageCreateFromFile($this->pickerImage),t3lib_div::_POST('coords_x'),t3lib_div::_POST('coords_y'));
00392 }
00393 $pickerFormImage = '
00394 <p class="c-head">'.$LANG->getLL('colorpicker_fromImage',1).'</p>
00395 <input type="image" src="../'.substr($this->pickerImage,strlen(PATH_site)).'" name="coords" style="cursor:crosshair;" /><br />';
00396 } else {
00397 $pickerFormImage = '';
00398 }
00399 } else {
00400 $pickerFormImage = '
00401 <p class="c-head">'.htmlspecialchars($this->imageError).'</p>';
00402 }
00403
00404 return $pickerFormImage;
00405 }
00406
00417 function getIndex($im,$x,$y) {
00418 $rgb = ImageColorAt($im, $x, $y);
00419 $colorrgb = imagecolorsforindex($im,$rgb);
00420 $index['r'] = dechex($colorrgb['red']);
00421 $index['g'] = dechex($colorrgb['green']);
00422 $index['b'] = dechex($colorrgb['blue']);
00423 foreach ($index as $value) {
00424 if(strlen($value) == 1) {
00425 $hexvalue[] = strtoupper('0'.$value);
00426 } else {
00427 $hexvalue[] = strtoupper($value);
00428 }
00429 }
00430 $hex = implode('',$hexvalue);
00431 return $hex;
00432 }
00433 }
00434
00435
00436 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_colorpicker.php']) {
00437 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_colorpicker.php']);
00438 }
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452 $SOBE = t3lib_div::makeInstance('SC_wizard_colorpicker');
00453 $SOBE->init();
00454 $SOBE->main();
00455 $SOBE->printContent();
00456 ?>