/** * Look through json files for a matching keys value, only checks top level keys * * @param string $path The file to search * @param array $search The values to find [["key" => string, "search" => string],[]...] */ public static function select_from_json_php_file($path, $search_array) { if (isset($search_array["key"])) { $search_array = array($search_array); } $data = RarsFileTools::read_file_contents($path, "json.php"); if (empty($data)) { return; } $match = array(); foreach ($data as $row) { $match_count = 0; foreach ($search_array as $search) { if (!isset($row->{$search}["key"]) || $row->{$search}["key"] != $search["search"]) { continue; } $match_count++; } if ($match_count == count($search_array)) { $match[] = $row; } } return $match; }
/** * Log Error * Log the error to log file * * @param array $error Error data array * @param string $log_book The log book to write to * @return bool False on fail */ public static function log_error($error, $log_book = 'rars-error-log') { if (empty($error)) { return false; } // get file contents $log = array(); if (is_file(RARS_BASE_PATH . "storage/log/{$log_book}.php")) { $log = RarsFileTools::read_file_contents(RARS_BASE_PATH . "storage/log/{$log_book}.php", 'array'); } // set date time $date_time = @date('d m Y - h:i:s', time()); $entry = "<?php /* [{$date_time}] [{$error['error']}]"; $entry .= isset($error['type']) ? " [type: {$error['type']}]" : ""; $entry .= isset($error['file']) ? " [file: {$error['file']}]" : ""; $entry .= isset($error['line']) ? " [line: {$error['line']}]" : ""; $entry .= " [message: {$error['string']}] */ ?>\n\r"; $log[] = $entry; if (count($log) > 100) { array_shift($log); } $log_string = implode('', $log); if (!is_dir(RARS_BASE_PATH . 'storage/log')) { mkdir(RARS_BASE_PATH . 'storage/log'); } RarsFileTools::write_file_contents(RARS_BASE_PATH . "storage/log/{$log_book}.php", $log_string); }