/** * Validate project owner. * * <code> * $projectId = 1; * $userId = 2; * * $owner = new Crowdfunding\Validator\Project\Owner(\JFactory::getDbo(), $projectId, $userId); * if(!$owner->isValid()) { * ...... * } * </code> * * @return bool */ public function isValid() { $query = $this->db->getQuery(true); $query->select('COUNT(*)')->from($this->db->quoteName('#__crowdf_projects', 'a'))->where('a.id = ' . (int) $this->projectId)->where('a.user_id = ' . (int) $this->userId); $this->db->setQuery($query, 0, 1); return (bool) $this->db->loadResult(); }
/** * Validate project owner. * * <code> * $projectId = 1; * $userId = 2; * * $owner = new Crowdfunding\Validator\Project\Owner(\JFactory::getDbo(), $projectId, $userId); * if(!$owner->isValid()) { * ...... * } * </code> * * @return bool */ public function isValid() { $query = $this->db->getQuery(true); $query->select("COUNT(*)")->from($this->db->quoteName("#__crowdf_projects", "a"))->where("a.id = " . (int) $this->projectId)->where("a.user_id = " . (int) $this->userId); $this->db->setQuery($query, 0, 1); $result = $this->db->loadResult(); return (bool) $result; }
/** * This method returns a number of all comments. * * @return int */ public function getTotalComments() { $query = $this->db->getQuery(true); $query->select("COUNT(*)")->from($this->db->quoteName("#__uideas_comments", "a")); $this->db->setQuery($query); $result = $this->db->loadResult(); if (!$result) { $result = 0; } return $result; }
/** * Count the number of campaigns in a period. * If star date and end date are not provides, the system will get default values. * The default values will be the beginning of the year and the end of the year. * * <code> * $usersId = 1; * * $statistics = new Crowdfunding\Statistics\Users(\JFactory::getDbo(), $usersId); * $numberOfCampaigns = $statistics->getNumberOfActiveCampaigns(); * </code> * * @param string $startDate * @param string $endDate * * @return int */ public function getNumberOfCampaignsInPeriod($startDate = null, $endDate = null) { // Set default start date. if (!(int) $startDate) { $date = new Prism\Date(); $date = $date->getBeginOfYear(); $startDate = $date->toSql(); } // Set default end date. if (!(int) $endDate) { $date = new Prism\Date(); $date = $date->getEndOfYear(); $endDate = $date->toSql(); } $startDate = new \JDate($startDate); $endDate = new \JDate($endDate); $query = $this->db->getQuery(true); $query->select("COUNT(*) AS number")->from($this->db->quoteName("#__crowdf_projects", "a"))->where("a.user_id = " . (int) $this->id)->where("a.funding_start >= " . $this->db->quote($startDate->toSql()))->where("a.funding_start <= " . $this->db->quote($endDate->toSql())); $this->db->setQuery($query, 0, 1); $result = $this->db->loadResult(); if (!$result) { $result = 0; } return $result; }
protected function createTable() { $this->debug('createTable: Check if plugin table exists.'); // Create plugin table if doesn't exist $query = "SHOW TABLES LIKE '{$this->db->getPrefix()}kunenadiscuss'"; $this->db->setQuery($query); if (!$this->db->loadResult()) { KunenaError::checkDatabaseError(); $query = "CREATE TABLE IF NOT EXISTS `#__kunenadiscuss`\n\t\t\t\t\t(`content_id` int(11) NOT NULL default '0',\n\t\t\t\t\t `thread_id` int(11) NOT NULL default '0',\n\t\t\t\t\t PRIMARY KEY (`content_id`)\n\t\t\t\t\t )"; $this->db->setQuery($query); $this->db->query(); KunenaError::checkDatabaseError(); $this->debug("Created #__kunenadiscuss cross reference table."); // Migrate data from old FireBoard discussbot if it exists $query = "SHOW TABLES LIKE '{$this->db->getPrefix()}fb_discussbot'"; $this->db->setQuery($query); if ($this->db->loadResult()) { $query = "REPLACE INTO `#__kunenadiscuss`\n\t\t\t\t\tSELECT `content_id` , `thread_id`\n\t\t\t\t\tFROM `#__fb_discussbot`"; $this->db->setQuery($query); $this->db->query(); KunenaError::checkDatabaseError(); $this->debug("Migrated old data."); } } }
/** * Count and return projects number of users. * * <code> * $usersId = 1; * * $statistics = new CrowdFundingStatisticsUser(JFactory::getDbo(), $usersId); * $projectsNumber = $statistics->getProjectsNumber(); * </code> * * @return array */ public function getProjectsNumber() { // If there are no IDs, return empty array. if (!$this->id) { return array(); } // Create a new query object. $query = $this->db->getQuery(true); $query->select("COUNT(*) as number")->from($this->db->quoteName("#__crowdf_projects", "a"))->where("a.user_id = " . (int) $this->id); $this->db->setQuery($query, 0, 1); $results = $this->db->loadResult(); if (!$results) { $results = array(); } return $results; }
/** * This method returns a number of all global tags. * * <code> * $statistics = new ItpMeta\Statistics\Basic(\JFactory::getDbo()); * echo $statistics->getTotalGlobalTags(); * </code> * * @return int */ public function getTotalGlobalTags() { $query = $this->db->getQuery(true); $query->select('COUNT(*)')->from($this->db->quoteName('#__itpm_global_tags', 'a')); $this->db->setQuery($query); $result = (int) $this->db->loadResult(); return $result; }
/** * Validate project record. * * <code> * $projectId = 1; * * $record = new Crowdfunding\Validator\Project\Record(\JFactory::getDbo(), $projectId); * if(!$record->isValid()) { * //...... * } * </code> * * @throws \RuntimeException * @return bool */ public function isValid() { $query = $this->db->getQuery(true); $query->select('COUNT(*)')->from($this->db->quoteName('#__crowdf_projects', 'a'))->where('a.id = ' . (int) $this->projectId); // Filter by user. $userId = array_key_exists('user_id', $this->options) ? (int) $this->options['user_id'] : 0; if ($userId > 0) { $query->where('a.user_id = ' . (int) $userId); } // Filter by state. $state = array_key_exists('state', $this->options) ? $this->options['state'] : null; if ($state !== null) { $query->where('a.published = ' . (int) $state); } $this->db->setQuery($query, 0, 1); return (bool) $this->db->loadResult(); }
/** * Return the number of updates. * * <code> * $projectId = 1; * * $statistics = new Crowdfunding\Statistics\Project(\JFactory::getDbo(), $projectId); * $numberOfUpdates = $statistics->getUpdatesNumber(); * </code> * * @return int */ public function getUpdatesNumber() { // Create a new query object. $query = $this->db->getQuery(true); $query->select('COUNT(*)')->from($this->db->quoteName('#__crowdf_updates', 'a'))->where('a.project_id = ' . (int) $this->id); $this->db->setQuery($query); return (int) $this->db->loadResult(); }
/** * This method checks for selected reward from user. * It will be checked, if the reward is part of transactions. * * <code> * $rewardId = 1; * * $reward = new CrowdFundingReward(JFactory::getDbo()); * $reward->load($rewardId); * * if ($reward->isSelectedByUser()) { * ... * } * </code> * * @return bool */ public function isSelectedByUser() { $query = $this->db->getQuery(true); // Count number of selections. $query->select("COUNT(*)")->from($this->db->quoteName("#__crowdf_transactions", "a"))->where("a.reward_id = " . (int) $this->id); $this->db->setQuery($query, 0, 1); $number = $this->db->loadResult(); return !$number ? false : true; }
/** * Retrieve Contact * * @param int $created_by Id of the user who created the contact * * @return mixed|null|integer */ protected function getContactId($created_by) { static $contacts = array(); if (isset($contacts[$created_by])) { return $contacts[$created_by]; } $query = $this->db->getQuery(true); $query->select('MAX(contact.id) AS contactid'); $query->from($this->db->quoteName('#__contact_details', 'contact')); $query->where('contact.published = 1'); $query->where('contact.user_id = ' . (int) $created_by); if (JLanguageMultilang::isEnabled() == 1) { $query->where('(contact.language in ' . '(' . $this->db->quote(JFactory::getLanguage()->getTag()) . ',' . $this->db->quote('*') . ') ' . ' OR contact.language IS NULL)'); } $this->db->setQuery($query); $contacts[$created_by] = $this->db->loadResult(); return $contacts[$created_by]; }
/** * Get total amount of all transactions. * * <code> * $statistics = new CrowdFundingStatisticsBasic(JFactory::getDbo()); * $total = $statistics->getTotalAmount(); * </code> */ public function getTotalAmount() { $query = $this->db->getQuery(true); $query->select("SUM(a.txn_amount)")->from($this->db->quoteName("#__crowdf_transactions", "a")); $this->db->setQuery($query); $result = $this->db->loadResult(); if (!$result) { $result = 0; } return $result; }
/** * Remove an extra image from database and file system. * * <code> * $fileId = 1; * $filesFolder = "/.../folder"; * * $file = new CrowdfundingFiles\File\Remover(JFactory::getDbo(), $fileId, $mediaFolder); * $file->remove(); * </code> */ public function remove() { // Get the image $query = $this->db->getQuery(true); $query->select("a.filename")->from($this->db->quoteName("#__cffiles_files", "a"))->where("a.id = " . (int) $this->fileId); $this->db->setQuery($query, 0, 1); $fileName = $this->db->loadResult(); if (!empty($fileName)) { // Remove the file from the filesystem $file = \JPath::clean($this->mediaFolder . DIRECTORY_SEPARATOR . $fileName); if (\JFile::exists($file)) { \JFile::delete($file); } // Delete the record $query = $this->db->getQuery(true); $query->delete($this->db->quoteName("#__cffiles_files"))->where($this->db->quoteName("id") . " = " . (int) $this->fileId); $this->db->setQuery($query); $this->db->execute(); } }
/** * Return the number of updates. * * <code> * $projectId = 1; * * $statistics = new CrowdfundingStatisticsProject(\JFactory::getDbo(), $projectId); * $numberOfUpdates = $statistics->getUpdatesNumber(); * </code> * * @return int */ public function getUpdatesNumber() { // Create a new query object. $query = $this->db->getQuery(true); $query->select("COUNT(*)")->from($this->db->quoteName("#__crowdf_updates", "a"))->where("a.project_id = " . (int) $this->id); $this->db->setQuery($query); $result = $this->db->loadResult(); if (!$result) { $result = 0; } return $result; }
/** * Retrieves the UCM type ID * * @param string $alias The string of the type alias * * @return integer The ID of the requested type * * @since 3.1 */ public function getTypeId($alias = null) { if (!$alias) { $alias = $this->alias; } $query = $this->db->getQuery(true); $query->select('ct.type_id'); $query->from($this->db->quoteName('#__content_types', 'ct')); $query->where($this->db->quoteName('ct.type_alias') . ' = ' . $this->db->q($alias)); $this->db->setQuery($query); $id = $this->db->loadResult(); return $id; }
/** * Get the number of successfully completed projects. * * <code> * $options = array( * "state" => 1, // The state of the campaign - published or unpublished. * "approved" => 1, // The approved state - approved or not approved. * ); * * $statistics = new Crowdfunding\Statistics\Basic(\JFactory::getDbo()); * $numberOfProjects = $statistics->getSuccessfullyCompletedProjects(); * </code> * * @param array $options Options used to be aggregated data. * * @return int */ public function getSuccessfullyCompletedProjects(array $options = array()) { $query = $this->db->getQuery(true); $query->select('COUNT(*)')->from($this->db->quoteName('#__crowdf_projects', 'a')); // Prepare filters. $this->prepareFilters($query, $options); // Filter by funding date. jimport('joomla.date.date'); $date = new \JDate(); $today = $date->toSql(); $query->where('a.funding_end < ' . $this->db->quote($today) . ' AND a.funded >= a.goal'); $this->db->setQuery($query); return (int) $this->db->loadResult(); }
/** * Method to get the next ordering value for a group of rows defined by an SQL WHERE clause. * This is useful for placing a new item last in a group of items in the table. * * @param string $where WHERE clause to use for selecting the MAX(ordering) for the table. * * @return mixed Boolean false an failure or the next ordering value as an integer. * * @link https://docs.joomla.org/JTable/getNextOrder * @since 11.1 * @throws UnexpectedValueException */ public function getNextOrder($where = '') { // If there is no ordering field set an error and return false. if (!property_exists($this, 'ordering')) { throw new UnexpectedValueException(sprintf('%s does not support ordering.', get_class($this))); } // Get the largest ordering value for a given where clause. $query = $this->_db->getQuery(true)->select('MAX(ordering)')->from($this->_tbl); if ($where) { $query->where($where); } $this->_db->setQuery($query); $max = (int) $this->_db->loadResult(); // Return the largest ordering value + 1. return $max + 1; }
/** * Method to determine if a row is checked out and therefore uneditable by * a user. If the row is checked out by the same user, then it is considered * not checked out -- as the user can still edit it. * * @param integer $with The userid to preform the match with, if an item is checked * out by this user the function will return false. * @param integer $against The userid to perform the match against when the function * is used as a static function. * * @return boolean True if checked out. * * @since K4.0 */ public function isCheckedOut($with = 0, $against = null) { // Handle the non-static case. if (isset($this) && $this instanceof JTable && is_null($against)) { $against = $this->get('checked_out'); } // The item is not checked out or is checked out by the same user. if (!$against || $against == $with) { return false; } static::$db = JFactory::getDBO(); static::$db->setQuery('SELECT COUNT(userid)' . ' FROM ' . static::$db->quoteName('#__session') . ' WHERE ' . static::$db->quoteName('userid') . ' = ' . (int) $against); $checkedOut = (bool) static::$db->loadResult(); // If a session exists for the user then it is checked out. return $checkedOut; }
/** * Get the number of successfully completed projects. * * <code> * $options = array( * "state" => 1, // The state of the campaign - published or unpublished. * "approved" => 1, // The approved state - approved or not approved. * ); * * $statistics = new Crowdfunding\Statistics\Basic(\JFactory::getDbo()); * $numberOfProjects = $statistics->getSuccessfullyCompletedProjects(); * </code> * * @param array $options Options used to be aggregated data. * * @return int */ public function getSuccessfullyCompletedProjects($options = array()) { $query = $this->db->getQuery(true); $query->select("COUNT(*)")->from($this->db->quoteName("#__crowdf_projects", "a")); // Prepare filters. $this->prepareFilters($query, $options); // Filter by funding date. jimport("joomla.date.date"); $date = new \JDate(); $today = $date->toSql(); $query->where("a.funding_end < " . $this->db->quote($today) . " AND a.funded >= a.goal"); $this->db->setQuery($query); $result = $this->db->loadResult(); if (!$result) { $result = 0; } return $result; }
/** * Method to get the next ordering value for a group of rows defined by an SQL WHERE clause. * This is useful for placing a new item last in a group of items in the table. * * @param string $where WHERE clause to use for selecting the MAX(ordering) for the table. * * @return mixed Boolean false an failure or the next ordering value as an integer. */ public function getNextOrder($where = '') { // If there is no ordering field set an error and return false. $ordering = $this->getColumnAlias('ordering'); if (!in_array($ordering, $this->getKnownFields())) { throw new UnexpectedValueException(sprintf('%s does not support ordering.', get_class($this))); } // Get the largest ordering value for a given where clause. $query = $this->_db->getQuery(true); $query->select('MAX(' . $this->_db->qn($ordering) . ')'); $query->from($this->_tbl); if ($where) { $query->where($where); } $this->_db->setQuery($query); $max = (int) $this->_db->loadResult(); // Return the largest ordering value + 1. return $max + 1; }
/** * Returns a record count for the query. * * @param JDatabaseQuery|string $query The query. * * @return integer Number of rows for query. * * @since 12.2 */ protected function _getListCount($query) { // Use fast COUNT(*) on JDatabaseQuery objects if there is no GROUP BY or HAVING clause: if ($query instanceof JDatabaseQuery && $query->type == 'select' && $query->group === null && $query->union === null && $query->unionAll === null && $query->having === null) { $query = clone $query; $query->clear('select')->clear('order')->clear('limit')->clear('offset')->select('COUNT(*)'); $this->_db->setQuery($query); return (int) $this->_db->loadResult(); } // Otherwise fall back to inefficient way of counting all results. // Remove the limit and offset part if it's a JDatabaseQuery object if ($query instanceof JDatabaseQuery) { $query = clone $query; $query->clear('limit')->clear('offset'); } $this->_db->setQuery($query); $this->_db->execute(); return (int) $this->_db->getNumRows(); }
private function prepareLocation() { $result = array(); $query = $this->db->getQuery(true); $query->select('a.id')->from($this->db->quoteName('#__social_fields', 'a'))->where('a.unique_key = ' . $this->db->quote('ADDRESS')); $this->db->setQuery($query); $typeId = (int) $this->db->loadResult(); if ($typeId > 0) { $query = $this->db->getQuery(true); $query->select('a.data')->from($this->db->quoteName('#__social_fields_data', 'a'))->where('a.uid = ' . (int) $this->user_id)->where('a.field_id = ' . (int) $typeId); $this->db->setQuery($query); $result = (string) $this->db->loadResult(); if (\JString::strlen($result) > 0) { // Set values to variables $result = json_decode($result, true); } else { $result = array(); } } $this->location = array_key_exists('city', $result) ? $result['city'] : ''; $this->country_code = array_key_exists('country', $result) ? $result['country'] : ''; }
/** * Return a location name where the user lives. * * <code> * $userId = 1; * * $profile = new ITPrismIntegrateProfileJomSocial($userId); * $location = $profile->getLocation(); * </code> * * @return string */ public function getLocation() { if (is_null($this->location)) { $result = ""; $query = $this->db->getQuery(true); $query->select("a.id")->from($this->db->quoteName("#__community_fields", "a"))->where("a.type = " . $this->db->quote("country")); $this->db->setQuery($query); $typeId = $this->db->loadResult(); if (!empty($typeId)) { $query = $this->db->getQuery(true); $query->select("a.value")->from($this->db->quoteName("#__community_fields_values", "a"))->where("a.user_id = " . (int) $this->user_id)->where("a.field_id = " . (int) $typeId); $this->db->setQuery($query); $result = $this->db->loadResult(); if (!$result) { // Set values to variables $result = ""; } } $this->location = $result; } return $this->location; }
/** * Return a location name where the user lives. * * <code> * $userId = 1; * * $profile = new Prism\Integration\Profile\JomSocial(\JFactory::getDbo()); * $profile->load($userId); * * $location = $profile->getLocation(); * </code> * * @return string */ public function getLocation() { if ($this->location === null) { $result = ''; $query = $this->db->getQuery(true); $query->select('a.id')->from($this->db->quoteName('#__community_fields', 'a'))->where('a.type = ' . $this->db->quote('country')); $this->db->setQuery($query); $typeId = (int) $this->db->loadResult(); if ($typeId > 0) { $query = $this->db->getQuery(true); $query->select('a.value')->from($this->db->quoteName('#__community_fields_values', 'a'))->where('a.user_id = ' . (int) $this->user_id)->where('a.field_id = ' . (int) $typeId); $this->db->setQuery($query); $result = $this->db->loadResult(); if (!$result) { // Set values to variables $result = ''; } } $this->location = $result; } return $this->location; }
private function prepareLocation() { $result = array(); $query = $this->db->getQuery(true); $query->select("a.id")->from($this->db->quoteName("#__social_fields", "a"))->where("a.unique_key = " . $this->db->quote("ADDRESS")); $this->db->setQuery($query); $typeId = $this->db->loadResult(); if (!empty($typeId)) { $query = $this->db->getQuery(true); $query->select("a.data")->from($this->db->quoteName("#__social_fields_data", "a"))->where("a.uid = " . (int) $this->user_id)->where("a.field_id = " . (int) $typeId); $this->db->setQuery($query); $result = $this->db->loadResult(); if (!empty($result)) { // Set values to variables $result = json_decode($result, true); } else { $result = array(); } } $this->location = isset($result["city"]) ? $result["city"] : ""; $this->country_code = isset($result["country"]) ? $result["country"] : ""; }
/** * Listener for the `onContentAfterTitle` event * * @param string $context The context of the content being passed to the plugin. * @param object &$article The article object. Note $article->text is also available * @param object &$params The article params * @param integer $page The 'page' number * * @return void * * @since 1.0 */ public function onContentAfterTitle($context, &$article, &$params, $page) { /* * Validate the plugin should run in the current context */ // Context check - This only works for com_content if (strpos($context, 'com_content') === false) { return; } // Additional context check; we only want this for the component! if (strpos($this->app->scope, 'mod_') === 0) { return; } // Check if the plugin is enabled if (JPluginHelper::isEnabled('content', 'joomlarrssb') == false) { return; } // Make sure the document is an HTML document $document = $this->app->getDocument(); if ($document->getType() != 'html') { return; } /* * Start processing the plugin event */ // Set the parameters $displayEmail = $this->params->get('displayEmail', '1'); $displayFacebook = $this->params->get('displayFacebook', '1'); $displayGoogle = $this->params->get('displayGoogle', '1'); $displayLinkedin = $this->params->get('displayLinkedin', '1'); $displayPinterest = $this->params->get('displayPinterest', '1'); $displayTwitter = $this->params->get('displayTwitter', '1'); $selectedCategories = $this->params->def('displayCategories', ''); $position = $this->params->def('displayPosition', 'top'); $view = $this->app->input->getCmd('view', ''); $shorten = $this->params->def('useYOURLS', true); // Check whether we're displaying the plugin in the current view if ($this->params->get('view' . ucfirst($view), '1') == '0') { return; } // If we're not in the article view, we have to get the full $article object ourselves if ($view == 'featured' || $view == 'category') { /* * We only want to handle com_content items; if this function returns null, there's no DB item * Also, make sure the object isn't already loaded and undo previous plugin processing */ $data = $this->loadArticle($article); if (!is_null($data) && !isset($article->catid)) { $article = $data; } } // Make sure we have a category ID, otherwise, end processing $properties = get_object_vars($article); if (!array_key_exists('catid', $properties)) { return; } // Get the current category if (is_null($article->catid)) { $currentCategory = 0; } else { $currentCategory = $article->catid; } // Define category restrictions if (is_array($selectedCategories)) { $categories = $selectedCategories; } elseif ($selectedCategories == '') { $categories = [$currentCategory]; } else { $categories = [$selectedCategories]; } // If we aren't in a defined category, exit if (!in_array($currentCategory, $categories)) { // If we made it this far, we probably deleted the text object; reset it if (!isset($article->text)) { $article->text = $article->introtext; } return; } // Create the article slug $article->slug = $article->alias ? $article->id . ':' . $article->alias : $article->id; // Build the URL for the plugins to use - the site URL should only be the scheme and host segments, JRoute will take care of the rest $siteURL = JUri::getInstance()->toString(['scheme', 'host', 'port']); $itemURL = $siteURL . JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catid)); // Check if we have an intro text image (Priority: fulltext image, intro image, content image, category image) $images = json_decode($article->images); if (isset($images->image_fulltext) && !empty($images->image_fulltext)) { $imageOg = $images->image_fulltext; } elseif (isset($images->image_intro) && !empty($images->image_intro)) { $imageOg = $images->image_intro; } else { // Get the content and merge in the template; first see if $article->text is defined if (!isset($article->text)) { $article->text = $article->introtext; } // Always run this preg_match as the results are also used in the layout $pattern = "/<img[^>]*src\\=['\"]?(([^>]*)(jpg|gif|JPG|png|jpeg))['\"]?/"; preg_match($pattern, $article->text, $matches); $imageOg = isset($matches[1]) ? $matches[1] : ''; // Check for category image if (empty($imageOg)) { // We get the article mostly from content plugin, so we need to do a query and can't do a join.. $query = $this->db->getQuery(true); $query->select('params')->from($this->db->quoteName('#__categories'))->where($this->db->quoteName('id') . ' = ' . $this->db->q($article->catid)); $this->db->setQuery($query); $result = $this->db->loadResult(); if ($result) { $categoryParams = json_decode($result); if (isset($categoryParams->image) && !empty($categoryParams->image)) { $imageOg = $categoryParams->image; } } } } // Make sure the image has an absolute URL if (!empty($imageOg)) { // If the image isn't prefixed with http then assume it's relative and put the site URL in front if (strpos($imageOg, 'http') !== 0) { $imageOg = substr(JUri::root(), 0, -1) . (substr($imageOg, 0, 1) !== '/' ? '/' : '') . $imageOg; } } /* * Add template metadata per the context */ // The metadata in this check should only be applied on a single article view if ($context === 'com_content.article') { if (!empty($imageOg)) { if (!$document->getMetaData('og:image')) { $document->setMetaData('og:image', $imageOg, 'property'); } if (!$document->getMetaData('twitter:image')) { $document->setMetaData('twitter:image', $imageOg); } } $description = !empty($article->metadesc) ? $article->metadesc : $article->introtext; $description = JHtml::_('string.truncate', $description, 200, true, false); // OpenGraph metadata if (!$document->getMetaData('og:description')) { $document->setMetaData('og:description', $description, 'property'); } if (!$document->getMetaData('og:title')) { $document->setMetaData('og:title', $article->title, 'property'); } if (!$document->getMetaData('og:type')) { $document->setMetaData('og:type', 'article', 'property'); } if (!$document->getMetaData('og:url')) { $document->setMetaData('og:url', $itemURL, 'property'); } // Twitter Card metadata if (!$document->getMetaData('twitter:description')) { $document->setMetaData('twitter:description', $description); } if (!$document->getMetaData('twitter:title')) { $document->setMetaData('twitter:title', JHtml::_('string.truncate', $article->title, 70, true, false)); } } // Check that we're actually displaying a button if ($displayEmail == '0' && $displayFacebook == '0' && $displayGoogle == '0' && $displayLinkedin == '0' && $displayPinterest == '0' && $displayTwitter == '0') { return; } // Apply our shortened URL if configured if ($shorten) { $data = ['signature' => $this->params->def('YOURLSAPIKey', '2909bc72e7'), 'action' => 'shorturl', 'url' => $itemURL, 'format' => 'simple']; try { $response = JHttpFactory::getHttp()->post($this->params->def('YOURLSUrl', 'http://joom.la') . '/yourls-api.php', $data); if ($response->code == 200) { $itemURL = $response->body; } } catch (Exception $e) { // In case of an error connecting out here, we can still use the 'real' URL. Carry on. } } // Load the layout ob_start(); $template = JPluginHelper::getLayoutPath('content', 'joomlarrssb'); include $template; $output = ob_get_clean(); // Add the output if ($position == 'top') { $article->introtext = $output . $article->introtext; $article->text = $output . $article->text; } else { $article->introtext = $output . $article->introtext; $article->text .= $output; } return; }
public function getPagination($total = null) { if (empty($total)) { $this->db->setQuery('SELECT count(*)' . ' FROM #__acctexp_' . $this->table . $this->getConstraints()); $total = $this->db->loadResult(); } return new bsPagination($total, $this->state->limitstart, $this->state->limit); }
/** * CVS Dump * * @param object $items Items to pass through * @param string $report Name of report to return. * * @return bool * * @since 1.7.0 */ public function getCsv($items, $report) { $date = new JDate('now'); $jWeb = new JApplicationWeb(); $csv = fopen('php://output', 'w'); $jWeb->clearHeaders(); // Clean the output buffer, @ob_end_clean(); @ob_start(); header("Content-type: text/csv"); header("Content-Disposition: attachment; filename=report." . $report . '.' . $date->format('Y-m-d-His') . ".csv"); header("Pragma: no-cache"); header("Expires: 0"); $count = 0; foreach ($items as $line) { foreach ($line as $c => $item) { if ($c == 'params') { $reg = new Joomla\Registry\Registry(); $reg->loadString($item); $params = $reg->toObject(); unset($line->params); $line = (object) array_merge((array) $line, (array) $params); } elseif ($c == 'attribs') { $reg = new Joomla\Registry\Registry(); $reg->loadString($item); $params = $reg->toObject(); $params_att = new stdClass(); foreach ($params as $p => $item_p) { $p = 'att_' . $p; if ($p == 'sex') { switch ($item_p) { case 0: $params_att->{$p} = 'M'; break; case 1: $params_att->{$p} = 'F'; break; } } else { $params_att->{$p} = $item_p; } } unset($line->attribs); $line = (object) array_merge((array) $line, (array) $params_att); } elseif ($c == 'kml_params') { $reg = new Joomla\Registry\Registry(); $reg->loadString($item); $params = $reg->toObject(); unset($line->kml_params); $line = (object) array_merge((array) $line, (array) $params); } elseif ($c == 'category_params') { $reg = new Joomla\Registry\Registry(); $reg->loadString($item); $params = $reg->toObject(); unset($line->category_params); $line = (object) array_merge((array) $line, (array) $params); } elseif ($c == 'metadata') { $reg = new Joomla\Registry\Registry(); $reg->loadString($item); $params = $reg->toObject(); unset($line->metadata); $line = (object) array_merge((array) $line, (array) $params); } elseif ($c == 'con_position') { $pos = []; if ($item != 0) { $positions = explode(',', $item); foreach ($positions as $p => $position) { $query = $this->db->getQuery(true); // Join on Position. $query->select('name'); $query->from('#__churchdirectory_position'); $query->where('id =' . $position); $this->db->setQuery($query); $pos[] = $this->db->loadResult(); } } else { $pos[] = null; } unset($line->con_position); $line = (object) array_merge((array) $line, ['con_position' => implode(",", $pos)]); } elseif ($c == 'image') { $line->{$c} = JUri::root() . $item; } } if ($count == 0) { $array = get_object_vars($line); fputcsv($csv, array_keys($array)); } $count = 1; fputcsv($csv, (array) $line); } @ob_flush(); @flush(); fclose($csv); exit; }
/** * This method loads the first field of the first row returned by the query. * * @return string|null The value returned in the query or null if the query failed. * * @throws \RuntimeException */ public function loadResult() { return $this->_db->loadResult(); }