Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @brief topic
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
@@ -12,36 +13,72 @@
|
||||
namespace IPS\cms\modules\front\database;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\cms\Categories;
|
||||
use IPS\cms\Databases;
|
||||
use IPS\cms\Fields;
|
||||
use IPS\cms\Pages\Page;
|
||||
use IPS\cms\Records;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\File;
|
||||
use IPS\forums\Topic as TopicClass;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Custom;
|
||||
use IPS\Helpers\Form\Editor;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Helpers\MultipleRedirect;
|
||||
use IPS\Helpers\Wizard;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Output;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use IPS\Request;
|
||||
use IPS\Session;
|
||||
use IPS\Theme;
|
||||
use LogicException;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* topic
|
||||
*/
|
||||
class _topic extends \IPS\Dispatcher\Controller
|
||||
class topic extends Controller
|
||||
{
|
||||
/**
|
||||
* @var TopicClass|null
|
||||
*/
|
||||
protected ?TopicClass $topic = null;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
if ( !\IPS\Member::loggedIn()->modPermission( 'can_copy_topic_database' ) )
|
||||
if ( !Member::loggedIn()->modPermission( 'can_copy_topic_database' ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2T353/1', 403, '' );
|
||||
Output::i()->error( 'node_error', '2T353/1', 403, '' );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$this->topic = \IPS\forums\Topic::load( \IPS\Request::i()->id );
|
||||
$this->topic = TopicClass::load( Request::i()->id );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2T353/3', 404, '' );
|
||||
Output::i()->error( 'node_error', '2T353/3', 404, '' );
|
||||
}
|
||||
|
||||
parent::execute();
|
||||
@@ -52,37 +89,37 @@ class _topic extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
$wizard = new \IPS\Helpers\Wizard( array(
|
||||
$wizard = new Wizard( array(
|
||||
'database' => array( $this, '_database' ),
|
||||
'category' => array( $this, '_category' ),
|
||||
), \IPS\Http\Url::internal( "app=cms&module=database&controller=topic&id=" . \IPS\Request::i()->id, 'front', 'topic_copy', $this->topic->title_seo ), FALSE );
|
||||
), Url::internal( "app=cms&module=database&controller=topic&id=" . Request::i()->id, 'front', 'topic_copy', $this->topic->title_seo ), FALSE );
|
||||
|
||||
/* Set Breadcrumb */
|
||||
foreach ( $this->topic->container()->parents() as $parent )
|
||||
{
|
||||
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
|
||||
Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->breadcrumb[] = array( $this->topic->container()->url(), $this->topic->container()->_title );
|
||||
Output::i()->breadcrumb[] = array( $this->topic->container()->url(), $this->topic->container()->_title );
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'copy_topic_to_database' );
|
||||
\IPS\Output::i()->output = (string) $wizard;
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack( 'copy_topic_to_database' );
|
||||
Output::i()->output = (string) $wizard;
|
||||
}
|
||||
|
||||
/**
|
||||
* Database
|
||||
*
|
||||
* @param mixed $data Data
|
||||
* @return void
|
||||
* @return array|string
|
||||
*/
|
||||
public function _database( $data )
|
||||
public function _database( mixed $data ) : array|string
|
||||
{
|
||||
$form = new \IPS\Helpers\Form( 'database', 'copy_select_database', \IPS\Http\Url::internal( "app=cms&module=database&controller=topic&id=" . \IPS\Request::i()->id, 'front', 'topic_copy', $this->topic->title_seo ) );
|
||||
$form->class = 'ipsForm_vertical';
|
||||
$form->hiddenValues['topic_id'] = \IPS\Request::i()->id;
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'database', NULL, TRUE, array( 'class' => '\IPS\cms\Databases', 'permissionCheck' => function( $row )
|
||||
$form = new Form( 'database', 'copy_select_database', Url::internal( "app=cms&module=database&controller=topic&id=" . Request::i()->id, 'front', 'topic_copy', $this->topic->title_seo ) );
|
||||
$form->class = 'ipsForm--vertical ipsForm--copy-database-topic';
|
||||
$form->hiddenValues['topic_id'] = Request::i()->id;
|
||||
$form->add( new Node( 'database', NULL, TRUE, array( 'class' => '\IPS\cms\Databases', 'permissionCheck' => function( $row )
|
||||
{
|
||||
/* If this database does not have a title or content field, we cannot copy. */
|
||||
if ( !$row->field_title OR !$row->field_content )
|
||||
@@ -106,39 +143,39 @@ class _topic extends \IPS\Dispatcher\Controller
|
||||
);
|
||||
}
|
||||
|
||||
return $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
|
||||
return $form->customTemplate( array( Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Category
|
||||
*
|
||||
* @param mixed $data Data
|
||||
* @return void
|
||||
* @return string
|
||||
*/
|
||||
public function _category( $data )
|
||||
public function _category( mixed $data ) : string
|
||||
{
|
||||
/* Do we need to even bother? */
|
||||
$database = \IPS\cms\Databases::load( $data['database_id'] );
|
||||
$database = Databases::load( $data['database_id'] );
|
||||
|
||||
if ( !$database->use_categories )
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=cms&module=database&controller=topic&do=form&id={$data['topic_id']}", 'front', 'topic_copy', $this->topic->title_seo )->setQueryString( array( 'database_id' => $data['database_id'], 'category_id' => $database->default_category ) ) );
|
||||
Output::i()->redirect( Url::internal( "app=cms&module=database&controller=topic&do=form&id={$data['topic_id']}", 'front', 'topic_copy', $this->topic->title_seo )->setQueryString( array( 'database_id' => $data['database_id'], 'category_id' => $database->default_category ) ) );
|
||||
}
|
||||
|
||||
$catClass = 'IPS\cms\Categories' . $data['database_id'];
|
||||
|
||||
$form = new \IPS\Helpers\Form( 'category', 'copy_select_category', \IPS\Http\Url::internal( "app=cms&module=database&controller=topic&id=" . \IPS\Request::i()->id, 'front', 'topic_copy', $this->topic->title_seo ) );
|
||||
$form->class = 'ipsForm_vertical';
|
||||
$form = new Form( 'category', 'copy_select_category', Url::internal( "app=cms&module=database&controller=topic&id=" . Request::i()->id, 'front', 'topic_copy', $this->topic->title_seo ) );
|
||||
$form->class = 'ipsForm--vertical ipsForm--copy-database-topic-category';
|
||||
$form->hiddenValues['topic_id'] = $data['topic_id'];
|
||||
$form->hiddenValues['database_id'] = $data['database_id'];
|
||||
$form->add( new \IPS\Helpers\Form\Node( 'select_category', NULL, TRUE, array( 'class' => $catClass, 'permissionCheck' => 'add' ) ) );
|
||||
$form->add( new Node( 'select_category', NULL, TRUE, array( 'class' => $catClass, 'permissionCheck' => 'add' ) ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=cms&module=database&controller=topic&do=form&id={$values['topic_id']}", 'front', 'topic_copy', $this->topic->title_seo )->setQueryString( array( 'database_id' => $values['database_id'], 'category_id' => $values['select_category']->_id ) ) );
|
||||
Output::i()->redirect( Url::internal( "app=cms&module=database&controller=topic&do=form&id={$values['topic_id']}", 'front', 'topic_copy', $this->topic->title_seo )->setQueryString( array( 'database_id' => $values['database_id'], 'category_id' => $values['select_category']->_id ) ) );
|
||||
}
|
||||
|
||||
return $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
|
||||
return $form->customTemplate( array( Theme::i()->getTemplate( 'forms', 'core' ), 'popupTemplate' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,33 +183,35 @@ class _topic extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function form()
|
||||
protected function form() : void
|
||||
{
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js('front_records.js', 'cms' ) );
|
||||
Output::i()->jsFiles = array_merge( Output::i()->jsFiles, Output::i()->js('front_records.js', 'cms' ) );
|
||||
|
||||
try
|
||||
{
|
||||
$database = \IPS\cms\Databases::load( \IPS\Request::i()->database_id );
|
||||
$database = Databases::load( Request::i()->database_id );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2T353/2', 404, '' );
|
||||
Output::i()->error( 'node_error', '2T353/2', 404, '' );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$page = \IPS\cms\Pages\Page::load( $database->page_id );
|
||||
$page = Page::load( $database->page_id );
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2T353/4', 404, '' );
|
||||
Output::i()->error( 'node_error', '2T353/4', 404, '' );
|
||||
}
|
||||
|
||||
|
||||
/* @var Categories $catClass
|
||||
* @var Records $recordClass
|
||||
* @var Fields $fieldClass */
|
||||
$recordClass = 'IPS\cms\Records' . $database->_id;
|
||||
$commentClass = 'IPS\cms\Comments' . $database->_id;
|
||||
$fieldClass = 'IPS\cms\Fields' . $database->_id;
|
||||
$catClass = 'IPS\cms\Categories' . $database->_id;
|
||||
$category = $catClass::load( \IPS\Request::i()->category_id );
|
||||
$category = $catClass::load( Request::i()->category_id );
|
||||
|
||||
$titleField = "field_{$database->field_title}";
|
||||
$contentField = "field_{$database->field_content}";
|
||||
@@ -180,27 +219,27 @@ class _topic extends \IPS\Dispatcher\Controller
|
||||
$fakeRecord = new $recordClass;
|
||||
$fakeRecord->$titleField = $this->topic->mapped('title');
|
||||
$fakeRecord->$contentField = $this->topic->content();
|
||||
$fakeRecord->category_id = \IPS\Request::i()->category_id;
|
||||
$fakeRecord->category_id = Request::i()->category_id;
|
||||
|
||||
if( $fakeRecord->_forum_record AND $fakeRecord->_forum_comments )
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['copy_comments_desc'] = sprintf( \IPS\Member::loggedIn()->language()->get( 'copy_comments_assoc_desc' ), $recordClass::_definiteArticle(), $recordClass::_definiteArticle() );
|
||||
Member::loggedIn()->language()->words['copy_comments_desc'] = sprintf( Member::loggedIn()->language()->get( 'copy_comments_assoc_desc' ), $recordClass::_definiteArticle(), $recordClass::_definiteArticle() );
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Member::loggedIn()->language()->words['copy_comments_desc'] = sprintf( \IPS\Member::loggedIn()->language()->get( 'copy_comments_desc' ), $recordClass::_definiteArticle() );
|
||||
Member::loggedIn()->language()->words['copy_comments_desc'] = sprintf( Member::loggedIn()->language()->get( 'copy_comments_desc' ), $recordClass::_definiteArticle() );
|
||||
}
|
||||
|
||||
\IPS\Member::loggedIn()->language()->words['copy_author_desc'] = sprintf( \IPS\Member::loggedIn()->language()->get( 'copy_author_desc' ), $recordClass::_definiteArticle() );
|
||||
Member::loggedIn()->language()->words['copy_author_desc'] = sprintf( Member::loggedIn()->language()->get( 'copy_author_desc' ), $recordClass::_definiteArticle() );
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->class = 'ipsForm_vertical';
|
||||
$form = new Form;
|
||||
$form->class = 'ipsForm--vertical ipsForm--copy-database-topic-categories';
|
||||
$form->hiddenValues['record_category_id'] = $category->_id;
|
||||
|
||||
foreach( $recordClass::formElements( $fakeRecord, $category ) AS $key => $element )
|
||||
{
|
||||
/* Skip these */
|
||||
if ( \in_array( $key, array( 'record_edit_reason', 'record_edit_show' ) ) )
|
||||
if ( in_array( $key, array( 'record_edit_reason', 'record_edit_show' ) ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -210,17 +249,17 @@ class _topic extends \IPS\Dispatcher\Controller
|
||||
|
||||
if ( $database->options['comments'] )
|
||||
{
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'copy_comments', FALSE, FALSE, array( 'togglesOn' => array( 'comments_show_message' ) ) ) );
|
||||
$form->add( new YesNo( 'copy_comments', FALSE, FALSE, array( 'togglesOn' => array( 'comments_show_message' ) ) ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'comments_show_message', TRUE, FALSE, array( 'togglesOn' => array( 'comments_meta_message', 'comments_meta_color' ) ), NULL, NULL, NULL, 'comments_show_message' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Editor( 'comments_meta_message', \IPS\Member::loggedIn()->language()->addToStack('default_copyposts_message'), FALSE, array( 'app' => 'core', 'key' => 'Meta', 'autoSaveKey' => "meta-message-new", 'attachIds' => NULL ), NULL, NULL, NULL, 'comments_meta_message' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'comments_meta_color', 'none', FALSE, array( 'getHtml' => function( $element )
|
||||
$form->add( new YesNo( 'comments_show_message', TRUE, FALSE, array( 'togglesOn' => array( 'comments_meta_message', 'comments_meta_color' ) ), NULL, NULL, NULL, 'comments_show_message' ) );
|
||||
$form->add( new Editor( 'comments_meta_message', Member::loggedIn()->language()->addToStack('default_copyposts_message'), FALSE, array( 'app' => 'core', 'key' => 'Meta', 'autoSaveKey' => "meta-message-new", 'attachIds' => NULL ), NULL, NULL, NULL, 'comments_meta_message' ) );
|
||||
$form->add( new Custom( 'comments_meta_color', 'none', FALSE, array( 'getHtml' => function( $element )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'forms', 'core', 'front' )->colorSelection( $element->name, $element->value );
|
||||
return Theme::i()->getTemplate( 'forms', 'core', 'front' )->colorSelection( $element->name, $element->value );
|
||||
} ), NULL, NULL, NULL, 'comments_meta_color' ) );
|
||||
}
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'copy_author', TRUE ) );
|
||||
$form->add( new YesNo( 'copy_author', TRUE ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
@@ -249,7 +288,7 @@ class _topic extends \IPS\Dispatcher\Controller
|
||||
unset( $values['copy_author'] );
|
||||
|
||||
/* If we are copying comments and we use the forums for comments, skip creating a topic as we will just reassocciate */
|
||||
if( $comments AND $fakeRecord->_forum_record AND $fakeRecord->_forum_comments )
|
||||
if( $fakeRecord->_forum_record )
|
||||
{
|
||||
$recordClass::$skipTopicCreation = true;
|
||||
}
|
||||
@@ -266,46 +305,49 @@ class _topic extends \IPS\Dispatcher\Controller
|
||||
if( $metaMessage['show'] )
|
||||
{
|
||||
$id = $record->addMessage( $metaMessage['message'], $metaMessage['color'] );
|
||||
\IPS\File::claimAttachments( "meta-message-new", $id, NULL, 'core_ContentMessages' );
|
||||
File::claimAttachments( "meta-message-new", $id, NULL, 'core_ContentMessages' );
|
||||
}
|
||||
}
|
||||
|
||||
/* If the record syncs with the forums and we are copying topics, just associate with the existing topic */
|
||||
if( $comments AND $record->_forum_record AND $record->_forum_comments )
|
||||
if( $record->_forum_record )
|
||||
{
|
||||
$record->record_topicid = $this->topic->tid;
|
||||
$record->save();
|
||||
|
||||
/* Reload using the proper class so first and last comment data can be rebuilt properly */
|
||||
$class = 'IPS\cms\Records\RecordsTopicSync' . $database->_id;
|
||||
$class::load( $this->topic->tid )->rebuildFirstAndLastCommentData();
|
||||
if( $comments and $record->_forum_comments )
|
||||
{
|
||||
$obj = $record->recordForTopicSynch();
|
||||
$obj->rebuildFirstAndLastCommentData();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
/* If the database is on a page, go to the record */
|
||||
\IPS\Output::i()->redirect( $record->url() );
|
||||
Output::i()->redirect( $record->url() );
|
||||
}
|
||||
catch( \LogicException $e )
|
||||
catch( LogicException $e )
|
||||
{
|
||||
/* If it is NOT then go back to the topic */
|
||||
\IPS\Output::i()->redirect( $this->topic->url() );
|
||||
Output::i()->redirect( $this->topic->url() );
|
||||
}
|
||||
}
|
||||
elseif ( $comments )
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=cms&module=database&controller=topic&do=comments&id={$this->topic->tid}", 'front', 'topic_copy', $this->topic->title_seo )->csrf()->setQueryString( array( 'record_id' => $record->primary_id_field, 'database_id' => $database->_id ) ) );
|
||||
Output::i()->redirect( Url::internal( "app=cms&module=database&controller=topic&do=comments&id={$this->topic->tid}", 'front', 'topic_copy', $this->topic->title_seo )->csrf()->setQueryString( array( 'record_id' => $record->primary_id_field, 'database_id' => $database->_id ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
/* If the database is on a page, go to the record */
|
||||
\IPS\Output::i()->redirect( $record->url() );
|
||||
Output::i()->redirect( $record->url() );
|
||||
}
|
||||
catch( \LogicException $e )
|
||||
catch( LogicException $e )
|
||||
{
|
||||
/* If it is NOT then go back to the topic */
|
||||
\IPS\Output::i()->redirect( $this->topic->url() );
|
||||
Output::i()->redirect( $this->topic->url() );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -319,27 +361,27 @@ class _topic extends \IPS\Dispatcher\Controller
|
||||
$fieldClass::fixedFieldFormShow( 'record_allow_comments' ) or
|
||||
$fieldClass::fixedFieldFormShow( 'record_expiry_date' ) or
|
||||
$fieldClass::fixedFieldFormShow( 'record_comment_cutoff' ) or
|
||||
\IPS\Member::loggedIn()->modPermission('can_content_edit_meta_tags') )
|
||||
Member::loggedIn()->modPermission('can_content_edit_meta_tags') )
|
||||
{
|
||||
$hasModOptions = TRUE;
|
||||
}
|
||||
|
||||
array_shift( \IPS\Output::i()->breadcrumb );
|
||||
array_shift( Output::i()->breadcrumb );
|
||||
$container = NULL;
|
||||
try
|
||||
{
|
||||
$container = $this->topic->container();
|
||||
foreach ( $container->parents() as $parent )
|
||||
{
|
||||
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
|
||||
Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
|
||||
}
|
||||
\IPS\Output::i()->breadcrumb[] = array( $container->url(), $container->_title );
|
||||
Output::i()->breadcrumb[] = array( $container->url(), $container->_title );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
\IPS\Output::i()->breadcrumb[] = array( $this->topic->url(), $this->topic->mapped( 'title' ) );
|
||||
\IPS\Output::i()->breadcrumb[] = array( NULL, \IPS\Member::loggedIn()->language()->addToStack( 'copy_topic_to_database' ) );
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'copy_topic_to_database' );
|
||||
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\cms\Theme::i()->getTemplate( $database->template_form, 'cms', 'database' ), 'recordForm' ), NULL, $category, $database, $page, \IPS\Member::loggedIn()->language()->addToStack( 'copy_topic_to_database' ), $hasModOptions );
|
||||
catch ( Exception $e ) { }
|
||||
Output::i()->breadcrumb[] = array( $this->topic->url(), $this->topic->mapped( 'title' ) );
|
||||
Output::i()->breadcrumb[] = array( NULL, Member::loggedIn()->language()->addToStack( 'copy_topic_to_database' ) );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack( 'copy_topic_to_database' );
|
||||
Output::i()->output = $form->customTemplate( array( \IPS\cms\Theme::i()->getTemplate( $database->template_form, 'cms', 'database' ), 'recordForm' ), NULL, $category, $database, $page, Member::loggedIn()->language()->addToStack( 'copy_topic_to_database' ), $hasModOptions );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -347,21 +389,24 @@ class _topic extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function comments()
|
||||
protected function comments() : void
|
||||
{
|
||||
\IPS\Session::i()->csrfCheck();
|
||||
|
||||
$mr = new \IPS\Helpers\MultipleRedirect( \IPS\Http\Url::internal( "app=cms&module=database&controller=topic&id=" . \IPS\Request::i()->id . "&do=comments", 'front', 'topic_copy', $this->topic->title_seo )->csrf()->setQueryString( array( 'database_id' => \IPS\Request::i()->database_id, 'record_id' => \IPS\Request::i()->record_id ) ), function( $data ) {
|
||||
$database = \IPS\cms\Databases::load( \IPS\Request::i()->database_id );
|
||||
$recordClass = 'IPS\cms\Records' . \IPS\Request::i()->database_id;
|
||||
Session::i()->csrfCheck();
|
||||
|
||||
$mr = new MultipleRedirect( Url::internal( "app=cms&module=database&controller=topic&id=" . Request::i()->id . "&do=comments", 'front', 'topic_copy', $this->topic->title_seo )->csrf()->setQueryString( array( 'database_id' => Request::i()->database_id, 'record_id' => Request::i()->record_id ) ), function( $data ) {
|
||||
|
||||
/* @var Records $recordClass
|
||||
* @var Records\Comment $commentClass */
|
||||
$database = Databases::load( Request::i()->database_id );
|
||||
$recordClass = 'IPS\cms\Records' . Request::i()->database_id;
|
||||
$commentClass = $recordClass::$commentClass;
|
||||
$record = $recordClass::load( \IPS\Request::i()->record_id );
|
||||
$total = \IPS\Db::i()->select( 'COUNT(*)', 'forums_posts', array( "topic_id=? AND new_topic=? AND queued!=?", \IPS\Request::i()->id, 0, 2 ) )->first();
|
||||
$record = $recordClass::load( Request::i()->record_id );
|
||||
$total = Db::i()->select( 'COUNT(*)', 'forums_posts', array( "topic_id=? AND new_topic=? AND queued!=?", Request::i()->id, 0, 2 ) )->first();
|
||||
|
||||
$done = 0;
|
||||
foreach( new \IPS\Patterns\ActiveRecordIterator( \IPS\Db::i()->select( '*', 'forums_posts', array( "topic_id=? AND new_topic=? AND queued!=?", \IPS\Request::i()->id, 0, -2 ), "pid ASC", array( $data, 100 ) ), 'IPS\forums\Topic\Post' ) AS $post )
|
||||
foreach( new ActiveRecordIterator( Db::i()->select( '*', 'forums_posts', array( "topic_id=? AND new_topic=? AND queued!=?", Request::i()->id, 0, -2 ), "pid ASC", array( $data, 100 ) ), 'IPS\forums\Topic\Post' ) AS $post )
|
||||
{
|
||||
$commentClass::create( $record, $post->content(), FALSE, NULL, TRUE, $post->author(), \IPS\DateTime::create(), $post->ip_address, $post->hidden() );
|
||||
$commentClass::create( $record, $post->content(), FALSE, NULL, TRUE, $post->author(), DateTime::create(), $post->ip_address, $post->hidden() );
|
||||
$done++;
|
||||
}
|
||||
|
||||
@@ -370,40 +415,42 @@ class _topic extends \IPS\Dispatcher\Controller
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return array( $data + $done, \IPS\Member::loggedIn()->language()->addToStack( 'copying_comments' ), 100 / $total * ( $data + 100 ) );
|
||||
return array( $data + $done, Member::loggedIn()->language()->addToStack( 'copying_comments' ), 100 / $total * ( $data + 100 ) );
|
||||
|
||||
}, function() {
|
||||
$recordClass = 'IPS\cms\Records' . \IPS\Request::i()->database_id;
|
||||
$record = $recordClass::load( \IPS\Request::i()->record_id );
|
||||
|
||||
/* @var Records $recordClass */
|
||||
$recordClass = 'IPS\cms\Records' . Request::i()->database_id;
|
||||
$record = $recordClass::load( Request::i()->record_id );
|
||||
|
||||
try
|
||||
{
|
||||
\IPS\Output::i()->redirect( $record->url() );
|
||||
Output::i()->redirect( $record->url() );
|
||||
}
|
||||
catch( \LogicException $e )
|
||||
catch( LogicException $e )
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\forums\Topic::load( \IPS\Request::i()->id )->url() );
|
||||
Output::i()->redirect( TopicClass::load( Request::i()->id )->url() );
|
||||
}
|
||||
} );
|
||||
|
||||
$topic = \IPS\forums\Topic::load( \IPS\Request::i()->id );
|
||||
$topic = TopicClass::load( Request::i()->id );
|
||||
|
||||
array_shift( \IPS\Output::i()->breadcrumb );
|
||||
array_shift( Output::i()->breadcrumb );
|
||||
$container = NULL;
|
||||
try
|
||||
{
|
||||
$container = $topic->container();
|
||||
foreach ( $container->parents() as $parent )
|
||||
{
|
||||
\IPS\Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
|
||||
Output::i()->breadcrumb[] = array( $parent->url(), $parent->_title );
|
||||
}
|
||||
\IPS\Output::i()->breadcrumb[] = array( $container->url(), $container->_title );
|
||||
Output::i()->breadcrumb[] = array( $container->url(), $container->_title );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
\IPS\Output::i()->breadcrumb[] = array( $topic->url(), $topic->mapped( 'title' ) );
|
||||
\IPS\Output::i()->breadcrumb[] = array( NULL, \IPS\Member::loggedIn()->language()->addToStack( 'copy_topic_to_database' ) );
|
||||
catch ( Exception $e ) { }
|
||||
Output::i()->breadcrumb[] = array( $topic->url(), $topic->mapped( 'title' ) );
|
||||
Output::i()->breadcrumb[] = array( NULL, Member::loggedIn()->language()->addToStack( 'copy_topic_to_database' ) );
|
||||
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack( 'copying_comments' );
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core', 'front' )->genericBlock( (string) $mr, \IPS\Member::loggedIn()->language()->addToStack( 'copying_comments' ), 'ipsBox ipsPad' );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack( 'copying_comments' );
|
||||
Output::i()->output = Theme::i()->getTemplate( 'global', 'core', 'front' )->genericBlock( (string) $mr, Member::loggedIn()->language()->addToStack( 'copying_comments' ), 'ipsBox i-padding_3' );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user