本文整理汇总了PHP中PageNumber函数的典型用法代码示例。如果您正苦于以下问题:PHP PageNumber函数的具体用法?PHP PageNumber怎么用?PHP PageNumber使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PageNumber函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: DiscussionsController_Tagged_Create
/**
* Load discussions for a specific tag.
*/
public function DiscussionsController_Tagged_Create($Sender)
{
$Offset = GetValue('1', $Sender->RequestArgs, 'p1');
list($Offset, $Limit) = OffsetLimit($Offset, Gdn::Config('Vanilla.Discussions.PerPage', 30));
$Sender->Tag = GetValue('0', $Sender->RequestArgs, '');
$Sender->Title(T('Tagged with ') . $Sender->Tag);
$Sender->Head->Title($Sender->Head->Title());
$Sender->CanonicalUrl(Url(ConcatSep('/', 'discussions/tagged/' . $Sender->Tag, PageNumber($Offset, $Limit, TRUE)), TRUE));
if ($Sender->Head) {
$Sender->AddJsFile('discussions.js');
$Sender->AddJsFile('bookmark.js');
$Sender->AddJsFile('js/library/jquery.menu.js');
$Sender->AddJsFile('options.js');
$Sender->Head->AddRss($Sender->SelfUrl . '/feed.rss', $Sender->Head->Title());
}
if (!is_numeric($Offset) || $Offset < 0) {
$Offset = 0;
}
// Add Modules
$Sender->AddModule('NewDiscussionModule');
$BookmarkedModule = new BookmarkedModule($Sender);
$BookmarkedModule->GetData();
$Sender->AddModule($BookmarkedModule);
$Sender->SetData('Category', FALSE, TRUE);
$DiscussionModel = new DiscussionModel();
$Tag = $DiscussionModel->SQL->Select()->From('Tag')->Where('Name', $Sender->Tag)->Get()->FirstRow();
$TagID = $Tag ? $Tag->TagID : 0;
$CountDiscussions = $Tag ? $Tag->CountDiscussions : 0;
$Sender->SetData('CountDiscussions', $CountDiscussions);
$Sender->AnnounceData = FALSE;
$Sender->SetData('Announcements', array(), TRUE);
$DiscussionModel->FilterToTagID = $TagID;
$Sender->DiscussionData = $DiscussionModel->Get($Offset, $Limit);
$Sender->SetData('Discussions', $Sender->DiscussionData, TRUE);
$Sender->SetJson('Loading', $Offset . ' to ' . $Limit);
// Build a pager.
$PagerFactory = new Gdn_PagerFactory();
$Sender->Pager = $PagerFactory->GetPager('Pager', $Sender);
$Sender->Pager->ClientID = 'Pager';
$Sender->Pager->Configure($Offset, $Limit, $CountDiscussions, 'discussions/tagged/' . $Sender->Tag . '/%1$s');
// Deliver json data if necessary
if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL) {
$Sender->SetJson('LessRow', $Sender->Pager->ToString('less'));
$Sender->SetJson('MoreRow', $Sender->Pager->ToString('more'));
$Sender->View = 'discussions';
}
// Set a definition of the user's current timezone from the db. jQuery
// will pick this up, compare to the browser, and update the user's
// timezone if necessary.
$CurrentUser = Gdn::Session()->User;
if (is_object($CurrentUser)) {
$ClientHour = $CurrentUser->HourOffset + date('G', time());
$Sender->AddDefinition('SetClientHour', $ClientHour);
}
// Render the controller
$Sender->Render(PATH_PLUGINS . '/Tagging/views/taggeddiscussions.php');
}
示例2: Index
/**
* Default all discussions view: chronological by most recent comment.
*
* @since 2.0.0
* @access public
*
* @param int $Page Multiplied by PerPage option to determine offset.
*/
public function Index($Page = '0')
{
// Determine offset from $Page
list($Page, $Limit) = OffsetLimit($Page, Gdn::Config('Vanilla.Discussions.PerPage', 30));
$this->CanonicalUrl(Url(ConcatSep('/', 'discussions', PageNumber($Page, $Limit, TRUE)), TRUE));
// Validate $Page
if (!is_numeric($Page) || $Page < 0) {
$Page = 0;
}
// Setup head
$this->Title(T('All Discussions'));
if ($this->Head) {
$this->Head->AddRss(Url('/discussions/feed.rss', TRUE), $this->Head->Title());
}
// Add modules
$this->AddModule('NewDiscussionModule');
$this->AddModule('CategoriesModule');
$BookmarkedModule = new BookmarkedModule($this);
$BookmarkedModule->GetData();
$this->AddModule($BookmarkedModule);
// Set criteria & get discussions data
$this->SetData('Category', FALSE, TRUE);
$DiscussionModel = new DiscussionModel();
$CountDiscussions = $DiscussionModel->GetCount();
$this->SetData('CountDiscussions', $CountDiscussions);
$this->AnnounceData = $Page == 0 ? $DiscussionModel->GetAnnouncements() : FALSE;
$this->SetData('Announcements', $this->AnnounceData !== FALSE ? $this->AnnounceData : array(), TRUE);
$this->DiscussionData = $DiscussionModel->Get($Page, $Limit);
$this->SetData('Discussions', $this->DiscussionData, TRUE);
$this->SetJson('Loading', $Page . ' to ' . $Limit);
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$this->EventArguments['PagerType'] = 'Pager';
$this->FireEvent('BeforeBuildPager');
$this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
$this->Pager->ClientID = 'Pager';
$this->Pager->Configure($Page, $Limit, $CountDiscussions, 'discussions/%1$s');
$this->FireEvent('AfterBuildPager');
// Deliver JSON data if necessary
if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
$this->SetJson('LessRow', $this->Pager->ToString('less'));
$this->SetJson('MoreRow', $this->Pager->ToString('more'));
$this->View = 'discussions';
}
// Set a definition of the user's current timezone from the db. jQuery
// will pick this up, compare to the browser, and update the user's
// timezone if necessary.
$CurrentUser = Gdn::Session()->User;
if (is_object($CurrentUser)) {
$ClientHour = $CurrentUser->HourOffset + date('G', time());
$this->AddDefinition('SetClientHour', $ClientHour);
}
// Render default view (discussions/index.php)
$this->Render();
}
示例3: Index
public function Index($Offset = '0')
{
list($Offset, $Limit) = OffsetLimit($Offset, Gdn::Config('Vanilla.Discussions.PerPage', 30));
$this->CanonicalUrl(Url(ConcatSep('/', 'discussions', PageNumber($Offset, $Limit, TRUE)), TRUE));
$this->Title(T('All Discussions'));
if ($this->Head) {
$this->Head->AddRss($this->SelfUrl . '/feed.rss', $this->Head->Title());
}
if (!is_numeric($Offset) || $Offset < 0) {
$Offset = 0;
}
// Add Modules
$this->AddModule('NewDiscussionModule');
$this->AddModule('CategoriesModule');
$BookmarkedModule = new BookmarkedModule($this);
$BookmarkedModule->GetData();
$this->AddModule($BookmarkedModule);
$this->SetData('Category', FALSE, TRUE);
$DiscussionModel = new DiscussionModel();
$CountDiscussions = $DiscussionModel->GetCount();
$this->SetData('CountDiscussions', $CountDiscussions);
$this->AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements() : FALSE;
$this->SetData('Announcements', $this->AnnounceData !== FALSE ? $this->AnnounceData : array(), TRUE);
$this->DiscussionData = $DiscussionModel->Get($Offset, $Limit);
$this->SetData('Discussions', $this->DiscussionData, TRUE);
$this->SetJson('Loading', $Offset . ' to ' . $Limit);
// Build a pager.
$PagerFactory = new Gdn_PagerFactory();
$this->Pager = $PagerFactory->GetPager('Pager', $this);
$this->Pager->ClientID = 'Pager';
$this->Pager->Configure($Offset, $Limit, $CountDiscussions, 'discussions/%1$s');
// Deliver json data if necessary
if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
$this->SetJson('LessRow', $this->Pager->ToString('less'));
$this->SetJson('MoreRow', $this->Pager->ToString('more'));
$this->View = 'discussions';
}
// Set a definition of the user's current timezone from the db. jQuery
// will pick this up, compare to the browser, and update the user's
// timezone if necessary.
$CurrentUser = Gdn::Session()->User;
if (is_object($CurrentUser)) {
$ClientHour = $CurrentUser->HourOffset + date('G', time());
$this->AddDefinition('SetClientHour', $ClientHour);
}
// Render the controller
$this->Render();
}
示例4: Comment
//.........这里部分代码省略.........
} elseif ($Preview) {
// If this was a preview click, create a comment shell with the values for this comment
$this->Comment = new stdClass();
$this->Comment->InsertUserID = $Session->User->UserID;
$this->Comment->InsertName = $Session->User->Name;
$this->Comment->InsertPhoto = $Session->User->Photo;
$this->Comment->DateInserted = Gdn_Format::Date();
$this->Comment->Body = ArrayValue('Body', $FormValues, '');
$this->AddAsset('Content', $this->FetchView('preview'));
} else {
// If this was a draft save, notify the user about the save
$this->StatusMessage = sprintf(T('Draft saved at %s'), Gdn_Format::Date());
}
}
} else {
// Handle ajax-based requests
if ($this->Form->ErrorCount() > 0) {
// Return the form errors
$this->StatusMessage = $this->Form->Errors();
} else {
// Make sure that the ajax request form knows about the newly created comment or draft id
$this->SetJson('CommentID', $CommentID);
$this->SetJson('DraftID', $DraftID);
if ($Preview) {
// If this was a preview click, create a comment shell with the values for this comment
$this->Comment = new stdClass();
$this->Comment->InsertUserID = $Session->User->UserID;
$this->Comment->InsertName = $Session->User->Name;
$this->Comment->InsertPhoto = $Session->User->Photo;
$this->Comment->DateInserted = Gdn_Format::Date();
$this->Comment->Body = ArrayValue('Body', $FormValues, '');
$this->View = 'preview';
} elseif (!$Draft) {
// If the comment was not a draft
// If Editing a comment
if ($Editing) {
// Just reload the comment in question
$this->Offset = 1;
$this->SetData('CommentData', $this->CommentModel->GetIDData($CommentID), TRUE);
// Load the discussion
$this->ControllerName = 'discussion';
$this->View = 'comments';
// Also define the discussion url in case this request came from the post screen and needs to be redirected to the discussion
$this->SetJson('DiscussionUrl', Url('/discussion/' . $DiscussionID . '/' . Gdn_Format::Url($this->Discussion->Name) . '/#Comment_' . $CommentID));
} else {
// If the comment model isn't sorted by DateInserted or CommentID then we can't do any fancy loading of comments.
$OrderBy = GetValueR('0.0', $this->CommentModel->OrderBy());
$Redirect = !in_array($OrderBy, array('c.DateInserted', 'c.CommentID'));
if (!$Redirect) {
// Otherwise load all new comments that the user hasn't seen yet
$LastCommentID = $this->Form->GetFormValue('LastCommentID');
if (!is_numeric($LastCommentID)) {
$LastCommentID = $CommentID - 1;
}
// Failsafe back to this new comment if the lastcommentid was not defined properly
// Don't reload the first comment if this new comment is the first one.
$this->Offset = $LastCommentID == 0 ? 1 : $this->CommentModel->GetOffset($LastCommentID);
// Do not load more than a single page of data...
$Limit = C('Vanilla.Comments.PerPage', 50);
// Redirect if the new new comment isn't on the same page.
$Redirect |= PageNumber($this->Offset, $Limit) != PageNumber($Discussion->CountComments - 1, $Limit);
}
if ($Redirect) {
// The user posted a comment on a page other than the last one, so just redirect to the last page.
$this->RedirectUrl = Gdn::Request()->Url("discussion/comment/{$CommentID}/#Comment_{$CommentID}", TRUE);
$this->CommentData = NULL;
} else {
// Make sure to load all new comments since the page was last loaded by this user
$this->SetData('CommentData', $this->CommentModel->GetNew($DiscussionID, $LastCommentID), TRUE);
$this->SetData('NewComments', TRUE);
$this->ControllerName = 'discussion';
$this->View = 'comments';
}
// Make sure to set the user's discussion watch records
$CountComments = $this->CommentModel->GetCount($DiscussionID);
$Limit = is_object($this->CommentData) ? $this->CommentData->NumRows() : $Discussion->CountComments;
$Offset = $CountComments - $Limit;
$this->CommentModel->SetWatch($this->Discussion, $Limit, $Offset, $CountComments);
}
} else {
// If this was a draft save, notify the user about the save
$this->StatusMessage = sprintf(T('Draft saved at %s'), Gdn_Format::Date());
}
// And update the draft count
$UserModel = Gdn::UserModel();
$CountDrafts = $UserModel->GetAttribute($Session->UserID, 'CountDrafts', 0);
$this->SetJson('MyDrafts', T('My Drafts'));
$this->SetJson('CountDrafts', $CountDrafts);
}
}
}
if (property_exists($this, 'Discussion')) {
$this->EventArguments['Discussion'] = $this->Discussion;
}
if (property_exists($this, 'Comment')) {
$this->EventArguments['Comment'] = $this->Comment;
}
$this->FireEvent('BeforeCommentRender');
$this->Render();
}
示例5: PageNumber
$numrows = $pro->num_rows();
$pro->get_products($list_id, true, false, $sort_fld, $direction, $first, $max_rows);
if ($pro->num_rows() == 0) {
$curpage = 1;
$pro->get_products($list_id, true, false, $sort_fld, $direction, 0, $max_rows);
}
$page = PageNumber($numrows, $max_rows, 5, $curpage, "index.php?list_id={$list_id}&sort_fld={$sort_fld}&direction={$direction}", $st, $cmdPrevious, $cmdNext);
} else {
$pro->get_products(-1, false, true, $sort_fld, $direction);
$numrows = $pro->num_rows();
$pro->get_products(-1, false, true, $sort_fld, $direction, $first, $max_rows);
if ($pro->num_rows() == 0) {
$curpage = 1;
$pro->get_products(-1, false, true, $sort_fld, $direction, 0, $max_rows);
}
$page = PageNumber($numrows, $max_rows, 5, $curpage, "index.php?list_id={$list_id}&sort_fld={$sort_fld}&direction={$direction}", $st, $cmdPrevious, $cmdNext);
}
$task = 'edit';
}
while ($pro->next_record()) {
$id = $pro->f('product_id');
$name = $pro->f('product_name');
$cate = $pro->f('category_name');
if (empty($cate)) {
$cate = $pro->f('attach_cate');
}
$click_del = "javascript:click_del(document.frmProList, {$id} , \"{$name}\" , \"" . sprintf($sc_ConfirmDeleteProduct, $name) . "\")";
?>
<tr>
<td width="1"><input type="checkbox" name="buy_id[]" value="<?php
示例6: Index
public function Index($DiscussionID = '', $DiscussionStub = '', $Offset = '', $Limit = '')
{
$this->AddCssFile('vanilla.css');
$Session = Gdn::Session();
$this->AddJsFile('jquery.resizable.js');
$this->AddJsFile('jquery.ui.packed.js');
$this->AddJsFile('jquery.autogrow.js');
// $this->AddJsFile('jquery.gardenmorepager.js');
$this->AddJsFile('options.js');
$this->AddJsFile('bookmark.js');
$this->AddJsFile('discussion.js');
$this->AddJsFile('autosave.js');
// Load the discussion record
$DiscussionID = is_numeric($DiscussionID) && $DiscussionID > 0 ? $DiscussionID : 0;
$this->SetData('Discussion', $this->DiscussionModel->GetID($DiscussionID), TRUE);
if (!is_object($this->Discussion)) {
return Gdn::Dispatcher()->Dispatch('Default404');
}
// Check Permissions
$this->Permission('Vanilla.Discussions.View', TRUE, 'Category', $this->Discussion->CategoryID);
$this->SetData('CategoryID', $this->CategoryID = $this->Discussion->CategoryID, TRUE);
// Setup
$this->Title($this->Discussion->Name);
// Actual number of comments, excluding the discussion itself
$ActualResponses = $this->Discussion->CountComments - 1;
// Define the query offset & limit
if (!is_numeric($Limit) || $Limit < 0) {
$Limit = C('Vanilla.Comments.PerPage', 50);
}
$OffsetProvided = $Offset != '';
list($Offset, $Limit) = OffsetLimit($Offset, $Limit);
// If $Offset isn't defined, assume that the user has not clicked to
// view a next or previous page, and this is a "view" to be counted.
if ($Offset == '') {
$this->DiscussionModel->AddView($DiscussionID);
}
$this->Offset = $Offset;
if (C('Vanilla.Comments.AutoOffset')) {
if (!is_numeric($this->Offset) || $this->Offset < 0 || !$OffsetProvided) {
// Round down to the appropriate offset based on the user's read comments & comments per page
$CountCommentWatch = $this->Discussion->CountCommentWatch > 0 ? $this->Discussion->CountCommentWatch : 0;
if ($CountCommentWatch > $ActualResponses) {
$CountCommentWatch = $ActualResponses;
}
// (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60;
$this->Offset = floor($CountCommentWatch / $Limit) * $Limit;
}
if ($ActualResponses <= $Limit) {
$this->Offset = 0;
}
if ($this->Offset == $ActualResponses) {
$this->Offset -= $Limit;
}
} else {
if ($this->Offset == '') {
$this->Offset = 0;
}
}
if ($this->Offset < 0) {
$this->Offset = 0;
}
// Set the canonical url to have the proper page title.
$this->CanonicalUrl(Url(ConcatSep('/', 'discussion/' . $this->Discussion->DiscussionID . '/' . Gdn_Format::Url($this->Discussion->Name), PageNumber($this->Offset, $Limit, TRUE)), TRUE));
// Make sure to set the user's discussion watch records
$this->CommentModel->SetWatch($this->Discussion, $Limit, $this->Offset, $this->Discussion->CountComments);
// Load the comments
$this->SetData('CommentData', $this->CommentModel->Get($DiscussionID, $Limit, $this->Offset), TRUE);
$this->SetData('Comments', $this->CommentData);
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$this->Pager = $PagerFactory->GetPager('Pager', $this);
$this->Pager->ClientID = 'Pager';
$this->Pager->Configure($this->Offset, $Limit, $ActualResponses, 'discussion/' . $DiscussionID . '/' . Gdn_Format::Url($this->Discussion->Name) . '/%1$s');
// $this->Pager->MoreCode = '%1$s more comments';
// $this->Pager->LessCode = '%1$s older comments';
// $this->Pager->ClientID = 'Pager';
// $this->Pager->Configure(
// $this->Offset,
// $Limit,
// $ActualResponses,
// 'discussion/'.$DiscussionID.'/'.Gdn_Format::Url($this->Discussion->Name).'/%1$s/%2$s/'
// );
// Define the form for the comment input
$this->Form = Gdn::Factory('Form', 'Comment');
$this->Form->Action = Url('/vanilla/post/comment/');
$this->DiscussionID = $this->Discussion->DiscussionID;
$this->Form->AddHidden('DiscussionID', $this->DiscussionID);
$this->Form->AddHidden('CommentID', '');
// Retrieve & apply the draft if there is one:
$DraftModel = new DraftModel();
$Draft = $DraftModel->Get($Session->UserID, 0, 1, $this->Discussion->DiscussionID)->FirstRow();
$this->Form->AddHidden('DraftID', $Draft ? $Draft->DraftID : '');
if ($Draft) {
$this->Form->SetFormValue('Body', $Draft->Body);
}
// Deliver json data if necessary
if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
$this->SetJson('LessRow', $this->Pager->ToString('less'));
$this->SetJson('MoreRow', $this->Pager->ToString('more'));
$this->View = 'comments';
//.........这里部分代码省略.........
示例7: Comment
public function Comment($CommentID)
{
// Get the discussionID
$Comment = $this->CommentModel->GetID($CommentID);
if (!$Comment) {
Redirect('dashboard/home/filenotfound');
}
$DiscussionID = $Comment->DiscussionID;
// Figure out how many comments are before this one
$Offset = $this->CommentModel->GetOffset($Comment);
$Limit = Gdn::Config('Vanilla.Comments.PerPage', 50);
// (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60;
//$Offset = floor($Offset / $Limit) * $Limit;
$PageNumber = PageNumber($Offset, $Limit, TRUE);
$this->View = 'index';
$this->Index($DiscussionID, 'x', $PageNumber);
}
示例8: RemovePageCache
public function RemovePageCache($DiscussionID, $From = 1)
{
if (!Gdn::Cache()->ActiveEnabled()) {
return;
}
$CountComments = $this->SQL->GetWhere('Discussion', array('DiscussionID' => $DiscussionID))->Value('CountComments');
$PageCount = PageNumber($CountComments - 1, C('Vanilla.Comments.PerPage', 30));
for ($Page = $From; $Page <= $PageCount; $Page++) {
$CacheKey = "Comment.Page.{$DiscussionID}.{$Page}";
Gdn::Cache()->Remove($CacheKey);
}
}
示例9: toStringPrevNext
/**
*
*
* @param string $Type
* @return string
*/
public function toStringPrevNext($Type = 'more')
{
$this->CssClass = ConcatSep(' ', $this->CssClass, 'PrevNextPager');
$CurrentPage = PageNumber($this->Offset, $this->Limit);
$Pager = '';
if ($CurrentPage > 1) {
$PageParam = 'p' . ($CurrentPage - 1);
$Pager .= anchor(t('Previous'), $this->PageUrl($CurrentPage - 1), 'Previous', array('rel' => 'prev'));
}
$HasNext = true;
if ($this->CurrentRecords !== false && $this->CurrentRecords < $this->Limit) {
$HasNext = false;
}
if ($HasNext) {
$PageParam = 'p' . ($CurrentPage + 1);
$Pager = ConcatSep(' ', $Pager, anchor(t('Next'), $this->PageUrl($CurrentPage + 1), 'Next', array('rel' => 'next')));
}
$ClientID = $this->ClientID;
$ClientID = $Type == 'more' ? $ClientID . 'After' : $ClientID . 'Before';
if (isset($this->HtmlBefore)) {
$Pager = $this->HtmlBefore . $Pager;
}
return $Pager == '' ? '' : sprintf($this->Wrapper, Attribute(array('id' => $ClientID, 'class' => $this->CssClass)), $Pager);
}
示例10: 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.autogrow.js');
$this->RemoveJsFile('autosave.js');
$this->AddJsFile('discussion.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);
} else {
if ($vanilla_identifier != '' && $vanilla_type != '') {
$Discussion = $this->DiscussionModel->GetForeignID($vanilla_identifier, $vanilla_type);
}
}
// Set discussion data if we have one for this page
if ($Discussion) {
$this->Permission('Vanilla.Discussions.View', TRUE, '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;
}
} else {
if ($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) {
//.........这里部分代码省略.........
示例11: ToStringPrevNext
public function ToStringPrevNext($Type = 'more')
{
$this->CssClass = ConcatSep(' ', $this->CssClass, 'PrevNextPager');
$CurrentPage = PageNumber($this->Offset, $this->Limit);
$Pager = '';
if ($CurrentPage > 1) {
$PageParam = 'p' . ($CurrentPage - 1);
$Pager .= Anchor(T('Previous'), self::FormatUrl($this->Url, $PageParam), 'Previous');
}
$HasNext = TRUE;
if ($this->CurrentRecords !== FALSE && $this->CurrentRecords < $this->Limit) {
$HasNext = FALSE;
}
if ($HasNext) {
$PageParam = 'p' . ($CurrentPage + 1);
$Pager = ConcatSep(' ', $Pager, Anchor('Next', self::FormatUrl($this->Url, $PageParam), 'Next'));
}
$ClientID = $this->ClientID;
$ClientID = $Type == 'more' ? $ClientID . 'After' : $ClientID . 'Before';
if (isset($this->HtmlBefore)) {
$Pager = $this->HtmlBefore . $Pager;
}
return $Pager == '' ? '' : sprintf($this->Wrapper, Attribute(array('id' => $ClientID, 'class' => $this->CssClass)), $Pager);
}
示例12: PageNumber
/**
* Return the page number from the given variables that may have an offset or a page.
*
* @param array $Vars The variables that should contain an Offset or Page key.
* @param int|string $PageSize The pagesize or the config key of the pagesize.
* @return int
*/
public static function PageNumber($Vars, $PageSize)
{
if (isset($Vars['Page'])) {
return $Vars['Page'];
}
if (isset($Vars['Offset'])) {
if (is_numeric($PageSize)) {
return PageNumber($Vars['Offset'], $PageSize, FALSE, Gdn::Session()->IsValid());
} else {
return PageNumber($Vars['Offset'], C($PageSize, 30), FALSE, Gdn::Session()->IsValid());
}
}
return 1;
}
示例13: DiscussionsController_Popular_Create
/**
* Load popular discussions.
*/
public function DiscussionsController_Popular_Create($Sender)
{
$Sender->Title(T('Popular'));
// Get rid of announcements from this view
if ($Sender->Head) {
$Sender->AddJsFile('discussions.js');
$Sender->Head->AddRss($Sender->SelfUrl . '/feed.rss', $Sender->Head->Title());
}
// Add Modules
$Sender->AddModule('DiscussionFilterModule');
$Sender->AddModule('NewDiscussionModule');
$Sender->AddModule('CategoriesModule');
$Sender->AddModule('BookmarkedModule');
// Determine offset from $Page
$Page = GetValue('0', $Sender->RequestArgs, 'p1');
list($Offset, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30));
if (!is_numeric($Offset) || $Offset < 0) {
$Offset = 0;
}
$Page = PageNumber($Offset, $Limit);
$Sender->SetData('Category', FALSE, TRUE);
$Limit = C('Vanilla.Discussions.PerPage', 30);
$DiscussionModel = new DiscussionModel();
$CountDiscussions = $DiscussionModel->GetCount();
$Sender->SetData('CountDiscussions', $CountDiscussions);
$Sender->AnnounceData = FALSE;
$Sender->SetData('Announcements', array(), TRUE);
$DiscussionModel->SQL->OrderBy('d.Score', 'desc');
$DiscussionModel->SQL->OrderBy('d.CountViews', 'desc');
$Sender->DiscussionData = $DiscussionModel->Get($Offset, $Limit);
$Sender->SetData('Discussions', $Sender->DiscussionData, TRUE);
$Sender->SetJson('Loading', $Offset . ' to ' . $Limit);
// Build a pager.
$PagerFactory = new Gdn_PagerFactory();
$Sender->Pager = $PagerFactory->GetPager('Pager', $Sender);
$Sender->Pager->ClientID = 'Pager';
$Sender->Pager->Configure($Offset, $Limit, $CountDiscussions, 'discussions/popular/%1$s');
if (!$Sender->Data('_PagerUrl')) {
$Sender->SetData('_PagerUrl', 'discussions/popular/{Page}');
}
$Sender->SetData('_Page', $Page);
$Sender->SetData('_Limit', $Limit);
// Deliver json data if necessary
if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL) {
$Sender->SetJson('LessRow', $Sender->Pager->ToString('less'));
$Sender->SetJson('MoreRow', $Sender->Pager->ToString('more'));
$Sender->View = 'discussions';
}
// Render the controller
$Sender->View = 'index';
$Sender->Render();
}
示例14: DiscussionsController_Tagged_Create
/**
* Load discussions for a specific tag.
*/
public function DiscussionsController_Tagged_Create($Sender)
{
Gdn_Theme::Section('DiscussionList');
if ($Sender->Request->Get('Tag')) {
$Tag = $Sender->Request->Get('Tag');
$Page = GetValue('0', $Sender->RequestArgs, 'p1');
} else {
$Tag = urldecode(GetValue('0', $Sender->RequestArgs, ''));
$Page = GetValue('1', $Sender->RequestArgs, 'p1');
}
if ($Sender->Request->Get('Page')) {
$Page = $Sender->Request->Get('Page');
}
$Tag = StringEndsWith($Tag, '.rss', TRUE, TRUE);
list($Offset, $Limit) = OffsetLimit($Page, C('Vanilla.Discussions.PerPage', 30));
$Sender->SetData('Tag', $Tag, TRUE);
$Sender->Title(T('Tagged with ') . htmlspecialchars($Tag));
$Sender->Head->Title($Sender->Head->Title());
$UrlTag = rawurlencode($Tag);
if (urlencode($Tag) == $Tag) {
$Sender->CanonicalUrl(Url(ConcatSep('/', "/discussions/tagged/{$UrlTag}", PageNumber($Offset, $Limit, TRUE)), TRUE));
$FeedUrl = Url(ConcatSep('/', "/discussions/tagged/{$UrlTag}/feed.rss", PageNumber($Offset, $Limit, TRUE, FALSE)), '//');
} else {
$Sender->CanonicalUrl(Url(ConcatSep('/', 'discussions/tagged', PageNumber($Offset, $Limit, TRUE)) . '?Tag=' . $UrlTag, TRUE));
$FeedUrl = Url(ConcatSep('/', 'discussions/tagged', PageNumber($Offset, $Limit, TRUE, FALSE), 'feed.rss') . '?Tag=' . $UrlTag, '//');
}
if ($Sender->Head) {
$Sender->AddJsFile('discussions.js');
$Sender->Head->AddRss($FeedUrl, $Sender->Head->Title());
}
if (!is_numeric($Offset) || $Offset < 0) {
$Offset = 0;
}
// Add Modules
$Sender->AddModule('NewDiscussionModule');
$Sender->AddModule('DiscussionFilterModule');
$BookmarkedModule = new BookmarkedModule($Sender);
$BookmarkedModule->GetData();
$Sender->AddModule($BookmarkedModule);
$Sender->SetData('Category', FALSE, TRUE);
$Sender->SetData('CountDiscussions', FALSE);
$Sender->AnnounceData = FALSE;
$Sender->SetData('Announcements', array(), TRUE);
$DiscussionModel = new DiscussionModel();
$this->_SetTagSql($DiscussionModel->SQL, $Tag, $Limit, $Offset, $Sender->Request->Get('op', 'or'));
$Sender->DiscussionData = $DiscussionModel->Get($Offset, $Limit, array('Announce' => 'all'));
$Sender->SetData('Discussions', $Sender->DiscussionData, TRUE);
$Sender->SetJson('Loading', $Offset . ' to ' . $Limit);
// Build a pager.
$PagerFactory = new Gdn_PagerFactory();
$Sender->Pager = $PagerFactory->GetPager('Pager', $Sender);
$Sender->Pager->ClientID = 'Pager';
if (urlencode($Sender->Tag) == $Sender->Tag) {
$PageUrlFormat = "discussions/tagged/{$Sender->Tag}/{Page}";
} else {
$PageUrlFormat = 'discussions/tagged/{Page}?Tag=' . urlencode($Sender->Tag);
}
$Sender->Pager->Configure($Offset, $Limit, FALSE, $PageUrlFormat);
// Deliver json data if necessary.
if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL) {
$Sender->SetJson('LessRow', $Sender->Pager->ToString('less'));
$Sender->SetJson('MoreRow', $Sender->Pager->ToString('more'));
$Sender->View = 'discussions';
}
// Render the controller
$Sender->Render('TaggedDiscussions', '', 'plugins/Tagging');
}
示例15: discussionsController_tagged_create
/**
* Load discussions for a specific tag.
*
* @param DiscussionsController $Sender Sending controller instance
* @param array $Args Event's arguments
* @throws Exception
*/
public function discussionsController_tagged_create($Sender, $Args)
{
Gdn_Theme::section('DiscussionList');
$Args = $Sender->RequestArgs;
$Get = array_change_key_case($Sender->Request->get());
if ($UseCategories = c('Plugins.Tagging.UseCategories')) {
// The url is in the form /category/tag/p1
$CategoryCode = val(0, $Args);
$Tag = val(1, $Args);
$Page = val(2, $Args);
} else {
// The url is in the form /tag/p1
$CategoryCode = '';
$Tag = val(0, $Args);
$Page = val(1, $Args);
}
// Look for explcit values.
$CategoryCode = val('category', $Get, $CategoryCode);
$Tag = val('tag', $Get, $Tag);
$Page = val('page', $Get, $Page);
$Category = CategoryModel::categories($CategoryCode);
$Tag = stringEndsWith($Tag, '.rss', true, true);
list($Offset, $Limit) = offsetLimit($Page, c('Vanilla.Discussions.PerPage', 30));
$MultipleTags = strpos($Tag, ',') !== false;
$Sender->setData('Tag', $Tag, true);
$TagModel = TagModel::instance();
$RecordCount = false;
if (!$MultipleTags) {
$Tags = $TagModel->getWhere(array('Name' => $Tag))->resultArray();
if (count($Tags) == 0) {
throw notFoundException('Page');
}
if (count($Tags) > 1) {
foreach ($Tags as $TagRow) {
if ($TagRow['CategoryID'] == val('CategoryID', $Category)) {
break;
}
}
} else {
$TagRow = array_pop($Tags);
}
$Tags = $TagModel->getRelatedTags($TagRow);
$RecordCount = $TagRow['CountDiscussions'];
$Sender->setData('CountDiscussions', $RecordCount);
$Sender->setData('Tags', $Tags);
$Sender->setData('Tag', $TagRow);
$ChildTags = $TagModel->getChildTags($TagRow['TagID']);
$Sender->setData('ChildTags', $ChildTags);
}
$Sender->title(htmlspecialchars($TagRow['FullName']));
$UrlTag = empty($CategoryCode) ? rawurlencode($Tag) : rawurlencode($CategoryCode) . '/' . rawurlencode($Tag);
if (urlencode($Tag) == $Tag) {
$Sender->canonicalUrl(url(ConcatSep('/', "/discussions/tagged/{$UrlTag}", PageNumber($Offset, $Limit, true)), true));
$FeedUrl = url(ConcatSep('/', "/discussions/tagged/{$UrlTag}/feed.rss", PageNumber($Offset, $Limit, true, false)), '//');
} else {
$Sender->canonicalUrl(url(ConcatSep('/', 'discussions/tagged', PageNumber($Offset, $Limit, true)) . '?Tag=' . $UrlTag, true));
$FeedUrl = url(ConcatSep('/', 'discussions/tagged', PageNumber($Offset, $Limit, true, false), 'feed.rss') . '?Tag=' . $UrlTag, '//');
}
if ($Sender->Head) {
$Sender->addJsFile('discussions.js');
$Sender->Head->addRss($FeedUrl, $Sender->Head->title());
}
if (!is_numeric($Offset) || $Offset < 0) {
$Offset = 0;
}
// Add Modules
$Sender->addModule('NewDiscussionModule');
$Sender->addModule('DiscussionFilterModule');
$Sender->addModule('BookmarkedModule');
$Sender->setData('Category', false, true);
$Sender->AnnounceData = false;
$Sender->setData('Announcements', array(), true);
$DiscussionModel = new DiscussionModel();
$TagModel->setTagSql($DiscussionModel->SQL, $Tag, $Limit, $Offset, $Sender->Request->get('op', 'or'));
$Sender->DiscussionData = $DiscussionModel->get($Offset, $Limit, array('Announce' => 'all'));
$Sender->setData('Discussions', $Sender->DiscussionData, true);
$Sender->setJson('Loading', $Offset . ' to ' . $Limit);
// Build a pager.
$PagerFactory = new Gdn_PagerFactory();
$Sender->EventArguments['PagerType'] = 'Pager';
$Sender->fireEvent('BeforeBuildPager');
if (!$Sender->data('_PagerUrl')) {
$Sender->setData('_PagerUrl', "/discussions/tagged/{$UrlTag}/{Page}");
}
$Sender->Pager = $PagerFactory->GetPager($Sender->EventArguments['PagerType'], $Sender);
$Sender->Pager->ClientID = 'Pager';
$Sender->Pager->configure($Offset, $Limit, $RecordCount, $Sender->data('_PagerUrl'));
$Sender->setData('_Page', $Page);
$Sender->setData('_Limit', $Limit);
$Sender->fireEvent('AfterBuildPager');
$Sender->View = c('Vanilla.Discussions.Layout');
// Render the controller.
$this->View = c('Vanilla.Discussions.Layout') == 'table' && $Sender->SyndicationMethod == SYNDICATION_NONE ? 'table' : 'index';
//.........这里部分代码省略.........