00001 <?php
00002
00011 class TKSnapMediaImageEditor extends TKSnapEditor {
00021 protected function showEditor($cm, $failed) {
00022 $form = new TKForm();
00023 $table = $form->addTable();
00024 $table->addTextTo('header', 'Upload/Resize Image', array('colspan' => 2, 'style' => array('font-size' => '1.4em')));
00025
00026 $table->addText("Image File", array('class' => array('snapInfoLabel')));
00027 $nb = $table->addNullBox();
00028 $upload = $nb->addFormInput('file', 'fileUpload');
00029 $upload->size = 30;
00030 $origOptions = $cm->getOptions();
00031 if($this->version->getContent() != "") {
00032 $nb->addText('<br />(leave blank to resize existing image)');
00033 }
00034
00035 $ts = isset($_REQUEST['thumbSize']) ? $_REQUEST['thumbSize'] :
00036 (isset($origOptions['thumbSize']) ? $origOptions['thumbSize'] : 'wide');
00037 $tw = isset($_REQUEST['thumbWidth']) ? $_REQUEST['thumbWidth'] :
00038 (isset($origOptions['thumbWidth']) ? $origOptions['thumbWidth'] : '150');
00039 $th = isset($_REQUEST['thumbHeight']) ? $_REQUEST['thumbHeight'] :
00040 (isset($origOptions['thumbHeight']) ? $origOptions['thumbHeight'] : '80');
00041 $twsc = isset($_REQUEST['thumbWidthScale']) ? $_REQUEST['thumbWidthScale'] :
00042 (isset($origOptions['thumbWidthScale']) ? $origOptions['thumbWidthScale'] : '25');
00043 $thsc = isset($_REQUEST['thumbHeightScale']) ? $_REQUEST['thumbHeightScale'] :
00044 (isset($origOptions['thumbHeightScale']) ? $origOptions['thumbHeightScale'] : '25');
00045 $tsc = isset($_REQUEST['thumbScale']) ? $_REQUEST['thumbScale'] :
00046 (isset($origOptions['thumbScale']) ? $origOptions['thumbScale'] : '25');
00047
00048 $ms = isset($_REQUEST['mediumSize']) ? $_REQUEST['mediumSize'] :
00049 (isset($origOptions['mediumSize']) ? $origOptions['mediumSize'] : 'standard');
00050 $mw = isset($_REQUEST['mediumWidth']) ? $_REQUEST['mediumWidth'] :
00051 (isset($origOptions['mediumWidth']) ? $origOptions['mediumWidth'] : '400');
00052 $mh = isset($_REQUEST['mediumHeight']) ? $_REQUEST['mediumHeight'] :
00053 (isset($origOptions['mediumHeight']) ? $origOptions['mediumHeight'] : '400');
00054 $mwsc = isset($_REQUEST['mediumWidthScale']) ? $_REQUEST['mediumWidthScale'] :
00055 (isset($origOptions['mediumWidthScale']) ? $origOptions['mediumWidthScale'] : '50');
00056 $mhsc = isset($_REQUEST['mediumHeightScale']) ? $_REQUEST['mediumHeightScale'] :
00057 (isset($origOptions['mediumHeightScale']) ? $origOptions['mediumHeightScale'] : '50');
00058 $msc = isset($_REQUEST['mediumScale']) ? $_REQUEST['mediumScale'] :
00059 (isset($origOptions['mediumScale']) ? $origOptions['mediumScale'] : '50');
00060
00061 $ds = isset($_REQUEST['displaySize']) ? $_REQUEST['displaySize'] :
00062 (isset($origOptions['displaySize']) ? $origOptions['displaySize'] : 'standard');
00063 $dw = isset($_REQUEST['displayWidth']) ? $_REQUEST['displayWidth'] :
00064 (isset($origOptions['displayWidth']) ? $origOptions['displayWidth'] : '600');
00065 $dh = isset($_REQUEST['displayHeight']) ? $_REQUEST['displayHeight'] :
00066 (isset($origOptions['displayHeight']) ? $origOptions['displayHeight'] : '600');
00067 $dwsc = isset($_REQUEST['displayWidthScale']) ? $_REQUEST['displayWidthScale'] :
00068 (isset($origOptions['displayWidthScale']) ? $origOptions['displayWidthScale'] : '100');
00069 $dhsc = isset($_REQUEST['displayHeightScale']) ? $_REQUEST['displayHeightScale'] :
00070 (isset($origOptions['displayHeightScale']) ? $origOptions['displayHeightScale'] : '100');
00071 $dsc = isset($_REQUEST['displayScale']) ? $_REQUEST['displayScale'] :
00072 (isset($origOptions['displayScale']) ? $origOptions['displayScale'] : '100');
00073
00074 $table->addRow();
00075 $table->addText("Thumb Size", array('class' => array('snapInfoLabel')));
00076 $table->add($this->makeSizeBox('thumb', array($tw,$th,$twsc,$thsc,$tsc), array('wide' => 'Standard (150x80)', 'square' => 'Square (80x80)'), $ts));
00077
00078 $table->addRow();
00079 $table->addText("Medium Size", array('class' => array('snapInfoLabel')));
00080 $table->add($this->makeSizebox('medium', array($mw,$mh,$mwsc,$mhsc,$msc), array('standard' => 'Standard(400x400)'), $ms));
00081
00082 $table->addRow();
00083 $table->addText("Display Size", array('class' => array('snapInfoLabel')));
00084 $table->add($this->makeSizebox('display', array($dw,$dh,$dwsc,$dhsc,$dsc), array('standard' => 'Standard(600x600)'), $ds));
00085
00086 $form->addText("<br />\n");
00087 $form->addFormInput('submit', 'snap2ed_save', "Save");
00088 $form->addFormInput('submit', 'snap2ed_saveAndExit', "Save and Exit");
00089 $form->addFormInput('submit', 'snap2ed_exit', "Exit without Saving");
00090 $form->addText("<br /><br />\n");
00091
00092 $this->add($form);
00093 }
00094
00106 private function makeSizeBox($sz, $nums, $sizes, $selected) {
00107 $title = ucfirst($sz);
00108 $sizeSelect = new TKSelect("${sz}Size");
00109 foreach($sizes as $name => $text) {
00110 $sizeSelect->addOption($name, $text);
00111 }
00112 $sizeSelect->addOption('customSize', "Custom Size");
00113 $sizeSelect->addOption('customScale', "Custom Scale");
00114 $sizeSelect->addOption('customScaleAspect', "Custom Scale (Keep Aspect)");
00115 $sizeSelect->selected = $selected;
00116
00117 $customSizeBox = new TKTable();
00118 $customSizeBox->addTextTo('header', "Custom $title Size", array('colspan' => 2));
00119 $customSizeBox->addText("Width", array('class' => array('snapInfoLabel')));
00120 $width = $customSizeBox->addFormInput('text', "${sz}Width", $nums[0]);
00121 $customSizeBox->addRow();
00122 $customSizeBox->addText("Height", array('class' => array('snapInfoLabel')));
00123 $height = $customSizeBox->addFormInput('text', "${sz}Height", $nums[1]);
00124 $customSizeBox->addRow();
00125 $tmp = $customSizeBox->addNullBox(array('colspan' => 2));
00126 $cb = $tmp->addCheckBox('lockSize', "Lock Aspect Ratio");
00127 $tmp->addText("Lock Aspect Ratio");
00128
00129 $cb->oncheck = array("var ${sz}_szchecked = false;\nvar ${sz}_aspect;", "${sz}_szchecked = true; ${sz}_aspect =
00130 document.getElementById('" . $height->getId() . "').value / document.getElementById('" . $width->getId() . "').value;");
00131 $cb->onuncheck = "${sz}_szchecked = false";
00132 $width->onkeyup = "if(${sz}_szchecked == true) {document.getElementById('" . $height->getId()
00133 . "').value = ${sz}_aspect * document.getElementById('" . $width->getId() . "').value }";
00134 $height->onkeyup = "if(${sz}_szchecked == true) {document.getElementById('" . $width->getId()
00135 . "').value = (1.0 / ${sz}_aspect) * document.getElementById('" . $height->getId() . "').value }";
00136
00137 $customScaleBox = new TKTable();
00138 $customScaleBox->addTextTo('header', "Custom $title Scale", array('colspan' => 2));
00139 $customScaleBox->addText("Width %", array('class' => array('snapInfoLabel')));
00140 $width = $customScaleBox->addFormInput('text', "${sz}WidthScale", $nums[2]);
00141 $customScaleBox->addRow();
00142 $customScaleBox->addText("Height %", array('class' => array('snapInfoLabel')));
00143 $height = $customScaleBox->addFormInput('text', "${sz}HeightScale", $nums[3]);
00144 $customScaleBox->addRow();
00145 $tmp = $customScaleBox->addNullBox(array('colspan' => 2));
00146 $cb = $tmp->addCheckBox('lockScale', "Lock Scale");
00147 $tmp->addText('Lock Scale');
00148
00149 $customScaleAspectBox = new TKTable();
00150 $customScaleAspectBox->addTextTo('header', "Custom $title Scale (Keep Aspect", array('colspan' => 2));
00151 $customScaleAspectBox->addText("Scale %", array('class' => array('snapInfoLabel')));
00152 $scale = $customScaleAspectBox->addFormInput('text', "${sz}Scale", $nums[4]);
00153
00154 $cb->oncheck = array("var ${sz}_checked = false", "${sz}_checked = true");
00155 $cb->onuncheck = "${sz}_checked = false";
00156 $width->onkeydown = "if(${sz}_checked == true) {document.getElementById('" . $height->getId()
00157 . "').value = document.getElementById('" . $width->getId() . "').value }";
00158 $height->onkeydown = "if(${sz}_checked == true) {document.getElementById('" . $width->getId()
00159 . "').value = document.getElementById('" . $height->getId() . "').value }";
00160 $width->onkeyup = "if(${sz}_checked == true) {document.getElementById('" . $height->getId()
00161 . "').value = document.getElementById('" . $width->getId() . "').value }";
00162 $height->onkeyup = "if(${sz}_checked == true) {document.getElementById('" . $width->getId()
00163 . "').value = document.getElementById('" . $height->getId() . "').value }";
00164
00165 $nb = new TKNullBox();
00166 $nb->add($sizeSelect);
00167 $nb->add($customSizeBox);
00168 $nb->add($customScaleBox);
00169 $nb->add($customScaleAspectBox);
00170 if($selected != 'customSize') {
00171 $customSizeBox->style['display'] = 'none';
00172 $customSizeBox->style['width'] = '100%';
00173 }
00174 if($selected != 'customScale') {
00175 $customScaleBox->style['display'] = 'none';
00176 $customScaleBox->style['width'] = '100%';
00177 }
00178 if($selected != 'customScaleAspect') {
00179 $customScaleAspectBox->style['display'] = 'none';
00180 $customScaleAspectBox->style['width'] = '100%';
00181 }
00182 $nb->style['width'] = '100%';
00183
00184 $i = count($sizes);
00185 $sizeSelect->setAction("onselect$i", new TKShowAction($customSizeBox));
00186 $sizeSelect->setAction("ondeselect$i", new TKHideAction($customSizeBox));
00187 $i++;
00188 $sizeSelect->setAction("onselect$i", new TKShowAction($customScaleBox));
00189 $sizeSelect->setAction("ondeselect$i", new TKHideAction($customScaleBox));
00190 $i++;
00191 $sizeSelect->setAction("onselect$i", new TKShowAction($customScaleAspectBox));
00192 $sizeSelect->setAction("ondeselect$i", new TKHideAction($customScaleAspectBox));
00193
00194 return $nb;
00195 }
00196
00205 protected function processSave($oldCM) {
00206 if(!isset($_FILES['fileUpload']) || $_FILES['fileUpload']['tmp_name'] == '') {
00207 $tmpFile = "";
00208 }
00209 else {
00210 $fileName = $_FILES['fileUpload']['name'];
00211 $tmpFile = $_FILES['fileUpload']['tmp_name'];
00212 }
00213
00214 $thumbSize = $_REQUEST['thumbSize'];
00215 $thumbWidth = $_REQUEST['thumbWidth'];
00216 $thumbHeight = $_REQUEST['thumbHeight'];
00217 $thumbWidthScale = $_REQUEST['thumbWidthScale'];
00218 $thumbHeightScale = $_REQUEST['thumbHeightScale'];
00219 $thumbScale = $_REQUEST['thumbScale'];
00220
00221 $mediumSize = $_REQUEST['mediumSize'];
00222 $mediumWidth = $_REQUEST['mediumWidth'];
00223 $mediumHeight = $_REQUEST['mediumHeight'];
00224 $mediumWidthScale = $_REQUEST['mediumWidthScale'];
00225 $mediumHeightScale = $_REQUEST['mediumHeightScale'];
00226 $mediumScale = $_REQUEST['mediumScale'];
00227
00228 $displaySize = $_REQUEST['displaySize'];
00229 $displayWidth = $_REQUEST['displayWidth'];
00230 $displayHeight = $_REQUEST['displayHeight'];
00231 $displayWidthScale = $_REQUEST['displayWidthScale'];
00232 $displayHeightScale = $_REQUEST['displayHeightScale'];
00233 $displayScale = $_REQUEST['displayScale'];
00234
00235 $options = array(
00236 'thumbSize' => $thumbSize,
00237 'thumbWidth' => $thumbWidth,
00238 'thumbHeight' => $thumbHeight,
00239 'thumbWidthScale' => $thumbWidthScale,
00240 'thumbHeightScale' => $thumbHeightScale,
00241 'thumbScale' => $thumbScale,
00242 'mediumSize' => $mediumSize,
00243 'mediumWidth' => $mediumWidth,
00244 'mediumHeight' => $mediumHeight,
00245 'mediumWidthScale' => $mediumWidthScale,
00246 'mediumHeightScale' => $mediumHeightScale,
00247 'mediumScale' => $mediumScale,
00248 'displaySize' => $displaySize,
00249 'displayWidth' => $displayWidth,
00250 'displayHeight' => $displayHeight,
00251 'displayWidthScale' => $displayWidthScale,
00252 'displayHeightScale' => $displayHeightScale,
00253 'displayScale' => $displayScale
00254 );
00255
00256 $params = array();
00257 if($thumbSize == 'customSize') {
00258 $params['thumbSize'] = array();
00259 $params['thumbSize']['width'] = $thumbWidth;
00260 $params['thumbSize']['height'] = $thumbHeight;
00261 }
00262 else if($thumbSize == 'customScale') {
00263 $scale = $thumbWidthScale / $thumbHeightScale;
00264 $params['thumbScale'] = $scale;
00265 }
00266 else if($thumbSize == 'customScaleAspect') {
00267 $params['thumbScale'] = $thumbScale / 100;
00268 }
00269 else {
00270 $params['thumb_resize'] = $thumbSize;
00271 }
00272
00273 if($mediumSize == 'customSize') {
00274 $params['mediumSize'] = array();
00275 $params['mediumSize']['width'] = $mediumWidth;
00276 $params['mediumSize']['height'] = $mediumHeight;
00277 }
00278 else if($mediumSize == 'customScale') {
00279 $scale = $mediumWidthScale / $mediumHeightScale;
00280 $params['mediumScale'] = $scale;
00281 }
00282 else if($mediumSize == 'customScaleAspect') {
00283 $params['mediumScale'] = $mediumScale / 100;
00284 }
00285 else {
00286 $params['medium_resize'] = $mediumSize;
00287 }
00288
00289 if($displaySize == 'customSize') {
00290 $params['displaySize'] = array();
00291 $params['displaySize']['width'] = $displayWidth;
00292 $params['displaySize']['height'] = $displayHeight;
00293 }
00294 else if($displaySize == 'customScale') {
00295 $scale = $displayWidthScale / $displayHeightScale;
00296 $params['displayScale'] = $scale;
00297 }
00298 else if($displaySize == 'customScaleAspect') {
00299 $params['displayScale'] = $displayScale / 100;
00300 }
00301 else {
00302 $params['display_resize'] = $displaySize;
00303 }
00304
00305 $cmNew = new SnapContentMediaImage($this->version);
00306
00307 if($tmpFile == "")
00308 $stat = $cmNew->rescaleImages($this->version->getContentModule(), $params);
00309 else
00310 $stat = $cmNew->uploadImage($tmpFile, $fileName, $params);
00311
00312 if(!$stat) {
00313 $html = "<p><b>Error:</b> Could not save document: " . $cmNew->getLastError() . "</p>";
00314 $this->addText($html);
00315 return false;
00316 }
00317
00318 $cmNew->setOptions($options);
00319
00320 return $cmNew;
00321 }
00322 }
00323
00324 ?>