/** * Manage whitelist. * * @access public * @return void */ public function setWhitelist() { $this->lang->guarder->menu = $this->lang->security->menu; $this->lang->menuGroups->site = 'security'; if ($_POST) { $user = $this->loadModel('user')->identify($this->app->user->account, $this->post->password); if (!$user) { $this->send(array('result' => 'fail', 'message' => $this->lang->user->identifyFailed)); } $setting = fixer::input('post')->get(); /* check IP. */ $ips = explode(',', $setting->ip); foreach ($ips as $ip) { if (!empty($ip) and !helper::checkIP($ip)) { $this->send(array('result' => 'fail', 'message' => $this->lang->guarder->whitelist->wrongIP)); } } $setting = array('whitelist' => helper::jsonEncode($setting)); $result = $this->loadModel('setting')->setItems('system.common.guarder', $setting, 'all'); if ($result) { $this->send(array('result' => 'success', 'message' => $this->lang->setSuccess, 'locate' => inlink('setWhitelist'))); } $this->send(array('result' => 'fail', 'message' => dao::getError())); } $this->view->title = $this->lang->guarder->setWhitelist; $this->display(); }
/** * Create an order. * * @access public * @return void */ public function create() { $order = fixer::input('post')->add('account', $this->app->user->account)->add('createdDate', helper::now())->add('payStatus', 'not_paid')->add('status', 'normal')->add('deliveryStatus', 'not_send')->add('type', 'shop')->get(); $address = $this->dao->select('*')->from(TABLE_ADDRESS)->where('id')->eq($this->post->deliveryAddress)->andWhere('account')->eq($this->app->user->account)->fetch(); $order->address = helper::jsonEncode($address); if ($this->post->createAddress) { $address = $this->createAddress(); if (!$address) { return array('result' => 'fail', 'message' => dao::getError()); } $order->address = helper::jsonEncode($address); } $this->dao->insert(TABLE_ORDER)->data($order, 'createAddress,deliveryAddress,phone,contact,zipcode,price,count,product')->autocheck()->batchCheck($this->config->order->require->create, 'notempty')->exec(); if (dao::isError()) { return array('result' => 'fail', 'message' => dao::getError()); } $orderID = $this->dao->lastInsertID(); $goods = new stdclass(); $goods->orderID = $orderID; if (!$this->post->product) { $this->clearOrder($orderID); return array('result' => 'fail', 'message' => $this->lang->order->noProducts); } /* Save products of the order and compute order amount. */ $amount = 0; foreach ($this->post->product as $product) { $product = $this->dao->select('*')->from(TABLE_PRODUCT)->where('id')->eq($product)->fetch(); if (empty($product)) { continue; } $goods->productID = $product->id; $goods->productName = $product->name; $goods->count = $this->post->count[$product->id]; if (isset($this->config->product->stock) && $this->config->product->stock) { if ($product->amount < $goods->count) { $this->clearOrder($orderID); return array('result' => 'fail', 'message' => sprintf($this->lang->order->lowStocks, $goods->productName)); } } $goods->price = $product->promotion > 0 ? $product->promotion : $product->price; if (!$goods->price) { continue; } $amount += $goods->price * $goods->count; $this->dao->insert(TABLE_ORDER_PRODUCT)->data($goods)->autoCheck()->exec(); } /* Check valid products count. */ $productCout = $this->dao->select("count(*) as count")->from(TABLE_ORDER_PRODUCT)->where('orderID')->eq($orderID)->fetch('count'); if (!$productCout) { return array('result' => 'fail', 'message' => $this->lang->order->noProducts); } $this->dao->update(TABLE_ORDER)->set('amount')->eq($amount)->where('id')->eq($orderID)->exec(); $this->dao->delete()->from(TABLE_CART)->where('account')->eq($this->app->user->account)->andWhere('product')->in($this->post->product)->exec(); if (!dao::isError()) { return $orderID; } }
/** * set site basic info. * * @access public * return void */ public function setOauth() { if (!empty($_POST)) { $provider = $this->post->provider; $oauth = array($provider => helper::jsonEncode($_POST)); $result = $this->loadModel('setting')->setItems('system.common.oauth', $oauth); if ($result) { $this->send(array('result' => 'success', 'message' => $this->lang->setSuccess)); } $this->send(array('result' => 'fail', 'message' => $this->lang->fail)); } $this->view->title = $this->lang->site->setOauth; $this->display(); }
/** * Nav admin function * * @param string $top * @access public * @return void */ public function admin($type = '') { if ($type == '' and $this->config->site->type == 'portal') { $type = $this->device . '_top'; } if ($type == '' and $this->config->site->type == 'blog') { $type = $this->device . '_blog'; } foreach ($this->lang->nav->system as $module => $name) { if (!commonModel::isAvailable($module)) { unset($this->lang->nav->system->{$module}); } } if ($_POST) { $navs = $this->post->nav; foreach ($navs as $key => $nav) { $navs[$key] = $this->nav->organizeNav($nav); } if (isset($navs[2])) { $navs[2] = $this->nav->group($navs[2]); if (isset($navs[3])) { $navs[3] = $this->nav->group($navs[3]); } foreach ($navs[2] as &$navList) { foreach ($navList as &$nav) { $nav['children'] = isset($navs[3][$nav['key']]) ? $navs[3][$nav['key']] : array(); } } } foreach ($navs[1] as &$nav) { $nav['children'] = isset($navs[2][$nav['key']]) ? $navs[2][$nav['key']] : array(); } $settings = array($type => helper::jsonEncode($navs[1])); $result = $this->loadModel('setting')->setItems('system.common.nav', $settings); if ($result) { $this->send(array('result' => 'success', 'message' => $this->lang->setSuccess)); } $this->send(array('result' => 'fail', 'message' => $this->lang->failed)); } $this->view->title = $this->lang->nav->setNav; $this->view->navs = $this->nav->getNavs($type); $this->view->type = $type; $this->view->types = $this->lang->nav->types; $this->view->articleTree = $this->loadModel('tree')->getOptionMenu('article'); $this->display(); }
/** * set contact information. * * @access public * @return void */ public function setContact() { if (!empty($_POST)) { if (!empty($_POST['email'])) { if (!validater::checkEmail($this->post->email)) { $this->send(array('result' => 'fail', 'message' => $this->lang->company->error->email)); } } $contact = array('contact' => helper::jsonEncode($_POST)); $result = $this->loadModel('setting')->setItems('system.common.company', $contact); if ($result) { $this->send(array('result' => 'success', 'message' => $this->lang->setSuccess)); } $this->send(array('result' => 'fail', 'message' => $this->lang->fail)); } $this->view->title = $this->lang->company->setContact; $this->view->contact = json_decode($this->config->company->contact); $this->display(); }
/** * Set others for ui. * * @access public * @return void */ public function others() { /* Get configs of list number. */ $this->app->loadConfig('article'); $this->app->loadConfig('product'); $this->app->loadConfig('file'); if (strpos($this->config->site->modules, 'blog') !== false) { $this->app->loadConfig('blog'); } if (strpos($this->config->site->modules, 'message') !== false) { $this->app->loadConfig('message'); } if (strpos($this->config->site->modules, 'forum') !== false) { $this->app->loadConfig('forum'); $this->app->loadConfig('reply'); } if (!empty($_POST)) { $thumbs = helper::jsonEncode($this->post->thumbs); $result = $this->loadModel('setting')->setItem('system.common.file.thumbs', $thumbs); if (!$result) { $this->send(array('result' => 'fail', 'message' => $this->lang->fail)); } $setting = fixer::input('post')->get('productView,QRCode'); $result = $this->loadModel('setting')->setItems('system.common.ui', $setting); if (!$result) { $this->send(array('result' => 'fail', 'message' => $this->lang->fail)); } $setting = fixer::input('post')->remove('productView,QRCode,thumbs')->get(); $result = $this->loadModel('setting')->setItems('system.common.site', $setting, 'all'); if ($result) { $this->send(array('result' => 'success', 'message' => $this->lang->setSuccess)); } $this->send(array('result' => 'fail', 'message' => $this->lang->fail)); } $this->view->title = $this->lang->ui->others; $this->display(); }
/** * Fix customed css. * * @access public * @return void */ public function fixCustomedCss() { $customedFile = $this->app->getDataRoot() . 'theme/custom.css'; if (is_file($customedFile)) { $customPath = $this->app->getDataRoot() . 'css' . DS . 'default' . DS . 'colorful' . DS; mkdir($customPath, 0777, true); rename($customedFile, $customPath . 'style.css'); } if (isset($this->config->site->themeSetting)) { $customed = json_decode($this->config->site->themeSetting, true); $setting['default']['colorful']['font-size'] = $customed['fontSize']; $setting['default']['colorful']['border-radius'] = $customed['borderRadius']; $setting['default']['colorful']['color-primary'] = $customed['primaryColor']; $setting['default']['colorful']['background-color'] = $customed['backColor']; return $this->loadModel('setting')->setItems('system.common.template', array('custom' => helper::jsonEncode($setting))); } return true; }
/** * Append ID for subRegion when upgrade from 4.4.1. * * @access public * @return void */ public function appendIDForRegion() { $layouts = $this->dao->select('*')->from(TABLE_LAYOUT)->fetchAll(); foreach ($layouts as $layout) { $blocks = json_decode($layout->blocks); foreach ($blocks as $block) { if (!isset($block->children)) { continue; } $regionID = $this->loadModel('block')->createRegion($layout->template, $layout->page, $layout->region); $block->id = $regionID; } $blocks = helper::jsonEncode($blocks); if ($blocks == $layout->blocks) { continue; } $layout->blocks = $blocks; $this->dao->replace(TABLE_LAYOUT)->data($layout)->exec(); } }
/** * Merge custom. * * @param object $info * @access public * @return void */ public function mergeCustom($info) { $template = $info->template; $theme = $info->theme; $code = $info->code; /* Merge theme custom param to current lang. */ $params = $this->dao->setAutoLang(false)->select('value')->from(TABLE_CONFIG)->where('lang')->eq('lang')->andWhere('`key`')->eq('custom')->fetch('value'); $params = json_decode($params, true); if (!empty($params[$template][$theme])) { $userCustom = $this->dao->setAutoLang(false)->select('*')->from(TABLE_CONFIG)->where('lang')->ne('lang')->andWhere('section')->eq('template')->andWhere('`key`')->eq('custom')->fetchAll('lang'); foreach ($userCustom as $lang => $custom) { $setting = json_decode($custom->value, true); if (!isset($setting[$template])) { $setting[$template] = array(); } $setting[$template][$code] = zget($params[$template], $theme, array()); $custom->value = helper::jsonEncode($setting); $this->dao->replace(TABLE_CONFIG)->data($custom)->exec(); } } return true; }
/** * set yangcong configure. * * @access public * return void */ public function setYangcong() { if (!empty($_POST)) { $setting = fixer::input('post')->get(); $result = $this->loadModel('setting')->setItem('system.common.site.yangcong', helper::jsonEncode($setting), "all"); if ($result) { $this->send(array('result' => 'success', 'message' => $this->lang->setSuccess)); } $this->send(array('result' => 'fail', 'message' => $this->lang->fail)); } $this->view->title = $this->lang->site->setYangcong; $this->view->setting = array(); if (!empty($this->config->site->yangcong)) { $this->view->setting = json_decode($this->config->site->yangcong); } $this->display(); }
/** * install * * @param int $webappID * @access public * @return void */ public function install($webappID) { $webapp = $this->getAppInfoByAPI($webappID); $webapp = $webapp->webapp; $open = $webapp->target == 'blank' ? 'blank' : 'iframe'; $maxOrder = $this->dao->select('`order`')->from(TABLE_ENTRY)->orderBy('order_desc')->limit(1)->fetch('order'); $entry = new stdclass(); /* Save webapp's icon. */ if (!empty($webapp->icon)) { $ext = explode('.', $webapp->icon); $extend = $ext[count($ext) - 1]; $fileName = md5(mt_rand(0, 10000) . str_shuffle(md5($webapp->icon)) . mt_rand(0, 10000)) . '.' . $extend; $dateInfo = date('Ym/', time()); /* mkdir if not exist. */ $savePath = $this->app->getDataRoot() . "upload/" . $dateInfo; if (!file_exists($savePath)) { @mkdir($savePath, 0777, true); } $savePath = $savePath . $fileName; $webPath = $this->app->getWebRoot() . 'data/upload/' . $dateInfo . $fileName; $icon = file_get_contents($this->config->webapp->url . $webapp->icon); file_put_contents($savePath, $icon); $entry->logo = $webPath; } $entry->code = $this->config->webapp->codePrefix . $webapp->id; $entry->name = $webapp->name; $entry->open = $open; $entry->login = $webapp->url; $entry->control = isset($webapp->control) ? $webapp->control : 'full'; $entry->position = isset($webapp->position) ? $webapp->position : 'center'; $entry->ip = '*'; $entry->visible = 0; $entry->buildin = 0; $entry->integration = 0; $entry->key = md5(time()); $entry->order = $maxOrder + 10; /* process size */ if ($open != 'blank') { $entry->size = $webapp->size == '0x0' ? 'max' : 'custom'; $size = explode('x', $webapp->size); if ($entry->size == 'custom') { $entry->size = helper::jsonEncode(array('width' => (int) $size[0], 'height' => (int) $size[1])); } } $this->app->loadConfig('entry'); $this->dao->insert(TABLE_ENTRY)->data($entry, $skip = 'files')->autoCheck()->batchCheck($this->config->entry->require->create, 'notempty')->check('code', 'unique')->check('code', 'code')->exec(); $this->addDownloadByAPI($webappID); if (dao::isError()) { return false; } return $webappID; }
/** * Set UI option with file. * * @param int $type * @param int $htmlTagName * @access public * @return void */ public function setOptionWithFile($section, $htmlTagName, $allowedFileType = 'jpg,jpeg,png,gif,bmp') { if (empty($_FILES)) { return array('result' => false, 'message' => $this->lang->ui->noSelectedFile); } $fileType = substr($_FILES['files']['name'], strrpos($_FILES['files']['name'], '.') + 1); if (strpos($allowedFileType, $fileType) === false) { return array('result' => false, 'message' => sprintf($this->lang->ui->notAlloweFileType, $allowedFileType)); } $fileModel = $this->loadModel('file'); if (!$this->file->checkSavePath()) { return array('result' => false, 'message' => $this->lang->file->errorUnwritable); } /* Delete old files. */ if ($section != 'logo') { $clientLang = $this->app->getClientLang(); $oldFiles = $this->dao->select('id')->from(TABLE_FILE)->where('objectType')->eq($section)->andWhere('lang')->eq($clientLang)->fetchAll('id'); foreach ($oldFiles as $file) { $fileModel->delete($file->id); } if (dao::isError()) { return array('result' => false, 'message' => $this->lang->fail); } } /* Upload new logo. */ $uploadResult = $fileModel->saveUpload($htmlTagName); if (!$uploadResult) { return array('result' => false, 'message' => $this->lang->fail); } $fileIdList = array_keys($uploadResult); $file = $fileModel->getById($fileIdList[0]); /* Save new data. */ $setting = new stdclass(); $setting->fileID = $file->id; $setting->pathname = $file->pathname; $setting->webPath = $file->webPath; $setting->addedBy = $file->addedBy; $setting->addedDate = $file->addedDate; if ($section == 'logo') { $device = helper::getDevice(); $template = $this->config->template->{$device}->name; $theme = $this->post->theme == 'all' ? 'all' : $this->config->template->{$device}->theme; $logo = isset($this->config->site->logo) ? json_decode($this->config->site->logo, true) : array(); if (!isset($logo[$template])) { $logo[$template] = array(); } $logo[$template]['themes'][$theme] = $setting; $result = $this->loadModel('setting')->setItems('system.common.site', array($section => helper::jsonEncode($logo))); } else { $result = $this->loadModel('setting')->setItems('system.common.site', array($section => helper::jsonEncode($setting))); } if ($result) { return array('result' => true); } return array('result' => false, 'message' => $this->lang->fail); }
/** * Init block when account use first. * * @param string $appName * @access public * @return bool */ public function initBlock($appName) { $this->app->loadLang('block', 'sys'); $blocks = $this->lang->block->default[$appName]; $account = $this->app->user->account; /* Mark this app has init. */ $this->loadModel('setting')->setItem("{$account}.{$appName}.common.blockInited", true); foreach ($blocks as $index => $block) { $block['order'] = $index; $block['app'] = $appName; $block['account'] = $account; $block['params'] = isset($block['params']) ? helper::jsonEncode($block['params']) : ''; if (!isset($block['source'])) { $block['source'] = $appName; } $this->dao->replace(TABLE_BLOCK)->data($block)->exec(); } return !dao::isError(); }
/** * Set device admin. * * @param string $device * @access public * @return void */ public function setDevice($device) { $this->session->set('device', $device); $template = $this->config->template->{$device}; if (isset($this->config->template->{$device}) and !is_object($this->config->template->{$device})) { $template = json_decode($this->config->template->{$device}); } $setting['name'] = $template->name; $setting['theme'] = $template->theme; $setting = helper::jsonEncode($setting); $result = $this->loadModel('setting')->setItems('system.common.template', array($device => $setting)); $this->locate($this->server->http_referer); }
/** * Fix Logo data when upgrade form 4.3.beta. * * @access public * @return bool */ public function fixLogo() { $logos = $this->dao->setAutoLang(false)->select('*')->from(TABLE_CONFIG)->where('section')->eq('logo')->fetchGroup('lang'); $logosForAllThemes = $this->dao->setAutoLang(false)->select('*')->from(TABLE_CONFIG)->where('`key`')->eq('logo')->fetchGroup('lang'); $logoSetting = array(); if (!empty($logos)) { foreach ($logos as $lang => $logoList) { if (isset($logosForAllThemes[$lang])) { $logoForAllThemes = $logosForAllThemes[$lang][0]; $logoSetting['default']['themes']['all'] = json_decode($logoForAllThemes->value); } foreach ($logoList as $logo) { $logoSetting['default']['themes'][$logo->key] = json_decode($logo->value); } $result = $this->loadModel('setting')->setItems('system.common.site', array('logo' => helper::jsonEncode($logoSetting)), $lang); if (!$result) { return false; } } } else { if (!empty($logosForAllThemes)) { foreach ($logosForAllThemes as $lang => $logoForAllTheme) { $logo = $logoForAllTheme[0]; $logoSetting['default']['themes']['all'] = json_decode($logo->value); $result = $this->loadModel('setting')->setItems('system.common.site', array('logo' => helper::jsonEncode($logoSetting)), $lang); if (!$result) { return false; } } } } return true; }
/** * Save message. * * @param int $public * @param object $data * @access public * @return void */ public function saveMessage($public, $data) { $message = new stdclass(); $message->public = $public; $message->wid = isset($data->msgId) ? $data->msgId : ''; $message->from = $data->fromUserName; $message->to = $data->toUserName; if (isset($data->response)) { $message->response = $data->response; } $message->type = $data->msgType; $message->content = isset($data->content) ? $data->content : helper::jsonEncode($data); if ($data->msgType == 'event') { $message->type = $data->event; $message->content = isset($data->eventKey) ? $data->eventKey : ''; } if (isset($data->event) && in_array($data->event, array('subscribe', 'unsubscribe', 'SCAN'))) { $message->content = isset($data->eventKey) ? $data->eventKey : $data->event; } $message->replied = isset($data->replied) ? $data->replied : 0; $message->time = helper::now(); $this->dao->insert(TABLE_WX_MESSAGE)->data($message)->autoCheck()->exec(); return !dao::isError(); }
/** * Sort blocks. * * @param string $template * @param string $theme * @param string $page * @param string $region * @param int $parent * @param string $orders * @access public * @return bool */ public function sortBlocks($template, $theme, $page, $region, $parent = 0, $orders = '') { $layout = $this->dao->select('*')->from(TABLE_LAYOUT)->where('page')->eq($page)->andWhere('region')->eq($region)->andWhere('template')->eq($template)->andWhere('theme')->eq($theme)->fetch(); $blocks = json_decode($layout->blocks); $orders = explode(',', $orders); if ($parent) { foreach ($blocks as $block) { if ($block->id == $parent) { $sortedBlocks = array(); foreach ($orders as $order) { foreach ($block->children as $child) { if ($child->id == $order) { $sortedBlocks[] = $child; } } } $block->children = $sortedBlocks; } } } else { $sortedBlocks = array(); foreach ($orders as $order) { foreach ($blocks as $block) { if ($block->id == $order) { $sortedBlocks[] = $block; } } } $blocks = $sortedBlocks; } $layout->blocks = helper::jsonEncode($blocks); $this->dao->replace(TABLE_LAYOUT)->data($layout)->exec(); return !dao::isError(); }
/** * Move base Style. * * @access public * @return void */ public function moveBaseStyle() { $template = $this->config->template; $setting = isset($this->config->template->custom) ? json_decode($this->config->template->custom, true) : array(); $setting[$template->name][$template->theme]['css'] = isset($this->config->site->basestyle) ? $this->config->site->basestyle : ''; return $this->loadModel('setting')->setItems('system.common.template', array('custom' => helper::jsonEncode($setting))); }
/** * Set device admin. * * @param string $device * @access public * @return void */ public function setDevice($device) { $this->session->set('device', $device); $template = $this->config->template->{$device}; if (isset($this->config->template->{$device}) and !is_object($this->config->template->{$device})) { $template = json_decode($this->config->template->{$device}); } $setting['name'] = $template->name; $setting['theme'] = $template->theme; $setting = helper::jsonEncode($setting); $result = $this->loadModel('setting')->setItems('system.common.template', array($device => $setting)); if ($result) { $this->send(array('result' => 'success', 'message' => $this->lang->setSuccess)); } $this->send(array('result' => 'fail', 'message' => $this->lang->fail)); }
/** * Custom theme. * * @param string $theme * @param string $template * @access public * @return void */ public function customTheme($theme = '', $template = '') { if (empty($template)) { $template = $this->config->template->name; } $templates = $this->ui->getTemplates(); if ($_POST) { if (isset($templates[$template]) && isset($templates[$template]['themes'][$theme])) { $cssFile = sprintf($this->config->site->ui->customCssFile, $template, $theme); $savePath = dirname($cssFile); if (!is_dir($savePath)) { mkdir($savePath, 0777, true); } file_put_contents($cssFile, $this->post->css); $setting = isset($this->config->template->custom) ? json_decode($this->config->template->custom, true) : array(); $postedSetting = fixer::input('post')->remove('template,theme,css')->get(); $setting[$template][$theme] = $postedSetting; $result = $this->loadModel('setting')->setItems('system.common.template', array('custom' => helper::jsonEncode($setting))); $this->loadModel('setting')->setItems('system.common.template', array('customVersion' => time())); $this->send(array('result' => 'success', 'message' => $this->lang->ui->themeSaved)); } } $setting = isset($this->config->template->custom) ? json_decode($this->config->template->custom, true) : array(); $this->view->setting = !empty($setting[$template][$theme]) ? $setting[$template][$theme] : array(); $this->view->title = "<i class='icon-cog'></i> " . $this->lang->ui->customtheme; $this->view->modalWidth = 1000; $this->view->theme = $theme; $this->view->template = $template; $this->display(); }
/** * Set style for entry. * * @param string $code * @access public * @return int */ public function setStyle($code) { $oldEntry = $this->getByCode($code); $entry = fixer::input('post')->get(); if ($entry->size == 'custom') { $entry->size = helper::jsonEncode(array('width' => (int) $entry->width, 'height' => (int) $entry->height)); } unset($entry->logo); $this->dao->update(TABLE_ENTRY)->data($entry, $skip = 'width,height,files')->autoCheck()->where('code')->eq($code)->exec(); return $oldEntry->id; }
/** * Set block of one region. * * @param string $page * @param string $region * @param string $template * @access public * @return void */ public function setRegion($page, $region, $template) { $layout = new stdclass(); $layout->page = $page; $layout->region = $region; $layout->template = $template; if (!$this->post->blocks) { $this->dao->delete()->from(TABLE_LAYOUT)->where('page')->eq($page)->andWhere('region')->eq($region)->andWhere('template')->eq($template)->exec(); if (!dao::isError()) { return true; } } $blocks = array(); foreach ($this->post->blocks as $key => $block) { $blocks[$key]['id'] = $block; $blocks[$key]['grid'] = $this->post->grid[$key]; $blocks[$key]['titleless'] = $this->post->titleless[$key]; $blocks[$key]['borderless'] = $this->post->borderless[$key]; } /* Compute children blocks. */ if ($this->post->parent) { $parents = (array) $this->post->parent; foreach ($parents as $key => $parent) { $children[$parent][] = $key; } foreach ($blocks as $key => $block) { if (empty($children[$key])) { continue; } foreach ($children[$key] as $child) { $blocks[$key]['children'][] = $blocks[$child]; unset($blocks[$child]); } } } /* Clear blocks keys. */ $sortedBlocks = array(); foreach ($blocks as $key => $block) { $sortedBlocks[] = $block; } $layout->blocks = helper::jsonEncode($sortedBlocks); $count = $this->dao->select('count(*) as count')->from(TABLE_LAYOUT)->where('page')->eq($page)->andWhere('region')->eq($region)->andWhere('template')->eq($template)->fetch('count'); if ($count) { $this->dao->update(TABLE_LAYOUT)->data($layout)->where('page')->eq($page)->andWhere('region')->eq($region)->andWhere('template')->eq($template)->exec(); } if (!$count) { $this->dao->insert(TABLE_LAYOUT)->data($layout)->exec(); } return !dao::isError(); }
/** * Merge custom. * * @param object $info * @access public * @return void */ public function mergeCustom($info) { $importedCustom = $this->dao->setAutoLang(false)->select('*')->from(TABLE_CONFIG)->where('lang')->eq('imported')->andWhere('`key`')->eq('custom')->fetch('value'); $custom = json_decode($importedCustom, true); $setting = isset($this->config->template->custom) ? json_decode($this->config->template->custom, true) : array(); if (isset($custom[$info->template][$info->theme])) { $setting[$info->template][$info->code] = $custom[$info->template][$info->theme]; } $this->loadModel('setting')->setItems('system.common.template', array('custom' => helper::jsonEncode($setting))); $this->dao->delete()->from(TABLE_CONFIG)->where('lang')->eq('imported')->andWhere('`key`')->eq('custom')->exec(); }
/** * Update an account. * * @param string $account * @access public * @return void */ public function update($account) { $oldUser = $this->getByAccount($account); /* If the user want to change his password. */ if ($this->post->password1 != false) { if (RUN_MODE == 'front') { $this->checkOldPassword(); } $this->checkPassword(); if (dao::isError()) { return false; } $password = $this->createPassword($this->post->password1, $account); $this->post->set('password', $password); } $user = fixer::input('post')->cleanInt('imobile, qq, zipcode')->setDefault('admin', 'no')->setIF(RUN_MODE == 'admin' and $this->post->admin != 'super', 'realnames', '')->remove('ip, account, join, visits, fingerprint, token')->removeIF(RUN_MODE != 'admin', 'admin')->removeIF(RUN_MODE == 'admin', 'groups')->removeIF(RUN_MODE == 'front', 'email')->get(); if (RUN_MODE == 'admin') { if ($user->admin == 'common') { $this->dao->delete()->from(TABLE_USERGROUP)->where('account')->eq($account)->exec(); if ($this->post->groups) { foreach ($this->post->groups as $group) { $data = new stdclass(); $data->account = $account; $data->group = $group; $this->dao->insert(TABLE_USERGROUP)->data($data)->exec(); } } } if ($user->admin == 'no') { $this->dao->delete()->from(TABLE_USERGROUP)->where('account')->eq($account)->exec(); } } if (RUN_MODE == 'admin' and $user->email != $oldUser->email) { $user->emailCertified = 0; } if (isset($user->admin) and $user->admin == 'super' or !empty($user->realnames)) { $user->realnames = helper::jsonEncode($user->realnames); $this->config->user->require->edit = 'realnames'; } $this->dao->update(TABLE_USER)->setAutolang(false)->data($user, $skip = 'token,oldPwd,password1,password2')->autoCheck()->batchCheck($this->config->user->require->edit, 'notempty')->checkIF($this->post->gtalk != false, 'gtalk', 'email')->beginIF(RUN_MODE == 'admin')->check('email', 'email')->check('email', 'unique', "account!='{$account}'")->fi()->where('account')->eq($account)->exec(); return !dao::isError(); }
/** * Update a slide. * * @param int $id * @access public * @return bool */ public function update($id) { $image = $this->uploadImage(); $slide = fixer::input('post')->stripTags('summary', $this->config->allowedTags->front)->setIf(!empty($image), 'image', $image)->remove('files')->get(); if ($slide->backgroundType == 'color') { $this->dao->insert('slide')->data($slide, 'label,buttonClass,buttonUrl,buttonTarget')->batchCheck($this->config->slide->require->edit, 'notempty')->check('height', 'ge', 100); if (dao::isError()) { return false; } } $slide->label = array_values($slide->label); $slide->buttonClass = array_values($slide->buttonClass); $slide->buttonUrl = array_values($slide->buttonUrl); $slide->buttonTarget = array_values($slide->buttonTarget); $slide->createdDate = time(); $this->dao->update(TABLE_CONFIG)->set('value')->eq(helper::jsonEncode($slide))->where('id')->eq($id)->exec(); return !dao::isError(); }
/** * Update a slide. * * @param int $id * @access public * @return bool */ public function update($id) { $slide = $this->getByID($id); $image = $this->uploadImage($slide->group); $data = fixer::input('post')->stripTags('summary', $this->config->allowedTags->front)->setIf(!empty($image), 'image', $image)->remove('files')->get(); $data->label = helper::jsonEncode(array_values($data->label)); $data->buttonClass = helper::jsonEncode(array_values($data->buttonClass)); $data->buttonUrl = helper::jsonEncode(array_values($data->buttonUrl)); $data->buttonTarget = helper::jsonEncode(array_values($data->buttonTarget)); $this->dao->update(TABLE_SLIDE)->data($data, $skip = 'uid')->batchCheckIF($this->post->backgroundType == 'color', $this->config->slide->require->create, 'notempty')->checkIF($this->post->backgroundType == 'color', 'height', 'ge', 100)->where('id')->eq($id)->exec(); if ($image) { $pathname = str_replace('/data/', '', $image); $this->dao->update(TABLE_FILE)->set('objectID')->eq($id)->where('pathname')->eq($pathname)->exec(); } return !dao::isError(); }
/** * Process block type. * * @access public * @return bool */ public function processBlockType() { $blocksHasType = 'order,contract,customer,task,project,thread'; $blocks = $this->dao->select('*')->from(TABLE_BLOCK)->where('block')->in($blocksHasType)->fetchAll(); foreach ($blocks as $block) { $block->params = json_decode($block->params); if ($block->block == 'project') { if (!isset($block->params->status)) { $block->params->status = 'doing'; $params = helper::jsonEncode($block->params); $this->dao->update(TABLE_BLOCK)->set('params')->eq($params)->where('id')->eq($block->id)->exec(); } } else { if (!isset($block->params->type)) { if ($block->block == 'order') { $block->params->type = 'assignedTo'; } if ($block->block == 'contract') { $block->params->type = 'returnedBy'; } if ($block->block == 'customer') { $block->params->type = 'today'; } if ($block->block == 'task') { $block->params->type = 'assignedTo'; } if ($block->block == 'thread') { $block->params->type = 'new'; } $params = helper::jsonEncode($block->params); $this->dao->update(TABLE_BLOCK)->set('params')->eq($params)->where('id')->eq($block->id)->exec(); } } } return !dao::isError(); }