Example #1
0
 public function updateConfig()
 {
     ipRequest()->mustBePost();
     $configModel = ConfigModel::instance();
     $form = $configModel->getThemeConfigForm(ipConfig()->theme());
     $post = ipRequest()->getPost();
     $errors = $form->validate($post);
     if ($errors) {
         return JsonRpc::error('Invalid form');
     }
     $configModel = ConfigModel::instance();
     $model = Model::instance();
     $theme = $model->getTheme(ipConfig()->theme());
     if (!$theme) {
         throw new \Ip\Exception("Theme doesn't exist");
     }
     $options = $theme->getOptionsAsArray();
     $valuesToStore = array();
     foreach ($options as $option) {
         if (empty($option['name'])) {
             continue;
         }
         $field = $form->getField($option['name']);
         if (!$field) {
             continue;
         }
         switch ($option['type']) {
             case 'checkbox':
                 /**
                  * @var \Ip\Form\Field\Checkbox $field
                  */
                 $value = $field->isChecked($post, $option['name']);
                 break;
             case 'RepositoryFile':
                 $value = '';
                 if (!empty($post[$option['name']][0])) {
                     $value = $post[$option['name']][0];
                 }
                 break;
             default:
                 $value = $field->getValueAsString($post, $option['name']);
         }
         $valuesToStore[$option['name']] = $value;
     }
     $valuesToStore = ipFilter('ipDesignOptionsSave', $valuesToStore);
     foreach ($valuesToStore as $key => $value) {
         $configModel->setConfigValue(ipConfig()->theme(), $key, $value);
     }
     $lessCompiler = LessCompiler::instance();
     $lessCompiler->rebuild(ipConfig()->theme());
     \Ip\Internal\Core\Service::invalidateAssetCache();
     ipAddJsVariable('ipModuleDesignConfiguration', Helper::getConfigurationBoxHtml());
     return JsonRpc::result(true);
 }
Example #2
0
 /**
  * @param string $name
  * @return \Ip\Form
  * @throws \Ip\Exception
  */
 public function getThemeConfigForm($name)
 {
     $model = Model::instance();
     $theme = $model->getTheme($name);
     if (!$theme) {
         throw new \Ip\Exception("Theme doesn't exist");
     }
     $form = new \Ip\Form();
     $form->setEnvironment(\Ip\Form::ENVIRONMENT_ADMIN);
     $form->addClass('ipsForm');
     $options = $theme->getOptions();
     $generalFieldset = $this->getFieldset($name, $options);
     $generalFieldset->setLabel(__('General options', 'Ip-admin'));
     if (count($generalFieldset->getFields())) {
         $form->addFieldset($generalFieldset);
     }
     foreach ($options as $option) {
         if (empty($option['type']) || empty($option['options'])) {
             continue;
         }
         if ($option['type'] != 'group') {
             continue;
         }
         $fieldset = $this->getFieldset($name, $option['options']);
         if (!empty($option['label'])) {
             $fieldset->setLabel($option['label']);
         }
         $form->addFieldset($fieldset);
     }
     $form->addFieldset(new \Ip\Form\Fieldset());
     $field = new Form\Field\Hidden();
     $field->setName('aa');
     $field->setValue('Design.updateConfig');
     $form->addField($field);
     return $form;
 }
Example #3
0
 public static function sendUsageStatistics($data = array(), $timeout = 3)
 {
     if (!function_exists('curl_init')) {
         return;
     }
     if (!isset($data['action'])) {
         $data['action'] = 'Ping.default';
     }
     if (!isset($data['php'])) {
         $data['php'] = phpversion();
     }
     if (!isset($data['db'])) {
         $data['db'] = null;
         // todo: make a db type/version check stable to work during install and later on
         //            if (class_exists('PDO')) {
         //                $pdo = ipDb()->getConnection();
         //                if ($pdo) {
         //                    $data['db'] = $pdo->getAttribute(\PDO::ATTR_SERVER_VERSION);
         //                }
         //            }
     }
     if (!isset($data['developmentEnvironment'])) {
         $data['developmentEnvironment'] = ipConfig()->get('developmentEnvironment');
     }
     if (!isset($data['showErrors'])) {
         $data['showErrors'] = ipConfig()->get('showErrors');
     }
     if (!isset($data['debugMode'])) {
         $data['debugMode'] = ipConfig()->get('debugMode');
     }
     if (!isset($data['timezone'])) {
         $data['timezone'] = ipConfig()->get('timezone');
     }
     if (!isset($data['data'])) {
         $data['data'] = array();
     }
     if (!isset($data['websiteId'])) {
         $data['websiteId'] = ipStorage()->get('Ip', 'websiteId');
     }
     if (!isset($data['websiteUrl'])) {
         $data['websiteUrl'] = ipConfig()->baseUrl();
     }
     if (!isset($data['version'])) {
         $data['version'] = \Ip\Application::getVersion();
     }
     if (!isset($data['locale'])) {
         $data['locale'] = \Ip\ServiceLocator::translator()->getAdminLocale();
     }
     if (!isset($data['doSupport'])) {
         $data['doSupport'] = ipStorage()->get('Ip', 'getImpressPagesSupport');
     }
     if (!isset($data['administrators'])) {
         $administrators = \Ip\Internal\Administrators\Model::getAll();
         $adminCollection = array();
         foreach ($administrators as $admin) {
             $permissions = \Ip\Internal\AdminPermissionsModel::getUserPermissions($admin['id']);
             $adminCollection[] = array('id' => $admin['id'], 'email' => $admin['email'], 'permissions' => $permissions);
         }
         $data['administrators'] = $adminCollection;
     }
     if (!isset($data['themes'])) {
         $data['themes'] = array('active' => ipConfig()->theme(), 'all' => \Ip\Internal\Design\Model::instance()->getAvailableThemes());
     }
     if (!isset($data['plugins'])) {
         $plugins = \Ip\Internal\Plugins\Model::getAllPluginNames();
         $activePlugins = \Ip\Internal\Plugins\Service::getActivePluginNames();
         $pluginCollection = array();
         foreach ($plugins as $pluginName) {
             $pluginCollection[] = array('name' => $pluginName, 'active' => in_array($pluginName, $activePlugins) ? true : false);
         }
         $data['plugins'] = $pluginCollection;
     }
     if (!isset($data['languages'])) {
         $data['languages'] = ipContent()->getLanguages();
     }
     if (!isset($data['pages'])) {
         $result = array();
         try {
             $table = ipTable('page');
             $sql = "\n                    SELECT\n                        `languageCode` AS `language`, COUNT( 1 ) AS `quantity`\n                    FROM\n                        {$table}\n                    GROUP BY\n                        `languageCode`\n                ";
             $result = ipDb()->fetchAll($sql);
         } catch (\Exception $e) {
             // Do nothing.
         }
         $data['pages'] = $result;
     }
     $postFields = 'data=' . urlencode(serialize($data));
     // Use sockets instead of CURL
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, ipConfig()->get('usageStatisticsUrl', 'http://service.impresspages.org/stats'));
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
     //        curl_setopt($ch, CURLOPT_REFERER, ipConfig()->baseUrl());
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
     curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
     curl_exec($ch);
 }