Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,41 +12,65 @@
|
||||
namespace IPS\cms\modules\admin\pages;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\cms\Media as MediaClass;
|
||||
use IPS\cms\Media\Folder;
|
||||
use IPS\cms\Pages\Page;
|
||||
use IPS\cms\Templates;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\File;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\Helpers\Form\Upload;
|
||||
use IPS\Helpers\Tree\Tree;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Controller;
|
||||
use IPS\Output;
|
||||
use IPS\Output\Plugin\Filesize;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function is_array;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* media
|
||||
*/
|
||||
class _media extends \IPS\Node\Controller
|
||||
class media extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* Node Class
|
||||
*/
|
||||
protected $nodeClass = '\IPS\cms\Media\Folder';
|
||||
protected string $nodeClass = '\IPS\cms\Media\Folder';
|
||||
|
||||
/**
|
||||
* @var string[] Additional allowed FileTypes for the media field.
|
||||
*/
|
||||
public static $additionalAllowedMediaFileTypes = array( 'pdf', 'svg' );
|
||||
|
||||
public static array $additionalAllowedMediaFileTypes = array( 'pdf', 'svg', 'woff', 'woff2', 'ttf', 'eot' );
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'media_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'media_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -55,24 +79,24 @@ class _media extends \IPS\Node\Controller
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function _getRootButtons()
|
||||
public function _getRootButtons(): array
|
||||
{
|
||||
$buttons = array();
|
||||
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'cms', 'pages', 'page_add' ) )
|
||||
if ( Member::loggedIn()->hasAcpRestriction( 'cms', 'pages', 'page_add' ) )
|
||||
{
|
||||
$buttons['add_folder'] = array(
|
||||
'icon' => 'folder-open',
|
||||
'title' => 'cms_add_media_folder',
|
||||
'link' => \IPS\Http\Url::internal( 'app=cms&module=pages&controller=media&do=form' ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('cms_add_media_folder') )
|
||||
'link' => Url::internal( 'app=cms&module=pages&controller=media&do=form' ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('cms_add_media_folder') )
|
||||
);
|
||||
|
||||
$buttons['add_page'] = array(
|
||||
'icon' => 'plus-circle',
|
||||
'title' => 'cms_add_media',
|
||||
'link' => \IPS\Http\Url::internal( 'app=cms&module=pages&controller=media&subnode=1&do=form' ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('cms_add_media') )
|
||||
'link' => Url::internal( 'app=cms&module=pages&controller=media&subnode=1&do=form' ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => Member::loggedIn()->language()->addToStack('cms_add_media') )
|
||||
);
|
||||
}
|
||||
|
||||
@@ -84,19 +108,19 @@ class _media extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteByFileIds()
|
||||
public function deleteByFileIds() : void
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
if ( isset( \IPS\Request::i()->fileIds ) )
|
||||
if ( isset( Request::i()->fileIds ) )
|
||||
{
|
||||
$ids = \IPS\Request::i()->fileIds;
|
||||
$ids = Request::i()->fileIds;
|
||||
|
||||
if ( ! \is_array( $ids ) )
|
||||
if ( ! is_array( $ids ) )
|
||||
{
|
||||
$try = json_decode( $ids, TRUE );
|
||||
|
||||
if ( ! \is_array( $try ) )
|
||||
if ( ! is_array( $try ) )
|
||||
{
|
||||
$ids = array( $ids );
|
||||
}
|
||||
@@ -106,11 +130,11 @@ class _media extends \IPS\Node\Controller
|
||||
}
|
||||
}
|
||||
|
||||
if ( \count( $ids ) )
|
||||
if ( count( $ids ) )
|
||||
{
|
||||
\IPS\cms\Media::deleteByFileIds( $ids );
|
||||
MediaClass::deleteByFileIds( $ids );
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__cms_deleted_media', array( \count( $ids ) => FALSE ) );
|
||||
Session::i()->log( 'acplogs__cms_deleted_media', array( count( $ids ) => FALSE ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,104 +142,97 @@ class _media extends \IPS\Node\Controller
|
||||
/**
|
||||
* Show the pages tree
|
||||
*
|
||||
* @return string
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
if ( \IPS\Theme::designersModeEnabled() )
|
||||
$url = Url::internal( "app=cms&module=pages&controller=media" );
|
||||
|
||||
/* Display the table */
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('menu__cms_pages_media');
|
||||
$output = new Tree( $url, 'menu__cms_pages_media',
|
||||
/* Get Roots */
|
||||
function () use ( $url )
|
||||
{
|
||||
$data = media::getRowsForTree( 0 );
|
||||
$rows = array();
|
||||
|
||||
foreach ( $data as $id => $row )
|
||||
{
|
||||
if( ( Request::i()->isAjax() && $row instanceof MediaClass ) || !Request::i()->isAjax() )
|
||||
{
|
||||
$rows[ $id ] = ( $row instanceof MediaClass) ? media::getItemRow( $row, $url ) : media::getFolderRow( $row, $url );
|
||||
}
|
||||
}
|
||||
|
||||
if( Request::i()->isAjax() )
|
||||
{
|
||||
Output::i()->sendOutput( json_encode( $rows ), 200, 'application/json' );
|
||||
}
|
||||
|
||||
return $data;
|
||||
},
|
||||
/* Get Row */
|
||||
function ( $id, $root ) use ( $url )
|
||||
{
|
||||
if ( $root )
|
||||
{
|
||||
return media::getFolderRow( Folder::load( $id ), $url );
|
||||
}
|
||||
else
|
||||
{
|
||||
return media::getItemRow( MediaClass::load( $id ), $url );
|
||||
}
|
||||
},
|
||||
/* Get Row Parent ID*/
|
||||
function ()
|
||||
{
|
||||
return NULL;
|
||||
},
|
||||
/* Get Children */
|
||||
function ( $id ) use ( $url )
|
||||
{
|
||||
$rows = array();
|
||||
$data = media::getRowsForTree( $id );
|
||||
|
||||
if ( ! isset( Request::i()->subnode ) )
|
||||
{
|
||||
foreach ( $data as $id => $row )
|
||||
{
|
||||
if( Request::i()->get == 'folders' && !( $row instanceof MediaClass ) )
|
||||
{
|
||||
$rows[ $id ] = media::getFolderRow( $row, $url );
|
||||
}
|
||||
elseif ( Request::i()->get == 'files' && $row instanceof MediaClass )
|
||||
{
|
||||
$rows[ $id ] = media::getItemRow( $row, $url );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if( Request::i()->isAjax() ){
|
||||
Output::i()->sendOutput( json_encode( $rows ), 200, 'application/json' );
|
||||
}
|
||||
|
||||
return $rows;
|
||||
},
|
||||
array( $this, '_getRootButtons' ),
|
||||
TRUE,
|
||||
FALSE,
|
||||
FALSE
|
||||
);
|
||||
|
||||
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js( 'admin_media.js', 'cms' ) );
|
||||
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'media/media.css', 'cms', 'admin' ) );
|
||||
|
||||
if( Request::i()->isAjax() )
|
||||
{
|
||||
$link = \IPS\Http\Url::internal( 'app=core&module=customization&controller=themes&do=designersmode' );
|
||||
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->message( \IPS\Member::loggedIn()->language()->addToStack( 'cms_media_designer_mode_warning', FALSE, array( 'sprintf' => array( $link ) ) ), 'information', NULL, FALSE );
|
||||
Output::i()->sendOutput( $output );
|
||||
}
|
||||
else
|
||||
{
|
||||
$url = \IPS\Http\Url::internal( "app=cms&module=pages&controller=media" );
|
||||
|
||||
/* Display the table */
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__cms_pages_media');
|
||||
$output = new \IPS\Helpers\Tree\Tree( $url, 'menu__cms_pages_media',
|
||||
/* Get Roots */
|
||||
function () use ( $url )
|
||||
{
|
||||
$data = \IPS\cms\modules\admin\pages\media::getRowsForTree( 0 );
|
||||
$rows = array();
|
||||
|
||||
foreach ( $data as $id => $row )
|
||||
{
|
||||
if( ( \IPS\Request::i()->isAjax() && $row instanceof \IPS\cms\Media ) || !\IPS\Request::i()->isAjax() )
|
||||
{
|
||||
$rows[ $id ] = ( $row instanceof \IPS\cms\Media) ? \IPS\cms\modules\admin\pages\media::getItemRow( $row, $url ) : \IPS\cms\modules\admin\pages\media::getFolderRow( $row, $url );
|
||||
}
|
||||
}
|
||||
|
||||
if( \IPS\Request::i()->isAjax() ){
|
||||
\IPS\Output::i()->sendOutput( json_encode( $rows ), 200, 'application/json' );
|
||||
}
|
||||
|
||||
return $data;
|
||||
},
|
||||
/* Get Row */
|
||||
function ( $id, $root ) use ( $url )
|
||||
{
|
||||
if ( $root )
|
||||
{
|
||||
return \IPS\cms\modules\admin\pages\media::getFolderRow( \IPS\cms\Media\Folder::load( $id ), $url );
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\cms\modules\admin\pages\media::getItemRow( \IPS\cms\Media::load( $id ), $url );
|
||||
}
|
||||
},
|
||||
/* Get Row Parent ID*/
|
||||
function ()
|
||||
{
|
||||
return NULL;
|
||||
},
|
||||
/* Get Children */
|
||||
function ( $id ) use ( $url )
|
||||
{
|
||||
$rows = array();
|
||||
$data = \IPS\cms\modules\admin\pages\media::getRowsForTree( $id );
|
||||
|
||||
if ( ! isset( \IPS\Request::i()->subnode ) )
|
||||
{
|
||||
foreach ( $data as $id => $row )
|
||||
{
|
||||
if( \IPS\Request::i()->get == 'folders' && !( $row instanceof \IPS\cms\Media ) )
|
||||
{
|
||||
$rows[ $id ] = \IPS\cms\modules\admin\pages\media::getFolderRow( $row, $url );
|
||||
}
|
||||
elseif ( \IPS\Request::i()->get == 'files' && $row instanceof \IPS\cms\Media )
|
||||
{
|
||||
$rows[ $id ] = \IPS\cms\modules\admin\pages\media::getItemRow( $row, $url );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if( \IPS\Request::i()->isAjax() ){
|
||||
\IPS\Output::i()->sendOutput( json_encode( $rows ), 200, 'application/json' );
|
||||
}
|
||||
|
||||
return $rows;
|
||||
},
|
||||
array( $this, '_getRootButtons' ),
|
||||
TRUE,
|
||||
FALSE,
|
||||
FALSE
|
||||
);
|
||||
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_media.js', 'cms' ) );
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'media/media.css', 'cms', 'admin' ) );
|
||||
|
||||
if( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( $output, 200, 'text/html' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'media', 'cms', 'admin' )->media( $output );
|
||||
}
|
||||
Output::i()->output = Theme::i()->getTemplate( 'media', 'cms', 'admin' )->media( $output );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,26 +241,26 @@ class _media extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function replace()
|
||||
public function replace() : void
|
||||
{
|
||||
if( !isset( \IPS\Request::i()->id ) OR !\IPS\Request::i()->id )
|
||||
if( !isset( Request::i()->id ) OR !Request::i()->id )
|
||||
{
|
||||
\IPS\Output::i()->error( 'missing_media_file', '3T334/2', 404, '' );
|
||||
Output::i()->error( 'missing_media_file', '3T334/2', 404, '' );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$media = \IPS\cms\Media::load( \IPS\Request::i()->id );
|
||||
$media = MediaClass::load( Request::i()->id );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'missing_media_file', '3T334/3', 404, '' );
|
||||
Output::i()->error( 'missing_media_file', '3T334/3', 404, '' );
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'form', 'upload' );
|
||||
$form->class = 'ipsForm_vertical ipsForm_noLabels';
|
||||
$form = new Form( 'form', 'upload' );
|
||||
$form->class = 'ipsForm--vertical ipsForm--replace-file ipsForm_noLabels';
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Upload( 'media_filename', NULL, FALSE, array( 'allowedFileTypes' => array_merge( \IPS\File::$safeFileExtensions, static::$additionalAllowedMediaFileTypes ), 'obscure' => FALSE, 'storageExtension' => 'cms_Media', 'storageContainer' => 'pages_media', 'multiple' => FALSE, 'minimize' => FALSE ), NULL, NULL, NULL, 'media_filename' ) );
|
||||
$form->add( new Upload( 'media_filename', NULL, FALSE, array( 'allowedFileTypes' => array_merge( File::$safeFileExtensions, static::$additionalAllowedMediaFileTypes ), 'obscure' => FALSE, 'storageExtension' => 'cms_Media', 'storageContainer' => 'pages_media', 'multiple' => FALSE, 'minimize' => FALSE ), NULL, NULL, NULL, 'media_filename' ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
@@ -253,7 +270,7 @@ class _media extends \IPS\Node\Controller
|
||||
/* If we have the same extension, we will just retain the same filename */
|
||||
if( $existingFileExtension == $newFileExtension )
|
||||
{
|
||||
$media->file_object = (string) \IPS\File::create( 'cms_Media', $media->filename_stored, $values['media_filename']->contents(), 'pages_media', TRUE, NULL, FALSE );
|
||||
$media->file_object = (string) File::create( 'cms_Media', $media->filename_stored, $values['media_filename']->contents(), 'pages_media', TRUE, NULL, FALSE );
|
||||
}
|
||||
/* Otherwise we need to update the rest of the file info too */
|
||||
else
|
||||
@@ -261,10 +278,10 @@ class _media extends \IPS\Node\Controller
|
||||
$media->is_image = $values['media_filename']->isImage();
|
||||
$media->filename = $values['media_filename']->originalFilename;
|
||||
$media->filename_stored = $media->parent . '_' . $media->filename;
|
||||
$media->file_object = (string) \IPS\File::create( 'cms_Media', $media->filename_stored, $values['media_filename']->contents(), 'pages_media', TRUE, NULL, FALSE );
|
||||
$media->file_object = (string) File::create( 'cms_Media', $media->filename_stored, $values['media_filename']->contents(), 'pages_media', TRUE, NULL, FALSE );
|
||||
}
|
||||
|
||||
$media->setFullPath( ( $media->parent ? \IPS\cms\Media\Folder::load( $media->parent )->path : '' ) );
|
||||
$media->setFullPath( ( $media->parent ? Folder::load( $media->parent )->path : '' ) );
|
||||
$media->save();
|
||||
|
||||
/* Remove the original as we created a copy with a slightly altered filename */
|
||||
@@ -272,37 +289,37 @@ class _media extends \IPS\Node\Controller
|
||||
{
|
||||
$values['media_filename']->delete();
|
||||
}
|
||||
catch( \Exception $ex ) { }
|
||||
catch( Exception $ex ) { }
|
||||
|
||||
/* Wipe out included JS just in case we're using this media thing */
|
||||
\IPS\cms\Templates::deleteCompiledFiles();
|
||||
\IPS\cms\Pages\Page::deleteCachedIncludes();
|
||||
Templates::deleteCompiledFiles();
|
||||
Page::deleteCachedIncludes();
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__cms_replaced_media', array( $values['media_filename']->originalFilename => FALSE ) );
|
||||
Session::i()->log( 'acplogs__cms_replaced_media', array( $values['media_filename']->originalFilename => FALSE ) );
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
if ( Request::i()->isAjax() )
|
||||
{
|
||||
$url = \IPS\Http\Url::internal( "app=cms&module=pages&controller=media" );
|
||||
$data = \IPS\cms\modules\admin\pages\media::getRowsForTree( $media->parent );
|
||||
$url = Url::internal( "app=cms&module=pages&controller=media" );
|
||||
$data = media::getRowsForTree( $media->parent );
|
||||
$rows = array();
|
||||
|
||||
foreach ( $data as $id => $row )
|
||||
{
|
||||
if ( $row instanceof \IPS\cms\Media )
|
||||
if ( $row instanceof MediaClass )
|
||||
{
|
||||
$rows[ $id ] = \IPS\cms\modules\admin\pages\media::getItemRow( $row, $url );
|
||||
$rows[ $id ] = media::getItemRow( $row, $url );
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->sendOutput( json_encode( array( 'fileID' => $media->id, 'folderID' => $media->parent, 'rows' => $rows ) ), 200, 'application/json' );
|
||||
Output::i()->sendOutput( json_encode( array( 'fileID' => $media->id, 'folderID' => $media->parent, 'rows' => $rows ) ), 200, 'application/json' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=pages&controller=media' ) );
|
||||
Output::i()->redirect( Url::internal( 'app=cms&module=pages&controller=media' ) );
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core', 'admin' )->block( 'upload', $form, FALSE );
|
||||
Output::i()->output = Theme::i()->getTemplate( 'global', 'core', 'admin' )->block( 'upload', $form, FALSE );
|
||||
}
|
||||
|
||||
|
||||
@@ -311,23 +328,23 @@ class _media extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function upload()
|
||||
public function upload() : void
|
||||
{
|
||||
$form = new \IPS\Helpers\Form( 'form', 'upload' );
|
||||
$form->class = 'ipsForm_vertical ipsForm_noLabels';
|
||||
$form = new Form( 'form', 'upload' );
|
||||
$form->class = 'ipsForm--vertical ipsForm--upload-items ipsForm_noLabels';
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Upload( 'media_filename', NULL, FALSE, array( 'allowedFileTypes' => array_merge( \IPS\File::$safeFileExtensions, static::$additionalAllowedMediaFileTypes ), 'obscure' => FALSE, 'storageExtension' => 'cms_Media', 'storageContainer' => 'pages_media', 'multiple' => true, 'minimize' => FALSE ), NULL, NULL, NULL, 'media_filename' ) );
|
||||
$form->add( new Upload( 'media_filename', NULL, FALSE, array( 'allowedFileTypes' => array_merge( File::$safeFileExtensions, static::$additionalAllowedMediaFileTypes ), 'obscure' => FALSE, 'storageExtension' => 'cms_Media', 'storageContainer' => 'pages_media', 'multiple' => true, 'minimize' => FALSE ), NULL, NULL, NULL, 'media_filename' ) );
|
||||
|
||||
if ( ! isset( \IPS\Request::i()->media_parent ) and ! \IPS\Request::i()->media_parent )
|
||||
if ( ! isset( Request::i()->media_parent ) and ! Request::i()->media_parent )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'media_parent', 0, FALSE, array(
|
||||
$form->add( new Node( 'media_parent', 0, FALSE, array(
|
||||
'class' => '\IPS\cms\Media\Folder',
|
||||
'zeroVal' => 'node_no_parent'
|
||||
) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$form->hiddenValues['media_parent_inline'] = \IPS\Request::i()->media_parent;
|
||||
$form->hiddenValues['media_parent_inline'] = Request::i()->media_parent;
|
||||
}
|
||||
|
||||
if ( $values = $form->values() )
|
||||
@@ -358,7 +375,7 @@ class _media extends \IPS\Node\Controller
|
||||
$filename = mb_substr( $filename, mb_strlen( $prefix ) );
|
||||
}
|
||||
|
||||
$new = new \IPS\cms\Media;
|
||||
$new = new MediaClass;
|
||||
$new->filename = $filename;
|
||||
$new->filename_stored = $parent . '_' . $filename;
|
||||
$new->is_image = $media->isImage();
|
||||
@@ -367,41 +384,41 @@ class _media extends \IPS\Node\Controller
|
||||
$new->file_object = (string) $media;
|
||||
$new->save();
|
||||
|
||||
$new->setFullPath( ( $parent ? \IPS\cms\Media\Folder::load( $parent )->path : '' ) );
|
||||
$new->setFullPath( ( $parent ? Folder::load( $parent )->path : '' ) );
|
||||
$new->save();
|
||||
|
||||
$count++;
|
||||
}
|
||||
|
||||
/* Wipe out included JS just in case we're using this media thing */
|
||||
\IPS\cms\Templates::deleteCompiledFiles();
|
||||
\IPS\cms\Pages\Page::deleteCachedIncludes();
|
||||
Templates::deleteCompiledFiles();
|
||||
Page::deleteCachedIncludes();
|
||||
|
||||
\IPS\Session::i()->log( 'acplogs__cms_uploaded_media', array( $count => FALSE ) );
|
||||
Session::i()->log( 'acplogs__cms_uploaded_media', array( $count => FALSE ) );
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
if ( Request::i()->isAjax() )
|
||||
{
|
||||
$url = \IPS\Http\Url::internal( "app=cms&module=pages&controller=media" );
|
||||
$data = \IPS\cms\modules\admin\pages\media::getRowsForTree( $parent );
|
||||
$url = Url::internal( "app=cms&module=pages&controller=media" );
|
||||
$data = media::getRowsForTree( $parent );
|
||||
$rows = array();
|
||||
|
||||
foreach ( $data as $id => $row )
|
||||
{
|
||||
if ( $row instanceof \IPS\cms\Media )
|
||||
if ( $row instanceof MediaClass )
|
||||
{
|
||||
$rows[ $id ] = \IPS\cms\modules\admin\pages\media::getItemRow( $row, $url );
|
||||
$rows[ $id ] = media::getItemRow( $row, $url );
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->sendOutput( json_encode( array( 'count' => $count, 'folderID' => $parent, 'rows' => $rows ) ), 200, 'application/json' );
|
||||
Output::i()->sendOutput( json_encode( array( 'count' => $count, 'folderID' => $parent, 'rows' => $rows ) ), 200, 'application/json' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=pages&controller=media' ) );
|
||||
Output::i()->redirect( Url::internal( 'app=cms&module=pages&controller=media' ) );
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core', 'admin' )->block( 'upload', $form, FALSE );
|
||||
Output::i()->output = Theme::i()->getTemplate( 'global', 'core', 'admin' )->block( 'upload', $form, FALSE );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -409,13 +426,13 @@ class _media extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function search()
|
||||
protected function search() : void
|
||||
{
|
||||
$rows = array();
|
||||
$url = \IPS\Http\Url::internal( "app=cms&module=pages&controller=media" );
|
||||
$url = Url::internal( "app=cms&module=pages&controller=media" );
|
||||
|
||||
/* Get results */
|
||||
$items = \IPS\cms\Media::search( 'media_filename', \IPS\Request::i()->input, 'media_filename' );
|
||||
$items = MediaClass::search( 'media_filename', Request::i()->input, 'media_filename' );
|
||||
|
||||
/* Convert to HTML */
|
||||
foreach ( $items as $id => $result )
|
||||
@@ -423,13 +440,13 @@ class _media extends \IPS\Node\Controller
|
||||
$rows[ $id ] = $this->getItemRow( $result, $url );
|
||||
}
|
||||
|
||||
if( \IPS\Request::i()->isAjax() )
|
||||
if( Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->sendOutput( json_encode( $rows ), 200, 'application/json' );
|
||||
Output::i()->sendOutput( json_encode( $rows ), 200, 'application/json' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'trees', 'core' )->rows( $rows, '' );
|
||||
Output::i()->output = Theme::i()->getTemplate( 'trees', 'core' )->rows( $rows, '' );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -438,21 +455,21 @@ class _media extends \IPS\Node\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function getFileInfo()
|
||||
protected function getFileInfo() : void
|
||||
{
|
||||
try
|
||||
{
|
||||
$row = \IPS\cms\Media::load( \IPS\Request::i()->id );
|
||||
$fileObject = \IPS\File::get( 'cms_Media', $row->file_object );
|
||||
$row = MediaClass::load( Request::i()->id );
|
||||
$fileObject = File::get( 'cms_Media', $row->file_object );
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
catch( OutOfRangeException $ex )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* Make a human-readable size */
|
||||
$filesize = \IPS\Output\Plugin\Filesize::humanReadableFilesize( $fileObject->filesize() );
|
||||
\IPS\Member::loggedIn()->language()->parseOutputForDisplay( $filesize );
|
||||
$filesize = Filesize::humanReadableFilesize( $fileObject->filesize() );
|
||||
Member::loggedIn()->language()->parseOutputForDisplay( $filesize );
|
||||
|
||||
$output = array(
|
||||
'fileSize' => $filesize,
|
||||
@@ -466,60 +483,61 @@ class _media extends \IPS\Node\Controller
|
||||
$output['dimensions'] = $dimensions[0] . ' x ' . $dimensions[1];
|
||||
}
|
||||
|
||||
\IPS\Output::i()->sendOutput( json_encode( $output ), 200, 'application/json' );
|
||||
Output::i()->sendOutput( json_encode( $output ), 200, 'application/json' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return HTML for a page row
|
||||
*
|
||||
* @param array $item Row data
|
||||
* @param object $url \IPS\Http\Url object
|
||||
* @param MediaClass $item Row data
|
||||
* @param object $url \IPS\Http\Url object
|
||||
* @return string HTML
|
||||
*/
|
||||
public static function getItemRow( $item, $url )
|
||||
public static function getItemRow( MediaClass $item, object $url ): string
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'media', 'cms', 'admin' )->fileListing( $url, $item );
|
||||
return Theme::i()->getTemplate( 'media', 'cms', 'admin' )->fileListing( $url, $item );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return HTML for a folder row
|
||||
*
|
||||
* @param array $folder Row data
|
||||
* @param object $url \IPS\Http\Url object
|
||||
* @param MediaClass|Folder $folder Row data
|
||||
* @param Url $url \IPS\Http\Url object
|
||||
* @return string HTML
|
||||
*/
|
||||
public static function getFolderRow( $folder, $url )
|
||||
public static function getFolderRow( MediaClass|Folder $folder, Url $url ): string
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'media', 'cms', 'admin' )->folderRow( $url, $folder );
|
||||
return Theme::i()->getTemplate( 'media', 'cms', 'admin' )->folderRow( $url, $folder );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch rows of folders/pages
|
||||
*
|
||||
* @param int $folderId Parent ID to fetch from
|
||||
* @param int $folderId Parent ID to fetch from
|
||||
* @return array
|
||||
*/
|
||||
public static function getRowsForTree( $folderId=0 )
|
||||
public static function getRowsForTree( int $folderId=0 ) : array
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( $folderId === 0 )
|
||||
{
|
||||
$folders = \IPS\cms\Media\Folder::roots();
|
||||
$folders = Folder::roots();
|
||||
}
|
||||
else
|
||||
{
|
||||
$folders = \IPS\cms\Media\Folder::load( $folderId )->children( NULL, NULL, FALSE );
|
||||
$folders = Folder::load( $folderId )->children( NULL, NULL, FALSE );
|
||||
}
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
catch( OutOfRangeException $ex )
|
||||
{
|
||||
$folders = array();
|
||||
}
|
||||
|
||||
$media = \IPS\cms\Media::getChildren( $folderId );
|
||||
$media = MediaClass::getChildren( $folderId );
|
||||
|
||||
return \IPS\cms\Media\Folder::munge( $folders, $media );
|
||||
return Folder::munge( $folders, $media );
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user