Version 4.0.13.1
This commit is contained in:
1 parent
f9e857d255
commit
c6a86f0d9b
7517 files changed
+597400
-668041
No files matched your search
@@ -0,0 +1,378 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Folder Model
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @since 15 Jan 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\cms\Pages;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Folder Model
|
||||
*/
|
||||
class _Folder extends \IPS\Node\Model
|
||||
{
|
||||
/**
|
||||
* Munge different record types
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function munge()
|
||||
{
|
||||
$rows = array();
|
||||
$args = func_get_args();
|
||||
|
||||
foreach( $args as $arg )
|
||||
{
|
||||
foreach( $arg as $id => $obj )
|
||||
{
|
||||
$rows[ $obj->getSortableName() . '_' . $obj::$databaseTable . '_' . $obj->id ] = $obj;
|
||||
}
|
||||
}
|
||||
|
||||
ksort( $rows );
|
||||
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'cms_folders';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'folder_';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = 'id';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database ID Fields
|
||||
*/
|
||||
protected static $databaseIdFields = array('folder_name', 'folder_path');
|
||||
|
||||
/**
|
||||
* @brief [Node] Parent ID Database Column
|
||||
*/
|
||||
public static $databaseColumnParent = 'parent_id';
|
||||
|
||||
/**
|
||||
* @brief [Node] Parent ID Root Value
|
||||
* @note This normally doesn't need changing though some legacy areas use -1 to indicate a root node
|
||||
*/
|
||||
public static $databaseColumnParentRootValue = 0;
|
||||
|
||||
/**
|
||||
* @brief [Node] Order Database Column
|
||||
*/
|
||||
public static $databaseColumnOrder = 'path';
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'folder';
|
||||
|
||||
/**
|
||||
* @brief [Node] Subnode class
|
||||
*/
|
||||
public static $subnodeClass = 'IPS\cms\Pages\Page';
|
||||
|
||||
/**
|
||||
* @brief [Node] Show forms modally?
|
||||
*/
|
||||
public static $modalForms = TRUE;
|
||||
|
||||
protected static $restrictions = array(
|
||||
'app' => 'cms',
|
||||
'module' => 'pages',
|
||||
'all' => 'page_manage',
|
||||
'prefix' => 'page_'
|
||||
);
|
||||
|
||||
/**
|
||||
* [Node] Get Title
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
protected function get__title()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sortable name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSortableName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Get buttons to display in tree
|
||||
* Example code explains return value
|
||||
* @endcode
|
||||
* @param string $url Base URL
|
||||
* @param bool $subnode Is this a subnode?
|
||||
* @return array
|
||||
*/
|
||||
public function getButtons( $url, $subnode=FALSE )
|
||||
{
|
||||
$buttons = parent::getButtons( $url, $subnode );
|
||||
$return = array();
|
||||
|
||||
if ( isset( $buttons['copy'] ) )
|
||||
{
|
||||
unset( $buttons['copy'] );
|
||||
}
|
||||
|
||||
if ( isset( $buttons['add'] ) )
|
||||
{
|
||||
$buttons['add']['icon'] = 'folder-open';
|
||||
$buttons['add']['title'] = 'content_add_folder';
|
||||
$buttons['add']['data'] = array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('content_add_folder') );
|
||||
$buttons['add']['link'] = $url->setQueryString( array( 'subnode' => 0, 'do' => 'form', 'parent' => $this->_id ) );
|
||||
|
||||
$buttons['add_page'] = array(
|
||||
'icon' => 'plus-circle',
|
||||
'title' => 'content_add_page',
|
||||
'link' => $url->setQueryString( array( 'subnode' => 1, 'do' => 'add', 'parent' => $this->_id ) ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('content_add_page') )
|
||||
);
|
||||
}
|
||||
|
||||
/* Re-arrange */
|
||||
if ( isset( $buttons['edit'] ) )
|
||||
{
|
||||
$return['edit'] = $buttons['edit'];
|
||||
}
|
||||
|
||||
if ( isset( $buttons['add_page'] ) )
|
||||
{
|
||||
$return['add_page'] = $buttons['add_page'];
|
||||
}
|
||||
|
||||
if ( isset( $buttons['add'] ) )
|
||||
{
|
||||
$return['add'] = $buttons['add'];
|
||||
}
|
||||
|
||||
if ( isset( $buttons['delete'] ) )
|
||||
{
|
||||
$return['delete'] = $buttons['delete'];
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Add/Edit Form
|
||||
*
|
||||
* @param \IPS\Helpers\Form $form The form
|
||||
* @return void
|
||||
*/
|
||||
public function form( &$form )
|
||||
{
|
||||
/* Build form */
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'folder_name', $this->id ? $this->name : '', TRUE, array( 'maxLength' => 64 ), function( $val )
|
||||
{
|
||||
try
|
||||
{
|
||||
$test = \IPS\cms\Pages\Folder::load( \IPS\Http\Url::seoTitle( $val ), 'folder_name' );
|
||||
|
||||
if ( ! empty( \IPS\Request::i()->id ) and $test->id != \IPS\Request::i()->id )
|
||||
{
|
||||
throw new \InvalidArgumentException('content_folder_name_in_use');
|
||||
}
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
/* If we hit here, we don't have an existing folder by that name so check for a collision */
|
||||
if ( \IPS\Request::i()->folder_parent_id == 0 AND \IPS\cms\Pages\Page::isFurlCollision( \IPS\Http\Url::seoTitle( $val ) ) )
|
||||
{
|
||||
throw new \InvalidArgumentException('content_folder_name_furl_collision');
|
||||
}
|
||||
}
|
||||
} ) );
|
||||
|
||||
$class = get_called_class();
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'folder_parent_id', $this->parent_id ? $this->parent_id : 0, FALSE, array(
|
||||
'class' => '\IPS\cms\Pages\Folder',
|
||||
'zeroVal' => 'node_no_parent',
|
||||
'permissionCheck' => function( $node ) use ( $class )
|
||||
{
|
||||
if( isset( $class::$subnodeClass ) AND $class::$subnodeClass AND $node instanceof $class::$subnodeClass )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return !isset( \IPS\Request::i()->id ) or ( $node->id != \IPS\Request::i()->id and !$node->isChildOf( $node::load( \IPS\Request::i()->id ) ) );
|
||||
}
|
||||
) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Format form values from add/edit form for save
|
||||
*
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
public function formatFormValues( $values )
|
||||
{
|
||||
$isNew = $this->_new;
|
||||
|
||||
if ( !$this->id )
|
||||
{
|
||||
$this->save();
|
||||
}
|
||||
|
||||
$this->origParentId = $this->parent_id;
|
||||
$this->origName = $this->name;
|
||||
|
||||
if ( isset( $values['folder_parent_id'] ) AND ( ! empty( $values['folder_parent_id'] ) OR $values['folder_parent_id'] === 0 ) )
|
||||
{
|
||||
$values['parent_id'] = ( $values['folder_parent_id'] === 0 ) ? 0 : $values['folder_parent_id']->id;
|
||||
unset( $values['folder_parent_id'] );
|
||||
}
|
||||
|
||||
if( isset( $values['folder_name'] ) )
|
||||
{
|
||||
$values['name'] = \IPS\Http\Url::seoTitle( $values['folder_name'] );
|
||||
unset( $values['folder_name'] );
|
||||
}
|
||||
|
||||
if ( ! $isNew and ( $this->parent_id !== $values['parent_id'] or $this->name !== $values['name'] ) )
|
||||
{
|
||||
$this->storeUrl();
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Original parent ID
|
||||
*/
|
||||
protected $origParentId;
|
||||
|
||||
/**
|
||||
* @brief Original Name
|
||||
*/
|
||||
protected $origName;
|
||||
|
||||
/**
|
||||
* [Node] Perform actions after saving the form
|
||||
*
|
||||
* @param array $values Values from the form
|
||||
* @return void
|
||||
*/
|
||||
public function postSaveForm( $values )
|
||||
{
|
||||
if ( $this->origParentId !== $values['parent_id'] OR $this->origName !== $values['name'] )
|
||||
{
|
||||
$this->resetPath( true );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the URL so when its changed, the old can 301 to the new location
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function storeUrl()
|
||||
{
|
||||
\IPS\Db::i()->insert( 'cms_url_store', array(
|
||||
'store_path' => $this->path,
|
||||
'store_current_id' => $this->_id,
|
||||
'store_type' => 'folder'
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a folder
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$this->last_modified = time();
|
||||
|
||||
parent::save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the stored path
|
||||
*
|
||||
* @param boolean $recursivelyCheck Recursively reset up and down the tree
|
||||
* @return void
|
||||
*/
|
||||
public function resetPath( $recursivelyCheck=true )
|
||||
{
|
||||
$path = array();
|
||||
|
||||
foreach( $this->parents() as $obj )
|
||||
{
|
||||
$path[] = $obj->name;
|
||||
}
|
||||
|
||||
$this->path = ( count( $path ) ) ? implode( '/', $path ) . '/' . $this->name : $this->name;
|
||||
|
||||
/* Save path update */
|
||||
parent::save();
|
||||
|
||||
/* Update pages */
|
||||
\IPS\cms\Pages\Page::resetPath( $this->id );
|
||||
|
||||
if ( $recursivelyCheck === true )
|
||||
{
|
||||
/* Fix children */
|
||||
foreach( $this->children( NULL, NULL, FALSE ) as $child )
|
||||
{
|
||||
$child->resetPath( false );
|
||||
$child->_recursivelyResetChildPaths();
|
||||
}
|
||||
|
||||
/* Fix parents */
|
||||
foreach( $this->parents() as $parent )
|
||||
{
|
||||
$parent->resetPath( false );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recurse through the node tree to reset kids
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _recursivelyResetChildPaths()
|
||||
{
|
||||
foreach( $this->children( NULL, NULL, FALSE ) as $child )
|
||||
{
|
||||
$child->resetPath( false );
|
||||
$child->_recursivelyResetChildPaths();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,434 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Menu Model
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @since 15 Sept 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\cms\Pages;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Menu Model
|
||||
*/
|
||||
class _Menu extends \IPS\Node\Model
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'cms_page_menu';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'menu_';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = 'id';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database ID Fields
|
||||
*/
|
||||
protected static $databaseIdFields = array();
|
||||
|
||||
/**
|
||||
* @brief [Node] Parent ID Database Column
|
||||
*/
|
||||
public static $databaseColumnParent = 'parent_id';
|
||||
|
||||
/**
|
||||
* @brief [Node] Parent ID Root Value
|
||||
* @note This normally doesn't need changing though some legacy areas use -1 to indicate a root node
|
||||
*/
|
||||
public static $databaseColumnParentRootValue = 0;
|
||||
|
||||
/**
|
||||
* @brief [Node] Order Database Column
|
||||
*/
|
||||
public static $databaseColumnOrder = 'position';
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'cms_menu';
|
||||
|
||||
/**
|
||||
* @brief [Node] Show forms modally?
|
||||
*/
|
||||
public static $modalForms = TRUE;
|
||||
|
||||
/**
|
||||
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
|
||||
*/
|
||||
public static $titleLangPrefix = 'cms_menu_title_';
|
||||
|
||||
/**
|
||||
* @brief [Node] ACP Restrictions
|
||||
* @code
|
||||
array(
|
||||
'app' => 'core', // The application key which holds the restrictrions
|
||||
'module' => 'foo', // The module key which holds the restrictions
|
||||
'map' => array( // [Optional] The key for each restriction - can alternatively use "prefix"
|
||||
'add' => 'foo_add',
|
||||
'edit' => 'foo_edit',
|
||||
'permissions' => 'foo_perms',
|
||||
'delete' => 'foo_delete'
|
||||
),
|
||||
'all' => 'foo_manage', // [Optional] The key to use for any restriction not provided in the map (only needed if not providing all 4)
|
||||
'prefix' => 'foo_', // [Optional] Rather than specifying each key in the map, you can specify a prefix, and it will automatically look for restrictions with the key "[prefix]_add/edit/permissions/delete"
|
||||
* @endcode
|
||||
*/
|
||||
protected static $restrictions = array(
|
||||
'app' => 'cms',
|
||||
'module' => 'pages',
|
||||
'all' => 'page_manage',
|
||||
'prefix' => 'page_'
|
||||
);
|
||||
|
||||
/**
|
||||
* Form elements
|
||||
*
|
||||
* @param \IPS\cms\Pages\Menu|null $node Menu item
|
||||
* @return array
|
||||
*/
|
||||
public static function formElements( $node=NULL, $forceType=NULL )
|
||||
{
|
||||
$form = array();
|
||||
|
||||
if ( $forceType === NULL )
|
||||
{
|
||||
$form['menu_type'] = new \IPS\Helpers\Form\Select( 'menu_type', ( $node !== NULL ? $node->type : 'page' ), TRUE, array(
|
||||
'options' => array(
|
||||
'page' => 'cms_menu_form_type_page',
|
||||
'url' => 'cms_menu_form_type_url',
|
||||
'folder' => 'cms_menu_form_type_folder',
|
||||
#'separator' => 'cms_menu_form_type_separator'
|
||||
),
|
||||
'toggles' => array(
|
||||
'page' => array( 'menu_content_page', 'menu_title_page', 'menu_permission_from_page'),
|
||||
'url' => array( 'menu_content_url', 'menu_title_url', 'menu_permission' ),
|
||||
'folder' => array( 'menu_title_folder', 'menu_permission')
|
||||
)
|
||||
) );
|
||||
}
|
||||
|
||||
/* Page fields */
|
||||
if ( $forceType !== 'page' )
|
||||
{
|
||||
$pages = array();
|
||||
foreach( \IPS\cms\Pages\Page::roots() as $id => $page )
|
||||
{
|
||||
$pages[ $id ] = $page->_title . ' (' . $page->full_path . ')';
|
||||
}
|
||||
|
||||
$form['menu_content_page'] = new \IPS\Helpers\Form\Select( 'menu_content_page', $node !== NULL ? ( $node->type === 'page' ? $node->content : NULL ) : 0, FALSE, array(
|
||||
'options' => $pages
|
||||
), NULL, NULL, NULL, 'menu_content_page' );
|
||||
}
|
||||
|
||||
$form['menu_title_page'] = new \IPS\Helpers\Form\Translatable( 'menu_title_page', NULL, FALSE, array( 'app' => 'cms', 'key' => ( ( ! empty( $node ) and $node->type === 'page' ) ? "cms_menu_title_" . $node->id : NULL ), 'maxLength' => 64 ), NULL, NULL, NULL, 'menu_title_page' );
|
||||
|
||||
/* URL Fields */
|
||||
if ( $forceType === NULL or $forceType === 'url' )
|
||||
{
|
||||
$form['menu_content_url'] = new \IPS\Helpers\Form\Text( 'menu_content_url', $node !== NULL ? ( $node->type === 'url' ? $node->content : NULL ) : '', FALSE, array(), NULL, NULL, NULL, 'menu_content_url' );
|
||||
|
||||
$form['menu_title_url'] = new \IPS\Helpers\Form\Translatable( 'menu_title_url', NULL, FALSE, array( 'app' => 'cms', 'key' => ( ( ! empty( $node ) and $node->type === 'url' ) ? "cms_menu_title_" . $node->id : NULL ), 'maxLength' => 64 ), NULL, NULL, NULL, 'menu_title_url' );
|
||||
}
|
||||
|
||||
/* Folder fields */
|
||||
if ( $forceType === NULL or $forceType === 'folder' )
|
||||
{
|
||||
$form['menu_title_folder'] = new \IPS\Helpers\Form\Translatable( 'menu_title_folder', NULL, FALSE, array( 'app' => 'cms', 'key' => ( ( ! empty( $node ) and $node->type === 'folder' ) ? "cms_menu_title_" . $node->id : NULL ), 'maxLength' => 64 ), NULL, NULL, NULL, 'menu_title_folder' );
|
||||
}
|
||||
|
||||
/* Shared fields */
|
||||
$form['menu_parent_id'] = new \IPS\Helpers\Form\Node( 'menu_parent_id', $node !== NULL ? intval( $node->parent_id ) : 0, FALSE, array(
|
||||
'class' => '\IPS\cms\Pages\Menu',
|
||||
'zeroVal' => 'node_no_parent',
|
||||
'permissionCheck' => function( $node )
|
||||
{
|
||||
return $node->type === 'folder';
|
||||
}
|
||||
), NULL, NULL, NULL, 'menu_parent_id' );
|
||||
|
||||
$form['menu_permission_from_page'] = new \IPS\Helpers\Form\Radio( 'menu_permission_type', $node !== NULL ? ( $node->permission === 'page' ? 'page' : 'manual' ) : ( $forceType === 'page' ? 'page' : 'manual' ), FALSE, array(
|
||||
'options' => array(
|
||||
'page' => 'cms_menu_form_perm_page',
|
||||
'manual' => 'cms_menu_form_perm_manual'
|
||||
),
|
||||
'toggles' => array(
|
||||
'manual' => array( 'menu_permission' )
|
||||
)
|
||||
), NULL, NULL, NULL, 'menu_permission_from_page' );
|
||||
|
||||
$form['menu_permission'] = new \IPS\Helpers\Form\Select( 'menu_permission', ( $node !== NULL ) ? ( ( $node->permission === '*' ) ? '*' : explode( ',', $node->permission ) ) : NULL, FALSE, array(
|
||||
'options' => array_combine( array_keys( \IPS\Member\Group::groups() ), array_map( function( $_group ) { return (string) $_group; }, \IPS\Member\Group::groups() ) ),
|
||||
'multiple' => true,
|
||||
'unlimited' => '*',
|
||||
'unlimitedLang' => 'cms_menu_perm_any'
|
||||
), NULL, NULL, NULL, 'menu_permission' );
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear caches
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function clearCaches()
|
||||
{
|
||||
unset( \IPS\Data\Store::i()->cms_menu );
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Set Title
|
||||
*
|
||||
* @param string $title Title
|
||||
* @return string|null
|
||||
*/
|
||||
protected function set__title( $title )
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Get Title
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
protected function get__title()
|
||||
{
|
||||
if ( ! $this->title AND $this->type === 'page' )
|
||||
{
|
||||
try
|
||||
{
|
||||
$this->title = \IPS\cms\Pages\Page::load( $this->content )->_title;
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
{
|
||||
$this->title = '';
|
||||
}
|
||||
}
|
||||
else if ( ! $this->title )
|
||||
{
|
||||
/* This is stored in a separate \Data\Store cache, so we can't return the hash */
|
||||
$this->title = \IPS\Member::loggedIn()->language()->get( 'cms_menu_title_' . $this->id );
|
||||
}
|
||||
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Get URL
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
protected function get__url()
|
||||
{
|
||||
if ( $this->type === 'page' )
|
||||
{
|
||||
try
|
||||
{
|
||||
return \IPS\cms\Pages\Page::load( $this->content )->url();
|
||||
}
|
||||
catch( \OutOfRangeException $ex )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Return the custom badge for each row
|
||||
*
|
||||
* @return NULL|array Null for no badge, or an array of badge data (0 => CSS class type, 1 => language string, 2 => optional raw HTML to show instead of language string)
|
||||
*/
|
||||
protected function get__badge()
|
||||
{
|
||||
if ( ! $this->permission )
|
||||
{
|
||||
return array( 'ipsBadge ipsBadge_negative', 'cms_menu_no_item_perm' );
|
||||
}
|
||||
|
||||
return ( $this->type === 'folder' ) ? NULL : array( 'ipsBadge ipsBadge_intermediary ipsPos_right', 'cms_menu_form_type_' . $this->type );
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Get buttons to display in tree
|
||||
* Example code explains return value
|
||||
*
|
||||
* @code
|
||||
array(
|
||||
array(
|
||||
'icon' => 'plus-circle', // Name of FontAwesome icon to use
|
||||
'title' => 'foo', // Language key to use for button's title parameter
|
||||
'link' => \IPS\Http\Url::internal( 'app=foo...' ) // URI to link to
|
||||
'class' => 'modalLink' // CSS Class to use on link (Optional)
|
||||
),
|
||||
... // Additional buttons
|
||||
);
|
||||
* @endcode
|
||||
* @param string $url Base URL
|
||||
* @param bool $subnode Is this a subnode?
|
||||
* @return array
|
||||
*/
|
||||
public function getButtons( $url, $subnode=FALSE )
|
||||
{
|
||||
$buttons = parent::getButtons( $url, $subnode );
|
||||
|
||||
if ( isset( $buttons['copy'] ) and $this->type === 'folder' )
|
||||
{
|
||||
unset( $buttons['copy'] );
|
||||
}
|
||||
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sortable name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSortableName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Add/Edit Form
|
||||
*
|
||||
* @param \IPS\Helpers\Form $form The form
|
||||
* @return void
|
||||
*/
|
||||
public function form( &$form )
|
||||
{
|
||||
/* Build form */
|
||||
foreach( static::formElements( $this ) as $element )
|
||||
{
|
||||
$form->add( $element );
|
||||
}
|
||||
|
||||
if ( $this->id )
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('cms_menu_edit', FALSE, array( 'sprintf' => array( $this->_title ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('cms_menu_adding');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Format form values from add/edit form for save
|
||||
*
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
public function formatFormValues( $values )
|
||||
{
|
||||
if ( ! $this->id )
|
||||
{
|
||||
$this->parent_id = 0;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
if( isset( $values['menu_type'] ) )
|
||||
{
|
||||
$title = '';
|
||||
$content = NULL;
|
||||
|
||||
switch ( $values['menu_type'] )
|
||||
{
|
||||
case 'page':
|
||||
$title = $values['menu_title_page'];
|
||||
$content = $values['menu_content_page'];
|
||||
break;
|
||||
case 'url':
|
||||
$title = $values['menu_title_url'];
|
||||
$content = $values['menu_content_url'];
|
||||
break;
|
||||
case 'folder':
|
||||
$title = $values['menu_title_folder'];
|
||||
break;
|
||||
}
|
||||
|
||||
/* We need to store something in menu_title field in the database as we can leave this blank to get the current page title. We can't examine an addToStack to see if any data was returned */
|
||||
$values['title'] = current( $title );
|
||||
$values['content'] = $content;
|
||||
|
||||
\IPS\Lang::saveCustom( 'cms', "cms_menu_title_" . $this->id, $title );
|
||||
|
||||
unset( $values['menu_title_folder'], $values['menu_title_url'], $values['menu_title_page'], $values['menu_content_page'], $values['menu_content_url'] );
|
||||
}
|
||||
|
||||
if( isset( $values['menu_permission'] ) )
|
||||
{
|
||||
$values['menu_permission'] = ( is_array( $values['menu_permission'] ) ) ? implode( ',', $values['menu_permission'] ) : $values['menu_permission'];
|
||||
}
|
||||
|
||||
if ( isset( $values['menu_type'] ) AND $values['menu_type'] === 'page' and $values['menu_permission_type'] === 'page' )
|
||||
{
|
||||
$values['menu_permission'] = 'page';
|
||||
}
|
||||
|
||||
if ( isset( $values['menu_parent_id'] ) AND ( ! empty( $values['menu_parent_id'] ) OR $values['menu_parent_id'] === 0 ) )
|
||||
{
|
||||
$values['menu_parent_id'] = ( $values['menu_parent_id'] === 0 ) ? 0 : $values['menu_parent_id']->id;
|
||||
}
|
||||
|
||||
if( isset( $values['menu_permission_type'] ) )
|
||||
{
|
||||
unset( $values['menu_permission_type'] );
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Does the currently logged in user have permission to add a child node to this node?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canAdd()
|
||||
{
|
||||
if ( parent::canAdd() )
|
||||
{
|
||||
return $this->type === 'folder';
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
static::clearCaches();
|
||||
parent::save();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
Whitespace-only changes.
Reference in new issue
Block a user