Skip to content

Commit

Permalink
#269 Ajout scope[admin|site] plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephane committed Dec 18, 2017
2 parents 5608f30 + f3b00da commit 42bdb37
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 35 deletions.
2 changes: 1 addition & 1 deletion core/admin/parametres_plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
$filename = realpath(PLX_PLUGINS.$plugin.'/config.php');
if(is_file($filename)) {
# si le plugin n'est pas actif, aucune instance n'a été créée, on va donc la créer, sinon on prend celle qui existe
if(!isset($plxAdmin->plxPlugins->aPlugins[$plugin]))
if(empty($plxAdmin->plxPlugins->aPlugins[$plugin]))
$plxPlugin = $plxAdmin->plxPlugins->getInstance($plugin);
else
$plxPlugin = $plxAdmin->plxPlugins->aPlugins[$plugin];
Expand Down
16 changes: 11 additions & 5 deletions core/admin/parametres_plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ function pluginsList($plugins, $defaultLang, $type) {
else
$icon=PLX_CORE.'admin/theme/images/icon_plugin.png';

$output .= '<tr class="top">';
# plugin activé uniquement côté site (<scope> == 'site')
if(empty($plugInstance) and $plugInstance=plxPlugins::getInstance($plugName)) {
$plugInstance->getInfos();
}
$output .= '<tr class="top" data-scope="'.$plugInstance->getInfo('scope').'">';

# checkbox
$output .= '<td>';
Expand Down Expand Up @@ -129,7 +133,12 @@ function pluginsList($plugins, $defaultLang, $type) {
<form action="parametres_plugins.php" method="post" id="form_plugins">

<div class="inline-form action-bar">
<h2><?php echo L_PLUGINS_TITLE ?></h2>
<h2>
<?php echo L_PLUGINS_TITLE ?>
<span data-scope="admin">Admin</span>
<span data-scope="site">Site</span>
</h2>

<ul class="menu">
<?php echo implode($breadcrumbs); ?>
</ul>
Expand Down Expand Up @@ -163,9 +172,6 @@ function pluginsList($plugins, $defaultLang, $type) {
</table>
</div>

<?php if($_SESSION['selPlugins']=='1') : ?>
<?php endif; ?>

</form>

<script>
Expand Down
2 changes: 1 addition & 1 deletion core/admin/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
$output='';
# chargement du fichier d'administration du plugin
$filename = realpath(PLX_PLUGINS.$plugin.'/admin.php');
if(isset($plxAdmin->plxPlugins->aPlugins[$plugin]) AND is_file($filename)) {
if(!empty($plxAdmin->plxPlugins->aPlugins[$plugin]) AND is_file($filename)) {
# utilisation de la variable plxPlugin pour faciliter la syntaxe dans les devs des plugins
$plxPlugin = $plxAdmin->plxPlugins->aPlugins[$plugin];
# Control des autorisation d'accès à l'écran admin.php du plugin
Expand Down
27 changes: 24 additions & 3 deletions core/admin/theme/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,6 @@ select {

select {
padding: 0 18px 0 0;
<<<<<<< HEAD
}

select {
Expand All @@ -865,9 +864,31 @@ select {
}

/*for IE10*/

select::-ms-expand {
display: none;
}
=======


/* ---- parametres_plugins ---- */

#form_plugins span[data-scope] {
padding: 2px 5px 0 5px;
font-size: 1.2rem;
}

#plugins-table tbody tr[data-scope] td.wrap strong:first-of-type {
padding: 0.2rem 0.5rem;
}

#form_plugins span[data-scope="admin"],
#plugins-table tbody tr[data-scope="admin"] td.wrap strong:first-of-type {
background-color: #258fd6;
color: #fff;
}

#form_plugins span[data-scope="site"],
#plugins-table tbody tr[data-scope="site"] td.wrap strong:first-of-type {
background-color: green;
color: #fff;
}
>>>>>>> c85a04a4b20f1ee08bf073ca1db89b9061e04bb9
2 changes: 1 addition & 1 deletion core/lang/it/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,4 +495,4 @@
'L_ERR_INVALID_DATE_UPDATE' => 'Data non valida aggiornato',
'L_CONFIG_THEME_UPDATE' => 'Cambia Aspetto',
);
?>
?>
79 changes: 55 additions & 24 deletions core/lib/class.plx.plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,36 @@ public function loadPlugins() {
$nb = sizeof($iTags['plugin']);
# On boucle sur $nb
for($i = 0; $i < $nb; $i++) {
$name = $values[$iTags['plugin'][$i] ]['attributes']['name'];
if($instance=$this->getInstance($name)) {
$this->aPlugins[$name] = $instance;
$this->aHooks = array_merge_recursive($this->aHooks, $instance->getHooks());
# Si le plugin a une méthode pour des actions de mises à jour
if(method_exists($instance, 'onUpdate')) {
if(is_file(PLX_PLUGINS.$name.'/update')) {
# on supprime le fichier update pour eviter d'appeler la methode onUpdate
# à chaque chargement du plugin
chmod(PLX_PLUGINS.$name.'/update', 0644);
unlink(PLX_PLUGINS.$name.'/update');
$updAction = $instance->onUpdate();
$attributes = $values[ $iTags['plugin'][$i] ]['attributes'];
$name = $attributes['name'];
$scope = (!empty($attributes['scope'])) ? $attributes['scope'] : '';
if(
defined('PLX_ADMIN') or
empty($scope) or # retro-compatibilité pour plugin sans balise <scope>
($scope == 'site')
) {
if(
empty($scope) or
(defined('PLX_ADMIN') and $scope == 'admin') or
(!defined('PLX_ADMIN') and $scope == 'site')
) {
if($instance = $this->getInstance($name)) {
$this->aPlugins[$name] = $instance;
$this->aHooks = array_merge_recursive($this->aHooks, $instance->getHooks());
# Si le plugin a une méthode pour des actions de mises à jour
if(method_exists($instance, 'onUpdate')) {
if(is_file(PLX_PLUGINS.$name.'/update')) {
# on supprime le fichier update pour eviter d'appeler la methode onUpdate
# à chaque chargement du plugin
chmod(PLX_PLUGINS.$name.'/update', 0644);
unlink(PLX_PLUGINS.$name.'/update');
$updAction = $instance->onUpdate();
}
}
}
} else {
# Si PLX_ADMIN, on recense le plugin pour les styles CSS, sans charger sa class
$this->aPlugins[$name] = false;
}
}
}
Expand Down Expand Up @@ -218,8 +235,18 @@ public function saveConfig($content) {
# Début du fichier XML
$xml = "<?xml version='1.0' encoding='".PLX_CHARSET."'?>\n";
$xml .= "<document>\n";
foreach($this->aPlugins as $k=>$v) {
$xml .= "\t<plugin name=\"$k\"></plugin>\n";
foreach($this->aPlugins as $name=>$plugin) {
if(!empty($plugin)) {
$scope = $plugin->getInfo('scope');
} elseif($plugInstance=$this->getInstance($name)) {
$scope = $plugInstance->getInfo('scope');
} else {
$scope = '';
}
$xml .= <<< PLUGIN
<plugin name="$name" scope="$scope"></plugin>
PLUGIN;
}
$xml .= "</document>";

Expand Down Expand Up @@ -264,21 +291,24 @@ public function deleteDir($deldir) { #fonction récursive
public function cssCache($type) {

$cache = '';
foreach($this->aPlugins as $plugName => $plugInstance) {
$filename = PLX_ROOT.PLX_CONFIG_PATH.'plugins/'.$plugName.'.'.$type.'.css';
if(is_file($filename)) {
$cache .= trim(file_get_contents($filename));
} else {
$filename = PLX_PLUGINS.$plugName.'/css/'.$type.'.css';
if(!preg_match('@\.css$@', $type)) $type .= '.css';
foreach(array_keys($this->aPlugins) as $plugName) {
$filesList = array(
PLX_ROOT.PLX_CONFIG_PATH."plugins/$plugName.$type",
PLX_PLUGINS."$plugName/css/$type"
);
foreach($filesList as $filename) {
if(is_file($filename)) {
$cache .= trim(file_get_contents($filename));
break;
}
}
}
if(is_file(PLX_PLUGINS.$type.'.css'))
unlink(PLX_PLUGINS.$type.'.css');
if($cache!='') {
return plxUtils::write(plxUtils::minify($cache), PLX_PLUGINS.$type.'.css');
$minify_filename = PLX_PLUGINS.$type;
if(!empty($cache)) {
return plxUtils::write(plxUtils::minify($cache), $minify_filename);
} elseif((is_file($minify_filename))) {
unlink($minify_filename);
}
return true;
}
Expand Down Expand Up @@ -631,6 +661,7 @@ public function getInfos() {
'date' => (isset($iTags['date']) AND isset($values[$iTags['date'][0]]['value']))?$values[$iTags['date'][0]]['value']:'',
'site' => (isset($iTags['site']) AND isset($values[$iTags['site'][0]]['value']))?$values[$iTags['site'][0]]['value']:'',
'description' => (isset($iTags['description']) AND isset($values[$iTags['description'][0]]['value']))?$values[$iTags['description'][0]]['value']:'',
'scope' => (isset($iTags['scope']) AND isset($values[$iTags['scope'][0]]['value']))?strtolower($values[$iTags['scope'][0]]['value']):''
);

}
Expand Down
1 change: 1 addition & 0 deletions readme/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
[+] #264 fonction debugJS (contribution bazooka07)
[+] #265 Affichage des archives sur une périodes glissantes de 12 mois (contribution bazooka07)
[+] #266 Tri des pages statiques, catégories et plugins par drag n drop (contribution bazooka07)
[+] #269 Ajout scope[admin|site] dans les fichiers infos.xml des plugins pour charger un plugin uniquement coté admin, site ou les 2 (contribution bazooka07)
FIX Suppression fichier plugin update impossible (droit fichier)
FIX Chevauchement des menus de l'administration avec un facteur de zoom > 100%
FIX Administration : mauvais affichage des caractères spéciaux dans le nom de l'auteur d'un commentaire (contribution bazooka07)
Expand Down

0 comments on commit 42bdb37

Please sign in to comment.