سوالف اندرويد




العودة   سوالف سوفت > سوالف برمجة المواقع وتطويرها > PHP
التسجيل المدوّنات البحث مشاركات اليوم جعل الأقسام مقروءة

الوسوم:

الرد على الموضوع
 
LinkBack أدوات الموضوع
عضو سوبر نشيط
#1  
نظام قوالب جديد من برمجتي

برمجت محرك قوالب بسيط تبعا لدروس استاذي ضيف الله العتيبي واستاذي حازم علي

للسكربتات الصغيرة والحجم صغير جدا 3 كيلو بايت ::

الكلاس

كود PHP:
   <?php
    
class template{
        var 
$files        = array();
        var 
$vars;
        var 
$fid;
        var 
$temp_dir;
        var 
$cache_dir;
    
//Function to load a template file.


    //Function to parse the Template Tags
        
function parse(){
//Foreach Statement
$this->files[$this->fid] = preg_replace("'<LOOP NAME=\"(.+)\">'i","<? foreach(\$this->vars[\\1] as \$key=>\$var){ ?>",$this->files[$this->fid]);
$this->files[$this->fid] = preg_replace("'</LOOP>'i","<? } ?>",$this->files[$this->fid]);
//Include Statement
$this->files[$this->fid] = preg_replace("'<INCLUDE FILENAME=\"(.+)\">'i","<? include(\"\\1\"); ?>",$this->files[$this->fid]);
//Foreach Variables
$this->files[$this->fid] = preg_replace("'{{(.+)}}'","<?= \$var[\\1]?>",$this->files[$this->fid]);
//Variables
$this->files[$this->fid] = preg_replace("'{(.+)}'","<?= \$this->vars[\\1]?>",$this->files[$this->fid]);
$this->files[$this->fid] = preg_replace("'<else>'","<? else{ ?>",$this->files[$this->fid]);
$this->files[$this->fid]= preg_replace('/\<if condtion\=\"(.*)\\ (.*)\\ (.*)\">/','<?if($GLOBALS[$1]$2$3){?>',$this->files[$this->fid]);
$this->files[$this->fid]= preg_replace('/\<\/if\>/','<?}?>',$this->files[$this->fid]);
$this->files[$this->fid] = preg_replace('/(<ELSE>|<ELSE \/>)/i','<? }else{ ?>',$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("neq","!=",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("eq","==",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("neq","!=",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("gt",">",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("lt","<",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("and","&&",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("orrrr","||",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("not","!",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("mod","%",$this->files[$this->fid]);

}
    
//Function to OUTPUT
        
function print_temp($filename) {
$this->fid "$this->cache_dir/$filename.php";
            
$this->files[$this->fid] = file_get_contents("$this->temp_dir/$filename");

            
$this->vars = &$GLOBALS;
            
$this->parse();
            
$fp fopen($this->fid,"w");
            
fwrite($fp,$this->files[$this->fid]);
            
fclose($fp);
            include(
$this->fid);
        }

    }
?>
طريقة الاستخدام


تعريف الكلاس
كود PHP:
 $tpl = new template;
    
$tpl->temp_dir      'templates'
    
$tpl->cache_dir      's'
templates هو مجلد القوالب
sهو مجلد الكاش

لطباعة التمبلت
كود PHP:
$tpl->print_temp('template1.html'); 
مع العلم ان template1.html
هو القالب الموجود بملف القوالب
القالب يدعم الاشارة الشرطية التضمين التكرار

ساشرحها لاحقا

اي افكار برمجية للقالب انا جاهز
يجب اعطاء ملف الكلاس التصريح 777
ويجب اعطاء الملف الذي تعرض به القالب التصريح 777
تحياتي






exchangeboss is offline   قديم 27-07-2008, 08:23 PM
الرد مع إقتباس
عضو نشيط جدا
#2  

اهلا عزيزي ...

النظام جيد .. وجيد تعني عندي ممتاز ..

لكن هناك شي احببت قوله ..

- في preg_replace تستطيع استخدام مصفوفه بدل ان تقوم باعادتها كذا مره ..
- لما استخدمت الاستبدال العام لكل الملف في دالة str_replace , يعني ان مثلا : يستبدل أي حرفين eq في الملف ...

- دالة str_replace ابطئ من preg_replace قم باستخدام الثانيه ..
- مافائده المتغير $files .. لما تريد ان تحتفظ بالمحتويات حتى بعد ظهور الصفحه وطباعتها .. اعتقد انه لافائده منه .. اكل للذاكره بلا فائده ..

- في النهايه قلت انه يجب ان نعطي مجلد كذا وكذا التصاريح .. لماذا لاتقوم انت بالكلاس بالتأكد وطبع جمله التأكد ..
- لما لا ترجع القيمة .. وتزيل دالة انكلود والكتابه لملف ... لانك تستخدم الكاش كاسم بلافائده ..كما ارى ..

- الكود غير مرتب .. استخدم التاب .. لامانع من ذلك ..


دمت بود






__________________
إلى اللقاء سوالف , وآسف على الإزعاج...
moffed.com , kleeja.com/tour/ar ,phpbbarabia.com
saanina is offline   قديم 27-07-2008, 09:49 PM
الرد مع إقتباس
عضو سوبر نشيط
#3  

إقتباس:
المشاركة الأصلية بواسطة saanina مشاهدة مشاركة
اهلا عزيزي ...

النظام جيد .. وجيد تعني عندي ممتاز ..

لكن هناك شي احببت قوله ..

- في preg_replace تستطيع استخدام مصفوفه بدل ان تقوم باعادتها كذا مره ..
- لما استخدمت الاستبدال العام لكل الملف في دالة str_replace , يعني ان مثلا : يستبدل أي حرفين eq في الملف ...

- دالة str_replace ابطئ من preg_replace قم باستخدام الثانيه ..
- مافائده المتغير $files .. لما تريد ان تحتفظ بالمحتويات حتى بعد ظهور الصفحه وطباعتها .. اعتقد انه لافائده منه .. اكل للذاكره بلا فائده ..

- في النهايه قلت انه يجب ان نعطي مجلد كذا وكذا التصاريح .. لماذا لاتقوم انت بالكلاس بالتأكد وطبع جمله التأكد ..
- لما لا ترجع القيمة .. وتزيل دالة انكلود والكتابه لملف ... لانك تستخدم الكاش كاسم بلافائده ..كما ارى ..

- الكود غير مرتب .. استخدم التاب .. لامانع من ذلك ..


دمت بود

يا هلا استذاي sannia
شرفني مرورك بالنسبة للمتغير كنت ناسي

ساحذفه واعدل الموضوع


في preg_replace تستطيع استخدام مصفوفه بدل ان تقوم باعادتها كذا مره ..

لم افهم هذه النقطة
اعذرني اخوك جديد بال OOP


- في النهايه قلت انه يجب ان نعطي مجلد كذا وكذا التصاريح .. لماذا لاتقوم انت بالكلاس بالتأكد وطبع جمله التأكد ..
- لما لا ترجع القيمة .. وتزيل دالة انكلود والكتابه لملف ... لانك تستخدم الكاش كاسم بلافائده ..كما ارى ..

هاذي لم افهم كيف بصراحه ارجو شرحها فانا لا زلت مبتدئ :bad:






exchangeboss is offline   قديم 27-07-2008, 10:21 PM
الرد مع إقتباس
عضو نشيط جدا
#4  

اهلين مره ثانيه ..

preg_replace تقبل المصفوفات
زي كذا

كود:
$var = preg_replace(array(..., ..., ...), array(..., ...., ...), $var);
ايضا عشان تعرف المجلد ينكتب فيه او لا
كود:
 if (!is_writeable($this->cache_dir))
{
 ....
}
اما نقطه الارجاع اقصد كذا ..

كود:
function print_temp($filename) 
{ 
    ...
    ...
$this->parse(); 
    return $this->fid;
} 
ليه ؟ لانك اصلا لاتستحدم الكاش جيدا .. فكل مره تقوم باعادة الكتابه له .. وهذا لايعتبر كاش .. يعتبر دوره لا فائده منها .. إما ان تستخدم الكاش .. او ترجع القيمه والسلام ..

دمت بود






__________________
إلى اللقاء سوالف , وآسف على الإزعاج...
moffed.com , kleeja.com/tour/ar ,phpbbarabia.com
saanina is offline   قديم 27-07-2008, 10:55 PM
الرد مع إقتباس
عضو سوبر نشيط
#5  

استاذي سانيا استخدمت الكاش ولكن يكتب اذا كان هناك تغييرات
ما رايك
كود PHP:
   <?php
    
class template{
               
        var 
$vars;
        var 
$fid;
        var 
$temp_dir;
        var 
$cache_dir;
    
//Function to load a template file.


    //Function to parse the Template Tags
        
function parse(){
//Foreach Statement
$this->files[$this->fid] = preg_replace("'<LOOP NAME=\"(.+)\">'i","<? foreach(\$this->vars[\\1] as \$key=>\$var){ ?>",$this->files[$this->fid]);
$this->files[$this->fid] = preg_replace("'</LOOP>'i","<? } ?>",$this->files[$this->fid]);
//Include Statement
$this->files[$this->fid] = preg_replace("'<INCLUDE FILENAME=\"(.+)\">'i","<? include(\"\\1\"); ?>",$this->files[$this->fid]);
//Foreach Variables
$this->files[$this->fid] = preg_replace("'{{(.+)}}'","<?= \$var[\\1]?>",$this->files[$this->fid]);
//Variables
$this->files[$this->fid] = preg_replace("'{(.+)}'","<?= \$this->vars[\\1]?>",$this->files[$this->fid]);
$this->files[$this->fid] = preg_replace("'<else>'","<? else{ ?>",$this->files[$this->fid]);
$this->files[$this->fid]= preg_replace('/\<if condtion\=\"(.*)\\ (.*)\\ (.*)\">/','<?if($GLOBALS[$1]$2$3){?>',$this->files[$this->fid]);
$this->files[$this->fid]= preg_replace('/\<\/if\>/','<?}?>',$this->files[$this->fid]);
$this->files[$this->fid] = preg_replace('/(<ELSE>|<ELSE \/>)/i','<? }else{ ?>',$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("neq","!=",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("eq","==",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("neq","!=",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("gt",">",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("lt","<",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("and","&&",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("orrrr","||",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("not","!",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("mod","%",$this->files[$this->fid]);
return
$this->files[$this->fid];
}
  FUNCTION 
check_output($file)
  {
          if( 
file_exists($file))
           {
              
$check = @fopen("$file",r);
              
$r     = @fread($check,filesize("$file"));
              @
fclose($check);

           }
         return  
$r;

  }
    
//Function to OUTPUT
        
function print_temp($filename) {
$this->fid "$this->cache_dir/$filename.php";
$this->parse();
$this->files[$this->fid] = file_get_contents("$this->temp_dir/$filename");
$this->vars = &$GLOBALS;
$this->parse();
$html=$this->parse();
$check$this->check_output($this->fid);
if(
$this->fid != $this->files[$this->fid]){
if(
$check != $html)
{

$fp fopen($this->fid,"w");
fwrite($fp,$this->files[$this->fid]);
fclose($fp); 

}
}
            include(
$this->fid);
        }

    }
?>






exchangeboss is offline   قديم 28-07-2008, 10:25 AM
الرد مع إقتباس
عضو نشيط جدا
#6  

كنظرة سريعة شغل جميل لكن يوجد عدة ملاحظات

ومن احدى الملاحظات

كود PHP:
$this->files[$this->fid]=str_replace("neq","!=",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("eq","==",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("neq","!=",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("gt",">",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("lt","<",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("and","&&",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("orrrr","||",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("not","!",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("mod","%",$this->files[$this->fid]); 
اعتقد انه من الافضل ان لا تكون هذه الاستبدالات عامة






__________________
صالح المطرفي (Mr.Saphpـ)
مدونتــــــي
الصندوق الماسي الخامس
قوالب WordPress
تم بحمد الله الإنتهاء من سكربت الدروس العربي 4.0
http://www.saphplesson.org
Saleh AlMatrafi is offline   قديم 28-07-2008, 02:52 PM
الرد مع إقتباس
عضو سوبر نشيط
#7  

Mr.Saphp

شكرا على النصائح استاذي حاولت بان اعملها داخل الاشارة فقط ولكني لم انجح
بالفعل عندما فعلتها عامة واجهت مشكلة وهي خراب التكرار لانس استخدم foreach
فاستبدل الor ب||فوضعتها orrrrrr
شكرا لك استاذي
المعذرة فانا مبتدئ






exchangeboss is offline   قديم 28-07-2008, 03:54 PM
الرد مع إقتباس
عضو سوبر نشيط
#8  

الان لن تحتاج لتصاريح فسيعطي التصاريح بنفسه

كود PHP:
   <?php
    
class template{
             
        var 
$vars;
        var 
$fid;
        var 
$temp_dir;
        var 
$cache_dir;
    
//Function to load a template file.


    //Function to parse the Template Tags

        
function parse(){
//Foreach Statement
$this->files[$this->fid] = preg_replace("'<LOOP NAME=\"(.+)\">'i","<? foreach(\$this->vars[\\1] as \$key=>\$var){ ?>",$this->files[$this->fid]);
$this->files[$this->fid] = preg_replace("'</LOOP>'i","<? } ?>",$this->files[$this->fid]);
//Include Statement
$this->files[$this->fid] = preg_replace("'<INCLUDE FILENAME=\"(.+)\">'i","<? include(\"\\1\"); ?>",$this->files[$this->fid]);
//Foreach Variables
$this->files[$this->fid] = preg_replace("'{{(.+)}}'","<?= \$var[\\1]?>",$this->files[$this->fid]);
//Variables
$this->files[$this->fid] = preg_replace("'{(.+)}'","<?= \$this->vars[\\1]?>",$this->files[$this->fid]);
$this->files[$this->fid] = preg_replace("'<else>'","<? else{ ?>",$this->files[$this->fid]);
$this->files[$this->fid]= preg_replace('/\<if condtion\=\"(.*)\\ (.*)\\ (.*)\">/','<?if($GLOBALS[$1]$2$3){?>',$this->files[$this->fid]);
$this->files[$this->fid]= preg_replace('/\<\/if\>/','<?}?>',$this->files[$this->fid]);
$this->files[$this->fid] = preg_replace('/(<ELSE>|<ELSE \/>)/i','<? }else{ ?>',$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("neq","!=",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("eq","==",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("neq","!=",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("gt",">",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("lt","<",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("and","&&",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("orrrr","||",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("not","!",$this->files[$this->fid]);
$this->files[$this->fid]=str_replace("mod","%",$this->files[$this->fid]);
return
$this->files[$this->fid];
}
  FUNCTION 
check_output($file)
  {
          if( 
file_exists($file))
           {
              
$check = @fopen("$file",r);
              
$r     = @fread($check,filesize("$file"));
              @
fclose($check);

           }
         return  
$r;

  }
    
//Function to OUTPUT
        
function print_temp($filename) {
$this->fid "$this->cache_dir/$filename.php";
$this->parse();
$this->files[$this->fid] = file_get_contents("$this->temp_dir/$filename");
$this->vars = &$GLOBALS;
$this->parse();
if (!
is_writeable($this->cache_dir ) ) {
$m = @chmod($this->cache_dir0777); 
$m = @chmod('class.php'0777);
if(
$m){echo"تم";}
$html=$this->parse();
$check$this->check_output($this->fid);
if(
$this->fid != $this->files[$this->fid]){
if(
$check != $html)
{

$fp fopen($this->fid,"w");
fwrite($fp,$this->files[$this->fid]);
fclose($fp); 

}
}
}else{
$html=$this->parse();
$check$this->check_output($this->fid);
if(
$this->fid != $this->files[$this->fid]){
if(
$check != $html)
{

$fp fopen($this->fid,"w");
fwrite($fp,$this->files[$this->fid]);
fclose($fp); 

}
}
}            include(
$this->fid);
        }

    }
?>
شكرا استاذ saanina
شكرا استاذ Mr.Saphp







آخر تعديل بواسطة exchangeboss في 28-07-2008 الساعة 04:18 PM.
exchangeboss is offline   قديم 28-07-2008, 04:15 PM
الرد مع إقتباس
الرد على الموضوع



أدوات الموضوع

قوانين المشاركات
لا يمكنك كتابة مواضيع جديدة
لا يمكنك إضافة ردود
لا يمكنك إرسال مرفقات
لا يمكنك تعديل مشاركاتك

كود vB متاح
كود [IMG] متاح
كود HTML غير متاح
Trackbacks are متاح
Pingbacks are متاح
Refbacks are متاح


المواضيع المشابهه
الموضوع كاتب الموضوع القسم الردود آخر مشاركة
ممكن احد يحول الملف التالي إلى نظام قوالب عبقور PHP 15 03-11-2007 12:10 AM
مارأيكم ؟؟؟؟ اي نظام قوالب ؟؟ ff5006 PHP 7 22-09-2007 10:45 PM
مايكروسوفت توضح موقفها بشأن تشغيل الأفلام عالية الجودة على نظام فيستا المرتقب تكنو الأخبار المتعلقة بالإنترنت والتقنية 0 30-08-2006 12:44 AM
قوالب جاهزة ولا أروع جديد aleppos.net الويب والويب 2.0 والـ Semantic Web 7 23-08-2005 09:59 PM


جميع الأوقات بتوقيت غرينتش +3. الوقت الآن هو 08:06 PM.