Specializing the editor
Code
Edit the file actions/campaigneditpage.php:
- global $with_toolbar;
- $node_editor = build('smseditor', $lang, $clang, $node_id);
Create the file smseditor.php in the folder blocks with the following content:
- 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;
- }
- 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;
- }
Add the functions sms_get_campaign
and sms_set_campaign
in the file models/sms.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 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 * 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)";
- $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;
- }
- }
- $r = cloud_tag_node($lang, $node_id, $sms_cloud);
- if (!$r) {
- return false;
- }
- $tabnodecontent=db_prefix_table('node_content');
- $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) {
- return false;
- }
- $content_id=$r[0]['content_id'];
- $sqltext=db_sql_arg($sms_text, true, true);
- $tabcontentsms=db_prefix_table('content_sms');
- $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)";
- $r = db_insert($sql);
- if ($r) {
- return true;
- }
- $sql="UPDATE $tabcontentsms SET text=$sqltext WHERE content_id=$content_id AND locale=$sqllang";
- $r = db_update($sql);
- if ($r === false) {
- return false;
- }
- return true;
- }
Create the view smseditor
in English and in French in the files views/en/smseditor.phtml and views/fr/smseditor.phtml:
- <?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 echo htmlspecialchars($sms_title, ENT_COMPAT, 'UTF-8'); ?>" 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 echo htmlspecialchars($sms_cloud, ENT_COMPAT, 'UTF-8'); ?></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 echo htmlspecialchars($sms_subject, ENT_COMPAT, 'UTF-8'); ?></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 echo htmlspecialchars($sms_text, ENT_COMPAT, 'UTF-8'); ?></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('nommshelp', $.cookie('nommshelp') == 1 ? '0' : '1');
- }
- if ($.cookie('nommshelp') == 1) {
- $('.helptoggle').each(function() {
- $(this).hide();
- });
- }
- $('.btn_help').each(function() {
- $(this).click(function() {togglehelp();});
- });
- </script>
- <?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 echo htmlspecialchars($sms_title, ENT_COMPAT, 'UTF-8'); ?>" 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 echo htmlspecialchars($sms_cloud, ENT_COMPAT, 'UTF-8'); ?></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 echo htmlspecialchars($sms_subject, ENT_COMPAT, 'UTF-8'); ?></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 echo htmlspecialchars($sms_text, ENT_COMPAT, 'UTF-8'); ?></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>
Add the CSS for the help messages at the end of the file css/theme.css:
Test
Connect as a client and go to the campaigns.
Edit the campaign The web engine
.
Modify the subject and the message of the campaign and press Configure.
If the title or the message is empty, an error is reported and the modification is rejected.
Message:
If the subject is empty, an error is reported but the modification is accepted.
Press on the flag to display the French version. Press on the flag to display the English version. IMPORTANT: The content of the editor is lost after switching to another language. Press Configure to validate your modifications.
Click on the triangle facing the language selector to show just the message. Click again on the triangle to display all the fields. NOTE: This option is preserved by the editor. If you don't see all the fields of a campaign, remember to click on the triangle to display them all.
Git
- /izendsms.com
- actions
- campaigneditpage.php
- blocks
- smseditor.php
- css
- theme.css
- models
- sms.inc
- views
- en
- smseditor.phtml
- fr
- smseditor.phtml
- en
- actions
Commit this 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: Edit the DB connector in the file includes/db.inc.
Comments