Skip to content

Commit

Permalink
Version 6.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
luigifab committed May 5, 2020
1 parent 1586b6e commit 12bb673
Show file tree
Hide file tree
Showing 27 changed files with 199 additions and 118 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ For more information, go to https://www.luigifab.fr/apijs and https://www.luigif

This repository is a mirror. To install the module, please use the extension key available in the documentation. If you like, take some of your time to improve the translations, go to https://bit.ly/2HyCCEc.

Version 6.0.1 released on 13/03/2020.
Version 6.1.0 released on 05/05/2020.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function render(Varien_Data_Form_Element_Abstract $element) {
private function checkRewrites() {

$rewrites = [
['block' => 'adminhtml/catalog_category_helper_image'],
['block' => 'adminhtml/catalog_product_helper_form_gallery_content'],
['block' => 'adminhtml/cms_wysiwyg_images_tree'],
['block' => 'adminhtml/system_config_form_field_image'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Created L/30/03/2020
* Updated L/30/03/2020
*
* Copyright 2008-2020 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/magento/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_Category extends Mage_Adminhtml_Block_Catalog_Category_Helper_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()) {
$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());
}

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

return parent::getElementHtml();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created L/26/10/2015
* Updated V/13/03/2020
* Updated L/30/03/2020
*
* Copyright 2008-2020 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/magento/apijs
Expand All @@ -28,18 +28,15 @@ public function getElementHtml() {
if (Mage::getStoreConfigFlag('apijs/general/backend')) {

$this->setData('class', 'input-file');
$html = '';
$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</a> ', $url, addslashes($this->getValue()), $this->getHtmlId(), Mage::helper('apijs')->__('Preview'));
$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());
}

$html .= Varien_Data_Form_Element_Abstract::getElementHtml();
$html .= $this->_getDeleteCheckbox();

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

return parent::getElementHtml();
Expand Down
36 changes: 26 additions & 10 deletions 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 J/23/01/2020
* Updated S/25/04/2020
*
* Copyright 2008-2020 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://www.luigifab.fr/magento/apijs
Expand Down Expand Up @@ -39,17 +39,17 @@ public function getNumberToHumanSize(int $number) {
else if (($number / 1024) < 1024) {
$data = $number / 1024;
$data = Zend_Locale_Format::toNumber($data, ['precision' => 2]);
$data = $this->__('%s kB', str_replace(['.00', ',00'], '', $data));
$data = $this->__('%s kB', preg_replace('#[.,]00[[:>:]]#', '', $data));
}
else if (($number / 1024 / 1024) < 1024) {
$data = $number / 1024 / 1024;
$data = Zend_Locale_Format::toNumber($data, ['precision' => 2]);
$data = $this->__('%s MB', str_replace(['.00', ',00'], '', $data));
$data = $this->__('%s MB', preg_replace('#[.,]00[[:>:]]#', '', $data));
}
else {
$data = $number / 1024 / 1024 / 1024;
$data = Zend_Locale_Format::toNumber($data, ['precision' => 2]);
$data = $this->__('%s GB', str_replace(['.00', ',00'], '', $data));
$data = $this->__('%s GB', preg_replace('#[.,]00[[:>:]]#', '', $data));
}

return $data;
Expand Down Expand Up @@ -99,21 +99,37 @@ public function deletedFiles($dir, $filename, $txt) {
}
}

public function getMaxSizes() {
public function getMaxSizes($dump = false) {

// config admise en Mo, maxsize et multiplemaxsize
return min(20, (int) ini_get('upload_max_filesize'), (int) ini_get('post_max_size')).', '.
min((int) ini_get('upload_max_filesize'), (int) ini_get('post_max_size'));
// config admise en Mo, "one file, all files"
if ($dump === true) {
return [
'config.xml one_max_size' => (int) Mage::getStoreConfig('apijs/general/one_max_size'),
'config.xml all_max_size' => (int) Mage::getStoreConfig('apijs/general/all_max_size'),
'php upload_max_filesize' => (int) ini_get('upload_max_filesize'),
'php post_max_size' => (int) ini_get('post_max_size')
];
}

return min(
(int) Mage::getStoreConfig('apijs/general/one_max_size'),
(int) ini_get('upload_max_filesize'),
(int) ini_get('post_max_size')
).', '.min(
(int) Mage::getStoreConfig('apijs/general/all_max_size'),
(int) ini_get('upload_max_filesize'),
(int) ini_get('post_max_size')
);
}

public function getTabName($product = null) {

$product = is_object($product) ? $product : Mage::registry('current_product');
$groups = Mage::getResourceModel('eav/entity_attribute_group_collection')
$egroups = Mage::getResourceModel('eav/entity_attribute_group_collection')
->setAttributeSetFilter($product->getData('attribute_set_id'))
->load();

foreach ($groups as $group) {
foreach ($egroups as $group) {
$attributes = $product->getAttributes($group->getId(), true);
foreach ($attributes as $key => $attribute) {
if (in_array($attribute->getData('attribute_code'), ['media_gallery', 'gallery']))
Expand Down
75 changes: 33 additions & 42 deletions app/code/community/Luigifab/Apijs/Model/Useragentparser.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<?php
/**
* https://github.com/donatj/PhpUserAgent 0.15.1
* Copyright 2013-2020 | Jesse G. Donat <donatj~gmail~com>
* https://github.com/donatj/PhpUserAgent
*
* Copyright 2019-2020 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* https://gist.github.com/luigifab/4cb373e75f3cd2f342ca6bc25504b149 (1.0.0-fork2)
*
* Parses a user agent string into its important parts
* Licensed under the MIT License
* Jesse G. Donat <donatj~gmail~com> 2013-2019
*/

class Luigifab_Apijs_Model_Useragentparser {

public function parse($userAgent = null) {

if (empty($userAgent)) {
$userAgent = getenv('HTTP_USER_AGENT');
}
if (empty($userAgent)) $userAgent = getenv('HTTP_USER_AGENT');

$platform = null;
$browser = null;
Expand All @@ -28,24 +30,21 @@ public function parse($userAgent = null) {
$parentMatches[1], $result);
$result['platform'] = array_unique($result['platform']);
if (count($result['platform']) > 1) {
if ($keys = array_intersect($priority, $result['platform'])) {
if (!empty($keys = array_intersect($priority, $result['platform'])))
$platform = reset($keys);
}
else {
else
$platform = $result['platform'][0];
}
}
else if (isset($result['platform'][0])) {
$platform = $result['platform'][0];
}
}

if ($platform == 'linux-gnu' || $platform == 'X11') {
if ($platform == 'linux-gnu' || $platform == 'X11')
$platform = 'Linux';
}
else if ($platform == 'CrOS') {
else if ($platform == 'CrOS')
$platform = 'Chrome OS';
}


preg_match_all( // ["browser" => ["Firefox"...], "version" => ["45.0"...]]
'/(?P<browser>Camino|Kindle(\ Fire)?|Firefox|Iceweasel|IceCat|Safari|MSIE|Trident|AppleWebKit|TizenBrowser|(?:Headless)?Chrome|YaBrowser|Vivaldi|IEMobile|Opera|OPR|Silk|Midori|Edge|Edg|CriOS|UCBrowser|Puffin|OculusBrowser|SamsungBrowser|Baiduspider|Googlebot|YandexBot|bingbot|Lynx|Version|Wget|curl|Valve\ Steam\ Tenfoot|NintendoBrowser|PLAYSTATION\ (\d|Vita)+) (?:\)?;?) (?:(?:[:\/ ])(?P<version>[0-9A-Z.]+)|\/(?:[A-Z]*))/ix',
Expand All @@ -59,7 +58,7 @@ public function parse($userAgent = null) {
return [
'platform' => $platform ?: null,
'browser' => $result['browser'],
'version' => !empty($result['version']) ? $result['version'] : null
'version' => empty($result['version']) ? null : $result['version']
];
}

Expand All @@ -78,10 +77,10 @@ public function parse($userAgent = null) {
$key = 0;
$val = '';

if ($browser == 'Iceweasel' || strtolower($browser) == 'icecat') {
$browser = 'Firefox';
if ($this->findT($lowerBrowser, ['OPR' => 'Opera', 'UCBrowser' => 'UC Browser', 'YaBrowser' => 'Yandex', 'Iceweasel' => 'Firefox', 'Icecat' => 'Firefox', 'CriOS' => 'Chrome', 'Edg' => 'Edge'], $key, $browser)) {
$version = $result['version'][$key];
}
else if ($this->find($lowerBrowser, 'Playstation Vita', $key)) {
else if ($this->find($lowerBrowser, 'Playstation Vita', $key, $platform)) {
$platform = 'PlayStation Vita';
$browser = 'Browser';
}
Expand All @@ -100,10 +99,6 @@ public function parse($userAgent = null) {
$browser = $result['browser'][$key];
$version = $result['version'][$key];
}
else if ($this->find($lowerBrowser, 'OPR', $key)) {
$browser = 'Opera';
$version = $result['version'][$key];
}
else if ($this->find($lowerBrowser, 'Opera', $key, $browser)) {
$this->find($lowerBrowser, 'Version', $key);
$version = $result['version'][$key];
Expand All @@ -121,34 +116,18 @@ public function parse($userAgent = null) {
}
}
}
else if ($this->find($lowerBrowser, 'YaBrowser', $key, $browser)) {
$browser = 'Yandex';
$version = $result['version'][$key];
}
else if ($this->find($lowerBrowser, ['Edge', 'Edg'], $key, $browser)) {
$browser = 'Edge';
$version = $result['version'][$key];
}
else if ($this->find($lowerBrowser, ['IEMobile', 'Midori', 'Vivaldi', 'OculusBrowser', 'SamsungBrowser', 'Valve Steam Tenfoot', 'Chrome', 'HeadlessChrome'], $key, $browser)) {
else if ($this->find($lowerBrowser, ['IEMobile', 'Edge', 'Midori', 'Vivaldi', 'OculusBrowser', 'SamsungBrowser', 'Valve Steam Tenfoot', 'Chrome', 'HeadlessChrome'], $key, $browser)) {
$version = $result['version'][$key];
}
else if ($rv_result && $this->find($lowerBrowser, 'Trident', $key)) {
else if ($rv_result && $this->find($lowerBrowser, 'Trident')) {
$browser = 'MSIE';
$version = $rv_result;
}
else if ($this->find($lowerBrowser, 'UCBrowser', $key)) {
$browser = 'UC Browser';
$version = $result['version'][$key];
}
else if ($this->find($lowerBrowser, 'CriOS', $key)) {
$browser = 'Chrome';
$version = $result['version'][$key];
}
else if ($browser == 'AppleWebKit') {
if ($platform == 'Android') {
$browser = 'Android Browser';
}
else if (strpos($platform, 'BB') === 0) {
else if (strncmp($platform, 'BB', 2) === 0) {
$browser = 'BlackBerry Browser';
$platform = 'BlackBerry';
}
Expand All @@ -161,7 +140,7 @@ public function parse($userAgent = null) {
$this->find($lowerBrowser, 'Version', $key);
$version = $result['version'][$key];
}
else if ($pKey = preg_grep('/playstation \d/i', $result['browser'])) {
else if (!empty($pKey = preg_grep('/playstation \d/i', $result['browser']))) {
$pKey = reset($pKey);
$platform = 'PlayStation '.preg_replace('/\D/', '', $pKey);
$browser = 'NetFront';
Expand All @@ -170,7 +149,7 @@ public function parse($userAgent = null) {
return ['platform' => $platform ?: null, 'browser' => $browser ?: null, 'version' => $version ?: null];
}

private function find($lowerBrowser, $search, &$key, &$value = null) {
private function find($lowerBrowser, $search, &$key = null, &$value = null) {

$search = (array) $search;

Expand All @@ -185,4 +164,16 @@ private function find($lowerBrowser, $search, &$key, &$value = null) {

return false;
}

private function findT($lowerBrowser, array $search, &$key = null, &$value = null) {

$value2 = null;

if ($this->find($lowerBrowser, array_keys($search), $key, $value2)) {
$value = $search[$value2];
return true;
}

return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created S/04/10/2014
* Updated S/01/02/2020
* Updated L/30/03/2020
*
* Copyright 2008-2020 | Fabrice Creuzot (luigifab) <code~luigifab~fr>
* Copyright 2019 | Fabrice Creuzot <fabrice~cellublue~com>
Expand Down Expand Up @@ -47,18 +47,22 @@ private function formatResult($success, $errors, $data) {

$result = ['html' => $data];

if (!empty($errors) && empty($success))
if (!empty($errors) && empty($success)) {
$result['bbcode'] = sprintf('[p]%s[/p][ul][li]%s[/li][/ul]',
$this->__('[strong]Warning[/strong], no files were saved:'),
implode('[/li][li]', $errors));
else if (!empty($errors))
$result['bbcode'] = str_replace('Disalollowed file format.', 'Exceeded maximum width/height.', $result['bbcode']);
}
else if (!empty($errors)) {
$result['bbcode'] = sprintf('[p]%s[/p][ul][li]%s[/li][/ul][p]%s[/p][ul][li]%s[/li][/ul]',
(count($errors) > 1) ? $this->__('[strong]Warning[/strong], the following files were not saved:') :
$this->__('[strong]Warning[/strong], the following file was not saved:'),
implode('[/li][li]', $errors),
(count($success) > 1) ? $this->__('[strong]However[/strong], the following files were successfully saved:') :
$this->__('[strong]However[/strong], the following file was successfully saved:'),
implode('[/li][li]', $success));
$result['bbcode'] = str_replace('Disalollowed file format.', 'Exceeded maximum width/height.', $result['bbcode']);
}

return 'success-'.json_encode($result);
}
Expand Down Expand Up @@ -224,6 +228,9 @@ public function saveAction() {
$product->save();
}

if (!empty($storeId)) // reload
$product->setStoreId($storeId)->load($product->getId());

// html
Mage::app()->getCacheInstance()->cleanType('block_html');
$result = $this->formatResult(null, null, Mage::helper('apijs')->renderGalleryBlock($product));
Expand Down Expand Up @@ -290,7 +297,7 @@ public function deleteAction() {

if ($product->hasDataChanges())
$product->save();
if (!empty($storeId))
if (!empty($storeId)) // reload
$product->setStoreId($storeId)->load($product->getId());

// supprime enfin les fichiers
Expand Down
Loading

0 comments on commit 12bb673

Please sign in to comment.