Spécialisation de l'éditeur
Code
Éditez le fichier actions/campaigneditpage.php :
- global $with_toolbar;
- $node_editor = build('smseditor', $lang, $clang, $node_id);
Créez le fichier smseditor.php dans le dossier blocks avec le contenu suivant :
- require_once 'readarg.php';
- require_once 'strtofname.php';
- require_once 'models/sms.inc';
- function smseditor($lang, $clang, $node_id) {
- $action='init';
- if (isset($_POST['sms_configure'])) {
- $action='configure';
- }
- $sms_modified=$sms_title=$sms_name=$sms_cloud=$sms_subject=$sms_text=false;
- switch($action) {
- case 'init':
- $r = sms_get_campaign($clang, $node_id);
- if ($r) {
- extract($r); /* sms_modified sms_title sms_name sms_cloud sms_subject sms_text */
- }
- break;
- case 'configure':
- if (isset($_POST['sms_modified'])) {
- $sms_modified=filter_var($_POST['sms_modified'], FILTER_VALIDATE_INT, array('options' => array('min_range' => 0)));
- }
- if (isset($_POST['sms_title'])) {
- $sms_title=readarg($_POST['sms_title']);
- $sms_name = strtofname($sms_title);
- }
- if (isset($_POST['sms_cloud'])) {
- $sms_cloud=readarg($_POST['sms_cloud'], true, false); // trim but DON'T strip!
- preg_match_all('/(\S+)/', $sms_cloud, $r);
- $sms_cloud=implode(' ', array_unique($r[0]));
- }
- if (isset($_POST['sms_subject'])) {
- $sms_subject=readarg($_POST['sms_subject']);
- }
- if (isset($_POST['sms_text'])) {
- $sms_text=readarg($_POST['sms_text']);
- }
- break;
- default:
- break;
- }
- $missing_title=false;
- $bad_title=false;
- $missing_subject=false;
- $missing_text=false;
- switch($action) {
- case 'configure':
- if (!$sms_title or !$sms_name) {
- $missing_title = true;
- }
- else if (!preg_match('#^\w+(-\w+)*$#', $sms_name)) {
- $bad_title = true;
- }
- if (!$sms_subject) {
- $missing_subject = true;
- }
- if (!$sms_text) {
- $missing_text = true;
- }
- break;
- default:
- if (!$sms_text) {
- $missing_text = true;
- }
- break;
- }
- $internal_error=false;
- switch($action) {
- case 'configure':
- if ($missing_title or $bad_title or $missing_text) {
- break;
- }
- $r = sms_set_campaign($clang, $node_id, $sms_title, $sms_name, $sms_cloud, $sms_subject, $sms_text);
- if (!$r) {
- $internal_error=true;
- break;
- }
- $sms_modified=time();
- break;
- default:
- break;
- }
- $inlanguages=view('inlanguages', false, compact('clang'));
- $errors = compact('internal_error', 'missing_title', 'bad_title', 'missing_subject', 'missing_text');
- $output = view('smseditor', $lang, compact('clang', 'inlanguages', 'sms_modified', 'sms_title', 'sms_cloud', 'sms_subject', 'sms_text', 'errors'));
- return $output;
- }
Ajoutez les fonctions sms_get_campaign et sms_set_campaign dans le fichier models/sms.inc:
- require_once 'models/node.inc';
- function sms_get_campaign($lang, $node_id) {
- $sqllang=db_sql_arg($lang, false);
- $tabnode=db_prefix_table('node');
- $tabnodelocale=db_prefix_table('node_locale');
- $tabnodecontent=db_prefix_table('node_content');
- $tabcontentsms=db_prefix_table('content_sms');
- $sql="SELECT nloc.name AS sms_name, nloc.title AS sms_title, nloc.abstract AS sms_subject, nloc.cloud AS sms_cloud, UNIX_TIMESTAMP(n.modified) AS sms_modified, c.text AS sms_text FROM $tabnode n JOIN $tabnodelocale nloc ON nloc.node_id=n.node_id AND nloc.locale=$sqllang LEFT JOIN $tabnodecontent nc ON nc.node_id=n.node_id AND nc.content_type='sms' AND nc.ignored=FALSE LEFT JOIN $tabcontentsms c ON c.content_id=nc.content_id AND c.locale=nloc.locale WHERE n.node_id=$node_id";
- $r = db_query($sql);
- return $r ? $r[0] : false;
- }
- function sms_set_campaign($lang, $node_id, $sms_title, $sms_name, $sms_cloud, $sms_subject, $sms_text) {
- $tabnode=db_prefix_table('node');
- $sql="UPDATE $tabnode SET modified=NOW() WHERE node_id=$node_id";
- $r = db_update($sql);
- if ($r === false) {
- return false;
- }
- $sqllang=db_sql_arg($lang, false);
- $sqlname=db_sql_arg($sms_name, true);
- $sqltitle=db_sql_arg($sms_title, true, true);
- $sqlcloud=db_sql_arg($sms_cloud, true, true);
- $sqlabstract=db_sql_arg($sms_subject, true, true);
- $tabnodelocale=db_prefix_table('node_locale');
- $sql="INSERT INTO $tabnodelocale (node_id, locale, name, title, abstract, cloud) SELECT $node_id, $sqllang, $sqlname, $sqltitle, $sqlabstract, $sqlcloud WHERE NOT EXISTS (SELECT node_id FROM $tabnodelocale WHERE node_id=$node_id AND locale=$sqllang)";
- $r = db_insert($sql);
- if ($r === false) {
- return false;
- }
- if ($r === 0) {
- $sql="UPDATE $tabnodelocale SET name=$sqlname, title=$sqltitle, abstract=$sqlabstract, cloud=$sqlcloud WHERE node_id=$node_id AND locale=$sqllang";
- $r = db_update($sql);
- if ($r === false) {
- return false;
- }
- }
- cloud_tag_node($lang, $node_id, $sms_cloud);
- $tabnodecontent=db_prefix_table('node_content');
- $tabcontentsms=db_prefix_table('content_sms');
- $sql="SELECT nc.content_id FROM $tabnodecontent nc WHERE nc.node_id=$node_id AND nc.content_type='sms'";
- $r = db_query($sql);
- if (!$r) {
- $r = node_create_content($lang, $node_id, 'sms');
- if (!$r) {
- return false;
- }
- $content_id = $r['content_id'];
- }
- else {
- $content_id = $r[0]['content_id'];
- }
- $content_type = 'sms';
- $content_ignored = false;
- $content_sms_text = $sms_text;
- return node_set_contents($lang, $node_id, array(compact('content_id', 'content_type', 'content_ignored', 'content_sms_text')));
- }
Créez la vue smseditor en français et en anglais dans les fichiers views/fr/smseditor.phtml et views/en/smseditor.phtml :
- <?php if ($sms_modified): ?>
- <?php require_once 'datefr.php'; ?>
- <p class="info" title="Dernière modification"><?php echo longdate_fr($sms_modified); ?> à <?php echo date('H:i', $sms_modified); ?></p>
- <?php endif; ?>
- <p class="info">Appuyez sur le bouton d'assistance <span class="btn_edit btn_help" title="Aide">aide</span> pour basculer l'affichage des messages d'aide.</p>
- <?php extract($errors); ?>
- <form method="post" class="compact">
- <input name="clang" type="hidden" value="<?php echo $clang; ?>" />
- <?php if ($sms_modified): ?>
- <input name="sms_modified" type="hidden" value="<?php echo $sms_modified; ?>" />
- <?php endif; ?>
- <p>
- <?php echo $inlanguages; ?>
- <span id="node_hidy" class="hidy">+</span>
- </p>
- <div id="node">
- <p class="inlabel<?php if ($missing_title or $bad_title): ?> inerror<?php endif; ?>">Titre :</p>
- <p><input id="sms_title" name="sms_title" type="text" size="40" maxlength="100" value="<?php if ($sms_title): ?><?php echo htmlspecialchars($sms_title, ENT_COMPAT, 'UTF-8'); ?><?php endif; ?>" title="Titre de la campagne" onkeypress="return focusonenter(event, 'sms_cloud')"/></p>
- <p class="inlabel">Nuage :</p>
- <textarea id="sms_cloud" name="sms_cloud" cols="80" rows="2" title="Série de mots clés pour le moteur de recherche"><?php if ($sms_cloud): ?><?php echo htmlspecialchars($sms_cloud, ENT_COMPAT, 'UTF-8'); ?><?php endif; ?></textarea>
- <p class="help helptoggle">
- Associez des mots clés à cette campagne.
- </p>
- <p class="inlabel<?php if ($missing_subject): ?> inerror<?php endif; ?>">Sujet :</p>
- <textarea id="sms_subject" name="sms_subject" cols="80" rows="2" title="Juste un paragraphe"><?php if ($sms_subject): ?><?php echo htmlspecialchars($sms_subject, ENT_COMPAT, 'UTF-8'); ?><?php endif; ?></textarea>
- <p class="help helptoggle">
- Décrivez le sujet de la campagne.
- </p>
- </div>
- <p class="inlabel<?php if ($missing_text): ?> inerror<?php endif; ?>">Message :</p>
- <textarea id="sms_text" name="sms_text" cols="80" rows="4" title="SMS" placeholder="Tapez le texte du SMS..."><?php if ($sms_text): ?><?php echo htmlspecialchars($sms_text, ENT_COMPAT, 'UTF-8'); ?><?php endif; ?></textarea>
- <p class="help helptoggle">
- </p>
- <p><input type="submit" class="submit submit_configure<?php if ($missing_title or $bad_title): ?> inerror<?php endif; ?>" name="sms_configure" id="sms_configure" value="Configurer" title="Configurez la campagne" /></p>
- </form>
- <?php if (!$missing_subject): ?>
- <?php head('javascript', 'jquery.cookie'); ?>
- <script>
- if ($.cookie('hidenode') == 1) {
- $('#node').hide();
- }
- $('#node_hidy').click(function() {
- $('#node').toggle();
- $.cookie('hidenode', $('#node').is(':hidden') ? 1 : 0, { path: '/' });
- });
- </script>
- <?php endif; ?>
- <?php
- $focus=false;
- if ($missing_title or $bad_title) {
- $focus='#sms_title';
- }
- else if ($missing_text) {
- $focus='#sms_text';
- }
- ?>
- <?php if ($focus): ?>
- <script>
- $(document).ready(function() {
- $('<?php echo $focus; ?>').focus();
- });
- </script>
- <?php endif; ?>
- <?php head('javascript', 'jquery.cookie'); ?>
- <script>
- function togglehelp() {
- $('.helptoggle').each(function() {
- $(this).toggle();
- });
- $.cookie('nosmshelp', $.cookie('nosmshelp') == 1 ? '0' : '1');
- }
- if ($.cookie('nosmshelp') == 1) {
- $('.helptoggle').each(function() {
- $(this).hide();
- });
- }
- $('.btn_help').each(function() {
- $(this).click(function() {togglehelp();});
- });
- </script>
- <?php if ($sms_modified): ?>
- <?php require_once 'dateen.php'; ?>
- <p class="info" title="Last modification"><?php echo longdate_en($sms_modified); ?> at <?php echo date('H:i', $sms_modified); ?></p>
- <?php endif; ?>
- <p class="info">Press the assistance button <span class="btn_edit btn_help" title="Help">help</span> to toggle the display of help messages.</p>
- <?php extract($errors); ?>
- <form method="post" class="compact">
- <input name="clang" type="hidden" value="<?php echo $clang; ?>" />
- <?php if ($sms_modified): ?>
- <input name="sms_modified" type="hidden" value="<?php echo $sms_modified; ?>" />
- <?php endif; ?>
- <p>
- <?php echo $inlanguages; ?>
- <span id="node_hidy" class="hidy">+</span>
- </p>
- <div id="node">
- <p class="inlabel<?php if ($missing_title or $bad_title): ?> inerror<?php endif; ?>">Title:</p>
- <p><input id="sms_title" name="sms_title" type="text" size="40" maxlength="100" value="<?php if ($sms_title): ?><?php echo htmlspecialchars($sms_title, ENT_COMPAT, 'UTF-8'); ?><?php endif; ?>" title="Campaign title" onkeypress="return focusonenter(event, 'sms_cloud')"/></p>
- <p class="inlabel">Cloud:</p>
- <textarea id="sms_cloud" name="sms_cloud" cols="80" rows="2" title="Series of keywords for the search engine"><?php if ($sms_cloud): ?><?php echo htmlspecialchars($sms_cloud, ENT_COMPAT, 'UTF-8'); ?><?php endif; ?></textarea>
- <p class="help helptoggle">
- Associate keywords to this campaign.
- </p>
- <p class="inlabel<?php if ($missing_subject): ?> inerror<?php endif; ?>">Subject:</p>
- <textarea id="sms_subject" name="sms_subject" cols="80" rows="2" title="Just a paragraph"><?php if ($sms_subject): ?><?php echo htmlspecialchars($sms_subject, ENT_COMPAT, 'UTF-8'); ?><?php endif; ?></textarea>
- <p class="help helptoggle">
- Describe the subject of the campaign.
- </p>
- </div>
- <p class="inlabel<?php if ($missing_text): ?> inerror<?php endif; ?>">Message:</p>
- <textarea id="sms_text" name="sms_text" cols="80" rows="4" title="SMS" placeholder="Type in the text of the SMS..."><?php if ($sms_text): ?><?php echo htmlspecialchars($sms_text, ENT_COMPAT, 'UTF-8'); ?><?php endif; ?></textarea>
- <p class="help helptoggle">
- </p>
- <p><input type="submit" class="submit submit_configure<?php if ($missing_title or $bad_title): ?> inerror<?php endif; ?>" name="sms_configure" id="sms_configure" value="Configure" title="Configure the campaign" /></p>
- </form>
- <?php if (!$missing_title): ?>
- <?php head('javascript', 'jquery.cookie'); ?>
- <script>
- if ($.cookie('hidenode') == 1) {
- $('#node').hide();
- }
- $('#node_hidy').click(function() {
- $('#node').toggle();
- $.cookie('hidenode', $('#node').is(':hidden') ? 1 : 0, { path: '/' });
- });
- </script>
- <?php endif; ?>
- <?php
- $focus=false;
- if ($missing_title or $bad_title) {
- $focus='#sms_title';
- }
- else if ($missing_text) {
- $focus='#sms_text';
- }
- ?>
- <?php if ($focus): ?>
- <script>
- $(document).ready(function() {
- $('<?php echo $focus; ?>').focus();
- });
- </script>
- <?php endif; ?>
- <?php head('javascript', 'jquery.cookie'); ?>
- <script>
- function togglehelp() {
- $('.helptoggle').each(function() {
- $(this).toggle();
- });
- $.cookie('nosmshelp', $.cookie('nosmshelp') == 1 ? '0' : '1');
- }
- if ($.cookie('nosmshelp') == 1) {
- $('.helptoggle').each(function() {
- $(this).hide();
- });
- }
- $('.btn_help').each(function() {
- $(this).click(function() {togglehelp();});
- });
- </script>
Ajoutez le CSS pour les messages d'aide à la fin du fichier css/theme.css :
Test
Connectez-vous
en tant que client et allez dans les campagnes.
Éditez
la campagne Le moteur web.
Modifiez le sujet et le message de la campagne et appuyez sur Configurer.
Si le titre ou le message est vide, une erreur est signalée et la modification est rejetée.
Message :
Si le sujet est vide, une erreur est signalée mais la modification est acceptée.
Appuyez sur le drapeau
pour afficher la version en anglais.
Appuyez sur le drapeau
pour afficher la version en français.
IMPORTANT : Le contenu de l'éditeur est perdu après un changement de langue.
Appuyez sur Configurer pour valider vos modifications.
Cliquez sur le triangle
en face du sélecteur de langue pour ne montrer que le message.
Cliquez de nouveau sur le triangle
pour afficher tous les champs.
NOTE : Cette option est conservée par l'éditeur. Si vous ne voyez pas tous les champs d'une campagne, pensez à cliquer sur le triangle
pour tous les afficher.
Git
- /izendsms.com
- actions
- campaigneditpage.php
- blocks
- smseditor.php
- css
- theme.css
- models
- sms.inc
- views
- en
- smseditor.phtml
- fr
- smseditor.phtml
- en
- actions
Commitez cette version :
$ git status
$ git add actions blocks/smseditor.php css models/sms.inc views/en/smseditor.phtml views/fr/smseditor.phtml
$ git commit -m'Adds a dedicated campaign editor'
Commentaires