primo commit
This commit is contained in:
131
administrator/components/com_attachments/models/attachment.php
Normal file
131
administrator/components/com_attachments/models/attachment.php
Normal file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
* Attachments component attachment model
|
||||
*
|
||||
* @package Attachments
|
||||
* @subpackage Attachments_Component
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2018 Jonathan M. Cameron, All Rights Reserved
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
|
||||
* @link http://joomlacode.org/gf/project/attachments/frs/
|
||||
* @author Jonathan M. Cameron
|
||||
*/
|
||||
|
||||
// No direct access to this file
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
// import Joomla modelform library
|
||||
jimport('joomla.application.component.modeladmin');
|
||||
|
||||
/**
|
||||
* Attachment Model
|
||||
*
|
||||
* @package Attachments
|
||||
*/
|
||||
class AttachmentsModelAttachment extends JModelAdmin
|
||||
{
|
||||
/**
|
||||
* 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 = 'Attachment', $prefix = 'AttachmentsTable', $config = array())
|
||||
{
|
||||
return JTable::getInstance($type, $prefix, $config);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Override the getItem() command to get some extra info
|
||||
*
|
||||
* @param integer $pk The id of the primary key.
|
||||
*
|
||||
* @return mixed Object on success, false on failure.
|
||||
*/
|
||||
public function getItem($pk = null)
|
||||
{
|
||||
$item = parent::getItem($pk);
|
||||
|
||||
if ( $item->id != 0 ) {
|
||||
|
||||
// If the item exists, get more info
|
||||
$db = $this->getDbo();
|
||||
|
||||
// Get the creator name
|
||||
$query = $db->getQuery(true);
|
||||
$query->select('name')->from('#__users')->where('id = ' . (int)$item->created_by);
|
||||
$db->setQuery($query, 0, 1);
|
||||
$item->creator_name = $db->loadResult();
|
||||
if ( $db->getErrorNum() ) {
|
||||
$errmsg = $db->stderr() . ' (ERR 112)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
// Get the modifier name
|
||||
$query = $db->getQuery(true);
|
||||
$query->select('name')->from('#__users')->where('id = ' . (int)$item->modified_by);
|
||||
$db->setQuery($query, 0, 1);
|
||||
$item->modifier_name = $db->loadResult();
|
||||
if ( $db->getErrorNum() ) {
|
||||
$errmsg = $db->stderr() . ' (ERR 113)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
// Get the parent info (??? Do we really need this?)
|
||||
$parent_type = $item->parent_type;
|
||||
$parent_entity = $item->parent_entity;
|
||||
JPluginHelper::importPlugin('attachments');
|
||||
$apm = getAttachmentsPluginManager();
|
||||
if ( !$apm->attachmentsPluginInstalled($parent_type) ) {
|
||||
$errmsg = JText::sprintf('ATTACH_ERROR_INVALID_PARENT_TYPE_S', $parent_type) . ' (ERR 114)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
$item->parent = $apm->getAttachmentsPlugin($parent_type);
|
||||
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the record form.
|
||||
*
|
||||
* @param array $data Data for the form.
|
||||
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
|
||||
* @return mixed 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_attachments.attachment', 'attachment',
|
||||
array('control' => 'jform', 'load_data' => $loadData));
|
||||
if (empty($form))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
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_attachments.edit.attachment.data', array());
|
||||
if (empty($data))
|
||||
{
|
||||
$data = $this->getItem();
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
370
administrator/components/com_attachments/models/attachments.php
Normal file
370
administrator/components/com_attachments/models/attachments.php
Normal file
@ -0,0 +1,370 @@
|
||||
<?php
|
||||
/**
|
||||
* Attachments component attachments model
|
||||
*
|
||||
* @package Attachments
|
||||
* @subpackage Attachments_Component
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2018 Jonathan M. Cameron, All Rights Reserved
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
|
||||
* @link http://joomlacode.org/gf/project/attachments/frs/
|
||||
* @author Jonathan M. Cameron
|
||||
*/
|
||||
|
||||
// No direct access to this file
|
||||
defined('_JEXEC') or die('Restricted access');
|
||||
|
||||
// import the Joomla modellist library
|
||||
jimport('joomla.application.component.modellist');
|
||||
|
||||
|
||||
/**
|
||||
* Attachments Model
|
||||
*
|
||||
* @package Attachments
|
||||
*/
|
||||
class AttachmentsModelAttachments extends JModelList
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array An optional associative array of configuration settings.
|
||||
* @see JControllerLegacy
|
||||
* @since 1.6
|
||||
*/
|
||||
public function __construct($config = array())
|
||||
{
|
||||
if (empty($config['filter_fields'])) {
|
||||
$config['filter_fields'] = array(
|
||||
'id',
|
||||
'a.state',
|
||||
'a.access',
|
||||
'a.filename',
|
||||
'a.description',
|
||||
'a.user_field_1',
|
||||
'a.user_field_2',
|
||||
'a.user_field_3',
|
||||
'a.file_type',
|
||||
'a.file_size',
|
||||
'creator_name',
|
||||
'modifier_name',
|
||||
'u1.name',
|
||||
'a.created',
|
||||
'a.modified',
|
||||
'a.download_count'
|
||||
);
|
||||
}
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Method to build an SQL query to load the attachments data.
|
||||
*
|
||||
* @return JDatabaseQuery An SQL query
|
||||
*/
|
||||
protected function getListQuery()
|
||||
{
|
||||
|
||||
// Create a new query object.
|
||||
$db = JFactory::getDBO();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$query->select('a.*, a.id as id');
|
||||
$query->from('#__attachments as a');
|
||||
|
||||
$query->select('u1.name as creator_name');
|
||||
$query->leftJoin('#__users AS u1 ON u1.id = a.created_by');
|
||||
|
||||
$query->select('u2.name as modifier_name');
|
||||
$query->leftJoin('#__users AS u2 ON u2.id = a.modified_by');
|
||||
|
||||
// Add the where clause
|
||||
$where = $this->_buildContentWhere($query);
|
||||
if ($where) {
|
||||
$query->where($where);
|
||||
}
|
||||
|
||||
// Add the order-by clause
|
||||
$order_by = $this->_buildContentOrderBy();
|
||||
if ($order_by) {
|
||||
$query->order($db->escape($order_by));
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Method to build the where clause of the query for the Items
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
* @since 1.0
|
||||
*/
|
||||
private function _buildContentWhere($query)
|
||||
{
|
||||
$where = Array();
|
||||
|
||||
// Set up the search
|
||||
$search = $this->getState('filter.search');
|
||||
|
||||
if ( $search ) {
|
||||
if ( ($search != '') && is_numeric($search) ) {
|
||||
$where[] = 'a.id = ' . (int) $search . '';
|
||||
}
|
||||
else {
|
||||
$db = $this->getDBO();
|
||||
$where[] = '(LOWER( a.filename ) LIKE ' .
|
||||
$db->quote( '%'.$db->escape( $search, true ).'%', false ) .
|
||||
' OR LOWER( a.description ) LIKE ' .
|
||||
$db->quote( '%'.$db->escape( $search, true ).'%', false ) .
|
||||
' OR LOWER( a.display_name ) LIKE ' .
|
||||
$db->quote( '%'.$db->escape( $search, true ).'%', false ) . ')';
|
||||
}
|
||||
}
|
||||
|
||||
// Get the entity filter info
|
||||
$filter_entity = $this->getState('filter.entity');
|
||||
if ( $filter_entity != 'ALL' ) {
|
||||
$where[] = "a.parent_entity = '$filter_entity'";
|
||||
}
|
||||
|
||||
// Get the parent_state filter
|
||||
jimport('joomla.application.component.helper');
|
||||
$params = JComponentHelper::getParams('com_attachments');
|
||||
|
||||
// Get the desired state
|
||||
$filter_parent_state_default = 'ALL';
|
||||
$suppress_obsolete_attachments = $params->get('suppress_obsolete_attachments', false);
|
||||
if ( $suppress_obsolete_attachments ) {
|
||||
$filter_parent_state_default = 'PUBLISHED';
|
||||
}
|
||||
$filter_parent_state = $this->getState('filter.parent_state', $filter_parent_state_default);
|
||||
if ( $filter_parent_state != 'ALL' ) {
|
||||
|
||||
$fps_wheres = array();
|
||||
|
||||
// Get the contributions for all the known content types
|
||||
JPluginHelper::importPlugin('attachments');
|
||||
$apm = getAttachmentsPluginManager();
|
||||
$known_parent_types = $apm->getInstalledParentTypes();
|
||||
foreach ($known_parent_types as $parent_type) {
|
||||
$parent = $apm->getAttachmentsPlugin($parent_type);
|
||||
$pwheres = $parent->getParentPublishedFilter($filter_parent_state, $filter_entity);
|
||||
foreach ($pwheres as $pw) {
|
||||
$fps_wheres[] = $pw;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $filter_parent_state == 'NONE' ) {
|
||||
$basic = '';
|
||||
$fps_wheres = '( (a.parent_id = 0) OR (a.parent_id IS NULL) ' .
|
||||
(count($fps_wheres) ?
|
||||
' OR (' . implode(' AND ', $fps_wheres) . ')' : '') . ')';
|
||||
}
|
||||
else {
|
||||
$fps_wheres = (count($fps_wheres) ? '(' . implode(' OR ', $fps_wheres) . ')' : '');
|
||||
}
|
||||
|
||||
// Copy the new where clauses into our main list
|
||||
if ($fps_wheres) {
|
||||
$where[] = $fps_wheres;
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure the user can only see the attachments they may access
|
||||
$user = JFactory::getUser();
|
||||
if ( !$user->authorise('core.admin') ) {
|
||||
$user_levels = implode(',', array_unique($user->getAuthorisedViewLevels()));
|
||||
$where[] = 'a.access in ('.$user_levels.')';
|
||||
}
|
||||
|
||||
// Construct the WHERE clause
|
||||
$where = (count($where) ? implode(' AND ', $where) : '');
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to build the orderby clause of the query for the Items
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
* @since 1.0
|
||||
*/
|
||||
private function _buildContentOrderBy()
|
||||
{
|
||||
// Get the ordering information
|
||||
$orderCol = $this->state->get('list.ordering');
|
||||
$orderDirn = $this->state->get('list.direction');
|
||||
|
||||
// Construct the ORDER BY clause
|
||||
$order_by = "a.parent_type, a.parent_entity, a.parent_id";
|
||||
if ( $orderCol ) {
|
||||
$order_by = "$orderCol $orderDirn, a.parent_entity, a.parent_id";
|
||||
}
|
||||
|
||||
return $order_by;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
// Initialise variables.
|
||||
$app = JFactory::getApplication('administrator');
|
||||
|
||||
// Set up the list limits (not sure why the base class version of this does not work)
|
||||
$value = $app->getUserStateFromRequest($this->context.'.list.limit', 'limit', $app->getCfg('list_limit'), 'uint');
|
||||
$limit = $value;
|
||||
$this->setState('list.limit', $limit);
|
||||
|
||||
$value = $app->getUserStateFromRequest($this->context.'.limitstart', 'limitstart', 0, 'uint');
|
||||
$limitstart = ($limit != 0 ? (floor($value / $limit) * $limit) : 0);
|
||||
$this->setState('list.start', $limitstart);
|
||||
|
||||
// Load the filter state.
|
||||
$search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search', null, 'string');
|
||||
$this->setState('filter.search', $search);
|
||||
|
||||
$entity = $this->getUserStateFromRequest($this->context.'.filter.entity', 'filter_entity', 'ALL', 'word');
|
||||
$this->setState('filter.entity', $entity);
|
||||
|
||||
$parent_state = $this->getUserStateFromRequest($this->context.'.filter.parent_state', 'filter_parent_state', null, 'string');
|
||||
$this->setState('filter.parent_state', $parent_state);
|
||||
|
||||
$state = $this->getUserStateFromRequest($this->context.'.filter.state', 'filter_state', '', 'string');
|
||||
$this->setState('filter.state', $state);
|
||||
|
||||
// Check if the ordering field is in the white list, otherwise use the incoming value.
|
||||
$value = $app->getUserStateFromRequest($this->context.'.ordercol', 'filter_order', $ordering, 'string');
|
||||
if (!in_array($value, $this->filter_fields)) {
|
||||
$value = $ordering;
|
||||
$app->setUserState($this->context.'.ordercol', $value);
|
||||
}
|
||||
$this->setState('list.ordering', $value);
|
||||
|
||||
// Check if the ordering direction is valid, otherwise use the incoming value.
|
||||
$value = $app->getUserStateFromRequest($this->context.'.orderdirn', 'filter_order_Dir', $direction, 'cmd');
|
||||
if (!in_array(strtoupper($value), array('ASC', 'DESC', ''))) {
|
||||
$value = $direction;
|
||||
$app->setUserState($this->context.'.orderdirn', $value);
|
||||
}
|
||||
$this->setState('list.direction', $value);
|
||||
|
||||
// Load the parameters.
|
||||
$params = JComponentHelper::getParams('com_attachments');
|
||||
$this->setState('params', $params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to get an array of data items.
|
||||
*
|
||||
* @return mixed An array of data items on success, false on failure.
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getItems()
|
||||
{
|
||||
$items = parent::getItems();
|
||||
if ( $items === false )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$good_items = Array();
|
||||
|
||||
// Update the attachments with information about thier parents
|
||||
JPluginHelper::importPlugin('attachments');
|
||||
$apm = getAttachmentsPluginManager();
|
||||
foreach ($items as $item) {
|
||||
$parent_id = $item->parent_id;
|
||||
$parent_type = $item->parent_type;
|
||||
$parent_entity = $item->parent_entity;
|
||||
if ( !$apm->attachmentsPluginInstalled($parent_type) ) {
|
||||
$errmsg = JText::sprintf('ATTACH_ERROR_INVALID_PARENT_TYPE_S',
|
||||
$parent_type . ':' . $parent_entity .
|
||||
' (ID ' .(string)$item->id . ')') . ' (ERR 115)';
|
||||
$app = JFactory::getApplication();
|
||||
$app->enqueueMessage($errmsg, 'warning');
|
||||
continue;
|
||||
}
|
||||
$parent = $apm->getAttachmentsPlugin($parent_type);
|
||||
|
||||
if ( $parent ) {
|
||||
|
||||
// Handle the normal case
|
||||
$item->parent_entity_type = JText::_('ATTACH_' . $parent_entity);
|
||||
$title = $parent->getTitle($parent_id, $parent_entity);
|
||||
$item->parent_exists = $parent->parentExists($parent_id, $parent_entity);
|
||||
if ( $item->parent_exists && $title ) {
|
||||
$item->parent_title = $title;
|
||||
$item->parent_url =
|
||||
JFilterOutput::ampReplace( $parent->getEntityViewURL($parent_id, $parent_entity) );
|
||||
}
|
||||
else {
|
||||
$item->parent_title = JText::sprintf('ATTACH_NO_PARENT_S', $item->parent_entity_type);
|
||||
$item->parent_url = '';
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
// Handle pathalogical case where there is no parent handler
|
||||
// (eg, deleted component)
|
||||
$item->parent_exists = false;
|
||||
$item->parent_entity_type = $parent_entity;
|
||||
$item->parent_title = JText::_('ATTACH_UNKNOWN');
|
||||
$item->parent_published = false;
|
||||
$item->parent_archived = false;
|
||||
$item->parent_url = '';
|
||||
}
|
||||
|
||||
$good_items[] = $item;
|
||||
}
|
||||
|
||||
// Return from the cache
|
||||
return $good_items;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 = 'Attachment', $prefix = 'AttachmentsTable', $config = array())
|
||||
{
|
||||
return JTable::getInstance($type, $prefix, $config);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Publish attachment(s)
|
||||
*
|
||||
* Applied to any selected attachments
|
||||
*/
|
||||
public function publish($cid, $value)
|
||||
{
|
||||
// Get the ids and make sure they are integers
|
||||
$attachmentTable = $this->getTable();
|
||||
$attachmentTable = JTable::getInstance('Attachment', 'AttachmentsTable');
|
||||
|
||||
return $attachmentTable->publish($cid, $value);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,163 @@
|
||||
<?php
|
||||
/**
|
||||
* Attachments component attachments model
|
||||
*
|
||||
* @package Attachments
|
||||
* @subpackage Attachments_Component
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2018 Jonathan M. Cameron, All Rights Reserved
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
|
||||
* @link http://joomlacode.org/gf/project/attachments/frs/
|
||||
* @author Jonathan M. Cameron
|
||||
*/
|
||||
|
||||
defined('JPATH_BASE') or die;
|
||||
|
||||
jimport('joomla.html.html');
|
||||
jimport('joomla.form.formfield');
|
||||
|
||||
/** Load the Attachements defines */
|
||||
require_once(JPATH_SITE.'/components/com_attachments/defines.php');
|
||||
|
||||
/**
|
||||
* Form Field class list of access levels the user has access to
|
||||
*
|
||||
* @package Attachments
|
||||
* @subpackage Attachments_Component
|
||||
*/
|
||||
class JFormFieldAccessLevels extends JFormField
|
||||
{
|
||||
/**
|
||||
* The form field type.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.6
|
||||
*/
|
||||
public $type = 'AccessLevels';
|
||||
|
||||
|
||||
/**
|
||||
* Method to get the field input markup.
|
||||
*
|
||||
* TODO: Add access check.
|
||||
*
|
||||
* @return string The field input markup.
|
||||
* @since 1.6
|
||||
*/
|
||||
protected function getInput()
|
||||
{
|
||||
$options = new JObject();
|
||||
$options->element = $this->element;
|
||||
$options->multiple = $this->multiple;
|
||||
$options->always_public = $this->fieldname == 'show_guest_access_levels';
|
||||
return $this->getAccessLevels($this->name, 'jform_'.$this->fieldname, $this->value, $options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the access levels HTML selector
|
||||
*
|
||||
* @param string $for_id the id for the select input
|
||||
* @param string $fieldname the name of the field
|
||||
* @param int $level_value the value of the level(s) to be initially selected
|
||||
*/
|
||||
public static function getAccessLevels($for_id, $fieldname, $level_value=null, $options=null)
|
||||
{
|
||||
$user = JFactory::getUser();
|
||||
$user_access_levels = array_unique($user->getAuthorisedViewLevels());
|
||||
|
||||
$db = JFactory::getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
// Get the access levels this user is permitted
|
||||
$query->select('a.*');
|
||||
$query->from('#__viewlevels AS a');
|
||||
if ( !$user->authorise('core.admin') ) {
|
||||
// Users that are not super-users can ONLY see the the view levels that they are authorized for
|
||||
$query->where('a.id in ('.implode(',', $user_access_levels).')');
|
||||
}
|
||||
$query->order('a.ordering ASC');
|
||||
$query->order($query->qn('title') . ' ASC');
|
||||
$db->setQuery($query);
|
||||
$levels = $db->loadObjectList();
|
||||
if ( $db->getErrorNum() ) {
|
||||
$errmsg = $db->stderr() . ' (ERR 116)';
|
||||
JError::raiseError(500, $errmsg);
|
||||
}
|
||||
|
||||
// Make sure there is a $level_value
|
||||
if ( $level_value === null ) {
|
||||
jimport('joomla.application.component.helper');
|
||||
$params = JComponentHelper::getParams('com_attachments');
|
||||
$level_value = $params->get('default_access_level', AttachmentsDefines::$DEFAULT_ACCESS_LEVEL_ID);
|
||||
}
|
||||
|
||||
// Make sure the $level_value is in an array
|
||||
if (!is_array($level_value)) {
|
||||
$level_value = Array($level_value);
|
||||
}
|
||||
|
||||
// Make sure the $level_value is in the user's authorised levels (except for super-user)
|
||||
if ( !$user->authorise('core.admin') ) {
|
||||
|
||||
// Filter out any non-permitted access levels
|
||||
$ok_access_levels = Array();
|
||||
foreach ($level_value as $lval) {
|
||||
if (in_array($lval, $user_access_levels)) {
|
||||
$ok_access_levels[] = $lval;
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure there is at least one access level left
|
||||
if (empty($ok_access_levels)) {
|
||||
// pick one arbitrarily
|
||||
$sorted_access_levels = sort($user_access_levels, SORT_NUMERIC);
|
||||
$level_value = Array($sorted_access_levels[0]);
|
||||
}
|
||||
else {
|
||||
$level_value = $ok_access_levels;
|
||||
}
|
||||
}
|
||||
|
||||
// Deal with multiple vs non-multiple selections
|
||||
if (isset($options->multiple) and $options->multiple) {
|
||||
|
||||
// Make sure Public is always selected, if desired
|
||||
$public = AttachmentsDefines::$PUBLIC_ACCESS_LEVEL_ID;
|
||||
if ($options->always_public) {
|
||||
if ( !in_array($public, $level_value) ) {
|
||||
array_unshift($level_value, $public);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (count($level_value) > 1) {
|
||||
// If not multiple, only one selection is allowed, arbitrarily pick the first one
|
||||
// (Not sure this will ever be necessary)
|
||||
$level_value = Array($level_value[0]);
|
||||
}
|
||||
}
|
||||
|
||||
// Construct the attributes for the list
|
||||
$attr = '';
|
||||
if ( $options === null ) {
|
||||
$attr = 'class="inputbox" size="1"';
|
||||
}
|
||||
else {
|
||||
$attr .= $options->element['class'] ? ' class="' . (string) $options->element['class'] . '"' : '';
|
||||
$attr .= ((string) $options->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
|
||||
$attr .= $options->element['size'] ? ' size="' . (int) $options->element['size'] . '"' : '';
|
||||
$attr .= $options->multiple ? ' multiple="multiple"' : '';
|
||||
}
|
||||
|
||||
// Construct the list
|
||||
$level_options = Array();
|
||||
foreach ( $levels as $level ) {
|
||||
// NOTE: We do not translate the access level titles
|
||||
$level_options[] = JHtml::_('select.option', $level->id, $level->title);
|
||||
}
|
||||
return JHtml::_('select.genericlist', $level_options, $for_id,
|
||||
$attr, 'value', 'text', $level_value, $fieldname
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* Attachments component icon filenames selector
|
||||
*
|
||||
* @package Attachments
|
||||
* @subpackage Attachments_Component
|
||||
*
|
||||
* @copyright Copyright (C) 2007-2018 Jonathan M. Cameron, All Rights Reserved
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL
|
||||
* @link http://joomlacode.org/gf/project/attachments/frs/
|
||||
* @author Jonathan M. Cameron
|
||||
*/
|
||||
|
||||
defined('JPATH_BASE') or die;
|
||||
|
||||
jimport('joomla.html.html');
|
||||
jimport('joomla.form.formfield');
|
||||
|
||||
/**
|
||||
* Supports an HTML select list of icon filenames
|
||||
*
|
||||
* @package Attachments
|
||||
*/
|
||||
class JFormFieldIconfilenames extends JFormField
|
||||
{
|
||||
/**
|
||||
* The form field type.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.6
|
||||
*/
|
||||
protected $type = 'Iconfilenames';
|
||||
|
||||
/**
|
||||
* Method to get the field input markup.
|
||||
*
|
||||
* @return string The field input markup.
|
||||
* @since 1.6
|
||||
*/
|
||||
public function getInput()
|
||||
{
|
||||
// Initialize variables.
|
||||
$html = array();
|
||||
|
||||
// Construct the list of legal icon filenames
|
||||
$icon_filenames = array();
|
||||
require_once(JPATH_COMPONENT_SITE.'/file_types.php');
|
||||
foreach ( AttachmentsFileTypes::unique_icon_filenames() as $ifname) {
|
||||
$icon_filenames[] = JHtml::_('select.option', $ifname);
|
||||
}
|
||||
$icon_list = JHtml::_('select.genericlist', $icon_filenames, 'jform[icon_filename]',
|
||||
'class="inputbox" size="1"', 'value', 'text', $this->value,
|
||||
'jform_icon_filename'
|
||||
);
|
||||
|
||||
// Is it readonly?
|
||||
if ((string) $this->element['readonly'] == 'true') {
|
||||
// Create a read-only list (no name) with a hidden input to store the value.
|
||||
$html[] = $icon_list;
|
||||
$html[] = '<input type="hidden" name="'.$this->name.'" value="'.$this->value.'"/>';
|
||||
}
|
||||
else {
|
||||
// Create a regular list.
|
||||
$html[] = $icon_list;
|
||||
}
|
||||
|
||||
return implode($html);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
@ -0,0 +1,110 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<form>
|
||||
<fieldset>
|
||||
<field name="id" type="text" default="0"
|
||||
label="ATTACH_ATTACHMENT_ID" description="ATTACH_ATTACHMENT_ID_DESCRIPTION"
|
||||
readonly="true" class="readonly"
|
||||
/>
|
||||
<field name="state" type="radio" default="0"
|
||||
label="JPUBLISHED" description="" >
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
<field name="parent_type" type="text"
|
||||
label="ATTACH_PARENT_TYPE" description="ATTACH_PARENT_TYPE_DESCRIPTION"
|
||||
readonly="true" class="readonly"
|
||||
/>
|
||||
<field name="parent_entity" type="text"
|
||||
label="ATTACH_PARENT_ENTITY" description="ATTACH_PARENT_ENTITY_DESCRIPTION"
|
||||
readonly="true" class="readonly"
|
||||
/>
|
||||
<field name="parent_id" type="text"
|
||||
label="ATTACH_PARENT_ID" description="ATTACH_PARENT_ID_DESCRIPTION"
|
||||
readonly="true" class="readonly"
|
||||
/>
|
||||
<field name="filename" type="file"
|
||||
label="ATTACH_FILENAME" description="ATTACH_FILENAME_DESCRIPTION"
|
||||
/>
|
||||
<field name="filename_sys" type="text"
|
||||
label="ATTACH_SYSTEM_FILENAME" description="ATTACH_SYSTEM_FILENAME_DESCRIPTION"
|
||||
readonly="true" class="readonly"
|
||||
/>
|
||||
<field name="file_type" type="text"
|
||||
label="ATTACH_FILE_TYPE" description="ATTACH_FILE_TYPE_DESCRIPTION"
|
||||
readonly="true" class="readonly"
|
||||
size="70"
|
||||
/>
|
||||
<field name="file_size" type="text"
|
||||
label="ATTACH_FILE_SIZE_KB" description=""
|
||||
readonly="true" class="readonly"
|
||||
/>
|
||||
<field name="icon_filename" type="Iconfilenames"
|
||||
label="ATTACH_ICON_FILENAME" description="ATTACH_ICON_FILENAME_DESCRIPTION"
|
||||
/>
|
||||
<field name="uri_type" type="text"
|
||||
label="ATTACH_ATTACHMENT_TYPE" description=""
|
||||
readonly="true" class="readonly"
|
||||
size="10"
|
||||
/>
|
||||
<field name="url" type="text"
|
||||
readonly="true" class="readonly"
|
||||
label="ATTACH_URL" description="ATTACH_URL_DESCRIPTION"
|
||||
size="70"
|
||||
/>
|
||||
<field name="url_valid" type="radio"
|
||||
label="ATTACH_URL_IS_VALID" description="ATTACH_URL_IS_VALID_TOOLTIP"
|
||||
default="1" >
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
<field name="url_relative" type="radio"
|
||||
label="ATTACH_RELATIVE_URL" description="ATTACH_RELATIVE_URL_TOOLTIP"
|
||||
default="0" >
|
||||
<option value="0">JNO</option>
|
||||
<option value="1">JYES</option>
|
||||
</field>
|
||||
<field name="display_name" type="text" class="inputbox"
|
||||
label="ATTACH_DISPLAY_NAME" description="ATTACH_DISPLAY_NAME_DESCRIPTION"
|
||||
size="80" maxlength="255"
|
||||
default=""
|
||||
/>
|
||||
<field name="user_field_1" type="text" class="inputbox"
|
||||
label="ATTACH_USER_DEFINED_FIELD_1" description=""
|
||||
size="80" maxlength="100"
|
||||
default=""
|
||||
/>
|
||||
<field name="user_field_2" type="text" class="inputbox"
|
||||
label="ATTACH_USER_DEFINED_FIELD_2" description=""
|
||||
size="80" maxlength="100"
|
||||
default=""
|
||||
/>
|
||||
<field name="user_field_3" type="text" class="inputbox"
|
||||
label="ATTACH_USER_DEFINED_FIELD_3" description=""
|
||||
size="80" maxlength="100"
|
||||
default=""
|
||||
/>
|
||||
<field name="description" type="text" class="inputbox"
|
||||
label="ATTACH_DESCRIPTION" description="ATTACH_DESCRIPTION_DESCRIPTION"
|
||||
size="80" maxlength="255"
|
||||
default=""
|
||||
/>
|
||||
<field name="created" type="Date"
|
||||
label="ATTACH_DATE_CREATED" description=""
|
||||
readonly="true" class="readonly"
|
||||
/>
|
||||
<field name="modified" type="Date"
|
||||
label="ATTACH_LAST_MODIFIED" description=""
|
||||
readonly="true" class="readonly"
|
||||
/>
|
||||
<field name="download_count" type="text"
|
||||
label="ATTACH_NUMBER_OF_DOWNLOADS" description="ATTACH_NUMBER_OF_DOWNLOADS_TOOLTIP"
|
||||
readonly="true" class="readonly"
|
||||
size="10"
|
||||
/>
|
||||
<field name="created_by" type="text"
|
||||
label="ATTACH_CREATOR_ID" description=""
|
||||
readonly="true" class="readonly"
|
||||
size="10"
|
||||
/>
|
||||
</fieldset>
|
||||
</form>
|
||||
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
||||
Reference in New Issue
Block a user