diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..c7376d5 --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,21 @@ +v1.1 - 05-03-2015 - Pierre Van Glabeke +* compatibilité dc2.7 +* cosmétique dc2.6 +* localisation +* aide intégrée +* version effectuée depuis la v1.0.1 présente sur DA + +2010-07-15 Gaetan Guillard +* v1.0.1 - Corrections for compatibility with Dotclear 2.2 + +2008-10-18 Oleksandr Syenchuk +* v2008.10 - Removed theme parameter from URL + + +2008-08-21 Oleksandr Syenchuk +* Excluded themes can not be selected by user. + + +2008-04-21 Oleksandr Syenchuk +* Dotclear r1790 compatibility, see + http://dev.dotclear.net/2.0/changeset/1790 diff --git a/_admin.php b/_admin.php new file mode 100644 index 0000000..cc92945 --- /dev/null +++ b/_admin.php @@ -0,0 +1,36 @@ +addItem(__('Theme switcher'),'plugin.php?p=arlequin', + 'index.php?pf=arlequin/icon.png', + preg_match('/plugin.php\?p=arlequin(&.*)?$/',$_SERVER['REQUEST_URI']), + $core->auth->check('contentadmin',$core->blog->id)); + +require dirname(__FILE__).'/_widgets.php'; + +$core->addBehavior('adminDashboardFavorites','arlequinDashboardFavorites'); + +function arlequinDashboardFavorites($core,$favs) +{ + $favs->register('arlequin', array( + 'title' => __('Theme switcher'), + 'url' => 'plugin.php?p=arlequin', + 'small-icon' => 'index.php?pf=arlequin/icon.png', + 'large-icon' => 'index.php?pf=arlequin/icon-big.png', + 'permissions' => 'usage,contentadmin' + )); +} \ No newline at end of file diff --git a/_define.php b/_define.php new file mode 100644 index 0000000..2e6c394 --- /dev/null +++ b/_define.php @@ -0,0 +1,31 @@ +registerModule( + /* Name */ 'Arlequin', + /* Description*/ 'Allows visitors choose a theme', + /* Author */ 'Oleksandr Syenchuk, Pierre Van Glabeke', + /* Version */ '1.1', + /* Properties */ + array( + 'permissions' => 'contentadmin', + 'type' => 'plugin', + 'dc_min' => '2.7', + 'support' => 'http://forum.dotclear.org/viewtopic.php?id=48345', + 'details' => 'http://plugins.dotaddict.org/dc2/details/arlequin' + ) +); \ No newline at end of file diff --git a/_public.php b/_public.php new file mode 100644 index 0000000..6db862e --- /dev/null +++ b/_public.php @@ -0,0 +1,185 @@ +blog); +$core->addBehavior('publicBeforeDocument',array('publicArlequinEngine','adjustCache')); +$core->tpl->addValue('themesList',array('publicArlequinInterface','template')); + +class publicArlequinEngine +{ + public static $cookie_theme; + public static $cookie_upddt; + + public static function trigger($blog) + { + $cname = base_convert($blog->uid,16,36); + self::$cookie_theme = 'dc_theme_'.$cname; + self::$cookie_upddt = 'dc_user_upddt_'.$cname; + + if (!empty($_REQUEST['theme'])) { + # Set cookie for 365 days + setcookie(self::$cookie_theme,$_REQUEST['theme'],time()+31536000,'/'); + setcookie(self::$cookie_upddt,time(),time()+31536000,'/'); + + # Redirect if needed + if (isset($_GET['theme'])) { + $p = '/(\?|&)theme(=.*)?$/'; + http::redirect(preg_replace($p,'',http::getSelfURI())); + } + + # Switch theme + self::switchTheme($blog,$_REQUEST['theme']); + } + elseif (!empty($_COOKIE[self::$cookie_theme])) { + self::switchTheme($blog,$_COOKIE[self::$cookie_theme]); + } + } + + public static function adjustCache($core) + { + if (!empty($_COOKIE[self::$cookie_upddt])) { + $GLOBALS['mod_ts'][] = (integer) $_COOKIE[self::$cookie_upddt]; + } + } + + public static function switchTheme($blog,$theme) + { + if ($blog->settings->multitheme->mt_exclude) { + if (in_array($theme,explode('/',$blog->settings->multitheme->mt_exclude))) { + return; + } + } + + $GLOBALS['__theme'] = $blog->settings->system->theme = $theme; + } +} + +class publicArlequinInterface +{ + public static function arlequinWidget($w) + { + return self::getHTML($w); + } + + public static function template($attr) + { + return ''; + } + + public static function getHTML($w=false) + { + global $core; + + if ($w->offline) + return; + + $cfg = @unserialize($core->blog->settings->multitheme->get('mt_cfg')); + + if (($w->homeonly == 1 && $core->url->type != 'default') || + ($w->homeonly == 2 && $core->url->type == 'default')) { + return; + } + + if ($cfg === false || + ($names = self::getNames()) === false) { + return; + } + + # Current page URL and the associated query string. Note : the URL for + # the switcher ($s_url) is different to the URL for an item ($e_url) + $s_url = $e_url = http::getSelfURI(); + + # If theme setting is already present in URL, we will replace its value + $replace = preg_match('/(\\?|&)theme\\=[^&]*/',$e_url); + + # URI extension to send theme setting by query string + if ($replace) { + $ext = ''; + } + elseif (strpos($e_url,'?') === false) { + $ext = '?theme='; + } + else { + $ext = (substr($e_url,-1) == '?' ? '' : '&').'theme='; + } + + $res = ''; + foreach ($names as $k=>$v) + { + if ($k == $GLOBALS['__theme']) { + $format = $cfg['a_html']; + } else { + $format = $cfg['e_html']; + } + + if ($replace) { + $e_url = preg_replace( + '/(\\?|&)(theme\\=)([^&]*)/', + '$1${2}'.addcslashes($k,'$\\'), + $e_url); + $val = ''; + } + else { + $val = html::escapeHTML(rawurlencode($k)); + } + $res .= sprintf($format, + $e_url,$ext,$val, + html::escapeHTML($v['name']), + html::escapeHTML($v['desc']), + html::escapeHTML($k)); + } + + # Nothing to display + if (!trim($res)) { + return; + } + + $res = sprintf($cfg['s_html'],$s_url,$res); + + if ($w) { + + $res = + ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : ''). + $res; + + return $w->renderDiv($w->content_only,'arlequin '.$w->class,'',$res); + } + + return $res; + } + + public static function getNames() + { + global $core; + + $mt_exclude = $core->blog->settings->multitheme->mt_exclude; + $exclude = array(); + if (!empty($mt_exclude)) { + $exclude = array_flip(explode('/',$core->blog->settings->multitheme->mt_exclude)); + } + + $names = array_diff_key($core->themes->getModules(),$exclude); + + return empty($names) ? false : $names; + } +} \ No newline at end of file diff --git a/_widgets.php b/_widgets.php new file mode 100644 index 0000000..3edb122 --- /dev/null +++ b/_widgets.php @@ -0,0 +1,73 @@ +addBehavior('initWidgets',array('adminArlequin','initWidgets')); + +class adminArlequin +{ + public static function initWidgets($w) + { + $w->create('arlequin',__('Arlequin'),array('publicArlequinInterface','arlequinWidget'), + null, + __('Theme switcher')); + $w->arlequin->setting('title',__('Title:'),__('Choose a theme')); + $w->arlequin->setting('homeonly',__('Display on:'),0,'combo', + array( + __('All pages') => 0, + __('Home page only') => 1, + __('Except on home page') => 2 + ) + ); + $w->arlequin->setting('content_only',__('Content only'),0,'check'); + $w->arlequin->setting('class',__('CSS class:'),''); + $w->arlequin->setting('offline',__('Offline'),0,'check'); + } + + public static function getDefaults() + { + return array( + 'e_html'=>'
  • %4$s
  • ', + 'a_html'=>'
  • %4$s
  • ', + 's_html'=>'
      %2$s
    '); + } + + public static function loadSettings($settings,&$initialized) + { + global $core; + + $initialized = false; + $mt_cfg = @unserialize($settings->multitheme->get('mt_cfg')); + $mt_exclude = $settings->multitheme->get('mt_exclude'); + + // Paramètres corrompus ou inexistants + if ($mt_cfg === false || + $mt_exclude === null || + !(isset($mt_cfg['e_html']) && + isset($mt_cfg['a_html']) && + isset($mt_cfg['s_html']))) + { + $mt_cfg = adminArlequin::getDefaults(); + $settings->addNameSpace('multitheme'); + $settings->multitheme->put('mt_cfg',serialize($mt_cfg),'string','Arlequin configuration'); + $settings->multitheme->put('mt_exclude','customCSS','string','Excluded themes'); + $initialized = true; + $core->blog->triggerBlog(); + } + + return array($mt_cfg,$mt_exclude); + } +} \ No newline at end of file diff --git a/icon-big.png b/icon-big.png new file mode 100644 index 0000000..e9ed514 Binary files /dev/null and b/icon-big.png differ diff --git a/icon.png b/icon.png new file mode 100644 index 0000000..f78fad5 Binary files /dev/null and b/icon.png differ diff --git a/index.php b/index.php new file mode 100644 index 0000000..3d910f7 --- /dev/null +++ b/index.php @@ -0,0 +1,141 @@ +blog->settings->addNameSpace('multitheme'); + list($mt_cfg,$mt_exclude) = + adminArlequin::loadSettings ($core->blog->settings,$initialized); + + /* Enregistrement des données depuis les formulaires + --------------------------------------------------- */ + + if (isset($_POST['mt_action_config'])) + { + $mt_cfg['e_html'] = $_POST['e_html']; + $mt_cfg['a_html'] = $_POST['a_html']; + $mt_cfg['s_html'] = $_POST['s_html']; + $mt_exclude = $_POST['mt_exclude']; + } + + /* Traitement des requêtes + --------------------------------------------------- */ + + if (isset($_POST['mt_action_config'])) + { + $core->blog->settings->multitheme->put('mt_cfg',serialize($mt_cfg)); + $core->blog->settings->multitheme->put('mt_exclude',$mt_exclude); + $messages[] = __('Settings have been successfully updated.'); + $core->blog->triggerBlog(); + http::redirect($p_url.'&config=1'); + } + if (isset($_POST['mt_action_restore'])) + { + $core->blog->settings->multitheme->drop('mt_cfg'); + $core->blog->settings->multitheme->drop('mt_exclude'); + $core->blog->triggerBlog(); + http::redirect($p_url.'&restore=1'); + } +} +catch (Exception $e) +{ + $core->error->add($e->getMessage()); +} + +/* DISPLAY +--------------------------------------------------- */ + +if ($initialized) { + $messages[] = __('Settings have been reinitialized.'); +} + +// Headers + +$jsModels = ''; $cslashes = "\n\"\'"; +foreach ($mt_models as $m) +{ + $jsModels .= "\t". + 'arlequin.addModel('. + '"'.html::escapeJS($m['name']).'",'. + '"'.addcslashes($m['s_html'],$cslashes).'",'. + '"'.addcslashes($m['e_html'],$cslashes).'",'. + '"'.addcslashes($m['a_html'],$cslashes).'"'. + ");\n"; +} + +echo ' + +'.$page_title.''. +dcPage::jsLoad('index.php?pf=arlequin/js/models.js').' + +'. +dcPage::breadcrumb( + array( + html::escapeHTML($core->blog->name) => '', + ''.$page_title.'' => '' + )); + +// Messages +if (!empty($_GET['config'])) { + dcPage::success(__('Settings have been successfully updated.')); +} +if (!empty($_GET['restore'])) { + dcPage::success(__('Settings have been reinitialized.')); +} + +echo + '
    +

    '.__('Switcher display format').'

    +
    +

    '. + form::textArea('s_html',50,10,html::escapeHTML($mt_cfg['s_html'])).'

    +
    +

    +

    +

    + +

    +
    +

    + '. + (is_callable(array($core,'formNonce')) ? $core->formNonce() : '').'

    +
    '; + +dcPage::helpBlock('arlequin'); ?> + \ No newline at end of file diff --git a/js/models.js b/js/models.js new file mode 100644 index 0000000..e7576c9 --- /dev/null +++ b/js/models.js @@ -0,0 +1,82 @@ +/* -*- tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/***************************************************************\ + * This is 'Arlequin', a plugin for Dotclear 2 * + * * + * Copyright (c) 2007,2015 * + * Oleksandr Syenchuk and contributors. * + * * + * This is an open source software, distributed under the GNU * + * General Public License (version 2) terms and conditions. * + * * + * You should have received a copy of the GNU General Public * + * License along 'Arlequin' (see COPYING.txt); * + * if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * +\***************************************************************/ + +var arlequin = { + msg : { + predefined_models : 'Generic models', + select_model : 'Select a generic model:', + user_defined : 'User defined' + }, + + models : Array(), + + addModel : function(model_name, s_html, e_html, a_html) { + model = new Array(model_name,s_html,e_html,a_html); + arlequin.models.push(model); + }, + + addDefault : function() { + arlequin.addModel(arlequin.msg.user_defined, + $("#s_html").val(), + $("#e_html").val(), + $("#a_html").val()); + }, + + drawInterface : function() { + if (!arlequin.models.length) { + return; + } + + res = ''; + res += '

    '+arlequin.msg.select_model+' '; + res += ''; + res += '

    '; + + return res; + }, + + selectModel : function(id) { + if (!arlequin.models[id]) { return; } + + $("#s_html").val(arlequin.models[id][1]); + $("#e_html").val(arlequin.models[id][2]); + $("#a_html").val(arlequin.models[id][3]); + } +}; + + +$(function() { + if (!document.getElementById || !document.getElementById('models')) { return; } + + var c = $('#models'); + c.html('

    '+ + arlequin.msg.predefined_models+'

    '); + + $('#model-control').click(function() { + c.html(arlequin.drawInterface()); + + $('#mt_model').change(function() { + arlequin.selectModel(this.value); + }); + + return false; + }); +}); \ No newline at end of file diff --git a/locales/en/help/arlequin.html b/locales/en/help/arlequin.html new file mode 100644 index 0000000..d1b684d --- /dev/null +++ b/locales/en/help/arlequin.html @@ -0,0 +1,55 @@ + + + + Aide Arlequin + + +

    Inserting the theme selector in the blog interface

    + +
    +
    With a widget
    +
    The easiest way is to use the Theme Selector + widget that displays a list of available themes.
    + +
    In the template file
    +
    The switch can also be integrated into the blog interface by editing your + template file. Simply add the {{tpl:themesList}} instruction in + the desired location.
    +
    + +

    Understanding Models

    +

    Arlequin is notable for its flexible configuration, due to the concept of + models that create their own interfaces for the theme selector.

    +

    The information needed to operate the theme selector contained in variables + of the form %n$s where n is an integer + denoting a variable.

    +

    Here is the list of variables that you can use:

    +
    +
    In switcher HTML code
    +
    + + + + +
    VariableMeaning
    %1$sCurrent page URL
    %2$sItems HTML code
    + +
    In items HTML code
    +
    + + + + + + + + +
    VariableMeaning
    %1$sCurrent page URL
    %2$sA suffix to send theme setting through URL, e.g. "&theme="
    %3$sTheme identifier only to be used in a URL
    %4$sTheme name
    %5$sTheme description
    %6$sTheme identifier
    +
    + +

    Add your own predefined templates

    +

    If you are the administrator of a platform of blogs, you can change the + predefined templates by editing the file plugins/arlequin/models.php.

    +

    Suggestion: some interesting models can be created in + association with JavaScript or CSS property, changing your themes.

    + + \ No newline at end of file diff --git a/locales/en/resources.php b/locales/en/resources.php new file mode 100644 index 0000000..d976353 --- /dev/null +++ b/locales/en/resources.php @@ -0,0 +1,20 @@ + + + + Aide Arlequin + + +

    Insertion du sélecteur de thème dans l'interface du blog

    + +
    +
    Avec un widget
    +
    Le plus simple est d'utiliser le widget + Sélecteur de thème qui affiche la liste des thèmes disponibles.
    + +
    Dans le fichier template
    +
    Le sélecteur peut aussi être intégré dans l'interface du blog en éditant + directement votre fichier template. Il suffit pour cela d'ajouter l'instruction + {{tpl:themesList}} à l'endroit voulu.
    +
    + +

    Comprendre les modèles

    +

    Arlequin est remarquable pour sa souplesse de configuration, due à la notion + de modèles qui permettent de créer ses propres interfaces pour le + sélecteur de thème.

    +

    Les informations nécessaires au fonctionnement du sélecteur de thème sont + contenues dans des variables de la forme %n$sn + est un entier désignant une variable.

    +

    Voici la liste des variables que vous pouvez utiliser :

    +
    +
    Dans le code HTML du sélecteur
    +
    + + + + +
    VariableSignification
    %1$sL'adresse URL de la page courante
    %2$sLe code HTML des items
    + +
    Dans le code HTML des items
    +
    + + + + + + + + +
    VariableSignification
    %1$sL'adresse URL de la page courante
    %2$sUn suffixe pour envoyer le paramètre du thème à travers + l'URL, p. ex. "&theme="
    %3$sL'identifiant du thème à utiliser uniquement dans une URL
    %4$sLe nom du thème
    %5$sLa description du thème
    %6$sL'identifiant du thème
    +
    + +

    Ajouter ses propres modèles prédéfinis

    +

    Si vous êtes l'administrateur d'une plate-forme de blogs, vous pouvez modifier + les modèles prédéfinis en éditant le fichier plugins/arlequin/models.php.

    +

    Conseil : des modèles assez intéressants peuvent être créés + en association avec du JavaScript ou avec des propriétés CSS, en modifiant vos thèmes.

    + + \ No newline at end of file diff --git a/locales/fr/main.po b/locales/fr/main.po new file mode 100644 index 0000000..90c4ffe --- /dev/null +++ b/locales/fr/main.po @@ -0,0 +1,91 @@ +msgid "" +msgstr "" +"Content-Type: text/plain; charset=UTF-8\n" +"Project-Id-Version: Dotclear 2 Arlequin v1.1 module\n" +"POT-Creation-Date: \n" +"PO-Revision-Date: 2009-10-20 21:01+0100\n" +"Last-Translator: brol \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Poedit-Language: French\n" +"X-Poedit-KeywordsList: __\n" +"X-Poedit-Basepath: ../..\n" +"X-Poedit-SearchPath-0: .\n" + +#: models.php:32 +msgid "Bullets list" +msgstr "Liste à puces" + +#: models.php:39 +msgid "Scrolled list" +msgstr "Liste déroulante" + +#: models.php:48 +msgid "active theme" +msgstr "thème actif" + +#: forms.php:22 +msgid "Switcher display format" +msgstr "Format d'affichage du sélecteur" + +#: forms.php:24 +msgid "Switcher HTML code:" +msgstr "Code HTML du sélecteur :" + +#: forms.php:27 +msgid "Item HTML code:" +msgstr "Code HTML d'un item :" + +#: forms.php:29 +msgid "Active item HTML code:" +msgstr "Code HTML d'un item actif :" + +#: forms.php:35 +msgid "Excluded themes (separated by slashs '/'):" +msgstr "Thèmes exclus (séparés par des slashs \"/\") :" + +#: forms.php:38 +msgid "Update" +msgstr "Mettre à jour" + +#: forms.php:39 +msgid "Restore defaults" +msgstr "Réinitialiser les paramètres" + +#: _admin.php:18 +#: _admin.php:29 +msgid "Theme switcher" +msgstr "Sélecteur de thème" + +#: _admin.php:32 +msgid "Choose a theme" +msgstr "Choisissez un thème" + +#: index.php:51 +msgid "Settings have been successfully updated." +msgstr "Les paramètres ont été mis à jour avec succès." + +#: index.php:71 +msgid "Settings have been reinitialized." +msgstr "Les paramètres ont été réinitialisés." + +#: index.php:18 +msgid "Arlequin - theme switcher configuration" +msgstr "Arlequin - configuration du sélecteur de thème" + +#: index.php:95 +msgid "Predefined models" +msgstr "Modèles prédéfinis" + +#: index.php:96 +msgid "Select a model" +msgstr "Sélectionnez un modèle" + +#: index.php:97 +msgid "User defined" +msgstr "Défini par l'utilisateur" + +msgid "Allows visitors choose a theme" +msgstr "Permettre aux visiteurs de choisir un thème" + diff --git a/locales/fr/resources.php b/locales/fr/resources.php new file mode 100644 index 0000000..d976353 --- /dev/null +++ b/locales/fr/resources.php @@ -0,0 +1,20 @@ +__('Model name'), // Nom du modèle prédéfini, éventuellement + // traduit dans un fichier de langue + 's_html'=>'[HTML code]', // Code HTML du sélecteur de thème + 'e_html'=>'[HTML code]', // Code HTML d'un item pouvant être sélectionné + 'a_html'=>'[HTML code]' // Code HTML d'un item actif (thème sélectionné) +); + +//*/ + +$mt_models[] = array( + 'name'=>__('Bullets list'), + 's_html'=>'
      %2$s
    ', + 'e_html'=>'
  • %4$s
  • ', + 'a_html'=>'
  • %4$s
  • ' +); + +$mt_models[] = array( + 'name'=>__('Scrolled list'), + 's_html'=> + '
    '."\n". + '

    '."\n". + '

    '."\n". + '
    ', + 'e_html'=>'', + 'a_html'=>'' +); \ No newline at end of file