Version 4.0.13.1

This commit is contained in:
Neo committed 2025-12-19 04:57:54 -08:00
1 parent f9e857d255
commit c6a86f0d9b
7517 files changed
+597400 -668041

No files matched your search

@@ -0,0 +1,73 @@
<?php
/**
* @brief Fields 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 8 April 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\cms\modules\admin\databases;
/* 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;
}
/**
* categories
*/
class _categories extends \IPS\Node\Controller
{
/**
* Node Class
*/
protected $nodeClass = '\IPS\cms\Categories';
/**
* Execute
*
* @return void
*/
public function execute()
{
$this->url = $this->url->setQueryString( array( 'database_id' => \IPS\Request::i()->database_id ) );
/* Assign the correct nodeClass so contentItem is specified */
$this->nodeClass = '\IPS\cms\Categories' . \IPS\Request::i()->database_id;
\IPS\Dispatcher::i()->checkAcpPermission( 'categories_manage' );
$nodeClass = $this->nodeClass;
$childLang = \IPS\Member::loggedIn()->language()->addToStack( $nodeClass::$nodeTitle . '_add_child' );
$nodeClass::$nodeTitle = \IPS\Member::loggedIn()->language()->addToStack('content_cat_db_title', FALSE, array( 'sprintf' => array( \IPS\cms\Databases::load( \IPS\Request::i()->database_id)->_title ) ) );
\IPS\Member::loggedIn()->language()->words[ $nodeClass::$nodeTitle . '_add_child' ] = $childLang;
parent::execute();
}
/**
* Get Root Rows
*
* @return array
*/
public function _getRoots()
{
$nodeClass = $this->nodeClass;
$rows = array();
foreach( $nodeClass::roots( NULL ) as $node )
{
if ( $node->database_id == \IPS\Request::i()->database_id )
{
$rows[ $node->_id ] = $this->_getRow( $node );
}
}
return $rows;
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,296 @@
<?php
/**
* @brief Fields 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 31 March 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\cms\modules\admin\databases;
/* 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;
}
/**
* fields
*/
class _fields extends \IPS\Node\Controller
{
/**
* Node Class
*/
protected $nodeClass = '\IPS\cms\Fields';
/**
* Execute
*
* @return void
*/
public function execute()
{
$this->url = $this->url->setQueryString( array( 'database_id' => \IPS\Request::i()->database_id ) );
$this->nodeClass = '\IPS\cms\Fields' . \IPS\Request::i()->database_id;
\IPS\Dispatcher::i()->checkAcpPermission( 'fields_manage' );
parent::execute();
}
/**
* Manage
*
* @return void
*/
protected function manage()
{
parent::manage();
$url = \IPS\Http\Url::internal( "app=cms&module=databases&controller=fields&database_id=" . \IPS\Request::i()->database_id );
$class = '\IPS\cms\Fields' . \IPS\Request::i()->database_id;
/* Build fixed fields */
$fixed = array_merge( array( 'record_publish_date' => array(), 'record_expiry_date' => array(), 'record_allow_comments' => array(), 'record_comment_cutoff' => array(), 'record_image' => array() ), $class::fixedFieldPermissions() );
/* Fixed fields */
$fixedFields = new \IPS\Helpers\Tree\Tree(
$url,
\IPS\Member::loggedIn()->language()->addToStack('content_fields_fixed_title'),
function() use ( $fixed, $url )
{
$rows = array();
foreach( $fixed as $field => $data )
{
$rows[ $field ] = \IPS\Theme::i()->getTemplate( 'trees', 'core' )->row( $url, $field, \IPS\Member::loggedIn()->language()->addToStack( 'content_fields_fixed_'. $field ), FALSE, array(
'permission' => array(
'icon' => 'lock',
'title' => 'permissions',
'link' => $url->setQueryString( array( 'field' => $field, 'do' => 'fixedPermissions' ) ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack( 'content_fields_fixed_'. $field ) )
)
), NULL, NULL, NULL, NULL, ( empty( $data['visible'] ) ? FALSE : TRUE ) );
}
return $rows;
},
function( $key, $root=FALSE ) use ( $fixed, $url ) {},
function() { return 0; },
function() { return array(); },
function() { return array(); },
FALSE,
TRUE,
TRUE
);
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'databases' )->fieldsWrapper( $fixedFields );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('content_database_field_area', FALSE, array( 'sprintf' => array( \IPS\cms\Databases::load( \IPS\Request::i()->database_id)->_title ) ) );
}
/**
* Get Root Rows
*
* @return array
*/
public function _getRoots()
{
$nodeClass = $this->nodeClass;
$rows = array();
foreach( $nodeClass::roots( NULL ) as $node )
{
if ( $node->database_id == \IPS\Request::i()->database_id )
{
$rows[ $node->_id ] = $this->_getRow( $node );
}
}
return $rows;
}
/**
* Fixed field permissions
*
* @return void
*/
public function enableToggle()
{
$class = '\IPS\cms\Fields' . \IPS\Request::i()->database_id;
$class::setFixedFieldVisibility( \IPS\Request::i()->id, (boolean) \IPS\Request::i()->status );
/* Redirect */
if ( \IPS\Request::i()->status )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=cms&module=databases&controller=fields&database_id=" . \IPS\Request::i()->database_id . '&do=fixedPermissions&field=' . \IPS\Request::i()->id ) );
}
else
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=cms&module=databases&controller=fields&database_id=" . \IPS\Request::i()->database_id ), 'saved' );
}
}
/**
* Set this field as the record title
*
* @return void
*/
public function setAsTitle()
{
$class = '\IPS\cms\Fields' . \IPS\Request::i()->database_id;
$database = \IPS\cms\Databases::load( \IPS\Request::i()->database_id );
try
{
$field = $class::load( \IPS\Request::i()->id );
if ( $field->canBeTitleField() )
{
$database->field_title = $field->id;
$database->save();
}
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=cms&module=databases&controller=fields&database_id=" . \IPS\Request::i()->database_id ), 'saved' );
}
catch( \OutOfRangeException $ex )
{
\IPS\Output::i()->error( 'cms_cannot_find_field', '2T255/1', 403, '' );
}
}
/**
* Set this field as the record content
*
* @return void
*/
public function setAsContent()
{
$class = '\IPS\cms\Fields' . \IPS\Request::i()->database_id;
$database = \IPS\cms\Databases::load( \IPS\Request::i()->database_id );
try
{
$field = $class::load( \IPS\Request::i()->id );
if ( $field->canBeContentField() )
{
$database->field_content = $field->id;
$database->save();
}
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=cms&module=databases&controller=fields&database_id=" . \IPS\Request::i()->database_id ), 'saved' );
}
catch( \OutOfRangeException $ex )
{
\IPS\Output::i()->error( 'cms_cannot_find_field', '2T255/2', 403, '' );
}
}
/**
* Fixed field permissions
*
* @return void
*/
public function fixedPermissions()
{
$class = '\IPS\cms\Fields' . \IPS\Request::i()->database_id;
$perms = $class::fixedFieldPermissions( \IPS\Request::i()->field );
$permMap = array( 'view' => 'view', 'edit' => 2, 'add' => 3 );
foreach( $permMap as $k => $v )
{
if ( ! isset( $perms[ 'perm_' . $v ] ) )
{
$perms[ 'perm_' . $v ] = NULL;
}
}
/* Build Matrix */
$matrix = new \IPS\Helpers\Form\Matrix;
$matrix->manageable = FALSE;
$matrix->langPrefix = 'content_perm_fixed_fields__';
$matrix->columns = array(
'label' => function( $key, $value, $data )
{
return $value;
},
);
foreach ( $permMap as $k => $v )
{
$matrix->columns[ $k ] = function( $key, $value, $data ) use ( $perms, $k, $v )
{
$groupId = mb_substr( $key, 0, -( 2 + mb_strlen( $k ) ) );
return new \IPS\Helpers\Form\Checkbox( $key, isset( $perms[ "perm_{$v}" ] ) and ( $perms[ "perm_{$v}" ] === '*' or in_array( $groupId, explode( ',', $perms[ "perm_{$v}" ] ) ) ) );
};
$matrix->checkAlls[ $k ] = ( $perms[ "perm_{$v}" ] === '*' );
}
$matrix->checkAllRows = TRUE;
$rows = array();
foreach ( \IPS\Member\Group::groups() as $group )
{
$rows[ $group->g_id ] = array(
'label' => $group->name,
'view' => TRUE,
);
}
$matrix->rows = $rows;
/* Handle submissions */
if ( $values = $matrix->values() )
{
$_perms = array();
$save = array();
/* Check for "all" checkboxes */
foreach ( $permMap as $k => $v )
{
if ( isset( \IPS\Request::i()->__all[ $k ] ) )
{
$_perms[ $v ] = '*';
}
else
{
$_perms[ $v ] = array();
}
}
/* Loop groups */
foreach ( $values as $group => $perms )
{
foreach ( $permMap as $k => $v )
{
if ( isset( $perms[ $k ] ) and $perms[ $k ] and is_array( $_perms[ $v ] ) )
{
$_perms[ $v ][] = $group;
}
}
}
/* Finalise */
foreach ( $_perms as $k => $v )
{
$save[ "perm_{$k}" ] = is_array( $v ) ? implode( $v, ',' ) : $v;
}
$class::setFixedFieldPermissions( \IPS\Request::i()->field, $save );
/* Redirect */
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=cms&module=databases&controller=fields&database_id=" . \IPS\Request::i()->database_id ), 'saved' );
}
/* Display */
\IPS\Output::i()->output .= $matrix;
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('content_database_manage_fields');
}
}
Whitespace-only changes.
@@ -0,0 +1,489 @@
<?php
/**
* @brief Records 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 8 April 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\cms\modules\admin\databases;
/* 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;
}
/**
* records
*/
class _records extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
$this->url = $this->url->setQueryString( array( 'database_id' => \IPS\Request::i()->database_id ) );
\IPS\Dispatcher::i()->checkAcpPermission( 'records_manage' );
parent::execute();
}
/**
* Manage
*
* @return void
*/
protected function manage()
{
$database = \IPS\cms\Databases::load( \IPS\Request::i()->database_id );
$title = \IPS\Member::loggedIn()->language()->addToStack('content_record_db_title', TRUE, array( 'sprintf' => array( $database->_title ) ) );
/* Create the table */
$table = new \IPS\Helpers\Table\Db( 'cms_custom_database_' . \IPS\Request::i()->database_id, \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records' ) );
$table->langPrefix = 'content_db_table_';
$table->title = $title;
$table->quickSearch = 'field_' . $database->field_title;
$table->baseUrl = $table->baseUrl->setQueryString( array( 'database_id' => \IPS\Request::i()->database_id ) );
/* Only specify these if we are not re-ordering via the table headers, which are set in the Table contructor */
if ( ! $table->sortBy )
{
$table->sortBy = $database->field_sort ? $database->field_sort : 'record_last_comment';
}
if ( ! $table->sortDirection )
{
$table->sortDirection = $database->field_direction ? $database->field_direction : 'desc';
}
$table->filters = array(
'content_db_table_filter_approved' => array('record_approved=?', 1 ),
'content_db_table_filter_unapproved' => array('record_approved=?', 0 ),
'content_db_table_filter_hidden' => array('record_approved=?', -1 ),
'content_db_table_filter_pinned' => array('record_pinned=?' , 1 )
);
if ( $database->use_categories )
{
$table->include = array(
'primary_id_field',
'field_' . $database->field_title,
'record_publish_date',
'category_id'
);
}
else
{
$table->include = array(
'primary_id_field',
'field_' . $database->field_title,
'record_publish_date'
);
}
/* Add title header */
\IPS\Member::loggedIn()->language()->words['content_db_table_field_' . $database->field_title ] = \IPS\Member::loggedIn()->language()->addToStack( 'content_db_table_title' );
$table->advancedSearch = array(
'category_id' => array( \IPS\Helpers\Table\SEARCH_NODE, array(
'class' => '\IPS\cms\Categories',
'disabled' => false,
'zeroVal' => 'content_db_table_as_no_cat',
'permissionCheck' => function( $node )
{
return $node->database_id == \IPS\Request::i()->database_id;
}
),
),
'record_comments'=> array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => array(
'null' => 'content_db_table_as_comments_null',
1 => 'content_db_table_as_comments_yes',
2 => 'content_db_table_as_comments_no'
)
) ),
);
/* Buttons */
if ( $database->use_categories )
{
$table->rootButtons = array(
'add' => array(
'title' => 'add',
'icon' => 'plus',
'link' => \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records&do=select&database_id=' . \IPS\Request::i()->database_id ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('database_select_category' ) )
),
);
}
else
{
$table->rootButtons = array(
'add' => array(
'title' => 'add',
'icon' => 'plus',
'link' => \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records&do=form&database_id=' . \IPS\Request::i()->database_id )
),
);
}
/* Buttons */
$table->rowButtons = function( $row )
{
return array(
'edit' => array(
'title' => 'edit',
'icon' => 'pencil',
'link' => \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records&database_id=' . \IPS\Request::i()->database_id . '&id=' . $row['primary_id_field'] . '&do=form' ),
'data' => array()
),
'move' => array(
'title' => 'move',
'icon' => 'arrow-right',
'link' => \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records&database_id=' . \IPS\Request::i()->database_id . '&do=select&move=' . $row['primary_id_field'] ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('database_select_category' ) )
),
'delete' => array(
'title' => 'delete',
'icon' => 'times-circle',
'link' => \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records&database_id=' . \IPS\Request::i()->database_id . '&id=' . $row['primary_id_field'] . '&do=delete' ),
'data' => array( 'delete' => '' )
),
);
};
$table->parsers = array(
'field_' . $database->field_title => function( $val, $row ) use ($database)
{
$class = '\IPS\cms\Records' . $database->id;
$val = $class::load( $row['primary_id_field'] )->_title;
return \IPS\Theme::i()->getTemplate( 'records', 'cms', 'admin' )->title( $row, $val );
},
'category_id' => function( $val ) use ($database)
{
if ( $val )
{
try
{
$class = '\IPS\cms\Categories' . $database->id;
return $class::load( $val )->_title;
}
catch( \OutOfRangeException $e )
{
return '';
}
}
return '';
},
'record_publish_date' => function( $val, $row )
{
$val = ( ! empty( $val ) ) ? $val : $row['record_saved'];
return \IPS\DateTime::ts( $val )->localeDate();
}
);
/* Add a button for managing DB settings */
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'cms', 'databases', 'databases_edit' ) )
{
\IPS\Output::i()->sidebar['actions']['databasemanage'] = array(
'title' => 'cms_manage_database',
'icon' => 'wrench',
'link' => \IPS\Http\Url::internal( 'app=cms&module=databases&controller=databases&do=form&id=' . $database->_id ),
'data' => NULL
);
}
/* Reset languages */
\IPS\Member::loggedIn()->language()->words[ $table->langPrefix . $database->field_title ] = \IPS\Member::loggedIn()->language()->addToStack($table->langPrefix . 'title');
/* Display */
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( $title, (string) $table );
\IPS\Output::i()->title = $title;
}
/**
* Delete
*
* @return void
*/
public function delete()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'records_delete' );
$recordClass = '\IPS\cms\Records' . \IPS\Request::i()->database_id;
try
{
$recordClass::load( \IPS\Request::i()->id )->delete();
}
catch( \OutofRangeException $ex )
{
\IPS\Output::i()->error( 'no_permission', '2T253/1', 403, '' );
}
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records&database_id=' . \IPS\Request::i()->database_id ), 'record_deleted' );
}
/**
* Show the pre add record form. This is used when no category is set.
*
* @return void
*/
protected function select()
{
$move = isset( \IPS\Request::i()->move ) ? \IPS\Request::i()->move : NULL;
$catClass = 'IPS\cms\Categories' . \IPS\Request::i()->database_id;
$recordClass = 'IPS\cms\Records' . \IPS\Request::i()->database_id;
$category = NULL;
$record = NULL;
if ( $move )
{
try
{
$record = $recordClass::load( $move );
$category = $catClass::load( $record->category_id );
}
catch( \OutOfRangeException $e ) { }
}
$form = new \IPS\Helpers\Form( 'select_category', 'continue' );
$form->class = 'ipsForm_vertical ipsForm_noLabels';
$form->add( new \IPS\Helpers\Form\Node( 'category', $category, TRUE, array(
'url' => \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records&do=select&database_id=' . \IPS\Request::i()->database_id . ( $move ) ? '&move=' . $move : '' ),
'class' => $catClass,
'multiple' => false,
'permissionCheck' => function( $node )
{
if ( $node->can( 'view' ) )
{
if ( $node->can( 'add' ) )
{
return TRUE;
}
return FALSE;
}
return NULL;
},
) ) );
if ( $values = $form->values() )
{
if ( $move and $record )
{
$record->category_id = $values['category']->id;
$record->save();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records&database_id=' . \IPS\Request::i()->database_id ), 'completed' );
}
else
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records&do=form&database_id=' . \IPS\Request::i()->database_id . '&category_id=' . $values['category']->id ) );
}
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'database_select_category' );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'records' )->categorySelector( $form );
}
/**
* Add/Edit
*
* @return void
*/
public function form()
{
$database = \IPS\cms\Databases::load( \IPS\Request::i()->database_id );
$title = \IPS\Member::loggedIn()->language()->addToStack('content_record_db_title', TRUE, array( 'sprintf' => array( $database->_title ) ) );
$current = NULL;
$customValues = array();
$class = 'IPS\cms\Records' . \IPS\Request::i()->database_id;
if ( \IPS\Request::i()->id )
{
$current = $class::load( \IPS\Request::i()->id );
$customValues = $current->fieldValues();
}
$fieldsClass = 'IPS\cms\Fields' . \IPS\Request::i()->database_id;
$catClass = 'IPS\cms\Categories' . \IPS\Request::i()->database_id;
$container = ( $current ) ? $catClass::load( $current->category_id ) : ( isset( \IPS\Request::i()->category_id ) ? $catClass::load( \IPS\Request::i()->category_id ) : NULL );
$customFields = $fieldsClass::fields( $customValues, 'view', $container );
$manuallyHandledFields = array( 'record_publish_date', 'record_expiry_date', 'record_allow_comments', 'record_comment_cutoff', 'record_meta_keywords', 'record_meta_description' );
$form = new \IPS\Helpers\Form();
$form->addtab( 'content_database_record_tab_content' );
$formElements = $class::formElements( $current, $container );
foreach( $formElements as $name => $field )
{
if ( in_array( $name, $manuallyHandledFields ) )
{
continue;
}
$form->add( $field );
}
/* Now custom fields */
foreach( $customFields as $id => $obj )
{
if ( $database->field_title === 'field_' . $obj->_id )
{
continue;
}
$form->add( $obj );
}
$form->addtab( 'content_database_record_tab_publish' );
if ( isset( $formElements['record_publish_date'] ) )
{
$form->add( $formElements['record_publish_date'] );
}
if ( isset( $formElements['record_expiry_date'] ) )
{
$form->add( $formElements['record_expiry_date'] );
}
$form->add( new \IPS\Helpers\Form\Radio( 'record_author_choice', $current ? ( $current->member_id === \IPS\Member::loggedIn()->member_id ? 'me' : 'notme' ) : 'me', FALSE, array(
'options' => array(
'me' => 'record_author_choice_me',
'notme' => 'record_author_choice_notme'
),
'toggles' => array(
'notme' => array( 'record_member_id' )
)
), NULL, NULL, NULL, 'record_author_choice' ) );
$form->add( new \IPS\Helpers\Form\Member( 'record_member_id', ( $current ? \IPS\Member::load( $current->member_id ) : NULL ), FALSE, array(), NULL, NULL, NULL, 'record_member_id' ) );
if ( isset( $formElements['record_allow_comments'] ) )
{
$form->addHeader( 'content_database_record_tab_comments' );
$form->add( $formElements['record_allow_comments'] );
if ( isset( $formElements['record_comment_cutoff'] ) )
{
$form->add( $formElements['record_comment_cutoff'] );
}
}
if ( \IPS\Member::loggedIn()->modPermission('can_content_edit_meta_tags') )
{
$form->addtab( 'content_database_record_tab_meta' );
$form->add( $formElements['record_meta_keywords'] );
$form->add( $formElements['record_meta_description'] );
}
if ( $values = $form->values() )
{
$recordClass = '\IPS\cms\Records' . \IPS\Request::i()->database_id;
$fieldClass = '\IPS\cms\Fields' . \IPS\Request::i()->database_id;
$new = false;
if ( empty( $current ) )
{
$new = true;
$category = NULL;
if ( ! $database->use_categories )
{
$catClass = 'IPS\cms\Categories' . $database->id;
$category = $catClass::load( $database->get__default_category() );
}
else
{
if ( isset( \IPS\Request::i()->category_id ) )
{
$category = $catClass::load( \IPS\Request::i()->category_id );
}
}
$current = $recordClass::createFromForm( $values, $category );
/* Claim attachments */
foreach( $fieldClass::data() as $key => $field )
{
if ( ucfirst( $field->type ) === 'Editor' )
{
\IPS\File::claimAttachments( 'RecordField_'. $field->id , $current->id, NULL, 'RecordField_'. $field->id, FALSE );
}
}
}
/* Other data */
$current->record_meta_keywords = $values['record_meta_keywords'];
$current->record_meta_description = $values['record_meta_description'];
$changeAuthor = FALSE;
if ( ! empty( \IPS\Request::i()->id ) and $values['record_author_choice'] === 'notme' and ! empty( $values['record_member_id'] ) )
{
$changeAuthor = TRUE;
}
/* Just editing, thanks */
if ( ! $new )
{
$current->processForm( $values );
$current->processAfterEdit( $values );
if ( isset( $recordClass::$databaseColumnMap['date'] ) and isset( $values[ $recordClass::$formLangPrefix . 'date' ] ) )
{
$column = $recordClass::$databaseColumnMap['date'];
if ( $values[ $recordClass::$formLangPrefix . 'date' ] instanceof \IPS\DateTime )
{
$current->$column = $values[ $recordClass::$formLangPrefix . 'date' ]->getTimestamp();
}
else
{
$current->$column = time();
}
}
}
$current->save();
if ( $changeAuthor )
{
try
{
$current->changeAuthor( $values['record_member_id'] );
}
catch( \LogicException $ex )
{
/* If the database isn't attached to a page, a call to url() when logging an author change throws this */
}
}
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=databases&controller=records&database_id=' . \IPS\Request::i()->database_id ), 'saved' );
}
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( $current ? $title : 'add', $form, FALSE );
\IPS\Output::i()->title = $title;
}
}
Whitespace-only changes.
@@ -0,0 +1,156 @@
<?php
/**
* @brief Customization AJAX actions
* @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 07 May 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\cms\modules\admin\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;
}
/**
* Members AJAX actions
*/
class _ajax extends \IPS\Dispatcher\Controller
{
/**
* Return a CSS or HTML menu
*
* @return html
*/
public function loadMenu()
{
$request = array(
't_location' => ( isset( \IPS\Request::i()->t_location ) ) ? \IPS\Request::i()->t_location : null,
't_group' => ( isset( \IPS\Request::i()->t_group ) ) ? \IPS\Request::i()->t_group : null,
't_key' => ( isset( \IPS\Request::i()->t_key ) ) ? \IPS\Request::i()->t_key : null,
't_type' => ( isset( \IPS\Request::i()->t_type ) ) ? \IPS\Request::i()->t_type : 'templates',
);
switch( $request['t_type'] )
{
default:
case 'template':
$flag = \IPS\cms\Templates::RETURN_ONLY_TEMPLATE;
break;
case 'js':
$flag = \IPS\cms\Templates::RETURN_ONLY_JS;
break;
case 'css':
$flag = \IPS\cms\Templates::RETURN_ONLY_CSS;
break;
}
$templates = \IPS\cms\Templates::buildTree( \IPS\cms\Templates::getTemplates( $flag + \IPS\cms\Templates::RETURN_DATABASE_ONLY ) );
$current = new \IPS\cms\Templates;
if ( ! empty( $request['t_key'] ) )
{
try
{
$current = \IPS\cms\Templates::load( $request['t_key'] );
}
catch( \OutOfRangeException $ex )
{
}
}
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'templates' )->menu( $templates, $current, $request );
}
/**
* Return HTML template as JSON
*
* @return string
*/
public function loadTemplate()
{
$t_location = \IPS\Request::i()->t_location;
$t_key = \IPS\Request::i()->t_key;
if ( $t_location === 'block' and $t_key === '_default_' and isset( \IPS\Request::i()->block_key ) )
{
/* Find it from the normal template system */
$plugin = \IPS\Widget::load( \IPS\Application::load( \IPS\Request::i()->block_app ), \IPS\Request::i()->block_key, uniqid() );
$location = $plugin->getTemplateLocation();
$templateBits = \IPS\Theme::master()->getRawTemplates( $location['app'], $location['location'], $location['group'], \IPS\Theme::RETURN_ALL );
$templateBit = $templateBits[ $location['app'] ][ $location['location'] ][ $location['group'] ][ $location['name'] ];
$templateBit['template_content'] = htmlentities( $templateBit['template_content'], \IPS\HTMLENTITIES, 'UTF-8', TRUE );
$templateArray = array(
'template_id' => $templateBit['template_id'],
'template_key' => 'template_' . $templateBit['template_name'] . '.' . $templateBit['template_id'],
'template_title' => $templateBit['template_name'],
'template_desc' => null,
'template_content' => $templateBit['template_content'],
'template_location' => null,
'template_group' => null,
'template_container' => null,
'template_rel_id' => null,
'template_user_created' => null,
'template_user_edited' => null,
'template_params' => $templateBit['template_data']
);
}
else
{
try
{
if ( is_numeric( $t_key ) )
{
$template = \IPS\cms\Templates::load( $t_key, 'template_id' );
}
else
{
$template = \IPS\cms\Templates::load( $t_key );
}
}
catch( \OutOfRangeException $ex )
{
\IPS\Output::i()->json( array( 'error' => true ) );
}
if ( $template !== null )
{
$templateArray = array(
'template_id' => $template->id,
'template_key' => $template->key,
'template_title' => $template->title,
'template_desc' => $template->desc,
'template_content' => htmlentities( $template->content, \IPS\HTMLENTITIES, 'UTF-8', TRUE ),
'template_location' => $template->location,
'template_group' => $template->group,
'template_container' => $template->container,
'template_rel_id' => $template->rel_id,
'template_user_created' => $template->user_created,
'template_user_edited' => $template->user_edited,
'template_params' => $template->params
);
}
}
if ( \IPS\Request::i()->show == 'json' )
{
\IPS\Output::i()->json( $templateArray );
}
else
{
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->blankTemplate( \IPS\Theme::i()->getTemplate( 'templates', 'cms', 'admin' )->viewTemplate( $templateArray ) ), 200, 'text/html', \IPS\Output::i()->httpHeaders );
}
}
}
@@ -0,0 +1,183 @@
<?php
/**
* @brief Block Controller
* @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 19 Feb 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\cms\modules\admin\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;
}
/**
* blocks
*/
class _blocks extends \IPS\Node\Controller
{
/**
* Node Class
*/
protected $nodeClass = '\IPS\cms\Blocks\Container';
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'block_manage' );
parent::execute();
}
/**
* Manage
*
* @return void
*/
public function manage()
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__cms_pages_blocks');
parent::manage();
}
/**
* Delete
*
* @return void
*/
protected function delete()
{
if ( isset( \IPS\Request::i()->id ) )
{
\IPS\cms\Blocks\Block::deleteCompiled( \IPS\Request::i()->id );
}
parent::delete();
}
/**
* Get Root Buttons
*
* @return array
*/
public function _getRootButtons()
{
$nodeClass = $this->nodeClass;
$buttons = array();
if ( $nodeClass::canAddRoot() )
{
$buttons['add_meow'] = array(
'icon' => 'plus',
'title' => 'content_block_cat_add',
'link' => $this->url->setQueryString( 'do', 'form' ),
'data' => ( $nodeClass::$modalForms ? array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('content_block_cat_add') ) : array() )
);
}
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'cms', 'pages', 'block_add' ) )
{
$buttons['add_block'] = array(
'icon' => 'puzzle-piece',
'title' => 'content_block_block_add',
'link' => $this->url->setQueryString( array( 'do' => 'addBlockType', 'subnode' => 1 ) ),
'data' => ( $nodeClass::$modalForms ? array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('content_block_block_add') ) : array() )
);
}
return $buttons;
}
/**
* Add block, pre form
*
* @return void
*/
public function addBlockType()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'block_add' );
$form = new \IPS\Helpers\Form( 'block_add_first_step', 'next');
$form->add( new \IPS\Helpers\Form\Radio( 'content_block_add_type', 'plugin', FALSE, array(
'options' => array(
'plugin' => 'content_block_add_type_plugin',
'custom' => 'content_block_add_type_custom'
),
'toggles' => array(
'plugin' => array( 'content_block_add_type_plugin' ),
'custom' => array( 'content_block_add_custom_type' )
)
)
) );
$plugins = array();
foreach ( \IPS\Db::i()->select( "*", 'core_widgets', array( 'embeddable=1') ) as $widget )
{
try
{
if ( $widget['app'] )
{
$plugins[ \IPS\Application::load( $widget['app'] )->_title ][ 'app__' . $widget['app'] . '__' . $widget['key'] ] = \IPS\Member::loggedIn()->language()->addToStack( 'block_' . $widget['key'] );
}
else
{
$plugins[ \IPS\Plugin::load( $widget['plugin'] )->_title ][ 'plugin__' . $widget['plugin'] . '__' . $widget['key'] ] = \IPS\Member::loggedIn()->language()->addToStack( 'block_' . $widget['key'] );
}
}
catch ( \OutOfRangeException $e ) { }
}
foreach( \IPS\cms\Databases::databases() as $db )
{
if ( $db->page_id )
{
$plugins[ \IPS\Member::loggedIn()->language()->addToStack( 'cms_db_feed_title' ) ][ 'db_feed_' . $db->id ] = \IPS\Member::loggedIn()->language()->addToStack( 'cms_db_feed_block_with_name', NULL, array( 'sprintf' => array( $db->_title ) ) );
}
}
$form->add( new \IPS\Helpers\Form\Select( 'content_block_add_type_plugin', null, false, array( 'options' => $plugins ), NULL, NULL, NULL, 'content_block_add_type_plugin' ) );
$form->add( new \IPS\Helpers\Form\Radio( 'content_block_add_custom_type', 'editor', TRUE, array(
'options' => array( 'editor' => 'content_block_add_custom_type_wysiwyg',
'html' => 'content_block_add_custom_type_html',
'php' => 'content_block_add_custom_type_php'
) ), NULL, NULL, NULL, 'content_block_add_custom_type' ) );
if ( $values = $form->values() )
{
if ( $values['content_block_add_type'] !== 'custom' )
{
if ( mb_substr( $values['content_block_add_type_plugin'], 0, 8 ) === 'db_feed_' )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=pages&controller=blocks&do=form&subnode=1&block_type=plugin&block_plugin=' . $values['content_block_add_type_plugin'] . '&block_plugin_app=cms&parent=' . \IPS\Request::i()->parent ) );
}
else
{
list( $type, $value, $key ) = explode( '__', $values['content_block_add_type_plugin'] );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=pages&controller=blocks&do=form&subnode=1&block_type=plugin&block_plugin=' . $key . "&block_plugin_{$type}={$value}" . '&parent=' . \IPS\Request::i()->parent ) );
}
}
else
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=pages&controller=blocks&do=form&subnode=1&block_type=' . $values['content_block_add_type'] . '&block_editor=' . $values['content_block_add_custom_type'] . '&parent=' . \IPS\Request::i()->parent ) );
}
}
/* Display */
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core', 'admin' )->block( \IPS\Member::loggedIn()->language()->addToStack('content_block_block_add'), $form, FALSE );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('content_block_block_add');
}
}
Whitespace-only changes.
@@ -0,0 +1,69 @@
<?php
/**
* @brief Page menu Controller
* @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\modules\admin\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;
}
/**
* Page management
*/
class _menu extends \IPS\Node\Controller
{
/**
* Node Class
*/
protected $nodeClass = '\IPS\cms\Pages\Menu';
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'menu_manage' );
parent::execute();
}
/**
* Show the pages tree
*
* @return string
*/
protected function manage()
{
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__cms_pages_menu');
if ( ! \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->message( \IPS\Member::loggedIn()->language()->addToStack('cms_menu_information'), 'information', NULL, FALSE );
}
return parent::manage();
}
/**
* Delete
*
* @return void
*/
protected function delete()
{
unset( \IPS\Data\Store::i()->cms_menu );
parent::delete();
}
}
@@ -0,0 +1,432 @@
<?php
/**
* @brief Pages Controller
* @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 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\cms\modules\admin\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;
}
/**
* Page management
*/
class _pages extends \IPS\Node\Controller
{
/**
* Node Class
*/
protected $nodeClass = '\IPS\cms\Pages\Folder';
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'page_manage' );
parent::execute();
}
/**
* Get Root Buttons
*
* @return array
*/
public function _getRootButtons()
{
$nodeClass = $this->nodeClass;
$buttons = array();
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'cms', 'pages', 'page_add' ) )
{
$buttons['add_folder'] = array(
'icon' => 'folder-open',
'title' => 'content_add_folder',
'link' => \IPS\Http\Url::internal( 'app=cms&module=pages&controller=pages&do=form' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('content_add_folder') )
);
$buttons['add_page'] = array(
'icon' => 'plus-circle',
'title' => 'content_add_page',
'link' => \IPS\Http\Url::internal( 'app=cms&module=pages&controller=pages&subnode=1&do=add' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('content_add_page') )
);
}
return $buttons;
}
/**
* Show the pages tree
*
* @return string
*/
protected function manage()
{
$url = \IPS\Http\Url::internal( "app=cms&module=pages&controller=pages" );
/* Display the table */
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__cms_pages_pages');
\IPS\Output::i()->output = new \IPS\Helpers\Tree\Tree( $url, 'menu__cms_pages_pages',
/* Get Roots */
function () use ( $url )
{
$data = \IPS\cms\modules\admin\pages\pages::getRowsForTree( 0 );
$rows = array();
foreach ( $data as $id => $row )
{
$rows[ $id ] = ( $row instanceof \IPS\cms\Pages\Page ) ? \IPS\cms\modules\admin\pages\pages::getPageRow( $row, $url ) : \IPS\cms\modules\admin\pages\pages::getFolderRow( $row, $url );
}
return $rows;
},
/* Get Row */
function ( $id, $root ) use ( $url )
{
if ( $root )
{
return \IPS\cms\modules\admin\pages\pages::getFolderRow( \IPS\cms\Pages\Folder::load( $id ), $url );
}
else
{
return \IPS\cms\modules\admin\pages\pages::getPageRow( \IPS\cms\Pages\Page::load( $id ), $url );
}
},
/* Get Row Parent ID*/
function ()
{
return NULL;
},
/* Get Children */
function ( $id ) use ( $url )
{
$rows = array();
$data = \IPS\cms\modules\admin\pages\pages::getRowsForTree( $id );
if ( ! isset( \IPS\Request::i()->subnode ) )
{
foreach ( $data as $id => $row )
{
$rows[ $id ] = ( $row instanceof \IPS\cms\Pages\Page ) ? \IPS\cms\modules\admin\pages\pages::getPageRow( $row, $url ) : \IPS\cms\modules\admin\pages\pages::getFolderRow( $row, $url );
}
}
return $rows;
},
array( $this, '_getRootButtons' ),
TRUE,
FALSE,
FALSE
);
/* Add a button for managing DB settings */
\IPS\Output::i()->sidebar['actions']['pagessettings'] = array(
'title' => 'cms_pages_settings',
'icon' => 'wrench',
'link' => \IPS\Http\Url::internal( 'app=cms&module=pages&controller=pages&do=settings' ),
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('cms_pages_settings') )
);
}
/**
* Page settings form
*
* @return void
*/
protected function settings()
{
$url = parse_url( \IPS\Settings::i()->base_url );
$disabled = FALSE;
$options = array();
$url['path'] = preg_replace( '#^/?(.+?)?/?$#', '\1', $url['path'] );
$disabled = ( $url['path'] ) ? FALSE : TRUE;
$dirs = explode( '/', $url['path'] );
if ( count( $dirs ) )
{
array_pop( $dirs );
$base = $url['scheme'] . '://' . $url['host'];
if ( isset( $url['port'] ) )
{
$base .= ':' .$url['port'];
}
$base .= '/';
$options[ $base ] = $base;
foreach( $dirs as $dir )
{
$base .= $dir . '/';
$options[ $base ] = $base;
}
}
if ( $disabled )
{
\IPS\Member::loggedIn()->language()->words['cms_use_different_gateway_warning'] = \IPS\Member::loggedIn()->language()->addToStack('cms_pages_different_gateway_impossible');
}
if ( \IPS\Settings::i()->htaccess_mod_rewrite )
{
\IPS\Member::loggedIn()->language()->words['cms_root_page_url_desc'] = \IPS\Member::loggedIn()->language()->addToStack('cms_root_page_url_rewrite_desc');
}
$form = new \IPS\Helpers\Form( 'form', 'save' );
$form->add( new \IPS\Helpers\Form\YesNo( 'cms_use_different_gateway', \IPS\Settings::i()->cms_use_different_gateway, FALSE, array( 'togglesOn' => array( 'cms_root_page_url' ), 'disabled' => $disabled ) ) );
$form->add( new \IPS\Helpers\Form\Select( 'cms_root_page_url', \IPS\Settings::i()->cms_root_page_url, FALSE, array( 'options' => $options ), function( $val )
{
if ( $val and \IPS\Request::i()->cms_use_different_gateway )
{
if ( mb_substr( $val, -1 ) !== '/' )
{
$val .= '/';
}
$page = \IPS\cms\Pages\Page::getDefaultPage();
$response = \IPS\Http\Url::external( ( \IPS\Settings::i()->htaccess_mod_rewrite ? $val . $page->full_path : $val . 'index.php?/' . $page->full_path ) )->request( 5, '1.1', FALSE )->get();
if ( $response->httpResponseCode != 200 and $response->httpResponseCode != 303 and ( \IPS\Settings::i()->site_online OR $response->httpResponseCode != 503 ) )
{
if ( \IPS\Settings::i()->htaccess_mod_rewrite )
{
throw new \LogicException( 'pages_different_gateway_load_error_rewrite' );
}
else
{
throw new \LogicException( 'pages_different_gateway_load_error' );
}
}
}
}, NULL, NULL, 'cms_root_page_url' ) );
if ( $values = $form->values() )
{
$form->saveAsSettings();
\IPS\Member::clearCreateMenu();
\IPS\cms\Pages\Menu::clearCaches();
/* Clear Sidebar Caches */
\IPS\Widget::deleteCaches();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=cms&module=pages&controller=pages" ), 'saved' );
}
/* Display */
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core', 'admin' )->block( \IPS\Member::loggedIn()->language()->addToStack('cms_pages_settings'), $form, FALSE );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('cms_pages_settings');
}
/**
* Download .htaccess file
*
* @return void
*/
protected function htaccess()
{
$dir = str_replace( \IPS\CP_DIRECTORY . '/index.php', '', $_SERVER['PHP_SELF'] );
$path = $dir . 'index.php';
if( \strpos( $dir, ' ' ) !== FALSE )
{
$dir = '"' . $dir . '"';
$path = '"' . $path . '"';
}
$htaccess = <<<FILE
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase {$dir}
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \\.(js|css|jpeg|jpg|gif|png|ico)(\\?|$) - [L,NC,R=404]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . {$path} [L]
</IfModule>
FILE;
\IPS\Output::i()->sendOutput( $htaccess, 200, 'application/x-htaccess', array( 'Content-Disposition' => 'attachment; filename=.htaccess' ) );
}
/**
* Page content form
*
* @return void
*/
protected function add()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'page_add' );
$form = new \IPS\Helpers\Form( 'form', 'next' );
$form->hiddenValues['parent'] = ( isset( \IPS\Request::i()->parent ) ) ? \IPS\Request::i()->parent : 0;
$form->add( new \IPS\Helpers\Form\Radio(
'page_type',
NULL,
FALSE,
array( 'options' => array( 'builder' => 'page_type_builder', 'html' => 'page_type_manual' ),
'descriptions' => array( 'builder' => 'page_type_builder_desc', 'html' => 'page_type_manual_custom_desc' ) ),
NULL,
NULL,
NULL,
'page_type'
) );
if ( $values = $form->values() )
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=pages&controller=pages&do=form&subnode=1&page_type=' . $values['page_type'] . '&parent=' . \IPS\Request::i()->parent ) );
}
/* Display */
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core', 'admin' )->block( \IPS\Member::loggedIn()->language()->addToStack('content_add_page'), $form, FALSE );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('content_add_page');
}
/**
* Delete
*
* @return void
*/
protected function delete()
{
if ( isset( \IPS\Request::i()->id ) )
{
\IPS\cms\Pages\Page::deleteCompiled( \IPS\Request::i()->id );
}
parent::delete();
}
/**
* Set as default page for this folder
*
* @return void
*/
protected function setAsDefault()
{
\IPS\cms\Pages\Page::load( \IPS\Request::i()->id )->setAsDefault();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=cms&module=pages&controller=pages" ), 'saved' );
}
/**
* Tree Search
*
* @return void
*/
protected function search()
{
$rows = array();
$url = \IPS\Http\Url::internal( "app=cms&module=pages&controller=pages" );
/* Get results */
$folders = \IPS\cms\Pages\Folder::search( 'folder_name' , \IPS\Request::i()->input, 'folder_name' );
$pages = \IPS\cms\Pages\Page::search( 'page_seo_name', \IPS\Request::i()->input, 'page_seo_name' );
$results = \IPS\cms\Pages\Folder::munge( $folders, $pages );
/* Convert to HTML */
foreach ( $results as $id => $result )
{
$rows[ $id ] = ( $result instanceof \IPS\cms\Pages\Page ) ? $this->_getPageRow( $result, $url ) : $this->_getFolderRow( $result, $url );
}
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'trees', 'core' )->rows( $rows, '' );
}
/**
* Return HTML for a page row
*
* @param array $row Row data
* @param object $url \IPS\Http\Url object
* @return string HTML
*/
public static function getPageRow( $page, $url )
{
return \IPS\Theme::i()->getTemplate( 'trees', 'core' )->row( $url, $page->id, $page->seo_name, false, $page->getButtons( \IPS\Http\url::internal('app=cms&module=pages&controller=pages'), true ), "", 'file-text-o', NULL, FALSE, NULL, NULL, NULL, FALSE, FALSE, FALSE );
}
/**
* Return HTML for a folder row
*
* @param array $row Row data
* @param object $url \IPS\Http\Url object
* @return string HTML
*/
public static function getFolderRow( $folder, $url )
{
return \IPS\Theme::i()->getTemplate( 'trees', 'core' )->row( $url, $folder->id, $folder->name, true, $folder->getButtons( \IPS\Http\url::internal('app=cms&module=pages&controller=pages') ), "", 'folder-o', NULL );
}
/**
* Fetch rows of folders/pages
*
* @param int $folderId Parent ID to fetch from
*/
public static function getRowsForTree( $folderId=0 )
{
try
{
if ( $folderId === 0 )
{
$folders = \IPS\cms\Pages\Folder::roots();
}
else
{
$folders = \IPS\cms\Pages\Folder::load( $folderId )->children( NULL, NULL, FALSE );
}
}
catch( \OutOfRangeException $ex )
{
$folders = array();
}
$pages = \IPS\cms\Pages\Page::getChildren( $folderId );
return \IPS\cms\Pages\Folder::munge( $folders, $pages );
}
/**
* Redirect after save
*
* @param \IPS\Node\Model $old A clone of the node as it was before or NULL if this is a creation
* @param \IPS\Node\Model $node The node now
* @return void
*/
protected function _afterSave( \IPS\Node\Model $old = NULL, \IPS\Node\Model $new )
{
if( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->json( array() );
}
else
{
if( isset( \IPS\Request::i()->save_and_reload ) )
{
$buttons = $new->getButtons( $this->url, !( $new instanceof $this->nodeClass ) );
\IPS\Output::i()->redirect( $buttons['edit']['link'], 'saved' );
}
else
{
\IPS\Output::i()->redirect( $this->url->setQueryString( array( 'root' => ( $new->parent() ? $new->parent()->_id : '' ) ) ), 'saved' );
}
}
}
}
@@ -0,0 +1,583 @@
<?php
/**
* @brief Templates Controller
* @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 25 Feb 2013
* @version SVN_VERSION_NUMBER
*/
namespace IPS\cms\modules\admin\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;
}
/**
* templates
*/
class _templates extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'template_manage' );
parent::execute();
}
/**
* Import the IN_DEV templates
*
* @return void
*/
public function importInDev()
{
\IPS\cms\Theme::importInDev('database');
\IPS\cms\Theme::importInDev('page');
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=pages&controller=templates' ), 'completed' );
}
/**
* List templates
*
* @return void
*/
public function manage()
{
\IPS\Dispatcher::i()->checkAcpPermission( 'template_add_edit' );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__cms_pages_templates');
if ( \IPS\Theme::designersModeEnabled() )
{
$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_theme_designer_mode_warning', NULL, array( 'sprintf' => array( $link ) ) ), 'information', NULL, FALSE );
}
else
{
$request = array(
't_location' => ( isset( \IPS\Request::i()->t_location ) ) ? \IPS\Request::i()->t_location : NULL,
't_group' => ( isset( \IPS\Request::i()->t_group ) ) ? \IPS\Request::i()->t_group : NULL,
't_key' => ( isset( \IPS\Request::i()->t_key ) ) ? \IPS\Request::i()->t_key : NULL,
't_type' => ( isset( \IPS\Request::i()->t_type ) ) ? \IPS\Request::i()->t_type : 'templates',
);
switch ( $request['t_type'] )
{
default:
case 'template':
$flag = \IPS\cms\Templates::RETURN_ONLY_TEMPLATE;
break;
case 'js':
$flag = \IPS\cms\Templates::RETURN_ONLY_JS;
break;
case 'css':
$flag = \IPS\cms\Templates::RETURN_ONLY_CSS;
break;
}
$templates = \IPS\cms\Templates::buildTree( \IPS\cms\Templates::getTemplates( $flag + \IPS\cms\Templates::RETURN_DATABASE_ONLY ) );
$current = NULL;
if ( !empty( $request['t_key'] ) )
{
try
{
$current = \IPS\cms\Templates::load( $request['t_key'] );
}
catch ( \OutOfRangeException $ex )
{
}
}
/* Load first block */
if ( $current === NULL )
{
foreach ( $templates as $type => $_templates )
{
if ( $_templates )
{
$test = key( $_templates );
try
{
$current = \IPS\cms\Templates::load( $test );
}
catch ( \OutofRangeException $e )
{
foreach ( $_templates as $location => $group )
{
foreach ( $group as $name => $template )
{
$current = $template;
break 3;
}
}
}
}
}
}
/* Display */
\IPS\Output::i()->responsive = FALSE;
/* A button */
if ( \IPS\IN_DEV )
{
\IPS\Output::i()->sidebar['actions']['add'] = array(
'icon' => 'cog',
'title' => 'content_import_dev_templates',
'link' => \IPS\Http\Url::internal( "app=cms&module=pages&controller=templates&do=importInDev" ),
'data' => array()
);
}
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'codemirror/diff_match_patch.js', 'core', 'interface' ) );
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'codemirror/codemirror.js', 'core', 'interface' ) );
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'codemirror/codemirror.css', 'core', 'interface' ) );
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'templates/templates.css', 'cms', 'admin' ) );
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'admin_templates.js', 'cms' ) );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'templates' )->templates( $templates, $current, $request );
}
}
/**
* Add Container
*
* @return void
*/
public function addContainer()
{
/* Check permission */
\IPS\Dispatcher::i()->checkAcpPermission( 'template_add' );
$type = \IPS\Request::i()->type;
/* Build form */
$form = new \IPS\Helpers\Form();
$form->add( new \IPS\Helpers\Form\Text( 'container_name', NULL, TRUE ) );
$form->hiddenValues['type'] = $type;
if ( $values = $form->values() )
{
$type = \IPS\Request::i()->type;
$newContainer = \IPS\cms\Templates\Container::add( array(
'name' => $values['container_name'],
'type' => 'template_' . $type
) );
if( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->json( array(
'id' => $newContainer->id,
'name' => $newContainer->title,
) );
}
else
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=pages&controller=templates' ), 'saved' );
}
}
/* Display */
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( 'content_template_add_container_' . $type, $form, FALSE );
}
/**
* Add Template
* This is never used for editing as this is done via the template manager
*
* @return void
*/
public function addTemplate()
{
/* Check permission */
\IPS\Dispatcher::i()->checkAcpPermission( 'template_add' );
$type = \IPS\Request::i()->type;
/* Build form */
$form = new \IPS\Helpers\Form();
$form->hiddenValues['type'] = $type;
$form->add( new \IPS\Helpers\Form\Text( 'template_title', NULL, TRUE ) );
/* Very specific */
if ( $type === 'database' )
{
$groups = array(); /* I was sorely tempted to put 'Radiohead', 'Beatles' in there */
foreach( \IPS\cms\Databases::$templateGroups as $key => $group )
{
$groups[ $key ] = \IPS\Member::loggedIn()->language()->addToStack( 'cms_new_db_template_group_' . $key );
}
$form->add( new \IPS\Helpers\Form\Select( 'database_template_type', NULL, FALSE, array(
'options' => $groups
) ) );
$databases = array( 0 => \IPS\Member::loggedIn()->language()->addToStack('cms_new_db_assign_to_db_none' ) );
foreach( \IPS\cms\Databases::databases() as $obj )
{
$databases[ $obj->id ] = $obj->_title;
}
$form->add( new \IPS\Helpers\Form\Select( 'database_assign_to', NULL, FALSE, array(
'options' => $databases
) ) );
}
else if ( $type === 'block' )
{
$plugins = array();
foreach ( \IPS\Db::i()->select( "*", 'core_widgets', array( 'embeddable=1') ) as $widget )
{
try
{
$plugins[ \IPS\Application::load( $widget['app'] )->_title ][ $widget['app'] . '__' . $widget['key'] ] = \IPS\Member::loggedIn()->language()->addToStack( 'block_' . $widget['key'] );
}
catch ( \OutOfRangeException $e ) { }
}
$form->add( new \IPS\Helpers\Form\Select( 'block_template_plugin_import', NULL, FALSE, array(
'options' => $plugins
) ) );
$form->add( new \IPS\Helpers\Form\Node( 'block_template_theme_import', NULL, TRUE, array(
'class' => '\IPS\Theme'
) ) );
}
else
{
/* Page, css, js */
switch( $type )
{
default:
$flag = \IPS\cms\Theme::RETURN_ONLY_TEMPLATE;
break;
case 'page':
$flag = \IPS\cms\Theme::RETURN_PAGE;
break;
case 'js':
$flag = \IPS\cms\Theme::RETURN_ONLY_JS;
break;
case 'css':
$flag = \IPS\cms\Theme::RETURN_ONLY_CSS;
break;
}
$templates = \IPS\cms\Theme::i()->getRawTemplates( array(), array(), array(), $flag | \IPS\cms\Theme::RETURN_ALL_NO_CONTENT );
$groups = array();
if ( isset( $templates['cms'][ $type ] ) )
{
foreach( $templates['cms'][ $type ] as $group => $data )
{
$groups[ $group ] = \IPS\cms\Templates::readableGroupName( $group );
}
}
if ( ! count( $groups ) )
{
$groups[ $type ] = \IPS\cms\Templates::readableGroupName( $type );
}
$form->add( new \IPS\Helpers\Form\Radio( 'theme_template_group_type', 'existing', FALSE, array(
'options' => array( 'existing' => 'theme_template_group_o_existing',
'new' => 'theme_template_group_o_new' ),
'toggles' => array( 'existing' => array( 'group_existing' ),
'new' => array( 'group_new' ) )
) ) );
$form->add( new \IPS\Helpers\Form\Text( 'template_group_new', NULL, FALSE, array( 'regex' => '/^([a-z0-9_]+?)?$/' ), NULL, NULL, NULL, 'group_new' ) );
$form->add( new \IPS\Helpers\Form\Select( 'template_group_existing', NULL, FALSE, array( 'options' => $groups ), NULL, NULL, NULL, 'group_existing' ) );
}
if ( ! \IPS\Request::i()->isAjax() AND $type !== 'database' )
{
$form->add( new \IPS\Helpers\Form\TextArea( 'template_content', NULL ) );
}
if ( $values = $form->values() )
{
$type = \IPS\Request::i()->type;
if ( $type == 'database' )
{
/* We need to copy templates */
$group = \IPS\cms\Databases::$templateGroups[ $values['database_template_type' ] ];
$templates = iterator_to_array( \IPS\Db::i()->select( '*', 'cms_templates', array( 'template_location=? AND template_group=? AND template_user_edited=0 AND template_user_created=0', 'database', $group ) ) );
foreach( $templates as $template )
{
unset( $template['template_id'] );
$template['template_original_group'] = $template['template_group'];
$template['template_group'] = str_replace( '-', '_', \IPS\Http\Url::seoTitle( $values['template_title'] ) );
$save = array();
foreach( $template as $k => $v )
{
$k = \mb_substr( $k, 9 );
$save[ $k ] = $v;
}
/* Make sure template tags call the correct group */
if ( mb_stristr( $save['content'], '{template' ) )
{
preg_match_all( '/\{([a-z]+?=([\'"]).+?\\2 ?+)}/', $save['content'], $matches, PREG_SET_ORDER );
/* Work out the plugin and the values to pass */
foreach( $matches as $index => $array )
{
preg_match_all( '/(.+?)=' . $array[ 2 ] . '(.+?)' . $array[ 2 ] . '\s?/', $array[ 1 ], $submatches );
$plugin = array_shift( $submatches[ 1 ] );
if ( $plugin == 'template' )
{
$value = array_shift( $submatches[ 2 ] );
$options = array();
foreach ( $submatches[ 1 ] as $k => $v )
{
$options[ $v ] = $submatches[ 2 ][ $k ];
}
if ( isset( $options['app'] ) and $options['app'] == 'cms' and isset( $options['location'] ) and $options['location'] == 'database' and isset( $options['group'] ) and $options['group'] == $template['template_original_group'] )
{
$options['group'] = $template['template_group'];
$replace = '{template="' . $value . '" app="' . $options['app'] . '" location="' . $options['location'] . '" group="' . $options['group'] . '" params="' . ( isset($options['params']) ? $options['params'] : NULL ) . '"}';
$save['content'] = str_replace( $matches[$index][0], $replace, $save['content'] );
}
}
}
}
$newTemplate = \IPS\cms\Templates::add( $save );
}
if ( $values['database_assign_to'] )
{
try
{
$db = \IPS\cms\Databases::load( $values['database_assign_to'] );
$key = 'template_' . $values['database_template_type'];
$db->$key = $template['template_group'];
$db->save();
}
catch( \OutOfRangeException $ex ) { }
}
}
else if ( $type === 'block' )
{
$save = array(
'title' => str_replace( '-', '_', \IPS\Http\Url::seoTitle( $values['template_title'] ) ),
'params' => isset( $values['template_params'] ) ? $values['template_params'] : null,
'location' => $type
);
/* Get template */
list( $widgetApp, $widgetKey ) = explode( '__', $values['block_template_plugin_import'] );
/* Find it from the normal template system */
$plugin = \IPS\Widget::load( \IPS\Application::load( $widgetApp ), $widgetKey, uniqid(), array() );
$location = $plugin->getTemplateLocation();
$theme = ( \IPS\IN_DEV ) ? \IPS\Theme::master() : $values['block_template_theme_import'];
$templateBits = $theme->getRawTemplates( $location['app'], $location['location'], $location['group'], \IPS\Theme::RETURN_ALL );
$templateBit = $templateBits[ $location['app'] ][ $location['location'] ][ $location['group'] ][ $location['name'] ];
$save['content'] = $templateBit['template_content'];
$save['params'] = $templateBit['template_data'];
$save['group'] = $widgetKey;
$newTemplate = \IPS\cms\Templates::add( $save );
}
else
{
$save = array( 'title' => $values['template_title'] );
/* Page, css, js */
if ( $type == 'js' or $type == 'css' )
{
$fileExt = ( $type == 'js' ) ? '.js' : ( $type == 'css' ? '.css' : NULL );
if ( $fileExt AND ! preg_match( '#' . preg_quote( $fileExt, '#' ) . '$#', $values['template_title'] ) )
{
$values['template_title'] .= $fileExt;
}
$save['title'] = $values['template_title'];
$save['type'] = $type;
}
if ( $type === 'page' AND $values['theme_template_group_type'] == 'existing' AND $values['template_group_existing'] == 'custom_wrappers' )
{
$save['params'] = '$html=NULL, $title=NULL';
}
if ( $type === 'page' AND $values['theme_template_group_type'] == 'existing' AND $values['template_group_existing'] == 'page_builder' )
{
$save['params'] = '$page, $widgets';
}
$save['group'] = ( $values['theme_template_group_type'] == 'existing' ) ? $values['template_group_existing'] : $values['template_group_new'];
if ( isset( $values['template_content'] ) )
{
$save['content'] = $values['template_content'];
}
$save['location'] = $type;
$newTemplate = \IPS\cms\Templates::add( $save );
}
/* Done */
if( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->json( array(
'id' => $newTemplate->id,
'title' => $newTemplate->title,
'params' => $newTemplate->params,
'desc' => $newTemplate->description,
'container' => $newTemplate->container,
'location' => $newTemplate->location
) );
}
else
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=pages&controller=templates' ), 'saved' );
}
}
/* Display */
$title = \strip_tags( \IPS\Member::loggedIn()->language()->get( 'content_template_add_template_' . $type ) );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->block( $title, $form, FALSE );
\IPS\Output::i()->title = $title;
}
/**
* Delete a template
* This can be either a CSS template or a HTML template
*
* @return void
*/
public function delete()
{
/* Check permission */
\IPS\Dispatcher::i()->checkAcpPermission( 'template_delete' );
$key = \IPS\Request::i()->t_key;
$return = array(
'template_content' => NULL,
'template_id' => NULL
);
try
{
\IPS\cms\Templates::load( $key )->delete();
/* Now reload */
try
{
$template = \IPS\cms\Templates::load( $key );
$return['template_location'] = $template->location;
$return['template_content'] = $template->content;
$return['template_id'] = $template->id;
$return['InheritedValue'] = ( $template->user_added ) ? 'custom' : ( $template->user_edited ? 'changed' : 0 );
}
catch( \OutOfRangeException $ex )
{
}
}
catch( \OutOfRangeException $ex )
{
\IPS\Output::i()->error( 'node_error', '3S121/1', 500, '' );
}
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
if( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->json( $return );
}
else
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=pages&controller=templates' ), 'completed' );
}
}
/**
* Saves a template
*
* @return void
*/
public function save()
{
$key = \IPS\Request::i()->t_key;
$contentKey = 'editor_' . $key;
$content = \IPS\Request::i()->$contentKey;
$description = \IPS\Request::i()->t_description;
$variables = isset( \IPS\Request::i()->t_variables ) ? \IPS\Request::i()->t_variables : '';
try
{
$obj = \IPS\cms\Templates::load( $key );
$obj->location = \IPS\Request::i()->t_location;
$obj->group = empty( \IPS\Request::i()->t_group ) ? null : \IPS\Request::i()->t_group;
$obj->title = \IPS\Request::i()->t_name;
$obj->params = $variables;
$obj->content = $content;
if( $description )
{
$obj->description = $description;
}
$obj->save();
$url = array(
't_location' => $obj->location,
't_group' => $obj->group,
't_key' => $key
);
}
catch( \Exception $ex )
{
\IPS\Output::i()->json( array( 'msg' => $ex->getMessage() ) );
}
/* reload to return new item Id */
$obj = \IPS\cms\Templates::load( $key );
/* Clear guest page caches */
\IPS\Data\Cache::i()->clearAll();
if( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->json( array( 'template_id' => $obj->id, 'template_title' => $obj->title, 'template_container' => $obj->container, 'template_user_added' => $obj->user_created ) );
}
else
{
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=cms&module=pages&controller=templates&' . implode( '&', $url ) ), 'completed' );
}
}
}