/**
  * Updates the CMS fields adding the fields defined in this extension
  * @param {FieldList} $fields Field List that new fields will be added to
  */
 public function updateSettingsFields(FieldList $fields)
 {
     $kapostRefID = $this->owner->KapostRefID;
     if (!empty($kapostRefID)) {
         if (CMSPageSettingsController::has_extension('KapostPageSettingsControllerExtension')) {
             $messageContent = _t('KapostSiteTreeExtension.KAPOST_CONTENT_WARNING_RO', '_This Page\'s content is being populated by Kapost, some fields are not editable.');
         } else {
             $messageContent = _t('KapostSiteTreeExtension.KAPOST_CONTENT_WARNING', '_This Page\'s content is being populated by Kapost.');
         }
         //Edit in kapost link
         $kapostBase = KapostAdmin::config()->kapost_base_url;
         if (!empty($kapostBase)) {
             $messageContent .= ' <a href="' . Controller::join_links($kapostBase, 'posts', $kapostRefID) . '" target="_blank">' . _t('KapostSiteTreeExtension.KAPOST_CONTENT_EDIT_LABEL', '_Click here to edit in Kapost') . '</a>';
         }
         $fields->insertBefore(new LiteralField('KapostContentWarning', '<div class="message warning">' . $messageContent . '</div>'), 'ClassName');
         //Detect Incoming Changes
         if (Permission::check('CMS_ACCESS_KapostAdmin')) {
             $incoming = KapostObject::get()->filter('KapostRefID', Convert::raw2sql($kapostRefID));
             if ($incoming->count() >= 1) {
                 $link = Controller::join_links(AdminRootController::config()->url_base, KapostAdmin::config()->url_segment, 'KapostObject/EditForm/field/KapostObject/item', $incoming->first()->ID, 'edit');
                 $messageContent = _t('KapostSiteTreeExtension.KAPOST_INCOMING', '_There are incoming changes from Kapost waiting for this page.') . ' ' . '<a href="' . $link . '" class="cms-panel-link">' . _t('KapostSiteTreeExtension.KAPOST_INCOMING_VIEW', '_Click here to view the changes') . '</a>';
                 $fields->insertBefore(new LiteralField('KapostIncomingWarning', '<div class="message warning">' . $messageContent . '</div>'), 'ClassName');
             }
         }
     }
 }
 /**
  * Gets a list of url_pattern => controller k/v pairs for each LeftAndMain derived controller
  */
 public static function rules()
 {
     if (self::$_rules === null) {
         self::$_rules = array();
         // Map over the array calling add_rule_for_controller on each
         $classes = CMSMenu::get_cms_classes(null, true, CMSMenu::URL_PRIORITY);
         array_map(array(__CLASS__, 'add_rule_for_controller'), $classes);
     }
     return self::$_rules;
 }
 /**
  * Gets a list of url_pattern => controller k/v pairs for each LeftAndMain derived controller
  */
 public static function rules()
 {
     if (self::$_rules === null) {
         self::$_rules = array();
         // Build an array of class => url_priority k/v pairs
         $classes = array();
         foreach (CMSMenu::get_cms_classes() as $class) {
             $classes[$class] = Config::inst()->get($class, 'url_priority', Config::FIRST_SET);
         }
         // Sort them so highest priority item is first
         arsort($classes, SORT_NUMERIC);
         // Map over the array calling add_rule_for_controller on each
         array_map(array(__CLASS__, 'add_rule_for_controller'), array_keys($classes));
     }
     return self::$_rules;
 }
 /**
  * Return a CMSMenuItem to add the given controller to the CMSMenu
  *
  * @param string $controllerClass
  * @return CMSMenuItem
  */
 protected static function menuitem_for_controller($controllerClass)
 {
     $urlBase = AdminRootController::admin_url();
     $urlSegment = Config::inst()->get($controllerClass, 'url_segment', Config::FIRST_SET);
     $menuPriority = Config::inst()->get($controllerClass, 'menu_priority', Config::FIRST_SET);
     // Don't add menu items defined the old way
     if (!$urlSegment) {
         return null;
     }
     $link = Controller::join_links($urlBase, $urlSegment) . '/';
     // doesn't work if called outside of a controller context (e.g. in _config.php)
     // as the locale won't be detected properly. Use {@link LeftAndMain->MainMenu()} to update
     // titles for existing menu entries
     $menuTitle = LeftAndMain::menu_title($controllerClass);
     return new CMSMenuItem($menuTitle, $link, $controllerClass, $menuPriority);
 }
 public function init()
 {
     if (!Controller::has_curr()) {
         return;
     }
     /* @var $ctrl Controller */
     $ctrl = Controller::curr();
     /* @ var $req SS_HTTPRequest */
     $req = $ctrl->getRequest();
     // Otherwise it will get excluded if it does not have access to all subsites...
     if (class_exists('Subsite')) {
         Subsite::$disable_subsite_filter = true;
     }
     $base = AdminRootController::config()->url_base;
     $defaultPanel = AdminRootController::config()->default_panel;
     $currentSegment = $req->getURL();
     // We will fail if we are redirected to a panel without the proper permission
     if (($currentSegment == $base || $currentSegment == $base . '/pages') && $defaultPanel == 'CMSPagesController' && !Permission::check('CMS_ACCESS_CMSMain')) {
         // Instead, let's redirect to something we can access
         if (Permission::check('CMS_ACCESS')) {
             $member = Member::currentUser();
             $permissions = Permission::permissions_for_member($member->ID);
             foreach ($permissions as $permission) {
                 if (strpos($permission, 'CMS_ACCESS_') === 0) {
                     $class = str_replace('CMS_ACCESS_', '', $permission);
                     $segment = Config::inst()->get($class, 'url_segment');
                     $url = Director::absoluteBaseURL() . $base . '/' . $segment;
                     header('Location:' . $url);
                     exit;
                 }
             }
         }
     }
     if (class_exists('Subsite')) {
         Subsite::$disable_subsite_filter = false;
     }
 }
Example #6
0
 /**
  * Given a successful login, tell the parent frame to close the dialog
  *
  * @return SS_HTTPResponse
  */
 public function success()
 {
     // Ensure member is properly logged in
     if (!Member::currentUserID()) {
         return $this->redirectToExternalLogin();
     }
     // Get redirect url
     $controller = $this->getResponseController(_t('CMSSecurity.SUCCESS', 'Success'));
     $backURLs = array($this->getRequest()->requestVar('BackURL'), Session::get('BackURL'), Director::absoluteURL(AdminRootController::config()->url_base, true));
     foreach ($backURLs as $backURL) {
         if ($backURL && Director::is_site_url($backURL)) {
             break;
         }
     }
     // Show login
     $controller = $controller->customise(array('Content' => _t('CMSSecurity.SUCCESSCONTENT', '<p>Login success. If you are not automatically redirected ' . '<a target="_top" href="{link}">click here</a></p>', 'Login message displayed in the cms popup once a user has re-authenticated themselves', array('link' => $backURL))));
     return $controller->renderWith($this->getTemplatesFor('success'));
 }
 /**
  * @todo Coupling with cms module, remove this method.
  *
  * @return string
  */
 public function DeleteLink()
 {
     return Controller::join_links(Director::absoluteBaseURL(), AdminRootController::admin_url(), "assets/removefile/", $this->ID);
 }
 /**
  * Returns the main menu of the CMS.  This is also used by init()
  * to work out which sections the user has access to.
  *
  * @param bool $cached
  * @return SS_List
  */
 public function MainMenu($cached = true)
 {
     if (!isset($this->_cache_MainMenu) || !$cached) {
         // Don't accidentally return a menu if you're not logged in - it's used to determine access.
         if (!Member::currentUser()) {
             return new ArrayList();
         }
         // Encode into DO set
         $menu = new ArrayList();
         $menuItems = CMSMenu::get_viewable_menu_items();
         // extra styling for custom menu-icons
         $menuIconStyling = '';
         if ($menuItems) {
             foreach ($menuItems as $code => $menuItem) {
                 // alternate permission checks (in addition to LeftAndMain->canView())
                 if (isset($menuItem->controller) && $this->hasMethod('alternateMenuDisplayCheck') && !$this->alternateMenuDisplayCheck($menuItem->controller)) {
                     continue;
                 }
                 $linkingmode = "link";
                 if ($menuItem->controller && get_class($this) == $menuItem->controller) {
                     $linkingmode = "current";
                 } else {
                     if (strpos($this->Link(), $menuItem->url) !== false) {
                         if ($this->Link() == $menuItem->url) {
                             $linkingmode = "current";
                             // default menu is the one with a blank {@link url_segment}
                         } else {
                             if (singleton($menuItem->controller)->stat('url_segment') == '') {
                                 if ($this->Link() == AdminRootController::admin_url()) {
                                     $linkingmode = "current";
                                 }
                             } else {
                                 $linkingmode = "current";
                             }
                         }
                     }
                 }
                 // already set in CMSMenu::populate_menu(), but from a static pre-controller
                 // context, so doesn't respect the current user locale in _t() calls - as a workaround,
                 // we simply call LeftAndMain::menu_title() again
                 // if we're dealing with a controller
                 if ($menuItem->controller) {
                     $title = LeftAndMain::menu_title($menuItem->controller);
                 } else {
                     $title = $menuItem->title;
                 }
                 // Provide styling for custom $menu-icon. Done here instead of in
                 // CMSMenu::populate_menu(), because the icon is part of
                 // the CMS right pane for the specified class as well...
                 if ($menuItem->controller) {
                     $menuIcon = LeftAndMain::menu_icon_for_class($menuItem->controller);
                     if (!empty($menuIcon)) {
                         $menuIconStyling .= $menuIcon;
                     }
                 }
                 $menu->push(new ArrayData(array("MenuItem" => $menuItem, "AttributesHTML" => $menuItem->getAttributesHTML(), "Title" => Convert::raw2xml($title), "Code" => DBField::create_field('Text', $code), "Link" => $menuItem->url, "LinkingMode" => $linkingmode)));
             }
         }
         if ($menuIconStyling) {
             Requirements::customCSS($menuIconStyling);
         }
         $this->_cache_MainMenu = $menu;
     }
     return $this->_cache_MainMenu;
 }
    public function schema($request)
    {
        // TODO Hardcoding schema until we can get GridField to generate a schema dynamically
        $treeClassJS = Convert::raw2js($this->config()->tree_class);
        $adminURL = Convert::raw2js(AdminRootController::admin_url());
        $json = <<<JSON
{
\t"id": "Form_EditForm",
\t"schema": {
\t\t"name": "EditForm",
\t\t"id": "Form_EditForm",
\t\t"action": "schema",
\t\t"method": "GET",
\t\t"schema_url": "{$adminURL}campaigns\\/schema\\/EditForm",
\t\t"attributes": {
\t\t\t"id": "Form_EditForm",
\t\t\t"action": "{$adminURL}campaigns\\/EditForm",
\t\t\t"method": "POST",
\t\t\t"enctype": "multipart\\/form-data",
\t\t\t"target": null
\t\t},
\t\t"data": [],
\t\t"fields": [{
\t\t\t"name": "ID",
\t\t\t"id": "Form_EditForm_ID",
\t\t\t"type": "Hidden",
\t\t\t"component": null,
\t\t\t"holder_id": null,
\t\t\t"title": false,
\t\t\t"source": null,
\t\t\t"extraClass": "hidden form-group--no-label",
\t\t\t"description": null,
\t\t\t"rightTitle": null,
\t\t\t"leftTitle": null,
\t\t\t"readOnly": false,
\t\t\t"disabled": false,
\t\t\t"customValidationMessage": "",
\t\t\t"attributes": [],
\t\t\t"data": []
\t\t}, {
\t\t\t"name": "ChangeSets",
\t\t\t"id": "Form_EditForm_ChangeSets",
\t\t\t"type": "Custom",
\t\t\t"component": "GridField",
\t\t\t"holder_id": null,
\t\t\t"title": "Campaigns",
\t\t\t"source": null,
\t\t\t"extraClass": null,
\t\t\t"description": null,
\t\t\t"rightTitle": null,
\t\t\t"leftTitle": null,
\t\t\t"readOnly": false,
\t\t\t"disabled": false,
\t\t\t"customValidationMessage": "",
\t\t\t"attributes": [],
\t\t\t"data": {
\t\t\t\t"recordType": "{$treeClassJS}",
\t\t\t\t"collectionReadEndpoint": {
\t\t\t\t\t"url": "{$adminURL}campaigns\\/sets",
\t\t\t\t\t"method": "GET"
\t\t\t\t},
\t\t\t\t"itemReadEndpoint": {
\t\t\t\t\t"url": "{$adminURL}campaigns\\/set\\/:id",
\t\t\t\t\t"method": "GET"
\t\t\t\t},
\t\t\t\t"itemUpdateEndpoint": {
\t\t\t\t\t"url": "{$adminURL}campaigns\\/set\\/:id",
\t\t\t\t\t"method": "PUT"
\t\t\t\t},
\t\t\t\t"itemCreateEndpoint": {
\t\t\t\t\t"url": "{$adminURL}campaigns\\/set\\/:id",
\t\t\t\t\t"method": "POST"
\t\t\t\t},
\t\t\t\t"itemDeleteEndpoint": {
\t\t\t\t\t"url": "{$adminURL}campaigns\\/set\\/:id",
\t\t\t\t\t"method": "DELETE"
\t\t\t\t},
\t\t\t\t"editFormSchemaEndpoint": "{$adminURL}campaigns\\/schema\\/DetailEditForm",
\t\t\t\t"columns": [
\t\t\t\t\t{"name": "Title", "field": "Name"},
\t\t\t\t\t{"name": "Changes", "field": "ChangesCount"},
\t\t\t\t\t{"name": "Description", "field": "Description"}
\t\t\t\t]
\t\t\t}
\t\t}, {
\t\t\t"name": "SecurityID",
\t\t\t"id": "Form_EditForm_SecurityID",
\t\t\t"type": "Hidden",
\t\t\t"component": null,
\t\t\t"holder_id": null,
\t\t\t"title": "Security ID",
\t\t\t"source": null,
\t\t\t"extraClass": "hidden",
\t\t\t"description": null,
\t\t\t"rightTitle": null,
\t\t\t"leftTitle": null,
\t\t\t"readOnly": false,
\t\t\t"disabled": false,
\t\t\t"customValidationMessage": "",
\t\t\t"attributes": [],
\t\t\t"data": []
\t\t}],
\t\t"actions": []
\t}
}
JSON;
        $formName = $request->param('ID');
        if ($formName == 'EditForm') {
            $response = $this->getResponse();
            $response->addHeader('Content-Type', 'application/json');
            $response->setBody($json);
            return $response;
        } else {
            return parent::schema($request);
        }
    }