สำหรับ นักพัฒนา ต้องสมัครสมาชิกก่อนเข้าระบบเพื่อ clone โค้ด

Commit 85be5fe4 authored by Nahm's avatar Nahm

import project

parents
Pipeline #173 canceled with stages
<?php
/**
* @package Plugin System MD Image Responsive
* @subpackage plg_system_mdimageresponsive
* @author Mindphp Developer Teams
* @copyright Copyright (C) 2015 Mindphp. All rights reserved..
* @license GNU General Public License version 2 or later;
*/
defined('JPATH_BASE') or die;
use Joomla\CMS\Factory;
JFormHelper::loadFieldClass('text');
class JFormFieldCacheDelete extends JFormFieldText
{
protected $type = 'CacheDelete';
public function getInput()
{
Factory::getDocument()->addScriptDeclaration("
jQuery(function($) {
var token = $('form[name=\"adminForm\"] input:last').prop('name');
$('#clear_cache_now').click(function() {
if(confirm('" . JText::_('PLG_SYSTEM_MDIMAGERESPONSIVE_ALERT_CLEAR_CACHE_NOW') . "')) {
var data = {};
data[token] = 1;
$.post('index.php?option=com_ajax&plugin=mdimageresponsive&group=system&format=json', data, function(result) {
console.log(result);
});
}
});
});
");
$html = '<a id="clear_cache_now" class="btn btn-danger">' . JText::_('PLG_SYSTEM_MDIMAGERESPONSIVE_CLEAR_CACHE_NOW') . '</a>';
return $html;
}
}
<?php
/**
* @package Plugin System MD Image Responsive
* @subpackage plg_system_mdimageresponsive
* @author Mindphp Developer Teams
* @copyright Copyright (C) 2015 Mindphp. All rights reserved..
* @license GNU General Public License version 2 or later;
*/
defined('JPATH_BASE') or die;
jimport('joomla.filesystem');
JFormHelper::loadFieldClass('list');
class JFormFieldGetComponent extends JFormFieldList
{
protected $type = 'GetComponent';
public function getOptions()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select($db->qn('element'))
->from($db->qn('#__extensions'))
->where($db->qn('type').'='.$db->q('component'));
$db->setQuery($query);
$rows = $db->loadColumn();
$options = array();
foreach ($rows as $element)
{
$object = new stdClass();
$object->value = $element;
$object->text = $element;
$options[] = $object;
}
$path_images = JPATH_ROOT . '/images';
$path = JPATH_PLUGINS . '/content/msocial/assets/img';
if(!JFile::exists($path_images . '/icon_facebook.png'))
{
JFile::copy($path . '/icon_facebook.png', $path_images . '/icon_facebook.png');
}
if(!JFile::exists($path_images . '/icon_google.png'))
{
JFile::copy($path . '/icon_google.png', $path_images . '/icon_google.png');
}
if(!JFile::exists($path_images . '/icon_twitter.png'))
{
JFile::copy($path . '/icon_twitter.png', $path_images . '/icon_twitter.png');
}
if(!JFile::exists($path_images . '/icon_line.png'))
{
JFile::copy($path . '/icon_line.png', $path_images . '/icon_line.png');
}
return array_merge(parent::getOptions(), $options);
}
}
; @package Plugin System MD Image Responsive
; @subpackage plg_system_mdimageresponsive
; @author Mindphp Developer Teams
; @copyright Copyright (C) 2020 Mindphp. All rights reserved.
; @license GNU General Public License version 2 or later;
PLG_SYSTEM_MDIMAGERESPONSIVE = "System - MD Image Responsive"
PLG_SYSTEM_MDIMAGERESPONSIVE_DESC = "This plug-in generate thumbnail for use multi screen."
PLG_SYSTEM_MDIMAGERESPONSIVE_EXCLUDE_COMPONENTS = "Exclude Components"
PLG_SYSTEM_MDIMAGERESPONSIVE_EXCLUDE_COMPONENTS_DESC = "Exclude Components"
PLG_SYSTEM_MDIMAGERESPONSIVE_HEADER_NOTE = "Max Width Setting"
PLG_SYSTEM_MDIMAGERESPONSIVE_HEADER_NOTE_DESC = "Enter max width (pixel) for all device."
PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_XS = "Extra small devices"
PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_XS_DESC = "For portrait phones, default 320px."
PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_SM = "Small devices"
PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_SM_DESC = "For landscape phones, default 576px."
PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_MD = "Medium devices"
PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_MD_DESC = "For tablets, default 768px."
PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_LG = "Large devices"
PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_LG_DESC = "For desktops, default 992px."
PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_XL = "Extra large devices"
PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_XL_DESC = "For large desktops, default 1200px."
PLG_SYSTEM_MDIMAGERESPONSIVE_AUTO_CLEAR_CACHE = "Auto Clear Cache"
PLG_SYSTEM_MDIMAGERESPONSIVE_AUTO_CLEAR_CACHE_DESC = "Select Yes for auto delete cache, No not delete."
PLG_SYSTEM_MDIMAGERESPONSIVE_CACHE_TIME = "Cache Time (Minute)"
PLG_SYSTEM_MDIMAGERESPONSIVE_CACHE_TIME_DESC = "Enter time for cache."
PLG_SYSTEM_MDIMAGERESPONSIVE_CACHE = "Cache"
PLG_SYSTEM_MDIMAGERESPONSIVE_CACHE_DESC = "Click button for clear cache now."
PLG_SYSTEM_MDIMAGERESPONSIVE_CLEAR_CACHE_NOW = "Clear Cache Now"
PLG_SYSTEM_MDIMAGERESPONSIVE_ALERT_CLEAR_CACHE_NOW = "Do yout want to clear cache now ?"
\ No newline at end of file
; @package Plugin System MD Image Responsive
; @subpackage plg_system_mdimageresponsive
; @author Mindphp Developer Teams
; @copyright Copyright (C) 2020 Mindphp. All rights reserved.
; @license GNU General Public License version 2 or later;
PLG_SYSTEM_MDIMAGERESPONSIVE = "System - MD Image Responsive"
PLG_SYSTEM_MDIMAGERESPONSIVE_DESC = "This plug-in generate thumbnail for use multi screen."
\ No newline at end of file
; @package Plugin System MD Image Responsive
; @subpackage plg_system_mdimageresponsive
; @author Mindphp Developer Teams
; @copyright Copyright (C) 2020 Mindphp. All rights reserved.
; @license GNU General Public License version 2 or later;
PLG_SYSTEM_MDIMAGERESPONSIVE = "ระบบ - เอ็มดี ปรับรูปภาพให้รองรับทุกอุปกรณ์"
PLG_SYSTEM_MDIMAGERESPONSIVE_DESC = "ปลั๊กอินนี้ใช้สร้างรูปภาพตามขนาดหน้าจอต่างๆ"
PLG_SYSTEM_MDIMAGERESPONSIVE_EXCLUDE_COMPONENTS = "คอมโพเน้นท์ที่ยกเว้น"
PLG_SYSTEM_MDIMAGERESPONSIVE_EXCLUDE_COMPONENTS_DESC = "เลือกคอมโพเน้นท์ที่ยกเว้น ปลั๊กอินจะไม่ทำงานเมื่อทำงานอยู่ในคอมโพเน้นท์ที่กำหนด"
PLG_SYSTEM_MDIMAGERESPONSIVE_HEADER_NOTE = "กำหนดความกว้างของรูปภาพ"
PLG_SYSTEM_MDIMAGERESPONSIVE_HEADER_NOTE_DESC = "กรอกความกว้างเป็นพิกเซล (pixel) ที่จะใช้แสดงในแต่ละอุปกรณ์"
PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_XS = "อุปกรณ์ขนาดเล็กสุด"
PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_XS_DESC = "สำหรับมือถือแนวตั้ง ค่าเริ่มต้น 320px."
PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_SM = "อุปกรณ์ขนาดเล็ก"
PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_SM_DESC = "สำหรับมือถือแนวนอน ค่าเริ่มต้น 576px."
PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_MD = "อุปกรณ์ขนาดกลาง"
PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_MD_DESC = "สำหรับแท็บเล็ต ค่าเริ่มต้น 768px."
PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_LG = "อุปกรณ์ขนาดใหญ่"
PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_LG_DESC = "สำหรับคอมพิวเตอร์ ค่าเริ่มต้น 992px."
PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_XL = "อุปกรณ์ขนาดใหญ่สุด"
PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_XL_DESC = "สำหรับคอมพิวเตอร์จอใหญ่ ค่าเริ่มต้น 1200px."
PLG_SYSTEM_MDIMAGERESPONSIVE_AUTO_CLEAR_CACHE = "ลบแคชอัตโนมัติ"
PLG_SYSTEM_MDIMAGERESPONSIVE_AUTO_CLEAR_CACHE_DESC = "เลือก ใช่ เพื่อให้ระบบลบไฟล์แคชอัตโนมัติ เลือก ไม่ ระบบจะไม่ลบไฟล์ออก"
PLG_SYSTEM_MDIMAGERESPONSIVE_CACHE_TIME = "ตั้งเวลาแคช (นาที)"
PLG_SYSTEM_MDIMAGERESPONSIVE_CACHE_TIME_DESC = "กรอกข้อมูลเวลาแคช"
PLG_SYSTEM_MDIMAGERESPONSIVE_CACHE = "แคช"
PLG_SYSTEM_MDIMAGERESPONSIVE_CACHE_DESC = "คลิกปุ่มเพื่อล้างไฟล์แคชทั้งหมดตอนนี้"
PLG_SYSTEM_MDIMAGERESPONSIVE_CLEAR_CACHE_NOW = "ลบไฟล์แคชทั้งหมด"
PLG_SYSTEM_MDIMAGERESPONSIVE_ALERT_CLEAR_CACHE_NOW = "คุณแน่ใจว่าต้องการเคลียร์แคชทั้งหมดตอนนี้ ?"
\ No newline at end of file
; @package Plugin System MD Image Responsive
; @subpackage plg_system_mdimageresponsive
; @author Mindphp Developer Teams
; @copyright Copyright (C) 2020 Mindphp. All rights reserved.
; @license GNU General Public License version 2 or later;
PLG_SYSTEM_MDIMAGERESPONSIVE = "ระบบ - เอ็มดี ปรับรูปภาพให้รองรับทุกอุปกรณ์"
PLG_SYSTEM_MDIMAGERESPONSIVE_DESC = "ปลั๊กอินนี้ใช้สร้างรูปภาพตามขนาดหน้าจอต่างๆ"
\ No newline at end of file
<?php
/**
* @package Plugin System MD Image Responsive
* @subpackage plg_system_mdimageresponsive
* @author Mindphp Developer Teams
* @copyright Copyright (C) 2020 Mindphp. All rights reserved.
* @license GNU General Public License version 2 or later;
*/
defined('_JEXEC') or die;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Factory;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Image\Image;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\Filesystem\Folder;
class PlgSystemMDImageResponsive extends CMSPlugin
{
private $cache_path;
private $cache_url;
private $width_xs = '320';
private $width_sm = '576';
private $width_md = '768';
private $width_lg = '992';
private $width_xl = '1200';
protected $autoloadLanguage = true;
public function onAfterRender()
{
$arr_width = array (
'xs' => $this->params->get('width_xs', $this->width_xs),
'sm' => $this->params->get('width_sm', $this->width_sm),
'md' => $this->params->get('width_md', $this->width_md),
'lg' => $this->params->get('width_lg', $this->width_lg),
'xl' => $this->params->get('width_xl', $this->width_xl)
);
$this->cache_path = JPATH_ROOT . str_replace('/', DIRECTORY_SEPARATOR, '/plugins/system/mdimageresponsive/cache/');
$this->cache_url = Uri::root() . 'plugins/system/mdimageresponsive/cache/';
$app = Factory::getApplication();
$component = $app->input->get('option', '');
$document = Factory::getDocument();
$exclude_components = $this->params->get('exclude_components', array ());
if ($app->isAdmin() || $document->getType() != 'html' || in_array($component, $exclude_components))
{
return false;
}
$cache = Factory::getCache('plg_system_mdimageresponsive', '');
$cache->setCaching($this->params->get('cache_auto_delete', 1) ? true : false);
$cache->setLifeTime($this->params->get('cache_time', 30));
$check_cache = $cache->get($cache->makeId());
if (!$check_cache)
{
$this->clearCache();
$cache->store('plg_system_mdimageresponsive', $cache->makeId());
}
$dom = new DOMDocument();
$dom->recover = true;
$dom->substituteEntities = true;
$dom->preserveWhiteSpace = false;
$source = JResponse::getBody();
$xhtml = (preg_match('/<XHTML/', $source)) ? true : false;
switch ($xhtml)
{
case true:
$dom->loadXML($source);
break;
case false:
libxml_use_internal_errors(true);
$dom->loadHTML($source);
libxml_use_internal_errors(false);
break;
}
$root_url = parse_url(Uri::root());
$images = $dom->getElementsByTagName('img');
$url_images = array ();
foreach ($images as $image)
{
$arr_attribute = array ();
if ($image->attributes->length)
{
foreach ($image->attributes as $attribute)
{
$arr_attribute[$attribute->nodeName] = $attribute->nodeValue;
}
}
$picture = $dom->createElement('picture');
$image_url = $image->getAttribute('src');
if (!in_array($image_url, $url_images))
{
if (preg_match('/^http/', $image_url))
{
if (strpos($image_url, $root_url['host']) !== false)
{
list(, $path) = explode($root_url['host'], $image_url);
if (isset($root_url['path']) && $root_url['path'])
{
$path = str_replace($root_url['path'], '/', $path);
$image_path = JPATH_ROOT . str_replace('/', DIRECTORY_SEPARATOR, $path);
$image_name = basename($image_path);
$image_ext = File::getExt($image_name);
if (file_exists($image_path) && $image_ext != 'webp')
{
$class_image = new Image($image_path);
$image_width = $class_image->getWidth();
foreach ($arr_width as $index => $width)
{
$new_image_name = str_replace('.' . $image_ext, '', $image_name) . '_' . $index . '.' . $image_ext;
if ($image_width > $width)
{
if (!File::exists($this->cache_path . $new_image_name))
{
$resize_image = $class_image->resize($width . 'px', null);
$resize_image->toFile($this->cache_path . $new_image_name);
$resize_image->destroy();
}
$source = $dom->createElement('source');
$source->setAttribute('media', '(max-width: ' . $width . 'px)');
$source->setAttribute('srcset', $this->cache_url . $new_image_name);
$picture->appendChild($source);
}
}
$class_image->destroy();
}
}
}
}
else
{
$path = $image_url;
if (isset($root_url['path']) && $root_url['path'])
{
$path = str_replace($root_url['path'], '/', $path);
}
if (!preg_match('(^/|\\\\)i', $path))
{
$path = DIRECTORY_SEPARATOR . $path;
}
$image_path = JPATH_ROOT . str_replace('/', DIRECTORY_SEPARATOR, $path);
$image_name = basename($image_path);
$image_ext = File::getExt($image_name);
if (file_exists($image_path) && $image_ext != 'webp')
{
$class_image = new Image($image_path);
$image_width = $class_image->getWidth();
foreach ($arr_width as $index => $width)
{
$new_image_name = str_replace('.' . $image_ext, '', $image_name) . '_' . $index . '.' . $image_ext;
if ($image_width > $width)
{
if (!File::exists($this->cache_path . $new_image_name))
{
$resize_image = $class_image->resize($width . 'px', null);
$resize_image->toFile($this->cache_path . $new_image_name);
$resize_image->destroy();
}
$source = $dom->createElement('source');
$source->setAttribute('media', '(max-width: ' . $width . 'px)');
$source->setAttribute('srcset', $this->cache_url . $new_image_name);
$picture->appendChild($source);
}
}
$class_image->destroy();
}
}
$new_image = $dom->createElement('img');
foreach ($arr_attribute as $key => $value)
{
$new_image->setAttribute($key, $value);
}
$picture->appendChild($new_image);
$image->parentNode->replaceChild($picture, $image);
$new_image->appendChild($image);
}
$url_images[] = $image_url;
}
JResponse::setBody($xhtml ? $dom->saveXML() : $dom->saveHTML());
}
public function onAjaxMDImageResponsive()
{
$this->clearCache();
}
public function clearCache()
{
$this->cache_path = JPATH_ROOT . str_replace('/', DIRECTORY_SEPARATOR, '/plugins/system/mdimageresponsive/cache/');
$files = Folder::files($this->cache_path);
foreach ($files as $file)
{
if ($file != 'index.html')
{
File::delete($this->cache_path . $file);
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<extension version="3.1" type="plugin" group="system" method="upgrade">
<name>plg_system_mdimageresponsive</name>
<author>Mindphp Developer Teams</author>
<creationDate>March 2020</creationDate>
<copyright>(C) 2020 Mindphp. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later</license>
<authorEmail>shop.mindphp@gmail.com</authorEmail>
<authorUrl>https://www.mindphp.com</authorUrl>
<version>1.0.0</version>
<description>PLG_SYSTEM_MDIMAGERESPONSIVE_DESC</description>
<files>
<folder>cache</folder>
<folder>fields</folder>
<folder>language</folder>
<filename plugin="mdimageresponsive">mdimageresponsive.php</filename>
</files>
<config>
<fields name="params" addfieldpath="/plugins/system/mdimageresponsive/fields">
<fieldset name="basic">
<field
name="header_width"
type="note"
label="PLG_SYSTEM_MDIMAGERESPONSIVE_HEADER_NOTE"
description="PLG_SYSTEM_MDIMAGERESPONSIVE_HEADER_NOTE_DESC"
/>
<field
name="width_xs"
type="text"
label="PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_XS"
description="PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_XS_DESC"
default="320"
class="validate-numeric required"
required="true"
/>
<field
name="width_sm"
type="text"
label="PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_SM"
description="PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_SM_DESC"
default="576"
class="validate-numeric required"
required="true"
/>
<field
name="width_md"
type="text"
label="PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_MD"
description="PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_MD_DESC"
default="768"
class="validate-numeric required"
required="true"
/>
<field
name="width_lg"
type="text"
label="PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_LG"
description="PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_LG_DESC"
default="992"
class="validate-numeric required"
required="true"
/>
<field
name="width_xl"
type="text"
label="PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_XL"
description="PLG_SYSTEM_MDIMAGERESPONSIVE_WIDTH_XL_DESC"
default="1200"
class="validate-numeric required"
required="true"
/>
</fieldset>
<fieldset name="advanced">
<field
name="exclude_components"
type="getcomponent"
label="PLG_SYSTEM_MDIMAGERESPONSIVE_EXCLUDE_COMPONENTS"
description="PLG_SYSTEM_MDIMAGERESPONSIVE_EXCLUDE_COMPONENTS_DESC"
multiple="true"
/>
<field
type="spacer"
hr="true"
/>
<field
name="cache_delete_now"
type="cachedelete"
label="PLG_SYSTEM_MDIMAGERESPONSIVE_CACHE"
description="PLG_SYSTEM_MDIMAGERESPONSIVE_CACHE_DESC"
/>
<field
name="cache_auto_delete"
type="radio"
label="PLG_SYSTEM_MDIMAGERESPONSIVE_AUTO_CLEAR_CACHE"
description="PLG_SYSTEM_MDIMAGERESPONSIVE_AUTO_CLEAR_CACHE_DESC"
class="btn-group btn-group-yesno"
default="1">
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field
name="cache_time"
type="text"
label="PLG_SYSTEM_MDIMAGERESPONSIVE_CACHE_TIME"
description="PLG_SYSTEM_MDIMAGERESPONSIVE_CACHE_TIME_DESC"
default="30"
class="validate-numeric required"
required="true"
showon="cache_auto_delete:1"
/>
</fieldset>
</fields>
</config>
<updateservers>
<server type="extension" priority="1" name="Plugin System MD Image Responsive">https://www.mindphp.com/update_server.php?element=mdimageresponsive&amp;type=plugin&amp;folder=system&amp;client=0</server>
</updateservers>
</extension>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment