1
13

Spécialisation de l'éditeur

Code

Éditez le fichier actions/campaigneditpage.php :

  1.     global $with_toolbar;
  1.     $node_editor = build('smseditor', $lang, $clang, $node_id);

Créez le fichier smseditor.php dans le dossier blocks avec le contenu suivant :

  1. require_once 'readarg.php';
  2. require_once 'strtofname.php';
  3. require_once 'models/sms.inc';
  4.  
  5. function smseditor($lang, $clang, $node_id) {
  6.     $action='init';
  7.     if (isset($_POST['sms_configure'])) {
  8.         $action='configure';
  9.     }
  10.  
  11.     $sms_modified=$sms_title=$sms_name=$sms_cloud=$sms_subject=$sms_text=false;
  12.  
  13.     switch($action) {
  14.         case 'init':
  15.             $r = sms_get_campaign($clang, $node_id);
  16.             if ($r) {
  17.                 extract($r);    /* sms_modified sms_title sms_name sms_cloud sms_subject sms_text */
  18.             }
  19.             break;
  20.  
  21.         case 'configure':
  22.             if (isset($_POST['sms_modified'])) {
  23.                 $sms_modified=filter_var($_POST['sms_modified'], FILTER_VALIDATE_INT, array('options' => array('min_range' => 0)));
  24.             }
  25.             if (isset($_POST['sms_title'])) {
  26.                 $sms_title=readarg($_POST['sms_title']);
  27.                 $sms_name = strtofname($sms_title);
  28.             }
  29.             if (isset($_POST['sms_cloud'])) {
  30.                 $sms_cloud=readarg($_POST['sms_cloud'], true, false);   // trim but DON'T strip!
  31.                 preg_match_all('/(\S+)/', $sms_cloud, $r);
  32.                 $sms_cloud=implode(' ', array_unique($r[0]));
  33.             }
  34.             if (isset($_POST['sms_subject'])) {
  35.                 $sms_subject=readarg($_POST['sms_subject']);
  36.             }
  37.             if (isset($_POST['sms_text'])) {
  38.                 $sms_text=readarg($_POST['sms_text']);
  39.             }
  40.             break;
  41.         default:
  42.             break;
  43.     }
  44.  
  45.     $missing_title=false;
  46.     $bad_title=false;
  47.  
  48.     $missing_subject=false;
  49.  
  50.     $missing_text=false;
  51.  
  52.     switch($action) {
  53.         case 'configure':
  54.             if (!$sms_title or !$sms_name) {
  55.                 $missing_title = true;
  56.             }
  57.             else if (!preg_match('#^\w+(-\w+)*$#', $sms_name)) {
  58.                 $bad_title = true;
  59.             }
  60.  
  61.             if (!$sms_subject) {
  62.                 $missing_subject = true;
  63.             }
  64.  
  65.             if (!$sms_text) {
  66.                 $missing_text = true;
  67.             }
  68.  
  69.             break;
  70.  
  71.         default:
  72.             if (!$sms_text) {
  73.                 $missing_text = true;
  74.             }
  75.  
  76.             break;
  77.     }
  78.  
  79.     switch($action) {
  80.         case 'configure':
  81.             if ($missing_title or $bad_title or $missing_text) {
  82.                 break;
  83.             }
  84.  
  85.             $r = sms_set_campaign($clang, $node_id, $sms_title, $sms_name, $sms_cloud, $sms_subject, $sms_text);
  86.  
  87.             if (!$r) {
  88.                 $internal_error=true;
  89.                 break;
  90.             }
  91.  
  92.             $sms_modified=time();
  93.  
  94.             break;
  95.  
  96.         default:
  97.             break;
  98.     }
  99.  
  100.     $inlanguages=view('inlanguages', false, compact('clang'));
  101.  
  102.     $errors = compact('internal_error', 'missing_title', 'bad_title', 'missing_subject', 'missing_text');
  103.  
  104.     $output = view('smseditor', $lang, compact('clang', 'inlanguages', 'sms_modified', 'sms_title', 'sms_cloud', 'sms_subject', 'sms_text', 'errors'));
  105.  
  106.     return $output;
  107. }

Ajoutez les fonctions sms_get_campaign et sms_set_campaign dans le fichier models/sms.inc:

  1. function sms_get_campaign($lang, $node_id) {
  2.     $sqllang=db_sql_arg($lang, false);
  3.  
  4.     $tabnode=db_prefix_table('node');
  5.     $tabnodelocale=db_prefix_table('node_locale');
  6.     $tabnodecontent=db_prefix_table('node_content');
  7.     $tabcontentsms=db_prefix_table('content_sms');
  8.  
  9.     $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 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";
  10.  
  11.     $r = db_query($sql);
  12.  
  13.     return $r ? $r[0] : false;
  14. }
  1. function sms_set_campaign($lang, $node_id, $sms_title, $sms_name, $sms_cloud, $sms_subject, $sms_text) {
  2.     $tabnode=db_prefix_table('node');
  3.  
  4.     $sql="UPDATE $tabnode SET modified=NOW() WHERE node_id=$node_id";
  5.  
  6.     $r = db_update($sql);
  7.  
  8.     if ($r === false) {
  9.         return false;
  10.     }
  11.  
  12.     $sqllang=db_sql_arg($lang, false);
  13.     $sqlname=db_sql_arg($sms_name, true);
  14.     $sqltitle=db_sql_arg($sms_title, true, true);
  15.     $sqlcloud=db_sql_arg($sms_cloud, true, true);
  16.     $sqlabstract=db_sql_arg($sms_subject, true, true);
  17.  
  18.     $tabnodelocale=db_prefix_table('node_locale');
  19.  
  20.     $sql="INSERT INTO $tabnodelocale (node_id, locale, name, title, abstract, cloud) SELECT * FROM (SELECT $node_id AS node_id, $sqllang AS locale, $sqlname AS name, $sqltitle AS title, $sqlabstract AS abstract, $sqlcloud AS cloud) s WHERE NOT EXISTS (SELECT node_id FROM $tabnodelocale WHERE node_id=$node_id AND locale=$sqllang)";
  21.  
  22.     $r = db_insert($sql);
  23.  
  24.     if ($r === false) {
  25.         return false;
  26.     }
  27.  
  28.     if ($r === 0) {
  29.         $sql="UPDATE $tabnodelocale SET name=$sqlname, title=$sqltitle, abstract=$sqlabstract, cloud=$sqlcloud WHERE node_id=$node_id AND locale=$sqllang";
  30.  
  31.         $r = db_update($sql);
  32.  
  33.         if ($r === false) {
  34.             return false;
  35.         }
  36.     }
  37.  
  38.     $r = cloud_tag_node($lang, $node_id, $sms_cloud);
  39.  
  40.     if (!$r) {
  41.         return false;
  42.     }
  43.  
  44.     $tabnodecontent=db_prefix_table('node_content');
  45.  
  46.     $sql="SELECT nc.content_id FROM $tabnodecontent nc WHERE nc.node_id=$node_id AND nc.content_type='sms'";
  47.  
  48.     $r = db_query($sql);
  49.  
  50.     if (!$r) {
  51.         return false;
  52.     }
  53.  
  54.     $content_id=$r[0]['content_id'];
  55.  
  56.     $sqltext=db_sql_arg($sms_text, true, true);
  57.  
  58.     $tabcontentsms=db_prefix_table('content_sms');
  59.  
  60.     $sql="INSERT INTO $tabcontentsms (content_id, locale, text) SELECT * FROM (SELECT $content_id AS user_id, $sqllang AS locale, $sqltext AS text) s WHERE NOT EXISTS (SELECT $content_id FROM $tabcontentsms WHERE content_id=$content_id AND locale=$sqllang)";
  61.  
  62.     $r = db_insert($sql);
  63.  
  64.     if ($r) {
  65.         return true;
  66.     }
  67.  
  68.     $sql="UPDATE $tabcontentsms SET text=$sqltext WHERE content_id=$content_id AND locale=$sqllang";
  69.  
  70.     $r = db_update($sql);
  71.  
  72.     if ($r === false) {
  73.         return false;
  74.     }
  75.  
  76.     return true;
  77. }

Créez la vue smseditor en français et en anglais dans les fichiers views/fr/smseditor.phtml et views/en/smseditor.phtml :

  1. <?php if ($sms_modified): ?>
  2. <?php require_once 'datefr.php'; ?>
  3. <p class="info" title="Dernière modification"><?php echo longdate_fr($sms_modified); ?> à <?php echo date('H:i', $sms_modified); ?></p>
  4. <?php endif; ?>
  5. <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>
  6. <?php extract($errors); ?>
  7. <form method="post" class="compact">
  8. <input name="clang" type="hidden" value="<?php echo $clang; ?>" />
  9. <?php if ($sms_modified): ?>
  10. <input name="sms_modified" type="hidden" value="<?php echo $sms_modified; ?>" />
  11. <?php endif; ?>
  12. <p>
  13. <?php echo $inlanguages; ?>
  14. <span id="node_hidy" class="hidy">+</span>
  15. </p>
  16. <div id="node">
  17. <p class="inlabel<?php if ($missing_title or $bad_title): ?> inerror<?php endif; ?>">Titre&nbsp;:</p>
  18. <p><input id="sms_title" name="sms_title" type="text" size="40" maxlength="100" value="<?php echo htmlspecialchars($sms_title, ENT_COMPAT, 'UTF-8'); ?>" title="Titre de la campagne" onkeypress="return focusonenter(event, 'sms_cloud')"/></p>
  19. <p class="inlabel">Nuage&nbsp;:</p>
  20. <textarea id="sms_cloud" name="sms_cloud" cols="80" rows="2" title="Série de mots clés pour le moteur de recherche"><?php echo htmlspecialchars($sms_cloud, ENT_COMPAT, 'UTF-8'); ?></textarea>
  21. <p class="help helptoggle">
  22. Associez des mots clés à cette campagne.
  23. </p>
  24. <p class="inlabel<?php if ($missing_subject): ?> inerror<?php endif; ?>">Sujet&nbsp;:</p>
  25. <textarea id="sms_subject" name="sms_subject" cols="80" rows="2" title="Juste un paragraphe"><?php echo htmlspecialchars($sms_subject, ENT_COMPAT, 'UTF-8'); ?></textarea>
  26. <p class="help helptoggle">
  27. Décrivez le sujet de la campagne.
  28. </p>
  29. </div>
  30. <p class="inlabel<?php if ($missing_text): ?> inerror<?php endif; ?>">Message&nbsp;:</p>
  31. <textarea id="sms_text" name="sms_text" cols="80" rows="4" title="SMS" placeholder="Tapez le texte du SMS..."><?php echo htmlspecialchars($sms_text, ENT_COMPAT, 'UTF-8'); ?></textarea>
  32. <p class="help helptoggle">
  33. </p>
  34. <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>
  35. </form>
  36. <?php if (!$missing_subject): ?>
  37. <?php head('javascript', 'jquery.cookie'); ?>
  38. <script>
  39. if ($.cookie('hidenode') == 1) {
  40.     $('#node').hide();
  41. }
  42. $('#node_hidy').click(function() {
  43.     $('#node').toggle();
  44.     $.cookie('hidenode', $('#node').is(':hidden') ? 1 : 0, { path: '/' });
  45. });
  46. </script>
  47. <?php endif; ?>
  48. <?php
  49. $focus=false;
  50. if ($missing_title or $bad_title) {
  51.     $focus='#sms_title';
  52. }
  53. else if ($missing_text) {
  54.     $focus='#sms_text';
  55. }
  56. ?>
  57. <?php if ($focus): ?>
  58. <script>
  59. $(document).ready(function() {
  60.     $('<?php echo $focus; ?>').focus();
  61. });
  62. </script>
  63. <?php endif; ?>
  64. <?php head('javascript', 'jquery.cookie'); ?>
  65. <script>
  66. function togglehelp() {
  67.     $('.helptoggle').each(function() {
  68.         $(this).toggle();
  69.     });
  70.     $.cookie('nosmshelp', $.cookie('nosmshelp') == 1 ? '0' : '1');
  71. }
  72.  
  73. if ($.cookie('nosmshelp') == 1) {
  74.     $('.helptoggle').each(function() {
  75.         $(this).hide();
  76.     });
  77. }
  78.  
  79. $('.btn_help').each(function() {
  80.     $(this).click(function() {togglehelp();});
  81. });
  82. </script>
  1. <?php if ($sms_modified): ?>
  2. <?php require_once 'dateen.php'; ?>
  3. <p class="info" title="Last modification"><?php echo longdate_en($sms_modified); ?> at <?php echo date('H:i', $sms_modified); ?></p>
  4. <?php endif; ?>
  5. <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>
  6. <?php extract($errors); ?>
  7. <form method="post" class="compact">
  8. <input name="clang" type="hidden" value="<?php echo $clang; ?>" />
  9. <?php if ($sms_modified): ?>
  10. <input name="sms_modified" type="hidden" value="<?php echo $sms_modified; ?>" />
  11. <?php endif; ?>
  12. <p>
  13. <?php echo $inlanguages; ?>
  14. <span id="node_hidy" class="hidy">+</span>
  15. </p>
  16. <div id="node">
  17. <p class="inlabel<?php if ($missing_title or $bad_title): ?> inerror<?php endif; ?>">Title:</p>
  18. <p><input id="sms_title" name="sms_title" type="text" size="40" maxlength="100" value="<?php echo htmlspecialchars($sms_title, ENT_COMPAT, 'UTF-8'); ?>" title="Campaign title" onkeypress="return focusonenter(event, 'sms_cloud')"/></p>
  19. <p class="inlabel">Cloud:</p>
  20. <textarea id="sms_cloud" name="sms_cloud" cols="80" rows="2" title="Series of keywords for the search engine"><?php echo htmlspecialchars($sms_cloud, ENT_COMPAT, 'UTF-8'); ?></textarea>
  21. <p class="help helptoggle">
  22. Associate keywords to this campaign.
  23. </p>
  24. <p class="inlabel<?php if ($missing_subject): ?> inerror<?php endif; ?>">Subject:</p>
  25. <textarea id="sms_subject" name="sms_subject" cols="80" rows="2" title="Just a paragraph"><?php echo htmlspecialchars($sms_subject, ENT_COMPAT, 'UTF-8'); ?></textarea>
  26. <p class="help helptoggle">
  27. Describe the subject of the campaign.
  28. </p>
  29. </div>
  30. <p class="inlabel<?php if ($missing_text): ?> inerror<?php endif; ?>">Message:</p>
  31. <textarea id="sms_text" name="sms_text" cols="80" rows="4" title="SMS" placeholder="Type in the text of the SMS..."><?php echo htmlspecialchars($sms_text, ENT_COMPAT, 'UTF-8'); ?></textarea>
  32. <p class="help helptoggle">
  33. </p>
  34. <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>
  35. </form>
  36. <?php if (!$missing_title): ?>
  37. <?php head('javascript', 'jquery.cookie'); ?>
  38. <script>
  39. if ($.cookie('hidenode') == 1) {
  40.     $('#node').hide();
  41. }
  42. $('#node_hidy').click(function() {
  43.     $('#node').toggle();
  44.     $.cookie('hidenode', $('#node').is(':hidden') ? 1 : 0, { path: '/' });
  45. });
  46. </script>
  47. <?php endif; ?>
  48. <?php
  49. $focus=false;
  50. if ($missing_title or $bad_title) {
  51.     $focus='#sms_title';
  52. }
  53. else if ($missing_text) {
  54.     $focus='#sms_text';
  55. }
  56. ?>
  57. <?php if ($focus): ?>
  58. <script>
  59. $(document).ready(function() {
  60.     $('<?php echo $focus; ?>').focus();
  61. });
  62. </script>
  63. <?php endif; ?>
  64. <?php head('javascript', 'jquery.cookie'); ?>
  65. <script>
  66. function togglehelp() {
  67.     $('.helptoggle').each(function() {
  68.         $(this).toggle();
  69.     });
  70.     $.cookie('nommshelp', $.cookie('nommshelp') == 1 ? '0' : '1');
  71. }
  72.  
  73. if ($.cookie('nommshelp') == 1) {
  74.     $('.helptoggle').each(function() {
  75.         $(this).hide();
  76.     });
  77. }
  78.  
  79. $('.btn_help').each(function() {
  80.     $(this).click(function() {togglehelp();});
  81. });
  82. </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
  1. /izendsms.com
    1. actions
      1. campaigneditpage.php
    2. blocks
      1. smseditor.php
    3. css
      1. theme.css
    4. models
      1. sms.inc
    5. views
      1. en
        1. smseditor.phtml
      2. fr
        1. smseditor.phtml

Commettez cette version :

$ git status
$ git add actions/campaigneditpage.php blocks/smseditor.php css/theme.css models/sms.inc views/en/smseditor.phtml views/fr/smseditor.phtml
$ git commit -m'Adds a dedicated campaign editor'

IMPORTANT : Éditez le connecteur à la BD défini dans le fichier includes/db.inc.

Commentaires

Votre commentaire :
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip aide 2000

Entrez un maximum de 2000 caractères.
Améliorez la présentation de votre texte avec les balises de formatage suivantes :
[p]paragraphe[/p], [b]gras[/b], [i]italique[/i], [u]souligné[/u], [s]barré[/s], [quote]citation[/quote], [pre]tel quel[/pre], [br]à la ligne,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]commande[/code], [code=langage]code source en c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].