instance() public static method

The singleton instance of this object.
public static instance ( ) : TagModel
return TagModel
 public function GetData()
 {
     $TagQuery = Gdn::SQL();
     $this->AutoContext();
     $TagCacheKey = "TagModule-{$this->ParentType}-{$this->ParentID}";
     switch ($this->ParentType) {
         case 'Discussion':
             $Tags = TagModel::instance()->getDiscussionTags($this->ParentID, false);
             break;
         case 'Category':
             $TagQuery->Join('TagDiscussion td', 't.TagID = td.TagID')->Select('COUNT(DISTINCT td.TagID)', '', 'NumTags')->Where('td.CategoryID', $this->ParentID)->GroupBy('td.TagID')->Cache($TagCacheKey, 'get', array(Gdn_Cache::FEATURE_EXPIRY => 120));
             break;
         case 'Global':
             $TagCacheKey = 'TagModule-Global';
             $TagQuery->Where('t.CountDiscussions >', 0, FALSE)->Cache($TagCacheKey, 'get', array(Gdn_Cache::FEATURE_EXPIRY => 120));
             if ($this->CategorySearch) {
                 $TagQuery->Where('t.CategoryID', '-1');
             }
             break;
     }
     if (isset($Tags)) {
         $this->_TagData = new Gdn_DataSet($Tags, DATASET_TYPE_ARRAY);
     } else {
         $this->_TagData = $TagQuery->Select('t.*')->From('Tag t')->OrderBy('t.CountDiscussions', 'desc')->Limit(25)->Get();
     }
     $this->_TagData->DatasetType(DATASET_TYPE_ARRAY);
 }
Esempio n. 2
0
 /**
  * The singleton instance of this object.
  * @return TagModel
  */
 public static function instance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new TagModel();
     }
     return self::$instance;
 }
Esempio n. 3
0
 /**
  * List all tags and allow searching
  *
  * @param SettingsController $Sender
  */
 public function SettingsController_Tagging_Create($Sender, $Search = NULL, $Type = NULL, $Page = NULL)
 {
     $Sender->Title('Tagging');
     $Sender->AddSideMenu('settings/tagging');
     $Sender->AddCSSFile('plugins/Tagging/design/tagadmin.css');
     $Sender->AddJSFile('plugins/Tagging/js/admin.js');
     $SQL = Gdn::SQL();
     // Get all tag types
     $TagModel = TagModel::instance();
     $TagTypes = $TagModel->getTagTypes();
     $Sender->Form->Method = 'get';
     $Sender->Form->InputPrefix = '';
     list($Offset, $Limit) = OffsetLimit($Page, 100);
     $Sender->SetData('_Limit', $Limit);
     if ($Search) {
         $SQL->Like('FullName', $Search, 'right');
     }
     // This type doesn't actually exist, but it will represent the
     // blank types in the column.
     if (strtolower($Type) == 'tags') {
         $Type = '';
     }
     if (!$Search) {
         if ($Type !== NULL) {
             if ($Type === 'null') {
                 $Type = NULL;
             }
             $SQL->Where('Type', $Type);
         } else {
             if ($Type == '') {
                 $SQL->Where('Type', '');
             }
         }
     } else {
         $Type = 'Search Results';
         // This is made up, and exists so search results can be placed in
         // their own tab.
         $TagTypes[$Type] = array('key' => $Type);
     }
     $TagTypes = array_change_key_case($TagTypes, CASE_LOWER);
     // Store type for view
     $TagType = !empty($Type) ? $Type : 'Tags';
     $Sender->SetData('_TagType', $TagType);
     // Store tag types
     $Sender->SetData('_TagTypes', $TagTypes);
     // Determine if new tags can be added for the current type.
     $CanAddTags = !empty($TagTypes[$Type]['addtag']) && $TagTypes[$Type]['addtag'] ? 1 : 0;
     $Sender->SetData('_CanAddTags', $CanAddTags);
     $Data = $SQL->Select('t.*')->From('Tag t')->OrderBy('t.FullName', 'asc')->OrderBy('t.CountDiscussions', 'desc')->Limit($Limit, $Offset)->Get()->ResultArray();
     $Sender->SetData('Tags', $Data);
     if ($Search) {
         $SQL->Like('Name', $Search, 'right');
     }
     // Make sure search uses its own search type, so results appear
     // in their own tab.
     $Sender->Form->Action = Url('/settings/tagging/?type=' . $TagType);
     // Search results pagination will mess up a bit, so don't provide a type
     // in the count.
     $RecordCountWhere = array('Type' => $Type);
     if ($Type == '') {
         $RecordCountWhere = array('Type' => '');
     }
     if ($Search) {
         $RecordCountWhere = array();
     }
     $Sender->SetData('RecordCount', $SQL->GetCount('Tag', $RecordCountWhere));
     $Sender->Render('tagging', '', 'plugins/Tagging');
 }
Esempio n. 4
0
 /**
  *
  *
  * @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;
 }
 /**
  * Add javascript to the post/edit discussion page so that tagging autocomplete works.
  */
 public function PostController_Render_Before($Sender)
 {
     $Sender->AddJsFile('jquery.tokeninput.js');
     $Sender->AddJsFile('tagging.js', 'plugins/Tagging');
     $Sender->AddDefinition('PluginsTaggingAdd', Gdn::Session()->CheckPermission('Plugins.Tagging.Add'));
     $Sender->AddDefinition('PluginsTaggingSearchUrl', Gdn::Request()->Url('plugin/tagsearch'));
     // Make sure that detailed tag data is available to the form.
     $DiscussionID = GetValue('DiscussionID', $Sender->Data['Discussion']);
     $TagModel = TagModel::instance();
     $Tags = $TagModel->getDiscussionTags($DiscussionID, TagModel::IX_EXTENDED);
     $Sender->SetData($Tags);
 }
Esempio n. 6
0
 /**
  * List all tags and allow searching
  *
  * @param SettingsController $Sender
  */
 public function settingsController_tagging_create($Sender, $Search = null, $Type = null, $Page = null)
 {
     $Sender->title('Tagging');
     $Sender->setHighlightRoute('settings/tagging');
     $Sender->addJSFile('tagadmin.js', 'plugins/Tagging');
     $SQL = Gdn::sql();
     // Get all tag types
     $TagModel = TagModel::instance();
     $TagTypes = $TagModel->getTagTypes();
     $Sender->Form->Method = 'get';
     list($Offset, $Limit) = offsetLimit($Page, 100);
     $Sender->setData('_Limit', $Limit);
     if ($Search) {
         $SQL->like('Name', $Search, 'right');
     }
     $queryType = $Type;
     if (strtolower($Type) == 'all' || $Search || $Type === null) {
         $queryType = false;
         $Type = '';
     }
     // This type doesn't actually exist, but it will represent the
     // blank types in the column.
     if (strtolower($Type) == 'tags') {
         $queryType = '';
     }
     if (!$Search && $queryType !== false) {
         $SQL->where('Type', $queryType);
     }
     $TagTypes = array_change_key_case($TagTypes, CASE_LOWER);
     // Store type for view
     $TagType = !empty($Type) ? $Type : 'All';
     $Sender->setData('_TagType', $TagType);
     // Store tag types
     $Sender->setData('_TagTypes', $TagTypes);
     // Determine if new tags can be added for the current type.
     $CanAddTags = !empty($TagTypes[$Type]['addtag']) && $TagTypes[$Type]['addtag'] ? 1 : 0;
     $CanAddTags &= CheckPermission('Plugins.Tagging.Add');
     $Sender->setData('_CanAddTags', $CanAddTags);
     $Data = $SQL->select('t.*')->from('Tag t')->orderBy('t.CountDiscussions', 'desc')->limit($Limit, $Offset)->get()->resultArray();
     $Sender->setData('Tags', $Data);
     if ($Search) {
         $SQL->like('Name', $Search, 'right');
     }
     // Make sure search uses its own search type, so results appear
     // in their own tab.
     $Sender->Form->Action = url('/settings/tagging/?type=' . $TagType);
     // Search results pagination will mess up a bit, so don't provide a type
     // in the count.
     $RecordCountWhere = array('Type' => $queryType);
     if ($queryType === false) {
         $RecordCountWhere = [];
     }
     if ($Search) {
         $RecordCountWhere = array();
     }
     $Sender->setData('RecordCount', $SQL->getCount('Tag', $RecordCountWhere));
     $Sender->render('tagging', '', 'plugins/Tagging');
 }