You've already forked joomla_test
first commit
This commit is contained in:
138
libraries/cms/ucm/base.php
Normal file
138
libraries/cms/ucm/base.php
Normal file
@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Libraries
|
||||
* @subpackage UCM
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('JPATH_BASE') or die;
|
||||
|
||||
/**
|
||||
* Base class for implementing UCM
|
||||
*
|
||||
* @package Joomla.Libraries
|
||||
* @subpackage UCM
|
||||
* @since 3.1
|
||||
*/
|
||||
class JUcmBase implements JUcm
|
||||
{
|
||||
/**
|
||||
* The UCM type object
|
||||
*
|
||||
* @var JUcmType
|
||||
* @since 3.1
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* The alias for the content table
|
||||
*
|
||||
* @var string
|
||||
* @since 3.1
|
||||
*/
|
||||
protected $alias;
|
||||
|
||||
/**
|
||||
* Instantiate the UcmBase.
|
||||
*
|
||||
* @param string $alias The alias string
|
||||
* @param JUcmType $type The type object
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
public function __construct($alias = null, JUcmType $type = null)
|
||||
{
|
||||
// Setup dependencies.
|
||||
$input = JFactory::getApplication()->input;
|
||||
$this->alias = isset($alias) ? $alias : $input->get('option') . '.' . $input->get('view');
|
||||
|
||||
$this->type = isset($type) ? $type : $this->getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data to the appropriate table
|
||||
*
|
||||
* @param array $data Data to be stored
|
||||
* @param JTable $table JTable Object
|
||||
* @param string $primaryKey The primary key name
|
||||
*
|
||||
* @return boolean True on success
|
||||
*
|
||||
* @since 3.1
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function store($data, JTable $table = null, $primaryKey = null)
|
||||
{
|
||||
if (!$table)
|
||||
{
|
||||
$table = JTable::getInstance('Ucm');
|
||||
}
|
||||
|
||||
$ucmId = isset($data['ucm_id']) ? $data['ucm_id'] : null;
|
||||
$primaryKey = $primaryKey ? $primaryKey : $ucmId;
|
||||
|
||||
if (isset($primaryKey))
|
||||
{
|
||||
$table->load($primaryKey);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$table->bind($data);
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
throw new Exception($e->getMessage(), 500);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$table->store();
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
throw new Exception($e->getMessage(), 500);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the UCM Content type.
|
||||
*
|
||||
* @return object The UCM content type
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
$type = new JUcmType($this->alias);
|
||||
|
||||
return $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to map the base ucm fields
|
||||
*
|
||||
* @param array $original Data array
|
||||
* @param JUcmType $type UCM Content Type
|
||||
*
|
||||
* @return array Data array of UCM mappings
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
public function mapBase($original, JUcmType $type = null)
|
||||
{
|
||||
$type = $type ? $type : $this->type;
|
||||
|
||||
$data = array(
|
||||
'ucm_type_id' => $type->id,
|
||||
'ucm_item_id' => $original[$type->primary_key],
|
||||
'ucm_language_id' => JHelperContent::getLanguageId($original['language'])
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
256
libraries/cms/ucm/content.php
Normal file
256
libraries/cms/ucm/content.php
Normal file
@ -0,0 +1,256 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Libraries
|
||||
* @subpackage UCM
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('JPATH_BASE') or die;
|
||||
|
||||
/**
|
||||
* Base class for implementing UCM
|
||||
*
|
||||
* @package Joomla.Libraries
|
||||
* @subpackage UCM
|
||||
* @since 3.1
|
||||
*/
|
||||
class JUcmContent extends JUcmBase
|
||||
{
|
||||
/**
|
||||
* The related table object
|
||||
*
|
||||
* @var JTable
|
||||
* @since 3.1
|
||||
*/
|
||||
protected $table;
|
||||
|
||||
/**
|
||||
* The UCM type object
|
||||
*
|
||||
* @var JUcmType
|
||||
* @since 3.1
|
||||
*/
|
||||
public $type;
|
||||
|
||||
/**
|
||||
* The alias for the content table
|
||||
*
|
||||
* @var string
|
||||
* @since 3.1
|
||||
*/
|
||||
protected $alias;
|
||||
|
||||
/**
|
||||
* The UCM data array
|
||||
*
|
||||
* @var array
|
||||
* @since 3.1
|
||||
*/
|
||||
public $ucmData;
|
||||
|
||||
/**
|
||||
* Instantiate JUcmContent.
|
||||
*
|
||||
* @param JTable $table The table object
|
||||
* @param sring $alias The type alias
|
||||
* @param JUcmType $type The type object
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
public function __construct(JTable $table = null, $alias = null, JUcmType $type = null)
|
||||
{
|
||||
// Setup dependencies.
|
||||
$input = JFactory::getApplication()->input;
|
||||
$this->alias = isset($alias) ? $alias : $input->get('option') . '.' . $input->get('view');
|
||||
|
||||
$this->type = isset($type) ? $type : $this->getType();
|
||||
|
||||
if ($table)
|
||||
{
|
||||
$this->table = $table;
|
||||
}
|
||||
else
|
||||
{
|
||||
$tableObject = json_decode($this->type->type->table);
|
||||
$this->table = JTable::getInstance($tableObject->special->type, $tableObject->special->prefix, $tableObject->special->config);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to save the data
|
||||
*
|
||||
* @param array $original The original data to be saved
|
||||
* @param JUcmType $type The UCM Type object
|
||||
*
|
||||
* @return boolean true
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
public function save($original = null, JUcmType $type = null)
|
||||
{
|
||||
$type = $type ? $type : $this->type;
|
||||
$ucmData = $original ? $this->mapData($original, $type) : $this->ucmData;
|
||||
|
||||
// Store the Common fields
|
||||
$this->store($ucmData['common']);
|
||||
|
||||
// Store the special fields
|
||||
if (isset($ucmData['special']))
|
||||
{
|
||||
$table = $this->table;
|
||||
$this->store($ucmData['special'], $table, '');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete content from the Core Content table
|
||||
*
|
||||
* @param mixed $pk The string/array of id's to delete
|
||||
* @param JUcmType $type The content type object
|
||||
*
|
||||
* @return boolean True if success
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
public function delete($pk, JUcmType $type = null)
|
||||
{
|
||||
$db = JFactory::getDbo();
|
||||
$type = $type ? $type : $this->type;
|
||||
|
||||
if (is_array($pk))
|
||||
{
|
||||
$pk = implode(',', $pk);
|
||||
}
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->delete('#__ucm_content')
|
||||
->where($db->quoteName('core_type_id') . ' = ' . (int) $type->type_id)
|
||||
->where($db->quoteName('core_content_item_id') . ' IN (' . $pk . ')');
|
||||
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map the original content to the Core Content fields
|
||||
*
|
||||
* @param array $original The original data array
|
||||
* @param JUcmType $type Type object for this data
|
||||
*
|
||||
* @return object $ucmData The mapped UCM data
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
public function mapData($original, JUcmType $type = null)
|
||||
{
|
||||
$contentType = isset($type) ? $type : $this->type;
|
||||
|
||||
$fields = json_decode($contentType->type->field_mappings);
|
||||
|
||||
$ucmData = array();
|
||||
|
||||
$common = (is_object($fields->common)) ? $fields->common : $fields->common[0];
|
||||
|
||||
foreach ($common as $i => $field)
|
||||
{
|
||||
if ($field && $field != 'null' && array_key_exists($field, $original))
|
||||
{
|
||||
$ucmData['common'][$i] = $original[$field];
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists('special', $ucmData))
|
||||
{
|
||||
$special = (is_object($fields->special)) ? $fields->special : $fields->special[0];
|
||||
|
||||
foreach ($special as $i => $field)
|
||||
{
|
||||
if ($field && $field != 'null' && array_key_exists($field, $original))
|
||||
{
|
||||
$ucmData['special'][$i] = $original[$field];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ucmData['common']['core_type_alias'] = $contentType->type->type_alias;
|
||||
$ucmData['common']['core_type_id'] = $contentType->type->type_id;
|
||||
|
||||
if (isset($ucmData['special']))
|
||||
{
|
||||
$ucmData['special']['ucm_id'] = $ucmData['common']['ucm_id'];
|
||||
}
|
||||
|
||||
$this->ucmData = $ucmData;
|
||||
|
||||
return $this->ucmData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store data to the appropriate table
|
||||
*
|
||||
* @param array $data Data to be stored
|
||||
* @param JTable $table JTable Object
|
||||
* @param boolean $primaryKey Flag that is true for data that are using #__ucm_content as their primary table
|
||||
*
|
||||
* @return Boolean true on success
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
protected function store($data, JTable $table = null, $primaryKey = null)
|
||||
{
|
||||
$table = $table ? $table : JTable::getInstance('Corecontent');
|
||||
|
||||
$typeId = $this->getType()->type->type_id;
|
||||
$primaryKey = $primaryKey ? $primaryKey : $this->getPrimaryKey($typeId, $data['core_content_item_id']);
|
||||
|
||||
if (!$primaryKey)
|
||||
{
|
||||
// Store the core UCM mappings
|
||||
$baseData = array();
|
||||
$baseData['ucm_type_id'] = $typeId;
|
||||
$baseData['ucm_item_id'] = $data['core_content_item_id'];
|
||||
$baseData['ucm_language_id'] = JHelperContent::getLanguageId($data['core_language']);
|
||||
|
||||
if (parent::store($baseData))
|
||||
{
|
||||
$primaryKey = $this->getPrimaryKey($typeId, $data['core_content_item_id']);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::store($data, $table, $primaryKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the primary key from #__ucm_base
|
||||
*
|
||||
* @param string $typeId The ID for the type
|
||||
* @param integer $contentItemId Value of the primary key in the legacy or secondary table
|
||||
*
|
||||
* @return integer The integer of the primary key
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
public function getPrimaryKey($typeId, $contentItemId)
|
||||
{
|
||||
$db = JFactory::getDbo();
|
||||
$queryccid = $db->getQuery(true);
|
||||
$queryccid->select($db->quoteName('ucm_id'))
|
||||
->from($db->quoteName('#__ucm_base'))
|
||||
->where(
|
||||
array(
|
||||
$db->quoteName('ucm_item_id') . ' = ' . $db->quote($contentItemId),
|
||||
$db->quoteName('ucm_type_id') . ' = ' . $db->quote($typeId)
|
||||
)
|
||||
);
|
||||
$db->setQuery($queryccid);
|
||||
$primaryKey = $db->loadResult();
|
||||
|
||||
return $primaryKey;
|
||||
}
|
||||
}
|
125
libraries/cms/ucm/type.php
Normal file
125
libraries/cms/ucm/type.php
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Libraries
|
||||
* @subpackage UCM
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('JPATH_BASE') or die;
|
||||
|
||||
/**
|
||||
* UCM Class for handling content types
|
||||
*
|
||||
* @package Joomla.Libraries
|
||||
* @subpackage UCM
|
||||
* @since 3.1
|
||||
*/
|
||||
class JUcmType implements JUcm
|
||||
{
|
||||
/**
|
||||
* The UCM Type
|
||||
*
|
||||
* @var JUcmType
|
||||
* @since 3.1
|
||||
*/
|
||||
public $type;
|
||||
|
||||
/**
|
||||
* The Database object
|
||||
*
|
||||
* @var JDatabaseDriver
|
||||
* @since 3.1
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* The alias for the content type
|
||||
*
|
||||
* @var string
|
||||
* @since 3.1
|
||||
*/
|
||||
protected $alias;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $alias The alias for the item
|
||||
* @param JDatabaseDriver $database The database object
|
||||
* @param JApplicationBase $application The application object
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
public function __construct($alias = null, JDatabaseDriver $database = null, JApplicationBase $application = null)
|
||||
{
|
||||
$this->db = $database ? $database : JFactory::getDbo();
|
||||
$app = $application ? $application : JFactory::getApplication();
|
||||
|
||||
// Make the best guess we can in the absence of information.
|
||||
$this->alias = $alias ? $alias : $app->input->get('option') . '.' . $app->input->get('view');
|
||||
$this->type = $this->getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Content Type
|
||||
*
|
||||
* @param integer $pk The primary key of the alias type
|
||||
*
|
||||
* @return object The UCM Type data
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
public function getType($pk = null)
|
||||
{
|
||||
if (!$pk)
|
||||
{
|
||||
$pk = $this->getTypeId();
|
||||
}
|
||||
|
||||
$query = $this->db->getQuery(true);
|
||||
$query->select('ct.*');
|
||||
$query->from($this->db->quoteName('#__content_types', 'ct'));
|
||||
|
||||
$query->where($this->db->quoteName('ct.type_id') . ' = ' . (int) $pk);
|
||||
$this->db->setQuery($query);
|
||||
|
||||
$type = $this->db->loadObject();
|
||||
|
||||
return $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the UCM type ID
|
||||
*
|
||||
* @param string $alias The string of the type alias
|
||||
*
|
||||
* @return mixed The ID of the requested type or false if type is not found
|
||||
*
|
||||
* @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();
|
||||
|
||||
if (!$id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $id;
|
||||
|
||||
}
|
||||
}
|
21
libraries/cms/ucm/ucm.php
Normal file
21
libraries/cms/ucm/ucm.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Libraries
|
||||
* @subpackage UCM
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
defined('JPATH_BASE') or die;
|
||||
|
||||
/**
|
||||
* Interface to handle UCM
|
||||
*
|
||||
* @package Joomla.Libraries
|
||||
* @subpackage UCM
|
||||
* @since 3.1
|
||||
*/
|
||||
interface JUcm
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user