__('Text','axfields'),
'select'=>__('Drop Down List','axfields'),
'checkbox'=>__('Checkbox','axfields'),
'checkboxlist'=>__('Checkbox List','axfields'),
'textarea'=>__('Multiple line text','axfields'),
'wysiwyg'=>__('WYSIWYG','axfields'));
}
public static function validation_types(){
return array(
array('type'=>'required','msg'=>__('Please enter %name%','axfields'),'name'=>__('Required field','axfields')),
array('type'=>'email','name'=>__('E-mail','axfields'),'msg'=>__('Please enter a valid email address','axfields')),
array('type'=>'noselect','name'=>__('Not select','axfields'),'msg'=>__('Please select a valid value','axfields'),'option'=>true,'description'=>__('Enter value not to be selecetd. Use this to force user not to select a specifc item n a drop down list','axfields')),
array('type'=>'maxselect','name'=>__('Maximum selection','axfields'),'msg'=>__('You can only select %n% items','axfields'),'option'=>true,'description'=>__('Enter the max number of item selecteable.Use this to set the maximum number of items selected in a list','axfields')),
array('type'=>'minselect','name'=>__('Minimum selection','axfields'),'msg'=>__('You should select at least %n% item(s)','axfields'),'option'=>true,'description'=>__('Enter the min number of item selecteable.Use this to set the minimum number of items selected in a list','axfields')),
array('type'=>'numeric','name'=>__('Numeric input','axfields'),'msg'=>__('Please enter numeric characters only','axfields'),'description'=>__('Use this to force only numeric input','axfields')),
array('type'=>'maxlen','name'=>__('Maximum string length','axfields'),'msg'=>__('The input for %name% must not be longer than %n% character','axfields'),'option'=>true,'description'=>__('Enter the max length of the text input.Use this to force input max length','axfields')),
array('type'=>'minlen','name'=>__('Minimum string length','axfields'),'msg'=>__('The input for %name% must not be at least %n% characters','axfields'),'option'=>true,'description'=>__('Enter the max length of the text input.Use this to force input min length','axfields')),
array('type'=>'minentry','msg'=>__('At least %n% entries for %name% is/are required','axfields'),'name'=>__('Minimum entry','axfields')),
array('type'=>'maxentry','msg'=>'The maximum number of entry for %name% is %n%','name'=>__('Maximum entry','axfields')),
array('type'=>'mustcheck','msg'=>__('Please check %name%','axfields'),'name'=>__('Required','axfields'))
);}
function __construct($box,$key,$label,$input_type,$order,$options='',$validations=array(),$slug='',$class='test') {
$this->label=$label;
$this->options=$options;
//$this->class=$class;
$this->name=$key;
$this->input_type=$input_type;
$this->slug=$slug;
$this->validations=$validations;
$this->order=$order;
$this->box=$box;
}
public function display() {
//
switch($this->input_type) {
case 'text':
echo '
';
break;
case 'textarea':
echo '
';
break;
case 'select':
echo '
';
break;
case 'checkbox':
$selected=$this->value?' checked="checked"':'';
echo '
';
}
}
public static function save_taxonomies_validation($settings,$opt_name='axf_tax_val') {
update_option($opt_name,json_encode($settings));
}
public static function get_taxonomies_validation($opt_name='axf_tax_val') {
$tax_vals=get_option($opt_name);
$arr_tax_vals=json_decode($tax_vals,true);
if(is_array($arr_tax_vals) && count($arr_tax_vals)>0)
return $arr_tax_vals;
else return false;
}
}
class ameta_box {
public $id=0;
public $title;
public $fields=array();
public $position='side';
public $post_types=array();
public $priority;
public static $table='axf_boxes';
public function __construct($title,$post_types,$position='side',$priority='default',$id=0) {
$this->title=$title;
$this->fields=$fields;
$this->position=$position;
$this->post_types=$post_types;
$this->priority=$priority;
$this->id=$id;
}
public static function delete_box($id) {
global $wpdb,$table_prefix;
$sql='DELETE FROM '.$table_prefix. self::$table.' WHERE id='.$id.';';
$sql.=' DELETE FROM '.$table_prefix.axfield::$table.' WHERE box='.$id.';';
return $wpdb->query($sql);
}
public function save($opt_name='a_metas') {
global $wpdb,$table_prefix;
$result=false;
$sql='';
if((int)$this->id>0) {
$sql="UPDATE ".$table_prefix. self::$table." SET title='$this->title' , position='$this->position',priority='$this->priority',post_types='$this->post_types' WHERE id=$this->id;";
$wpdb->query($sql);
$result=$this->id;
}
else {
$sql="INSERT INTO ".$table_prefix. self::$table."(title,position,priority,post_types) VALUES('$this->title','$this->position','$this->priority','$this->post_types');";
$wpdb->query($sql);
$result=$wpdb->insert_id;
}
return $result;
}
public static function get_metaboxes($meta_boxes_opt='a_metas') {
global $wpdb,$table_prefix;
$sql='SELECT b. * , (
SELECT count( * )
FROM '.$table_prefix.axfield::$table.' f
WHERE f.box = b.id
) AS fields_count
FROM '.$table_prefix.self::$table.' b';
return $wpdb->get_results($sql,OBJECT);
}
public static function get_box_fields($id) {
global $wpdb,$table_prefix;
$sql='SELECT * FROM '.$table_prefix.axfield::$table.' WHERE box = '.$id.';';
return $wpdb->get_results($sql,OBJECT);
}
public static function get_metabox($id) {
global $table_prefix,$wpdb;
$sql='SELECT * FROM '.$table_prefix.self::$table.' WHERE id='.$id.';';
$obj= $wpdb->get_row($sql, OBJECT);
$obj->fields=self::get_box_fields($id);
return $obj;
}
public static function remove_metaboxes($opt_name='a_metas') {
delete_option($opt_name);
return true;
}
public static function save_metabox($title,$post_types,$position='normal',$priority='default',$id=0) {
$box_id=!empty($id)?$id:0;
if(is_array($post_types)) $post_types=implode(',', $post_types);
$mb=new ameta_box($title, $post_types, $position, $priority, $box_id);
return $mb->save();
}
}
$fields_validations=array();
?>