You've already forked joomla_test
first commit
This commit is contained in:
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_weblinks
|
||||
*
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* Supports an HTML select list of categories
|
||||
*
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_weblinks
|
||||
* @since 1.6
|
||||
*/
|
||||
class JFormFieldOrdering extends JFormField
|
||||
{
|
||||
/**
|
||||
* The form field type.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $type = 'Ordering';
|
||||
|
||||
/**
|
||||
* Method to get the field input markup.
|
||||
*
|
||||
* @return string The field input markup.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getInput()
|
||||
{
|
||||
$html = array();
|
||||
$attr = '';
|
||||
|
||||
// Initialize some field attributes.
|
||||
$attr .= $this->element['class'] ? ' class="'.(string) $this->element['class'].'"' : '';
|
||||
$attr .= ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
|
||||
$attr .= $this->element['size'] ? ' size="'.(int) $this->element['size'].'"' : '';
|
||||
|
||||
// Initialize JavaScript field attributes.
|
||||
$attr .= $this->element['onchange'] ? ' onchange="'.(string) $this->element['onchange'].'"' : '';
|
||||
|
||||
// Get some field values from the form.
|
||||
$weblinkId = (int) $this->form->getValue('id');
|
||||
$categoryId = (int) $this->form->getValue('catid');
|
||||
|
||||
// Build the query for the ordering list.
|
||||
$query = 'SELECT ordering AS value, title AS text' .
|
||||
' FROM #__weblinks' .
|
||||
' WHERE catid = ' . (int) $categoryId .
|
||||
' ORDER BY ordering';
|
||||
|
||||
// Create a read-only list (no name) with a hidden input to store the value.
|
||||
if ((string) $this->element['readonly'] == 'true')
|
||||
{
|
||||
$html[] = JHtml::_('list.ordering', '', $query, trim($attr), $this->value, $weblinkId ? 0 : 1);
|
||||
$html[] = '<input type="hidden" name="'.$this->name.'" value="'.$this->value.'"/>';
|
||||
}
|
||||
// Create a regular list.
|
||||
else {
|
||||
$html[] = JHtml::_('list.ordering', $this->name, $query, trim($attr), $this->value, $weblinkId ? 0 : 1);
|
||||
}
|
||||
|
||||
return implode($html);
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
249
administrator/components/com_weblinks/models/forms/weblink.xml
Normal file
249
administrator/components/com_weblinks/models/forms/weblink.xml
Normal file
@ -0,0 +1,249 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<form>
|
||||
<fieldset addfieldpath="/administrator/components/com_categories/models/fields">
|
||||
<field name="id" type="text" default="0" label="JGLOBAL_FIELD_ID_LABEL"
|
||||
readonly="true" class="readonly"
|
||||
description="JGLOBAL_FIELD_ID_DESC"/>
|
||||
|
||||
<field name="title" type="text" class="inputbox"
|
||||
size="40" label="JGLOBAL_TITLE"
|
||||
description="COM_WEBLINKS_FIELD_TITLE_DESC" required="true" />
|
||||
|
||||
<field name="alias" type="text" class="inputbox"
|
||||
size="40" label="JFIELD_ALIAS_LABEL"
|
||||
description="COM_WEBLINKS_FIELD_ALIAS_DESC" />
|
||||
|
||||
<field name="catid" type="categoryedit" extension="com_weblinks"
|
||||
label="JCATEGORY" description="COM_WEBLINKS_FIELD_CATEGORY_DESC"
|
||||
class="inputbox"
|
||||
>
|
||||
</field>
|
||||
|
||||
|
||||
<field name="url" type="url" class="inputbox"
|
||||
filter="url"
|
||||
size="40" label="COM_WEBLINKS_FIELD_URL_LABEL"
|
||||
description="COM_WEBLINKS_FIELD_URL_DESC" required="true" />
|
||||
|
||||
<field name="description" type="editor" buttons="true" hide="pagebreak,readmore"
|
||||
class="inputbox"
|
||||
filter="JComponentHelper::filterText"
|
||||
label="JGLOBAL_DESCRIPTION" description="COM_WEBLINKS_FIELD_DESCRIPTION_DESC" />
|
||||
|
||||
<field name="hits"
|
||||
type="text"
|
||||
class="readonly"
|
||||
size="6" label="JGLOBAL_HITS"
|
||||
description="COM_WEBLINKS_HITS_DESC"
|
||||
readonly="true"
|
||||
filter="unset" />
|
||||
|
||||
|
||||
<field
|
||||
name="state"
|
||||
type="list"
|
||||
label="JSTATUS"
|
||||
description="COM_WEBLINKS_FIELD_STATE_DESC"
|
||||
class="inputbox span12 small"
|
||||
size="1"
|
||||
default="1">
|
||||
<option
|
||||
value="1">JPUBLISHED</option>
|
||||
<option
|
||||
value="0">JUNPUBLISHED</option>
|
||||
<option
|
||||
value="2">JARCHIVED</option>
|
||||
<option
|
||||
value="-3">COM_WEBLINKS_FIELD_VALUE_REPORTED</option>
|
||||
<option
|
||||
value="-2">JTRASHED</option>
|
||||
</field>
|
||||
|
||||
<field name="ordering" type="Ordering" class="inputbox"
|
||||
label="JFIELD_ORDERING_LABEL"
|
||||
description="JFIELD_ORDERING_DESC" />
|
||||
|
||||
<field name="access" type="accesslevel" label="JFIELD_ACCESS_LABEL"
|
||||
description="JFIELD_ACCESS_DESC" class="inputbox span12 small" size="1" />
|
||||
|
||||
<field
|
||||
name="language"
|
||||
type="contentlanguage"
|
||||
label="JFIELD_LANGUAGE_LABEL"
|
||||
description="COM_WEBLINKS_FIELD_LANGUAGE_DESC"
|
||||
class="inputbox span12 small">
|
||||
<option value="*">JALL</option>
|
||||
</field>
|
||||
|
||||
<field name="tags"
|
||||
type="tag"
|
||||
label="JTAG"
|
||||
description="JTAG_DESC"
|
||||
class="inputbox span12 small"
|
||||
multiple="true"
|
||||
>
|
||||
</field>
|
||||
|
||||
<field name="created" type="calendar"
|
||||
label="JGLOBAL_FIELD_CREATED_LABEL" description="JGLOBAL_FIELD_CREATED_DESC"
|
||||
class="inputbox" size="22" format="%Y-%m-%d %H:%M:%S"
|
||||
filter="user_utc" />
|
||||
|
||||
<field name="created_by" type="user"
|
||||
label="JGLOBAL_FIELD_CREATED_BY_LABEL" description="JGLOBAL_FIELD_CREATED_BY_Desc" />
|
||||
|
||||
<field name="created_by_alias" type="text"
|
||||
label="JGLOBAL_FIELD_CREATED_BY_ALIAS_LABEL" description="JGLOBAL_FIELD_CREATED_BY_ALIAS_DESC"
|
||||
class="inputbox" size="20" />
|
||||
|
||||
<field name="modified" type="calendar" class="readonly"
|
||||
label="JGLOBAL_FIELD_MODIFIED_LABEL" description="COM_WEBLINKS_FIELD_MODIFIED_DESC"
|
||||
size="22" readonly="true" format="%Y-%m-%d %H:%M:%S"
|
||||
filter="user_utc" />
|
||||
|
||||
<field name="modified_by" type="user"
|
||||
label="JGLOBAL_FIELD_MODIFIED_BY_LABEL"
|
||||
class="readonly"
|
||||
readonly="true"
|
||||
filter="unset" />
|
||||
|
||||
<field name="checked_out" type="hidden" filter="unset" />
|
||||
|
||||
<field name="checked_out_time" type="hidden" filter="unset" />
|
||||
|
||||
<field name="publish_up" type="calendar"
|
||||
label="JGLOBAL_FIELD_PUBLISH_UP_LABEL" description="JGLOBAL_FIELD_PUBLISH_UP_DESC"
|
||||
class="inputbox" format="%Y-%m-%d %H:%M:%S" size="22"
|
||||
filter="user_utc" />
|
||||
|
||||
<field name="publish_down" type="calendar"
|
||||
label="JGLOBAL_FIELD_PUBLISH_DOWN_LABEL" description="JGLOBAL_FIELD_PUBLISH_DOWN_DESC"
|
||||
class="inputbox" format="%Y-%m-%d %H:%M:%S" size="22"
|
||||
filter="user_utc" />
|
||||
|
||||
<field name="version" type="text" class="readonly"
|
||||
label="COM_WEBLINKS_FIELD_VERSION_LABEL" size="6" description="COM_WEBLINKS_FIELD_VERSION_DESC"
|
||||
readonly="true" filter="unset" />
|
||||
|
||||
|
||||
<field name="metakey" type="textarea"
|
||||
label="JFIELD_META_KEYWORDS_LABEL" description="JFIELD_META_KEYWORDS_DESC"
|
||||
class="inputbox" rows="3" cols="30" />
|
||||
|
||||
<field name="metadesc" type="textarea"
|
||||
label="JFIELD_META_DESCRIPTION_LABEL" description="JFIELD_META_DESCRIPTION_DESC"
|
||||
class="inputbox" rows="3" cols="30" />
|
||||
|
||||
<field name="xreference" type="text"
|
||||
label="JFIELD_XREFERENCE_LABEL" description="JFIELD_XREFERENCE_DESC"
|
||||
class="inputbox" size="20" />
|
||||
</fieldset>
|
||||
|
||||
<fields name="params">
|
||||
<fieldset name="jbasic" label="COM_WEBLINKS_FIELDSET_OPTIONS">
|
||||
<field name="target" type="list" default=""
|
||||
label="COM_WEBLINKS_FIELD_TARGET_LABEL" description="COM_WEBLINKS_FIELD_TARGET_DESC"
|
||||
>
|
||||
<option value="">JGLOBAL_USE_GLOBAL</option>
|
||||
<option value="0">JBROWSERTARGET_PARENT</option>
|
||||
<option value="1">JBROWSERTARGET_NEW</option>
|
||||
<option value="2">JBROWSERTARGET_POPUP</option>
|
||||
<option value="3">JBROWSERTARGET_MODAL</option>
|
||||
</field>
|
||||
|
||||
<field name="width" type="text"
|
||||
class="inputbox validate-numeric" label="COM_WEBLINKS_FIELD_WIDTH_LABEL"
|
||||
description="COM_WEBLINKS_FIELD_WIDTH_DESC" />
|
||||
|
||||
<field name="height" type="text"
|
||||
class="inputbox validate-numeric" label="COM_WEBLINKS_FIELD_HEIGHT_LABEL"
|
||||
description="COM_WEBLINKS_FIELD_HEIGHT_DESC" />
|
||||
|
||||
<field name="count_clicks" type="list"
|
||||
label="COM_WEBLINKS_FIELD_COUNTCLICKS_LABEL"
|
||||
description="COM_WEBLINKS_FIELD_COUNTCLICKS_DESC"
|
||||
>
|
||||
<option value="">JGLOBAL_USE_GLOBAL</option>
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
</fieldset>
|
||||
</fields>
|
||||
<fields name="images">
|
||||
<field
|
||||
name="image_first"
|
||||
type="media"
|
||||
label="COM_WEBLINKS_FIELD_FIRST_LABEL"
|
||||
description="COM_WEBLINKS_FIELD_FIRST_DESC" />
|
||||
<field
|
||||
name="float_first"
|
||||
type="list"
|
||||
label="COM_WEBLINKS_FLOAT_LABEL"
|
||||
description="COM_WEBLINKS_FLOAT_DESC">
|
||||
<option value="">JGLOBAL_USE_GLOBAL</option>
|
||||
<option value="right">COM_WEBLINKS_RIGHT</option>
|
||||
<option value="left">COM_WEBLINKS_LEFT</option>
|
||||
<option value="none">COM_WEBLINKS_NONE</option>
|
||||
</field>
|
||||
<field name="image_first_alt"
|
||||
type="text"
|
||||
label="COM_WEBLINKS_FIELD_IMAGE_ALT_LABEL"
|
||||
description="COM_WEBLINKS_FIELD_IMAGE_ALT_DESC"
|
||||
class="inputbox"
|
||||
size="20" />
|
||||
<field name="image_first_caption"
|
||||
type="text"
|
||||
label="COM_WEBLINKS_FIELD_IMAGE_CAPTION_LABEL"
|
||||
description="COM_WEBLINKS_FIELD_IMAGE_CAPTION_DESC"
|
||||
class="inputbox"
|
||||
size="20" />
|
||||
|
||||
<field
|
||||
name="image_second"
|
||||
type="media"
|
||||
label="COM_WEBLINKS_FIELD_SECOND_LABEL"
|
||||
description="COM_WEBLINKS_FIELD_SECOND_DESC" />
|
||||
<field
|
||||
name="float_second"
|
||||
type="list"
|
||||
label="COM_WEBLINKS_FLOAT_LABEL"
|
||||
description="COM_WEBLINKS_FLOAT_DESC">
|
||||
<option value="">JGLOBAL_USE_GLOBAL</option>
|
||||
<option value="right">COM_WEBLINKS_RIGHT</option>
|
||||
<option value="left">COM_WEBLINKS_LEFT</option>
|
||||
<option value="none">COM_WEBLINKS_NONE</option>
|
||||
</field>
|
||||
<field name="image_second_alt"
|
||||
type="text"
|
||||
label="COM_WEBLINKS_FIELD_IMAGE_ALT_LABEL"
|
||||
description="COM_WEBLINKS_FIELD_IMAGE_ALT_DESC"
|
||||
class="inputbox"
|
||||
size="20" />
|
||||
<field name="image_second_caption"
|
||||
type="text"
|
||||
label="COM_WEBLINKS_FIELD_IMAGE_CAPTION_LABEL"
|
||||
description="COM_WEBLINKS_FIELD_IMAGE_CAPTION_DESC"
|
||||
class="inputbox"
|
||||
size="20" />
|
||||
</fields>
|
||||
<fields name="metadata">
|
||||
<fieldset name="jmetadata" label="JGLOBAL_FIELDSET_METADATA_OPTIONS">
|
||||
|
||||
<field name="robots"
|
||||
type="list"
|
||||
label="JFIELD_METADATA_ROBOTS_LABEL"
|
||||
description="JFIELD_METADATA_ROBOTS_DESC"
|
||||
>
|
||||
<option value="">JGLOBAL_USE_GLOBAL</option>
|
||||
<option value="index, follow">JGLOBAL_INDEX_FOLLOW</option>
|
||||
<option value="noindex, follow">JGLOBAL_NOINDEX_FOLLOW</option>
|
||||
<option value="index, nofollow">JGLOBAL_INDEX_NOFOLLOW</option>
|
||||
<option value="noindex, nofollow">JGLOBAL_NOINDEX_NOFOLLOW</option>
|
||||
</field>
|
||||
|
||||
<field name="rights" type="text"
|
||||
label="JFIELD_META_RIGHTS_LABEL" description="JFIELD_META_RIGHTS_DESC"
|
||||
required="false" filter="string" cols="30" rows="2" />
|
||||
</fieldset>
|
||||
</fields>
|
||||
</form>
|
1
administrator/components/com_weblinks/models/index.html
Normal file
1
administrator/components/com_weblinks/models/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
309
administrator/components/com_weblinks/models/weblink.php
Normal file
309
administrator/components/com_weblinks/models/weblink.php
Normal file
@ -0,0 +1,309 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_weblinks
|
||||
*
|
||||
* @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('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* Weblinks model.
|
||||
*
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_weblinks
|
||||
* @since 1.5
|
||||
*/
|
||||
class WeblinksModelWeblink extends JModelAdmin
|
||||
{
|
||||
/**
|
||||
* @var string The prefix to use with controller messages.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $text_prefix = 'COM_WEBLINKS';
|
||||
|
||||
/**
|
||||
* Method to test whether a record can be deleted.
|
||||
*
|
||||
* @param object A record object.
|
||||
* @return boolean True if allowed to delete the record. Defaults to the permission set in the component.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function canDelete($record)
|
||||
{
|
||||
if (!empty($record->id))
|
||||
{
|
||||
if ($record->state != -2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
$user = JFactory::getUser();
|
||||
|
||||
if ($record->catid)
|
||||
{
|
||||
return $user->authorise('core.delete', 'com_weblinks.category.'.(int) $record->catid);
|
||||
}
|
||||
else
|
||||
{
|
||||
return parent::canDelete($record);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to test whether a record can have its state changed.
|
||||
*
|
||||
* @param object A record object.
|
||||
* @return boolean True if allowed to change the state of the record. Defaults to the permission set in the component.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function canEditState($record)
|
||||
{
|
||||
$user = JFactory::getUser();
|
||||
|
||||
if (!empty($record->catid))
|
||||
{
|
||||
return $user->authorise('core.edit.state', 'com_weblinks.category.'.(int) $record->catid);
|
||||
}
|
||||
else
|
||||
{
|
||||
return parent::canEditState($record);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the a Table object, always creating it.
|
||||
*
|
||||
* @param type The table type to instantiate
|
||||
* @param string A prefix for the table class name. Optional.
|
||||
* @param array Configuration array for model. Optional.
|
||||
* @return JTable A database object
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getTable($type = 'Weblink', $prefix = 'WeblinksTable', $config = array())
|
||||
{
|
||||
return JTable::getInstance($type, $prefix, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the record form.
|
||||
*
|
||||
* @param array $data An optional array of data for the form to interogate.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
* @return JForm A JForm object on success, false on failure
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getForm($data = array(), $loadData = true)
|
||||
{
|
||||
// Get the form.
|
||||
$form = $this->loadForm('com_weblinks.weblink', 'weblink', array('control' => 'jform', 'load_data' => $loadData));
|
||||
if (empty($form))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Determine correct permissions to check.
|
||||
if ($this->getState('weblink.id'))
|
||||
{
|
||||
// Existing record. Can only edit in selected categories.
|
||||
$form->setFieldAttribute('catid', 'action', 'core.edit');
|
||||
}
|
||||
else
|
||||
{
|
||||
// New record. Can only create in selected categories.
|
||||
$form->setFieldAttribute('catid', 'action', 'core.create');
|
||||
}
|
||||
|
||||
// Modify the form based on access controls.
|
||||
if (!$this->canEditState((object) $data))
|
||||
{
|
||||
// Disable fields for display.
|
||||
$form->setFieldAttribute('ordering', 'disabled', 'true');
|
||||
$form->setFieldAttribute('state', 'disabled', 'true');
|
||||
$form->setFieldAttribute('publish_up', 'disabled', 'true');
|
||||
$form->setFieldAttribute('publish_down', 'disabled', 'true');
|
||||
|
||||
// Disable fields while saving.
|
||||
// The controller has already verified this is a record you can edit.
|
||||
$form->setFieldAttribute('ordering', 'filter', 'unset');
|
||||
$form->setFieldAttribute('state', 'filter', 'unset');
|
||||
$form->setFieldAttribute('publish_up', 'filter', 'unset');
|
||||
$form->setFieldAttribute('publish_down', 'filter', 'unset');
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the data that should be injected in the form.
|
||||
*
|
||||
* @return mixed The data for the form.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function loadFormData()
|
||||
{
|
||||
// Check the session for previously entered form data.
|
||||
$data = JFactory::getApplication()->getUserState('com_weblinks.edit.weblink.data', array());
|
||||
|
||||
if (empty($data))
|
||||
{
|
||||
$data = $this->getItem();
|
||||
|
||||
// Prime some default values.
|
||||
if ($this->getState('weblink.id') == 0)
|
||||
{
|
||||
$app = JFactory::getApplication();
|
||||
$data->set('catid', $app->input->get('catid', $app->getUserState('com_weblinks.weblinks.filter.category_id'), 'int'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->preprocessData('com_weblinks.weblink', $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a single record.
|
||||
*
|
||||
* @param integer The id of the primary key.
|
||||
*
|
||||
* @return mixed Object on success, false on failure.
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getItem($pk = null)
|
||||
{
|
||||
if ($item = parent::getItem($pk))
|
||||
{
|
||||
// Convert the metadata field to an array.
|
||||
$registry = new JRegistry;
|
||||
$registry->loadString($item->metadata);
|
||||
$item->metadata = $registry->toArray();
|
||||
|
||||
// Convert the images field to an array.
|
||||
$registry = new JRegistry;
|
||||
$registry->loadString($item->images);
|
||||
$item->images = $registry->toArray();
|
||||
|
||||
if (!empty($item->id))
|
||||
{
|
||||
$item->tags = new JHelperTags;
|
||||
$item->tags->getTagIds($item->id, 'com_weblinks.weblink');
|
||||
$item->metadata['tags'] = $item->tags;
|
||||
}
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare and sanitise the table prior to saving.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function prepareTable($table)
|
||||
{
|
||||
$date = JFactory::getDate();
|
||||
$user = JFactory::getUser();
|
||||
|
||||
$table->title = htmlspecialchars_decode($table->title, ENT_QUOTES);
|
||||
$table->alias = JApplication::stringURLSafe($table->alias);
|
||||
|
||||
if (empty($table->alias))
|
||||
{
|
||||
$table->alias = JApplication::stringURLSafe($table->title);
|
||||
}
|
||||
|
||||
if (empty($table->id))
|
||||
{
|
||||
// Set the values
|
||||
|
||||
// Set ordering to the last item if not set
|
||||
if (empty($table->ordering))
|
||||
{
|
||||
$db = JFactory::getDbo();
|
||||
$db->setQuery('SELECT MAX(ordering) FROM #__weblinks');
|
||||
$max = $db->loadResult();
|
||||
|
||||
$table->ordering = $max + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Set the values
|
||||
$table->modified = $date->toSql();
|
||||
$table->modified_by = $user->get('id');
|
||||
}
|
||||
|
||||
// Increment the content version number.
|
||||
$table->version++;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* A protected method to get a set of ordering conditions.
|
||||
*
|
||||
* @param object A record object.
|
||||
* @return array An array of conditions to add to add to ordering queries.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getReorderConditions($table)
|
||||
{
|
||||
$condition = array();
|
||||
$condition[] = 'catid = '.(int) $table->catid;
|
||||
return $condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to save the form data.
|
||||
*
|
||||
* @param array $data The form data.
|
||||
*
|
||||
* @return boolean True on success.
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
public function save($data)
|
||||
{
|
||||
$app = JFactory::getApplication();
|
||||
|
||||
// Alter the title for save as copy
|
||||
if ($app->input->get('task') == 'save2copy')
|
||||
{
|
||||
list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
|
||||
$data['title'] = $name;
|
||||
$data['alias'] = $alias;
|
||||
$data['state'] = 0;
|
||||
}
|
||||
$return = parent::save($data);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to change the title & alias.
|
||||
*
|
||||
* @param integer $category_id The id of the parent.
|
||||
* @param string $alias The alias.
|
||||
* @param string $name The title.
|
||||
*
|
||||
* @return array Contains the modified title and alias.
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
protected function generateNewTitle($category_id, $alias, $name)
|
||||
{
|
||||
// Alter the title & alias
|
||||
$table = $this->getTable();
|
||||
|
||||
while ($table->load(array('alias' => $alias, 'catid' => $category_id)))
|
||||
{
|
||||
if ($name == $table->title)
|
||||
{
|
||||
$name = JString::increment($name);
|
||||
}
|
||||
$alias = JString::increment($alias, 'dash');
|
||||
}
|
||||
|
||||
return array($name, $alias);
|
||||
}
|
||||
}
|
232
administrator/components/com_weblinks/models/weblinks.php
Normal file
232
administrator/components/com_weblinks/models/weblinks.php
Normal file
@ -0,0 +1,232 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_weblinks
|
||||
*
|
||||
* @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('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* Methods supporting a list of weblink records.
|
||||
*
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_weblinks
|
||||
* @since 1.6
|
||||
*/
|
||||
class WeblinksModelWeblinks extends JModelList
|
||||
{
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array An optional associative array of configuration settings.
|
||||
* @see JController
|
||||
* @since 1.6
|
||||
*/
|
||||
public function __construct($config = array())
|
||||
{
|
||||
if (empty($config['filter_fields']))
|
||||
{
|
||||
$config['filter_fields'] = array(
|
||||
'id', 'a.id',
|
||||
'title', 'a.title',
|
||||
'alias', 'a.alias',
|
||||
'checked_out', 'a.checked_out',
|
||||
'checked_out_time', 'a.checked_out_time',
|
||||
'catid', 'a.catid', 'category_title',
|
||||
'state', 'a.state',
|
||||
'access', 'a.access', 'access_level',
|
||||
'created', 'a.created',
|
||||
'created_by', 'a.created_by',
|
||||
'ordering', 'a.ordering',
|
||||
'featured', 'a.featured',
|
||||
'language', 'a.language',
|
||||
'hits', 'a.hits',
|
||||
'publish_up', 'a.publish_up',
|
||||
'publish_down', 'a.publish_down',
|
||||
'url', 'a.url',
|
||||
);
|
||||
}
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
* Note. Calling getState in this method will result in recursion.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function populateState($ordering = null, $direction = null)
|
||||
{
|
||||
// Load the filter state.
|
||||
$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
|
||||
$this->setState('filter.search', $search);
|
||||
|
||||
$accessId = $this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access', null, 'int');
|
||||
$this->setState('filter.access', $accessId);
|
||||
|
||||
$published = $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'string');
|
||||
$this->setState('filter.state', $published);
|
||||
|
||||
$categoryId = $this->getUserStateFromRequest($this->context . '.filter.category_id', 'filter_category_id', '');
|
||||
$this->setState('filter.category_id', $categoryId);
|
||||
|
||||
$language = $this->getUserStateFromRequest($this->context . '.filter.language', 'filter_language', '');
|
||||
$this->setState('filter.language', $language);
|
||||
|
||||
$tag = $this->getUserStateFromRequest($this->context . '.filter.tag', 'filter_tag', '');
|
||||
$this->setState('filter.tag', $tag);
|
||||
|
||||
// Load the parameters.
|
||||
$params = JComponentHelper::getParams('com_weblinks');
|
||||
$this->setState('params', $params);
|
||||
|
||||
// List state information.
|
||||
parent::populateState('a.title', 'asc');
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get a store id based on model configuration state.
|
||||
*
|
||||
* This is necessary because the model is used by the component and
|
||||
* different modules that might need different sets of data or different
|
||||
* ordering requirements.
|
||||
*
|
||||
* @param string $id A prefix for the store id.
|
||||
* @return string A store id.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getStoreId($id = '')
|
||||
{
|
||||
// Compile the store id.
|
||||
$id .= ':' . $this->getState('filter.search');
|
||||
$id .= ':' . $this->getState('filter.access');
|
||||
$id .= ':' . $this->getState('filter.state');
|
||||
$id .= ':' . $this->getState('filter.category_id');
|
||||
$id .= ':' . $this->getState('filter.language');
|
||||
|
||||
return parent::getStoreId($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an SQL query to load the list data.
|
||||
*
|
||||
* @return JDatabaseQuery
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getListQuery()
|
||||
{
|
||||
// Create a new query object.
|
||||
$db = $this->getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
$user = JFactory::getUser();
|
||||
|
||||
// Select the required fields from the table.
|
||||
$query->select(
|
||||
$this->getState(
|
||||
'list.select',
|
||||
'a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid,' .
|
||||
'a.hits,' .
|
||||
'a.state, a.access, a.ordering,' .
|
||||
'a.language, a.publish_up, a.publish_down'
|
||||
)
|
||||
);
|
||||
$query->from($db->quoteName('#__weblinks') . ' AS a');
|
||||
|
||||
// Join over the language
|
||||
$query->select('l.title AS language_title')
|
||||
->join('LEFT', $db->quoteName('#__languages') . ' AS l ON l.lang_code = a.language');
|
||||
|
||||
// Join over the users for the checked out user.
|
||||
$query->select('uc.name AS editor')
|
||||
->join('LEFT', '#__users AS uc ON uc.id=a.checked_out');
|
||||
|
||||
// Join over the asset groups.
|
||||
$query->select('ag.title AS access_level')
|
||||
->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');
|
||||
|
||||
// Join over the categories.
|
||||
$query->select('c.title AS category_title')
|
||||
->join('LEFT', '#__categories AS c ON c.id = a.catid');
|
||||
|
||||
// Filter by access level.
|
||||
if ($access = $this->getState('filter.access'))
|
||||
{
|
||||
$query->where('a.access = ' . (int) $access);
|
||||
}
|
||||
|
||||
// Implement View Level Access
|
||||
if (!$user->authorise('core.admin'))
|
||||
{
|
||||
$groups = implode(',', $user->getAuthorisedViewLevels());
|
||||
$query->where('a.access IN (' . $groups . ')');
|
||||
}
|
||||
|
||||
// Filter by published state
|
||||
$published = $this->getState('filter.state');
|
||||
if (is_numeric($published))
|
||||
{
|
||||
$query->where('a.state = ' . (int) $published);
|
||||
}
|
||||
elseif ($published === '')
|
||||
{
|
||||
$query->where('(a.state IN (0, 1))');
|
||||
}
|
||||
|
||||
// Filter by category.
|
||||
$categoryId = $this->getState('filter.category_id');
|
||||
if (is_numeric($categoryId))
|
||||
{
|
||||
$query->where('a.catid = ' . (int) $categoryId);
|
||||
}
|
||||
|
||||
// Filter by search in title
|
||||
$search = $this->getState('filter.search');
|
||||
if (!empty($search))
|
||||
{
|
||||
if (stripos($search, 'id:') === 0)
|
||||
{
|
||||
$query->where('a.id = ' . (int) substr($search, 3));
|
||||
}
|
||||
else
|
||||
{
|
||||
$search = $db->quote('%' . $db->escape($search, true) . '%');
|
||||
$query->where('(a.title LIKE ' . $search . ' OR a.alias LIKE ' . $search . ')');
|
||||
}
|
||||
}
|
||||
|
||||
// Filter on the language.
|
||||
if ($language = $this->getState('filter.language'))
|
||||
{
|
||||
$query->where('a.language = ' . $db->quote($language));
|
||||
}
|
||||
|
||||
$tagId = $this->getState('filter.tag');
|
||||
// Filter by a single tag.
|
||||
if (is_numeric($tagId))
|
||||
{
|
||||
$query->where($db->quoteName('tagmap.tag_id') . ' = ' . (int) $tagId)
|
||||
->join(
|
||||
'LEFT', $db->quoteName('#__contentitem_tag_map', 'tagmap')
|
||||
. ' ON ' . $db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
|
||||
. ' AND ' . $db->quoteName('tagmap.type_alias') . ' = ' . $db->quote('com_weblinks.weblink')
|
||||
);
|
||||
}
|
||||
|
||||
// Add the list ordering clause.
|
||||
$orderCol = $this->state->get('list.ordering');
|
||||
$orderDirn = $this->state->get('list.direction');
|
||||
if ($orderCol == 'a.ordering' || $orderCol == 'category_title')
|
||||
{
|
||||
$orderCol = 'c.title ' . $orderDirn . ', a.ordering';
|
||||
}
|
||||
$query->order($db->escape($orderCol . ' ' . $orderDirn));
|
||||
|
||||
//echo nl2br(str_replace('#__','jos_',$query));
|
||||
return $query;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user