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; }
public static function addJomsocialActivities($blog, $isNew) { EasyBlogHelper::addJomSocialActivityBlog($blog, $isNew); }
function import($feedObj, $maxItems = 0) { jimport('simplepie.simplepie'); $config = EasyBlogHelper::getConfig(); $itemMigrated = 0; $isDomSupported = false; $defaultAllowedHTML = '<img>,<a>,<br>,<table>,<tbody>,<th>,<tr>,<td>,<div>,<span>,<p>,<h1>,<h2>,<h3>,<h4>,<h5>,<h6>'; if (class_exists('DomDocument')) { $isDomSupported = true; require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'readability' . DIRECTORY_SEPARATOR . 'Readability.php'; } $params = EasyBlogHelper::getRegistry($feedObj->params); $maxItems = $maxItems ? $maxItems : $params->get('feedamount', 0); $feedURL = $feedObj->url; require_once EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'connectors.php'; $connector = new EasyBlogConnectorsHelper(); $connector->addUrl($feedURL); $connector->execute(); $content = $connector->getResult($feedURL); // to ensure the leading no text before the <?xml> tag //$pattern = '/(.*?)(?=<\?xml)/ims'; $pattern = '/(.*?)<\\?xml version/is'; $replacement = '<?xml version'; $content = preg_replace($pattern, $replacement, $content, 1); if (strpos($content, '<?xml version') === false) { // look like the content missing the xml header. lets manually add in. $content = '<?xml version="1.0" encoding="utf-8"?>' . $content; } $parser = new SimplePie(); $parser->strip_htmltags(false); $parser->set_raw_data($content); $parser->init(); $items = ''; $items = $parser->get_items(); if (count($items) > 0) { //lets process the data insert $myCnt = 0; foreach ($items as $item) { @ini_set('max_execution_time', 180); if (!empty($maxItems) && $myCnt == $maxItems) { break; } $timezoneSec = $item->get_date('Z'); $itemdate = $item->get_date('U'); $itemdate = $itemdate - $timezoneSec; $mydate = date('Y-m-d H:i:s', $itemdate); $feedUid = $item->get_id(); $feedPath = $item->get_link(); $feedHistory = EasyBlogHelper::getTable('FeedHistory'); $newHistoryId = ''; if ($feedHistory->isExists($feedObj->id, $feedUid)) { continue; } else { //log the feed item so that in future it will not process again. $date = EasyBlogHelper::getDate(); $newHistory = EasyBlogHelper::getTable('FeedHistory'); $newHistory->feed_id = $feedObj->id; $newHistory->uid = $feedUid; $newHistory->created = $date->toMySQL(); $newHistory->store(); $newHistoryId = $newHistory->id; } $blogObj = new stdClass(); // set the default setting from the feed configuration via backend. $blogObj->category_id = $feedObj->item_category; $blogObj->published = $feedObj->item_published; $blogObj->frontpage = $feedObj->item_frontpage; $blogObj->created_by = $feedObj->item_creator; $blogObj->allowcomment = $config->get('main_comment', 1); $blogObj->subscription = $config->get('main_subscription', 1); $blogObj->issitewide = '1'; $text = $item->get_content(); // @rule: Append copyright text $blogObj->copyrights = $params->get('copyrights', ''); if ($feedObj->item_get_fulltext && $isDomSupported) { $feedItemUrl = urldecode($item->get_link()); $fiConnector = new EasyBlogConnectorsHelper(); $fiConnector->addUrl($feedItemUrl); $fiConnector->execute(); $fiContent = $fiConnector->getResult($feedItemUrl); // to ensure the leading no text before the <?xml> tag $pattern = '/(.*?)<html/is'; $replacement = '<html'; $fiContent = preg_replace($pattern, $replacement, $fiContent, 1); if (!empty($fiContent)) { $fiContent = EasyBlogHelper::getHelper('string')->forceUTF8($fiContent); $readability = new Readability($fiContent); $readability->debug = false; $readability->convertLinksToFootnotes = false; $result = $readability->init(); if ($result) { $content = $readability->getContent()->innerHTML; //$content = EasyBlogHelper::getHelper( 'string' )->fixUTF8( $content ); $content = EasyBlogFeedsHelper::tidyContent($content); if (stristr(html_entity_decode($content), '<!DOCTYPE html') === false) { $text = $content; $text = $this->_processRelLinktoAbs($text, $feedPath); } } } } // strip un-allowed html tag. $text = strip_tags($text, $params->get('allowed', $defaultAllowedHTML)); // Append original source link into article if necessary if ($params->get('sourceLinks')) { JFactory::getLanguage()->load('com_easyblog', JPATH_ROOT); $text .= '<div><a href="' . $item->get_link() . '" target="_blank">' . JText::_('COM_EASYBLOG_FEEDS_ORIGINAL_LINK') . '</a></div>'; } if ($feedObj->author) { $feedAuthor = $item->get_author(); if (!empty($feedAuthor)) { $authorName = $feedAuthor->get_name(); $authorEmail = $feedAuthor->get_email(); if (!empty($authorName)) { // Store it as copyright column instead $text .= '<div>' . JText::sprintf('COM_EASYBLOG_FEEDS_ORIGINAL_AUTHOR', $authorName) . '</div>'; } else { if (!empty($authorEmail)) { $authorArr = explode(' ', $authorEmail); if (isset($authorArr[1])) { $authorName = $authorArr[1]; $authorName = str_replace(array('(', ')'), '', $authorName); $text .= '<div>' . JText::sprintf('COM_EASYBLOG_FEEDS_ORIGINAL_AUTHOR', $authorName) . '</div>'; } } } } } if ($feedObj->item_content == 'intro') { $blogObj->intro = $text; } else { $blogObj->content = $text; } $creationDate = $mydate; $blogObj->created = $mydate; $blogObj->modified = $mydate; $blogObj->title = $item->get_title(); if (empty($blogObj->title)) { $blogObj->title = $this->_getTitleFromLink($item->get_link()); } $blogObj->title = EasyBlogStringHelper::unhtmlentities($blogObj->title); $blogObj->permalink = EasyBlogHelper::getPermalink($blogObj->title); $blogObj->publish_up = $mydate; $blogObj->isnew = !$feedObj->item_published ? true : false; $blog = EasyBlogHelper::getTable('blog'); $blog->bind($blogObj); if ($feedObj->item_published) { $blog->notify(); } if ($blog->store()) { $myCnt++; //update the history with blog id if (!empty($newHistoryId)) { $tmpHistory = EasyBlogHelper::getTable('FeedHistory'); $tmpHistory->load($newHistoryId); $tmpHistory->post_id = $blog->id; $tmpHistory->store(); } $itemMigrated++; if ($feedObj->item_published) { //insert activity here. EasyBlogHelper::addJomSocialActivityBlog($blog, true, true); // Determines if admin wants to auto post this item to the social sites. if ($params->get('autopost')) { $allowed = array(EBLOG_OAUTH_LINKEDIN, EBLOG_OAUTH_FACEBOOK, EBLOG_OAUTH_TWITTER); // @rule: Process centralized options first // See if there are any global postings enabled. $blog->autopost($allowed, $allowed); } } } //end if } } return $itemMigrated; }