Version 5.0.0 beta 8
This commit is contained in:
1 parent
54d5dcd0a0
commit
214f649f1d
483 files changed
+35354
-33568
No files matched your search
@@ -40,11 +40,14 @@ use IPS\Patterns\ActiveRecord;
|
||||
use IPS\Request;
|
||||
use IPS\Theme;
|
||||
use IPS\Widget;
|
||||
use IPS\Widget\Polymorphic;
|
||||
use LogicException;
|
||||
use OutOfRangeException;
|
||||
use ParseError;
|
||||
use function class_implements;
|
||||
use function defined;
|
||||
use function func_get_args;
|
||||
use function get_class;
|
||||
use function in_array;
|
||||
use function intval;
|
||||
use function is_array;
|
||||
@@ -628,9 +631,17 @@ EOF;
|
||||
{
|
||||
$templates = array( '_default_' => Member::loggedIn()->language()->addToStack('content_block_template_use_default') );
|
||||
|
||||
$keys =[ $this->widget()->key ];
|
||||
if( in_array( Polymorphic::class, class_implements( $this->widget() ) ) )
|
||||
{
|
||||
/* @var Polymorphic $widgetClass */
|
||||
$widgetClass = get_class( $this->widget() );
|
||||
$keys[] = $widgetClass::getBaseKey();
|
||||
}
|
||||
|
||||
foreach( Templates::getTemplates( Templates::RETURN_BLOCK ) as $id => $obj )
|
||||
{
|
||||
if ( $obj->group == $this->widget()->key )
|
||||
if( in_array( $obj->group, $keys ) )
|
||||
{
|
||||
$templates[ $obj->key ] = $obj->title;
|
||||
}
|
||||
|
||||
@@ -370,7 +370,8 @@ class Records extends Item implements
|
||||
return Topic::getCommentsPerPage();
|
||||
}
|
||||
|
||||
return static::database()->field_perpage;
|
||||
$databaseSetting = static::database()->comments_perpage;
|
||||
return ( is_int( $databaseSetting ) and $databaseSetting > 0 ) ? $databaseSetting : static::database()->field_perpage;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -543,12 +544,13 @@ class Records extends Item implements
|
||||
* Indefinite Article
|
||||
*
|
||||
* @param Lang|null $lang The language to use, or NULL for the language of the currently logged in member
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
public function indefiniteArticle( ?Lang $lang = NULL ): string
|
||||
public function indefiniteArticle( ?Lang $lang = NULL, array $options=array() ): string
|
||||
{
|
||||
$lang = $lang ?: Member::loggedIn()->language();
|
||||
return $lang->addToStack( 'content_db_lang_ia_' . static::$customDatabaseId, FALSE );
|
||||
return $lang->addToStack( 'content_db_lang_ia_' . static::$customDatabaseId, FALSE, $options );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -556,12 +558,13 @@ class Records extends Item implements
|
||||
*
|
||||
* @param array|null $containerData Container data
|
||||
* @param Lang|null $lang The language to use, or NULL for the language of the currently logged in member
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
public static function _indefiniteArticle( ?array $containerData = NULL, ?Lang $lang = NULL ): string
|
||||
public static function _indefiniteArticle( ?array $containerData = NULL, ?Lang $lang = NULL, array $options=array() ): string
|
||||
{
|
||||
$lang = $lang ?: Member::loggedIn()->language();
|
||||
return $lang->addToStack( 'content_db_lang_ia_' . static::$customDatabaseId, FALSE );
|
||||
return $lang->addToStack( 'content_db_lang_ia_' . static::$customDatabaseId, FALSE, $options );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2768,47 +2771,40 @@ class Records extends Item implements
|
||||
{
|
||||
if ( $this->recordCommentPageCount === NULL or $recache === TRUE )
|
||||
{
|
||||
/* If the database has a custom per page set, use that. */
|
||||
if ( static::database()->comments_perpage )
|
||||
if ( $this->useForumComments() )
|
||||
{
|
||||
$this->recordCommentPageCount = parent::commentPageCount( $recache );
|
||||
try
|
||||
{
|
||||
$topic = $this->topic();
|
||||
|
||||
if ( $topic !== null )
|
||||
{
|
||||
/* Store the real count so it is not accidentally written as the actual value */
|
||||
$realCount = $topic->posts;
|
||||
|
||||
/* If we are NOT featuring the first post in the topics, then we need to
|
||||
compensate for the first post (which is actually the record) */
|
||||
if ( !Member::loggedIn()->getLayoutValue( 'forum_topic_view_firstpost' ) )
|
||||
{
|
||||
$topic->posts = ( $topic->posts - 1 ) > 0 ? $topic->posts - 1 : 0;
|
||||
}
|
||||
|
||||
/* Get our page count considering all of that */
|
||||
$this->recordCommentPageCount = $topic->commentPageCount();
|
||||
|
||||
/* Reset the count back to the real count */
|
||||
$topic->posts = $realCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->recordCommentPageCount = 1;
|
||||
}
|
||||
}
|
||||
catch ( Exception $e ) {}
|
||||
}
|
||||
/* Otherwise do the normal stuff */
|
||||
else
|
||||
{
|
||||
if ( $this->useForumComments() )
|
||||
{
|
||||
try
|
||||
{
|
||||
$topic = $this->topic();
|
||||
|
||||
if ( $topic !== null )
|
||||
{
|
||||
/* Store the real count so it is not accidentally written as the actual value */
|
||||
$realCount = $topic->posts;
|
||||
|
||||
/* If we are NOT featuring the first post in the topics, then we need to
|
||||
compensate for the first post (which is actually the record) */
|
||||
if ( !Member::loggedIn()->getLayoutValue( 'forum_topic_view_firstpost' ) )
|
||||
{
|
||||
$topic->posts = ( $topic->posts - 1 ) > 0 ? $topic->posts - 1 : 0;
|
||||
}
|
||||
|
||||
/* Get our page count considering all of that */
|
||||
$this->recordCommentPageCount = $topic->commentPageCount();
|
||||
|
||||
/* Reset the count back to the real count */
|
||||
$topic->posts = $realCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->recordCommentPageCount = 1;
|
||||
}
|
||||
}
|
||||
catch ( Exception $e )
|
||||
{
|
||||
}
|
||||
}
|
||||
$this->recordCommentPageCount = parent::commentPageCount( $recache );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3846,7 +3842,7 @@ class Records extends Item implements
|
||||
{
|
||||
/* @var Fields $fieldClass */
|
||||
$fieldClass = 'IPS\cms\Fields' . static::$customDatabaseId;
|
||||
$photo->editable = $fieldClass::fixedFieldFormShow( 'record_image' );
|
||||
$photo->editable = ( $this->canEdit() and $fieldClass::fixedFieldFormShow( 'record_image' ) );
|
||||
}
|
||||
|
||||
return $photo;
|
||||
|
||||
@@ -610,7 +610,7 @@ class Templates extends ActiveRecord
|
||||
*/
|
||||
public static function exportForm( bool $appPluginBuild=FALSE, array $preSelected=array() ): Form
|
||||
{
|
||||
$form = new Form( 'form', $appPluginBuild ? 'save' : 'next' );
|
||||
$form = new Form( 'form', $appPluginBuild ? 'save' : 'download' );
|
||||
if( !$appPluginBuild )
|
||||
{
|
||||
$form->addMessage( 'cms_templates_export_description', 'ipsMessage ipsMessage_information' );
|
||||
@@ -623,21 +623,17 @@ class Templates extends ActiveRecord
|
||||
|
||||
$templates = [];
|
||||
|
||||
foreach(Templates::getTemplates( Templates::RETURN_DATABASE_ONLY + Templates::RETURN_ALL ) as $template )
|
||||
foreach(Templates::getTemplates( Templates::RETURN_DATABASE_AND_IN_DEV + Templates::RETURN_ALL ) as $template )
|
||||
{
|
||||
$title = Templates::readableGroupName( $template->group );
|
||||
|
||||
if ( $template->location === 'database' )
|
||||
if( $template->location == 'database' )
|
||||
{
|
||||
$templates['database'][ $template->group ] = $title;
|
||||
}
|
||||
else if ( $template->location === 'block' )
|
||||
else
|
||||
{
|
||||
$templates['block'][ $template->key ] = $title . ' > ' . $template->title;
|
||||
}
|
||||
else if ( $template->location === 'page' )
|
||||
{
|
||||
$templates['page'][ $template->key ] = $title . ' > ' . $template->title;
|
||||
$templates[ $template->location ][ $template->key ] = $title . ' > ' . $template->title;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -737,7 +733,10 @@ class Templates extends ActiveRecord
|
||||
if ( !in_array( substr( $k, 9 ), array( 'content', 'params' ) ) )
|
||||
{
|
||||
$xml->startAttribute( $k );
|
||||
$xml->text( $v );
|
||||
if( !empty( $v ) )
|
||||
{
|
||||
$xml->text( $v );
|
||||
}
|
||||
$xml->endAttribute();
|
||||
}
|
||||
}
|
||||
@@ -857,7 +856,7 @@ class Templates extends ActiveRecord
|
||||
|
||||
$conflictKey = md5( microtime() );
|
||||
|
||||
$templates = Theme::i()->getAllTemplates( 'cms', NULL, NULL, \IPS\cms\Theme::RETURN_DATABASE_ONLY + Theme::RETURN_ALL );
|
||||
$templates = \IPS\cms\Theme::i()->getAllTemplates( 'cms', [ 'database', 'page', 'css', 'js' ], [], \IPS\cms\Theme::RETURN_DATABASE_ONLY + Theme::RETURN_ALL );
|
||||
|
||||
if ( ! @$xml->read() )
|
||||
{
|
||||
@@ -866,7 +865,7 @@ class Templates extends ActiveRecord
|
||||
$xml->read();
|
||||
while ( $xml->read() )
|
||||
{
|
||||
if ( $xml->name === 'template' )
|
||||
if ( $xml->name == 'template' )
|
||||
{
|
||||
$node = new SimpleXMLElement( $xml->readOuterXML() );
|
||||
$attrs = array();
|
||||
@@ -883,7 +882,6 @@ class Templates extends ActiveRecord
|
||||
$attrs[ $k ] = ( $tryJson ) ?: (string) $v;
|
||||
}
|
||||
|
||||
|
||||
if ( isset( $attrs['template_title'] ) and isset( $attrs['template_location'] ) and isset( $attrs['template_group'] ) )
|
||||
{
|
||||
/* Got this template? */
|
||||
|
||||
@@ -213,6 +213,117 @@ class Theme extends SystemTheme
|
||||
return $seen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Import database templates from the dev directory
|
||||
*
|
||||
* @param string $directoryName
|
||||
* @param string $templateType
|
||||
* @return void
|
||||
*/
|
||||
public static function importDatabaseTemplate( string $directoryName, string $templateType ) : void
|
||||
{
|
||||
$directory = ROOT_PATH . "/applications/cms/dev/html/database/" . $directoryName;
|
||||
if( !file_exists( $directory ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/* Clear out any existing versions */
|
||||
Db::i()->delete( 'cms_templates', [ 'template_master=? and template_group=? and template_location=? and template_original_group=?', 0, $directoryName, 'database', $templateType ] );
|
||||
|
||||
foreach( new DirectoryIterator( $directory ) as $file )
|
||||
{
|
||||
if( $file->isDot() or $file->isDir() or $file->getFilename() == 'index.html' )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$html = file_get_contents( $directory . '/' . $file->getFilename() );
|
||||
|
||||
/* Parse the header tag */
|
||||
preg_match( '/^<ips:template parameters="(.+?)?"([^>]+?)>(\r\n?|\n)/', $html, $params );
|
||||
|
||||
/* Strip it */
|
||||
$html = ( isset($params[0]) ) ? str_replace( $params[0], '', $html ) : $html;
|
||||
$title = str_replace( '.phtml', '', $file->getFilename() );
|
||||
|
||||
/* remove compiled version */
|
||||
$key = strtolower( 'template_cms_' .static::makeBuiltTemplateLookupHash( 'cms', 'database', $directoryName ) . '_' . static::cleanGroupName( $directoryName ) );
|
||||
|
||||
if ( isset( Store::i()->$key ) )
|
||||
{
|
||||
unset(Store::i()->$key);
|
||||
}
|
||||
|
||||
Db::i()->insert( 'cms_templates', array(
|
||||
'template_key' => str_replace( ' ', '_', 'database_' . $directoryName . '_' . $title ),
|
||||
'template_title' => $title,
|
||||
'template_desc' => '',
|
||||
'template_content' => $html,
|
||||
'template_location' => 'database',
|
||||
'template_group' => $directoryName,
|
||||
'template_original_group' => $templateType,
|
||||
'template_container' => 0,
|
||||
'template_params' => ( isset($params[1]) ) ? $params[1] : '',
|
||||
'template_master' => 0,
|
||||
'template_user_created' => 0,
|
||||
'template_type' => 'template'
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Import a custom page wrapper
|
||||
*
|
||||
* @param string $wrapperName
|
||||
* @return void
|
||||
*/
|
||||
public static function importPageWrapper( string $wrapperName ) : void
|
||||
{
|
||||
$file = ROOT_PATH . "/applications/cms/dev/html/page/custom_wrappers/" . $wrapperName;
|
||||
if( !file_exists( $file ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$wrapperName = str_replace( '.phtml', '', $wrapperName );
|
||||
|
||||
/* Delete the original */
|
||||
Db::i()->delete( 'cms_templates', [ 'template_location=? and template_title=? and template_group=? and template_master=?', 'page', $wrapperName, 'custom_wrappers', 0 ] );
|
||||
|
||||
$html = file_get_contents( $file );
|
||||
|
||||
/* Parse the header tag */
|
||||
preg_match( '/^<ips:template parameters="(.+?)?"([^>]+?)>(\r\n?|\n)/', $html, $params );
|
||||
|
||||
/* Strip it */
|
||||
$html = ( isset($params[0]) ) ? str_replace( $params[0], '', $html ) : $html;
|
||||
|
||||
/* remove compiled version */
|
||||
$key = strtolower( 'template_cms_' .static::makeBuiltTemplateLookupHash( 'cms', 'page', 'custom_wrappers' ) . '_' . static::cleanGroupName( $wrapperName ) );
|
||||
|
||||
if ( isset( Store::i()->$key ) )
|
||||
{
|
||||
unset(Store::i()->$key);
|
||||
}
|
||||
|
||||
Db::i()->insert( 'cms_templates', array(
|
||||
'template_key' => 'page_custom_wrappers_' . $wrapperName,
|
||||
'template_title' => $wrapperName,
|
||||
'template_desc' => '',
|
||||
'template_content' => $html,
|
||||
'template_location' => 'page',
|
||||
'template_group' => 'custom_wrappers',
|
||||
'template_original_group' => null,
|
||||
'template_container' => 0,
|
||||
'template_params' => ( isset($params[1]) ) ? $params[1] : '',
|
||||
'template_master' => 0,
|
||||
'template_user_created' => 0,
|
||||
'template_type' => 'template'
|
||||
) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a template to disk
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user