if (@txpinterface == 'admin') { register_callback("smd_browse_by_image", "image"); register_callback("smd_browse_by_article", "list"); register_callback("smd_browse_by_file", "file"); register_callback("smd_browse_by_link", "link"); } function smd_browse_by_image($evt, $stp) { $smd_browse_by_form = form(smd_browse_dropdown('image', $evt), '', '', 'get'); smd_browse_by_js($smd_browse_by_form); } function smd_browse_by_article($evt, $stp) { $smd_browse_by_form = form(smd_browse_dropdown('article_cat', $evt), '', '', 'get') .form(smd_browse_dropdown('article_sec', $evt), '', '', 'get'); smd_browse_by_js($smd_browse_by_form); } function smd_browse_by_file($evt, $stp) { $smd_browse_by_form = form(smd_browse_dropdown('file', $evt), '', '', 'get'); smd_browse_by_js($smd_browse_by_form); } function smd_browse_by_link($evt, $stp) { $smd_browse_by_form = form(smd_browse_dropdown('link', $evt), '', '', 'get'); smd_browse_by_js($smd_browse_by_form); } // Common js to place each 'browse by' above each area's search form function smd_browse_by_js($content) { $out = doSlash($content); $js = << jQuery(document).ready(function() { jQuery(".search-form").before('
{$out}
'); }); EOC; echo $js; } function smd_browse_dropdown($type, $evt) { $browsable = array( 'article_cat' => array( 'by' => smd_browse_by_gTxt('by_cat'), 'table' => 'txp_category', 'where' => "type = 'article' AND name != 'root'", 'step' => 'list', 'meth' => 'categories', ), 'article_sec' => array( 'by' => smd_browse_by_gTxt('by_sec'), 'table' => 'txp_section', 'where' => "name != 'default'", 'step' => 'list', 'meth' => 'section', ), 'image' => array( 'by' => smd_browse_by_gTxt('by_cat'), 'table' => 'txp_category', 'where' => "type = 'image' AND name != 'root'", 'step' => 'image_list', 'meth' => 'category', ), 'file' => array( 'by' => smd_browse_by_gTxt('by_cat'), 'table' => 'txp_category', 'where' => "type = 'file' AND name != 'root'", 'step' => 'file_list', 'meth' => 'category', ), 'link' => array( 'by' => smd_browse_by_gTxt('by_cat'), 'table' => 'txp_category', 'where' => "type = 'link' AND name != 'root'", 'step' => 'link_edit', 'meth' => 'category', ), ); if (isset($browsable[$type])) { $entry = $browsable[$type]; $section_cat = safe_rows('name, title', $entry['table'], $entry['where']); $sel = array(); foreach ($section_cat as $row) { $sel[$row['name']] = $row['title']; } if ($sel) { $use_go = get_pref('smd_browse_by_go_button', 0); return $entry['by'] . sp . selectInput('crit', $sel, gps('crit'), true, (($use_go) ? false : true) ) . (($use_go) ? fInput('submit', '', gTxt('go'), 'smallerbox') : '') . hInput('event', $evt) . hInput('step', $entry['step']) . hInput('search_method', $entry['meth']); } } return false; } // ------------------------ // Plugin-specific replacement strings - localise as required function smd_browse_by_gTxt($what, $atts = array()) { $lang = array( 'by_cat' => 'Browse by Category:', 'by_sec' => 'Browse by Section:', ); return strtr($lang[$what], $atts); }