public static function getLink($type, $id) { if (empty($type) || empty($id)) { return false; } //prevent jtable is not loading incase overwritten by other component. JTable::addIncludePath(EBLOG_TABLES); $oauth = EB::table('Oauth'); $oauth->loadByUser($id, $type); $param = EB::registry($oauth->params); $screenName = $param->get('screen_name', ''); $acl = EB::acl($id); $rule = 'update_' . $type; if (!$acl->get($rule)) { return false; } switch ($type) { case 'twitter': $link = empty($screenName) ? '' : 'http://twitter.com/' . $screenName; break; case 'facebook': $link = ''; break; case 'linkedin': $link = ''; break; } return $link; }
/** 1.5 **/ public function onSearch($text, $phrase = '', $ordering = '', $areas = null) { $plugin = JPluginHelper::getPlugin('search', 'easyblog'); $params = EB::registry($plugin->params); if (!plgSearchEasyblog::exists()) { return array(); } if (is_array($areas)) { if (!array_intersect($areas, array_keys(plgSearchEasyblog::onContentSearchAreas()))) { return array(); } } $text = trim($text); if ($text == '') { return array(); } $result = plgSearchEasyblog::getResult($text, $phrase, $ordering); if (!$result) { return array(); } // require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'router.php' ); foreach ($result as $row) { $row->section = plgSearchEasyblog::getCategory($row->category_id); $row->section = JText::sprintf('PLG_EASYBLOG_SEARCH_BLOGS_SECTION', $row->section); $row->href = EBR::_('index.php?option=com_easyblog&view=entry&id=' . $row->id); $blog = EB::table('Blog'); $blog->bind($row); if ($blog->getImage()) { $row->image = $blog->getImage('frontpage'); } } return $result; }
public function getParams($name = '', $contents = '', $manifestFile, $xpath = false) { $this->form = new JForm($name); if ($xpath == 'params') { $xpath = 'config/fields'; } $this->form->loadFile($manifestFile, true, $xpath); $config = EB::table('Configs'); $config->load($name); $params = new JRegistry($config->params); $registry = EB::registry($contents); $this->form->bind($registry->toArray()); }
public function trigger($event, &$row) { $params = EB::registry(); $limitstart = $this->input->get('limitstart', 0, 'int'); $dispatcher = JDispatcher::getInstance(); // Need to make this behave like how Joomla category behaves. if (!isset($row->catid)) { $row->catid = $row->category_id; } if (!isset($this->events[$event])) { return false; } $result = $dispatcher->trigger($this->events[$event], array('easyblog.blog', &$row, &$params, $limitstart)); // Remove unwanted fields. unset($row->catid); return $result; }
public static function getBloggerTheme() { $id = EasyBlogRouter::isBloggerMode(); if (empty($id)) { return false; } $profile = EB::user($id); $userparams = EB::registry($profile->params); return $userparams->get('theme', false); }
public static function getItemIdByEntry($blogId) { static $entriesItems = null; if (!isset($entriesItems[$blogId])) { $db = EasyBlogHelper::db(); // We need to check against the correct latest entry to be used based on the category this article is in $query = 'SELECT ' . $db->nameQuote('id') . ',' . $db->nameQuote('params') . ' FROM ' . $db->nameQuote('#__menu') . 'WHERE ' . $db->nameQuote('link') . '=' . $db->Quote('index.php?option=com_easyblog&view=latest') . 'AND ' . $db->nameQuote('published') . '=' . $db->Quote('1') . EBR::getLanguageQuery(); $db->setQuery($query); $menus = $db->loadObjectList(); $blog = EB::table('Blog'); $blog->load($blogId); if ($menus) { foreach ($menus as $menu) { $params = EB::registry($menu->params); $inclusion = EasyBlogHelper::getCategoryInclusion($params->get('inclusion')); if (empty($inclusion)) { continue; } if (!is_array($inclusion)) { $inclusion = array($inclusion); } if (in_array($blog->category_id, $inclusion)) { $entriesItems[$blogId] = $menu->id; } } } // Test if there is any entry specific view as this will always override the latest above. $query = 'SELECT ' . $db->nameQuote('id') . ' FROM ' . $db->nameQuote('#__menu') . ' ' . 'WHERE ' . $db->nameQuote('link') . '=' . $db->Quote('index.php?option=com_easyblog&view=entry&id=' . $blogId) . ' ' . 'AND ' . $db->nameQuote('published') . '=' . $db->Quote('1') . EBR::getLanguageQuery() . ' LIMIT 1'; $db->setQuery($query); $itemid = $db->loadResult(); if ($itemid) { $entriesItems[$blogId] = $itemid; } else { // this is to check if we used category menu item from this post or not. // if yes, we do nothing. if not, we need to update the cache object so that the next checking will // not execute sql again. if (isset($entriesItems[$blogId])) { return $entriesItems[$blogId]; } else { $entriesItems[$blogId] = ''; } } } return $entriesItems[$blogId]; }
function save() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); // @task: Check for acl rules. $this->checkAccess('user'); $mainframe = JFactory::getApplication(); $db = EasyBlogHelper::db(); $my = JFactory::getUser(); $acl = JFactory::getACL(); $config = EasyBlogHelper::getConfig(); // Create a new JUser object $user = JFactory::getUser(JRequest::getVar('id', 0, 'post', 'int')); $original_gid = $user->get('gid'); $post = JRequest::get('post'); $post['username'] = JRequest::getVar('username', '', 'post', 'username'); $post['password'] = JRequest::getVar('password', '', 'post', 'string', JREQUEST_ALLOWRAW); $post['password2'] = JRequest::getVar('password2', '', 'post', 'string', JREQUEST_ALLOWRAW); if (EasyBlogHelper::getJoomlaVersion() >= '1.6') { $jformPost = JRequest::getVar('jform', array(), 'post', 'array'); $post['params'] = $jformPost['params']; } if (!$user->bind($post)) { EasyBlogHelper::storeSession($post, 'EASYBLOG_REGISTRATION_POST'); $mainframe->enqueueMessage($user->getError(), 'error'); $this->_saveError($user->id); } if (EasyBlogHelper::getJoomlaVersion() >= '1.6') { if ($user->get('id') == $my->get('id') && $user->get('block') == 1) { $mainframe->enqueueMessage(JText::_('You cannot block Yourself!'), 'error'); $this->_saveError($user->id); } else { if ($user->authorise('core.admin') && $user->get('block') == 1) { $mainframe->enqueueMessage(JText::_('You cannot block a Super User'), 'error'); $this->_saveError($user->id); } else { if ($user->authorise('core.admin') && !$my->authorise('core.admin')) { $mainframe->enqueueMessage(JText::_('You cannot edit a Super User account'), 'message'); $this->_saveError($user->id); } } } //replacing thr group name with group id so it is save correctly into the Joomla group table. $jformPost = JRequest::getVar('jform', array(), 'post', 'array'); if (!empty($jformPost['groups'])) { $user->groups = array(); foreach ($jformPost['groups'] as $groupid) { $user->groups[$groupid] = $groupid; } } } else { $objectID = $acl->get_object_id('users', $user->get('id'), 'ARO'); $groups = $acl->get_object_groups($objectID, 'ARO'); $this_group = strtolower($acl->get_group_name($groups[0], 'ARO')); if ($user->get('id') == $my->get('id') && $user->get('block') == 1) { $mainframe->enqueueMessage(JText::_('You cannot block Yourself!'), 'error'); $this->_saveError($user->id); } else { if ($this_group == 'super administrator' && $user->get('block') == 1) { $mainframe->enqueueMessage(JText::_('You cannot block a Super Administrator'), 'error'); $this->_saveError($user->id); } else { if ($this_group == 'administrator' && $my->get('gid') == 24 && $user->get('block') == 1) { $mainframe->enqueueMessage(JText::_('WARNBLOCK'), 'error'); $this->_saveError($user->id); } else { if ($this_group == 'super administrator' && $my->get('gid') != 25) { $mainframe->enqueueMessage(JText::_('You cannot edit a super administrator account'), 'message'); $this->_saveError($user->id); } } } } } // Are we dealing with a new user which we need to create? $isNew = $user->get('id') < 1; if (EasyBlogHelper::getJoomlaVersion() <= '1.5') { // do this step only for J1.5 if (!$isNew) { // if group has been changed and where original group was a Super Admin if ($user->get('gid') != $original_gid && $original_gid == 25) { // count number of active super admins $query = 'SELECT COUNT( id )' . ' FROM #__users' . ' WHERE gid = 25' . ' AND block = 0'; $db->setQuery($query); $count = $db->loadResult(); if ($count <= 1) { // disallow change if only one Super Admin exists $this->setRedirect('index.php?option=com_users', JText::_('WARN_ONLY_SUPER')); return false; } } } } if (!$user->save()) { $mainframe->enqueueMessage($user->getError(), 'error'); return $this->execute('edit'); } // If updating self, load the new user object into the session if (EasyBlogHelper::getJoomlaVersion() <= '1.5') { if ($user->get('id') == $my->get('id')) { // Get an ACL object $acl = JFactory::getACL(); // Get the user group from the ACL $grp = $acl->getAroGroup($user->get('id')); // Mark the user as logged in $user->set('guest', 0); $user->set('aid', 1); // Fudge Authors, Editors, Publishers and Super Administrators into the special access group if ($acl->is_group_child_of($grp->name, 'Registered') || $acl->is_group_child_of($grp->name, 'Public Backend')) { $user->set('aid', 2); } // Set the usertype based on the ACL group name $user->set('usertype', $grp->name); $session = JFactory::getSession(); $session->set('user', $user); } } else { // Update session data if the current user was updated if ($user->get('id') == $my->get('id')) { $session = JFactory::getSession(); $session->set('user', $user); // Force load from database } } $post = JRequest::get('post'); if ($isNew) { unset($post['id']); } $post['permalink'] = $post['user_permalink']; unset($post['user_permalink']); if (EasyBlogHelper::isSiteAdmin()) { $post['description'] = JRequest::getVar('description', '', 'POST', '', JREQUEST_ALLOWRAW); $post['biography'] = JRequest::getVar('biography', '', 'POST', '', JREQUEST_ALLOWRAW); } $blogger = EB::user($user->id); $blogger->bind($post); $file = JRequest::getVar('Filedata', '', 'Files', 'array'); if (!empty($file['name'])) { $newAvatar = EasyBlogHelper::uploadAvatar($blogger, true); $blogger->avatar = $newAvatar; } //save params $userparams = EB::registry(); // @rule: Save google profile url if (isset($post['google_profile_url'])) { $userparams->set('google_profile_url', $post['google_profile_url']); } if (isset($post['show_google_profile_url'])) { $userparams->set('show_google_profile_url', $post['show_google_profile_url']); } $blogger->params = $userparams->toString(); $blogger->store(); JTable::addIncludePath(EBLOG_TABLES); //save twitter info. $twitter = EB::table('Oauth'); $twitter->loadByUser($user->id, EBLOG_OAUTH_TWITTER); $twitter->auto = JRequest::getVar('integrations_twitter_auto'); $twitter->message = JRequest::getVar('integrations_twitter_message'); if (!$twitter->store()) { $mainframe->enqueueMessage(JText::_('COM_EASYBLOG_INTEGRATIONS_TWITTER_ERROR'), 'error'); } // Map linkedin items $linkedin = EB::table('Oauth'); $linkedin->loadByUser($user->id, EBLOG_OAUTH_LINKEDIN); $linkedin->auto = JRequest::getVar('integrations_linkedin_auto'); $linkedin->message = JRequest::getVar('integrations_linkedin_message'); $linkedin->private = JRequest::getVar('integrations_linkedin_private'); if (!$linkedin->store()) { $mainframe->enqueueMessage(JText::_('COM_EASYBLOG_INTEGRATIONS_LINKEDIN_ERROR'), 'error'); } // store faebook info $facebook = EB::table('Oauth'); $facebook->loadByUser($user->id, EBLOG_OAUTH_FACEBOOK); $facebook->auto = JRequest::getVar('integrations_facebook_auto'); $facebook->message = ''; if (!$facebook->store()) { $mainframe->enqueueMessage(JText::_('COM_EASYBLOG_INTEGRATIONS_FACEBOOK_FAILED_UPDATE_INFO_ERROR'), 'error'); } if ($config->get('integration_google_adsense_enable')) { // Store adsense data $adsense = EB::table('Adsense'); $adsense->load($user->id); $adsense->code = $post['adsense_code']; $adsense->display = $post['adsense_display']; $adsense->published = $post['adsense_published']; $adsense->store(); } // Store feedburner data $feedburner = EB::table('Feedburner'); $feedburner->load($user->id); $feedburner->url = $post['feedburner_url']; $feedburner->store(); $this->_saveSuccess($user->id); }
/** * Displays the latest entry on the site using the entry view * * @since 5.0 * @access public * @param string * @return */ public function latest() { // Fetch the latest blog entry $model = EB::model('Blog'); // Get the current active menu's properties. $app = JFactory::getApplication(); $menu = $app->getMenu()->getActive(); $inclusion = ''; if (is_object($menu)) { $params = EB::registry($menu->params); $inclusion = EB::getCategoryInclusion($params->get('inclusion')); } $items = $model->getBlogsBy('latest', 0, '', 1, EBLOG_FILTER_PUBLISHED, null, true, array(), false, false, true, array(), $inclusion); if (is_array($items) && !empty($items)) { JRequest::setVar('id', $items[0]->id); return $this->display(); } echo JText::_('COM_EASYBLOG_NO_BLOG_ENTRY'); }
/** * This will be a callback from the oauth client. * @param null * @return null **/ public function grant() { $type = JRequest::getCmd('type'); $userId = JRequest::getVar('id'); $mainframe = JFactory::getApplication(); $config = EasyBlogHelper::getConfig(); $key = $config->get('integrations_' . $type . '_api_key'); $secret = $config->get('integrations_' . $type . '_secret_key'); $my = JFactory::getUser($userId); $redirect = JRequest::getVar('redirect', ''); $redirectUri = !empty($redirect) ? '&redirect=' . $redirect : ''; // @task: Let's see if caller wants us to go to any specific location or not. if (!empty($redirect)) { $redirect = base64_decode($redirect); } if (!EasyBlogHelper::isLoggedIn()) { $mainframe->enqueueMessage(JText::_('COM_EASYBLOG_YOU_MUST_LOGIN_FIRST'), 'error'); $this->setRedirect(JRoute::_('index.php?option=com_easyblog&view=users', false)); return; } $oauth = EB::table('Oauth'); $loaded = $oauth->loadByUser($my->id, $type); $denied = JRequest::getVar('denied', ''); $call = JRequest::getWord('call'); $callUri = !empty($call) ? '&call=' . $call . '&id=' . $my->id : '&id=' . $my->id; if (!empty($denied)) { $oauth->delete(); $mainframe->enqueueMessage(JText::_('COM_EASYBLOG_OAUTH_DENIED_ERROR'), 'error'); $redirect = JRoute::_('index.php?option=com_easyblog&view=users', false); $this->setRedirect($redirect, false); return; } if (!$loaded) { $mainframe->enqueueMessage(JText::_('COM_EASYBLOG_OAUTH_UNABLE_TO_LOCATE_RECORD'), 'error'); $redirect = JRoute::_('index.php?option=com_easyblog&view=users', false); $this->setRedirect($redirect, false); return; } $request = EB::registry($oauth->request_token); $callback = rtrim(JURI::root(), '/') . '/administrator/index.php?option=com_easyblog&c=oauth&task=grant&type=' . $type . $redirect . $callUri; $consumer = EasyBlogOauthHelper::getConsumer($type, $key, $secret, $callback); $verifier = $consumer->getVerifier(); if (empty($verifier)) { // Since there is a problem with the oauth authentication, we need to delete the existing record. $oauth->delete(); JError::raiseError(500, JText::_('COM_EASYBLOG_INVALID_VERIFIER_CODE')); } $access = $consumer->getAccess($request->get('token'), $request->get('secret'), $verifier); if (!$access || empty($access->token) || empty($access->secret)) { // Since there is a problem with the oauth authentication, we need to delete the existing record. $oauth->delete(); $mainframe->enqueueMessage(JText::_('COM_EASYBLOG_OAUTH_ACCESS_TOKEN_ERROR'), 'error'); $this->setRedirect($redirect, false); return; } $param = EB::registry(); $param->set('token', $access->token); $param->set('secret', $access->secret); if (isset($access->expires)) { $param->set('expires', $access->expires); } $oauth->access_token = $param->toString(); $oauth->params = $access->params; $oauth->store(); $mainframe->enqueueMessage(JText::_('Application revoked successfully.')); $url = JRoute::_('index.php?option=com_easyblog&c=user&id=' . $my->id . '&task=edit', false); if (!empty($redirect)) { $url = $redirect; } // @task: Let's see if the oauth client if (!empty($call)) { $consumer->{$call}(); } else { $this->setRedirect($url); } }
/** * Responsible to receive the incoming redirection from the respective oauth sites * * @since 4.0 * @access public * @param string * @return */ public function grant() { // Ensure that the user is logged in EB::requireLogin(); // Default redirect url $return = EBR::_('index.php?option=com_easyblog&view=dashboard&layout=profile', false); // Get the client $client = $this->input->get('client', '', 'cmd'); // Get the redirection url $redirect = $this->input->get('redirect', '', 'default'); // Get the redirection url $redirectUri = !empty($redirect) ? '&redirect=' . $redirect : ''; // Let's see if caller wants us to go to any specific location or not. if ($redirect) { $redirect = base64_decode($redirect); } // Load the oauth object $table = EB::table('OAuth'); $table->loadByUser($this->my->id, $client); if (!$table->id) { $this->info->set('COM_EASYBLOG_OAUTH_UNABLE_TO_LOCATE_RECORD', 'error'); return $this->app->redirect($return); } // Detect if there's any errors $denied = $this->input->get('denied', '', 'default'); // When there's an error, delete the oauth data if ($denied) { $table->delete(); $this->info->set('COM_EASYBLOG_OAUTH_DENIED_ERROR', 'error'); return $this->app->redirect($return); } // Get the request token $request = json_decode($table->request_token); // Get the callback url $callback = EBR::getRoutedURL('index.php?option=com_easyblog&task=oauth.grant&client=' . $client . $redirect, false, true); // Get the client $consumer = EB::oauth()->getClient($client); $consumer->setCallback($callback); // Get the verifier $verifier = $consumer->getVerifier(); if (!$verifier) { $table->delete(); return $this->app->redirect($return); } // Get the access token $consumer->setRequestToken($request->token, $request->secret); $access = $consumer->getAccess($verifier); // Since there is a problem with the oauth authentication, we need to delete the existing record. if (!$access || !$access->token || !$access->secret) { $table->delete(); $this->info->set('COM_EASYBLOG_OAUTH_ACCESS_TOKEN_ERROR', 'error'); return $this->app->redirect($return); } // Once we have the token, we need to map it back $params = EB::registry(); $params->set('token', $access->token); $params->set('secret', $access->secret); // Set the expiration date if (isset($access->expires)) { $table->expires = $access->expires; } $table->access_token = $params->toString(); $table->params = $access->params; // Store the oauth table now $table->store(); $this->info->set(JText::sprintf('COM_EASYBLOG_OAUTH_SUCCESS_' . strtoupper($client)), 'success'); echo '<script type="text/javascript">window.opener.doneLogin();window.close();</script>'; exit; }
/** * Retrieves the limit for pagination * * @since 5.0 * @access public * @param string * @return */ public static function getLimit($key = 'listlength') { $app = JFactory::getApplication(); $default = EB::getJConfig()->get('list_limit'); if ($app->isAdmin()) { return $default; } // Get the active menu $menu = $app->getMenu()->getActive(); $limit = -2; // Get the pagination limit from the menu parameters if (is_object($menu)) { $params = EB::registry($menu->params); $limit = $params->get('limit', '-2'); } // If there is no pagination limit set on the menu, try to use the limit from EasyBlog's settings if ($limit == '-2') { $config = EB::config(); $index = 'layout_pagination_' . $key; if ($key == 'listlength') { $index = 'layout_listlength'; } $limit = $config->get($index); } // Revert to joomla's pagination if configured to inherit from Joomla if ($limit == '0' || $limit == '-1' || $limit == '-2') { $limit = $default; } return $limit; }
/** * Retrieves the comment count for the post * * @since 5.0 * @access public * @param string * @return */ public function getCommentCount($post) { static $counter = array(); if (isset($counter[$post->id])) { return $counter[$post->id]; } $adapter = false; // If configured to display multiple comments, we can't display the counter if ($this->config->get('main_comment_multiple')) { $counter[$post->id] = false; return false; } // @Livefyre comments if ($this->config->get('comment_livefyre')) { return false; } // @Intense debate comments if ($this->config->get('intensedebate')) { $counter[$post->id] = false; return false; } // @RSComments if ($this->config->get('comment_rscomments')) { return false; } // @FB Comments if ($this->config->get('comment_facebook')) { return false; } // easyblog builtin comment if ($this->config->get('comment_easyblog', 1)) { $adapter = $this->getAdapter('easyblog'); } // @Komento if ($this->config->get('comment_komento')) { $adapter = $this->getAdapter('komento'); } // @EasySocial if ($this->config->get('comment_easysocial')) { $adapter = $this->getAdapter('easysocial'); } // @Compojoom Comments if ($this->config->get('comment_compojoom')) { $adapter = $this->getAdapter('cjcomment'); } // @Disqus comments if ($this->config->get('comment_disqus')) { $adapter = $this->getAdapter('disqus'); } // @JComment comments if ($this->config->get('comment_jcomments')) { $adapter = $this->getAdapter('jcomments'); } if ($adapter) { $counter[$post->id] = $adapter->getCount($post); return $counter[$post->id]; } // Let's allow the plugin to also trigger the comment count. $params = EB::registry(); $result = EB::triggerEvent('easyblog.commentCount', $post, $params, 0); // Get the count $count = trim(implode(' ', $result)); if (!empty($count)) { $counter[$post->id] = $count; } else { $counter[$post->id] = 0; } return $counter[$post->id]; }
/** * Retrieves a key value from the access token object. */ public function getAccessTokenValue($key) { $param = EB::registry($this->access_token); return $param->get($key); }
public function setAccess($access) { $access = EB::registry($access); return parent::setTokenAccess(array('oauth_token' => $access->get('token'), 'oauth_token_secret' => $access->get('secret'))); }
/** * Allows caller to import posts from twitter * * @since 5.0 * @access public * @param string * @return */ public function import() { $key = $this->config->get('integrations_twitter_api_key'); $secret = $this->config->get('integrations_twitter_secret_key'); // Ensure that the settings is enabled if (!$this->config->get('integrations_twitter_microblog')) { // TODO: Turn this into language string. return EB::exception('Twitter import has been disabled.', EASYBLOG_MSG_ERROR); } // Get a list of hashtags $hashtags = $this->config->get('integrations_twitter_microblog_hashes'); // If there are no hashtags, skip this if (!$hashtags) { // TODO: Turn this into language string. return EB::exception('No hashtags provided to search. Skipping this.', EASYBLOG_MSG_INFO); } $hashtags = explode(',', $hashtags); $total = count($hashtags); // Get the list of accounts $model = EB::model('OAuth'); $accounts = $model->getTwitterAccounts(); if (!$accounts) { return EB::exception('No Twitter accounts associated on the site. Skipping this', EASYBLOG_MSG_INFO); } // Get the default category to save the tweets into $categoryId = $this->config->get('integrations_twitter_microblog_category'); // Default state of the post $published = $this->config->get('integrations_twitter_microblog_publish'); // Determines if the post should be available on the frontpage $frontpage = $this->config->get('integrations_twitter_microblog_frontpage'); // Determines the total number of items imported $total = 0; // Go through each twitter accounts and search for the tags foreach ($accounts as $account) { $params = EB::registry($account->params); $screen = $params->get('screen_name'); // If we can't get the screen name, do not try to process it. if (!$screen) { continue; } // Get the twitter consumer $consumer = EB::oauth()->getClient('Twitter'); $consumer->setAccess($account->access_token); // Get the last tweet that has been imported so we don't try to search for anything prior to that $lastImport = $model->getLastTweetImport($account->id); // Prepare the search params $tweets = $consumer->search($hashtags, $lastImport); if (!$tweets) { return EB::exception('No tweets found. Skipping this.', EASYBLOG_MSG_INFO); } foreach ($tweets as $tweet) { $data = array(); $data['title'] = JString::substr($tweet->text, 0, 20) . JText::_('COM_EASYBLOG_ELLIPSES'); $data['posttype'] = EBLOG_MICROBLOG_TWITTER; $data['created_by'] = $account->user_id; $data['created'] = EB::date()->toSql(); $data['modified'] = EB::date()->toSql(); $data['publish_up'] = EB::date()->toSql(); $data['intro'] = $tweet->text; $data['published'] = $published; $data['frontpage'] = $frontpage; $data['source_id'] = '0'; $data['source_type'] = EASYBLOG_POST_SOURCE_SITEWIDE; $data['category_id'] = $categoryId; $data['categories'] = array($categoryId); // we need to set this as legacy post as the post did not go through composer. $data['doctype'] = EASYBLOG_POST_DOCTYPE_LEGACY; $post = EB::post(); $createOption = array('overrideDoctType' => 'legacy', 'checkAcl' => false, 'overrideAuthorId' => $account->user_id); $post->create($createOption); // binding $post->bind($data); $saveOptions = array('applyDateOffset' => false, 'validateData' => false, 'useAuthorAsRevisionOwner' => true, 'checkAcl' => false, 'overrideAuthorId' => $account->user_id); // Save the post now try { $post->save($saveOptions); } catch (EasyBlogException $exception) { return $exception; } // We need to save some of these tweets $adapter = EB::quickpost()->getAdapter('twitter'); if ($adapter) { $adapter->saveAsset($post->id, 'screen_name', $tweet->user->screen_name); $adapter->saveAsset($post->id, 'created_at', $tweet->created_at); } // Create a new history record $history = EB::table('TwitterMicroBlog'); $history->id_str = $tweet->id_str; $history->post_id = $post->id; $history->oauth_id = $account->id; $history->created = $post->created; $history->tweet_author = $screen; $history->store(); $total++; } } return EB::exception(JText::sprintf('%1$s tweets retrieved from twitter', $total), EASYBLOG_MSG_SUCCESS); }
/** * Retrieves author's twitter link * * @since 5.0 * @access public * @param string * @return */ public function getTwitterLink() { static $links = array(); if (!isset($links[$this->id])) { $links[$this->id] = ''; $oauth = EB::table('OAuth'); $oauth->loadByUser($this->id, 'twitter'); $params = EB::registry($oauth->params); $screenName = $params->get('screen_name'); if ($screenName) { $links[$this->id] = 'https://twitter.com/' . $screenName; } } return $links[$this->id]; }
/** * Saves an author object * * @since 4.0 * @access public * @param string * @return */ public function save() { // Check for request forgeries EB::checkToken(); // Check for acl rules. $this->checkAccess('user'); // Create a new JUser object $id = $this->input->get('id', 0, 'int'); $user = JFactory::getUser($id); // Get the user group's id $gid = $user->get('gid'); // Get the posted data $post = $this->input->getArray('post'); // Retrieve the username and password of the user $post['username'] = $this->input->get('username', '', 'default'); $post['password'] = $this->input->get('password', '', 'default'); $post['password2'] = $this->input->get('password2', '', 'default'); // Get the data from Joomla's form if (isset($post['jform']['params'])) { $post['params'] = $post['jform']['params']; unset($post['jform']); } // Bind the post request on the user's object $state = $user->bind($post); // Default redirection url $redirect = 'index.php?option=com_easyblog&view=bloggers&layout=form&id=' . $user->id; if (!$state) { $this->info->set($user->getError(), 'error'); return $this->app->redirect($redirect); } // Get the user's id if ($user->id == $this->my->id && $user->block) { $this->info->set(JText::_('You are not allowed to block yourself.'), 'error'); return $this->app->redirect($redirect); } if ($user->authorise('core.admin') && $user->block) { $this->info->set(JText::_('You are not allowed to block a super administrator.'), 'error'); return $this->app->redirect($redirect); } if ($user->authorise('core.admin') && !$this->my->authorise('core.admin')) { $this->info->set(JText::_('You cannot edit a Super User account.'), 'error'); return $this->app->redirect($redirect); } $gid = $post['gid']; if (!empty($gid)) { $user->groups = array(); foreach ($gid as $groupid) { $user->groups[$groupid] = $groupid; } } // Are we dealing with a new user which we need to create? $isNew = $user->id < 1; // Try to save the user now $state = $user->save(); if (!$state) { $this->info->set($user->getError(), 'error'); return $this->app->redirect($redirect); } // Update the user's session data if the current user is being edited to ensure that // the current user's data is correct if ($user->id == $this->my->id) { $session = JFactory::getSession(); $session->set('user', $user); } // If this is a new record, ensure that the id is not set if ($isNew) { unset($post['id']); } // Set the proper permalink if (isset($post['user_permalink'])) { $post['permalink'] = $post['user_permalink']; unset($post['user_permalink']); } // Only allow site admins to add html codes for the description and biography if (EB::isSiteAdmin()) { $post['description'] = $this->input->get('description', '', 'html'); $post['biography'] = $this->input->get('biography', '', 'html'); } // After the user record is stored, we also want to update EasyBlog's records. $author = EB::user($user->id); // Bind the posted data $author->bind($post); // Get the file data $file = $this->input->files->get('avatar', ''); if (isset($file['tmp_name']) && !empty($file['tmp_name'])) { $author->bindAvatar($file, EB::acl()); } // Save other user parameters $registry = EB::registry(); // Save google profile url if (isset($post['google_profile_url'])) { $registry->set('google_profile_url', $post['google_profile_url']); } if (isset($post['show_google_profile_url'])) { $registry->set('show_google_profile_url', $post['show_google_profile_url']); } $author->params = $registry->toString(); // Try to save the author object now $author->store(); // Save the social settings $twitter = EB::table('OAuth'); $twitter->load(array('user_id' => $user->id, 'type' => EBLOG_OAUTH_TWITTER)); $twitter->auto = $this->input->get('integrations_twitter_auto'); $twitter->message = $this->input->get('integrations_twitter_message', '', 'default'); // Try to save the twitter oauth object now $state = $twitter->store(); if (!$state) { $this->info->set($twitter->getError(), 'error'); return $this->app->redirect($redirect); } // Try to save the linked in oauth object $linkedin = EB::table('OAuth'); $linkedin->load(array('user_id' => $user->id, 'type' => EBLOG_OAUTH_LINKEDIN)); $linkedin->auto = $this->input->get('integrations_linkedin_auto', '', 'bool'); $linkedin->message = $this->input->get('integrations_linkedin_message', '', 'default'); $linkedin->private = $this->input->get('integrations_linkedin_private', '', 'bool'); // Save the oauth object now $state = $linkedin->store(); if (!$state) { $this->info->set($linkedin->getError(), 'error'); return $this->app->redirect($redirect); } // Store the Facebook oauth object now $facebook = EB::table('OAuth'); $facebook->load(array('user_id' => $user->id, 'type' => EBLOG_OAUTH_FACEBOOK)); $facebook->auto = $this->input->get('integrations_facebook_auto', '', 'bool'); $facebook->message = ''; // Save the facebook object now $state = $facebook->store(); if (!$state) { $this->info->set($facebook->getError(), 'error'); return $this->app->redirect($redirect); } // Save google adsense codes now if ($this->config->get('integration_google_adsense_enable')) { $adsense = EB::table('Adsense'); $adsense->load($user->id); $adsense->code = $post['adsense_code']; $adsense->display = $post['adsense_display']; $adsense->published = $post['adsense_published']; $adsense->store(); } // Store Feedburner's data $feedburner = EB::table('Feedburner'); $feedburner->load($user->id); $feedburner->url = $post['feedburner_url']; $feedburner->store(); // Get the current task $task = $this->getTask(); $this->info->set('COM_EASYBLOG_BLOGGER_SAVED', 'success'); if ($task == 'apply') { $redirect = 'index.php?option=com_easyblog&view=bloggers&layout=form&id=' . $user->id; return $this->app->redirect($redirect); } return $this->app->redirect('index.php?option=com_easyblog&view=bloggers'); }
/** * Main method to import the feed items * * @since 4.0 * @access public * @param string * @return */ public function import(EasyBlogTableFeed &$feed, $limit = 0) { // Load site language file EB::loadLanguages(); // Import simplepie library jimport('simplepie.simplepie'); // We need DomDocument to exist if (!class_exists('DomDocument')) { return false; } // Set the maximum execution time to a higher value @ini_set('max_execution_time', 720); // Get the feed params $params = EB::registry($feed->params); // Determines the limit of items to fetch $limit = $limit ? $limit : $params->get('feedamount', 0); // Setup the outgoing connection to the feed source $connector = EB::connector(); $connector->addUrl($feed->url); $connector->execute(); // Get the contents $contents = $connector->getResult($feed->url); // If contents is empty, we know something failed if (!$contents) { return EB::exception(JText::sprintf('COM_EASYBLOG_FEEDS_UNABLE_TO_REACH_TARGET_URL', $feed->url), EASYBLOG_MSG_ERROR); } // Get the cleaner to clean things up $cleaner = $this->getAdapter('Cleaner'); $contents = $cleaner->cleanup($contents); // Load up the xml parser $parser = new SimplePie(); $parser->strip_htmltags(false); $parser->set_raw_data($contents); @$parser->init(); // Get a list of items // We need to supress errors here because simplepie will throw errors on STRICT mode. $items = @$parser->get_items(); if (!$items) { // TODO: Language string return EB::exception('COM_EASYBLOG_FEEDS_NOTHING_TO_BE_IMPORTED_CURRENTLY', EASYBLOG_MSG_ERROR); } // Get the feeds model $model = EB::model('Feeds'); // Determines the total number of items migrated $total = 0; foreach ($items as $item) { // If it reaches limit, skip processing if ($limit && $total == $limit) { break; } // Get the item's unique id $uid = @$item->get_id(); // If item already exists, skip this if ($model->isFeedItemImported($feed->id, $uid)) { continue; } // Log down a new history record to avoid fetching of the same item again $history = EB::table('FeedHistory'); $history->feed_id = $feed->id; $history->uid = $uid; $history->created = EB::date()->toSql(); $history->store(); // Get the item's link $link = @$item->get_link(); // Load up the post library $post = EB::post(); $createOption = array('overrideDoctType' => 'legacy', 'checkAcl' => false, 'overrideAuthorId' => $feed->item_creator); $post->create($createOption); // Pass this to the adapter to map the items $mapper = $this->getAdapter('Mapper'); $mapper->map($post, $item, $feed, $params); // Now we need to get the content of the blog post $mapper->mapContent($post, $item, $feed, $params); $saveOptions = array('applyDateOffset' => false, 'validateData' => false, 'useAuthorAsRevisionOwner' => true, 'checkAcl' => false, 'overrideAuthorId' => $feed->item_creator); // Try to save the blog post now try { $post->save($saveOptions); // Update the history table $history->post_id = $post->id; $history->store(); $total++; } catch (EasyBlogException $exception) { // do nothing. } } return EB::exception(JText::sprintf('COM_EASYBLOG_FEEDS_POSTS_MIGRATED_FROM_FEED', $total, $feed->url), EASYBLOG_MSG_SUCCESS); }
public function setAccess($access) { $access = EB::registry($access); $this->token = new OAuthConsumer($access->get('token'), $access->get('secret')); return $this->token; }
public function setParams($params) { $param = EB::registry($params); $this->_param = $param; return $this->_param; }
public function onAfterEasyBlogSave($post, $isNew) { if (!$this->exists()) { return; } if (!$post->isPublished()) { return; } $db = EasyBlogHelper::db(); $user = JFactory::getUser(); // Get plugin info $plugin = JPluginHelper::getPlugin('easyblog', 'autoarticle'); $pluginParams = EB::registry($plugin->params); // easyblog blog details $data = array(); $data['title'] = $post->title; $data['alias'] = $post->permalink; // if (empty($post->intro)) { // $data['introtext'] = $post->content; // $data['fulltext'] = ''; // } else { // $data['introtext'] = $post->intro; // $data['fulltext'] = $post->content; // } $data['introtext'] = $post->getContent('entry'); $data['fulltext'] = ''; $EasyBlogitemId = EBR::getItemId('latest'); $readmoreURL = EBR::_('index.php?option=com_easyblog&view=entry&id=' . $post->id . '&Itemid=' . $EasyBlogitemId); $readmoreURL = str_replace('/administrator/', '/', $readmoreURL); $readmoreLink = '<a href="' . $readmoreURL . '" class="readon"><span>' . JText::_('Read More') . '</span></a>'; $data['introtext'] = $data['introtext'] . '<br />' . $readmoreLink; $data['created'] = $post->created; $data['created_by'] = $post->created_by; $data['modified'] = $post->modified; $data['modified_by'] = $user->id; $data['publish_up'] = $post->publish_up; $data['publish_down'] = $post->publish_down; //these four get from plugin params $state = $pluginParams->get('status'); $access = 1; if ($pluginParams->get('access', '-1') == '-1') { $access = $post->access ? 2 : 1; } else { $tmpAccess = $pluginParams->get('access'); switch ($tmpAccess) { case '1': $access = '2'; break; case '2': $access = '3'; break; case '0': default: $access = '1'; break; } } $section = '0'; $category = $pluginParams->get('sectionCategory', '0'); $frontpage = $pluginParams->get('frontpage', '-1') == '-1' ? $post->frontpage : $pluginParams->get('frontpage', '0'); $autoMapCategory = $pluginParams->get('autocategory', '0'); if ($autoMapCategory) { $autoMapped = self::mapCategory($post->category_id); if (!empty($autoMapped->cid)) { $category = $autoMapped->cid; } } $data['state'] = $state; $data['access'] = $access; $data['sectionid'] = $section; $data['catid'] = $category; $data['metakey'] = JRequest::getVar('keywords', ''); $data['metadesc'] = JRequest::getVar('description', ''); $contentMap = EB::table('AutoArticleMap'); $joomlaContent = JTable::getInstance('content'); $aid = ''; // try to get the existing content id via the mapping table $contentMap->load($post->id, true); if (!empty($contentMap->content_id)) { $aid = $contentMap->content_id; } if (empty($aid) && !empty($post->permalink)) { //try to get if the article already inserted before based on title alias. $query = 'SELECT `id` FROM `#__content` WHERE `alias` = ' . $db->Quote($post->permalink); $db->setQuery($query); $aid = $db->loadResult(); } if (!empty($aid)) { $joomlaContent->load($aid); } $joomlaContent->bind($data); // Convert the params field to an array. $registry = new JRegistry(); $joomlaContent->attribs = $registry->toArray(); $joomlaContent->store(); $articleId = $joomlaContent->id; if (is_null($isNew)) { // something wrong here. test the aid to determine. if (empty($aid)) { $isNew = true; } else { $isNew = false; } } if ($isNew && !empty($articleId)) { // if saved ok, then insert the mapping into our map table. $jdate = EB::date(); $map = array(); $map['content_id'] = $articleId; $map['post_id'] = $post->id; $map['created'] = $jdate->toMySQL(); $contentMap->bind($map); $contentMap->store(); } if ($isNew && $frontpage) { JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_content/tables'); $table = JTable::getInstance('Featured', 'ContentTable'); // Insert the new entry $query = 'INSERT INTO `#__content_frontpage`' . ' VALUES ( ' . (int) $articleId . ', 1 )'; $db->setQuery($query); $db->query(); // we require the table object so that we can reorder the ordering column. // reorder featured table ordering $table->reorder(); } $cache = JFactory::getCache('com_content'); $cache->clean(); }
public function getConfig() { static $config = null; if (is_null($config)) { $params = $this->_getParams('config'); $config = EB::registry($params); } return $config; }
/** * Saves a user profile * * @since 4.0 * @access public * @param string * @return */ public function save() { // Check for request forgeries EB::checkToken(); // Require user to be logged in EB::requireLogin(); // Get the post data here $post = $this->input->getArray('post'); // Since adsense codes may contain html codes $post['adsense_code'] = $this->input->get('adsense_code', '', 'raw'); // Prepare the redirection url $redirect = EB::_('index.php?option=com_easyblog&view=dashboard&layout=profile', false); if (EB::isSiteAdmin() || $this->config->get('layout_dashboard_biography_editor')) { $post['description'] = $this->input->get('description', '', 'raw'); $post['biography'] = $this->input->get('biography', '', 'raw'); } // Trim data array_walk($post, array($this, '_trim')); if ($this->config->get('main_dashboard_editaccount')) { if (!$this->validateProfile($post)) { return $this->app->redirect($redirect); } $this->my->name = $post['fullname']; $this->my->save(); } // Determines if we should save the user's params. if ($this->config->get('main_joomlauserparams')) { $email = $post['email']; $password = $post['password']; $password2 = $post['password2']; if (JString::strlen($password) || JString::strlen($password2)) { if ($password != $password2) { EB::info()->set(JText::_('COM_EASYBLOG_DASHBOARD_ACCOUNT_PASSWORD_ERROR'), 'error'); return $this->app->redirect($redirect); } } // Store Joomla info $user = JFactory::getUser(); $data = array('email' => $email, 'password' => $password, 'password2' => $password2); // Bind data $user->bind($data); $state = $user->save(); if (!$state) { EB::info()->set($user->getError(), 'error'); return $this->app->redirect($redirect); } $session = JFactory::getSession(); $session->set('user', $user); $table = JTable::getInstance('Session'); $table->load($session->getId()); $table->username = $user->get('username'); $table->store(); } // Set the permalink $post['permalink'] = $post['user_permalink']; unset($post['user_permalink']); // Get users model $model = EB::model('Users'); // Ensure that the permalink doesn't exist if ($model->permalinkExists($post['permalink'], $this->my->id)) { EB::info()->set(JText::_('COM_EASYBLOG_DASHBOARD_ACCOUNT_PERMALINK_EXISTS'), 'error'); return $this->app->redirect($redirect); } // Load up EasyBlog's profile $profile = EB::user($this->my->id); $profile->bind($post); // Bind Feedburner data $profile->bindFeedburner($post, $this->acl); // Bind oauth settings $profile->bindOauth($post, $this->acl); // Bind adsense settings $profile->bindAdsense($post, $this->acl); // Bind avatar $avatar = $this->input->files->get('avatar', ''); // Save avatar if (isset($avatar['tmp_name']) && !empty($avatar['tmp_name'])) { $profile->bindAvatar($avatar, $this->acl); } $acl = EB::acl(); //save meta if ($acl->get('add_entry')) { //meta post info $metaId = JRequest::getInt('metaid', 0); $metapos = array(); $metapost['keywords'] = $this->input->get('metakeywords', '', 'raw'); $metapost['description'] = $this->input->get('metadescription', '', 'raw'); $metapost['content_id'] = $this->my->id; $metapost['type'] = META_TYPE_BLOGGER; $meta = EB::table('Meta'); $meta->load($metaId); $meta->bind($metapost); $meta->store(); } //save params $userparams = EB::registry(); $userparams->set('theme', $post['theme']); // @rule: Save google profile url if (isset($post['google_profile_url'])) { $userparams->set('google_profile_url', $post['google_profile_url']); } if (isset($post['show_google_profile_url'])) { $userparams->set('show_google_profile_url', $post['show_google_profile_url']); } $profile->params = $userparams->toString(); // If user is allowed to save their settings if ($this->config->get('main_dashboard_editaccount') && $this->config->get('main_joomlauserparams')) { $this->my->save(true); } $state = $profile->store(); if (!$state) { EB::info()->set(JText::_('COM_EASYBLOG_DASHBOARD_PROFILE_UPDATE_FAILED'), 'error'); return $this->app->redirect($redirect); } EB::info()->set(JText::_('COM_EASYBLOG_DASHBOARD_PROFILE_UPDATE_SUCCESS'), 'success'); return $this->app->redirect($redirect); }
public function grant() { // @task: Check for acl rules. $this->checkAccess('autoposting'); $type = JRequest::getCmd('type'); $mainframe = JFactory::getApplication(); $config = EasyBlogHelper::getConfig(); $key = $config->get('integrations_' . $type . '_api_key'); $secret = $config->get('integrations_' . $type . '_secret_key'); $my = JFactory::getUser(); $from = JRequest::getWord('return'); $oauth = EB::table('Oauth'); $loaded = $oauth->loadSystemByType($type); $denied = JRequest::getVar('denied', ''); $redirect = JRoute::_('index.php?option=com_easyblog&view=autoposting&layout=' . $type . '&step=2', false); if ($from == 'form') { $redirect = JRoute::_('index.php?option=com_easyblog&view=autoposting&layout=form&type=' . $type, false); } $call = JRequest::getWord('call'); $callUri = !empty($call) ? '&call=' . $call : ''; if (!empty($denied)) { $oauth->delete(); $this->setRedirect($redirect, JText::sprintf('Denied by %1s', $type), 'error'); return; } if (!$loaded) { $oauth->delete(); JError::raiseError(500, JText::_('COM_EASYBLOG_AUTOPOST_ERRORS_REQUEST_TOKENS_NOT_LOADED')); } $request = EB::registry($oauth->request_token); $return = JRequest::getWord('return'); $return = !empty($return) ? '&return=' . $return : ''; $callback = rtrim(JURI::root(), '/') . '/administrator/index.php?option=com_easyblog&c=autoposting&task=grant&type=' . $type . $return . $callUri; $consumer = EasyBlogHelper::getHelper('OAuth')->getConsumer($type, $key, $secret, $callback); $verifier = $consumer->getVerifier(); if (empty($verifier)) { // Since there is a problem with the oauth authentication, we need to delete the existing record. $oauth->delete(); JError::raiseError(500, JText::_('COM_EASYBLOG_AUTOPOST_ERRORS_INVALID_VERIFIER')); } $access = $consumer->getAccess($request->get('token'), $request->get('secret'), $verifier); if (!$access || empty($access->token) || empty($access->secret)) { // Since there is a problem with the oauth authentication, we need to delete the existing record. $oauth->delete(); $this->setRedirect($redirect, JText::sprintf('COM_EASYBLOG_AUTOPOST_ERRORS_INVALID_ACCESS_TOKENS', $type), 'error'); return; } $param = EB::registry(); $param->set('token', $access->token); $param->set('secret', $access->secret); if (isset($access->expires)) { $param->set('expires', $access->expires); } $oauth->access_token = $param->toString(); $oauth->params = $access->params; $oauth->store(); // @task: Let's see if the oauth client if (!empty($call)) { $consumer->{$call}(); } else { $this->setRedirect($redirect, JText::_('COM_EASYBLOG_AUTOPOST_ACCOUNT_ASSOCIATED_SUCCESSFULLY')); } return; }