name = 'gmcrop'; $this->prefix = strtoupper($this->name); $this->tab = 'administration'; $this->version = '1.2.3'; $this->author = 'GreenMouseStudio.com'; $this->need_instance = 0; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Perfect Thumbnails'); $this->description = $this->l('Crop images instead of adding whitespace around them'); $this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_); $this->getConfiguration(); } protected function getConfiguration() { $this->cropOrigin = Configuration::get($this->prefix.'_ORIGIN'); $this->backgroundColor = Configuration::get($this->prefix.'_BGCOLOR'); $imageTypesString = Configuration::get($this->prefix.'_CROPPEDTYPES'); $this->croppedImageTypes = explode(',', $imageTypesString); $this->cropBackground = (bool)Configuration::get($this->prefix.'_CROPBG'); $this->optimizeForBandwitdh = (bool)Configuration::get($this->prefix.'_BANDWIDTH'); $optimizedTypesString = Configuration::get($this->prefix.'_FITTEDTYPES'); $this->fittedImageTypes = explode(',', $optimizedTypesString); } public function install() { return parent::install() && Configuration::updateValue($this->prefix.'_ORIGIN', 4) && Configuration::updateValue($this->prefix.'_BGCOLOR', '#ffffff') && Configuration::updateValue($this->prefix.'_CROPPEDTYPES', 'home_default') && Configuration::updateValue($this->prefix.'_CROPBG', true) && Configuration::updateValue($this->prefix.'_FITTEDTYPES', 'thickbox_default') && $this->registerHook('displayBackOfficeHeader'); } public function uninstall() { Configuration::deleteByName($this->prefix.'_ORIGIN'); Configuration::deleteByName($this->prefix.'_BGCOLOR'); Configuration::deleteByName($this->prefix.'_CROPPEDTYPES'); Configuration::deleteByName($this->prefix.'_FITTEDTYPES'); Configuration::deleteByName($this->prefix.'_CROPBG'); return parent::uninstall(); } public function getContent() { $this->getConfiguration(); $output = ''; if (((bool) Tools::isSubmit($this->name.'submit')) == true) { $this->postProcess(); $output .= $this->displayConfirmation($this->l('Settings updated')); } $output .= $this->renderForm(); return $output; } protected function getImagesTypes() { $data = array(); $imagesTypes = ImageType::getImagesTypes(); foreach ($imagesTypes as $type) { $data[] = $type['name']; } return $data; } protected function renderTypesCheckboxes($name, $label, $selectedTypes) { $content = '
'; $imageTypes = $this->getImagesTypes(); foreach ($imageTypes as $type) { $content .= '
'; $content .= '
'; } $content .= '
'; return $content; } protected function renderPanelFooter() { $output = ''; return $output; } protected function renderForm() { $output = '
' .'
' .$this->l('Settings') .'
' .'
' .'
'; if (function_exists('imagecropauto')) { $output .= $this->renderCheckbox($this->prefix.'_CROPBG', $this->l('Extract product from background'), $this->cropBackground, $this->l('Removes white or transparent background around the product on the original image.')); } $output .= $this->renderTypesCheckboxes('GMCROP_FITTEDTYPES', $this->l('Keep original proportions for images of type:'), $this->fittedImageTypes); $output .= $this->renderOriginMatrix(); $output .= $this->renderTypesCheckboxes('GMCROP_CROPPEDTYPES', $this->l('Crop images of type:'), $this->croppedImageTypes); $output .= $this->renderColorPicker(); $output .= $this->renderPanelFooter(); $output .= '
'; return $output; } protected function renderOriginMatrix() { $output = '
'; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= '
cropOrigin == 0) { $output .= ' checked="checked" '; } $output .= '/>cropOrigin == 1) { $output .= ' checked="checked" '; } $output .= '/>cropOrigin == 2) { $output .= ' checked="checked" '; } $output .= '/>
cropOrigin == 3) { $output .= ' checked="checked" '; } $output .= '/>cropOrigin == 4) { $output .= ' checked="checked" '; } $output .= '/>cropOrigin == 5) { $output .= ' checked="checked" '; } $output .= '/>
cropOrigin == 6) { $output .= ' checked="checked" '; } $output .= '/>cropOrigin == 7) { $output .= ' checked="checked" '; } $output .= '/>cropOrigin == 8) { $output .= ' checked="checked" '; } $output .= '/>
'; $output .= '
'; return $output; } protected function renderTextInput($name, $label, $value = null, $help = null) { $content = '
'; if ($help != null) { $content .= '

'.$help.'

'; } $content .= '
'; return $content; } protected function renderCheckbox($name, $label, $checked = false, $help = null, $onText = null, $offText = null) { if (!$onText) { $onText = $this->l('Yes'); } if (!$offText) { $offText = $this->l('No'); } $content = '
'.$onText.' '.$offText.' '; if ($help != null) { $content .= '

'.$help.'

'; } $content .='
'; return $content; } protected function renderColorPicker() { $content = ''; $content .= '
'; return $content; } protected function postProcess() { $this->cropOrigin = Tools::getValue($this->prefix.'_ORIGIN'); $this->backgroundColor = Tools::getValue($this->prefix.'_BGCOLOR'); $this->croppedImageTypes = Tools::getValue($this->prefix.'_CROPPEDTYPES'); $this->cropBackground = Tools::getValue($this->prefix.'_CROPBG'); $this->optimizeForBandwitdh = Tools::getValue($this->prefix.'_BANDWIDTH'); $this->fittedImageTypes = Tools::getValue($this->prefix.'_FITTEDTYPES'); $this->updateConfiguration(); } protected function updateConfiguration() { Configuration::updateValue($this->prefix.'_ORIGIN', $this->cropOrigin); Configuration::updateValue($this->prefix.'_BGCOLOR', $this->backgroundColor); $croppedTypesString = ''; if (is_array($this->croppedImageTypes)) { $croppedTypesString = implode(',', $this->croppedImageTypes); } Configuration::updateValue($this->prefix.'_CROPPEDTYPES', $croppedTypesString); Configuration::updateValue($this->prefix.'_CROPBG', $this->cropBackground); $fittedTypesString = ''; if (is_array($this->fittedImageTypes)) { $fittedTypesString = implode(',', $this->fittedImageTypes); } Configuration::updateValue($this->prefix.'_FITTEDTYPES', $fittedTypesString); return true; } public function hookDisplayBackOfficeHeader() { $this->context->controller->addJquery(); $this->context->controller->addjqueryPlugin('colorpicker'); } }