/** * Log to db * * Default log types: DEBUG|INFO|ERROR|INFO or use specific module name */ function log_message($type = 'UNDEFINED', $message = '', $userid = 0) { $log = array('log_created' => date('Y-m-d H:i:s', now()), 'log_type' => 'UNDEFINED', 'log_ip' => getRemoteIP(), 'log_user_agent' => '', 'log_user_id' => 0, 'log_user_name' => '', 'log_referrer_id' => 0, 'log_referrer_url' => '', 'log_data1' => '', 'log_data2' => '', 'log_data3' => '', 'log_msg' => ''); if (is_array($type)) { foreach ($type as $key => $value) { if (isset($log[$key])) { $log[$key] = $value; } } } else { $log['log_type'] = trim($type); $log['log_user_id'] = intval($userid); $log['log_msg'] = trim($message); } $log['log_type'] = strtoupper($log['log_type']); if ($log['log_user_agent'] == '') { $log['log_user_agent'] = empty($_SERVER['HTTP_USER_AGENT']) ? implode(', ', phpwcms_getUserAgent()) : $_SERVER['HTTP_USER_AGENT']; } if (empty($log['log_referrer_url']) && isset($_SERVER['HTTP_REFERER'])) { $log['log_referrer_url'] = $_SERVER['HTTP_REFERER']; } _dbInsert('phpwcms_log', $log, 'DELAYED'); }
/** * Parse and render text for device specific replacement tags * * * @param string * @return string */ function render_device($string) { if (empty($string)) { return ''; } if (empty($GLOBALS['phpwcms']['render_device']) || strpos($string, '<!--if:') === false) { return $string; } preg_match_all('/<!--!{0,1}if:(.+?)-->.*?<!--\\/!{0,1}if-->/s', $string, $matches); if (!isset($matches[0][0])) { return $string; } // get agent information $user_agent = phpwcms_getUserAgent(); // Test against $cache = array(); foreach ($matches[1] as $match) { $hash = md5($match); if (isset($cache[$hash])) { continue; } $cache[$hash] = true; $validity = array(); $values = explode(';', strtolower($match)); // parameters (AND) foreach ($values as $check) { // values (OR) $check = explode(':', trim($check)); $param = trim($check[0]); $value = isset($check[1]) ? explode(',', trim($check[1])) : array(); // mobile if ($param == 'mobile') { $validity[] = $user_agent['mobile'] ? 1 : 0; } elseif ($param == 'desktop') { $validity[] = $user_agent['mobile'] ? 0 : 1; } elseif ($param == 'platform') { // WinPhone, WinCE, Win, iOS, Mac, GoogleTV, Android, // BlackBerry, WebOS, Linux, Unix, Symbian, Other $validity[] = in_array(strtolower($user_agent['platform']), $value) ? 1 : 0; } elseif ($param == 'device') { // Default, Other, Smartphone, Tablet, Desktop, TV $validity[] = in_array(strtolower($user_agent['device']), $value) ? 1 : 0; } elseif ($param == 'browser') { // Other, Firefox, Chrome, Safari, IE, IEMobile, Opera, Mozilla $validity[] = in_array(strtolower($user_agent['agent']), $value) ? 1 : 0; } elseif ($param == 'engine') { // Gecko, Other, WebKit, Opera, KHTML, $validity[] = in_array(strtolower($user_agent['engine']), $value) ? 1 : 0; } elseif ($param == 'version') { // Only first value will be used for comparison // >Version, <Version, =Version, <=Version, >=Version if (preg_match('/^([<>=]+)(\\d+)$/', current($value), $value)) { $compare = $value[1]; $value = intval($value[2]); if ($compare == '=' && $user_agent['version'] == $value) { $validity[] = 1; } elseif ($compare == '<' && $user_agent['version'] < $value) { $validity[] = 1; } elseif ($compare == '>' && $user_agent['version'] > $value) { $validity[] = 1; } elseif ($compare == '<=' && $user_agent['version'] <= $value) { $validity[] = 1; } elseif ($compare == '>=' && $user_agent['version'] >= $value) { $validity[] = 1; } else { $validity[] = 0; } } else { $validity[] = 0; } } } $match = preg_quote($match); if (array_sum($validity) == count($values)) { // Valid – delete the !if and !if:default $string = preg_replace(array('/<!--if:' . $match . '-->(.*?)<!--\\/if-->/s', '/<!--!if:' . $match . '-->.*?<!--\\/!if-->/s', '/<!--!if:default-->.*?<!--\\/!if-->/s'), array('$1', '', ''), $string); } else { // Invalid – keep the !if and !if:default $string = preg_replace(array('/<!--if:' . $match . '-->.*?<!--\\/if-->/s', '/<!--!if:' . $match . '-->(.*?)<!--\\/!if-->/s', '/<!--!if:default-->(.*?)<!--\\/!if-->/s'), array('', '$1', '$1'), $string); } } return $string; }