Пример #1
0
 /**
  * The main function for converting to an XML document.
  * Pass in a multi dimensional array and this recrusively loops through and builds up an XML document.
  *
  * @param array $data
  * @param string $rootNodeName - what you want the root node to be - defaultsto data.
  * @param SimpleXMLElement $xml - should only be used recursively
  * @return string XML
  */
 public static function toXml($data, $rootNodeName = 'data', &$xml = null)
 {
     // turn off compatibility mode as simple xml throws a wobbly if you don't.
     if (@ini_get('zend.ze1_compatibility_mode') == 1) {
         @ini_set('zend.ze1_compatibility_mode', 0);
     }
     if (is_null($xml)) {
         $xml = @simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><{$rootNodeName} />");
     }
     // loop through the data passed in.
     foreach ($data as $key => $value) {
         // if numeric key, assume array of rootNodeName elements
         if (is_numeric($key)) {
             $key = $rootNodeName;
         }
         // delete any char not allowed in XML element names
         $key = preg_replace('/[^a-z0-9\\-\\_\\.\\:]/i', '', $key);
         // if there is another array found recrusively call this function
         if (is_array($value)) {
             // create a new node unless this is an array of elements
             $node = Gio_Core_Array::isAssoc($value) ? $xml->addChild($key) : $xml;
             // recrusive call - pass $key as the new rootNodeName
             Gio_Core_Array::toXml($value, $key, $node);
         } else {
             // add single node.
             $value = utf8_encode($value);
             $node = $xml->addChild($key, $value);
         }
     }
     // pass back as string. or simple xml object if you want!
     return $xml->asXML();
 }
Пример #2
0
 public function layoutAction()
 {
     $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->pageData = $page;
     $blocksData = array();
     $dataFile = TEMPLATE_DIR . DS . $template . DS . 'data' . DS . $page['route'] . '.xml';
     if (file_exists($dataFile)) {
         $blocksData = Modules_Core_Services_Page::importXml($dataFile);
     }
     $this->view->blocksData = $blocksData;
     if ($request->isPost()) {
         $this->setNoRender();
         $this->disableLayout();
         $blocks = $request->getPost('blocks');
         $newBlocks = array();
         if ($blocks) {
             foreach ($blocks as $index => $block) {
                 if (isset($block['type']) && $block['type'] == 'widget') {
                     $block['action'] = 'show';
                 } else {
                     $block['type'] = 'action';
                 }
                 $block['load'] = isset($block['load']) && $block['load'] == 'ajax' ? 'ajax' : 'php';
                 $block['cache']['enable'] = isset($block['cache']['enable']) && $block['cache']['enable'] == 'true' ? 'true' : 'false';
                 $block['cache']['timeout'] = isset($block['cache']['timeout']) && $block['cache']['timeout'] > 0 ? $block['cache']['timeout'] : 0;
                 $newBlocks['block'][] = $block;
             }
         }
         $content = utf8_decode(Gio_Core_Array::toXml($newBlocks, 'pages'));
         Gio_Core_File::writeToFile($dataFile, $content);
         $this->getResponse()->setBody('RESULT_OK');
         return;
     }
     $layoutFile = TEMPLATE_DIR . DS . $template . DS . 'layouts' . DS . $page['route'] . '.phtml';
     if (!file_exists($layoutFile)) {
         return;
     }
     $blocks = Modules_Core_Services_Page::import($layoutFile);
     $this->view->blocks = $blocks;
 }
Пример #3
0
 /**
  * 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);
 }
Пример #4
0
 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;
         }
     }
 }
Пример #5
0
 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;
         }
     }
 }