Skip to content
Snippets Groups Projects
Commit 266d6b7e authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

RegExp V1.0: Initial version of the RegExp vmshipmentrules plugin that...

RegExp V1.0: Initial version of the RegExp vmshipmentrules plugin that provides five regexp-matching/replacing functions
parent b7b6ac6f
No related branches found
No related tags found
No related merge requests found
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)
; 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
; 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."
<!DOCTYPE html><title></title>
<!DOCTYPE html><title></title>
<?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
<?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();
// }
}
<?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>
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment