Source for file corecontent.php

Documentation is available at corecontent.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Libraries
  4.  * @subpackage  Table
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Core content table
  14.  *
  15.  * @package     Joomla.Libraries
  16.  * @subpackage  Table
  17.  * @since       3.1
  18.  */
  19. class JTableCorecontent extends JTable
  20. {
  21.     /**
  22.      * Constructor
  23.      *
  24.      * @param   JDatabaseDriver  $db  A database connector object
  25.      *
  26.      * @since   3.1
  27.      */
  28.     public function __construct($db)
  29.     {
  30.         parent::__construct('#__ucm_content''core_content_id'$db);
  31.     }
  32.  
  33.     /**
  34.      * Overloaded bind function
  35.      *
  36.      * @param   array  $array   Named array
  37.      * @param   mixed  $ignore  An optional array or space separated list of properties
  38.      *                           to ignore while binding.
  39.      *
  40.      * @return  mixed  Null if operation was satisfactory, otherwise returns an error string
  41.      *
  42.      * @see     JTable::bind()
  43.      * @since   3.1
  44.      */
  45.     public function bind($array$ignore '')
  46.     {
  47.         if (isset($array['core_params']&& is_array($array['core_params']))
  48.         {
  49.             $registry new JRegistry;
  50.             $registry->loadArray($array['core_params']);
  51.             $array['core_params'= (string) $registry;
  52.         }
  53.  
  54.         if (isset($array['core_metadata']&& is_array($array['core_metadata']))
  55.         {
  56.             $registry new JRegistry;
  57.             $registry->loadArray($array['core_metadata']);
  58.             $array['core_metadata'= (string) $registry;
  59.         }
  60.  
  61.         if (isset($array['core_images']&& is_array($array['core_images']))
  62.         {
  63.             $registry new JRegistry;
  64.             $registry->loadArray($array['core_images']);
  65.             $array['core_images'= (string) $registry;
  66.         }
  67.  
  68.         if (isset($array['core_urls']&& is_array($array['core_urls']))
  69.         {
  70.             $registry new JRegistry;
  71.             $registry->loadArray($array['core_urls']);
  72.             $array['core_urls'= (string) $registry;
  73.         }
  74.  
  75.         if (isset($array['core_body']&& is_array($array['core_body']))
  76.         {
  77.             $registry new JRegistry;
  78.             $registry->loadArray($array['core_body']);
  79.             $array['core_body'= (string) $registry;
  80.         }
  81.  
  82.         return parent::bind($array$ignore);
  83.     }
  84.  
  85.     /**
  86.      * Overloaded check function
  87.      *
  88.      * @return  boolean  True on success, false on failure
  89.      *
  90.      * @see     JTable::check()
  91.      * @since   3.1
  92.      */
  93.     public function check()
  94.     {
  95.         if (trim($this->core_title== '')
  96.         {
  97.             $this->setError(JText::_('LIB_CMS_WARNING_PROVIDE_VALID_NAME'));
  98.             return false;
  99.         }
  100.  
  101.         if (trim($this->core_alias== '')
  102.         {
  103.             $this->core_alias $this->core_title;
  104.         }
  105.  
  106.         $this->core_alias JApplication::stringURLSafe($this->core_alias);
  107.  
  108.         if (trim(str_replace('-'''$this->core_alias)) == '')
  109.         {
  110.             $this->core_alias JFactory::getDate()->format('Y-m-d-H-i-s');
  111.         }
  112.  
  113.         // Check the publish down date is not earlier than publish up.
  114.         if ($this->core_publish_down $this->_db->getNullDate(&& $this->core_publish_down $this->core_publish_up)
  115.         {
  116.             // Swap the dates.
  117.             $temp $this->core_publish_up;
  118.             $this->core_publish_up $this->core_publish_down;
  119.             $this->core_publish_down $temp;
  120.         }
  121.  
  122.         // Clean up keywords -- eliminate extra spaces between phrases
  123.         // and cr (\r) and lf (\n) characters from string
  124.         if (!empty($this->core_metakey))
  125.         {
  126.             // Only process if not empty
  127.  
  128.             // Array of characters to remove
  129.             $bad_characters array("\n""\r""\"""<"">");
  130.  
  131.             // Remove bad characters
  132.             $after_clean JString::str_ireplace($bad_characters""$this->core_metakey);
  133.  
  134.             // Create array using commas as delimiter
  135.             $keys explode(','$after_clean);
  136.  
  137.             $clean_keys array();
  138.  
  139.             foreach ($keys as $key)
  140.             {
  141.                 if (trim($key))
  142.                 {
  143.                     // Ignore blank keywords
  144.                     $clean_keys[trim($key);
  145.                 }
  146.             }
  147.             // Put array back together delimited by ", "
  148.             $this->core_metakey implode(", "$clean_keys);
  149.         }
  150.  
  151.         return true;
  152.     }
  153.  
  154.     /**
  155.      * Override JTable delete method to include deleting corresponding row from #__ucm_base.
  156.      *
  157.      * @param   integer  $pk  primary key value to delete. Must be set or throws an exception.
  158.      *
  159.      * @return  boolean  True on success.
  160.      *
  161.      * @since   3.1
  162.      * @throws  UnexpectedValueException
  163.      */
  164.     public function delete($pk null)
  165.     {
  166.         $baseTable JTable::getInstance('Ucm');
  167.         return parent::delete($pk&& $baseTable->delete($pk);
  168.     }
  169.  
  170.     /**
  171.      * Method to delete a row from the #__ucm_content table by content_item_id.
  172.      *
  173.      * @param   integer  $contentItemId  value of the core_content_item_id to delete. Corresponds to the primary key of the content table.
  174.      *
  175.      * @return  boolean  True on success.
  176.      *
  177.      * @since   3.1
  178.      * @throws  UnexpectedValueException
  179.      */
  180.     public function deleteByContentId($contentItemId null)
  181.     {
  182.         if ($contentItemId === null || ((int) $contentItemId=== 0)
  183.         {
  184.             throw new UnexpectedValueException('Null content item key not allowed.');
  185.         }
  186.  
  187.         $db $this->getDbo();
  188.         $query $db->getQuery(true);
  189.         $query->select($db->quoteName('core_content_id'))
  190.             ->from($db->quoteName('#__ucm_content'))
  191.             ->where($db->quoteName('core_content_item_id'' = ' . (int) $contentItemId);
  192.         $db->setQuery($query);
  193.         if ($ucmId $db->loadResult())
  194.         {
  195.             return $this->delete($ucmId);
  196.         }
  197.         else
  198.         {
  199.             return true;
  200.         }
  201.     }
  202.  
  203.     /**
  204.      * Overrides JTable::store to set modified data and user id.
  205.      *
  206.      * @param   boolean  $updateNulls  True to update fields even if they are null.
  207.      *
  208.      * @return  boolean  True on success.
  209.      *
  210.      * @since   3.1
  211.      */
  212.     public function store($updateNulls false)
  213.     {
  214.         $date JFactory::getDate();
  215.         $user JFactory::getUser();
  216.  
  217.         if ($this->core_content_id)
  218.         {
  219.             // Existing item
  220.             $this->core_modified_time $date->toSql();
  221.             $this->core_modified_user_id $user->get('id');
  222.             $isNew false;
  223.         }
  224.         else
  225.         {
  226.             // New content item. A content item core_created_time and core_created_user_id field can be set by the user,
  227.             // so we don't touch either of these if they are set.
  228.             if (!(int) $this->core_created_time)
  229.             {
  230.                 $this->core_created_time $date->toSql();
  231.             }
  232.  
  233.             if (empty($this->core_created_user_id))
  234.             {
  235.                 $this->core_created_user_id $user->get('id');
  236.             }
  237.  
  238.             $isNew true;
  239.  
  240.         }
  241.  
  242.         $oldRules $this->getRules();
  243.         if (empty($oldRules))
  244.         {
  245.             $this->setRules('{}');
  246.         }
  247.  
  248.         $result parent::store($updateNulls);
  249.  
  250.         return $result && $this->storeUcmBase($updateNulls$isNew);
  251.     }
  252.  
  253.     /**
  254.      * Insert or update row in ucm_base table
  255.      *
  256.      * @param   boolean  $updateNulls  True to update fields even if they are null.
  257.      * @param   boolean  $isNew        if true, need to insert. Otherwise update.
  258.      *
  259.      * @return  boolean  True on success.
  260.      *
  261.      * @since   3.1
  262.      */
  263.     protected function storeUcmBase($updateNulls false$isNew false)
  264.     {
  265.         // Store the ucm_base row
  266.         $db $this->getDbo();
  267.         $query $db->getQuery(true);
  268.         $languageId JHelperContent::getLanguageId($this->core_language);
  269.  
  270.         if ($isNew)
  271.         {
  272.             $query->insert($db->quoteName('#__ucm_base'))
  273.                 ->columns(array($db->quoteName('ucm_id')$db->quoteName('ucm_item_id')$db->quoteName('ucm_type_id')$db->quoteName('ucm_language_id')))
  274.                 ->values(
  275.                     $db->quote($this->core_content_id', '
  276.                     . $db->quote($this->core_content_item_id', '
  277.                     . $db->quote($this->core_type_id', '
  278.                     . $db->quote($languageId)
  279.             );
  280.         }
  281.         else
  282.         {
  283.             $query->update($db->quoteName('#__ucm_base'))
  284.                 ->set($db->quoteName('ucm_item_id'' = ' $db->quote($this->core_content_item_id))
  285.                 ->set($db->quoteName('ucm_type_id'' = ' $db->quote($this->core_type_id))
  286.                 ->set($db->quoteName('ucm_language_id'' = ' $db->quote($languageId))
  287.                 ->where($db->quoteName('ucm_id'' = ' $db->quote($this->core_content_id));
  288.         }
  289.  
  290.         $db->setQuery($query);
  291.  
  292.         return $db->execute();
  293.     }
  294.  
  295.     /**
  296.      * Method to set the publishing state for a row or list of rows in the database
  297.      * table. The method respects checked out rows by other users and will attempt
  298.      * to checkin rows that it can after adjustments are made.
  299.      *
  300.      * @param   mixed    $pks     An optional array of primary key values to update.  If not set the instance property value is used.
  301.      * @param   integer  $state   The publishing state. eg. [0 = unpublished, 1 = published]
  302.      * @param   integer  $userId  The user id of the user performing the operation.
  303.      *
  304.      * @return  boolean  True on success.
  305.      *
  306.      * @since   3.1
  307.      */
  308.     public function publish($pks null$state 1$userId 0)
  309.     {
  310.         $k $this->_tbl_key;
  311.  
  312.         // Sanitize input.
  313.         JArrayHelper::toInteger($pks);
  314.         $userId = (int) $userId;
  315.         $state = (int) $state;
  316.  
  317.         // If there are no primary keys set check to see if the instance key is set.
  318.         if (empty($pks))
  319.         {
  320.             if ($this->$k)
  321.             {
  322.                 $pks array($this->$k);
  323.             }
  324.             // Nothing to set publishing state on, return false.
  325.             else
  326.             {
  327.                 $this->setError(JText::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED'));
  328.                 return false;
  329.             }
  330.         }
  331.  
  332.         $pksImploded implode(','$pks);
  333.  
  334.         // Get the JDatabaseQuery object
  335.         $query $this->_db->getQuery(true);
  336.  
  337.         // Update the publishing state for rows with the given primary keys.
  338.         $query->update($this->_db->quoteName($this->_tbl))
  339.             ->set($this->_db->quoteName('core_state'' = ' . (int) $state)
  340.             ->where($this->_db->quoteName($k'IN (' $pksImploded ')');
  341.  
  342.         // Determine if there is checkin support for the table.
  343.         $checkin false;
  344.         if (property_exists($this'core_checked_out_user_id'&& property_exists($this'core_checked_out_time'))
  345.         {
  346.             $checkin true;
  347.             $query->where(' (' $this->_db->quoteName('core_checked_out_user_id'' = 0 OR ' $this->_db->quoteName('core_checked_out_user_id'' = ' . (int) $userId ')');
  348.         }
  349.         $this->_db->setQuery($query);
  350.  
  351.         try
  352.         {
  353.             $this->_db->execute();
  354.         }
  355.         catch (RuntimeException $e)
  356.         {
  357.             $this->setError($e->getMessage());
  358.             return false;
  359.         }
  360.  
  361.         // If checkin is supported and all rows were adjusted, check them in.
  362.         if ($checkin && (count($pks== $this->_db->getAffectedRows()))
  363.         {
  364.             // Checkin the rows.
  365.             foreach ($pks as $pk)
  366.             {
  367.                 $this->checkin($pk);
  368.             }
  369.         }
  370.  
  371.         // If the JTable instance value is in the list of primary keys that were set, set the instance.
  372.         if (in_array($this->$k$pks))
  373.         {
  374.             $this->core_state $state;
  375.         }
  376.  
  377.         $this->setError('');
  378.  
  379.         return true;
  380.     }
  381. }

Documentation generated on Tue, 19 Nov 2013 14:57:37 +0100 by phpDocumentor 1.4.3