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' );
}
}
}
Whitespace-only changes.
@@ -0,0 +1,37 @@
<?php
/**
* @brief Ajax only methods
* @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
* @subpackage Content
* @since 01 Oct 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\cms\modules\front\database;
/* 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;
}
/**
* Ajax only methods
*/
class _ajax extends \IPS\Content\Controller
{
/**
* Return a FURL
*
* @return void
*/
protected function makeFurl()
{
return \IPS\Output::i()->json( array( 'slug' => \IPS\Http\Url::seoTitle( \IPS\Request::i()->slug ) ) );
}
}
@@ -0,0 +1,474 @@
<?php
/**
* @brief [Database] Category 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 Content
* @since 16 April 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\cms\modules\front\database;
/* 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
*/
class _category extends \IPS\cms\Databases\Controller
{
/**
* Determine which method to load
*
* @return void
*/
public function manage()
{
$this->view();
}
/**
* Clear any filters
*
* @return void
*/
public function clearFilters()
{
$catClass = 'IPS\cms\Categories' . \IPS\cms\Databases\Dispatcher::i()->databaseId;
try
{
$category = $catClass::loadAndCheckPerms( \IPS\cms\Databases\Dispatcher::i()->categoryId );
$category->saveFilterCookie( FALSE );
\IPS\Output::i()->redirect( $category->url(), 'cms_filters_cleared' );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2T254/1', 403, '' );
}
}
/**
* Display a category. Please.
*
* @return void
*/
public function view()
{
$category = NULL;
$fieldClass = 'IPS\cms\Fields' . \IPS\cms\Databases\Dispatcher::i()->databaseId;
$catClass = 'IPS\cms\Categories' . \IPS\cms\Databases\Dispatcher::i()->databaseId;
$database = \IPS\cms\Databases::load( \IPS\cms\Databases\Dispatcher::i()->databaseId );
$breadcrumbs = NULL;
try
{
$category = $catClass::loadAndCheckPerms( \IPS\cms\Databases\Dispatcher::i()->categoryId );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2T254/2', 403, '' );
}
$customFields = $fieldClass::data( 'view', $category, $fieldClass::FIELD_SKIP_TITLE_CONTENT );
if ( ! $database->use_categories )
{
$breadcrumbs = \IPS\Output::i()->breadcrumb;
}
/* Check cookie */
$activeFilters = array();
$where = array();
$cookie = $category->getFilterCookie();
if ( $cookie !== NULL )
{
foreach( $cookie as $f => $v )
{
$k = 'content_field_' . $f;
if ( isset( $customFields[ $f ] ) and !isset( \IPS\Request::i()->$k ) and $v !== '___any___' )
{
if ( is_array( $v ) )
{
$like = array();
foreach( $v as $val )
{
if ( $val === 0 or ! empty( $val ) )
{
$like[] = "CONCAT( ',', " . mb_substr( $k, 8 ) . ", ',') LIKE '%," . \IPS\Db::i()->real_escape_string( $val ) . ",%'";
}
}
$where[] = array( '( ' . \IPS\Db::i()->in( mb_substr( $k, 8 ), $v ) . ( count( $like ) ? " OR (" . implode( ' OR ', $like ) . ') )' : ')' ) );
}
else
{
if ( $v !== 0 and ! $v )
{
$where[] = array( mb_substr( $k, 8 ) . " IS NULL" );
}
else
{
$where[] = array( mb_substr( $k, 8 ) . "=?", $v );
}
}
$activeFilters[ $f ] = array( 'field' => $customFields[ $f ], 'value' => $customFields[ $f ]->displayValue( $v ) );
}
}
}
if ( ! count( $where ) )
{
$where = NULL;
}
$table = new \IPS\Helpers\Table\Content( 'IPS\cms\Records' . \IPS\cms\Databases\Dispatcher::i()->databaseId, $category->url(), $where, $category, NULL );
$table->tableTemplate = array( \IPS\cms\Theme::i()->getTemplate( $category->_template_listing, 'cms', 'database' ), 'categoryTable' );
$table->rowsTemplate = array( \IPS\cms\Theme::i()->getTemplate( $category->_template_listing, 'cms', 'database' ), 'recordRow' );
$table->baseUrl = $table->baseUrl->setQueryString( 'd', \IPS\cms\Databases\Dispatcher::i()->databaseId );
$table->hover = TRUE;
$table->sortBy = ( isset( \IPS\Request::i()->sortby ) ) ? \IPS\Request::i()->sortby : ( $database->field_sort ? $database->field_sort : 'record_last_comment' );
$table->sortDirection = ( isset( \IPS\Request::i()->sortdirection ) ) ? \IPS\Request::i()->sortdirection : ( $database->field_direction ? $database->field_direction : 'desc' );
$table->limit = $database->field_perpage ? $database->field_perpage : 25;
$table->title = \IPS\Member::loggedIn()->language()->addToStack( $database->use_categories ? 'x_records_in_this_category' : 'x_records' , FALSE, array( 'sprintf' => array( $category->records, $database->recordWord( $category->records ) ) ) );
/* Make sure table doesn't add breadcrumbs if we're not using categories */
if ( ! $database->use_categories )
{
\IPS\Output::i()->breadcrumb = $breadcrumbs;
}
/* Custom Search */
$filterOptions = array(
'all' => 'content_all_records',
'open' => 'content_open_records',
'locked' => 'content_locked_records',
);
$timeFrameOptions = array(
'show_all' => 'show_all',
'today' => 'today',
'last_5_days' => 'last_5_days',
'last_7_days' => 'last_7_days',
'last_10_days' => 'last_10_days',
'last_15_days' => 'last_15_days',
'last_20_days' => 'last_20_days',
'last_25_days' => 'last_25_days',
'last_30_days' => 'last_30_days',
'last_60_days' => 'last_60_days',
'last_90_days' => 'last_90_days',
);
if ( \IPS\Member::loggedIn()->member_id AND \IPS\Member::loggedIn()->last_visit)
{
$timeFrameOptions['since_last_visit'] = \IPS\Member::loggedIn()->language()->addToStack('since_last_visit', FALSE, array( 'sprintf' => array( \IPS\DateTime::ts( \IPS\Member::loggedIn()->last_visit ) ) ) );
}
$sortBy = array(
'record_last_comment' => 'content_record_last_comment',
'record_comments' => 'content_record_comments',
'record_views' => 'content_record_views',
'field_' . $database->field_title => 'content_record_title',
'record_publish_date' => 'content_record_publish_date'
);
if ( !isset( $sortBy[ $database->field_sort ] ) )
{
switch ( $database->field_sort )
{
case 'primary_id_field':
$sortBy[ $database->field_sort ] = 'database_field__id';
$table->sortOptions['database_field__id'] = $database->field_sort;
\IPS\Member::loggedIn()->language()->words['sort_database_field__id'] = \IPS\Member::loggedIn()->language()->addToStack('database_field__id');
break;
case 'member_id':
$sortBy[ $database->field_sort ] = 'database_field__member';
$table->sortOptions['database_field__member'] = $database->field_sort;
\IPS\Member::loggedIn()->language()->words['sort_database_field__member'] = \IPS\Member::loggedIn()->language()->addToStack('database_field__member');
break;
case 'rating_real':
$sortBy[ $database->field_sort ] = 'database_field__rating';
$table->sortOptions['database_field__rating'] = $database->field_sort;
\IPS\Member::loggedIn()->language()->words['sort_database_field__rating'] = \IPS\Member::loggedIn()->language()->addToStack('database_field__rating');
break;
}
}
if ( !$database->options['comments'] )
{
unset ( $sortBy['record_last_comment'] );
unset ( $sortBy['record_comments'] );
unset ( $table->sortOptions['record_last_comment'] );
unset ( $table->sortOptions['record_comments'] );
unset ( $table->sortOptions['last_comment'] );
unset ( $table->sortOptions['num_comments'] );
}
else
{
unset( $table->sortOptions['updated'] );
}
if ( !$database->options['reviews'] )
{
unset ( $table->sortOptions['num_reviews'] );
unset( $table->sortOptions['rating'] );
}
/* If the sort field isn't one of the above, best add it */
if ( mb_substr( $database->field_sort, 0, 6 ) === 'field_' )
{
if ( $database->field_title !== mb_substr( $database->field_sort, 6 ) )
{
$sortBy[ $database->field_sort ] = \IPS\Member::loggedIn()->language()->addToStack( 'content_field_' . mb_substr( $database->field_sort, 6 ) );
}
}
$table->advancedSearch = array(
'record_type' => array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => $filterOptions ) ),
'sortby' => array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => $sortBy ) ),
'sortdirection' => array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => array(
'asc' => 'asc',
'desc' => 'desc',
) )
),
'time_frame' => array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => $timeFrameOptions ) ),
);
foreach( $customFields as $obj )
{
if ( $obj->filter )
{
\IPS\Member::loggedIn()->language()->words['content_field_' . $obj->id ] = $obj->_title;
$table->advancedSearch[ 'content_field_' . $obj->id ] = array( \IPS\Helpers\Table\SEARCH_SELECT, array( 'options' => $obj->extra, 'multiple' => TRUE, 'noDefault' => true ) );
$table->advancedSearch['sortby'][1]['options']['field_' . $obj->id ] = 'content_field_' . $obj->id;
}
$table->sortOptions[ 'field_' . $obj->id ] = 'field_' . $obj->id;
}
$table->advancedSearchCallback = function( $table, $values ) use ( $database, $sortBy )
{
/* Type */
foreach( $values as $k => $v )
{
if ( mb_substr( $k, 0, 14 ) === 'content_field_' )
{
if ( is_array( $v ) )
{
$like = array();
foreach( $v as $val )
{
if ( $val === 0 or ! empty( $val ) )
{
$like[] = "CONCAT( ',', " . mb_substr( $k, 8 ) . ", ',') LIKE '%," . \IPS\Db::i()->real_escape_string( $val ) . ",%'";
}
}
$table->where[] = array( '( ' . \IPS\Db::i()->in( mb_substr( $k, 8 ), $v ) . ( count( $like ) ? " OR (" . implode( ' OR ', $like ) . ') )' : ')' ) );
}
else
{
if ( $v !== '___any___' )
{
if ( $v !== 0 and ! $v )
{
$table->where[] = array( mb_substr( $k, 8 ) . " IS NULL" );
}
else
{
$table->where[] = array( mb_substr( $k, 8 ) . "=?", $v );
}
}
}
}
}
if ( isset( $values['record_type'] ) )
{
switch ( $values['record_type'] )
{
case 'open':
$table->where[] = 'record_locked=0';
break;
case 'locked':
$table->where[] = 'record_locked=1';
break;
}
}
/* Sort */
if ( isset( $values['sortby'] ) and isset( $sortBy[ $values['sortby'] ] ) )
{
$table->sortBy = $values['sortby'];
$table->sortDirection = $values['sortdirection'];
}
/* Cutoff */
$days = NULL;
if ( isset( $values['time_frame'] ) )
{
switch ( $values['time_frame'] )
{
case 'today':
$days = 1;
break;
case 'last_5_days':
$days = 5;
break;
case 'last_7_days':
$days = 7;
break;
case 'last_10_days':
$days = 10;
break;
case 'last_15_days':
$days = 15;
break;
case 'last_20_days':
$days = 20;
break;
case 'last_25_days':
$days = 25;
break;
case 'last_30_days':
$days = 30;
break;
case 'last_60_days':
$days = 60;
break;
case 'last_90_days':
$days = 90;
break;
case 'since_last_visit':
$table->where[] = array( 'record_last_comment>?', \IPS\Member::loggedIn()->last_visit );
break;
}
if ( $days !== NULL )
{
$table->where[] = array( 'record_last_comment>?', \IPS\DateTime::create()->sub( new \DateInterval( 'P' . $days . 'D' ) ) );
}
}
};
/* RSS */
if ( $database->rss )
{
$rssUrl = $table->baseUrl->setQueryString('rss', 1 );
$rssName = $database->_title . ': ' . $category->_title;
\IPS\Output::i()->rssFeeds[ $rssName ] = $rssUrl;
/* Show RSS feed */
if ( isset( \IPS\Request::i()->rss ) )
{
$rssName = \IPS\Member::loggedIn()->language()->get('content_db_' . $database->id ) . ': ' . \IPS\Member::loggedIn()->language()->get('content_cat_name_' . $category->id );
$document = \IPS\Xml\Rss::newDocument( $table->baseUrl, $rssName, $rssName );
$contentField = 'field_' . $database->field_content;
foreach ( $table->getRows( array() ) as $record )
{
if ( ! $record->hidden() )
{
$document->addItem( $record->_title, $record->url(), $record->$contentField, \IPS\DateTime::ts( $record->record_last_comment ), $record->_id );
}
}
/* @note application/rss+xml is not a registered IANA mime-type so we need to stick with text/xml for RSS */
\IPS\Output::i()->sendOutput( $document->asXML(), 200, 'text/xml' );
}
}
/* Update location */
$permissions = $category->permissions();
\IPS\Session::i()->setLocation( $category->url(), explode( ",", $permissions['perm_view'] ), 'loc_cms_viewing_db_cat', array( 'content_db_' . $database->id => TRUE, 'content_cat_name_' . $category->id => TRUE ) );
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'records/list.css', 'cms', 'front' ) );
\IPS\cms\Databases\Dispatcher::i()->output .= \IPS\cms\Theme::i()->getTemplate( $category->_template_listing, 'cms', 'database' )->categoryHeader( $category, (string) $table, $activeFilters );
if ( ( $category->hasChildren() AND $category->show_records ) OR ! $category->hasChildren() )
{
\IPS\cms\Databases\Dispatcher::i()->output .= (string) $table;
}
\IPS\cms\Databases\Dispatcher::i()->output .= \IPS\cms\Theme::i()->getTemplate( $category->_template_listing, 'cms', 'database' )->categoryFooter( $category, (string) $table, $activeFilters );
}
/**
* Form
*
* @return void
*/
public function form()
{
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js('front_records.js', 'cms' ) );
$database = \IPS\cms\Databases::load( \IPS\cms\Databases\Dispatcher::i()->databaseId );
$recordClass = '\IPS\cms\Records' . \IPS\cms\Databases\Dispatcher::i()->databaseId;
$categoryClass = '\IPS\cms\Categories' . \IPS\cms\Databases\Dispatcher::i()->databaseId;
$category = $categoryClass::loadAndCheckPerms( \IPS\cms\Databases\Dispatcher::i()->categoryId );
$fieldsClass = '\IPS\cms\Fields' . \IPS\cms\Databases\Dispatcher::i()->databaseId;
$title = \IPS\Member::loggedIn()->language()->addToStack( 'content_record_form_new_record', FALSE, array( 'sprintf' => array( $database->recordWord( 1, TRUE ) ) ) );
$form = $recordClass::create( $category );
$form->class = 'ipsForm_vertical';
$hasModOptions = FALSE;
if ( $recordClass::modPermission( 'lock', NULL, $category ) or
$recordClass::modPermission( 'pin', NULL, $category ) or
$recordClass::modPermission( 'hide', NULL, $category ) or
$recordClass::modPermission( 'feature', NULL, $category ) )
{
$hasModOptions = TRUE;
}
\IPS\Output::i()->sidebar['enabled'] = FALSE;
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\cms\Theme::i(), 'getTemplate' ), array( $database->template_form, 'cms', 'database' ) ), 'recordForm' ), NULL, $category, $database, \IPS\cms\Pages\Page::$currentPage, $title, $hasModOptions );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( $title );
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'records/form.css', 'cms', 'front' ) );
try
{
if ( $database->use_categories )
{
foreach( $category->parents() AS $parent )
{
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
}
\IPS\Output::i()->breadcrumb[] = array( $category->url(), $category->_title );
}
}
catch( \Exception $e ) {}
\IPS\Output::i()->breadcrumb[] = array( NULL, $title );
}
/**
* Mark Read
*
* @return void
*/
protected function markRead()
{
\IPS\Session::i()->csrfCheck();
try
{
$meowBreed = '\IPS\cms\Categories' . \IPS\cms\Databases\Dispatcher::i()->databaseId;
$meow = $meowBreed::load( \IPS\cms\Databases\Dispatcher::i()->categoryId );
\IPS\cms\Records::markContainerRead( $meow );
\IPS\Output::i()->redirect( $meow->url() );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'module_no_permission', '2T254/3', 403, '' );
}
}
}
Whitespace-only changes.
@@ -0,0 +1,165 @@
<?php
/**
* @brief [Database] Category List 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 16 April 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\cms\modules\front\database;
/* 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;
}
/**
* List
*/
class _index extends \IPS\cms\Databases\Controller
{
/**
* Determine which method to load
*
* @return void
*/
public function manage()
{
$database = \IPS\cms\Databases::load( \IPS\cms\Databases\Dispatcher::i()->databaseId );
/* Not using categories? */
if ( ! $database->use_categories AND $database->cat_index_type === 0 )
{
$controller = new \IPS\cms\modules\front\database\category( $this->url );
return $controller->view();
}
$this->view();
}
/**
* Display database category list.
*
* @return void
*/
protected function view()
{
$database = \IPS\cms\Databases::load( \IPS\cms\Databases\Dispatcher::i()->databaseId );
$recordClass = 'IPS\cms\Records' . \IPS\cms\Databases\Dispatcher::i()->databaseId;
$url = \IPS\Http\Url::internal( "app=cms&module=pages&controller=page&path=" . \IPS\cms\Pages\Page::$currentPage->full_path, 'front', 'content_page_path', \IPS\cms\Pages\Page::$currentPage->full_path );
/* RSS */
if ( $database->rss )
{
/* Show the link */
\IPS\Output::i()->rssFeeds[ $database->_title ] = $url->setQueryString( 'rss', 1 );
/* Or actually show RSS feed */
if ( isset( \IPS\Request::i()->rss ) )
{
$document = \IPS\Xml\Rss::newDocument( $url, \IPS\Member::loggedIn()->language()->get('content_db_' . $database->id ), \IPS\Member::loggedIn()->language()->get('content_db_' . $database->id . '_desc' ) );
$contentField = 'field_' . $database->field_content;
foreach ( $recordClass::getItemsWithPermission( array(), $database->field_sort . ' ' . $database->field_direction, $database->rss, 'read' ) as $record )
{
$document->addItem( $record->_title, $record->url(), $record->$contentField, \IPS\DateTime::ts( $record->_publishDate ), $record->_id );
}
/* @note application/rss+xml is not a registered IANA mime-type so we need to stick with text/xml for RSS */
\IPS\Output::i()->sendOutput( $document->asXML(), 200, 'text/xml' );
}
}
$page = isset( \IPS\Request::i()->page ) ? intval( \IPS\Request::i()->page ) : 1;
if( $page < 1 )
{
$page = 1;
}
if ( $database->cat_index_type === 1 and ! isset( \IPS\Request::i()->show ) )
{
/* Featured */
$limit = 0;
$count = 0;
if ( isset( \IPS\Request::i()->page ) )
{
$limit = $database->featured_settings['perpage'] * ( $page - 1 );
}
$where = ( $database->featured_settings['featured'] ) ? array( array( 'record_featured=?', 1 ) ) : NULL;
$articles = $recordClass::getItemsWithPermission( $where, 'record_pinned DESC, ' . $database->featured_settings['sort'] . ' ' . $database->featured_settings['direction'], array( $limit, $database->featured_settings['perpage'] ), 'read', FALSE, 0, NULL, FALSE, FALSE, FALSE, FALSE );
if ( $database->featured_settings['pagination'] )
{
$count = $recordClass::getItemsWithPermission( $where, 'record_pinned DESC, ' . $database->featured_settings['sort'] . ' ' . $database->featured_settings['direction'], $database->featured_settings['perpage'], 'read', FALSE, 0, NULL, FALSE, FALSE, FALSE, TRUE );
}
/* Pagination */
$pagination = array(
'page' => $page,
'pages' => ( $count > 0 ) ? ceil( $count['cnt'] / $database->featured_settings['perpage'] ) : 1
);
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'database_index/featured.css', 'cms', 'front' ) );
\IPS\cms\Databases\Dispatcher::i()->output .= \IPS\Output::i()->output = \IPS\cms\Theme::i()->getTemplate( $database->template_featured, 'cms', 'database' )->index( $database, $articles, $url, $pagination );
}
else
{
/* Category view */
$class = '\IPS\cms\Categories' . $database->id;
$categories = $class::roots('view', \IPS\Member::loggedIn(), null, $database->_id );
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'records/index.css', 'cms', 'front' ) );
\IPS\cms\Databases\Dispatcher::i()->output .= \IPS\Output::i()->output = \IPS\cms\Theme::i()->getTemplate( $database->template_categories, 'cms', 'database' )->index( $database, $categories, $url );
}
}
/**
* Show the pre add record form. This is used when no category is set.
*
* @return void
*/
protected function form()
{
$form = new \IPS\Helpers\Form( 'select_category', 'continue' );
$form->class = 'ipsForm_vertical ipsForm_noLabels';
$form->add( new \IPS\Helpers\Form\Node( 'category', NULL, TRUE, array(
'url' => \IPS\cms\Pages\Page::$currentPage->url()->setQueryString('do', 'form'),
'class' => 'IPS\cms\Categories' . \IPS\cms\Databases\Dispatcher::i()->databaseId,
'permissionCheck' => function( $node )
{
if ( $node->can( 'view' ) )
{
if ( $node->can( 'add' ) )
{
return TRUE;
}
return FALSE;
}
return NULL;
},
) ) );
if ( $values = $form->values() )
{
\IPS\Output::i()->redirect( $values['category']->url()->setQueryString( 'do', 'form' ) );
}
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'cms_select_category' );
\IPS\Output::i()->breadcrumb[] = array( NULL, \IPS\Member::loggedIn()->language()->addToStack( 'cms_select_category' ) );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'records' )->categorySelector( $form );
}
}
@@ -0,0 +1,753 @@
<?php
/**
* @brief Record View
* @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
* @subpackage Content
* @since 17 Apr 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\cms\modules\front\database;
/* 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;
}
/**
* Record View
*/
class _record extends \IPS\Content\Controller
{
/**
* [Content\Controller] Class
*/
protected static $contentModel = NULL;
/**
* Constructor
*
* @param \IPS\Http\Url|NULL $url The base URL for this controller or NULL to calculate automatically
* @return void
*/
public function __construct( $url=NULL )
{
static::$contentModel = 'IPS\cms\Records' . \IPS\cms\Databases\Dispatcher::i()->databaseId;
parent::__construct( \IPS\cms\Databases\Dispatcher::i()->url );
}
/**
* View Record
*
* @return void
*/
protected function manage()
{
/* Load record */
try
{
$record = parent::manage();
}
catch( \Exception $e )
{
\IPS\Output::i()->error( 'node_error', '3T252/1', 403, '' );
}
if ( $record === NULL )
{
\IPS\Output::i()->error( 'node_error', '3T252/2', 403, '' );
}
if ( \IPS\Request::i()->view )
{
$this->_doViewCheck();
}
/* Sort out comments and reviews */
$tabs = $record->commentReviewTabs();
$_tabs = array_keys( $tabs );
$tab = isset( \IPS\Request::i()->tab ) ? \IPS\Request::i()->tab : array_shift( $_tabs );
$activeTabContents = $record->commentReviews( $tab );
$comments = count( $tabs ) ? \IPS\cms\Theme::i()->getTemplate( $record->container()->_template_display, 'cms', 'database' )->commentsAndReviewsTabs( \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $tab, $activeTabContents, $record->url(), 'tab', FALSE, TRUE ), md5( $record->url() ) ) : NULL;
if ( \IPS\Request::i()->isAjax() and isset( \IPS\Request::i()->tab ) )
{
\IPS\Output::i()->sendOutput( $activeTabContents, 200, 'text/html', \IPS\Output::i()->httpHeaders );
}
$class = '\IPS\cms\Categories' . $record::$customDatabaseId;
$category = $class::load( $record->category_id );
$FieldsClass = '\\IPS\\cms\\Fields' . $record::$customDatabaseId;
$updateFields = $FieldsClass::fields( $record->fieldValues(), 'edit', $record->container(), $FieldsClass::FIELD_SKIP_TITLE_CONTENT | $FieldsClass::FIELD_DISPLAY_COMMENTFORM );
$form = null;
if ( count( $updateFields ) )
{
$form = new \IPS\Helpers\Form( 'update_record', 'update', $record->url()->setQueryString( array( 'd' => $record::$customDatabaseId ) ) );
$form->class = 'ipsForm_vertical';
foreach( $updateFields as $id => $field )
{
$form->add( $field );
}
$form->add( new \IPS\Helpers\Form\Checkbox( 'record_display_field_change', TRUE, FALSE ) );
if ( $values = $form->values() )
{
if ( ! $record->canEdit() )
{
\IPS\Output::i()->error( 'module_no_permission', '2T252/3', 403, '' );
}
/* Custom fields */
$customValues = array();
$fieldsClass = 'IPS\cms\Fields' . $record::$customDatabaseId;
foreach( $values as $k => $v )
{
if ( mb_substr( $k, 0, 14 ) === 'content_field_' )
{
$customValues[ mb_substr( $k, 8 ) ] = $v;
}
}
if ( count( $customValues ) )
{
if ( $values['record_display_field_change'] )
{
$record->addCommentWhenFiltersChanged( $values );
}
foreach( $fieldsClass::fields( $customValues, 'edit', $record->category_id ? $category : NULL, $FieldsClass::FIELD_SKIP_TITLE_CONTENT | $FieldsClass::FIELD_DISPLAY_COMMENTFORM) as $key => $field )
{
$key = 'field_' . $key;
$record->$key = $field::stringValue( isset( $values[ $field->name ] ) ? $values[ $field->name ] : NULL );
}
$record->save();
$record->processAfterEdit( $values );
\IPS\Output::i()->redirect( $record->url() );
}
}
}
if ( $record->record_meta_keywords )
{
\IPS\Output::i()->metaTags['keywords'] = $record->record_meta_keywords;
}
if ( $record->record_meta_description )
{
\IPS\Output::i()->metaTags['description'] = $record->record_meta_description;
\IPS\Output::i()->metaTags['og:description'] = $record->record_meta_description;
}
/* Update location */
if( $record->database()->use_categories )
{
\IPS\Session::i()->setLocation( $record->url(), $record->onlineListPermissions(), 'loc_cms_viewing_db_record', array( $record->_title => FALSE, 'content_db_' . $record->database()->id => TRUE ,'content_cat_name_' . $category->id => TRUE ) );
}
else
{
\IPS\Session::i()->setLocation( $record->url(), $record->onlineListPermissions(), 'loc_cms_viewing_db_record_no_cats', array( $record->_title => FALSE, 'content_db_' . $record->database()->id => TRUE ) );
}
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'records/record.css', 'cms', 'front' ) );
/* Next unread */
try
{
$nextUnread = $record->nextUnread();
}
catch( \Exception $e )
{
$nextUnread = NULL;
}
if ( $record->record_image )
{
\IPS\Output::i()->metaTags['og:image'] = (string) \IPS\File::get( 'cms_Records', $record->record_image )->url;
}
\IPS\cms\Databases\Dispatcher::i()->output .= \IPS\cms\Theme::i()->getTemplate( $record->container()->_template_display, 'cms', 'database' )->record( $record, $comments, $form, $nextUnread );
}
/**
* Set the breadcrumb and title
*
* @param \IPS\Content\Item $item Content item
* @param bool $link Link the content item element in the breadcrumb
* @return void
*/
protected function _setBreadcrumbAndTitle( $item, $link=TRUE )
{
if ( \IPS\cms\Databases::load( \IPS\cms\Databases\Dispatcher::i()->databaseId )->use_categories )
{
parent::_setBreadcrumbAndTitle( $item, $link );
}
else
{
\IPS\Output::i()->breadcrumb[] = array( $link ? $item->url() : NULL, $item->mapped('title') );
$title = ( isset( \IPS\Request::i()->page ) and \IPS\Request::i()->page > 1 ) ? \IPS\Member::loggedIn()->language()->addToStack( 'title_with_page_number', FALSE, array( 'sprintf' => array( $item->mapped('title'), \IPS\Request::i()->page ) ) ) : $item->mapped('title');
\IPS\Output::i()->title = $title;
}
}
/**
* View check
*
* @return void
*/
protected function _doViewCheck()
{
try
{
$class = static::$contentModel;
$topic = $class::loadAndCheckPerms( \IPS\Request::i()->id );
switch( \IPS\Request::i()->view )
{
case 'getnewpost':
\IPS\Output::i()->redirect( $topic->url( 'getNewComment' ) );
break;
case 'getlastpost':
\IPS\Output::i()->redirect( $topic->url( 'getLastComment' ) );
break;
}
}
catch( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'node_error', '2F173/F', 403, '' );
}
}
/**
* Revisions
*
* @return void
*/
protected function revisions()
{
$recordClass = '\IPS\cms\Records' . \IPS\cms\Databases\Dispatcher::i()->databaseId;
try
{
$record = $recordClass::loadAndCheckPerms( \IPS\Request::i()->id );
$category = $record->container();
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'module_no_permission', '2T252/4', 403, '' );
}
if ( ! $record->canManageRevisions() )
{
\IPS\Output::i()->error( 'module_no_permission', '2T252/5', 403, '' );
}
$title = \IPS\Member::loggedIn()->language()->addToStack('content_revision_record_title', FALSE, array( 'sprintf' => array( $record->_title ) ) );
$table = new \IPS\Helpers\Table\Db( 'cms_database_revisions', $record->url('revisions'), array( 'revision_database_id=? and revision_record_id=?', $record::$customDatabaseId, $record->_id ) );
$table->tableTemplate = array( \IPS\Theme::i()->getTemplate( 'revisions', 'cms', 'front' ), 'table' );
$table->rowsTemplate = array( \IPS\Theme::i()->getTemplate( 'revisions', 'cms', 'front' ), 'rows' );
$table->title = $title;
$table->include = array( 'revision_id', 'revision_date', 'revision_data', 'revision_member_id' );
$table->mainColumn = 'revision_date';
$table->sortBy = $table->sortBy ?: 'revision_date';
$table->sortDirection = $table->sortDirection ?: 'desc';
/* Parsers */
$table->parsers = array(
'revision_member_id' => function( $val )
{
return \IPS\Member::load( $val );
},
'revision_date' => function( $val )
{
return \IPS\DateTime::ts( $val )->relative();
},
'revision_data' => function( $val, $row ) use ( $record )
{
return \IPS\cms\Records\Revisions::load( $row['revision_id'] )->getDiffHtmlTables( $record::$customDatabaseId, $record, true );
}
);
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'system/diff.css', 'core', 'admin' ) );
/* Output */
if ( \IPS\Request::i()->isAjax() )
{
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->blankTemplate( $table ), 200, 'text/html', \IPS\Output::i()->httpHeaders );
}
else
{
try
{
foreach( $category->parents() AS $parent )
{
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
}
\IPS\Output::i()->breadcrumb[] = array( $category->url(), $category->_title );
}
catch( \Exception $e ) {}
\IPS\Output::i()->breadcrumb[] = array( $record->url(), $record->_title );
\IPS\Output::i()->title = $title;
\IPS\Output::i()->output .= (string) $table;
}
}
/**
* Delete Revision
*
* @return void
*/
protected function revisionDelete()
{
\IPS\Session::i()->csrfCheck();
$recordClass = '\IPS\cms\Records' . \IPS\cms\Databases\Dispatcher::i()->databaseId;
try
{
$record = $recordClass::loadAndCheckPerms( \IPS\Request::i()->id );
$category = $record->container();
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'module_no_permission', '2T252/6', 403, '' );
}
try
{
$revision = \IPS\cms\Records\Revisions::load( \IPS\Request::i()->revision_id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'module_no_permission', '2T252/7', 403, '' );
}
if ( ! $record->canManageRevisions() )
{
\IPS\Output::i()->error( 'module_no_permission', '2T252/8', 403, '' );
}
$revision->delete();
if ( isset( \IPS\Request::i()->ajax ) )
{
\IPS\Output::i()->redirect( $record->url() );
}
else
{
\IPS\Output::i()->redirect( $record->url('revisions') );
}
}
/**
* View Revision
*
* @return void
*/
protected function revisionView()
{
$recordClass = '\IPS\cms\Records' . \IPS\cms\Databases\Dispatcher::i()->databaseId;
try
{
$record = $recordClass::loadAndCheckPerms( \IPS\Request::i()->id );
$category = $record->container();
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'module_no_permission', '2T252/9', 403, '' );
}
try
{
$revision = \IPS\cms\Records\Revisions::load( \IPS\Request::i()->revision_id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'module_no_permission', '2T252/A', 403, '' );
}
if ( ! $record->canManageRevisions() )
{
\IPS\Output::i()->error( 'module_no_permission', '2T252/B', 403, '' );
}
$title = \IPS\Member::loggedIn()->language()->addToStack('content_revision_record_title', FALSE, array( 'sprintf' => array( $record->_title ) ) );
$fieldsClass = 'IPS\cms\Fields' . $record::$customDatabaseId;
$customFields = $fieldsClass::data( 'view', $category );
$conflicts = array();
$form = new \IPS\Helpers\Form( 'form', 'content_revision_restore' );
require_once \IPS\ROOT_PATH . "/system/3rd_party/Diff/class.Diff.php";
/* Build up our data set */
foreach( $customFields as $id => $field )
{
$key = 'field_' . $field->id;
if ( $record->$key AND $revision->get( $key ) )
{
if ( md5( $record->$key ) != md5( $revision->get( $key ) ) )
{
$conflicts[ $key ] = array(
'revision' => $revision->get( $key ),
'record' => $record->$key,
'field' => $field,
'diff' => \Diff::toTable( \Diff::compare( $revision->get( $key ), $record->$key ) )
);
$form->add( new \IPS\Helpers\Form\Radio( 'conflict_' . $field->id, 'no', false, array( 'options' => array( 'old' => '', 'new' => '' ) ) ) );
}
}
}
if ( $values = $form->values() )
{
foreach( $values as $k => $v )
{
if ( $v === 'old' )
{
$fieldId = mb_substr( $k, 9 );
$key = 'field_' . $fieldId;
$record->$key = $revision->get( $key );
}
\IPS\Session::i()->modLog( 'modlog__content_revision_restored', array( $record->_title => FALSE, $revision->id => FALSE ) );
$record->save();
$revision->delete();
\IPS\Output::i()->redirect( $record->url('revisions') );
}
}
try
{
foreach( $category->parents() AS $parent )
{
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
}
\IPS\Output::i()->breadcrumb[] = array( $category->url(), $category->_title );
}
catch( \Exception $e ) {}
\IPS\Output::i()->breadcrumb[] = array( $record->url(), $record->_title );
\IPS\Output::i()->breadcrumb[] = array( $record->url()->setQueryString( array( 'do' => 'revisions', 'd' => $record::$customDatabaseId ) ), $title );
\IPS\Output::i()->title = $title;
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'system/diff.css', 'core', 'admin' ) );
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'revisions', 'cms' ), 'view' ), $record, $revision, $conflicts );
}
/**
* Edit Item
*
* @return void
*/
protected function edit()
{
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js('front_records.js', 'cms' ) );
$recordClass = '\IPS\cms\Records' . \IPS\cms\Databases\Dispatcher::i()->databaseId;
$database = \IPS\cms\Databases::load( \IPS\cms\Databases\Dispatcher::i()->databaseId );
try
{
$record = $recordClass::loadAndCheckPerms( \IPS\Request::i()->id );
$category = $record->container();
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'module_no_permission', '2T252/C', 403, '' );
}
$title = \IPS\Member::loggedIn()->language()->addToStack( 'content_record_form_edit_record', FALSE, array( 'sprintf' => array( $record->_title ) ) );
$formElements = $recordClass::formElements( $record, $category );
if ( \IPS\Request::i()->id AND ! $record->canEdit() )
{
\IPS\Output::i()->error( 'module_no_permission', '2T252/D', 403, '' );
}
$form = new \IPS\Helpers\Form( 'form', isset( \IPS\Member::loggedIn()->language()->words[ $recordClass::$formLangPrefix . '_save' ] ) ? $recordClass::$formLangPrefix . '_save' : 'save' );
$form->class = 'ipsForm_vertical';
foreach( $formElements as $name => $field )
{
$form->add( $field );
}
$hasModOptions = FALSE;
if ( $recordClass::modPermission( 'lock', NULL, $category ) or
$recordClass::modPermission( 'pin', NULL, $category ) or
$recordClass::modPermission( 'hide', NULL, $category ) or
$recordClass::modPermission( 'feature', NULL, $category ) )
{
$hasModOptions = TRUE;
}
if ( $values = $form->values() )
{
$record->processForm( $values );
$record->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 )
{
$record->$column = $values[ $recordClass::$formLangPrefix . 'date' ]->getTimestamp();
}
else
{
$record->$column = time();
}
}
$record->save();
\IPS\Output::i()->redirect( $record->url() );
}
\IPS\Output::i()->sidebar['enabled'] = FALSE;
\IPS\Output::i()->output = $form->customTemplate( array( call_user_func_array( array( \IPS\cms\Theme::i(), 'getTemplate' ), array( $database->template_form, 'cms', 'database' ) ), 'recordForm' ), NULL, $category, $database, \IPS\cms\Pages\Page::$currentPage, $title, $hasModOptions );
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( $title );
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'records/form.css', 'cms', 'front' ) );
try
{
if ( $database->use_categories )
{
foreach( $category->parents() AS $parent )
{
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
}
\IPS\Output::i()->breadcrumb[] = array( $category->url(), $category->_title );
}
}
catch( \Exception $e ) {}
\IPS\Output::i()->breadcrumb[] = array( $record->url(), $record->mapped('title') );
}
/**
* Mark Topic Read
*
* @return void
*/
public function markRead()
{
\IPS\Session::i()->csrfCheck();
try
{
$record = $this->_getRecord();
$record->markRead();
\IPS\Output::i()->redirect( $record->url() );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'module_no_permission', '2F173/C', 403, 'module_no_permission_guest' );
}
}
/**
* Return a record based on query string 'id' param
*
* @return \IPS\cms\Records
*/
public function _getRecord()
{
$recordClass = '\IPS\cms\Records' . \IPS\cms\Databases\Dispatcher::i()->databaseId;
try
{
$record = $recordClass::loadAndCheckPerms( \IPS\Request::i()->id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'module_no_permission', '2T252/E', 403, '' );
}
return $record;
}
/* IP.Board integration */
/**
* Hide Comment/Review
*
* @param string $commentClass The comment/review class
* @param \IPS\Content\Comment $comment The comment/review
* @param \IPS\Content\Item $item The item
* @return void
* @throws \LogicException
*/
public function _hide( $commentClass, $comment, $item )
{
return $this->_doSomething( '_hide', $commentClass, $comment, $item );
}
/**
* Unhide Comment/Review
*
* @param string $commentClass The comment/review class
* @param \IPS\Content\Comment $comment The comment/review
* @param \IPS\Content\Item $item The item
* @return void
* @throws \LogicException
*/
public function _unhide( $commentClass, $comment, $item )
{
return $this->_doSomething( '_unhide', $commentClass, $comment, $item );
}
/**
* Split Comment
*
* @param string $commentClass The comment/review class
* @param \IPS\Content\Comment $comment The comment/review
* @param \IPS\Content\Item $item The item
* @return void
* @throws \LogicException
*/
protected function _split( $commentClass, $comment, $item )
{
return $this->_doSomething( '_split', $commentClass, $comment, $item );
}
/**
* Edit Comment/Review
*
* @param string $commentClass The comment/review class
* @param \IPS\Content\Comment $comment The comment/review
* @param \IPS\Content\Item $item The item
* @return void
* @throws \LogicException
*/
protected function _edit( $commentClass, $comment, $item )
{
return $this->_doSomething( '_edit', $commentClass, $comment, $item );
}
/**
* Report Comment/Review
*
* @param string $commentClass The comment/review class
* @param \IPS\Content\Comment $comment The comment/review
* @param \IPS\Content\Item $item The item
* @return void
* @throws \LogicException
*/
protected function _report( $commentClass, $comment, $item )
{
return $this->_doSomething( '_report', $commentClass, $comment, $item );
}
/**
* Edit Log
*
* @param string $commentClass The comment/review class
* @param \IPS\Content\Comment $comment The comment/review
* @param \IPS\Content\Item $item The item
* @return void
* @throws \LogicException
*/
public function _editlog( $commentClass, $comment, $item )
{
return $this->_doSomething( '_editlog', $commentClass, $comment, $item );
}
/**
* Delete Comment/Review
*
* @param string $commentClass The comment/review class
* @param \IPS\Content\Comment $comment The comment/review
* @param \IPS\Content\Item $item The item
* @return void
* @throws \LogicException
*/
protected function _delete( $commentClass, $comment, $item )
{
return $this->_doSomething( '_delete', $commentClass, $comment, $item );
}
/**
* Rep Comment/Review
*
* @param string $commentClass The comment/review class
* @param \IPS\Content\Comment $comment The comment/review
* @param \IPS\Content\Item $item The item
* @return void
* @throws \LogicException
*/
protected function _rep( $commentClass, $comment, $item )
{
return $this->_doSomething( '_rep', $commentClass, $comment, $item );
}
/**
* Show Comment/Review Rep
*
* @param string $commentClass The comment/review class
* @param \IPS\Content\Comment $comment The comment/review
* @param \IPS\Content\Item $item The item
* @return void
* @throws \LogicException
*/
protected function _showRep( $commentClass, $comment, $item )
{
return $this->_doSomething( '_showRep', $commentClass, $comment, $item );
}
/**
* Do something that needs to be overriden from the Content controller
*
* @param string $method The method name
* @param string $commentClass The comment/review class
* @param \IPS\Content\Comment $comment The comment/review
* @param \IPS\Content\Item $item The item
* @return void
* @throws \LogicException
*/
protected function _doSomething( $method, $commentClass, $comment, $item )
{
$record = $this->_getRecord();
if ( $record->useForumComments() AND isset( \IPS\Request::i()->comment) )
{
$commentClass = 'IPS\cms\Records\CommentTopicSync' . $record::$customDatabaseId;
$comment = $commentClass::load( \IPS\Request::i()->comment );
$item = $record;
}
try
{
return parent::$method( $commentClass, $comment, $item );
}
catch( \LogicException $e )
{
\IPS\Output::i()->error( 'node_error', '2T252/F', 403, '' );
}
}
}
Whitespace-only changes.
@@ -0,0 +1,307 @@
<?php
/**
* @brief [Front] Page 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 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\cms\modules\front\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
*/
class _builder extends \IPS\core\modules\front\system\widgets
{
/**
* Preview a block (from the ACP or elsewhere dynamically)
*
* @return html
*/
public function previewBlock()
{
$output = "";
if ( isset( \IPS\Request::i()->block_plugin ) )
{
$block = new \IPS\cms\Blocks\Block;
$block->type = "plugin";
$block->plugin = \IPS\Request::i()->block_plugin;
$block->plugin_app = ( isset( \IPS\Request::i()->block_plugin_app ) ) ? \IPS\Request::i()->block_plugin_app : \IPS\Request::i()->block_app;
$block->plugin_plugin = \IPS\Request::i()->block_plugin_plugin;
$block->key = md5( uniqid() );
$params = array();
$block->content = NULL;
if ( isset( \IPS\Request::i()->_sending ) )
{
foreach( explode( ",", \IPS\Request::i()->_sending ) as $field )
{
if ( $field and isset( \IPS\Request::i()->$field ) )
{
if ( $field == 'block_content' )
{
$block->content = \IPS\Request::i()->$field;
if ( isset( \IPS\Request::i()->template_params ) )
{
$block->template_params = \IPS\Request::i()->template_params;
}
continue;
}
$params[ $field ] = \IPS\Request::i()->$field;
}
}
}
$block->plugin_config = json_encode( $params );
/* Template stuffs */
if ( \IPS\Request::i()->block_template_use_how == 'copy' )
{
$block->widget()->template( array( $block, 'getTemplate' ) );
}
$output = $block->widget()->render();
}
\IPS\Output::i()->sendOutput( \IPS\Theme::i()->getTemplate( 'global', 'core' )->blankTemplate( $output ), 200, 'text/html', \IPS\Output::i()->httpHeaders );
}
/**
* Get Output For Adding A New Block
*
* @return void
*/
protected function getBlock()
{
$key = $block = explode( "_", \IPS\Request::i()->blockID );
if ( isset( \IPS\Request::i()->pageID ) )
{
try
{
foreach ( \IPS\Db::i()->select( '*', 'cms_page_widget_areas', array( 'area_page_id=?', \IPS\Request::i()->pageID ) ) as $item )
{
$blocks = json_decode( $item['area_widgets'], TRUE );
foreach( $blocks as $block )
{
if( $block['key'] == $key[2] AND $block['unique'] == $key[3] )
{
if ( isset( $block['app'] ) and $block['app'] == $key[1] )
{
$widget = \IPS\Widget::load( \IPS\Application::load( $block['app'] ), $block['key'], $block['unique'], $block['configuration'], null, \IPS\Request::i()->orientation );
}
elseif ( isset( $block['plugin'] ) and $block['plugin'] == $key[1] )
{
$widget = \IPS\Widget::load( \IPS\Plugin::load( $block['plugin'] ), $block['key'], $block['unique'], $block['configuration'], null, \IPS\Request::i()->orientation );
}
}
}
}
}
catch ( \UnderflowException $e ) { }
/* Make sure the current page is set so the widgets have database/page scope */
\IPS\cms\Pages\Page::$currentPage = \IPS\cms\Pages\Page::load( \IPS\Request::i()->pageID );
/* Have we got a database for this page? */
$database = \IPS\cms\Pages\Page::$currentPage->getDatabase();
if ( $database )
{
\IPS\cms\Databases\Dispatcher::i()->setDatabase( $database->id );
}
}
if ( !isset( $widget ) )
{
try
{
$widget = \IPS\Widget::load( \IPS\Application::load( $key[1] ), $key[2], $key[3], array(), null, \IPS\Request::i()->orientation );
}
catch ( \OutOfRangeException $e )
{
$widget = \IPS\Widget::load( \IPS\Plugin::load( $key[1] ), $key[2], $key[3], array(), null, \IPS\Request::i()->orientation );
}
}
$output = (string) $widget;
\IPS\Output::i()->output = ( $output ) ? $output : \IPS\Theme::i()->getTemplate( 'widgets', 'core', 'front' )->blankWidget( $widget );
}
/**
* Get Configuration
*
* @return void
*/
protected function getConfiguration()
{
/* Standard widget area, allow the core stuff to handle this */
if( in_array( \IPS\Request::i()->area, array( 'sidebar', 'header', 'footer' ) ) )
{
return parent::getConfiguration();
}
$key = explode( "_", \IPS\Request::i()->block );
$blocks = array( 'area_widgets' => NULL );
/* CMS only stuff */
try
{
$blocks = \IPS\Db::i()->select( '*', 'cms_page_widget_areas', array( 'area_page_id=? AND area_area=?', \IPS\Request::i()->pageID, \IPS\Request::i()->pageArea ) )->first();
$where = ( $key[0] ) == 'app' ? '`key`=? AND `app`=?' : '`key`=? AND `plugin`=?';
$widgetMaster = \IPS\Db::i()->select( '*', 'core_widgets', array( $where, $key[2], $key[1] ) )->first();
}
catch ( \UnderflowException $e )
{
}
$blocks = json_decode( $blocks['area_widgets'], TRUE );
$widget = NULL;
if( !empty( $blocks ) )
{
foreach ( $blocks as $k => $block )
{
if ( $block['key'] == $key[2] AND $block['unique'] == $key[3] )
{
if ( isset( $block['app'] ) and $block['app'] == $key[1] )
{
$widget = \IPS\Widget::load( \IPS\Application::load( $block['app'] ), $block['key'], $block['unique'], $block['configuration'] );
$widget->menuStyle = $widgetMaster['menu_style'];
}
elseif ( isset( $block['plugin'] ) and $block['plugin'] == $key[1] )
{
$widget = \IPS\Widget::load( \IPS\Plugin::load( $block['plugin'] ), $block['key'], $block['unique'], $block['configuration'] );
$widget->menuStyle = $widgetMaster['menu_style'];
}
}
if( $widget !== NULL AND method_exists( $widget, 'configuration' ) )
{
$form = new \IPS\Helpers\Form( 'form', 'saveSettings' );
if ( $widget->configuration( $form ) !== NULL )
{
if ( $values = $form->values() )
{
if ( method_exists( $widget, 'preConfig' ) )
{
$values = $widget->preConfig( $values );
}
$blocks[ $k ]['configuration'] = $values;
\IPS\Db::i()->insert( 'cms_page_widget_areas', array( 'area_page_id' => \IPS\Request::i()->pageID, 'area_area' => \IPS\Request::i()->pageArea, 'area_widgets' => json_encode( $blocks ) ), TRUE );
\IPS\Output::i()->json( 'OK' );
}
\IPS\Output::i()->sendOutput( $widget->configuration()->customTemplate( array( call_user_func_array( array( \IPS\Theme::i(), 'getTemplate' ), array( 'widgets', 'core' ) ), 'formTemplate' ), $widget ) );
}
}
}
}
}
/**
* Reorder Blocks
*
* @return void
*/
protected function saveOrder()
{
$newOrder = array();
$seen = array();
try
{
$currentConfig = \IPS\Db::i()->select( '*', 'cms_page_widget_areas', array( 'area_page_id=? AND area_area=?', \IPS\Request::i()->pageID, \IPS\Request::i()->area ) )->first();
$widgets = json_decode( $currentConfig['area_widgets'], TRUE );
}
catch ( \UnderflowException $e )
{
$widgets = array();
}
/* Loop over the new order and merge in current blocks so we don't lose config */
if ( isset ( \IPS\Request::i()->order ) )
{
foreach ( \IPS\Request::i()->order as $block )
{
$block = explode( "_", $block );
$added = FALSE;
foreach( $widgets as $widget )
{
if ( $widget['key'] == $block[2] and $widget['unique'] == $block[3] )
{
$seen[] = $widget['unique'];
$newOrder[] = $widget;
$added = TRUE;
break;
}
}
if( !$added )
{
$newBlock = array();
if ( $block[0] == 'app' )
{
$newBlock['app'] = $block[1];
}
else
{
$newBlock['plugin'] = $block[1];
}
$newBlock['key'] = $block[2];
$newBlock['unique'] = $block[3];
$newBlock['configuration'] = array();
/* Make sure this widget doesn't have configuration in another area */
$newBlock['configuration'] = \IPS\cms\Widget::getConfiguration( $newBlock['unique'] );
$seen[] = $block[3];
$newOrder[] = $newBlock;
}
}
}
/* Anything to update? */
if ( count( $widgets ) > count( $newOrder ) )
{
/* No items left in area, or one has been removed */
foreach( $widgets as $widget )
{
/* If we haven't seen this widget, it's been removed, so add to trash */
if ( ! in_array( $widget['unique'], $seen ) )
{
\IPS\Widget::trash( $widget['unique'], $widget );
}
}
}
/* Expire Caches so up to date information displays */
\IPS\Widget::deleteCaches();
/* Save to database */
$orientation = ( isset( \IPS\Request::i()->orientation ) and \IPS\Request::i()->orientation === 'vertical' ) ? 'vertical' : 'horizontal';
\IPS\Db::i()->replace( 'cms_page_widget_areas', array( 'area_orientation' => $orientation, 'area_page_id' => \IPS\Request::i()->pageID, 'area_widgets' => json_encode( $newOrder ), 'area_area' => \IPS\Request::i()->area ) );
\IPS\cms\Pages\Page::load( \IPS\Request::i()->pageID )->postWidgetOrderSave();
}
}
Whitespace-only changes.
@@ -0,0 +1,265 @@
<?php
/**
* @brief [Front] Page 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 2014
* @version SVN_VERSION_NUMBER
*/
namespace IPS\cms\modules\front\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
*/
class _page extends \IPS\Dispatcher\Controller
{
/**
* Execute
*
* @return void
*/
public function execute()
{
parent::execute();
}
/**
* Determine which method to load
*
* @return void
*/
public function manage()
{
$this->view();
}
/**
* Display a page. Sounds simple doesn't it? Well it's not.
*
* @return void
*/
protected function view()
{
$page = $this->getPage();
/* Database specific checks */
if ( isset( \IPS\Request::i()->advancedSearchForm ) AND isset( \IPS\Request::i()->d ) )
{
/* showTableSearchForm just triggers __call which returns the database dispatcher HTML as we
* do not want the page content around the actual database */
\IPS\Output::i()->output = $this->showTableSearchForm();
return;
}
$includes = $page->getIncludes();
if ( isset( $includes['js'] ) and is_array( $includes['js'] ) )
{
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, array_values( $includes['js'] ) );
}
/* Display */
if ( $page->ipb_wrapper or $page->type === 'builder' )
{
$page->setTheme();
$nav = array();
\IPS\Output::i()->title = $page->getHtmlTitle();
/* This has to be done after setTheme(), otherwise \IPS\Theme::switchTheme() can wipe out CSS includes */
if ( isset( $includes['css'] ) and is_array( $includes['css'] ) )
{
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, array_values( $includes['css'] ) );
}
if ( $page->type === 'builder' )
{
list( $group, $name, $key ) = explode( '__', $page->template );
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('pages')->globalWrap( $nav, \IPS\cms\Theme::i()->getTemplate($group, 'cms', 'page')->$name( $page, $page->getWidgets() ), $page );
}
else
{
/* Populate \IPS\Output::i()->sidebar['widgets'] sidebar/header/footer widgets */
$page->getWidgets();
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('pages')->globalWrap( $nav, $page->getHtmlContent(), $page );
}
\IPS\Output::i()->sidebar['enabled'] = true;
/* Set the meta tags, but do not reset them if they are already set - articles can define custom meta tags and this code
overwrites the ones set by articles if we don't verify they aren't set first */
if ( $page->meta_keywords AND ( !isset( \IPS\Output::i()->metaTags['keywords'] ) OR !\IPS\Output::i()->metaTags['keywords'] ) )
{
\IPS\Output::i()->metaTags['keywords'] = $page->meta_keywords;
}
if ( $page->meta_description AND ( !isset( \IPS\Output::i()->metaTags['description'] ) OR !\IPS\Output::i()->metaTags['description'] ) )
{
\IPS\Output::i()->metaTags['description'] = $page->meta_description;
}
/* Can only disable sidebar if HTML page */
if ( ! $page->show_sidebar and $page->type === 'html' )
{
\IPS\Output::i()->sidebar['enabled'] = false;
}
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'pages/page.css', 'cms', 'front' ) );
if ( \IPS\Request::i()->path == $page->full_path )
{
/* Just viewing this page, no database categories or records */
$permissions = $page->permissions();
\IPS\Session::i()->setLocation( $page->url(), explode( ",", $permissions['perm_view'] ), 'loc_cms_viewing_page', array( 'cms_page_' . $page->_id => TRUE ) );
}
if ( ! ( \IPS\Application::load('cms')->default AND ! $page->folder_id AND $page->default ) )
{
\IPS\Output::i()->breadcrumb['module'] = array( $page->url(), $page->_title );
}
\IPS\Output::i()->allowDefaultWidgets = FALSE;
/* Let the dispatcher finish off and show page */
return;
}
else
{
if ( isset( $includes['css'] ) and is_array( $includes['css'] ) )
{
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, array_values( $includes['css'] ) );
}
if ( $page->wrapper_template and $page->wrapper_template !== '_none_' and ! \IPS\Request::i()->isAjax() )
{
try
{
list( $group, $name, $key ) = explode( '__', $page->wrapper_template );
\IPS\Output::i()->sendOutput( \IPS\cms\Theme::i()->getTemplate($group, 'cms', 'page')->$name( $page->getHtmlContent(), $page->getHtmlTitle() ), 200, $page->getContentType(), \IPS\Output::i()->httpHeaders );
}
catch( \OutOfRangeException $e )
{
}
}
/* Set the title */
\IPS\Output::i()->title = $page->getHtmlTitle();
\IPS\Member::loggedIn()->language()->parseOutputForDisplay( \IPS\Output::i()->title );
/* Send straight to the output engine */
\IPS\Output::i()->sendOutput( $page->getHtmlContent(), 200, $page->getContentType(), \IPS\Output::i()->httpHeaders );
}
}
/**
* Get the current page
*
* @return \IPS\cms\Pages\Page
*/
public function getPage()
{
$page = null;
if ( isset( \IPS\Request::i()->page_id ) )
{
try
{
$page = \IPS\cms\Pages\Page::load( \IPS\Request::i()->page_id );
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'content_err_page_404', '2T187/1', 404, '' );
}
}
else if ( isset( \IPS\Request::i()->path ) AND \IPS\Request::i()->path != '/' )
{
try
{
$page = \IPS\cms\Pages\Page::loadFromPath( \IPS\Request::i()->path );
}
catch ( \OutOfRangeException $e )
{
try
{
\IPS\Output::i()->redirect( \IPS\cms\Pages\Page::getUrlFromHistory( \IPS\Request::i()->path, ( isset( \IPS\Request::i()->url()->data['query'] ) ? \IPS\Request::i()->url()->data['query'] : NULL ) ), NULL, 301 );
}
catch( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'content_err_page_404', '2T187/2', 404, '' );
}
}
}
else
{
try
{
$page = \IPS\cms\Pages\Page::getDefaultPage();
}
catch ( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'content_err_page_404', '2T257/1', 404, '' );
}
}
if ( $page === NULL )
{
\IPS\Output::i()->error( 'content_err_page_404', '2T257/2', 404, '' );
}
if ( ! $page->can('view') )
{
\IPS\Output::i()->error( 'content_err_page_403', '2T187/3', 403, '' );
}
/* Set the current page, so other blocks, DBs, etc don't have to figure out where they are */
\IPS\cms\Pages\Page::$currentPage = $page;
return $page;
}
/**
* Capture database specific things
*
* @param string $method Desired method
* @param array $args Arguments
* @return void
*/
public function __call( $method, $args )
{
$page = $this->getPage();
$databaseId = ( isset( \IPS\Request::i()->d ) ) ? \IPS\Request::i()->d : $page->getDatabase()->_id;
if ( $databaseId !== NULL )
{
try
{
return \IPS\cms\Databases\Dispatcher::i()->setDatabase( $databaseId )->run();
}
catch( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'content_err_page_404', '2T257/3', 404, '' );
}
}
}
/**
* Embed
*
* @return void
*/
protected function embed()
{
return $this->__call( 'embed', func_get_args() );
}
}
View File
Whitespace-only changes.