コード例 #1
0
function saveCommaSeparated($list)
{
    $list = preg_replace('~[^\\d,]+~i', '', $list);
    $list = explode(',', $list);
    $list = array_empty_trim($list);
    $list = implode(',', $list);
    return $list;
}
コード例 #2
0
 if (empty($bot_name)) {
     $bot_errors[] = $lang->phrase('admin_spider_missing_bot_name');
 }
 if (count($bot_errors) > 0) {
     error("admin.php?action=spider&job=" . $job . iif($id > 0, '&id=' . $id), $bot_errors);
 } else {
     if ($job == 'add2') {
         $db->query("INSERT INTO {$db->pre}spider (name, user_agent, bot_ip, type, last_visit, pending_agent, pending_ip) VALUES ('{$bot_name}', '{$bot_agent}', '{$bot_ip}', '{$type}', '', '', '')");
     } else {
         $bot_visits = $gpc->get('visits', int);
         $reset_lastvisit = $gpc->get('reset_lastvisit', int);
         if ($reset_lastvisit == 1) {
             $result = $db->query("SELECT last_visit FROM {$db->pre}spider WHERE id = '{$id}'");
             $lvdat = $db->fetch_assoc($result);
             $lastvisits = explode('|', $lvdat['last_visit']);
             $lastvisits = array_empty_trim($lastvisits);
             if (count($lastvisits) > 0) {
                 $last = max($lastvisits);
             } else {
                 $last = '';
             }
         } else {
             $last = '';
         }
         $db->query("UPDATE {$db->pre}spider SET name='{$bot_name}', user_agent='{$bot_agent}', bot_ip='{$bot_ip}', bot_visits='{$bot_visits}'" . iif($reset_lastvisit > 0, ", last_visit = '{$last}'") . " WHERE id = '{$id}'");
     }
     if ($db->affected_rows() != 1) {
         error("admin.php?action=spider&job=" . iif($job == 'edit2', 'edit', 'add') . iif($id > 0, '&id=' . $id), "No data changed.");
     } else {
         $delobj = $scache->load('spiders');
         $delobj->delete();
コード例 #3
0
/**
 * Checks if the visitor is a robot.
 *
 * The id of the robot (set in database) will be returned or 0 on failure/not finding a matching robot.
 *
 * @return integer
 */
function log_robot()  {
	global $db, $config;

	foreach ($this->bots as $row) {
		$agent_match = 0;
		$ip_match = 0;

		// check for user agent match
		foreach (explode('|', $row['user_agent']) as $bot_agent) {
			if ($row['user_agent'] && !empty($bot_agent) && stristr($this->user_agent, $bot_agent) !== false) {
				$agent_match = 1;
				break;
			}
		}

		// check for ip match
		foreach (explode('|', $row['bot_ip']) as $bot_ip) {
			if ($row['bot_ip'] && !empty($bot_ip) && strpos($this->ip, $bot_ip) !== false) {
				$ip_match = 1;
				break;
			}
		}

		$today = time();

		if ($config['spider_logvisits'] == 2 && $config['spider_pendinglist'] != 1 && ($agent_match == 1 || $ip_match == 1)) {
			$db->query("UPDATE {$db->pre}spider SET bot_visits = bot_visits + 1 WHERE id = '{$row['id']}'");
		}
		if ($agent_match == 1 && $ip_match == 1) {
			if ($config['spider_logvisits'] == 1) {
				$result = $db->query("SELECT bot_visits, last_visit FROM {$db->pre}spider WHERE id = '{$row['id']}'");
				$row = array_merge($row, $db->fetch_assoc($result));

				$row['bot_visits']++;

				$last_visits = explode('|', $row['last_visit']);
				$last_visits[] = $today;
				$last_visit = implode("|", array_empty_trim($last_visits));

				$db->query("UPDATE {$db->pre}spider SET last_visit = '{$last_visit}', bot_visits = '{$row['bot_visits']}' WHERE id = '{$row['id']}'");
			}

			return $row['id'];
		}
		elseif ($agent_match == 1 || $ip_match == 1) {
			$column = ((!$agent_match) ? 'agent' : 'ip');
			$column2 = ((!$agent_match) ? 'user_agent' : 'bot_ip');
			$sqlselect = array();
			if ($config['spider_pendinglist'] == 1) {
				$sqlselect[] = "pending_{$column}";
				$sqlselect[] = $column2;
			}
			if ($config['spider_logvisits'] == 1) {
				$sqlselect[] = "bot_visits";
				$sqlselect[] = "last_visit";
			}
			if ($config['spider_logvisits'] == 1 || $config['spider_pendinglist'] == 1) {
				$result = $db->query("SELECT ".implode(', ', $sqlselect)." FROM {$db->pre}spider WHERE id = '{$row['id']}'");
				$row = array_merge($row, $db->fetch_assoc($result));
			}

			if ($config['spider_pendinglist'] == 1 && $db->num_rows($result) > 0) {
				$func = ((!$agent_match) ? 'stristr' : 'strpos');

				$pending_array = (( $row['pending_'.$column] ) ? explode('|', $row['pending_'.$column]) : array());

				$found = 0;
				$count = count($pending_array);
				if ($count > 0) {
					for ($loop = 0; $loop < $count; $loop+=2) {
						if ($pending_array[$loop] == ((!$agent_match) ? $this->user_agent : $this->ip)) {
							$found = 1;
							foreach (explode('|', $row[$column2]) as $entry) {
								if ($row[$column2] && !empty($entry) && $func(((!$agent_match) ? $this->user_agent : $this->ip), $entry) !== false) {
									$found = 0;
									break;
								}
							}
						}
					}
				}

				if ($found == 0)  {
					$pending_array[] = ((!$agent_match) ? str_replace("|", "&#124;", $this->user_agent) : $this->ip);
					$pending_array[] = ((!$agent_match) ? $this->ip : str_replace("|", "&#124;", $this->user_agent));
				}
				$pending = implode("|", array_empty_trim($pending_array));
			}
			if ($config['spider_logvisits'] == 1 && $db->num_rows($result) > 0) {
				$row['bot_visits']++;

				$last_visits = explode('|', $row['last_visit']);
				$last_visits[] = $today;
				$last_visit = implode("|", array_empty_trim($last_visits));
			}

			$sqlset = array();
			if ($config['spider_pendinglist'] == 1) {
				$sqlset[] = "pending_{$column} = '{$pending}'";
			}
			if ($config['spider_logvisits'] == 1) {
				$sqlset[] = "last_visit = '{$last_visit}'";
				$sqlset[] = "bot_visits = '{$row['bot_visits']}'";
			}
			if (count($sqlset) > 0 && ($config['spider_logvisits'] == 1 || $config['spider_pendinglist'] == 1)) {
				$db->query("UPDATE {$db->pre}spider SET ".implode(', ', $sqlset)." WHERE id = '{$row['id']}' LIMIT 1");
			}

			return $row['id'];
		}
	}

	return 0;
}
コード例 #4
0
 function error($errcomment)
 {
     // Try to get better results for line and file.
     if (viscacha_function_exists('debug_backtrace') == true) {
         $backtraceInfo = debug_backtrace();
         // 0 is class.mysql.php, 1 is the calling code...
         if (isset($backtraceInfo[1]) == true) {
             $errline = $backtraceInfo[1]['line'];
             $errfile = $backtraceInfo[1]['file'];
         }
     }
     if ($this->logerrors) {
         $logs = array();
         if (file_exists($this->errlogfile)) {
             $logs = file($this->errlogfile);
             $logs = array_empty_trim($logs);
         }
         $row = array($this->errno(), $this->errstr(), $errfile, $errline, $errcomment, $_SERVER['REQUEST_URI'], time(), PHP_VERSION . " (" . PHP_OS . ")");
         $row = array_map('makeOneLine', $row);
         $logs[] = implode("\t", $row);
         @file_put_contents($this->errlogfile, implode("\n", $logs));
     }
     $errcomment = nl2br($errcomment);
     return "Database error " . $this->errno() . ": " . $this->errstr() . "<br />File: {$errfile} on line {$errline}<br />Query: <code>{$errcomment}</code>";
 }