public function actionAdd() { $shipping_id = (int) \yii::$app->request->get('shipping', 0); $sql = "SELECT shipping_name,shipping_code FROM " . Shipping::tableName() . " WHERE id={$shipping_id}"; $shipping = \yii::$app->getDb()->createCommand($sql)->queryOne(); $set_modules = 1; include_once \yii::getAlias('@ext') . '/shipping/' . $shipping['shipping_code'] . '.php'; $fields = []; foreach ($modules[0]['configure'] as $key => $val) { $fields[$key]['name'] = $val['name']; $fields[$key]['value'] = $val['value']; $fields[$key]['label'] = \yii::t('shipping', $val['name']); } $count = count($fields); $fields[$count]['name'] = "freee_money"; $fields[$count]['value'] = "0"; $fields[$count]['label'] = \yii::t('shipping', 'free_money'); //如果支持货到付款,则允许设置货到付款支付费用 if ($modules[0]['cod']) { $count++; $fields[$count]['name'] = "pay_fee"; $fields[$count]['value'] = "0"; $fields[$count]['label'] = \yii::t('shipping', 'pay_fee'); } $shipping_area['shipping_id'] = 0; $shipping_area['free_money'] = 0; return $this->render('shipping_area_info', ['shipping_area' => ['shipping_id' => $shipping_id, 'shipping_code' => $shipping['shipping_code']], 'fields' => $fields, 'form_action' => 'insert']); }
public function save() { $base = yii::getAlias("@app/config"); $handle = fopen($base . "/smsdb.php", "w+"); $content = "<?php\nreturn [\n 'class' => 'yii\\db\\Connection',\n 'dsn' => 'mysql:host={$this->host};port={$this->port};dbname={$this->dbname}',\n 'username' => '{$this->user}',\n 'password' => '{$this->pass}',\n 'charset' => 'utf8',\n];"; fwrite($handle, $content); }
/** * 图片上传的处理函数 * * @access public * @param * array upload 包含上传的图片文件信息的数组 * @param * array dir 文件要上传在$this->data_dir下的目录名。如果为空图片放在则在$this->images_dir下以当月命名的目录下 * @param * array img_name 上传图片名称,为空则随机生成 * @return mix 如果成功则返回文件名,否则返回false */ public function UploadImage($upload, $dir = '', $img_name = '') { if (empty($dir)) { $dir = date('Ym'); $dir = \yii::getAlias('@static') . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR; } else { $dir = \yii::getAlias('@static') . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR; if ($img_name) { $img_name = $dir . $img_name; } } if (!file_exists($dir)) { if (!$this->make_dir($dir)) { return false; } } if (empty($img_name)) { $img_name = $this->unique_name($dir); $img_name = $dir . $img_name . UtilD::get_filetype($upload['name']); } if (!UtilD::check_img_type($upload['type'])) { return false; } //允许上传的类型 $allow_file_types = ['gif', 'jpg', 'jpeg', 'png', 'bmp', 'swf']; //'|GIF|JPG|JEPG|PNG|BMP|SWF|'; if (!UtilD::check_file_type($upload['tmp_name'], $img_name, $allow_file_types)) { return false; } if ($this->move_file($upload, $img_name)) { return str_replace(\yii::getAlias('@static') . DIRECTORY_SEPARATOR, '', $img_name); } else { return false; } }
private function getMainDependenciesConfig() { if (is_null($this->mainDependenciesConfig)) { $this->mainDependenciesConfig = (require \yii::getAlias("@appBuilder") . "/config/Dependencies.php"); } return $this->mainDependenciesConfig; }
/** * 根据错误状态码解析错误提示信息 * @param $code * @return string * @deprecate 转换到parseCode方法 */ private static function _parseCode($code) { include_once \yii::getAlias('@common/config/error.php'); $lang = \yii::$app->language; include_once \yii::getAlias('@common/lang/' . $lang . '/error_message_lang.php'); //待优化 return isset($lang[$code]) ? $lang[$code] : null; }
public static function getURLForAuth($fbAPI) { define('FACEBOOK_SDK_V4_SRC_DIR', \yii::getAlias('@frontend/modules/socials/fb')); FacebookSession::setDefaultApplication($fbAPI['APPID'], $fbAPI['SECURITY_KEY']); $helper = new FacebookRedirectLoginHelper(\yii::$app->params['fbAPI']['redirectURL']); $loginUrl = $helper->getLoginUrl(); return $loginUrl; }
public function getContent() { $twig = Yii::$app->twig->env(new \Twig_Loader_Filesystem(\yii::getAlias('@app/views/cmslayouts/'))); $insertion = []; foreach ($this->layout->getJsonConfig('placeholders') as $item) { $insertion[$item['var']] = $this->renderPlaceholder($this->id, $item['var'], 0); } return $twig->render($this->layout->view_file, ['placeholders' => $insertion, 'activeUrl' => Yii::$app->links->activeUrl]); }
/** * @param $langfile * @param string $idiom * @param bool|FALSE $return * @return array|bool|void * @throws InvalidConfigException */ public function load($langfile, $idiom = '', $return = FALSE) { if (is_array($langfile)) { foreach ($langfile as $value) { $this->load($value, $idiom, $return); } return; } $langfile = str_replace('.php', '', $langfile) . '_lang.php'; if (empty($idiom) or !preg_match('/^[a-z_-]+$/i', $idiom)) { $idiom = \yii::$app->language ?: 'zh_cn'; } if ($return === FALSE && isset($this->is_loaded[$langfile]) && $this->is_loaded[$langfile] === $idiom) { return; } $_is_load = false; // Load the base file, so any others found can override it $lang = []; //循环获取多个模块下的语言文件 foreach ($this->_lang_paths as $path) { $_file_path = \yii::getAlias($path . '/lang/' . $idiom . '/' . $langfile); if (!file_exists($_file_path)) { continue; } $section_lang = (include_once $_file_path); if (!is_array($section_lang)) { if ($return === true) { return []; } else { throw new InvalidConfigException('Language file contains no data: language/' . $idiom . '/' . $langfile); } } $_is_load = true; $lang = ArrayHelper::merge($lang, $section_lang); } if ($_is_load !== TRUE) { if ($return === true) { return []; } else { throw new InvalidConfigException('Unable to load the requested language file: language/' . $idiom . '/' . $langfile); } } $this->is_loaded[$langfile] = $idiom; $this->_current_lang = $lang; $this->language = ArrayHelper::merge($this->language, $lang); if ($return === TRUE) { return $lang; } return TRUE; }
public static function saveImage($location, $sourceName, $fileName) { if (isset($_FILES[$sourceName])) { $fileName = $fileName . '.jpg'; $path = '/upload/' . $location . '/'; $saveImage = self::SaveFileFromPost($sourceName, Yii::$app->basePath . $path, $fileName, false); $link = substr(yii::getAlias('@web'), 0, -4); $link = Url::to($link . $path . $fileName, true); if ($saveImage == true) { return $link; } else { return false; } } else { return false; } }
/** * Load Config File * * @param string $file Configuration file name * @param bool $return 是否返回 * @param bool $use_sections Whether configuration values should be loaded into their own section * @param bool $fail_gracefully Whether to just return FALSE or display an error message * @return bool TRUE if the file was loaded correctly or FALSE on failure */ public function load($file = '', $return = true, $use_sections = FALSE, $fail_gracefully = FALSE) { $file = $file === '' ? 'main' : str_replace('.php', '', $file); $loaded = FALSE; foreach ($this->_config_paths as $path) { foreach ([$file, YII_ENV . '/' . $file] as $location) { $file_path = \yii::getAlias($path . '/config/' . $location . '.php'); if (in_array($file_path, $this->is_loaded, TRUE)) { return TRUE; } if (!file_exists($file_path)) { continue; } $sction_config = (include_once $file_path); if (!is_array($sction_config)) { if ($fail_gracefully === TRUE) { return FALSE; } //show_error('Your '.$file_path.' file does not appear to contain a valid configuration array.'); } $this->current_config = ArrayHelper::merge($this->current_config, $sction_config); if ($use_sections === TRUE) { self::$config[$file] = isset(self::$config[$file]) ? ArrayHelper::merge(self::$config[$file], $this->current_config) : $this->current_config; } else { self::$config = ArrayHelper::merge(self::$config, $this->current_config); } $this->is_loaded[] = $file_path; $loaded = TRUE; //log_message('debug', 'Config file loaded: '.$file_path); } } if ($loaded === TRUE) { if ($return === true) { return $this->current_config; } else { return TRUE; } } elseif ($fail_gracefully === TRUE) { return FALSE; } //show_error('The configuration file '.$file.'.php does not exist.'); }
public static function sendMail($data) { $from = Utility::getConfig('admin_email'); $url = parse_url(\yii::$app->urlManager->getHostInfo()); $search = ['{copyright}' => '© ' . date('Y') . ' - ' . \yii::$app->urlManager->getHostInfo() . ' All rights reserved.', '{logo}' => \yii::getAlias('@base_url') . '/images/logo.jpg', '{domain_name}' => $url['host'], '{domain_url}' => \yii::$app->urlManager->getHostInfo()]; switch ($data['request']) { case "forget_password": $subject = "Reset Password Link"; $to = $data['to']; $link = $data['link']; $emailModel = EmailTemplate::getEmailTemplate('forget_password'); $emailContent = $emailModel->content; $search['{name}'] = ucwords($data['user']); $search['{link}'] = $data['link']; $emailContent = str_replace(array_keys($search), array_values($search), $emailContent); break; case "user_registration": $subject = "Registration"; $to = $data['to']; $link = $data['activationLink']; $emailModel = EmailTemplate::getEmailTemplate('user_registration'); $emailContent = $emailModel->content; $emailContent = str_replace('{name}', ucwords($data['user_name']), $emailContent); $emailContent = str_replace('{link}', $data['activationLink'], $emailContent); break; case "newsletter": $subject = $data['subject']; $to = $data['email']; $emailModel = EmailTemplate::getEmailTemplate('news_letter'); $emailContent = $emailModel->et_content; $emailContent = str_replace('{name}', $to, $emailContent); $emailContent = str_replace('{message}', $data['message'], $emailContent); break; default: echo "default case"; } \Yii::$app->mail->compose()->setFrom($from)->setTo($to)->setSubject($subject)->setHtmlBody($emailContent)->send(); return true; }
/** * @param $file * @param array $config_path * @return array * @throws InvalidConfigException */ public static function loadConfig($file, $config_path = []) { static $_config_paths = ['@common', '@backend']; if (!empty($config_path)) { $_config_paths = $config_path; } $_config = []; $file = $file === '' ? 'main' : str_replace('.php', '', $file); foreach ($_config_paths as $path) { foreach ([$file, YII_ENV . '/' . $file] as $location) { $file_path = \yii::getAlias($path . '/config/' . $location . '.php'); if (!file_exists($file_path)) { continue; } $_config_section = (include_once $file_path); if (!is_array($_config_section)) { throw new InvalidConfigException('Your ' . $file_path . ' file does not appear to contain a valid configuration array.'); } $_config = ArrayHelper::merge($_config, $_config_section); } } return $_config; }
public function __construct() { parent::__construct(); $this->baseUrl = \yii::getAlias('@base_url'); }
public function actionPost() { $allow_file_types = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'swf']; $values = \yii::$app->request->post('value', []); $type = \Yii::$app->request->post('type', ''); /* 保存变量值 */ $count = count($values); $arr = []; $sql = "SELECT id,value FROM " . ShopConfig::tableName(); $res = \yii::$app->db->createCommand($sql)->queryAll(); foreach ($res as $row) { $arr[$row['id']] = $row['value']; } foreach ($_POST['value'] as $key => $val) { //值更改则更新 if ($arr[$key] != $val) { $sql = "UPDATE " . ShopConfig::tableName() . " SET value='" . trim($val) . "' WHERE id=" . $key; $rs = \yii::$app->db->createCommand($sql)->execute(); } } /* 处理上传文件 */ $file_var_list = []; $sql = "SELECT * FROM " . ShopConfig::tableName() . " WHERE parent_id > 0 AND type='file'"; $res = \yii::$app->db->createCommand($sql)->queryAll(); foreach ($res as $row) { $file_var_list[$row['code']] = $row; } foreach ($_FILES as $code => $file) { /* 判断用户是否选择了文件 */ if (isset($file['error']) && $file['error'] == 0 || !isset($file['error']) && $file['tmp_name'] != 'none') { //检查上传的文件类型是否合法 if (!UtilD::check_file_type($file['tmp_name'], $file['name'], $allow_file_types)) { UtilD::toJavaScriptAlert('', 'back'); \yii::$app->end(); } else { $file_path = \yii::getAlias('@static') . DIRECTORY_SEPARATOR . $file_var_list[$code]['store_dir']; //取得文件路径 if ($code == 'shop_logo') { $ext = array_pop(explode('.', $file['name'])); $file_name = 'logo.' . $ext; } elseif ($code == 'watermark') { $ext = array_pop(explode('.', $file['name'])); $file_name = 'watermark.' . $ext; if (file_exists($file_var_list[$code]['value'])) { @unlink($file_var_list[$code]['value']); } } elseif ($code == 'wap_logo') { $ext = array_pop(explode('.', $file['name'])); $file_name = 'wap_logo.' . $ext; if (file_exists($file_var_list[$code]['value'])) { @unlink($file_var_list[$code]['value']); } } else { $file_name = $file['name']; } /* 判断是否上传成功 */ if (move_uploaded_file($file['tmp_name'], $file_path . $file_name)) { $sql = "UPDATE " . ShopConfig::tableName() . " SET value='" . $file_name . "' WHERE code='" . $code . "'"; $rs = \yii::$app->db->createCommand($sql)->execute(); } } } } /* 处理发票类型及税率 */ if (!empty($_POST['invoice_rate'])) { foreach ($_POST['invoice_rate'] as $key => $rate) { $rate = round(floatval($rate), 2); if ($rate < 0) { $rate = 0; } $_POST['invoice_rate'][$key] = $rate; } $invoice = ['type' => $_POST['invoice_type'], 'rate' => $_POST['invoice_rate']]; $sql = "UPDATE " . ShopConfig::tableName() . " SET value='" . serialize($invoice) . "' WHERE code ='invoice_type'"; \yii::$app->db->createCommand($sql)->execute(); } AdminLog::admin_log('', 'edit', 'shop_config'); /* 清除缓存 */ ShopConfig::clearCache(); if ($type == 'mail_setting') { return $this->redirect(Url::to('/config/mail-settings')); } else { return $this->redirect(\yii\helpers\Url::to('/config/listedit')); } }
public static function getProfileUrl($id) { $user = self::find()->byUserId($id)->one(); if (file_exists('/upload/' . $user->userProfile->profile_image)) { return \yii::getAlias('@profile_url') . $user->profile_image; } else { return FALSE; } }
<?php $alias = \yii::getAlias('@web'); ?> <div class=""> <div id="slider" class="sl-slider-wrapper"> <div class="sl-slider"> <div class="sl-slide" data-orientation="horizontal" data-slice1-rotation="-25" data-slice2-rotation="-25" data-slice1-scale="2" data-slice2-scale="2"> <div class="sl-slide-inner"> <div class="bg-img bg-img-1"></div> <h2><a href="#">2 Bed Rooms and 1 Dinning Room Aparment on Sale</a></h2> <blockquote> <p class="location"><span class="glyphicon glyphicon-map-marker"></span> 1890 Syndey, Australia</p> <p>Until he extends the circle of his compassion to all living things, man will not himself find peace.</p> <cite>$ 20,000,000</cite> </blockquote> </div> </div> <div class="sl-slide" data-orientation="vertical" data-slice1-rotation="10" data-slice2-rotation="-15" data-slice1-scale="1.5" data-slice2-scale="1.5"> <div class="sl-slide-inner"> <div class="bg-img bg-img-2"></div> <h2><a href="#">2 Bed Rooms and 1 Dinning Room Aparment on Sale</a></h2> <blockquote> <p class="location"><span class="glyphicon glyphicon-map-marker"></span> 1890 Syndey, Australia</p> <p>Until he extends the circle of his compassion to all living things, man will not himself find peace.</p> <cite>$ 20,000,000</cite>
protected function _fileExists($file) { return file_exists(\yii::getAlias($this->sourcePath) . '/' . $file); }
public function actionEdit() { $code = \yii::$app->request->get('code', ''); if (empty($code)) { UtilD::toJavaScriptAlert(\yii::t('app', 'invalid_parameter', 'back')); \yii::$app->end(); } $sql = "SELECT * FROM " . Payment::tableName() . " where pay_code='{$code}' AND enabled=1"; $pay = \yii::$app->getDb()->createCommand($sql)->queryOne(); if (empty($pay)) { UtilD::toJavaScriptAlert(\yii::t('app', 'payment_not_available', 'back')); \yii::$app->end(); } //获取插件信息 $set_modules = true; include_once \yii::getAlias('@ext') . '/payment/' . $code . ".php"; $data = $modules[0]; if (is_string($pay['pay_config'])) { $store = unserialize($pay['pay_config']); $code_list = []; foreach ($store as $key => $val) { $code_list[$val['name']] = $val['value']; } $pay['pay_config'] = []; /* 循环插件中所有属性 */ foreach ($data['config'] as $key => $value) { $messge = \yii::t($data['code'], $value['name'] . '_desc'); $pay['pay_config'][$key]['desc'] = $messge == $value['name'] . '_desc' ? '' : $messge; $pay['pay_config'][$key]['label'] = \yii::t($data['code'], $value['name']); $pay['pay_config'][$key]['name'] = $value['name']; $pay['pay_config'][$key]['type'] = $value['type']; if (isset($code_list[$value['name']])) { $pay['pay_config'][$key]['value'] = $code_list[$value['name']]; } else { $pay['pay_config'][$key]['value'] = $value['value']; } if ($pay['pay_config'][$key]['type'] == 'select' || $pay['pay_config'][$key]['type'] == 'radiobox') { $pay['pay_config'][$key]['range'] = \Yii::t($data['code'], $pay['pay_config'][$key]['name'] . '_range'); } } } if (!isset($pay['pay_fee'])) { if (isset($data['pay_fee'])) { $pay['pay_fee'] = $data['pay_fee']; } else { $pay['pay_fee'] = 0; } } return $this->render('edit', ['pay' => $pay]); }
public function actionRecoveryDefaultTemplate() { $shipping_id = \yii::$app->request->post('shipping', 0); $sql = "SELECT shipping_code FROM " . Shipping::tableName() . " WHERE id={$shipping_id}"; $code = \yii::$app->getDb()->createCommand($sql)->queryScalar(); $set_modules = true; include_once \yii::getAlias('@ext') . '/shipping/' . $code . '.php'; $sql = "UPDATE " . Shipping::tableName() . " SET print_bg='" . addslashes($modules[0]['print_bg']) . "',config_lable='" . addslashes($modules[0]['config_lable']) . "' WHERE shipping_code='{$code}' LIMIT 1"; \yii::$app->getDb()->createCommand($sql)->execute(); $this->redirect(['/shipping/edit-print-template', 'shipping' => $shipping_id]); }
/** * Render static pages */ public function actionStatic() { $sitemap = '<?xml version="1.0" encoding="UTF-8"?>' . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; echo "Static pages for deputies...\n"; $this->layout = 'deputy'; $dir = \yii::getAlias('@frontend/депутати'); $deputies = Deputy::find()->orderBy('name')->all(); foreach ($deputies as $deputy) { // Save deputy page $this->view->params['deputy'] = $deputy; $pageHtml = $this->render('deputy', ['deputy' => $deputy]); $fileName = str_replace(' ', '-', "{$deputy->name} {$deputy->id}"); $file = fopen("wfio://{$dir}/{$fileName}.html", 'w'); fwrite($file, $pageHtml); fclose($file); // Append to sitemap $sitemap .= "<url><loc>http://vvkp.in.ua/депутати/{$fileName}.html</loc></url>"; } echo "Sitemap...\n"; $sitemap .= '</urlset>'; file_put_contents(\yii::getAlias('@frontend') . '/sitemap.xml', $sitemap); }
/** * Get cache dir */ public function getCacheDir() { $cacheDir = \yii::getAlias('@runtime') . '/' . $this->cacheDir; if (!file_exists($cacheDir)) { mkdir($cacheDir); } return $cacheDir; }