function generate_autocomplete($id, $options) { global $autocomplete_length_breaks; $js = ''; // Turn the array into a simple, numerically indexed, array $options = array_values($options); $n_options = count($options); if ($n_options > 0) { // Work out a suitable value for the autocomplete minLength // option, ie the number of characters that must be typed before // a list of options appears. We want to avoid presenting a huge // list of options. $min_length = 0; if (isset($autocomplete_length_breaks) && is_array($autocomplete_length_breaks)) { foreach ($autocomplete_length_breaks as $break) { if ($n_options < $break) { break; } $min_length++; } } // Start forming the array literal // Escape the options for ($i = 0; $i < $n_options; $i++) { $options[$i] = escape_js($options[$i]); } $options_string = "'" . implode("','", $options) . "'"; // Build the JavaScript. We don't support autocomplete in IE6 and below // because the browser doesn't render the autocomplete box properly - it // gets hidden behind other elements. Although there are fixes for this, // it's not worth it ... $js .= "if (!lteIE6)\n"; $js .= "{\n"; $js .= " \$('#{$id}').autocomplete({\n"; $js .= " source: [{$options_string}],\n"; $js .= " minLength: {$min_length}\n"; $js .= " })"; // If the minLength is 0, then the autocomplete widget doesn't do // quite what you might expect and you need to force it to display // the available options when it receives focus if ($min_length == 0) { $js .= ".focus(function() {\n"; $js .= " \$(this).autocomplete('search', '');\n"; $js .= " })"; } $js .= " ;\n"; $js .= "}\n"; } return $js; }
function create_field_entry_areas($disabled = FALSE) { global $areas, $area_id, $rooms; echo "<div id=\"div_areas\">\n"; echo "</div>\n"; // if there is more than one area then give the option // to choose areas. if (count($areas) > 1) { ?> <script type="text/javascript"> //<![CDATA[ var area = <?php echo $area_id; ?> ; function changeRooms( formObj ) { areasObj = eval( "formObj.area" ); area = areasObj[areasObj.selectedIndex].value; roomsObj = eval( "formObj.elements['rooms']" ); // remove all entries roomsNum = roomsObj.length; for (i=(roomsNum-1); i >= 0; i--) { roomsObj.options[i] = null; } // add entries based on area selected switch (area){ <?php foreach ($areas as $a) { print "case \"" . $a['id'] . "\":\n"; // get rooms for this area $i = 0; foreach ($rooms as $r) { if ($r['area_id'] == $a['id']) { print "roomsObj.options[{$i}] = new Option(\"" . escape_js($r['room_name']) . "\"," . $r['id'] . ");\n"; $i++; } } // select the first entry by default to ensure // that one room is selected to begin with if ($i > 0) { print "roomsObj.options[0].selected = true;\n"; } print "break;\n"; } ?> } //switch <?php // Replace the start and end selectors with those for the new area // (1) We set the display for the old elements to "none" and the new // elements to "block". (2) We also need to disable the old selectors and // enable the new ones: they all have the same name, so we only want // one passed through with the form. (3) We take a note of the currently // selected start and end values so that we can have a go at finding a // similar time/period in the new area. (4) We also take a note of the old // area id because we'll need that when trying to match up slots: it only // makes sense to match up slots if both old and new area used the same // mode (periods/times). // For the "all day" checkbox, the process is slightly different. This // is because the checkboxes themselves are visible or not depending on // the time restrictions for that particular area. (1) We set the display // for the old *container* element to "none" and the new elements to // "block". (2) We disable the old checkboxes and enable the new ones for // the same reasons as above. (3) We copy the value of the old check box // to the new check box ?> var oldStartId = "start_seconds" + currentArea; var oldEndId = "end_seconds" + currentArea; var newStartId = "start_seconds" + area; var newEndId = "end_seconds" + area; var oldAllDayId = "ad" + currentArea; var newAllDayId = "ad" + area; var oldAreaStartValue = formObj[oldStartId].options[formObj[oldStartId].selectedIndex].value; var oldAreaEndValue = formObj[oldEndId].options[formObj[oldEndId].selectedIndex].value; $("#" + oldStartId).hide() .attr('disabled', 'disabled'); $("#" + oldEndId).hide() .attr('disabled', 'disabled'); $("#" + newStartId).show() .removeAttr('disabled'); $("#" + newEndId).show() .removeAttr('disabled'); + $("#" + oldAllDayId).hide(); $("#" + newAllDayId).show(); if($("#all_day" + currentArea).attr('checked') == 'checked') { $("#all_day" + area).attr('checked', 'checked').removeAttr('disabled'); } else { $("#all_day" + area).removeAttr('checked').removeAttr('disabled'); } $("#all_day" + currentArea).removeAttr('disabled'); var oldArea = currentArea; currentArea = area; prevStartValue = undefined; adjustSlotSelectors(formObj, oldArea, oldAreaStartValue, oldAreaEndValue); } // Create area selector, only if we have Javascript var div_areas = document.getElementById('div_areas'); // First of all create a label and insert it into the <div> var area_label = document.createElement('label'); var area_label_text = document.createTextNode('<?php echo get_vocab("area"); ?> :'); area_label.appendChild(area_label_text); area_label.setAttribute('for', 'area'); div_areas.appendChild(area_label); // Now give it a select box var area_select = document.createElement('select'); area_select.setAttribute('id', 'area'); area_select.setAttribute('name', 'area'); area_select.onchange = function(){changeRooms(this.form)}; // setAttribute doesn't work for onChange with IE6 // populated with options var option; var option_text <?php // go through the areas and create the options foreach ($areas as $a) { ?> option = document.createElement('option'); option.value = <?php echo $a['id']; ?> ; option_text = document.createTextNode('<?php echo escape_js($a['area_name']); ?> '); <?php if ($a['id'] == $area_id) { ?> option.selected = true; <?php } ?> option.appendChild(option_text); area_select.appendChild(option); <?php } ?> // insert the <select> which we've just assembled into the <div> div_areas.appendChild(area_select); <?php if ($disabled) { // If the field is disabled we need to disable the select box and // add in a hidden input containing the value ?> $('#area').attr('disabled', 'disabled'); $('<input>').attr('type', 'hidden') .attr('name', 'area') .val('<?php echo $area_id; ?> ') .appendTo('#div_areas'); <?php } ?> //]]> </script> <?php } // if count($areas) }
defaultOptions.bProcessing = true; defaultOptions.bScrollCollapse = true; defaultOptions.bStateSave = true; defaultOptions.iDisplayLength = 25; defaultOptions.sDom = 'C<"clear">lfrtip'; defaultOptions.sScrollX = "100%"; defaultOptions.sPaginationType = "full_numbers"; defaultOptions.oColReorder = {}; defaultOptions.oColVis = {sSize: "auto", buttonText: '<?php echo escape_js(get_vocab("show_hide_columns")); ?> ', bRestore: true, sRestore: '<?php echo escape_js(get_vocab("restore_original")); ?> '}; defaultOptions.fnInitComplete = function(){ if (((leftCol !== undefined) && (leftCol !== null)) || ((rightCol !== undefined) && (rightCol !== null)) ) { <?php // Fix the left and/or right columns. This has to be done when // initialisation is complete as the language files are loaded // asynchronously ?> var options = {}; if ((leftCol !== undefined) && (leftCol !== null))
{ alertMessage += '<?php echo escape_js(mrbs_entity_decode(get_vocab("conflict"))); ?> ' + ": \n\n"; var conflictsList = getErrorList(result.conflicts); alertMessage += conflictsList.text; } if (result.rules_broken.length > 0) { if (result.conflicts.length > 0) { alertMessage += "\n\n"; } alertMessage += '<?php echo escape_js(mrbs_entity_decode(get_vocab("rules_broken"))); ?> ' + ": \n\n"; var rulesList = getErrorList(result.rules_broken); alertMessage += rulesList.text; } window.alert(alertMessage); } turnOnPageRefresh(); }, 'json'); } <?php // if (rectanglesIdentical(r1, r2)) ?> }; <?php
/** * AJAX response handler for the 'my_name_is' step */ static function my_name_is() { // Grab the new name from POST data $in = ps('my_name'); // ...further processing might go here: Database updates, input validation, ... self::$my_name = $in; // Prepare response string $in = escape_js($in); // Send a javascript response to render this posted data back into the document's headline. // Find the target HTML fragment via jQuery through its selector '#my_name_output' // and replace its text. send_script_response(<<<EOS \t\t\$('#my_name_output').text('{$in}'); EOS ); }
$search = urldecode(trim($_GET['what'])); if (!strlen($search)) { print "false;"; die; } $eligible = $actions = array(); $list = $DB->GetAll(' SELECT id, name FROM netdeviceproducers WHERE name ?LIKE? ' . $DB->Escape("%{$search}%") . ' OR alternative_name ?LIKE? ' . $DB->Escape("%{$search}%") . ' ORDER BY name LIMIT 10'); if (!empty($list)) { foreach ($list as $idx => $row) { $eligible[$idx] = escape_js($row['name']); $actions[$idx] = sprintf("javascript: search_producer(%d)", $row['id']); } print "this.eligible = [\"" . implode('","', $eligible) . "\"];\n"; print "this.actions = [\"" . implode('","', $actions) . "\"];\n"; } else { print "false;\n"; } die; } $LMS->InitXajax(); $LMS->RegisterXajaxFunction('select_producer'); $SMARTY->assign('xajax', $LMS->RunXajax()); $layout['pagetitle'] = trans('Select model'); $netdevmodelid = isset($_GET['netdevmodelid']) ? intval($_GET['netdevmodelid']) : null; $producer = isset($_GET['producer']) ? $_GET['producer'] : null;
function section_save() { global $txpcfg, $app_mode; extract(doSlash(psa(array('page', 'css', 'old_name')))); extract(psa(array('name', 'title'))); $prequel = ''; $sequel = ''; if (empty($title)) { $title = $name; } // Prevent non url chars on section names include_once txpath . '/lib/classTextile.php'; $textile = new Textile(); $title = doSlash($textile->TextileThis($title, 1)); $name = doSlash(sanitizeForUrl($name)); if ($old_name && strtolower($name) != strtolower($old_name)) { if (safe_field('name', 'txp_section', "name='{$name}'")) { $message = array(gTxt('section_name_already_exists', array('{name}' => $name)), E_ERROR); if ($app_mode == 'async') { // TODO: Better/themeable popup send_script_response('window.alert("' . escape_js(strip_tags(gTxt('section_name_already_exists', array('{name}' => $name)))) . '")'); } else { sec_section_list($message); return; } } } if ($name == 'default') { safe_update('txp_section', "page = '{$page}', css = '{$css}'", "name = 'default'"); update_lastmod(); } else { extract(array_map('assert_int', psa(array('is_default', 'on_frontpage', 'in_rss', 'searchable')))); // note this means 'selected by default' not 'default page' if ($is_default) { safe_update("txp_section", "is_default = 0", "name != '{$old_name}'"); // switch off $is_default for all sections in async app_mode if ($app_mode == 'async') { $prequel = '$("input[name=\\"is_default\\"][value=\\"1\\"]").attr("checked", false);' . '$("input[name=\\"is_default\\"][value=\\"0\\"]").attr("checked", true);'; } } safe_update('txp_section', "\n\t\t\t\tname = '{$name}',\n\t\t\t\ttitle = '{$title}',\n\t\t\t\tpage = '{$page}',\n\t\t\t\tcss = '{$css}',\n\t\t\t\tis_default = {$is_default},\n\t\t\t\ton_frontpage = {$on_frontpage},\n\t\t\t\tin_rss = {$in_rss},\n\t\t\t\tsearchable = {$searchable}\n\t\t\t", "name = '{$old_name}'"); safe_update('textpattern', "Section = '{$name}'", "Section = '{$old_name}'"); update_lastmod(); } $message = gTxt('section_updated', array('{name}' => $name)); if ($app_mode == 'async') { // Caveat: Use unslashed params for DTO $s = psa(array('name', 'title', 'page', 'css')) + compact('is_default', 'on_frontpage', 'in_rss', 'searchable'); $s = section_detail_partial($s); send_script_response($prequel . '$("#section-form-' . $name . '").replaceWith("' . escape_js($s) . '");' . $sequel); } else { sec_section_list($message); } }
/** * Renders article editor form. * * @param string|array $message The activity message * @param bool $concurrent Treat as a concurrent save * @param bool $refresh_partials Whether refresh partial contents */ function article_edit($message = '', $concurrent = false, $refresh_partials = false) { global $vars, $txp_user, $prefs, $event, $view; extract($prefs); /* $partials is an array of: $key => array ( 'mode' => {PARTIAL_STATIC | PARTIAL_VOLATILE | PARTIAL_VOLATILE_VALUE}, 'selector' => $DOM_selector, 'cb' => $callback_function, 'html' => $return_value_of_callback_function (need not be intialised here) ) */ $partials = array('html_title' => array('mode' => PARTIAL_VOLATILE, 'selector' => 'title', 'cb' => 'article_partial_html_title'), 'sLastMod' => array('mode' => PARTIAL_VOLATILE_VALUE, 'selector' => '[name=sLastMod]', 'cb' => 'article_partial_value'), 'sPosted' => array('mode' => PARTIAL_VOLATILE_VALUE, 'selector' => '[name=sPosted]', 'cb' => 'article_partial_value'), 'sidehelp' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#textfilter_group', 'cb' => 'article_partial_sidehelp'), 'url_title' => array('mode' => PARTIAL_STATIC, 'selector' => 'p.url-title', 'cb' => 'article_partial_url_title'), 'url_title_value' => array('mode' => PARTIAL_VOLATILE_VALUE, 'selector' => '#url-title', 'cb' => 'article_partial_url_title_value'), 'description' => array('mode' => PARTIAL_STATIC, 'selector' => 'p.description', 'cb' => 'article_partial_description'), 'description_value' => array('mode' => PARTIAL_VOLATILE_VALUE, 'selector' => '#description', 'cb' => 'article_partial_description_value'), 'keywords' => array('mode' => PARTIAL_STATIC, 'selector' => 'p.keywords', 'cb' => 'article_partial_keywords'), 'keywords_value' => array('mode' => PARTIAL_VOLATILE_VALUE, 'selector' => '#keywords', 'cb' => 'article_partial_keywords_value'), 'image' => array('mode' => PARTIAL_STATIC, 'selector' => '#image_group', 'cb' => 'article_partial_image'), 'custom_fields' => array('mode' => PARTIAL_STATIC, 'selector' => '#custom_field_group', 'cb' => 'article_partial_custom_fields'), 'recent_articles' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#recent_group .recent', 'cb' => 'article_partial_recent_articles'), 'title' => array('mode' => PARTIAL_STATIC, 'selector' => 'p.title', 'cb' => 'article_partial_title'), 'title_value' => array('mode' => PARTIAL_VOLATILE_VALUE, 'selector' => '#title', 'cb' => 'article_partial_title_value'), 'article_clone' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#article_partial_article_clone', 'cb' => 'article_partial_article_clone'), 'article_view' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#article_partial_article_view', 'cb' => 'article_partial_article_view'), 'body' => array('mode' => PARTIAL_STATIC, 'selector' => 'p.body', 'cb' => 'article_partial_body'), 'excerpt' => array('mode' => PARTIAL_STATIC, 'selector' => 'p.excerpt', 'cb' => 'article_partial_excerpt'), 'author' => array('mode' => PARTIAL_VOLATILE, 'selector' => 'p.author', 'cb' => 'article_partial_author'), 'view_modes' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#view_modes', 'cb' => 'article_partial_view_modes'), 'article_nav' => array('mode' => PARTIAL_VOLATILE, 'selector' => 'p.nav-tertiary', 'cb' => 'article_partial_article_nav'), 'status' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#write-status', 'cb' => 'article_partial_status'), 'categories' => array('mode' => PARTIAL_STATIC, 'selector' => '#categories_group', 'cb' => 'article_partial_categories'), 'section' => array('mode' => PARTIAL_STATIC, 'selector' => 'p.section', 'cb' => 'article_partial_section'), 'comments' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#write-comments', 'cb' => 'article_partial_comments'), 'posted' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#write-timestamp', 'cb' => 'article_partial_posted'), 'expires' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#write-expires', 'cb' => 'article_partial_expires')); // Add partials for custom fields (and their values which is redundant by // design, for plugins). global $cfs; foreach ($cfs as $k => $v) { $partials["custom_field_{$k}"] = array('mode' => PARTIAL_STATIC, 'selector' => "p.custom-field.custom-{$k}", 'cb' => 'article_partial_custom_field'); $partials["custom_{$k}"] = array('mode' => PARTIAL_STATIC, 'selector' => "#custom-{$k}", 'cb' => 'article_partial_value'); } extract(gpsa(array('view', 'from_view', 'step'))); // Newly-saved article. if (!empty($GLOBALS['ID'])) { $ID = $GLOBALS['ID']; $step = 'edit'; } else { $ID = gps('ID'); } // Switch to 'text' view upon page load and after article post. if (!$view || gps('save') || gps('publish')) { $view = 'text'; } if (!$step) { $step = "create"; } if ($step == "edit" && $view == "text" && !empty($ID) && $from_view != 'preview' && $from_view != 'html' && !$concurrent) { $pull = true; // It's an existing article - off we go to the database. $ID = assert_int($ID); $rs = safe_row("*, UNIX_TIMESTAMP(Posted) AS sPosted,\n UNIX_TIMESTAMP(Expires) AS sExpires,\n UNIX_TIMESTAMP(LastMod) AS sLastMod", 'textpattern', "ID = {$ID}"); if (empty($rs)) { return; } $rs['reset_time'] = $rs['publish_now'] = false; } else { $pull = false; // Assume they came from post. if ($from_view == 'preview' or $from_view == 'html') { $store_out = array(); $store = unserialize(base64_decode(ps('store'))); foreach ($vars as $var) { if (isset($store[$var])) { $store_out[$var] = $store[$var]; } } } else { $store_out = gpsa($vars); if ($concurrent) { $store_out['sLastMod'] = safe_field("UNIX_TIMESTAMP(LastMod) AS sLastMod", 'textpattern', "ID = {$ID}"); } if (!has_privs('article.set_markup') && !empty($ID)) { $oldArticle = safe_row("textile_body, textile_excerpt", 'textpattern', "ID = {$ID}"); if (!empty($oldArticle)) { $store_out['textile_body'] = $oldArticle['textile_body']; $store_out['textile_excerpt'] = $oldArticle['textile_excerpt']; } } } // Use preferred Textfilter as default and fallback. $hasfilter = new \Textpattern\Textfilter\Constraint(null); $validator = new Validator(); foreach (array('textile_body', 'textile_excerpt') as $k) { $hasfilter->setValue($store_out[$k]); $validator->setConstraints($hasfilter); if (!$validator->validate()) { $store_out[$k] = $use_textile; } } $rs = textile_main_fields($store_out); if (!empty($rs['exp_year'])) { if (empty($rs['exp_month'])) { $rs['exp_month'] = 1; } if (empty($rs['exp_day'])) { $rs['exp_day'] = 1; } if (empty($rs['exp_hour'])) { $rs['exp_hour'] = 0; } if (empty($rs['exp_minute'])) { $rs['exp_minute'] = 0; } if (empty($rs['exp_second'])) { $rs['exp_second'] = 0; } $rs['sExpires'] = safe_strtotime($rs['exp_year'] . '-' . $rs['exp_month'] . '-' . $rs['exp_day'] . ' ' . $rs['exp_hour'] . ':' . $rs['exp_minute'] . ':' . $rs['exp_second']); } if (!empty($rs['year'])) { $rs['sPosted'] = safe_strtotime($rs['year'] . '-' . $rs['month'] . '-' . $rs['day'] . ' ' . $rs['hour'] . ':' . $rs['minute'] . ':' . $rs['second']); } } $validator = new Validator(new SectionConstraint($rs['Section'])); if (!$validator->validate()) { $rs['Section'] = getDefaultSection(); } extract($rs); $GLOBALS['step'] = $step; if ($step != 'create' && isset($sPosted)) { // Previous record? $rs['prev_id'] = checkIfNeighbour('prev', $sPosted); // Next record? $rs['next_id'] = checkIfNeighbour('next', $sPosted); } else { $rs['prev_id'] = $rs['next_id'] = 0; } // Let plugins chime in on partials meta data. callback_event_ref('article_ui', 'partials_meta', 0, $rs, $partials); $rs['partials_meta'] =& $partials; // Get content for volatile partials. foreach ($partials as $k => $p) { if ($p['mode'] == PARTIAL_VOLATILE || $p['mode'] == PARTIAL_VOLATILE_VALUE) { $cb = $p['cb']; $partials[$k]['html'] = is_array($cb) ? call_user_func($cb, $rs, $k) : $cb($rs, $k); } } if ($refresh_partials) { $response[] = announce($message); $response[] = '$("#article_form [type=submit]").val(textpattern.gTxt("save"))'; if ($Status < STATUS_LIVE) { $response[] = '$("#article_form").addClass("saved").removeClass("published")'; } else { $response[] = '$("#article_form").addClass("published").removeClass("saved")'; } // Update the volatile partials. foreach ($partials as $k => $p) { // Volatile partials need a target DOM selector. if (empty($p['selector']) && $p['mode'] != PARTIAL_STATIC) { trigger_error("Empty selector for partial '{$k}'", E_USER_ERROR); } else { // Build response script. if ($p['mode'] == PARTIAL_VOLATILE) { // Volatile partials replace *all* of the existing HTML // fragment for their selector. $response[] = '$("' . $p['selector'] . '").replaceWith("' . escape_js($p['html']) . '")'; } elseif ($p['mode'] == PARTIAL_VOLATILE_VALUE) { // Volatile partial values replace the *value* of elements // matching their selector. $response[] = '$("' . $p['selector'] . '").val("' . escape_js($p['html']) . '")'; } } } send_script_response(join(";\n", $response)); // Bail out. return; } foreach ($partials as $k => $p) { if ($p['mode'] == PARTIAL_STATIC) { $cb = $p['cb']; $partials[$k]['html'] = is_array($cb) ? call_user_func($cb, $rs, $k) : $cb($rs, $k); } } $page_title = $ID ? $Title : gTxt('write'); pagetop($page_title, $message); $class = array(); if ($Status >= STATUS_LIVE) { $class[] = 'published'; } elseif ($ID) { $class[] = 'saved'; } if ($step !== 'create') { $class[] = 'async'; } echo n . tag_start('form', array('class' => $class, 'id' => 'article_form', 'name' => 'article_form', 'method' => 'post', 'action' => 'index.php')); if (!empty($store_out)) { echo hInput('store', base64_encode(serialize($store_out))); } echo hInput('ID', $ID) . eInput('article') . sInput($step) . hInput('sPosted', $sPosted) . hInput('sLastMod', $sLastMod) . hInput('AuthorID', $AuthorID) . hInput('LastModID', $LastModID) . n . '<input type="hidden" name="view" />'; echo n . '<div class="txp-layout-4col-cell-1-2-3">' . hed(gTxt('tab_write'), 1, array('class' => 'txp-heading')); echo n . '<div role="region" id="main_content">'; // View mode tabs. echo $partials['view_modes']['html']; // Title input. if ($view == 'preview') { echo n . '<div class="preview">' . graf(gTxt('title'), array('class' => 'alert-block information')) . hed($Title, 1, ' class="title"'); } elseif ($view == 'html') { echo n . '<div class="html">' . graf(gTxt('title'), array('class' => 'alert-block information')) . hed($Title, 1, ' class="title"'); } elseif ($view == 'text') { echo n . '<div class="text">' . $partials['title']['html']; } // Body. if ($view == 'preview') { echo n . '<div class="body">' . n . graf(gTxt('body'), array('class' => 'alert-block information')) . $Body_html . '</div>'; } elseif ($view == 'html') { echo graf(gTxt('body'), array('class' => 'alert-block information')) . n . tag(str_replace(array(n, t), array(br, sp . sp . sp . sp), txpspecialchars($Body_html)), 'pre', ' class="body"'); } else { echo $partials['body']['html']; } // Excerpt. if ($articles_use_excerpts) { if ($view == 'preview') { echo n . '<div class="excerpt">' . graf(gTxt('excerpt'), array('class' => 'alert-block information')) . $Excerpt_html . '</div>'; } elseif ($view == 'html') { echo graf(gTxt('excerpt'), array('class' => 'alert-block information')) . n . tag(str_replace(array(n, t), array(br, sp . sp . sp . sp), txpspecialchars($Excerpt_html)), 'pre', array('class' => 'excerpt')); } else { echo $partials['excerpt']['html']; } } echo hInput('from_view', $view), n . '</div>'; // Author. if ($view == "text" && $step != "create") { echo $partials['author']['html']; } echo n . '</div>' . n . '</div>'; // End of .txp-layout-4col-cell-1-2-3. // Sidebar column (only shown if in text editing view). if ($view == 'text') { echo n . '<div class="txp-layout-4col-cell-4alt">'; // 'Publish/Save' button. if ($step == 'create' and empty($GLOBALS['ID'])) { if (has_privs('article.publish')) { $push_button = fInput('submit', 'publish', gTxt('publish'), 'publish'); } else { $push_button = fInput('submit', 'publish', gTxt('save'), 'publish'); } echo graf($push_button, array('class' => 'txp-save')); } elseif ($Status >= STATUS_LIVE && has_privs('article.edit.published') || $Status >= STATUS_LIVE && $AuthorID === $txp_user && has_privs('article.edit.own.published') || $Status < STATUS_LIVE && has_privs('article.edit') || $Status < STATUS_LIVE && $AuthorID === $txp_user && has_privs('article.edit.own')) { echo graf(fInput('submit', 'save', gTxt('save'), 'publish'), array('class' => 'txp-save')); } // View/Duplicate/Create new article links. $an_cb = href('<span class="ui-icon ui-extra-icon-new-document"></span> ' . gTxt('create_new'), 'index.php?event=article', array('class' => 'txp-new')); $ac_cb = $rs['partials_meta']['article_clone']['cb']; $av_cb = $rs['partials_meta']['article_view']['cb']; echo $step != 'create' ? graf($an_cb . $ac_cb($rs) . $av_cb($rs), array('class' => 'txp-actions')) : ''; // Prev/next article links. if ($step != 'create' and ($rs['prev_id'] or $rs['next_id'])) { echo $partials['article_nav']['html']; } echo n . '<div role="region" id="supporting_content">'; // 'Sort and display' section. echo pluggable_ui('article_ui', 'sort_display', wrapRegion('txp-write-sort-group', $partials['status']['html'] . $partials['section']['html'] . $partials['categories']['html'], '', gTxt('sort_display')), $rs); // 'Date and time' collapsible section. if ($step == "create" and empty($GLOBALS['ID'])) { // Timestamp. // Avoiding modified date to disappear. if (!empty($store_out['year'])) { $persist_timestamp = safe_strtotime($store_out['year'] . '-' . $store_out['month'] . '-' . $store_out['day'] . ' ' . $store_out['hour'] . ':' . $store_out['minute'] . ':' . $store_out['second']); } else { $persist_timestamp = time(); } $posted_block = pluggable_ui('article_ui', 'timestamp', inputLabel('year', tsi('year', '%Y', $persist_timestamp, '', 'year') . ' <span role="separator">/</span> ' . tsi('month', '%m', $persist_timestamp, '', 'month') . ' <span role="separator">/</span> ' . tsi('day', '%d', $persist_timestamp, '', 'day'), 'publish_date', array('timestamp', 'instructions_publish_date'), array('class' => 'txp-form-field date posted')) . inputLabel('hour', tsi('hour', '%H', $persist_timestamp, '', 'hour') . ' <span role="separator">:</span> ' . tsi('minute', '%M', $persist_timestamp, '', 'minute') . ' <span role="separator">:</span> ' . tsi('second', '%S', $persist_timestamp, '', 'second'), 'publish_time', array('', 'instructions_publish_time'), array('class' => 'txp-form-field time posted')) . n . tag(checkbox('publish_now', '1', $publish_now, '', 'publish_now') . n . tag(gTxt('set_to_now'), 'label', array('for' => 'publish_now')), 'div', array('class' => 'posted-now')), array('sPosted' => $persist_timestamp) + $rs); // Expires. if (!empty($store_out['exp_year'])) { $persist_timestamp = safe_strtotime($store_out['exp_year'] . '-' . $store_out['exp_month'] . '-' . $store_out['exp_day'] . ' ' . $store_out['exp_hour'] . ':' . $store_out['exp_minute'] . ':' . $store_out['second']); } else { $persist_timestamp = 0; } $expires_block = pluggable_ui('article_ui', 'expires', inputLabel('exp_year', tsi('exp_year', '%Y', $persist_timestamp, '', 'exp_year') . ' <span role="separator">/</span> ' . tsi('exp_month', '%m', $persist_timestamp, '', 'exp_month') . ' <span role="separator">/</span> ' . tsi('exp_day', '%d', $persist_timestamp, '', 'exp_day'), 'expire_date', array('expires', 'instructions_expire_date'), array('class' => 'txp-form-field date expires')) . inputLabel('exp_hour', tsi('exp_hour', '%H', $persist_timestamp, '', 'exp_hour') . ' <span role="separator">:</span> ' . tsi('exp_minute', '%M', $persist_timestamp, '', 'exp_minute') . ' <span role="separator">:</span> ' . tsi('exp_second', '%S', $persist_timestamp, '', 'exp_second'), 'expire_time', array('', 'instructions_expire_time'), array('class' => 'txp-form-field time expires')), $rs); } else { // Timestamp. $posted_block = $partials['posted']['html']; // Expires. $expires_block = $partials['expires']['html']; } echo wrapRegion('txp-dates-group', $posted_block . $expires_block, 'txp-dates-group-content', 'date_settings', 'article_dates'); // 'Meta' collapsible section. // 'URL-only title' field. $html_url_title = $partials['url_title']['html']; // 'Description' field. $html_description = $partials['description']['html']; // 'Keywords' field. $html_keywords = $partials['keywords']['html']; echo wrapRegion('txp-meta-group', $html_url_title . $html_description . $html_keywords, 'txp-meta-group-content', 'meta', 'article_meta'); // 'Comment options' collapsible section. echo wrapRegion('txp-comments-group', $partials['comments']['html'], 'txp-comments-group-content', 'comment_settings', 'article_comments', $use_comments == 1 ? '' : 'empty'); // 'Article image' collapsible section. echo $partials['image']['html']; // 'Custom fields' collapsible section. echo $partials['custom_fields']['html']; // 'Advanced options' collapsible section. // 'Article markup'/'Excerpt markup' selection. if (has_privs('article.set_markup')) { $html_markup = inputLabel('markup-body', pref_text('textile_body', $textile_body, 'markup-body'), 'article_markup', array('', 'instructions_textile_body'), array('class' => 'txp-form-field markup markup-body')) . inputLabel('markup-excerpt', pref_text('textile_excerpt', $textile_excerpt, 'markup-excerpt'), 'excerpt_markup', array('', 'instructions_textile_excerpt'), array('class' => 'txp-form-field markup markup-excerpt')); } else { $html_markup = ''; } $html_markup = pluggable_ui('article_ui', 'markup', $html_markup, $rs); // 'Override form' selection. $form_pop = $allow_form_override ? form_pop($override_form, 'override-form') : ''; $html_override = $form_pop ? pluggable_ui('article_ui', 'override', inputLabel('override-form', $form_pop, 'override_default_form', array('override_form', 'instructions_override_form'), array('class' => 'txp-form-field override-form')), $rs) : ''; echo wrapRegion('txp-advanced-group', $html_markup . $html_override, 'txp-advanced-group-content', 'advanced_options', 'article_advanced'); // Custom menu entries. echo pluggable_ui('article_ui', 'extend_col_1', '', $rs); // 'Text formatting help' collapsible section. echo $partials['sidehelp']['html']; // 'Recent articles' collapsible section. echo wrapRegion('txp-recent-group', $partials['recent_articles']['html'], 'txp-recent-group-content', 'recent_articles', 'article_recent'); echo n . '</div>'; // End of #supporting_content. echo n . '</div>'; // End of .txp-layout-4col-cell-4alt. } echo tInput() . n . '</form>'; }
function article_edit($message = '', $concurrent = FALSE, $refresh_partials = FALSE) { global $vars, $txp_user, $prefs, $event; extract($prefs); /* $partials is an array of: $key => array ( 'mode' => {PARTIAL_STATIC | PARTIAL_VOLATILE | PARTIAL_VOLATILE_VALUE}, 'selector' => $DOM_selector, 'cb' => $callback_function, 'html' => $return_value_of_callback_function (need not be intialized here) ) */ $partials = array('sLastMod' => array('mode' => PARTIAL_VOLATILE_VALUE, 'selector' => '[name=sLastMod]', 'cb' => 'article_partial_value'), 'sPosted' => array('mode' => PARTIAL_VOLATILE_VALUE, 'selector' => '[name=sPosted]', 'cb' => 'article_partial_value'), 'custom_fields' => array('mode' => PARTIAL_STATIC, 'selector' => '#custom_field_group', 'cb' => 'article_partial_custom_fields'), 'image' => array('mode' => PARTIAL_STATIC, 'selector' => '#image_group', 'cb' => 'article_partial_image'), 'keywords' => array('mode' => PARTIAL_STATIC, 'selector' => 'p.keywords', 'cb' => 'article_partial_keywords'), 'keywords_value' => array('mode' => PARTIAL_VOLATILE_VALUE, 'selector' => '#keywords', 'cb' => 'article_partial_keywords_value'), 'url_title' => array('mode' => PARTIAL_STATIC, 'selector' => 'p.url-title', 'cb' => 'article_partial_url_title'), 'url_title_value' => array('mode' => PARTIAL_VOLATILE_VALUE, 'selector' => '#url-title', 'cb' => 'article_partial_url_title_value'), 'recent_articles' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#recent_group .recent', 'cb' => 'article_partial_recent_articles'), 'title' => array('mode' => PARTIAL_STATIC, 'selector' => 'p.title', 'cb' => 'article_partial_title'), 'title_value' => array('mode' => PARTIAL_VOLATILE_VALUE, 'selector' => '#title', 'cb' => 'article_partial_title_value'), 'article_view' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#article_partial_article_view', 'cb' => 'article_partial_article_view'), 'body' => array('mode' => PARTIAL_STATIC, 'selector' => 'p.body', 'cb' => 'article_partial_body'), 'excerpt' => array('mode' => PARTIAL_STATIC, 'selector' => 'p.excerpt', 'cb' => 'article_partial_excerpt'), 'author' => array('mode' => PARTIAL_VOLATILE, 'selector' => 'p.author', 'cb' => 'article_partial_author'), 'article_nav' => array('mode' => PARTIAL_VOLATILE, 'selector' => 'p.nav-tertiary', 'cb' => 'article_partial_article_nav'), 'status' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#write-status', 'cb' => 'article_partial_status'), 'categories' => array('mode' => PARTIAL_STATIC, 'selector' => '#categories_group', 'cb' => 'article_partial_categories'), 'section' => array('mode' => PARTIAL_STATIC, 'selector' => 'p.section', 'cb' => 'article_partial_section'), 'comments' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#write-comments', 'cb' => 'article_partial_comments'), 'posted' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#write-timestamp', 'cb' => 'article_partial_posted'), 'expires' => array('mode' => PARTIAL_VOLATILE, 'selector' => '#write-expires', 'cb' => 'article_partial_expires')); // add partials for custom fields (and their values which is redundant by design, for plugins) global $cfs; foreach ($cfs as $k => $v) { $partials["custom_field_{$k}"] = array('mode' => PARTIAL_STATIC, 'selector' => "p.custom-field.custom-{$k}", 'cb' => 'article_partial_custom_field'); $partials["custom_{$k}"] = array('mode' => PARTIAL_STATIC, 'selector' => "#custom-{$k}", 'cb' => 'article_partial_value'); } extract(gpsa(array('view', 'from_view', 'step'))); if (!empty($GLOBALS['ID'])) { // newly-saved article $ID = $GLOBALS['ID']; $step = 'edit'; } else { $ID = gps('ID'); } // switch to 'text' view upon page load and after article post if (!$view || gps('save') || gps('publish')) { $view = 'text'; } if (!$step) { $step = "create"; } if ($step == "edit" && $view == "text" && !empty($ID) && $from_view != 'preview' && $from_view != 'html' && !$concurrent) { $pull = true; //-- it's an existing article - off we go to the db $ID = assert_int($ID); $rs = safe_row("*, unix_timestamp(Posted) as sPosted,\n\t\t\t\tunix_timestamp(Expires) as sExpires,\n\t\t\t\tunix_timestamp(LastMod) as sLastMod", "textpattern", "ID={$ID}"); if (empty($rs)) { return; } $rs['reset_time'] = $rs['publish_now'] = false; } else { $pull = false; //-- assume they came from post if ($from_view == 'preview' or $from_view == 'html') { $store_out = array(); $store = unserialize(base64_decode(ps('store'))); foreach ($vars as $var) { if (isset($store[$var])) { $store_out[$var] = $store[$var]; } } } else { $store_out = gpsa($vars); if ($concurrent) { $store_out['sLastMod'] = safe_field('unix_timestamp(LastMod) as sLastMod', 'textpattern', 'ID=' . $ID); } } $rs = textile_main_fields($store_out); if (!empty($rs['exp_year'])) { if (empty($rs['exp_month'])) { $rs['exp_month'] = 1; } if (empty($rs['exp_day'])) { $rs['exp_day'] = 1; } if (empty($rs['exp_hour'])) { $rs['exp_hour'] = 0; } if (empty($rs['exp_minute'])) { $rs['exp_minute'] = 0; } if (empty($rs['exp_second'])) { $rs['exp_second'] = 0; } $rs['sExpires'] = safe_strtotime($rs['exp_year'] . '-' . $rs['exp_month'] . '-' . $rs['exp_day'] . ' ' . $rs['exp_hour'] . ':' . $rs['exp_minute'] . ':' . $rs['exp_second']); } if (!empty($rs['year'])) { $rs['sPosted'] = safe_strtotime($rs['year'] . '-' . $rs['month'] . '-' . $rs['day'] . ' ' . $rs['hour'] . ':' . $rs['minute'] . ':' . $rs['second']); } } $validator = new Validator(array(new SectionConstraint($rs['Section']))); if (!$validator->validate()) { $rs['Section'] = getDefaultSection(); } extract($rs); $GLOBALS['step'] = $step; if ($step == 'create') { $textile_body = $use_textile; $textile_excerpt = $use_textile; } if ($step != 'create' && isset($sPosted)) { // Previous record? $rs['prev_id'] = checkIfNeighbour('prev', $sPosted); // Next record? $rs['next_id'] = checkIfNeighbour('next', $sPosted); } else { $rs['prev_id'] = $rs['next_id'] = 0; } // let plugins chime in on partials meta data callback_event_ref('article_ui', 'partials_meta', 0, $rs, $partials); $rs['partials_meta'] =& $partials; // get content for volatile partials foreach ($partials as $k => $p) { if ($p['mode'] == PARTIAL_VOLATILE || $p['mode'] == PARTIAL_VOLATILE_VALUE) { $cb = $p['cb']; $partials[$k]['html'] = is_array($cb) ? call_user_func($cb, $rs, $k) : $cb($rs, $k); } } if ($refresh_partials) { global $theme; $response[] = $theme->announce_async($message); // update the volatile partials foreach ($partials as $k => $p) { // volatile partials need a target DOM selector if (empty($p['selector']) && $p['mode'] != PARTIAL_STATIC) { trigger_error("Empty selector for partial '{$k}'", E_USER_ERROR); } else { // build response script if ($p['mode'] == PARTIAL_VOLATILE) { // volatile partials replace *all* of the existing HTML fragment for their selector $response[] = '$("' . $p['selector'] . '").replaceWith("' . escape_js($p['html']) . '")'; } elseif ($p['mode'] == PARTIAL_VOLATILE_VALUE) { // volatile partial values replace the *value* of elements matching their selector $response[] = '$("' . $p['selector'] . '").val("' . escape_js($p['html']) . '")'; } } } send_script_response(join(";\n", $response)); // bail out return; } foreach ($partials as $k => $p) { if ($p['mode'] == PARTIAL_STATIC) { $cb = $p['cb']; $partials[$k]['html'] = is_array($cb) ? call_user_func($cb, $rs, $k) : $cb($rs, $k); } } $page_title = $Title ? $Title : gTxt('write'); pagetop($page_title, $message); echo n . '<div id="' . $event . '_container" class="txp-container">'; echo n . n . '<form id="article_form" name="article_form" method="post" action="index.php" ' . ($step == 'create' ? '>' : ' class="async">'); if (!empty($store_out)) { echo hInput('store', base64_encode(serialize($store_out))); } echo hInput('ID', $ID) . n . eInput('article') . n . sInput($step) . n . hInput('sPosted', $sPosted) . n . hInput('sLastMod', $sLastMod) . n . hInput('AuthorID', $AuthorID) . n . hInput('LastModID', $LastModID) . '<input type="hidden" name="view" />' . startTable('', '', 'txp-columntable') . '<tr>' . n . '<td id="article-col-1"><div id="configuration_content">'; if ($view == 'text') { //-- markup help -------------- echo pluggable_ui('article_ui', 'sidehelp', side_help($textile_body, $textile_excerpt), $rs); //-- custom menu entries -------------- echo pluggable_ui('article_ui', 'extend_col_1', '', $rs); //-- advanced -------------- echo '<div id="advanced_group"><h3 class="lever' . (get_pref('pane_article_advanced_visible') ? ' expanded' : '') . '"><a href="#advanced">' . gTxt('advanced_options') . '</a></h3>' . '<div id="advanced" class="toggle" style="display:' . (get_pref('pane_article_advanced_visible') ? 'block' : 'none') . '">'; // markup selection echo pluggable_ui('article_ui', 'markup', n . graf('<label for="markup-body">' . gTxt('article_markup') . '</label>' . br . pref_text('textile_body', $textile_body, 'markup-body'), ' class="markup markup-body"') . n . graf('<label for="markup-excerpt">' . gTxt('excerpt_markup') . '</label>' . br . pref_text('textile_excerpt', $textile_excerpt, 'markup-excerpt'), ' class="markup markup-excerpt"'), $rs); // form override echo $allow_form_override ? pluggable_ui('article_ui', 'override', graf('<label for="override-form">' . gTxt('override_default_form') . '</label>' . sp . popHelp('override_form') . br . form_pop($override_form, 'override-form'), ' class="override-form"'), $rs) : ''; echo '</div></div>' . n; //-- custom fields -------------- echo $partials['custom_fields']['html']; //-- article image -------------- echo $partials['image']['html']; //-- meta info -------------- echo '<div id="meta_group"><h3 class="lever' . (get_pref('pane_article_meta_visible') ? ' expanded' : '') . '"><a href="#meta">' . gTxt('meta') . '</a></h3>' . '<div id="meta" class="toggle" style="display:' . (get_pref('pane_article_meta_visible') ? 'block' : 'none') . '">'; // keywords echo $partials['keywords']['html']; // url title echo $partials['url_title']['html']; echo '</div></div>' . n; //-- recent articles -------------- echo '<div id="recent_group"><h3 class="lever' . (get_pref('pane_article_recent_visible') ? ' expanded' : '') . '"><a href="#recent">' . gTxt('recent_articles') . '</a>' . '</h3>' . '<div id="recent" class="toggle" style="display:' . (get_pref('pane_article_recent_visible') ? 'block' : 'none') . '">'; echo $partials['recent_articles']['html']; echo '</div></div>'; } else { echo sp; } echo '</div></td>' . n . '<td id="article-main"><div id="main_content">'; //-- title input -------------- if ($view == 'preview') { echo '<div class="preview">' . hed(gTxt('preview'), 2) . hed($Title, 1, ' class="title"'); } elseif ($view == 'html') { echo '<div class="html">' . hed('HTML', 2) . hed($Title, 1, ' class="title"'); } elseif ($view == 'text') { echo '<div class="text">' . n . $partials['title']['html']; } //-- body -------------------- if ($view == 'preview') { echo '<div class="body">' . $Body_html . '</div>'; } elseif ($view == 'html') { echo tag(str_replace(array(n, t), array(br, sp . sp . sp . sp), txpspecialchars($Body_html)), 'code', ' class="body"'); } else { echo $partials['body']['html']; } //-- excerpt -------------------- if ($articles_use_excerpts) { if ($view == 'preview') { echo n . '<hr /><div class="excerpt">' . $Excerpt_html . '</div>'; } elseif ($view == 'html') { echo n . '<hr />' . tag(str_replace(array(n, t), array(br, sp . sp . sp . sp), txpspecialchars($Excerpt_html)), 'code', ' class="excerpt"'); } else { echo $partials['excerpt']['html']; } } //-- author -------------- if ($view == "text" && $step != "create") { echo $partials['author']['html']; } echo hInput('from_view', $view), '</div></div></td>'; //-- layer tabs ------------------- echo '<td id="article-tabs"><div id="view_modes">'; echo pluggable_ui('article_ui', 'view', $use_textile == USE_TEXTILE || $textile_body == USE_TEXTILE ? tag(tab('text', $view) . tab('html', $view) . tab('preview', $view), 'ul') : ' ', $rs); echo '</div></td>'; echo '<td id="article-col-2"><div id="supporting_content">'; if ($view == 'text') { if ($step != 'create') { echo n . graf(href(gtxt('create_new'), 'index.php?event=article'), ' class="action-create"'); } //-- prev/next article links -- if ($step != 'create' and ($rs['prev_id'] or $rs['next_id'])) { echo $partials['article_nav']['html']; } //-- status radios -------------- echo $partials['status']['html']; //-- sort and display ----------- echo pluggable_ui('article_ui', 'sort_display', n . n . tag(n . '<legend>' . gTxt('sort_display') . '</legend>' . $partials['section']['html'] . $partials['categories']['html'] . n, 'fieldset', ' id="write-sort"'), $rs); //-- "Comments" section echo n . n . '<div id="comments_group"' . ($use_comments == 1 ? '' : ' class="empty"') . '><h3 class="lever' . (get_pref('pane_article_comments_visible') ? ' expanded' : '') . '"><a href="#comments">' . gTxt('comment_settings') . '</a></h3>', '<div id="comments" class="toggle" style="display:' . (get_pref('pane_article_comments_visible') ? 'block' : 'none') . '">'; echo $partials['comments']['html']; // end "Comments" section echo '</div></div>'; //-- "Dates" section echo n . n . '<div id="dates_group"><h3 class="lever' . (get_pref('pane_article_dates_visible') ? ' expanded' : '') . '"><a href="#dates">' . gTxt('date_settings') . '</a></h3>', '<div id="dates" class="toggle" style="display:' . (get_pref('pane_article_dates_visible') ? 'block' : 'none') . '">'; if ($step == "create" and empty($GLOBALS['ID'])) { //-- timestamp ------------------- //Avoiding modified date to disappear $persist_timestamp = !empty($store_out['year']) ? safe_strtotime($store_out['year'] . '-' . $store_out['month'] . '-' . $store_out['day'] . ' ' . $store_out['hour'] . ':' . $store_out['minute'] . ':' . $store_out['second']) : time(); echo pluggable_ui('article_ui', 'timestamp', n . n . '<fieldset id="write-timestamp">' . n . '<legend>' . gTxt('timestamp') . '</legend>' . n . graf(checkbox('publish_now', '1', $publish_now, '', 'publish_now') . '<label for="publish_now">' . gTxt('set_to_now') . '</label>', ' class="publish-now"') . n . graf(gTxt('or_publish_at') . sp . popHelp('timestamp'), ' class="publish-at"') . n . graf('<span class="label">' . gtxt('date') . '</span>' . sp . tsi('year', '%Y', $persist_timestamp) . ' / ' . tsi('month', '%m', $persist_timestamp) . ' / ' . tsi('day', '%d', $persist_timestamp), ' class="date posted created"') . n . graf('<span class="label">' . gTxt('time') . '</span>' . sp . tsi('hour', '%H', $persist_timestamp) . ' : ' . tsi('minute', '%M', $persist_timestamp) . ' : ' . tsi('second', '%S', $persist_timestamp), ' class="time posted created"') . n . '</fieldset>', array('sPosted' => $persist_timestamp) + $rs); //-- expires ------------------- $persist_timestamp = !empty($store_out['exp_year']) ? safe_strtotime($store_out['exp_year'] . '-' . $store_out['exp_month'] . '-' . $store_out['exp_day'] . ' ' . $store_out['exp_hour'] . ':' . $store_out['exp_minute'] . ':' . $store_out['second']) : NULLDATETIME; echo pluggable_ui('article_ui', 'expires', n . n . '<fieldset id="write-expires">' . n . '<legend>' . gTxt('expires') . '</legend>' . n . graf('<span class="label">' . gtxt('date') . '</span>' . sp . tsi('exp_year', '%Y', $persist_timestamp) . ' / ' . tsi('exp_month', '%m', $persist_timestamp) . ' / ' . tsi('exp_day', '%d', $persist_timestamp), ' class="date expires"') . n . graf('<span class="label">' . gTxt('time') . '</span>' . sp . tsi('exp_hour', '%H', $persist_timestamp) . ' : ' . tsi('exp_minute', '%M', $persist_timestamp) . ' : ' . tsi('exp_second', '%S', $persist_timestamp), ' class="time expires"') . n . '</fieldset>', $rs); // end "Dates" section echo n . n . '</div></div>'; //-- publish button -------------- echo graf(has_privs('article.publish') ? fInput('submit', 'publish', gTxt('publish'), "publish", '', '', '', 4) : fInput('submit', 'publish', gTxt('save'), "publish", '', '', '', 4), ' id="write-publish"'); } else { //-- timestamp ------------------- echo $partials['posted']['html']; //-- expires ------------------- echo $partials['expires']['html']; // end "Dates" section echo n . n . '</div></div>'; //-- save button -------------- if ($Status >= STATUS_LIVE and has_privs('article.edit.published') or $Status >= STATUS_LIVE and $AuthorID == $txp_user and has_privs('article.edit.own.published') or $Status < STATUS_LIVE and has_privs('article.edit') or $Status < STATUS_LIVE and $AuthorID == $txp_user and has_privs('article.edit.own')) { echo graf(fInput('submit', 'save', gTxt('save'), "publish", '', '', '', 4), ' id="write-save"'); } } } echo '</div></td></tr></table>' . n . tInput() . n . '</form></div>' . n; // Assume users would not change the timestamp if they wanted to "publish now"/"reset time" echo script_js(<<<EOS \t\t\$('#write-timestamp input.year,#write-timestamp input.month,#write-timestamp input.day,#write-timestamp input.hour,#write-timestamp input.minute,#write-timestamp input.second').change( \t\t\tfunction() { \t\t\t\t\$('#publish_now').prop('checked', false); \t\t\t\t\$('#reset_time').prop('checked', false); \t\t\t}); EOS ); }
return false; } <?php // Remove the <colgroup>. This is only needed to assist in the formatting // of the non-datatable version of the table. When we have a datatable, // the datatable sorts out its own formatting. ?> table.find('colgroup').remove(); <?php // Set up the default options ?> defaultOptions = { buttons: [{extend: 'colvis', text: '<?php echo escape_js(get_vocab("show_hide_columns")); ?> '}], deferRender: true, paging: true, pageLength: 25, pagingType: 'full_numbers', processing: true, scrollCollapse: true, stateSave: true, dom: 'B<"clear">lfrtip', scrollX: '100%', colReorder: {} }; <?php
if (preg_match("~{$search}~i", $row['address'])) { $descriptions[$row['id']] = escape_js(trans('Address:') . ' ' . $row['address']); continue; } else { if (preg_match("~{$search}~i", $row['post_name'])) { $descriptions[$row['id']] = escape_js(trans('Name:') . ' ' . $row['post_name']); continue; } else { if (preg_match("~{$search}~i", $row['post_address'])) { $descriptions[$row['id']] = escape_js(trans('Address:') . ' ' . $row['post_address']); continue; } } } if (preg_match("~{$search}~i", $row['email'])) { $descriptions[$row['id']] = escape_js(trans('E-mail:') . ' ' . $row['email']); continue; } $descriptions[$row['id']] = ''; } } header('Content-type: text/plain'); if ($eglible) { print "this.eligible = [\"" . implode('","', $eglible) . "\"];\n"; print "this.descriptions = [\"" . implode('","', $descriptions) . "\"];\n"; print "this.actions = [\"" . implode('","', $actions) . "\"];\n"; } else { print "false;\n"; } exit; }
return false; } } } <?php } ?> if ((thisValue > startValue) || ((thisValue === startValue) && enablePeriods) || (dateDifference !== 0)) { optionClone = $(this).clone(); if (dateDifference < 0) { optionClone.text('<?php echo escape_js(get_vocab("start_after_end")); ?> '); } else { optionClone.text($(this).text() + nbsp + nbsp + '(' + getDuration(startValue, thisValue, dateDifference) + ')'); } endSelect.append(optionClone); } }); endValue = Math.min(endValue, parseInt(endSelect.find('option').last().val(), 10)); endSelect.val(endValue);
area_select.setAttribute('name', 'area'); area_select.onchange = function(){changeRooms(this.form)}; // setAttribute doesn't work for onChange with IE6 // populated with options var option; var option_text <?php // go through the areas and create the options foreach ($areas as $a) { ?> option = document.createElement('option'); option.value = <?php echo $a['id']; ?> ; option_text = document.createTextNode('<?php echo escape_js($a['area_name']); ?> '); <?php if ($a['id'] == $area_id) { ?> option.selected = true; <?php } ?> option.appendChild(option_text); area_select.appendChild(option); <?php } ?> // insert the <select> which we've just assembled into the <div>
/** * Hooks to article saving process and updates short URLs */ public static function update() { global $prefs; if (empty($prefs['rah_bitly_login']) || empty($prefs['rah_bitly_apikey']) || empty($prefs['rah_bitly_field'])) { return; } static $old = array(); static $updated = false; $id = !empty($GLOBALS['ID']) ? $GLOBALS['ID'] : ps('ID'); if (!$id || ps('_txp_token') != form_token() || intval(ps('Status')) < 4) { $old = array('permlink' => NULL, 'status' => NULL); return; } include_once txpath . '/publish/taghandlers.php'; /* Get the old article permlink before anything is saved */ if (!$old) { $old = array('permlink' => permlinkurl_id($id), 'status' => fetch('Status', 'textpattern', 'ID', $id)); return; } /* Clear the permlink cache */ unset($GLOBALS['permlinks'][$id]); /* Generate a new if permlink has changed or if article is published */ if (callback_event('rah_bitly.update') !== '') { return; } if ($updated == false && ($permlink = permlinkurl_id($id)) && ($old['permlink'] != $permlink || !ps('custom_' . $prefs['rah_bitly_field']) || $old['status'] != ps('Status'))) { $uri = self::fetch($permlink); if ($uri) { $fields = getCustomFields(); if (!isset($fields[$prefs['rah_bitly_field']])) { return; } safe_update('textpattern', 'custom_' . intval($prefs['rah_bitly_field']) . "='" . doSlash($uri) . "'", "ID='" . doSlash($id) . "'"); $_POST['custom_' . $prefs['rah_bitly_field']] = $uri; } $updated = true; } if (!empty($uri)) { echo script_js('$(\'input[name="custom_' . $prefs['rah_bitly_field'] . '"]\').val("' . escape_js($uri) . '");'); } }
return $JSResponse; } $LMS->InitXajax(); $LMS->RegisterXajaxFunction(array('getGroupTableRow')); $SMARTY->assign('xajax', $LMS->RunXajax()); if (isset($_GET['ajax'])) { header('Content-type: text/plain'); $search = urldecode(trim($_GET['what'])); $result = $DB->GetAll('SELECT id, name as item FROM voip_prefix_groups WHERE name ?LIKE? ? LIMIT 20', array('%' . $search . '%')); $eglible = $descriptions = array(); if ($result) { foreach ($result as $idx => $row) { $eglible[$row['item']] = escape_js($row['item']); $descriptions[$row['item']] = $row['id'] . ' :id'; } } if ($eglible) { print "this.eligible = [\"" . implode('","', $eglible) . "\"];\n"; print "this.descriptions = [\"" . implode('","', $descriptions) . "\"];\n"; } else { print "false;\n"; } exit; } $rule = isset($_POST['rule']) ? $_POST['rule'] : NULL; $rule_id = isset($_GET['id']) ? (int) $_GET['id'] : 0; $error = array(); if (isset($_GET['action']) && $_GET['action'] == 'delete') {
// Check whether everything has finished ?> if (results.length >= nBatches) { $('#report_table_processing').css('visibility', 'hidden'); <?php // If all's gone well the result will contain the number of entries deleted ?> nDeleted = 0; isInt = /^\s*\d+\s*$/; for (i=0; i<results.length; i++) { if (!isInt.test(results[i])) { window.alert("<?php echo escape_js(get_vocab('delete_entries_failed')); ?> "); break; } nDeleted += parseInt(results[i], 10); } <?php // Reload the page to get the new dataset. If we're using // an Ajax data source (for true Ajax data sources, not server // side processing) and there's no summary table we can be // slightly more elegant and just reload the Ajax data source. ?> oSettings = reportTable.fnSettings(); if (oSettings.ajax && !oSettings.bServerSide &&
$search = str_replace(' ', '%', $search); $sql_search = $DB->Escape("%{$search}%"); if (isset($_GET['ajax'])) { $candidates = $DB->GetAll("SELECT s.id, s.productid, s.serialnumber, s.pricebuynet, s.pricebuygross, s.bdate,\n\t\t\t\t\t" . $DB->Concat('m.name', "' '", 'p.name') . " as name, p.ean\n\t\t\t\t\tFROM stck_stock s\n\t\t\t\t\tLEFT JOIN stck_products p ON p.id = s.productid\n\t\t\t\t\tLEFT JOIN stck_manufacturers m ON m.id = p.manufacturerid\n\t\t\t\t\tLEFT JOIN stck_warehouses w ON s.warehouseid = w.id\n\t\t\t\t\tWHERE s.leavedate = 0 AND\n\t\t\t\t\t(" . (preg_match('/^[0-9]+$/', $search) ? 's.productid = ' . intval($search) . ' OR ' : '') . "\n\t\t\t\t\tLOWER(" . $DB->Concat('m.name', "' '", 'p.name') . ") ?LIKE? LOWER(" . $sql_search . ")\n\t\t\t\t\tOR LOWER(p.ean) ?LIKE? LOWER(" . $sql_search . ")\n\t\t\t\t\tOR LOWER(s.serialnumber) ?LIKE? LOWER(" . $sql_search . "))\n\t\t\t\t\tAND w.commerce = 1\n\t\t\t\t\tORDER BY s.creationdate ASC, name\n\t\t\t\t\tLIMIT 15"); $eglible = array(); $actions = array(); $descriptions = array(); if ($candidates) { foreach ($candidates as $idx => $row) { $desc = $row['name']; if ($row['serialnumber']) { $desc = $desc . " (S/N: " . $row['serialnumber'] . ")"; } //$actions[$row['id']] = 'javascript:pinv(\''.$row['id'].'\',\''.$row['pricebuynet'].'\',\''.$row['pricebuygross'].'\')'; $actions[$row['id']] = '?m=stckproductinfo&id=' . $row['productid']; $eglible[$row['id']] = escape_js(($row['deleted'] ? '<font class="blend">' : '') . truncate_str($desc, 100) . ($row['deleted'] ? '</font>' : '')); $descriptions[$row['id']] = '<b>' . trans("Gross:") . " " . $row['pricebuygross'] . "</b> " . trans("Bought:") . " " . date("d/m/Y", $row['bdate']); } } header('Content-type: text/plain'); if ($eglible) { print "this.eligible = [\"" . implode('","', $eglible) . "\"];\n"; print "this.descriptions = [\"" . implode('","', $descriptions) . "\"];\n"; print "this.actions = [\"" . implode('","', $actions) . "\"];\n"; } else { print "false;\n"; } } exit; break;
JOIN domains d ON (a.domainid = d.id) WHERE a.login ?LIKE? LOWER($username) ".($domain ? "AND d.name ?LIKE? LOWER($domain)" : '').") ORDER BY login, domain LIMIT 15"); $eglible=array(); $actions=array(); $descriptions=array(); if ($candidates) foreach($candidates as $idx => $row) { if($row['type']) $actions[$row['id']] = '?m=aliasinfo&id='.$row['id']; else $actions[$row['id']] = '?m=accountinfo&id='.$row['id']; $eglible[$row['id']] = escape_js($row['login'].'@'.$row['domain']); $descriptions[$row['id']] = ''; } header('Content-type: text/plain'); if ($eglible) { print "this.eligible = [\"".implode('","',$eglible)."\"];\n"; print "this.descriptions = [\"".implode('","',$descriptions)."\"];\n"; print "this.actions = [\"".implode('","',$actions)."\"];\n"; } else { print "false;\n"; } exit; } $search = array(); $search['login'] = $ac[0];
private function _announce($thing, $async, $modal) { // $thing[0]: message text. // $thing[1]: message type, defaults to "success" unless empty or a different flag is set. if (!is_array($thing) || !isset($thing[1])) { $thing = array($thing, 0); } // Still nothing to say? if (trim($thing[0]) === '') { return ''; } switch ($thing[1]) { case E_ERROR: $class = 'error'; break; case E_WARNING: $class = 'warning'; break; default: $class = 'success'; break; } if ($modal) { $html = ''; // TODO: Say what? $js = 'window.alert("' . escape_js(strip_tags($thing[0])) . '")'; } else { $html = span(gTxt($thing[0]) . sp . href('×', '#close', ' class="close" role="button" title="' . gTxt('close') . '" aria-label="' . gTxt('close') . '"'), array('class' => $class, 'id' => 'message', 'role' => 'alert')); // Try to inject $html into the message pane no matter when _announce()'s output is printed. $js = escape_js($html); $js = <<<EOS \$(document).ready(function () { \$("#messagepane").html("{$js}"); \$('#message.success, #message.warning, #message.error').fadeOut('fast').fadeIn('fast'); }); EOS; } if ($async) { return $js; } else { return script_js(str_replace('</', '<\\/', $js), $html); } }
case DOC_INVOICE: $actions[$row['id']] = '?m=invoice&id=' . $row['id']; break; case DOC_RECEIPT: $actions[$row['id']] = '?m=receipt&id=' . $row['id']; break; case DOC_CNOTE: $actions[$row['id']] = '?m=note&id=' . $row['id']; break; default: $actions[$row['id']] = '?m=documentview&id=' . $row['id']; } */ $actions[$row['id']] = '?m=customerinfo&id=' . $row['cid']; $eglible[$row['id']] = escape_js($row['fullnumber']); $descriptions[$row['id']] = escape_js(truncate_str($row['customername'], 35)); //$descriptions[$row['id']] = trans('Document id:') . ' ' . $row['id']; } header('Content-type: text/plain'); if ($eglible) { print "this.eligible = [\"".implode('","',$eglible)."\"];\n"; print "this.descriptions = [\"".implode('","',$descriptions)."\"];\n"; print "this.actions = [\"".implode('","',$actions)."\"];\n"; } else { print "false;\n"; } $SESSION->close(); $DB->Destroy(); exit; }
} $list = $DB->GetAll('SELECT c.id, c.name, b.name AS borough, b.type AS btype, d.name AS district, d.id AS districtid, s.name AS state, s.id AS stateid FROM location_cities c JOIN location_boroughs b ON (c.boroughid = b.id) JOIN location_districts d ON (b.districtid = d.id) JOIN location_states s ON (d.stateid = s.id) WHERE c.name ?LIKE? ' . $DB->Escape("%{$search}%") . ' ORDER BY c.name, b.type LIMIT 10'); $eligible = $actions = array(); if ($list) { foreach ($list as $idx => $row) { $name = sprintf('%s (%s%s, %s)', $row['name'], $row['btype'] < 4 ? trans('<!borough_abbr>') : '', $row['borough'], trans('<!district_abbr>') . $row['district']); $eligible[$idx] = escape_js($name); $actions[$idx] = sprintf("javascript: search_update(%d,%d,%d)", $row['id'], $row['districtid'], $row['stateid']); } } if ($eligible) { print "this.eligible = [\"" . implode('","', $eligible) . "\"];\n"; print "this.actions = [\"" . implode('","', $actions) . "\"];\n"; } else { print "false;\n"; } die; } function select_location($what, $id) { global $DB; $JSResponse = new xajaxResponse();
/** * Attach a HTML fragment to a DOM node. * * @param string $id Target DMO node's id * @param string $content HTML fragment * @param string $noscript noscript alternative fragment [''] * @param string $wraptag Wrapping HTML element * @param string $wraptagid Wrapping element's HTML id * @return string HTML/JS */ function dom_attach($id, $content, $noscript = '', $wraptag = 'div', $wraptagid = '') { $content = escape_js($content); $js = <<<EOF \t\t\t\$(document).ready(function() { \t\t\t\t\$('#{$id}').append(\$('<{$wraptag} />').attr('id', '{$wraptagid}').html('{$content}')); \t\t\t}); EOF; return script_js($js, $noscript); }
/** * Renders a checkbox to set/unset a browser cookie. * * @param string $classname Label text. The cookie's name will be derived from this value * @param bool $form Create as a stand-along <form> element * @return string HTML */ function cookie_box($classname, $form = true) { $name = 'cb_' . $classname; $id = escape_js($name); $class = escape_js($classname); if (cs('toggle_' . $classname)) { $value = 1; } else { $value = 0; } $newvalue = 1 - $value; $out = checkbox($name, 1, (bool) $value, 0, $name) . n . tag(gTxt($classname), 'label', array('for' => $name)); $js = <<<EOF \$(function () { \$('input') .filter(function () { if (\$(this).attr('id') === '{$id}') { return true; } }) .change(function () { setClassRemember('{$class}', {$newvalue}); \$(this).parents('form').submit(); }); }); EOF; $out .= script_js($js); if ($form) { if (serverSet('QUERY_STRING')) { $action = 'index.php?' . serverSet('QUERY_STRING'); } else { $action = 'index.php'; } $out .= eInput(gps('event')) . tInput(); return tag($out, 'form', array('class' => $name, 'method' => 'post', 'action' => $action)); } return $out; }
private function _announce($thing, $async, $modal) { // $thing[0]: message text. // $thing[1]: message type, defaults to "success" unless empty or a different flag is set. if ($thing === '') { return ''; } if (!is_array($thing) || !isset($thing[1])) { $thing = array($thing, 0); } switch ($thing[1]) { case E_ERROR: $class = 'error'; $icon = 'ui-icon-closethick'; break; case E_WARNING: $class = 'warning'; $icon = 'ui-icon-alert'; break; default: $class = 'success'; $icon = 'ui-icon-check'; break; } if ($modal) { $html = ''; // TODO: Say what? $js = 'window.alert("' . escape_js(strip_tags($thing[0])) . '")'; } else { $html = span(span(null, array('class' => 'ui-icon ' . $icon)) . ' ' . gTxt($thing[0]) . sp . href('×', '#close', ' class="close" role="button" title="' . gTxt('close') . '" aria-label="' . gTxt('close') . '"'), array('class' => 'messageflash ' . $class, 'role' => 'alert', 'aria-live' => 'assertive')); // Try to inject $html into the message pane no matter when _announce()'s output is printed. $js = escape_js($html); $js = <<<EOS \$(document).ready(function () { \$("#messagepane").html("{$js}"); \$(window).resize(function () { \$("#messagepane").css({ left: (\$(window).width() - \$("#messagepane").outerWidth()) / 2 }); }); \$(window).resize(); }); EOS; } if ($async) { return $js; } else { return script_js(str_replace('</', '<\\/', $js), $html); } }
vocab['hours'] = []; vocab['hours']['singular'] = '<?php echo escape_js(get_vocab("hour_lc")); ?> '; vocab['hours']['plural'] = '<?php echo escape_js(get_vocab("hours")); ?> '; vocab['days'] = []; vocab['days']['singular'] = '<?php echo escape_js(get_vocab("day_lc")); ?> '; vocab['days']['plural'] = '<?php echo escape_js(get_vocab("days")); ?> '; <?php // Get the details of the start and end slot selectors now since // they are fully populated with options. We can then use the details // to rebuild the selectors later on ?> var i, j, area, startSelect, endSelect, allDay; for (i in areas) { area = i; startSelect = form["start_seconds" + area]; endSelect = form["end_seconds" + area]; startOptions[area] = [];
if (!isset($mode)) { print 'false;'; exit; } $candidates = $DB->GetAll('SELECT ' . $mode . ' as item, count(id) as entries FROM customeraddressview WHERE ' . $mode . ' != \'\' AND lower(' . $mode . ') ?LIKE? lower(' . $DB->Escape('%' . $search . '%') . ') GROUP BY item ORDER BY entries desc, item asc LIMIT 15'); $eglible = array(); $descriptions = array(); if ($candidates) { foreach ($candidates as $idx => $row) { $eglible[$row['item']] = escape_js($row['item']); $descriptions[$row['item']] = escape_js($row['entries'] . ' ' . trans('entries')); } } if ($eglible) { print "this.eligible = [\"" . implode('","', $eglible) . "\"];\n"; print "this.descriptions = [\"" . implode('","', $descriptions) . "\"];\n"; } else { print "false;\n"; } exit; } $customeradd = array(); if (isset($_POST['customeradd'])) { $customeradd = $_POST['customeradd']; if (sizeof($customeradd)) { foreach ($customeradd as $key => $value) {
if ($CONFIG['debug']) { $fulltitle = clean($res['title']) . "<br>Rating: {$res['rating']}"; } else { $fulltitle = clean($res['title']); } $tooltipdata[] = array('id' => $id, 'fulltitle' => $fulltitle); $title = clean(limit($res['title'], ' on YouTube', 65)); $caption = "\$('youtube_caption_{$jsid}')"; ?> <div class="youtube_frame"> <div class="youtube_thumb" onmouseover="<?php echo $caption; ?> .innerHTML = '<?php echo escape_js($title); ?> ';" onmouseout="<?php echo $caption; ?> .innerHTML = '<?php echo $default_caption; ?> ';" > <a class="bodylink youtube_link" href="<?php echo $content; //$link; ?> " onclick="<?php showYouTubeVid($content);
$actions = array(); $descriptions = array(); if ($candidates) { foreach ($candidates as $idx => $row) { $actions[$row['id']] = 'javascript:pad(\'' . $row['id'] . '\')'; $eglible[$row['id']] = escape_js(($row['deleted'] ? '<font class="blend">' : '') . truncate_str($row['name'], 150) . ($row['deleted'] ? '</font>' : '')); if (preg_match("~^{$search}\$~i", $row['id'])) { $descriptions[$row['id']] = escape_js(trans('Id:') . ' ' . $row['id']); continue; } if (preg_match("~{$search}~i", $row['name'])) { $descriptions[$row['id']] = ''; continue; } if (preg_match("~{$search}~i", $row['ean'])) { $descriptions[$row['id']] = escape_js(trans('EAN:') . ' ' . $row['ean']); continue; } $descriptions[$row['id']] = ''; } } header('Content-type: text/plain'); if ($eglible) { print "this.eligible = [\"" . implode('","', $eglible) . "\"];\n"; print "this.descriptions = [\"" . implode('","', $descriptions) . "\"];\n"; print "this.actions = [\"" . implode('","', $actions) . "\"];\n"; } else { print "false;\n"; } exit; }
private function _announce($thing, $async, $modal) { // $thing[0]: message text // $thing[1]: message type, defaults to "success" unless empty or a different flag is set if ($thing === '') { return ''; } if (!is_array($thing) || !isset($thing[1])) { $thing = array($thing, 0); } switch ($thing[1]) { case E_ERROR: $class = 'error'; break; case E_WARNING: $class = 'warning'; break; default: $class = 'success'; break; } if ($modal) { $html = ''; // TODO: Say what? $js = 'window.alert("' . escape_js(strip_tags($thing[0])) . '")'; } else { $html = '<span id="message" class="messageflash ' . $class . '">' . gTxt($thing[0]) . ' <a href="#close" class="close">×</a></span>'; // Try to inject $html into the message pane no matter when _announce()'s output is printed $js = escape_js($html); $js = <<<EOS \t\t\t\t\$(document).ready(function() { \t\t\t\t\t\$("#messagepane").html("{$js}"); \t\t\t\t\t\$(window).resize(function() { \t\t\t\t\t\t\$("#messagepane").css({ \t\t\t\t\t\t\tleft: (\$(window).width() - \$("#messagepane").outerWidth()) / 2 \t\t\t\t\t\t}); \t\t\t\t\t}); \t\t\t\t\t\$(window).resize(); \t\t\t\t}); EOS; } if ($async) { return $js; } else { return script_js(str_replace('</', '<\\/', $js), $html); } }