本文整理汇总了PHP中ArrayTranslate函数的典型用法代码示例。如果您正苦于以下问题:PHP ArrayTranslate函数的具体用法?PHP ArrayTranslate怎么用?PHP ArrayTranslate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ArrayTranslate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GetOpenID
/**
* @return LightOpenID
*/
public function GetOpenID() {
if (get_magic_quotes_gpc()) {
foreach ($_GET as $Name => $Value) {
$_GET[$Name] = stripslashes($Value);
}
}
$OpenID = new LightOpenID();
if (isset($_GET['url']))
$OpenID->identity = $_GET['url'];
$Url = Url('/entry/connect/openid', TRUE);
$UrlParts = explode('?', $Url);
parse_str(GetValue(1, $UrlParts, ''), $Query);
$Query = array_merge($Query, ArrayTranslate($_GET, array('display', 'Target')));
$OpenID->returnUrl = $UrlParts[0].'?'.http_build_query($Query);
$OpenID->required = array('contact/email', 'namePerson/first', 'namePerson/last', 'pref/language');
$this->EventArguments['OpenID'] = $OpenID;
$this->FireEvent('GetOpenID');
return $OpenID;
}
示例2: smarty_function_breadcrumbs
/**
* Render a breadcrumb trail for the user based on the page they are on.
*/
function smarty_function_breadcrumbs($Params, &$Smarty)
{
$Breadcrumbs = $Smarty->Controller->Data('Breadcrumbs');
if (!is_array($Breadcrumbs)) {
$Breadcrumbs = array();
}
$Options = ArrayTranslate($Params, array('homeurl' => 'HomeUrl', 'hidelast' => 'HideLast'));
return Gdn_Theme::Breadcrumbs($Breadcrumbs, GetValue('homelink', $Params, TRUE), $Options);
}
示例3: profileController_jsConnect_create
/**
*
*
* @param Gdn_Controller $Sender
* @param array $Args
*/
public function profileController_jsConnect_create($Sender, $Args = array())
{
include_once dirname(__FILE__) . '/functions.jsconnect.php';
$client_id = $Sender->Request->get('client_id', 0);
$Provider = self::getProvider($client_id);
$client_id = val('AuthenticationKey', $Provider);
$Secret = val('AssociationSecret', $Provider);
if (Gdn::session()->isValid()) {
$User = ArrayTranslate((array) Gdn::session()->User, array('UserID' => 'UniqueID', 'Name', 'Email', 'PhotoUrl', 'DateOfBirth', 'Gender'));
// Grab the user's roles.
$Roles = Gdn::userModel()->getRoles(Gdn::session()->UserID);
$Roles = array_column($Roles, 'Name');
$User['Roles'] = '';
if (is_array($Roles) && sizeof($Roles)) {
$User['Roles'] = implode(',', $Roles);
}
if (!$User['PhotoUrl'] && function_exists('UserPhotoDefaultUrl')) {
$User['PhotoUrl'] = Url(UserPhotoDefaultUrl(Gdn::session()->User), true);
}
} else {
$User = [];
}
ob_clean();
writeJsConnect($User, $Sender->Request->get(), $client_id, $Secret, val('HashType', $Provider, true));
exit;
}
示例4: AddCategoryColumns
/**
* Modifies category data before it is returned.
*
* Adds CountAllDiscussions column to each category representing the sum of
* discussions within this category as well as all subcategories.
*
* @since 2.0.17
* @access public
*
* @param object $Data SQL result.
*/
public static function AddCategoryColumns($Data)
{
$Result =& $Data->Result();
$Result2 = $Result;
foreach ($Result as &$Category) {
if (!property_exists($Category, 'CountAllDiscussions')) {
$Category->CountAllDiscussions = $Category->CountDiscussions;
}
if (!property_exists($Category, 'CountAllComments')) {
$Category->CountAllComments = $Category->CountComments;
}
// Calculate the following field.
$Following = !((bool) GetValue('Archived', $Category) || (bool) GetValue('Unfollow', $Category));
$Category->Following = $Following;
$DateMarkedRead = GetValue('DateMarkedRead', $Category);
$UserDateMarkedRead = GetValue('UserDateMarkedRead', $Category);
if (!$DateMarkedRead) {
$DateMarkedRead = $UserDateMarkedRead;
} elseif ($UserDateMarkedRead && Gdn_Format::ToTimestamp($UserDateMarkedRead) > Gdn_Format::ToTimeStamp($DateMarkedRead)) {
$DateMarkedRead = $UserDateMarkedRead;
}
// Set appropriate Last* columns.
SetValue('LastTitle', $Category, GetValue('LastDiscussionTitle', $Category, NULL));
$LastDateInserted = GetValue('LastDateInserted', $Category, NULL);
if (GetValue('LastCommentUserID', $Category) == NULL) {
SetValue('LastCommentUserID', $Category, GetValue('LastDiscussionUserID', $Category, NULL));
SetValue('DateLastComment', $Category, GetValue('DateLastDiscussion', $Category, NULL));
SetValue('LastUserID', $Category, GetValue('LastDiscussionUserID', $Category, NULL));
$LastDiscussion = ArrayTranslate($Category, array('LastDiscussionID' => 'DiscussionID', 'CategoryID' => 'CategoryID', 'LastTitle' => 'Name'));
SetValue('LastUrl', $Category, DiscussionUrl($LastDiscussion, FALSE, '//') . '#latest');
if (is_null($LastDateInserted)) {
SetValue('LastDateInserted', $Category, GetValue('DateLastDiscussion', $Category, NULL));
}
} else {
$LastDiscussion = ArrayTranslate($Category, array('LastDiscussionID' => 'DiscussionID', 'CategoryID' => 'CategoryID', 'LastTitle' => 'Name'));
SetValue('LastUserID', $Category, GetValue('LastCommentUserID', $Category, NULL));
SetValue('LastUrl', $Category, DiscussionUrl($LastDiscussion, FALSE, '//') . '#latest');
if (is_null($LastDateInserted)) {
SetValue('LastDateInserted', $Category, GetValue('DateLastComment', $Category, NULL));
}
}
$LastDateInserted = GetValue('LastDateInserted', $Category, NULL);
if ($DateMarkedRead) {
if ($LastDateInserted) {
$Category->Read = Gdn_Format::ToTimestamp($DateMarkedRead) >= Gdn_Format::ToTimestamp($LastDateInserted);
} else {
$Category->Read = TRUE;
}
} else {
$Category->Read = FALSE;
}
foreach ($Result2 as $Category2) {
if ($Category2->TreeLeft > $Category->TreeLeft && $Category2->TreeRight < $Category->TreeRight) {
$Category->CountAllDiscussions += $Category2->CountDiscussions;
$Category->CountAllComments += $Category2->CountComments;
}
}
}
}
示例5: GetID
/**
* Get meta data of a single conversation.
*
* @since 2.0.0
* @access public
*
* @param int $ConversationID Unique ID of conversation.
* @param int $ViewingUserID Unique ID of current user.
* @return Gdn_DataSet SQL result (single row).
*/
public function GetID($ConversationID, $ViewingUserID = FALSE)
{
// Get the conversation.
$Conversation = $this->GetWhere(array('ConversationID' => $ConversationID))->FirstRow(DATASET_TYPE_ARRAY);
if ($ViewingUserID) {
$Data = $this->SQL->GetWhere('UserConversation', array('ConversationID' => $ConversationID, 'UserID' => $ViewingUserID))->FirstRow(DATASET_TYPE_ARRAY);
// Convert the array.
$UserConversation = ArrayTranslate($Data, array('LastMessageID', 'CountReadMessages', 'DateLastViewed', 'Bookmarked'));
$UserConversation['CountNewMessages'] = $Conversation['CountMessages'] - $Data['CountReadMessages'];
} else {
$UserConversation = array('CountNewMessages' => 0, 'CountReadMessages' => $Conversation['CountMessages'], 'DateLastViewed' => $Conversation['DateUpdated']);
}
$Conversation = array_merge($Conversation, $UserConversation);
return (object) $Conversation;
}
示例6: AnalyzeAddon
/**
* Check an addon's file to extract the addon information out of it.
*
* @param string $Path The path to the file.
* @param bool $Fix Whether or not to fix files that have been zipped incorrectly.
* @return array An array of addon information.
*/
public static function AnalyzeAddon($Path, $ThrowError = TRUE)
{
if (!file_exists($Path)) {
if ($ThrowError) {
throw new Exception("{$Path} not found.", 404);
}
return FALSE;
}
$Result = array();
$InfoPaths = array('/settings/about.php', '/default.php', '/class.*.plugin.php', '/about.php', '/definitions.php', '/index.php', 'vanilla2export.php');
// Get the list of potential files to analyze.
if (is_dir($Path)) {
$Entries = self::_GetInfoFiles($Path, $InfoPaths);
} else {
$Entries = self::_GetInfoZip($Path, $InfoPaths, FALSE, $ThrowError);
$DeleteEntries = TRUE;
}
foreach ($Entries as $Entry) {
if ($Entry['Name'] == '/index.php') {
// This could be the core vanilla package.
$Version = self::ParseCoreVersion($Entry['Path']);
if (!$Version) {
continue;
}
// The application was confirmed.
$Addon = array('AddonKey' => 'vanilla', 'AddonTypeID' => ADDON_TYPE_CORE, 'Name' => 'Vanilla', 'Description' => 'Vanilla is an open-source, standards-compliant, multi-lingual, fully extensible discussion forum for the web. Anyone who has web-space that meets the requirements can download and use Vanilla for free!', 'Version' => $Version, 'Path' => $Entry['Path']);
break;
} elseif ($Entry['Name'] == 'vanilla2export.php') {
// This could be the vanilla porter.
$Version = self::ParseCoreVersion($Entry['Path']);
if (!$Version) {
continue;
}
$Addon = array('AddonKey' => 'porter', 'AddonTypeID' => ADDON_TYPE_CORE, 'Name' => 'Vanilla Porter', 'Description' => 'Drop this script in your existing site and navigate to it in your web browser to export your existing forum data to the Vanilla 2 import format.', 'Version' => $Version, 'Path' => $Entry['Path']);
break;
} else {
// This could be an addon.
$Info = self::ParseInfoArray($Entry['Path']);
if (!is_array($Info) && count($Info)) {
continue;
}
$Key = key($Info);
$Variable = $Info['Variable'];
$Info = $Info[$Key];
// Validate the addon.
$Name = $Entry['Name'];
$Valid = TRUE;
if (!GetValue('Name', $Info)) {
$Info['Name'] = $Key;
}
if (!GetValue('Description', $Info)) {
$Result[] = $Name . ': ' . sprintf(T('ValidateRequired'), T('Description'));
$Valid = FALSE;
}
if (!GetValue('Version', $Info)) {
$Result[] = $Name . ': ' . sprintf(T('ValidateRequired'), T('Version'));
$Valid = FALSE;
}
if (isset($Entry['Base']) && strcasecmp($Entry['Base'], $Key) != 0 && $Variable != 'ThemeInfo') {
$Result[] = "{$Name}: The addon's key is not the same as its folder name.";
$Valid = FALSE;
}
if (!$Valid) {
continue;
}
// The addon is valid.
$Addon = array_merge(array('AddonKey' => $Key, 'AddonTypeID' => ''), $Info);
switch ($Variable) {
case 'ApplicationInfo':
$Addon['AddonTypeID'] = ADDON_TYPE_APPLICATION;
break;
case 'LocaleInfo':
$Addon['AddonTypeID'] = ADDON_TYPE_LOCALE;
break;
case 'PluginInfo':
$Addon['AddonTypeID'] = ADDON_TYPE_PLUGIN;
break;
case 'ThemeInfo':
$Addon['AddonTypeID'] = ADDON_TYPE_THEME;
break;
}
}
}
if ($DeleteEntries) {
$FolderPath = substr($Path, 0, -4);
Gdn_FileSystem::RemoveFolder($FolderPath);
}
// Add the addon requirements.
if ($Addon) {
$Requirements = ArrayTranslate($Addon, array('RequiredApplications' => 'Applications', 'RequiredPlugins' => 'Plugins', 'RequiredThemes' => 'Themes'));
foreach ($Requirements as $Type => $Items) {
if (!is_array($Items)) {
unset($Requirements[$Type]);
//.........这里部分代码省略.........
示例7: ModerationController_MergeDiscussions_Create
/**
* Add a method to the ModerationController to handle merging discussions.
* @param Gdn_Controller $Sender
*/
public function ModerationController_MergeDiscussions_Create($Sender)
{
$Session = Gdn::Session();
$Sender->Form = new Gdn_Form();
$Sender->Title(T('Merge Discussions'));
$DiscussionModel = new DiscussionModel();
$CheckedDiscussions = Gdn::UserModel()->GetAttribute($Session->User->UserID, 'CheckedDiscussions', array());
if (!is_array($CheckedDiscussions)) {
$CheckedDiscussions = array();
}
$DiscussionIDs = $CheckedDiscussions;
$Sender->SetData('DiscussionIDs', $DiscussionIDs);
$CountCheckedDiscussions = count($DiscussionIDs);
$Sender->SetData('CountCheckedDiscussions', $CountCheckedDiscussions);
$Discussions = $DiscussionModel->SQL->WhereIn('DiscussionID', $DiscussionIDs)->Get('Discussion')->ResultArray();
$Sender->SetData('Discussions', $Discussions);
// Perform the merge
if ($Sender->Form->AuthenticatedPostBack()) {
// Create a new discussion record
$MergeDiscussion = FALSE;
$MergeDiscussionID = $Sender->Form->GetFormValue('MergeDiscussionID');
foreach ($Discussions as $Discussion) {
if ($Discussion['DiscussionID'] == $MergeDiscussionID) {
$MergeDiscussion = $Discussion;
break;
}
}
$RedirectLink = $Sender->Form->GetFormValue('RedirectLink');
if ($MergeDiscussion) {
$ErrorCount = 0;
// Verify that the user has permission to perform the merge.
$Category = CategoryModel::Categories($MergeDiscussion['CategoryID']);
if ($Category && !$Category['PermsDiscussionsEdit']) {
throw PermissionException('Vanilla.Discussions.Edit');
}
$DiscussionModel->DefineSchema();
$MaxNameLength = GetValue('Length', $DiscussionModel->Schema->GetField('Name'));
// Assign the comments to the new discussion record
$DiscussionModel->SQL->Update('Comment')->Set('DiscussionID', $MergeDiscussionID)->WhereIn('DiscussionID', $DiscussionIDs)->Put();
$CommentModel = new CommentModel();
foreach ($Discussions as $Discussion) {
if ($Discussion['DiscussionID'] == $MergeDiscussionID) {
continue;
}
// Create a comment out of the discussion.
$Comment = ArrayTranslate($Discussion, array('Body', 'Format', 'DateInserted', 'InsertUserID', 'InsertIPAddress', 'DateUpdated', 'UpdateUserID', 'UpdateIPAddress', 'Attributes', 'Spam', 'Likes', 'Abuse'));
$Comment['DiscussionID'] = $MergeDiscussionID;
$CommentModel->Validation->Results(TRUE);
$CommentID = $CommentModel->Save($Comment);
if ($CommentID) {
// Move any attachments (FileUpload plugin awareness)
if (class_exists('MediaModel')) {
$MediaModel = new MediaModel();
$MediaModel->Reassign($Discussion['DiscussionID'], 'discussion', $CommentID, 'comment');
}
if ($RedirectLink) {
// The discussion needs to be changed to a moved link.
$RedirectDiscussion = array('Name' => SliceString(sprintf(T('Merged: %s'), $Discussion['Name']), $MaxNameLength), 'Type' => 'redirect', 'Body' => FormatString(T('This discussion has been <a href="{url,html}">merged</a>.'), array('url' => DiscussionUrl($MergeDiscussion))), 'Format' => 'Html');
$DiscussionModel->SetField($Discussion['DiscussionID'], $RedirectDiscussion);
$CommentModel->UpdateCommentCount($Discussion['DiscussionID']);
$CommentModel->RemovePageCache($Discussion['DiscussionID']);
} else {
// Delete discussion that was merged.
$DiscussionModel->Delete($Discussion['DiscussionID']);
}
} else {
$Sender->InformMessage($CommentModel->Validation->ResultsText());
$ErrorCount++;
}
}
// Update counts on all affected discussions.
$CommentModel->UpdateCommentCount($MergeDiscussionID);
$CommentModel->RemovePageCache($MergeDiscussionID);
// Clear selections
Gdn::UserModel()->SaveAttribute($Session->UserID, 'CheckedDiscussions', FALSE);
ModerationController::InformCheckedDiscussions($Sender);
if ($ErrorCount == 0) {
$Sender->JsonTarget('', '', 'Refresh');
}
}
}
$Sender->Render('MergeDiscussions', '', 'plugins/SplitMerge');
}
示例8: SaveUser
/**
* Change ban data on a user (ban or unban them).
*
* @since 2.0.18
* @access public
*
* @param array $User
* @param bool $BannedValue Whether user is banned.
*/
public function SaveUser($User, $BannedValue, $Ban = FALSE)
{
$Banned = $User['Banned'];
if ($Banned == $BannedValue) {
return;
}
Gdn::UserModel()->SetField($User['UserID'], 'Banned', $BannedValue);
// Add the activity.
$ActivityModel = new ActivityModel();
$Activity = array('ActivityType' => 'Ban', 'ActivityUserID' => $User['UserID'], 'RegardingUserID' => Gdn::Session()->UserID, 'NotifyUserID' => ActivityModel::NOTIFY_MODS);
$BannedString = $BannedValue ? 'banned' : 'unbanned';
if ($Ban) {
$Activity['HeadlineFormat'] = '{ActivityUserID,user} was ' . $BannedString . ' (based on {Data.BanType}: {Data.BanValue}).';
$Activity['Data'] = ArrayTranslate($Ban, array('BanType', 'BanValue'));
$Activity['Story'] = $Ban['Notes'];
$Activity['RecordType'] = 'Ban';
if (isset($Ban['BanID'])) {
$Activity['BanID'] = $Ban['BanID'];
}
} else {
$Activity['HeadlineFormat'] = '{ActivityUserID,user} was ' . $BannedString . '.';
}
$ActivityModel->Save($Activity);
}
示例9: EntryController_Twauthorize_Create
public function EntryController_Twauthorize_Create($Sender, $Dir = '')
{
$Query = ArrayTranslate($Sender->Request->Get(), array('display', 'Target'));
$Query = http_build_query($Query);
if ($Dir == 'profile') {
// This is a profile connection.
$this->RedirectUri(self::ProfileConnecUrl());
}
$this->Authorize($Query);
}
示例10: getTableInfo
/**
* Get the high-level table information for a given table.
*
* @param string $tableName The name of the table to get the information for.
* @return array? Returns an array of table information.
*/
protected function getTableInfo($tableName)
{
$pxName = $this->_DatabasePrefix . $tableName;
$status = $this->Database->query("show table status where name = '{$pxName}'")->firstRow(DATASET_TYPE_ARRAY);
if (!$status) {
return null;
}
$result = ArrayTranslate($status, array('Engine' => 'engine', 'Rows' => 'rows', 'Collation' => 'collation'));
// Look up the encoding for the collation.
$result['charset'] = $this->getCharsetFromCollation($result['collation']);
return $result;
}
示例11: Settings_AddEdit
/**
* @param Gdn_Controller $Sender
* @param array $Args
*/
protected function Settings_AddEdit($Sender, $Args)
{
$client_id = $Sender->Request->Get('client_id');
Gdn::Locale()->SetTranslation('AuthenticationKey', 'Client ID');
Gdn::Locale()->SetTranslation('AssociationSecret', 'Secret');
Gdn::Locale()->SetTranslation('AuthenticateUrl', 'Authentication Url');
$Form = new Gdn_Form();
$Sender->Form = $Form;
$Model = new Gdn_AuthenticationProviderModel();
if ($Form->AuthenticatedPostBack()) {
if ($Form->GetFormValue('Generate') || $Sender->Request->Post('Generate')) {
$Form->SetFormValue('AuthenticationKey', mt_rand());
$Form->SetFormValue('AssociationSecret', md5(mt_rand()));
$Sender->SetFormSaved(FALSE);
} else {
$Form->ValidateRule('AuthenticationKey', 'ValidateRequired');
$Form->ValidateRule('AuthenticationKey', 'regex:`^[a-z0-9_-]+$`i', T('The client id must contain only letters, numbers and dashes.'));
$Form->ValidateRule('AssociationSecret', 'ValidateRequired');
$Form->ValidateRule('AuthenticateUrl', 'ValidateRequired');
$Values = $Form->FormValues();
$Values = ArrayTranslate($Values, array('Name', 'AuthenticationKey', 'URL', 'AssociationSecret', 'AuthenticateUrl', 'SignInUrl', 'RegisterUrl', 'SignOutUrl', 'IsDefault'));
$Values['AuthenticationSchemeAlias'] = 'jsconnect';
$Values['AssociationHashMethod'] = 'md5';
$Values['Attributes'] = serialize(array('HashType' => $Form->GetFormValue('HashType'), 'TestMode' => $Form->GetFormValue('TestMode'), 'Trusted' => $Form->GetFormValue('Trusted', 0)));
if ($Form->ErrorCount() == 0) {
$IsDefault = GetValue('IsDefault', $Values);
if ($IsDefault) {
Gdn::SQL()->Put('UserAuthenticationProvider', array('IsDefault' => 0), array('AuthenticationKey <>' => val('AuthenticationKey', $Values)));
}
if ($client_id) {
Gdn::SQL()->Put('UserAuthenticationProvider', $Values, array('AuthenticationKey' => $client_id));
} else {
Gdn::SQL()->Options('Ignore', TRUE)->Insert('UserAuthenticationProvider', $Values);
}
$Sender->RedirectUrl = Url('/settings/jsconnect');
}
}
} else {
if ($client_id) {
$Provider = self::GetProvider($client_id);
TouchValue('Trusted', $Provider, 1);
} else {
$Provider = array();
}
$Form->SetData($Provider);
}
$Sender->SetData('Title', sprintf(T($client_id ? 'Edit %s' : 'Add %s'), T('Connection')));
$Sender->Render('Settings_AddEdit', '', 'plugins/jsconnect');
}
示例12: AnalyzeAddon
//.........这里部分代码省略.........
if (StringEndsWith($Name, '/definitions.php')) {
if (count(explode('/', $Folder)) > 3) {
// The file is too deep to be a plugin file.
continue;
}
// This could be a locale pack, but we have to examine its info array.
$Zip->extractTo($FolderPath, $Entry['name']);
$FilePath = CombinePaths(array($FolderPath, $Name));
$Info = self::ParseInfoArray($FilePath, 'LocaleInfo');
Gdn_FileSystem::RemoveFolder(dirname($FilePath));
if (!is_array($Info) || !count($Info)) {
continue;
}
$Key = key($Info);
$Info = $Info[$Key];
$Valid = TRUE;
$Root = trim(substr($Name, 0, -strlen('/definitions.php')), '/');
// Make sure the locale is at least one folder deep.
if ($Root != $Key) {
$Result[] = $Name . ': The locale pack\'s key must be the same as its folder name.';
$Valid = FALSE;
}
if (!GetValue('Locale', $Info)) {
$Result[] = $Name . ': ' . sprintf(T('ValidateRequired'), T('Locale'));
$Valud = FALSE;
} elseif (strcasecmp($Info['Locale'], $Key) == 0) {
$Result[] = $Name . ': ' . T('The locale\'s key cannot be the same as the name of the locale.');
$Valid = FALSE;
}
if (!GetValue('Description', $Info)) {
$Result[] = $Name . ': ' . sprintf(T('ValidateRequired'), T('Description'));
$Valid = FALSE;
}
if (!GetValue('Version', $Info)) {
$Result[] = $Name . ': ' . sprintf(T('ValidateRequired'), T('Version'));
$Valid = FALSE;
}
if ($Valid) {
// The locale pack was confirmed.
$Addon = array('AddonKey' => $Key, 'AddonTypeID' => ADDON_TYPE_LOCALE, 'Name' => GetValue('Name', $Info) ? $Info['Name'] : $Key, 'Description' => $Info['Description'], 'Version' => $Info['Version'], 'Path' => $Path);
break;
}
}
// Check to see if the entry is a core file.
if (StringEndsWith($Name, '/index.php')) {
if (count(explode('/', $Folder)) != 3) {
// The file is too deep to be the core's index.php
continue;
}
// This could be a theme file, but we have to examine its info array.
$Zip->extractTo($FolderPath, $Entry['name']);
$FilePath = CombinePaths(array($FolderPath, $Name));
// Get the version number from the core.
$Version = self::ParseCoreVersion($FilePath);
if (!$Version) {
continue;
}
// The application was confirmed.
$Addon = array('AddonKey' => 'vanilla', 'AddonTypeID' => ADDON_TYPE_CORE, 'Name' => 'Vanilla', 'Description' => 'Vanilla is an open-source, standards-compliant, multi-lingual, fully extensible discussion forum for the web. Anyone who has web-space that meets the requirements can download and use Vanilla for free!', 'Version' => $Version, 'Path' => $Path);
$Info = array();
break;
}
}
if ($Addon) {
// Add the requirements.
$Requirements = ArrayTranslate($Info, array('RequiredApplications' => 'Applications', 'RequiredPlugins' => 'Plugins', 'RequiredThemes' => 'Themes'));
foreach ($Requirements as $Type => $Items) {
if (!is_array($Items)) {
unset($Requirements[$Type]);
}
}
$Addon['Requirements'] = serialize($Requirements);
$Addon['Checked'] = TRUE;
$UploadsPath = PATH_ROOT . '/uploads/';
if (StringBeginsWith($Addon['Path'], $UploadsPath)) {
$Addon['File'] = substr($Addon['Path'], strlen($UploadsPath));
}
if ($Fix) {
// Delete extraneous files.
foreach ($Deletes as $Delete) {
$Zip->deleteName($Delete['name']);
}
}
}
$Zip->close();
if (file_exists($FolderPath)) {
Gdn_FileSystem::RemoveFolder($FolderPath);
}
if ($Addon) {
$Addon['MD5'] = md5_file($Path);
return $Addon;
} else {
if ($ThrowError) {
$Msg = implode("\n", $Result);
throw new Exception($Msg, 400);
} else {
return FALSE;
}
}
}
示例13: Save
/**
* Inserts or updates the discussion via form values.
*
* Events: BeforeSaveDiscussion, AfterSaveDiscussion.
*
* @since 2.0.0
* @access public
*
* @param array $FormPostValues Data sent from the form model.
* @return int $DiscussionID Unique ID of the discussion.
*/
public function Save($FormPostValues)
{
$Session = Gdn::Session();
// Define the primary key in this model's table.
$this->DefineSchema();
// Add & apply any extra validation rules:
$this->Validation->ApplyRule('Body', 'Required');
$MaxCommentLength = Gdn::Config('Vanilla.Comment.MaxLength');
if (is_numeric($MaxCommentLength) && $MaxCommentLength > 0) {
$this->Validation->SetSchemaProperty('Body', 'Length', $MaxCommentLength);
$this->Validation->ApplyRule('Body', 'Length');
}
// Get the DiscussionID from the form so we know if we are inserting or updating.
$DiscussionID = ArrayValue('DiscussionID', $FormPostValues, '');
// See if there is a source ID.
if (array_key_exists('SourceID', $FormPostValues)) {
$DiscussionID = $this->SQL->GetWhere('Discussion', ArrayTranslate($FormPostValues, array('Source', 'SourceID')))->Value('DiscussionID');
if ($DiscussionID) {
$FormPostValues['DiscussionID'] = $DiscussionID;
}
}
$Insert = $DiscussionID == '' ? TRUE : FALSE;
$this->EventArguments['Insert'] = $Insert;
if ($Insert) {
unset($FormPostValues['DiscussionID']);
// If no categoryid is defined, grab the first available.
if (ArrayValue('CategoryID', $FormPostValues) === FALSE) {
$FormPostValues['CategoryID'] = $this->SQL->Get('Category', 'CategoryID', '', 1)->FirstRow()->CategoryID;
}
$this->AddInsertFields($FormPostValues);
// $FormPostValues['LastCommentUserID'] = $Session->UserID;
$FormPostValues['DateLastComment'] = Gdn_Format::ToDateTime();
}
// Add the update fields because this table's default sort is by DateUpdated (see $this->Get()).
$this->AddUpdateFields($FormPostValues);
// Set checkbox values to zero if they were unchecked
if (ArrayValue('Announce', $FormPostValues, '') === FALSE) {
$FormPostValues['Announce'] = 0;
}
if (ArrayValue('Closed', $FormPostValues, '') === FALSE) {
$FormPostValues['Closed'] = 0;
}
if (ArrayValue('Sink', $FormPostValues, '') === FALSE) {
$FormPostValues['Sink'] = 0;
}
// Prep and fire event
$this->EventArguments['FormPostValues'] =& $FormPostValues;
$this->EventArguments['DiscussionID'] = $DiscussionID;
$this->FireEvent('BeforeSaveDiscussion');
// Validate the form posted values
if ($this->Validate($FormPostValues, $Insert)) {
// If the post is new and it validates, make sure the user isn't spamming
if (!$Insert || !$this->CheckForSpam('Discussion')) {
// Get all fields on the form that relate to the schema
$Fields = $this->Validation->SchemaValidationFields();
// Get DiscussionID if one was sent
$DiscussionID = intval(ArrayValue('DiscussionID', $Fields, 0));
// Remove the primary key from the fields for saving
$Fields = RemoveKeyFromArray($Fields, 'DiscussionID');
$Discussion = FALSE;
$StoredCategoryID = FALSE;
if ($DiscussionID > 0) {
// Updating
$Stored = $this->GetID($DiscussionID);
// Clear the cache if necessary.
if (GetValue('Announce', $Stored) != GetValue('Announce', $Fields)) {
$CacheKeys = array('Announcements', 'Announcements_' . GetValue('CategoryID', $Fields));
$Announce = GetValue('Announce', $Discussion);
$this->SQL->Cache($CacheKeys);
}
$this->SQL->Put($this->Name, $Fields, array($this->PrimaryKey => $DiscussionID));
$Fields['DiscussionID'] = $DiscussionID;
LogModel::LogChange('Edit', 'Discussion', (array) $Fields, (array) $Stored);
if ($Stored->CategoryID != $Fields['CategoryID']) {
$StoredCategoryID = $Stored->CategoryID;
}
} else {
// Inserting.
if (!GetValue('Format', $Fields)) {
$Fields['Format'] = Gdn::Config('Garden.InputFormatter', '');
}
// Check for spam.
$Spam = SpamModel::IsSpam('Discussion', $Fields);
// Clear the cache if necessary.
if (GetValue('Announce', $Fields)) {
$CacheKeys = array('Announcements', 'Announcements_' . GetValue('CategoryID', $Fields));
$Announce = GetValue('Announce', $Discussion);
$this->SQL->Cache($CacheKeys);
}
//.........这里部分代码省略.........
示例14: Initialize
public function Initialize($Schema = NULL)
{
if ($Schema !== NULL) {
$this->Schema($Schema);
}
$Form = $this->Form();
if ($Form->AuthenticatedPostBack()) {
// Grab the data from the form.
$Data = array();
foreach ($this->_Schema as $Row) {
$Name = $Row['Name'];
if (strtolower(GetValue('Control', $Row)) == 'imageupload') {
$Form->SaveImage($Name, ArrayTranslate($Row, array('Prefix', 'Size')));
}
$Value = $Form->GetFormValue($Name);
if ($Value == GetValue('Default', $Value, '')) {
$Value = '';
}
$Data[$Name] = $Value;
}
// Save it to the config.
SaveToConfig($Data, array('RemoveEmpty' => TRUE));
$this->_Sender->InformMessage(T('Saved'));
} else {
// Load the form data from the config.
$Data = array();
foreach ($this->_Schema as $Row) {
$Data[$Row['Name']] = C($Row['Name'], GetValue('Default', $Row, ''));
}
$Form->SetData($Data);
}
}
示例15: Insert
/**
* Log an operation into the log table.
*
* @param string $Operation The operation being performed. This is usually one of:
* - Delete: The record has been deleted.
* - Edit: The record has been edited.
* - Spam: The record has been marked spam.
* - Moderate: The record requires moderation.
* @param string $RecordType The type of record being logged. This usually correspond to the tablename of the record.
* @param array $Data The record data.
* - If you are logging just one row then pass the row as an array.
* - You can pass an additional _New element to tell the logger what the new data is.
* @return int The log id.
*/
public static function Insert($Operation, $RecordType, $Data, $Options = array())
{
// Check to see if we are storing two versions of the data.
if (($InsertUserID = self::_LogValue($Data, 'Log_InsertUserID')) === NULL) {
$InsertUserID = Gdn::Session()->UserID;
}
if (($InsertIPAddress = self::_LogValue($Data, 'Log_InsertIPAddress')) == NULL) {
$InsertIPAddress = Gdn::Request()->IPAddress();
}
// Do some known translations for the parent record ID.
if (($ParentRecordID = self::_LogValue($Data, 'ParentRecordID')) === NULL) {
switch ($RecordType) {
case 'Activity':
$ParentRecordID = self::_LogValue($Data, 'CommentActivityID', 'CommentActivityID');
break;
case 'Comment':
$ParentRecordID = self::_LogValue($Data, 'DiscussionID', 'DiscussionID');
break;
}
}
// Get the row information from the data or determine it based on the type.
$LogRow = array('Operation' => $Operation, 'RecordType' => $RecordType, 'RecordID' => self::_LogValue($Data, 'RecordID', $RecordType . 'ID'), 'RecordUserID' => self::_LogValue($Data, 'RecordUserID', 'UpdateUserID', 'InsertUserID'), 'RecordIPAddress' => self::_LogValue($Data, 'RecordIPAddress', 'LastIPAddress', 'InsertIPAddress'), 'RecordDate' => self::_LogValue($Data, 'RecordDate', 'DateUpdated', 'DateInserted'), 'InsertUserID' => $InsertUserID, 'InsertIPAddress' => $InsertIPAddress, 'DateInserted' => Gdn_Format::ToDateTime(), 'ParentRecordID' => $ParentRecordID, 'Data' => serialize($Data));
if ($LogRow['RecordDate'] == NULL) {
$LogRow['RecordDate'] = Gdn_Format::ToDateTime();
}
$GroupBy = GetValue('GroupBy', $Options);
// Make sure we aren't grouping by null values.
if (is_array($GroupBy)) {
foreach ($GroupBy as $Name) {
if (GetValue($Name, $LogRow) === NULL) {
$GroupBy = FALSE;
break;
}
}
}
if ($GroupBy) {
$GroupBy[] = 'Operation';
$GroupBy[] = 'RecordType';
// Check to see if there is a record already logged here.
$Where = array_combine($GroupBy, ArrayTranslate($LogRow, $GroupBy));
$LogRow2 = Gdn::SQL()->GetWhere('Log', $Where)->FirstRow(DATASET_TYPE_ARRAY);
if ($LogRow2) {
$LogID = $LogRow2['LogID'];
$OtherUserIDs = explode(',', $LogRow2['OtherUserIDs']);
if (!is_array($OtherUserIDs)) {
$OtherUserIDs = array();
}
if ($InsertUserID != $LogRow2['InsertUserID'] && !in_array($InsertUserID, $OtherUserIDs)) {
$OtherUserIDs[] = $InsertUserID;
}
if (array_key_exists('OtherUserIDs', $Options)) {
$OtherUserIDs = array_merge($OtherUserIDs, $Options['OtherUserIDs']);
$OtherUserIDs = array_unique($OtherUserIDs);
$OtherUserIDs = array_diff($OtherUserIDs, array($InsertUserID));
$Count = count($OtherUserIDs) + 1;
} else {
$Count = (int) $LogRow2['CountGroup'] + 1;
}
Gdn::SQL()->Put('Log', array('OtherUserIDs' => implode(',', $OtherUserIDs), 'CountGroup' => $Count, 'DateUpdated' => Gdn_Format::ToDateTime()), array('LogID' => $LogID));
} else {
$LogID = Gdn::SQL()->Insert('Log', $LogRow);
}
} else {
// Insert the log entry.
$LogID = Gdn::SQL()->Insert('Log', $LogRow);
}
return $LogID;
}