أسعد الله اوقاتكم بكل خير ..
انا قمت بعمل محرك بحث بسيط لقوالب الأستايلات لمنتدى الـ MySmartBB
بحيث يقوم بإظهار نتيجة البحث عن كلمة معينة وفي اي قالب تكون ونجحت والحمد لله ،،
لكن شكل النتيجة لم يعجبني ما انا بحاجة إليه
هو ظهور نتائج البحث بشكل افضل على هيئة جدول منسق
وإيضاً ارغب بإضافة تحرير وتعديل للقالب الذي تم ايجاد النص به
الكلاسس الكامل هو كالتالي :
<?php
class searchFileContents{
var $dir = '../styles';
var $search_phrase = '$_POST[T1]';
var $allowed_file_types = array('tpl');
var $foundFiles;
var $myfiles;
function search($directory, $search_phrase){
$this->dir = $directory;
$this->search_phrase = $search_phrase;
$this->myfiles = $this->GetDirContents($this->dir);
$this->foundFiles = array();
if ( empty($this->search_phrase) ) die('لم تقم بكتابة كلمة للبحث');
if ( empty($this->dir) ) die('You must select a directory to search');
foreach ( $this->myfiles as $f ){
if ( in_array(array_pop(explode ( '.', $f )), $this->allowed_file_types) ){
$contents = file_get_contents($f);
if ( strpos($contents, $this->search_phrase) !== false )
$this->foundFiles [] = $f;
}
}
return $this->foundFiles;
}
function GetDirContents($dir){
if (!is_dir($dir)){die ("Function GetDirContents: Problem reading : $dir!");}
if ($root=@opendir($dir)){
while ($file=readdir($root)){
if($file=="." || $file==".."){continue;}
if(is_dir($dir."/".$file)){
$files=array_merge($files,$this->GetDirContents($dir."/".$file));
}else{
$files[]=$dir."/".$file;
}
}
}
return $files;
}
}
//Example :
echo "<style type='text/css' media='all'>
@import url(../admin/style/css/style.css);
</style>";
echo "<br /><body bgcolor='#EEEEEE'><table dir='ltr' class='td' border='1' cellpadding='1' cellspacing='1' width='100%'><tr><td dir='ltr' valign='top'>";
$search = new searchFileContents;
$search->search('../styles', $_POST[T1]);
var_dump($search->foundFiles);
echo "</td></tr></table>";
?>وهذا الفورم المرتبط به :
<br /><br /><br /><p dir="rtl" align="center"><form method="POST" action="../includes/searchFileContents.php"> <table border="1" cellpadding="0" cellspacing="0" width="50%"><tr><td valign="top"> <p dir="rtl" align="center">البحث في القوالب : <textarea rows="5" name="T1" cols="60" dir="rtl" style="font-family: Tahoma; font-size: 10pt"></textarea> <br><input type="submit" value="ابحث" name="B1" style="font-family: Tahoma; font-size: 8pt"></p>
ظهور نتائج البحث يظهر بالشكل التالي طبعاً غير مرتب :
array(2) { [0]=> string(35) "../styles/main/templates/header.tpl" [1]=> string(36) "../styles/smart/templates/header.tpl" }احتاج إلى تنسيقة بشكل أفضل !
هل من مساعدة .. :wub: