本文整理汇总了PHP中Gdn_Url类的典型用法代码示例。如果您正苦于以下问题:PHP Gdn_Url类的具体用法?PHP Gdn_Url怎么用?PHP Gdn_Url使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Gdn_Url类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: Comment
public function Comment()
{
$Session = Gdn::Session();
$this->Form->SetModel($this->ActivityModel);
$NewActivityID = 0;
if ($this->Form->AuthenticatedPostBack()) {
$Body = $this->Form->GetValue('Body', '');
$ActivityID = $this->Form->GetValue('ActivityID', '');
if ($Body != '' && is_numeric($ActivityID) && $ActivityID > 0) {
$NewActivityID = $this->ActivityModel->Add($Session->UserID, 'ActivityComment', $Body, '', $ActivityID, '', TRUE);
}
}
// Redirect back to the sending location if this isn't an ajax request
if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
Redirect($this->Form->GetValue('Return', Gdn_Url::WebRoot()));
} else {
// Load the newly added comment
$this->Comment = $this->ActivityModel->GetID($NewActivityID);
$this->Comment->ActivityType .= ' Hidden';
// Hide it so jquery can reveal it
// Set it in the appropriate view
$this->View = 'comment';
// And render
$this->Render();
}
}
开发者ID:nbudin,项目名称:Garden,代码行数:26,代码来源:activity.php
示例2: Settings
/**
* Manage the current ranks and add new ones
*/
public function Settings()
{
$this->Permission('Yaga.Ranks.Manage');
$this->AddSideMenu('rank/settings');
$this->Title(T('Yaga.Ranks.Manage'));
// Get list of ranks from the model and pass to the view
$this->SetData('Ranks', $this->RankModel->Get());
if ($this->Form->IsPostBack() == TRUE) {
// Handle the photo upload
$Upload = new Gdn_Upload();
$TmpImage = $Upload->ValidateUpload('PhotoUpload', FALSE);
if ($TmpImage) {
// Generate the target image name
$TargetImage = $Upload->GenerateTargetName(PATH_UPLOADS);
$ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
// Save the uploaded image
$Parts = $Upload->SaveAs($TmpImage, 'yaga' . DS . $ImageBaseName);
$RelativeUrl = StringBeginsWith($Parts['Url'], Gdn_Url::WebRoot(TRUE), TRUE, TRUE);
SaveToConfig('Yaga.Ranks.Photo', $RelativeUrl);
if (C('Yaga.Ranks.Photo') == $Parts['SaveName']) {
$this->InformMessage(T('Yaga.Rank.PhotoUploaded'));
}
}
}
include_once $this->FetchViewLocation('helper_functions', 'rank');
$this->Render();
}
开发者ID:hxii,项目名称:Application-Yaga,代码行数:30,代码来源:class.rankcontroller.php
示例3: BuildPager
private function BuildPager($Sender, $Total)
{
$Sanitized = $this->ValidateInputs();
//get offset
$GETString = '?' . Gdn_Url::QueryString() . '&tar=srch';
//use this to providea link back to search - be sure to append the '&tar=srch' to tell to load the main search page
$GETString = str_replace('p=search&', 'search?', $GETString);
//echo $GETString; die;
$Limit = $this->Settings['Admin']->LimitResultsPage;
$Offset = ($Sanitized['Offset'] - 1) * $Limit;
//limit per page
$Pos = strpos($GETString, '&pg=' . $_GET['pg']);
if (!$Pos == FALSE) {
//$Url = substr($GETString, 0, $Pos); //strip the page number if it exists
$Url = str_replace('&pg=' . GetIncomingValue('pg'), '', $GETString);
//strip the page number if it exists
$Url = str_replace('&tar=srch', '', $Url);
//don't want to load adv search page when clicking page numbers
} else {
$Url = str_replace('&tar=srch', '', $GETString);
}
//don't want to load adv search page when clicking page numbers
$PagerFactory = new Gdn_PagerFactory();
$Sender->Pager = $PagerFactory->GetPager('Pager', $Sender);
$Sender->Pager->MoreCode = '>';
$Sender->Pager->LessCode = '<';
$Sender->Pager->ClientID = 'Pager';
$Sender->Pager->Configure($Offset, $Limit, $Total, $Url . '&pg=%1$s');
//echo $Url; die;
$Sender->SetData('GETString', $GETString);
}
开发者ID:Nordic-T,项目名称:vanilla-plugins,代码行数:31,代码来源:class.widget.main.php
示例4: insert_oa_login
private function insert_oa_login($caption, $element, $callback_uri)
{
$providers = implode(',', array_map(function ($p) {
return "'" . $p . "'";
}, C(self::CONFIG_PREFIX . 'Providers', array())));
$host = Gdn_Url::webRoot(TRUE);
return "<h4 class='login-title'>{$caption}</h4>\r\n\t\t\t\t<div class='oneall_social_login_providers' id='{$element}'></div>\r\n\t\t\t\t<!-- OneAll Social Login : http://www.oneall.com //-->\r\n\t\t\t\t<script type='text/javascript'>\r\n\t\t\t\t\t// <![CDATA[\r\n\t\t\t\t\tvar _oneall = _oneall || [];\r\n\t\t\t\t\t_oneall.push(['social_login', 'set_providers', [{$providers}]]);\r\n\t\t\t\t\t_oneall.push(['social_login', 'set_callback_uri', '{$host}{$callback_uri}']);\r\n\t\t\t\t\t_oneall.push(['social_login', 'set_custom_css_uri', (('https:' == document.location.protocol) ? 'https://secure' : 'http://public') + '.oneallcdn.com/css/api/socialize/themes/wordpress/default.css']);\r\n\t\t\t\t\t_oneall.push(['social_login', 'do_render_ui', '{$element}']);\r\n\t\t\t\t\t// ]]>\r\n\t\t\t\t</script>";
}
开发者ID:Nordic-T,项目名称:vanilla-plugins,代码行数:8,代码来源:class.oneallsociallogin.plugin.php
示例5: ActivityController_Render_Before
public function ActivityController_Render_Before(&$Sender)
{
$Session = Gdn::Session();
if (!$Session->CheckPermission('Plugins.Privacy.Activity')) {
if (!$Session->IsValid()) {
Redirect(Gdn::Authenticator()->SignInUrl(Gdn_Url::Request()));
} else {
Redirect(Gdn::Config('Routes.DefaultPermission'));
}
}
}
开发者ID:grahamlyons,项目名称:VanillaPrivacy,代码行数:11,代码来源:default.php
示例6: Check
public function Check($Type = '', $Name = '')
{
if ($Type != '' && $Name != '') {
$this->AddItem($Type, $Name);
}
if (count($this->_Items) > 0) {
// TODO: Use garden update check url instead of this:
$UpdateUrl = Url('/lussumo/update', TRUE, TRUE);
$Host = Gdn_Url::Host();
$Path = CombinePaths(array(Gdn_Url::WebRoot(), 'lussumo', 'update'), '/');
$Port = 80;
/*
$UpdateUrl = Gdn::Config('Garden.UpdateCheckUrl', '');
$UpdateUrl = parse_url($UpdateUrl);
$Host = ArrayValue('host', $UpdateUrl, 'www.lussumo.com');
$Path = ArrayValue('path', $UpdateUrl, '/');
$Port = ArrayValue('port', $UpdateUrl, '80');
*/
$Path .= '?Check=' . urlencode(Format::Serialize($this->_Items));
$Locale = Gdn::Config('Garden.Locale', 'Undefined');
$Referer = Gdn_Url::WebRoot(TRUE);
if ($Referer === FALSE) {
$Referer = 'Undefined';
}
$Timeout = 10;
$Response = '';
// Connect to the update server.
$Pointer = @fsockopen($Host, '80', $ErrorNumber, $Error, $Timeout);
if (!$Pointer) {
throw new Exception(sprintf(Gdn::Translate('Encountered an error when attempting to connect to the update server (%1$s): [%2$s] %3$s'), $UpdateUrl, $ErrorNumber, $Error));
} else {
// send the necessary headers to get the file
fputs($Pointer, "GET {$Path} HTTP/1.0\r\n" . "Host: {$Host}\r\n" . "User-Agent: Lussumo Garden/1.0\r\n" . "Accept: */*\r\n" . "Accept-Language: " . $Locale . "\r\n" . "Accept-Charset: utf-8;\r\n" . "Keep-Alive: 300\r\n" . "Connection: keep-alive\r\n" . "Referer: {$Referer}\r\n\r\n");
// Retrieve the response from the remote server
while ($Line = fread($Pointer, 4096)) {
$Response .= $Line;
}
fclose($Pointer);
// Remove response headers
$Response = substr($Response, strpos($Response, "\r\n\r\n") + 4);
}
$Result = Format::Unserialize($Response);
// print_r($Result);
if (is_array($Result)) {
$this->_Items = $Result;
} else {
$Result = FALSE;
}
return $Result;
}
}
开发者ID:kidmax,项目名称:Garden,代码行数:51,代码来源:class.updatemanager.php
示例7: or
/*
Copyright 2008, 2009 Mark O'Sullivan
This file is part of Garden.
Garden is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Garden is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Garden. If not, see <http://www.gnu.org/licenses/>.
Contact Mark O'Sullivan at mark [at] lussumo [dot] com
*/
// Report and track all errors.
error_reporting(E_ALL);
ini_set('display_errors', 'on');
ini_set('track_errors', 1);
ob_start();
// 1. Define the constants we need to get going.
define('APPLICATION', 'Garden');
define('APPLICATION_VERSION', '1.0');
define('DS', DIRECTORY_SEPARATOR);
define('PATH_ROOT', dirname(__FILE__));
// 2. Include the header.
require_once PATH_ROOT . DS . 'bootstrap.php';
// 3. Start the application.
if (strpos(Gdn_Url::Request(), 'gardensetup') === FALSE) {
Gdn::Session()->Start(Gdn::Authenticator());
}
$Dispatcher = Gdn::Dispatcher();
$EnabledApplications = Gdn::Config('EnabledApplications');
$Dispatcher->EnabledApplicationFolders($EnabledApplications);
$Dispatcher->PassProperty('EnabledApplications', $EnabledApplications);
$Dispatcher->Routes = Gdn::Config('Routes');
// Process the request.
$Dispatcher->Dispatch();
开发者ID:kidmax,项目名称:Garden,代码行数:31,代码来源:index.php
示例8: isActive
/**
* Checks whether the current request url matches an item's link url.
*
* @param array $item The item to check.
* @return bool Whether the current request url matches an item's link url.
*/
protected function isActive($item)
{
if (empty($this->highlightRoute)) {
$highlightRoute = Gdn_Url::request(true);
} else {
$highlightRoute = url($this->highlightRoute);
}
return val('url', $item) && trim(url(val('url', $item)), '/') == trim($highlightRoute, '/');
}
开发者ID:vanilla,项目名称:vanilla,代码行数:15,代码来源:class.nestedcollection.php
示例9: Open
/**
* Returns the xhtml for the opening of the form (the form tag and all
* hidden elements).
*
* @param array $Attributes An associative array of attributes for the form tag. Here is a list of
* "special" attributes and their default values:
*
* Attribute Options Default
* ----------------------------------------
* method get,post post
* action [any url] [The current url]
* ajax TRUE,FALSE FALSE
*
* @return string
*
* @todo check that missing DataObject parameter
*/
public function Open($Attributes = FALSE)
{
$Return = '<form';
if ($this->InputPrefix != '') {
$Return .= $this->_IDAttribute($this->InputPrefix, $Attributes);
}
// Method
$MethodFromAttributes = ArrayValueI('method', $Attributes);
$this->Method = $MethodFromAttributes === FALSE ? $this->Method : $MethodFromAttributes;
// Action
$ActionFromAttributes = ArrayValueI('action', $Attributes);
if ($this->Action == '') {
$this->Action = Url(Gdn_Url::Request());
}
$this->Action = $ActionFromAttributes === FALSE ? $this->Action : $ActionFromAttributes;
$Return .= ' method="' . $this->Method . '"' . ' action="' . $this->Action . '"' . $this->_AttributesToString($Attributes) . ">\n";
// Postback Key - don't allow it to be posted in the url (prevents csrf attacks & hijacks)
if ($this->Method != "get") {
$Session = Gdn::Session();
$Return .= $this->Hidden('TransientKey', array('value' => $Session->TransientKey()));
// Also add a honeypot if Forms.HoneypotName has been defined
$HoneypotName = Gdn::Config('Garden.Forms.HoneypotName');
if ($HoneypotName) {
$Return .= $this->Hidden($HoneypotName, array('Name' => $HoneypotName, 'style' => "display: none;"));
}
}
// Render all other hidden inputs that have been defined
$Return .= $this->GetHidden();
return $Return;
}
开发者ID:kidmax,项目名称:Garden,代码行数:47,代码来源:class.form.php
示例10: WriteActivityComment
function WriteActivityComment($Comment, &$Sender, &$Session)
{
$Author = UserBuilder($Comment, 'Activity');
$PhotoAnchor = UserPhoto($Author, 'Photo');
$CssClass = 'Item ActivityComment Condensed ' . $Comment->ActivityType;
if ($PhotoAnchor != '') {
$CssClass .= ' HasPhoto';
}
?>
<li id="Activity_<?php
echo $Comment->ActivityID;
?>
" class="<?php
echo $CssClass;
?>
">
<?php
if ($PhotoAnchor != '') {
?>
<div class="Author Photo"><?php
echo $PhotoAnchor;
?>
</div>
<?php
}
?>
<div class="ItemContent ActivityComment">
<?php
echo UserAnchor($Author, 'Title Name');
?>
<div class="Excerpt"><?php
echo Gdn_Format::Display($Comment->Story);
?>
</div>
<div class="Meta">
<span class="DateCreated"><?php
echo Gdn_Format::Date($Comment->DateInserted);
?>
</span>
<?php
if ($Session->UserID == $Comment->InsertUserID || $Session->CheckPermission('Garden.Activity.Delete')) {
echo Anchor(T('Delete'), 'dashboard/activity/delete/' . $Comment->ActivityID . '/' . $Session->TransientKey() . '?Return=' . urlencode(Gdn_Url::Request()), 'DeleteComment');
}
?>
</div>
</div>
</li>
<?php
}
开发者ID:seedbank,项目名称:old-repo,代码行数:49,代码来源:helper_functions.php
示例11: toString
/**
*
*
* @param string $HighlightRoute
* @return string
* @throws Exception
*/
public function toString($HighlightRoute = '')
{
if ($HighlightRoute == '') {
$HighlightRoute = $this->_HighlightRoute;
}
if ($HighlightRoute == '') {
$HighlightRoute = Gdn_Url::Request();
}
$this->fireEvent('BeforeToString');
$Username = '';
$UserID = '';
$Session_TransientKey = '';
$Session = Gdn::session();
$Admin = false;
if ($Session->isValid() === true) {
$UserID = $Session->User->UserID;
$Username = $Session->User->Name;
$Session_TransientKey = $Session->TransientKey();
$Admin = $Session->User->Admin > 0 ? true : false;
}
$Menu = '';
if (count($this->Items) > 0) {
// Apply the menu group sort if present...
if (is_array($this->Sort)) {
$Items = array();
$Count = count($this->Sort);
for ($i = 0; $i < $Count; ++$i) {
$Group = $this->Sort[$i];
if (array_key_exists($Group, $this->Items)) {
$Items[$Group] = $this->Items[$Group];
unset($this->Items[$Group]);
}
}
foreach ($this->Items as $Group => $Links) {
$Items[$Group] = $Links;
}
} else {
$Items = $this->Items;
}
foreach ($Items as $GroupName => $Links) {
$ItemCount = 0;
$LinkCount = 0;
$OpenGroup = false;
$Group = '';
foreach ($Links as $Key => $Link) {
$CurrentLink = false;
$ShowLink = false;
$RequiredPermissions = array_key_exists('Permission', $Link) ? $Link['Permission'] : false;
if ($RequiredPermissions !== false && !is_array($RequiredPermissions)) {
$RequiredPermissions = explode(',', $RequiredPermissions);
}
// Show if there are no permissions or the user has ANY of the specified permissions or the user is admin
$ShowLink = $Admin || $RequiredPermissions === false || Gdn::session()->checkPermission($RequiredPermissions, false);
if ($ShowLink === true) {
if ($ItemCount == 1) {
$Group .= '<ul>';
$OpenGroup = true;
} elseif ($ItemCount > 1) {
$Group .= "</li>\r\n";
}
$Url = val('Url', $Link);
if (substr($Link['Text'], 0, 1) === '\\') {
$Text = substr($Link['Text'], 1);
} else {
$Text = str_replace('{Username}', $Username, $Link['Text']);
}
$Attributes = val('Attributes', $Link, array());
$AnchorAttributes = val('AnchorAttributes', $Link, array());
if ($Url !== false) {
$Url = url(str_replace(array('{Username}', '{UserID}', '{Session_TransientKey}'), array(urlencode($Username), $UserID, $Session_TransientKey), $Link['Url']));
$CurrentLink = $Url == url($HighlightRoute);
$CssClass = val('class', $Attributes, '');
if ($CurrentLink) {
$Attributes['class'] = $CssClass . ' Highlight';
}
$Group .= '<li' . Attribute($Attributes) . '><a' . Attribute($AnchorAttributes) . ' href="' . $Url . '">' . $Text . '</a>';
++$LinkCount;
} else {
$Group .= '<li' . Attribute($Attributes) . '>' . $Text;
}
++$ItemCount;
}
}
if ($OpenGroup === true) {
$Group .= "</li>\r\n</ul>\r\n";
}
if ($Group != '' && $LinkCount > 0) {
$Menu .= $Group . "</li>\r\n";
}
}
if ($Menu != '') {
$Menu = '<ul id="' . $this->HtmlId . '"' . ($this->CssClass != '' ? ' class="' . $this->CssClass . '"' : '') . '>' . $Menu . '</ul>';
}
//.........这里部分代码省略.........
开发者ID:vanilla,项目名称:vanilla,代码行数:101,代码来源:class.menumodule.php
示例12: ToString
public function ToString($HighlightRoute = '')
{
if ($HighlightRoute == '') {
$HighlightRoute = $this->_HighlightRoute;
}
if ($HighlightRoute == '') {
$HighlightRoute = Gdn_Url::Request();
}
$HighlightUrl = Url($HighlightRoute);
// Apply a sort to the items if given.
if (is_array($this->Sort)) {
$Sort = array_flip($this->Sort);
foreach ($this->Items as $Group => &$Item) {
if (isset($Sort[$Group])) {
$Item['Sort'] = $Sort[$Group];
} else {
$Item['_Sort'] += count($Sort);
}
foreach ($Item['Links'] as $Url => &$Link) {
if (isset($Sort[$Url])) {
$Link['Sort'] = $Sort[$Url];
} elseif (isset($Sort[$Link['Text']])) {
$Link['Sort'] = $Sort[$Link['Text']];
} else {
$Link['_Sort'] += count($Sort);
}
}
}
}
// Sort the groups.
$this->_Compare($this->Items);
uasort($this->Items, array($this, '_Compare'));
// Sort the items within the groups.
foreach ($this->Items as &$Item) {
$this->_Compare($Item['Links']);
uasort($Item['Links'], array($this, '_Compare'));
// Highlight the group.
if (GetValue('Url', $Item) && Url($Item['Url']) == $HighlightUrl) {
$Item['Attributes']['class'] = ConcatSep(' ', GetValue('class', $Item['Attributes']), 'Active');
}
// Hightlight the correct item in the group.
foreach ($Item['Links'] as &$Link) {
if (GetValue('Url', $Link) && Url($Link['Url']) == $HighlightUrl) {
$Link['Attributes']['class'] = ConcatSep(' ', GetValue('class', $Link['Attributes']), 'Active');
$Item['Attributes']['class'] = ConcatSep(' ', GetValue('class', $Item['Attributes']), 'Active');
}
}
}
return parent::ToString();
}
开发者ID:Raz0r,项目名称:Garden,代码行数:50,代码来源:class.sidemenumodule.php
示例13: saveAdminUser
/**
* Create an admin user account.
*
* @param array $FormPostValues
*/
public function saveAdminUser($FormPostValues)
{
$UserID = 0;
// Add & apply any extra validation rules:
$Name = val('Name', $FormPostValues, '');
$FormPostValues['Email'] = val('Email', $FormPostValues, strtolower($Name . '@' . Gdn_Url::host()));
$FormPostValues['ShowEmail'] = '0';
$FormPostValues['TermsOfService'] = '1';
$FormPostValues['DateOfBirth'] = '1975-09-16';
$FormPostValues['DateLastActive'] = Gdn_Format::toDateTime();
$FormPostValues['DateUpdated'] = Gdn_Format::toDateTime();
$FormPostValues['Gender'] = 'u';
$FormPostValues['Admin'] = '1';
$this->addInsertFields($FormPostValues);
if ($this->validate($FormPostValues, true) === true) {
$Fields = $this->Validation->schemaValidationFields();
// Only fields that are present in the schema
// Insert the new user
$UserID = $this->insertInternal($Fields, ['NoConfirmEmail' => true, 'Setup' => true]);
if ($UserID > 0) {
$ActivityModel = new ActivityModel();
$ActivityModel->save(['ActivityUserID' => $UserID, 'ActivityType' => 'Registration', 'HeadlineFormat' => t('HeadlineFormat.Registration', '{ActivityUserID,You} joined.'), 'Story' => t('Welcome Aboard!')], false, ['GroupBy' => 'ActivityTypeID']);
}
$this->saveRoles($UserID, [16], false);
}
return $UserID;
}
开发者ID:vanilla,项目名称:vanilla,代码行数:32,代码来源:class.usermodel.php
示例14: proxyRequest
/**
* Use curl or fsock to make a request to a remote server.
*
* @param string $Url The full url to the page being requested (including http://).
* @param integer $Timeout How long to allow for this request.
* Default Garden.SocketTimeout or 1, 0 to never timeout.
* @param boolean $FollowRedirects Whether or not to follow 301 and 302 redirects. Defaults false.
* @return string Returns the response body.
*/
function proxyRequest($Url, $Timeout = false, $FollowRedirects = false)
{
$OriginalTimeout = $Timeout;
if ($Timeout === false) {
$Timeout = c('Garden.SocketTimeout', 1.0);
}
$UrlParts = parse_url($Url);
$Scheme = GetValue('scheme', $UrlParts, 'http');
$Host = GetValue('host', $UrlParts, '');
$Port = GetValue('port', $UrlParts, $Scheme == 'https' ? '443' : '80');
$Path = GetValue('path', $UrlParts, '');
$Query = GetValue('query', $UrlParts, '');
// Get the cookie.
$Cookie = '';
$EncodeCookies = c('Garden.Cookie.Urlencode', true);
foreach ($_COOKIE as $Key => $Value) {
if (strncasecmp($Key, 'XDEBUG', 6) == 0) {
continue;
}
if (strlen($Cookie) > 0) {
$Cookie .= '; ';
}
$EValue = $EncodeCookies ? urlencode($Value) : $Value;
$Cookie .= "{$Key}={$EValue}";
}
$Response = '';
if (function_exists('curl_init')) {
//$Url = $Scheme.'://'.$Host.$Path;
$Handler = curl_init();
curl_setopt($Handler, CURLOPT_URL, $Url);
curl_setopt($Handler, CURLOPT_PORT, $Port);
curl_setopt($Handler, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($Handler, CURLOPT_HEADER, 1);
curl_setopt($Handler, CURLOPT_USERAGENT, val('HTTP_USER_AGENT', $_SERVER, 'Vanilla/2.0'));
curl_setopt($Handler, CURLOPT_RETURNTRANSFER, 1);
if ($Cookie != '') {
curl_setopt($Handler, CURLOPT_COOKIE, $Cookie);
}
if ($Timeout > 0) {
curl_setopt($Handler, CURLOPT_TIMEOUT, $Timeout);
}
// TIM @ 2010-06-28: Commented this out because it was forcing all requests with parameters to be POST.
//Same for the $Url above
//
//if ($Query != '') {
// curl_setopt($Handler, CURLOPT_POST, 1);
// curl_setopt($Handler, CURLOPT_POSTFIELDS, $Query);
//}
$Response = curl_exec($Handler);
$Success = true;
if ($Response == false) {
$Success = false;
$Response = '';
throw new Exception(curl_error($Handler));
}
curl_close($Handler);
} elseif (function_exists('fsockopen')) {
$Referer = Gdn_Url::WebRoot(true);
// Make the request
$Pointer = @fsockopen($Host, $Port, $ErrorNumber, $Error, $Timeout);
if (!$Pointer) {
throw new Exception(sprintf(T('Encountered an error while making a request to the remote server (%1$s): [%2$s] %3$s'), $Url, $ErrorNumber, $Error));
}
stream_set_timeout($Pointer, $Timeout);
if (strlen($Cookie) > 0) {
$Cookie = "Cookie: {$Cookie}\r\n";
}
$HostHeader = $Host . ($Port != 80 ? ":{$Port}" : '');
$Header = "GET {$Path}?{$Query} HTTP/1.1\r\n" . "Host: {$HostHeader}\r\n" . "User-Agent: " . val('HTTP_USER_AGENT', $_SERVER, 'Vanilla/2.0') . "\r\n" . "Accept: */*\r\n" . "Accept-Charset: utf-8;\r\n" . "Referer: {$Referer}\r\n" . "Connection: close\r\n";
if ($Cookie != '') {
$Header .= $Cookie;
}
$Header .= "\r\n";
// Send the headers and get the response
fputs($Pointer, $Header);
while ($Line = fread($Pointer, 4096)) {
$Response .= $Line;
}
@fclose($Pointer);
$Bytes = strlen($Response);
$Response = trim($Response);
$Success = true;
$StreamInfo = stream_get_meta_data($Pointer);
if (GetValue('timed_out', $StreamInfo, false) === true) {
$Success = false;
$Response = "Operation timed out after {$Timeout} seconds with {$Bytes} bytes received.";
}
} else {
throw new Exception(T('Encountered an error while making a request to the remote server: Your PHP configuration does not allow curl or fsock requests.'));
}
if (!$Success) {
//.........这里部分代码省略.........
开发者ID:sitexa,项目名称:vanilla,代码行数:101,代码来源:functions.general.php
示例15: Request
/**
* Returns the Request part of the current url. ie. "/controller/action/" in
* "http://localhost/garden/index.php/controller/action/".
*
* @param boolean $WithWebRoot
* @param boolean $WithDomain
* @param boolean $RemoveSyndication
* @return string
*/
public static function Request($WithWebRoot = FALSE, $WithDomain = FALSE, $RemoveSyndication = FALSE)
{
$Return = '';
// TODO: Test this on various platforms/browsers. Very breakable.
// Try PATH_INFO
$Request = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');
if ($Request) {
$Return = $Request;
}
// Try ORIG_PATH_INFO
if (!$Return) {
$Request = isset($_SERVER['ORIG_PATH_INFO']) ? $_SERVER['ORIG_PATH_INFO'] : @getenv('ORIG_PATH_INFO');
if ($Request != '') {
$Return = $Request;
}
}
// Try with PHP_SELF
if (!$Return) {
$PhpSelf = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : @getenv('PHP_SELF');
$ScriptName = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : @getenv('SCRIPT_NAME');
if ($PhpSelf && $ScriptName) {
$Return = substr($PhpSelf, strlen($ScriptName));
}
}
$Return = trim($Return, '/');
if (strcasecmp(substr($Return, 0, 9), 'index.php') == 0) {
$Return = substr($Return, 9);
}
$Return = trim($Return, '/');
if ($RemoveSyndication) {
$Prefix = strtolower(substr($Return, 0, strpos($Return, '/')));
if ($Prefix == 'rss') {
$Return = substr($Return, 4);
} else {
if ($Prefix == 'atom') {
$Return = substr($Return, 5);
}
}
}
if ($WithWebRoot) {
$WebRoot = Gdn_Url::WebRoot($WithDomain);
if (substr($WebRoot, -1, 1) != '/') {
$WebRoot .= '/';
}
$Return = $WebRoot . $Return;
}
return $Return;
}
开发者ID:Aetasiric,项目名称:Garden,代码行数:57,代码来源:class.url.php
示例16: Configure
//.........这里部分代码省略.........
$Connection = new PDO($ConnectionString, $DatabaseUser, $DatabasePassword);
} catch (PDOException $Exception) {
switch ($Exception->getCode()) {
case 1044:
$this->Form->AddError(T('The database user you specified does not have permission to access the database. Have you created the database yet? The database reported: <code>%s</code>'), strip_tags($Exception->getMessage()));
break;
case 1045:
$this->Form->AddError(T('Failed to connect to the database with the username and password you entered. Did you mistype them? The database reported: <code>%s</code>'), strip_tags($Exception->getMessage()));
break;
case 1049:
$this->Form->AddError(T('It appears as though the database you specified does not exist yet. Have you created it yet? Did you mistype the name? The database reported: <code>%s</code>'), strip_tags($Exception->getMessage()));
break;
case 2005:
$this->Form->AddError(T("Are you sure you've entered the correct database host name? Maybe you mistyped it? The database reported: <code>%s</code>"), strip_tags($Exception->getMessage()));
break;
default:
$this->Form->AddError(sprintf(T('ValidateConnection'), strip_tags($Exception->getMessage())));
break;
}
}
$ConfigurationModel->Validation->ApplyRule('Garden.Title', 'Required');
$ConfigurationFormValues = $this->Form->FormValues();
if ($ConfigurationModel->Validate($ConfigurationFormValues) !== TRUE || $this->Form->ErrorCount() > 0) {
// Apply the validation results to the form(s)
$this->Form->SetValidationResults($ConfigurationModel->ValidationResults());
} else {
$Host = array_shift(explode(':', Gdn::Request()->RequestHost()));
$Domain = Gdn::Request()->Domain();
// Set up cookies now so that the user can be signed in.
$ConfigurationFormValues['Garden.Cookie.Salt'] = RandomString(10);
$ConfigurationFormValues['Garden.Cookie.Domain'] = strpos($Host, '.') === FALSE ? '' : $Host;
// Don't assign the domain if it is a non .com domain as that will break cookies.
$ConfigurationModel->Save($ConfigurationFormValues);
// If changing locale, redefine locale sources:
$NewLocale = 'en-CA';
// $this->Form->GetFormValue('Garden.Locale', FALSE);
if ($NewLocale !== FALSE && Gdn::Config('Garden.Locale') != $NewLocale) {
$ApplicationManager = new Gdn_ApplicationManager();
$PluginManager = Gdn::Factory('PluginManager');
$Locale = Gdn::Locale();
$Locale->Set($NewLocale, $ApplicationManager->EnabledApplicationFolders(), $PluginManager->EnabledPluginFolders(), TRUE);
}
// Set the instantiated config object's db params and make the database use them (otherwise it will use the default values from conf/config-defaults.php).
$Config->Set('Database.Host', $ConfigurationFormValues['Database.Host']);
$Config->Set('Database.Name', $ConfigurationFormValues['Database.Name']);
$Config->Set('Database.User', $ConfigurationFormValues['Database.User']);
$Config->Set('Database.Password', $ConfigurationFormValues['Database.Password']);
$Config->ClearSaveData();
Gdn::FactoryInstall(Gdn::AliasDatabase, 'Gdn_Database', PATH_LIBRARY . DS . 'database' . DS . 'class.database.php', Gdn::FactorySingleton, array(Gdn::Config('Database')));
// Install db structure & basic data.
$Database = Gdn::Database();
$Drop = FALSE;
// Gdn::Config('Garden.Version') === FALSE ? TRUE : FALSE;
$Explicit = FALSE;
try {
include PATH_APPLICATIONS . DS . 'dashboard' . DS . 'settings' . DS . 'structure.php';
} catch (Exception $ex) {
$this->Form->AddError(strip_tags($ex->getMessage()));
}
if ($this->Form->ErrorCount() > 0) {
return FALSE;
}
// Create the administrative user
$UserModel = Gdn::UserModel();
$UserModel->DefineSchema();
$UserModel->Validation->ApplyRule('Name', 'Username', self::UsernameError);
$UserModel->Validation->ApplyRule('Name', 'Required', T('You must specify an admin username.'));
$UserModel->Validation->ApplyRule('Password', 'Required', T('You must specify an admin password.'));
$UserModel->Validation->ApplyRule('Password', 'Match');
$UserModel->Validation->ApplyRule('Email', 'Email');
if (!$UserModel->SaveAdminUser($ConfigurationFormValues)) {
$this->Form->SetValidationResults($UserModel->ValidationResults());
} else {
// The user has been created successfully, so sign in now
$Authenticator = Gdn::Authenticator();
$AuthUserID = $Authenticator->Authenticate(array('Email' => $this->Form->GetValue('Email'), 'Password' => $this->Form->GetValue('Password'), 'RememberMe' => TRUE));
}
if ($this->Form->ErrorCount() > 0) {
return FALSE;
}
// Assign some extra settings to the configuration file if everything succeeded.
$ApplicationInfo = array();
include CombinePaths(array(PATH_APPLICATIONS . DS . 'dashboard' . DS . 'settings' . DS . 'about.php'));
// Detect rewrite abilities
try {
$Query = Gdn::Request()->Domain() . Gdn::Request()->WebRoot() . "entry";
$Results = ProxyHead($Query, array(), 1);
$CanRewrite = FALSE;
if (in_array(ArrayValue('StatusCode', $Results, 404), array(200, 302)) && ArrayValue('X-Garden-Version', $Results, 'None') != 'None') {
$CanRewrite = TRUE;
}
} catch (Exception $e) {
// cURL and fsockopen arent supported... guess?
$CanRewrite = function_exists('apache_get_modules') && in_array('mod_rewrite', apache_get_modules()) ? TRUE : FALSE;
}
SaveToConfig(array('Garden.Version' => ArrayValue('Version', GetValue('Dashboard', $ApplicationInfo, array()), 'Undefined'), 'Garden.WebRoot' => Gdn_Url::WebRoot(), 'Garden.RewriteUrls' => $CanRewrite, 'Garden.Domain' => $Domain, 'Garden.CanProcessImages' => function_exists('gd_info'), 'EnabledPlugins.GettingStarted' => 'GettingStarted', 'EnabledPlugins.HTMLPurifier' => 'HtmlPurifier'));
}
}
return $this->Form->ErrorCount() == 0 ? TRUE : FALSE;
}
开发者ID:sheldon,项目名称:Garden,代码行数:101,代码来源:class.setupcontroller.php
示例17: DefinitionList
/**
* Undocumented method.
*
* @todo Method DefinitionList() needs a description.
*/
public function DefinitionList()
{
$Session = Gdn::Session();
if (!array_key_exists('TransportError', $this->_Definitions)) {
$this->_Definitions['TransportError'] = Gdn::Translate('A fatal error occurred while processing the request.<br />The server returned the following response: %s');
}
if (!array_key_exists('TransientKey', $this->_Definitions)) {
$this->_Definitions['TransientKey'] = $Session->TransientKey();
}
if (!array_key_exists('WebRoot', $this->_Definitions)) {
$this->_Definitions['WebRoot'] = Gdn_Url::WebRoot(TRUE);
}
if (!array_key_exists('ConfirmHeading', $this->_Definitions)) {
$this->_Definitions['ConfirmHeading'] = Gdn::Translate('Confirm');
}
if (!array_key_exists('ConfirmText', $this->_Definitions)) {
$this->_Definitions['ConfirmText'] = Gdn::Translate('Are you sure you want to do that?');
}
if (!array_key_exists('Okay', $this->_Definitions)) {
$this->_Definitions['Okay'] = Gdn::Translate('Okay');
}
if (!array_key_exists('Cancel', $this->_Definitions)) {
$this->_Definitions['Cancel'] = Gdn::Translate('Cancel');
}
$Return = '<!-- Various definitions for Javascript //-->
<div id="Definitions" style="display: none;">
';
foreach ($this->_Definitions as $Term => $Definition) {
$Return .= '<input type="hidden" id="' . $Term . '" value="' . $Definition . '" />' . "\n";
}
return $Return . '</div>';
}
开发者ID:robi-bobi,项目名称:Garden,代码行数:37,代码来源:class.controller.php
示例18: array
$Gdn_Config = Gdn::Factory(Gdn::AliasConfig);
/// Configuration Defaults.
$Gdn_Config->Load(PATH_CONF . DS . 'config-defaults.php', 'Use');
// Load the custom configurations so that we know what apps are enabled.
$Gdn_Config->Load(PATH_CONF . DS . 'config.php', 'Use');
/// Load the configurations for the installed items.
$Gdn_EnabledApplications = Gdn::Config('EnabledApplications', array());
foreach ($Gdn_EnabledApplications as $ApplicationName => $ApplicationFolder) {
$Gdn_Config->Load(PATH_APPLICATIONS . DS . $ApplicationFolder . DS . 'settings' . DS . 'configuration.php', 'Use');
}
/// Load the custom configurations again so that application setting defaults are overridden.
$Gdn_Config->Load(PATH_CONF . DS . 'config.php', 'Use');
unset($Gdn_Config);
// Redirect to the setup screen if Garden hasn't been installed yet.
if (!Gdn::Config('Garden.Installed', FALSE) && strpos(Gdn_Url::Request(), 'gardensetup') === FALSE) {
header('location: ' . CombinePaths(array(Gdn_Url::WebRoot(TRUE), 'index.php/garden/gardensetup'), '/'));
exit;
}
/// Install some of the services.
// Default database.
Gdn::FactoryInstall(Gdn::AliasDatabase, 'Gdn_Database', PATH_LIBRARY . DS . 'database' . DS . 'class.database.php', Gdn::FactorySingleton, array('Database'));
// Database drivers.
Gdn::FactoryInstall('MySQLDriver', 'Gdn_MySQLDriver', PATH_LIBRARY . DS . 'database' . DS . 'class.mysql.driver.php', Gdn::FactoryInstance);
Gdn::FactoryInstall('MySQLStructure', 'Gdn_MySQLStructure', PATH_LIBRARY . DS . 'database' . DS . 'class.mysql.structure.php', Gdn::FactoryInstance);
// Identity, Authenticator & Session.
Gdn::FactoryIns
|
请发表评论