\[\/attachment\]\<\/e\>\<\/ATTACHMENT\>/i';
$replacement = '[attachment=' . $attachId . ':name]';
if( $row['attach_comment'] )
{
$replacement .= '' . $row['attach_comment'] . '
';
}
if( preg_match( $regex31, $this->_postContent[ $pid ] ) )
{
$this->_postContent[ $pid ] = preg_replace( $regex31, $replacement, $this->_postContent[ $pid ] );
}
elseif( preg_match( $regex32, $this->_postContent[ $pid ] ) )
{
$this->_postContent[ $pid ] = preg_replace( $regex32, $replacement, $this->_postContent[ $pid ] );
}
else
{
$this->_postContent[ $pid ] .= '
' . $replacement;
}
}
catch( UnderflowException|OutOfRangeException $e ) {}
}
$libraryClass->setLastKeyValue( $row['attach_id'] );
}
/* Do the updates */
foreach( $this->_postContent as $pid => $content )
{
Db::i()->update( 'forums_posts', array( 'post' => $content ), array( 'pid=?', $pid ) );
}
}
/**
* Check if we can redirect the legacy URLs from this software to the new locations
*
* @return Url|NULL
*/
public function checkRedirects(): ?Url
{
$url = Request::i()->url();
if( mb_strpos( $url->data[ Url::COMPONENT_PATH ], 'viewtopic.php' ) !== FALSE )
{
if( isset( Request::i()->p ) )
{
$class = '\IPS\forums\Topic\Post';
$types = array( 'posts', 'forums_posts' );
$oldId = Request::i()->p;
}
else
{
$class = '\IPS\forums\Topic';
$types = array( 'topics', 'forums_topics' );
$oldId = Request::i()->tid ?: Request::i()->t;
}
}
elseif( mb_strpos( $url->data[ Url::COMPONENT_PATH ], 'viewforum.php' ) !== FALSE )
{
$class = '\IPS\forums\Forum';
$types = array( 'forums', 'forums_forums' );
$oldId = Request::i()->f;
}
elseif( mb_strpos( $url->data[ Url::COMPONENT_PATH ], 'download/file.php' ) !== FALSE )
{
try
{
$data = (string) $this->app->getLink( Request::i()->id, array( 'attachments', 'core_attachments' ) );
return Url::external( Settings::i()->base_url . 'applications/core/interface/file/attachment.php' )->setQueryString( 'id', $data );
}
catch( Exception $e )
{
return NULL;
}
}
if( isset( $class ) )
{
try
{
try
{
$data = (string) $this->app->getLink( $oldId, $types );
}
catch( OutOfRangeException $e )
{
$data = (string) $this->app->getLink( $oldId, $types, FALSE, TRUE );
}
$item = $class::load( $data );
if( $item instanceof Content )
{
if( $item->canView() )
{
return $item->url();
}
}
elseif( $item instanceof Model )
{
if( $item->can( 'view' ) )
{
return $item->url();
}
}
}
catch( Exception $e )
{
return NULL;
}
}
return NULL;
}
}