diff --git a/plugins/regexp/Makefile b/plugins/regexp/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..38d4f19979f4101abd6f7781ddaf4b0f6d72439c --- /dev/null +++ b/plugins/regexp/Makefile @@ -0,0 +1,19 @@ +BASE=regexp +PLUGINTYPE=vmshipmentrules +ZIPBASE=opentools_vmshipmentrules +VERSION=1.0 + +PLUGINFILES=$(BASE).php $(BASE).script.php $(BASE).xml index.html + +TRANSLATIONS=$(call wildcard,language/en*/*.plg_$(PLUGINTYPE)_$(BASE).*ini) +INDEXFILES=language/index.html $(call wildcard,language/**/index.html) +ZIPFILE=plg_$(ZIPBASE)_$(BASE)_v$(VERSION).zip + +all: zip + +zip: $(PLUGINFILES) $(TRANSLATIONS) $(ADVANCEDFILES) $(INDEXFILES) + @echo "Packing all files into distribution file $(ZIPFILE):" + @zip -r $(ZIPFILE) $(PLUGINFILES) $(TRANSLATIONS) $(INDEXFILES) + +clean: + rm -f $(ZIPFILE) diff --git a/plugins/regexp/index.html b/plugins/regexp/index.html new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/plugins/regexp/language/en-GB/en-GB.plg_vmshipmentrules_regexp.ini b/plugins/regexp/language/en-GB/en-GB.plg_vmshipmentrules_regexp.ini new file mode 100644 index 0000000000000000000000000000000000000000..52f8ee34a53d4bb5af238b113ab887c6687d9c3a --- /dev/null +++ b/plugins/regexp/language/en-GB/en-GB.plg_vmshipmentrules_regexp.ini @@ -0,0 +1,8 @@ +; VM Rule-based Shipping plugin: Extension plugin providing regexp functions +; Copyright (C) 2014 Reinhold Kainhofer, Open Tools. All rights reserved. +; License http://www.gnu.org/licenses/gpl.html GNU/GPL +; Note : All ini files need to be saved as UTF-8 - No BOM +VMSHIPMENTRULES_REGEXP="VM Shipping by Rules: RegExp functions" +VMSHIPMENTRULES_REGEXP_DESC="This plugin provides functions for regular expression matches to the Shipping by Rules plugin." + +VMSHIPMENT_RULES_REGEXP_ARGS="The function %s needs to be called with %s arguments: %s. <br />Encountered in rule '%s'." \ No newline at end of file diff --git a/plugins/regexp/language/en-GB/en-GB.plg_vmshipmentrules_regexp.sys.ini b/plugins/regexp/language/en-GB/en-GB.plg_vmshipmentrules_regexp.sys.ini new file mode 100644 index 0000000000000000000000000000000000000000..877988d494db0439e91b455ced206d6f5bb6ed0e --- /dev/null +++ b/plugins/regexp/language/en-GB/en-GB.plg_vmshipmentrules_regexp.sys.ini @@ -0,0 +1,6 @@ +; VM Rule-based Shipping plugin: Extension plugin providing regexp functions +; Copyright (C) 2014 Reinhold Kainhofer, Open Tools. All rights reserved. +; License http://www.gnu.org/licenses/gpl.html GNU/GPL +; Note : All ini files need to be saved as UTF-8 - No BOM +VMSHIPMENTRULES_REGEXP="VM Shipping by Rules: RegExp functions" +VMSHIPMENTRULES_REGEXP_DESC="This plugin provides functions for regular expression matches to the Shipping by Rules plugin." diff --git a/plugins/regexp/language/en-GB/index.html b/plugins/regexp/language/en-GB/index.html new file mode 100644 index 0000000000000000000000000000000000000000..2efb97f319a35f6bd80f1751134ed71ec11888eb --- /dev/null +++ b/plugins/regexp/language/en-GB/index.html @@ -0,0 +1 @@ +<!DOCTYPE html><title></title> diff --git a/plugins/regexp/language/index.html b/plugins/regexp/language/index.html new file mode 100644 index 0000000000000000000000000000000000000000..2efb97f319a35f6bd80f1751134ed71ec11888eb --- /dev/null +++ b/plugins/regexp/language/index.html @@ -0,0 +1 @@ +<!DOCTYPE html><title></title> diff --git a/plugins/regexp/regexp.php b/plugins/regexp/regexp.php new file mode 100644 index 0000000000000000000000000000000000000000..0b6d9611168aa1e1c4ba446877f06b9fc83ddba8 --- /dev/null +++ b/plugins/regexp/regexp.php @@ -0,0 +1,93 @@ +<?php + +defined ('_JEXEC') or die('Restricted access'); + +/** + * Plugin providing regexp function for VM Shipping by Rules + * + * @subpackage Plugins - VmShipmentRules + * @copyright Copyright (C) 2014 Reinhold Kainhofer, office@open-tools.net + * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php + * VirtueMart is free software. This version may have been modified pursuant + * to the GNU General Public License, and as distributed it includes or + * is derivative of works licensed under the GNU General Public License or + * other free or open source software licenses. + * See administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details. + * + * http://open-tools.net/ + * + */ +if (!class_exists ('VmPlugin')) { + require(JPATH_VM_PLUGINS . DS . 'vmplugin.php'); +} + +/** This plugin provides the following RegExp-related functions to the shipping by rules plugin: + * - RegExpMatch(pattern, value) - returns whether the value matches the expression (true/false) + * - RegExpMatches(pattern, value) - returns an array of all matches of regexp within the value (array) + * - RegExpReplace(pattern, value) - preforms a regexp replacement on the value, returns the resulting string (string) + * - RegExpSplit(pattern, value) - splits value using the regexp as delimiter, returns array of all substrings (excluding the delimiter) (array) + * - RegExpFilter(pattern, array) - returns all members of the array that match the regexp (array) + */ + +/** Extension plugin for the "Shipping by Rules" shipping plugin for VirtueMart + */ +class plgVmShipmentRulesRegexp extends VmPlugin { + /** Register the regexp functions... */ + function onVmShippingRulesRegisterCustomFunctions() { + return array( + 'RegExpMatch' => array('plgVmShipmentRulesRegexp', 'rules_regexp_match'), + 'RegExpMatches' => array('plgVmShipmentRulesRegexp', 'rules_regexp_matches'), + 'RegExpReplace' => array('plgVmShipmentRulesRegexp', 'rules_regexp_replace'), + 'RegExpSplit' => array('plgVmShipmentRulesRegexp', 'rules_regexp_split'), + 'RegExpFilter' => array('plgVmShipmentRulesRegexp', 'rules_regexp_filter'), + ); + } + + /** RegExpMatch(RegExp, string) => return true/false */ + static function rules_regexp_match($args, $rule) { + if (count($args)<2) { + JFactory::getApplication()->enqueueMessage(JText::sprintf('VMSHIPMENT_RULES_REGEXP_ARGS', "RegExpMatch", "two", "RegExpMatch(pattern, string)", htmlentities($rule->rulestring)), 'error'); + return false; + } + return preg_match($args[0], $args[1]); + } + + /** RegExpMatches(RegExp, string) => returns an array of all matches of regexp in the given string */ + static function rules_regexp_matches($args, $rule) { + if (count($args)<2) { + JFactory::getApplication()->enqueueMessage(JText::sprintf('VMSHIPMENT_RULES_REGEXP_ARGS', "RegExpMatches", "two", "RegExpMatches(pattern, string)", htmlentities($rule->rulestring)), 'error'); + return false; + } + preg_match_all($args[0], $args[1], $matches); + return $matches[0]; + } + + /** RegExpReplace(RegExp, string) => preforms a regexp replacement on the value, returns the resulting string */ + static function rules_regexp_replace($args, $rule) { + if (count($args)<3) { + JFactory::getApplication()->enqueueMessage(JText::sprintf('VMSHIPMENT_RULES_REGEXP_ARGS', "RegExpReplace", "three", "RegExpReplace(pattern, replacement, string)", htmlentities($rule->rulestring)), 'error'); + return false; + } + return preg_replace($args[0], $args[1], $args[2]); + } + + /** RegExpSplit(RegExp, string) => preforms a regexp replacement on the value, returns the resulting string */ + static function rules_regexp_split($args, $rule) { + if (count($args)<2) { + JFactory::getApplication()->enqueueMessage(JText::sprintf('VMSHIPMENT_RULES_REGEXP_ARGS', "RegExpSplit", "two", "RegExpSplit(pattern, string)", htmlentities($rule->rulestring)), 'error'); + return false; + } + return preg_split($args[0], $args[1]); + } + + /** RegExpFilter(RegExp, array) => returns all entries of the array that match the regexp pattern */ + static function rules_regexp_filter($args, $rule) { + if (count($args)<2) { + JFactory::getApplication()->enqueueMessage(JText::sprintf('VMSHIPMENT_RULES_REGEXP_ARGS', "RegExpFilter", "two", "RegExpFilter(pattern, array)", htmlentities($rule->rulestring)), 'error'); + return false; + } + return preg_grep($args[0], $args[1]); + } +} + +// No closing tag diff --git a/plugins/regexp/regexp.script.php b/plugins/regexp/regexp.script.php new file mode 100644 index 0000000000000000000000000000000000000000..843e90e541db9f0941ce278c913c0d9149b239a8 --- /dev/null +++ b/plugins/regexp/regexp.script.php @@ -0,0 +1,88 @@ +<?php +defined('_JEXEC') or die('Restricted access'); + +/** + * Installation script for the plugin + * + * @copyright Copyright (C) 2014 Reinhold Kainhofer, office@open-tools.net + * @license GPL v3+, http://www.gnu.org/copyleft/gpl.html + */ + +// Adjust the class name. It has to be of the form: +// plgVmShipmentRegexpInstallerScript +class plgVmShipmentRulesRegexpInstallerScript +{ + /** + * Constructor + * + * @param JAdapterInstance $adapter The object responsible for running this script + */ +// public function __constructor(JAdapterInstance $adapter); + + /** + * Called before any type of action + * + * @param string $route Which action is happening (install|uninstall|discover_install) + * @param JAdapterInstance $adapter The object responsible for running this script + * + * @return boolean True on success + */ +// public function preflight($route, JAdapterInstance $adapter); + + /** + * Called after any type of action + * + * @param string $route Which action is happening (install|uninstall|discover_install) + * @param JAdapterInstance $adapter The object responsible for running this script + * + * @return boolean True on success + */ +// public function postflight($route, JAdapterInstance $adapter); + + /** + * Called on installation + * + * @param JAdapterInstance $adapter The object responsible for running this script + * + * @return boolean True on success + */ + public function install(JAdapterInstance $adapter) + { + // enabling plugin upon installation + $db =& JFactory::getDBO(); + $db->setQuery('update #__extensions set enabled = 1 where type = "plugin" and element = "regexp" and folder = "vmshipmentrules"'); + $db->query(); + + return True; + } + + /** + * Called on update + * + * @param JAdapterInstance $adapter The object responsible for running this script + * + * @return boolean True on success + */ +// public function update(JAdapterInstance $adapter) +// { +// jimport( 'joomla.filesystem.file' ); +// $file = JPATH_ROOT . DS . "administrator" . DS . "language" . DS . "en-GB" . DS . "en-GB.plg_vmshipmentrules_regexp.sys.ini"; +// if (JFile::exists($file)) JFile::delete($file); +// $file = JPATH_ROOT . DS . "administrator" . DS . "language" . DS . "de-DE" . DS . "de-DE.plg_vmshipmentrules_regexp.sys.ini"; +// if (JFile::exists($file)) JFile::delete($file); +// return true; +// } + + /** + * Called on uninstallation + * + * @param JAdapterInstance $adapter The object responsible for running this script + */ +// public function uninstall(JAdapterInstance $adapter) +// { +// // Remove plugin table +// $db =& JFactory::getDBO(); +// $db->setQuery('DROP TABLE IF EXISTS `#__virtuemart_vmshipmentrulesles_regexp`;'); +// $db->query(); +// } +} diff --git a/plugins/regexp/regexp.xml b/plugins/regexp/regexp.xml new file mode 100644 index 0000000000000000000000000000000000000000..a1f23011a8526fae51828824c205308aca3cc84a --- /dev/null +++ b/plugins/regexp/regexp.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<extension version="2.5" type="plugin" group="vmshipmentrules" method="upgrade"> + <name>VMSHIPMENTRULES_REGEXP</name> + <creationDate>2014-11-10</creationDate> + <author>Reinhold Kainhofer, Open Tools</author> + <authorUrl>http://www.open-tools.net</authorUrl> + <copyright>Copyright (C) 2014, Reinhold Kainhofer</copyright> + <license>GPL v3+</license> + <version>1.0</version> + <description>VMSHIPMENTRULES_REGEXP_DESC</description> + <files> + <filename plugin="regexp">regexp.php</filename> + <folder>language</folder> + </files> + <languages folder="language"> + <language tag="en-GB">en-GB/en-GB.plg_vmshipmentrules_regexp.ini</language> + <language tag="en-GB">en-GB/en-GB.plg_vmshipmentrules_regexp.sys.ini</language> + </languages> + <scriptfile>regexp.script.php</scriptfile> + + <!-- VM 3.x support (fields rather than params): --> + <vmconfig></vmconfig> + + <!-- VM 2.0 support (params rather than fields): --> + <params></params> + +</extension> diff --git a/plugins/regexp/releases/plg_opentools_vmshipmentrules_regexp_v1.0.zip b/plugins/regexp/releases/plg_opentools_vmshipmentrules_regexp_v1.0.zip new file mode 100644 index 0000000000000000000000000000000000000000..3a17054f812a51a3a0cd4a4ab09080feb159a1fe Binary files /dev/null and b/plugins/regexp/releases/plg_opentools_vmshipmentrules_regexp_v1.0.zip differ