'.$query.'
'.$single_table_model->last_error; $error_count++; if (!$ignore_error) { break; } } else { $html_table = new ADFO_html_table(); $single_table_model->sort = false; $single_table_model->filter = false; $html_content = $html_table->template_render($single_table_model); $items[] = (object)['model'=>$single_table_model, 'content'=>$html_content]; } if (!ADFO_fn::get_max_execution_time()) { break; } } $temporaly = new ADFO_temporaly_files(); $temporaly->store(['total_queries' => $total_queries, 'queries_filename' => $array_temp_file['queries_filename'], 'error_count' => $error_count, 'report_queries' => $report_queries], $filename); if (count($queries) > 0) { $temporaly->store($queries, $array_temp_file['queries_filename']); } else { $temporaly->delete($array_temp_file['queries_filename']); // $temporaly->delete($filename); } $executed_queries = $total_queries - count($queries); } return ['last_error' => $last_error, 'total_queries' => $total_queries, 'executed_queries' => $executed_queries, 'filename' => $filename, 'error_count' => $error_count, 'items'=>$items ]; } /** * Quando lo carichi la prima volta setta il tempo iniziale e torna true. Poi ogni volta che lo carichi verifica quanto tempo è passato e se è passato più di un tot di tempo ritorna false; * @return Boolean Se hai ancora tempo per l'esecuzione dello script oppure no. */ static function get_max_execution_time() { /** * @var Integer $max_time Il tempo massimo di esecuzione del php */ $max_time = @ini_get("max_execution_time"); if ($max_time < 30) { $max_time = 30; } //TODO metterlo a /2 $max_time = $max_time / 2; if ( ( microtime(true) - ADFO_fn::$execute_time_start ) < $max_time ) { return true; } else { return false; } } /** * Converte un carattere speciale nella sua forma visuale */ static function convert_char_to_special($char) { $a = array("\\\\t"=>"\\t","\\\\n"=>"\\n","\\\\r"=>"\\r", "\\t"=>"\\t","\\n"=>"\\n","\\r"=>"\\r","\t"=>"\\t","\n"=>"\\n","\r"=>"\\r"); if(isset($a[$char])) { return $a[$char]; } else { return substr(str_replace("\\", "", $char),0,1); } } /** * Converte un carattere speciale dalla sua forma visuale alla forma reale */ static function convert_special_to_char($char) { $a = array("\t"=>"\t","\n"=>"\n","\r"=>"\r","\t"=>"\t","\\n"=>"\n","\\r"=>"\r","\\\\t"=>"\t","\\\\n"=>"\n","\\\\r"=>"\r"); if(isset($a[$char])) { return $a[$char]; } else { return substr(str_replace("\\", "", $char),0,1); } } /** * Ritorna il prefisso delle tabelle di wordpress */ static function get_prefix() { global $wpdb; return $wpdb->prefix; } /** * Trova l'elenco dei posttype * @return array */ static function get_post_types() { global $wpdb; $p = $wpdb->get_results('SELECT DISTINCT(`post_type`) pt FROM '.$wpdb->posts.' ORDER BY `post_type` DESC LIMIT 1000'); foreach ($p as &$value) { $value = $value->pt; } return $p; } /** * Calcola il massimo upload file */ static function get_max_upload_file() { $max_upload = (ini_get('upload_max_filesize')); $max_post =(ini_get('post_max_size')); $memory_limit = (ini_get('memory_limit')); if (stripos($max_upload,'m') > 0 && stripos($max_post, 'm' ) > 0 && stripos($memory_limit, 'm' ) > 0) { $max_upload = (int) $max_upload; $max_post = (int) $max_post; $memory_limit = (int) $memory_limit; if ($max_upload > 0 && $max_post > 0 && $memory_limit > 0) { return min($max_upload, $max_post, $memory_limit). " Mb"; } else if ($max_upload > 0) { return $max_upload. " Mb"; } } return false; } /** * Calcola il massimo numero di upload_vars impostato * Se si passa il numero di input che si intende inviare ritorna il testo dell'errore * @return Mixed o il valore max_input_vars oppure * se input_used è impostato allora un messaggio se input used è maggiore di max_input_vars o "" */ static function get_max_input_vars($input_used = 0) { $max_input = (int)ini_get('max_input_vars') ; if ($max_input == 0 ) { $max_input = 2000; } if ($input_used > 0) { if ($input_used > $max_input) { return sprintf(__('The maximum number of input_var (max_input_vars) allowed by php.ini is %s But to manage this table I need at least %s', 'admin_form'),$max_input, $input_used); } else { return ""; } } return $max_input; } /** * Converte una stringa per essere accettata come nome di una colonna mysql */ static function convert_to_mysql_column_name($temp_name) { $temp_name = ADFO_fn::clean_string($temp_name); if (!ctype_alpha(substr($temp_name,0,1))) { $temp_name = "col_".$temp_name; } return substr($temp_name,0, 64); } /** * Ritorna tutte le opzioni delle tabelle */ static function get_all_dbp_options() { $table_options = get_option('dbp_table_info'); return $table_options; } /** * Trova le opzioni di una tabella specifica * @return array [status:'DRAFT|PUBLISH|CLOSE', description, $external_filter:boolean] */ static function get_dbp_option_table($table_name) { if ($table_name == "") { $return = ['status'=>'DRAFT', 'description'=>'']; } else { $table_name = trim(str_replace('`','',$table_name)); $table_options = get_option('dbp_table_info'); if ($table_options === false || !array_key_exists($table_name, $table_options)) { $return = ['status'=>'PUBLISH', 'description'=>'']; } else { $return = $table_options[$table_name]; } } $current_status = $return['status']; $return['status'] = apply_filters( 'adfo_table_status', $return['status'], $table_name); /** * FILTER LEGACY MODE * @deprecated v.1.2.0 */ $return['status'] = apply_filters( 'dbp_table_status', $return['status'], $table_name); if ($return['status'] != $current_status) { $return['external_filter'] = true; } else { $return['external_filter'] = false; } return $return; } /** * Aggiorna lo stato di una tabella * @param String $table * @param String|Boolean $status DRAFT|PUBLISH|CLOSE SE falso non lo aggiorna * @param String|Boolean $description Se false non lo aggiorna */ static function update_dbp_option_table_status($table, $status = false, $description = false) { $dbp_table_info = get_option('dbp_table_info'); if ($dbp_table_info === false ) { $dbp_table_info = []; } if ($status == false && $description == false) { return false; } if ($status != false) { $dbp_table_info[$table]['status'] = $status; } if ($description != false) { $dbp_table_info[$table]['description'] = $description; } update_option('dbp_table_info', $dbp_table_info, false); } /** * Rimuove le impostazioni di una tabella dalle option * @param String $table */ static function delete_dbp_option_table_status($table) { $dbp_table_info = get_option('dbp_table_info'); if ($dbp_table_info === false || !array_key_exists($table,$dbp_table_info)) { return true; } unset($dbp_table_info[$table]); update_option('dbp_table_info', $dbp_table_info, false); } /** * Ritorna una stringa univoca. (uniqid non è sicuro!) */ static function get_uniqid() { $uniq = explode(".", uniqid('', true)); return (base_convert($uniq[0], 16, 36).base_convert($uniq[1], 10, 36) ); } /** * Disegna il titolo * @param String $section list|table * @param String $title * @param String $description * @param String $msg * @param String $msg_error * @return Boolean se $msg_error != "" */ static function echo_html_title_box($title, $description = "", $msg = "", $msg_error = "", $append = "") { $array_link_page = ['list'=>'dbp_list', 'table'=>'information-schema']; ?>".$th->original_table." == ". $primaries[$th->original_table]." > ".$row->$k."
"); if (isset($th->table) && $th->original_table != "" && isset($primaries[$th->original_table]) && $primaries[$th->original_table] == $th->original_name && $row->$k > 0) { $primary_values[$th->$key_name] = $row->$k; } } return $primary_values; } /** * Trova i valori delle colonne primarie di un record * $row = $table_model->items[$key] * @param [type] $table_model * @param string $key_name il nome che si vuole estrarre. Se si vuole estrarre il nome del campo allora scrivo "name". * @return void */ static function data_primaries_values_from_schema($primaries, $table_header_schema, $row, $key_name ='name_request') { $primary_values = []; //var_dump ($row); if (is_array($table_header_schema) || is_object($table_header_schema)) { foreach ($table_header_schema as $k => $th) { // LEGACY: se è chiamato dal content non c'è schema Qui c'è un pasticcio tra schema del post_content e schema della prima riga dei risultati if (is_object($th)) { $k = $th->name; $th = ['schema' => $th]; } // print ("".$th['schema']->orgname." == ". $primaries[$th['schema']->orgtable]." > ".$row->$k."
"); if (isset($th['schema']->table) && $th['schema']->orgtable != "" && isset($primaries[$th['schema']->orgtable]) && $primaries[$th['schema']->orgtable] == $th['schema']->orgname && $row->$k > 0) { $primary_values[$th['schema']->$key_name] = $row->$k; } } } return $primary_values; } /** * Rimuove tutte le colonne che devono essere nascoste in un'estrazione di un model * * @param [type] $table_model * @return void */ static function remove_hide_columns(&$table_model) { if (!isset($table_model->items) || !is_countable($table_model->items) || count($table_model->items) == 0 ){ return false; } $table_header = reset($table_model->items); foreach ($table_model->items as $key => $_) { foreach ($table_header as $k=>$th) { if (isset($th->toggle) && $th->toggle == "HIDE") { if (is_array($table_model->items[$key])) { unset($table_model->items[$key][$k]); } else if (is_object($table_model->items[$key])) { unset($table_model->items[$key]->$k); } } } } //echo (htmlentities(json_encode($table_model->items))); } /** * Rimuove tutte le colonne che devono essere nascoste in una riga di un'estrazione * * @param [type] $table_model * @return array */ static function remove_hide_columns_in_row($table_header, $row) { foreach ($table_header as $k=>$th) { if (isset($th->toggle) && $th->toggle == "HIDE") { if (is_array($row) && array_key_exists($k, $row)) { unset($row[$k]); } else if (is_object($row) && property_exists($row, $k)) { unset($row->$k); } } } return $row; //echo (htmlentities(json_encode($table_model->items))); } /** * Cancella una serie di record specifici * * @param array $rids [["table_alias.column_pri"=>value, ]] || [' {"table_alias.id":"val"}','{"table_alias.id":"val"}'] * @param string $sql * @param int $dbp_id * @return array [error,sql] executed */ static function delete_rows($rids, $request_sql = "", $dbp_id = 0) { global $wpdb; if ($request_sql != "") { $queries = self::prepare_delete_rows($rids, $request_sql); } else if ($dbp_id > 0) { $queries = self::prepare_delete_rows($rids,'', $dbp_id); } $errors = [$queries['error']]; $return_sql = []; foreach ($queries['sql'] as $sql) { if (!$wpdb->query($sql)) { $errors[] = $wpdb->last_error; } else { $return_sql[] = $sql; } } return ['error'=> implode("\n", $errors), 'sql'=> implode("\n", $return_sql)]; } /** * Prepara le query per rimuove le righe selezionate. Scegli se lavorare tramite query o dbp_id * @param array $rids [["table_alias.column_pri"=>value, ]] || [' {"table_alias.id":"val"}','{"table_alias.id":"val"}'] * @param string $sql * @param int $dbp_id * @return array the errors or "" if ok. */ static function prepare_delete_rows($rids, $request_sql = "", $dbp_id = 0) { $error = $sql = $items = $checkboxes = []; $show_msg = ''; $dbp_id = absint($dbp_id); $post = false; if (is_countable($rids)) { if ($request_sql != "") { $form = new ADFO_class_form($request_sql); } else if ($dbp_id > 0) { $form = new ADFO_class_form($dbp_id); $post = ADFO_functions_list::get_post_dbp($dbp_id); } else { return ['error' => 'Important data is missing.', 'sql' => [], 'items' => [], 'checkboxes' => []]; } list($settings, $table_options) = $form->get_form(); $table_options = array_shift($table_options); foreach ($rids as $ids) { if (is_string($ids)) { $ids = json_decode(wp_unslash($ids)); } foreach ($ids as $column => $id) { foreach ($table_options as $table_option) { if ($column == $table_option->table . "." . $table_option->pri_orgname) { $option = ADFO_fn::get_dbp_option_table($table_option->orgtable); if ($option['status'] != "CLOSE") { $sql[] = 'DELETE FROM `' . ADFO_fn::sanitize_key($table_option->orgtable) . '` WHERE `' . ADFO_fn::sanitize_key($table_option->orgtable) . '`.`' . ADFO_fn::sanitize_key($table_option->pri_orgname) . '` = \''.esc_sql(absint($id)).'\''; $add_item = true; if ($dbp_id > 0 && $post != false) { $add_item = !(array_key_exists($table_option->table, $post->post_content['delete_params']->remove_tables_alias) && $post->post_content['delete_params']->remove_tables_alias[$table_option->table] == 0); } if ($add_item) { $items[] = 'DELETE FROM `' . $table_option->orgtable . '` WHERE ' . $table_option->orgtable . '.' . $table_option->pri_orgname . '= \''.esc_sql($id).'\''; $checkboxes[] = esc_attr(json_encode([$column => $id])); } } else { $errors[] = sprintf(__('Records in the "%s" table cannot be removed because they are in a closed state. If you want to be able to remove the data, change the status from the table structure to "published"', 'admin_form'), $table_option->orgtable); } } } } } } if ($dbp_id > 0) { $show_msg = __('Are you sure you want to remove the %s selected records?', 'admin_form'); } return ['error' => implode("\n",$error), 'sql' => $sql, 'items' => $items, 'checkboxes' => $checkboxes, 'show_msg' => $show_msg]; } /** * Setto i cookie è una funzione generica. */ static function set_cookie($variable, $value) { //var_dump(headers_sent()); setcookie('dbp_'.$variable, wp_kses_post( wp_unslash($value)), time()+ 3600 * 24, COOKIEPATH, COOKIE_DOMAIN, false); $_COOKIE['dbp_'.$variable] = wp_kses_post( wp_unslash($value)); } /** * i messaggi ok dai cookie */ static function get_msg_cookie() { return (isset(self::$cookie_msgs['dbp_msg'])) ? self::$cookie_msgs['dbp_msg'] : ''; } /** * i messaggi di errore dai cookie */ static function get_error_cookie() { return (isset(self::$cookie_msgs['dbp_error'])) ? self::$cookie_msgs['dbp_error'] : ''; } /** * Trastoprto le informazioni dei messaggi dei cookie dentro la variabile statica cookie_msgs * Questa funzione deve essere chiamata dall'init del loader */ static function init_get_msg_cookie() { self::$cookie_msgs = []; if (isset($_COOKIE['dbp_msg'])) { self::$cookie_msgs['msg'] = wp_kses_post( wp_unslash($_COOKIE['dbp_msg'])); setcookie("dbp_msg", "", time() - 3600); } if (isset($_COOKIE['dbp_error'])) { self::$cookie_msgs['error'] = wp_kses_post( wp_unslash($_COOKIE['dbp_error'])); setcookie("dbp_error", "", time() - 3600); } } /** * trovo l'alias della tabella di cui si sta facendo il join * @param String $table * @param String $other_name Se presente aggiunge altri 3 caratteri al nome * esempio wp_post pos */ static function get_table_alias($table, $query = "", $other_name = "") { global $wpdb; $table_alias_temp = substr(ADFO_fn::clean_string(str_replace( [$wpdb->prefix."adfo", $wpdb->prefix,"_","-"], "", $table)),0 ,3); if (strlen($table_alias_temp) < 3 ) { $table_alias_temp = $table_alias_temp.substr(md5($table),0 , 2); } if ($other_name != "") { $table_alias_temp .= self::get_table_alias($other_name, ""); } $table_alias = $table_alias_temp; $count_ta = 1; while(stripos($query, $table_alias.'`') !== false || stripos($query, $table_alias.' ') !== false) { $table_alias = $table_alias_temp.''.$count_ta; $count_ta++; } return $table_alias; } /** * Creo un alias di una colonna e verifico che non sia già stata usata * @param String $string Il nome della colonna * @param String Query la query per evitare colonne con lo stesso nome * La query devo prenderla da get_current_query() altrimenti è compressa!! */ static function get_column_alias($string, $query) { $alias = $alias_temp =substr(ADFO_fn::clean_string($string),0, 60); $count_alias = 1; // verifico che l'alias della colonna non sia stato già usato while(stripos($query, $alias.'`') !== false || stripos($query, $alias.' ') !== false) { $alias = $alias_temp.''.$count_alias; $count_alias++; } return $alias; } /** * Separa una stringa secondo una serie di occorrenze definite in un array * @param Array $separators L'elenco delle parole per cui dividere la stringa * @param String $string la stringa da dividere * @param Bool $add_separators Aggiunge nei risultati anche i delimitatori es: [ris1, delimiter, ris2] * @return Array ritorna un array di stringe divise dai delimitatori */ static function multi_explode($separators, $string, $add_separators = false) { $delimiter = 1; $old_delimiter = 0; $offset = 0; $explode = []; while($delimiter > 0) { $current_delimiter = ''; $delimiter = 0; $curr_pos = strlen($string); foreach ($separators as $separator) { $pos = stripos($string, $separator, $offset); if ($pos < $curr_pos && $pos !== false) { $curr_pos = $pos; $delimiter = strlen($separator); $current_delimiter = $separator; } } if ($curr_pos > 0) { if ($add_separators) { $explode[] = substr($string, $offset , $curr_pos - $offset ); $explode[] = $current_delimiter; } else { $explode[] = substr($string, $offset - $old_delimiter , $curr_pos - $offset + $old_delimiter); } } $offset = $curr_pos + $delimiter; $old_delimiter = $delimiter; } return $explode; } /** * Trova la prima occorrenza tra una serie di delimitatori * @param Array $delimiters L'elenco delle parole per cui dividere la stringa * @param String $string la stringa da dividere * @return Array [position, delimiter] */ static function find_first($needles, $string, $offset = 0) { $curr_pos = strlen($string); $delimiter = ""; foreach ($needles as $needle) { $pos = stripos($string, $needle, $offset); if ($pos < $curr_pos && $pos !== false) { $curr_pos = $pos; $delimiter = $needle; } } if ($curr_pos == strlen($string)) { $curr_pos = 0; } return [$curr_pos, $delimiter]; } /** * Quando genero una form per modificare o inserire un record da una query * per ogni tabella collegata che restituisce risultati senza ID mostro tutti i campi della tabella * oltre a quelli selezionati dalla query. Modifica gli $items e i $field_name * @param ADFO_field_param[] $table_param */ /* static function adding_external_to_query_fields($info, &$item, &$table_param) { $fields = self::get_table_structure($info['schema']->orgtable); foreach ($fields as $field) { $new_field_name = 'edit_table['.$info['count_form_block'].']['.$info['schema']->orgtable.']['.$field->Field.'][]'; $find = false; foreach ($table_param as $param) { if ($param->name == $field->Field) { $find = true; break; } } if (!$find) { $item[$field->Field] = ''; $field_name[$field->Field] = $new_field_name ; if ($field->Type == "DATE") { $type = "DATE"; } elseif ($field->Type == "DATETIME") { $type = "DATETIME"; } elseif ($field->Type == "TEXT" || $field->Type == "MEDIUMTEXT" || $field->Type == "LONGTEXT" || $field->Type == "TINYTEXT") { $type = "TEXT"; } else { $type = "VARCHAR"; } // print " FIELD FIELD: ". $field->Field." \n\r"; $table_param[$field->Field] = new ADFO_field_param(['name'=>$field->Field,'orgtable'=>$info['schema']->orgtable, 'table'=>$info['schema']->table, 'label'=>$field->Field, 'field_name'=> "edit_table[".$info['count_form_block']."][".$info['schema']->orgtable."][".$field->Field."][]", 'form_type'=>$type]); } } // $item['my_custom_field'] = 23; // $field_name['my_custom_field'] = 'edit_table['.$info['schema']->orgtable.'][my_custom_column][]'; } */ /** * Nella visualizzazione dei dati e modifica, se c'è una query che ritorna più righe di risultato * cerco di raggrupparli per tabelle * @param Array $table_items il risultato di model->get_list * @param boolean $convert_value per le view * @param boolean $add_orphan per le view * @return Array in cui ogni item è il risultato di una tabella */ static function convert_table_items_to_group($table_items, $convert_value = true, $add_orphan = true) { $header = array_shift($table_items); // Divido in gruppi a seconda della tabella $items = []; foreach ($table_items as $item) { // preparo il gruppo $temp_groups = []; foreach ($header as $key=>$th) { // print "\n".$th['schema']->table."\n"; if ($th['schema']->table != "") { if (!isset($temp_groups[$th['schema']->table])) { $temp_groups[$th['schema']->table] = []; } if ($convert_value) { $temp_groups[$th['schema']->table][$key] = self::format_single_detail_value($item->$key); } else { $temp_groups[$th['schema']->table][$key] =$item->$key; } } else { if (!isset($temp_groups['__orphan__'])) { $temp_groups['__orphan__'] = []; } if ($convert_value) { $temp_groups['__orphan__'][$key] = self::format_single_detail_value($item->$key); } else { $temp_groups['__orphan__'][$key] = $item->$key; } } } // inserisco il gruppo $count_group = 1; foreach ($temp_groups as $key=>$group) { $count_group++; if ($key != '__orphan__') { $items["gr".$count_group] = $group; } else if ($add_orphan) { $items[$key] = $group; } } } return $items; } /** * Formatta un valore per la visualizzazione nel datail row */ static function format_single_detail_value($value) { $value = maybe_unserialize($value); $htmlentities = true; if (is_object($value) || is_array($value)) { $htmlentities = false; $value = dbp_items_list_setting::show_obj($value, 1, 20000, 100, 1000); } else { $value2 = json_decode($value, true); if (json_last_error() == JSON_ERROR_NONE) { $htmlentities = false; $value = dbp_items_list_setting::show_obj($value2, 1, 20000, 100, 1000); } } if ($htmlentities) { $value = htmlentities($value); } return $value; } /** * Aggiunge ai select le chiavi primarie per ogni tabella inserita * così da poter gestire form di modifica ed inserimento. * @deprecated v0.4 sostituito con $table_model->add_primary_ids * @return Void */ static function add_primary_ids_to_sql( &$table_model, &$table_items) { $current_query_select = $table_model->get_partial_query_select(); if (!is_countable($table_items)) return; $header = reset($table_items); if (!is_countable($header)) return; // Preparo i dati: // Trovo tutte le chiavi primarie di ogni tabella interessata // e raggruppo i campi per tabella $all_pri_ids = []; $field_group = []; foreach ($header as $key=>$th) { if ($th['schema']->orgtable != "") { // mi segno la chiave primaria della tabella if (!array_key_exists($th['schema']->orgtable, $all_pri_ids)) { $all_pri_ids[$th['schema']->orgtable] = self::get_primary_key($th['schema']->orgtable); } // Raggruppo i campi per tabella (alias) if ($th['schema']->table != "") { if (!isset($field_group[$th['schema']->table])) { $field_group[$th['schema']->table] = ['table'=>$th['schema']->orgtable, 'alias_table'=>$th['schema']->table, 'fields'=>[]]; } $field_group[$th['schema']->table]['fields'][] = $th['schema']; } } } $all_pri_ids = array_filter($all_pri_ids); // verifico se c'è la chiave primaria, oppure segno che deve essere aggiunta $add_select_pri = []; foreach ( $field_group as $group) { // group [table:String, fields:[]] $exist_pri = false; if (isset($all_pri_ids[$group['table']])) { // verifico se è già presente la chiave primaria foreach ($group['fields'] as $fields) { if ($fields->orgname == $all_pri_ids[$group['table']]) { $exist_pri = true; break; } } if (!$exist_pri) { $alias = ADFO_fn::get_column_alias($group['alias_table']."_".$all_pri_ids[$group['table']], $current_query_select); $add_select_pri[] = '`'. $group['alias_table'].'`.`'.$all_pri_ids[$group['table']].'` AS `'.$alias.'`'; $current_query_select .= " ".$alias; } } } // aggiungo i nuovi select, ripeto la query e aggiorno table_items if (count($add_select_pri) > 0) { $table_model->list_add_select(implode(", ", $add_select_pri)); $table_items = $table_model->get_list(); // se la query non risponde nessun dato (tipo una nuova tabella), allora ne creo uno dall'header if (is_countable($table_items) && count($table_items) == 1) { $header = reset($table_items); $new_item = (object)[]; foreach ($header as $kh=>$_) { $new_item->$kh = ""; } $table_items = [$header, $new_item]; } } } /** * inposta una variabile javascript per stampare le variabili pinacode */ static function echo_pinacode_variables_script($array) { $array = (array)$array; $shortcode = []; foreach($array as $key=>$value) { if (is_array($value)) { foreach($value as $kv=>$vv) { if (stripos($vv, " ") === false) { $shortcode[] = "[%".$key.".".$vv."]"; } else { $shortcode[] = "[%".$key." get=\"".addslashes($vv)."\"]"; } } } else { if (stripos($value, " ") === false) { $shortcode[] = "[%".$value."]"; } } } ?> 99 ) */ static function column_formatting_convert($format_csv_values, $value, $default = "") { if ($format_csv_values == NULL) return $default; $lines = explode(PHP_EOL, $format_csv_values); foreach ($lines as $line) { if (trim($line) != "") { $temp_array = str_getcsv($line); if (count($temp_array) > 1) { $if = trim(array_shift($temp_array)); if (substr($if,0,1) == "=" && strpos($if,"-") !== false) { $temp_if = explode("-",substr($if,1)); if ($value >= $temp_if[0] && $value <= $temp_if[1]) { return implode(", ", $temp_array); } } else if (substr($if,0,1) == '<') { $temp_if = trim(str_replace('<', '', substr($if,1))); if ($value < $temp_if) { return implode(", ", $temp_array); } } else if (substr($if,0,1) == '>') { $temp_if = trim(str_replace('>', '', substr($if,1))); if ($value > $temp_if) { return implode(", ", $temp_array); } } elseif (trim($value) == $if) { return implode(", ", $temp_array); } } } } return $default; } /** * Fa il parsing delle righe csv di options */ static function parse_csv_options($string) { if ($string == "") return []; $lines = explode(PHP_EOL, $string); $options = []; foreach ($lines as $line) { if (trim($line) != "") { $temp_array = str_getcsv($line); if (count($temp_array) == 1) { $options[] = ['label'=>self::all_trim(reset($temp_array))]; } else if (count($temp_array) >= 2) { $options[] = ['value'=>self::all_trim(array_shift($temp_array)), 'label'=>self::all_trim(implode(",", $temp_array))]; } } } return $options; } /** * Ritrasforma un array in una stringa per la visualizzazione nel textarea dell'options. * */ static function stringify_csv_options($array) { if (is_countable($array)) { $string = []; foreach ($array as $key=>$option) { if (strpos($option['label'], PHP_EOL)) { $option['label'] = '"'.$option['label'].'"'; } if (array_key_exists('value', $option)) { $string[] = $option['value'].", ". $option['label']; } else { $string[] = $option['label']; } } return implode(PHP_EOL, $string); } if (is_string($array)) { return $array; } else { return ''; } } /** * Stampa l'icona dell'info * @param String $file Il nome del file della documentazione senza .php * @param String $anchor L'id del div che si sta ancorando senza dbp_help_ */ static function echo_html_icon_help($file, $anchor) { ?>get_results('SELECT ID, post_title, post_excerpt as description, post_content FROM '.$wpdb->posts.' WHERE post_type ="dbp_list" AND `post_status` = "publish" ORDER BY ID DESC LIMIT 5'); $lists = []; if (is_countable($query_lists)) { foreach ($query_lists as $ql) { $ql->post_content = ADFO_functions_list::convert_post_content_to_list_params($ql->post_content); $lists[$ql->ID] = $ql; } } return $lists; } /** * Le tre funzioni is_form_open open_form e close form servono ad identificare se * c'è una form aperta dal plugin così da non aprirne altre se ci sono tabelle annidate. * Verifica se una form è aperta oppure no * * @return array */ static function is_form_open() { return self::$is_form_open; } static function set_open_form() { self::$is_form_open = true; } static function set_close_form() { self::$is_form_open = false; } /** * Verifica se è stato passato almeno un filtro */ static function is_query_filtered() { if (isset($_REQUEST['filter']['search']) && is_array($_REQUEST['filter']['search'])) { foreach ($_REQUEST['filter']['search'] as $key => $value) { if (isset($value['value']) && $value['value'] != "") { return true; } } } return false; } /** * Cerca e sostituisce nei dati serializzati */ static function search_and_resplace_in_serialize($obj, $search, $replace) { if (is_array($obj)) { foreach ($obj as $key=>$o) { if (is_array($o) || is_object($o)) { $obj[$key] = self::search_and_resplace_in_serialize($o, $search, $replace); } else { $obj[$key] = str_ireplace($search, $replace, $o); } } } else if (is_object($obj)) { foreach ($obj as $key=>$o) { if (is_array($o) || is_object($o)) { $obj->$key= self::search_and_resplace_in_serialize($o, $search, $replace); } else { $obj->$key = str_ireplace($search, $replace, $o); } } } else { $obj = str_ireplace($search, $replace, $obj); } return $obj; } /** * Ritorna una stringa alfanumerica che può essere passata nell'url con gli id del record. */ static function ids_url_encode($table_model, $current_item) { $primaries = $table_model->get_pirmaries(); $ids = ADFO_fn::data_primaries_values_from_schema($primaries, reset($table_model->items), $current_item); return rtrim(strtr(base64_encode(json_encode($ids)), '+/', '-_'), '='); } /** * Ritorna una stringa alfanumerica che può essere passata nell'url con gli id del record. */ static function ids_url_encode2($post_content, $current_item) { $primaries = $post_content['primaries']; if (count($primaries) == 0) { return ""; } $ids = ADFO_fn::data_primaries_values_from_schema($primaries, $post_content['schema'], $current_item); return rtrim(strtr(base64_encode(json_encode($ids)), '+/', '-_'), '='); } /** * Ricevuta la stringa alfanumerica ne ritorna l'arrai con gli id */ static function ids_url_decode($data) { $data = base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT)); $data = (array) json_decode(wp_unslash( $data )); $data = array_map('sanitize_text_field', $data); return $data; } /** * */ static function save_list_config($post_id, $config_array) { return update_post_meta($post_id, '_dbp_list_config', $config_array); } static function get_allowed_tag() { $allow = ['type'=>true,'name'=>true, 'data-rif'=>true, 'data-fieldkey'=>true, 'data-dbp_sort_key'=>true, 'data-column'=>true, 'data-dbp_sort_order'=>true, 'data-dbp_sort_key'=>true, 'onclick'=>true, 'class'=>true, 'id'=>true, 'value'=>true, 'style'=>true,'href'=>true,'src'=>true]; $allowed_tags = wp_kses_allowed_html('post'); $allowed_tags['script'] = true; $allowed_tags['style'] = true; $allowed_tags['span'] = array_merge( $allowed_tags['span'], $allow); $allowed_tags['div'] = array_merge( $allowed_tags['div'], $allow); $allowed_tags['input'] = $allow; $allowed_tags['a'] = array_merge( $allowed_tags['a'], $allow); $allowed_tags['select'] = $allow; $allowed_tags['option'] = $allow; $allowed_tags['textarea'] = $allow; return $allowed_tags; } } // setto 'inizio dell'esecuzione dello script; ADFO_fn::$execute_time_start = microtime(true);