本文整理汇总了PHP中offsetLimit函数的典型用法代码示例。如果您正苦于以下问题:PHP offsetLimit函数的具体用法?PHP offsetLimit怎么用?PHP offsetLimit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了offsetLimit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* User management list.
*
* @since 2.0.0
* @access public
* @param mixed $Keywords Term or array of terms to filter list of users.
* @param int $Page Page number.
* @param string $Order Sort order for list.
*/
public function index($Keywords = '', $Page = '', $Order = '')
{
$this->permission(array('Garden.Users.Add', 'Garden.Users.Edit', 'Garden.Users.Delete'), '', false);
// Page setup
$this->addJsFile('jquery.gardenmorepager.js');
$this->addJsFile('user.js');
$this->title(t('Users'));
$this->addSideMenu('dashboard/user');
// Form setup
$this->Form->Method = 'get';
// Input Validation.
list($Offset, $Limit) = offsetLimit($Page, PagerModule::$DefaultPageSize);
if (!$Keywords) {
$Keywords = $this->Form->getFormValue('Keywords');
if ($Keywords) {
$Offset = 0;
}
}
if (!is_string($Keywords)) {
$Keywords = '';
}
// Put the Keyword back in the form
if ($Keywords) {
$this->Form->setFormValue('Keywords', $Keywords);
}
$UserModel = new UserModel();
//$Like = trim($Keywords) == '' ? FALSE : array('u.Name' => $Keywords, 'u.Email' => $Keywords);
list($Offset, $Limit) = offsetLimit($Page, 30);
$Filter = $this->_GetFilter();
if ($Filter) {
$Filter['Keywords'] = $Keywords;
} else {
$Filter = array('Keywords' => (string) $Keywords);
}
$Filter['Optimize'] = $this->PastUserThreshold();
// Sorting
if (in_array($Order, array('DateInserted', 'DateFirstVisit', 'DateLastActive'))) {
$Order = 'u.' . $Order;
$OrderDir = 'desc';
} else {
$Order = 'u.Name';
$OrderDir = 'asc';
}
// Get user list
$this->UserData = $UserModel->Search($Filter, $Order, $OrderDir, $Limit, $Offset);
$this->setData('Users', $this->UserData);
if ($this->PastUserThreshold()) {
$this->setData('_CurrentRecords', $this->UserData->count());
} else {
$this->setData('RecordCount', $UserModel->SearchCount($Filter));
}
RoleModel::SetUserRoles($this->UserData->result());
// Deliver json data if necessary
if ($this->_DeliveryType != DELIVERY_TYPE_ALL && $this->_DeliveryMethod == DELIVERY_METHOD_XHTML) {
$this->setJson('LessRow', $this->Pager->toString('less'));
$this->setJson('MoreRow', $this->Pager->toString('more'));
$this->View = 'users';
}
$this->render();
}
示例2: index
/**
* Default search functionality.
*
* @since 2.0.0
* @access public
* @param int $Page Page number.
*/
public function index($Page = '')
{
$this->addJsFile('search.js');
$this->title(t('Search'));
saveToConfig('Garden.Format.EmbedSize', '160x90', false);
Gdn_Theme::section('SearchResults');
list($Offset, $Limit) = offsetLimit($Page, c('Garden.Search.PerPage', 20));
$this->setData('_Limit', $Limit);
$Search = $this->Form->getFormValue('Search');
$Mode = $this->Form->getFormValue('Mode');
if ($Mode) {
$this->SearchModel->ForceSearchMode = $Mode;
}
try {
$ResultSet = $this->SearchModel->Search($Search, $Offset, $Limit);
} catch (Gdn_UserException $Ex) {
$this->Form->addError($Ex);
$ResultSet = array();
} catch (Exception $Ex) {
LogException($Ex);
$this->Form->addError($Ex);
$ResultSet = array();
}
Gdn::userModel()->joinUsers($ResultSet, array('UserID'));
// Fix up the summaries.
$SearchTerms = explode(' ', Gdn_Format::text($Search));
foreach ($ResultSet as &$Row) {
$Row['Summary'] = SearchExcerpt(Gdn_Format::plainText($Row['Summary'], $Row['Format']), $SearchTerms);
$Row['Summary'] = Emoji::instance()->translateToHtml($Row['Summary']);
$Row['Format'] = 'Html';
}
$this->setData('SearchResults', $ResultSet, true);
$this->setData('SearchTerm', Gdn_Format::text($Search), true);
if ($ResultSet) {
$NumResults = count($ResultSet);
} else {
$NumResults = 0;
}
if ($NumResults == $Offset + $Limit) {
$NumResults++;
}
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$this->Pager = $PagerFactory->GetPager('MorePager', $this);
$this->Pager->MoreCode = 'More Results';
$this->Pager->LessCode = 'Previous Results';
$this->Pager->ClientID = 'Pager';
$this->Pager->configure($Offset, $Limit, $NumResults, 'dashboard/search/%1$s/%2$s/?Search=' . Gdn_Format::url($Search));
// if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
// $this->setJson('LessRow', $this->Pager->toString('less'));
// $this->setJson('MoreRow', $this->Pager->toString('more'));
// $this->View = 'results';
// }
$this->canonicalUrl(url('search', true));
$this->render();
}
示例3: index
/**
* Default search functionality.
*
* @since 2.0.0
* @access public
* @param int $Page Page number.
*/
public function index($Page = '')
{
$this->addJsFile('search.js');
$this->title(t('Search'));
saveToConfig('Garden.Format.EmbedSize', '160x90', false);
Gdn_Theme::section('SearchResults');
list($Offset, $Limit) = offsetLimit($Page, c('Garden.Search.PerPage', 20));
$this->setData('_Limit', $Limit);
$Search = $this->Form->getFormValue('Search');
$Mode = $this->Form->getFormValue('Mode');
if ($Mode) {
$this->SearchModel->ForceSearchMode = $Mode;
}
try {
$ResultSet = $this->SearchModel->search($Search, $Offset, $Limit);
} catch (Gdn_UserException $Ex) {
$this->Form->addError($Ex);
$ResultSet = array();
} catch (Exception $Ex) {
LogException($Ex);
$this->Form->addError($Ex);
$ResultSet = array();
}
Gdn::userModel()->joinUsers($ResultSet, array('UserID'));
// Fix up the summaries.
$SearchTerms = explode(' ', Gdn_Format::text($Search));
foreach ($ResultSet as &$Row) {
$Row['Summary'] = searchExcerpt(htmlspecialchars(Gdn_Format::plainText($Row['Summary'], $Row['Format'])), $SearchTerms);
$Row['Summary'] = Emoji::instance()->translateToHtml($Row['Summary']);
$Row['Format'] = 'Html';
}
$this->setData('SearchResults', $ResultSet, true);
$this->setData('SearchTerm', Gdn_Format::text($Search), true);
$this->setData('_CurrentRecords', count($ResultSet));
$this->canonicalUrl(url('search', true));
$this->render();
}
示例4: write
/**
*
*
* @param array $Options
* @throws Exception
*/
public static function write($Options = array())
{
static $WriteCount = 0;
if (!self::$_CurrentPager) {
if (is_a($Options, 'Gdn_Controller')) {
self::$_CurrentPager = new PagerModule($Options);
$Options = array();
} else {
self::$_CurrentPager = new PagerModule(val('Sender', $Options, Gdn::controller()));
}
}
$Pager = self::$_CurrentPager;
$Pager->Wrapper = val('Wrapper', $Options, $Pager->Wrapper);
$Pager->MoreCode = val('MoreCode', $Options, $Pager->MoreCode);
$Pager->LessCode = val('LessCode', $Options, $Pager->LessCode);
$Pager->ClientID = val('ClientID', $Options, $Pager->ClientID);
$Pager->Limit = val('Limit', $Options, $Pager->Controller()->data('_Limit', $Pager->Limit));
$Pager->HtmlBefore = val('HtmlBefore', $Options, val('HtmlBefore', $Pager, ''));
$Pager->CurrentRecords = val('CurrentRecords', $Options, $Pager->Controller()->data('_CurrentRecords', $Pager->CurrentRecords));
// Try and figure out the offset based on the parameters coming in to the controller.
if (!$Pager->Offset) {
$Page = $Pager->Controller()->Request->get('Page', false);
if (!$Page) {
$Page = 'p1';
foreach ($Pager->Controller()->RequestArgs as $Arg) {
if (preg_match('`p\\d+`', $Arg)) {
$Page = $Arg;
break;
}
}
}
list($Offset, $Limit) = offsetLimit($Page, $Pager->Limit);
$TotalRecords = val('RecordCount', $Options, $Pager->Controller()->data('RecordCount', false));
$Get = $Pager->Controller()->Request->get();
unset($Get['Page'], $Get['DeliveryType'], $Get['DeliveryMethod']);
$Url = val('Url', $Options, $Pager->Controller()->SelfUrl . '?Page={Page}&' . http_build_query($Get));
$Pager->configure($Offset, $Limit, $TotalRecords, $Url);
} elseif ($Url = val('Url', $Options)) {
$Pager->Url = $Url;
}
echo $Pager->toString($WriteCount > 0 ? 'more' : 'less');
$WriteCount++;
// list($Offset, $Limit) = offsetLimit(GetValue, 20);
// $Pager->configure(
// $Offset,
// $Limit,
// $TotalAddons,
// "/settings/addons/$Section?Page={Page}"
// );
// $Sender->setData('_Pager', $Pager);
}
示例5: bans
/**
* Manage user bans (add, edit, delete, list).
*
* @since 2.0.18
* @access public
* @param string $Action Add, edit, delete, or none.
* @param string $Search Term to filter ban list by.
* @param int $Page Page number.
* @param int $ID Ban ID we're editing or deleting.
*/
public function bans($Action = '', $Search = '', $Page = '', $ID = '')
{
$this->permission('Garden.Settings.Manage');
// Page setup
$this->addSideMenu();
$this->title(t('Banning Options'));
$this->addJsFile('bans.js');
list($Offset, $Limit) = offsetLimit($Page, 20);
$BanModel = new BanModel();
$this->_BanModel = $BanModel;
switch (strtolower($Action)) {
case 'add':
case 'edit':
$this->Form->setModel($BanModel);
if ($this->Form->authenticatedPostBack()) {
if ($ID) {
$this->Form->setFormValue('BanID', $ID);
}
try {
// Save the ban.
$NewID = $this->Form->save();
} catch (Exception $Ex) {
$this->Form->addError($Ex);
}
} else {
if ($ID) {
$this->Form->setData($BanModel->getID($ID));
}
}
$this->setData('_BanTypes', array('IPAddress' => t('IP Address'), 'Email' => t('Email'), 'Name' => t('Name')));
$this->View = 'Ban';
break;
case 'delete':
if ($this->Form->authenticatedPostBack()) {
$BanModel->delete(array('BanID' => $ID));
$this->View = 'BanDelete';
}
break;
default:
$Bans = $BanModel->getWhere(array(), 'BanType, BanValue', 'asc', $Limit, $Offset)->resultArray();
$this->setData('Bans', $Bans);
break;
}
$this->render();
}
示例6: 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;
}
//.........这里部分代码省略.........
示例7: index
/**
* User management list.
*
* @since 2.0.0
* @access public
* @param mixed $Keywords Term or array of terms to filter list of users.
* @param int $Page Page number.
* @param string $Order Sort order for list.
*/
public function index($Keywords = '', $Page = '', $Order = '')
{
$this->permission(array('Garden.Users.Add', 'Garden.Users.Edit', 'Garden.Users.Delete'), '', false);
// Page setup
$this->addJsFile('jquery.gardenmorepager.js');
$this->addJsFile('user.js');
$this->title(t('Users'));
$this->setHighlightRoute('dashboard/user');
Gdn_Theme::section('Moderation');
// Form setup
$this->Form->Method = 'get';
// Input Validation.
list($Offset, $Limit) = offsetLimit($Page, PagerModule::$DefaultPageSize);
if (!$Keywords) {
$Keywords = $this->Form->getFormValue('Keywords');
if ($Keywords) {
$Offset = 0;
}
}
if (!is_string($Keywords)) {
$Keywords = '';
}
// Put the Keyword back in the form
if ($Keywords) {
$this->Form->setFormValue('Keywords', $Keywords);
}
$UserModel = new UserModel();
list($Offset, $Limit) = offsetLimit($Page, 30);
// Determine our data filters.
$Filter = $this->_getFilter();
if ($Filter) {
$Filter['Keywords'] = $Keywords;
} else {
$Filter = array('Keywords' => (string) $Keywords);
}
$Filter['Optimize'] = Gdn::userModel()->pastUserThreshold();
// Sorting
if (in_array($Order, array('DateInserted', 'DateFirstVisit', 'DateLastActive'))) {
$Order = 'u.' . $Order;
$OrderDir = 'desc';
} else {
$Order = 'u.Name';
$OrderDir = 'asc';
}
// Get user list
$this->UserData = $UserModel->search($Filter, $Order, $OrderDir, $Limit, $Offset);
$this->setData('Users', $this->UserData);
// Figure out our number of results and users.
$showUserCount = $this->UserData->count();
if (!Gdn::userModel()->pastUserThreshold()) {
// Pfft, query that sucker however you want.
$this->setData('RecordCount', $UserModel->searchCount($Filter));
} else {
// We have a user search, so at least set enough data for the Next pager.
if ($showUserCount) {
$this->setData('_CurrentRecords', $showUserCount);
} else {
// No search was done. Just give the total users overall. First, zero-out our pager.
$this->setData('_CurrentRecords', 0);
if (!Gdn::userModel()->pastUserMegaThreshold()) {
// Restoring this semi-optimized counter is our compromise to let non-mega sites know their exact total users.
$this->setData('UserCount', $UserModel->getCount());
} else {
// Dang, yo. Get a table status guess instead of really counting.
$this->setData('UserEstimate', Gdn::userModel()->countEstimate());
}
}
}
// Add roles to the user data.
RoleModel::setUserRoles($this->UserData->result());
// Deliver json data if necessary
if ($this->_DeliveryType != DELIVERY_TYPE_ALL && $this->_DeliveryMethod == DELIVERY_METHOD_XHTML) {
$this->setJson('LessRow', $this->Pager->toString('less'));
$this->setJson('MoreRow', $this->Pager->toString('more'));
$this->View = 'users';
}
$this->render();
}
示例8: spam
/**
* View spam logs.
*
* @since 2.0.?
* @access public
*
* @param int $Page Page number.
*/
public function spam($Page = '')
{
$this->permission(array('Garden.Moderation.Manage', 'Moderation.Spam.Manage'), false);
list($Offset, $Limit) = offsetLimit($Page, 10);
$this->setData('Title', t('Spam Queue'));
$Where = array('Operation' => array('Spam'));
$RecordCount = $this->LogModel->getCountWhere($Where);
$this->setData('RecordCount', $RecordCount);
if ($Offset >= $RecordCount) {
$Offset = $RecordCount - $Limit;
}
$Log = $this->LogModel->getWhere($Where, 'LogID', 'Desc', $Offset, $Limit);
$this->setData('Log', $Log);
if ($this->deliveryType() == DELIVERY_TYPE_VIEW) {
$this->View = 'Table';
}
$this->addSideMenu('dashboard/log/spam');
$this->render();
}
示例9: discussionsController_unresolved_create
/**
* Discussions filter: Unresolved.
*
* @return void
*/
public function discussionsController_unresolved_create($sender, $args)
{
$sender->permission('Plugins.Resolved.Manage');
$page = val(0, $args, 0);
// Determine offset from $Page
list($page, $limit) = offsetLimit($page, C('Vanilla.Discussions.PerPage', 30));
// Validate $Page
if (!is_numeric($page) || $page < 0) {
$page = 0;
}
$discussionModel = new DiscussionModel();
$wheres = array('d.Resolved' => '0');
// Hack in our wheregroup.
Gdn::sql()->beginWhereGroup()->whereNotIn('d.Type', array('page', 'Report', 'poll', 'SimplePage'))->orWhere('d.Type is null')->endWhereGroup();
$sender->DiscussionData = $discussionModel->Get($page, $limit, $wheres);
$sender->setData('Discussions', $sender->DiscussionData);
$countDiscussions = $discussionModel->GetCount($wheres);
$sender->setData('CountDiscussions', $countDiscussions);
$sender->Category = false;
$sender->setJson('Loading', $page . ' to ' . $limit);
// Build a pager
$pagerFactory = new Gdn_PagerFactory();
$sender->EventArguments['PagerType'] = 'Pager';
$sender->fireEvent('BeforeBuildBookmarkedPager');
$sender->Pager = $pagerFactory->getPager($sender->EventArguments['PagerType'], $sender);
$sender->Pager->ClientID = 'Pager';
$sender->Pager->configure($page, $limit, $countDiscussions, 'discussions/unresolved/%1$s');
if (!$sender->data('_PagerUrl')) {
$sender->setData('_PagerUrl', 'discussions/unresolved/{Page}');
}
$sender->setData('_Page', $page);
$sender->setData('_Limit', $limit);
$sender->fireEvent('AfterBuildBookmarkedPager');
// 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';
}
// Add modules
$sender->addModule('DiscussionFilterModule');
$sender->addModule('NewDiscussionModule');
$sender->addModule('CategoriesModule');
// Render default view
$sender->setData('Title', T('Unresolved'));
$sender->setData('Breadcrumbs', array(array('Name' => T('Unresolved'), 'Url' => '/discussions/unresolved')));
$sender->render('index');
}
示例10: mine
/**
* Display discussions started by the user.
*
* @since 2.0.0
* @access public
*
* @param int $Offset Number of discussions to skip.
*/
public function mine($Page = 'p1')
{
$this->permission('Garden.SignIn.Allow');
Gdn_Theme::section('DiscussionList');
// Set criteria & get discussions data
list($Offset, $Limit) = offsetLimit($Page, c('Vanilla.Discussions.PerPage', 30));
$Session = Gdn::session();
$Wheres = array('d.InsertUserID' => $Session->UserID);
$DiscussionModel = new DiscussionModel();
$this->DiscussionData = $DiscussionModel->get($Offset, $Limit, $Wheres);
$this->setData('Discussions', $this->DiscussionData);
$CountDiscussions = $this->setData('CountDiscussions', $DiscussionModel->getCount($Wheres));
$this->View = 'index';
if (c('Vanilla.Discussions.Layout') === 'table') {
$this->View = 'table';
}
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$this->EventArguments['PagerType'] = 'MorePager';
$this->fireEvent('BeforeBuildMinePager');
$this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this);
$this->Pager->MoreCode = 'More Discussions';
$this->Pager->LessCode = 'Newer Discussions';
$this->Pager->ClientID = 'Pager';
$this->Pager->configure($Offset, $Limit, $CountDiscussions, 'discussions/mine/%1$s');
$this->setData('_PagerUrl', 'discussions/mine/{Page}');
$this->setData('_Page', $Page);
$this->setData('_Limit', $Limit);
$this->fireEvent('AfterBuildMinePager');
// 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';
}
// Add modules
$this->addModule('DiscussionFilterModule');
$this->addModule('NewDiscussionModule');
$this->addModule('CategoriesModule');
$this->addModule('BookmarkedModule');
// Render view
$this->setData('Title', t('My Discussions'));
$this->setData('Breadcrumbs', array(array('Name' => t('My Discussions'), 'Url' => '/discussions/mine')));
$this->render();
}
示例11: categories
/**
* Manage the category hierarchy.
*
* @param string $parent The URL slug of a parent category if looking at a sub tree.
*/
public function categories($parent = '')
{
$this->permission(['Garden.Community.Manage', 'Garden.Settings.Manage'], false);
$this->setHighlightRoute('vanilla/settings/categories');
// Make sure we are reading the categories from the database only.
$collection = $this->CategoryModel->createCollection(Gdn::sql(), new Gdn_Dirtycache());
$allowSorting = true;
$usePagination = false;
$perPage = 30;
$page = Gdn::request()->get('Page', Gdn::request()->get('page', null));
list($offset, $limit) = offsetLimit($page, $perPage);
if (!empty($parent)) {
$categoryRow = $collection->get((string) $parent);
if (empty($categoryRow)) {
throw notFoundException('Category');
}
$this->setData('Category', $categoryRow);
$parentID = $categoryRow['CategoryID'];
$parentDisplayAs = val('DisplayAs', $categoryRow);
} else {
$parentID = -1;
$parentDisplayAs = CategoryModel::getRootDisplayAs();
}
if (in_array($parentDisplayAs, ['Flat'])) {
$allowSorting = false;
$usePagination = true;
}
if ($parentDisplayAs === 'Flat') {
$categories = $this->CategoryModel->getTreeAsFlat($parentID, $offset, $limit);
} else {
$categories = $collection->getTree($parentID, ['maxdepth' => 10, 'collapsecategories' => true]);
}
$this->setData('ParentID', $parentID);
$this->setData('Categories', $categories);
$this->setData('_Limit', $perPage);
$this->setData('_CurrentRecords', count($categories));
if ($parentID > 0) {
$ancestors = $collection->getAncestors($parentID, true);
$this->setData('Ancestors', $ancestors);
}
$this->setData('AllowSorting', $allowSorting);
$this->setData('UsePagination', $usePagination);
$this->addDefinition('AllowSorting', $allowSorting);
$this->addJsFile('category-settings.js');
$this->addJsFile('manage-categories.js');
$this->addJsFile('jquery.nestable.js');
require_once $this->fetchViewLocation('category-settings-functions');
$this->addAsset('Content', $this->fetchView('symbols'));
$this->render();
}
示例12: index
/**
* Default activity stream.
*
* @since 2.0.0
* @access public
*
* @param int $Offset Number of activity items to skip.
*/
public function index($Filter = false, $Page = false)
{
switch (strtolower($Filter)) {
case 'mods':
$this->title(t('Recent Moderator Activity'));
$this->permission('Garden.Moderation.Manage');
$NotifyUserID = ActivityModel::NOTIFY_MODS;
break;
case 'admins':
$this->title(t('Recent Admin Activity'));
$this->permission('Garden.Settings.Manage');
$NotifyUserID = ActivityModel::NOTIFY_ADMINS;
break;
case '':
case 'feed':
// rss feed
$Filter = 'public';
$this->title(t('Recent Activity'));
$this->permission('Garden.Activity.View');
$NotifyUserID = ActivityModel::NOTIFY_PUBLIC;
break;
default:
throw notFoundException();
}
// Which page to load
list($Offset, $Limit) = offsetLimit($Page, c('Garden.Activities.PerPage', 30));
$Offset = is_numeric($Offset) ? $Offset : 0;
if ($Offset < 0) {
$Offset = 0;
}
// Page meta.
$this->addJsFile('activity.js');
if ($this->Head) {
$this->Head->addRss(url('/activity/feed.rss', true), $this->Head->title());
}
// Comment submission
$Session = Gdn::session();
$Comment = $this->Form->getFormValue('Comment');
$Activities = $this->ActivityModel->getWhere(array('NotifyUserID' => $NotifyUserID), '', '', $Limit, $Offset)->resultArray();
$this->ActivityModel->joinComments($Activities);
$this->setData('Filter', strtolower($Filter));
$this->setData('Activities', $Activities);
$this->addModule('ActivityFilterModule');
$this->View = 'all';
$this->render();
}
示例13: index
//.........这里部分代码省略.........
}
Gdn_Theme::section('DiscussionList');
// Figure out which discussions layout to choose (Defined on "Homepage" settings page).
$Layout = c('Vanilla.Discussions.Layout');
switch ($Layout) {
case 'table':
if ($this->SyndicationMethod == SYNDICATION_NONE) {
$this->View = 'table';
}
break;
default:
// $this->View = 'index';
break;
}
// Load the subtree.
$Categories = CategoryModel::GetSubtree($CategoryIdentifier, false);
$this->setData('Categories', $Categories);
// Setup head
$this->Menu->highlightRoute('/discussions');
if ($this->Head) {
$this->addJsFile('discussions.js');
$this->Head->AddRss($this->SelfUrl . '/feed.rss', $this->Head->title());
}
// Set CategoryID
$CategoryID = val('CategoryID', $Category);
$this->setData('CategoryID', $CategoryID, true);
// Add modules
$this->addModule('NewDiscussionModule');
$this->addModule('DiscussionFilterModule');
$this->addModule('CategoriesModule');
$this->addModule('BookmarkedModule');
// Get a DiscussionModel
$DiscussionModel = new DiscussionModel();
$CategoryIDs = array($CategoryID);
if (c('Vanilla.ExpandCategories')) {
$CategoryIDs = array_merge($CategoryIDs, array_column($this->data('Categories'), 'CategoryID'));
}
$Wheres = array('d.CategoryID' => $CategoryIDs);
$this->setData('_ShowCategoryLink', count($CategoryIDs) > 1);
// Check permission
$this->permission('Vanilla.Discussions.View', true, 'Category', val('PermissionCategoryID', $Category));
// Set discussion meta data.
$this->EventArguments['PerPage'] = c('Vanilla.Discussions.PerPage', 30);
$this->fireEvent('BeforeGetDiscussions');
list($Offset, $Limit) = offsetLimit($Page, $this->EventArguments['PerPage']);
if (!is_numeric($Offset) || $Offset < 0) {
$Offset = 0;
}
$Page = PageNumber($Offset, $Limit);
// Allow page manipulation
$this->EventArguments['Page'] =& $Page;
$this->EventArguments['Offset'] =& $Offset;
$this->EventArguments['Limit'] =& $Limit;
$this->fireEvent('AfterPageCalculation');
// We want to limit the number of pages on large databases because requesting a super-high page can kill the db.
$MaxPages = c('Vanilla.Categories.MaxPages');
if ($MaxPages && $Page > $MaxPages) {
throw notFoundException();
}
$CountDiscussions = $DiscussionModel->getCount($Wheres);
if ($MaxPages && $MaxPages * $Limit < $CountDiscussions) {
$CountDiscussions = $MaxPages * $Limit;
}
$this->setData('CountDiscussions', $CountDiscussions);
$this->setData('_Limit', $Limit);
// We don't wan't child categories in announcements.
$Wheres['d.CategoryID'] = $CategoryID;
$AnnounceData = $Offset == 0 ? $DiscussionModel->GetAnnouncements($Wheres) : new Gdn_DataSet();
$this->setData('AnnounceData', $AnnounceData, true);
$Wheres['d.CategoryID'] = $CategoryIDs;
$this->DiscussionData = $this->setData('Discussions', $DiscussionModel->getWhere($Wheres, $Offset, $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($Offset, $Limit, $CountDiscussions, array('CategoryUrl'));
$this->Pager->Record = $Category;
PagerModule::Current($this->Pager);
$this->setData('_Page', $Page);
$this->setData('_Limit', $Limit);
$this->fireEvent('AfterBuildPager');
// Set the canonical Url.
$this->canonicalUrl(CategoryUrl($Category, PageNumber($Offset, $Limit)));
// Change the controller name so that it knows to grab the discussion views
$this->ControllerName = 'DiscussionsController';
// Pick up the discussions class
$this->CssClass = 'Discussions Category-' . GetValue('UrlCode', $Category);
// 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';
}
// Render default view.
$this->fireEvent('BeforeCategoriesRender');
$this->render();
}
}
示例14: browse
/**
* Filter the list of addons.
*
* @param string $FilterToType AddonModel::$TypesPlural and 'plugins,applications'.
* @param string $Sort Order addons by popularity or recency.
* @param string $Page Which page to display.
*/
public function browse($FilterToType = '', $Sort = '', $Page = '')
{
// Create a virtual type called 'apps' as a stand-in for both plugins & applications.
if ($FilterToType == 'apps') {
$FilterToType = 'plugins,applications';
}
// Implement user prefs
$Session = Gdn::session();
if ($Session->isValid()) {
if ($FilterToType != '') {
$Session->setPreference('Addons.FilterType', $FilterToType);
}
//if ($VanillaVersion != '') {
$Session->setPreference('Addons.FilterVanilla', '2');
//}
if ($Sort != '') {
$Session->setPreference('Addons.Sort', $Sort);
}
$FilterToType = $Session->getPreference('Addons.FilterType', 'all');
$VanillaVersion = $Session->getPreference('Addons.FilterVanilla', '2');
$Sort = $Session->getPreference('Addons.Sort', 'recent');
}
$allowedFilters = AddonModel::$TypesPlural + ['plugins,applications' => true];
if (!array_key_exists($FilterToType, $allowedFilters)) {
$FilterToType = 'all';
}
if ($Sort != 'popular') {
$Sort = 'recent';
}
if (!in_array($VanillaVersion, array('1', '2'))) {
$VanillaVersion = '2';
}
$this->Version = $VanillaVersion;
$this->Sort = $Sort;
$this->FilterChecked = 'checked';
$this->addJsFile('jquery.gardenmorepager.js');
$this->addJsFile('browse.js');
list($Offset, $Limit) = offsetLimit($Page, c('Garden.Search.PerPage', 20));
$this->Filter = $FilterToType;
if ($this->Filter == 'themes') {
$Title = 'Browse Themes';
} elseif ($this->Filter == 'plugins,applications') {
$Title = 'Browse Plugins & Applications';
} else {
$Title = 'Browse Addons';
}
$this->setData('Title', $Title);
$Search = GetIncomingValue('Keywords', '');
$this->buildBrowseWheres($Search);
$SortField = $Sort == 'recent' ? 'DateUpdated' : 'CountDownloads';
$ResultSet = $this->AddonModel->getWhere(false, $SortField, 'desc', $Limit, $Offset);
$this->setData('Addons', $ResultSet);
$this->buildBrowseWheres($Search);
$NumResults = $this->AddonModel->getCount(false);
$this->setData('TotalAddons', $NumResults);
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$Pager = $PagerFactory->getPager('Pager', $this);
$Pager->MoreCode = '›';
$Pager->LessCode = '‹';
$Pager->ClientID = 'Pager';
$Pager->configure($Offset, $Limit, $NumResults, 'addon/browse/' . $FilterToType . '/' . $Sort . '/%1$s/?Keywords=' . urlencode($Search));
$this->setData('_Pager', $Pager);
if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
$this->setJson('MoreRow', $Pager->toString('more'));
}
$this->addModule('AddonHelpModule');
$this->render();
}
示例15: bans
/**
* Manage user bans (add, edit, delete, list).
*
* @since 2.0.18
* @access public
* @param string $Action Add, edit, delete, or none.
* @param string $Search Term to filter ban list by.
* @param int $Page Page number.
* @param int $ID Ban ID we're editing or deleting.
*/
public function bans($Action = '', $Search = '', $Page = '', $ID = '')
{
$this->permission('Garden.Settings.Manage');
// Page setup
$this->title(t('Banning Options'));
list($Offset, $Limit) = offsetLimit($Page, 20);
$BanModel = $this->getBanModel();
switch (strtolower($Action)) {
case 'add':
case 'edit':
$this->Form->setModel($BanModel);
if ($this->Form->authenticatedPostBack()) {
if ($ID) {
$this->Form->setFormValue('BanID', $ID);
}
// Trim the ban value to avoid obvious mismatches.
$banValue = trim($this->Form->getFormValue('BanValue'));
$this->Form->setFormValue('BanValue', $banValue);
// We won't let you HAL 9000 the entire crew.
$crazyBans = ['*', '*@*', '*.*', '*.*.*', '*.*.*.*'];
if (in_array($banValue, $crazyBans)) {
$this->Form->addError("I'm sorry Dave, I'm afraid I can't do that.");
}
try {
// Save the ban.
$NewID = $this->Form->save();
} catch (Exception $Ex) {
$this->Form->addError($Ex);
}
} else {
if ($ID) {
$this->Form->setData($BanModel->getID($ID));
}
}
$this->setData('_BanTypes', array('IPAddress' => t('IP Address'), 'Email' => t('Email'), 'Name' => t('Name')));
$this->View = 'Ban';
break;
case 'delete':
if ($this->Form->authenticatedPostBack()) {
$BanModel->delete(array('BanID' => $ID));
$this->View = 'BanDelete';
}
break;
default:
$Bans = $BanModel->getWhere(array(), 'BanType, BanValue', 'asc', $Limit, $Offset)->resultArray();
$this->setData('Bans', $Bans);
break;
}
Gdn_Theme::section('Moderation');
$this->render();
}