From d76b4df139cb2cd662cf5ec275eab1e05b97b34c Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Thu, 23 Apr 2015 17:03:04 +0200 Subject: [PATCH] Added more fields --- src/CoreFields/ArrayField.php | 38 +++ src/CoreFields/ChoiceField.php | 157 ++++++++++ src/CoreFields/DateField.php | 143 +++++++++ src/CoreFields/FileField.php | 162 ++++++++++ src/CoreFields/ForeignKeyField.php | 191 +++++++++++ src/CoreFields/ImageField.php | 487 +++++++++++++++++++++++++++++ src/CoreFields/KeyField.php | 63 ++++ src/CoreFields/SerializeField.php | 120 +++++++ src/CoreFields/TextField.php | 68 ++++ src/CoreFields/TextHTMLField.php | 127 ++++++++ src/Webmodel.php | 18 +- 11 files changed, 1568 insertions(+), 6 deletions(-) create mode 100644 src/CoreFields/ArrayField.php create mode 100644 src/CoreFields/ChoiceField.php create mode 100644 src/CoreFields/DateField.php create mode 100644 src/CoreFields/FileField.php create mode 100644 src/CoreFields/ForeignKeyField.php create mode 100644 src/CoreFields/ImageField.php create mode 100644 src/CoreFields/KeyField.php create mode 100644 src/CoreFields/SerializeField.php create mode 100644 src/CoreFields/TextField.php create mode 100644 src/CoreFields/TextHTMLField.php diff --git a/src/CoreFields/ArrayField.php b/src/CoreFields/ArrayField.php new file mode 100644 index 0000000..13da650 --- /dev/null +++ b/src/CoreFields/ArrayField.php @@ -0,0 +1,38 @@ + \ No newline at end of file diff --git a/src/CoreFields/ChoiceField.php b/src/CoreFields/ChoiceField.php new file mode 100644 index 0000000..01dc1fe --- /dev/null +++ b/src/CoreFields/ChoiceField.php @@ -0,0 +1,157 @@ +size=$size; + $this->form='SelectForm'; + $this->type=$type; + $this->arr_values=$arr_values; + $this->default_value=$default_value; + $this->arr_formatted['']=''; + + foreach($arr_values as $value) + { + + $this->arr_formatted[$value]=$value; + + } + + } + + function restart_formatted() + { + + foreach($this->arr_values as $value) + { + + $this->arr_formatted[$value]=$value; + + } + + } + + function check($value) + { + + switch($this->type) + { + + case 'integer': + + settype($value, "integer"); + + break; + + case 'string': + + $value=form_text($value); + + break; + + } + + if(in_array($value, $this->arr_values)) + { + + return $value; + + } + else + { + + return $this->default_value; + + } + + } + + function get_type_sql() + { + + switch($this->type) + { + + case 'integer': + + return 'INT('.$this->size.') NOT NULL'; + + break; + + case 'string': + + return 'VARCHAR('.$this->size.') NOT NULL'; + + break; + + } + + } + + /** + * This function is used for show the value on a human format + */ + + public function show_formatted($value) + { + + return $this->arr_formatted[$value]; + + } + + function get_parameters_default() + { + + if(count($this->arr_values)>0) + { + $arr_return=array($this->default_value); + + foreach($this->arr_values as $value) + { + + $arr_return[]=$this->arr_formatted[$value]; + $arr_return[]=$value; + + } + + $arr_values=$arr_return; + + } + else + { + + $arr_values=array(0, 'Option 1', 0, 'Option 2', 1); + + } + + return array($this->name_component, '', $arr_values); + + } + +} + +?> \ No newline at end of file diff --git a/src/CoreFields/DateField.php b/src/CoreFields/DateField.php new file mode 100644 index 0000000..08b2964 --- /dev/null +++ b/src/CoreFields/DateField.php @@ -0,0 +1,143 @@ +size=$size; + $this->form='DateForm'; + + } + + //The check have 3 parts, in a part you have a default time, other part if you have an array from a form, last part if you send a timestamp directly. + + function check($value) + { + + $final_value=0; + + if($this->set_default_time==0) + { + + $final_value=mktime(date('H'), date('i'), date('s')); + + } + + if(gettype($value)=='array') + { + + settype($value[0], 'integer'); + settype($value[1], 'integer'); + settype($value[2], 'integer'); + settype($value[3], 'integer'); + settype($value[4], 'integer'); + settype($value[5], 'integer'); + + if($value[0]>0 && $value[1]>0 && $value[2]>0) + { + + /*$substr_time=$user_data['format_time']/3600; + + $value[3]-=$substr_time;*/ + + $final_value=mktime ($value[3], $value[4], $value[5], $value[1], $value[0], $value[2] ); + + } + + /*echo date('H-i-s', $final_value); + + //echo $final_value; + + die;*/ + + } + else if(strpos($value, '-')!==false) + { + + $arr_time=explode('-',trim($value)); + + settype($arr_time[0], 'integer'); + settype($arr_time[1], 'integer'); + settype($arr_time[2], 'integer'); + + $final_value=mktime (0, 0, 0, $arr_time[1], $arr_time[0], $arr_time[2] ); + + if($final_value===false) + { + + $final_value=mktime (0, 0, 0, $arr_time[1], $arr_time[2], $arr_time[0] ); + + } + + } + else + if(gettype($value)=='string' || gettype($value)=='integer') + { + + settype($value, 'integer'); + $final_value=$value; + + } + + $this->value=Utils::form_text($final_value); + + return $final_value; + + } + + function get_type_sql() + { + + return 'INT('.$this->size.') NOT NULL'; + + + } + + /** + * This function is used for show the value on a human format + */ + + public function show_formatted($value) + { + + return $this->format_date($value); + + } + + static public function format_date($value) + { + + load_libraries(array('form_date')); + + return form_date( $value ); + + } + + function get_parameters_default() + { + + return array($this->name_component, '', time()); + + } + +} + +?> \ No newline at end of file diff --git a/src/CoreFields/FileField.php b/src/CoreFields/FileField.php new file mode 100644 index 0000000..0dfd9c4 --- /dev/null +++ b/src/CoreFields/FileField.php @@ -0,0 +1,162 @@ +name_file=$name_file; + $this->path=$path; + $this->url_path=$url_path; + //$this->type=$type; + + } + + //Check if the file is correct.. + + function check($file) + { + + $file_field=$this->name_file; + + settype($_POST['delete_'.$file_field], 'integer'); + + if($_POST['delete_'.$file_field]==1) + { + + $file_delete=Utils::form_text($_POST[$file_field]); + + if($file_delete!='') + { + + @unlink($this->path.'/'.$file_delete); + + $file=''; + + } + + } + + if(isset($_FILES[$file_field]['tmp_name'])) + { + + if($_FILES[$file_field]['tmp_name']!='') + { + + if( move_uploaded_file ( $_FILES[$file_field]['tmp_name'] , $this->path.'/'.$_FILES[$file_field]['name'] ) ) + { + + return $_FILES[$file_field]['name']; + + //return $this->path.'/'.$_FILES[$file]['name']; + + } + else + { + + $this->std_error=PhangoVar::$l_['common']->lang('error_cannot_upload_this_file_to_the_server', 'Error: Cannot upload this file to the server'); + + return ''; + + } + + + } + else if($file!='') + { + + return $file; + + } + + } + else + { + + $this->std_error=PhangoVar::$l_['error_model']->lang('check_error_enctype_for_upload_file', 'Please, check enctype form of file form'); + + return ''; + + } + + $this->value=''; + + return ''; + + + } + + + function get_type_sql() + { + + return 'VARCHAR(255) NOT NULL'; + + } + + /** + * This function is used for show the value on a human format + */ + + public function show_formatted($value) + { + + return $value; + + } + + function show_file_url($value) + { + + return $this->url_path.'/'.$value; + + } + + function get_parameters_default() + { + + return array($this->name_component, '', ''); + + } + + function process_delete_field($model, $name_field, $conditions) + { + + $query=$model->select($conditions, array($name_field)); + + while(list($file_name)=webtsys_fetch_row($query)) + { + + if(!unlink($this->path.'/'.$file_name)) + { + + $this->std_error=PhangoVar::$l_['common']->lang('cannot_delete_file', 'Cannot delete the file'); + + } + + } + + } + +} + +?> \ No newline at end of file diff --git a/src/CoreFields/ForeignKeyField.php b/src/CoreFields/ForeignKeyField.php new file mode 100644 index 0000000..4ae5996 --- /dev/null +++ b/src/CoreFields/ForeignKeyField.php @@ -0,0 +1,191 @@ +size=$size; + $this->form='SelectForm'; + $this->related_model=&$related_model; + $this->container_model=$this->related_model->name_model; + //Fields obtained from related_model if you make a query... + $this->fields_related_model=array(); + //Representative field for related model... + $this->name_field_to_field=''; + $this->null_relation=$null_relation; + $this->default_id=$default; + + //PhangoVar::$model[$related_model]->related_models_delete[]=array('model' => $this->name_model, 'related_field' => $this->name_component); + + //echo get_parent_class(); + + } + + function set_relationships() + { + + //We need the model loaded... + + if(isset($this->related_model)) + { + $this->related_model->related_models_delete[]=array('model' => $this->name_model, 'related_field' => $this->name_component); + } + else + { + + //show_error('You need load model before set relantionship', $this->related_model.' model not exists. You need load model before set relantionship with ForeignKeyField with '.$this->name_model.' model', $output_external=''); + + throw new \Exception($this->related_model.' model not exists. You need load model before set relantionship with ForeignKeyField with '.$this->name_model.' model'); + + die; + + } + } + + function check($value) + { + + settype($value, "integer"); + + //Reload related model if not exists, if exists, only check cache models... + + if(!isset($this->related_model)) + { + + load_model($this->container_model); + + } + + //Need checking if the value exists with a select_count + + $num_rows=$this->related_model->select_count('where '.$this->related_model.'.'.$this->related_model->idmodel.'='.$value, $this->related_model->idmodel); + + if($num_rows>0) + { + + if($value==0 && $this->yes_zero==0) + { + + return NULL; + + } + + return $value; + + } + else + { + + if($this->default_id<=0 && $this->yes_zero==0) + { + + return NULL; + + } + else + { + + return $this->default_id; + + } + + } + + + } + + function simple_check($value) + { + + settype($value, 'integer'); + + return $value; + + } + + + function get_type_sql() + { + + $arr_null[0]='NOT NULL'; + $arr_null[1]='NULL'; + + return 'INT('.$this->size.') '.$arr_null[$this->null_relation]; + + } + + /** + * This function is used for show the value on a human format + */ + + public function show_formatted($value) + { + + return $this->related_model->components[$this->name_field_to_field]->show_formatted($value); + + //return $value; + + } + + function get_parameters_default() + { + + + load_libraries(array('forms/selectmodelform')); + + //SelectModelForm($name, $class, $value, $model_name, $identifier_field, $where='') + + //Prepare parameters for selectmodelform + + if(isset($this->name_component) && $this->name_field_to_field!='' && $this->name_model!='' && count(PhangoVar::$model[$this->name_model]->forms)>0) + { + PhangoVar::$model[$this->name_model]->forms[$this->name_component]->form='SelectModelForm'; + + return array($this->name_component, '', '', $this->related_model, $this->name_field_to_field, ''); + + } + else + { + + $arr_values=array('', PhangoVar::$l_['common']->lang('any_option_chosen', 'Any option chosen'), ''); + + return array($this->name_component, '', $arr_values); + + } + + } + + function get_all_fields() + { + + return array_keys($this->related_model->components); + + } + +} + +?> \ No newline at end of file diff --git a/src/CoreFields/ImageField.php b/src/CoreFields/ImageField.php new file mode 100644 index 0000000..ce56a3a --- /dev/null +++ b/src/CoreFields/ImageField.php @@ -0,0 +1,487 @@ + 150), $quality_jpeg=85) + { + + $this->name_file=$name_file; + $this->path=$path; + $this->url_path=$url_path; + $this->type=$type; + $this->thumb=$thumb; + $this->img_width=$img_width; + $this->quality_jpeg=$quality_jpeg; + + } + + //Check if the image is correct.. + + function check($image) + { + //Only accept jpeg, gif y png + + + + $file=$this->name_file; + $image=basename($image); + + settype($_POST['delete_'.$file], 'integer'); + + if($_POST['delete_'.$file]==1) + { + + //Delete old_image + + $image_file=Utils::form_text($_POST[$file]); + + if($image_file!='') + { + + @unlink($this->path.'/'.$image_file); + + foreach($this->img_width as $key => $value) + { + + @unlink($this->path.'/'.$key.'_'.$image_file); + + } + + $image=''; + + } + + } + + if(isset($_FILES[$file]['tmp_name'])) + { + + if($_FILES[$file]['tmp_name']!='') + { + + + $arr_image=getimagesize($_FILES[$file]['tmp_name']); + + $_FILES[$file]['name']=Utils::slugify(Utils::form_text($_FILES[$file]['name'])); + + if($this->prefix_id==1) + { + + $func_token=$this->func_token; + + $_FILES[$file]['name']=$func_token().'_'.$_FILES[$file]['name']; + + } + + $this->value=$_FILES[$file]['name']; + + //Check size + + if($this->min_size[0]>0 && $this->min_size[1]>0) + { + + if($arr_image[0]<$this->min_size[0] || $arr_image[1]<$this->min_size[1]) + { + + $this->std_error=PhangoVar::$l_['common']->lang('image_size_is_not_correct', 'Image size is wrong').'
'.PhangoVar::$l_['common']->lang('min_size', 'Minimal size').': '.$this->min_size[0].'x'.$this->min_size[1]; + + $this->value=''; + return ''; + + + } + + } + + /*//Check if exists a image with same name. + + if(file_exists($this->path.'/'.$_FILES[$file]['name'])) + { + + $this->std_error=PhangoVar::$l_['common']->lang('a_image_with_same_name_exists', 'There is an image with the same name'); + + return $image; + + }*/ + + //Delete other image if exists.. + + if($image!='') + { + + unlink($this->path.'/'.$image); + + } + + //gif 1 + //jpg 2 + //png 3 + //Only gifs y pngs... + + //Need checking gd support... + + $func_image[1]='imagecreatefromgif'; + $func_image[2]='imagecreatefromjpeg'; + $func_image[3]='imagecreatefrompng'; + + if($arr_image[2]==1 || $arr_image[2]==2 || $arr_image[2]==3) + { + + $image_func_create='imagejpeg'; + + switch($arr_image[2]) + { + + case 1: + + //$_FILES[$file]['name']=str_replace('.gif', '.jpg', $_FILES[$file]['name']); + $image_func_create='imagegif'; + + break; + + case 3: + + //$_FILES[$file]['name']=str_replace('.png', '.jpg', $_FILES[$file]['name']); + $image_func_create='imagepng'; + //Make conversion to png scale + $this->quality_jpeg=floor($this->quality_jpeg/10); + + if($this->quality_jpeg>9) + { + + $this->quality_jpeg=9; + + } + + break; + + } + + $move_file_func=$this->move_file_func; + + + if( $move_file_func ( $_FILES[$file]['tmp_name'] , $this->path.'/'.$_FILES[$file]['name'] )) + { + + //Make jpeg. + + $func_final=$func_image[$arr_image[2]]; + + $img = $func_final($this->path.'/'.$_FILES[$file]['name']); + + //imagejpeg ( $img, $this->path.'/'.$_FILES[$file]['name'], $this->quality_jpeg ); + + /*$mini_photo=$_FILES[$file]['name']; + + $mini_photo=str_replace('.gif', '.jpg', $mini_photo); + $mini_photo=str_replace('.png', '.jpg', $mini_photo);*/ + + //Reduce size for default if $this->img_width[''] + + if(isset($this->img_width[''])) + { + if($arr_image[0]>$this->img_width['']) + { + $width=$this->img_width['']; + + $ratio = ($arr_image[0] / $width); + $height = round($arr_image[1] / $ratio); + + $thumb = imagecreatetruecolor($width, $height); + + imagecopyresampled ($thumb, $img, 0, 0, 0, 0, $width, $height, $arr_image[0], $arr_image[1]); + + $image_func_create ( $thumb, $this->path.'/'.$_FILES[$file]['name'], $this->quality_jpeg ); + + } + + unset($this->img_width['']); + } + + //Make thumb if specific... + if($this->thumb==1) + { + + //Convert to jpeg. + + foreach($this->img_width as $name_width => $width) + { + + $ratio = ($arr_image[0] / $width); + $height = round($arr_image[1] / $ratio); + + if(isset($this->img_minimal_height[$name_width])) + { + + if($height<$this->img_minimal_height[$name_width]) + { + + //Need recalculate the adecuate width and height. + + $height=$this->img_minimal_height[$name_width]; + + $ratio=($arr_image[1] / $height); + + $width=round($arr_image[0]/$ratio); + + //$width= + + } + + } + + $thumb = imagecreatetruecolor($width, $height); + + imagecopyresampled ($thumb, $img, 0, 0, 0, 0, $width, $height, $arr_image[0], $arr_image[1]); + + $image_func_create ( $thumb, $this->path.'/'.$name_width.'_'.$_FILES[$file]['name'], $this->quality_jpeg ); + ; + //imagepng ( resource $image [, string $filename [, int $quality [, int $filters ]]] ) + + } + + } + + //unlink($_FILES[$file]['tmp_name']); + + //Unlink if exists image + + if(isset($_POST[$file])) + { + + if($_POST[$file]!='') + { + $image_file=Utils::form_text($_POST[$file]); + + if($image_file!='') + { + + @unlink($this->path.'/'.$image_file); + + foreach($this->img_width as $key => $value) + { + + @unlink($this->path.'/'.$key.'_'.$image_file); + + } + + $image=''; + + } + + } + + } + + return $_FILES[$file]['name']; + + //return $this->path.'/'.$_FILES[$file]['name']; + + } + else + { + + $this->std_error=PhangoVar::$l_['common']->lang('error_cannot_upload_this_image_to_the_server', 'Error: Cannot upload this image to the server'); + + if(DEBUG==1) + { + + $this->std_error.=' Image origin '.$_FILES[$file]['tmp_name'].' in this path '.$this->path; + + } + + return ''; + + } + + + } + else + { + + $this->std_error.=PhangoVar::$l_['error_model']->lang('img_format_error', 'Img format error, only accept gif, jpg and png formats'); + + } + + } + else if($image!='') + { + + return $image; + + } + + + } + else if($image!=='') + { + + + if(file_exists($this->path.'/'.$image)) + { + + $this->value=$this->path.'/'.$image; + return $image; + + } + else + { + + $this->std_error=PhangoVar::$l_['error_model']->lang('check_error_enctype_for_upload_file', 'Please, check enctype form of file form'); + return ''; + + } + + + + } + else + { + + $this->std_error=PhangoVar::$l_['error_model']->lang('check_error_enctype_for_upload_file', 'Please, check enctype form of file form'); + + } + + $this->value=''; + return ''; + + + } + + + function get_type_sql() + { + + return 'VARCHAR(255) NOT NULL'; + + } + + function show_image_url($value) + { + + return $this->url_path.'/'.$value; + + } + + function process_delete_field($model, $name_field, $conditions) + { + + + + //die; + $query=$model->select($conditions, array($name_field)); + + while(list($image_name)=webtsys_fetch_row($query)) + { + + if( file_exists($this->path.'/'.$image_name) && !is_dir($this->path.'/'.$image_name) ) + { + if(unlink($this->path.'/'.$image_name)) + { + + //Unlink mini_images + + unset($this->img_width['']); + + foreach($this->img_width as $key => $value) + { + + if(!unlink($this->path.'/'.$key.'_'.$image_name)) + { + + $this->std_error.=PhangoVar::$l_['common']->lang('cannot_delete_image', 'Cannot delete the image').': '.$key.'_'.$image_name; + + } + + } + + $this->std_error.=PhangoVar::$l_['common']->lang('cannot_delete_image', 'Cannot delete the image').': '.$image_name; + + } + else + { + + $this->std_error.=PhangoVar::$l_['common']->lang('cannot_delete_image', 'Cannot delete the image').': '.$image_name; + + } + + } + else + { + + $this->std_error.=PhangoVar::$l_['common']->lang('cannot_delete_image', 'Cannot delete the image').': '.$image_name; + + } + + } + + } + + /** + * Method for return a formatted value readable for humans. + */ + + public function show_formatted($value) + { + + //Size + + $size=150; + + if($this->thumb==1) + { + + reset($this->img_width); + + if(isset($this->img_width[''])) + { + + next($this->img_width); + + } + + $key=key($this->img_width); + + $value=$key.'_'.$value; + + $size=$this->img_width[$key]; + + + } + + return ''; + + } + +} + +?> \ No newline at end of file diff --git a/src/CoreFields/KeyField.php b/src/CoreFields/KeyField.php new file mode 100644 index 0000000..a23ed84 --- /dev/null +++ b/src/CoreFields/KeyField.php @@ -0,0 +1,63 @@ +size=$size; + $this->form='TextForm'; + + } + + function check($value) + { + + $this->value=Utils::form_text($value); + + settype($value, "integer"); + return $value; + + } + + function get_type_sql() + { + + return 'INT('.$this->size.') NOT NULL'; + + } + + /** + * This function is used for show the value on a human format + */ + + public function show_formatted($value) + { + + return $value; + + } + +} + +?> \ No newline at end of file diff --git a/src/CoreFields/SerializeField.php b/src/CoreFields/SerializeField.php new file mode 100644 index 0000000..f162a75 --- /dev/null +++ b/src/CoreFields/SerializeField.php @@ -0,0 +1,120 @@ +related_type=&$related_type; + + } + + public $type_data=''; + + //This method is used for check all members from serialize + + function recursive_form($value) + { + + if(gettype($value)=="array") + { + + foreach($value as $key => $value_key) + { + + if(gettype($value_key)=="array") + { + + $value[$key]=$this->recursive_form($value_key); + + } + else + { + + //Create new type. + //$type_field=new $this->related_type(); + + $value[$key]=$this->related_type->check($value_key); + + } + + } + + } + + return $value; + + } + + function check($value) + { + + $value=$this->recursive_form($value); + + $this->value=$value; + + return webtsys_escape_string(serialize($value)); + + } + + function get_type_sql() + { + + return 'TEXT NOT NULL'; + + + } + + /** + * This function is used for show the value on a human format + */ + + public function show_formatted($value) + { + + $real_value=unserialize($value); + + return implode(', ', $return_value); + + } + + static function unserialize($value) + { + + $real_value=@unserialize($value); + + if($real_value!==false) + { + return $real_value; + } + else + { + + //$this->std_error=''; + return false; + + } + + } + +} + +?> \ No newline at end of file diff --git a/src/CoreFields/TextField.php b/src/CoreFields/TextField.php new file mode 100644 index 0000000..d8c4b32 --- /dev/null +++ b/src/CoreFields/TextField.php @@ -0,0 +1,68 @@ +form='TextAreaForm'; + $this->multilang=$multilang; + + } + + function check($value) + { + + //Delete Javascript tags and simple quotes. + $this->value=$value; + return form_text($value, $this->br); + + } + + //Function check_form + + function get_type_sql() + { + + return 'TEXT NOT NULL'; + + + } + + /** + * This function is used for show the value on a human format + */ + + public function show_formatted($value) + { + + return $value; + + } + + function get_parameters_default() + { + + return array($this->name_component, '', ''); + + } + +} +?> \ No newline at end of file diff --git a/src/CoreFields/TextHTMLField.php b/src/CoreFields/TextHTMLField.php new file mode 100644 index 0000000..7a3620c --- /dev/null +++ b/src/CoreFields/TextHTMLField.php @@ -0,0 +1,127 @@ +form='TextAreaForm'; + $this->multilang=$multilang; + + } + + function check($value) + { + + //Delete Javascript tags and simple quotes. + + $txt_without_tags=str_replace(' ', '', strip_tags($value, '') ); + + $txt_without_tags=trim(str_replace(' ', '', $txt_without_tags)); + + if($txt_without_tags=='') + { + + return ''; + + } + + if(Utils::$textbb_type=='') + { + + $this->value=Utils::unform_text($value); + + } + else + { + + $this->value=$value; + + } + + return Utils::form_text_html($value, $this->allowedtags); + + } + + //Methot for show the allowed html tags to the user + + function show_allowedtags() + { + + $arr_example_tags=array(); + + foreach($this->allowedtags as $tag => $arr_tag) + { + + $arr_example_tags[]=htmlentities($arr_tag['example']); + + } + + return implode(', ', $arr_example_tags); + + } + + function get_type_sql() + { + + return 'TEXT NOT NULL'; + + + } + + /** + * This function is used for show the value on a human format + */ + + public function show_formatted($value) + { + + return $value; + + } + + function get_parameters_default() + { + + return array($this->name_component, '', ''); + + } + + function set_safe_html_tags() + { + + $this->allowedtags['a']=array('pattern' => '/<a.*?href="(http:\/\/.*?)".*?>(.*?)<\/a>/', 'replace' => '$2', 'example' => ''); + $this->allowedtags['p']=array('pattern' => '/<p.*?>(.*?)<\/p>/s', 'replace' => '$1','example' => '

'); + $this->allowedtags['br']=array('pattern' => '/<br.*?\/>/', 'replace' => '', 'example' => '
'); + $this->allowedtags['strong']=array('pattern' => '/<strong.*?>(.*?)<\/strong>/s', 'replace' => '$1', 'example' => ''); + $this->allowedtags['em']=array('pattern' => '/<em.*?>(.*?)<\/em>/s', 'replace' => '$1', 'example' => ''); + $this->allowedtags['i']=array('pattern' => '/<i.*?>(.*?)<\/i>/s', 'replace' => '$1', 'example' => ''); + $this->allowedtags['u']=array('pattern' => '/<u.*?>(.*?)<\/u>/s', 'replace' => '$1', 'example' => ''); + $this->allowedtags['blockquote']=array('pattern' => '/<blockquote.*?>(.*?)<\/blockquote>/s', 'replace' => '$1', 'example' => '
', 'recursive' => 1); + $this->allowedtags['img']=array('pattern' => '/<img.*?alt="([aA-zZ]+)".*?src="('.str_replace('/', '\/', PhangoVar::$base_url).'\/media\/smileys\/[^\r\n\t<"].*?)".*?\/>/', 'replace' => '', 'example' => 'emoticon'); + + } + +} + +?> \ No newline at end of file diff --git a/src/Webmodel.php b/src/Webmodel.php index 4332aa1..72227dc 100644 --- a/src/Webmodel.php +++ b/src/Webmodel.php @@ -310,10 +310,12 @@ class Webmodel { //$text_error='

Output: '.$output.'

'; - $arr_error_sql[0]='

Error: Cannot connect to MySQL db.

'; - $arr_error_sql[1]='

Error: Cannot connect to MySQL db, '.$output.'

'; + /*$arr_error_sql[0]='

Error: Cannot connect to MySQL db.

'; + $arr_error_sql[1]='

Error: Cannot connect to MySQL db, '.$output.'

';*/ - show_error($arr_error_sql[0], $arr_error_sql[1]); + //show_error($arr_error_sql[0], $arr_error_sql[1]); + + throw new \Exception('Error: cannot connect to database'); } @@ -334,10 +336,12 @@ class Webmodel { //$text_error='

Output: '.$output.'

'; - $arr_error_sql[0]='

Error: Cannot connect to MySQL db.

'; + /*$arr_error_sql[0]='

Error: Cannot connect to MySQL db.

'; $arr_error_sql[1]='

Error: Cannot connect to MySQL db, '.$output.'

'; - show_error($arr_error_sql[0], $arr_error_sql[1]); + show_error($arr_error_sql[0], $arr_error_sql[1]);*/ + + throw new \Exception('Error: cannot connect to database'); } @@ -386,7 +390,9 @@ class Webmodel { if(count($this->components)>1) { - show_error('

Error in a model for use ids.

', '

Error in model '.$this->name.' for use change_id_default. This method must be used before any component.

'); + //show_error('

Error in a model for use ids.

', '

Error in model '.$this->name.' for use change_id_default. This method must be used before any component.

'); + + throw new \Exception('Error in model '.$this->name.' for use change_id_default. This method must be used before any component'); }