echo anchor(Gdn_Format::date($Discussion->DateInserted, 'html'), $Discussion->Url, 'Permalink', array('rel' => 'nofollow')); ?> </span> <?php echo dateUpdated($Discussion, array('<span class="MItem">', '</span>')); ?> <?php // Include source if one was set if ($Source = val('Source', $Discussion)) { echo ' ' . wrap(sprintf(t('via %s'), t($Source . ' Source', $Source)), 'span', array('class' => 'MItem MItem-Source')) . ' '; } // Category if (c('Vanilla.Categories.Use')) { echo ' <span class="MItem Category">'; echo ' ' . t('in') . ' '; echo anchor(htmlspecialchars($this->data('Discussion.Category')), categoryUrl($this->data('Discussion.CategoryUrlCode'))); echo '</span> '; } // Include IP Address if we have permission if ($Session->checkPermission('Garden.PersonalInfo.View')) { echo wrap(ipAnchor($Discussion->InsertIPAddress), 'span', array('class' => 'MItem IPAddress')); } $this->fireEvent('DiscussionInfo'); $this->fireEvent('AfterDiscussionMeta'); // DEPRECATED ?> </div> </div> <?php $this->fireEvent('BeforeDiscussionBody'); ?>
$this->fireEvent('AfterBodyField'); echo '</div>'; echo "<div class=\"Buttons\">\n"; $this->fireEvent('BeforeFormButtons'); $CancelText = t('Home'); $CancelClass = 'Back'; if (!$NewOrDraft || $Editing) { $CancelText = t('Cancel'); $CancelClass = 'Cancel'; } echo '<span class="' . $CancelClass . '">'; echo anchor($CancelText, '/'); if ($CategoryID = $this->data('Discussion.CategoryID')) { $Category = CategoryModel::categories($CategoryID); if ($Category) { echo ' <span class="Bullet">•</span> ' . anchor(htmlspecialchars($Category['Name']), categoryUrl($Category)); } } echo '</span>'; $ButtonOptions = array('class' => 'Button Primary CommentButton'); $ButtonOptions['tabindex'] = 1; if (!$Editing && $Session->isValid()) { echo ' ' . anchor(t('Preview'), '#', 'Button PreviewButton') . "\n"; echo ' ' . anchor(t('Edit'), '#', 'Button WriteButton Hidden') . "\n"; if ($NewOrDraft) { echo ' ' . anchor(t('Save Draft'), '#', 'Button DraftButton') . "\n"; } } if ($Session->isValid()) { echo $this->Form->button($Editing ? 'Save Comment' : 'Post Comment', $ButtonOptions); } else {
$OpenCount++; echo "\n<ol>"; } elseif ($OpenCount > $CountRight) { // Or are we closing open list and list items? while ($OpenCount > $CountRight) { $OpenCount--; echo "</li>\n</ol>\n"; } echo '</li>'; } elseif ($Loop > 0) { // Or are we closing an open list item? echo "</li>"; } echo "\n" . '<li id="list_' . $Category->CategoryID . '">'; // DEBUG: echo wrap($Category->Name.' [countright: '.$CountRight.' lastcount: '.$LastRight.' opencount: '.$OpenCount.']', 'div'); $CategoryUrl = categoryUrl($Category); if ($Category->Photo) { $Photo = img(Gdn_Upload::url($Category->Photo), array('class' => 'CategoryPhoto')); } else { $Photo = ''; } echo wrap('<table' . ($OpenCount > 0 ? ' class="Indented"' : '') . '> <tr> <td> ' . $Photo . ' <strong>' . htmlspecialchars($Category->Name) . '</strong> ' . anchor(htmlspecialchars(rawurldecode($CategoryUrl)), $CategoryUrl) . ' ' . Wrap($Category->Description, 'blockquote') . ' ' . ' </td> <td class="Buttons">' . anchor(t('Edit'), 'vanilla/settings/editcategory/' . $Category->CategoryID, 'SmallButton') . anchor(t('Move'), "vanilla/settings/movecategory/{$Category->CategoryID}", 'js-modal SmallButton') . (val('CanDelete', $Category) ? anchor(t('Delete'), 'vanilla/settings/deletecategory/' . $Category->CategoryID, 'SmallButton') : '') . '</td>
function main() { // اضافه کردن محصول به سبد با کتگوری و محصول if (isset($_GET['p']) && isset($_GET['c'])) { $productId = (int) $_GET['p']; $categoryId = (int) $_GET['c']; // بررسی وجود محصول $sql = "SELECT * FROM `products` WHERE `id` = {$productId};"; $result = dbQuery($sql); if (mysql_num_rows($result) !== 1) { die('وجود ندارد'); } $product = mysql_fetch_assoc($result); mysql_free_result($result); if (!isset($_SESSION['cart'])) { $_SESSION['cart'] = array(); } if (!isset($_SESSION['cart'][$productId])) { $count = 1; } else { $count = $_SESSION['cart'][$productId] + 1; } ///// if ($count > (int) $product['product_stock']) { // @TODo نمایش پیغام خطا $_SESSION['cart'][$productId] = $count; addMessage('تعداد درخواستی شما بیش از موجودی فروشگاه می باشد، از قسمت ارتباط با ما درخواست خود را ثبت نمایید.', FAILURE); } else { $_SESSION['cart'][$productId] = $count; addMessage('محصول به درستی به سبد اضافه شد.', SUCSESS); } $url = categoryUrl($categoryId); return array('redirect' => $url); } elseif (isset($_GET['p'])) { // اگر از صفحه محصول آمده باشد //@ToDo المان کنترل تعداد اضافه به سبد کار نمیکند $productId = $_GET['p']; // بررسی وجود محصول $sql = "SELECT * FROM `products` WHERE `id` = {$productId};"; $result = dbQuery($sql); if (mysql_num_rows($result) !== 1) { die('وجود ندارد'); } $product = mysql_fetch_assoc($result); mysql_free_result($result); if (!isset($_SESSION['cart'])) { $_SESSION['cart'] = array(); } // بررسی موجود بودن در انبار //@ToDo بازبینی شود if ((int) $product['product_stock'] !== 0) { // موجودی کافی در انبار هست به سبد خرید اضافه گردد if (!isset($_SESSION['cart'][$productId])) { $count = 1; } else { $count = $_SESSION['cart'][$productId] + 1; } if ($count > (int) $product['product_stock']) { // @TODo نمایش پیغام خطا $_SESSION['cart'][$productId] = $count; addMessage('تعداد درخواستی شما بیش از موجودی فروشگاه می باشد، از قسمت ارتباط با ما درخواست خود را ثبت نمایید.', FAILURE); } else { $_SESSION['cart'][$productId] = $count; // @ToDo ایجاد پیغام درست $_SESSION['cart'][$productId] = $count; addMessage('محصول به درستی به سبد اضافه شد.', SUCSESS); } } else { addMessage('تعداد درخواستی شما بیش از موجودی فروشگاه می باشد، از قسمت ارتباط با ما درخواست خود را ثبت نمایید.', FAILURE); } $url = productUrl($productId); return array('redirect' => $url); } }
/** * * * @param $Filename * @param $Get * @return bool|string */ public function filenameRedirect($Filename, $Get) { trace(['Filename' => $Filename, 'Get' => $Get], 'Testing'); $Filename = strtolower($Filename); array_change_key_case($Get); if (!isset(self::$Files[$Filename])) { return false; } $Row = self::$Files[$Filename]; if (is_callable($Row)) { // Use a callback to determine the translation. $Row = call_user_func_array($Row, [&$Get]); } trace($Get, 'New Get'); // Translate all of the get parameters into new parameters. $Vars = array(); foreach ($Get as $Key => $Value) { if (!isset($Row[$Key])) { continue; } $Opts = (array) $Row[$Key]; if (isset($Opts['Filter'])) { // Call the filter function to change the value. $R = call_user_func($Opts['Filter'], $Value, $Opts[0]); if (is_array($R)) { if (isset($R[0])) { // The filter can change the column name too. $Opts[0] = $R[0]; $Value = $R[1]; } else { // The filter can return return other variables too. $Vars = array_merge($Vars, $R); $Value = null; } } else { $Value = $R; } } if ($Value !== null) { $Vars[$Opts[0]] = $Value; } } trace($Vars, 'Translated Arguments'); // Now let's see what kind of record we have. // We'll check the various primary keys in order of importance. $Result = false; if (isset($Vars['CommentID'])) { trace("Looking up comment {$Vars['CommentID']}."); $CommentModel = new CommentModel(); // If a legacy slug is provided (assigned during a merge), attempt to lookup the comment using it if (isset($Get['legacy']) && Gdn::Structure()->Table('Comment')->ColumnExists('ForeignID')) { $Comment = $CommentModel->GetWhere(['ForeignID' => $Get['legacy'] . '-' . $Vars['CommentID']])->FirstRow(); } else { $Comment = $CommentModel->GetID($Vars['CommentID']); } if ($Comment) { $Result = CommentUrl($Comment, '//'); } } elseif (isset($Vars['DiscussionID'])) { trace("Looking up discussion {$Vars['DiscussionID']}."); $DiscussionModel = new DiscussionModel(); $DiscussionID = $Vars['DiscussionID']; $Discussion = false; if (is_numeric($DiscussionID)) { // If a legacy slug is provided (assigned during a merge), attempt to lookup the discussion using it if (isset($Get['legacy']) && Gdn::Structure()->Table('Discussion')->ColumnExists('ForeignID')) { $Discussion = $DiscussionModel->GetWhere(['ForeignID' => $Get['legacy'] . '-' . $DiscussionID])->FirstRow(); } else { $Discussion = $DiscussionModel->GetID($Vars['DiscussionID']); } } else { // This is a slug style discussion ID. Let's see if there is a UrlCode column in the discussion table. $DiscussionModel->DefineSchema(); if ($DiscussionModel->Schema->FieldExists('Discussion', 'UrlCode')) { $Discussion = $DiscussionModel->GetWhere(['UrlCode' => $DiscussionID])->FirstRow(); } } if ($Discussion) { $Result = DiscussionUrl($Discussion, self::pageNumber($Vars, 'Vanilla.Comments.PerPage'), '//'); } } elseif (isset($Vars['UserID'])) { trace("Looking up user {$Vars['UserID']}."); $User = Gdn::UserModel()->GetID($Vars['UserID']); if ($User) { $Result = Url(UserUrl($User), '//'); } } elseif (isset($Vars['TagID'])) { $Tag = TagModel::instance()->GetID($Vars['TagID']); if ($Tag) { $Result = TagUrl($Tag, self::pageNumber($Vars, 'Vanilla.Discussions.PerPage'), '//'); } } elseif (isset($Vars['CategoryID'])) { trace("Looking up category {$Vars['CategoryID']}."); // If a legacy slug is provided (assigned during a merge), attempt to lookup the category ID based on it if (isset($Get['legacy']) && Gdn::Structure()->Table('Category')->ColumnExists('ForeignID')) { $CategoryModel = new CategoryModel(); $Category = $CategoryModel->GetWhere(['ForeignID' => $Get['legacy'] . '-' . $Vars['CategoryID']])->FirstRow(); } else { $Category = CategoryModel::Categories($Vars['CategoryID']); } if ($Category) { $Result = categoryUrl($Category, self::pageNumber($Vars, 'Vanilla.Discussions.PerPage'), '//'); } } elseif (isset($Vars['CategoryCode'])) { trace("Looking up category {$Vars['CategoryCode']}."); $category = CategoryModel::instance()->getByCode($Vars['CategoryCode']); if ($category) { $pageNumber = self::pageNumber($Vars, 'Vanilla.Discussions.PerPage'); if ($pageNumber > 1) { $pageParam = '?Page=' . $pageNumber; } else { $pageParam = null; } $Result = categoryUrl($category, '', '//') . $pageParam; } } return $Result; }
/** * Show all discussions in a particular category. * * @since 2.0.0 * @access public * * @param string $CategoryIdentifier Unique category slug or ID. * @param int $Offset Number of discussions to skip. */ public function index($CategoryIdentifier = '', $Page = '0') { // Figure out which category layout to choose (Defined on "Homepage" settings page). $Layout = c('Vanilla.Categories.Layout'); if ($CategoryIdentifier == '') { switch ($Layout) { case 'mixed': $this->View = 'discussions'; $this->discussions(); break; case 'table': $this->table(); break; default: $this->View = 'all'; $this->all('', CategoryModel::getRootDisplayAs()); break; } return; } else { $Category = CategoryModel::categories($CategoryIdentifier); if (empty($Category)) { throw notFoundException(); } $Category = (object) $Category; Gdn_Theme::section($Category->CssClass); // Load the breadcrumbs. $this->setData('Breadcrumbs', CategoryModel::getAncestors(val('CategoryID', $Category))); $this->setData('Category', $Category, true); $this->title(htmlspecialchars(val('Name', $Category, ''))); $this->description(val('Description', $Category), true); switch ($Category->DisplayAs) { case 'Flat': case 'Heading': case 'Categories': $stopHeadings = val('Depth', $Category) > CategoryModel::instance()->getNavDepth(); CategoryModel::instance()->setStopHeadingsCalculation($stopHeadings); if ($this->SyndicationMethod != SYNDICATION_NONE) { // RSS can't show a category list so just tell it to expand all categories. saveToConfig('Vanilla.ExpandCategories', true, false); } else { // This category is an overview style category and displays as a category list. switch ($Layout) { case 'mixed': $this->View = 'discussions'; $this->discussions($CategoryIdentifier); break; case 'table': $this->table($CategoryIdentifier, $Category->DisplayAs); break; default: $this->View = 'all'; $this->All($CategoryIdentifier, $Category->DisplayAs); break; } return; } break; } 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; } $this->setData('CategoryTree', $this->getCategoryTree($CategoryIdentifier, val('DisplayAs', $Category))); // Add a backwards-compatibility shim for the old categories. $this->categoriesCompatibilityCallback = function () use($CategoryIdentifier) { $categories = CategoryModel::getSubtree($CategoryIdentifier, false); return $categories; }; // Setup head $this->Menu->highlightRoute('/discussions'); if ($this->Head) { $this->addJsFile('discussions.js'); $this->Head->addRss(categoryUrl($Category) . '/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(); $DiscussionModel->setSort(Gdn::request()->get()); $DiscussionModel->setFilters(Gdn::request()->get()); $this->setData('Sort', $DiscussionModel->getSort()); $this->setData('Filters', $DiscussionModel->getFilters()); $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 = $DiscussionModel->getAnnouncements($Wheres, $Offset, $Limit); $this->AnnounceData = $this->setData('Announcements', $AnnounceData); $Wheres['d.CategoryID'] = $CategoryIDs; // RSS should include announcements. if ($this->SyndicationMethod !== SYNDICATION_NONE) { $Wheres['Announce'] = 'all'; } $this->DiscussionData = $this->setData('Discussions', $DiscussionModel->getWhereRecent($Wheres, $Limit, $Offset)); // Build a pager $PagerFactory = new Gdn_PagerFactory(); $url = CategoryUrl($CategoryIdentifier); $this->EventArguments['PagerType'] = 'Pager'; $this->fireEvent('BeforeBuildPager'); if (!$this->data('_PagerUrl')) { $this->setData('_PagerUrl', $url . '/{Page}'); } $queryString = DiscussionModel::getSortFilterQueryString($DiscussionModel->getSort(), $DiscussionModel->getFilters()); $this->setData('_PagerUrl', $this->data('_PagerUrl') . $queryString); $this->Pager = $PagerFactory->GetPager($this->EventArguments['PagerType'], $this); $this->Pager->ClientID = 'Pager'; $this->Pager->configure($Offset, $Limit, $CountDiscussions, $this->data('_PagerUrl')); $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-' . val('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(); } }
/** * Constructs an options dropdown menu for a discussion. * * @param object|array|null $discussion The discussion to get the dropdown options for. * @return DropdownModule A dropdown consisting of discussion options. * @throws Exception */ function getDiscussionOptionsDropdown($discussion = null) { $dropdown = new DropdownModule(); $sender = Gdn::controller(); $session = Gdn::session(); if ($discussion == null) { $discussion = $sender->data('Discussion'); } $categoryID = val('CategoryID', $discussion); if (!$categoryID && property_exists($sender, 'Discussion')) { trace('Getting category ID from controller Discussion property.'); $categoryID = val('CategoryID', $sender->Discussion); } $discussionID = $discussion->DiscussionID; $categoryUrl = urlencode(categoryUrl(CategoryModel::categories($categoryID))); $permissionCategoryID = val('PermissionCategoryID', $discussion, val('PermissionCategoryID', $discussion)); // Permissions $canEdit = DiscussionModel::canEdit($discussion, $timeLeft); $canAnnounce = $session->checkPermission('Vanilla.Discussions.Announce', true, 'Category', $permissionCategoryID); $canSink = $session->checkPermission('Vanilla.Discussions.Sink', true, 'Category', $permissionCategoryID); $canClose = $session->checkPermission('Vanilla.Discussions.Close', true, 'Category', $permissionCategoryID); $canDelete = $session->checkPermission('Vanilla.Discussions.Delete', true, 'Category', $permissionCategoryID); $canMove = $canEdit && $session->checkPermission('Garden.Moderation.Manage'); $canRefetch = $canEdit && valr('Attributes.ForeignUrl', $discussion); $canDismiss = c('Vanilla.Discussions.Dismiss', 1) && $discussion->Announce == '1' && $discussion->Dismissed != '1' && $session->isValid(); if ($canEdit && $timeLeft) { $timeLeft = ' (' . Gdn_Format::seconds($timeLeft) . ')'; } $dropdown->addLinkIf($canDismiss, t('Dismiss'), "vanilla/discussion/dismissannouncement?discussionid={$discussionID}", 'dismiss', 'DismissAnnouncement Hijack')->addLinkIf($canEdit, t('Edit') . $timeLeft, '/post/editdiscussion/' . $discussionID, 'edit')->addLinkIf($canAnnounce, t('Announce'), '/discussion/announce?discussionid=' . $discussionID, 'announce', 'AnnounceDiscussion Popup')->addLinkIf($canSink, t($discussion->Sink ? 'Unsink' : 'Sink'), '/discussion/sink?discussionid=' . $discussionID . '&sink=' . (int) (!$discussion->Sink), 'sink', 'SinkDiscussion Hijack')->addLinkIf($canClose, t($discussion->Closed ? 'Reopen' : 'Close'), '/discussion/close?discussionid=' . $discussionID . '&close=' . (int) (!$discussion->Closed), 'close', 'CloseDiscussion Hijack')->addLinkIf($canRefetch, t('Refetch Page'), '/discussion/refetchpageinfo.json?discussionid=' . $discussionID, 'refetch', 'RefetchPage Hijack')->addLinkIf($canMove, t('Move'), '/moderation/confirmdiscussionmoves?discussionid=' . $discussionID, 'move', 'MoveDiscussion Popup')->addLinkIf($canDelete, t('Delete Discussion'), '/discussion/delete?discussionid=' . $discussionID . '&target=' . $categoryUrl, 'delete', 'DeleteDiscussion Popup'); // DEPRECATED $options = []; $sender->EventArguments['DiscussionOptions'] =& $options; $sender->EventArguments['Discussion'] = $discussion; $sender->fireEvent('DiscussionOptions'); // Backwards compatability $dropdown = discussionOptionsToDropdown($options, $dropdown); // Allow plugins to edit the dropdown. $sender->EventArguments['DiscussionOptionsDropdown'] =& $dropdown; $sender->EventArguments['Discussion'] = $discussion; $sender->fireEvent('DiscussionOptionsDropdown'); return $dropdown; }