Exemplo n.º 1
0
 private static function checkForUpdates()
 {
     $module = Model::instance();
     $systemInfo = $module->getIpNotifications();
     if ($systemInfo != '') {
         //send an email
         $md5 = \Ip\ServiceLocator::storage()->get('Ip', 'lastSystemMessageSent');
         if (!$md5 || $md5 != md5(serialize($systemInfo))) {
             //we have a new message
             $message = '';
             $messages = $systemInfo;
             if (is_array($messages)) {
                 foreach ($messages as $messageVal) {
                     $message .= '<p>' . $messageVal->message . '</p>';
                 }
                 $onlyStatusMessages = true;
                 foreach ($messages as $messageVal) {
                     if ($messageVal->type != 'status') {
                         $onlyStatusMessages = false;
                     }
                 }
                 if ($onlyStatusMessages) {
                     return;
                     //TODO replace to something that would not terminate execution of following scripts if they will be there some day
                 }
             } else {
                 return;
                 //TODO replace to something that would not terminate execution of following scripts if they will be there some day
             }
             ipEvent('ipSystemMessages', array('messages' => $messages));
             \Ip\ServiceLocator::storage()->set('Ip', 'lastSystemMessageSent', md5(serialize($systemInfo)));
         }
     }
 }
Exemplo n.º 2
0
 public function saveValue()
 {
     $request = \Ip\ServiceLocator::request();
     $request->mustBePost();
     $post = $request->getPost();
     if (empty($post['fieldName'])) {
         throw new \Exception('Missing required parameter');
     }
     $fieldName = $post['fieldName'];
     if (!isset($post['value'])) {
         throw new \Exception('Missing required parameter');
     }
     $value = $post['value'];
     if (!in_array($fieldName, array('websiteTitle', 'websiteEmail')) && !(in_array($fieldName, array('automaticCron', 'cronPassword', 'removeOldRevisions', 'removeOldRevisionsDays', 'removeOldEmails', 'removeOldEmailsDays', 'allowAnonymousUploads', 'trailingSlash')) && ipAdminPermission('Config advanced'))) {
         throw new \Exception('Unknown config value');
     }
     $emailValidator = new \Ip\Form\Validator\Email();
     $error = $emailValidator->getError(array('value' => $value), 'value', \Ip\Form::ENVIRONMENT_ADMIN);
     if ($fieldName === 'websiteEmail' && $error !== false) {
         return $this->returnError($error);
     }
     if (in_array($fieldName, array('websiteTitle', 'websiteEmail'))) {
         if (!isset($post['languageId'])) {
             throw new \Exception('Missing required parameter');
         }
         $languageId = $post['languageId'];
         $language = ipContent()->getLanguage($languageId);
         ipSetOptionLang('Config.' . $fieldName, $value, $language->getCode());
     } else {
         ipSetOption('Config.' . $fieldName, $value);
     }
     return new \Ip\Response\Json(array(1));
 }
Exemplo n.º 3
0
 /**
  * Render field
  *
  * @param string $doctype
  * @param $environment
  * @return string
  */
 public function render($doctype, $environment)
 {
     $session = \Ip\ServiceLocator::application();
     return '
         <input ' . $this->getAttributesStr($doctype) . ' class="' . implode(' ', $this->getClasses()) . '" name="' . htmlspecialchars($this->getName()) . '"  ' . $this->getValidationAttributesStr($doctype) . ' type="hidden" value="' . addslashes($session->getSecurityToken()) . '" />
     ';
 }
Exemplo n.º 4
0
 public static function ipBeforeController()
 {
     $request = \Ip\ServiceLocator::request();
     $sessionLifetime = ini_get('session.gc_maxlifetime');
     if (!$sessionLifetime) {
         $sessionLifetime = 120;
     }
     if ($sessionLifetime > 30) {
         $sessionLifetime = $sessionLifetime - 20;
     }
     ipAddJsVariable('ipSessionRefresh', $sessionLifetime);
     if (ipConfig()->isDebugMode()) {
         ipAddJs('Ip/Internal/Core/assets/ipCore/jquery.js', null, 10);
         // default, global jQuery
         ipAddJs('Ip/Internal/Core/assets/ipCore/console.log.js', null, 10);
         ipAddJs('Ip/Internal/Core/assets/ipCore/functions.js');
         ipAddJs('Ip/Internal/Core/assets/ipCore/jquery.tools.form.js');
         ipAddJs('Ip/Internal/Core/assets/ipCore/form/color.js');
         ipAddJs('Ip/Internal/Core/assets/ipCore/form/file.js');
         ipAddJs('Ip/Internal/Core/assets/ipCore/form/richtext.js');
         ipAddJs('Ip/Internal/Core/assets/ipCore/form/repositoryFile.js');
         ipAddJs('Ip/Internal/Core/assets/ipCore/form/url.js');
         ipAddJs('Ip/Internal/Core/assets/ipCore/form.js');
         ipAddJs('Ip/Internal/Core/assets/ipCore/validator.js');
         ipAddJs('Ip/Internal/Core/assets/ipCore/widgets.js');
         ipAddJs('Ip/Internal/Core/assets/ipCore/ipCore.js');
     } else {
         ipAddJs('Ip/Internal/Core/assets/ipCore.min.js', null, 10);
     }
     //Form init
     $validatorTranslations = array('Ip-admin' => static::validatorLocalizationData('Ip-admin'), ipContent()->getCurrentLanguage()->getCode() => static::validatorLocalizationData('Ip'));
     ipAddJsVariable('ipValidatorTranslations', $validatorTranslations);
     if (ipAdminId() || \Ip\Internal\Admin\Model::isLoginPage() || \Ip\Internal\Admin\Model::isPasswordResetPage()) {
         if (ipConfig()->isDebugMode()) {
             ipAddJs('Ip/Internal/Core/assets/admin/managementMode.js');
             ipAddJs('Ip/Internal/Core/assets/admin/functions.js');
             ipAddJs('Ip/Internal/Core/assets/admin/validator.js');
             ipAddJs('Ip/Internal/Core/assets/admin/bootstrap/bootstrap.js');
             ipAddJs('Ip/Internal/Core/assets/admin/bootstrap-switch/bootstrap-switch.js');
         } else {
             ipAddJs('Ip/Internal/Core/assets/admin.min.js', null, 10);
         }
         ipAddJs('Ip/Internal/Core/assets/tinymce/pastePreprocess.js');
         ipAddJs('Ip/Internal/Core/assets/tinymce/default.js');
     }
     if (ipAdminId()) {
         ipAddJs('Ip/Internal/Core/assets/js/tiny_mce/jquery.tinymce.min.js');
         ipAddJs('Ip/Internal/Core/assets/js/tiny_mce/tinymce.min.js');
         ipAddJsVariable('ipBrowseLinkModalTemplate', ipView('view/browseLinkModal.php')->render());
         ipAddJs('Ip/Internal/Core/assets/ipCore/plupload/plupload.full.js');
         ipAddJs('Ip/Internal/Core/assets/ipCore/plupload/plupload.browserplus.js');
         ipAddJs('Ip/Internal/Core/assets/ipCore/plupload/plupload.gears.js');
         ipAddJs('Ip/Internal/Core/assets/ipCore/plupload/jquery.plupload.queue/jquery.plupload.queue.js');
         if (is_file(ipThemeFile('setup/admin.js'))) {
             ipAddJs(ipThemeUrl('setup/admin.js'));
         }
         ipAddCss('Ip/Internal/Core/assets/admin/admin.css');
     }
 }
Exemplo n.º 5
0
 public function index()
 {
     $revision = \Ip\ServiceLocator::content()->getCurrentRevision();
     if ($revision) {
         return \Ip\Internal\Content\Model::generateBlock('main', $revision['revisionId'], 0, ipIsManagementState());
     } else {
         return '';
     }
 }
Exemplo n.º 6
0
 public function generateJavascript()
 {
     $cacheVersion = $this->getCacheVersion();
     $javascriptFiles = $this->getJavascript();
     $javascriptFilesSorted = array();
     foreach ($javascriptFiles as $level) {
         foreach ($level as &$file) {
             if ($file['type'] == 'file' && $file['cacheFix']) {
                 $file['value'] .= (strpos($file['value'], '?') !== false ? '&' : '?') . $cacheVersion;
             }
         }
         $javascriptFilesSorted = array_merge($javascriptFilesSorted, $level);
     }
     $data = array('ip' => array('baseUrl' => ipConfig()->baseUrl(), 'languageId' => null, 'languageUrl' => '', 'theme' => ipConfig()->get('theme'), 'pageId' => null, 'securityToken' => \Ip\ServiceLocator::application()->getSecurityToken(), 'developmentEnvironment' => ipConfig()->isDevelopmentEnvironment(), 'debugMode' => ipconfig()->isDebugMode(), 'isManagementState' => false, 'isAdminState' => false, 'isAdminNavbarDisabled' => false), 'javascriptVariables' => $this->getJavascriptVariables(), 'javascript' => $javascriptFilesSorted);
     return ipView(ipFile('Ip/Internal/Config/view/javascript.php'), $data)->render();
 }
Exemplo n.º 7
0
 /**
  * Get error
  *
  * @param array $values
  * @param int $valueKey
  * @param $environment
  * @return string|bool
  */
 public function getError($values, $valueKey, $environment)
 {
     if (empty($values[$valueKey])) {
         return 'error';
     }
     $session = \Ip\ServiceLocator::application();
     if ($values[$valueKey] != $session->getSecurityToken()) {
         if ($environment == \Ip\Form::ENVIRONMENT_ADMIN) {
             $errorText = __('Session has expired. Please refresh the page.', 'Ip-admin');
         } else {
             $errorText = __('Session has expired. Please refresh the page.', 'Ip');
         }
         return $errorText;
     } else {
         return false;
     }
 }
Exemplo n.º 8
0
 public function generateSlot($name, $params = array())
 {
     $content = \Ip\ServiceLocator::dispatcher()->slot($name, $params);
     //look for predefined content
     $predefinedContent = $this->getSlotContent($name);
     if ($predefinedContent !== null) {
         if (is_object($predefinedContent) && method_exists($predefinedContent, 'render')) {
             $predefinedContent = $content->render();
         }
         return $predefinedContent;
     }
     if ($content) {
         if (is_object($content) && method_exists($content, 'render')) {
             $content = $content->render();
         }
         return $content;
     }
     return '';
 }
Exemplo n.º 9
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());
     }
 }
Exemplo n.º 10
0
 private function generateBlockHtml($revisionId)
 {
     $predefinedContent = \Ip\ServiceLocator::content()->getBlockContent($this->name);
     if ($predefinedContent !== null) {
         return $predefinedContent;
     }
     if (ipContent()->getCurrentPage() == null && $revisionId == 0 && !$this->isStatic) {
         return '';
     }
     if ($this->isStatic) {
         $languageId = ipContent()->getCurrentLanguage()->getId();
         $revisionId = 0;
     } else {
         if ($revisionId === 0) {
             $revision = \Ip\ServiceLocator::content()->getCurrentRevision();
             if ($revision) {
                 $revisionId = $revision['revisionId'];
             }
         }
         $languageId = 0;
     }
     return \Ip\Internal\Content\Model::generateBlock($this->name, $revisionId, $languageId, ipIsManagementState(), $this->exampleContent);
 }
Exemplo n.º 11
0
 /**
  * @param $info
  * @return array|null
  * @throws \Ip\Exception
  */
 public static function ipRouteAction_70($info)
 {
     $result = \Ip\ServiceLocator::router()->match(rtrim($info['relativeUri'], '/'), ipRequest());
     if (!$result) {
         return null;
     }
     if (is_callable($result['action'])) {
         unset($result['plugin'], $result['controller']);
     }
     if (empty($result['page'])) {
         if ($info['relativeUri'] == '') {
             $pageId = ipContent()->getDefaultPageId();
             $page = \Ip\Internal\Pages\Service::getPage($pageId);
         } else {
             $languageCode = ipContent()->getCurrentLanguage()->getCode();
             $page = \Ip\Internal\Pages\Service::getPageByUrl($languageCode, $info['relativeUri']);
         }
         if ($page && (!$page['isSecured'] || !ipAdminId())) {
             $result['page'] = new \Ip\Page($page);
         }
     }
     return $result;
 }
Exemplo n.º 12
0
 /**
  * Used when management is needed in controller routed using routes.
  * @param $info
  * @return null
  */
 public static function ipBeforeController_70($info)
 {
     if (empty($info['page']) || empty($info['management']) || !ipIsManagementState()) {
         return null;
     }
     //find current page
     $page = $info['page'];
     // change layout if safe mode
     if (\Ip\Internal\Admin\Service::isSafeMode()) {
         ipSetLayout(ipFile('Ip/Internal/Admin/view/safeModeLayout.php'));
     } else {
         ipSetLayout($page->getLayout());
     }
     // initialize management
     if (!ipRequest()->getQuery('ipDesignPreview') && !ipRequest()->getQuery('disableManagement')) {
         Helper::initManagement();
     }
     //show page content
     $response = ipResponse();
     $response->setDescription(\Ip\ServiceLocator::content()->getDescription());
     $response->setKeywords(ipContent()->getKeywords());
     $response->setTitle(ipContent()->getTitle());
 }
Exemplo n.º 13
0
 public static function ipBeforeApplicationClosed()
 {
     /*
      Automatic execution of cron.
      The best solution is to setup cron service to launch file www.yoursite.com/ip_cron.php few times a day.
      By default fake cron is enabled
     */
     if (\Ip\Internal\Admin\Model::isSafeMode() || !ipGetOption('Config.automaticCron', 1)) {
         return;
     }
     $lastExecution = \Ip\ServiceLocator::storage()->get('Cron', 'lastExecutionStart');
     if ($lastExecution && date('Y-m-d H') == date('Y-m-d H', $lastExecution)) {
         // we execute cron once an hour and cron has been executed this hour
         return;
     }
     if (function_exists('curl_init')) {
         $ch = curl_init();
         $url = ipConfig()->baseUrl() . '?pa=Cron&pass='******'Config.cronPassword'));
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_REFERER, ipConfig()->baseUrl());
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_TIMEOUT, ipGetOption('Config.cronTimeout', 10));
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
         $fakeCronAnswer = curl_exec($ch);
         if ($fakeCronAnswer != __('OK', 'Ip-admin', false)) {
             ipLog()->error('Cron.failedFakeCron', array('result' => $fakeCronAnswer, 'type' => 'curl', 'error' => curl_error($ch)));
         }
     } else {
         $request = new \Ip\Request();
         $request->setQuery(array('pa' => 'Cron', 'pass' => ipGetOption('Config.cronPassword')));
         $fakeCronAnswer = \Ip\ServiceLocator::application()->handleRequest($request)->getContent();
         if ($fakeCronAnswer != __('OK', 'Ip-admin', false)) {
             ipLog()->error('Cron.failedFakeCron', array('result' => $fakeCronAnswer, 'type' => 'subrequest'));
         }
     }
 }
Exemplo n.º 14
0
 protected function addFileRoutes($routesFile, $plugin)
 {
     $router = \Ip\ServiceLocator::router();
     if (file_exists($routesFile)) {
         $routes = array();
         include $routesFile;
         $router->addRoutes($routes, array('plugin' => $plugin, 'controller' => 'PublicController'));
     }
 }
Exemplo n.º 15
0
$translator->addTranslationFilePattern('json', $trOverrideDir, 'Install-%s.json', 'Install');
$request = new \Plugin\Install\Request();
$request->setQuery($_GET);
$request->setPost($_POST);
$request->setServer($_SERVER);
$request->setRequest($_REQUEST);
\Ip\ServiceLocator::addRequest($request);
$language = new \Ip\Language(null, $options['translationsLanguageCode'], null, null, null, 0, 'ltr');
ipContent()->_setCurrentLanguage($language);
\Ip\ServiceLocator::dispatcher()->_bindInstallEvents();
if ($request->isGet()) {
    $controller = new \Plugin\Install\PublicController();
    if (!empty($_GET['pa']) && $_GET['pa'] == 'Install.testSessions') {
        $response = $controller->testSessions();
    } else {
        $response = $controller->index();
    }
} elseif ($request->isPost()) {
    $route = Ip\Internal\Core\Job::ipRouteAction_20(array('request' => $request));
    if (!$route || $route['plugin'] != 'Install' || $route['controller'] != 'PublicController') {
        $response = new \Ip\Response\PageNotFound();
    } else {
        $controller = new \Plugin\Install\PublicController();
        $response = $controller->{$route['action']}();
    }
} else {
    exit('HTTP Method not supported.');
}
\Ip\ServiceLocator::removeRequest();
\Ip\ServiceLocator::setResponse($response);
$application->handleResponse($response);
Exemplo n.º 16
0
 public function getIpNotifications()
 {
     $systemInfo = Model::getIpNotifications();
     if (isset($_REQUEST['afterLogin'])) {
         // Request after login.
         if ($systemInfo == '') {
             $_SESSION['ipSystem']['show_system_message'] = false;
             // Don't display system alert at the top.
             return null;
         } else {
             $md5 = \Ip\ServiceLocator::storage()->get('Ip', 'lastSystemMessageShown');
             if ($systemInfo && (!$md5 || $md5 != md5(serialize($systemInfo)))) {
                 // We have a new message.
                 $newMessage = false;
                 foreach (json_decode($systemInfo) as $infoValue) {
                     if ($infoValue->type != 'status') {
                         $newMessage = true;
                     }
                 }
                 $_SESSION['ipSystem']['show_system_message'] = $newMessage;
                 // Display system alert.
             } else {
                 // This message was already seen.
                 $_SESSION['ipSystem']['show_system_message'] = false;
                 // Don't display system alert at the top.
                 return null;
             }
         }
     } else {
         // administrator/system tab.
         \Ip\ServiceLocator::storage()->set('Ip', 'lastSystemMessageShown', md5(serialize($systemInfo)));
         $_SESSION['ipSystem']['show_system_message'] = false;
         // Don't display system alert at the top.
     }
     return new \Ip\Response\Json($systemInfo);
 }
Exemplo n.º 17
0
 /**
  * Generate language URL
  *
  * @return string Returns link to home page if multilingual option is turned off
  */
 public function getLink()
 {
     $link = ipConfig()->baseUrl();
     if (ipConfig()->get('rewritesDisabled')) {
         $link .= 'index.php/';
     }
     $link .= \Ip\ServiceLocator::content()->getLanguage($this->getId())->getUrlPath();
     return $link;
 }
Exemplo n.º 18
0
 /**
  * Get all web site options
  *
  * @return array Configuration options
  */
 function getAllOptions()
 {
     $optionValues = \Ip\ServiceLocator::storage()->getAll('Config');
     $options = array();
     foreach ($optionValues as $option) {
         $options[$option['key']] = $option['value'];
     }
     return $options;
 }
Exemplo n.º 19
0
if (!empty($description)) {
    ?>
    <meta property="og:description" content="<?php 
    echo escAttr($description);
    ?>
" />
<?php 
}
if (!empty($siteName)) {
    ?>
    <meta property="og:site_name" content="<?php 
    echo escAttr($siteName);
    ?>
" />
<?php 
}
if (!empty($images)) {
    ?>
    <?php 
    foreach ($images as $imageUrl) {
        ?>
        <meta property="og:image" content="<?php 
        echo escAttr($imageUrl);
        ?>
?v=0<?php 
        echo \Ip\ServiceLocator::storage()->get('Ip', 'cacheVersion', 1);
        ?>
" />
    <?php 
    }
}
Exemplo n.º 20
0
 protected function getCurrentRevision()
 {
     return \Ip\ServiceLocator::content()->getCurrentRevision();
 }
Exemplo n.º 21
0
 /**
  * @return array
  */
 public static function initManagementData()
 {
     $tmpWidgets = Model::getAvailableWidgetObjects();
     $tmpWidgets = Model::sortWidgets($tmpWidgets);
     $tags = array('Core' => array());
     $uncategorizedWidgets = array();
     unset($tmpWidgets['Columns']);
     foreach ($tmpWidgets as $key => $widget) {
         if ($widget->isCore()) {
             $tags['Core'][$key] = $widget->getName();
         } else {
             $pluginName = $widget->getPluginName();
             if (!array_key_exists($pluginName, $tags)) {
                 $tags[$pluginName] = array();
             }
             $tags[$pluginName][] = $widget->getName();
         }
     }
     // Filter out single widget categories
     foreach ($tags as $key => $widget) {
         $widgetCount = count($tags[$key]);
         if ($widgetCount === 1) {
             $uncategorizedWidgets[] = $widget[0];
             unset($tags[$key]);
         }
     }
     if (count($uncategorizedWidgets) > 0) {
         $tags['Other'] = $uncategorizedWidgets;
     }
     //these two tranlsations appear here just to make translations engine to find these dynamic translations
     __('Other', 'Ip-admin', false);
     __('Core', 'Ip-admin', false);
     $revision = \Ip\ServiceLocator::content()->getCurrentRevision();
     $revisions = \Ip\Internal\Revision::getPageRevisions(ipContent()->getCurrentPage()->getId());
     $manageableRevision = isset($revisions[0]['revisionId']) && $revisions[0]['revisionId'] == $revision['revisionId'];
     $page = ipContent()->getCurrentPage();
     $tags = ipFilter('ipAdminWidgets', $tags);
     $data = array('widgets' => $tmpWidgets, 'tags' => $tags, 'page' => $page, 'currentRevision' => $revision, 'manageableRevision' => $manageableRevision, 'categorySplit' => 3, 'mobile' => Browser::isMobile());
     $controlPanelHtml = ipView('view/adminPanel.php', $data)->render();
     $data = array('tags' => $tags, 'controlPanelHtml' => $controlPanelHtml, 'manageableRevision' => $manageableRevision);
     return $data;
 }
Exemplo n.º 22
0
 public function installTheme($themeName)
 {
     $themes = $this->getAvailableThemes();
     if (!isset($themes[$themeName])) {
         throw new \Ip\Exception("Theme '" . esc($themeName) . "' does not exist.");
     }
     $theme = $themes[$themeName];
     ipEvent('ipBeforeThemeInstalled', array('themeName' => $themeName));
     \Ip\ServiceLocator::storage()->set('Ip', 'theme', $themeName);
     $service = Service::instance();
     $service->saveWidgetOptions($theme);
     //write down default theme options
     $options = $theme->getOptionsAsArray();
     foreach ($options as $option) {
         if (empty($option['name']) || empty($option['default'])) {
             continue;
         }
         $configModel = ConfigModel::instance();
         $newValue = $configModel->getConfigValue($themeName, $option['name'], $option['default']);
         $configModel->setConfigValue($themeName, $option['name'], $newValue);
     }
     ipEvent('ipThemeInstalled', array('themeName' => $themeName));
 }
Exemplo n.º 23
0
 public static function ipAdminNavbarCenterElements($elements, $info)
 {
     if (ipContent()->getCurrentPage() && ipAdminPermission('Content')) {
         $revision = \Ip\ServiceLocator::content()->getCurrentRevision();
         $revisions = \Ip\Internal\Revision::getPageRevisions(ipContent()->getCurrentPage()->getId());
         $managementUrls = array();
         $currentPageLink = ipContent()->getCurrentPage()->getLink();
         foreach ($revisions as $value) {
             $managementUrls[] = $currentPageLink . '?_revision=' . $value['revisionId'];
         }
         $data = array('revisions' => $revisions, 'currentRevision' => $revision, 'managementUrls' => $managementUrls, 'isPublished' => !\Ip\Internal\Content\Model::isRevisionModified($revision['revisionId']) && ipContent()->getCurrentPage()->isVisible(), 'isVisible' => ipContent()->getCurrentPage()->isvisible());
         $elements[] = ipView('view/publishButton.php', $data);
     }
     return $elements;
 }
Exemplo n.º 24
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);
 }
Exemplo n.º 25
0
 public function login($username, $password)
 {
     $ip = ipRequest()->getServer('REMOTE_ADDR');
     $preventReason = ipJob('ipAdminLoginPrevent', array('username' => $username));
     if ($preventReason) {
         $this->errors = array('global_error' => $preventReason);
         ipLog()->notice('Admin.loginPrevented: {username} from {ip}', array('username' => $username, 'ip' => ipRequest()->getServer('REMOTE_ADDR')));
         return false;
     }
     $administrator = \Ip\Internal\Administrators\Service::getByUsername($username);
     if (!$administrator) {
         \Ip\ServiceLocator::dispatcher()->event('ipAdminLoginFailed', array('username' => $username, 'ip' => ipRequest()->getServer('REMOTE_ADDR')));
         ipLog()->info('Admin.incorrectLogin: {username} from {ip}', array('username' => $username, 'ip' => $ip));
         $this->errors = array('login' => __('Following user doesn\'t exist', 'Ip-admin'));
         return false;
     }
     if (\Ip\Internal\Administrators\Service::checkPassword($administrator['id'], $password)) {
         Service::setAdminLogin($username);
         return true;
     } else {
         \Ip\ServiceLocator::dispatcher()->event('ipAdminLoginFailed', array('username' => $username, 'ip' => ipRequest()->getServer('REMOTE_ADDR')));
         ipLog()->info('Admin.incorrectLogin: {username} from {ip}', array('username' => $username, 'ip' => $ip));
         $this->errors = array('password' => __('Incorrect password', 'Ip-admin'));
         return false;
     }
 }
Exemplo n.º 26
0
/**
 * Get info about current route
 * @return \Ip\Route
 */
function ipRoute()
{
    return \Ip\ServiceLocator::route();
}
Exemplo n.º 27
0
 /**
  * @throws \Ip\Exception
  */
 public function installTheme()
 {
     $request = ServiceLocator::request();
     $request->mustBePost();
     $themeName = $request->getPost('themeName');
     if (empty($themeName)) {
         throw new \Ip\Exception('Invalid arguments.');
     }
     $model = Model::instance();
     try {
         $model->installTheme($themeName);
     } catch (\Ip\Exception $e) {
         return JsonRpc::error($e->getMessage());
     }
     // TODO jsonrpc
     return new \Ip\Response\Json(array('status' => 'success'));
 }