コード例 #1
0
	/**
	 * Test for the JDatabaseDriver::__call method.
	 *
	 * @return  void
	 *
	 * @since   12.1
	 */
	public function test__callQuote()
	{
		$this->assertThat(
			$this->db->q('foo'),
			$this->equalTo($this->db->quote('foo')),
			'Tests the q alias of quote.'
		);
	}
コード例 #2
0
ファイル: table.php プロジェクト: deenison/joomla-cms
 /**
  * Method to provide a shortcut to binding, checking and storing a FOFTable
  * instance to the database table.  The method will check a row in once the
  * data has been stored and if an ordering filter is present will attempt to
  * reorder the table rows based on the filter.  The ordering filter is an instance
  * property name.  The rows that will be reordered are those whose value matches
  * the FOFTable instance for the property specified.
  *
  * @param   mixed   $src             An associative array or object to bind to the FOFTable instance.
  * @param   string  $orderingFilter  Filter for the order updating
  * @param   mixed   $ignore          An optional array or space separated list of properties
  *                                   to ignore while binding.
  *
  * @return  boolean  True on success.
  */
 public function save($src, $orderingFilter = '', $ignore = '')
 {
     // Attempt to bind the source to the instance.
     if (!$this->bind($src, $ignore)) {
         return false;
     }
     // Run any sanity checks on the instance and verify that it is ready for storage.
     if (!$this->check()) {
         return false;
     }
     // Attempt to store the properties to the database table.
     if (!$this->store()) {
         return false;
     }
     // Attempt to check the row in, just in case it was checked out.
     if (!$this->checkin()) {
         return false;
     }
     // If an ordering filter is set, attempt reorder the rows in the table based on the filter and value.
     if ($orderingFilter) {
         $filterValue = $this->{$orderingFilter};
         $this->reorder($orderingFilter ? $this->_db->qn($orderingFilter) . ' = ' . $this->_db->q($filterValue) : '');
     }
     // Set the error to empty and return true.
     $this->setError('');
     return true;
 }
コード例 #3
0
ファイル: type.php プロジェクト: GitIPFire/Homeworks
 /**
  * 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;
 }
コード例 #4
0
ファイル: list.php プロジェクト: jfquestiaux/fabrik
 /**
  * Get the the collation for a given table
  *
  * @param   Registry        $params
  * @param   JDatabaseDriver $db
  * @param   string          $tableName
  *
  * @return string
  */
 protected function getOriginalCollation($params, $db, $tableName)
 {
     if (!empty($tableName)) {
         $db->setQuery('SHOW TABLE STATUS LIKE ' . $db->q($tableName));
         $info = $db->loadObject();
         $origCollation = is_object($info) ? $info->Collation : $params->get('collation', 'none');
     } else {
         $origCollation = $params->get('collation', 'none');
     }
     return $origCollation;
 }
コード例 #5
0
 /**
  * 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;
 }