From c96be8964abbb559a03b7b5b887cb25203ec1266 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Thu, 10 Mar 2016 11:15:24 +0800 Subject: [PATCH] * change for framework. --- framework/base/control.class.php | 6 +- framework/base/helper.class.php | 6 +- framework/base/model.class.php | 6 +- framework/base/router.class.php | 6 +- framework/control.class.php | 18 ++++++ framework/helper.class.php | 18 ++++++ framework/model.class.php | 18 ++++++ framework/router.class.php | 95 ++++++++++---------------------- lib/base/front/front.class.php | 38 ++++++++++--- lib/front/front.class.php | 61 ++++++++++++++++++++ module/common/model.php | 4 ++ 11 files changed, 189 insertions(+), 87 deletions(-) diff --git a/framework/base/control.class.php b/framework/base/control.class.php index e36b865171..9546f804b1 100644 --- a/framework/base/control.class.php +++ b/framework/base/control.class.php @@ -1,7 +1,7 @@ setModuleName('common'); - $commonModelFile = helper::setModelFile('common'); - if(file_exists($commonModelFile)) - { - helper::import($commonModelFile); - if(class_exists('extcommonModel')) - { - $commonClass = 'class common extends extcommonModel{}'; - eval($commonClass); - return new extcommonModel(); - } - elseif(class_exists('commonModel')) - { - $commonClass = 'class common extends commonModel{}'; - eval($commonClass); - return new commonModel(); - } - else - { - return false; - } - } - } - + /** + * 加载语言文件,返回全局$lang对象。 + * Load lang and return it as the global lang object. + * + * @param string $moduleName the module name + * @param string $appName the app name + * @access public + * @return bool|ojbect the lang object or false. + */ public function loadLang($moduleName, $appName = '') { - $modulePath = $this->getModulePath($appName, $moduleName); - $mainLangFile = $modulePath . 'lang' . DS . $this->clientLang . '.php'; - $extLangPath = $this->getModuleExtPath($appName, $moduleName, 'lang'); - $commonExtLangFiles = helper::ls($extLangPath['common'] . $this->clientLang, '.php'); - $siteExtLangFiles = helper::ls($extLangPath['site'] . $this->clientLang, '.php'); - $extLangFiles = array_merge($commonExtLangFiles, $siteExtLangFiles); - - /* Set the files to includ. */ - if(!is_file($mainLangFile)) - { - if(empty($extLangFiles)) return false; // also no extension file. - $langFiles = $extLangFiles; - } - else - { - $langFiles = array_merge(array($mainLangFile), $extLangFiles); - } - global $lang; if(!is_object($lang)) $lang = new language(); @@ -67,28 +50,6 @@ class router extends baseRouter $lang->projectCommon = isset($this->config->projectCommonList[$this->clientLang][(int)$projectCommon]) ? $this->config->projectCommonList[$this->clientLang][(int)$projectCommon] : $this->config->projectCommonList['zh-cn'][0]; } - static $loadedLangs = array(); - foreach($langFiles as $langFile) - { - if(in_array($langFile, $loadedLangs)) continue; - include $langFile; - $loadedLangs[] = $langFile; - } - - /* Merge from the db lang. */ - if($moduleName != 'common' and isset($lang->db->custom[$moduleName])) - { - foreach($lang->db->custom[$moduleName] as $section => $fields) - { - foreach($fields as $key => $value) - { - unset($lang->{$moduleName}->{$section}[$key]); - $lang->{$moduleName}->{$section}[$key] = $value; - } - } - } - - $this->lang = $lang; - return $lang; + return parent::loadLang($moduleName, $appName); } } diff --git a/lib/base/front/front.class.php b/lib/base/front/front.class.php index 737c1aae3f..fd8cd164fc 100644 --- a/lib/base/front/front.class.php +++ b/lib/base/front/front.class.php @@ -107,7 +107,7 @@ class baseHTML * @access public * @return string */ - static public function a($href = '', $title = '', $target = "_self", $misc = '', $newline = true) + static public function a($href = '', $title = '', $misc = '', $newline = true) { global $config; if(empty($title)) $title = $href; @@ -120,8 +120,7 @@ class baseHTML $href .= $onlybody; } - if($target == '_self') return "$title$newline"; - return "$title$newline"; + return "$title$newline"; } /** @@ -450,7 +449,7 @@ class baseHTML * @access public * @return string the submit button tag. */ - public static function submitButton($label = '', $misc = '', $class = 'btn btn-primary') + public static function submitButton($label = '', $class = 'btn btn-primary', $misc = '') { global $lang; @@ -515,7 +514,7 @@ class baseHTML * @access public * @return string the common button tag. */ - public static function commonButton($label = '', $misc = '', $class = 'btn btn-default', $icon = '') + public static function commonButton($label = '', $class = 'btn btn-default', $misc = '', $icon = '') { if($icon) $label = " " . $label; return " "; @@ -534,7 +533,7 @@ class baseHTML * @access public * @return string */ - public static function linkButton($label = '', $link = '', $target = 'self', $misc = '', $class = 'btn btn-default') + public static function linkButton($label = '', $link = '', $class='btn btn-default', $misc = '', $target = 'self') { global $config, $lang; @@ -673,15 +672,38 @@ EOT; * Create select buttons include 'selectAll' and 'selectReverse'. * * @param string $scope the scope of select reverse. + * @param bool $asGroup * @param string $appendClass * @static * @access public * @return string */ - static public function selectButton($scope = "", $appendClass = 'btn') + static public function selectButton($scope = "", $asGroup = true, $appendClass = '') { + $string = << +$(function() +{ + if($('body').data('bindSelectBtn')) return; + $('body').data('bindSelectBtn', true); + $(document).on('click', '.check-all, .check-inverse, #allchecker, #reversechecker', function() + { + var e = $(this); + if(e.closest('.datatable').length) return; + scope = e.data('scope'); + scope = scope ? $('#' + scope) : e.closest('.table'); + if(!scope.length) scope = e.closest('form'); + scope.find('input:checkbox').each(e.hasClass('check-inverse') ? function() { $(this).prop("checked", !$(this).prop("checked"));} : function() { $(this).prop("checked", true);}); + }); +}); + +EOT; global $lang; - return "
"; + if($asGroup) $string .= "
"; + $string .= "{$lang->selectAll}"; + $string .= "{$lang->selectReverse}"; + if($asGroup) $string .= "
"; + return $string; } /** diff --git a/lib/front/front.class.php b/lib/front/front.class.php index 1d79f06037..1c37d32e96 100644 --- a/lib/front/front.class.php +++ b/lib/front/front.class.php @@ -20,6 +20,67 @@ helper::import(dirname(dirname(__FILE__)) . '/base/front/front.class.php'); */ class html extends baseHTML { + /** + * 生成超链接。 + * Create tags like text + * + * @param string $href the link url. + * @param string $title the link title. + * @param string $misc other params. + * @param string $newline + * @static + * @access public + * @return string + */ + static public function a($href = '', $title = '', $target = "_self", $misc = '', $newline = true) + { + if(empty($target)) $target = '_self'; + if($target != '_self') $misc .= " target='$target'"; + return parent::a($href, $title, $misc, $newline); + } + + /** + * 创建提交按钮。 + * Create submit button. + * + * @param string $label the label of the button + * @param string $class the class of the button + * @param string $misc other params + * @static + * @access public + * @return string the submit button tag. + */ + public static function submitButton($label = '', $misc = '', $class = 'btn btn-primary') + { + return parent::submitButton($label, $class, $misc); + } + + public static function commonButton($label = '', $misc = '', $class = 'btn btn-default', $icon = '') + { + return parent::commonButton($label, $class, $misc, $icon); + } + + public static function linkButton($label = '', $link = '', $target = 'self', $misc = '', $class = 'btn btn-default') + { + return parent::linkButton($label, $link, $class, $misc, $target); + } + + /** + * 创建全选checkbox。 + * Create select buttons include 'selectAll' and 'selectReverse'. + * + * @param string $scope the scope of select reverse. + * @param bool $asGroup + * @param string $appendClass + * @static + * @access public + * @return string + */ + static public function selectButton($scope = "", $asGroup = true, $appendClass = 'btn') + { + global $lang; + return "
"; + } } /** diff --git a/module/common/model.php b/module/common/model.php index 979a5f9d9f..c8bb7acb83 100644 --- a/module/common/model.php +++ b/module/common/model.php @@ -1267,3 +1267,7 @@ class commonModel extends model return "$httpType://$httpHost"; } } + +class common extends commonModel +{ +}