plugins/SpecialPageFuncs.php
changeset 581 5e8fd89c02ea
parent 564 a1c450a911a6
child 588 20484deb89cd
equal deleted inserted replaced
580:41c45314ac27 581:5e8fd89c02ea
    62       ));
    62       ));
    63     
    63     
    64     $paths->add_page(Array(
    64     $paths->add_page(Array(
    65       \'name\'=>\'specialpage_tag_cloud\',
    65       \'name\'=>\'specialpage_tag_cloud\',
    66       \'urlname\'=>\'TagCloud\',
    66       \'urlname\'=>\'TagCloud\',
       
    67       \'namespace\'=>\'Special\',
       
    68       \'special\'=>0,\'visible\'=>1,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\',
       
    69       ));
       
    70     
       
    71     $paths->add_page(Array(
       
    72       \'name\'=>\'specialpage_autofill\',
       
    73       \'urlname\'=>\'Autofill\',
    67       \'namespace\'=>\'Special\',
    74       \'namespace\'=>\'Special\',
    68       \'special\'=>0,\'visible\'=>1,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\',
    75       \'special\'=>0,\'visible\'=>1,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\',
    69       ));
    76       ));
    70     ');
    77     ');
    71 
    78 
   826   $template->sidebar_widget($lang->get('pagetools_tagcloud_sidebar_title'), "<div style='padding: 5px;'>$sb_html</div>");
   833   $template->sidebar_widget($lang->get('pagetools_tagcloud_sidebar_title'), "<div style='padding: 5px;'>$sb_html</div>");
   827 }
   834 }
   828 
   835 
   829 $plugins->attachHook('compile_template', 'sidebar_add_tag_cloud();');
   836 $plugins->attachHook('compile_template', 'sidebar_add_tag_cloud();');
   830 
   837 
       
   838 function page_Special_Autofill()
       
   839 {
       
   840   global $db, $session, $paths, $template, $plugins; // Common objects
       
   841   global $lang;
       
   842   
       
   843   header('Content-type: text/javascript');
       
   844   
       
   845   $dataset = array();
       
   846   if ( isset($_GET['type']) )
       
   847   {
       
   848     switch($_GET['type'])
       
   849     {
       
   850       case 'username':
       
   851         if ( isset($_GET['userinput']) && strlen($_GET['userinput']) >= 3 )
       
   852         {
       
   853           $search = '%' . escape_string_like($_GET['userinput']) . '%';
       
   854           $q = $db->sql_query('SELECT username FROM ' . table_prefix . "users WHERE " . ENANO_SQLFUNC_LOWERCASE . "(username) LIKE '$search' AND user_id > 1");
       
   855           if ( !$q )
       
   856             $db->die_json();
       
   857           
       
   858           while ( $row = $db->fetchrow() )
       
   859           {
       
   860             $key = array(
       
   861               'name' => $row['username'],
       
   862               'name_highlight' => highlight_term($_GET['userinput'], $row['username'], '<b>', '</b>')
       
   863             );
       
   864             $key = array_merge($key, $session->get_user_rank($row['username']));
       
   865             $key['rank_title'] = $lang->get($key['rank_title']);
       
   866             $dataset[] = $key;
       
   867           }
       
   868         }
       
   869         break;
       
   870       case 'page':
       
   871         if ( isset($_GET['userinput']) && strlen($_GET['userinput']) >= 3 )
       
   872         {
       
   873           $search = '%' . escape_string_like($_GET['userinput']) . '%';
       
   874           $q = $db->sql_query('SELECT urlname, namespace, name FROM ' . table_prefix . "users\n"
       
   875                             . "  WHERE (\n"
       
   876                             . "       " . ENANO_SQLFUNC_LOWERCASE . "(urlname) LIKE '$search'\n"
       
   877                             . "    OR " . ENANO_SQLFUNC_LOWERCASE . "(name)    LIKE '$search'\n"
       
   878                             . "  ) AND user_id > 1");
       
   879           if ( !$q )
       
   880             $db->die_json();
       
   881           
       
   882           while ( $row = $db->fetchrow() )
       
   883           {
       
   884             $pathskey = ( isset($paths->nslist[$row['namespace']]) ? $paths->nslist[$row['namespace']] : $row['namespace'] . substr($paths->nslist['Special'], -1) ) . $row['urlname'];
       
   885             $key = array(
       
   886               'page_id' => $pathskey,
       
   887               'pid_highlight'  => highlight_term($_GET['userinput'], dirtify_page_id($pathskey), '<b>', '</b>'),
       
   888               'name_highlight' => highlight_term($_GET['userinput'], $row['name'], '<b>', '</b>')
       
   889             );
       
   890             $dataset[] = $key;
       
   891           }
       
   892         }
       
   893         break;
       
   894       default:
       
   895         $code = $plugins->setHook('autofill_json_request');
       
   896         foreach ( $code as $cmd )
       
   897         {
       
   898           eval($cmd);
       
   899         }
       
   900         break;
       
   901     }
       
   902   }
       
   903   
       
   904   echo enano_json_encode($dataset);
       
   905 }
       
   906 
   831 ?>
   907 ?>