Exemple #1
0
 protected static function getControllerMenu($class)
 {
     $reflector = new \ReflectionClass($class);
     $methods = $reflector->getMethods();
     $submenuItems = array();
     foreach ($methods as $method) {
         if (in_array($method, array('index'))) {
             continue;
         }
         if (!$method->isPublic()) {
             continue;
         }
         $docComment = $method->getDocComment();
         if (preg_match_all('/@(\\w+)\\s+(.*)\\r?\\n/m', $docComment, $matches)) {
             $result = array_combine($matches[1], $matches[2]);
             if (isset($result['ipSubmenu'])) {
                 $menuItem = new \Ip\Menu\Item();
                 $menuItem->setTitle(__($result['ipSubmenu'], ipRoute()->plugin(), false));
                 $menuItem->setUrl(ipActionUrl(array('aa' => ipRoute()->plugin() . '.' . $method->getName())));
                 if (ipRoute()->action() == $method->getName()) {
                     $menuItem->markAsCurrent(true);
                 }
                 $submenuItems[] = $menuItem;
             }
         }
     }
     if (!empty($submenuItems)) {
         return $submenuItems;
     }
     return null;
 }
Exemple #2
0
 public static function ipBeforeController()
 {
     if (!ipRoute()->isAdmin()) {
         return;
     }
     ipAddCss('assets/dataTableWidgetPlugin.css');
 }
Exemple #3
0
 /**
  * @return \Ip\Menu\Item[]
  */
 public static function getSubmenuItems()
 {
     $modules = self::getModuleNames();
     $submenuItems = array();
     if (0) {
         // It is for translation engine to find following strings
         __('Content', 'Ip-admin');
         __('Pages', 'Ip-admin');
         __('Design', 'Ip-admin');
         __('Plugins', 'Ip-admin');
         __('Config', 'Ip-admin');
         __('Languages', 'Ip-admin');
         __('System', 'Ip-admin');
     }
     foreach ($modules as $module) {
         $menuItem = new \Ip\Menu\Item();
         $title = $module;
         if ($title == 'Email') {
             $title = 'Email log';
         }
         $menuItem->setTitle(__($title, 'Ip-admin', false));
         //
         $menuItem->setUrl(ipActionUrl(array('aa' => $module . '.index')));
         if (ipRoute()->controllerClass() == 'Ip\\Internal\\' . $module . '\\AdminController') {
             $menuItem->markAsCurrent(true);
         }
         if (ipAdminPermission($module)) {
             $submenuItems[] = $menuItem;
         }
     }
     return $submenuItems;
 }
Exemple #4
0
 protected function chooseLayout()
 {
     if (ipRoute()->isAdmin()) {
         $this->layout = 'Ip/Internal/Admin/view/layout.php';
     } elseif (\Ip\Internal\Admin\Model::isSafeMode()) {
         $this->layout = 'Ip/Internal/Admin/view/safeModeLayout.php';
     } else {
         $this->layout = 'main.php';
     }
 }
Exemple #5
0
 public static function ipSendResponse($response)
 {
     $enableAdmin = ipGetOption('AnyScript.enableInAdmin', 0);
     if ($enableAdmin && ipRoute()->isAdmin() || !ipRoute()->isAdmin()) {
         $anyJavascript = ipGetOption('AnyScript.anyJavascript');
         $anyCss = ipGetOption('AnyScript.anyCss');
         ipAddJsContent("anyJavascript", $anyJavascript);
         ipAddJsContent("anyCss", '$("head").append("<style>' . preg_replace('/\\s+/', ' ', trim($anyCss)) . '</style>");');
     }
     return $response;
 }
Exemple #6
0
 public static function ipPageUpdated($data)
 {
     if (ipRoute()->plugin() != 'Pages' || ipRoute()->action() != 'updatePage') {
         return;
     }
     $pageId = $data['id'];
     $pagePassword = Model::getPagePassword($pageId);
     if (!isset($data['pagePassword']) && empty($pagePassword)) {
         return;
     }
     Model::updatePagePassword($pageId, $data['pagePassword']);
 }
Exemple #7
0
 public static function ipPageUpdated($data)
 {
     if (ipRoute()->plugin() != 'Pages' || ipRoute()->action() != 'updatePage') {
         return;
         //we want to handle only page updates that are made from within Pages section.
     }
     $pageId = $data['id'];
     $pageImages = Model::getPageImages($pageId);
     if (!isset($data['pageImage']) && empty($pageImages)) {
         return;
     }
     if (empty($data['pageImage']) || !is_array($data['pageImage'])) {
         $data['pageImage'] = array();
     }
     Model::updatePageImages($pageId, $data['pageImage']);
 }
Exemple #8
0
 public static function ipPageUpdated($data)
 {
     if (ipRoute()->plugin() != 'Pages' || ipRoute()->action() != 'updatePage') {
         return;
     }
     if (!isset($data['keywordlist']) && !isset($data['pagedescription'])) {
         return;
     }
     $pageId = $data['id'];
     $keywords = $data['keywordlist'];
     $description = $data['pagedescription'];
     if (empty($keywords) && empty($description)) {
         Model::removePageKey($pageId);
     } else {
         Model::setPageKey($pageId, $keywords, $description);
     }
 }
Exemple #9
0
 public static function ipBeforeController()
 {
     if (ipIsManagementState() || ipRoute()->isAdmin() || ipRequest()->getQuery('ipDesignPreview')) {
         ipAddJs('Ip/Internal/Core/assets/js/jquery-ui/jquery-ui.js');
         ipAddJs('Ip/Internal/Repository/assets/ipRepository.js');
         ipAddJs('Ip/Internal/Repository/assets/ipRepositoryUploader.js');
         ipAddJs('Ip/Internal/Repository/assets/ipRepositoryAll.js');
         ipAddJs('Ip/Internal/Repository/assets/ipRepositoryBuy.js');
         ipAddJs('Ip/Internal/System/assets/market.js');
         ipAddJs('Ip/Internal/Core/assets/js/easyXDM/easyXDM.min.js');
         $marketUrl = ipConfig()->get('imageMarketUrl', 'http://market.impresspages.org/images-v1/');
         $popupData = array('marketUrl' => $marketUrl, 'allowUpload' => ipAdminPermission('Repository upload'), 'allowRepository' => ipAdminPermission('Repository'));
         ipAddJsVariable('ipRepositoryHtml', ipView('view/popup.php', $popupData)->render());
         ipAddJsVariable('ipRepositoryTranslate_confirm_delete', __('Are you sure you want to delete selected files?', 'Ip-admin'));
         ipAddJsVariable('ipRepositoryTranslate_delete_warning', __('Some of the selected files are still used somewhere on your website. Do you still want to remove them? ', 'Ip-admin'));
     }
 }
 /**
  * MasonryGrid.js ask to provide widget management popup HTML. This controller does this.
  * @return \Ip\Response\Json
  * @throws \Ip\Exception\View
  */
 public function widgetPopupHtml()
 {
     $versionParts = explode('.', \Ip\Application::getVersion());
     if (version_compare(\Ip\Application::getVersion(), '4.2.1') < 0) {
         return new \Ip\Response('This widget can be used on ImpressPages 4.2.1 or later.');
     }
     $widgetId = ipRequest()->getQuery('widgetId');
     $widgetRecord = \Ip\Internal\Content\Model::getWidgetRecord($widgetId);
     $widgetData = $widgetRecord['data'];
     $plugin = ipRoute()->plugin();
     //Render form and popup HTML
     $viewData = array('gridUrl' => ipActionUrl(array('aa' => $plugin . '.grid', 'disableAdminNavbar' => 1, 'widgetId' => $widgetId)));
     $popupHtml = ipView('view/editPopup.php', $viewData)->render();
     $data = array('popup' => $popupHtml);
     //Return rendered widget management popup HTML in JSON format
     return new \Ip\Response\Json($data);
 }
Exemple #11
0
 public function __construct()
 {
     $this->fieldsets = array();
     $this->method = self::METHOD_POST;
     $this->action = ipConfig()->baseUrl();
     $this->attributes = array();
     $this->classes = array();
     $this->ajaxSubmit = true;
     $this->validate = true;
     $this->addClass('ipsAjaxSubmit');
     if (ipRoute()->isAdmin()) {
         $this->setEnvironment(self::ENVIRONMENT_ADMIN);
     } else {
         $this->addClass('ipModuleForm');
         $this->setEnvironment(self::ENVIRONMENT_PUBLIC);
     }
     $this->addCsrfCheck();
     $this->addSpamCheck();
 }
 public static function ipPageUpdated($data)
 {
     if (ipRoute()->plugin() != 'Pages' || ipRoute()->action() != 'updatePage') {
         return;
         //we want to handle only page updates that are made from within Pages section.
     }
     $pageId = $data['id'];
     $newTags = array();
     if (isset($data['facebookTagTitle'])) {
         $newTags['title'] = $data['facebookTagTitle'];
     }
     if (isset($data['facebookTagDescription'])) {
         $newTags['description'] = $data['facebookTagDescription'];
     }
     if (isset($data['facebookTagImages'])) {
         $newTags['images'] = $data['facebookTagImages'];
     }
     Model::updateFacebookTags($pageId, $newTags);
 }
 /**
  * GridWidget.js ask to provide widget management popup HTML. This controller does this.
  * @return \Ip\Response\Json
  * @throws \Ip\Exception\View
  */
 public function widgetPopupHtml()
 {
     $versionParts = explode('.', \Ip\Application::getVersion());
     if (empty($versionParts[2]) || $versionParts[0] < 4 || $versionParts[0] == 4 && $versionParts[1] < 2 || $versionParts[0] == 4 && ($versionParts[1] = 2 && $versionParts[2] < 1)) {
         return new \Ip\Response('This widget can be used on ImpressPages 4.2.1 or later.');
     }
     $widgetId = ipRequest()->getQuery('widgetId');
     $widgetRecord = \Ip\Internal\Content\Model::getWidgetRecord($widgetId);
     $widgetData = $widgetRecord['data'];
     //create form prepopulated with current widget data
     $form = $this->managementForm($widgetData);
     $plugin = ipRoute()->plugin();
     //Render form and popup HTML
     $viewData = array('gridUrl' => ipActionUrl(array('aa' => $plugin . '.grid', 'disableAdminNavbar' => 1, 'widgetId' => $widgetId)));
     $popupHtml = ipView('view/editPopup.php', $viewData)->render();
     $data = array('popup' => $popupHtml);
     //Return rendered widget management popup HTML in JSON format
     return new \Ip\Response\Json($data);
 }
Exemple #14
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());
     }
 }
Exemple #15
0
 /**
  * @ignore
  * @param Request $request
  * @param array $options
  * @param bool $subrequest
  * @return Response\Json|Response\PageNotFound|Response\Redirect
  * @throws Exception
  * @ignore
  */
 public function _handleOnlyRequest(\Ip\Request $request, $options = array(), $subrequest = true)
 {
     if (empty($options['skipInitEvents'])) {
         \Ip\ServiceLocator::dispatcher()->_bindApplicationEvents();
     }
     $result = ipJob('ipRouteLanguage', array('request' => $request, 'relativeUri' => $request->getRelativePath()));
     if ($result) {
         $requestLanguage = $result['language'];
         $routeLanguage = $requestLanguage->getCode();
         ipRequest()->_setRoutePath($result['relativeUri']);
     } else {
         $routeLanguage = null;
         $requestLanguage = ipJob('ipRequestLanguage', array('request' => $request));
         ipRequest()->_setRoutePath($request->getRelativePath());
     }
     //find out and set locale
     $locale = $requestLanguage->getCode();
     if (strlen($locale) == '2') {
         $locale = strtolower($locale) . '_' . strtoupper($locale);
     } else {
         $locale = str_replace('-', '_', $locale);
     }
     $locale .= '.utf8';
     if ($locale == "tr_TR.utf8" && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 5)) {
         //Overcoming this bug https://bugs.php.net/bug.php?id=18556
         setlocale(LC_COLLATE, $locale);
         setlocale(LC_MONETARY, $locale);
         setlocale(LC_NUMERIC, $locale);
         setlocale(LC_TIME, $locale);
         setlocale(LC_MESSAGES, $locale);
         setlocale(LC_CTYPE, "en_US.utf8");
     } else {
         setLocale(LC_ALL, $locale);
     }
     setlocale(LC_NUMERIC, "C");
     //user standard C syntax for numbers. Otherwise you will get funny things with when autogenerating CSS, etc.
     ipContent()->_setCurrentLanguage($requestLanguage);
     $_SESSION['ipLastLanguageId'] = $requestLanguage->getId();
     if (empty($options['skipTranslationsInit'])) {
         if (!empty($options['translationsLanguageCode'])) {
             $languageCode = $options['translationsLanguageCode'];
         } else {
             $languageCode = $requestLanguage->getCode();
         }
         $this->initTranslations($languageCode);
     }
     if (empty($options['skipModuleInit'])) {
         $this->modulesInit();
     }
     ipEvent('ipInitFinished');
     $routeAction = ipJob('ipRouteAction', array('request' => $request, 'relativeUri' => ipRequest()->getRoutePath(), 'routeLanguage' => $routeLanguage));
     if (!empty($routeAction)) {
         if (!empty($routeAction['page'])) {
             ipContent()->_setCurrentPage($routeAction['page']);
         }
         if (!empty($routeAction['environment'])) {
             ipRoute()->setEnvironment($routeAction['environment']);
         } else {
             if (!empty($routeAction['controller']) && $routeAction['controller'] == 'AdminController') {
                 ipRoute()->setEnvironment(\Ip\Route::ENVIRONMENT_ADMIN);
             } else {
                 ipRoute()->setEnvironment(\Ip\Route::ENVIRONMENT_PUBLIC);
             }
         }
         if (!empty($routeAction['controller'])) {
             ipRoute()->setController($routeAction['controller']);
         }
         if (!empty($routeAction['plugin'])) {
             ipRoute()->setPlugin($routeAction['plugin']);
         }
         if (!empty($routeAction['name'])) {
             ipRoute()->setName($routeAction['name']);
         }
         if (!empty($routeAction['action'])) {
             ipRoute()->setAction($routeAction['action']);
         }
     }
     //check for CSRF attack
     if (empty($options['skipCsrfCheck']) && $request->isPost() && $request->getPost('securityToken') != $this->getSecurityToken() && (empty($routeAction['controller']) || $routeAction['controller'] != 'PublicController')) {
         ipLog()->error('Core.possibleCsrfAttack', array('post' => ipRequest()->getPost()));
         $data = array('status' => 'error');
         if (ipConfig()->isDevelopmentEnvironment()) {
             $data['errors'] = array('securityToken' => __('Possible CSRF attack. Please pass correct securityToken.', 'Ip-admin'));
         }
         // TODO JSONRPC
         return new \Ip\Response\Json($data);
     }
     if (empty($routeAction)) {
         $routeAction = array('plugin' => 'Core', 'controller' => 'PublicController', 'action' => 'pageNotFound');
     }
     $eventInfo = $routeAction;
     if (!empty($routeAction['plugin'])) {
         $plugin = $routeAction['plugin'];
         $controller = $routeAction['controller'];
         if (in_array($plugin, \Ip\Internal\Plugins\Model::getModules())) {
             $controllerClass = 'Ip\\Internal\\' . $plugin . '\\' . $controller;
         } else {
             if (!in_array($plugin, \Ip\Internal\Plugins\Service::getActivePluginNames())) {
                 throw new \Ip\Exception("Plugin '" . esc($plugin) . "' doesn't exist or isn't activated.");
             }
             $controllerClass = 'Plugin\\' . $plugin . '\\' . $controller;
         }
         if (!class_exists($controllerClass)) {
             throw new \Ip\Exception('Requested controller doesn\'t exist. ' . esc($controllerClass));
         }
         // check if user is logged in
         if ($controller == 'AdminController' && !\Ip\Internal\Admin\Backend::userId()) {
             if (ipConfig()->get('rewritesDisabled')) {
                 return new \Ip\Response\Redirect(ipConfig()->baseUrl() . 'index.php/admin');
             } else {
                 return new \Ip\Response\Redirect(ipConfig()->baseUrl() . 'admin');
             }
         }
         if ($controller == 'AdminController') {
             if (!ipAdminPermission($plugin)) {
                 throw new \Ip\Exception('User has no permission to access ' . esc($plugin) . '');
             }
         }
         $eventInfo['controllerClass'] = $controllerClass;
         $eventInfo['controllerType'] = $controller;
     }
     if (empty($eventInfo['page'])) {
         $eventInfo['page'] = null;
     }
     // change layout if safe mode
     if (\Ip\Internal\Admin\Service::isSafeMode()) {
         ipSetLayout(ipFile('Ip/Internal/Admin/view/safeModeLayout.php'));
     } else {
         if ($eventInfo['page']) {
             ipSetLayout($eventInfo['page']->getLayout());
         }
     }
     ipEvent('ipBeforeController', $eventInfo);
     $controllerAnswer = ipJob('ipExecuteController', $eventInfo);
     return $controllerAnswer;
 }