public function configAction() { $request = $this->getRequest(); $languagesFile = ROOT_DIR . DS . 'configs' . DS . 'languages.xml'; if (!file_exists($languagesFile)) { return; } $languagesXml = @simplexml_load_file($languagesFile); if (null == $languagesXml) { return; } $locales = array(); foreach ($languagesXml->language as $language) { $arr = explode('|', $language); $locales[$arr[0]] = array('code' => $arr[0], 'localName' => $arr[1], 'englishName' => $arr[2]); } $this->view->locales = $locales; $this->view->availableLanguages = array(); $configs = Gio_Core_Config_Xml::getConfig(); $this->view->configs = $configs; $default = isset($configs->localization->languages->default) ? $configs->localization->languages->default : $configs->web->language; $available = isset($configs->localization->languages->list) ? explode(',', $configs->localization->languages->list) : array($default); $this->view->availableLanguages = $available; if ($request->isPost()) { $localizationEenable = $request->getPost('localization_enable') != null ? 'true' : 'false'; $default = $request->getPost('default_language'); $available = $request->getPost('supported_languages'); $listLangs = array($default); if ($available != null) { foreach ($available as $index => $locale) { if ($locale != $default) { $listLangs[] = $locale; } } } $configs->web->language = $default; $configs->localization->enable = $localizationEenable; $configs->localization->languages->default = $default; $configs->localization->languages->list = implode(',', $listLangs); /** * Reset language details */ $configs->localization->languages->details = null; foreach ($listLangs as $lang) { $configs->localization->languages->details->{$lang} = implode('|', array($locales[$lang]['code'], $locales[$lang]['localName'], $locales[$lang]['englishName'])); } $configFile = Gio_Core_Config_Xml::getConfigFile(); $content = $configs->asXML(); $fileName = Gio_Core_Config_Xml::getConfigFile(); Gio_Core_File::writeToFile($fileName, $content); Gio_Core_Messenger::getInstance()->addMessage($this->view->TRANSLATOR->translator('locale_actions_config_success')); $this->redirect($this->view->url('core_locale_config')); } }
public function setAction() { $request = $this->getRequest(); $this->disableLayout(); $this->setNoRender(); $templateName = $request->getPost('template_id'); if (!$request->isPost() || !$templateName) { $this->getResponse()->setBody('RESULT_NOT_OK'); } $configs = Gio_Core_Config_Xml::getConfig(); $configs->web->template = $templateName; $content = $configs->asXML(); $fileName = Gio_Core_Config_Xml::getConfigFile(); Gio_Core_File::writeToFile($fileName, $content); $this->getResponse()->setBody('RESULT_OK'); }
public static function add($page) { $conn = Gio_Db_Connection::getConnection(); $pageDao = new Modules_Core_Models_Mysql_Page(); $pageDao->setConnection($conn); /** * Create route layout */ $configs = Gio_Core_Config_Xml::getConfig('web'); $filename = $page['route'] . '.phtml'; $file = TEMPLATE_DIR . DS . $configs->template . DS . 'layouts' . DS . $filename; $content = null; if (file_exists($file)) { $content = file_get_contents($file); } Gio_Core_File::writeToFile($file, $content); return $pageDao->add($page); }
/** * Save mail server configurations * * @param array $data */ public static function saveConfig($data) { $config = self::getConfig(); $protocol = $data['protocol']['protocol']; $config['protocol']['protocol'] = $protocol; switch ($protocol) { case 'mail': if (isset($config['smtp'])) { unset($config['smtp']); } break; case 'smtp': $host = $data['smtp']['host']; if ($host == null || $host == '') { unset($config['smtp']['host']); } else { $config['smtp']['host'] = $host; } $port = $data['smtp']['port']; if ($port == null || $port == '') { unset($config['smtp']['port']); } else { $config['smtp']['port'] = $port; } if ($data['authentication'] == 'true') { $config['smtp']['username'] = $data['smtp']['username']; $config['smtp']['password'] = $data['smtp']['password']; } else { unset($config['smtp']['username']); unset($config['smtp']['password']); } $security = $data['smtp']['security']; if ($security != 'none') { $config['smtp']['security'] = $security; } break; } $content = Gio_Core_Array::toIni($config, true); /** * Write file */ $fileName = MOD_DIR . DS . 'mail' . DS . 'configs' . DS . 'config.ini'; return Gio_Core_File::writeToFile($fileName, $content); }
/** * Get available languages * * @return array */ public static function getAvailableLanguages() { $languages = array(); /** * Get the list of modules */ $modules = Gio_Core_File::getSubDir(ROOT_DIR . DS . 'modules'); $numModules = count($modules); foreach ($modules as $module) { $moduleDir = ROOT_DIR . DS . 'modules' . DS . $module . DS . 'languages'; if (!file_exists($moduleDir)) { continue; } /** * Get list of language files in module */ $dirIterator = new DirectoryIterator($moduleDir); foreach ($dirIterator as $dir) { if (!$dir->isDot() && !$dir->isDir()) { $file = $dir->getFilename(); $sections = explode('.', $file); $lang = $sections[1]; $languages[$lang][] = $module; } } } foreach ($languages as $lang => $modules) { if (count($modules) == $numModules) { if (isset(self::$LANGUAGES[$lang])) { $languages[$lang] = self::$LANGUAGES[$lang]; } else { $languages[$lang] = array('englishName' => $lang, 'localName' => $lang); } } else { unset($languages[$lang]); } } return $languages; }
public function configAction() { $request = $this->getRequest(); $configs = Gio_Core_Config_Xml::getConfig(); $this->view->configs = $configs; $languagesFile = ROOT_DIR . DS . 'configs' . DS . 'languages.xml'; if (!file_exists($languagesFile)) { return; } $languagesXml = @simplexml_load_file($languagesFile); if (null == $languagesXml) { return; } $locales = array(); foreach ($languagesXml->language as $language) { $arr = explode('|', $language); $locales[$arr[0]] = array('code' => $arr[0], 'localName' => $arr[1], 'englishName' => $arr[2]); } $this->view->locales = $locales; if ($request->isPost()) { $act = $request->getPost('act'); switch ($act) { case 'testdbconn': $this->setNoRender(); $this->disableLayout(); $this->_testdbconn(); break; default: $version = isset($configs->install->version) ? $configs->install->version : Gio_Core_Cms::getVersion(); $date = isset($configs->install->date) ? $configs->install->date : date('Y-m-d H:i:s'); $author = isset($configs->install->author) ? (array) $configs->install->author : Gio_Core_Cms::getAuthor(); $localization = array('localization' => array('enable' => (string) $configs->localization->enable, 'languages' => array('default' => (string) $configs->localization->languages->default, 'list' => (string) $configs->localization->languages->list, 'details' => array()))); $timezone = array('timezone' => array('date' => (string) $configs->timezone->date, 'datetime' => (string) $configs->timezone->datetime)); if ($configs->localization->languages->list != null) { $list = explode(',', $configs->localization->languages->list); foreach ($list as $value) { $localization['localization']['languages']['details'][$value] = (string) $configs->localization->languages->details->{$value}; } } $configs = $request->getPost('configs'); $localization['localization']['languages']['default'] = $configs['web']['language']; $data = Modules_Core_Services_Installer::validate($configs); if (isset($data['messages_error']) && $data['messages_error']) { $this->view->errorMessages = $data['messages']; $configs = Gio_Core_Array::toObject($configs); $this->view->configs = $configs; return; } $install = array('install' => array('version' => $version, 'date' => $date, 'author' => $author)); $configs = array_merge($configs, $install); $configs = array_merge($configs, $localization); $configs = array_merge($configs, $timezone); $content = utf8_decode(Gio_Core_Array::toXml($configs, 'config')); $fileName = Gio_Core_Config_Xml::getConfigFile(); Gio_Core_File::writeToFile($fileName, $content); Gio_Core_Messenger::getInstance()->addMessage($this->view->TRANSLATOR->translator('website_actions_config_success')); $this->redirect($this->view->url('core_website_config')); break; } } }
public function contentAction() { $request = $this->getRequest(); $template = $request->getParam('template_id'); $this->view->template = $template; $pageId = $request->getParam('page_id'); $page = Modules_Core_Services_Page::getById($pageId); if (null == $page) { return; } $page['template_id'] = $template; $this->view->page = $page; $templateFile = TEMPLATE_DIR . DS . $template . DS . 'layouts' . DS . $page['route'] . '.phtml'; if (!file_exists($templateFile)) { throw new Exception(''); } if ($request->isPost()) { $this->setNoRender(); $this->disableLayout(); $content = $request->getPost('content'); Gio_Core_File::writeToFile($templateFile, $content); $this->getResponse()->setBody('RESULT_OK'); return; } $content = file_get_contents($templateFile); $this->view->content = $content; }
public function uploadAction() { $this->disableLayout(); $this->setNoRender(); $request = $this->getRequest(); if (!$request->isPost()) { exit; } /** * Authentication */ $phpSessionId = $request->getPost('PHPSESSID'); $session = Gio_Core_Session::getSessionById($phpSessionId); $json = new Services_JSON(); $user = null == $session || null == $session['data'] ? null : $json->decode($session['data']); if (null == $user) { return; } /** * Get config */ $configFile = MOD_DIR . DS . 'upload' . DS . 'configs' . DS . 'config.ini'; $iniArray = @parse_ini_file($configFile, true); $tool = isset($iniArray['thumbnail']['tool']) ? $iniArray['thumbnail']['tool'] : 'gd'; $sizes = array(); foreach ($iniArray['size'] as $key => $value) { list($method, $width, $height) = explode('_', $value); $sizes[$key] = array('method' => $method, 'width' => $width, 'height' => $height); } $user = (array) $user; $userName = $user['username']; $module = $request->getPost('mod'); $thumbnailSizes = $request->getPost('thumbnails', null); /** * Prepare folders */ $dir = ROOT_DIR . DS . 'upload'; $path = implode(DS, array($module, $userName, date('Y'), date('m'))); Gio_Core_File::createDirs($dir, $path); /** * Upload file */ $ext = explode('.', $_FILES['Filedata']['name']); $extension = $ext[count($ext) - 1]; unset($ext[count($ext) - 1]); $fileName = date('YmdHis_') . implode('', $ext); $file = $dir . DS . $path . DS . $fileName . '.' . $extension; move_uploaded_file($_FILES['Filedata']['tmp_name'], $file); /** * Water mark * @since 2.0.4 */ $watermark = $request->getParam('watermark'); $overlayText = $color = $overlayImage = $position = $sizesApplied = null; if ((bool) $watermark) { $overlayText = $request->getParam('text'); $color = $request->getParam('color'); $overlayImage = $request->getParam('image'); $position = $request->getParam('position'); $sizesApplied = $request->getParam('sizes'); $sizesApplied = explode(',', $sizesApplied); } /** * Generate thumbnails if requested */ if (!isset($thumbnailSizes) || $thumbnailSizes == null) { $thumbnailSizes = array_keys($sizes); } else { if ($thumbnailSizes != 'none') { $thumbnailSizes = explode(',', $thumbnailSizes); } } $service = null; switch (strtolower($tool)) { case 'imagemagick': $service = new Gio_Image_ImageMagick(); break; case 'gd': $service = new Gio_Image_GD(); break; } $ret = array(); /** * Remove script filename from base URL */ $baseUrl = $request->getBaseUrl(); $prefixUrl = rtrim($baseUrl, '/') . '/upload/' . $module . '/' . $userName . '/' . date('Y') . '/' . date('m'); $ret['original'] = array('url' => $prefixUrl . '/' . $fileName . '.' . $extension, 'size' => null); if ($thumbnailSizes != 'none') { $service->setFile($file); $ret['original']['size'] = $service->getWidth() . ' x ' . $service->getHeight(); foreach ($thumbnailSizes as $s) { $service->setFile($file); $method = $sizes[$s]['method']; $width = $sizes[$s]['width']; $height = $sizes[$s]['height']; $f = $fileName . '_' . $s . '.' . $extension; $newFile = $dir . DS . $path . DS . $f; /** * Create thumbnail */ switch ($method) { case 'resize': $service->resizeLimit($newFile, $width, $height); break; case 'crop': $service->crop($newFile, $width, $height); break; } /** * Create watermark if requested */ if ((bool) $watermark) { $service->setWatermarkFont(ROOT_DIR . DS . 'data' . DS . 'upload' . DS . self::WATERMARK_FONT); $service->setFile($newFile); if ($overlayText && in_array($s, $sizesApplied)) { $service->watermarkText($overlayText, $position, array('color' => $color, 'rotation' => 0, 'opacity' => 50, 'size' => null)); } if ($overlayImage && in_array($s, $sizesApplied)) { $overlay = explode('/', $overlayImage); $n = count($overlay); $overlay = implode(DS, array($dir, 'multimedia', $overlay[$n - 4], $overlay[$n - 3], $overlay[$n - 2], $overlay[$n - 1])); $service->watermarkImage($overlay, $position); } } $ret[$s] = array('url' => $prefixUrl . '/' . $f, 'size' => $width . ' x ' . $height); } } /** * Return the reponse */ $json = new Services_JSON(); $this->getResponse()->setBody($json->encodeUnsafe($ret)); }
/** * Perform install actions * * @param bool $importSampleData * @return bool */ public static function install($importSampleData = false, $adminInfo = array()) { try { $view = Gio_Core_View::getInstance(); $moduleDirs = Gio_Core_File::getSubDir(ROOT_DIR . DS . 'modules'); /** * Install modules */ $modules = array(); foreach ($moduleDirs as $module) { $modules[] = Modules_Core_Services_Module::install($module); } foreach ($modules as $module) { if ($module) { Modules_Core_Services_Module::add($module); } } /** * Install widgets */ foreach ($moduleDirs as $module) { /** * Load all widgets from module */ $widgetDirs = Gio_Core_File::getSubDir(ROOT_DIR . DS . 'modules' . DS . $module . DS . 'widgets'); foreach ($widgetDirs as $widgetName) { $widget = array('module_id' => $module, 'widget_id' => $widgetName, 'title' => $view->TRANSLATOR->widget('about_title', $module, $widgetName), 'description' => $view->TRANSLATOR->widget('about_description', $module, $widgetName), 'created_date' => date('Y-m-d H:i:s')); Modules_Core_Services_Widget::add($widget); } } /** * Create resources and previleges */ foreach ($moduleDirs as $module) { $file = ROOT_DIR . DS . 'modules' . DS . $module . DS . 'configs' . DS . 'permissions.xml'; if (!file_exists($file)) { continue; } $xml = simplexml_load_file($file); foreach ($xml->controller as $res) { $attr = $res->attributes(); $langKey = (string) $attr['langKey']; $description = $view->TRANSLATOR->translator($langKey, $module); $description = $description == $langKey ? (string) $attr['description'] : $description; $resource = array('controller_id' => $attr['name'], 'description' => $description, 'module_id' => $module, 'created_date' => date('Y-m-d H:i:s')); /** * Add resource */ Modules_Core_Services_Controller::add($resource); if ($res->action) { foreach ($res->action as $pri) { $attr2 = $pri->attributes(); $langKey = (string) $attr2['langKey']; $description = $view->TRANSLATOR->translator($langKey, $module); $description = $description == $langKey ? (string) $attr2['description'] : $description; $privilege = array('controller_id' => $attr['name'], 'description' => $description, 'module_id' => $module, 'action_id' => $attr2['name'], 'created_date' => date('Y-m-d H:i:s')); Modules_Core_Services_Action::add($privilege); } } } } /** * Finally, init data */ $dbFile = ROOT_DIR . DS . 'install' . DS . 'db.xml'; if (file_exists($dbFile)) { $xml = simplexml_load_file($dbFile); $xpath = $xml->xpath('module/query'); if (is_array($xpath) && count($xpath) > 0) { $conn = Gio_Db_Connection::getConnection(); foreach ($xpath as $query) { $q = str_replace('###table_prefix###', $conn->_tablePrefix, (string) $query); $conn->query($q); } } } /** * Allows user to import sample data */ if ($importSampleData) { $file = ROOT_DIR . DS . 'install' . DS . 'giocms_sample_db.sql'; $importer = Gio_Core_Import_Importer::getInstance(); if ($importer != null && $file != null) { $importer->import($file); } } /** * Create admin user */ $salt = md5(time()); $user = array('username' => $adminInfo['username'], 'password' => md5(md5($adminInfo['password']) . $salt), 'email' => $adminInfo['email'], 'fullname' => $adminInfo['fullname'], 'salt' => $salt, 'status' => 'active', 'created_date' => date('Y-m-d H:i:s'), 'role_id' => 1); Modules_Core_Services_User::add($user); } catch (Exception $ex) { return false; } return true; }
public function loadAction() { $request = $this->getRequest(); if (!$request->isPost()) { return; } $this->view->editor = 'ckeditor'; $module = $request->getPost('mod'); $widgetName = $request->getPost('name'); $this->view->module = $module; $this->view->widgetName = $widgetName; $pageIndex = $request->getPost('page'); $pageIndex = $pageIndex ? $pageIndex : 1; $perPage = 30; $offset = ($pageIndex - 1) * $perPage; $this->view->start = $offset; $this->view->end = $offset + $perPage; $sizes = null; $this->view->sizes = null; $params = $request->getPost('params'); $json = new Services_JSON(); $params = $json->decode($params); $path = isset($params->path) ? $params->path : null; $path = $path ? base64_decode(rawurldecode($path)) : null; $path = trim($path, DS); $style = isset($params->style) ? $params->style : null; $style = $style ? $style : 'list'; $fullPath = ROOT_DIR . DS . $path; $this->view->fullPath = $fullPath; if (!file_exists($fullPath)) { $fullPath = ROOT_DIR; $path = null; } $dirIterator = new DirectoryIterator($fullPath); $dirs = $files = array(); foreach ($dirIterator as $obj) { if ($obj->isDot()) { continue; } $name = $obj->getFilename(); if ('CVS' == $name || '.svn' == strtolower($name)) { continue; } if ($obj->isDir()) { $dir = array(); $dir['name'] = $name; $dir['size'] = Gio_Core_File::formatFileSize(Gio_Core_File::getDirSize($fullPath . DS . $name)); $dir['modified'] = null; $dir['is_dir'] = true; $dirs[] = $dir; } else { $file = array(); $file['name'] = $name; $file['size'] = Gio_Core_File::formatFileSize(@filesize($fullPath . DS . $name)); $file['modified'] = @filemtime($fullPath . DS . $name); $file['is_dir'] = false; $files[] = $file; } } $data = array_merge($dirs, $files); $breakcrumb = $path ? explode(DS, $path) : array(''); $this->view->breakcrumb = $breakcrumb; $upDir = null; if ($path) { array_pop($breakcrumb); $upDir = implode(DS, $breakcrumb); } // $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array($data)); // $paginator->setCurrentPageNumber($pageIndex)->setItemCountPerPage($perPage); // // $this->_view->paginator = $paginator; // $this->_view->paginatorOptions = array( // 'path' => '', // 'itemLink' => "javascript: Tomato.Upload.Widgets.FileToolbox.loadWidgets('" // . $this->_view->directoryBuilder()->getPathLink($path) . "', %d, '" . $style . "')", // ); $this->view->path = $path; $this->view->style = $style; $this->view->data = $data; $viewFilePath = ROOT_DIR . DS . 'modules' . DS . $module . DS . 'widgets' . DS . $widgetName; $response = null; switch ($style) { case 'grid': $response = $this->view->render($viewFilePath . DS . '_grid.phtml'); break; case 'list': default: $response = $this->view->render($viewFilePath . DS . '_list.phtml'); break; } $this->view->response = $response; }
public function step1Action() { /** * Remove all plugins */ Gio_Core_Application::getInstance()->removePlugins(); if (Gio_Core_Application::_initInstallChecker()) { $this->redirect($this->view->url('core_index_index')); } $this->setTemplate('admin'); $this->setLayout('install'); $request = $this->getRequest(); $configs = Gio_Core_Config_Xml::getConfig(); $request = Gio_Core_Request::getInstance(); if ((string) $configs->web->url != $request->getBaseUrl()) { $configs->server->static = $request->getBaseUrl(); $configs->server->resource = $request->getBaseUrl(); $configs->web->url = $request->getBaseUrl(); } $this->view->configs = $configs; $timezone = array('timezone' => array('date' => (string) $configs->timezone->date, 'datetime' => (string) $configs->timezone->datetime)); $localization = array('localization' => array('enable' => (string) $configs->localization->enable, 'languages' => array('default' => (string) $configs->localization->languages->default, 'list' => (string) $configs->localization->languages->list, 'details' => array()))); if ($configs->localization->languages->list != null) { $list = explode(',', $configs->localization->languages->list); foreach ($list as $value) { $localization['localization']['languages']['details'][$value] = (string) $configs->localization->languages->details->{$value}; } } $languagesFile = ROOT_DIR . DS . 'configs' . DS . 'languages.xml'; if (!file_exists($languagesFile)) { return; } $languagesXml = @simplexml_load_file($languagesFile); if (null == $languagesXml) { return; } $locales = array(); foreach ($languagesXml->language as $language) { $arr = explode('|', $language); $locales[$arr[0]] = array('code' => $arr[0], 'localName' => $arr[1], 'englishName' => $arr[2]); } $this->view->locales = $locales; if ($request->isPost()) { $act = $request->getPost('act'); switch ($act) { case 'testdbconn': $this->setNoRender(); $this->disableLayout(); $this->_testdbconn(); break; case '': default: $configs = $request->getPost('configs'); $data = Modules_Core_Services_Installer::validate($configs); if (isset($data['messages_error']) && $data['messages_error']) { $this->view->errorMessages = $data['messages']; $configs = Gio_Core_Array::toObject($configs); $this->view->configs = $configs; return; } $install = array('install' => array('version' => Gio_Core_Cms::getVersion(), 'date' => date('Y-m-d H:i:s'), 'author' => Gio_Core_Cms::getAuthor())); $configs = array_merge($configs, $install); $configs = array_merge($configs, $localization); $configs = array_merge($configs, $timezone); $content = utf8_decode(Gio_Core_Array::toXml($configs, 'config')); $fileName = Gio_Core_Config_Xml::getConfigFile(); Gio_Core_File::writeToFile($fileName, $content); $adminInfo = array('username' => 'admin', 'password' => '123456', 'email' => '*****@*****.**', 'fullname' => 'Ninhgio'); Modules_Core_Services_Installer::install(false, $adminInfo); $this->redirect($this->view->url('core_index_index')); break; } } }