0 && isset($length) && $length >= 0 ) { $pagination = sprintf( ' LIMIT %d OFFSET %d ', $start, $length ); } try { ob_start(); $fields = ['*']; $sql_filters = []; if (isset($filter['free_search']) === true && empty($filter['free_search']) === false ) { $sql_filters[] = sprintf( ' AND (`id_user` like "%%%s%%" OR `version` like "%%%s%%") ', $filter['free_search'], $filter['free_search'] ); } if (isset($order) === true) { $dir = 'asc'; if ($order == 'desc') { $dir = 'desc'; }; if (in_array( $sort_field, [ 'version', 'type', 'id_user', 'utimestamp', ] ) === true ) { $order_by = sprintf( 'ORDER BY `%s` %s', $sort_field, $dir ); } } // Retrieve data. $sql = sprintf( 'SELECT %s FROM tupdate_journal WHERE 1=1 %s %s %s', join(',', $fields), join(' ', $sql_filters), $order_by, $pagination ); $return = db_get_all_rows_sql($sql); if ($return === false) { $data = []; } else { $data = $return; } // Retrieve counter. $count = db_get_value('count(*)', '('.$sql.') t'); if ($data) { if ($config['prominent_time'] === 'timestamp') { $data = array_reduce( $data, function ($carry, $item) { // Transforms array of arrays $data into an array // of objects, making a post-process of certain fields. $tmp = (object) $item; date_default_timezone_set($user_timezone); $title = human_time_comparation($tmp->utimestamp); $tmp->utimestamp = ''.modules_format_timestamp($tmp->utimestamp).''; $carry[] = $tmp; return $carry; } ); } else if ($config['prominent_time'] === 'comparation') { $data = array_reduce( $data, function ($carry, $item) { // Transforms array of arrays $data into an array // of objects, making a post-process of certain fields. $tmp = (object) $item; date_default_timezone_set($user_timezone); $title = modules_format_timestamp($tmp->utimestamp); $tmp->utimestamp = ''.human_time_comparation($tmp->utimestamp).''; $carry[] = $tmp; return $carry; } ); } else if ($config['prominent_time'] === 'compact') { $data = array_reduce( $data, function ($carry, $item) { // Transforms array of arrays $data into an array // of objects, making a post-process of certain fields. $tmp = (object) $item; date_default_timezone_set($user_timezone); $title = modules_format_timestamp($tmp->utimestamp); $tmp->utimestamp = ''.human_time_comparation($tmp->utimestamp, 'tiny').''; $carry[] = $tmp; return $carry; } ); } else { $data = array_reduce( $data, function ($carry, $item) { // Transforms array of arrays $data into an array // of objects, making a post-process of certain fields. $tmp = (object) $item; date_default_timezone_set($user_timezone); $title = modules_format_timestamp($tmp->utimestamp); $tmp->utimestamp = ''.human_time_comparation($tmp->utimestamp).''; $carry[] = $tmp; return $carry; } ); } } // Datatables format: RecordsTotal && recordsfiltered. echo json_encode( [ 'data' => $data, 'recordsTotal' => $count, 'recordsFiltered' => $count, ] ); // Capture output. $response = ob_get_clean(); } catch (Exception $e) { echo json_encode(['error' => $e->getMessage()]); exit; } // If not valid, show error with issue. json_decode($response); if (json_last_error() == JSON_ERROR_NONE) { // If valid dump. echo $response; } else { echo json_encode( ['error' => $response] ); } exit; }