Permalink
Browse files

new formprotect and iffalse template tag modules

  • Loading branch information...
1 parent 0e7fcb2 commit 060c8b9764fd0b91c49103dabf9294ac0a0f34f6 @haraldpdl committed Feb 14, 2014
Showing with 96 additions and 0 deletions.
  1. +42 −0 osCommerce/OM/Core/Template/Tag/formprotect.php
  2. +54 −0 osCommerce/OM/Core/Template/Tag/iffalse.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * osCommerce Online Merchant
+ *
+ * @copyright Copyright (c) 2014 osCommerce; http://www.oscommerce.com
+ * @license BSD License; http://www.oscommerce.com/bsdlicense.txt
+ */
+
+ namespace osCommerce\OM\Core\Template\Tag;
+
+ use osCommerce\OM\Core\HTML;
+ use osCommerce\OM\Core\OSCOM;
+ use osCommerce\OM\Core\Registry;
+
+/**
+ * @since v3.0.3
+ */
+
+ class formprotect extends \osCommerce\OM\Core\Template\TagAbstract {
+ static protected $_parse_result = false;
+
+ static public function execute($string) {
+ $OSCOM_Template = Registry::get('Template');
+
+ if ( !$OSCOM_Template->valueExists($string) ) {
+ if ( class_exists('osCommerce\\OM\\Core\\Site\\' . OSCOM::getSite() . '\\Application\\' . OSCOM::getSiteApplication() . '\\Module\\Template\\Value\\' . $string . '\\Controller') && is_subclass_of('osCommerce\\OM\\Core\\Site\\' . OSCOM::getSite() . '\\Application\\' . OSCOM::getSiteApplication() . '\\Module\\Template\\Value\\' . $string . '\\Controller', 'osCommerce\\OM\\Core\\Template\\ValueAbstract') ) {
+ call_user_func(array('osCommerce\\OM\\Core\\Site\\' . OSCOM::getSite() . '\\Application\\' . OSCOM::getSiteApplication() . '\\Module\\Template\\Value\\' . $string . '\\Controller', 'initialize'));
+ } elseif ( class_exists('osCommerce\\OM\\Core\\Site\\' . OSCOM::getSite() . '\\Module\\Template\\Value\\' . $string . '\\Controller') && is_subclass_of('osCommerce\\OM\\Core\\Site\\' . OSCOM::getSite() . '\\Module\\Template\\Value\\' . $string . '\\Controller', 'osCommerce\\OM\\Core\\Template\\ValueAbstract') ) {
+ call_user_func(array('osCommerce\\OM\\Core\\Site\\' . OSCOM::getSite() . '\\Module\\Template\\Value\\' . $string . '\\Controller', 'initialize'));
+ }
+ }
+
+ $result = '';
+
+ if ( $OSCOM_Template->valueExists($string) ) {
+ $result = HTML::hiddenField($string, md5($OSCOM_Template->getValue($string)));
+ }
+
+ return $result;
+ }
+ }
+?>
@@ -0,0 +1,54 @@
+<?php
+/**
+ * osCommerce Online Merchant
+ *
+ * @copyright Copyright (c) 2014 osCommerce; http://www.oscommerce.com
+ * @license BSD License; http://www.oscommerce.com/bsdlicense.txt
+ */
+
+ namespace osCommerce\OM\Core\Template\Tag;
+
+ use osCommerce\OM\Core\OSCOM;
+ use osCommerce\OM\Core\Registry;
+
+/**
+ * @since v3.0.3
+ */
+
+ class iffalse extends \osCommerce\OM\Core\Template\TagAbstract {
+ static protected $_parse_result = false;
+
+ static public function execute($string) {
+ $args = func_get_args();
+
+ $OSCOM_Template = Registry::get('Template');
+
+ $key = trim($args[1]);
+
+ if ( !$OSCOM_Template->valueExists($key) ) {
+ if ( class_exists('osCommerce\\OM\\Core\\Site\\' . OSCOM::getSite() . '\\Application\\' . OSCOM::getSiteApplication() . '\\Module\\Template\\Value\\' . $key . '\\Controller') && is_subclass_of('osCommerce\\OM\\Core\\Site\\' . OSCOM::getSite() . '\\Application\\' . OSCOM::getSiteApplication() . '\\Module\\Template\\Value\\' . $key . '\\Controller', 'osCommerce\\OM\\Core\\Template\\ValueAbstract') ) {
+ call_user_func(array('osCommerce\\OM\\Core\\Site\\' . OSCOM::getSite() . '\\Application\\' . OSCOM::getSiteApplication() . '\\Module\\Template\\Value\\' . $key . '\\Controller', 'initialize'));
+ } elseif ( class_exists('osCommerce\\OM\\Core\\Site\\' . OSCOM::getSite() . '\\Module\\Template\\Value\\' . $key . '\\Controller') && is_subclass_of('osCommerce\\OM\\Core\\Site\\' . OSCOM::getSite() . '\\Module\\Template\\Value\\' . $key . '\\Controller', 'osCommerce\\OM\\Core\\Template\\ValueAbstract') ) {
+ call_user_func(array('osCommerce\\OM\\Core\\Site\\' . OSCOM::getSite() . '\\Module\\Template\\Value\\' . $key . '\\Controller', 'initialize'));
+ }
+ }
+
+ $is_false = $OSCOM_Template->valueExists($key) && ($OSCOM_Template->getValue($key) === false);
+ $has_else = strpos($string, '{else}');
+
+ $result = '';
+
+ if ( $has_else !== false ) {
+ if ( $is_false === true ) {
+ $result = substr($string, 0, $has_else);
+ } else {
+ $result = substr($string, $has_else + 6); // strlen('{else}')==6
+ }
+ } elseif ( $is_false === true ) {
+ $result = $string;
+ }
+
+ return $result;
+ }
+ }
+?>

0 comments on commit 060c8b9

Please sign in to comment.