Example #1
0
/**
 * Renders the list of preferences.
 *
 * Plugins may add their own prefs, for example by using plugin lifecycle events
 * or raising a (pre) callback on event=admin / step=prefs_list so they are
 * installed or updated when accessing the Preferences panel. Access to the
 * prefs can be controlled by using add_privs() on 'prefs.your-prefs-event-name'.
 *
 * @param string $message The feedback / error string to display
 */
function prefs_list($message = '')
{
    global $prefs, $txp_user;
    extract($prefs);
    pagetop(gTxt('tab_preferences'), $message);
    $locale = setlocale(LC_ALL, $locale);
    echo n . '<form class="prefs-form" id="prefs_form" method="post" action="index.php">';
    // TODO: remove 'custom' when custom fields are refactored.
    $core_events = array('site', 'admin', 'publish', 'feeds', 'comments', 'custom');
    $joined_core = join(',', quote_list($core_events));
    $sql = array();
    $sql[] = 'prefs_id = 1 and event != "" and type in(' . PREF_CORE . ', ' . PREF_PLUGIN . ')';
    $sql[] = "(user_name = '' OR (user_name = '" . doSlash($txp_user) . "' AND name NOT IN (\n            SELECT name FROM " . safe_pfx('txp_prefs') . " WHERE user_name = ''\n        )))";
    if (!get_pref('use_comments', 1, 1)) {
        $sql[] = "event != 'comments'";
    }
    $rs = safe_rows_start("*, FIELD(event, {$joined_core}) AS sort_value", 'txp_prefs', join(" AND ", $sql) . " ORDER BY sort_value = 0, sort_value, event, position");
    $last_event = null;
    $out = array();
    $build = array();
    $groupOut = array();
    if (numRows($rs)) {
        while ($a = nextRow($rs)) {
            if (!has_privs('prefs.' . $a['event'])) {
                continue;
            }
            if ($a['event'] !== $last_event) {
                if ($last_event !== null) {
                    $build[] = tag(hed(gTxt($last_event), 2, array('id' => 'prefs_group_' . $last_event . '-label')) . join(n, $out), 'section', array('class' => 'txp-prefs-group', 'id' => 'prefs_group_' . $last_event, 'aria-labelledby' => 'prefs_group_' . $last_event . '-label'));
                    $groupOut[] = n . tag(href(gTxt($last_event), '#prefs_group_' . $last_event, array('data-txp-pane' => $last_event, 'data-txp-token' => form_token())), 'li');
                }
                $last_event = $a['event'];
                $out = array();
            }
            $label = '';
            if (!in_array($a['html'], array('yesnoradio', 'is_dst'))) {
                $label = $a['name'];
            }
            // TODO: remove exception when custom fields move to meta store.
            $help = '';
            if (strpos($a['name'], 'custom_') === false) {
                $help = $a['name'];
            }
            if ($a['html'] == 'text_input') {
                $size = INPUT_REGULAR;
            } else {
                $size = '';
            }
            $out[] = inputLabel($a['name'], pref_func($a['html'], $a['name'], $a['val'], $size), $label, $help, array('class' => 'txp-form-field', 'id' => 'prefs-' . $a['name']));
        }
    }
    if ($last_event === null) {
        echo graf(gTxt('no_preferences'));
    } else {
        $build[] = tag(hed(gTxt($last_event), 2, array('id' => 'prefs_group_' . $last_event . '-label')) . join(n, $out), 'section', array('class' => 'txp-prefs-group', 'id' => 'prefs_group_' . $last_event, 'aria-labelledby' => 'prefs_group_' . $last_event . '-label'));
        $groupOut[] = n . tag(href(gTxt($last_event), '#prefs_group_' . $last_event, array('data-txp-pane' => $last_event, 'data-txp-token' => form_token())), 'li') . n;
        echo hed(gTxt('tab_preferences'), 1, array('class' => 'txp-heading')) . n . '<div class="txp-layout-4col-cell-1alt">' . wrapGroup('all_preferences', n . tag(join($groupOut), 'ul', array('class' => 'switcher-list')), 'all_preferences');
        if ($last_event !== null) {
            echo graf(fInput('submit', 'Submit', gTxt('save'), 'publish'), array('class' => 'txp-save'));
        }
        echo n . '</div>' . n . '<div class="txp-layout-4col-cell-2-3-4">' . join(n, $build) . n . '</div>' . sInput('prefs_save') . eInput('prefs') . hInput('prefs_id', '1') . tInput();
    }
    echo n . '</form>';
}
Example #2
0
/**
 * Renders the list of preferences.
 *
 * Plugins may add their own prefs, for example by using plugin lifecycle events or
 * raising a (pre) callback on event=admin / step=prefs_list so they are installed
 * or updated when accessing the Preferences panel. Access to the prefs can be
 * controlled by using add_privs() on 'prefs.your-prefs-event-name'.
 *
 * @param  string $message The feedback / error string to display
 */
function prefs_list($message = '')
{
    global $prefs, $txp_user;
    extract($prefs);
    pagetop(gTxt('tab_preferences'), $message);
    $locale = setlocale(LC_ALL, $locale);
    echo hed(gTxt('tab_preferences'), 1, array('class' => 'txp-heading'));
    echo n . '<div id="prefs_container" class="txp-container">' . n . '<form method="post" class="prefs-form" action="index.php">' . n . '<div class="txp-layout-textbox">';
    // TODO: remove 'custom' when custom fields are refactored.
    $core_events = array('site', 'admin', 'publish', 'feeds', 'comments', 'custom');
    $joined_core = join(',', quote_list($core_events));
    $sql = array();
    $sql[] = 'prefs_id = 1 and event != "" and type in(' . PREF_CORE . ', ' . PREF_PLUGIN . ')';
    $sql[] = "(user_name = '' or (user_name='" . doSlash($txp_user) . "' and name not in(\n            select name from " . safe_pfx('txp_prefs') . " where user_name = ''\n        )))";
    if (!get_pref('use_comments', 1, 1)) {
        $sql[] = "event != 'comments'";
    }
    $rs = safe_rows_start("*, FIELD(event,{$joined_core}) as sort_value", 'txp_prefs', join(' and ', $sql) . " ORDER BY sort_value = 0, sort_value, event, position");
    $last_event = null;
    $out = array();
    if (numRows($rs)) {
        while ($a = nextRow($rs)) {
            if (!has_privs('prefs.' . $a['event'])) {
                continue;
            }
            if ($a['event'] !== $last_event) {
                if ($last_event !== null) {
                    echo wrapRegion('prefs_group_' . $last_event, join(n, $out), 'prefs_' . $last_event, $last_event, 'prefs_' . $last_event);
                }
                $last_event = $a['event'];
                $out = array();
            }
            $label = '';
            if (!in_array($a['html'], array('yesnoradio', 'is_dst'))) {
                $label = $a['name'];
            }
            // TODO: remove exception when custom fields move to meta store.
            $help = '';
            if (strpos($a['name'], 'custom_') === false) {
                $help = $a['name'];
            }
            if ($a['html'] == 'text_input') {
                $size = INPUT_REGULAR;
            } else {
                $size = '';
            }
            $out[] = inputLabel($a['name'], pref_func($a['html'], $a['name'], $a['val'], $size), $label, $help, array('id' => 'prefs-' . $a['name']));
        }
    }
    if ($last_event === null) {
        echo graf(gTxt('no_preferences'));
    } else {
        echo wrapRegion('prefs_group_' . $last_event, join(n, $out), 'prefs_' . $last_event, $last_event, 'prefs_' . $last_event);
    }
    echo n . '</div>' . sInput('prefs_save') . eInput('prefs') . hInput('prefs_id', '1') . tInput();
    if ($last_event !== null) {
        echo graf(fInput('submit', 'Submit', gTxt('save'), 'publish'));
    }
    echo n . '</form>' . n . '</div>';
}
Example #3
0
function advanced_prefs($message = '')
{
    global $textarray;
    // this means new language strings and new help entries
    echo pagetop(gTxt('advanced_preferences'), $message) . n . n . '<form method="post" action="index.php">' . n . n . startTable('list') . n . n . tr(tdcs(hed(gTxt('advanced_preferences'), 1), 3)) . n . n . tr(tdcs(sLink('prefs', 'prefs_list', gTxt('site_prefs'), 'navlink') . sp . sLink('prefs', 'advanced_prefs', gTxt('advanced_preferences'), 'navlink-active') . sp . sLink('prefs', 'list_languages', gTxt('manage_languages'), 'navlink'), '3'));
    $rs = safe_rows_start('*', 'txp_prefs', "type = 1 and prefs_id = 1 order by event, position");
    $cur_evt = '';
    while ($a = nextRow($rs)) {
        if ($a['event'] != $cur_evt) {
            $cur_evt = $a['event'];
            echo n . n . tr(tdcs(hed(gTxt($a['event']), 2, ' class="pref-heading"'), 3));
        }
        $label = $a['html'] != 'yesnoradio' ? '<label for="' . $a['name'] . '">' . gTxt($a['name']) . '</label>' : gTxt($a['name']);
        $out = tda($label, ' style="text-align: right; vertical-align: middle;"');
        if ($a['html'] == 'text_input') {
            $look_for = array('expire_logs_after', 'max_url_len', 'time_offset', 'rss_how_many', 'logs_expire');
            $size = in_array($a['name'], $look_for) ? 3 : 20;
            $out .= td(pref_func('text_input', $a['name'], $a['val'], $size));
        } else {
            if (is_callable($a['html'])) {
                $out .= td(pref_func($a['html'], $a['name'], $a['val']));
            } else {
                $out .= td($a['val']);
            }
        }
        $out .= tda(popHelp($a['name']), ' style="vertical-align: middle;"');
        echo n . n . tr($out);
    }
    echo n . n . tr(tda(fInput('submit', 'Submit', gTxt('save_button'), 'publish') . sInput('advanced_prefs_save') . eInput('prefs') . hInput('prefs_id', '1'), ' colspan="3" class="noline"')) . n . n . endTable() . n . n . '</form>';
}
Example #4
0
function advanced_prefs($message = '')
{
    echo pagetop(gTxt('advanced_preferences'), $message) . n . '<div id="prefs_container" class="txp-container txp-list">' . n . n . '<form method="post" class="prefs-form advanced" action="index.php">' . n . n . startTable('list', '', 'list') . n . n . tr(tdcs(hed(gTxt('advanced_preferences'), 2), 3)) . n . n . tr(tdcs(sLink('prefs', 'prefs_list', gTxt('site_prefs'), 'navlink') . sp . sLink('prefs', 'advanced_prefs', gTxt('advanced_preferences'), 'navlink-active') . sp . sLink('prefs', 'list_languages', gTxt('manage_languages'), 'navlink'), '3', '', 'nav-tertiary'));
    $rs = safe_rows_start('*', 'txp_prefs', "type = 1 and prefs_id = 1 order by event, position");
    $cur_evt = '';
    while ($a = nextRow($rs)) {
        if ($a['event'] != $cur_evt) {
            $cur_evt = $a['event'];
            $ctr = 1;
            echo n . n . tr(tdcs(hed(gTxt($a['event']), 3, ' class="pref-heading ' . $a['event'] . '-prefs"'), 3));
        }
        $label = $a['html'] != 'yesnoradio' ? '<label for="' . $a['name'] . '">' . gTxt($a['name']) . '</label>' : gTxt($a['name']);
        $out = tda($label, ' style="text-align: right; vertical-align: middle;" class="pref-label"');
        if ($a['html'] == 'text_input') {
            $look_for = array('expire_logs_after', 'max_url_len', 'time_offset', 'rss_how_many', 'logs_expire');
            $size = in_array($a['name'], $look_for) ? 3 : 20;
            $out .= td(pref_func('text_input', $a['name'], $a['val'], $size));
        } else {
            if (is_callable($a['html'])) {
                $out .= td(pref_func($a['html'], $a['name'], $a['val']), '', 'pref-value');
            } else {
                $out .= td($a['val'], '', 'pref-value');
            }
        }
        $out .= tda(popHelp($a['name']), ' style="vertical-align: middle;"');
        echo n . n . tr($out, " id='prefs-{$a['name']}' class='{$a['event']}-prefs " . ($ctr % 2 == 0 ? 'even' : 'odd') . "'");
        $ctr++;
    }
    echo n . n . tr(tda(fInput('submit', 'Submit', gTxt('save_button'), 'publish') . sInput('advanced_prefs_save') . eInput('prefs') . hInput('prefs_id', '1'), ' colspan="3" class="noline"')) . n . n . endTable() . n . n . '</form>' . n . '</div>';
}
Example #5
0
function advanced_prefs($message = '')
{
    global $textarray;
    #this means new language strings and new help entries
    echo pagetop(gTxt('advanced_preferences'), $message), '<form action="index.php" method="post">', startTable('list'), tr(tdcs(hed(gTxt('advanced_preferences'), 1), 3)), tr(tdcs(sLink('prefs', 'prefs_list', gTxt('site_prefs'), 'navlink') . sp . sLink('prefs', 'list_languages', gTxt('manage_languages'), 'navlink'), '3'));
    $rs = safe_rows_start('*', 'txp_prefs', "type='1' AND prefs_id='1' ORDER BY event,position");
    $cur_evt = '';
    while ($a = nextRow($rs)) {
        if ($a['event'] != $cur_evt) {
            $cur_evt = $a['event'];
            echo tr(tdcs(hed(gTxt($a['event']), 1), 3));
        }
        $out = tda(gTxt($a['name']), ' style="text-align:right;vertical-align:middle"');
        if ($a['html'] == 'text_input') {
            $size = $a['name'] == 'expire_logs_after' || $a['name'] == 'max_url_len' || $a['name'] == 'time_offset' || $a['name'] == 'rss_how_many' || $a['name'] == 'logs_expire' ? 3 : 20;
            $out .= td(pref_func('text_input', $a['name'], $a['val'], $size));
        } else {
            if (is_callable($a['html'])) {
                $out .= td(pref_func($a['html'], $a['name'], $a['val']));
            } else {
                $out .= td($a['val']);
            }
        }
        $out .= tda(popHelp($a['name']), ' style="vertical-align:middle"');
        echo tr($out);
    }
    echo tr(tda(fInput('submit', 'Submit', gTxt('save_button'), 'publish'), ' colspan="3" class="noline"')), endTable(), sInput('advanced_prefs_save'), eInput('prefs'), hInput('prefs_id', "1"), hInput('lastmod', "now()"), '</form>';
}
Example #6
0
function advanced_prefs($message = '')
{
    echo pagetop(gTxt('advanced_preferences'), $message) . n . '<h1 class="txp-heading">' . gTxt('tab_preferences') . '</h1>' . n . '<div id="prefs_container" class="txp-container">' . n . n . '<form method="post" class="prefs-form advanced" action="index.php">' . n . '<p class="nav-tertiary">' . sLink('prefs', 'prefs_list', gTxt('site_prefs'), 'navlink') . sLink('prefs', 'advanced_prefs', gTxt('advanced_preferences'), 'navlink-active') . sLink('prefs', 'list_languages', gTxt('manage_languages'), 'navlink') . n . '</p>' . n . n . startTable('', '', 'txp-list') . '<tbody>';
    $rs = safe_rows_start('*', 'txp_prefs', "type = 1 and prefs_id = 1 order by event, position");
    $cur_evt = '';
    while ($a = nextRow($rs)) {
        $headingPopHelp = strpos($a['name'], 'custom_') !== false;
        if ($a['event'] != $cur_evt) {
            $cur_evt = $a['event'];
            echo n . n . tr(tdcs(hed(gTxt($a['event']) . ($headingPopHelp ? n . popHelp($a['name']) : ''), 3, ' class="' . $a['event'] . '-prefs"'), 2), ' class="pref-heading"');
        }
        $label = !in_array($a['html'], array('yesnoradio', 'is_dst')) ? '<label for="' . $a['name'] . '">' . gTxt($a['name']) . '</label>' : gTxt($a['name']);
        $out = tda($label . ($headingPopHelp ? '' : n . popHelp($a['name'])), ' class="pref-label"');
        if ($a['html'] == 'text_input') {
            $look_for = array('expire_logs_after', 'max_url_len', 'time_offset', 'rss_how_many', 'logs_expire');
            $size = in_array($a['name'], $look_for) ? INPUT_XSMALL : INPUT_REGULAR;
            $out .= td(pref_func('text_input', $a['name'], $a['val'], $size), '', 'pref-value');
        } else {
            $out .= td(pref_func($a['html'], $a['name'], $a['val']), '', 'pref-value');
        }
        echo n . n . tr($out, " id='prefs-{$a['name']}' class='{$a['event']}-prefs'");
    }
    echo n . '</tbody>' . n . endTable() . graf(fInput('submit', 'Submit', gTxt('save'), 'publish') . n . sInput('advanced_prefs_save') . n . eInput('prefs') . n . hInput('prefs_id', '1') . n . tInput()) . n . n . '</form>' . n . '</div>';
}
 function main()
 {
     // Make txp_prefs.php happy :)
     global $event;
     $event = $this->parent->event;
     include_once txpath . '/include/txp_prefs.php';
     echo '<form action="index.php" method="post">', startTable('list');
     foreach ($this->parent->preferences as $key => $pref) {
         extract($pref);
         $out = tda(gTxt($key), ' style="text-align:right;vertical-align:middle"');
         switch ($type) {
             case 'text_input':
                 $out .= td(pref_func('text_input', $key, $value, 20));
                 break;
             default:
                 if (is_callable(array(&$this->parent, $type))) {
                     $out .= td(call_user_func(array(&$this->parent, $type), 'ui_in', $value, $key));
                 } else {
                     $out .= td(pref_func($type, $key, $value, 50));
                 }
                 break;
         }
         $out .= tda($this->popHelp($key), ' style="vertical-align:middle"');
         echo tr($out);
     }
     echo tr(tda(fInput('submit', 'Submit', gTxt('save_button'), 'publish'), ' colspan="3" class="noline"')), endTable(), $this->parent->form_inputs(), sInput('prefs_save'), '</form>';
 }