本文整理汇总了PHP中Director::absoluteBaseURL方法的典型用法代码示例。如果您正苦于以下问题:PHP Director::absoluteBaseURL方法的具体用法?PHP Director::absoluteBaseURL怎么用?PHP Director::absoluteBaseURL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Director
的用法示例。
在下文中一共展示了Director::absoluteBaseURL方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
public function register(SS_HTTPRequest $request)
{
if ($request->isPOST()) {
try {
if (Customer::get()->filter('Email', $request->postVar('Email'))->count()) {
throw new ValidationException("Sorry a member with that email address already exists");
}
$password = Customer::create_new_password();
/** @var Customer $member */
$member = Injector::inst()->create('ProfiledMemberClass');
$member->changePassword($password);
// update member with cleansed posted variables
$updateData = array_merge(ProfiledMemberForm::update_models('register', array_merge($request->postVars(), ['Password' => $password]), $member));
/** @var CryptofierImplementation $crypto */
$crypto = Injector::inst()->get('CryptofierService');
$token = $crypto->friendly($crypto->encrypt($member->Email));
$member->{ProfiledMemberExtension::VerificationFieldName} = $token;
$member->write();
$member->addToGroupByCode(self::CustomerGroupCode);
// add verification link and HasRegisteredFlag
$updateData = array_merge(['Password' => $password, 'VerificationLink' => Controller::join_links(Director::absoluteBaseURL(), $this()->ActionLink("verify/{$token}"))], $updateData);
$this->sendEmail('Register', $member, $updateData);
Session::set(self::SessionEmailKey, $member->Email);
$url = CrackerjackModule::get_config_setting(__CLASS__, 'post_register_url') ?: $this()->ActionLink('thanks');
return $this()->redirect($url);
} catch (ValidationException $e) {
ProfiledMemberForm::set_form_message($e->getMessage(), CrackerjackForm::Bad);
return $this()->redirectBack();
}
} else {
return array();
}
}
示例2: getCMSFields
public function getCMSFields()
{
$datetimeField = DatetimeField::create("Date")->setTitle($this->fieldLabel("Date"));
$datetimeField->getDateField()->setConfig("dmyfields", true);
// Check if NewsImage should be saved in a seperate folder
if (self::config()->save_image_in_seperate_folder == false) {
$UploadField = UploadField::create("NewsImage")->setTitle($this->fieldLabel("NewsImage"))->setFolderName("news");
} else {
if ($this->ID == "0") {
$UploadField = FieldGroup::create(LiteralField::create("Save", $this->fieldLabel("SaveHelp")))->setTitle($this->fieldLabel("NewsImage"));
} else {
$UploadField = UploadField::create("NewsImage")->setTitle($this->fieldLabel("NewsImage"))->setFolderName("news/" . $this->URLSegment);
}
}
// Create direct link to NewsArticle
if ($this->ID == "0") {
// Little hack to hide $urlsegment when article isn't saved yet.
$urlsegment = LiteralField::create("NoURLSegmentYet", "");
} else {
if ($NewsHolder = $this->NewsHolder()) {
$baseLink = Controller::join_links(Director::absoluteBaseURL(), $NewsHolder->Link(), $this->URLSegment);
}
$urlsegment = Fieldgroup::create(LiteralField::create("URLSegment", "URLSegment")->setContent('<a href="' . $baseLink . '" target="_blank">' . $baseLink . '</a>'))->setTitle("URLSegment");
}
$fields = FieldList::create(new TabSet("Root", new Tab("Main", $urlsegment, TextField::create("Title")->setTitle($this->fieldLabel("Title")), $datetimeField, HTMLEditorField::create("Content")->setTitle($this->fieldLabel("Content")), $UploadField)));
$this->extend("updateCMSFields", $fields);
return $fields;
}
示例3: generateSiteMap
public function generateSiteMap($sitemap = 'sitemap.xml', $siteURL = null)
{
$siteData = singleton('SiteDataService');
$pages = $siteData->getItems();
$xml = new SimpleXMLElement('<urlset></urlset>');
$xml->addAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
$xml->addAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$xml->addAttribute('xsi:schemaLocation', 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd');
if (!$siteURL) {
$siteURL = self::config()->get('base_url');
if (!$siteURL) {
$siteURL = Director::absoluteBaseURL();
}
}
$siteURL = rtrim($siteURL, '/') . '/';
if (!strpos($siteURL, ':/')) {
$siteURL = $this->config()->protocol . '://' . $siteURL;
}
foreach ($pages as $page) {
$url = $xml->addChild('url');
$url->addChild('loc', $siteURL . $page->Link);
$url->addChild('changefreq', $page->ChangeFreq);
$url->addChild('priority', $page->Priority);
}
file_put_contents($sitemap, $xml->asXML());
}
示例4: subscribeRealtime
public function subscribeRealtime()
{
$subID = $_GET['subscription'];
$sub = InstagramSubscription::get()->byID($subID);
$callback = Director::absoluteBaseURL() . Config::inst()->get('Instagram', 'subscribeCallback');
$type = $sub->Type;
if ($type !== 'tag' && $type !== 'user') {
throw new Exception('Subscription type is invalid');
}
$url = 'v1/subscriptions';
if ($type == 'tag') {
$key = $sub->Hashtag;
$data = array("client_id" => $this->clientID, 'client_secret' => $this->clientSecret, 'object' => 'tag', 'object_id' => $key, 'aspect' => 'media', 'callback_url' => $callback);
} else {
if ($type == 'user') {
$data = array("client_id" => $this->clientID, 'client_secret' => $this->clientSecret, 'object' => 'user', 'aspect' => 'media', 'verify_token' => $sub->AccessToken, 'callback_url' => $callback);
}
}
$res = $this->json_request($url, 'POST', $data);
if ($res->meta->code == 200) {
$sub->SubscriptionID = $res->data->id;
$sub->write();
return true;
} else {
throw new Exception('Error Subscribing to Instagram');
}
}
示例5: ConvertURL
public function ConvertURL($url, $filename, $useCacheIfAvailable = false)
{
$folderFilename = '';
if (isset($_GET["flush"])) {
$useCacheIfAvailable = false;
}
$folderFilename = $this->file2FolderFilename($filename);
if ($folderFilename && $useCacheIfAvailable) {
if (file_exists($folderFilename)) {
$url = Director::absoluteBaseURL() . $this->file2FolderFilename($filename, true);
header("Location: {$url}");
exit;
}
}
try {
$pdf = $this->pdf->convertURI($url);
} catch (PdfcrowdException $e) {
return "Pdfcrowd Error: " . $e->getMessage();
}
if ($folderFilename = $this->file2FolderFilename($filename)) {
if (!$pdf) {
$pdf = "error occured";
}
$this->removeCachedPDF($filename);
$fh = fopen($folderFilename, 'w');
fwrite($fh, $pdf);
fclose($fh);
}
return $this->outputPDF($pdf, $filename);
}
示例6: testExternalBackUrlRedirectionDisallowed
function testExternalBackUrlRedirectionDisallowed() {
$page = new SiteTree();
$page->URLSegment = 'testpage';
$page->Title = 'Testpage';
$page->write();
$page->publish('Stage','Live');
// Test internal relative redirect
$response = $this->doTestLoginForm('noexpiry@silverstripe.com', '1nitialPassword', 'testpage');
$this->assertEquals(302, $response->getStatusCode());
$this->assertRegExp('/testpage/', $response->getHeader('Location'),
"Internal relative BackURLs work when passed through to login form"
);
// Log the user out
$this->session()->inst_set('loggedInAs', null);
// Test internal absolute redirect
$response = $this->doTestLoginForm('noexpiry@silverstripe.com', '1nitialPassword', Director::absoluteBaseURL() . 'testpage');
// for some reason the redirect happens to a relative URL
$this->assertRegExp('/^' . preg_quote(Director::absoluteBaseURL(), '/') . 'testpage/', $response->getHeader('Location'),
"Internal absolute BackURLs work when passed through to login form"
);
// Log the user out
$this->session()->inst_set('loggedInAs', null);
// Test external redirect
$response = $this->doTestLoginForm('noexpiry@silverstripe.com', '1nitialPassword', 'http://myspoofedhost.com');
$this->assertNotRegExp('/^' . preg_quote('http://myspoofedhost.com', '/') . '/', $response->getHeader('Location'),
"Redirection to external links in login form BackURL gets prevented as a measure against spoofing attacks"
);
// Log the user out
$this->session()->inst_set('loggedInAs', null);
}
示例7: index
function index()
{
Session::clear("loggedInAs");
Requirements::themedCSS("form");
// if the email address is given
$emailAddress = Convert::raw2sql($this->urlParams['Email']);
$mailingListID = (int) $this->urlParams['MailingList'];
if ($mailingListID) {
$mailingList = DataObject::get_by_id("NewsletterType", $mailingListID);
}
// try to find the member with the email specified
if ($emailAddress) {
$member = DataObject::get_one('Member', "`Email` = '{$emailAddress}'");
} else {
$member = false;
}
// if the email address and mailing list is given in the URL and both are valid,
// then unsubscribe the user
if ($member && $mailingList && $member->inGroup($mailingList->GroupID)) {
$this->unsubscribeFromList($member, $mailingList);
$url = '/done/' . $member->Email . '/' . $mailingList->Title;
Director::redirect(Director::absoluteBaseURL() . $this->RelativeLink() . $url);
return;
} elseif ($member) {
$listForm = $this->MailingListForm($member);
} else {
$listForm = $this->EmailAddressForm();
}
if ($this->urlParams['Email'] == "done") {
$listForm->sessionMessage(_t('Unsubscribe.SUCCESS', 'Thank you. You have been removed from the selected groups'), "good");
}
return $this->customise(array('Content' => $listForm->forTemplate()))->renderWith('Page');
}
示例8: CartLink
/**
* Convenience method to return links to cart related page.
*
* @param String $type The type of cart page a link is needed for
* @return String The URL to the particular page
*/
function CartLink($type = 'Cart')
{
switch ($type) {
case 'Account':
if ($page = DataObject::get_one('AccountPage')) {
return $page->Link();
} else {
break;
}
case 'Checkout':
if ($page = DataObject::get_one('CheckoutPage')) {
return $page->Link();
} else {
break;
}
case 'Login':
return Director::absoluteBaseURL() . 'Security/login';
break;
case 'Logout':
if ($page = DataObject::get_one('AccountPage')) {
return $page->Link() . 'logout';
} else {
break;
}
case 'Cart':
default:
if ($page = DataObject::get_one('CartPage')) {
return $page->Link();
} else {
break;
}
}
}
示例9: callback
/**
* Retrieve and process order data from the request
*/
public function callback($request)
{
$this->extend('onBeforeCallback');
$data = $this->request->postVars();
$status = "error";
$order_id = 0;
$payment_id = 0;
$success_url = Controller::join_links(Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, 'complete');
$error_url = Controller::join_links(Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, 'complete', 'error');
$vars = array("SiteConfig" => SiteConfig::current_site_config(), "RedirectURL" => $error_url);
// Check if CallBack data exists and install id matches the saved ID
if (isset($data) && (isset($data['instId']) && isset($data['cartId']) && isset($data['transStatus']) && isset($data["callbackPW"])) && $this->payment_gateway->InstallID == $data['instId'] && $this->payment_gateway->ResponsePassword == $data["callbackPW"]) {
$order_id = $data['cartId'];
$payment_id = $data['transId'];
$status = $data['transStatus'];
if ($data['transStatus'] == 'Y') {
$status = 'paid';
$vars["RedirectURL"] = $success_url;
} else {
$status = 'failed';
}
} else {
return $this->httpError(500);
}
$payment_data = ArrayData::array_to_object(array("OrderID" => $order_id, "PaymentProvider" => "WorldPay", "PaymentID" => $payment_id, "Status" => $status, "GatewayData" => $data));
$this->setPaymentData($payment_data)->customise($vars);
$this->extend('onAfterCallback');
return $this->renderWith(array("Worldpay_callback"));
}
示例10: EditProfileForm
/**
* @return Form|SS_HTTPResponse
*/
public function EditProfileForm()
{
if (!Member::currentUser()) {
$this->setFlash(_t('EditProfilePage.LoginWarning', 'Please login to edit your profile'), 'warning');
return $this->redirect(Director::absoluteBaseURL());
}
$firstName = new TextField('FirstName');
$firstName->setAttribute('placeholder', _t('EditProfilePage.FirstNamePlaceholder', 'Enter your first name'))->setAttribute('required', 'required')->addExtraClass('form-control');
$surname = new TextField('Surname');
$surname->setAttribute('placeholder', _t('EditProfilePage.SurnamePlaceholder', 'Enter your surname'))->setAttribute('required', 'required')->addExtraClass('form-control');
$email = new EmailField('Email');
$email->setAttribute('placeholder', _t('EditProfilePage.EmailPlaceholder', 'Enter your email address'))->setAttribute('required', 'required')->addExtraClass('form-control');
$jobTitle = new TextField('JobTitle');
$jobTitle->setAttribute('placeholder', _t('EditProfilePage.JobTitlePlaceholder', 'Enter your job title'))->addExtraClass('form-control');
$website = new TextField('Website');
$website->setAttribute('placeholder', _t('EditProfilePage.WebsitePlaceholder', 'Enter your website'))->addExtraClass('form-control');
$blurb = new TextareaField('Blurb');
$blurb->setAttribute('placeholder', _t('EditProfilePage.BlurbPlaceholder', 'Enter your blurb'))->addExtraClass('form-control');
$confirmPassword = new ConfirmedPasswordField('Password', _t('EditProfilePage.PasswordLabel', 'New Password'));
$confirmPassword->canBeEmpty = true;
$confirmPassword->setAttribute('placeholder', _t('EditProfilePage.PasswordPlaceholder', 'Enter your password'))->addExtraClass('form-control');
$fields = new FieldList($firstName, $surname, $email, $jobTitle, $website, $blurb, $confirmPassword);
$action = new FormAction('SaveProfile', _t('EditProfilePage.SaveProfileText', 'Update Profile'));
$action->addExtraClass('btn btn-primary btn-lg');
$actions = new FieldList($action);
// Create action
$validator = new RequiredFields('FirstName', 'Email');
//Create form
$form = new Form($this, 'EditProfileForm', $fields, $actions, $validator);
//Populate the form with the current members data
$Member = Member::currentUser();
$form->loadDataFrom($Member->data());
//Return the form
return $form;
}
示例11: onBeforeInit
public function onBeforeInit()
{
$host = GlobalNavSiteTreeExtension::get_toolbar_hostname();
if (isset($_REQUEST['flush']) && $host == Director::absoluteBaseURL()) {
GlobalNavSiteTreeExtension::create_nav();
}
}
示例12: run
/**
* @inheritdoc
*/
public function run($request)
{
/* Get the protocol and host */
list($protocol, $host) = explode('://', Director::absoluteBaseURL());
$host = trim($host, '/\\');
try {
/* Flush via SSViewer, this is a clean flush */
echo 'Flushing SSViewer caches<br />';
SSViewer::flush_template_cache();
/* Remove the entire cache directory forcefully. Hard, unclean flush */
echo 'Removing temp folder ' . TEMP_FOLDER . '<br />';
exec('rm -rf ' . TEMP_FOLDER);
if (!file_exists(TEMP_FOLDER)) {
/* Show a success-message if the TEMP_FOLDER is gone */
echo 'Succesfully purged the temporary folder. A rebuild of caches is necessary now.<br />';
}
/* Flush Varnish. If it isn't available, this _might_ crash. Previous statements have been executed though */
echo "Flushing Varnish cache for host {$host}<br />";
exec('flushvarnish -h ' . $host);
/* Be friendly to the user */
echo 'Done clearing caches, please reload your site: <a href="' . Director::absoluteBaseURL() . '">here</a><br />';
echo 'Please note, all protocols have the same cache, so not only ' . $protocol . 'is cleared';
} catch (Exception $e) {
/* When boom, error out */
echo 'Error while clearing caches: ' . $e->getMessage();
}
}
示例13: init
public function init()
{
// Check permissions
// if(!Member::currentUser() || !Member::currentUser()->isAdmin()) Security::permissionFailure($this);
parent::init();
/*
if(!$this->can('AdminCMS')) {
$messageSet = array(
'default' => "Please choose an authentication method and enter your credentials to access the CMS.",
'alreadyLoggedIn' => "I'm sorry, but you can't access that part of the CMS. If you want to log in as someone else, do so below",
'logInAgain' => "You have been logged out of the CMS. If you would like to log in again, enter a username and password below.",
);
Security::permissionFailure($this, $messageSet);
return;
}*/
Requirements::javascript(MCE_ROOT . "tiny_mce_src.js");
Requirements::javascript("jsparty/tiny_mce_improvements.js");
Requirements::javascript("jsparty/hover.js");
Requirements::javascript("jsparty/scriptaculous/controls.js");
Requirements::javascript("cms/javascript/SecurityAdmin.js");
Requirements::javascript("cms/javascript/LeftAndMain_left.js");
Requirements::javascript("cms/javascript/LeftAndMain_right.js");
Requirements::javascript("cms/javascript/CMSMain_left.js");
Requirements::javascript("cms/javascript/NewsletterAdmin_left.js");
Requirements::javascript("cms/javascript/NewsletterAdmin_right.js");
Requirements::javascript("sapphire/javascript/ProgressBar.js");
// We don't want this showing up in every ajax-response, it should always be present in a CMS-environment
if (!Director::is_ajax()) {
Requirements::javascriptTemplate("cms/javascript/tinymce.template.js", array("ContentCSS" => project() . "/css/editor.css", "BaseURL" => Director::absoluteBaseURL(), "Lang" => i18n::get_tinymce_lang()));
}
// needed for MemberTableField (Requirements not determined before Ajax-Call)
Requirements::javascript("cms/javascript/MemberTableField.js");
Requirements::css("cms/css/NewsletterAdmin.css");
}
示例14: index
function index() {
$tasks = $this->getTasks();
// Web mode
if(!Director::is_cli()) {
$renderer = new DebugView();
$renderer->writeHeader();
$renderer->writeInfo("Sapphire Development Tools: Tasks", Director::absoluteBaseURL());
$base = Director::baseURL();
if(strpos($base,-1) != '/') $base .= '/';
echo "<ul>";
foreach($tasks as $task) {
echo "<li>";
echo "<a href=\"{$base}dev/tasks/" . $task['class'] . "\">" . $task['title'] . "</a><br />";
echo "<span class=\"description\">" . $task['description'] . "</span>";
echo "</li>\n";
}
echo "</ul>";
$renderer->writeFooter();
// CLI mode
} else {
echo "SAPPHIRE DEVELOPMENT TOOLS: Tasks\n--------------------------\n\n";
foreach($tasks as $task) {
echo " * $task: sake dev/tasks/" . $task['class'] . "\n";
}
}
}
示例15: placeOrder
public function placeOrder(SS_HTTPRequest $request)
{
$eventbrite_event_header = $request->getHeader('X-Eventbrite-Event');
if (!$eventbrite_event_header) {
return $this->httpError(403);
}
if ($eventbrite_event_header !== 'order.placed') {
return $this->httpError(403);
}
if (!$this->isJson()) {
return $this->httpError(403);
}
$json_request = $this->getJsonRequest();
if (!isset($json_request['config']) || !isset($json_request['api_url'])) {
return $this->httpError(403);
}
$config = $json_request['config'];
if (!isset($config['action']) || $config['action'] !== 'order.placed') {
return $this->httpError(403);
}
$current_local_url = Controller::join_links(Director::absoluteBaseURL(), $request->getURL());
if (!isset($config['endpoint_url']) || $config['endpoint_url'] !== $current_local_url) {
return $this->httpError(403);
}
try {
$this->manager->registerEvent('ORDER_PLACED', $json_request['api_url']);
} catch (Exception $ex) {
SS_Log::log($ex->getMessage(), SS_Log::ERR);
return $this->httpError(500);
}
return true;
}