$c = 0; foreach ($images as $k => $image) { if (!in_array($image['image'], $ImageNames)) { $ImageNames[$c] = $image['image']; $c++; } } if (!empty($ImageNames)) { $confs = $home_slider->getConfiguration($hook, $shop); $configuration = $confs[$hook]; $folder = dirname(__FILE__) . '/images/'; $success = false; foreach ($ImageNames as $in) { $resizeObj = new PerfectResize($folder . $in); $resizeObj->resizeImage($configuration['width'], $configuration['height'], 'crop'); $resizeObj->saveImage($folder . '/resize_' . $in, $quality); $success = true; } if ($success) { echo $home_slider->l('Images resized for slider') . ': ' . $hook; } else { echo $home_slider->l('No image to resize for') . ': ' . $hook; } } } } if (Tools::getValue('action') == 'alertNewVersion') { $v = Tools::getValue('params'); if (!empty($v)) { $settings = unserialize(Configuration::get('SLIDERSEVERYWHERE_SETS')); $settings['need_update'] = $v;
/** * Adds samples */ private function installSamples() { $languages = Language::getLanguages(false); $defaults['sample'] = $this->defaultConf; if ($this->isPS6) { $defaults['sample']['media']['max']['pos'] = 2; $defaults['sample']['media']['max']['lspace'] = 15; $defaults['sample']['media']['max']['rspace'] = 15; } $this->hook = array('sample'); $standardHooks = array('displayTop' => array(0 => 'sample')); if (Shop::isFeatureActive() && $this->context->shop->getContext() == Shop::CONTEXT_ALL) { $id_shops = Shop::getContextListShopID(); } else { $id_shops = array(0 => $this->getShopId()); } foreach ($id_shops as $id_shop) { $this->saveConfig('HOMESLIDERPRO_STANDARD', $standardHooks, (int) $id_shop); $this->saveConfig('HOMESLIDERPRO_HOOKS', $this->hook, (int) $id_shop); $this->saveSlideConfiguration($defaults, $id_shop); $folder = _PS_MODULE_DIR_ . $this->name . '/images/'; for ($i = 1; $i <= 5; ++$i) { $slide = new HomeSlidePro(); $slide->position = $i; $slide->active = 1; $slide->id_hook = 'sample'; $slide->has_area = 0; $resizeObj = new PerfectResize($folder . 'sample-' . $i . '.jpg'); $resizeObj->resizeImage($defaults['sample']['width'], $defaults['sample']['height'], 'crop'); $resizeObj->saveImage($folder . 'resize_' . 'sample-' . $i . '.jpg', 90); $resizeObj->resizeImage(60, 40, 'crop'); $resizeObj->saveImage($folder . 'thumb_' . 'sample-' . $i . '.jpg', 90); foreach ($languages as $language) { $slide->title[$language['id_lang']] = 'Sample ' . $i; $slide->description[$language['id_lang']] = 'This is a sample picture'; $slide->legend[$language['id_lang']] = 'sample-' . $i; $slide->url[$language['id_lang']] = 'http://www.syncrea.it'; $slide->image[$language['id_lang']] = 'sample-' . $i . '.jpg'; } $slide->add(true, false, (int) $id_shop); } } }
public function ajaxResponse() { $this->_conf = array(); //remove confirmation messages from admin controller... conflict with parameter name.. if (Tools::getValue('action') == 'updateSlidesPosition' && Tools::getValue('slides')) { $slides = Tools::getValue('slides'); foreach ($slides as $position => $id_slide) { $res = Db::getInstance()->execute(' UPDATE `' . _DB_PREFIX_ . 'homesliderpro_slides` SET `position` = ' . (int) $position . ' WHERE `id_homeslider_slides` = ' . (int) $id_slide); } echo $this->l('Positions Updated'); $this->module->clearCache(); } // ACTIVATE CMS HOOK if (Tools::getValue('action') == 'activateCMS') { $settings = $this->module->getConfig('SLIDERSEVERYWHERE_SETS'); if (!isset($settings['CMS']) || $settings['CMS'] == 0) { $cms_tpl = _PS_THEME_DIR_ . 'cms.tpl'; $cms_bakup = _PS_THEME_DIR_ . 'cms.tpl.bak'; $theme_file = file_get_contents($cms_tpl); if (strpos($theme_file, '{hook h="DisplaySlidersPro" CMS="1"}') !== false) { //hook found $settings['CMS'] = 1; $this->module->saveConfig('SLIDERSEVERYWHERE_SETS', $settings); echo $this->l('CMS functionality already activated'); exit; } else { if (strpos($theme_file, '{$cms->content}') !== false) { //string found if (!is_writable(_PS_THEME_DIR_)) { echo $this->l('Cannot create the backup, your theme directory is not writable'); exit; } file_put_contents($cms_bakup, $theme_file); $theme_file = str_replace('{$cms->content}', '<!-- added by SlidersEverywhere module -->' . "\n" . '{hook h="DisplaySlidersPro" CMS="1"}' . "\n" . '<!-- END added by SlidersEverywhere module -->' . "\n" . '{$cms->content}', $theme_file); file_put_contents($cms_tpl, $theme_file); $settings['CMS'] = 1; $this->module->saveConfig('SLIDERSEVERYWHERE_SETS', $settings); echo $this->l('CMS functionality activated!'); } else { echo $this->l('Cannot activate an error occurred!'); } } } else { echo $this->l('CMS functionality already activated'); exit; } $this->module->clearCache(); } // deactivate CMS hook; if (Tools::getValue('action') == 'deactivateCMS') { $settings = $this->module->getConfig('SLIDERSEVERYWHERE_SETS'); if (isset($settings['CMS']) && $settings['CMS'] == 1) { $cms_tpl = _PS_THEME_DIR_ . 'cms.tpl'; $cms_bakup = _PS_THEME_DIR_ . 'cms.tpl.bak'; if (file_exists($cms_bakup)) { if (unlink($cms_tpl)) { if (rename($cms_bakup, $cms_tpl)) { $settings['CMS'] = 0; $this->module->saveConfig('SLIDERSEVERYWHERE_SETS', $settings); echo $this->l('All done!'); } else { echo $this->l('Error: cannot rename ') . ' ' . $cms_bakup; } } else { echo $this->l('Error: cannot delete ') . ' ' . $cms_tpl; } } else { //backup doesn' t exists check if the module is activated $theme_file = file_get_contents($cms_tpl); if (strpos($theme_file, '{hook h="DisplaySlidersPro" CMS="1"}') !== false) { //it is activated but without backup echo $this->l('Error: backup file') . ' "' . $cms_bakup . '" ' . $this->l('not found! Please manually remove from cms.tpl') . ': {hook h="DisplaySlidersPro" CMS="1"}'; } else { // it wasn't activated update the database $settings['CMS'] = 0; $this->module->saveConfig('SLIDERSEVERYWHERE_SETS', $settings); echo $this->l('All done!'); } } } else { echo $this->l('Cannot deactivate unactive CMS functionality'); } } // ACTIVATE CATEGORY HOOK if (Tools::getValue('action') == 'activateCat') { $settings = $this->module->getConfig('SLIDERSEVERYWHERE_SETS'); if (!isset($settings['CAT']) || $settings['CAT'] == 0) { $checkVersion = version_compare(_PS_VERSION_, '1.6'); if ($checkVersion >= 0) { //we are on ps 1.6 $searchString = '{if $category->id AND $category->active}'; } else { //we are on ps 1.5 $searchString = '{if $scenes || $category->description || $category->id_image}'; } $cat_tpl = _PS_THEME_DIR_ . 'category.tpl'; $cat_bakup = _PS_THEME_DIR_ . 'category.tpl.bak'; $theme_file = file_get_contents($cat_tpl); //check if hook is in theme file if (strpos($theme_file, '{hook h="DisplaySlidersPro" CAT="1"}') !== false) { $settings['CAT'] = 1; $this->module->saveConfig('SLIDERSEVERYWHERE_SETS', $settings); echo $this->l('CATEGORY functionality already activated'); exit; } else { if (strpos($theme_file, $searchString) !== false) { if (!is_writable(_PS_THEME_DIR_)) { echo $this->l('Cannot create the backup, your theme directory is not writable'); exit; } file_put_contents($cat_bakup, $theme_file); $theme_file = str_replace($searchString, '<!-- added by SlidersEverywhere module -->' . "\n" . '{hook h="DisplaySlidersPro" CAT="1"}' . "\n" . '<!-- END added by SlidersEverywhere module -->' . "\n" . $searchString, $theme_file); file_put_contents($cat_tpl, $theme_file); $settings['CAT'] = 1; $this->module->saveConfig('SLIDERSEVERYWHERE_SETS', $settings); echo $this->l('CATEGORY functionality activated!'); } else { echo $this->l('Cannot activate an error occurred!'); } } } else { echo $this->l('CATEGORY functionality already activated'); exit; } $this->module->clearCache(); } // deactivate category hook if (Tools::getValue('action') == 'deactivateCat') { $settings = $this->module->getConfig('SLIDERSEVERYWHERE_SETS'); if (isset($settings['CAT']) && $settings['CAT'] == 1) { $cat_tpl = _PS_THEME_DIR_ . 'category.tpl'; $cat_bakup = _PS_THEME_DIR_ . 'category.tpl.bak'; if (file_exists($cat_bakup)) { if (unlink($cat_tpl)) { if (rename($cat_bakup, $cat_tpl)) { $settings['CAT'] = 0; $this->module->saveConfig('SLIDERSEVERYWHERE_SETS', $settings); echo $this->l('All done!'); } else { echo $this->l('Error: cannot rename') . ' ' . $cat_bakup; } } else { echo $this->l('Error: cannot delete') . ' ' . $cat_tpl; } } else { $theme_file = file_get_contents($cat_tpl); if (strpos($theme_file, '{hook h="DisplaySlidersPro" CAT="1"}') !== false) { //it is activated but without backup echo $this->l('Error: backup file') . ' "' . $cat_bakup . '" ' . $this->l('not found! Please manually remove from category.tpl') . ': {hook h="DisplaySlidersPro" CAT="1"}'; } else { // it wasn't activated update the database $settings['CAT'] = 0; $this->module->saveConfig('SLIDERSEVERYWHERE_SETS', $settings); echo $this->l('All done!'); } echo $this->l('Error: backup file') . ' "' . $cat_bakup . '" ' . $this->l('not found!'); } } else { echo $this->l('Cannot deactivate unactive CATEGORY functionality'); } } // edit Permissions if (Tools::getValue('action') == 'editPermissions') { $data = Tools::getValue('settings'); $settings = $this->module->getConfig('SLIDERSEVERYWHERE_SETS'); $settings['permissions'] = $data['permissions']; $settings['img_ql'] = $data['img_ql']; $settings['media_steps'] = $data['media_steps']; $this->module->saveConfig('SLIDERSEVERYWHERE_SETS', $settings); echo $this->l('Settings Saved!'); } // change slide active status if (Tools::getValue('action') == 'changeStatus') { $slide = new HomeSlidePro((int) Tools::getValue('id_slide')); if ($slide->active == 0) { $slide->active = 1; } else { $slide->active = 0; } $response = array(); $response['success'] = 0; if ($res = $slide->update()) { $response['success'] = 1; } $response['message'] = $res ? $this->l('Status changed!') : $this->l('The status cannot be changed.'); echo json_encode($response); } if (Tools::getValue('action') == 'updateConfiguration') { $configs = Tools::getValue('configs'); $shop = Tools::getValue('shop'); if ($this->module->saveSlideConfiguration($configs, $shop)) { echo $this->l('Configuration updated', $filename); } else { echo $this->l('Problem changing configuration'); } } if (Tools::getValue('action') == 'updateDB') { $sql = 'ALTER TABLE `' . _DB_PREFIX_ . 'category` ADD proslider varchar(255) NULL'; if (Db::getInstance()->execute($sql)) { echo $this->l('Database Updated!'); } else { echo $this->l('Error Occurred'); } } if (Tools::getValue('action') == 'updateModule') { if ($this->downloadUpdate($this->module)) { $settings = $this->module->getConfig('SLIDERSEVERYWHERE_SETS'); $settings['need_update'] = 0; $this->module->saveConfig('SLIDERSEVERYWHERE_SETS', $settings); echo $this->l('Module Updated!'); } else { echo $this->l('Error'); } } /** ajax image resize */ if (Tools::getValue('action') == 'resizeImages') { $settings = $this->module->getConfig('SLIDERSEVERYWHERE_SETS'); $quality = isset($settings['img_ql']) ? $settings['img_ql'] : 90; $hook = Tools::getValue('hookname'); $sql = 'SELECT lang.image , sl.id_homeslider_slides FROM `' . _DB_PREFIX_ . 'homesliderpro` sl LEFT JOIN `' . _DB_PREFIX_ . 'homesliderpro_slides_lang` lang ON (sl.id_homeslider_slides = lang.id_homeslider_slides) WHERE sl.id_hook = "' . $hook . '"'; if ($images = Db::getInstance()->executeS($sql)) { $ImageNames = array(); $c = 0; foreach ($images as $k => $image) { if (!in_array($image['image'], $ImageNames)) { $ImageNames[$c] = $image['image']; $c++; } } if (!empty($ImageNames)) { $confs = $this->module->getSlideConfiguration($hook, $shop); $configuration = $confs[$hook]; $folder = dirname(__FILE__) . '/images/'; $success = false; foreach ($ImageNames as $in) { $resizeObj = new PerfectResize($folder . $in); $resizeObj->resizeImage($configuration['width'], $configuration['height'], 'crop'); $resizeObj->saveImage($folder . '/resize_' . $in, $quality); $success = true; } if ($success) { echo $this->l('Images resized for slider') . ': ' . $hook; } else { echo $this->l('No image to resize for') . ': ' . $hook; } } } } // new version alert if (Tools::getValue('action') == 'alertNewVersion') { $v = Tools::getValue('params'); if (!empty($v)) { $settings = $this->module->getConfig('SLIDERSEVERYWHERE_SETS'); $settings['need_update'] = $v; $this->module->saveConfig('SLIDERSEVERYWHERE_SETS', $settings); echo 'New Version Available: ' . $v; } } // autocomplete helpre for product filters if (Tools::getValue('action') == 'autocomplete') { if (Tools::getValue('value') == 'products') { $s = Tools::getValue('s'); $q = 'SELECT DISTINCT `name`, `id_product` FROM `' . _DB_PREFIX_ . 'product_lang` WHERE `name` LIKE "%' . $s . '%" LIMIT 10'; if ($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($q)) { $response = array(); foreach ($result as $k => $r) { $response[$k]['label'] = $r['name']; $response[$k]['value'] = $r['id_product']; } echo json_encode($response); } } } }