Version 4.0.13.1
This commit is contained in:
1 parent
f9e857d255
commit
c6a86f0d9b
7517 files changed
+597400
-668041
No files matched your search
@@ -0,0 +1,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, '' );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user