From: <txm...@us...> - 2014-12-06 21:54:52
|
Revision: 12888 http://sourceforge.net/p/xoops/svn/12888 Author: txmodxoops Date: 2014-12-06 21:54:48 +0000 (Sat, 06 Dec 2014) Log Message: ----------- Updated - Fixed bugs Modified Paths: -------------- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/admin/fields.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/admin/header.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/building.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/fields.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/TDMCreateArchitecture.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/TDMCreateFile.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/admin/AdminPages.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/classes/ClassFormElements.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/admin/TemplatesAdminPages.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/blocks/TemplatesBlocks.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/user/TemplatesUserPages.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/modules.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/tables.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/include/common.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/templates/admin/tdmcreate_fields.tpl Added Paths: ----------- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/TDMCreateHelper.php XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/TDMCreateHtmlSmartyCodes.php Removed Paths: ------------- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/request.php Modified: XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/admin/fields.php =================================================================== --- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/admin/fields.php 2014-12-04 21:57:19 UTC (rev 12887) +++ XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/admin/fields.php 2014-12-06 21:54:48 UTC (rev 12888) @@ -132,10 +132,10 @@ } else { $GLOBALS['xoopsTpl']->assign('error', _AM_TDMCREATE_THEREARENT_FIELDS); } - var_dump($fieldMid); + /*var_dump($fieldMid); var_dump($fieldTid); var_dump($fieldNumb); - var_dump($fieldName); + var_dump($fieldName);*/ break; case 'new': @@ -152,10 +152,10 @@ $form = $fieldsObj->getFormNew($fieldMid, $fieldTid, $fieldNumb, $fieldName); $GLOBALS['xoopsTpl']->assign('form', $form->render()); // Test -> Will be removed - var_dump($fieldMid); + /*var_dump($fieldMid); var_dump($fieldTid); var_dump($fieldNumb); - var_dump($fieldName); + var_dump($fieldName); */ break; case 'save': @@ -242,7 +242,7 @@ $form = $fieldsObj->getFormEdit($fieldMid, $fieldTid); $GLOBALS['xoopsTpl']->assign('form', $form->render()); // Test -> Will be removed - var_dump($fieldTid); + //var_dump($fieldTid); break; case 'drag': @@ -273,7 +273,23 @@ unset($i); } exit; - break; + break; + + case 'delete': + $tablesObj =& $tdmcreate->getHandler('tables')->get($fieldTid); + if (isset($_REQUEST['ok']) && $_REQUEST['ok'] == 1) { + if ( !$GLOBALS['xoopsSecurity']->check() ) { + redirect_header('fields.php', 3, implode(',', $GLOBALS['xoopsSecurity']->getErrors())); + } + if ($tdmcreate->getHandler('tables')->delete($tablesObj)) { + redirect_header('fields.php', 3, _AM_TDMCREATE_FORMDELOK); + } else { + echo $tablesObj->getHtmlErrors(); + } + } else { + xoops_confirm(array('ok' => 1, 'field_tid' => $fieldTid, 'op' => 'delete'), $_SERVER['REQUEST_URI'], sprintf(_AM_TDMCREATE_FORMSUREDEL, $tablesObj->getVar('table_name'))); + } + break; case 'display': // Modified: XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/admin/header.php =================================================================== --- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/admin/header.php 2014-12-04 21:57:19 UTC (rev 12887) +++ XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/admin/header.php 2014-12-06 21:54:48 UTC (rev 12888) @@ -30,7 +30,7 @@ $modPathIcon32 = $GLOBALS['xoopsModule']->getInfo('modicons32'); $pathModuleAdmin = $GLOBALS['xoopsModule']->getInfo('dirmoduleadmin'); // TDMCreate Instance -$tdmcreate = TDMCreate::getInstance(); +$tdmcreate = TDMCreateHelper::getInstance(); // MyTextSanitizer $myts =& MyTextSanitizer::getInstance(); if (!isset($xoopsTpl) || !is_object($xoopsTpl)) { Added: XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/TDMCreateHelper.php =================================================================== --- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/TDMCreateHelper.php (rev 0) +++ XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/TDMCreateHelper.php 2014-12-06 21:54:48 UTC (rev 12888) @@ -0,0 +1,173 @@ +<?php +/* + You may not change or alter any portion of this comment or credits + of supporting developers from this source code or any supporting source code + which is considered copyrighted (c) material of the original comment or credit authors. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ +/** + * tdmcreate module + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + * @package tdmcreate + * @since 2.5.0 + * @author trabis <lus...@gm...> + * @version $Id: TDMCreateHelper.php 12258 2014-04-12 23:45:12Z timgno $ + */ +defined('XOOPS_ROOT_PATH') or die('Restricted access'); + +class TDMCreateHelper +{ + /** + * @var string + */ + private $dirname = null; + /** + * @var string + */ + private $module = null; + /** + * @var string + */ + private $handler = null; + /** + * @var string + */ + private $config = null; + /** + * @var string + */ + private $debug = null; + /** + * @var array + */ + private $debugArray = array(); + /* + * @protected function constructor class + * @param mixed $debug + */ + protected function __construct($debug) + { + $this->debug = $debug; + $this->dirname = basename(dirname(dirname(__FILE__))); + } + /* + * @static function &getInstance + * @param mixed $debug + */ + public static function &getInstance($debug = false) + { + static $instance = false; + if (!$instance) { + $instance = new self($debug); + } + return $instance; + } + /* + * @static function getModule + * @param null + */ + public function &getModule() + { + if ($this->module == null) { + $this->initModule(); + } + return $this->module; + } + /* + * @static function getConfig + * @param string $name + */ + public function getConfig($name = null) + { + if ($this->config == null) { + $this->initConfig(); + } + if (!$name) { + $this->addLog("Getting all config"); + return $this->config; + } + if (!isset($this->config[$name])) { + $this->addLog("ERROR :: CONFIG '{$name}' does not exist"); + return null; + } + $this->addLog("Getting config '{$name}' : " . $this->config[$name]); + return $this->config[$name]; + } + /* + * @static function setConfig + * @param string $name + * @param mixed $value + */ + public function setConfig($name = null, $value = null) + { + if ($this->config == null) { + $this->initConfig(); + } + $this->config[$name] = $value; + $this->addLog("Setting config '{$name}' : " . $this->config[$name]); + return $this->config[$name]; + } + /* + * @static function getHandler + * @param string $name + */ + public function &getHandler($name) + { + if (!isset($this->handler[$name . '_handler'])) { + $this->initHandler($name); + } + $this->addLog("Getting handler '{$name}'"); + return $this->handler[$name . '_handler']; + } + /* + * @static function initModule + * @param null + */ + public function initModule() + { + global $xoopsModule; + if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $this->dirname) { + $this->module = $xoopsModule; + } else { + $hModule = xoops_gethandler('module'); + $this->module = $hModule->getByDirname($this->dirname); + } + $this->addLog('INIT MODULE'); + } + /* + * @static function initConfig + * @param null + */ + public function initConfig() + { + $this->addLog('INIT CONFIG'); + $hModConfig = xoops_gethandler('config'); + $this->config = $hModConfig->getConfigsByCat(0, $this->getModule()->getVar('mid')); + } + /* + * @static function initHandler + * @param string $name + */ + public function initHandler($name) + { + $this->addLog('INIT ' . $name . ' HANDLER'); + $this->handler[$name . '_handler'] = xoops_getModuleHandler($name, $this->dirname); + } + /* + * @static function addLog + * @param string $log + */ + public function addLog($log) + { + if ($this->debug) { + if (is_object($GLOBALS['xoopsLogger'])) { + $GLOBALS['xoopsLogger']->addExtra($this->module->name(), $log); + } + } + } +} \ No newline at end of file Modified: XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/building.php =================================================================== --- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/building.php 2014-12-04 21:57:19 UTC (rev 12887) +++ XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/building.php 2014-12-06 21:54:48 UTC (rev 12888) @@ -36,7 +36,7 @@ public function __construct() { $this->XoopsObject(); - $this->tdmcreate = TDMCreate::getInstance(); + $this->tdmcreate = TDMCreateHelper::getInstance(); } /* Modified: XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/fields.php =================================================================== --- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/fields.php 2014-12-04 21:57:19 UTC (rev 12887) +++ XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/fields.php 2014-12-06 21:54:48 UTC (rev 12888) @@ -38,7 +38,7 @@ */ public function __construct() { - $this->tdmcreate = TDMCreate::getInstance(); + $this->tdmcreate = TDMCreateHelper::getInstance(); $this->initVar('field_id', XOBJ_DTYPE_INT); $this->initVar('field_mid', XOBJ_DTYPE_INT); $this->initVar('field_tid', XOBJ_DTYPE_INT); @@ -248,16 +248,10 @@ $check_field_block->addOption(1, _AM_TDMCREATE_FIELD_BLOCK); $parameters_tray->addElement($check_field_block); - if(($i == 1)) { - $field_main = 1; + $field_main = ( $i == 1 ) ? 1 : 0; $check_field_main = new XoopsFormRadio('', 'field_main['.$i.']', $field_main); - $check_field_main->addOption($field_main, _AM_TDMCREATE_FIELD_MAINFIELD ); - } else { - $field_main = 0; - $check_field_main = new XoopsFormRadio('', 'field_main['.$i.']'); - $check_field_main->addOption($field_main, _AM_TDMCREATE_FIELD_MAINFIELD ); - } - $parameters_tray->addElement($check_field_main); + $check_field_main->addOption($i, _AM_TDMCREATE_FIELD_MAINFIELD ); + $parameters_tray->addElement($check_field_main); $field_search = 0; $check_field_search = new XoopsFormCheckBox(' ', 'field_search['.$i.']', $field_search); @@ -379,15 +373,11 @@ $check_field_block = new XoopsFormCheckBox('', 'field_block['.$field_id.']', $field->getVar('field_block')); $check_field_block->addOption(1, _AM_TDMCREATE_FIELD_BLOCK); - $parameters_tray->addElement($check_field_block); - - $field_main = $field->getVar('field_main'); - if($field_main == 1) { - $check_field_main = new XoopsFormRadio('', 'field_main['.$field_id.']', $field_main); - } else { - $check_field_main = new XoopsFormRadio('', 'field_main['.$field_id.']'); - } - $check_field_main->addOption($field_main, _AM_TDMCREATE_FIELD_MAINFIELD ); + $parameters_tray->addElement($check_field_block); + + $field_main = $field->getVar('field_main'); + $check_field_main = new XoopsFormRadio('', 'field_main['.$field_id.']', $field_main); + $check_field_main->addOption($field_id, _AM_TDMCREATE_FIELD_MAINFIELD ); $parameters_tray->addElement($check_field_main); $check_field_search = new XoopsFormCheckBox(' ', 'field_search['.$field_id.']', $field->getVar('field_search')); Modified: XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/TDMCreateArchitecture.php =================================================================== --- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/TDMCreateArchitecture.php 2014-12-04 21:57:19 UTC (rev 12887) +++ XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/TDMCreateArchitecture.php 2014-12-06 21:54:48 UTC (rev 12888) @@ -36,7 +36,7 @@ * @param null */ public function __construct() { - $this->tdmcreate = TDMCreate::getInstance(); + $this->tdmcreate = TDMCreateHelper::getInstance(); $this->structure = TDMCreateStructure::getInstance(); } /* Modified: XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/TDMCreateFile.php =================================================================== --- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/TDMCreateFile.php 2014-12-04 21:57:19 UTC (rev 12887) +++ XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/TDMCreateFile.php 2014-12-06 21:54:48 UTC (rev 12888) @@ -88,7 +88,7 @@ */ public function __construct() { $this->xoopsFile = XoopsFile::getHandler(); - $this->tdmcreate = TDMCreate::getInstance(); + $this->tdmcreate = TDMCreateHelper::getInstance(); } /* Modified: XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/admin/AdminPages.php =================================================================== --- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/admin/AdminPages.php 2014-12-04 21:57:19 UTC (rev 12887) +++ XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/admin/AdminPages.php 2014-12-06 21:54:48 UTC (rev 12888) @@ -124,7 +124,7 @@ $rpFieldName = $this->tdmcfile->getRightString($fieldName); // $fieldElement = $fields[$f]->getVar('field_element'); - if( ($fields[$f]->getVar('field_admin') == 1) || ($tableAutoincrement == 1) ) { + if( ($fields[$f]->getVar('field_admin') == 1) || ($tableAutoincrement == 1) && ($fields[$f]->getVar('field_inlist') == 1) ) { switch($fieldElement) { case 3: case 4: @@ -307,6 +307,8 @@ * @public function getAdminPagesDelete * @param string $tableName * @param string $language + * @param string $fpif + * @param string $fpmf */ public function getAdminPagesDelete($tableName, $language, $fpif, $fpmf) { @@ -331,6 +333,33 @@ } /* + * @public function getAdminPagesUpdate + * @param string $moduleDirname + * @param string $tableName + * @param string $language + * @param string $fpif + * @param string $fpmf + */ + public function getAdminPagesUpdate($moduleDirname, $tableName, $language, $fpif, $fpmf) { + + $upModuleName = strtoupper($moduleDirname); + $ret = <<<EOT + case 'update': + if (isset(\${$fpif})) { + \${$tableName}Obj =& \${$tableName}Handler->get(\${$fpif}); + } + \${$tableName}Obj->setVar("\${$tableName}_display", \$_POST["\${$tableName}_display"]); + + if (\${$tableName}Handler->insert(\${$tableName}Obj)) { + redirect_header("\${$tableName}.php", 3, _AM_{$upModuleName}_FORMOK); + } + echo \${$tableName}Obj->getHtmlErrors(); + break;\n +EOT; + return $ret; + } + + /* * @public function getAdminPagesFooter * @param null */ @@ -350,7 +379,7 @@ { $module = $this->getModule(); $table = $this->getTable(); - $moduleDirname = $module->getVar('mod_dirname'); + $moduleDirname = $module->getVar('mod_dirname'); $tableName = $table->getVar('table_name'); $tableFieldname = $table->getVar('table_fieldname'); $language = $this->getLanguage($moduleDirname, 'AM'); Modified: XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/classes/ClassFormElements.php =================================================================== --- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/classes/ClassFormElements.php 2014-12-04 21:57:19 UTC (rev 12887) +++ XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/classes/ClassFormElements.php 2014-12-06 21:54:48 UTC (rev 12888) @@ -28,7 +28,7 @@ */ public function __construct() { parent::__construct(); - $this->tdmcreate = TDMCreate::getInstance(); + $this->tdmcreate = TDMCreateHelper::getInstance(); } /* * @static function &getInstance @@ -300,9 +300,23 @@ * @param string $fields * @param string $required */ - private function getXoopsFormTopic($language, $moduleDirname, $tableName, $field_id, $field_pid, $fieldName, $field_main, $required = 'false') + private function getXoopsFormTopic($language, $moduleDirname, $table, $fields, $required = 'false') { + $tableName = $table->getVar('table_name'); $ucfTableName = ucfirst($tableName); + foreach(array_keys($fields) as $f) + { + $fieldName = $fields[$f]->getVar('field_name'); + if(($f == 0) && ($table->getVar('table_autoincrement') == 1)) { + $fieldId = $fieldName; + } + if($fields[$f]->getVar('field_parent') == 1) { + $fieldPid = $fieldName; + } + if($fields[$f]->getVar('field_main') == 1) { + $fieldMain = $fieldName; + } + } $ret = <<<EOT // Form Topic {$ucfTableName} //\${$tableName}Handler = \$this->{$moduleDirname}->getHandler('{$tableName}'); @@ -310,9 +324,9 @@ \${$tableName} = \${$tableName}Handler->getObjects( \$criteria ); if(\${$tableName}) { include_once(XOOPS_ROOT_PATH . '/class/tree.php'); - \${$tableName}_tree = new XoopsObjectTree( \${$tableName}, '{$field_id}', '{$field_pid}' ); - \${$field_pid} = \${$tableName}_tree->makeSelBox( '{$field_pid}', '{$field_main}', '--', \$this->getVar('{$field_pid}', 'e' ), true ); - \$form->addElement( new XoopsFormLabel ( {$language}, \${$field_pid} ){$required} ); + \${$tableName}_tree = new XoopsObjectTree( \${$tableName}, '{$fieldId}', '{$fieldPid}' ); + \${$fieldPid} = \${$tableName}_tree->makeSelBox( '{$fieldPid}', '{$fieldMain}', '--', \$this->getVar('{$fieldPid}', 'e' ), true ); + \$form->addElement( new XoopsFormLabel ( {$language}, \${$fieldPid} ){$required} ); }\n EOT; return $ret; @@ -399,7 +413,7 @@ } if ($fieldElement > 13) { if($table->getVar('table_category') == 1) { - $ret .= $this->getXoopsFormTopic($language, $moduleDirname, $tableName, $fieldId, $fieldPid, $fieldName, $fieldMain, $required); + $ret .= $this->getXoopsFormTopic($language, $moduleDirname, $table, $fields, $required); } else { $ret .= $this->getXoopsFormTable($language, $moduleDirname, $tableName, $fieldName, $fieldElement, $required); } Added: XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/TDMCreateHtmlSmartyCodes.php =================================================================== --- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/TDMCreateHtmlSmartyCodes.php (rev 0) +++ XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/TDMCreateHtmlSmartyCodes.php 2014-12-06 21:54:48 UTC (rev 12888) @@ -0,0 +1,308 @@ +<?php +/* + You may not change or alter any portion of this comment or credits + of supporting developers from this source code or any supporting source code + which is considered copyrighted (c) material of the original comment or credit authors. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + */ +/** + * tdmcreate module + * + * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ + * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) + * @package tdmcreate + * @since 2.5.0 + * @author Txmod Xoops http://www.txmodxoops.org + * @version $Id: htmlsmartycodes.php 12258 2014-01-02 09:33:29Z timgno $ + */ +defined('XOOPS_ROOT_PATH') or die('Restricted access'); + +class TDMCreateHtmlSmartyCodes extends TDMCreateFile +{ + /* + * @public function constructor + * @param null + */ + public function __construct() { + parent::__construct(); + } + /* + * @static function &getInstance + * @param null + */ + public static function &getInstance() + { + static $instance = false; + if (!$instance) { + $instance = new self(); + } + return $instance; + } + /* + * @public function getHtmlDiv + * @param string $class + * @param string $content + */ + public function getHtmlDiv($class = 'bnone', $content = '') { + $ret = <<<EOT + <div class='{$class}'> + {$content} + </div> +EOT; + return $ret; + } + /* + * @public function getHtmlSpan + * @param string $class + * @param string $content + */ + public function getHtmlSpan($class = 'bnone', $content = '') { + $ret = <<<EOT + <span class='{$class}'> + {$content} + </span> +EOT; + return $ret; + } + /* + * @public function getHtmlParagraph + * @param string $class + * @param string $content + */ + public function getHtmlParagraph($class = 'bnone', $content = '') { + $ret = <<<EOT + <p class='{$class}'> + {$content} + </p> +EOT; + return $ret; + } + /* + * @public function getHtmlAnchor + * @param string $class + * @param string $url + * @param string $target + * @param string $content + */ + public function getHtmlAnchor($class = 'bnone', $url = 'http://', $target = '_top', $content = '') { + $ret = <<<EOT + <a class='{$class}' href='{$url}' target='{$target}'> + {$content} + </a> +EOT; + return $ret; + } + /* + * @public function getHtmlImage + * @param string $class + * @param string $src + * @param string $alt + */ + public function getHtmlImage($class = 'bnone', $src = 'blank.gif', $alt = 'blank.gif') { + $ret = <<<EOT + <img class='{$class}' src='{$src}' alt='{$alt}' /> +EOT; + return $ret; + } + /* + * @public function getHtmlTable + * @param string $class + * @param string $content + */ + public function getHtmlTable($class = 'bnone', $content = '') { + $ret = <<<EOT + <table class='{$class}'> + {$content} + </table> +EOT; + return $ret; + } + /* + * @public function getHtmlTableThead + * @param string $class + * @param string $content + */ + public function getHtmlTableThead($class = 'bnone', $content = '') { + $ret = <<<EOT + <thead class='{$class}'> + {$content} + </thead> +EOT; + return $ret; + } + /* + * @public function getHtmlTableTbody + * @param string $class + * @param string $content + */ + public function getHtmlTableTbody($class = 'bnone', $content = '') { + $ret = <<<EOT + <tbody class='{$class}'> + {$content} + </tbody> +EOT; + return $ret; + } + /* + * @public function getHtmlTableTfoot + * @param string $class + * @param string $content + */ + public function getHtmlTableTfoot($class = 'bnone', $content = '') { + $ret = <<<EOT + <tfoot class='{$class}'> + {$content} + </tfoot> +EOT; + return $ret; + } + /* + * @public function getHtmlTableHead + * @param string $class + * @param string $content + */ + public function getHtmlTableHead($class = 'bnone', $content = '') { + $ret = <<<EOT + <th class='{$class}'>{$content}</th> +EOT; + return $ret; + } + /* + * @public function getHtmlTableRow + * @param string $class + * @param string $content + */ + public function getHtmlTableRow($class = 'bnone', $content = '') { + $ret = <<<EOT + <tr class='{$class}'> + {$content} + </tr> +EOT; + return $ret; + } + /* + * @public function getHtmlTableData + * @param string $class + * @param string $content + */ + public function getHtmlTableData($class = 'bnone', $content = '') { + $ret = <<<EOT + <td class='{$class}'>{$content}</td> +EOT; + return $ret; + } + /* + * @public function getSmartyConst + * @param string $language + * @param mixed $fieldName + */ + public function getSmartyConst($language, $fieldName) { + $ret = <<<EOT + <{\$smarty.const.{$language}{$fieldName}}> +EOT; + return $ret; + } + /* + * @public function getSmartyTableFieldNameEmptyData + * @param string $tableName + * @param string $fieldName + */ + public function getSmartyTableFieldNameEmptyData($tableName = '', $fieldName = '') { + $ret = <<<EOT + <{\${$tableName}.{$fieldName}}> +EOT; + return $ret; + } + /* + * @public function getSmartyTableField + * @param string $tableFieldname + * @param string $fieldName + */ + public function getSmartyTableFieldData($tableFieldname = '', $fieldName = '') { + $ret = <<<EOT + <{\${$tableFieldname}.{$fieldName}}> +EOT; + return $ret; + } + /* + * @public function getSmartyIncludeFile + * @param string $name + */ + public function getSmartyIncludeFile($moduleDirname, $tableName = 'header') { + $ret = <<<EOT + <{include file='db:{$moduleDirname}_{$tableName}.html'}> +EOT; + return $ret; + } + /* + * @public function getSmartyConditions + * @param string $condition + * @param string $operator + * @param string $type + * @param string $content_if + * @param mixed $content_else + */ + public function getSmartyConditions($condition = '', $operator = '==', $type = '1', $content_if = '', $content_else = false) { + if(!$content_else) { + $ret = <<<EOT + <{if ${$condition} {$operator} {$type}'}> + {$content_if} + <{/if}> +EOT; + } else { + $ret = <<<EOT + <{if ${$condition} {$operator} {$type}'}> + {$content_if} + <{else}> + {$content_else} + <{/if}> +EOT; + } + return $ret; + } + /* + * @public function getSmartyForeach + * @param string $item + * @param string $from + * @param string $content + */ + public function getSmartyForeach($item = 'item', $from = 'from', $content = 'content') { + $ret = <<<EOT + <{foreach item={$item} from=${$from}}> + {$content} + <{/foreach}> +EOT; + return $ret; + } + /* + * @public function getSmartyForeachQuery + * @param string $item + * @param string $from + * @param string $content + */ + public function getSmartyForeachQuery($item = 'item', $from = 'from', $content = 'content') { + $ret = <<<EOT + <{foreachq item={$item} from=${$from}}> + {$content} + <{/foreachq}> +EOT; + return $ret; + } + /* + * @public function getSmartySection + * @param string $name + * @param string $loop + * @param string $content + */ + public function getSmartySection($name = 'name', $loop = 'loop', $content = 'content') { + $ret = <<<EOT + <{section name={$name} loop=${$loop}}> + {$content} + <{/section}> +EOT; + return $ret; + } +} \ No newline at end of file Modified: XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/admin/TemplatesAdminPages.php =================================================================== --- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/admin/TemplatesAdminPages.php 2014-12-04 21:57:19 UTC (rev 12887) +++ XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/admin/TemplatesAdminPages.php 2014-12-06 21:54:48 UTC (rev 12888) @@ -113,7 +113,7 @@ switch( $fieldElement ) { case 9: $ret .= <<<EOT - <td class="center"><span style="background-color: <{\$list.{$rpFieldName}}>;"> </span></td>\n + <td class="center"><span style="background-color: #<{\$list.{$rpFieldName}}>;"> </span></td>\n EOT; break; case 10: @@ -176,7 +176,7 @@ switch( $fieldElement ) { case 9: $ret .= <<<EOT - <td class="center"><span style="background-color: <{\$list.{$fieldName}}>;">\t\t</span></td>\n + <td class="center"><span style="background-color: #<{\$list.{$fieldName}}>;">\t\t</span></td>\n EOT; break; case 10: Modified: XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/blocks/TemplatesBlocks.php =================================================================== --- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/blocks/TemplatesBlocks.php 2014-12-04 21:57:19 UTC (rev 12887) +++ XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/blocks/TemplatesBlocks.php 2014-12-06 21:54:48 UTC (rev 12888) @@ -102,7 +102,7 @@ switch( $fieldElement ) { case 9: $ret .= <<<EOT - <td class="center"><span style="background-color: <{\$list.{$rpFieldName}}>;">\t\t</span></td>\n + <td class="center"><span style="background-color: #<{\$list.{$rpFieldName}}>;">\t\t</span></td>\n EOT; break; case 10: @@ -156,7 +156,7 @@ switch( $fieldElement ) { case 9: $ret .= <<<EOT - <td class="center"><span style="background-color: <{\$list.{$fieldName}}>;">\t\t</span></td>\n + <td class="center"><span style="background-color: #<{\$list.{$fieldName}}>;">\t\t</span></td>\n EOT; break; case 10: Modified: XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/user/TemplatesUserPages.php =================================================================== --- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/user/TemplatesUserPages.php 2014-12-04 21:57:19 UTC (rev 12887) +++ XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/files/templates/user/TemplatesUserPages.php 2014-12-06 21:54:48 UTC (rev 12888) @@ -107,7 +107,7 @@ switch( $fieldElement ) { case 9: $ret .= <<<EOT - <td class="center"><span style="background-color: <{\$list.{$rpFieldName}}>;">\t\t</span></td>\n + <td class="center"><span style="background-color: #<{\$list.{$rpFieldName}}>;">\t\t</span></td>\n EOT; break; case 10: @@ -159,7 +159,7 @@ switch( $fieldElement ) { case 9: $ret .= <<<EOT - <td class="center"><span style="background-color: <{\$list.{$fieldName}}>;"></span></td>\n + <td class="center"><span style="background-color: #<{\$list.{$fieldName}}>;"></span></td>\n EOT; break; case 10: Modified: XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/modules.php =================================================================== --- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/modules.php 2014-12-04 21:57:19 UTC (rev 12887) +++ XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/modules.php 2014-12-06 21:54:48 UTC (rev 12888) @@ -40,7 +40,7 @@ */ public function __construct() { - $this->tdmcreate = TDMCreate::getInstance(); + $this->tdmcreate = TDMCreateHelper::getInstance(); $this->initVar('mod_id',XOBJ_DTYPE_INT); $this->initVar('mod_name',XOBJ_DTYPE_TXTBOX, $this->tdmcreate->getConfig('name')); $this->initVar('mod_dirname',XOBJ_DTYPE_TXTBOX, $this->tdmcreate->getConfig('dirname')); Deleted: XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/request.php =================================================================== --- XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/request.php 2014-12-04 21:57:19 UTC (rev 12887) +++ XoopsModules/TDMCreate/branches/timgno/1.91/tdmcreate/class/request.php 2014-12-06 21:54:48 UTC (rev 12888) @@ -1,960 +0,0 @@ -<?php -/* - You may not change or alter any portion of this comment or credits - of supporting developers from this source code or any supporting source code - which is considered copyrighted (c) material of the original comment or credit authors. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - */ -/** - * Request class - * - * @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved. - * @license GNU/GPL, see LICENSE.php - * Joomla! 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 COPYRIGHT.php for copyright notices and details. - * @package TDMCreate - * @since 1.0 - * @author trabis <lus...@gm...> - * @version $Id: request.php 10374 2012-12-12 23:39:48Z trabis $ - * @version $Id: request.php 12424 2014-04-18 22:11:14Z timgno $ - */ - -/** - * Set the available masks for cleaning variables - */ -define('TDMCREATE_REQUEST_NOTRIM', 1); -define('TDMCREATE_REQUEST_ALLOWRAW', 2); -define('TDMCREATE_REQUEST_ALLOWHTML', 4); - -/** - * TDMCreateRequest Class - * This class serves to provide a common interface to access - * request variables. This includes $_POST, $_GET, and naturally $_REQUEST. Variables - * can be passed through an input filter to avoid injection or returned raw. - */ -class TDMCreateRequest -{ - - /** - * Gets the request method - * - * @return string - */ - static function getOptions() - { - $method = strtoupper($_SERVER['REQUEST_METHOD']); - return $method; - } - - /** - * Fetches and returns a given variable. - * The default behaviour is fetching variables depending on the - * current request method: GET and HEAD will result in returning - * an entry from $_GET, POST and PUT will result in returning an - * entry from $_POST. - * You can force the source by setting the $hash parameter: - * post $_POST - * get $_GET - * files $_FILES - * cookie $_COOKIE - * env $_ENV - * server $_SERVER - * method via current $_SERVER['REQUEST_METHOD'] - * default $_REQUEST - * - * @static - * - * @param string $name Variable name - * @param string $default Default value if the variable does not exist - * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) - * @param string $type Return type for the variable, for valid values see {@link JFilterInput::clean()} - * @param int $mask Filter mask for the variable - * - * @return mixed Requested variable - */ - static function getVar($name, $default = null, $hash = 'default', $type = 'none', $mask = 0) - { - // Ensure hash and type are uppercase - $hash = strtoupper($hash); - if ($hash === 'METHOD') { - $hash = strtoupper($_SERVER['REQUEST_METHOD']); - } - $type = strtoupper($type); - // Get the input hash - switch ($hash) { - case 'GET' : - $input = & $_GET; - break; - case 'POST' : - $input = & $_POST; - break; - case 'FILES' : - $input = & $_FILES; - break; - case 'COOKIE' : - $input = & $_COOKIE; - break; - case 'ENV' : - $input = & $_ENV; - break; - case 'SERVER' : - $input = & $_SERVER; - break; - default: - $input = & $_REQUEST; - $hash = 'REQUEST'; - break; - } - if (isset($input[$name]) && $input[$name] !== null) { - // Get the variable from the input hash and clean it - $var = TDMCreateRequest::_cleanVar($input[$name], $mask, $type); - // Handle magic quotes compatability - if (get_magic_quotes_gpc() && ($var != $default) && ($hash != 'FILES')) { - $var = TDMCreateRequest::_stripSlashesRecursive($var); - } - } else if ($default !== null) { - // Clean the default value - $var = TDMCreateRequest::_cleanVar($default, $mask, $type); - } else { - $var = $default; - } - return $var; - } - - /** - * Fetches and returns a given filtered variable. The integer - * filter will allow only digits to be returned. This is currently - * only a proxy function for getVar(). - * See getVar() for more in-depth documentation on the parameters. - * - * @static - * - * @param string $name Variable name - * @param int $default Default value if the variable does not exist - * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) - * - * @return integer Requested variable - */ - static function getInt($name, $default = 0, $hash = 'default') - { - return TDMCreateRequest::getVar($name, $default, $hash, 'int'); - } - - /** - * Fetches and returns a given filtered variable. The float - * filter only allows digits and periods. This is currently - * only a proxy function for getVar(). - * See getVar() for more in-depth documentation on the parameters. - * - * @static - * - * @param string $name Variable name - * @param float $default Default value if the variable does not exist - * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) - * - * @return float Requested variable - */ - static function getFloat($name, $default = 0.0, $hash = 'default') - { - return TDMCreateRequest::getVar($name, $default, $hash, 'float'); - } - - /** - * Fetches and returns a given filtered variable. The bool - * filter will only return true/false bool values. This is - * currently only a proxy function for getVar(). - * See getVar() for more in-depth documentation on the parameters. - * - * @static - * - * @param string $name Variable name - * @param bool $default Default value if the variable does not exist - * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) - * - * @return bool Requested variable - */ - static function getBool($name, $default = false, $hash = 'default') - { - return TDMCreateRequest::getVar($name, $default, $hash, 'bool'); - } - - /** - * Fetches and returns a given filtered variable. The word - * filter only allows the characters [A-Za-z_]. This is currently - * only a proxy function for getVar(). - * See getVar() for more in-depth documentation on the parameters. - * - * @static - * - * @param string $name Variable name - * @param string $default Default value if the variable does not exist - * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) - * - * @return string Requested variable - */ - static function getWord($name, $default = '', $hash = 'default') - { - return TDMCreateRequest::getVar($name, $default, $hash, 'word'); - } - - /** - * Fetches and returns a given filtered variable. The cmd - * filter only allows the characters [A-Za-z0-9.-_]. This is - * currently only a proxy function for getVar(). - * See getVar() for more in-depth documentation on the parameters. - * - * @static - * - * @param string $name Variable name - * @param string $default Default value if the variable does not exist - * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) - * - * @return string Requested variable - */ - static function getCmd($name, $default = '', $hash = 'default') - { - return TDMCreateRequest::getVar($name, $default, $hash, 'cmd'); - } - - /** - * Fetches and returns a given filtered variable. The string - * filter deletes 'bad' HTML code, if not overridden by the mask. - * This is currently only a proxy function for getVar(). - * See getVar() for more in-depth documentation on the parameters. - * - * @static - * - * @param string $name Variable name - * @param string $default Default value if the variable does not exist - * @param string $hash Where the var should come from (POST, GET, FILES, COOKIE, METHOD) - * @param int $mask Filter mask for the variable - * - * @return string Requested variable - */ - static function getString($name, $default = '', $hash = 'default', $mask = 0) - { - // Cast to string, in case JREQUEST_ALLOWRAW was specified for mask - return (string)TDMCreateRequest::getVar($name, $default, $hash, 'string', $mask); - } - - static function getArray($name, $default = array(), $hash = 'default') - { - return TDMCreateRequest::getVar($name, $default, $hash, 'array'); - } - - static function getText($name, $default = '', $hash = 'default') - { - return (string)TDMCreateRequest::getVar($name, $default, $hash, 'string', TDMCREATE_REQUEST_ALLOWRAW); - } - - /** - * Set a variabe in on of the request variables - * - * @access public - * - * @param string $name Name - * @param string $value Value - * @param string $hash Hash - * @param boolean $overwrite Boolean - * - * @return string Previous value - */ - static function setVar($name, $value = null, $hash = 'method', $overwrite = true) - { - //If overwrite is true, makes sure the variable hasn't been set yet - if (!$overwrite && array_key_exists($name, $_REQUEST)) { - return $_REQUEST[$name]; - } - // Get the request hash value - $hash = strtoupper($hash); - if ($hash === 'METHOD') { - $hash = strtoupper($_SERVER['REQUEST_METHOD']); - } - $previous = array_key_exists($name, $_REQUEST) ? $_REQUEST[$name] : null; - switch ($hash) { - case 'GET' : - $_GET[$name] = $value; - $_REQUEST[$name] = $value; - break; - case 'POST' : - $_POST[$name] = $value; - $_REQUEST[$name] = $value; - break; - case 'COOKIE' : - $_COOKIE[$name] = $value; - $_REQUEST[$name] = $value; - break; - case 'FILES' : - $_FILES[$name] = $value; - break; - case 'ENV' : - $_ENV['name'] = $value; - break; - case 'SERVER' : - $_SERVER['name'] = $value; - break; - } - return $previous; - } - - /** - * Fetches and returns a request array. - * The default behaviour is fetching variables depending on the - * current request method: GET and HEAD will result in returning - * $_GET, POST and PUT will result in returning $_POST. - * You can force the source by setting the $hash parameter: - * post $_POST - * get $_GET - * files $_FILES - * cookie $_COOKIE - * env $_ENV - * server $_SERVER - * method via current $_SERVER['REQUEST_METHOD'] - * default $_REQUEST - * - * @static - * - * @param string $hash to get (POST, GET, FILES, METHOD) - * @param int $mask Filter mask for the variable - * - * @return mixed Request hash - */ - static function get($hash = 'default', $mask = 0) - { - $hash = strtoupper($hash); - if ($hash === 'METHOD') { - $hash = strtoupper($_SERVER['REQUEST_METHOD']); - } - switch ($hash) { - case 'GET' : - $input = $_GET; - break; - case 'POST' : - $input = $_POST; - break; - case 'FILES' : - $input = $_FILES; - break; - case 'COOKIE' : - $input = $_COOKIE; - break; - case 'ENV' : - $input = & $_ENV; - break; - case 'SERVER' : - $input = & $_SERVER; - break; - default: - $input = $_REQUEST; - break; - } - $result = TDMCreateRequest::_cleanVar($input, $mask); - // Handle magic quotes compatability - if (get_magic_quotes_gpc() && ($hash != 'FILES')) { - $result = TDMCreateRequest::_stripSlashesRecursive($result); - } - return $result; - } - - /** - * Sets a request variable - * - * @param array $array An associative array of key-value pairs - * @param string $hash The request variable to set (POST, GET, FILES, METHOD) - * @param boolean $overwrite If true and an existing key is found, the value is overwritten, otherwise it is ingored - */ - static function set($array, $hash = 'default', $overwrite = true) - { - foreach ($array as $key => $value) { - TDMCreateRequest::setVar($key, $value, $hash, $overwrite); - } - } - - /** - * Cleans the request from script injection. - * - * @static - * @return void - */ - static function clean() - { - TDMCreateRequest::_cleanArray($_FILES); - TDMCreateRequest::_cleanArray($_ENV); - TDMCreateRequest::_cleanArray($_GET); - TDMCreateRequest::_cleanArray($_POST); - TDMCreateRequest::_cleanArray($_COOKIE); - TDMCreateRequest::_cleanArray($_SERVER); - if (isset($_SESSION)) { - TDMCreateRequest::_cleanArray($_SESSION); - } - $REQUEST = $_REQUEST; - $GET = $_GET; - $POST = $_POST; - $COOKIE = $_COOKIE; - $FILES = $_FILES; - $ENV = $_ENV; - $SERVER = $_SERVER; - if (isset ($_SESSION)) { - $SESSION = $_SESSION; - } - foreach ($GLOBALS as $key => $value) { - if ($key != 'GLOBALS') { - unset($GLOBALS[$key]); - } - } - $_REQUEST = $REQUEST; - $_GET = $GET; - $_POST = $POST; - $_COOKIE = $COOKIE; - $_FILES = $FILES; - $_ENV = $ENV; - $_SERVER = $SERVER; - if (isset($SESSION)) { - $_SESSION = $SESSION; - } - } - - /** - * Adds an array to the GLOBALS array and checks that the GLOBALS variable is not being attacked - * - * @access protected - * - * @param array $array Array to clean - * @param boolean $globalise True if the array is to be added to the GLOBALS - */ - static function _cleanArray(&$array, $globalise = false) - { - static $banned = array('_files', '_env', '_get', '_post', '_cookie', '_server', '_session', 'globals'); - foreach ($array as $key => $value) { - // PHP GLOBALS injection bug - $failed = in_array(strtolower($key), $banned); - // PHP Zend_Hash_Del_Key_Or_Index bug - $failed |= is_numeric($key); - if ($failed) { - exit('Illegal variable <strong>' . implode('</strong> or <strong>', $banned) . '</strong> passed to script.'); - } - if ($globalise) { - $GLOBALS[$key] = $value; - } - } - } - - /** - * Clean up an input variable. - * - * @param mixed $var The input variable. - * @param int $mask Filter bit mask. 1=no trim: If this flag is cleared and the - * input is a string, the string will have leading and trailing whitespace - * trimmed. 2=allow_raw: If set, no more filtering is performed, higher bits - * are ignored. 4=allow_html: HTML is allowed, but passed through a safe - * HTML filter first. If set, no more filtering is performed. If no bits - * other than the 1 bit is set, a strict filter is applied. - * @param string $type The variable type {@see JFilterInput::clean()}. - * - * @return string - */ - static function _cleanVar($var, $mask = 0, $type = null) - { - // Static input filters for specific settings - static $noHtmlFilter = null; - static $safeHtmlFilter = null; - // If the no trim flag is not set, trim the variable - if (!($mask & 1) && is_string($var)) { - $var = trim($var); - } - // Now we handle input filtering - if ($mask & 2) { - // If the allow raw flag is set, do not modify the variable - } else if ($mask & 4) { - // If the allow html flag is set, apply a safe html filter to the variable - if (is_null($safeHtmlFilter)) { - $safeHtmlFilter = TDMCreateFilterInput::getInstance(null, null, 1, 1); - } - $var = $safeHtmlFilter->clean($var, $type); - } else { - // Since no allow flags were set, we will apply the most strict filter to the variable - if (is_null($noHtmlFilter)) { - $noHtmlFilter = TDMCreateFilterInput::getInstance( /* $tags, $attr, $tag_method, $attr_method, $xss_auto */); - } - $var = $noHtmlFilter->clean($var, $type); - } - return $var; - } - - /** - * Strips slashes recursively on an array - * - * @access protected - * - * @param array $value Array of (nested arrays of) strings - * - * @return array|string The input array with stripshlashes applied to it - */ - protected function _stripSlashesRecursive($value) - { - $value = is_array($value) ? array_map(array('TDMCreateRequest', '_stripSlashesRecursive'), $value) : stripslashes($value); - return $value; - } -} - -/** - * TDMCreateInput is a class for filtering input from any data source - * Forked from the php input filter library by: Daniel Morris <da...@ro...> - * Original Contributors: Gianpaolo Racca, Ghislain Picard, Marco Wandschneider, Chris Tobin and Andrew Eddie. - * - * @author Louis Landry <lou...@jo...> - */ -class TDMCreateFilterInput -{ - var $tagsArray; // default = empty array - var $attrArray; // default = empty array - var $tagsMethod; // default = 0 - var $attrMethod; // default = 0 - var $xssAuto; // default = 1 - var $tagBlacklist = array('applet', 'body', 'bgsound', 'base', 'basefont', 'embed', 'frame', 'frameset', 'head', 'html', 'id', 'iframe', 'ilayer', 'layer', 'link', 'meta', 'name', 'object', 'script', 'style', 'title', 'xml'); - var $attrBlacklist = array('action', 'background', 'codebase', 'dynsrc', 'lowsrc'); // also will strip ALL event handlers - /** - * Constructor for inputFilter class. Only first parameter is required. - * - * @access protected - * - * @param array $tagsArray list of user-defined tags - * @param array $attrArray list of user-defined attributes - * @param int $tagsMethod WhiteList method = 0, BlackList method = 1 - * @param int $attrMethod WhiteList method = 0, BlackList method = 1 - * @param int $xssAuto Only auto clean essentials = 0, Allow clean blacklisted tags/attr = 1 - */ - public function __construct($tagsArray = array(), $attrArray = array(), $tagsMethod = 0, $attrMethod = 0, $xssAuto = 1) - { - // Make sure user defined arrays are in lowercase - $tagsArray = array_map('strtolower', (array)$tagsArray); - $attrArray = array_map('strtolower', (array)$attrArray); - // Assign member variables - $this->tagsArray = $tagsArray; - $this->attrArray = $attrArray; - $this->tagsMethod = $tagsMethod; - $this->attrMethod = $attrMethod; - $this->xssAuto = $xssAuto; - } - - /** - * Returns a reference to an input filter object, only creating it if it doesn't already exist. - * This method must be invoked as: - * <pre> $filter = & TDMCreateFilterInput::getInstance();</pre> - * - * @static - * - * @param array $tagsArray list of user-defined tags - * @param array $attrArray list of user-defined attributes - * @param int $tagsMethod WhiteList method = 0, BlackList method = 1 - * @param int $attrMethod WhiteList method = 0, BlackList method = 1 - * @param int $xssAuto Only auto clean essentials = 0, Allow clean blacklisted tags/attr = 1 - * - * @return object The TDMCreateFilterInput object. - * @since 1.5 - */ - public function & getInstance($tagsArray = array(), $attrArray = array(), $tagsMethod = 0, $attrMethod = 0, $xssAuto = 1) - { - static $instances; - $sig = md5(serialize(array($tagsArray, $attrArray, $tagsMethod, $attrMethod, $xssAuto))); - if (!isset ($instances)) { - $instances = array(); - } - if (empty ($instances[$sig])) { - $instances[$sig] = new TDMCreateFilterInput($tagsArray, $attrArray, $tagsMethod, $attrMethod, $xssAuto); - } - return $instances[$sig]; - } - - /** - * Method to be called by another php script. Processes for XSS and - * specified bad code. - * - * @access public - * - * @param mixed $source Input string/array-of-string to be 'cleaned' - * @param string $type Return type for the variable (INT, FLOAT, BOOLEAN, WORD, ALNUM, CMD, BASE64, STRING, ARRAY, PATH, NONE) - * - * @return mixed 'Cleaned' version of input parameter - * @static - */ - public function clean($source, $type = 'string') - { - // Handle the type constraint - switch (strtoupper($type)) { - case 'INT' : - case 'INTEGER' : - // Only use the first integer value - preg_match('/-?[0-9]+/', (string)$source, $matches); - $result = @ (int)$matches[0]; - break; - case 'FLOAT' : - case 'DOUBLE' : - // Only use the first floating point value - preg_match('/-?[0-9]+(\.[0-9]+)?/', (string)$source, $matches); - $result = @ (float)$matches[0]; - break; - case 'BOOL' : - case 'BOOLEAN' : - $result = (bool)$source; - break; - case 'WORD' : - $result = (string)preg_replace('/[^A-Z_]/i', '', $source); - break; - case 'ALNUM' : - $result = (string)preg_replace('/[^A-Z0-9]/i', '', $source); - break; - case 'CMD' : - $result = (string)preg_replace('/[^A-Z0-9_\.-]/i', '', $source); - $result = ltrim($result, '.'); - break; - case 'BASE64' : - $result = (string)preg_replace('/[^A-Z0-9\/+=]/i', '', $source); - break; - case 'STRING' : - // Check for static usage and assign $filter the proper variable - if (isset($this) && is_a($this, 'TDMCreateFilterInput')) { - $filter =& $this; - } else { - $filter = TDMCreateFilterInput::getInstance(); - } - $result = (string)$filter->_remove($filter->_decode((string)$source)); - break; - case 'ARRAY' : - $result = (array)$source; - break; - case 'PATH' : - $pattern = '/^[A-Za-z0-9_-]+[A-Za-z0-9_\.-]*([\\\\\/][A-Za-z0-9_-]+[A-Za-z0-9_\.-]*)*$/'; - preg_match($pattern, (string)$source, $matches); - $result = @ (string)$matches[0]; - break; - case 'USERNAME' : - $result = (string)preg_replace('/[\x00-\x1F\x7F<>"\'%&]/', '', $source); - break; - default : - // Check for static usage and assign $filter the proper variable - if (is_object($this) && get_class($this) == 'TDMCreateFilterInput') { - $filter =& $this; - } else { - $filter = TDMCreateFilterInput::getInstance(); - } - // Are we dealing with an array? - if (is_array($source)) { - foreach ($source as $key => $value) { - // filter element for XSS and other 'bad' code etc. - if (is_string($value)) { - $source[$key] = $filter->_remove($filter->_decode($value)); - } - } - $result = $source; - } else { - // Or a string? - if (is_string($source) && !empty ($source)) { - // filter source for XSS and other 'bad' code etc. - $result = $filter->_remove($filter->_decode($source)); - } else { - // Not an array or string.. return the passed parameter - $result = $source; - } - } - break; - } - return $result; - } - - /** - * Function to determine if contents of an attribute is safe - * - * @static - * - * @param array $attrSubSet A 2 element array for attributes name,value - * - * @return boolean True if bad code is detected - */ - public function checkAttribute($attrSubSet) - { - $attrSubSet[0] = strtolower($attrSubSet[0]); - $attrSubSet[1] = strtolower($attrSubSet[1]); - return (((strpos($attrSubSet[1], 'expression') !== false) && ($attrSubSet[0]) == 'style') || (strpos($attrSubSet[1], 'javascript:') !== false) || (strpos($attrSubSet[1], 'behaviour:') !== false) || (strpos($attrSubSet[1], 'vbscript:') !== false) || (strpos($attrSubSet[1], 'mocha:') !== false) || (strpos($attrSubSet[1], 'livescript:') !== false)); - } - - /** - * Internal method to iteratively remove all unwanted tags and attributes - * - * @access protected - * - * @param string $source Input string to be 'cleaned' - * - * @return string 'Cleaned' version of input parameter - */ - protected function _remove($source) - { - $loopCounter = 0; - // Iteration provides nested tag protection - while ($source != $this->_cleanTags($source)) { - $source = $this->_cleanTags($source); - $loopCounter++; - } - retur... [truncated message content] |