| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?php
- /*
- * FecShop file.
- *
- * @link http://www.fecshop.com/
- * @copyright Copyright (c) 2016 FecShop Software LLC
- * @license http://www.fecshop.com/license/
- */
- namespace fecshop\services;
- use yii\base\InvalidConfigException;
- use Yii;
- /**
- * Admin services.
- *
- * @property \fecshop\services\customer\UrlKey $urlKey
- * @property \fecshop\services\customer\RoleUrlKey $roleUrlKey
- * @property \fecshop\services\customer\Role $role
- * @property \fecshop\services\customer\Config $config
- * @property \fecshop\services\customer\UserRole $userRole
- * @property \fecshop\services\customer\SystemLog $systemLog
- * @property \fecshop\services\customer\Menu $menu
- *
- * @author Terry Zhao <2358269014@qq.com>
- * @since 1.0
- */
- class Admin extends Service
- {
- public $xhEditorUploadImgUrl = 'cms/xeditor/imageupload';
- public $xhEditorUploadImgForamt = 'jpg,jpeg,gif,png';
- public $xhEditorUploadFlashUrl = 'cms/xeditor/flashupload';
- public $xhEditorUploadFlashFormat = 'swf';
- public $xhEditorUploadLinkUrl = 'cms/xeditor/linkupload';
- public $xhEditorUploadLinkFormat = 'zip,rar,txt';
- public $xhEditorUploadMediaUrl = 'cms/xeditor/mediaupload';
- public $xhEditorUploadMediaFormat = 'avi';
- protected $_currentLangCode;
- const ADMIN_CURRENT_LANG_CODE = 'admin_current_lang_code';
- /**
- * @return string 得到编辑器上传图片upload url
- */
- public function getXhEditorUploadImgUrl(){
- return $this->xhEditorUploadImgUrl;
- }
- /**
- * @return string 得到编辑器上传图片允许的文件格式
- */
- public function getXhEditorUploadImgForamt(){
- return $this->xhEditorUploadImgForamt;
- }
- /**
- * @return string 得到编辑器上传Flash upload url
- */
- public function getXhEditorUploadFlashUrl(){
- return $this->xhEditorUploadFlashUrl;
- }
- /**
- * @return string 得到编辑器上传Flash允许的文件格式
- */
- public function getXhEditorUploadFlashFormat(){
- return $this->xhEditorUploadFlashFormat;
- }
- /**
- * @return string 得到编辑器上传Link upload url
- */
- public function getXhEditorUploadLinkUrl(){
- return $this->xhEditorUploadLinkUrl;
- }
- /**
- * @return string 得到编辑器上传Link允许的文件格式
- */
- public function getXhEditorUploadLinkFormat(){
- return $this->xhEditorUploadLinkFormat;
- }
- /**
- * @return string 得到编辑器上传Media upload url
- */
- public function getXhEditorUploadMediaUrl(){
- return $this->xhEditorUploadMediaUrl;
- }
- /**
- * @return string 得到编辑器上传Media允许的文件格式
- */
- public function getXhEditorUploadMediaFormat(){
- return $this->xhEditorUploadMediaFormat;
- }
- /**
- * @param $app
- * 在Yii2框架的初始化过程过程过程中执行的函数,将被组件(Yii2 components)Yii::$app->store->bootstrap() 调用
- * Yii::$app->store 组件, 就是文件:fecshop\components\Store.php
- * @throws InvalidConfigException
- */
- public function bootstrap($app){
- $this->initLangCode();
- }
- /**
- * 初始化后台多语言
- * @throws InvalidConfigException
- */
- protected function initLangCode(){
- if (!$this->_currentLangCode) {
- $currentLangCode = Yii::$service->session->get(self::ADMIN_CURRENT_LANG_CODE);
- if (!$currentLangCode) {
- $currentLangCode = Yii::$service->fecshoplang->defaultLangCode;
- }
- if (!$currentLangCode) {
- throw new InvalidConfigException('default lang code must config');
- }
- if ($this->setTranslateLang($currentLangCode)) {
- $this->_currentLangCode = $currentLangCode;
- } else {
- throw new InvalidConfigException('lang code: '.$currentLangCode.' can not find in fecshoplang service config, you should add this language config');
- }
- }
- }
- public function getCurrentLangCode(){
- if (!$this->_currentLangCode) {
- $this->initLangCode();
- }
- return $this->_currentLangCode;
- }
-
- public function setCurrentLangCode($code){
- $adminLangCode = Yii::$service->fecshoplang->getAdminLangCode();
- if (in_array($code, $adminLangCode)) {
- Yii::$service->session->set(self::ADMIN_CURRENT_LANG_CODE, $code);
- $this->_currentLangCode = $code;
- if ($this->setTranslateLang($code)) {
- return true;
- }
- }
-
- return false;
- }
- public function setTranslateLang($code){
- $langCodeArr = Yii::$service->fecshoplang->getLangAndCodeArr();
- if (isset($langCodeArr[$code]) && $langCodeArr[$code]) {
- Yii::$service->page->translate->setLanguage($langCodeArr[$code]);
- return true;
- }
- return false;
- }
-
- public function getLangArr(){
- $arr = [];
- $adminLangCode = Yii::$service->fecshoplang->adminLangCode;
-
- if (is_array($adminLangCode)) {
- foreach ($adminLangCode as $one) {
- $arr[$one['code']] = $one['name'];
- }
- }
-
- return $arr;
- }
-
- }
|