public function connect()
 {
     if (!($member = Member::currentUser())) {
         /** @var stdClass $params */
         $params = $this->getAccessToken($this->request->getVar('code'));
         // member is not currently logged into SilverStripe. Look up
         // for a member with the UID which matches first.
         $member = Member::get()->filter(array("VkUID" => $params->user_id))->first();
         if (!$member) {
             // see if we have a match based on email. From a
             // security point of view, users have to confirm their
             // email address in facebook so doing a match up is fine
             $email = $params->email;
             if ($email) {
                 $member = Member::get()->filter(array('Email' => $email))->first();
             }
         }
         if (!$member) {
             $member = Injector::inst()->create('Member');
             $member->syncVkDetails($this->getUserInfo());
         }
     }
     $member->logIn(true);
     // redirect the user to the provided url, otherwise take them
     // back to the route of the website.
     if ($url = Session::get(VkControllerExtension::SESSION_REDIRECT_URL_FLAG)) {
         return $this->redirect($url);
     } else {
         return $this->redirect(Director::absoluteBaseUrl());
     }
 }
 public function doContinue($data)
 {
     Session::set('Checkout.PaymentMethodID', $data['PaymentMethodID']);
     Session::set("Checkout.PostageID", $data["PostageID"]);
     $url = Controller::join_links(Director::absoluteBaseUrl(), Payment_Controller::config()->url_segment);
     return $this->controller->redirect($url);
 }
 public function connect()
 {
     // check we have a valid session
     $appId = Config::inst()->get('FacebookControllerExtension', 'app_id');
     $secret = Config::inst()->get('FacebookControllerExtension', 'api_secret');
     $session = $this->getFacebookHelper()->getSessionFromRedirect();
     if ($session) {
         $token = $session->getAccessToken();
         // get a long lived token by default. Access token is saved in
         // session.
         try {
             $long = $token->extend($appId, $secret);
             if ($long) {
                 $accessTokenValue = (string) $long;
             } else {
                 $accessTokenValue = (string) $token;
             }
         } catch (Exception $e) {
             $accessTokenValue = (string) $token;
         }
         try {
             Session::set(FacebookControllerExtension::FACEBOOK_ACCESS_TOKEN, $accessTokenValue);
             $fields = Config::inst()->get('FacebookControllerExtension', 'facebook_fields');
             $user = (new FacebookRequest($session, 'GET', '/me', array('fields' => implode(',', $fields))))->execute()->getGraphObject(GraphUser::className());
             if (!($member = Member::currentUser())) {
                 // member is not currently logged into SilverStripe. Look up
                 // for a member with the UID which matches first.
                 $member = Member::get()->filter(array("FacebookUID" => $user->getId()))->first();
                 if (!$member) {
                     // see if we have a match based on email. From a
                     // security point of view, users have to confirm their
                     // email address in facebook so doing a match up is fine
                     $email = $user->getProperty('email');
                     if ($email) {
                         $member = Member::get()->filter(array('Email' => $email))->first();
                     }
                 }
                 if (!$member) {
                     $member = Injector::inst()->create('Member');
                 }
             }
             $member->syncFacebookDetails($user);
             $member->logIn();
             // redirect the user to the provided url, otherwise take them
             // back to the route of the website.
             if ($url = Session::get(FacebookControllerExtension::SESSION_REDIRECT_URL_FLAG)) {
                 return $this->redirect($url);
             } else {
                 return $this->redirect(Director::absoluteBaseUrl());
             }
         } catch (Exception $e) {
             SS_Log::log($e, SS_Log::ERR);
         }
     } else {
         return $this->httpError(400);
     }
     return $this->httpError(400);
 }
 function testUrlsToPathsWithAbsoluteUrls()
 {
     $fsp = new FilesystemPublisher('.', 'html');
     $url = Director::absoluteBaseUrl();
     $this->assertEquals($fsp->urlsToPaths(array($url)), array($url => './index.html'), 'Root URL path mapping');
     $url = Director::absoluteBaseUrl() . 'about-us';
     $this->assertEquals($fsp->urlsToPaths(array($url)), array($url => './about-us.html'), 'URLsegment path mapping');
     $url = Director::absoluteBaseUrl() . 'parent/child';
     $this->assertEquals($fsp->urlsToPaths(array($url)), array($url => 'parent/child.html'), 'Nested URLsegment path mapping');
 }
 public function description()
 {
     $viewer = new DocumentationViewer();
     if (!$viewer->canView()) {
         return Security::permissionFailure($this);
     }
     if (!Config::inst()->get('DocumentationSearch', 'enabled')) {
         return $this->httpError('404');
     }
     $data = DocumentationSearch::get_meta_data();
     $link = Director::absoluteBaseUrl() . ($data['SearchPageLink'] = Controller::join_links($viewer->Link(), 'results/?Search={searchTerms}&start={startIndex}&length={count}&action_results=1'));
     $data['SearchPageAtom'] = $data['SearchPageLink'] . '&format=atom';
     return $this->customise(new ArrayData($data))->renderWith(array('OpenSearchDescription'));
 }
 public function __construct($member = null)
 {
     $member = $member ? $member : Member::currentUser();
     $link = Director::absoluteBaseUrl();
     $host = parse_url($link, PHP_URL_HOST);
     $this->subject = _t('WelcomeEmail.SUBJECT', "Welcome to {Website}", 'Email subject', ['Website' => SiteConfig::current_site_config()->Title]);
     if ($member) {
         $this->to = $member->Email;
         if ($member->FirstName) {
             $name = trim($member->FirstName . ' ' . $member->Surname);
             $this->to = $name . ' <' . $member->Email . '>';
         }
     }
     parent::__construct();
     $this->populateTemplate(new ArrayData(['Member' => $member, 'AbsoluteWebsiteLink' => $link, 'WebsiteLink' => $host]));
 }
 protected function templateArray()
 {
     global $project;
     $config = SiteConfig::current_site_config();
     if ($config->Theme) {
         Config::inst()->update('SSViewer', 'theme_enabled', true);
         Config::inst()->update('SSViewer', 'theme', $config->Theme);
     }
     $theme = $config->Theme;
     $manifest = SS_TemplateLoader::instance()->getManifest();
     $templateList = array();
     foreach ($manifest->getTemplates() as $template_name => $templateInfo) {
         $projectexists = isset($templateInfo[$project]) && isset($templateInfo[$project]['Patterns']);
         $themeexists = $theme && isset($templateInfo['themes'][$theme]) && isset($templateInfo['themes'][$theme]['Patterns']);
         //always use project template files, and grab template files if not already used
         if ($projectexists || $themeexists && !isset($templateList[$template_name])) {
             $templateList[$template_name] = array('Link' => Controller::join_links(Director::absoluteBaseUrl(), 'patterns', 'index', $template_name), 'Name' => $this->stripeTemplateName($template_name), 'Template' => $template_name);
         }
     }
     ksort($templateList);
     return $templateList;
 }
 /**
  * @return string
  */
 public function getVkCallbackLink()
 {
     return Controller::join_links(Director::absoluteBaseUrl(), 'VkConnectAuthCallback/connect');
 }
Пример #9
0
 function baseurl()
 {
     return Director::absoluteBaseUrl() . "\n";
 }
 public function ItemEditForm()
 {
     Requirements::javascript("orders/javascript/entwine.orders.js");
     $form = parent::ItemEditForm();
     $fields = $form->Fields();
     $actions = $form->Actions();
     $record = $this->record;
     $member = Member::currentUser();
     $can_view = $this->record->canView();
     $can_edit = $this->record->canEdit();
     $can_change_status = $this->record->canChangeStatus();
     $can_delete = $this->record->canDelete();
     $can_create = $this->record->canCreate();
     // First remove the delete button
     $actions->removeByName("action_doDelete");
     // Deal with Estimate objects
     if ($record->ClassName == "Estimate") {
         if ($record->ID && $record->AccessKey) {
             $frontend_url = Controller::join_links(Director::absoluteBaseUrl(), "OrdersFront", "quote", $record->ID, $record->AccessKey);
             $html = '<a href="' . $frontend_url . '" ';
             $html .= 'target="_blank" ';
             $html .= 'class="action ss-ui-button ui-button ui-corner-all open-external" ';
             $html .= '>' . _t('Orders.ViewQuote', 'View Quote') . '</a>';
             $actions->insertAfter(LiteralField::create('openQuote', $html), "action_doSave");
         }
         if ($record->ID && $can_edit) {
             $actions->insertAfter(FormAction::create('doConvert', _t('Orders.ConvertToOrder', 'Convert To Order'))->setUseButtonTag(true), "action_doSave");
         }
     }
     // Deal with Order objects
     if ($record->ClassName == "Order") {
         // Set our status field as a dropdown (has to be here to
         // ignore canedit)
         // Allow users to change status (as long as they have permission)
         if ($can_edit || $can_change_status) {
             $status_field = DropdownField::create('Status', null, $record->config()->statuses);
             // Set default status if we can
             if (!$record->Status && !$record->config()->default_status) {
                 $status_field->setValue($record->config()->default_status);
             } else {
                 $status_field->setValue($record->Status);
             }
             $fields->replaceField("Status", $status_field);
         }
         // Setup order history
         if (Permission::check(array('COMMERCE_ORDER_HISTORY', 'ADMIN'), 'any', $member)) {
             $versions = $record->AllVersions();
             $first_version = $versions->First();
             $curr_version = $first_version ? $versions->First() : null;
             $message = "";
             foreach ($versions as $version) {
                 $i = $version->Version;
                 $name = "History_{$i}";
                 if ($i > 0) {
                     $frm = Versioned::get_version($record->class, $record->ID, $i - 1);
                     $to = Versioned::get_version($record->class, $record->ID, $i);
                     $diff = new DataDifferencer($frm, $to);
                     if ($version->Author()) {
                         $message = "<p>{$version->Author()->FirstName} ({$version->LastEdited})</p>";
                     } else {
                         $message = "<p>Unknown ({$version->LastEdited})</p>";
                     }
                     if ($diff->ChangedFields()->exists()) {
                         $message .= "<ul>";
                         // Now loop through all changed fields and track as message
                         foreach ($diff->ChangedFields() as $change) {
                             if ($change->Name != "LastEdited") {
                                 $message .= "<li>{$change->Title}: {$change->Diff}</li>";
                             }
                         }
                         $message .= "</ul>";
                     }
                     $fields->addFieldToTab("Root.History", LiteralField::create($name, "<div class=\"field\">{$message}</div>"));
                 }
             }
         }
         // Is user cannot edit, but can change status, add change
         // status button
         if ($record->ID && !$can_edit && $can_change_status) {
             $actions->push(FormAction::create('doChangeStatus', _t('Orders.Save', 'Save'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept'));
         }
         if ($record->ID && $record->AccessKey) {
             $frontend_url = Controller::join_links(Director::absoluteBaseUrl(), "OrdersFront", "invoice", $record->ID, $record->AccessKey);
             $html = '<a href="' . $frontend_url . '" ';
             $html .= 'target="_blank" ';
             $html .= 'class="action ss-ui-button ui-button ui-corner-all open-external" ';
             $html .= '>' . _t('Orders.ViewInvoice', 'View Invoice') . '</a>';
             $link_field = LiteralField::create('openQuote', $html);
             if ($actions->find("Name", "action_doSave")) {
                 $actions->insertAfter($link_field, "action_doSave");
             }
             if ($actions->find("Name", "action_doChangeStatus")) {
                 $actions->insertAfter($link_field, "action_doChangeStatus");
             }
         }
     }
     // Add a duplicate button, either after the save button or
     // the change status "save" button.
     if ($record->ID) {
         $duplicate_button = FormAction::create('doDuplicate', _t('Orders.Duplicate', 'Duplicate'))->setUseButtonTag(true);
         if ($actions->find("Name", "action_doSave")) {
             $actions->insertAfter($duplicate_button, "action_doSave");
         }
         if ($actions->find("Name", "action_doChangeStatus")) {
             $actions->insertAfter($duplicate_button, "action_doChangeStatus");
         }
     }
     // Finally, if allowed, re-add the delete button (so it is last)
     if ($record->ID && $can_delete) {
         $actions->push(FormAction::create('doDelete', _t('GridFieldDetailForm.Delete', 'Delete'))->setUseButtonTag(true)->addExtraClass('ss-ui-action-destructive action-delete'));
     }
     // Set our custom template
     $form->setTemplate("OrdersItemEditForm");
     $this->extend("updateItemEditForm", $form);
     return $form;
 }
 /**
  * @return string
  */
 public function AbsoluteLink($action)
 {
     return Controller::join_links(Director::absoluteBaseUrl(), $this->Link($action));
 }