Skip to content

Commit

Permalink
Version 6.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
luigifab committed Jul 7, 2021
1 parent 6c9b851 commit 772ae8b
Show file tree
Hide file tree
Showing 49 changed files with 513 additions and 282 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
# apijs

Beautiful javascript popup and slideshow for [OpenMage](https://github.com/OpenMage/magento-lts).
JavaScript pop-ups and slideshow for [OpenMage](https://github.com/OpenMage/magento-lts).

For more information, go to https://www.luigifab.fr/apijs and https://www.luigifab.fr/openmage/apijs (IPv6 is required, it's not a joke). No IPv6? It's possible to get an IPv6 thanks to *Miredo*. Run `sudo apt install miredo` and `sudo service miredo force-start`.

- for the app, go to [apijs](https://www.github.com/luigifab/apijs)
- for the plugin for Redmine, go to [redmine-apijs](https://www.github.com/luigifab/redmine-apijs)
- for the bundle for Symfony, go to [symfony-apijs](https://www.github.com/luigifab/symfony-apijs)

This repository is a releases mirror. To install the module, please use the composer key available in the documentation.

- Current version: 6.6.0 (03/03/2021)
- Current version: 6.7.0 (07/07/2021)
- Compatibility: OpenMage 19.x / 20.x, PHP 7.2 / 7.3 / 7.4 / 8.0, Python 3.3 / 3.4 / 3.5 / 3.6 / 3.7 / 3.8 / 3.9
- Client compatibility: Firefox 36+, Chrome 32+, Opera 19+, Edge 16+, Safari 9+
- Translations: English (en), French (fr-FR/fr-CA), German (de), Italian (it), Portuguese (pt-PT/pt-BR), Spanish (es)
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"type": "magento-module",
"name": "luigifab/openmage-apijs",
"description": "Beautiful javascript popup and slideshow for OpenMage.",
"description": "JavaScript pop-ups and slideshow for OpenMage.",
"keywords": ["openmage", "openmage-module"],
"homepage": "https://github.com/luigifab/openmage-apijs",
"license": "GPL-2.0-or-later",
"authors": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created V/23/05/2014
* Updated V/12/02/2021
* Updated L/24/05/2021
*
* Copyright 2008-2021 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/apijs
Expand All @@ -23,14 +23,12 @@ public function render(Varien_Data_Form_Element_Abstract $element) {

$msg = $this->checkRewrites();
if ($msg !== true)
return sprintf('<p class="box">%s %s <span class="right"><a href="https://www.%s">%3$s</a> | ⚠ IPv6</span></p>'.
'<p class="box" style="margin-top:-5px; color:white; background-color:#E60000;"><strong>%s</strong><br />%s</p>',
return sprintf('<p class="box">%s %s <span class="right"><a href="https://www.%s">%3$s</a> | ⚠ IPv6</span></p><p class="box" style="margin-top:-5px; color:white; background-color:#E60000;"><strong>%s</strong><br />%s</p>',
'Luigifab/Apijs', $this->helper('apijs')->getVersion(), 'luigifab.fr/openmage/apijs',
$this->__('INCOMPLETE MODULE INSTALLATION'),
$this->__('There is conflict (<em>%s</em>).', $msg));

return sprintf('<p class="box">%s %s '.
'<span class="right"><a href="https://www.%s">%3$s</a> | <a href="https://www.%4$s">%4$s</a> | ⚠ IPv6</span></p>',
return sprintf('<p class="box">%s %s <span class="right"><a href="https://www.%s">%3$s</a> | <a href="https://www.%4$s">%4$s</a> | ⚠ IPv6</span></p>',
'Luigifab/Apijs', $this->helper('apijs')->getVersion(), 'luigifab.fr/openmage/apijs', 'luigifab.fr/apijs');
}

Expand All @@ -40,10 +38,13 @@ private function checkRewrites() {
['block' => 'adminhtml/cache_additional'],
['block' => 'adminhtml/catalog_category_helper_image'],
['block' => 'adminhtml/catalog_product_helper_form_gallery_content'],
['block' => 'adminhtml/catalog_product_helper_form_image'],
['block' => 'adminhtml/cms_wysiwyg_images_tree'],
['block' => 'adminhtml/system_config_form_field_image'],
['helper' => 'catalog/image'],
['model' => 'catalog/category_attribute_backend_image'],
['model' => 'catalog/product_attribute_backend_media'],
['model' => 'catalog_resource/product_attribute_backend_image'],
['model' => 'catalog_resource/product_attribute_backend_media'],
['model' => 'core/file_validator_image']
];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created L/30/03/2020
* Updated J/18/02/2021
* Updated D/30/05/2021
*
* Copyright 2008-2021 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/apijs
Expand All @@ -17,7 +17,7 @@
* GNU General Public License (GPL) for more details.
*/

class Luigifab_Apijs_Block_Adminhtml_Rewrite_Category extends Mage_Adminhtml_Block_Catalog_Category_Helper_Image {
class Luigifab_Apijs_Block_Adminhtml_Rewrite_Categoryimg extends Mage_Adminhtml_Block_Catalog_Category_Helper_Image {

protected function _construct() {
$this->setModuleName('Mage_Adminhtml');
Expand All @@ -31,9 +31,9 @@ public function getElementHtml() {
$html = '<div class="image preview">'.Varien_Data_Form_Element_Abstract::getElementHtml();

if ($this->getValue()) {
$url = $this->_getUrl();
$url = (mb_stripos($url, 'http') === 0) ? $url : Mage::getBaseUrl('media').$url;
$html .= sprintf(' <a href="%s" onclick="apijs.dialog.dialogPhoto(this.href, \'false\', \'false\', \'%s\'); return false;" id="%s_image">%s (%s)</a> ', $url, addslashes($this->getValue()), $this->getHtmlId(), Mage::helper('apijs')->__('Preview'), $this->getValue()); // pas de this->helper ici
$link = $this->_getUrl();
$link = (mb_stripos($link, 'http') === 0) ? $link : Mage::getBaseUrl('media').$link;
$html .= sprintf(' <a href="%s" onclick="apijs.dialog.dialogPhoto(this.href, \'false\', \'false\', \'%s\'); return false;" id="%s_image">%s (%s)</a> ', $link, addslashes($this->getValue()), $this->getHtmlId(), Mage::helper('apijs')->__('Preview'), $this->getValue()); // pas de this->helper ici
}

return $html.$this->_getDeleteCheckbox().'</div>';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created L/26/10/2015
* Updated J/28/01/2021
* Updated V/28/05/2021
*
* Copyright 2008-2021 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/apijs
Expand Down Expand Up @@ -31,9 +31,9 @@ public function getElementHtml() {
$html = '<div class="image preview">'.Varien_Data_Form_Element_Abstract::getElementHtml();

if ($this->getValue()) {
$url = $this->_getUrl();
$url = (mb_stripos($url, 'http') === 0) ? $url : Mage::getBaseUrl('media').$url;
$html .= sprintf(' <a href="%s" onclick="apijs.dialog.dialogPhoto(this.href, \'false\', \'false\', \'%s\'); return false;" id="%s_image">%s (%s)</a> ', $url, addslashes($this->getValue()), $this->getHtmlId(), Mage::helper('apijs')->__('Preview'), $this->getValue()); // pas de $this->helper
$link = $this->_getUrl();
$link = (mb_stripos($link, 'http') === 0) ? $link : Mage::getBaseUrl('media').$link;
$html .= sprintf(' <a href="%s" onclick="apijs.dialog.dialogPhoto(this.href, \'false\', \'false\', \'%s\'); return false;" id="%s_image">%s (%s)</a> ', $link, addslashes($this->getValue()), $this->getHtmlId(), Mage::helper('apijs')->__('Preview'), $this->getValue()); // pas de this->helper ici
}

return $html.$this->_getDeleteCheckbox().'</div>';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created S/04/10/2014
* Updated L/06/07/2020
* Updated V/19/03/2021
*
* Copyright 2008-2021 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/apijs
Expand Down Expand Up @@ -32,7 +32,62 @@ public function __construct() {
$this->setTemplate('luigifab/apijs/gallery.phtml'); // catalog/product/helper/gallery.phtml
}

public function getScopeLabel($attribute) {
public function getImages(bool $sortByStore) {

$product = Mage::registry('current_product');
$storeId = $product->getStoreId();
$attributes = $product->getMediaAttributes();

$values = $product->getMediaGallery('images');
$values = empty($values) ? [] : $values;

$images = [];
$counts = [];
foreach ($values as $image) {

$image = is_object($image) ? $image : new Varien_Object($image);
$images[$image->getData('file')] = $image;

if (empty($storeId))
$image->setData('position', (int) $image->getData('position'));
else if ($image->getData('position') != $image->getData('position_default'))
$image->setData('position', (int) $image->getData('position'));
else
$image->setData('position', (int) $image->getData('position_default'));

$image->setData('apijs_group', $sortByStore ? (int) ($image->getData('position') / 100) * 100 : 0);

if (array_key_exists($image->getData('apijs_group'), $counts))
$counts[$image->getData('apijs_group')]++;
else
$counts[$image->getData('apijs_group')] = 1;
}

$ids = [];
foreach ($attributes as $attribute) {
if (($attribute->getIsText() !== true) && ($attribute->getIsCheckbox() !== true))
$ids[] = $attribute->getId();
}

$database = Mage::getSingleton('core/resource');
$read = $database->getConnection('core_read');
$table = $database->getTableName('catalog_product_entity_varchar');
$values = $read->fetchAll('SELECT store_id, attribute_id, value FROM '.$table.' WHERE entity_id = '.$product->getId().' AND attribute_id IN ('.implode(',', $ids).')');

$defaults = [];
foreach ($values as $value) {

if (!empty($images[$value['value']])) {
$image = $images[$value['value']];
if (floor($image->getData('position') / 100) == $value['store_id'])
$defaults[$value['attribute_id']][$value['store_id']] = $value['value'];
}
}

return [$images, $counts, $defaults];
}

public function getScopeLabel(object $attribute) {

if ($attribute->isScopeGlobal())
return $this->__('[GLOBAL]');
Expand All @@ -42,7 +97,7 @@ public function getScopeLabel($attribute) {
return $this->__('[STORE VIEW]');
}

public function isUseGlobal($image, $field, $value) {
public function isUseGlobal(object $image, string $field, string $value) {
return empty($image->getData($field.'_global')) ? '' : $value.'="'.$value.'"';
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Created J/27/05/2021
* Updated D/30/05/2021
*
* Copyright 2008-2021 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/apijs
*
* This program is free software, you can redistribute it or modify
* it under the terms of the GNU General Public License (GPL) as published
* by the free software foundation, either version 2 of the license, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but without any warranty, without even the implied warranty of
* merchantability or fitness for a particular purpose. See the
* GNU General Public License (GPL) for more details.
*/

class Luigifab_Apijs_Block_Adminhtml_Rewrite_Productimg extends Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Image {

protected function _construct() {
$this->setModuleName('Mage_Adminhtml');
}

public function getElementHtml() {

if (Mage::getStoreConfigFlag('apijs/general/backend')) {

$this->setData('class', 'input-file');
$html = '<div class="image preview">'.Varien_Data_Form_Element_Abstract::getElementHtml();

if ($this->getValue()) {
$link = $this->_getUrl();
$link = (mb_stripos($link, 'http') === 0) ? $link : Mage::getBaseUrl('media').$link;
$html .= sprintf(' <a href="%s" onclick="apijs.dialog.dialogPhoto(this.href, \'false\', \'false\', \'%s\'); return false;" id="%s_image">%s (%s)</a> ', $link, addslashes($this->getValue()), $this->getHtmlId(), Mage::helper('apijs')->__('Preview'), $this->getValue()); // pas de this->helper ici
}

return $html.$this->_getDeleteCheckbox().'</div>';
}

return parent::getElementHtml();
}
}
73 changes: 53 additions & 20 deletions src/app/code/community/Luigifab/Apijs/Helper/Data.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created D/20/11/2011
* Updated D/21/02/2021
* Updated V/28/05/2021
*
* Copyright 2008-2021 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/openmage/apijs
Expand Down Expand Up @@ -58,16 +58,23 @@ public function getNumberToHumanSize(int $number) {


public function getCatalogProductImageDir(bool $cache = false) {
return rtrim(Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath(), '/').($cache ? '/cache/' : '/');

if (empty($this->_baseMediaPath))
$this->_baseMediaPath = rtrim(Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath(), '/');

return $this->_baseMediaPath.($cache ? '/cache/' : '/');
}

public function getCatalogCategoryImageDir(bool $cache = false) {
return str_replace('/product/', '/category/', $this->getCatalogProductImageDir($cache));
}

public function getWysiwygImageDir(bool $cache = false, bool $old = false) {
$dir = $old ? Mage_Cms_Model_Wysiwyg_Images_Storage::THUMBS_DIRECTORY_NAME : 'cache';
return rtrim(Mage::helper('cms/wysiwyg_images')->getStorageRoot(), '/').($cache ? '/'.$dir.'/' : '/');

if (empty($this->_baseWysiwygPath))
$this->_baseWysiwygPath = rtrim(Mage::helper('cms/wysiwyg_images')->getStorageRoot(), '/');

return $this->_baseWysiwygPath.($cache ? '/'.($old ? Mage_Cms_Model_Wysiwyg_Images_Storage::THUMBS_DIRECTORY_NAME : 'cache').'/' : '/');
}


Expand Down Expand Up @@ -184,21 +191,6 @@ public function getThumbnail($product, $default, object $image, int $id) {
}


public function removeFiles(string $dir, string $file) {

// recherche tous les fichiers avec la commande find
// si le nom du fichier contient des caractères simples
if (Mage::getStoreConfigFlag('apijs/general/remove_cache') && (preg_match('#[\w\-]+\.\w+$#', $file) === 1)) {

Mage::log(sprintf('Remove all %s images with exec(find) in %s', $file, $dir), Zend_Log::INFO, 'apijs.log');

if (mb_stripos($file, '/') === false)
exec('find '.escapeshellarg($dir).' -name '.escapeshellarg($file).' | xargs rm');
else
exec('find '.escapeshellarg($dir).' -wholename '.escapeshellarg('*/'.$file).' | xargs rm');
}
}

public function getMaxSizes(bool $dump = false) {

// config admise en Mo, "one file, all files"
Expand Down Expand Up @@ -231,7 +223,7 @@ public function getTabName($product = null) {

foreach ($egroups as $group) {
$attributes = $product->getAttributes($group->getId(), true);
foreach ($attributes as $key => $attribute) {
foreach ($attributes as $attribute) {
if (in_array($attribute->getData('attribute_code'), ['media_gallery', 'gallery']))
return 'group_'.$group->getId();
}
Expand All @@ -249,4 +241,45 @@ public function renderGalleryBlock(object $product) {

return $block->toHtml();
}


private function searchAndRemoveFiles(string $dir, string $file) {

if (mb_stripos($file, '/') === false)
$cmd = 'find '.escapeshellarg($dir).' -name '.escapeshellarg($file).' | xargs rm';
else
$cmd = 'find '.escapeshellarg($dir).' -wholename '.escapeshellarg('*/'.trim($file, '/')).' | xargs rm';

Mage::log($cmd, Zend_Log::DEBUG, 'apijs.log');
exec($cmd);
}

public function removeFiles(string $dir, string $file, bool $now = false) {

// recherche et supprime tous les fichiers avec la commande find
// si le nom du fichier contient des caractères simples
if (Mage::getStoreConfigFlag('apijs/general/remove_cache') && (preg_match('#[\w\-]+\.\w+$#', $file) === 1)) {

if (empty($this->_filesToRemove))
$this->_filesToRemove = [];

if (is_dir($dir)) {
if ($now)
$this->searchAndRemoveFiles($dir, $file);
else
$this->_filesToRemove[] = [$dir => $file];
}
}
}

public function __destruct() {

if (!empty($this->_filesToRemove)) {
foreach ($this->_filesToRemove as $data) {
foreach ($data as $dir => $file) {
$this->searchAndRemoveFiles($dir, $file);
}
}
}
}
}
Loading

0 comments on commit 772ae8b

Please sign in to comment.