Version 5.0.13
This commit is contained in:
1 parent
b89858b2ff
commit
5efe744c5f
1407 files changed
+69690
-30177
No files matched your search
@@ -1002,6 +1002,12 @@ class Editor extends FormAbstract
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Return if we have plugins already */
|
||||
if( !empty( Store::i()->editorPluginJs ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* If we are not in dev, check if we have the bundled JS, and if not, build it */
|
||||
$pluginJs = "";
|
||||
$hasPlugins = false;
|
||||
@@ -1063,10 +1069,8 @@ js;
|
||||
|
||||
$pluginJs = Minifier::minify( $pluginJs, array( 'flaggedComments' => false ) );
|
||||
|
||||
$jsFile = File::create( 'core_Theme', "editorPlugins.js", $pluginJs );
|
||||
Settings::i()->changeValues([
|
||||
'editor_plugin_js' => (string) $jsFile
|
||||
]);
|
||||
$jsFile = File::create( 'core_Theme', "editorPlugins.js", $pluginJs, container: 'editor', obscure: false );
|
||||
Store::i()->editorPluginJs = (string) $jsFile;
|
||||
}
|
||||
|
||||
return $hasPlugins;
|
||||
@@ -1141,6 +1145,40 @@ js;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get editor restrictions for the member based on group settings
|
||||
*
|
||||
* @param Member|null $member The member/null for logged in member
|
||||
* @param bool $comments Whether to use restrictions for the comment editor rather than the normal one
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getMemberRestrictionLevel( ?Member $member=null, bool $comments = false ) : int
|
||||
{
|
||||
$member = $member ?: Member::loggedIn();
|
||||
static $restrictLevelCache = [];
|
||||
$cacheKey = ($member->member_id ?: 0) . '-' . ((int) $comments);
|
||||
if ( !isset( $restrictLevelCache[$cacheKey] ) )
|
||||
{
|
||||
$restrictLevel = 0;
|
||||
foreach ( $member->groups as $gid )
|
||||
{
|
||||
$group = Member\Group::load( $gid );
|
||||
$restrictLevel = max( $group->getEditorRestrictionLevel( $comments ), $restrictLevel );
|
||||
|
||||
// 2 is the advanced editor, we won't find one more advanced
|
||||
if ( $restrictLevel >= 2 )
|
||||
{
|
||||
$restrictLevel = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$restrictLevelCache[$cacheKey] = $restrictLevel;
|
||||
}
|
||||
|
||||
return $restrictLevelCache[$cacheKey];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get editor restrictions for the member based on group settings
|
||||
*
|
||||
@@ -1153,32 +1191,24 @@ js;
|
||||
{
|
||||
$member = $member ?: Member::loggedIn();
|
||||
$settings = static::getRestrictionSetting();
|
||||
Output::i()->jsVars['editor_restrictions'] = []; // this needs to be shared to make sure the editor uses saved restriction settings of custom plugins rather than the defaults
|
||||
$restrictions = [];
|
||||
|
||||
$restrictLevel = 0;
|
||||
foreach ( $member->groups as $gid )
|
||||
{
|
||||
$group = Member\Group::load( $gid );
|
||||
$restrictLevel = max( $group->getEditorRestrictionLevel( $comments ), $restrictLevel );
|
||||
|
||||
// 2 is the advanced editor, we won't find one more advanced
|
||||
if ( $restrictLevel >= 2 )
|
||||
{
|
||||
$restrictLevel = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$restrictLevel = static::getMemberRestrictionLevel( $member, $comments );
|
||||
|
||||
foreach ( $settings as $level => $_restrictions )
|
||||
{
|
||||
if ( (int) $restrictLevel > (int) $level )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach( $_restrictions as $restriction )
|
||||
{
|
||||
$restrictions[] = $restriction;
|
||||
if ( preg_match( "/^ipsCustom(Node|Mark|Extension)__/", $restriction ) )
|
||||
{
|
||||
Output::i()->jsVars['editor_restrictions'][ $restriction ] = (int)$level;
|
||||
}
|
||||
|
||||
if ( $restrictLevel <= (int) $level )
|
||||
{
|
||||
$restrictions[] = $restriction;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1191,6 +1221,11 @@ js;
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( Output::i()->jsVars['editor_restrictions'] ) )
|
||||
{
|
||||
unset( Output::i()->jsVars['editor_restrictions'] );
|
||||
}
|
||||
|
||||
return $restrictions;
|
||||
}
|
||||
|
||||
@@ -1270,10 +1305,12 @@ js;
|
||||
/**
|
||||
* Get the level of a restriction based on the settings
|
||||
*
|
||||
* @param string $restriction
|
||||
* @param string $restriction The key of the restriction
|
||||
* @param ?int $default=null The default value of the restriction
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getRestrictionLevel( string $restriction ) : int
|
||||
public static function getRestrictionLevel( string $restriction, ?int $default =null ) : int
|
||||
{
|
||||
$settings = static::getRestrictionSetting();
|
||||
foreach ( $settings as $level => $restrictions )
|
||||
@@ -1291,6 +1328,6 @@ js;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
return $default ?? -1;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user