PDA

View Full Version : سوال: template engin مناسب و ساده برای شروع کار چیست؟



css-man
یک شنبه 27 اسفند 1391, 22:00 عصر
دوستان من تازه میخوام با یه template engin کار کنم
هیچ تجربه ای هم تو این زمینه ندارم
دوستان اگر میشناسید یه نمونه ساده و ابتدایی رو معرفی کنید که بدرد شروع بخوره

مرسی

T.R.G.T
یک شنبه 27 اسفند 1391, 22:30 عصر
بنظرم بهتره خودت بسازی کار خیییییییلی ساده ایه

css-man
یک شنبه 27 اسفند 1391, 23:52 عصر
می شه راهنمائیم کنید
تا حالا این کار رو نکردم
از کجا باید شروع کنم

اصلا منطقش رو نمیدونم

SadeghPro19
دوشنبه 28 اسفند 1391, 10:02 صبح
راین رو بهتون پیشنهاد میکنم هم سادست و هم کارائی خوبی داره و البته سبک هم هست.
RainTemplate.com

T.R.G.T
دوشنبه 28 اسفند 1391, 10:44 صبح
من این کلاس رو برای سیستم مدیریت محتوایی که دارم مینویسم نوشتم میتونه:
داده ها رو روی یک قالب html ساده پیاده کنه
داده ها رو روی یک قالب پویا(html بهمراه php)پیاده کنه
در صورت مشکل برای تم اصلی از تم جایگزین استفاده کنه
در صورت مشکل برای تم جایگزین داده ها رو بدون تم نمایش بده
میتونه از محل های مختلف در تم استفاده کنه
اگه محل یک داده از سیستم اشتباه بود بدون مشکل به کار خودش ادامه بده
خلاصه اینکه هر بلایی سرش بیاد به کارش ادامه میده
البته چون هنوز با سیستم مچ نشده متد های کنترلی رو اضافه نکردم ولی در کل فکر کنم مثال خوبی باشه برای تمپلیت انجین



<?php
class template{
public $template_name;
public $template_type;
public $template_path;
public $template_replace_name;

public $template_files;
public $template_files_name;

public $positions;
public $positions_processor;
public $positions_processor_type;

public $useful_positions;
public $unprocessed_positions_processor;
public $unprocessed_positions_value;

public $processed_positions;
public $processed_address_positions;

public function template(){
$this->find_template_name();
$this->template_fasap();
$this->template_data();
}
public function find_template_name(){
$template_name_obj=new config;
$this->template_name=$template_name_obj->config_sistem_file('template');
$this->template_replace_name=$template_name_obj->config_sistem_file('alternative_template');
}
public function template_fasap(){
if(file_exists('template/'.$this->template_name.'/index.php')){
$this->template_type='dynamic';
$this->template_path='template/'.$this->template_name.'/';
}elseif(file_exists('template/'.$this->template_name.'/index.html') or file_exists('template/'.$this->template_name.'/index.htm')){
$this->template_type='static';
$this->template_path='template/'.$this->template_name.'/';
}elseif(file_exists('template/'.$this->template_replace_name.'/index.php')){
$this->template_type='dynamic';
$this->template_path='template/'.$this->template_replace_name.'/';
}elseif(file_exists('template/'.$this->template_replace_name.'/index.html') or file_exists('template/'.$this->template_replace_name.'/index.htm')){
$this->template_type='static';
$this->template_path='template/'.$this->template_replace_name.'/';
}else{
$this->template_type='not_found';
}
$this->template_load($this->template_path);
}
public function template_load($path){
if($this->template_type=='dynamic'){
include $path.'index.php';
$template_class=new template_class;
$template_files=$template_class->files;
$template_files_name=$template_class->files_name;
$template_files_number=count($template_files);
for($i=0;$i<$template_files_number;$i++){
if(file_exists($path.$template_files[$i])){
$file[$template_files_name[$i]]=file_get_contents($path.$template_files[$i]);
}else{
$template_files_error[$i]=$template_files_name[$i];
}
}
$this->template_files=$file;
$this->template_files_name=$template_files_name;
}elseif($this->template_type=='static'){
if(file_exists($path.'index.htm')){
$file=file_get_contents($path.'index.htm');
}elseif(file_exists($path.'index.html')){
$file=file_get_contents($path.'index.html');
}
echo $file;
$this->template_files=$file;
}
}
public function template_data(){
if($this->template_type=='dynamic'){
$template_obj=new template_class;
$this->positions=$template_obj->positions;
$this->positions_processor=$template_obj->positions_processor;
$this->positions_processor_type=$template_obj->positions_processor_type;
}elseif($this->template_type=='static'){
$regx_first_position='/id="position_static_.*?"/';
preg_match_all($regx_first_position,$this->template_files,$first_position_array);
$count_first_position_array=count($first_position_ array[0]);
for($i=0;$i<$count_first_position_array;$i++){
$regx_position='/position_static_.*?"/';
preg_match($regx_position,$first_position_array[0][$i],$position_array);
$temp=str_replace('"','',$position_array[0]);
$position[$i]=$temp;
}
$this->positions=$position;
$position_count=count($this->positions);
$ddoc=new DOMDocument;
@$ddoc->loadHTML($this->template_files);
for($i=0;$i<$position_count;$i++){
$ddocn=$ddoc->getElementById($this->positions[$i]);
$position_processor=$ddocn->getAttribute('type');
$ddocn->removeAttribute('type');
if(!empty($position_processor)){
$this->positions_processor[$i]=$position_processor;
}else{
$this->positions_processor[$i]='';
}
$this->positions_processor_type[$i]='function';
}
$ddoc->saveHTML();
}
}
public function initialize_positions($positions,$processor,$positi ons_value){
if($this->template_type=='dynamic' or $this->template_type=='static'){
if(!is_array($this->useful_positions)){settype($this->useful_positions,'array');}
if(!is_array($this->unprocessed_positions_value)){settype($this->unprocessed_positions_value,'array');}
if(!is_array($this->unprocessed_positions_processor)){settype($this->unprocessed_positions_processor,'array');}
for($i=0;$i<count($positions);$i++){
for($j=0;$j<count($this->positions);$j++){
if($this->positions[$j]==$positions[$i]){
array_push($this->useful_positions,$positions[$i]);
array_push($this->unprocessed_positions_value,$positions_value[$i]);
array_push($this->unprocessed_positions_processor,$processor[$i]);
}
}
}
}else{
$this->useful_positions=$positions;
$this->unprocessed_positions_value=$positions_value;
$this->unprocessed_positions_processor=$processor;
}
$this->set_processed_positions();
return $this->view_them();
}
public function processe_positions_value($postation,$processor,$va lue){
if($this->template_type=='dynamic' or $this->template_type=='static' and $processor=='external_processor'){
$cont_pos=count($this->positions);
for($i=0;$i<$cont_pos;$i++){
if($this->positions[$i]==$postation){
if(isset($this->positions_processor[$i]) and !empty($this->positions_processor[$i])){
if($this->positions_processor_type[$i]=='function'){
return @call_user_func($this->positions_processor[$i],$value);
}elseif($this->positions_processor_type[$i]=='method' and $this->template_type=='dynamic'){
$tm_obj=new template_class;
return @call_user_method($this->positions_processor[$i],$tm_obj,$value);
}
}elseif(chec_status_template_data_system_default($ this->positions[$i])){
return template_data_system_default($this->positions[$i],$value);
}
}
}
}elseif($this->template_type=='not_found' and $processor=='external_processor' and chec_status_template_data_system_default($postatio n)){
return template_data_system_default($postation,$value);
}elseif(!isset($processor) or empty($processor)){
return $value;
}else{
return @call_user_func($processor,$value);
}
}
public function set_processed_positions(){
$count_postations=count($this->useful_positions);
for($i=0;$i<$count_postations;$i++){
$temp=$this->processe_positions_value($this->useful_positions[$i],$this->unprocessed_positions_processor[$i],$this->unprocessed_positions_value[$i]);
$position_name=$this->useful_positions[$i];
if(!is_array($this->processed_positions[$position_name])){
settype($this->processed_positions[$position_name],'array');
}
if(!is_array($this->processed_address_positions)){
settype($this->processed_address_positions,'array');
}if(!is_array($this->processed_address_positions)){
settype($this->processed_address_positions,'array');
}
array_push($this->processed_positions[$position_name],$temp);
$asp=array_search($this->useful_positions[$i],$this->processed_address_positions);
if($asp===0){
$asp=true;
}
if(!$asp){
array_push($this->processed_address_positions,$this->useful_positions[$i]);
}
}
}
public function view_them(){
$positions_number=count($this->processed_positions);
if($this->template_type=='dynamic' or $this->template_type=='static'){
if($this->template_type=='dynamic'){
$file=$this->template_files['template'];
}else{
$file=$this->template_files;
}
for($i=0;$i<$positions_number;$i++){
$position_node_value=implode('',$this->processed_positions[$this->processed_address_positions[$i]]);
$regx_first_position='/id="'.$this->processed_address_positions[$i].'.*?>/';
preg_match_all($regx_first_position,$file,$first_p osition_array);
$regx_position='/id="'.$this->processed_address_positions[$i].'.*?>/';
$file=preg_replace($regx_position,$first_position_ array[0][0].$position_node_value,$file);
}
}else{
for($i=0;$i<$positions_number;$i++){
$position_node_value.='<p>'.implode('<br />',$this->processed_positions[$this->processed_address_positions[$i]]).'</p>';
}
$file=$position_node_value;
}
return $file;
}
}
?>

اینم از فایل تست (http://ttrrgg.persiangig.com/test.zip)

AmirSky
دوشنبه 28 اسفند 1391, 15:22 عصر
من پیشنهاد میکنم بجای اینکه وقتت رو با این کارها تلف کنی از یکی از فریم ورکهای php استفاده کنی