Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sélection des plugins à charger selon côté admin ou côté site #269

Merged
merged 1 commit into from
Dec 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 10 additions & 3 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 (<usage> == 'site')
if(empty($plugInstance) and $plugInstance=plxPlugins::getInstance($plugName)) {
$plugInstance->getInfos();
}
$output .= '<tr class="top" data-usage="'.$plugInstance->getInfo('usage').'">';

# checkbox
$output .= '<td>';
Expand Down Expand Up @@ -163,8 +167,11 @@ function pluginsList($plugins, $defaultLang, $type) {
</table>
</div>

<?php if($_SESSION['selPlugins']=='1') : ?>
<?php endif; ?>
<div id="plugins-usage" class="in-action-bar">
<div><strong data-usage=""><?php echo L_GENERAL_PURPOSE; ?></strong></div>
<div><strong data-usage="admin">Admin</strong></div>
<div><strong data-usage="site">Site</strong></div>
</div>

</form>

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
25 changes: 25 additions & 0 deletions core/admin/theme/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -854,4 +854,29 @@ select {

select {
padding: 0 18px 0 0;
}
/* ---- parametres_plugins ---- */
#plugins-table tbody tr[data-usage] td.wrap strong:first-of-type {
padding: 0.2rem 0.5rem;
}
#plugins-table tbody tr[data-usage="admin"] td.wrap strong:first-of-type,
#plugins-usage.in-action-bar strong[data-usage="admin"] {
background-color: red;
color: #fff;
}
#plugins-table tbody tr[data-usage="site"] td.wrap strong:first-of-type,
#plugins-usage.in-action-bar strong[data-usage="site"] {
background-color: green;
color: #fff;
}
#plugins-usage.in-action-bar {
right: 1.5rem;
width: 15rem;
margin-top: 1rem;
}
#plugins-usage.in-action-bar strong {
display: inline-block;
width: 100%;
margin: 0.3rem 0;
text-align: center;
}
1 change: 1 addition & 0 deletions core/lang/de/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@
'L_PLUGINS_CSS_TITLE' => 'Bearbeiten Sie den CSS-Code des Plugins',
'L_CONTENT_FIELD_FRONTEND' => 'CSS-Datei-Inhalte Website',
'L_CONTENT_FIELD_BACKEND' => 'CSS-Datei Content-Administrator',
'L_GENERAL_PURPOSE' => 'Allgemeiner Zweck',
'L_PLUGINS_TITLE' => 'Pluginverwaltung',
'L_PLUGINS_VERSION' => 'Version',
'L_PLUGINS_AUTHOR' => 'Autor',
Expand Down
1 change: 1 addition & 0 deletions core/lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@
'L_PLUGINS_CSS_TITLE' => 'Edit the css code of the plugin',
'L_CONTENT_FIELD_FRONTEND' => 'Css file content site',
'L_CONTENT_FIELD_BACKEND' => 'Css file content administrator',
'L_GENERAL_PURPOSE' => 'General purpose',
'L_PLUGINS_TITLE' => 'Manage plugins',
'L_PLUGINS_VERSION' => 'Version',
'L_PLUGINS_AUTHOR' => 'Author',
Expand Down
1 change: 1 addition & 0 deletions core/lang/es/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@
'L_PLUGINS_CSS_TITLE' => 'Editar el código CSS del complemento',
'L_CONTENT_FIELD_FRONTEND' => 'Contenido del archivo de código CSS para el sitio web',
'L_CONTENT_FIELD_BACKEND' => 'Contenido del archivo de código CSS para el sitio de administración',
'L_GENERAL_PURPOSE' => 'multiuso',

# parametres_plugins.php

Expand Down
1 change: 1 addition & 0 deletions core/lang/fr/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@
'L_PLUGINS_CSS_TITLE' => 'Éditer le code CSS du plugin',
'L_CONTENT_FIELD_FRONTEND' => 'Contenu fichier CSS site',
'L_CONTENT_FIELD_BACKEND' => 'Contenu fichier CSS administrateur',
'L_GENERAL_PURPOSE' => 'Tous usages',

# parametres_plugins.php

Expand Down
3 changes: 2 additions & 1 deletion core/lang/it/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@
'L_PLUGINS_CSS_TITLE' => 'Modificare il codice css del plugin',
'L_CONTENT_FIELD_FRONTEND' => 'Sito web contenuto del file Css',
'L_CONTENT_FIELD_BACKEND' => 'Amministratore contenuti css',
'L_GENERAL_PURPOSE' => 'tutto l\'uso',
'L_PLUGINS_TITLE' => 'Gestione plugin',
'L_PLUGINS_VERSION' => 'Versione',
'L_PLUGINS_AUTHOR' => 'Autore',
Expand Down Expand Up @@ -495,4 +496,4 @@
'L_ERR_INVALID_DATE_UPDATE' => 'Data non valida aggiornato',
'L_CONFIG_THEME_UPDATE' => 'Cambia Aspetto',
);
?>
?>
78 changes: 54 additions & 24 deletions core/lib/class.plx.plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,35 @@ 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'];
$usage = (!empty($attributes['usage'])) ? $attributes['usage'] : '';
if(
defined('PLX_ADMIN') or
empty($usage) or # retro-compatibilité pour plugin sans balise <usage>
($usage == 'site')
) {
if(
empty($usage) or
(defined('PLX_ADMIN') and $usage == 'admin') or
(!defined('PLX_ADMIN') and $usage == 'site')
) {
$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 +234,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)) {
$usage = $plugin->getInfo('usage');
} elseif($plugInstance=$this->getInstance($name)) {
$usage = $plugInstance->getInfo('usage');
} else {
$usage = '';
}
$xml .= <<< PLUGIN
<plugin name="$name" usage="$usage"></plugin>

PLUGIN;
}
$xml .= "</document>";

Expand Down Expand Up @@ -264,21 +290,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 +660,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']:'',
'usage' => (isset($iTags['usage']) AND isset($values[$iTags['usage'][0]]['value']))?strtolower($values[$iTags['usage'][0]]['value']):''
);

}
Expand Down