@@ -17,60 +17,60 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | trait ServerStats |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * serverStats() |
|
| 22 | - * |
|
| 23 | - * @return string |
|
| 24 | - */ |
|
| 25 | - public static function getServerStats() |
|
| 26 | - { |
|
| 27 | - //mb $wfdownloads = WfdownloadsWfdownloads::getInstance(); |
|
| 28 | - $moduleDirName = basename(dirname(dirname(__DIR__))); |
|
| 29 | - $moduleDirNameUpper = strtoupper($moduleDirName); |
|
| 30 | - xoops_loadLanguage('common', $moduleDirName); |
|
| 31 | - $html = ''; |
|
| 32 | - // $sql = 'SELECT metavalue'; |
|
| 33 | - // $sql .= ' FROM ' . $GLOBALS['xoopsDB']->prefix('wfdownloads_meta'); |
|
| 34 | - // $sql .= " WHERE metakey='version' LIMIT 1"; |
|
| 35 | - // $query = $GLOBALS['xoopsDB']->query($sql); |
|
| 36 | - // list($meta) = $GLOBALS['xoopsDB']->fetchRow($query); |
|
| 37 | - $html .= "<fieldset><legend style='font-weight: bold; color: #900;'>" . constant('CO_' . $moduleDirNameUpper . '_IMAGEINFO') . "</legend>\n"; |
|
| 38 | - $html .= "<div style='padding: 8px;'>\n"; |
|
| 39 | - // $html .= '<div>' . constant('CO_' . $moduleDirNameUpper . '_METAVERSION') . $meta . "</div>\n"; |
|
| 40 | - // $html .= "<br>\n"; |
|
| 41 | - // $html .= "<br>\n"; |
|
| 42 | - $html .= '<div>' . constant('CO_' . $moduleDirNameUpper . '_SPHPINI') . "</div>\n"; |
|
| 43 | - $html .= "<ul>\n"; |
|
| 44 | - // |
|
| 45 | - $gdlib = function_exists('gd_info') ? '<span style="color: green;">' . constant('CO_' . $moduleDirNameUpper . '_GDON') . '</span>' : '<span style="color: red;">' . constant('CO_' . $moduleDirNameUpper . '_GDOFF') . '</span>'; |
|
| 46 | - $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_GDLIBSTATUS') . $gdlib; |
|
| 47 | - if (function_exists('gd_info')) { |
|
| 48 | - if (true === ($gdlib = gd_info())) { |
|
| 49 | - $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_GDLIBVERSION') . '<b>' . $gdlib['GD Version'] . '</b>'; |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - // |
|
| 53 | - // $safemode = ini_get('safe_mode') ? constant('CO_' . $moduleDirNameUpper . '_ON') . constant('CO_' . $moduleDirNameUpper . '_SAFEMODEPROBLEMS : constant('CO_' . $moduleDirNameUpper . '_OFF'); |
|
| 54 | - // $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SAFEMODESTATUS . $safemode; |
|
| 55 | - // |
|
| 56 | - // $registerglobals = (!ini_get('register_globals')) ? "<span style=\"color: green;\">" . constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>' : "<span style=\"color: red;\">" . constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>'; |
|
| 57 | - // $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_REGISTERGLOBALS . $registerglobals; |
|
| 58 | - // |
|
| 59 | - $downloads = ini_get('file_uploads') ? '<span style="color: green;">' . constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>' : '<span style="color: red;">' . constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>'; |
|
| 60 | - $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SERVERUPLOADSTATUS') . $downloads; |
|
| 61 | - // |
|
| 62 | - $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_MAXUPLOADSIZE') . ' <b><span style="color: blue;">' . ini_get('upload_max_filesize') . "</span></b>\n"; |
|
| 63 | - $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_MAXPOSTSIZE') . ' <b><span style="color: blue;">' . ini_get('post_max_size') . "</span></b>\n"; |
|
| 64 | - $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_MEMORYLIMIT') . ' <b><span style="color: blue;">' . ini_get('memory_limit') . "</span></b>\n"; |
|
| 65 | - $html .= "</ul>\n"; |
|
| 66 | - $html .= "<ul>\n"; |
|
| 67 | - $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SERVERPATH') . ' <b>' . XOOPS_ROOT_PATH . "</b>\n"; |
|
| 68 | - $html .= "</ul>\n"; |
|
| 69 | - $html .= "<br>\n"; |
|
| 70 | - $html .= constant('CO_' . $moduleDirNameUpper . '_UPLOADPATHDSC') . "\n"; |
|
| 71 | - $html .= '</div>'; |
|
| 72 | - $html .= '</fieldset><br>'; |
|
| 20 | + /** |
|
| 21 | + * serverStats() |
|
| 22 | + * |
|
| 23 | + * @return string |
|
| 24 | + */ |
|
| 25 | + public static function getServerStats() |
|
| 26 | + { |
|
| 27 | + //mb $wfdownloads = WfdownloadsWfdownloads::getInstance(); |
|
| 28 | + $moduleDirName = basename(dirname(dirname(__DIR__))); |
|
| 29 | + $moduleDirNameUpper = strtoupper($moduleDirName); |
|
| 30 | + xoops_loadLanguage('common', $moduleDirName); |
|
| 31 | + $html = ''; |
|
| 32 | + // $sql = 'SELECT metavalue'; |
|
| 33 | + // $sql .= ' FROM ' . $GLOBALS['xoopsDB']->prefix('wfdownloads_meta'); |
|
| 34 | + // $sql .= " WHERE metakey='version' LIMIT 1"; |
|
| 35 | + // $query = $GLOBALS['xoopsDB']->query($sql); |
|
| 36 | + // list($meta) = $GLOBALS['xoopsDB']->fetchRow($query); |
|
| 37 | + $html .= "<fieldset><legend style='font-weight: bold; color: #900;'>" . constant('CO_' . $moduleDirNameUpper . '_IMAGEINFO') . "</legend>\n"; |
|
| 38 | + $html .= "<div style='padding: 8px;'>\n"; |
|
| 39 | + // $html .= '<div>' . constant('CO_' . $moduleDirNameUpper . '_METAVERSION') . $meta . "</div>\n"; |
|
| 40 | + // $html .= "<br>\n"; |
|
| 41 | + // $html .= "<br>\n"; |
|
| 42 | + $html .= '<div>' . constant('CO_' . $moduleDirNameUpper . '_SPHPINI') . "</div>\n"; |
|
| 43 | + $html .= "<ul>\n"; |
|
| 44 | + // |
|
| 45 | + $gdlib = function_exists('gd_info') ? '<span style="color: green;">' . constant('CO_' . $moduleDirNameUpper . '_GDON') . '</span>' : '<span style="color: red;">' . constant('CO_' . $moduleDirNameUpper . '_GDOFF') . '</span>'; |
|
| 46 | + $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_GDLIBSTATUS') . $gdlib; |
|
| 47 | + if (function_exists('gd_info')) { |
|
| 48 | + if (true === ($gdlib = gd_info())) { |
|
| 49 | + $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_GDLIBVERSION') . '<b>' . $gdlib['GD Version'] . '</b>'; |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + // |
|
| 53 | + // $safemode = ini_get('safe_mode') ? constant('CO_' . $moduleDirNameUpper . '_ON') . constant('CO_' . $moduleDirNameUpper . '_SAFEMODEPROBLEMS : constant('CO_' . $moduleDirNameUpper . '_OFF'); |
|
| 54 | + // $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SAFEMODESTATUS . $safemode; |
|
| 55 | + // |
|
| 56 | + // $registerglobals = (!ini_get('register_globals')) ? "<span style=\"color: green;\">" . constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>' : "<span style=\"color: red;\">" . constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>'; |
|
| 57 | + // $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_REGISTERGLOBALS . $registerglobals; |
|
| 58 | + // |
|
| 59 | + $downloads = ini_get('file_uploads') ? '<span style="color: green;">' . constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>' : '<span style="color: red;">' . constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>'; |
|
| 60 | + $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SERVERUPLOADSTATUS') . $downloads; |
|
| 61 | + // |
|
| 62 | + $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_MAXUPLOADSIZE') . ' <b><span style="color: blue;">' . ini_get('upload_max_filesize') . "</span></b>\n"; |
|
| 63 | + $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_MAXPOSTSIZE') . ' <b><span style="color: blue;">' . ini_get('post_max_size') . "</span></b>\n"; |
|
| 64 | + $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_MEMORYLIMIT') . ' <b><span style="color: blue;">' . ini_get('memory_limit') . "</span></b>\n"; |
|
| 65 | + $html .= "</ul>\n"; |
|
| 66 | + $html .= "<ul>\n"; |
|
| 67 | + $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SERVERPATH') . ' <b>' . XOOPS_ROOT_PATH . "</b>\n"; |
|
| 68 | + $html .= "</ul>\n"; |
|
| 69 | + $html .= "<br>\n"; |
|
| 70 | + $html .= constant('CO_' . $moduleDirNameUpper . '_UPLOADPATHDSC') . "\n"; |
|
| 71 | + $html .= '</div>'; |
|
| 72 | + $html .= '</fieldset><br>'; |
|
| 73 | 73 | |
| 74 | - return $html; |
|
| 75 | - } |
|
| 74 | + return $html; |
|
| 75 | + } |
|
| 76 | 76 | } |
@@ -17,60 +17,60 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | trait VersionChecks |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * |
|
| 22 | - * Verifies XOOPS version meets minimum requirements for this module |
|
| 23 | - * @static |
|
| 24 | - * @param \XoopsModule $module |
|
| 25 | - * |
|
| 26 | - * @param null|string $requiredVer |
|
| 27 | - * @return bool true if meets requirements, false if not |
|
| 28 | - */ |
|
| 29 | - public static function checkVerXoops(\XoopsModule $module = null, $requiredVer = null) |
|
| 30 | - { |
|
| 31 | - $moduleDirName = basename(dirname(dirname(__DIR__))); |
|
| 32 | - if (null === $module) { |
|
| 33 | - $module = \XoopsModule::getByDirname($moduleDirName); |
|
| 34 | - } |
|
| 35 | - xoops_loadLanguage('admin', $moduleDirName); |
|
| 20 | + /** |
|
| 21 | + * |
|
| 22 | + * Verifies XOOPS version meets minimum requirements for this module |
|
| 23 | + * @static |
|
| 24 | + * @param \XoopsModule $module |
|
| 25 | + * |
|
| 26 | + * @param null|string $requiredVer |
|
| 27 | + * @return bool true if meets requirements, false if not |
|
| 28 | + */ |
|
| 29 | + public static function checkVerXoops(\XoopsModule $module = null, $requiredVer = null) |
|
| 30 | + { |
|
| 31 | + $moduleDirName = basename(dirname(dirname(__DIR__))); |
|
| 32 | + if (null === $module) { |
|
| 33 | + $module = \XoopsModule::getByDirname($moduleDirName); |
|
| 34 | + } |
|
| 35 | + xoops_loadLanguage('admin', $moduleDirName); |
|
| 36 | 36 | |
| 37 | - //check for minimum XOOPS version |
|
| 38 | - $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string |
|
| 39 | - if (null === $requiredVer) { |
|
| 40 | - $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string |
|
| 41 | - } |
|
| 42 | - $success = true; |
|
| 37 | + //check for minimum XOOPS version |
|
| 38 | + $currentVer = substr(XOOPS_VERSION, 6); // get the numeric part of string |
|
| 39 | + if (null === $requiredVer) { |
|
| 40 | + $requiredVer = '' . $module->getInfo('min_xoops'); //making sure it's a string |
|
| 41 | + } |
|
| 42 | + $success = true; |
|
| 43 | 43 | |
| 44 | - if (version_compare($currentVer, $requiredVer, '<')) { |
|
| 45 | - $success = false; |
|
| 46 | - $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_XOOPS'), $requiredVer, $currentVer)); |
|
| 47 | - } |
|
| 44 | + if (version_compare($currentVer, $requiredVer, '<')) { |
|
| 45 | + $success = false; |
|
| 46 | + $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_XOOPS'), $requiredVer, $currentVer)); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - return $success; |
|
| 50 | - } |
|
| 49 | + return $success; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * |
|
| 54 | - * Verifies PHP version meets minimum requirements for this module |
|
| 55 | - * @static |
|
| 56 | - * @param \XoopsModule $module |
|
| 57 | - * |
|
| 58 | - * @return bool true if meets requirements, false if not |
|
| 59 | - */ |
|
| 60 | - public static function checkVerPhp(\XoopsModule $module) |
|
| 61 | - { |
|
| 62 | - xoops_loadLanguage('admin', $module->dirname()); |
|
| 63 | - // check for minimum PHP version |
|
| 64 | - $success = true; |
|
| 65 | - $verNum = PHP_VERSION; |
|
| 66 | - $reqVer =& $module->getInfo('min_php'); |
|
| 67 | - if (false !== $reqVer && '' !== $reqVer) { |
|
| 68 | - if (version_compare($verNum, $reqVer, '<')) { |
|
| 69 | - $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), $reqVer, $verNum)); |
|
| 70 | - $success = false; |
|
| 71 | - } |
|
| 72 | - } |
|
| 52 | + /** |
|
| 53 | + * |
|
| 54 | + * Verifies PHP version meets minimum requirements for this module |
|
| 55 | + * @static |
|
| 56 | + * @param \XoopsModule $module |
|
| 57 | + * |
|
| 58 | + * @return bool true if meets requirements, false if not |
|
| 59 | + */ |
|
| 60 | + public static function checkVerPhp(\XoopsModule $module) |
|
| 61 | + { |
|
| 62 | + xoops_loadLanguage('admin', $module->dirname()); |
|
| 63 | + // check for minimum PHP version |
|
| 64 | + $success = true; |
|
| 65 | + $verNum = PHP_VERSION; |
|
| 66 | + $reqVer =& $module->getInfo('min_php'); |
|
| 67 | + if (false !== $reqVer && '' !== $reqVer) { |
|
| 68 | + if (version_compare($verNum, $reqVer, '<')) { |
|
| 69 | + $module->setErrors(sprintf(constant('CO_' . $moduleDirNameUpper . '_ERROR_BAD_PHP'), $reqVer, $verNum)); |
|
| 70 | + $success = false; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - return $success; |
|
| 75 | - } |
|
| 74 | + return $success; |
|
| 75 | + } |
|
| 76 | 76 | } |
@@ -31,48 +31,48 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class Breadcrumb |
| 33 | 33 | { |
| 34 | - public $dirname; |
|
| 35 | - private $bread = []; |
|
| 34 | + public $dirname; |
|
| 35 | + private $bread = []; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * |
|
| 39 | - */ |
|
| 40 | - public function __construct() |
|
| 41 | - { |
|
| 42 | - $this->dirname = basename(dirname(__DIR__)); |
|
| 43 | - } |
|
| 37 | + /** |
|
| 38 | + * |
|
| 39 | + */ |
|
| 40 | + public function __construct() |
|
| 41 | + { |
|
| 42 | + $this->dirname = basename(dirname(__DIR__)); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Add link to breadcrumb |
|
| 47 | - * |
|
| 48 | - * @param string $title |
|
| 49 | - * @param string $link |
|
| 50 | - */ |
|
| 51 | - public function addLink($title = '', $link = '') |
|
| 52 | - { |
|
| 53 | - $this->bread[] = [ |
|
| 54 | - 'link' => $link, |
|
| 55 | - 'title' => $title |
|
| 56 | - ]; |
|
| 57 | - } |
|
| 45 | + /** |
|
| 46 | + * Add link to breadcrumb |
|
| 47 | + * |
|
| 48 | + * @param string $title |
|
| 49 | + * @param string $link |
|
| 50 | + */ |
|
| 51 | + public function addLink($title = '', $link = '') |
|
| 52 | + { |
|
| 53 | + $this->bread[] = [ |
|
| 54 | + 'link' => $link, |
|
| 55 | + 'title' => $title |
|
| 56 | + ]; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Render Pedigree BreadCrumb |
|
| 61 | - * |
|
| 62 | - */ |
|
| 63 | - public function render() |
|
| 64 | - { |
|
| 65 | - if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) { |
|
| 66 | - require_once $GLOBALS['xoops']->path('class/theme.php'); |
|
| 67 | - $GLOBALS['xoTheme'] = new \xos_opal_Theme(); |
|
| 68 | - } |
|
| 59 | + /** |
|
| 60 | + * Render Pedigree BreadCrumb |
|
| 61 | + * |
|
| 62 | + */ |
|
| 63 | + public function render() |
|
| 64 | + { |
|
| 65 | + if (!isset($GLOBALS['xoTheme']) || !is_object($GLOBALS['xoTheme'])) { |
|
| 66 | + require_once $GLOBALS['xoops']->path('class/theme.php'); |
|
| 67 | + $GLOBALS['xoTheme'] = new \xos_opal_Theme(); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - require_once $GLOBALS['xoops']->path('class/template.php'); |
|
| 71 | - $breadcrumbTpl = new \XoopsTpl(); |
|
| 72 | - $breadcrumbTpl->assign('breadcrumb', $this->bread); |
|
| 73 | - $html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl'); |
|
| 74 | - unset($breadcrumbTpl); |
|
| 70 | + require_once $GLOBALS['xoops']->path('class/template.php'); |
|
| 71 | + $breadcrumbTpl = new \XoopsTpl(); |
|
| 72 | + $breadcrumbTpl->assign('breadcrumb', $this->bread); |
|
| 73 | + $html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl'); |
|
| 74 | + unset($breadcrumbTpl); |
|
| 75 | 75 | |
| 76 | - return $html; |
|
| 77 | - } |
|
| 76 | + return $html; |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -17,229 +17,229 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | trait FilesManagement |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Function responsible for checking if a directory exists, we can also write in and create an index.html file |
|
| 22 | - * |
|
| 23 | - * @param string $folder The full path of the directory to check |
|
| 24 | - * |
|
| 25 | - * @return void |
|
| 26 | - * @throws \RuntimeException |
|
| 27 | - */ |
|
| 28 | - public static function createFolder($folder) |
|
| 29 | - { |
|
| 30 | - try { |
|
| 31 | - if (!file_exists($folder)) { |
|
| 32 | - if (!is_dir($folder) && !mkdir($folder) && !is_dir($folder)) { |
|
| 33 | - throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
| 37 | - } |
|
| 38 | - } catch (\Exception $e) { |
|
| 39 | - echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
|
| 40 | - } |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @param $file |
|
| 45 | - * @param $folder |
|
| 46 | - * @return bool |
|
| 47 | - */ |
|
| 48 | - public static function copyFile($file, $folder) |
|
| 49 | - { |
|
| 50 | - return copy($file, $folder); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @param $src |
|
| 55 | - * @param $dst |
|
| 56 | - */ |
|
| 57 | - public static function recurseCopy($src, $dst) |
|
| 58 | - { |
|
| 59 | - $dir = opendir($src); |
|
| 60 | - // @mkdir($dst); |
|
| 61 | - if (!mkdir($dst) && !is_dir($dst)) { |
|
| 62 | - while (false !== ($file = readdir($dir))) { |
|
| 63 | - if (('.' !== $file) && ('..' !== $file)) { |
|
| 64 | - if (is_dir($src . '/' . $file)) { |
|
| 65 | - self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
|
| 66 | - } else { |
|
| 67 | - copy($src . '/' . $file, $dst . '/' . $file); |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - closedir($dir); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * |
|
| 77 | - * Remove files and (sub)directories |
|
| 78 | - * |
|
| 79 | - * @param string $src source directory to delete |
|
| 80 | - * |
|
| 81 | - * @uses \Xmf\Module\Helper::getHelper() |
|
| 82 | - * @uses \Xmf\Module\Helper::isUserAdmin() |
|
| 83 | - * |
|
| 84 | - * @return bool true on success |
|
| 85 | - */ |
|
| 86 | - public static function deleteDirectory($src) |
|
| 87 | - { |
|
| 88 | - // Only continue if user is a 'global' Admin |
|
| 89 | - if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
| 90 | - return false; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $success = true; |
|
| 94 | - // remove old files |
|
| 95 | - $dirInfo = new \SplFileInfo($src); |
|
| 96 | - // validate is a directory |
|
| 97 | - if ($dirInfo->isDir()) { |
|
| 98 | - $fileList = array_diff(scandir($src, SCANDIR_SORT_NONE), ['..', '.']); |
|
| 99 | - foreach ($fileList as $k => $v) { |
|
| 100 | - $fileInfo = new \SplFileInfo("{$src}/{$v}"); |
|
| 101 | - if ($fileInfo->isDir()) { |
|
| 102 | - // recursively handle subdirectories |
|
| 103 | - if (!$success = self::deleteDirectory($fileInfo->getRealPath())) { |
|
| 104 | - break; |
|
| 105 | - } |
|
| 106 | - } else { |
|
| 107 | - // delete the file |
|
| 108 | - if (!($success = unlink($fileInfo->getRealPath()))) { |
|
| 109 | - break; |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - // now delete this (sub)directory if all the files are gone |
|
| 114 | - if ($success) { |
|
| 115 | - $success = rmdir($dirInfo->getRealPath()); |
|
| 116 | - } |
|
| 117 | - } else { |
|
| 118 | - // input is not a valid directory |
|
| 119 | - $success = false; |
|
| 120 | - } |
|
| 121 | - return $success; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * |
|
| 126 | - * Recursively remove directory |
|
| 127 | - * |
|
| 128 | - * @todo currently won't remove directories with hidden files, should it? |
|
| 129 | - * |
|
| 130 | - * @param string $src directory to remove (delete) |
|
| 131 | - * |
|
| 132 | - * @return bool true on success |
|
| 133 | - */ |
|
| 134 | - public static function rrmdir($src) |
|
| 135 | - { |
|
| 136 | - // Only continue if user is a 'global' Admin |
|
| 137 | - if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
| 138 | - return false; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - // If source is not a directory stop processing |
|
| 142 | - if (!is_dir($src)) { |
|
| 143 | - return false; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - $success = true; |
|
| 147 | - |
|
| 148 | - // Open the source directory to read in files |
|
| 149 | - $iterator = new \DirectoryIterator($src); |
|
| 150 | - foreach ($iterator as $fObj) { |
|
| 151 | - if ($fObj->isFile()) { |
|
| 152 | - $filename = $fObj->getPathname(); |
|
| 153 | - $fObj = null; // clear this iterator object to close the file |
|
| 154 | - if (!unlink($filename)) { |
|
| 155 | - return false; // couldn't delete the file |
|
| 156 | - } |
|
| 157 | - } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
| 158 | - // Try recursively on directory |
|
| 159 | - self::rrmdir($fObj->getPathname()); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - $iterator = null; // clear iterator Obj to close file/directory |
|
| 163 | - return rmdir($src); // remove the directory & return results |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * Recursively move files from one directory to another |
|
| 168 | - * |
|
| 169 | - * @param string $src - Source of files being moved |
|
| 170 | - * @param string $dest - Destination of files being moved |
|
| 171 | - * |
|
| 172 | - * @return bool true on success |
|
| 173 | - */ |
|
| 174 | - public static function rmove($src, $dest) |
|
| 175 | - { |
|
| 176 | - // Only continue if user is a 'global' Admin |
|
| 177 | - if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
| 178 | - return false; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // If source is not a directory stop processing |
|
| 182 | - if (!is_dir($src)) { |
|
| 183 | - return false; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - // If the destination directory does not exist and could not be created stop processing |
|
| 187 | - if (!is_dir($dest) && !mkdir($dest) && !is_dir($dest)) { |
|
| 188 | - return false; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // Open the source directory to read in files |
|
| 192 | - $iterator = new \DirectoryIterator($src); |
|
| 193 | - foreach ($iterator as $fObj) { |
|
| 194 | - if ($fObj->isFile()) { |
|
| 195 | - rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
| 196 | - } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
| 197 | - // Try recursively on directory |
|
| 198 | - self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
| 199 | - // rmdir($fObj->getPath()); // now delete the directory |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - $iterator = null; // clear iterator Obj to close file/directory |
|
| 203 | - return rmdir($src); // remove the directory & return results |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Recursively copy directories and files from one directory to another |
|
| 208 | - * |
|
| 209 | - * @param string $src - Source of files being moved |
|
| 210 | - * @param string $dest - Destination of files being moved |
|
| 211 | - * |
|
| 212 | - * @uses \Xmf\Module\Helper::getHelper() |
|
| 213 | - * @uses \Xmf\Module\Helper::isUserAdmin() |
|
| 214 | - * |
|
| 215 | - * @return bool true on success |
|
| 216 | - */ |
|
| 217 | - public static function rcopy($src, $dest) |
|
| 218 | - { |
|
| 219 | - // Only continue if user is a 'global' Admin |
|
| 220 | - if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
| 221 | - return false; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - // If source is not a directory stop processing |
|
| 225 | - if (!is_dir($src)) { |
|
| 226 | - return false; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // If the destination directory does not exist and could not be created stop processing |
|
| 230 | - if (!is_dir($dest) && !mkdir($dest) && !is_dir($dest)) { |
|
| 231 | - return false; |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - // Open the source directory to read in files |
|
| 235 | - $iterator = new \DirectoryIterator($src); |
|
| 236 | - foreach ($iterator as $fObj) { |
|
| 237 | - if ($fObj->isFile()) { |
|
| 238 | - copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
| 239 | - } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
| 240 | - self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - return true; |
|
| 244 | - } |
|
| 20 | + /** |
|
| 21 | + * Function responsible for checking if a directory exists, we can also write in and create an index.html file |
|
| 22 | + * |
|
| 23 | + * @param string $folder The full path of the directory to check |
|
| 24 | + * |
|
| 25 | + * @return void |
|
| 26 | + * @throws \RuntimeException |
|
| 27 | + */ |
|
| 28 | + public static function createFolder($folder) |
|
| 29 | + { |
|
| 30 | + try { |
|
| 31 | + if (!file_exists($folder)) { |
|
| 32 | + if (!is_dir($folder) && !mkdir($folder) && !is_dir($folder)) { |
|
| 33 | + throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
| 37 | + } |
|
| 38 | + } catch (\Exception $e) { |
|
| 39 | + echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @param $file |
|
| 45 | + * @param $folder |
|
| 46 | + * @return bool |
|
| 47 | + */ |
|
| 48 | + public static function copyFile($file, $folder) |
|
| 49 | + { |
|
| 50 | + return copy($file, $folder); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @param $src |
|
| 55 | + * @param $dst |
|
| 56 | + */ |
|
| 57 | + public static function recurseCopy($src, $dst) |
|
| 58 | + { |
|
| 59 | + $dir = opendir($src); |
|
| 60 | + // @mkdir($dst); |
|
| 61 | + if (!mkdir($dst) && !is_dir($dst)) { |
|
| 62 | + while (false !== ($file = readdir($dir))) { |
|
| 63 | + if (('.' !== $file) && ('..' !== $file)) { |
|
| 64 | + if (is_dir($src . '/' . $file)) { |
|
| 65 | + self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
|
| 66 | + } else { |
|
| 67 | + copy($src . '/' . $file, $dst . '/' . $file); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + closedir($dir); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * |
|
| 77 | + * Remove files and (sub)directories |
|
| 78 | + * |
|
| 79 | + * @param string $src source directory to delete |
|
| 80 | + * |
|
| 81 | + * @uses \Xmf\Module\Helper::getHelper() |
|
| 82 | + * @uses \Xmf\Module\Helper::isUserAdmin() |
|
| 83 | + * |
|
| 84 | + * @return bool true on success |
|
| 85 | + */ |
|
| 86 | + public static function deleteDirectory($src) |
|
| 87 | + { |
|
| 88 | + // Only continue if user is a 'global' Admin |
|
| 89 | + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
| 90 | + return false; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $success = true; |
|
| 94 | + // remove old files |
|
| 95 | + $dirInfo = new \SplFileInfo($src); |
|
| 96 | + // validate is a directory |
|
| 97 | + if ($dirInfo->isDir()) { |
|
| 98 | + $fileList = array_diff(scandir($src, SCANDIR_SORT_NONE), ['..', '.']); |
|
| 99 | + foreach ($fileList as $k => $v) { |
|
| 100 | + $fileInfo = new \SplFileInfo("{$src}/{$v}"); |
|
| 101 | + if ($fileInfo->isDir()) { |
|
| 102 | + // recursively handle subdirectories |
|
| 103 | + if (!$success = self::deleteDirectory($fileInfo->getRealPath())) { |
|
| 104 | + break; |
|
| 105 | + } |
|
| 106 | + } else { |
|
| 107 | + // delete the file |
|
| 108 | + if (!($success = unlink($fileInfo->getRealPath()))) { |
|
| 109 | + break; |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + // now delete this (sub)directory if all the files are gone |
|
| 114 | + if ($success) { |
|
| 115 | + $success = rmdir($dirInfo->getRealPath()); |
|
| 116 | + } |
|
| 117 | + } else { |
|
| 118 | + // input is not a valid directory |
|
| 119 | + $success = false; |
|
| 120 | + } |
|
| 121 | + return $success; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * |
|
| 126 | + * Recursively remove directory |
|
| 127 | + * |
|
| 128 | + * @todo currently won't remove directories with hidden files, should it? |
|
| 129 | + * |
|
| 130 | + * @param string $src directory to remove (delete) |
|
| 131 | + * |
|
| 132 | + * @return bool true on success |
|
| 133 | + */ |
|
| 134 | + public static function rrmdir($src) |
|
| 135 | + { |
|
| 136 | + // Only continue if user is a 'global' Admin |
|
| 137 | + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
| 138 | + return false; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + // If source is not a directory stop processing |
|
| 142 | + if (!is_dir($src)) { |
|
| 143 | + return false; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + $success = true; |
|
| 147 | + |
|
| 148 | + // Open the source directory to read in files |
|
| 149 | + $iterator = new \DirectoryIterator($src); |
|
| 150 | + foreach ($iterator as $fObj) { |
|
| 151 | + if ($fObj->isFile()) { |
|
| 152 | + $filename = $fObj->getPathname(); |
|
| 153 | + $fObj = null; // clear this iterator object to close the file |
|
| 154 | + if (!unlink($filename)) { |
|
| 155 | + return false; // couldn't delete the file |
|
| 156 | + } |
|
| 157 | + } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
| 158 | + // Try recursively on directory |
|
| 159 | + self::rrmdir($fObj->getPathname()); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + $iterator = null; // clear iterator Obj to close file/directory |
|
| 163 | + return rmdir($src); // remove the directory & return results |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * Recursively move files from one directory to another |
|
| 168 | + * |
|
| 169 | + * @param string $src - Source of files being moved |
|
| 170 | + * @param string $dest - Destination of files being moved |
|
| 171 | + * |
|
| 172 | + * @return bool true on success |
|
| 173 | + */ |
|
| 174 | + public static function rmove($src, $dest) |
|
| 175 | + { |
|
| 176 | + // Only continue if user is a 'global' Admin |
|
| 177 | + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
| 178 | + return false; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // If source is not a directory stop processing |
|
| 182 | + if (!is_dir($src)) { |
|
| 183 | + return false; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + // If the destination directory does not exist and could not be created stop processing |
|
| 187 | + if (!is_dir($dest) && !mkdir($dest) && !is_dir($dest)) { |
|
| 188 | + return false; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // Open the source directory to read in files |
|
| 192 | + $iterator = new \DirectoryIterator($src); |
|
| 193 | + foreach ($iterator as $fObj) { |
|
| 194 | + if ($fObj->isFile()) { |
|
| 195 | + rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
| 196 | + } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
| 197 | + // Try recursively on directory |
|
| 198 | + self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
| 199 | + // rmdir($fObj->getPath()); // now delete the directory |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + $iterator = null; // clear iterator Obj to close file/directory |
|
| 203 | + return rmdir($src); // remove the directory & return results |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Recursively copy directories and files from one directory to another |
|
| 208 | + * |
|
| 209 | + * @param string $src - Source of files being moved |
|
| 210 | + * @param string $dest - Destination of files being moved |
|
| 211 | + * |
|
| 212 | + * @uses \Xmf\Module\Helper::getHelper() |
|
| 213 | + * @uses \Xmf\Module\Helper::isUserAdmin() |
|
| 214 | + * |
|
| 215 | + * @return bool true on success |
|
| 216 | + */ |
|
| 217 | + public static function rcopy($src, $dest) |
|
| 218 | + { |
|
| 219 | + // Only continue if user is a 'global' Admin |
|
| 220 | + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
| 221 | + return false; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + // If source is not a directory stop processing |
|
| 225 | + if (!is_dir($src)) { |
|
| 226 | + return false; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // If the destination directory does not exist and could not be created stop processing |
|
| 230 | + if (!is_dir($dest) && !mkdir($dest) && !is_dir($dest)) { |
|
| 231 | + return false; |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + // Open the source directory to read in files |
|
| 235 | + $iterator = new \DirectoryIterator($src); |
|
| 236 | + foreach ($iterator as $fObj) { |
|
| 237 | + if ($fObj->isFile()) { |
|
| 238 | + copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
| 239 | + } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
| 240 | + self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + return true; |
|
| 244 | + } |
|
| 245 | 245 | } |
@@ -15,452 +15,452 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Prototype extends JavaScript |
| 17 | 17 | { |
| 18 | - public $CALLBACKS = [ |
|
| 19 | - 'uninitialized', |
|
| 20 | - 'loading', |
|
| 21 | - 'loaded', |
|
| 22 | - 'interactive', |
|
| 23 | - 'complete', |
|
| 24 | - 'failure', |
|
| 25 | - 'success' |
|
| 26 | - ]; |
|
| 27 | - |
|
| 28 | - public $AJAX_OPTIONS = [ |
|
| 29 | - 'before', |
|
| 30 | - 'after', |
|
| 31 | - 'condition', |
|
| 32 | - 'url', |
|
| 33 | - 'asynchronous', |
|
| 34 | - 'method', |
|
| 35 | - 'insertion', |
|
| 36 | - 'position', |
|
| 37 | - 'form', |
|
| 38 | - 'with', |
|
| 39 | - 'update', |
|
| 40 | - 'script', |
|
| 41 | - 'uninitialized', |
|
| 42 | - 'loading', |
|
| 43 | - 'loaded', |
|
| 44 | - 'interactive', |
|
| 45 | - 'complete', |
|
| 46 | - 'failure', |
|
| 47 | - 'success' |
|
| 48 | - ]; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @return string |
|
| 52 | - */ |
|
| 53 | - public function evaluate_remote_response() |
|
| 54 | - { |
|
| 55 | - return 'eval(request.responseText)'; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @param $options |
|
| 60 | - * @return string |
|
| 61 | - */ |
|
| 62 | - public function form_remote_tag($options) |
|
| 63 | - { |
|
| 64 | - $options['form'] = true; |
|
| 65 | - |
|
| 66 | - return '<form action="' . $options['url'] . '" onsubmit="' . $this->remote_function($options) . '; return false;" method="' . (isset($options['method']) ? $options['method'] : 'post') . '" >'; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @param $name |
|
| 71 | - * @param null $options |
|
| 72 | - * @param null $html_options |
|
| 73 | - * @return string |
|
| 74 | - */ |
|
| 75 | - public function link_to_remote($name, $options = null, $html_options = null) |
|
| 76 | - { |
|
| 77 | - return $this->link_to_function($name, $this->remote_function($options), $html_options); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @param $field_id |
|
| 82 | - * @param null $options |
|
| 83 | - * @return string |
|
| 84 | - */ |
|
| 85 | - public function observe_field($field_id, $options = null) |
|
| 86 | - { |
|
| 87 | - if (isset($options['frequency']) && $options['frequency'] > 0) { |
|
| 88 | - return $this->_build_observer('Form.Element.Observer', $field_id, $options); |
|
| 89 | - } else { |
|
| 90 | - return $this->_build_observer('Form.Element.EventObserver', $field_id, $options); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @param $form_id |
|
| 96 | - * @param null $options |
|
| 97 | - * @return string |
|
| 98 | - */ |
|
| 99 | - public function observe_form($form_id, $options = null) |
|
| 100 | - { |
|
| 101 | - if (isset($options['frequency'])) { |
|
| 102 | - return $this->_build_observer('Form.Observer', $form_id, $options); |
|
| 103 | - } else { |
|
| 104 | - return $this->_build_observer('Form.EventObserver', $form_id, $options); |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @param null $options |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - public function periodically_call_remote($options = null) |
|
| 113 | - { |
|
| 114 | - $frequency = isset($options['frequency']) ? $options['frequency'] : 10; |
|
| 115 | - $code = 'new PeriodicalExecuter(function() {' . $this->remote_function($options) . '},' . $frequency . ')'; |
|
| 116 | - |
|
| 117 | - return $code; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @param $options |
|
| 122 | - * @return string |
|
| 123 | - */ |
|
| 124 | - public function remote_function($options) |
|
| 125 | - { |
|
| 126 | - $javascript_options = $this->_options_for_ajax($options); |
|
| 127 | - |
|
| 128 | - $update = ''; |
|
| 129 | - |
|
| 130 | - if (isset($options['update']) && is_array($options['update'])) { |
|
| 131 | - $update = isset($options['update']['success']) ? 'success: ' . $options['update']['success'] : ''; |
|
| 132 | - $update .= empty($update) ? '' : ','; |
|
| 133 | - $update .= isset($options['update']['failure']) ? 'failure: ' . $options['update']['failure'] : ''; |
|
| 134 | - } else { |
|
| 135 | - $update .= isset($options['update']) ? $options['update'] : ''; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - $ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\'' . $update . '\','; |
|
| 139 | - |
|
| 140 | - $ajax_function .= "'" . $options['url'] . "'"; |
|
| 141 | - $ajax_function .= ',' . $javascript_options . ')'; |
|
| 142 | - |
|
| 143 | - $ajax_function = isset($options['before']) ? $options['before'] . ';' . $ajax_function : $ajax_function; |
|
| 144 | - $ajax_function = isset($options['after']) ? $ajax_function . ';' . $options['after'] : $ajax_function; |
|
| 145 | - $ajax_function = isset($options['condition']) ? 'if (' . $options['condition'] . ') {' . $ajax_function . '}' : $ajax_function; |
|
| 146 | - $ajax_function = isset($options['confirm']) ? 'if ( confirm(\'' . $options['confirm'] . '\' ) ) { ' . $ajax_function . ' } ' : $ajax_function; |
|
| 147 | - |
|
| 148 | - return $ajax_function; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @param $name |
|
| 153 | - * @param $value |
|
| 154 | - * @param $options |
|
| 155 | - * @return string |
|
| 156 | - */ |
|
| 157 | - public function submit_to_remote($name, $value, $options) |
|
| 158 | - { |
|
| 159 | - if (isset($options['with'])) { |
|
| 160 | - $options['with'] = 'Form.serialize(this.form)'; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - return '<input type="button" onclick="' . $this->remote_function($options) . '" name="' . $name . '" value ="' . $value . '">'; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @param $element_id |
|
| 168 | - * @param null $options |
|
| 169 | - * @param $block |
|
| 170 | - */ |
|
| 171 | - public function update_element_function($element_id, $options = null, $block) |
|
| 172 | - { |
|
| 173 | - $content = isset($options['content']) ? $options['content'] : ''; |
|
| 174 | - $content = $this->escape($content); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * @param $block |
|
| 179 | - */ |
|
| 180 | - public function update_page($block) |
|
| 181 | - { |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * @param $block |
|
| 186 | - * @return string |
|
| 187 | - */ |
|
| 188 | - public function update_page_tag(& $block) |
|
| 189 | - { |
|
| 190 | - return $this->tag($block); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
| 194 | - // Private functions |
|
| 195 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * @param $options |
|
| 199 | - * @return array |
|
| 200 | - */ |
|
| 201 | - public function _build_callbacks($options) |
|
| 202 | - { |
|
| 203 | - $callbacks = []; |
|
| 204 | - foreach ($options as $callback => $code) { |
|
| 205 | - if (in_array($callback, $this->CALLBACKS)) { |
|
| 206 | - $name = 'on' . ucfirst($callback); |
|
| 207 | - $callbacks[$name] = 'function(request){' . $code . '}'; |
|
| 208 | - } |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - return $callbacks; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * @param $klass |
|
| 216 | - * @param $name |
|
| 217 | - * @param null $options |
|
| 218 | - * @return string |
|
| 219 | - */ |
|
| 220 | - public function _build_observer($klass, $name, $options = null) |
|
| 221 | - { |
|
| 222 | - if (isset($options['with']) && false === strpos($options['with'], '=')) { |
|
| 223 | - $options['with'] = '\'' . $options['with'] . '=\' + value'; |
|
| 224 | - } elseif (isset($options['with']) && isset($options['update'])) { |
|
| 225 | - $options['with'] = 'value'; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - $callback = $options['function'] ?: $this->remote_function($options); |
|
| 229 | - |
|
| 230 | - $javascript = "new $klass('$name', "; |
|
| 231 | - $javascript .= isset($options['frequency']) ? $options['frequency'] . ', ' : ''; |
|
| 232 | - $javascript .= 'function (element,value) { '; |
|
| 233 | - $javascript .= $callback; |
|
| 234 | - $javascript .= isset($options['on']) ? ', ' . $options['on'] : ''; |
|
| 235 | - $javascript .= '})'; |
|
| 236 | - |
|
| 237 | - return $javascript; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * @param $method |
|
| 242 | - * @return string |
|
| 243 | - */ |
|
| 244 | - public function _method_option_to_s($method) |
|
| 245 | - { |
|
| 246 | - return false !== strpos($method, "'") ? $method : "'$method'"; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * @param $options |
|
| 251 | - * @return string |
|
| 252 | - */ |
|
| 253 | - public function _options_for_ajax($options) |
|
| 254 | - { |
|
| 255 | - $js_options = is_array($options) ? $this->_build_callbacks($options) : []; |
|
| 256 | - |
|
| 257 | - if (isset($options['type']) && 'synchronous' === $option['type']) { |
|
| 258 | - $js_options['asynchronous'] = 'false'; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - if (isset($options['method'])) { |
|
| 262 | - $js_options['method'] = $this->_method_option_to_s($options['method']); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - if (isset($options['position'])) { |
|
| 266 | - $js_options['insertion'] = 'Insertion.' . ucfirst($options['position']); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - $js_options['evalScripts'] = isset($options['script']) ? $options['script'] : 'true'; |
|
| 270 | - |
|
| 271 | - if (isset($options['form'])) { |
|
| 272 | - $js_options['parameters'] = 'Form.serialize(this)'; |
|
| 273 | - } elseif (isset($options['parameters'])) { |
|
| 274 | - $js_options['parameters'] = 'Form.serialize(\'' . $options['submit'] . '\')'; |
|
| 275 | - } elseif (isset($options['with'])) { |
|
| 276 | - $js_options['parameters'] = $options['with']; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - return $this->_options_for_javascript($js_options); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
| 283 | - // Mergerd Javascript Generator helpers |
|
| 284 | - ///////////////////////////////////////////////////////////////////////////////////// |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * @param $javascript |
|
| 288 | - */ |
|
| 289 | - public function dump($javascript) |
|
| 290 | - { |
|
| 291 | - echo $javascript; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * @param $id |
|
| 296 | - * @param null $extend |
|
| 297 | - * @return string |
|
| 298 | - */ |
|
| 299 | - public function ID($id, $extend = null) |
|
| 300 | - { |
|
| 301 | - return "$('$id')" . (!empty($extend)) ? '.' . $extend . '()' : ''; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * @param $message |
|
| 306 | - * @return string |
|
| 307 | - */ |
|
| 308 | - public function alert($message) |
|
| 309 | - { |
|
| 310 | - return $this->call('alert', $message); |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * @param $variable |
|
| 315 | - * @param $value |
|
| 316 | - * @return string |
|
| 317 | - */ |
|
| 318 | - public function assign($variable, $value) |
|
| 319 | - { |
|
| 320 | - return "$variable = $value;"; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * @param $function |
|
| 325 | - * @param null $args |
|
| 326 | - * @return string |
|
| 327 | - */ |
|
| 328 | - public function call($function, $args = null) |
|
| 329 | - { |
|
| 330 | - $arg_str = ''; |
|
| 331 | - if (is_array($args)) { |
|
| 332 | - foreach ($args as $arg) { |
|
| 333 | - if (!empty($arg_str)) { |
|
| 334 | - $arg_str .= ', '; |
|
| 335 | - } |
|
| 336 | - if (is_string($arg)) { |
|
| 337 | - $arg_str .= "'$arg'"; |
|
| 338 | - } else { |
|
| 339 | - $arg_str .= $arg; |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - } else { |
|
| 343 | - if (is_string($args)) { |
|
| 344 | - $arg_str .= "'$args'"; |
|
| 345 | - } else { |
|
| 346 | - $arg_str .= $args; |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - return "$function($arg_str)"; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * @param int $seconds |
|
| 355 | - * @param string $script |
|
| 356 | - * @return string |
|
| 357 | - */ |
|
| 358 | - public function delay($seconds = 1, $script = '') |
|
| 359 | - { |
|
| 360 | - return "setTimeout( function() { $script } , " . ($seconds * 1000) . ' )'; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * @param $id |
|
| 365 | - * @return string |
|
| 366 | - */ |
|
| 367 | - public function hide($id) |
|
| 368 | - { |
|
| 369 | - return $this->call('Element.hide', $id); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * @param $position |
|
| 374 | - * @param $id |
|
| 375 | - * @param null $options_for_render |
|
| 376 | - * @return string |
|
| 377 | - */ |
|
| 378 | - public function insert_html($position, $id, $options_for_render = null) |
|
| 379 | - { |
|
| 380 | - $args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render])); |
|
| 381 | - |
|
| 382 | - return $this->call('new Insertion.' . ucfirst($position), $args); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * @param $location |
|
| 387 | - * @return string |
|
| 388 | - */ |
|
| 389 | - public function redirect_to($location) |
|
| 390 | - { |
|
| 391 | - return $this->assign('window.location.href', $location); |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * @param $id |
|
| 396 | - * @return string |
|
| 397 | - */ |
|
| 398 | - public function remove($id) |
|
| 399 | - { |
|
| 400 | - if (is_array($id)) { |
|
| 401 | - $arr_str = ''; |
|
| 402 | - foreach ($id as $obj) { |
|
| 403 | - if (!empty($arg_str)) { |
|
| 404 | - $arg_str .= ', '; |
|
| 405 | - } |
|
| 406 | - $arg_str .= "'$arg'"; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - return "$A[$arg_str].each(Element.remove)"; |
|
| 410 | - } else { |
|
| 411 | - return "Element.remove('$id')"; |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * @param $id |
|
| 417 | - * @param $options_for_render |
|
| 418 | - * @return string |
|
| 419 | - */ |
|
| 420 | - public function replace($id, $options_for_render) |
|
| 421 | - { |
|
| 422 | - $args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render])); |
|
| 423 | - |
|
| 424 | - return $this->call('Element.replace', $args); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - /** |
|
| 428 | - * @param $id |
|
| 429 | - * @param $options_for_render |
|
| 430 | - * @return string |
|
| 431 | - */ |
|
| 432 | - public function replace_html($id, $options_for_render) |
|
| 433 | - { |
|
| 434 | - $args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render])); |
|
| 435 | - |
|
| 436 | - return $this->call('Element.update', $args); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * @param $pattern |
|
| 441 | - * @param null $extend |
|
| 442 | - * @return string |
|
| 443 | - */ |
|
| 444 | - public function select($pattern, $extend = null) |
|
| 445 | - { |
|
| 446 | - return "$$('$pattern')" . (!empty($extend)) ? '.' . $extend : ''; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * @param $id |
|
| 451 | - * @return string |
|
| 452 | - */ |
|
| 453 | - public function show($id) |
|
| 454 | - { |
|
| 455 | - return $this->call('Element.show', $id); |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * @param $id |
|
| 460 | - * @return string |
|
| 461 | - */ |
|
| 462 | - public function toggle($id) |
|
| 463 | - { |
|
| 464 | - return $this->call('Element.toggle', $id); |
|
| 465 | - } |
|
| 18 | + public $CALLBACKS = [ |
|
| 19 | + 'uninitialized', |
|
| 20 | + 'loading', |
|
| 21 | + 'loaded', |
|
| 22 | + 'interactive', |
|
| 23 | + 'complete', |
|
| 24 | + 'failure', |
|
| 25 | + 'success' |
|
| 26 | + ]; |
|
| 27 | + |
|
| 28 | + public $AJAX_OPTIONS = [ |
|
| 29 | + 'before', |
|
| 30 | + 'after', |
|
| 31 | + 'condition', |
|
| 32 | + 'url', |
|
| 33 | + 'asynchronous', |
|
| 34 | + 'method', |
|
| 35 | + 'insertion', |
|
| 36 | + 'position', |
|
| 37 | + 'form', |
|
| 38 | + 'with', |
|
| 39 | + 'update', |
|
| 40 | + 'script', |
|
| 41 | + 'uninitialized', |
|
| 42 | + 'loading', |
|
| 43 | + 'loaded', |
|
| 44 | + 'interactive', |
|
| 45 | + 'complete', |
|
| 46 | + 'failure', |
|
| 47 | + 'success' |
|
| 48 | + ]; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @return string |
|
| 52 | + */ |
|
| 53 | + public function evaluate_remote_response() |
|
| 54 | + { |
|
| 55 | + return 'eval(request.responseText)'; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @param $options |
|
| 60 | + * @return string |
|
| 61 | + */ |
|
| 62 | + public function form_remote_tag($options) |
|
| 63 | + { |
|
| 64 | + $options['form'] = true; |
|
| 65 | + |
|
| 66 | + return '<form action="' . $options['url'] . '" onsubmit="' . $this->remote_function($options) . '; return false;" method="' . (isset($options['method']) ? $options['method'] : 'post') . '" >'; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @param $name |
|
| 71 | + * @param null $options |
|
| 72 | + * @param null $html_options |
|
| 73 | + * @return string |
|
| 74 | + */ |
|
| 75 | + public function link_to_remote($name, $options = null, $html_options = null) |
|
| 76 | + { |
|
| 77 | + return $this->link_to_function($name, $this->remote_function($options), $html_options); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @param $field_id |
|
| 82 | + * @param null $options |
|
| 83 | + * @return string |
|
| 84 | + */ |
|
| 85 | + public function observe_field($field_id, $options = null) |
|
| 86 | + { |
|
| 87 | + if (isset($options['frequency']) && $options['frequency'] > 0) { |
|
| 88 | + return $this->_build_observer('Form.Element.Observer', $field_id, $options); |
|
| 89 | + } else { |
|
| 90 | + return $this->_build_observer('Form.Element.EventObserver', $field_id, $options); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @param $form_id |
|
| 96 | + * @param null $options |
|
| 97 | + * @return string |
|
| 98 | + */ |
|
| 99 | + public function observe_form($form_id, $options = null) |
|
| 100 | + { |
|
| 101 | + if (isset($options['frequency'])) { |
|
| 102 | + return $this->_build_observer('Form.Observer', $form_id, $options); |
|
| 103 | + } else { |
|
| 104 | + return $this->_build_observer('Form.EventObserver', $form_id, $options); |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @param null $options |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + public function periodically_call_remote($options = null) |
|
| 113 | + { |
|
| 114 | + $frequency = isset($options['frequency']) ? $options['frequency'] : 10; |
|
| 115 | + $code = 'new PeriodicalExecuter(function() {' . $this->remote_function($options) . '},' . $frequency . ')'; |
|
| 116 | + |
|
| 117 | + return $code; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @param $options |
|
| 122 | + * @return string |
|
| 123 | + */ |
|
| 124 | + public function remote_function($options) |
|
| 125 | + { |
|
| 126 | + $javascript_options = $this->_options_for_ajax($options); |
|
| 127 | + |
|
| 128 | + $update = ''; |
|
| 129 | + |
|
| 130 | + if (isset($options['update']) && is_array($options['update'])) { |
|
| 131 | + $update = isset($options['update']['success']) ? 'success: ' . $options['update']['success'] : ''; |
|
| 132 | + $update .= empty($update) ? '' : ','; |
|
| 133 | + $update .= isset($options['update']['failure']) ? 'failure: ' . $options['update']['failure'] : ''; |
|
| 134 | + } else { |
|
| 135 | + $update .= isset($options['update']) ? $options['update'] : ''; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + $ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\'' . $update . '\','; |
|
| 139 | + |
|
| 140 | + $ajax_function .= "'" . $options['url'] . "'"; |
|
| 141 | + $ajax_function .= ',' . $javascript_options . ')'; |
|
| 142 | + |
|
| 143 | + $ajax_function = isset($options['before']) ? $options['before'] . ';' . $ajax_function : $ajax_function; |
|
| 144 | + $ajax_function = isset($options['after']) ? $ajax_function . ';' . $options['after'] : $ajax_function; |
|
| 145 | + $ajax_function = isset($options['condition']) ? 'if (' . $options['condition'] . ') {' . $ajax_function . '}' : $ajax_function; |
|
| 146 | + $ajax_function = isset($options['confirm']) ? 'if ( confirm(\'' . $options['confirm'] . '\' ) ) { ' . $ajax_function . ' } ' : $ajax_function; |
|
| 147 | + |
|
| 148 | + return $ajax_function; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @param $name |
|
| 153 | + * @param $value |
|
| 154 | + * @param $options |
|
| 155 | + * @return string |
|
| 156 | + */ |
|
| 157 | + public function submit_to_remote($name, $value, $options) |
|
| 158 | + { |
|
| 159 | + if (isset($options['with'])) { |
|
| 160 | + $options['with'] = 'Form.serialize(this.form)'; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + return '<input type="button" onclick="' . $this->remote_function($options) . '" name="' . $name . '" value ="' . $value . '">'; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @param $element_id |
|
| 168 | + * @param null $options |
|
| 169 | + * @param $block |
|
| 170 | + */ |
|
| 171 | + public function update_element_function($element_id, $options = null, $block) |
|
| 172 | + { |
|
| 173 | + $content = isset($options['content']) ? $options['content'] : ''; |
|
| 174 | + $content = $this->escape($content); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * @param $block |
|
| 179 | + */ |
|
| 180 | + public function update_page($block) |
|
| 181 | + { |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * @param $block |
|
| 186 | + * @return string |
|
| 187 | + */ |
|
| 188 | + public function update_page_tag(& $block) |
|
| 189 | + { |
|
| 190 | + return $this->tag($block); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
| 194 | + // Private functions |
|
| 195 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * @param $options |
|
| 199 | + * @return array |
|
| 200 | + */ |
|
| 201 | + public function _build_callbacks($options) |
|
| 202 | + { |
|
| 203 | + $callbacks = []; |
|
| 204 | + foreach ($options as $callback => $code) { |
|
| 205 | + if (in_array($callback, $this->CALLBACKS)) { |
|
| 206 | + $name = 'on' . ucfirst($callback); |
|
| 207 | + $callbacks[$name] = 'function(request){' . $code . '}'; |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + return $callbacks; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * @param $klass |
|
| 216 | + * @param $name |
|
| 217 | + * @param null $options |
|
| 218 | + * @return string |
|
| 219 | + */ |
|
| 220 | + public function _build_observer($klass, $name, $options = null) |
|
| 221 | + { |
|
| 222 | + if (isset($options['with']) && false === strpos($options['with'], '=')) { |
|
| 223 | + $options['with'] = '\'' . $options['with'] . '=\' + value'; |
|
| 224 | + } elseif (isset($options['with']) && isset($options['update'])) { |
|
| 225 | + $options['with'] = 'value'; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + $callback = $options['function'] ?: $this->remote_function($options); |
|
| 229 | + |
|
| 230 | + $javascript = "new $klass('$name', "; |
|
| 231 | + $javascript .= isset($options['frequency']) ? $options['frequency'] . ', ' : ''; |
|
| 232 | + $javascript .= 'function (element,value) { '; |
|
| 233 | + $javascript .= $callback; |
|
| 234 | + $javascript .= isset($options['on']) ? ', ' . $options['on'] : ''; |
|
| 235 | + $javascript .= '})'; |
|
| 236 | + |
|
| 237 | + return $javascript; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * @param $method |
|
| 242 | + * @return string |
|
| 243 | + */ |
|
| 244 | + public function _method_option_to_s($method) |
|
| 245 | + { |
|
| 246 | + return false !== strpos($method, "'") ? $method : "'$method'"; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * @param $options |
|
| 251 | + * @return string |
|
| 252 | + */ |
|
| 253 | + public function _options_for_ajax($options) |
|
| 254 | + { |
|
| 255 | + $js_options = is_array($options) ? $this->_build_callbacks($options) : []; |
|
| 256 | + |
|
| 257 | + if (isset($options['type']) && 'synchronous' === $option['type']) { |
|
| 258 | + $js_options['asynchronous'] = 'false'; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + if (isset($options['method'])) { |
|
| 262 | + $js_options['method'] = $this->_method_option_to_s($options['method']); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + if (isset($options['position'])) { |
|
| 266 | + $js_options['insertion'] = 'Insertion.' . ucfirst($options['position']); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + $js_options['evalScripts'] = isset($options['script']) ? $options['script'] : 'true'; |
|
| 270 | + |
|
| 271 | + if (isset($options['form'])) { |
|
| 272 | + $js_options['parameters'] = 'Form.serialize(this)'; |
|
| 273 | + } elseif (isset($options['parameters'])) { |
|
| 274 | + $js_options['parameters'] = 'Form.serialize(\'' . $options['submit'] . '\')'; |
|
| 275 | + } elseif (isset($options['with'])) { |
|
| 276 | + $js_options['parameters'] = $options['with']; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + return $this->_options_for_javascript($js_options); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
| 283 | + // Mergerd Javascript Generator helpers |
|
| 284 | + ///////////////////////////////////////////////////////////////////////////////////// |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * @param $javascript |
|
| 288 | + */ |
|
| 289 | + public function dump($javascript) |
|
| 290 | + { |
|
| 291 | + echo $javascript; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * @param $id |
|
| 296 | + * @param null $extend |
|
| 297 | + * @return string |
|
| 298 | + */ |
|
| 299 | + public function ID($id, $extend = null) |
|
| 300 | + { |
|
| 301 | + return "$('$id')" . (!empty($extend)) ? '.' . $extend . '()' : ''; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * @param $message |
|
| 306 | + * @return string |
|
| 307 | + */ |
|
| 308 | + public function alert($message) |
|
| 309 | + { |
|
| 310 | + return $this->call('alert', $message); |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * @param $variable |
|
| 315 | + * @param $value |
|
| 316 | + * @return string |
|
| 317 | + */ |
|
| 318 | + public function assign($variable, $value) |
|
| 319 | + { |
|
| 320 | + return "$variable = $value;"; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * @param $function |
|
| 325 | + * @param null $args |
|
| 326 | + * @return string |
|
| 327 | + */ |
|
| 328 | + public function call($function, $args = null) |
|
| 329 | + { |
|
| 330 | + $arg_str = ''; |
|
| 331 | + if (is_array($args)) { |
|
| 332 | + foreach ($args as $arg) { |
|
| 333 | + if (!empty($arg_str)) { |
|
| 334 | + $arg_str .= ', '; |
|
| 335 | + } |
|
| 336 | + if (is_string($arg)) { |
|
| 337 | + $arg_str .= "'$arg'"; |
|
| 338 | + } else { |
|
| 339 | + $arg_str .= $arg; |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + } else { |
|
| 343 | + if (is_string($args)) { |
|
| 344 | + $arg_str .= "'$args'"; |
|
| 345 | + } else { |
|
| 346 | + $arg_str .= $args; |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + return "$function($arg_str)"; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * @param int $seconds |
|
| 355 | + * @param string $script |
|
| 356 | + * @return string |
|
| 357 | + */ |
|
| 358 | + public function delay($seconds = 1, $script = '') |
|
| 359 | + { |
|
| 360 | + return "setTimeout( function() { $script } , " . ($seconds * 1000) . ' )'; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * @param $id |
|
| 365 | + * @return string |
|
| 366 | + */ |
|
| 367 | + public function hide($id) |
|
| 368 | + { |
|
| 369 | + return $this->call('Element.hide', $id); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * @param $position |
|
| 374 | + * @param $id |
|
| 375 | + * @param null $options_for_render |
|
| 376 | + * @return string |
|
| 377 | + */ |
|
| 378 | + public function insert_html($position, $id, $options_for_render = null) |
|
| 379 | + { |
|
| 380 | + $args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render])); |
|
| 381 | + |
|
| 382 | + return $this->call('new Insertion.' . ucfirst($position), $args); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * @param $location |
|
| 387 | + * @return string |
|
| 388 | + */ |
|
| 389 | + public function redirect_to($location) |
|
| 390 | + { |
|
| 391 | + return $this->assign('window.location.href', $location); |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * @param $id |
|
| 396 | + * @return string |
|
| 397 | + */ |
|
| 398 | + public function remove($id) |
|
| 399 | + { |
|
| 400 | + if (is_array($id)) { |
|
| 401 | + $arr_str = ''; |
|
| 402 | + foreach ($id as $obj) { |
|
| 403 | + if (!empty($arg_str)) { |
|
| 404 | + $arg_str .= ', '; |
|
| 405 | + } |
|
| 406 | + $arg_str .= "'$arg'"; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + return "$A[$arg_str].each(Element.remove)"; |
|
| 410 | + } else { |
|
| 411 | + return "Element.remove('$id')"; |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * @param $id |
|
| 417 | + * @param $options_for_render |
|
| 418 | + * @return string |
|
| 419 | + */ |
|
| 420 | + public function replace($id, $options_for_render) |
|
| 421 | + { |
|
| 422 | + $args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render])); |
|
| 423 | + |
|
| 424 | + return $this->call('Element.replace', $args); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * @param $id |
|
| 429 | + * @param $options_for_render |
|
| 430 | + * @return string |
|
| 431 | + */ |
|
| 432 | + public function replace_html($id, $options_for_render) |
|
| 433 | + { |
|
| 434 | + $args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render])); |
|
| 435 | + |
|
| 436 | + return $this->call('Element.update', $args); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * @param $pattern |
|
| 441 | + * @param null $extend |
|
| 442 | + * @return string |
|
| 443 | + */ |
|
| 444 | + public function select($pattern, $extend = null) |
|
| 445 | + { |
|
| 446 | + return "$$('$pattern')" . (!empty($extend)) ? '.' . $extend : ''; |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * @param $id |
|
| 451 | + * @return string |
|
| 452 | + */ |
|
| 453 | + public function show($id) |
|
| 454 | + { |
|
| 455 | + return $this->call('Element.show', $id); |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * @param $id |
|
| 460 | + * @return string |
|
| 461 | + */ |
|
| 462 | + public function toggle($id) |
|
| 463 | + { |
|
| 464 | + return $this->call('Element.toggle', $id); |
|
| 465 | + } |
|
| 466 | 466 | } |
@@ -13,253 +13,253 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class XoopsCaptcha |
| 15 | 15 | { |
| 16 | - public $active = true; |
|
| 17 | - public $mode = 'text'; // potential values: image, text |
|
| 18 | - public $config = []; |
|
| 19 | - |
|
| 20 | - public $message = []; // Logging error messages |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * XoopsCaptcha constructor. |
|
| 24 | - */ |
|
| 25 | - public function __construct() |
|
| 26 | - { |
|
| 27 | - // Loading default preferences |
|
| 28 | - $this->config = @include __DIR__ . '/config.php'; |
|
| 29 | - |
|
| 30 | - $this->setMode($this->config['mode']); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @return XoopsCaptcha |
|
| 35 | - */ |
|
| 36 | - public static function getInstance() |
|
| 37 | - { |
|
| 38 | - static $instance; |
|
| 39 | - if (null === $instance) { |
|
| 40 | - $instance = new static(); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - return $instance; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @param $name |
|
| 48 | - * @param $val |
|
| 49 | - * @return bool |
|
| 50 | - */ |
|
| 51 | - public function setConfig($name, $val) |
|
| 52 | - { |
|
| 53 | - if ('mode' === $name) { |
|
| 54 | - $this->setMode($val); |
|
| 55 | - } elseif (isset($this->$name)) { |
|
| 56 | - $this->$name = $val; |
|
| 57 | - } else { |
|
| 58 | - $this->config[$name] = $val; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - return true; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Set CAPTCHA mode |
|
| 66 | - * |
|
| 67 | - * For future possible modes, right now force to use text or image |
|
| 68 | - * |
|
| 69 | - * @param string $mode if no mode is set, just verify current mode |
|
| 70 | - */ |
|
| 71 | - public function setMode($mode = null) |
|
| 72 | - { |
|
| 73 | - if (!empty($mode) && in_array($mode, ['text', 'image'])) { |
|
| 74 | - $this->mode = $mode; |
|
| 75 | - |
|
| 76 | - if ('image' !== $this->mode) { |
|
| 77 | - return; |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - // Disable image mode |
|
| 82 | - if (!extension_loaded('gd')) { |
|
| 83 | - $this->mode = 'text'; |
|
| 84 | - } else { |
|
| 85 | - $required_functions = [ |
|
| 86 | - 'imagecreatetruecolor', |
|
| 87 | - 'imagecolorallocate', |
|
| 88 | - 'imagefilledrectangle', |
|
| 89 | - 'imagejpeg', |
|
| 90 | - 'imagedestroy', |
|
| 91 | - 'imageftbbox' |
|
| 92 | - ]; |
|
| 93 | - foreach ($required_functions as $func) { |
|
| 94 | - if (!function_exists($func)) { |
|
| 95 | - $this->mode = 'text'; |
|
| 96 | - break; |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Initializing the CAPTCHA class |
|
| 104 | - * @param string $name |
|
| 105 | - * @param null $skipmember |
|
| 106 | - * @param null $num_chars |
|
| 107 | - * @param null $fontsize_min |
|
| 108 | - * @param null $fontsize_max |
|
| 109 | - * @param null $background_type |
|
| 110 | - * @param null $background_num |
|
| 111 | - */ |
|
| 112 | - public function init( |
|
| 113 | - $name = 'xoopscaptcha', |
|
| 114 | - $skipmember = null, |
|
| 115 | - $num_chars = null, |
|
| 116 | - $fontsize_min = null, |
|
| 117 | - $fontsize_max = null, |
|
| 118 | - $background_type = null, |
|
| 119 | - $background_num = null |
|
| 120 | - ) { |
|
| 121 | - // Loading RUN-TIME settings |
|
| 122 | - foreach (array_keys($this->config) as $key) { |
|
| 123 | - if (isset(${$key}) && null !== ${$key}) { |
|
| 124 | - $this->config[$key] = ${$key}; |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - $this->config['name'] = $name; |
|
| 128 | - |
|
| 129 | - // Skip CAPTCHA for member if set |
|
| 130 | - if ($this->config['skipmember'] && is_object($GLOBALS['xoopsUser'])) { |
|
| 131 | - $this->active = false; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Verify user submission |
|
| 137 | - * @param null $skipMember |
|
| 138 | - * @return bool |
|
| 139 | - */ |
|
| 140 | - public function verify($skipMember = null) |
|
| 141 | - { |
|
| 142 | - $sessionName = @$_SESSION['XoopsCaptcha_name']; |
|
| 143 | - $skipMember = (null === $skipMember) ? @$_SESSION['XoopsCaptcha_skipmember'] : $skipMember; |
|
| 144 | - $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
| 145 | - |
|
| 146 | - $is_valid = false; |
|
| 147 | - |
|
| 148 | - // Skip CAPTCHA for member if set |
|
| 149 | - if (is_object($GLOBALS['xoopsUser']) && !empty($skipMember)) { |
|
| 150 | - $is_valid = true; |
|
| 151 | - // Kill too many attempts |
|
| 152 | - } elseif (!empty($maxAttempts) && $_SESSION['XoopsCaptcha_attempt_' . $sessionName] > $maxAttempts) { |
|
| 153 | - $this->message[] = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
|
| 154 | - |
|
| 155 | - // Verify the code |
|
| 156 | - } elseif (!empty($_SESSION['XoopsCaptcha_sessioncode'])) { |
|
| 157 | - $func = $this->config['casesensitive'] ? 'strcmp' : 'strcasecmp'; |
|
| 158 | - $is_valid = !$func(trim(@$_POST[$sessionName]), $_SESSION['XoopsCaptcha_sessioncode']); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - if (!empty($maxAttempts)) { |
|
| 162 | - if (!$is_valid) { |
|
| 163 | - // Increase the attempt records on failure |
|
| 164 | - $_SESSION['XoopsCaptcha_attempt_' . $sessionName]++; |
|
| 165 | - // Log the error message |
|
| 166 | - $this->message[] = XOOPS_CAPTCHA_INVALID_CODE; |
|
| 167 | - } else { |
|
| 168 | - |
|
| 169 | - // reset attempt records on success |
|
| 170 | - $_SESSION['XoopsCaptcha_attempt_' . $sessionName] = null; |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - $this->destroyGarbage(true); |
|
| 174 | - |
|
| 175 | - return $is_valid; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * @return mixed|string |
|
| 180 | - */ |
|
| 181 | - public function getCaption() |
|
| 182 | - { |
|
| 183 | - return defined('XOOPS_CAPTCHA_CAPTION') ? constant('XOOPS_CAPTCHA_CAPTION') : ''; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @return string |
|
| 188 | - */ |
|
| 189 | - public function getMessage() |
|
| 190 | - { |
|
| 191 | - return implode('<br>', $this->message); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Destory historical stuff |
|
| 196 | - * @param bool $clearSession |
|
| 197 | - * @return bool |
|
| 198 | - */ |
|
| 199 | - public function destroyGarbage($clearSession = false) |
|
| 200 | - { |
|
| 201 | - require_once __DIR__ . '/' . $this->mode . '.php'; |
|
| 202 | - $class = 'XoopsCaptcha' . ucfirst($this->mode); |
|
| 203 | - $captchaHandler = new $class(); |
|
| 204 | - if (method_exists($captchaHandler, 'destroyGarbage')) { |
|
| 205 | - $captchaHandler->loadConfig($this->config); |
|
| 206 | - $captchaHandler->destroyGarbage(); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - if ($clearSession) { |
|
| 210 | - $_SESSION['XoopsCaptcha_name'] = null; |
|
| 211 | - $_SESSION['XoopsCaptcha_skipmember'] = null; |
|
| 212 | - $_SESSION['XoopsCaptcha_sessioncode'] = null; |
|
| 213 | - $_SESSION['XoopsCaptcha_maxattempts'] = null; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - return true; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * @return mixed|string |
|
| 221 | - */ |
|
| 222 | - public function render() |
|
| 223 | - { |
|
| 224 | - $form = ''; |
|
| 225 | - |
|
| 226 | - if (!$this->active || empty($this->config['name'])) { |
|
| 227 | - return $form; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - $_SESSION['XoopsCaptcha_name'] = $this->config['name']; |
|
| 231 | - $_SESSION['XoopsCaptcha_skipmember'] = $this->config['skipmember']; |
|
| 232 | - $maxAttempts = $this->config['maxattempt']; |
|
| 233 | - $_SESSION['XoopsCaptcha_maxattempts'] = $maxAttempts; |
|
| 234 | - /* |
|
| 16 | + public $active = true; |
|
| 17 | + public $mode = 'text'; // potential values: image, text |
|
| 18 | + public $config = []; |
|
| 19 | + |
|
| 20 | + public $message = []; // Logging error messages |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * XoopsCaptcha constructor. |
|
| 24 | + */ |
|
| 25 | + public function __construct() |
|
| 26 | + { |
|
| 27 | + // Loading default preferences |
|
| 28 | + $this->config = @include __DIR__ . '/config.php'; |
|
| 29 | + |
|
| 30 | + $this->setMode($this->config['mode']); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @return XoopsCaptcha |
|
| 35 | + */ |
|
| 36 | + public static function getInstance() |
|
| 37 | + { |
|
| 38 | + static $instance; |
|
| 39 | + if (null === $instance) { |
|
| 40 | + $instance = new static(); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + return $instance; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @param $name |
|
| 48 | + * @param $val |
|
| 49 | + * @return bool |
|
| 50 | + */ |
|
| 51 | + public function setConfig($name, $val) |
|
| 52 | + { |
|
| 53 | + if ('mode' === $name) { |
|
| 54 | + $this->setMode($val); |
|
| 55 | + } elseif (isset($this->$name)) { |
|
| 56 | + $this->$name = $val; |
|
| 57 | + } else { |
|
| 58 | + $this->config[$name] = $val; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + return true; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Set CAPTCHA mode |
|
| 66 | + * |
|
| 67 | + * For future possible modes, right now force to use text or image |
|
| 68 | + * |
|
| 69 | + * @param string $mode if no mode is set, just verify current mode |
|
| 70 | + */ |
|
| 71 | + public function setMode($mode = null) |
|
| 72 | + { |
|
| 73 | + if (!empty($mode) && in_array($mode, ['text', 'image'])) { |
|
| 74 | + $this->mode = $mode; |
|
| 75 | + |
|
| 76 | + if ('image' !== $this->mode) { |
|
| 77 | + return; |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + // Disable image mode |
|
| 82 | + if (!extension_loaded('gd')) { |
|
| 83 | + $this->mode = 'text'; |
|
| 84 | + } else { |
|
| 85 | + $required_functions = [ |
|
| 86 | + 'imagecreatetruecolor', |
|
| 87 | + 'imagecolorallocate', |
|
| 88 | + 'imagefilledrectangle', |
|
| 89 | + 'imagejpeg', |
|
| 90 | + 'imagedestroy', |
|
| 91 | + 'imageftbbox' |
|
| 92 | + ]; |
|
| 93 | + foreach ($required_functions as $func) { |
|
| 94 | + if (!function_exists($func)) { |
|
| 95 | + $this->mode = 'text'; |
|
| 96 | + break; |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Initializing the CAPTCHA class |
|
| 104 | + * @param string $name |
|
| 105 | + * @param null $skipmember |
|
| 106 | + * @param null $num_chars |
|
| 107 | + * @param null $fontsize_min |
|
| 108 | + * @param null $fontsize_max |
|
| 109 | + * @param null $background_type |
|
| 110 | + * @param null $background_num |
|
| 111 | + */ |
|
| 112 | + public function init( |
|
| 113 | + $name = 'xoopscaptcha', |
|
| 114 | + $skipmember = null, |
|
| 115 | + $num_chars = null, |
|
| 116 | + $fontsize_min = null, |
|
| 117 | + $fontsize_max = null, |
|
| 118 | + $background_type = null, |
|
| 119 | + $background_num = null |
|
| 120 | + ) { |
|
| 121 | + // Loading RUN-TIME settings |
|
| 122 | + foreach (array_keys($this->config) as $key) { |
|
| 123 | + if (isset(${$key}) && null !== ${$key}) { |
|
| 124 | + $this->config[$key] = ${$key}; |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + $this->config['name'] = $name; |
|
| 128 | + |
|
| 129 | + // Skip CAPTCHA for member if set |
|
| 130 | + if ($this->config['skipmember'] && is_object($GLOBALS['xoopsUser'])) { |
|
| 131 | + $this->active = false; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Verify user submission |
|
| 137 | + * @param null $skipMember |
|
| 138 | + * @return bool |
|
| 139 | + */ |
|
| 140 | + public function verify($skipMember = null) |
|
| 141 | + { |
|
| 142 | + $sessionName = @$_SESSION['XoopsCaptcha_name']; |
|
| 143 | + $skipMember = (null === $skipMember) ? @$_SESSION['XoopsCaptcha_skipmember'] : $skipMember; |
|
| 144 | + $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
| 145 | + |
|
| 146 | + $is_valid = false; |
|
| 147 | + |
|
| 148 | + // Skip CAPTCHA for member if set |
|
| 149 | + if (is_object($GLOBALS['xoopsUser']) && !empty($skipMember)) { |
|
| 150 | + $is_valid = true; |
|
| 151 | + // Kill too many attempts |
|
| 152 | + } elseif (!empty($maxAttempts) && $_SESSION['XoopsCaptcha_attempt_' . $sessionName] > $maxAttempts) { |
|
| 153 | + $this->message[] = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
|
| 154 | + |
|
| 155 | + // Verify the code |
|
| 156 | + } elseif (!empty($_SESSION['XoopsCaptcha_sessioncode'])) { |
|
| 157 | + $func = $this->config['casesensitive'] ? 'strcmp' : 'strcasecmp'; |
|
| 158 | + $is_valid = !$func(trim(@$_POST[$sessionName]), $_SESSION['XoopsCaptcha_sessioncode']); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + if (!empty($maxAttempts)) { |
|
| 162 | + if (!$is_valid) { |
|
| 163 | + // Increase the attempt records on failure |
|
| 164 | + $_SESSION['XoopsCaptcha_attempt_' . $sessionName]++; |
|
| 165 | + // Log the error message |
|
| 166 | + $this->message[] = XOOPS_CAPTCHA_INVALID_CODE; |
|
| 167 | + } else { |
|
| 168 | + |
|
| 169 | + // reset attempt records on success |
|
| 170 | + $_SESSION['XoopsCaptcha_attempt_' . $sessionName] = null; |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + $this->destroyGarbage(true); |
|
| 174 | + |
|
| 175 | + return $is_valid; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * @return mixed|string |
|
| 180 | + */ |
|
| 181 | + public function getCaption() |
|
| 182 | + { |
|
| 183 | + return defined('XOOPS_CAPTCHA_CAPTION') ? constant('XOOPS_CAPTCHA_CAPTION') : ''; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @return string |
|
| 188 | + */ |
|
| 189 | + public function getMessage() |
|
| 190 | + { |
|
| 191 | + return implode('<br>', $this->message); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Destory historical stuff |
|
| 196 | + * @param bool $clearSession |
|
| 197 | + * @return bool |
|
| 198 | + */ |
|
| 199 | + public function destroyGarbage($clearSession = false) |
|
| 200 | + { |
|
| 201 | + require_once __DIR__ . '/' . $this->mode . '.php'; |
|
| 202 | + $class = 'XoopsCaptcha' . ucfirst($this->mode); |
|
| 203 | + $captchaHandler = new $class(); |
|
| 204 | + if (method_exists($captchaHandler, 'destroyGarbage')) { |
|
| 205 | + $captchaHandler->loadConfig($this->config); |
|
| 206 | + $captchaHandler->destroyGarbage(); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + if ($clearSession) { |
|
| 210 | + $_SESSION['XoopsCaptcha_name'] = null; |
|
| 211 | + $_SESSION['XoopsCaptcha_skipmember'] = null; |
|
| 212 | + $_SESSION['XoopsCaptcha_sessioncode'] = null; |
|
| 213 | + $_SESSION['XoopsCaptcha_maxattempts'] = null; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + return true; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * @return mixed|string |
|
| 221 | + */ |
|
| 222 | + public function render() |
|
| 223 | + { |
|
| 224 | + $form = ''; |
|
| 225 | + |
|
| 226 | + if (!$this->active || empty($this->config['name'])) { |
|
| 227 | + return $form; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + $_SESSION['XoopsCaptcha_name'] = $this->config['name']; |
|
| 231 | + $_SESSION['XoopsCaptcha_skipmember'] = $this->config['skipmember']; |
|
| 232 | + $maxAttempts = $this->config['maxattempt']; |
|
| 233 | + $_SESSION['XoopsCaptcha_maxattempts'] = $maxAttempts; |
|
| 234 | + /* |
|
| 235 | 235 | if (!empty($maxAttempts)) { |
| 236 | 236 | $_SESSION['XoopsCaptcha_maxattempts_'.$_SESSION['XoopsCaptcha_name']] = $maxAttempts; |
| 237 | 237 | } |
| 238 | 238 | */ |
| 239 | 239 | |
| 240 | - // Fail on too many attempts |
|
| 241 | - if (!empty($maxAttempts) && @$_SESSION['XoopsCaptcha_attempt_' . $this->config['name']] > $maxAttempts) { |
|
| 242 | - $form = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
|
| 243 | - // Load the form element |
|
| 244 | - } else { |
|
| 245 | - $form = $this->loadForm(); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - return $form; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * @return mixed |
|
| 253 | - */ |
|
| 254 | - public function loadForm() |
|
| 255 | - { |
|
| 256 | - require_once __DIR__ . '/' . $this->mode . '.php'; |
|
| 257 | - $class = 'XoopsCaptcha' . ucfirst($this->mode); |
|
| 258 | - $captchaHandler = new $class(); |
|
| 259 | - $captchaHandler->loadConfig($this->config); |
|
| 260 | - |
|
| 261 | - $form = $captchaHandler->render(); |
|
| 262 | - |
|
| 263 | - return $form; |
|
| 264 | - } |
|
| 240 | + // Fail on too many attempts |
|
| 241 | + if (!empty($maxAttempts) && @$_SESSION['XoopsCaptcha_attempt_' . $this->config['name']] > $maxAttempts) { |
|
| 242 | + $form = XOOPS_CAPTCHA_TOOMANYATTEMPTS; |
|
| 243 | + // Load the form element |
|
| 244 | + } else { |
|
| 245 | + $form = $this->loadForm(); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + return $form; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * @return mixed |
|
| 253 | + */ |
|
| 254 | + public function loadForm() |
|
| 255 | + { |
|
| 256 | + require_once __DIR__ . '/' . $this->mode . '.php'; |
|
| 257 | + $class = 'XoopsCaptcha' . ucfirst($this->mode); |
|
| 258 | + $captchaHandler = new $class(); |
|
| 259 | + $captchaHandler->loadConfig($this->config); |
|
| 260 | + |
|
| 261 | + $form = $captchaHandler->render(); |
|
| 262 | + |
|
| 263 | + return $form; |
|
| 264 | + } |
|
| 265 | 265 | } |
@@ -38,60 +38,60 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | class XoopsFormCaptcha extends \XoopsFormElement |
| 40 | 40 | { |
| 41 | - public $_captchaHandler; |
|
| 41 | + public $_captchaHandler; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @param string $caption Caption of the form element, default value is defined in captcha/language/ |
|
| 45 | - * @param string $name Name for the input box |
|
| 46 | - * @param boolean $skipmember Skip CAPTCHA check for members |
|
| 47 | - * @param int $numchar Number of characters in image mode, and input box size for text mode |
|
| 48 | - * @param int $minfontsize Minimum font-size of characters in image mode |
|
| 49 | - * @param int $maxfontsize Maximum font-size of characters in image mode |
|
| 50 | - * @param int $backgroundtype Background type in image mode: 0 - bar; 1 - circle; 2 - line; 3 - rectangle; 4 - ellipse; 5 - polygon; 100 - generated from files |
|
| 51 | - * @param int $backgroundnum Number of background images in image mode |
|
| 52 | - * |
|
| 53 | - */ |
|
| 54 | - public function __construct( |
|
| 55 | - $caption = '', |
|
| 56 | - $name = 'xoopscaptcha', |
|
| 57 | - $skipmember = null, |
|
| 58 | - $numchar = null, |
|
| 59 | - $minfontsize = null, |
|
| 60 | - $maxfontsize = null, |
|
| 61 | - $backgroundtype = null, |
|
| 62 | - $backgroundnum = null |
|
| 63 | - ) { |
|
| 64 | - if (!class_exists('XoopsCaptcaha')) { |
|
| 65 | - require_once SMARTOBJECT_ROOT_PATH . '/include/captcha/captcha.php'; |
|
| 66 | - } |
|
| 43 | + /** |
|
| 44 | + * @param string $caption Caption of the form element, default value is defined in captcha/language/ |
|
| 45 | + * @param string $name Name for the input box |
|
| 46 | + * @param boolean $skipmember Skip CAPTCHA check for members |
|
| 47 | + * @param int $numchar Number of characters in image mode, and input box size for text mode |
|
| 48 | + * @param int $minfontsize Minimum font-size of characters in image mode |
|
| 49 | + * @param int $maxfontsize Maximum font-size of characters in image mode |
|
| 50 | + * @param int $backgroundtype Background type in image mode: 0 - bar; 1 - circle; 2 - line; 3 - rectangle; 4 - ellipse; 5 - polygon; 100 - generated from files |
|
| 51 | + * @param int $backgroundnum Number of background images in image mode |
|
| 52 | + * |
|
| 53 | + */ |
|
| 54 | + public function __construct( |
|
| 55 | + $caption = '', |
|
| 56 | + $name = 'xoopscaptcha', |
|
| 57 | + $skipmember = null, |
|
| 58 | + $numchar = null, |
|
| 59 | + $minfontsize = null, |
|
| 60 | + $maxfontsize = null, |
|
| 61 | + $backgroundtype = null, |
|
| 62 | + $backgroundnum = null |
|
| 63 | + ) { |
|
| 64 | + if (!class_exists('XoopsCaptcaha')) { |
|
| 65 | + require_once SMARTOBJECT_ROOT_PATH . '/include/captcha/captcha.php'; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - $this->_captchaHandler = XoopsCaptcha::getInstance(); |
|
| 69 | - $this->_captchaHandler->init($name, $skipmember, $numchar, $minfontsize, $maxfontsize, $backgroundtype, $backgroundnum); |
|
| 70 | - if (!$this->_captchaHandler->active) { |
|
| 71 | - $this->setHidden(); |
|
| 72 | - } else { |
|
| 73 | - $caption = !empty($caption) ? $caption : $this->_captchaHandler->getCaption(); |
|
| 74 | - $this->setCaption($caption); |
|
| 75 | - } |
|
| 76 | - } |
|
| 68 | + $this->_captchaHandler = XoopsCaptcha::getInstance(); |
|
| 69 | + $this->_captchaHandler->init($name, $skipmember, $numchar, $minfontsize, $maxfontsize, $backgroundtype, $backgroundnum); |
|
| 70 | + if (!$this->_captchaHandler->active) { |
|
| 71 | + $this->setHidden(); |
|
| 72 | + } else { |
|
| 73 | + $caption = !empty($caption) ? $caption : $this->_captchaHandler->getCaption(); |
|
| 74 | + $this->setCaption($caption); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @param $name |
|
| 80 | - * @param $val |
|
| 81 | - * @return bool |
|
| 82 | - */ |
|
| 83 | - public function setConfig($name, $val) |
|
| 84 | - { |
|
| 85 | - return $this->_captchaHandler->setConfig($name, $val); |
|
| 86 | - } |
|
| 78 | + /** |
|
| 79 | + * @param $name |
|
| 80 | + * @param $val |
|
| 81 | + * @return bool |
|
| 82 | + */ |
|
| 83 | + public function setConfig($name, $val) |
|
| 84 | + { |
|
| 85 | + return $this->_captchaHandler->setConfig($name, $val); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * @return mixed|string |
|
| 90 | - */ |
|
| 91 | - public function render() |
|
| 92 | - { |
|
| 93 | - if (!$this->isHidden()) { |
|
| 94 | - return $this->_captchaHandler->render(); |
|
| 95 | - } |
|
| 96 | - } |
|
| 88 | + /** |
|
| 89 | + * @return mixed|string |
|
| 90 | + */ |
|
| 91 | + public function render() |
|
| 92 | + { |
|
| 93 | + if (!$this->isHidden()) { |
|
| 94 | + return $this->_captchaHandler->render(); |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | 97 | } |
@@ -14,15 +14,15 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | function xoops_debug_dumbQuery($msg = '') |
| 16 | 16 | { |
| 17 | - global $xoopsDB; |
|
| 18 | - $xoopsDB->query('SELECT * ' . $msg . ' FROM dudewhereismycar2'); |
|
| 17 | + global $xoopsDB; |
|
| 18 | + $xoopsDB->query('SELECT * ' . $msg . ' FROM dudewhereismycar2'); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | function xoops_debug_initiateQueryCount() |
| 22 | 22 | { |
| 23 | - global $smartfactory_query_count_activated, $smartfactory_query_count; |
|
| 24 | - $smartfactory_query_count_activated = true; |
|
| 25 | - $smartfactory_query_count = 0; |
|
| 23 | + global $smartfactory_query_count_activated, $smartfactory_query_count; |
|
| 24 | + $smartfactory_query_count_activated = true; |
|
| 25 | + $smartfactory_query_count = 0; |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -30,9 +30,9 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | function xoops_debug_getQueryCount($msg = '') |
| 32 | 32 | { |
| 33 | - global $smartfactory_query_count; |
|
| 33 | + global $smartfactory_query_count; |
|
| 34 | 34 | |
| 35 | - return xoops_debug("xoops debug Query count ($msg): $smartfactory_query_count"); |
|
| 35 | + return xoops_debug("xoops debug Query count ($msg): $smartfactory_query_count"); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -41,10 +41,10 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | function xoops_debug($msg, $exit = false) |
| 43 | 43 | { |
| 44 | - echo "<div style='padding: 5px; color: red; font-weight: bold;'>debug:: $msg</div>"; |
|
| 45 | - if ($exit) { |
|
| 46 | - die(); |
|
| 47 | - } |
|
| 44 | + echo "<div style='padding: 5px; color: red; font-weight: bold;'>debug:: $msg</div>"; |
|
| 45 | + if ($exit) { |
|
| 46 | + die(); |
|
| 47 | + } |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | function xoops_comment($msg) |
| 54 | 54 | { |
| 55 | - echo "<div style='padding: 5px; color: green; font-weight: bold;'>=> $msg</div>"; |
|
| 55 | + echo "<div style='padding: 5px; color: green; font-weight: bold;'>=> $msg</div>"; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -60,10 +60,10 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | function xoops_debug_vardump($var) |
| 62 | 62 | { |
| 63 | - if (class_exists('MyTextSanitizer')) { |
|
| 64 | - $myts = \MyTextSanitizer::getInstance(); |
|
| 65 | - xoops_debug($myts->displayTarea(var_export($var, true))); |
|
| 66 | - } else { |
|
| 67 | - xoops_debug(var_export($var, true)); |
|
| 68 | - } |
|
| 63 | + if (class_exists('MyTextSanitizer')) { |
|
| 64 | + $myts = \MyTextSanitizer::getInstance(); |
|
| 65 | + xoops_debug($myts->displayTarea(var_export($var, true))); |
|
| 66 | + } else { |
|
| 67 | + xoops_debug(var_export($var, true)); |
|
| 68 | + } |
|
| 69 | 69 | } |
@@ -19,62 +19,62 @@ |
||
| 19 | 19 | |
| 20 | 20 | function getConfig() |
| 21 | 21 | { |
| 22 | - $moduleDirName = basename(dirname(__DIR__)); |
|
| 23 | - $moduleDirNameUpper = strtoupper($moduleDirName); |
|
| 24 | - return (object)[ |
|
| 25 | - 'name' => strtoupper($moduleDirName) . ' Module Configurator', |
|
| 26 | - 'paths' => [ |
|
| 27 | - 'dirname' => $moduleDirName, |
|
| 28 | - 'admin' => XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/admin', |
|
| 29 | - 'modPath' => XOOPS_ROOT_PATH . '/modules/' . $moduleDirName, |
|
| 30 | - 'modUrl' => XOOPS_URL . '/modules/' . $moduleDirName, |
|
| 31 | - 'uploadPath' => XOOPS_UPLOAD_PATH . '/' . $moduleDirName, |
|
| 32 | - 'uploadUrl' => XOOPS_UPLOAD_URL . '/' . $moduleDirName, |
|
| 33 | - ], |
|
| 34 | - 'uploadFolders' => [ |
|
| 35 | - constant($moduleDirNameUpper . '_UPLOAD_PATH'), |
|
| 36 | - constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/category', |
|
| 37 | - constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/screenshots', |
|
| 38 | - //XOOPS_UPLOAD_PATH . '/flags' |
|
| 39 | - ], |
|
| 40 | - 'copyBlankFiles' => [ |
|
| 41 | - constant($moduleDirNameUpper . '_UPLOAD_PATH'), |
|
| 42 | - constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/category', |
|
| 43 | - constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/screenshots', |
|
| 44 | - //XOOPS_UPLOAD_PATH . '/flags' |
|
| 45 | - ], |
|
| 22 | + $moduleDirName = basename(dirname(__DIR__)); |
|
| 23 | + $moduleDirNameUpper = strtoupper($moduleDirName); |
|
| 24 | + return (object)[ |
|
| 25 | + 'name' => strtoupper($moduleDirName) . ' Module Configurator', |
|
| 26 | + 'paths' => [ |
|
| 27 | + 'dirname' => $moduleDirName, |
|
| 28 | + 'admin' => XOOPS_ROOT_PATH . '/modules/' . $moduleDirName . '/admin', |
|
| 29 | + 'modPath' => XOOPS_ROOT_PATH . '/modules/' . $moduleDirName, |
|
| 30 | + 'modUrl' => XOOPS_URL . '/modules/' . $moduleDirName, |
|
| 31 | + 'uploadPath' => XOOPS_UPLOAD_PATH . '/' . $moduleDirName, |
|
| 32 | + 'uploadUrl' => XOOPS_UPLOAD_URL . '/' . $moduleDirName, |
|
| 33 | + ], |
|
| 34 | + 'uploadFolders' => [ |
|
| 35 | + constant($moduleDirNameUpper . '_UPLOAD_PATH'), |
|
| 36 | + constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/category', |
|
| 37 | + constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/screenshots', |
|
| 38 | + //XOOPS_UPLOAD_PATH . '/flags' |
|
| 39 | + ], |
|
| 40 | + 'copyBlankFiles' => [ |
|
| 41 | + constant($moduleDirNameUpper . '_UPLOAD_PATH'), |
|
| 42 | + constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/category', |
|
| 43 | + constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/screenshots', |
|
| 44 | + //XOOPS_UPLOAD_PATH . '/flags' |
|
| 45 | + ], |
|
| 46 | 46 | |
| 47 | - 'copyTestFolders' => [ |
|
| 48 | - // constant($moduleDirNameUpper . '_UPLOAD_PATH'), |
|
| 49 | - //[ |
|
| 50 | - // constant($moduleDirNameUpper . '_PATH') . '/testdata/images', |
|
| 51 | - // constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/images', |
|
| 52 | - //] |
|
| 53 | - ], |
|
| 47 | + 'copyTestFolders' => [ |
|
| 48 | + // constant($moduleDirNameUpper . '_UPLOAD_PATH'), |
|
| 49 | + //[ |
|
| 50 | + // constant($moduleDirNameUpper . '_PATH') . '/testdata/images', |
|
| 51 | + // constant($moduleDirNameUpper . '_UPLOAD_PATH') . '/images', |
|
| 52 | + //] |
|
| 53 | + ], |
|
| 54 | 54 | |
| 55 | - 'templateFolders' => [ |
|
| 56 | - '/templates/', |
|
| 57 | - '/templates/blocks/', |
|
| 58 | - '/templates/admin/' |
|
| 55 | + 'templateFolders' => [ |
|
| 56 | + '/templates/', |
|
| 57 | + '/templates/blocks/', |
|
| 58 | + '/templates/admin/' |
|
| 59 | 59 | |
| 60 | - ], |
|
| 61 | - 'oldFiles' => [ |
|
| 62 | - '/class/request.php', |
|
| 63 | - '/class/registry.php', |
|
| 64 | - '/class/utilities.php', |
|
| 65 | - '/class/util.php', |
|
| 66 | - '/include/constants.php', |
|
| 67 | - '/include/functions.php', |
|
| 68 | - '/ajaxrating.txt', |
|
| 69 | - ], |
|
| 70 | - 'oldFolders' => [ |
|
| 71 | - '/images', |
|
| 72 | - '/css', |
|
| 73 | - '/js', |
|
| 74 | - '/tcpdf', |
|
| 75 | - '/images', |
|
| 76 | - ], |
|
| 77 | - 'modCopyright' => "<a href='https://xoops.org' title='XOOPS Project' target='_blank'> |
|
| 60 | + ], |
|
| 61 | + 'oldFiles' => [ |
|
| 62 | + '/class/request.php', |
|
| 63 | + '/class/registry.php', |
|
| 64 | + '/class/utilities.php', |
|
| 65 | + '/class/util.php', |
|
| 66 | + '/include/constants.php', |
|
| 67 | + '/include/functions.php', |
|
| 68 | + '/ajaxrating.txt', |
|
| 69 | + ], |
|
| 70 | + 'oldFolders' => [ |
|
| 71 | + '/images', |
|
| 72 | + '/css', |
|
| 73 | + '/js', |
|
| 74 | + '/tcpdf', |
|
| 75 | + '/images', |
|
| 76 | + ], |
|
| 77 | + 'modCopyright' => "<a href='https://xoops.org' title='XOOPS Project' target='_blank'> |
|
| 78 | 78 | <img src='" . constant($moduleDirNameUpper . '_AUTHOR_LOGOIMG') . '\' alt=\'XOOPS Project\' /></a>', |
| 79 | - ]; |
|
| 79 | + ]; |
|
| 80 | 80 | } |