~~NOCACHE~~ error_reporting(E_ERROR|E_PARSE); global $pages, $meta, $namespaces, $prefixes, $adminsonly, $options, $optionsearch, $allchars, $allwords, $allcounter, $tagfiles, $tagdb, $foundwithtag, $namespaces_publicnames; $options='sdt'; $url=urldecode($_SERVER['QUERY_STRING']); $url=str_replace('id=vickysearch', '', $url); $url=ltrim($url, '&'); $url=str_replace('lattilad.org/', '', $url); $url=str_replace('kereses=', '', $url); echo '
A kereső használati utasítása

 
'; if($url=='') return; $pages='data/pages/'; $meta='data/meta/'; $namespaces=array( ''=>'blog', 'b'=>'blog', 'k'=>'konyvtar,kissy,login,tv-basic', 't'=>'talema/blog', 'z'=>'blog,talema/blog', ); $namespaces_publicnames=array( '*'=>'mindenhol', ''=>'LAttilaD-blog', 'blog'=>'LAttilaD-blog', 'konyvtar'=>'Könyvtár', 'kissy'=>'Kissy', 'login'=>'Login', 'tv-basic'=>'TV–BASIC', 'talema/blog'=>'Talema-blog', ); $tagfiles=array( 'blog'=>'blogtags.array', 'talema/blog'=>'talematags.array', ); $prefixes=array( '>'=>'Tag', '<'=>'Tag Exact', '?'=>'Fulltext', '$'=>'Filename', '~'=>'Date', '!'=>'Not', '%'=>'Sensitive', '@'=>'Regexp', '='=>'Option', '&'=>'Additionally', ); $adminsonly=array( 'szupervizio', ); lattiladorgsearch($url); function lattiladorgsearch($url) { global $foundlist, $counthits; $url=urldecode($url); $conditions=createsearcharray($url); foreach($conditions as $condition) if($condition!='') { searchcondition($condition); $counthits[]=count($foundlist); } if(is_array($foundlist)) echo result($foundlist); else echo 'Nincs találat.'; echo '
'; listconditions($conditions); echo '
'.htmlentities($url).'

'; } function listconditions($cond) { global $namespaces_publicnames, $options, $counthits; $cns=array(); foreach((array) $cond[0]['ns'] as $ns) if(isset($namespaces_publicnames[$ns])) $cns[]=$namespaces_publicnames[$ns]; else $cns[]=$ns; echo (count($cond[0]['ns'])>1?'Névterek: '.implode(', ', $cns):'Névtér: '.implode('', $cns)).'
'; foreach($cond as $c) { echo ''.++$counter.'. '; $type=''; if(cmd($c, 'Additionally')!==false) echo 'vagy pedig '; if(cmd($c, 'Fulltext')!==false) $type='a teljes szövegben'; if(cmd($c, 'Filename')!==false) $type='a file-nevekben'; if(cmd($c, 'Date')!==false) $type='a dátumokban'; if(cmd($c, 'Tag')!==false) { if(cmd($c, 'Exact')===false) $type='a címkék részeként'; else $type='a címkék között'; } if($type=='') $type='a címekben'; echo $type.(cmd($c, 'Not')!==false?' ne ':'').' szerepeljen '; echo (cmd($c, 'Sensitive')!==false?' (esetérzékenyen) ':''); echo '„'.$c['text'].'”'; echo (cmd($c, 'Regexp')!==false?' (reguláris kifejezés)':''); echo ($counter>1?'. Eddig összesen ':'. ').$counthits[$counter-1].' találat.'; echo '
'; } if($options!='') { echo 'Opciók: '; $op=array(); if(strpos($options, 'c')!==false) $op[]='szövegrészszámlálás'; if(strpos($options, 's')!==false) $op[]='méretstatisztika'; if(strpos($options, 'd')!==false) $op[]='dátumkiírás'; if(strpos($options, 't')!==false) $op[]='címkekiírás'; echo implode(', ', $op).'
'; } } function searchcondition($cond) { global $foundlist; extract($cond); if(!is_array($foundlist)) $foundlist=readnamespace($cond); elseif(cmd($cond, 'Additionally')!==false) $foundlist=array_unique(array_merge($foundlist, readnamespace($cond))); if($text=='*') return $foundlist; if(is_array($foundlist)) foreach($foundlist as $fileindex=>$file) if(!checkfile($cond, $file)) unset($foundlist[$fileindex]); return $foundlist; } function checkfile($cond, $file) { global $pages; $text=file_get_contents($pages.$file); if(cmd($cond, 'Filename')) if(spos($file, $cond)!==false) return true; if(cmd($cond, 'Fulltext')) if(spos(file_get_contents($pages.$file), $cond)!==false) return true; if(cmd($cond, 'Title')) if(spos(gettitle($file), $cond)!==false) return true; if(cmd($cond, 'Date')) if(pagedate($file, $cond)!==false) return true; if(cmd($cond, 'Tag')) { $t=(tag($file, $cond)!==false); if(cmd($cond, 'Not')!==false) return !$t; else return $t; } return false; } function tag($file, $cond) { global $tagdb, $foundwithtag; $fid=strtr($file, array('/'=>':', '.txt'=>'')); $tx=deac(strtolower($cond['text'])); foreach($tagdb as $subtagdb) { foreach($subtagdb as $ky=>$t) { $found=false; if(cmd($cond, 'Exact')) if(strtolower($ky)==$tx) $found=true; else; else if(strpos(strtolower($ky), $tx)!==false) $found=true; if($found) foreach($t as $tf) if($tf['link']==$fid) { if(!in_array($ky, $foundwithtag[$tf['link']])) $foundwithtag[$tf['link']][]=$ky; return true; } } } return false; } function loadtagdb($cond) { global $tagfiles, $pages, $tagdb; $tagfile=$tagfiles[$cond['ns']]; $t=unserialize(file_get_contents($pages.$tagfile)); $tagdb[]=$t; } function pagedate($file, $cond) { $date=$cond['text']; preg_match_all('/y\d{1,4}/', $date, $year); preg_match_all('/m\d{1,2}/', $date, $month); preg_match_all('/d\d{1,2}/', $date, $day); preg_match_all('/w\d{1}/', $date, $week); $year=substr($year[0][0], 1); $month=substr($month[0][0], 1); $month++; $month--; $day=substr($day[0][0], 1); $day++; $day--; $week=substr($week[0][0], 1); $ar=array_filter(array($year, $month, $day, $week)); $meta = p_get_metadata(str_replace('.txt', '', $file), '', false); $date=$meta['date']['created']; if(count($ar)==1) if($year==date('Y', $date) ||$month==date('n', $date) ||$day==date('j', $date) ||$week==date('N', $date)) return true; else; else { if( ($year!=''&&$year!=date('Y', $date)) ||($month!=''&&$month!=date('n', $date)) ||($day!=''&&$day!=date('j', $date)) ||($week!=''&&$week!=date('N', $date)) ) return false; return true; } return false; } function gettitle($file) { global $meta; $file=str_replace('.txt', '.meta', $file); $data=unserialize(file_get_contents($meta.$file)); return $data['current']['title']; } function readnamespace($cond) { $files=array(); if(is_array($cond['ns'])) foreach($cond['ns'] as $ns) $files=array_merge($files, readsinglenamespace($ns)); else $files=readsinglenamespace($cond['ns']); return $files; } function readsinglenamespace($ns) { global $pages, $namespaces; $ns=str_replace('.', '/', $ns); if(substr($ns, -1, 1)=='*') { if($ns=='*') { $dirs=nsprefix('', glob_recursive($pages.'*', GLOB_ONLYDIR)); sort($dirs); } else { $nd=explode('/', $ns); $dirs=glob_recursive($pages.$nd[0].'/*', GLOB_ONLYDIR); sort($dirs); } $files=array(); foreach($dirs as $ns) { $sc=array_diff(scandir($ns), array('.', '..')); if(count($sc)>0) $files=array_merge($files, nsprefix($ns, $sc)); } } else $files=nsprefix($ns, array_diff(scandir($pages.$ns), array('.', '..'))); return $files; } function nsprefix($ns, $arr) { global $pages; if($ns!='') foreach($arr as $a) $r[]=ltrim(str_replace($pages, '', $ns.'/'.$a), '/'); else foreach($arr as $a) $r[]=$a; return $r; } function spos($text, $cond) { if(cmd($cond, 'Regexp')) $s=!!preg_match('/'.$cond['text'].'/'.(cmd($cond, 'Sensitive')?'':'i'), $text); else if(cmd($cond, 'Sensitive')) $s=strpos($text, $cond['text']); else $s=stripos($text, $cond['text']); if(cmd($cond, 'Not')) $s=!$s; return $s; } function cmd($cond, $cmd) { return strpos($cond['cmd'], $cmd); } function glob_recursive($pattern, $flags = 0) { $files = glob($pattern, $flags); foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) { $files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags)); } return $files; } function authorize($l) { global $INPUT, $USERINFO, $adminsonly; $user=$INPUT->server->str('REMOTE_USER'); if(is_array($USERINFO)) $admin=in_array('admin', $USERINFO['grps']); foreach($l as $id) { $oid=$id; list($ns)=explode('/', $id); if(in_array($ns, $adminsonly)) if(!$admin) continue; $id=urldecode(str_replace('.txt', '', $id)); $id=str_replace('/', ':', $id); $a=auth_aclcheck_cb(array('id'=>$id, 'user'=>$user, 'groups'=>$USERINFO['grps'])); if($a) $r[]=$oid; } return $r; } function createsearcharray($url) { global $namespaces, $prefixes, $options; $u=explode('/', $url); foreach($u as $cond) { $c=array(); $c['text']=$cond; $repeat=true; while($repeat) { if(isset($prefixes[substr($c['text'], 0, 1)])) { $c['cmd'].=' '.$prefixes[substr($c['text'], 0, 1)]; $c['text']=substr($c['text'], 1); } else { $repeat=false; } } if(strpos($c['text'], ':')) { list($c['ns'], $c['text'])=explode(':', $c['text']); if(isset($namespaces[$c['ns']])) $c['ns']=$namespaces[$c['ns']]; if(strpos($c['ns'], ',')) $c['ns']=explode(',', $c['ns']); if($c['text']=='') $c['text']='*'; } if(cmd($c, 'Filename')===false &&cmd($c, 'Tag')===false &&cmd($c, 'Fulltext')===false &&cmd($c, 'Option')===false) $c['cmd'].=' Title'; if(cmd($c, 'Filename')) $c['text']=str_replace(' ', '_', $c['text']); if(!isset($c['ns'])) $c['ns']='blog'; if(cmd($c, 'Tag')) loadtagdb($c); if(cmd($c, 'Option')) $options=$c['text']; else $conditions[]=$c; } return $conditions; } function option($id, $link) { global $options, $optionsearch, $pages, $allchars, $allwords, $allcounter, $foundwithtag; if(strpos($options, 'c')!==false ||strpos($options, 's')!==false ) $text=file_get_contents($pages.str_replace(':', '/', $id).'.txt'); if(strpos($options, 'c')!==false) { preg_match('/c\[(.*?)\]/', $options, $pat); $optionsearch=$pat[1]; $count=substr_count(strtolower($text), strtolower($optionsearch)); $counter=' – '.num($count).' előfordulás'; $allcounter+=$count; } if(strpos($options, 'd')!==false) { $meta = p_get_metadata($id, '', false); $date=date('Y.n.j.', $meta['date']['created']).' '; } if(strpos($options, 's')!==false) { $chars=mb_strlen($text); $words=wordcount($text); $stats=' ('.num($words).' szó, '.num($chars).' betű)'; $allchars+=$chars; $allwords+=$words; } if(strpos($options, 't')!==false) if(isset($foundwithtag[$id])) $tag=' ←('.str_replace('_', ' ', implode(', ', $foundwithtag[$id])).')'; return $date.$link.$stats.$counter.$tag; } function wordcount($text) { $t=preg_split('/\s+/', $text); return count($t); } function num($n) { return number_format($n, 0, '', ' '); } function result($l) { global $options, $optionsearch, $allchars, $allwords, $allcounter; $l=authorize($l); sort($l); $header=count($l).' találat.'; if(count($l)<1) return; foreach($l as $link) { $id=str_replace('/', ':', $link); $id=str_replace('.txt', '', $id); list($ns)=explode(':', $id); if($ns!=$prevns) { $r.='
'.strtoupper($ns).'

'; $prevns=$ns; } $r.=option($id, ''.title($id).'').'
'; } if(strpos($options, 's')!==false) $header.=' Összesen '.num($allwords).' szó, '.num($allchars).' betű.'; if(strpos($options, 'c')!==false) $header.=' A keresett „'.$optionsearch.'” '.num($allcounter).' példányban fordul elő.'; return $header.'
'.$r; } function title($pid) { $meta = p_get_metadata($pid, '', false); if(isset($meta['title'])) return $meta['title']; global $ID; $meta = p_get_metadata($ID, '', false); if($meta['title']=='') { $meta=p_get_metadata(urldecode($pid), '', false); if(isset($meta['title'])) return $meta['title']; return '['.urldecode($pid).']'; } return $meta['title']; } function deac($t) { return mb_strtr($t, 'àáâãäāăåȧąćčĉċçđèéêëěēẽėęĝģğġǵǧĥħìíîïīįıĩĭǐĵķļłĺńňņñòóôõöőøōŏǫŕřŗśšŝşţŧùúûüūűųŭůŵýÿźžżæďľœťßþ', 'aaaaaaaaaacccccdeeeeeeeeegggggghhiiiiiiiiiijkllĺnnnnoooooooooorrrssssttuuuuuuuuuwyyzzzadlotst'); } /* function mb_strtr($str, $from, $to) { return str_replace(mb_str_split($from), mb_str_split($to), $str); } function mb_str_split($str) { return preg_split('~~u', $str, null, PREG_SPLIT_NO_EMPTY);; }*/