Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setting up models and views of new MVC
- Loading branch information
Showing
4 changed files
with
381 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,164 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Administrator | ||
* @subpackage com_media | ||
* | ||
* @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; | ||
|
||
/** | ||
* Media Component Manager Model | ||
* | ||
* @package Joomla.Administrator | ||
* @subpackage com_media | ||
* @since 3.3 | ||
*/ | ||
class MediaModelMedia extends ConfigModelForm | ||
{ | ||
public function getState($property = null, $default = null) | ||
{ | ||
static $set; | ||
|
||
if (!$set) | ||
{ | ||
$input = JFactory::getApplication()->input; | ||
|
||
$folder = $input->get('folder', '', 'path'); | ||
$this->state->set('folder', $folder); | ||
|
||
$fieldid = $input->get('fieldid', ''); | ||
$this->state->set('field.id', $fieldid); | ||
|
||
$parent = str_replace("\\", "/", dirname($folder)); | ||
$parent = ($parent == '.') ? null : $parent; | ||
$this->state->set('parent', $parent); | ||
$set = true; | ||
} | ||
|
||
if(!$property) | ||
{ | ||
|
||
return parent::getState(); | ||
} | ||
else | ||
{ | ||
|
||
return parent::getState()->get($property, $default); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Image Manager Popup | ||
* | ||
* @param string $listFolder The image directory to display | ||
* @since 3.3 | ||
*/ | ||
function getFolderList($base = null) | ||
{ | ||
// Get some paths from the request | ||
if (empty($base)) | ||
{ | ||
$base = COM_MEDIA_BASE; | ||
} | ||
//corrections for windows paths | ||
$base = str_replace(DIRECTORY_SEPARATOR, '/', $base); | ||
$com_media_base_uni = str_replace(DIRECTORY_SEPARATOR, '/', COM_MEDIA_BASE); | ||
|
||
// Get the list of folders | ||
jimport('joomla.filesystem.folder'); | ||
$folders = JFolder::folders($base, '.', true, true); | ||
|
||
$document = JFactory::getDocument(); | ||
$document->setTitle(JText::_('COM_MEDIA_INSERT_IMAGE')); | ||
|
||
// Build the array of select options for the folder list | ||
$options[] = JHtml::_('select.option', "", "/"); | ||
|
||
foreach ($folders as $folder) | ||
{ | ||
$folder = str_replace($com_media_base_uni, "", str_replace(DIRECTORY_SEPARATOR, '/', $folder)); | ||
$value = substr($folder, 1); | ||
$text = str_replace(DIRECTORY_SEPARATOR, "/", $folder); | ||
$options[] = JHtml::_('select.option', $value, $text); | ||
} | ||
|
||
// Sort the folder list array | ||
if (is_array($options)) | ||
{ | ||
sort($options); | ||
} | ||
|
||
// Get asset and author id (use integer filter) | ||
$input = JFactory::getApplication()->input; | ||
$asset = $input->get('asset', 0, 'integer'); | ||
|
||
// For new items the asset is a string. JAccess always checks type first | ||
// so both string and integer are supported. | ||
if ($asset == 0) | ||
{ | ||
$asset = $input->get('asset', 0, 'string'); | ||
} | ||
|
||
$author = $input->get('author', 0, 'integer'); | ||
|
||
// Create the drop-down folder select list | ||
$list = JHtml::_('select.genericlist', $options, 'folderlist', 'class="inputbox" size="1" onchange="ImageManager.setFolder(this.options[this.selectedIndex].value, '.$asset.', '.$author.')" ', 'value', 'text', $base); | ||
|
||
return $list; | ||
} | ||
|
||
function getFolderTree($base = null) | ||
{ | ||
// Get some paths from the request | ||
if (empty($base)) | ||
{ | ||
$base = COM_MEDIA_BASE; | ||
} | ||
|
||
$mediaBase = str_replace(DIRECTORY_SEPARATOR, '/', COM_MEDIA_BASE.'/'); | ||
|
||
// Get the list of folders | ||
jimport('joomla.filesystem.folder'); | ||
$folders = JFolder::folders($base, '.', true, true); | ||
|
||
$tree = array(); | ||
|
||
foreach ($folders as $folder) | ||
{ | ||
$folder = str_replace(DIRECTORY_SEPARATOR, '/', $folder); | ||
$name = substr($folder, strrpos($folder, '/') + 1); | ||
$relative = str_replace($mediaBase, '', $folder); | ||
$absolute = $folder; | ||
$path = explode('/', $relative); | ||
$node = (object) array('name' => $name, 'relative' => $relative, 'absolute' => $absolute); | ||
|
||
$tmp = &$tree; | ||
for ($i = 0, $n = count($path); $i < $n; $i++) | ||
{ | ||
if (!isset($tmp['children'])) | ||
{ | ||
$tmp['children'] = array(); | ||
} | ||
|
||
if ($i == $n - 1) | ||
{ | ||
// We need to place the node | ||
$tmp['children'][$relative] = array('data' => $node, 'children' => array()); | ||
break; | ||
} | ||
|
||
if (array_key_exists($key = implode('/', array_slice($path, 0, $i + 1)), $tmp['children'])) | ||
{ | ||
$tmp = &$tmp['children'][$key]; | ||
} | ||
} | ||
} | ||
$tree['data'] = (object) array('name' => JText::_('COM_MEDIA_MEDIA'), 'relative' => '', 'absolute' => $base); | ||
|
||
return $tree; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,213 @@ | ||
<?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; | ||
|
||
jimport('joomla.filesystem.folder'); | ||
jimport('joomla.filesystem.file'); | ||
|
||
/** | ||
* Media Component MediaList Model | ||
* | ||
* @package Joomla.Administrator | ||
* @subpackage com_media | ||
* @since 3.3 | ||
*/ | ||
class MediaModelMedialist extends ConfigModelForm | ||
{ | ||
public function getState($property = null, $default = null) | ||
{ | ||
static $set; | ||
|
||
if (!$set) | ||
{ | ||
$input = JFactory::getApplication()->input; | ||
$folder = $input->get('folder', '', 'path'); | ||
$this->state->set('folder', $folder); | ||
|
||
$parent = str_replace("\\", "/", dirname($folder)); | ||
$parent = ($parent == '.') ? null : $parent; | ||
$this->state->set('parent', $parent); | ||
$set = true; | ||
} | ||
|
||
if(!$property) | ||
{ | ||
|
||
return parent::getState(); | ||
} | ||
else | ||
{ | ||
|
||
return parent::getState()->get($property, $default); | ||
} | ||
|
||
} | ||
|
||
public function getImages() | ||
{ | ||
$list = $this->getList(); | ||
|
||
return $list['images']; | ||
} | ||
|
||
public function getFolders() | ||
{ | ||
$list = $this->getList(); | ||
|
||
return $list['folders']; | ||
} | ||
|
||
public function getDocuments() | ||
{ | ||
$list = $this->getList(); | ||
|
||
return $list['docs']; | ||
} | ||
|
||
/** | ||
* Build imagelist | ||
* | ||
* @param string $listFolder The image directory to display | ||
* @since 1.5 | ||
*/ | ||
public function getList() | ||
{ | ||
static $list; | ||
|
||
// Only process the list once per request | ||
if (is_array($list)) | ||
{ | ||
return $list; | ||
} | ||
|
||
// Get current path from request | ||
$current = $this->getState('folder'); | ||
|
||
// If undefined, set to empty | ||
if ($current == 'undefined') | ||
{ | ||
$current = ''; | ||
} | ||
|
||
if (strlen($current) > 0) | ||
{ | ||
$basePath = COM_MEDIA_BASE.'/'.$current; | ||
} | ||
else | ||
{ | ||
$basePath = COM_MEDIA_BASE; | ||
} | ||
|
||
$mediaBase = str_replace(DIRECTORY_SEPARATOR, '/', COM_MEDIA_BASE.'/'); | ||
|
||
$images = array (); | ||
$folders = array (); | ||
$docs = array (); | ||
|
||
$fileList = false; | ||
$folderList = false; | ||
if (file_exists($basePath)) | ||
{ | ||
// Get the list of files and folders from the given folder | ||
$fileList = JFolder::files($basePath); | ||
$folderList = JFolder::folders($basePath); | ||
} | ||
|
||
// Iterate over the files if they exist | ||
if ($fileList !== false) | ||
{ | ||
foreach ($fileList as $file) | ||
{ | ||
if (is_file($basePath.'/'.$file) && substr($file, 0, 1) != '.' && strtolower($file) !== 'index.html') | ||
{ | ||
$tmp = new JObject; | ||
$tmp->name = $file; | ||
$tmp->title = $file; | ||
$tmp->path = str_replace(DIRECTORY_SEPARATOR, '/', JPath::clean($basePath . '/' . $file)); | ||
$tmp->path_relative = str_replace($mediaBase, '', $tmp->path); | ||
$tmp->size = filesize($tmp->path); | ||
|
||
$ext = strtolower(JFile::getExt($file)); | ||
switch ($ext) | ||
{ | ||
// Image | ||
case 'jpg': | ||
case 'png': | ||
case 'gif': | ||
case 'xcf': | ||
case 'odg': | ||
case 'bmp': | ||
case 'jpeg': | ||
case 'ico': | ||
$info = @getimagesize($tmp->path); | ||
$tmp->width = @$info[0]; | ||
$tmp->height = @$info[1]; | ||
$tmp->type = @$info[2]; | ||
$tmp->mime = @$info['mime']; | ||
|
||
if (($info[0] > 60) || ($info[1] > 60)) | ||
{ | ||
$dimensions = MediaHelper::imageResize($info[0], $info[1], 60); | ||
$tmp->width_60 = $dimensions[0]; | ||
$tmp->height_60 = $dimensions[1]; | ||
} | ||
else { | ||
$tmp->width_60 = $tmp->width; | ||
$tmp->height_60 = $tmp->height; | ||
} | ||
|
||
if (($info[0] > 16) || ($info[1] > 16)) | ||
{ | ||
$dimensions = MediaHelper::imageResize($info[0], $info[1], 16); | ||
$tmp->width_16 = $dimensions[0]; | ||
$tmp->height_16 = $dimensions[1]; | ||
} | ||
else { | ||
$tmp->width_16 = $tmp->width; | ||
$tmp->height_16 = $tmp->height; | ||
} | ||
|
||
$images[] = $tmp; | ||
break; | ||
|
||
// Non-image document | ||
default: | ||
$tmp->icon_32 = "media/mime-icon-32/".$ext.".png"; | ||
$tmp->icon_16 = "media/mime-icon-16/".$ext.".png"; | ||
$docs[] = $tmp; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Iterate over the folders if they exist | ||
if ($folderList !== false) | ||
{ | ||
foreach ($folderList as $folder) | ||
{ | ||
$tmp = new JObject; | ||
$tmp->name = basename($folder); | ||
$tmp->path = str_replace(DIRECTORY_SEPARATOR, '/', JPath::clean($basePath . '/' . $folder)); | ||
$tmp->path_relative = str_replace($mediaBase, '', $tmp->path); | ||
$mediaHelper = new JHelperMedia; | ||
$count = $mediaHelper->countFiles($dir); | ||
$tmp->files = $count[0]; | ||
$tmp->folders = $count[1]; | ||
|
||
$folders[] = $tmp; | ||
} | ||
} | ||
|
||
$list = array('folders' => $folders, 'docs' => $docs, 'images' => $images); | ||
|
||
return $list; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.