// ------------------------------------------------------------- if (@txpinterface == 'admin') { add_privs('smd_wu','1,2'); // Extensions tab register_tab('extensions', 'smd_wu', smd_wu_gTxt('smd_wu')); register_callback('smd_wu', 'smd_wu'); } // ------------------------------------------------------------- function smd_wu($event, $step) { if(!$step or !in_array($step, array( 'smd_wu_search', ))) { smd_wu_showform(''); } else $step(); } // ------------------------------------------------------------- function smd_wu_showform($message, $term='', $sel=array(), $incl=0, $whole=0) { pagetop(smd_wu_gTxt('smd_wu'),$message); $btnSearch = fInput('submit', 'smd_wu_search', gTxt('search'), 'smallerbox').sInput('smd_wu_search'); $btnStyle = ' style="border:0;height:25px"'; $place = array('sections','pages','forms','articles'); $sel = (empty($sel)) ? $place : $sel; echo '
'; echo startTable('list'); echo tr(fLabelCell(smd_wu_gTxt('search_lbl')) . tdcs(fInput('text', 'search_for', stripslashes($term), '', '', '', 30), 4) . tda($btnSearch, $btnStyle)); echo tr(td(smd_wu_gTxt('filter')).tdcs(radio('meth',0,(($incl==0)?1:0)).smd_wu_gTxt('inclusion')." " . radio('meth',1,(($incl==1)?1:0)).smd_wu_gTxt('exclusion'). " | " . smd_wu_gTxt('whole_word').checkbox('whole', 1, (($whole==1)?1:0)), 4)); $out = ''; foreach ($place as $here) { $out .= fLabelCell(gTxt($here) . checkbox('places[]', $here, in_array($here,$sel))); } echo tr(fLabelCell(smd_wu_gTxt('search_where_lbl')) . $out); echo endTable(); echo '
'; } // ------------------------------------------------------------- function smd_wu_search() { extract(doSlash(gpsa(array('search_for')))); $whole = gps('whole'); $meth = gps('meth'); // 0 = include, 1 = exclude $joinme = ($meth == 0) ? " OR " : " AND "; $places = gps('places'); $places = is_array($places) ? $places : array(); smd_wu_showform('', $search_for, $places, $meth, $whole); // Entries in this array are: // Table to search // Column to search // Column to return // Heading to display if results found // Event of destination URL // Step of destination URL // Additional URL var // Additional URL var replacement $placeTable = array( 'pages' => array('txp_page', 'user_html', 'name', gTxt('pages'), 'page', '', 'name', '{name}'), 'forms' => array('txp_form', 'form', 'name', gTxt('forms'), 'form', 'form_edit', 'name', '{name}'), 'articles' => array('textpattern', 'Body,Excerpt,override_form,section', 'ID,title', gTxt('articles'), 'article', 'edit', 'ID', '{ID}'), 'sections' => array('txp_section', 'page,css', 'name', gTxt('sections'), 'section', '', '#', 'section-{name}'), ); $rs = array(); echo startTable('list'); echo tr(tdcs(tag(gTxt('search_results'), 'h3'), 3)); $colHead = array(); $colBody = array(); if ($search_for) { foreach ($places as $place) { $crow = $placeTable[$place]; $where = array(); $witems = do_list($crow[1]); $list = do_list($crow[2]); foreach ($witems as $item) { $where[] = $item . (($meth==1) ? ' NOT' : '') . (($whole==1) ? ' REGEXP \'[[:<:]]'.$search_for.'[[:>:]]\'' : " LIKE '%$search_for%'"); } $rs = safe_rows($crow[2], $crow[0], '('.join($joinme, $where).') ORDER BY '.$list[0]); $colHead[] = td(strong($crow[3])); if ($rs) { $out = ''; $out .= ''; $colBody[] = td($out); } else { $colBody[] = td(gTxt('no_results_found')); } } echo tr(join(" ", $colHead)); echo tr(join(" ", $colBody)); } echo endTable(); } // ------------------------------------------------------------- // Plugin-specific replacement strings - localise as required // ------------------------------------------------------------- function smd_wu_gTxt($what, $atts = array()) { $lang = array( 'exclusion' => 'Exclude', 'inclusion' => 'Include', 'filter' => 'Filter:', 'search_lbl' => 'Find:', 'search_where_lbl' => 'Look in:', 'smd_wu' => 'Where used', 'whole_word' => 'Whole words', ); return strtr($lang[$what], $atts); }