update
This commit is contained in:
180
modules/anblog/libs/AnblogImage.php
Normal file
180
modules/anblog/libs/AnblogImage.php
Normal file
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
/**
|
||||
* 2024 Anvanto
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
*
|
||||
* @author Anvanto <anvantoco@gmail.com>
|
||||
* @copyright 2024 Anvanto
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once _PS_MODULE_DIR_.'anblog/loader.php';
|
||||
|
||||
class AnblogImage
|
||||
{
|
||||
public $id;
|
||||
public $uplname = '';
|
||||
public $main = '';
|
||||
public $mainurl = '';
|
||||
public $error = '';
|
||||
public $thumbs = array();
|
||||
public $thumbsurls = array();
|
||||
public $exists = false;
|
||||
|
||||
public function __construct($post)
|
||||
{
|
||||
if (is_array($post) && array_key_exists('id_anblog_blog', $post)) {
|
||||
$this->id = $post['id_anblog_blog'];
|
||||
$postimg = $post['image'];
|
||||
} elseif (is_array($post) && array_key_exists('id', $post)) {
|
||||
$this->id = $post['id'];
|
||||
$postimg = $post['image'];
|
||||
} elseif (is_object($post) && get_class($post) == 'AnblogBlog' && isset($post->id)) {
|
||||
$this->id = $post->id;
|
||||
$postimg = $post->image;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($postimg != '') {
|
||||
$this->main = _ANBLOG_BLOG_IMG_DIR_.'b/'.$postimg;
|
||||
|
||||
if (!$this->baseImgExists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$url = _ANBLOG_BLOG_IMG_URI_;
|
||||
$this->mainurl = $url.'b/'.$postimg;
|
||||
$this->checkAndCreateThumbs();
|
||||
$this->exists = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function baseImgExists()
|
||||
{
|
||||
return file_exists($this->main);
|
||||
}
|
||||
|
||||
public function uploadNew($id = 0)
|
||||
{
|
||||
$image = $_FILES['image_link'];
|
||||
$res = true;
|
||||
if ($id) {
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
$res &= is_array($image);
|
||||
if (ImageManager::validateUpload($image) != false) {
|
||||
$this->error = ImageManager::validateUpload($image);
|
||||
return false;
|
||||
}
|
||||
$tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
|
||||
$res &= move_uploaded_file($image['tmp_name'], $tmp_name);
|
||||
|
||||
if ($res) {
|
||||
$type = Tools::strtolower(Tools::substr(strrchr($image['name'], '.'), 1));
|
||||
|
||||
Configuration::set('PS_IMAGE_QUALITY', $type);
|
||||
$img_name = 'b-'. uniqid() . '-' .'anblog_original.'.$type;
|
||||
if (ImageManager::resize(
|
||||
$tmp_name,
|
||||
_ANBLOG_BLOG_IMG_DIR_.'b/'.$img_name
|
||||
)
|
||||
&& chmod(_ANBLOG_BLOG_IMG_DIR_.'b/'.$img_name, 0666)
|
||||
) {
|
||||
$res = true;
|
||||
$this->main = _ANBLOG_BLOG_IMG_DIR_.'b/'.$img_name;
|
||||
$this->uplname = $img_name;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$res &= $this->checkAndCreateThumbs(true);
|
||||
|
||||
if (!$res || !isset($img_name)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->exists = true;
|
||||
return $img_name;
|
||||
}
|
||||
|
||||
public function checkAndCreateThumbs($new = false)
|
||||
{
|
||||
|
||||
if ($this->main == '') {
|
||||
return false;
|
||||
}
|
||||
$res = true;
|
||||
|
||||
$image_types = Db::getInstance()->executeS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'image_type`
|
||||
WHERE `name`LIKE \'anblog_%\'');
|
||||
|
||||
$type = Tools::strtolower(Tools::substr(strrchr($this->main, '.'), 1));
|
||||
|
||||
Configuration::set('PS_IMAGE_QUALITY', $type);
|
||||
foreach ($image_types as $imageType) {
|
||||
$img_path = str_replace('anblog_original', $imageType['name'], $this->main);
|
||||
if ($new || !file_exists($img_path)) {
|
||||
if (ImageManager::resize(
|
||||
$this->main,
|
||||
$img_path,
|
||||
(int)$imageType['width'],
|
||||
(int)$imageType['height']
|
||||
)
|
||||
&& chmod($img_path, 0666)
|
||||
) {
|
||||
$res &= true;
|
||||
} else {
|
||||
$res &= false;
|
||||
}
|
||||
}
|
||||
|
||||
$this->thumbs[$imageType['name']] = $img_path;
|
||||
$this->thumbsurls[$imageType['name']] = str_replace('anblog_original', $imageType['name'], $this->mainurl);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function getImageTypeByName($name)
|
||||
{
|
||||
return Db::getInstance()->getRow('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'image_type`
|
||||
WHERE `name`=\''. $name .'\'');
|
||||
}
|
||||
|
||||
public function delete($originalSave = false)
|
||||
{
|
||||
if ($this->baseImgExists()) {
|
||||
|
||||
$image_types = Db::getInstance()->executeS('
|
||||
SELECT *
|
||||
FROM `'._DB_PREFIX_.'image_type`
|
||||
WHERE `name`LIKE \'anblog_%\'');
|
||||
foreach ($image_types as $imageType) {
|
||||
|
||||
// if (!$thumbsOnly || $imageType['name'] != 'anblog_default') {
|
||||
@unlink(str_replace('anblog_original', $imageType['name'], $this->main));
|
||||
// }
|
||||
}
|
||||
|
||||
if (!$originalSave){
|
||||
return @unlink($this->main);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
333
modules/anblog/libs/Helper.php
Normal file
333
modules/anblog/libs/Helper.php
Normal file
@@ -0,0 +1,333 @@
|
||||
<?php
|
||||
/**
|
||||
* 2024 Anvanto
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License (AFL 3.0)
|
||||
*
|
||||
* @author Anvanto <anvantoco@gmail.com>
|
||||
* @copyright 2024 Anvanto
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class AnblogHelper
|
||||
{
|
||||
public $bloglink = null;
|
||||
public $ssl;
|
||||
|
||||
public static function getInstance()
|
||||
{
|
||||
static $instance = null;
|
||||
if (!$instance) {
|
||||
// validate module
|
||||
$instance = new AnblogHelper();
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if (Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE')) {
|
||||
$this->ssl = true;
|
||||
}
|
||||
|
||||
$protocol_link = (Configuration::get('PS_SSL_ENABLED') || Tools::usingSecureMode()) ? 'https://' : 'http://';
|
||||
$use_ssl = ((isset($this->ssl) && $this->ssl && Configuration::get('PS_SSL_ENABLED')) || Tools::usingSecureMode()) ? true : false;
|
||||
$protocol_content = ($use_ssl) ? 'https://' : 'http://';
|
||||
$this->bloglink = new AnblogLink($protocol_link, $protocol_content);
|
||||
}
|
||||
|
||||
public static function loadMedia($context, $obj)
|
||||
{
|
||||
if (file_exists(_PS_THEME_DIR_.'css/modules/anblog/views/assets/anblog.css')) {
|
||||
$context->controller->addCss($obj->module->getPathUri().'views/assets/anblog.css');
|
||||
} else {
|
||||
$context->controller->addCss($obj->module->getPathUri().'views/css/anblog.css');
|
||||
}
|
||||
|
||||
if (file_exists(_PS_THEME_DIR_.'js/modules/anblog/views/assets/anblog.js')) {
|
||||
$context->controller->addJs($obj->module->getPathUri().'views/assets/anblog.js');
|
||||
} else {
|
||||
$context->controller->addJs($obj->module->getPathUri() . 'views/js/anblog.js');
|
||||
}
|
||||
|
||||
if (Configuration::get(anblog::PREFIX . 'item_comment_engine') == 'local' &&
|
||||
Configuration::get(anblog::PREFIX . 'google_captcha_site_key') &&
|
||||
Configuration::get(anblog::PREFIX . 'google_captcha_secret_key') &&
|
||||
Configuration::get(anblog::PREFIX . 'google_captcha_status')) {
|
||||
$context->controller->registerJavascript('recaptcha', 'https://www.google.com/recaptcha/api.js', array('server' => 'remote', 'position' => 'bottom', 'priority' => 20));
|
||||
}
|
||||
}
|
||||
|
||||
public function getLinkObject()
|
||||
{
|
||||
return $this->bloglink;
|
||||
}
|
||||
|
||||
public function getModuleLink($route_id, $controller, array $params = array(), $ssl = null, $id_lang = null, $id_shop = null)
|
||||
{
|
||||
return $this->getLinkObject()->getLink($route_id, $controller, $params, $ssl, $id_lang, $id_shop);
|
||||
}
|
||||
|
||||
public function getFontBlogLink()
|
||||
{
|
||||
return $this->getModuleLink('module-anblog-list', 'list', array());
|
||||
}
|
||||
|
||||
public function getPaginationLink($route_id, $controller, array $params = array(), $nb = false, $sort = false, $pagination = false, $array = true)
|
||||
{
|
||||
return $this->getLinkObject()->getANPaginationLink('anblog', $route_id, $controller, $params, $nb, $sort, $pagination, $array);
|
||||
}
|
||||
|
||||
public function getBlogLink($blog, $params1 = array(), $id_lang = null)
|
||||
{
|
||||
$params = array(
|
||||
'id' => $blog['id_anblog_blog'],
|
||||
'rewrite' => $blog['link_rewrite'],
|
||||
);
|
||||
|
||||
$params = array_merge($params, $params1);
|
||||
return $this->getModuleLink('module-anblog-blog', 'blog', $params, null, $id_lang);
|
||||
}
|
||||
|
||||
public function getTagLink($tag)
|
||||
{
|
||||
$params = array(
|
||||
'tag' => $tag,
|
||||
);
|
||||
|
||||
return $this->getModuleLink('blog_user_filter_rule', 'blog', $params);
|
||||
}
|
||||
|
||||
public function getBlogCatLink($cparams, $id_lang = null)
|
||||
{
|
||||
$params = array(
|
||||
'id' => '',
|
||||
'rewrite' => ''
|
||||
);
|
||||
$params = array_merge($params, $cparams);
|
||||
return $this->getModuleLink('module-anblog-category', 'category', $params, null, $id_lang);
|
||||
}
|
||||
|
||||
public function getBlogTagLink($tag, $cparams = array())
|
||||
{
|
||||
$params = array(
|
||||
'tag' => urlencode($tag),
|
||||
);
|
||||
$params = array_merge($params, $cparams);
|
||||
return $this->getModuleLink('module-anblog-list', 'list', $params);
|
||||
}
|
||||
|
||||
public function getBlogAuthorLink($author, $cparams = array())
|
||||
{
|
||||
$params = array(
|
||||
'author' => $author,
|
||||
);
|
||||
$params = array_merge($params, $cparams);
|
||||
return $this->getModuleLink('module-anblog-list', 'list', $params);
|
||||
}
|
||||
|
||||
public static function getTemplates()
|
||||
{
|
||||
$theme = _THEME_NAME_;
|
||||
$path = _PS_MODULE_DIR_.'anblog';
|
||||
$tpath = _PS_ALL_THEMES_DIR_.$theme.'modules/anblog/front';
|
||||
|
||||
$output = array();
|
||||
|
||||
$templates = glob($path.'/views/templates/front/*', GLOB_ONLYDIR);
|
||||
|
||||
$ttemplates = glob($tpath, GLOB_ONLYDIR);
|
||||
if ($templates) {
|
||||
foreach ($templates as $t) {
|
||||
// validate module
|
||||
$output[basename($t)] = array('type' => 'module', 'template' => basename($t));
|
||||
}
|
||||
}
|
||||
if ($ttemplates) {
|
||||
foreach ($ttemplates as $t) {
|
||||
// validate module
|
||||
$output[basename($t)] = array('type' => 'module', 'template' => basename($t));
|
||||
}
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public static function buildBlog($helper, $blog, $image_type, $config, $id_lang = null)
|
||||
{
|
||||
// module validation
|
||||
|
||||
|
||||
$url = _PS_BASE_URL_;
|
||||
if (Tools::usingSecureMode()) {
|
||||
// validate module
|
||||
$url = _PS_BASE_URL_SSL_;
|
||||
}
|
||||
|
||||
$id_shop = (int)Context::getContext()->shop->id;
|
||||
$blog['preview_url'] = '';
|
||||
|
||||
$imgObj = new AnblogImage($blog);
|
||||
$blog['thumb_url'] = '';
|
||||
|
||||
$blog['image_url'] = '';
|
||||
if ($imgObj->mainurl != ''){
|
||||
$blog['image_url'] = $url;
|
||||
}
|
||||
|
||||
$blog['image_url'] .= $imgObj->mainurl;
|
||||
if (array_key_exists($image_type, $imgObj->thumbsurls)) {
|
||||
$blog['preview_url'] = $url.$imgObj->thumbsurls[$image_type];
|
||||
$blog['thumb_url'] = $url.$imgObj->thumbsurls[$image_type];
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'rewrite' => $blog['category_link_rewrite'],
|
||||
'id' => $blog['id_anblogcat']
|
||||
);
|
||||
if (Configuration::get(anblog::PREFIX . 'item_comment_engine', 'local') == 'local') {
|
||||
// validate module
|
||||
$blog['comment_count'] = AnblogComment::countComments($blog['id_anblog_blog'], true, true);
|
||||
}
|
||||
$blog['category_link'] = $helper->getBlogCatLink($params);
|
||||
$blog['link'] = $helper->getBlogLink($blog, [], $id_lang);
|
||||
return $blog;
|
||||
}
|
||||
|
||||
public static function rrmdir($dir)
|
||||
{
|
||||
if (is_dir($dir)) {
|
||||
$objects = scandir($dir);
|
||||
foreach ($objects as $object) {
|
||||
if ($object != '.' && $object != '..') {
|
||||
if (filetype($dir.'/'.$object) == 'dir') {
|
||||
self::rrmdir($dir.'/'.$object);
|
||||
} else {
|
||||
unlink($dir.'/'.$object);
|
||||
}
|
||||
}
|
||||
}
|
||||
$objects = scandir($dir);
|
||||
reset($objects);
|
||||
rmdir($dir);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getConfigKey($multi_lang = false)
|
||||
{
|
||||
if ($multi_lang == false) {
|
||||
return array(
|
||||
'saveConfiguration',
|
||||
'indexation',
|
||||
'rss_limit_item',
|
||||
'rss_title_item',
|
||||
'listing_show_categoryinfo',
|
||||
'listing_limit_items',
|
||||
'listing_show_title',
|
||||
'listing_show_description',
|
||||
'listing_show_readmore',
|
||||
'listing_show_image',
|
||||
'listing_show_author',
|
||||
'listing_show_category',
|
||||
'listing_show_created',
|
||||
'listing_show_hit',
|
||||
'listing_show_counter',
|
||||
'item_show_description',
|
||||
'item_show_image',
|
||||
'item_show_author',
|
||||
'item_show_category',
|
||||
'item_show_created',
|
||||
'item_show_hit',
|
||||
'item_show_counter',
|
||||
'social_code',
|
||||
'google_captcha_status',
|
||||
'google_captcha_site_key',
|
||||
'google_captcha_secret_key',
|
||||
'item_show_listcomment',
|
||||
'item_show_formcomment',
|
||||
'item_comment_engine',
|
||||
'item_limit_comments',
|
||||
'item_diquis_account',
|
||||
'item_facebook_appid',
|
||||
'item_facebook_width',
|
||||
'show_popular_blog',
|
||||
'limit_popular_blog',
|
||||
'show_recent_blog',
|
||||
'limit_recent_blog',
|
||||
'limit_DisplayHome_blog',
|
||||
'show_all_tags',
|
||||
'link_rewrite',
|
||||
'show_in_blog',
|
||||
'show_in_post',
|
||||
'categories_DisplayHome_blog',
|
||||
'show_in_DisplayHome',
|
||||
'item_posts_type',
|
||||
);
|
||||
} else {
|
||||
return array(
|
||||
'blog_link_title',
|
||||
'category_rewrite',
|
||||
'detail_rewrite',
|
||||
'meta_title',
|
||||
'meta_description',
|
||||
'meta_keywords',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return day in month
|
||||
* 1st, 2nd, 3rd, 4th, ...
|
||||
*/
|
||||
public function ordinal($number)
|
||||
{
|
||||
$ends = array('th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th');
|
||||
if ((($number % 100) >= 11) && (($number % 100) <= 13)) {
|
||||
return $number.'th';
|
||||
} else {
|
||||
return $number.$ends[$number % 10];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return day in month
|
||||
* st, nd, rd, th, ...
|
||||
*/
|
||||
public function string_ordinal($number)
|
||||
{
|
||||
$number = (int) $number;
|
||||
$ends = array('th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th');
|
||||
if ((($number % 100) >= 11) && (($number % 100) <= 13)) {
|
||||
return 'th';
|
||||
} else {
|
||||
return $ends[$number % 10];
|
||||
}
|
||||
}
|
||||
|
||||
public static function genKey()
|
||||
{
|
||||
return md5(time().rand());
|
||||
}
|
||||
|
||||
static $id_shop;
|
||||
/**
|
||||
* FIX Install multi theme
|
||||
* AnblogHelper::getIDShop();
|
||||
*/
|
||||
public static function getIDShop()
|
||||
{
|
||||
if ((int)self::$id_shop) {
|
||||
$id_shop = (int)self::$id_shop;
|
||||
} else {
|
||||
$id_shop = (int)Context::getContext()->shop->id;
|
||||
}
|
||||
return $id_shop;
|
||||
}
|
||||
}
|
||||
0
modules/anblog/libs/index.php
Normal file
0
modules/anblog/libs/index.php
Normal file
Reference in New Issue
Block a user