Ejemplo n.º 1
1
 public function store($log = true)
 {
     // @rule: Load language file from the front end.
     JFactory::getLanguage()->load('com_easyblog', JPATH_ROOT);
     $config = EasyBlogHelper::getConfig();
     $under_approval = false;
     if (isset($this->under_approval)) {
         $under_approval = true;
         // now we need to reset this variable from the blog object.
         unset($this->under_approval);
     }
     // @trigger: onBeforeSave
     $this->triggerBeforeSave();
     // @rule: Determine if this record is new or not.
     if (empty($this->isnew)) {
         $isNew = empty($this->id) ? true : false;
     } else {
         $isNew = true;
     }
     // @rule: Get the rulesets for this user.
     $acl = EasyBlogACLHelper::getRuleSet();
     // @rule: Process badword filters for title here.
     $blockedWord = EasyBlogHelper::getHelper('String')->hasBlockedWords($this->title);
     if ($blockedWord !== false) {
         $this->setError(JText::sprintf('COM_EASYBLOG_BLOG_TITLE_CONTAIN_BLOCKED_WORDS', $blockedWord));
         return false;
     }
     // @rule: Check for minimum words in the content if required.
     if ($config->get('main_post_min')) {
         $minimum = $config->get('main_post_length');
         $total = JString::strlen(strip_tags($this->intro . $this->content));
         if ($total < $minimum) {
             $this->setError(JText::sprintf('COM_EASYBLOG_CONTENT_LESS_THAN_MIN_LENGTH', $minimum));
             return false;
         }
     }
     // @rule: Check for invalid title
     if (empty($this->title) || $this->title == JText::_('COM_EASYBLOG_DASHBOARD_WRITE_DEFAULT_TITLE')) {
         $this->setError(JText::_('COM_EASYBLOG_DASHBOARD_SAVE_EMPTY_TITLE_ERROR'));
         return false;
     }
     // @rule: For edited blogs, ensure that they have permissions to edit it.
     if (!$isNew && $this->created_by != JFactory::getUser()->id && !EasyBlogHelper::isSiteAdmin() && empty($acl->rules->moderate_entry)) {
         if (!class_exists('EasyBlogModelTeamBlogs')) {
             jimport('joomla.application.component.model');
             JLoader::import('blog', EBLOG_ROOT . DIRECTORY_SEPARATOR . 'models');
         }
         // @task: Only throw error when this blog post is not a team blog post and it's not owned by the current logged in user.
         JModel::addIncludePath(JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_easyblog' . DIRECTORY_SEPARATOR . 'models');
         $model = JModel::getInstance('TeamBlogs', 'EasyBlogModel');
         $contribution = $model->getBlogContributed($this->id);
         if (!$contribution || !$model->checkIsTeamAdmin(JFactory::getUser()->id, $contribution->team_id)) {
             $this->setError(JText::_('COM_EASYBLOG_NO_PERMISSION_TO_EDIT_BLOG'));
             return false;
         }
     }
     // @rule: Every blog post must be assigned to a category
     if (empty($this->category_id)) {
         $this->setError(JText::_('COM_EASYBLOG_DASHBOARD_SAVE_EMPTY_CATEGORY_ERROR'));
         return false;
     }
     // Filter / strip contents that are not allowed
     $filterTags = EasyBlogHelper::getHelper('Acl')->getFilterTags();
     $filterAttributes = EasyBlogHelper::getHelper('Acl')->getFilterAttributes();
     // @rule: Apply filtering on contents
     jimport('joomla.filter.filterinput');
     $inputFilter = JFilterInput::getInstance($filterTags, $filterAttributes, 1, 1, 0);
     $inputFilter->tagBlacklist = $filterTags;
     $inputFilter->attrBlacklist = $filterAttributes;
     if (count($filterTags) > 0 && !empty($filterTags[0]) || count($filterAttributes) > 0 && !empty($filterAttributes[0])) {
         $this->intro = $inputFilter->clean($this->intro);
         $this->content = $inputFilter->clean($this->content);
     }
     // @rule: Process badword filters for content here.
     $blockedWord = EasyBlogHelper::getHelper('String')->hasBlockedWords($this->intro . $this->content);
     if ($blockedWord !== false) {
         $this->setError(JText::sprintf('COM_EASYBLOG_BLOG_POST_CONTAIN_BLOCKED_WORDS', $blockedWord));
         return false;
     }
     // @rule: Test for the empty-ness
     if (empty($this->intro) && empty($this->content)) {
         $this->setError(JText::_('COM_EASYBLOG_DASHBOARD_SAVE_CONTENT_ERROR'));
     }
     // alway set this to false no matter what! TODO: remove this column.
     $this->ispending = '0';
     $state = parent::store();
     $source = JRequest::getVar('blog_contribute_source', 'easyblog');
     // @trigger: onBeforeSave
     $this->triggerAfterSave();
     // if this is blog edit, then we should see the column isnew to determine
     // whether the post is really new or not.
     if (!$isNew) {
         $isNew = $this->isnew;
     }
     // @task: If auto featured is enabled, we need to feature the blog post automatically since the blogger is featured.
     if ($config->get('main_autofeatured', 0) && EasyBlogHelper::isFeatured('blogger', $this->created_by) && !EasyBlogHelper::isFeatured('post', $this->id)) {
         EasyBlogHelper::makeFeatured('post', $this->id);
     }
     // @task: This is when the blog is either created or updated.
     if ($source == 'easyblog' && $state && $this->published == POST_ID_PUBLISHED && $log) {
         // @rule: Add new stream item in jomsocial
         EasyBlogHelper::addJomSocialActivityBlog($this, $isNew);
         // @rule: Log new stream item into EasyBlog
         $activity = new stdClass();
         $activity->actor_id = $this->created_by;
         $activity->target_id = '0';
         $activity->context_type = 'post';
         $activity->context_id = $this->id;
         $activity->verb = $isNew ? 'add' : 'update';
         $activity->uuid = $this->title;
         EasyBlogHelper::activityLog($activity);
     }
     if ($source == 'easyblog' && $state && $this->published == POST_ID_PUBLISHED && $isNew && $log) {
         // @rule: Send email notifications out to subscribers.
         $author = EasyBlogHelper::getTable('Profile');
         $author->load($this->created_by);
         // @rule: Ping pingomatic
         if ($config->get('main_pingomatic')) {
             if (!EasyBlogHelper::getHelper('Pingomatic')->ping($this->title, EasyBlogHelper::getExternalLink('index.php?option=com_easyblog&view=entry&id=' . $this->id, true))) {
                 EasyBlogHelper::setMessageQueue(JText::_('COM_EASYBLOG_DASHBOARD_SAVE_PINGOMATIC_ERROR'), 'error');
             }
         }
         // Assign EasySocial points
         $easysocial = EasyBlogHelper::getHelper('EasySocial');
         $easysocial->assignPoints('blog.create', $this->created_by);
         // @rule: Add userpoints for jomsocial
         if ($config->get('main_jomsocial_userpoint')) {
             $path = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_community' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'userpoints.php';
             if (JFile::exists($path)) {
                 require_once $path;
                 CUserPoints::assignPoint('com_easyblog.blog.add', $this->created_by);
             }
         }
         $link = $this->getExternalBlogLink('index.php?option=com_easyblog&view=entry&id=' . $this->id);
         // @rule: Add notifications for jomsocial 2.6
         if ($config->get('integrations_jomsocial_notification_blog')) {
             // Get list of users who subscribed to this blog.
             $target = $this->getRegisteredSubscribers('new', array($this->created_by));
             EasyBlogHelper::getHelper('JomSocial')->addNotification(JText::sprintf('COM_EASYBLOG_JOMSOCIAL_NOTIFICATIONS_NEW_BLOG', $author->getName(), $link, $this->title), 'easyblog_new_blog', $target, $this->created_by, $link);
         }
         // @rule: Mighty Touch karma points
         EasyBlogHelper::getHelper('MightyTouch')->setKarma($this->created_by, 'new_blog');
         // @rule: Integrations with EasyDiscuss
         EasyBlogHelper::getHelper('EasyDiscuss')->log('easyblog.new.blog', $this->created_by, JText::sprintf('COM_EASYBLOG_EASYDISCUSS_HISTORY_NEW_BLOG', $this->title));
         EasyBlogHelper::getHelper('EasyDiscuss')->addPoint('easyblog.new.blog', $this->created_by);
         EasyBlogHelper::getHelper('EasyDiscuss')->addBadge('easyblog.new.blog', $this->created_by);
         // Assign badge for users that report blog post.
         // Only give points if the viewer is viewing another person's blog post.
         EasyBlogHelper::getHelper('EasySocial')->assignBadge('blog.create', JText::_('COM_EASYBLOG_EASYSOCIAL_BADGE_CREATE_BLOG_POST'));
         if ($config->get('integrations_easydiscuss_notification_blog')) {
             // Get list of users who subscribed to this blog.
             $target = $this->getRegisteredSubscribers('new', array($this->created_by));
             EasyBlogHelper::getHelper('EasyDiscuss')->addNotification($this, JText::sprintf('COM_EASYBLOG_EASYDISCUSS_NOTIFICATIONS_NEW_BLOG', $author->getName(), $this->title), EBLOG_NOTIFICATIONS_TYPE_BLOG, $target, $this->created_by, $link);
         }
         $my = JFactory::getUser();
         // @rule: Add points for AlphaUserPoints
         if ($my->id == $this->created_by && EasyBlogHelper::isAUPEnabled()) {
             // get blog post URL
             $url = EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $this->id);
             $aupid = AlphaUserPointsHelper::getAnyUserReferreID($this->created_by);
             AlphaUserPointsHelper::newpoints('plgaup_easyblog_add_blog', $aupid, 'easyblog_add_blog_' . $this->id, JText::sprintf('COM_EASYBLOG_AUP_NEW_BLOG_CREATED', $url, $this->title));
         }
         // @rule: Process trackbacks
         $this->processTrackbacks();
         // Update the isnew column so that if user edits this entry again, it doesn't send any notifications the second time.
         $this->isnew = 0;
         $this->store(false);
     }
     return $state;
 }
Ejemplo n.º 2
0
 /**
  * Toggle featured bloggers.
  *
  * @since	3.5
  * @access	public
  */
 public function toggleFeatured()
 {
     // Check for request forgeries
     JRequest::checkToken() or jexit('Invalid Token');
     // @task: Check for acl rules.
     $this->checkAccess('user');
     $mainframe = JFactory::getApplication();
     $records = JRequest::getVar('cid', '');
     $message = '';
     $task = JRequest::getVar('task');
     if (empty($records)) {
         $mainframe->enqueueMessage(JText::_('COM_EASYBLOG_INVALID_BLOGGER_ID'), 'error');
         $mainframe->redirect('index.php?option=com_easyblog&view=users');
         $mainframe->close();
     }
     foreach ($records as $record) {
         if ($task == 'unfeature') {
             EasyBlogHelper::removeFeatured(EBLOG_FEATURED_BLOGGER, $record);
             $message = JText::_('COM_EASYBLOG_BLOGGER_UNFEATURED_SUCCESSFULLY');
         } else {
             EasyBlogHelper::makeFeatured(EBLOG_FEATURED_BLOGGER, $record);
             $message = JText::_('COM_EASYBLOG_BLOGGER_FEATURED_SUCCESSFULLY');
         }
     }
     $mainframe->enqueueMessage($message, 'message');
     $mainframe->redirect('index.php?option=com_easyblog&view=users');
     $mainframe->close();
 }
Ejemplo n.º 3
0
 /**
  * Mark an item as featured
  *
  * @param	string	$type	The type of this item
  * @param	int		$postId	The unique id of the item
  *
  * @return	string	Json string
  **/
 function makeFeatured($type, $postId)
 {
     $ajax = new Ejax();
     $config = EasyBlogHelper::getConfig();
     $acl = EasyBlogACLHelper::getRuleset();
     // Only super admins can feature items
     if (!EasyBlogHelper::isSiteAdmin() && !$acl->rules->feature_entry) {
         $ajax->alert(JText::_('COM_EASYBLOG_NOT_ALLOWED'), '', '450');
         $ajax->send();
         return;
     }
     // Only non protected blog can be feature
     if ($config->get('main_password_protect')) {
         $blog = EasyBlogHelper::getTable('Blog', 'Table');
         $blog->load($postId);
         if (!empty($blog->blogpassword)) {
             $ajax->alert(JText::_('COM_EASYBLOG_PASSWORD_PROTECTED_CANNOT_BE_FEATURED'), '', '450');
             $ajax->send();
             return;
         }
     }
     EasyBlogHelper::makeFeatured($type, $postId);
     $idName = '';
     $message = '';
     switch ($type) {
         case 'blogger':
             $idName = '#blogger_title_' . $postId;
             $message = JText::_('COM_EASYBLOG_BLOGGER_FEATURED');
             break;
         case 'teamblog':
             $idName = '#teamblog_title_' . $postId;
             $message = JText::_('COM_EASYBLOG_TEAMBLOG_FEATURED');
             break;
         case 'post':
         default:
             $idName = '#title_' . $postId;
             $message = JText::_('COM_EASYBLOG_BLOG_FEATURED');
             break;
     }
     $ajax->alert($message, JText::_('COM_EASYBLOG_INFO'), '450', 'auto');
     $ajax->send();
     return;
 }
Ejemplo n.º 4
0
 function _process($authorId, $stateId, $catId, $sectionId, $myblogSection, $jomcomment = false)
 {
     $db = EasyBlogHelper::db();
     $jSession = JFactory::getSession();
     $ejax = new EJax();
     $migrateStat = $jSession->get('EBLOG_MIGRATOR_JOOMLA_STAT', '', 'EASYBLOG');
     if (empty($migrateStat)) {
         $migrateStat = new stdClass();
         $migrateStat->blog = 0;
         $migrateStat->category = 0;
         $migrateStat->user = array();
     }
     $query = 'SELECT * FROM `#__content` AS a';
     $query .= ' WHERE NOT EXISTS (';
     $query .= ' SELECT content_id FROM `#__easyblog_migrate_content` AS b WHERE b.`content_id` = a.`id` and `component` = ' . $db->Quote('com_content');
     $query .= ' )';
     if ($authorId != '0') {
         $query .= ' AND a.`created_by` = ' . $db->Quote($authorId);
     }
     if ($stateId != '*') {
         switch ($stateId) {
             case 'P':
                 $query .= ' AND a.`state` = ' . $db->Quote('1');
                 break;
             case 'U':
                 $query .= ' AND a.`state` = ' . $db->Quote('0');
                 break;
             case 'A':
                 $query .= ' AND a.`state` = ' . $db->Quote('-1');
                 break;
                 // joomla 1.6 compatibility
             // joomla 1.6 compatibility
             case '1':
                 // publish
                 $query .= ' AND a.`state` = ' . $db->Quote('1');
                 break;
             case '0':
                 //unpublish
                 $query .= ' AND a.`state` = ' . $db->Quote('0');
                 break;
             case '2':
                 // archive
                 $query .= ' AND a.`state` = ' . $db->Quote('2');
                 break;
             case '-2':
                 // trash
                 $query .= ' AND a.`state` = ' . $db->Quote('-2');
                 break;
             default:
                 break;
         }
     }
     if ($sectionId != '-1') {
         $query .= ' AND a.`sectionid` = ' . $db->Quote($sectionId);
     }
     // we do not want the myblog post process here.
     if ($myblogSection != '') {
         $query .= ' AND a.`sectionid` != ' . $db->Quote($myblogSection);
     }
     if ($catId != '0') {
         $query .= ' AND a.`catid` = ' . $db->Quote($catId);
     }
     $query .= ' ORDER BY a.`id` LIMIT 1';
     $db->setQuery($query);
     $row = $db->loadObject();
     if (is_null($row)) {
         //at here, we check whether there are any records processed. if yes,
         //show the statistic.
         $ejax->append('progress-status', JText::_('COM_EASYBLOG_MIGRATOR_FINISHED'));
         $ejax->script("divSrolltoBottom();");
         //update statistic
         $stat = '========================================== <br />';
         $stat .= JText::_('COM_EASYBLOG_MIGRATOR_JOOMLA_TOTAL_ARTICLE') . ' : ' . $migrateStat->blog . '<br />';
         $stat .= JText::_('COM_EASYBLOG_MIGRATOR_JOOMLA_TOTAL_CATEGORY') . ' : ' . $migrateStat->category . '<br />';
         $statUser = $migrateStat->user;
         if (!empty($statUser)) {
             $stat .= '<br />';
             $stat .= JText::_('COM_EASYBLOG_MIGRATOR_TOTAL_USER_CONTRIBUTIONS') . ' : ' . count($statUser) . '<br />';
             foreach ($statUser as $eachUser) {
                 $stat .= JText::_('COM_EASYBLOG_MIGRATOR_TOTAL_ARTICLES_USER') . ' \'' . $eachUser->name . '\': ' . $eachUser->blogcount . '<br />';
             }
         }
         $stat .= '<br />==========================================';
         $ejax->assign('stat-status', $stat);
         $ejax->script("\$( '#migrator-submit' ).html('" . JText::_('COM_EASYBLOG_MIGRATOR_MIGRATION_COMPLETED') . "');");
         $ejax->script("\$( '#migrator-submit' ).attr('disabled' , '');");
         $ejax->script("\$( '#icon-wait' ).css( 'display' , 'none' );");
     } else {
         // here we should process the migration
         // step 1 : create categery if not exist in eblog_categories
         // step 2 : create user if not exists in eblog_users - create user through profile jtable load method.
         $date = EasyBlogHelper::getDate();
         $blogObj = new stdClass();
         //default
         $blogObj->category_id = 1;
         //assume 1 is the uncategorized id.
         if (!empty($row->catid)) {
             $joomlaCat = $this->_getJoomlaCategory($row->catid);
             $eCat = $this->_isEblogCategoryExists($joomlaCat);
             if ($eCat === false) {
                 $eCat = $this->_createEblogCategory($joomlaCat);
             }
             $blogObj->category_id = $eCat;
         }
         $profile = EasyBlogHelper::getTable('Profile', 'Table');
         $blog = EasyBlogHelper::getTable('Blog', 'Table');
         //load user profile
         $profile->load($row->created_by);
         //assigning blog data
         $blogObj->created_by = $profile->id;
         $blogObj->created = !empty($row->created) ? $row->created : $date->toMySQL();
         $blogObj->modified = $date->toMySQL();
         $blogObj->title = $row->title;
         $blogObj->permalink = $row->alias;
         // Need to remap the access.
         $access = 0;
         if (EasyBlogHelper::getJoomlaVersion() >= '1.6') {
             switch ($row->access) {
                 case 1:
                     $access = 0;
                     break;
                 default:
                     $access = 1;
                     break;
             }
         } else {
             $access = $row->access == 2 ? 1 : $row->access;
         }
         $blogObj->private = $access;
         if (empty($row->fulltext)) {
             $blogObj->intro = '';
             $blogObj->content = $row->introtext;
         } else {
             $blogObj->intro = $row->introtext;
             $blogObj->content = $row->fulltext;
         }
         // joomla 3.0 intro imag properties.
         if (isset($row->images) && !empty($row->images)) {
             $joomlaImages = json_decode($row->images);
             if (isset($joomlaImages->image_intro) and !empty($joomlaImages->image_intro)) {
                 $imgTag = '<img';
                 if ($joomlaImages->image_intro_caption) {
                     $imgTag .= ' class="caption" title="' . htmlspecialchars($joomlaImages->image_intro_caption) . '"';
                 }
                 $imgTag .= ' src="' . htmlspecialchars($joomlaImages->image_intro) . '" alt="' . htmlspecialchars($joomlaImages->image_intro_alt) . '"/>';
                 $blogObj->intro = $imgTag . $blogObj->intro;
             }
             if (isset($joomlaImages->image_fulltext) and !empty($joomlaImages->image_fulltext)) {
                 $imgTag = '<img';
                 if ($joomlaImages->image_fulltext_caption) {
                     $imgTag .= ' class="caption" title="' . htmlspecialchars($joomlaImages->image_fulltext_caption) . '"';
                 }
                 $imgTag .= ' src="' . htmlspecialchars($joomlaImages->image_fulltext) . '" alt="' . htmlspecialchars($joomlaImages->image_fulltext_alt) . '"/>';
                 $blogObj->content = $imgTag . $blogObj->content;
             }
         }
         //translating the article state into easyblog publish status.
         $blogState = '';
         if (EasyBlogHelper::getJoomlaVersion() >= '1.6') {
             $blogState = $row->state == 2 || $row->state == -2 ? 0 : $row->state;
         } else {
             $blogState = $row->state == -1 ? 0 : $row->state;
         }
         $blogObj->published = $blogState;
         $blogObj->publish_up = !empty($row->publish_up) ? $row->publish_up : $date->toMySQL();
         $blogObj->publish_down = !empty($row->publish_down) ? $row->publish_down : $date->toMySQL();
         $blogObj->ordering = $row->ordering;
         $blogObj->hits = $row->hits;
         $blogObj->frontpage = 1;
         $blog->bind($blogObj);
         $blog->store();
         // Run jomcomment migration here.
         if ($jomcomment) {
             $this->migrateJomcomment($row->id, $blog->id, 'com_content');
         }
         //migrate meta description
         $this->_migrateContentMeta($row->metakey, $row->metadesc, $blog->id);
         //isfeatured! only applicable in joomla1.6
         if (EasyBlogHelper::getJoomlaVersion() >= '1.6') {
             if ($row->featured) {
                 EasyBlogHelper::makeFeatured('post', $blog->id);
             }
         }
         //update session value
         $migrateStat->blog++;
         $statUser = $migrateStat->user;
         $statUserObj = null;
         if (!isset($statUser[$profile->id])) {
             $statUserObj = new stdClass();
             $statUserObj->name = $profile->nickname;
             $statUserObj->blogcount = 0;
         } else {
             $statUserObj = $statUser[$profile->id];
         }
         $statUserObj->blogcount++;
         $statUser[$profile->id] = $statUserObj;
         $migrateStat->user = $statUser;
         $jSession->set('EBLOG_MIGRATOR_JOOMLA_STAT', $migrateStat, 'EASYBLOG');
         //log the entry into migrate table.
         $migrator = EasyBlogHelper::getTable('Migrate', 'Table');
         $migrator->content_id = $row->id;
         $migrator->post_id = $blog->id;
         $migrator->session_id = $jSession->getToken();
         $migrator->component = 'com_content';
         $migrator->store();
         $ejax->append('progress-status', JText::_('COM_EASYBLOG_MIGRATOR_MIGRATED_JOOMLA_ARTICLE') . ': ' . $row->id . JText::_('COM_EASYBLOG_MIGRATOR_EASYBLOG') . ': ' . $blog->id . '<br />');
         $ejax->script("ejax.load('migrators','_process','{$authorId}', '{$stateId}', '{$catId}', '{$sectionId}', '{$myblogSection}','{$jomcomment}');");
     }
     $ejax->send();
 }