本文整理汇总了PHP中DiscussionModel::GetForeignID方法的典型用法代码示例。如果您正苦于以下问题:PHP DiscussionModel::GetForeignID方法的具体用法?PHP DiscussionModel::GetForeignID怎么用?PHP DiscussionModel::GetForeignID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DiscussionModel
的用法示例。
在下文中一共展示了DiscussionModel::GetForeignID方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: embed
/**
* Alternate version of Index that uses the embed master view.
*
* @param int $DiscussionID Unique identifier, if discussion has been created.
* @param string $DiscussionStub Deprecated.
* @param int $Offset
* @param int $Limit
*/
public function embed($DiscussionID = '', $DiscussionStub = '', $Offset = '', $Limit = '')
{
$this->title(t('Comments'));
// Add theme data
$this->Theme = c('Garden.CommentsTheme', $this->Theme);
Gdn_Theme::section('Comments');
// Force view options
$this->MasterView = 'empty';
$this->CanEditComments = false;
// Don't show the comment checkboxes on the embed comments page
// Add some css to help with the transparent bg on embedded comments
if ($this->Head) {
$this->Head->addString('<style type="text/css">
body { background: transparent !important; }
</style>');
}
// Javascript files & options
$this->addJsFile('jquery.gardenmorepager.js');
$this->addJsFile('jquery.autosize.min.js');
$this->addJsFile('discussion.js');
$this->removeJsFile('autosave.js');
$this->addDefinition('DoInform', '0');
// Suppress inform messages on embedded page.
$this->addDefinition('SelfUrl', Gdn::request()->PathAndQuery());
$this->addDefinition('Embedded', true);
// Define incoming variables (prefer querystring parameters over method parameters)
$DiscussionID = is_numeric($DiscussionID) && $DiscussionID > 0 ? $DiscussionID : 0;
$DiscussionID = getIncomingValue('vanilla_discussion_id', $DiscussionID);
$Offset = getIncomingValue('Offset', $Offset);
$Limit = getIncomingValue('Limit', $Limit);
$vanilla_identifier = getIncomingValue('vanilla_identifier', '');
// Only allow vanilla identifiers of 32 chars or less - md5 if larger
if (strlen($vanilla_identifier) > 32) {
$vanilla_identifier = md5($vanilla_identifier);
}
$vanilla_type = getIncomingValue('vanilla_type', 'page');
$vanilla_url = getIncomingValue('vanilla_url', '');
$vanilla_category_id = getIncomingValue('vanilla_category_id', '');
$ForeignSource = array('vanilla_identifier' => $vanilla_identifier, 'vanilla_type' => $vanilla_type, 'vanilla_url' => $vanilla_url, 'vanilla_category_id' => $vanilla_category_id);
$this->setData('ForeignSource', $ForeignSource);
// Set comment sorting
$SortComments = c('Garden.Embed.SortComments') == 'desc' ? 'desc' : 'asc';
$this->setData('SortComments', $SortComments);
// Retrieve the discussion record
$Discussion = false;
if ($DiscussionID > 0) {
$Discussion = $this->DiscussionModel->getID($DiscussionID);
} elseif ($vanilla_identifier != '' && $vanilla_type != '') {
$Discussion = $this->DiscussionModel->GetForeignID($vanilla_identifier, $vanilla_type);
}
// Set discussion data if we have one for this page
if ($Discussion) {
// Allow Vanilla.Comments.View to be defined to limit access to embedded comments only.
// Otherwise, go with normal discussion view permissions. Either will do.
$this->permission(array('Vanilla.Discussions.View', 'Vanilla.Comments.View'), false, 'Category', $Discussion->PermissionCategoryID);
$this->setData('Discussion', $Discussion, true);
$this->setData('DiscussionID', $Discussion->DiscussionID, true);
$this->title($Discussion->Name);
// Actual number of comments, excluding the discussion itself
$ActualResponses = $Discussion->CountComments;
// Define the query offset & limit
if (!is_numeric($Limit) || $Limit < 0) {
$Limit = c('Garden.Embed.CommentsPerPage', 30);
}
$OffsetProvided = $Offset != '';
list($Offset, $Limit) = offsetLimit($Offset, $Limit);
$this->Offset = $Offset;
if (c('Vanilla.Comments.AutoOffset')) {
if ($ActualResponses <= $Limit) {
$this->Offset = 0;
}
if ($this->Offset == $ActualResponses) {
$this->Offset -= $Limit;
}
} elseif ($this->Offset == '') {
$this->Offset = 0;
}
if ($this->Offset < 0) {
$this->Offset = 0;
}
// Set the canonical url to have the proper page title.
$this->canonicalUrl(discussionUrl($Discussion, pageNumber($this->Offset, $Limit)));
// Load the comments.
$CurrentOrderBy = $this->CommentModel->orderBy();
if (stringBeginsWith(GetValueR('0.0', $CurrentOrderBy), 'c.DateInserted')) {
$this->CommentModel->orderBy('c.DateInserted ' . $SortComments);
// allow custom sort
}
$this->setData('Comments', $this->CommentModel->get($Discussion->DiscussionID, $Limit, $this->Offset), true);
if (count($this->CommentModel->where()) > 0) {
$ActualResponses = false;
}
//.........这里部分代码省略.........
示例2: Gdn_Statistics_Tick_Handler
public function Gdn_Statistics_Tick_Handler($Sender, $Args)
{
$Path = Gdn::Request()->Post('Path');
$Args = Gdn::Request()->Post('Args');
parse_str($Args, $Args);
$ResolvedPath = trim(Gdn::Request()->Post('ResolvedPath'), '/');
$ResolvedArgs = @json_decode(Gdn::Request()->Post('ResolvedArgs'));
$DiscussionID = NULL;
$DiscussionModel = new DiscussionModel();
// Gdn::Controller()->SetData('Path', $Path);
// Gdn::Controller()->SetData('Args', $Args);
// Gdn::Controller()->SetData('ResolvedPath', $ResolvedPath);
// Gdn::Controller()->SetData('ResolvedArgs', $ResolvedArgs);
// Comment permalink
if ($ResolvedPath == 'vanilla/discussion/comment') {
$CommentID = GetValue('CommentID', $ResolvedArgs);
$CommentModel = new CommentModel();
$Comment = $CommentModel->GetID($CommentID);
$DiscussionID = GetValue('DiscussionID', $Comment);
} elseif ($ResolvedPath == 'vanilla/discussion/index') {
$DiscussionID = GetValue('DiscussionID', $ResolvedArgs, NULL);
} elseif ($ResolvedPath == 'vanilla/discussion/embed') {
$ForeignID = GetValue('vanilla_identifier', $Args);
if ($ForeignID) {
// This will be hit a lot so let's try caching it...
$Key = "DiscussionID.ForeignID.page.{$ForeignID}";
$DiscussionID = Gdn::Cache()->Get($Key);
if (!$DiscussionID) {
$Discussion = $DiscussionModel->GetForeignID($ForeignID, 'page');
$DiscussionID = GetValue('DiscussionID', $Discussion);
Gdn::Cache()->Store($Key, $DiscussionID, array(Gdn_Cache::FEATURE_EXPIRY, 1800));
}
}
}
if ($DiscussionID) {
$DiscussionModel->AddView($DiscussionID);
}
}
示例3: Comment
/**
* Create or update a comment.
*
* @since 2.0.0
* @access public
*
* @param int $DiscussionID Unique ID to add the comment to. If blank, this method will throw an error.
*/
public function Comment($DiscussionID = '')
{
// Get $DiscussionID from RequestArgs if valid
if ($DiscussionID == '' && count($this->RequestArgs)) {
if (is_numeric($this->RequestArgs[0])) {
$DiscussionID = $this->RequestArgs[0];
}
}
// If invalid $DiscussionID, get from form.
$this->Form->SetModel($this->CommentModel);
$DiscussionID = is_numeric($DiscussionID) ? $DiscussionID : $this->Form->GetFormValue('DiscussionID', 0);
// Set discussion data
$this->DiscussionID = $DiscussionID;
$this->Discussion = $Discussion = $this->DiscussionModel->GetID($DiscussionID);
// Is this an embedded comment being posted to a discussion that doesn't exist yet?
$vanilla_type = $this->Form->GetFormValue('vanilla_type', '');
$vanilla_url = $this->Form->GetFormValue('vanilla_url', '');
$vanilla_category_id = $this->Form->GetFormValue('vanilla_category_id', '');
$Attributes = array('ForeignUrl' => $vanilla_url);
$vanilla_identifier = $this->Form->GetFormValue('vanilla_identifier', '');
// Only allow vanilla identifiers of 32 chars or less - md5 if larger
if (strlen($vanilla_identifier) > 32) {
$Attributes['vanilla_identifier'] = $vanilla_identifier;
$vanilla_identifier = md5($vanilla_identifier);
}
if (!$Discussion && $vanilla_url != '' && $vanilla_identifier != '') {
$Discussion = $Discussion = $this->DiscussionModel->GetForeignID($vanilla_identifier, $vanilla_type);
if ($Discussion) {
$this->DiscussionID = $DiscussionID = $Discussion->DiscussionID;
$this->Form->SetValue('DiscussionID', $DiscussionID);
}
}
// If so, create it!
if (!$Discussion && $vanilla_url != '' && $vanilla_identifier != '') {
// Add these values back to the form if they exist!
$this->Form->AddHidden('vanilla_identifier', $vanilla_identifier);
$this->Form->AddHidden('vanilla_type', $vanilla_type);
$this->Form->AddHidden('vanilla_url', $vanilla_url);
$this->Form->AddHidden('vanilla_category_id', $vanilla_category_id);
$PageInfo = FetchPageInfo($vanilla_url);
if (!($Title = $this->Form->GetFormValue('Name'))) {
$Title = GetValue('Title', $PageInfo, '');
if ($Title == '') {
$Title = T('Undefined discussion subject.');
}
}
$Description = GetValue('Description', $PageInfo, '');
$Images = GetValue('Images', $PageInfo, array());
$LinkText = T('EmbededDiscussionLinkText', 'Read the full story here');
if (!$Description && count($Images) == 0) {
$Body = FormatString('<p><a href="{Url}">{LinkText}</a></p>', array('Url' => $vanilla_url, 'LinkText' => $LinkText));
} else {
$Body = FormatString('
<div class="EmbeddedContent">{Image}<strong>{Title}</strong>
<p>{Excerpt}</p>
<p><a href="{Url}">{LinkText}</a></p>
<div class="ClearFix"></div>
</div>', array('Title' => $Title, 'Excerpt' => $Description, 'Image' => count($Images) > 0 ? Img(GetValue(0, $Images), array('class' => 'LeftAlign')) : '', 'Url' => $vanilla_url, 'LinkText' => $LinkText));
}
if ($Body == '') {
$Body = $vanilla_url;
}
if ($Body == '') {
$Body = T('Undefined discussion body.');
}
// Validate the CategoryID for inserting.
$Category = CategoryModel::Categories($vanilla_category_id);
if (!$Category) {
$vanilla_category_id = C('Vanilla.Embed.DefaultCategoryID', 0);
if ($vanilla_category_id <= 0) {
// No default category defined, so grab the first non-root category and use that.
$vanilla_category_id = $this->DiscussionModel->SQL->Select('CategoryID')->From('Category')->Where('CategoryID >', 0)->Get()->FirstRow()->CategoryID;
// No categories in the db? default to 0
if (!$vanilla_category_id) {
$vanilla_category_id = 0;
}
}
} else {
$vanilla_category_id = $Category['CategoryID'];
}
$EmbedUserID = C('Garden.Embed.UserID');
if ($EmbedUserID) {
$EmbedUser = Gdn::UserModel()->GetID($EmbedUserID);
}
if (!$EmbedUserID || !$EmbedUser) {
$EmbedUserID = Gdn::UserModel()->GetSystemUserID();
}
$EmbeddedDiscussionData = array('InsertUserID' => $EmbedUserID, 'DateInserted' => Gdn_Format::ToDateTime(), 'DateUpdated' => Gdn_Format::ToDateTime(), 'CategoryID' => $vanilla_category_id, 'ForeignID' => $vanilla_identifier, 'Type' => $vanilla_type, 'Name' => $Title, 'Body' => $Body, 'Format' => 'Html', 'Attributes' => serialize($Attributes));
$this->EventArguments['Discussion'] = $EmbeddedDiscussionData;
$this->FireEvent('BeforeEmbedDiscussion');
$DiscussionID = $this->DiscussionModel->SQL->Insert('Discussion', $EmbeddedDiscussionData);
$ValidationResults = $this->DiscussionModel->ValidationResults();
//.........这里部分代码省略.........