示例#1
0
 public static function ipJs($jsFiles)
 {
     if (ipGetOption('ConcatenateJsCss.disableInAdmin', 1) && ipAdminId() || ipStorage()->get('ConcatenateJsCss', 'concatenationInProgress') > time()) {
         return $jsFiles;
     }
     ipStorage()->set('ConcatenateJsCss', 'concatenationInProgress', time() + 60);
     //if some CSS / JS links to the website itself, we may have an infinite recursion. So we have to disable ourself during the concatenation
     $tinymceUrl = ipFileUrl('Ip/Internal/Core/assets/js/tiny_mce');
     $answer = array('concatenateJsCss_tinymce_fix' => array('type' => 'content', 'value' => "var tinyMCEPreInit = {\n    suffix: '.min',\n    base: '" . $tinymceUrl . "',\n    query: ''\n};", 'attributes' => array(), 'cacheFix' => false));
     $chunk = array();
     foreach ($jsFiles as &$file) {
         if ($file['type'] == 'content') {
             //we have faced a piece of inline JS. It can't be concatenated. We have to split concatenated JS in to two parts.
             if (!empty($chunk)) {
                 $answer = array_merge($answer, self::concatenateChunk($chunk));
             }
             $chunk = array();
             //add current inline content JS
             $answer[] = $file;
         } else {
             $chunk[] = $file;
         }
     }
     if (!empty($chunk)) {
         $answer = array_merge($answer, self::concatenateChunk($chunk));
     }
     ipStorage()->remove('ConcatenateJsCss', 'concatenationInProgress');
     return $answer;
 }
示例#2
0
 public function setWidgetWidth()
 {
     $id = ipRequest()->getRequest('widgetId', false);
     $width = ipRequest()->getRequest('width', 50);
     ipStorage()->set('FloatImageWidth', 'widget_' . $id, $width);
     return new \Ip\Response\Json(array('status' => 'success'));
 }
示例#3
0
 public static function ipWidgetDuplicated($data)
 {
     $oldId = $data['oldWidgetId'];
     $newId = $data['newWidgetId'];
     $widgetData = ipStorage()->get('FloatImage', 'widget_' . $oldId, false);
     if ($widgetData) {
         ipStorage()->set('FloatImage', 'widget_' . $newId, $widgetData);
     }
 }
示例#4
0
 public static function runMigrations()
 {
     $curDbVersion = ipStorage()->get('Ip', 'dbVersion');
     for ($i = $curDbVersion + 1; $i <= Model::getDbVersion(); $i++) {
         $migrationMethod = 'update_' . $i;
         if (method_exists(__NAMESPACE__ . '\\Migration', $migrationMethod)) {
             Migration::$migrationMethod();
         }
         ipStorage()->set('Ip', 'dbVersion', $i);
     }
 }
示例#5
0
 public static function ipWidgetHtmlFull($html, $data)
 {
     if ($data['name'] == 'Image') {
         $float = ipStorage()->get('FloatImage', 'widget_' . $data['id'], 'false');
         if ($float !== 'false') {
             $html = str_replace('ipWidget-Image', 'ipWidget-Image floatWidget float-' . $float, $html);
             $width = ipStorage()->get('FloatImageWidth', 'widget_' . $data['id'], 50);
             $html = str_replace('class="ipWidget', 'style="width:' . $width . '%;" class="ipWidget', $html);
         }
     }
     return $html;
 }
示例#6
0
 public function removeAdminIsAutogeneratedAjax()
 {
     ipRequest()->mustBePost();
     // Removing temporary data
     ipStorage()->remove('Ip', 'adminIsAutogenerated');
     // If user wants to change credentials, redirecting to Administrators list
     if (ipRequest()->getPost('action') == 'change') {
         // todo: redirect and automatically select user and open popup
         $redirect = ipActionUrl(array('aa' => 'Administrators.index')) . "#/hash=&administrator=" . \Ip\Internal\Admin\Backend::userId();
         \Ip\Internal\System\Model::sendUsageStatistics(array('action' => 'Install.adminChange'));
         return \Ip\Response\JsonRpc::result(array('redirect' => $redirect));
     }
     \Ip\Internal\System\Model::sendUsageStatistics(array('action' => 'Install.adminKeep'));
     return \Ip\Response\JsonRpc::result(array('close' => 1));
 }
示例#7
0
 public static function ipBeforeController()
 {
     //show admin submenu if needed
     if (ipRoute()->isAdmin()) {
         ipAddJs('Ip/Internal/Core/assets/js/jquery-ui/jquery-ui.js');
         ipAddCss('Ip/Internal/Core/assets/js/jquery-ui/jquery-ui.css');
         $submenu = Submenu::getSubmenuItems();
         $submenu = ipFilter('ipAdminSubmenu', $submenu);
         if ($submenu) {
             ipResponse()->setLayoutVariable('submenu', $submenu);
         }
     }
     // Show admin toolbar if admin is logged in:
     if (ipAdminId() && !ipRequest()->getRequest('pa') || ipRequest()->getRequest('aa') && ipAdminId()) {
         if (!ipRequest()->getQuery('ipDesignPreview') && !ipRequest()->getQuery('disableAdminNavbar')) {
             ipAddJs('Ip/Internal/Admin/assets/admin.js');
             ipAddJsVariable('ipAdminNavbar', static::getAdminNavbarHtml());
         }
     }
     // Show popup with autogenerated user information if needed
     $adminIsAutogenerated = ipStorage()->get('Ip', 'adminIsAutogenerated');
     if ($adminIsAutogenerated) {
         $adminId = \Ip\Internal\Admin\Backend::userId();
         $admin = \Ip\Internal\Administrators\Model::getById($adminId);
         ipAddJs('Ip/Internal/Admin/assets/adminIsAutogenerated.js');
         $data = array('adminUsername' => $admin['username'], 'adminPassword' => ipStorage()->get('Ip', 'adminIsAutogenerated'), 'adminEmail' => $admin['email']);
         ipAddJsVariable('ipAdminIsAutogenerated', ipView('view/adminIsAutoGenerated.php', $data)->render());
     }
     if (ipContent()->getCurrentPage()) {
         // initialize management
         if (ipIsManagementState()) {
             if (!ipRequest()->getQuery('ipDesignPreview') && !ipRequest()->getQuery('disableManagement')) {
                 \Ip\Internal\Content\Helper::initManagement();
             }
         }
         //show page content
         $response = ipResponse();
         $response->setDescription(\Ip\ServiceLocator::content()->getDescription());
         $response->setKeywords(ipContent()->getKeywords());
         $response->setTitle(ipContent()->getTitle());
     }
 }
示例#8
0
 public function login()
 {
     if (\Ip\Internal\Admin\Backend::userId()) {
         //user has already been logged in
         \Ip\Internal\Content\Service::setManagementMode(1);
         return new \Ip\Response\Redirect(ipHomeUrl());
     }
     // If none of the administrator exist, we create default one and log in user
     $administrators = \Ip\Internal\Administrators\Model::getAll();
     if (empty($administrators)) {
         $adminUsername = '******';
         $adminEmail = ipGetOptionLang('Config.websiteEmail');
         $adminPassword = Model::randString(8);
         $adminId = \Ip\Internal\Administrators\Service::add($adminUsername, $adminEmail, $adminPassword);
         \Ip\Internal\AdminPermissionsModel::addPermission('Super admin', $adminId);
         // Set variable to know that user is autogenerated
         ipStorage()->set('Ip', 'adminIsAutogenerated', $adminPassword);
         // Logging in new admin
         $model = Model::instance();
         if ($model->login($adminUsername, $adminPassword)) {
             \Ip\Internal\System\Model::sendUsageStatistics(array('action' => 'Install.adminIsAutogenerated'));
             $redirectUrl = ipHomeUrl();
             return new \Ip\Response\Redirect($redirectUrl);
         } else {
             \Ip\Internal\System\Model::sendUsageStatistics(array('action' => 'Install.adminIsAutogeneratedFailed'));
             // todo: handle errors
             // $errors = $model->getErrors();
         }
     }
     $content = ipView('view/login.php', array('loginForm' => FormHelper::getLoginForm()));
     ipAddJs('Ip/Internal/Admin/assets/login.js');
     $response = ipResponse();
     $response->setLayout('Ip/Internal/Admin/view/loginLayout.php');
     $response->setLayoutVariable('content', $content);
     ipAddJs('assets/languageSelect.js');
     $response->setLayoutVariable('languageSelectForm', FormHelper::getLanguageSelectForm());
     return $response;
 }
示例#9
0
 protected function init()
 {
     $this->firstTimeThisYear = true;
     $this->firstTimeThisMonth = true;
     $this->firstTimeThisWeek = true;
     $this->firstTimeThisDay = true;
     $this->firstTimeThisHour = true;
     $this->lastTime = null;
     $lastExecution = ipStorage()->get('Cron', 'lastExecutionEnd', null);
     $lastExecutionStart = ipStorage()->get('Cron', 'lastExecutionStart', null);
     if ($lastExecution < $lastExecutionStart) {
         // if last cron execution failed to finish
         $lastExecution = $lastExecutionStart;
     }
     if ($lastExecution && !(ipRequest()->getQuery('test', 0) && ipAdminId())) {
         $this->firstTimeThisYear = date('Y') != date('Y', $lastExecution);
         $this->firstTimeThisMonth = date('Y-m') != date('Y-m', $lastExecution);
         $this->firstTimeThisWeek = date('Y-w') != date('Y-w', $lastExecution);
         $this->firstTimeThisDay = date('Y-m-d') != date('Y-m-d', $lastExecution);
         $this->firstTimeThisHour = date('Y-m-d H') != date('Y-m-d H', $lastExecution);
         $this->lastTime = $lastExecution;
     }
 }
示例#10
0
 /**
  * Rename Title widget to Heading widget.
  */
 public static function update_7()
 {
     ipDb()->update('widget', array('name' => 'Heading'), array('name' => 'Title'));
     ipDb()->update('widgetOrder', array('widgetName' => 'Heading'), array('widgetName' => 'Title'));
     ipStorage()->set('Ip', 'cacheVersion', ipStorage()->get('Ip', 'cacheVersion', 1) + 1);
     ipDb()->update('storage', array('value' => '"4.0.2"'), array('key' => 'version', 'plugin' => 'Ip'));
 }
示例#11
0
 public static function removeRawCode($pageId)
 {
     ipStorage()->remove('Php', $pageId . '-rawCode');
 }
示例#12
0
 public static function setDefaultMenuPagePosition($menuAlias, $whenPageIsSelected, $position)
 {
     $key = 'menu_' . $menuAlias . '_default_position';
     if ($whenPageIsSelected) {
         $key .= '_selected';
     }
     ipStorage()->set('Pages', $key, $position);
 }
示例#13
0
 private function setFailedLogins($failedLogins)
 {
     ipStorage()->set('Admin', 'failedLogins', $failedLogins);
 }
示例#14
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);
 }
示例#15
0
 public static function invalidateAssetCache()
 {
     ipStorage()->set('Ip', 'cacheVersion', ipStorage()->get('Ip', 'cacheVersion') + 1);
 }
 public function createDatabase()
 {
     if (!Helper::isInstallAvailable()) {
         return sprintf(__('Please remove content from %s file.', 'Install', false), 'config.php');
     }
     $db = ipRequest()->getPost('db');
     if (!isset($_SESSION['db_errors'])) {
         $_SESSION['db_errors'] = array();
     }
     foreach (array('hostname', 'username', 'database') as $key) {
         if (empty($db[$key])) {
             $_SESSION['db_errors'][] = 'Required fields';
             return \Ip\Response\JsonRpc::error(__('Please fill in required fields.', 'Install', false));
         }
     }
     if (empty($db['tablePrefix'])) {
         $db['tablePrefix'] = '';
     }
     if (strlen($db['tablePrefix']) > 7) {
         $_SESSION['db_errors'][] = 'Prefix too long';
         return \Ip\Response\JsonRpc::error(__("Prefix can't be longer than 7 symbols.", 'Install', false));
     }
     if ($db['tablePrefix'] != '' && !preg_match('/^([A-Za-z_][A-Za-z0-9_]*)$/', $db['tablePrefix'])) {
         $_SESSION['db_errors'][] = 'Prefix is bad';
         return \Ip\Response\JsonRpc::error(__("Prefix can't contain any special characters and should start with a letter.", 'Install', false));
     }
     $dbConfig = array('hostname' => $db['hostname'], 'username' => $db['username'], 'password' => $db['password'], 'tablePrefix' => $db['tablePrefix'], 'database' => '', 'charset' => 'utf8');
     ipConfig()->set('db', $dbConfig);
     try {
         ipDb()->getConnection();
     } catch (\Exception $e) {
         $_SESSION['db_errors'][] = 'Cannot connect';
         return \Ip\Response\JsonRpc::error(__("Can't connect to database.", 'Install'), false);
     }
     try {
         Model::createAndUseDatabase($db['database']);
     } catch (\Ip\Exception $e) {
         $_SESSION['db_errors'][] = 'DB cannot be created';
         return \Ip\Response\JsonRpc::error(__('Specified database does not exists and cannot be created.', 'Install', false));
     }
     if (Helper::testDBTables($db['tablePrefix']) && empty($db['replaceTables'])) {
         $_SESSION['db_errors'][] = 'Replace tables';
         return \Ip\Response\JsonRpc::error(__('Do you like to replace existing tables in the database?', 'Install', false), 'table_exists');
     }
     $errors = Model::createDatabaseStructure($db['database'], $db['tablePrefix']);
     if (!$errors) {
         $errors = Model::importData($dbConfig['tablePrefix']);
     }
     if ($errors) {
         $_SESSION['db_errors'][] = 'Failed install';
         return \Ip\Response\JsonRpc::error(__('There were errors while executing install queries. ' . serialize($errors), 'Install', false));
     }
     $dbConfig['database'] = $db['database'];
     $_SESSION['db'] = $dbConfig;
     $configToFile = array();
     $configToFile['sessionName'] = 'ses' . rand();
     $configToFile['db'] = $_SESSION['db'];
     $configToFile['timezone'] = $_SESSION['config']['timezone'];
     if (Helper::checkModRewrite() != 'success') {
         $configToFile['rewritesDisabled'] = true;
     }
     $admin = ipRequest()->getPost('admin');
     if ($admin) {
         $adminUsername = $admin['username'];
         $adminEmail = $admin['email'];
         $adminPassword = $admin['password'];
     }
     $cachedBaseUrl = substr(rtrim(ipConfig()->baseUrl(), "/"), 0, -strlen('install'));
     try {
         ipConfig()->set('db', $dbConfig);
         // if admin data is posted then user will be created
         if ($admin) {
             Model::insertAdmin($adminUsername, $adminEmail, $adminPassword);
         }
         ipSetOptionLang('Config.websiteTitle', $_SESSION['config']['websiteName'], 'en');
         ipSetOptionLang('Config.websiteEmail', $_SESSION['config']['websiteEmail'], 'en');
         Model::generateCronPassword();
         ipStorage()->set('Ip', 'cachedBaseUrl', $cachedBaseUrl);
         ipStorage()->set('Ip', 'websiteId', $_SESSION['websiteId']);
         ipStorage()->set('Ip', 'getImpressPagesSupport', $_SESSION['config']['support']);
     } catch (\Exception $e) {
         $_SESSION['db_errors'][] = $e->getTraceAsString();
         return \Ip\Response\JsonRpc::error($e->getTraceAsString());
     }
     try {
         Model::writeConfigFile($configToFile, ipFile('config.php'));
     } catch (\Exception $e) {
         $_SESSION['db_errors'][] = 'Cannot write config file';
         return \Ip\Response\JsonRpc::error(__('Can\'t write configuration "/config.php"', 'Install', false));
     }
     // Send usage statistics
     $usageStatistics = Helper::setUsageStatistics('Install.database', $_SESSION['db_errors']);
     \Ip\Internal\System\Model::sendUsageStatistics($usageStatistics);
     $redirect = $cachedBaseUrl . 'admin';
     return \Ip\Response\JsonRpc::result(array('redirect' => $redirect));
 }
示例#17
0
 private function gmapsApiAvailable()
 {
     return ipGetOption('Config.gmapsApiKey') || ipStorage()->get('Ip', 'upgradedFrom4.6.6', false);
 }
示例#18
0
 public static function getPaymentData($key)
 {
     return ipStorage()->get('Ecommerce', 'payment_' . $key);
 }
示例#19
0
 public function theme()
 {
     if (!empty($this->config['theme'])) {
         return $this->config['theme'];
     } else {
         return ipStorage()->get('Ip', 'theme');
     }
 }
示例#20
0
 public static function clearCache()
 {
     ipStorage()->set('Ip', 'cacheVersion', ipStorage()->get('Ip', 'cacheVersion', 1) + 1);
     ipEvent('ipCacheClear');
 }