Example #1
0
 /**
  * Display a list of blog entries
  *
  * @return  void
  */
 public function displayTask()
 {
     $filters = array('entry_id' => Request::getState($this->_option . '.' . $this->_controller . '.entry_id', 'entry_id', 0, 'int'), 'search' => urldecode(Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', '')), 'limit' => Request::getState($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int'), 'sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'created'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'ASC'));
     $entry = Entry::oneOrFail($filters['entry_id']);
     $comments = Comment::all();
     if ($filters['search']) {
         $comments->whereLike('title', strtolower((string) $filters['search']));
     }
     if ($filters['entry_id']) {
         $comments->whereEquals('entry_id', $filters['entry_id']);
     }
     $rows = $comments->ordered('filter_order', 'filter_order_Dir')->rows();
     $levellimit = $filters['limit'] == 0 ? 500 : $filters['limit'];
     $list = array();
     $children = array();
     if ($rows) {
         // First pass - collect children
         foreach ($rows as $k) {
             $pt = $k->get('parent');
             $list = @$children[$pt] ? $children[$pt] : array();
             array_push($list, $k);
             $children[$pt] = $list;
         }
         // Second pass - get an indent list of the items
         $list = $this->treeRecurse(0, '', array(), $children, max(0, $levellimit - 1));
     }
     // Output the HTML
     $this->view->set('filters', $filters)->set('entry', $entry)->set('total', count($list))->set('rows', array_slice($list, $filters['start'], $filters['limit']))->display();
 }
Example #2
0
 /**
  * Build module contents
  *
  * @return  void
  */
 public function run()
 {
     include_once \Component::path('com_blog') . DS . 'models' . DS . 'entry.php';
     $this->row = null;
     $filters = array('state' => 1, 'access' => 1, 'sort' => "RAND()", 'sort_Dir' => '', 'search' => '', 'scope' => 'member', 'scope_id' => 0, 'authorized' => false);
     $row = Entry::all()->whereEquals('scope', $filters['scope'])->whereEquals('state', $filters['state'])->whereEquals('access', $filters['access'])->row();
     // Did we have a result to display?
     if ($row->get('id')) {
         $this->row = $row;
         $this->cls = trim($this->params->get('moduleclass_sfx'));
         $this->txt_length = trim($this->params->get('txt_length'));
         require $this->getLayoutPath();
     }
 }
Example #3
0
 /**
  * Retrieves a row from the database
  *
  * @param      string $refid    ID of the database table row
  * @param      string $category Element type (determines table to look in)
  * @param      string $parent   If the element has a parent element
  * @return     array
  */
 public function getReportedItem($refid, $category, $parent)
 {
     if (!$this->_canHandle($category)) {
         return null;
     }
     require_once PATH_CORE . DS . 'components' . DS . 'com_blog' . DS . 'models' . DS . 'entry.php';
     $query = "SELECT rc.id, rc.entry_id, rc.content as `text`, rc.created_by as author, rc.created, NULL as subject, rc.anonymous as anon, 'blog' AS parent_category\n\t\t\t\t\tFROM `#__blog_comments` AS rc\n\t\t\t\t\tWHERE rc.id=" . $refid;
     $database = App::get('db');
     $database->setQuery($query);
     $rows = $database->loadObjectList();
     if ($rows) {
         foreach ($rows as $key => $row) {
             if (preg_match('/^<!-- \\{FORMAT:(.*)\\} -->/i', $row->text, $matches)) {
                 $rows[$key]->text = preg_replace('/^(<!-- \\{FORMAT:.*\\} -->)/i', '', $row->text);
             }
             $entry = \Components\Blog\Models\Entry::oneOrFail($rows[$key]->entry_id);
             $rows[$key]->text = strip_tags($rows[$key]->text);
             $rows[$key]->href = Route::url($entry->link() . '#c' . $rows[$key]->id);
         }
     }
     return $rows;
 }
Example #4
0
 /**
  * Download a file
  *
  * @return  void
  */
 public function downloadTask()
 {
     $archive = new Archive('site', 0);
     $entry = Entry::oneByScope(Request::getVar('alias', ''), 'site', 0);
     if (!$entry->get('id') || !$entry->access('view')) {
         throw new Exception(Lang::txt('Access denied.'), 403);
     }
     if (!($file = Request::getVar('file', ''))) {
         $filename = array_pop(explode('/', $_SERVER['REQUEST_URI']));
         // Get the file name
         if (substr(strtolower($filename), 0, strlen('image:')) == 'image:') {
             $file = substr($filename, strlen('image:'));
         } elseif (substr(strtolower($filename), 0, strlen('file:')) == 'file:') {
             $file = substr($filename, strlen('file:'));
         }
     }
     // Decode file name
     $file = urldecode($file);
     // Build file path
     $file_path = $archive->filespace() . DS . $file;
     // Ensure the file exist
     if (!file_exists($file_path)) {
         throw new InvalidArgumentException(Lang::txt('The requested file could not be found: %s', $file), 404);
     }
     // Serve up the image
     $server = new Server();
     $server->filename($file_path);
     $server->disposition('inline');
     $server->acceptranges(false);
     // @TODO fix byte range support
     // Serve up file
     if (!$server->serve()) {
         // Should only get here on error
         throw new RuntimeException(Lang::txt('An error occurred while trying to output the file'), 500);
     } else {
         exit;
     }
 }
Example #5
0
 /**
  * Delete an entry
  *
  * @apiMethod DELETE
  * @apiUri    /blog/{id}
  * @apiParameter {
  * 		"name":        "id",
  * 		"description": "Blog entry identifier",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @return    void
  */
 public function deleteTask()
 {
     $this->requiresAuthentication();
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     if (count($ids) <= 0) {
         throw new Exception(Lang::txt('COM_BLOG_ERROR_MISSING_ID'), 500);
     }
     foreach ($ids as $id) {
         $row = Entry::oneOrNew(intval($id));
         if (!$row->get('id')) {
             throw new Exception(Lang::txt('COM_BLOG_ERROR_MISSING_RECORD'), 404);
         }
         if (!$row->destroy()) {
             throw new Exception($row->getError(), 500);
         }
     }
     $this->send(null, 204);
 }
Example #6
0
 /**
  * Turn comments on/off
  *
  * @return  void
  */
 public function setcommentsTask()
 {
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     if (!User::authorise('core.edit.state', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming
     $ids = Request::getVar('id', array(0));
     $ids = !is_array($ids) ? array($ids) : $ids;
     $state = Request::getInt('state', 0);
     // Check for a resource
     if (count($ids) < 1) {
         Notify::warning(Lang::txt('COM_BLOG_SELECT_ENTRY_TO_COMMENTS', $this->_task));
         return $this->cancelTask();
     }
     // Loop through all the IDs
     $success = 0;
     foreach ($ids as $id) {
         // Load the article
         $row = Entry::oneOrFail(intval($id));
         $row->set('allow_comments', $state);
         // Store new content
         if (!$row->save()) {
             Notify::error($row->getError());
             continue;
         }
         $success++;
     }
     if ($success) {
         $message = $state ? Lang::txt('COM_BLOG_ITEMS_COMMENTS_ENABLED', $success) : Lang::txt('COM_BLOG_ITEMS_COMMENTS_DISABLED', $success);
         Notify::success($message);
     }
     // Set the redirect
     $this->cancelTask();
 }
Example #7
0
 /**
  * Delete an entry
  *
  * @return  string
  */
 private function _delete()
 {
     if (User::isGuest()) {
         $this->setError(Lang::txt('MEMBERS_LOGIN_NOTICE'));
         return;
     }
     if (User::get('id') != $this->member->get('uidNumber')) {
         $this->setError(Lang::txt('PLG_MEMBERS_BLOG_NOT_AUTHORIZED'));
         return $this->_browse();
     }
     // Incoming
     $id = Request::getInt('entry', 0);
     if (!$id) {
         return $this->_browse();
     }
     $process = Request::getVar('process', '');
     $confirmdel = Request::getVar('confirmdel', '');
     // Initiate a blog entry object
     $entry = \Components\Blog\Models\Entry::oneOrFail($id);
     // Did they confirm delete?
     if (!$process || !$confirmdel) {
         if ($process && !$confirmdel) {
             $this->setError(Lang::txt('PLG_MEMBERS_BLOG_ERROR_CONFIRM_DELETION'));
         }
         // Output HTML
         $view = $this->view('default', 'delete')->set('option', $this->option)->set('member', $this->member)->set('task', $this->task)->set('config', $this->params)->set('entry', $entry)->set('authorized', true);
         foreach ($this->getErrors() as $error) {
             $view->setError($error);
         }
         return $view->loadTemplate();
     }
     // Delete the entry itself
     $entry->set('state', 2);
     if (!$entry->save()) {
         $this->setError($entry->getError());
     }
     // Return the topics list
     App::redirect(Route::url($this->member->getLink() . '&active=' . $this->_name));
 }
Example #8
0
 /**
  * Display an RSS feed of comments
  *
  * @return  string  RSS
  */
 public function commentsTask()
 {
     if (!$this->config->get('feeds_enabled')) {
         throw new Exception(Lang::txt('Feed not found.'), 404);
     }
     // Set the mime encoding for the document
     Document::setType('feed');
     // Start a new feed object
     $doc = Document::instance();
     $doc->link = Route::url('index.php?option=' . $this->_option);
     // Incoming
     $alias = Request::getVar('alias', '');
     if (!$alias) {
         throw new Exception(Lang::txt('Feed not found.'), 404);
     }
     $this->entry = Entry::oneByScope($alias, 'site', 0);
     if (!$this->entry->isAvailable()) {
         throw new Exception(Lang::txt('Feed not found.'), 404);
     }
     $year = Request::getInt('year', date("Y"));
     $month = Request::getInt('month', 0);
     // Build some basic RSS document information
     $doc->title = Config::get('sitename') . ' - ' . Lang::txt(strtoupper($this->_option));
     $doc->title .= $year ? ': ' . $year : '';
     $doc->title .= $month ? ': ' . sprintf("%02d", $month) : '';
     $doc->title .= stripslashes($this->entry->get('title', ''));
     $doc->title .= ': ' . Lang::txt('Comments');
     $doc->description = Lang::txt('COM_BLOG_COMMENTS_RSS_DESCRIPTION', Config::get('sitename'), stripslashes($this->entry->get('title')));
     $doc->copyright = Lang::txt('COM_BLOG_RSS_COPYRIGHT', date("Y"), Config::get('sitename'));
     $rows = $this->entry->comments()->whereIn('state', array(1, 3))->ordered()->rows();
     // Start outputing results if any found
     if ($rows->count() <= 0) {
         return;
     }
     foreach ($rows as $row) {
         $this->_comment($doc, $row);
     }
 }
Example #9
0
 /**
  * Create an item entry
  *
  * @param   integer  $id  Optional ID to use
  * @return  boolean
  */
 public function make($id = null)
 {
     if ($this->exists()) {
         return true;
     }
     $id = $id ?: Request::getInt('id', 0);
     include_once PATH_CORE . DS . 'components' . DS . 'com_blog' . DS . 'models' . DS . 'entry.php';
     $post = null;
     if (!$id) {
         $alias = Request::getVar('alias', '');
         $post = Entry::oneByScope($alias, 'site', 0);
         $id = $post->get('id');
     }
     $this->_tbl->loadType($id, $this->_type);
     if ($this->exists()) {
         return true;
     }
     if (!$post) {
         $post = Entry::oneOrFail($id);
     }
     if (!$post->get('id')) {
         $this->setError(Lang::txt('Blog post not found.'));
         return false;
     }
     $this->set('type', $this->_type)->set('object_id', $post->get('id'))->set('created', $post->get('created'))->set('created_by', $post->get('created_by'))->set('title', $post->get('title'))->set('description', \Hubzero\Utility\String::truncate(strip_tags($post->content()), 200))->set('url', Route::url($post->link()));
     if (!$this->store()) {
         return false;
     }
     return true;
 }
Example #10
0
 /**
  * Delete an entry
  *
  * @apiMethod DELETE
  * @apiUri    /blog/{id}
  * @apiParameter {
  * 		"name":        "id",
  * 		"description": "Blog entry identifier",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @return    void
  */
 public function deleteTask()
 {
     $this->requiresAuthentication();
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     if (count($ids) <= 0) {
         throw new Exception(Lang::txt('COM_BLOG_ERROR_MISSING_ID'), 500);
     }
     foreach ($ids as $id) {
         $row = Entry::oneOrNew(intval($id));
         if (!$row->get('id')) {
             throw new Exception(Lang::txt('COM_BLOG_ERROR_MISSING_RECORD'), 404);
         }
         if (!$row->destroy()) {
             throw new Exception($row->getError(), 500);
         }
         // Log activity
         $base = rtrim(Request::base(), '/');
         $url = str_replace('/api', '', $base . '/' . ltrim(Route::url($row->link()), '/'));
         Event::trigger('system.logActivity', ['activity' => ['action' => 'deleted', 'scope' => 'blog.entry', 'scope_id' => $id, 'description' => Lang::txt('COM_BLOG_ACTIVITY_ENTRY_DELETED', '<a href="' . $url . '">' . $row->get('title') . '</a>'), 'details' => array('title' => $row->get('title'), 'url' => $url)], 'recipients' => [$entry->get('created_by')]]);
     }
     $this->send(null, 204);
 }
Example #11
0
 /**
  * Get module contents
  *
  * @return  void
  */
 public function run()
 {
     include_once Component::path('com_resources') . DS . 'tables' . DS . 'resource.php';
     include_once Component::path('com_members') . DS . 'models' . DS . 'member.php';
     include_once Component::path('com_answers') . DS . 'models' . DS . 'question.php';
     include_once Component::path('com_blog') . DS . 'models' . DS . 'archive.php';
     $this->database = \App::get('db');
     // Get the admin configured settings
     $filters = array();
     $filters['limit'] = 5;
     $filters['start'] = 0;
     // featured items
     $tbls = array('resources', 'profiles');
     $spots = array();
     $spots[0] = trim($this->params->get('spotone'));
     $spots[1] = trim($this->params->get('spottwo'));
     $spots[2] = trim($this->params->get('spotthree'));
     $spots[3] = trim($this->params->get('spotfour'));
     $spots[4] = trim($this->params->get('spotfive'));
     $spots[5] = trim($this->params->get('spotsix'));
     $spots[6] = trim($this->params->get('spotseven'));
     $numspots = $this->params->get('numspots', 3);
     // some collectors
     $activespots = array();
     $rows = array();
     // styling
     $cls = trim($this->params->get('moduleclass_sfx'));
     $txtLength = trim($this->params->get('txt_length'));
     $start = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y'))) . ' 00:00:00';
     $end = date('Y-m-d', mktime(0, 0, 0, date('m'), date('d'), date('Y'))) . ' 23:59:59';
     $this->html = '';
     $k = 1;
     $out = '';
     for ($i = 0, $n = $numspots; $i < $numspots; $i++) {
         $spot = $spots[$i];
         if ($spot == '') {
             continue;
         }
         $row = null;
         $out = '';
         $tbl = '';
         $tbl = $spot == 'tools' || $spot == 'nontools' ? 'resources' : '';
         $tbl = $spot == 'members' ? 'profiles' : $tbl;
         $tbl = $spot == 'topics' ? 'topics' : $tbl;
         $tbl = $spot == 'itunes' ? 'itunes' : $tbl;
         $tbl = $spot == 'answers' ? 'answers' : $tbl;
         $tbl = $spot == 'blog' ? 'blog' : $tbl;
         $tbl = !$tbl ? array_rand($tbls, 1) : $tbl;
         // we need to randomly choose one
         switch ($tbl) {
             case 'resources':
                 // Initiate a resource object
                 $rr = new \Components\Resources\Tables\Resource($this->database);
                 $filters['start'] = 0;
                 $filters['type'] = $spot;
                 $filters['sortby'] = 'random';
                 $filters['minranking'] = trim($this->params->get('minranking'));
                 $filters['tag'] = $spot == 'tools' ? trim($this->params->get('tag')) : '';
                 // tag is set for tools only
                 // Get records
                 $rows[$spot] = isset($rows[$spot]) ? $rows[$spot] : $rr->getRecords($filters, false);
                 break;
             case 'profiles':
                 // Get records
                 if (!isset($rows[$spot])) {
                     $last = \Components\Members\Models\Member::all()->select('id')->whereEquals('block', 0)->whereEquals('activation', 1)->where('approved', '>', 0)->order('id', 'desc')->row();
                     $r = mt_rand(0, $last->get('id'));
                     $rows[$spot] = \Components\Members\Models\Member::all()->whereEquals('block', 0)->whereEquals('activation', 1)->where('approved', '>', 0)->where('id', '>=', $r)->row();
                 }
                 break;
             case 'topics':
                 // No - so we need to randomly choose one
                 $topics_tag = trim($this->params->get('topics_tag'));
                 $query = "SELECT DISTINCT w.id, w.pagename, w.title ";
                 $query .= " FROM #__wiki_page AS w ";
                 if ($topics_tag) {
                     $query .= " JOIN #__tags_object AS RTA ON RTA.objectid=w.id AND RTA.tbl='wiki' ";
                     $query .= " INNER JOIN #__tags AS TA ON TA.id=RTA.tagid ";
                 } else {
                     $query .= ", #__wiki_version AS v ";
                 }
                 $query .= " WHERE w.access!=1 AND w.scope = ''  ";
                 if ($topics_tag) {
                     $query .= " AND (TA.tag='" . $topics_tag . "' OR TA.raw_tag='" . $topics_tag . "') ";
                 } else {
                     $query .= " AND v.pageid=w.id AND v.approved = 1 AND v.pagetext != '' ";
                 }
                 $query .= " ORDER BY RAND() ";
                 $this->database->setQuery($query);
                 $rows[$spot] = isset($rows[$spot]) ? $rows[$spot] : $this->database->loadObjectList();
                 break;
             case 'itunes':
                 // Initiate a resource object
                 $rr = new \Components\Resources\Tables\Resource($this->database);
                 $filters['start'] = 0;
                 $filters['sortby'] = 'random';
                 $filters['tag'] = trim($this->params->get('itunes_tag'));
                 // Get records
                 $rows[$spot] = isset($rows[$spot]) ? $rows[$spot] : $rr->getRecords($filters, false);
                 break;
             case 'answers':
                 $query = "SELECT C.id, C.subject, C.question, C.created, C.created_by, C.anonymous  ";
                 $query .= ", (SELECT COUNT(*) FROM #__answers_responses AS a WHERE a.state!=2 AND a.question_id=C.id) AS rcount ";
                 $query .= " FROM #__answers_questions AS C ";
                 $query .= " WHERE C.state=0 ";
                 $query .= " AND (C.reward > 0 OR C.helpful > 0) ";
                 $query .= " ORDER BY RAND() ";
                 $this->database->setQuery($query);
                 $rows[$spot] = isset($rows[$spot]) ? $rows[$spot] : $this->database->loadObjectList();
                 break;
             case 'blog':
                 $filters = array();
                 $filters['limit'] = 1;
                 $filters['start'] = 0;
                 $filters['state'] = 'public';
                 $filters['order'] = "RAND()";
                 $filters['search'] = '';
                 $filters['scope'] = 'member';
                 $filters['group_id'] = 0;
                 $filters['authorized'] = false;
                 $filters['sql'] = '';
                 $entry = \Components\Blog\Models\Entry::all()->whereEquals('scope', 'member')->whereEquals('state', 1)->whereIn('access', User::getAuthorisedViewLevels())->row();
                 $rows[$spot] = isset($rows[$spot]) ? $rows[$spot] : $entry;
                 break;
         }
         if ($rows && count($rows[$spot]) > 0) {
             $row = $rows[$spot][0];
         }
         // make sure we aren't pulling the same item
         if ($k != 1 && in_array($spot, $activespots) && $rows && count($rows[$spot]) > 1) {
             $row = count($rows[$spot]) < $k ? $rows[$spot][$k - 1] : $rows[$spot][1];
             // get the next one
         }
         // pull info
         if ($row) {
             $out = $this->_composeEntry($row, $tbl, $txtLength);
             $itemid = $this->_composeEntry($row, $tbl, 0, 1);
             $activespots[] = $spot;
         }
         // Did we get any results?
         if ($out) {
             $this->html .= '<li class="spot_' . $k . '">' . $out . '</li>' . "\n";
             $k++;
         }
     }
     // Output HTML
     require $this->getLayoutPath();
 }
Example #12
0
 /**
  * Delete an entry
  *
  * @return     string
  */
 private function _delete()
 {
     if (User::isGuest()) {
         $this->setError(Lang::txt('GROUPS_LOGIN_NOTICE'));
         return;
     }
     if (!$this->authorized) {
         $this->setError(Lang::txt('PLG_GROUPS_BLOG_NOT_AUTHORIZED'));
         return $this->_browse();
     }
     if (!$this->_getPostingPermissions()) {
         $this->setError(Lang::txt('PLG_GROUPS_BLOG_ERROR_PERMISSION_DENIED'));
         return $this->_browse();
     }
     // Incoming
     $id = Request::getInt('entry', 0);
     if (!$id) {
         return $this->_browse();
     }
     $process = Request::getVar('process', '');
     $confirmdel = Request::getVar('confirmdel', '');
     // Initiate a blog entry object
     $entry = \Components\Blog\Models\Entry::oneOrFail($id);
     // Did they confirm delete?
     if (!$process || !$confirmdel) {
         if ($process && !$confirmdel) {
             $this->setError(Lang::txt('PLG_GROUPS_BLOG_ERROR_CONFIRM_DELETION'));
         }
         // Output HTML
         $view = $this->view('default', 'delete')->set('option', $this->option)->set('group', $this->group)->set('task', $this->action)->set('config', $this->params)->set('entry', $entry)->set('authorized', $this->authorized);
         foreach ($this->getErrors() as $error) {
             $view->setError($error);
         }
         return $view->loadTemplate();
     }
     // Delete the entry itself
     $entry->set('state', 2);
     if (!$entry->save()) {
         $this->setError($entry->getError());
     }
     // Return the topics list
     return $this->_browse();
 }
Example #13
0
 /**
  * Turn comments on/off
  *
  * @return  void
  */
 public function setcommentsTask()
 {
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     // Incoming
     $ids = Request::getVar('id', array(0));
     $ids = !is_array($ids) ? array($ids) : $ids;
     $state = Request::getInt('state', 0);
     // Check for a resource
     if (count($ids) < 1) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_BLOG_SELECT_ENTRY_TO_COMMENTS', $this->_task), 'error');
         return;
     }
     // Loop through all the IDs
     $success = 0;
     foreach ($ids as $id) {
         // Load the article
         $row = Entry::oneOrFail(intval($id));
         $row->set('allow_comments', $state);
         // Store new content
         if (!$row->save()) {
             Notify::error($row->getError());
             continue;
         }
         $success++;
     }
     $message = $state ? Lang::txt('COM_BLOG_ITEMS_COMMENTS_ENABLED', $success) : Lang::txt('COM_BLOG_ITEMS_COMMENTS_DISABLED', $success);
     // Set the redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), $message);
 }
Example #14
0
 /**
  * Remove all user blog entries for the given user ID
  *
  * Method is called after user data is deleted from the database
  *
  * @param   array    $user     Holds the user data
  * @param   boolean  $success  True if user was succesfully stored in the database
  * @param   string   $msg      Message
  * @return  boolean
  */
 public function onMemberAfterDelete($user, $success, $msg)
 {
     if (!$success) {
         return false;
     }
     $userId = \Hubzero\Utility\Arr::getValue($user, 'id', 0, 'int');
     if ($userId) {
         try {
             include_once PATH_CORE . DS . 'components' . DS . 'com_blog' . DS . 'models' . DS . 'archive.php';
             $entries = \Components\Blog\Models\Entry::all()->whereEquals('created_by', $user['id'])->rows();
             foreach ($entries as $entry) {
                 if (!$entry->destroy()) {
                     throw new Exception($entry->getError());
                 }
             }
         } catch (Exception $e) {
             return false;
         }
     }
     return true;
 }
Example #15
0
 /**
  * Get a count of, model for, or list of entries
  *
  * @param   array   $filters  Filters to apply to data retrieval
  * @return  object
  */
 public function entries($filters = array())
 {
     if (!isset($filters['scope'])) {
         $filters['scope'] = (string) $this->get('scope');
     }
     if (!isset($filters['scope_id'])) {
         $filters['scope_id'] = (int) $this->get('scope_id');
     }
     $results = Entry::all()->including(['creator', function ($creator) {
         $creator->select('*');
     }])->including(['comments', function ($comment) {
         $comment->select('id')->select('entry_id')->whereIn('state', array(Comment::STATE_PUBLISHED, Comment::STATE_FLAGGED));
     }]);
     if ($filters['scope']) {
         $results->whereEquals('scope', $filters['scope'])->whereEquals('scope_id', $filters['scope_id']);
     }
     if (isset($filters['state'])) {
         $results->whereEquals('state', $filters['state']);
     }
     if (isset($filters['access'])) {
         $results->whereIn('access', $filters['access']);
     }
     if (isset($filters['year']) && $filters['year'] != 0) {
         if (isset($filters['month']) && $filters['month'] != 0) {
             $startdate = $filters['year'] . '-' . $filters['month'] . '-01 00:00:00';
             if ($filters['month'] + 1 == 13) {
                 $year = $filters['year'] + 1;
                 $month = 1;
             } else {
                 $month = $filters['month'] + 1;
                 $year = $filters['year'];
             }
             $enddate = sprintf("%4d-%02d-%02d 00:00:00", $year, $month, 1);
         } else {
             $startdate = $filters['year'] . '-01-01 00:00:00';
             $enddate = $filters['year'] + 1 . '-01-01 00:00:00';
         }
         $results->where('publish_up', '>=', $startdate)->where('publish_up', '<', $enddate);
     } else {
         $results->whereEquals('publish_up', '0000-00-00 00:00:00', 1)->orWhere('publish_up', '<=', Date::toSql(), 1);
     }
     $results->resetDepth();
     if (!isset($filters['authorized']) || !$filters['authorized']) {
         $results->whereEquals('publish_down', '0000-00-00 00:00:00', 1)->orWhere('publish_down', '>=', Date::toSql(), 1);
     }
     if (isset($filters['search']) && $filters['search']) {
         $filters['search'] = '%' . strtolower(stripslashes($filters['search'])) . '%';
         $results->where('title', 'LIKE', $filters['search'])->orWhere('content', 'LIKE', $filters['search']);
     }
     if (isset($filters['limit']) && $filters['limit']) {
         $results->limit($filters['limit']);
     }
     return $results;
 }
Example #16
0
 /**
  * Delete a comment
  *
  * @return     string
  */
 private function _deletecomment()
 {
     // Ensure the user is logged in
     if (User::isGuest()) {
         $this->setError(Lang::txt('GROUPS_LOGIN_NOTICE'));
         return;
     }
     // Incoming
     $id = Request::getInt('comment', 0);
     if (!$id) {
         return $this->_entry();
     }
     // Initiate a blog comment object
     $comment = \Components\Blog\Models\Comment::oneOrFail($id);
     // Delete all comments on an entry
     $comment->set('state', $comment::STATE_DELETED);
     // Delete the entry itself
     if (!$comment->save()) {
         $this->setError($comment->getError());
     }
     // Record the activity
     $recipients = array(['group', $this->group->get('gidNumber')]);
     if (!in_array($comment->get('created_by'), $this->group->get('managers'))) {
         $recipients[] = ['user', $comment->get('created_by')];
     }
     foreach ($this->group->get('managers') as $recipient) {
         $recipients[] = ['user', $recipient];
     }
     $entry = \Components\Blog\Models\Entry::oneOrFail($comment->get('entry_id'));
     Event::trigger('system.logActivity', ['activity' => ['action' => 'deleted', 'scope' => 'blog.entry.comment', 'scope_id' => $comment->get('id'), 'description' => Lang::txt('PLG_GROUPS_BLOG_ACTIVITY_COMMENT_DELETED', $comment->get('id'), '<a href="' . Route::url($entry->link()) . '">' . $entry->get('title') . '</a>'), 'details' => array('title' => $entry->get('title'), 'entry_id' => $entry->get('id'), 'url' => $entry->link())], 'recipients' => $recipients]);
     // Return the topics list
     return $this->_entry();
 }
Example #17
0
 /**
  * Get a count of all blog entries
  *
  * @param      string $gid Group alias
  * @return     integer
  */
 public static function getGroupBlogCount($gid)
 {
     if (!$gid) {
         return 0;
     }
     include_once PATH_CORE . DS . 'components' . DS . 'com_blog' . DS . 'models' . DS . 'entry.php';
     $total = \Components\Blog\Models\Entry::all()->whereEquals('scope', 'group')->whereEquals('scope_id', $gid)->where('state', '!=', \Components\Blog\Models\Entry::STATE_DELETED)->total();
     return $total;
 }
Example #18
0
 /**
  * Get a count of, model for, or list of entries
  *
  * @param   string   $rtrn     Data to return
  * @param   array    $filters  Filters to apply to data retrieval
  * @param   boolean  $reset    Clear cached data?
  * @return  mixed
  */
 public function entries($filters = array())
 {
     if (!isset($filters['scope'])) {
         $filters['scope'] = (string) $this->get('scope');
     }
     if (!isset($filters['scope_id'])) {
         $filters['scope_id'] = (int) $this->get('scope_id');
     }
     $results = Entry::all();
     if ($filters['scope']) {
         $results->whereEquals('scope', $filters['scope'])->whereEquals('scope_id', $filters['scope_id']);
     }
     if (isset($filters['state'])) {
         $results->whereEquals('state', $filters['state']);
     }
     if (isset($filters['access'])) {
         $results->whereIn('access', $filters['access']);
     }
     if (isset($filters['year']) && $filters['year'] != 0) {
         if (isset($filters['month']) && $filters['month'] != 0) {
             $startdate = $filters['year'] . '-' . $filters['month'] . '-01 00:00:00';
             if ($filters['month'] + 1 == 13) {
                 $year = $filters['year'] + 1;
                 $month = 1;
             } else {
                 $month = $filters['month'] + 1;
                 $year = $filters['year'];
             }
             $enddate = sprintf("%4d-%02d-%02d 00:00:00", $year, $month, 1);
         } else {
             $startdate = $filters['year'] . '-01-01 00:00:00';
             $enddate = $filters['year'] + 1 . '-01-01 00:00:00';
         }
         $results->where('publish_up', '>=', $startdate)->where('publish_up', '<', $enddate);
     } else {
         $results->whereEquals('publish_up', '0000-00-00 00:00:00', 1)->orWhere('publish_up', '<=', Date::toSql(), 1);
     }
     $results->resetDepth();
     $results->whereEquals('publish_down', '0000-00-00 00:00:00', 1)->orWhere('publish_down', '>=', Date::toSql(), 1);
     if (isset($filters['search']) && $filters['search']) {
         $filters['search'] = '%' . strtolower(stripslashes($filters['search'])) . '%';
         $results->where('title', 'LIKE', $filters['search'])->orWhere('content', 'LIKE', $filters['search']);
     }
     return $results;
 }
Example #19
0
 /**
  * Static method for formatting results
  *
  * @param      object $row Database row
  * @return     string HTML
  */
 public static function out($row)
 {
     include_once PATH_CORE . DS . 'components' . DS . 'com_blog' . DS . 'models' . DS . 'entry.php';
     $row->scope = $row->rcount;
     $row->scope_id = $row->data2;
     $row->content = $row->ftext;
     $view = new \Hubzero\Plugin\View(array('folder' => 'tags', 'element' => 'blogs', 'name' => 'result'));
     $view->entry = \Components\Blog\Models\Entry::blank();
     $view->entry->set(get_object_vars($row));
     return $view->loadTemplate();
 }