0byt3m1n1-V2
Path:
/
home
/
a
/
c
/
a
/
academiac
/
www
/
[
Home
]
File: media.php.tar
home/academiac/www/administrator/components/com_media/media.php 0000644 00000002574 15137207155 0020777 0 ustar 00 <?php /** * @package Joomla.Administrator * @subpackage com_media * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; // Access check. $user = JFactory::getUser(); $asset = JRequest::getCmd('asset'); $author = JRequest::getCmd('author'); if ( !$user->authorise('core.manage', 'com_media') && (!$asset or ( !$user->authorise('core.edit', $asset) && !$user->authorise('core.create', $asset) && count($user->getAuthorisedCategories($asset, 'core.create')) == 0) && !($user->id==$author && $user->authorise('core.edit.own', $asset)))) { return JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR')); } $params = JComponentHelper::getParams('com_media'); // Load the admin HTML view require_once JPATH_COMPONENT.'/helpers/media.php'; // Set the path definitions $popup_upload = JRequest::getCmd('pop_up', null); $path = "file_path"; $view = JRequest::getCmd('view'); if (substr(strtolower($view), 0, 6) == "images" || $popup_upload == 1) { $path = "image_path"; } define('COM_MEDIA_BASE', JPATH_ROOT.'/'.$params->get($path, 'images')); define('COM_MEDIA_BASEURL', JURI::root().$params->get($path, 'images')); $controller = JControllerLegacy::getInstance('Media'); $controller->execute(JRequest::getCmd('task')); $controller->redirect(); home/academiac/www/administrator/components/com_virtuemart/models/media.php 0000604 00000034327 15137216064 0023401 0 ustar 00 <?php /** * * Description * * @package VirtueMart * @subpackage * @author Max Milbers * @link http://www.virtuemart.net * @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved by the author. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php * VirtueMart is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * @version $Id: media.php 6549 2012-10-16 13:20:50Z Milbo $ */ // Check to ensure this file is included in Joomla! defined('_JEXEC') or die('Restricted access'); if(!class_exists('VmModel'))require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'vmmodel.php'); /** * Model for VirtueMart Product Files * * @package VirtueMart */ class VirtueMartModelMedia extends VmModel { /** * constructs a VmModel * setMainTable defines the maintable of the model * @author Max Milbers */ function __construct() { parent::__construct('virtuemart_media_id'); $this->setMainTable('medias'); $this->addvalidOrderingFieldName(array('ordering')); $this->_selectedOrdering = 'created_on'; } /** * Gets a single media by virtuemart_media_id * . * @param string $type * @param string $mime mime type of file, use for exampel image * @return mediaobject */ function getFile($type=0,$mime=0){ if (empty($this->_data)) { $data = $this->getTable('medias'); $data->load((int)$this->_id); if (!class_exists('VmMediaHandler')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'mediahandler.php'); $this->_data = VmMediaHandler::createMedia($data,$type,$mime); } return $this->_data; } /** * Kind of getFiles, it creates a bunch of image objects by an array of virtuemart_media_id * * @author Max Milbers * @param int $virtuemart_media_id * @param string $type * @param string $mime */ function createMediaByIds($virtuemart_media_ids,$type='',$mime='',$limit =0){ if (!class_exists('VmMediaHandler')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'mediahandler.php'); $app = JFactory::getApplication(); $medias = array(); static $_medias = array(); if(!empty($virtuemart_media_ids)){ if(!is_array($virtuemart_media_ids)) $virtuemart_media_ids = explode(',',$virtuemart_media_ids); //Lets delete empty ids //$virtuemart_media_ids = array_diff($virtuemart_media_ids,array('0','')); $data = $this->getTable('medias'); foreach($virtuemart_media_ids as $k => $virtuemart_media_id){ if($limit!==0 and $k==$limit and !empty($medias)) break; // never break if $limit = 0 if(is_object($virtuemart_media_id)){ $id = $virtuemart_media_id->virtuemart_media_id; } else { $id = $virtuemart_media_id; } if(!empty($id)){ if (!array_key_exists ($id, $_medias)) { $data->load((int)$id); if($app->isSite()){ if($data->published==0){ $_medias[$id] = $this->createVoidMedia($type,$mime); continue; } } $file_type = empty($data->file_type)? $type:$data->file_type; $mime = empty($data->file_mimetype)? $mime:$data->file_mimetype; if($app->isSite()){ $selectedLangue = explode(",", $data->file_lang); //vmdebug('selectedLangue',$selectedLangue); $lang = JFactory::getLanguage(); if(in_array($lang->getTag(), $selectedLangue) || $data->file_lang == '') { $_medias[$id] = VmMediaHandler::createMedia($data,$file_type,$mime); if(is_object($virtuemart_media_id) && !empty($virtuemart_media_id->product_name)) $_medias[$id]->product_name = $virtuemart_media_id->product_name; } } else { $_medias[$id] = VmMediaHandler::createMedia($data,$file_type,$mime); if(is_object($virtuemart_media_id) && !empty($virtuemart_media_id->product_name)) $_medias[$id]->product_name = $virtuemart_media_id->product_name; } } if (!empty($_medias[$id])) { $medias[] = $_medias[$id]; } } } } if(empty($medias)){ $medias[] = $this->createVoidMedia($type,$mime); } return $medias; } function createVoidMedia($type,$mime){ static $voidMedia = null; if(empty($voidMedia)){ $data = $this->getTable('medias'); //Create empty data $data->virtuemart_media_id = 0; $data->virtuemart_vendor_id = 0; $data->file_title = ''; $data->file_description = ''; $data->file_meta = ''; $data->file_mimetype = ''; $data->file_type = ''; $data->file_url = ''; $data->file_url_thumb = ''; $data->published = 0; $data->file_is_downloadable = 0; $data->file_is_forSale = 0; $data->file_is_product_image = 0; $data->shared = 0; $data->file_params = 0; $data->file_lang = ''; $voidMedia = VmMediaHandler::createMedia($data,$type,$mime); } return $voidMedia; } /** * Retrieve a list of files from the database. This is meant only for backend use * * @author Max Milbers * @param boolean $onlyPublished True to only retrieve the published files, false otherwise * @param boolean $noLimit True if no record count limit is used, false otherwise * @return object List of media objects */ function getFiles($onlyPublished=false, $noLimit=false, $virtuemart_product_id=null, $cat_id=null, $where=array(),$nbr=false){ $this->_noLimit = $noLimit; if(empty($this->_db)) $this->_db = JFactory::getDBO(); $vendorId = 1; //TODO set to logged user or requested vendorId, not easy later $query = ''; $selectFields = array(); $joinTables = array(); $joinedTables = ''; $whereItems= array(); $groupBy =''; $orderByTable = ''; if(!empty($virtuemart_product_id)){ $mainTable = '`#__virtuemart_product_medias`'; $selectFields[] = ' `#__virtuemart_medias`.`virtuemart_media_id` as virtuemart_media_id '; $joinTables[] = ' LEFT JOIN `#__virtuemart_medias` ON `#__virtuemart_medias`.`virtuemart_media_id`=`#__virtuemart_product_medias`.`virtuemart_media_id` and `virtuemart_product_id` = "'.$virtuemart_product_id.'"'; $whereItems[] = '`virtuemart_product_id` = "'.$virtuemart_product_id.'"'; if($this->_selectedOrdering=='ordering'){ $orderByTable = '`#__virtuemart_product_medias`.'; } else{ $orderByTable = '`#__virtuemart_medias`.'; } } else if(!empty($cat_id)){ $mainTable = '`#__virtuemart_category_medias`'; $selectFields[] = ' `#__virtuemart_medias`.`virtuemart_media_id` as virtuemart_media_id'; $joinTables[] = ' LEFT JOIN `#__virtuemart_medias` ON `#__virtuemart_medias`.`virtuemart_media_id`=`#__virtuemart_category_medias`.`virtuemart_media_id` and `virtuemart_category_id` = "'.$cat_id.'"'; $whereItems[] = '`virtuemart_category_id` = "'.$cat_id.'"'; if($this->_selectedOrdering=='ordering'){ $orderByTable = '`#__virtuemart_category_medias`.'; } else{ $orderByTable = '`#__virtuemart_medias`.'; } } else { $mainTable = '`#__virtuemart_medias`'; $selectFields[] = ' `virtuemart_media_id` '; if(!class_exists('Permissions')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'permissions.php'); if(!Permissions::getInstance()->check('admin') ){ $whereItems[] = '(`virtuemart_vendor_id` = "'.(int)$vendorId.'" OR `shared`="1")'; } } if ($onlyPublished) { $whereItems[] = '`#__virtuemart_medias`.`published` = 1'; } if ($search = JRequest::getString('searchMedia', false)){ $search = '"%' . $this->_db->getEscaped( $search, true ) . '%"' ; $where[] = ' (`file_title` LIKE '.$search.' OR `file_description` LIKE '.$search.' OR `file_meta` LIKE '.$search.' OR `file_url` LIKE '.$search.' OR `file_url_thumb` LIKE '.$search.' ) '; } if ($type = JRequest::getWord('search_type')) { $where[] = 'file_type = "'.$type.'" ' ; } if ($role = JRequest::getWord('search_role')) { if ($role == "file_is_downloadable") { $where[] = '`file_is_downloadable` = 1'; $where[] = '`file_is_forSale` = 0'; } elseif ($role == "file_is_forSale") { $where[] = '`file_is_downloadable` = 0'; $where[] = '`file_is_forSale` = 1'; } else { $where[] = '`file_is_downloadable` = 0'; $where[] = '`file_is_forSale` = 0'; } } if (!empty($where)) $whereItems = array_merge($whereItems,$where); if(count($whereItems)>0){ $whereString = ' WHERE '.implode(' AND ', $whereItems ); } else { $whereString = ' '; } $orderBy = $this->_getOrdering($orderByTable);# if(count($selectFields)>0){ $select = implode(', ', $selectFields ).' FROM '.$mainTable; //$selectFindRows = 'SELECT COUNT(*) FROM '.$mainTable; if(count($joinTables)>0){ foreach($joinTables as $table){ $joinedTables .= $table; } } } else { vmError('No select fields given in getFiles','No select fields given'); return false; } $this->_data = $this->exeSortSearchListQuery(2, $select, $joinedTables, $whereString, $groupBy, $orderBy,'',$nbr); if(empty($this->_data)){ return array(); } if( !is_array($this->_data)){ $this->_data = explode(',',$this->_data); } $this->_data = $this->createMediaByIds($this->_data); return $this->_data; } /** * This function stores a media and updates then the refered table * * @author Max Milbers * @author Patrick Kohl * @param array $data Data from a from * @param string $type type of the media category,product,manufacturer,shop, ... */ function storeMedia($data,$type){ // vmdebug('my data in media to store start',$data['virtuemart_media_id']); JRequest::checkToken() or jexit( 'Invalid Token, while trying to save media' ); if(empty($data['media_action'])){ $data['media_action'] = 'none'; } //vmdebug('storeMedia',$data); //the active media id is not empty, so there should be something done with it //if( (!empty($data['active_media_id']) && !empty($data['virtuemart_media_id']) ) || $data['media_action']=='upload'){ if( (!empty($data['active_media_id']) and isset($data['virtuemart_media_id']) ) || $data['media_action']=='upload'){ $oldIds = $data['virtuemart_media_id']; $data['file_type'] = $type; //$data['virtuemart_media_id'] = (int)$data['active_media_id']; //done within the function now $this -> setId($data['active_media_id']); $virtuemart_media_id = $this->store($data,$type); //added by Mike, Mike why did you add this? This function storeMedia is extremely nasty $this->setId($virtuemart_media_id); if(!empty($oldIds)){ if(!is_array($oldIds)) $oldIds = array($oldIds); if(!empty($data['mediaordering']) && $data['media_action']=='upload'){ // array_push($data['mediaordering'],count($data['mediaordering'])+1); $data['mediaordering'][$virtuemart_media_id] = count($data['mediaordering']); } $virtuemart_media_ids = array_merge( (array)$virtuemart_media_id,$oldIds); // vmdebug('merged old and new',$virtuemart_media_ids); $data['virtuemart_media_id'] = array_unique($virtuemart_media_ids); } else { $data['virtuemart_media_id'] = $virtuemart_media_id; } } if(!empty($data['mediaordering'])){ asort($data['mediaordering']); $sortedMediaIds = array(); foreach($data['mediaordering'] as $k=>$v){ $sortedMediaIds[] = $k; } // vmdebug('merging old and new',$oldIds,$virtuemart_media_id); $data['virtuemart_media_id'] = $sortedMediaIds; } // vmdebug('my data in media to store',$data['virtuemart_media_id'],$data['mediaordering']); //set the relations $table = $this->getTable($type.'_medias'); // Bind the form fields to the country table $table->bindChecknStore($data); $errors = $table->getErrors(); foreach($errors as $error){ vmError($error); } return $table->virtuemart_media_id; } /** * Store an entry of a mediaItem, this means in end effect every media file in the shop * images, videos, pdf, zips, exe, ... * * @author Max Milbers */ public function store(&$data,$type) { VmConfig::loadJLang('com_virtuemart_media'); //if(empty($data['media_action'])) return $table->virtuemart_media_id; if (!class_exists('VmMediaHandler')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'mediahandler.php'); $table = $this->getTable('medias'); /* $a = trim($data['file_url_thumb']); $b = trim(JText::sprintf('COM_VIRTUEMART_DEFAULT_URL',$data['file_url_thumb'])); vmdebug(' the miese Assi',$a,$b); if( $a == $b ){ vmdebug('Unset the miese Assi'); unset($data['file_url_thumb']); }*/ //unset($data['file_url_thumb']); $data['virtuemart_media_id'] = $this->getId(); $table->bind($data); $data = VmMediaHandler::prepareStoreMedia($table,$data,$type); //this does not store the media, it process the actions and prepares data // workarround for media published and product published two fields in one form. $tmpPublished = false; if (isset($data['media_published'])){ $tmpPublished = $data['published']; $data['published'] = $data['media_published']; //vmdebug('$data["published"]',$data['published']); } $table->bindChecknStore($data); $errors = $table->getErrors(); foreach($errors as $error){ vmError('store medias '.$error); } if($tmpPublished){ $data['published'] = $tmpPublished; } // vmdebug('store media $table->virtuemart_media_id '.$table->virtuemart_media_id); return $table->virtuemart_media_id; } public function attachImages($objects,$type,$mime='',$limit=0){ if(!empty($objects)){ if(!is_array($objects)) $objects = array($objects); foreach($objects as $k => $object){ if(empty($object->virtuemart_media_id)) $virtuemart_media_id = null; else $virtuemart_media_id = $object->virtuemart_media_id; $object->images = $this->createMediaByIds($virtuemart_media_id,$type,$mime,$limit); //This should not be used in fact. It is for legacy reasons there. if(isset($object->images[0]->file_url_thumb)){ $object->file_url_thumb = $object->images[0]->file_url_thumb; $object->file_url = $object->images[0]->file_url; } } } } } // pure php no closing tag home/academiac/www/administrator/components/com_virtuemart/controllers/media.php 0000604 00000006065 15137243201 0024453 0 ustar 00 <?php /** * * Media controller * * @package VirtueMart * @subpackage * @author Max Milbers * @link http://www.virtuemart.net * @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php * VirtueMart is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * @version $Id: media.php 6071 2012-06-06 15:33:04Z Milbo $ */ // Check to ensure this file is included in Joomla! defined('_JEXEC') or die('Restricted access'); // Load the controller framework jimport('joomla.application.component.controller'); if(!class_exists('VmController'))require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'vmcontroller.php'); /** * Product Controller * * @package VirtueMart * @author Max Milbers */ class VirtuemartControllerMedia extends VmController { /** * Method to display the view * * @access public * @author */ function __construct() { VmConfig::loadJLang('com_virtuemart_media'); parent::__construct('virtuemart_media_id'); } /** * for ajax call media */ function viewJson() { /* Create the view object. */ $view = $this->getView('media', 'json'); /* Now display the view. */ $view->display(null); } function save($data = 0){ $fileModel = VmModel::getModel('media'); //Now we try to determine to which this media should be long to $data = JRequest::get('post'); //$data['file_title'] = JRequest::getVar('file_title','','post','STRING',JREQUEST_ALLOWHTML); $data['file_description'] = JRequest::getVar('file_description','','post','STRING',JREQUEST_ALLOWHTML); $data['media_attributes'] = JRequest::getWord('media_attributes'); $data['file_type'] = JRequest::getWord('file_type'); if(empty($data['file_type'])){ $data['file_type'] = $data['media_attributes']; } if ($id = $fileModel->store($data,$data['file_type'])) { $msg = JText::_('COM_VIRTUEMART_FILE_SAVED_SUCCESS'); } else { $msg = $fileModel->getError(); } $cmd = JRequest::getCmd('task'); if($cmd == 'apply'){ $redirection = 'index.php?option=com_virtuemart&view=media&task=edit&virtuemart_media_id='.$id; } else { $redirection = 'index.php?option=com_virtuemart&view=media'; } $this->setRedirect($redirection, $msg); } function synchronizeMedia(){ if(!class_exists('Permissions')) require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'permissions.php'); if(!Permissions::getInstance()->check('admin')){ $msg = 'Forget IT'; $this->setRedirect('index.php?option=com_virtuemart', $msg); } if(!class_exists('Migrator')) require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'migrator.php'); $migrator = new Migrator(); $result = $migrator->portMedia(); $this->setRedirect($this->redirectPath, $result); } } // pure php no closing tag home/academiac/www/libraries/joomla/form/fields/media.php 0000644 00000016176 15137513642 0017467 0 ustar 00 <?php /** * @package Joomla.Platform * @subpackage Form * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE */ defined('JPATH_PLATFORM') or die; /** * Form Field class for the Joomla Platform. * Provides a modal media selector including upload mechanism * * @package Joomla.Platform * @subpackage Form * @since 11.1 */ class JFormFieldMedia extends JFormField { /** * The form field type. * * @var string * @since 11.1 */ protected $type = 'Media'; /** * The initialised state of the document object. * * @var boolean * @since 11.1 */ protected static $initialised = false; /** * Method to get the field input markup for a media selector. * Use attributes to identify specific created_by and asset_id fields * * @return string The field input markup. * * @since 11.1 */ protected function getInput() { $assetField = $this->element['asset_field'] ? (string) $this->element['asset_field'] : 'asset_id'; $authorField = $this->element['created_by_field'] ? (string) $this->element['created_by_field'] : 'created_by'; $asset = $this->form->getValue($assetField) ? $this->form->getValue($assetField) : (string) $this->element['asset_id']; if ($asset == '') { $asset = JRequest::getCmd('option'); } $link = (string) $this->element['link']; if (!self::$initialised) { // Load the modal behavior script. JHtml::_('behavior.modal'); // Build the script. $script = array(); $script[] = ' function jInsertFieldValue(value, id) {'; $script[] = ' var old_value = document.id(id).value;'; $script[] = ' if (old_value != value) {'; $script[] = ' var elem = document.id(id);'; $script[] = ' elem.value = value;'; $script[] = ' elem.fireEvent("change");'; $script[] = ' if (typeof(elem.onchange) === "function") {'; $script[] = ' elem.onchange();'; $script[] = ' }'; $script[] = ' jMediaRefreshPreview(id);'; $script[] = ' }'; $script[] = ' }'; $script[] = ' function jMediaRefreshPreview(id) {'; $script[] = ' var value = document.id(id).value;'; $script[] = ' var img = document.id(id + "_preview");'; $script[] = ' if (img) {'; $script[] = ' if (value) {'; $script[] = ' img.src = "' . JURI::root() . '" + value;'; $script[] = ' document.id(id + "_preview_empty").setStyle("display", "none");'; $script[] = ' document.id(id + "_preview_img").setStyle("display", "");'; $script[] = ' } else { '; $script[] = ' img.src = ""'; $script[] = ' document.id(id + "_preview_empty").setStyle("display", "");'; $script[] = ' document.id(id + "_preview_img").setStyle("display", "none");'; $script[] = ' } '; $script[] = ' } '; $script[] = ' }'; $script[] = ' function jMediaRefreshPreviewTip(tip)'; $script[] = ' {'; $script[] = ' tip.setStyle("display", "block");'; $script[] = ' var img = tip.getElement("img.media-preview");'; $script[] = ' var id = img.getProperty("id");'; $script[] = ' id = id.substring(0, id.length - "_preview".length);'; $script[] = ' jMediaRefreshPreview(id);'; $script[] = ' }'; // Add the script to the document head. JFactory::getDocument()->addScriptDeclaration(implode("\n", $script)); self::$initialised = true; } // Initialize variables. $html = array(); $attr = ''; // Initialize some field attributes. $attr .= $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : ''; $attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : ''; // Initialize JavaScript field attributes. $attr .= $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : ''; // The text field. $html[] = '<div class="fltlft">'; $html[] = ' <input type="text" name="' . $this->name . '" id="' . $this->id . '"' . ' value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . ' readonly="readonly"' . $attr . ' />'; $html[] = '</div>'; $directory = (string) $this->element['directory']; if ($this->value && file_exists(JPATH_ROOT . '/' . $this->value)) { $folder = explode('/', $this->value); array_shift($folder); array_pop($folder); $folder = implode('/', $folder); } elseif (file_exists(JPATH_ROOT . '/' . JComponentHelper::getParams('com_media')->get('image_path', 'images') . '/' . $directory)) { $folder = $directory; } else { $folder = ''; } // The button. $html[] = '<div class="button2-left">'; $html[] = ' <div class="blank">'; $html[] = ' <a class="modal" title="' . JText::_('JLIB_FORM_BUTTON_SELECT') . '"' . ' href="' . ($this->element['readonly'] ? '' : ($link ? $link : 'index.php?option=com_media&view=images&tmpl=component&asset=' . $asset . '&author=' . $this->form->getValue($authorField)) . '&fieldid=' . $this->id . '&folder=' . $folder) . '"' . ' rel="{handler: \'iframe\', size: {x: 800, y: 500}}">'; $html[] = JText::_('JLIB_FORM_BUTTON_SELECT') . '</a>'; $html[] = ' </div>'; $html[] = '</div>'; $html[] = '<div class="button2-left">'; $html[] = ' <div class="blank">'; $html[] = ' <a title="' . JText::_('JLIB_FORM_BUTTON_CLEAR') . '"' . ' href="#" onclick="'; $html[] = 'jInsertFieldValue(\'\', \'' . $this->id . '\');'; $html[] = 'return false;'; $html[] = '">'; $html[] = JText::_('JLIB_FORM_BUTTON_CLEAR') . '</a>'; $html[] = ' </div>'; $html[] = '</div>'; // The Preview. $preview = (string) $this->element['preview']; $showPreview = true; $showAsTooltip = false; switch ($preview) { case 'false': case 'none': $showPreview = false; break; case 'true': case 'show': break; case 'tooltip': default: $showAsTooltip = true; $options = array( 'onShow' => 'jMediaRefreshPreviewTip', ); JHtml::_('behavior.tooltip', '.hasTipPreview', $options); break; } if ($showPreview) { if ($this->value && file_exists(JPATH_ROOT . '/' . $this->value)) { $src = JURI::root() . $this->value; } else { $src = ''; } $attr = array( 'id' => $this->id . '_preview', 'class' => 'media-preview', 'style' => 'max-width:160px; max-height:100px;' ); $img = JHtml::image($src, JText::_('JLIB_FORM_MEDIA_PREVIEW_ALT'), $attr); $previewImg = '<div id="' . $this->id . '_preview_img"' . ($src ? '' : ' style="display:none"') . '>' . $img . '</div>'; $previewImgEmpty = '<div id="' . $this->id . '_preview_empty"' . ($src ? ' style="display:none"' : '') . '>' . JText::_('JLIB_FORM_MEDIA_PREVIEW_EMPTY') . '</div>'; $html[] = '<div class="media-preview fltlft">'; if ($showAsTooltip) { $tooltip = $previewImgEmpty . $previewImg; $options = array( 'title' => JText::_('JLIB_FORM_MEDIA_PREVIEW_SELECTED_IMAGE'), 'text' => JText::_('JLIB_FORM_MEDIA_PREVIEW_TIP_TITLE'), 'class' => 'hasTipPreview' ); $html[] = JHtml::tooltip($tooltip, $options); } else { $html[] = ' ' . $previewImgEmpty; $html[] = ' ' . $previewImg; } $html[] = '</div>'; } return implode("\n", $html); } } home/academiac/www/components/com_media/media.php 0000644 00000005265 15137643117 0016121 0 ustar 00 <?php /** * @package Joomla.Site * @subpackage com_media * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // no direct access defined('_JEXEC') or die; $params = JComponentHelper::getParams('com_media'); // Make sure the user is authorized to view this page $user = JFactory::getUser(); $asset = JRequest::getCmd('asset'); $author = JRequest::getCmd('author'); if (!$asset or !$user->authorise('core.edit', $asset) && !$user->authorise('core.create', $asset) && count($user->getAuthorisedCategories($asset, 'core.create')) == 0 && !($user->id==$author && $user->authorise('core.edit.own', $asset))) { return JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR')); } // Set the path definitions define('COM_MEDIA_BASE', JPATH_ROOT.'/'.$params->get('image_path', 'images')); define('COM_MEDIA_BASEURL', JURI::root().'/'.$params->get('image_path', 'images')); $lang = JFactory::getLanguage(); $lang->load('com_media', JPATH_ADMINISTRATOR, null, false, true) || $lang->load('com_media', JPATH_SITE, null, false, true); // Load the admin HTML view require_once JPATH_COMPONENT_ADMINISTRATOR.'/helpers/media.php'; // Require the base controller require_once JPATH_COMPONENT.'/controller.php'; // Make sure the user is authorized to view this page $user = JFactory::getUser(); $app = JFactory::getApplication(); $cmd = JRequest::getCmd('task', null); if (strpos($cmd, '.') != false) { // We have a defined controller/task pair -- lets split them out list($controllerName, $task) = explode('.', $cmd); // Define the controller name and path $controllerName = strtolower($controllerName); $controllerPath = JPATH_COMPONENT_ADMINISTRATOR.'/controllers/'.$controllerName.'.php'; // If the controller file path exists, include it ... else lets die with a 500 error if (file_exists($controllerPath)) { require_once $controllerPath; } else { JError::raiseError(500, JText::_('JERROR_INVALID_CONTROLLER')); } } else { // Base controller, just set the task :) $controllerName = null; $task = $cmd; } // Set the name for the controller and instantiate it $controllerClass = 'MediaController'.ucfirst($controllerName); if (class_exists($controllerClass)) { $controller = new $controllerClass(); } else { JError::raiseError(500, JText::_('JERROR_INVALID_CONTROLLER_CLASS')); } // Set the model and view paths to the administrator folders $controller->addViewPath(JPATH_COMPONENT_ADMINISTRATOR.'/views'); $controller->addModelPath(JPATH_COMPONENT_ADMINISTRATOR.'/models'); // Perform the Request task $controller->execute($task); // Redirect if set by the controller $controller->redirect(); home/academiac/www/administrator/components/com_media/helpers/media.php 0000644 00000015625 15140276040 0022433 0 ustar 00 <?php /** * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; /** * @package Joomla.Administrator * @subpackage com_media */ abstract class MediaHelper { /** * Checks if the file is an image * @param string The filename * @return boolean */ public static function isImage($fileName) { static $imageTypes = 'xcf|odg|gif|jpg|png|bmp'; return preg_match("/\.(?:$imageTypes)$/i", $fileName); } /** * Checks if the file is an image * @param string The filename * @return boolean */ public static function getTypeIcon($fileName) { // Get file extension return strtolower(substr($fileName, strrpos($fileName, '.') + 1)); } /** * Checks if the file can be uploaded * * @param array File information * @param string An error message to be returned * @return boolean */ public static function canUpload($file, &$err) { $params = JComponentHelper::getParams('com_media'); if (empty($file['name'])) { $err = 'COM_MEDIA_ERROR_UPLOAD_INPUT'; return false; } jimport('joomla.filesystem.file'); if ($file['name'] !== JFile::makesafe($file['name'])) { $err = 'COM_MEDIA_ERROR_WARNFILENAME'; return false; } $format = strtolower(JFile::getExt($file['name'])); // Media file names should never have executable extensions buried in them. $executable = array( 'php', 'js', 'exe', 'phtml', 'java', 'perl', 'py', 'asp','dll', 'go', 'ade', 'adp', 'bat', 'chm', 'cmd', 'com', 'cpl', 'hta', 'ins', 'isp', 'jse', 'lib', 'mde', 'msc', 'msp', 'mst', 'pif', 'scr', 'sct', 'shb', 'sys', 'vb', 'vbe', 'vbs', 'vxd', 'wsc', 'wsf', 'wsh' ); $explodedFileName = explode('.', $file['name']); if (count($explodedFileName > 2)) { foreach ($executable as $extensionName) { if (in_array($extensionName, $explodedFileName)) { $app->enqueueMessage(JText::_('JLIB_MEDIA_ERROR_WARNFILETYPE'), 'notice'); return false; } } } $allowable = explode(',', $params->get('upload_extensions')); $ignored = explode(',', $params->get('ignore_extensions')); if ($format == '' || $format == false || (!in_array($format, $allowable) && !in_array($format, $ignored))) { $err = 'COM_MEDIA_ERROR_WARNFILETYPE'; return false; } $maxSize = (int) ($params->get('upload_maxsize', 0) * 1024 * 1024); if ($maxSize > 0 && (int) $file['size'] > $maxSize) { $err = 'COM_MEDIA_ERROR_WARNFILETOOLARGE'; return false; } $user = JFactory::getUser(); $imginfo = null; if ($params->get('restrict_uploads', 1)) { $images = explode(',', $params->get('image_extensions')); if (in_array($format, $images)) { // if its an image run it through getimagesize // if tmp_name is empty, then the file was bigger than the PHP limit if (!empty($file['tmp_name'])) { if (($imginfo = getimagesize($file['tmp_name'])) === FALSE) { $err = 'COM_MEDIA_ERROR_WARNINVALID_IMG'; return false; } } else { $err = 'COM_MEDIA_ERROR_WARNFILETOOLARGE'; return false; } } elseif (!in_array($format, $ignored)) { // if its not an image...and we're not ignoring it $allowed_mime = explode(',', $params->get('upload_mime')); $illegal_mime = explode(',', $params->get('upload_mime_illegal')); if (function_exists('finfo_open') && $params->get('check_mime', 1)) { // We have fileinfo $finfo = finfo_open(FILEINFO_MIME); $type = finfo_file($finfo, $file['tmp_name']); if (strlen($type) && !in_array($type, $allowed_mime) && in_array($type, $illegal_mime)) { $err = 'COM_MEDIA_ERROR_WARNINVALID_MIME'; return false; } finfo_close($finfo); } elseif (function_exists('mime_content_type') && $params->get('check_mime', 1)) { // we have mime magic $type = mime_content_type($file['tmp_name']); if (strlen($type) && !in_array($type, $allowed_mime) && in_array($type, $illegal_mime)) { $err = 'COM_MEDIA_ERROR_WARNINVALID_MIME'; return false; } } elseif (!$user->authorise('core.manage')) { $err = 'COM_MEDIA_ERROR_WARNNOTADMIN'; return false; } } } $xss_check = JFile::read($file['tmp_name'], false, 256); $html_tags = array('abbr', 'acronym', 'address', 'applet', 'area', 'audioscope', 'base', 'basefont', 'bdo', 'bgsound', 'big', 'blackface', 'blink', 'blockquote', 'body', 'bq', 'br', 'button', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'comment', 'custom', 'dd', 'del', 'dfn', 'dir', 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'fn', 'font', 'form', 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'hr', 'html', 'iframe', 'ilayer', 'img', 'input', 'ins', 'isindex', 'keygen', 'kbd', 'label', 'layer', 'legend', 'li', 'limittext', 'link', 'listing', 'map', 'marquee', 'menu', 'meta', 'multicol', 'nobr', 'noembed', 'noframes', 'noscript', 'nosmartquotes', 'object', 'ol', 'optgroup', 'option', 'param', 'plaintext', 'pre', 'rt', 'ruby', 's', 'samp', 'script', 'select', 'server', 'shadow', 'sidebar', 'small', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'title', 'tr', 'tt', 'ul', 'var', 'wbr', 'xml', 'xmp', '!DOCTYPE', '!--'); foreach($html_tags as $tag) { // A tag is '<tagname ', so we need to add < and a space or '<tagname>' if (stristr($xss_check, '<'.$tag.' ') || stristr($xss_check, '<'.$tag.'>')) { $err = 'COM_MEDIA_ERROR_WARNIEXSS'; return false; } } return true; } public static function parseSize($size) { if ($size < 1024) { return JText::sprintf('COM_MEDIA_FILESIZE_BYTES', $size); } elseif ($size < 1024 * 1024) { return JText::sprintf('COM_MEDIA_FILESIZE_KILOBYTES', sprintf('%01.2f', $size / 1024.0)); } else { return JText::sprintf('COM_MEDIA_FILESIZE_MEGABYTES', sprintf('%01.2f', $size / (1024.0 * 1024))); } } public static function imageResize($width, $height, $target) { //takes the larger size of the width and height and applies the //formula accordingly...this is so this script will work //dynamically with any size image if ($width > $height) { $percentage = ($target / $width); } else { $percentage = ($target / $height); } //gets the new value and applies the percentage, then rounds the value $width = round($width * $percentage); $height = round($height * $percentage); return array($width, $height); } public static function countFiles($dir) { $total_file = 0; $total_dir = 0; if (is_dir($dir)) { $d = dir($dir); while (false !== ($entry = $d->read())) { if (substr($entry, 0, 1) != '.' && is_file($dir . DIRECTORY_SEPARATOR . $entry) && strpos($entry, '.html') === false && strpos($entry, '.php') === false) { $total_file++; } if (substr($entry, 0, 1) != '.' && is_dir($dir . DIRECTORY_SEPARATOR . $entry)) { $total_dir++; } } $d->close(); } return array ($total_file, $total_dir); } }
©
2018.