public function store($updateNulls = false) { if (empty($this->email) && $this->userid) { $user = JFactory::getUser($this->userid); $this->fullname = $user->email(); } if (empty($this->fullname) && $this->userid) { $profile = DiscussHelper::getTable('Profile'); $profile->load($this->userid); $this->fullname = $profile->getName(); } if (empty($this->member)) { $this->member = $this->userid ? 1 : 0; } if (empty($this->interval)) { $this->interval = 'instant'; } if (empty($this->created)) { $this->created = DiscussHelper::getDate()->toMySQL(); } if (empty($this->sent_out)) { $this->sent_out = DiscussHelper::getDate()->toMySQL(); } return parent::store($updateNulls); }
public function display($tpl = null) { // Initialise variables $mainframe = JFactory::getApplication(); $tagId = JRequest::getVar('tagid', ''); $tag = JTable::getInstance('Tags', 'Discuss'); $tag->load($tagId); $tag->title = JString::trim($tag->title); $tag->alias = JString::trim($tag->alias); $this->tag = $tag; // Generate All tags for merging selections $tagsModel = $this->getModel('Tags'); $tags = $tagsModel->getData(false); $tagList = array(); array_push($tagList, JHTML::_('select.option', 0, 'Select tag', 'value', 'text', false)); if (!empty($tags)) { foreach ($tags as $item) { if ($item->id != $tagId) { $tagList[] = JHtml::_('select.option', $item->id, $item->title); } } } // Set default values for new entries. if (empty($tag->created)) { $date = DiscussHelper::getDate(); $date->setOffSet($mainframe->getCfg('offset')); $tag->created = $date->toFormat(); $tag->published = true; } $this->assignRef('tag', $tag); $this->assignRef('tagList', $tagList); parent::display($tpl); }
public function display($tpl = null) { $id = JRequest::getInt('id', 0); $badge = DiscussHelper::getTable('Badges'); $badge->load($id); if (!$badge->created) { $date = DiscussHelper::getHelper('Date')->dateWithOffset(DiscussHelper::getDate()->toMySQL()); $badge->created = $date->toMySQL(); } // There could be some errors here. if (JRequest::getMethod() == 'POST') { $badge->bind(JRequest::get('post')); // Description might contain html codes $description = JRequest::getVar('description', '', 'post', 'string', JREQUEST_ALLOWRAW); $badge->description = $description; } $jConfig = DiscussHelper::getJConfig(); $editor = JFactory::getEditor($jConfig->get('editor')); $model = $this->getModel('Badges'); $rules = $model->getRules(); $badges = $this->getBadges(); $this->assign('editor', $editor); $this->assign('badges', $badges); $this->assign('rules', $rules); $this->assign('badge', $badge); parent::display($tpl); }
public static function addLikes($contentId, $type, $userId = null) { if (is_null($userId)) { $userId = JFactory::getUser()->id; } $date = DiscussHelper::getDate(); $likes = DiscussHelper::getTable('Likes'); $params = array(); $params['type'] = $type; $params['content_id'] = $contentId; $params['created_by'] = $userId; $params['created'] = $date->toMySQL(); $likes->bind($params); // Check if the user already likes or not. if yes, then return the id. $id = $likes->exists(); if ($id !== false) { return $id; } $likes->store(); if ($type == 'post') { // Now update the post $db = DiscussHelper::getDBO(); $query = 'UPDATE `#__discuss_posts` SET `num_likes` = `num_likes` + 1'; $query .= ' WHERE `id` = ' . $db->Quote($contentId); $db->setQuery($query); $db->query(); } return $likes->id; }
function process() { $view = new EasyDiscussView(); $date = DiscussHelper::getDate(); $now = $date->toMySQL(); $modelSubscribe = $view->getModel('Subscribe'); $subscribers = $modelSubscribe->getSiteSubscribers($this->interval, $now); $total = count($subscribers); if (empty($total)) { return false; } foreach ($subscribers as $subscriber) { $notify = DiscussHelper::getNotification(); $data = array(); $rows = $modelSubscribe->getCreatedPostByInterval($subscriber->sent_out, $now); $posts = array(); if ($rows) { foreach ($rows as $row) { $row['categorylink'] = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=categorie&layout=listings&category_id=' . $row['category_id'], false, true); $row['link'] = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $row['id'], false, true); $row['userlink'] = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=profile&id=' . $row['user_id'], false, true); $category = DiscussHelper::getTable('Category'); $creator = DiscussHelper::getTable('Profile'); $category->load($row['category_id']); $creator->load($row['user_id']); $row['category'] = $category->getTitle(); $row['avatar'] = $creator->getAvatar(); $row['name'] = $creator->getName(); $row['date'] = DiscussDateHelper::toFormat($row['created'], '%b %e, %Y'); $row['message'] = DiscussHelper::parseContent($row['content']); $posts[] = $row; } } $data['post'] = $posts; $data['total'] = count($data['post']); $data['unsubscribeLink'] = DiscussHelper::getUnsubscribeLink($subscriber, true, true); $subject = $date->toMySQL(); switch (strtoupper($this->interval)) { case 'DAILY': $subject = $date->toFormat('%F'); $data['interval'] = JText::_('today'); break; case 'WEEKLY': $subject = $date->toFormat('%V'); $data['interval'] = JText::_('this week'); break; case 'MONTHLY': $subject = $date->toFormat('%B'); $data['interval'] = JText::_('this month'); break; } if (!empty($data['post'])) { $notify->addQueue($subscriber->email, JText::sprintf('COM_EASYDISCUSS_YOUR_' . $this->interval . '_SUBSCRIPTION', $subject), '', 'email.subscription.site.interval.php', $data); } $subscribe = DiscussHelper::getTable('Subscribe'); $subscribe->load($subscriber->id); $subscribe->sent_out = $now; $subscribe->store(); } }
public function store($updateNulls = false) { if (empty($this->created) || $this->created == '0000-00-00 00:00:00') { $this->created = DiscussHelper::getDate()->toMySQL(); } return parent::store(); }
public function display($tmpl = null) { $config = DiscussHelper::getConfig(); $jConfig = DiscussHelper::getJConfig(); if (!$config->get('main_rss')) { return; } $filteractive = JRequest::getString('filter', 'allposts'); $sort = JRequest::getString('sort', 'latest'); if ($filteractive == 'unanswered' && ($sort == 'active' || $sort == 'popular')) { //reset the active to latest. $sort = 'latest'; } $doc = JFactory::getDocument(); $doc->link = JRoute::_('index.php?option=com_easydiscuss&view=index'); // Load up the tag $tag = JRequest::getInt('id', 0); $table = DiscussHelper::getTable('Tags'); $table->load($tag); // Set the title of the document $doc->setTitle($table->title); $doc->setDescription(JText::sprintf('COM_EASYDISCUSS_DISCUSSIONS_TAGGED_IN', $table->title)); $postModel = $this->getModel('Posts'); $posts = $postModel->getTaggedPost($tag, $sort, $filteractive); $pagination = $postModel->getPagination('0', $sort, $filteractive); $jConfig = DiscussHelper::getJConfig(); $posts = DiscussHelper::formatPost($posts); foreach ($posts as $row) { // Assign to feed item $title = $this->escape($row->title); $title = html_entity_decode($title); // load individual item creator class $item = new JFeedItem(); $item->title = $title; $item->link = JRoute::_('index.php?option=com_easydiscuss&view=post&id=' . $row->id); $item->description = $row->content; $item->date = DiscussHelper::getDate($row->created)->toMySQL(); if (!empty($row->tags)) { $tagData = array(); foreach ($row->tags as $tag) { $tagData[] = '<a href="' . JRoute::_('index.php?option=com_easydiscuss&view=tags&id=' . $tag->id) . '">' . $tag->title . '</a>'; } $row->tags = implode(', ', $tagData); } else { $row->tags = ''; } $item->category = $row->tags; $item->author = $row->user->getName(); if ($jConfig->get('feed_email') != 'none') { if ($jConfig->get('feed_email') == 'author') { $item->authorEmail = $row->user->email; } else { $item->authorEmail = $jConfig->get('mailfrom'); } } $doc->addItem($item); } }
public static function getHTML() { $captcha = DiscussHelper::getTable('Captcha'); $captcha->created = DiscussHelper::getDate()->toMySQL(); $captcha->store(); $theme = new DiscussThemes(); $theme->set('id', $captcha->id); return $theme->fetch('form.captcha.php'); }
/** * Delete the outdated entries. */ function clear() { $db = DiscussHelper::getDBO(); $date = DiscussHelper::getDate(); $query = 'DELETE FROM `#__discuss_captcha` WHERE `created` <= DATE_SUB( ' . $db->Quote($date->toMySQL()) . ', INTERVAL 12 HOUR )'; $db->setQuery($query); $db->query(); return true; }
/** * Overrides parent's bind method to add our own logic. * * @param Array $data **/ public function bind($data, $ignore = array()) { parent::bind($data); if (empty($this->created_time) || $this->created_time == '0000-00-00 00:00:00') { $this->created_time = DiscussHelper::getDate()->toMySQL(); } if (empty($this->created_user_id)) { $this->created_user_id = JFactory::getUser()->id; } }
/** * Overrides parent's bind method to add our own logic. * * @param Array $data **/ public function bind($data, $ignore = array()) { parent::bind($data); if (empty($this->created)) { $this->created = DiscussHelper::getDate()->toMySQL(); } if (empty($this->creator)) { $this->creator = JFactory::getUser()->id; } }
/** * Creates a new history record for the particular action. * * @access private * @param string $command The current action * @param int $userId The current actor * @param string $title The title of the history or action. * @return boolean True on success, false otherwise. **/ public function log($command, $userId, $title, $content_id = 0) { $activity = DiscussHelper::getTable('History'); $activity->set('command', $command); $activity->set('user_id', $userId); $activity->set('title', $title); $activity->set('created', DiscussHelper::getDate()->toMySQL()); $activity->set('content_id', $content_id); return $activity->store(); }
/** * Override parents implementation **/ public function store($updateNulls = false) { if (is_null($this->created)) { $this->created = DiscussHelper::getDate()->toMySQL(); } // Set the state to new if (is_null($this->state)) { $this->state = DISCUSS_NOTIFICATION_NEW; } return parent::store($updateNulls); }
public function updateView($userId, $url) { if (!$this->loadByUser($userId)) { // Store a new record for the user. $this->set('user_id', $userId); } $this->set('hash', $this->getHash($url)); $this->set('created', DiscussHelper::getDate()->toMySQL()); $this->set('ip', $_SERVER['REMOTE_ADDR']); return $this->store(); }
/** * Performs some maintenance here. * * @since 3.0 * @access public */ public function pruneNotifications() { $db = DiscussHelper::getDBO(); $date = DiscussHelper::getDate(); $config = DiscussHelper::getConfig(); $days = $config->get('notifications_history', 30); $query = 'DELETE FROM ' . $db->nameQuote('#__discuss_notifications') . ' ' . 'WHERE ' . $db->nameQuote('created') . ' <= DATE_SUB( ' . $db->Quote($date->toMySQL()) . ' , INTERVAL ' . $days . ' DAY )'; $db->setQuery($query); $db->query(); return true; }
public function addFav($postId, $userId, $type = 'post') { $date = DiscussHelper::getDate(); $fav = DiscussHelper::getTable('Favourites'); $fav->created_by = $userId; $fav->post_id = $postId; $fav->type = $type; $fav->created = $date->toMySQL(); if (!$fav->store()) { return false; } return true; }
function display($tmpl = null) { $config = DiscussHelper::getConfig(); if (!$config->get('main_rss')) { return; } $document = JFactory::getDocument(); $document->link = JRoute::_('index.php?option=com_easydiscuss&view=index'); $document->setTitle($this->escape($document->getTitle())); $sort = JRequest::getString('sort', 'latest'); $filter = JRequest::getString('filter', 'allposts'); $category = JRequest::getInt('category_id', 0); $postModel = $this->getModel('Posts'); $posts = $postModel->getData(true, $sort, null, $filter, $category); $pagination = $postModel->getPagination('0', $sort, $filter, $category); $jConfig = DiscussHelper::getJConfig(); $posts = DiscussHelper::formatPost($posts); require_once DISCUSS_HELPERS . '/parser.php'; foreach ($posts as $row) { // Assign to feed item $title = $this->escape($row->title); $title = html_entity_decode($title); $category = DiscussHelper::getTable('Category'); $category->load($row->category_id); // load individual item creator class $item = new JFeedItem(); //Problems with other language //$item->title = htmlentities( $title ); $item->title = $row->title; $item->link = JRoute::_('index.php?option=com_easydiscuss&view=post&id=' . $row->id); //$row->content = DiscussHelper::parseContent( $row->content ); if ($row->content_type == 'bbcode') { $row->content = DiscussHelper::parseContent($row->content); $row->content = html_entity_decode($row->content); } // Problems with other language //$item->description = htmlentities( $row->content ); $item->description = $row->content; $item->date = DiscussHelper::getDate($row->created)->toMySQL(); $item->author = $row->user->getName(); $item->category = $category->getTitle(); if ($jConfig->get('feed_email') != 'none') { if ($jConfig->get('feed_email') == 'author') { $item->authorEmail = $row->user->user->email; } else { $item->authorEmail = $jConfig->get('mailfrom'); } } $document->addItem($item); } }
/** * Stores a private message composed by the user. * * @since 3.0 * @access public * @param null */ public function save() { JRequest::checkToken('request') or jexit('Invalid Token'); $config = DiscussHelper::getConfig(); $recipientId = JRequest::getInt('recipient', 0); $app = JFactory::getApplication(); $my = JFactory::getUser(); // Test for valid recipients. if (!$recipientId) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_MESSAGING_INVALID_RECIPIENT')); $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=conversation&layout=compose', false)); $app->close(); } // Do not allow user to send a message to himself, it's crazy. if ($recipientId == $my->id) { DiscussHelper::setMessageQueue(JText::_('You should not start a conversation with your self.')); $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=conversation&layout=compose', false)); $app->close(); } // Initialize conversation table. $conversation = DiscussHelper::getTable('Conversation'); // Check if this conversation already exist in the system. $state = $conversation->loadByRelation($my->id, $recipientId); if (!$state) { $date = DiscussHelper::getDate()->toMySQL(); $conversation->created = $date; $conversation->created_by = $my->id; $conversation->lastreplied = $date; $conversation->store(); } // Get message from query. $content = JRequest::getVar('message'); // Initialize message table. $message = DiscussHelper::getTable('ConversationMessage'); $message->message = $content; $message->conversation_id = $conversation->id; $message->created = DiscussHelper::getDate()->toMySQL(); $message->created_by = $my->id; $message->store(); // Add participant to this conversation. $model = DiscussHelper::getModel('Conversation'); $model->addParticipant($conversation->id, $recipientId, $my->id); // Add message map so that recipient can view the message. $model->addMessageMap($conversation->id, $message->id, $recipientId, $my->id); // @TODO: Add notification for recipient to let them know they received a message. // @TODO: Add points for user. // @TODO: Add badge for user. // Set message queue. DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_MESSAGE_SENT')); $app->redirect(DiscussRouter::getMessageRoute($conversation->id, false)); }
function display($tmpl = null) { $config = DiscussHelper::getConfig(); if (!$config->get('main_rss')) { return; } $userid = JRequest::getInt('id', null); $user = JFactory::getUser($userid); $document = JFactory::getDocument(); $document->link = DiscussRouter::_('index.php?option=com_easydiscuss&view=profile&id=' . $user->id); $profile = DiscussHelper::getTable('Profile'); $profile->load($user->id); $document->setTitle($profile->getName()); $document->setDescription($profile->getDescription()); $jConfig = DiscussHelper::getJConfig(); $model = $this->getModel('Posts'); $posts = $model->getPostsBy('user', $profile->id); $posts = DiscussHelper::formatPost($posts); foreach ($posts as $row) { // Assign to feed item $title = $this->escape($row->title); $title = html_entity_decode($title); // load individual item creator class $item = new JFeedItem(); $item->title = $title; $item->link = JRoute::_('index.php?option=com_easydiscuss&view=post&id=' . $row->id); $item->description = $row->content; $item->date = DiscussHelper::getDate($row->created)->toMySQL(); if (!empty($row->tags)) { $tagData = array(); foreach ($row->tags as $tag) { $tagData[] = '<a href="' . JRoute::_('index.php?option=com_easydiscuss&view=tags&id=' . $tag->id) . '">' . $tag->title . '</a>'; } $row->tags = implode(', ', $tagData); } else { $row->tags = ''; } $item->category = $row->tags; $item->author = $row->user->getName(); if ($jConfig->get('feed_email') != 'none') { if ($jConfig->get('feed_email') == 'author') { $item->authorEmail = $row->user->email; } else { $item->authorEmail = $jConfig->get('mailfrom'); } } $document->addItem($item); } }
/** * * */ public function bind($post, $isPost = false) { parent::bind($post); if ($isPost) { $date = DiscussHelper::getDate(); //replace a url to link $reason = $post['reporttext']; $JFilter = JFilterInput::getInstance(); $this->reason = $JFilter->clean($reason); if (empty($this->created) || $this->created == '0000-00-00 00:00:00') { $this->created = $date->toMySQL(); } $this->created_by = $post['created_by']; } return true; }
public function ajaxSubmitEmail($data) { $my = JFactory::getUser(); $djax = new Disjax(); $post = DiscussStringHelper::ajaxPostToArray($data); if ($my->id == 0) { $djax->alert(JText::_('COM_EASYDISCUSS_YOU_DO_NOT_HAVE_PERMISION_TO_SUBMIT_REPORT'), JText::_('ERROR'), '450', 'auto'); $djax->send(); return; } // Load language files from front end. JFactory::getLanguage()->load('com_easydiscuss', JPATH_ROOT); if (empty($post['post_id'])) { $djax->alert(JText::_('COM_EASYDISCUSS_INVALID_POST_ID'), JText::_('ERROR'), '450', 'auto'); $djax->send(); return; } $postId = (int) $post['post_id']; $emailContent = $post['content']; // Prepare email data $postTbl = JTable::getInstance('posts', 'Discuss'); $postTbl->load($postId); $moderator = DiscussHelper::getTable('Profile'); $moderator->load($my->id); $creator = JFactory::getUser($postTbl->user_id); $date = DiscussHelper::getDate($postTbl->created); $emailData = array(); $emailData['postAuthor'] = $moderator->getName(); $emailData['postAuthorAvatar'] = $moderator->getAvatar(); $emailData['postDate'] = $date->toFormat(); $emailData['postLink'] = JURI::root() . 'index.php?option=com_easydiscuss&view=post&id=' . $postTbl->id; $emailData['postTitle'] = $postTbl->title; $emailData['messages'] = $emailContent; if (!empty($postTbl->parent_id)) { $parentTbl = JTable::getInstance('posts', 'Discuss'); $parentTbl->load($postTbl->parent_id); $emailData['postTitle'] = $parentTbl->title; $emailData['postLink'] = JURI::root() . 'index.php?option=com_easydiscuss&view=post&id=' . $parentTbl->id; } $noti = DiscussHelper::getNotification(); $noti->addQueue($creator->email, JText::sprintf('COM_EASYDISCUSS_REQUIRED_YOUR_ATTENTION', $emailData['postTitle']), '', 'email.report.attention.php', $emailData); $djax->assign('report-entry-msg-' . $postId, JText::_('COM_EASYDISCUSS_EMAIL_SENT_TO_AUTHOR')); $djax->script('admin.reports.revertEmailForm("' . $postId . '");'); $djax->send(); return; }
public function diplayLabel() { // Initialise variables $mainframe = JFactory::getApplication(); $labelId = JRequest::getVar('label_id', ''); $label = DiscussHelper::getTable('Label'); $label->load($labelId); $label->title = JString::trim($label->title); $this->label = $label; // Set default values for new entries. if (empty($label->created)) { $date = DiscussHelper::getDate(); $date->setOffSet($mainframe->getCfg('offset')); $label->created = $date->toFormat(); $label->published = true; } $this->assignRef('label', $label); parent::display('edit'); }
public function assign($command, $userId) { // We don't have to give any badge to guests. if (!$userId || $userId == 0) { return; } // @task: Load necessary language files JFactory::getLanguage()->load('com_easydiscuss', JPATH_ROOT); $config = DiscussHelper::getConfig(); // If badges is disabled, do not proceed. if (!$config->get('main_badges')) { return; } // @task: Compute the count of the history already matches any badge for this user. $total = $this->getTotal($command, $userId); // @task: Get the badges that is relevant to this command $badges = $this->getBadges($command, $userId); if (!$badges) { return false; } foreach ($badges as $badge) { if ($total >= $badge->rule_limit) { $table = DiscussHelper::getTable('BadgesUsers'); $table->set('badge_id', $badge->id); $table->set('user_id', $userId); $table->set('created', DiscussHelper::getDate()->toMySQL()); $table->set('published', 1); $table->store(); // @task: Add a new notification when they earned a new badge. $notification = DiscussHelper::getTable('Notifications'); $notification->bind(array('title' => JText::sprintf('COM_EASYDISCUSS_NEW_BADGE_NOTIFICATION_TITLE', $badge->title), 'cid' => $badge->id, 'type' => DISCUSS_NOTIFICATIONS_BADGE, 'target' => $userId, 'author' => $userId, 'permalink' => 'index.php?option=com_easydiscuss&view=profile&id=' . $userId)); $notification->store(); //insert into JS stream. if ($config->get('integration_jomsocial_activity_badges', 0)) { $badgeTable = DiscussHelper::getTable('Badges'); $badgeTable->load($badge->id); $badgeTable->uniqueId = $table->id; DiscussHelper::getHelper('jomsocial')->addActivityBadges($badgeTable); } } } return true; }
/** * Stores a private message composed by the user. * * @since 3.0 * @access public * @param null */ public function save() { JRequest::checkToken('request') or jexit('Invalid Token'); $config = DiscussHelper::getConfig(); $recipientId = JRequest::getInt('recipient', 0); $app = JFactory::getApplication(); // Test for valid recipients. if (!$recipientId) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_MESSAGING_INVALID_RECIPIENT')); $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=messaging&layout=compose', false)); $app->close(); } // Get message meta here. $title = JRequest::getVar('title'); $content = JRequest::getVar('message'); // Store the new message. $message = DiscussHelper::getTable('Message'); $message->created_by = JFactory::getUser()->id; $message->recipient = $recipientId; $message->created = DiscussHelper::getDate()->toMySQL(); $message->lastreplied = DiscussHelper::getDate()->toMySQL(); $message->store(); // Store the message meta. $meta = DiscussHelper::getTable('MessageMeta'); $meta->message_id = $message->id; $meta->title = $title; $meta->message = $content; $meta->created = DiscussHelper::getDate()->toMySQL(); $meta->created_by = JFactory::getUser()->id; $meta->isparent = true; $meta->store(); $app = JFactory::getApplication(); // @TODO: Add notification for recipient to let them know they received a message. // @TODO: Add points for user. // @TODO: Add badge for user. // Set message queue. DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_MESSAGE_SENT')); $app->redirect(DiscussRouter::getMessageRoute($message->id, false)); }
public function form() { $id = JRequest::getInt('id', 0); $this->addPathway('Home', 'index.php?option=com_easydiscuss'); $this->addPathway('Points', 'index.php?option=com_easydiscuss&view=points'); $point = DiscussHelper::getTable('Points'); $point->load($id); if ($point->id) { $this->addPathway(JText::_('COM_EASYDISCUSS_PATHWAY_EDIT_POINT')); } else { $this->addPathway(JText::_('COM_EASYDISCUSS_PATHWAY_NEW_POINT')); } if (!$point->created) { $date = DiscussHelper::getHelper('Date')->dateWithOffset(DiscussHelper::getDate()->toMySQL()); $point->created = $date->toMySQL(); } $model = $this->getModel('Points'); $rules = $model->getRules(); $this->assign('rules', $rules); $this->assign('point', $point); parent::display(); }
public function bindImage($elementName) { $file = JRequest::getVar($elementName, '', 'FILES'); if (!isset($file['tmp_name']) || empty($file['tmp_name'])) { return false; } jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); // @task: Test if the folder containing the badges exists if (!JFolder::exists(DISCUSS_BADGES_PATH)) { JFolder::create(DISCUSS_BADGES_PATH); } // @task: Test if the folder containing uploaded badges exists if (!JFolder::exists(DISCUSS_BADGES_UPLOADED)) { JFolder::create(DISCUSS_BADGES_UPLOADED); } require_once DISCUSS_CLASSES . '/simpleimage.php'; $image = new SimpleImage(); $image->load($file['tmp_name']); if ($image->getWidth() > 64 || $image->getHeight() > 64) { return false; } $storage = DISCUSS_BADGES_UPLOADED; $name = md5($this->id . DiscussHelper::getDate()->toMySQL()) . $image->getExtension(); // @task: Create the necessary path $path = $storage . '/' . $this->id; if (!JFolder::exists($path)) { JFolder::create($path); } // @task: Copy the original image into the storage path JFile::copy($file['tmp_name'], $path . '/' . $name); // @task: Resize to the 16x16 favicon $image->resize(DISCUSS_BADGES_FAVICON_WIDTH, DISCUSS_BADGES_FAVICON_HEIGHT); $image->save($path . '/' . 'favicon_' . $name); $this->avatar = $this->id . '/' . $name; $this->thumbnail = $this->id . '/' . 'favicon_' . $name; return $this->store(); }
public function save() { JRequest::checkToken('request') or jexit('Invalid Token'); $app = JFactory::getApplication(); $point = DiscussHelper::getTable('Points'); $id = JRequest::getInt('id'); $point->load($id); $post = JRequest::get('POST'); $point->bind($post); if (empty($point->created)) { $point->created = DiscussHelper::getDate()->toMySQL(); } // Store the badge $point->store(); $message = !empty($id) ? JText::_('COM_EASYDISCUSS_POINTS_UPDATED') : JText::_('COM_EASYDISCUSS_POINTS_CREATED'); $url = 'index.php?option=com_easydiscuss&view=points'; if (JRequest::getVar('task') == 'saveNew') { //$url = 'index.php?option=com_easydiscuss&controller=points&layout=form'; $url = 'index.php?option=com_easydiscuss&view=points&layout=form'; } DiscussHelper::setMessageQueue($message, DISCUSS_QUEUE_SUCCESS); $app->redirect($url); }
public function store($updateNulls = false) { $date = DiscussHelper::getDate(); $this->modified = $date->toMySQL(); // @since 3.0 $this->legacy = '0'; if ($this->published == 1 && !empty($this->parent_id)) { $this->updateParentLastRepliedDate(); } return parent::store(); }
</th> <th width="1%" class="center"><?php echo JHTML::_('grid.sort', JText::_('Id'), 'a.id', $this->orderDirection, $this->order); ?> </th> </tr> </thead> <tbody> <?php if ($this->postTypes) { $k = 0; $x = 0; $config = DiscussHelper::getJConfig(); for ($i = 0, $n = count($this->postTypes); $i < $n; $i++) { $row = $this->postTypes[$i]; $date = DiscussHelper::getDate($row->created, $config->get('offset')); ?> <tr class="<?php echo "row{$k}"; ?> "> <td class="center" style="text-align: center;"> <?php echo JHTML::_('grid.id', $x++, $row->id); ?> </td> <td align="left"> <a href="<?php echo 'index.php?option=com_easydiscuss&view=post_types&layout=form&id=' . $row->id; ?>
public static function uploadAvatar($profile, $isFromBackend = false) { jimport('joomla.utilities.error'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); $my = JFactory::getUser(); $mainframe = JFactory::getApplication(); $config = DiscussHelper::getConfig(); $avatar_config_path = $config->get('main_avatarpath'); $avatar_config_path = rtrim($avatar_config_path, '/'); $avatar_config_path = JString::str_ireplace('/', DIRECTORY_SEPARATOR, $avatar_config_path); $upload_path = JPATH_ROOT . '/' . $avatar_config_path; $rel_upload_path = $avatar_config_path; $err = null; $file = JRequest::getVar('Filedata', '', 'files', 'array'); // Check whether the upload folder exist or not. if not create it. if (!JFolder::exists($upload_path)) { if (!JFolder::create($upload_path)) { // Redirect if (!$isFromBackend) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_FAILED_TO_CREATE_UPLOAD_FOLDER'), 'error'); $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=profile', false)); } else { // From backend $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=users', false), JText::_('COM_EASYDISCUSS_FAILED_TO_CREATE_UPLOAD_FOLDER'), 'error'); } return; } } // Makesafe on the file $date = DiscussHelper::getDate(); $file_ext = DiscussImageHelper::getFileExtention($file['name']); $file['name'] = $my->id . '_' . JFile::makeSafe(md5($file['name'] . $date->toMySQL())) . '.' . strtolower($file_ext); if (isset($file['name'])) { $target_file_path = $upload_path; $relative_target_file = $rel_upload_path . '/' . $file['name']; $target_file = JPath::clean($target_file_path . '/' . JFile::makeSafe($file['name'])); $original = JPath::clean($target_file_path . '/' . 'original_' . JFile::makeSafe($file['name'])); $isNew = false; require_once DISCUSS_HELPERS . '/image.php'; require_once DISCUSS_CLASSES . '/simpleimage.php'; if (!DiscussImageHelper::canUpload($file, $err)) { if (!$isFromBackend) { DiscussHelper::setMessageQueue(JText::_($err), 'error'); $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=profile&layout=edit', false)); } else { // From backend $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=users', false), JText::_($err), 'error'); } return; } if (0 != (int) $file['error']) { if (!$isFromBackend) { DiscussHelper::setMessageQueue($file['error'], 'error'); $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=profile&layout=edit', false)); } else { //from backend $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=users', false), $file['error'], 'error'); } return; } //rename the file 1st. $oldAvatar = $profile->avatar; $tempAvatar = ''; if ($oldAvatar != 'default.png') { $session = JFactory::getSession(); $sessionId = $session->getToken(); $fileExt = JFile::getExt(JPath::clean($target_file_path . '/' . $oldAvatar)); $tempAvatar = JPath::clean($target_file_path . '/' . $sessionId . '.' . $fileExt); // Test if old original file exists. if (JFile::exists($target_file_path . '/original_' . $oldAvatar)) { JFile::delete($target_file_path . '/original_' . $oldAvatar); } JFile::move($target_file_path . '/' . $oldAvatar, $tempAvatar); } else { $isNew = true; } if (JFile::exists($target_file)) { if ($oldAvatar != 'default.png') { //rename back to the previous one. JFile::move($tempAvatar, $target_file_path . '/' . $oldAvatar); } if (!$isFromBackend) { DiscussHelper::setMessageQueue(JText::sprintf('COM_EASYDISCUSS_FILE_ALREADY_EXISTS', $relative_target_file), 'error'); $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=profile', false)); } else { //from backend $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=users', false), JText::sprintf('COM_EASYDISCUSS_FILE_ALREADY_EXISTS', $relative_target_file), 'error'); } return; } if (JFolder::exists($target_file)) { if ($oldAvatar != 'default.png') { //rename back to the previous one. JFile::move($tempAvatar, $target_file_path . '/' . $oldAvatar); } if (!$isFromBackend) { DiscussHelper::setMessageQueue(JText::sprintf('COM_EASYDISCUSS_FILE_ALREADY_EXISTS', $relative_target_file), 'error'); $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=profile', false)); } else { //from backend $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=users', false), JText::sprintf('COM_EASYDISCUSS_FILE_ALREADY_EXISTS', $relative_target_file), 'error'); } return; } $configImageWidth = $config->get('layout_avatarwidth', 160); $configImageHeight = $config->get('layout_avatarheight', 160); $originalImageWidth = $config->get('layout_originalavatarwidth', 400); $originalImageHeight = $config->get('layout_originalavatarheight', 400); // Copy the original image files over $image = new SimpleImage(); $image->load($file['tmp_name']); //$image->resizeToFill( $originalImageWidth , $originalImageHeight ); // By Kevin Lankhorst $image->resizeOriginal($originalImageWidth, $originalImageHeight, $configImageWidth, $configImageHeight); $image->save($original, $image->image_type); unset($image); $image = new SimpleImage(); $image->load($file['tmp_name']); $image->resizeToFill($configImageWidth, $configImageHeight); $image->save($target_file, $image->image_type); //now we update the user avatar. If needed, we remove the old avatar. if ($oldAvatar != 'default.png') { if (JFile::exists($tempAvatar)) { JFile::delete($tempAvatar); } } return JFile::makeSafe($file['name']); } else { return 'default.png'; } }