first commit

This commit is contained in:
2024-12-12 15:33:18 +01:00
commit 2c8998663e
3360 changed files with 777573 additions and 0 deletions

295
autoload/RestClient.php Normal file
View File

@@ -0,0 +1,295 @@
<?php
if (!function_exists('http_parse_headers')) {
function http_parse_headers($raw_headers)
{
$headers = array();
$key = ''; // [+]
foreach(explode("\n", $raw_headers) as $i => $h)
{
$h = explode(':', $h, 2);
if (isset($h[1]))
{
if (!isset($headers[$h[0]]))
$headers[$h[0]] = trim($h[1]);
elseif (is_array($headers[$h[0]]))
{
// $tmp = array_merge($headers[$h[0]], array(trim($h[1]))); // [-]
// $headers[$h[0]] = $tmp; // [-]
$headers[$h[0]] = array_merge($headers[$h[0]], array(trim($h[1]))); // [+]
}
else
{
// $tmp = array_merge(array($headers[$h[0]]), array(trim($h[1]))); // [-]
// $headers[$h[0]] = $tmp; // [-]
$headers[$h[0]] = array_merge(array($headers[$h[0]]), array(trim($h[1]))); // [+]
}
$key = $h[0]; // [+]
}
else // [+]
{ // [+]
if (substr($h[0], 0, 1) == "\t") // [+]
$headers[$key] .= "\r\n\t".trim($h[0]); // [+]
elseif (!$key) // [+]
$headers[0] = trim($h[0]); // [+]
} // [+]
}
return $headers;
}
}
/**
* PHP REST Client build with cURL
*
* @author Fabio Agostinho Boris <fabioboris@gmail.com>
*/
class RestClient
{
public $host; // the url to the rest server
public $port;
public $post_type = 'json';
public $timeout = 60;
private $token; // Auth token
private $ba_user;
private $ba_password;
public $last_url = '';
public $user_agent = '';
public function __construct($host, $token = null, $ba_user = null, $ba_password = null, $user_agent = null)
{
$arr_h = parse_url($host);
if (isset($arr_h['port'])) {
$this->port = (int)$arr_h['port'];
$this->host = str_replace(":".$this->port, "", $host);
} else {
$this->port = null;
$this->host = $host;
}
$this->token = $token;
$this->ba_user = $ba_user;
$this->ba_password = $ba_password;
$this->user_agent = $user_agent;
}
/**
* Returns the absolute URL
*
* @param string $url
*/
private function url($url = null)
{
$_host = rtrim($this->host, '/');
$_url = ltrim($url, '/');
return isset($this->port) ? "{$_host}:{$this->port}/{$_url}" : "{$_host}/{$_url}";
}
/**
* Returns the URL with encoded query string params
*
* @param string $url
* @param array $params
*/
private function urlQueryString($url, $params = null)
{
$qs = array();
if ($params) {
foreach ($params as $key => $value) {
$qs[] = "{$key}=" . urlencode($value);
}
}
$url = explode('?', $url);
if (isset($url[1])) $url_qs = $url[1];
$url = $url[0];
if (isset($url_qs)) $url = "{$url}?{$url_qs}";
if (count($qs)) return "{$url}?" . implode('&', $qs);
else return $url;
}
/**
* Make an HTTP request using cURL
*
* @param string $verb
* @param string $url
* @param array $params
*/
private function request($verb, $url, $params = array())
{
$ch = curl_init(); // the cURL handler
$url = $this->url($url); // the absolute URL
$request_headers = array();
if (!empty($this->token)) {
$request_headers[] = "Authorization: {$this->token}";
}
if ((!empty($this->ba_user)) AND (!empty($this->ba_password))) {
curl_setopt($ch, CURLOPT_USERPWD, $this->ba_user . ":" . $this->ba_password);
}
// encoded query string on GET
switch (true) {
case 'GET' == $verb:
$url = $this->urlQueryString($url, $params);
$this->last_url = $url;
break;
case in_array($verb, array('POST', 'PUT', 'DELETE')):
if ($this->post_type == 'json') {
$request_headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
} else {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
}
}
if (!empty($this->user_agent)) {
curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent);
}
// set the URL
curl_setopt($ch, CURLOPT_URL, $url);
// set the HTTP verb for the request
switch ($verb) {
case 'POST':
curl_setopt($ch, CURLOPT_POST, true);
break;
case 'PUT':
case 'DELETE':
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $verb);
}
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
if (!empty($this->port)) {
curl_setopt($ch, CURLOPT_PORT, $this->port);
}
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers = http_parse_headers(substr($response, 0, $header_size));
$response = substr($response, $header_size);
$http_code = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
$content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
$content_error = curl_error($ch);
curl_close($ch);
if (strpos($content_type, 'json')) $response = json_decode($response, true);
switch (true) {
case 'GET' == $verb:
if ($http_code !== 200) {
$this->throw_error($response, $http_code);
}
return $response;
case in_array($verb, array('POST', 'PUT', 'DELETE')):
if (($http_code !== 303) AND ($http_code !== 200)) {
$this->throw_error($response, $http_code);
}
if ($http_code === 200) {
return $response;
} else {
return str_replace(rtrim($this->host, '/') . '/', '', $headers['Location']);
}
}
}
private function throw_error($response, $http_code)
{
if (is_array($response) && array_key_exists('error', $response)) {
if ((isset($response['error']['message'])) AND (isset($response['error']['code']))) {
if (is_array($response['error']['message'])) {
throw new RestClientException(implode("; ", $response['error']['message']), (int)$response['error']['code'], $http_code);
} else {
throw new RestClientException($response['error']['message'], (int)$response['error']['code'], $http_code);
}
} else {
throw new RestClientException(implode("; ", $response), 0, $http_code);
}
} else {
if (is_string($response)) {
throw new RestClientException($response, 0, $http_code);
} else {
}
}
}
/**
* Make an HTTP GET request
*
* @param string $url
* @param array $params
*/
public function get($url, $params = array())
{
return $this->request('GET', $url, $params);
}
/**
* Make an HTTP POST request
*
* @param string $url
* @param array $params
*/
public function post($url, $params = array())
{
return $this->request('POST', $url, $params);
}
/**
* Make an HTTP PUT request
*
* @param string $url
* @param array $params
*/
public function put($url, $params = array())
{
return $this->request('PUT', $url, $params);
}
/**
* Make an HTTP DELETE request
*
* @param string $url
* @param array $params
*/
public function delete($url, $params = array())
{
return $this->request('DELETE', $url, $params);
}
}
class RestClientException extends Exception
{
protected $http_code;
public function __construct($message, $code = 0, $http_code, Exception $previous = null)
{
$this->http_code = $http_code;
parent::__construct($message, $code, $previous);
}
public function getHttpCode()
{
return $this->http_code;
}
public function __toString() {
return __CLASS__ . ": [{$this->code}]: {$this->message} (HTTP status code: {$this->http_code})\n";
}
}

323
autoload/RestClient3.php Normal file
View File

@@ -0,0 +1,323 @@
<?php
/**
* PHP 7.4-8.0 REST Client build with cURL
*
* @author Fabio Agostinho Boris <fabioboris@gmail.com>
* @added DataForSEO
*/
class RestClient {
public string $host; // the url to the rest server
public ?int $port = null;
public string $scheme;
public string $post_type = 'json';
public int $timeout = 60;
public int $connection_timeout = 10;
private ?string $token; // Auth token
private ?string $ba_user;
private ?string $ba_password;
private ?string $ba_ua;
public string $last_url = '';
public $last_response = null;
public $last_http_code = null;
public function __construct(string $host, string $token = null, string $ba_user = null, string $ba_password = null, string $ba_user_agent = null) {
$arr_h = parse_url($host);
if (isset($arr_h['port'])) {
$this->port = (int)$arr_h['port'];
$this->host = str_replace(":" . $this->port, "", $host);
} else {
$this->port = null;
$this->host = $host;
}
if (isset($arr_h['scheme'])) {
$this->scheme = $arr_h['scheme'];
}
$this->token = $token;
$this->ba_user = $ba_user;
$this->ba_password = $ba_password;
$this->ba_ua = $ba_user_agent;
}
/**
* Returns the absolute URL
*
* @param string $raw_headers
*/
private function http_parse_headers(string $raw_headers): array {
$headers = array();
$key = '';
foreach (explode("\n", $raw_headers) as $h) {
$h = explode(':', $h, 2);
if (isset($h[1])) {
if (!isset($headers[$h[0]])) {
$headers[$h[0]] = trim($h[1]);
} elseif (is_array($headers[$h[0]])) {
$headers[$h[0]] = array_merge($headers[$h[0]], array(trim($h[1])));
} else {
$headers[$h[0]] = array_merge(array($headers[$h[0]]), array(trim($h[1])));
}
$key = $h[0];
} else {
if (substr($h[0], 0, 1) == "\t") {
$headers[$key] .= "\r\n\t" . trim($h[0]);
} elseif (!$key) {
$headers[0] = trim($h[0]);
}
}
}
return $headers;
}
/**
* Returns the absolute URL
*
* @param string|null $url
* @return string
*/
private function url(string $url = null): string {
$_host = rtrim($this->host, '/');
$_url = ltrim($url, '/');
return "{$_host}:{$this->port}/{$_url}";
}
/**
* Returns the URL with encoded query string params
*
* @param string $url
* @param array|null $params
* @return string
*/
private function urlQueryString(string $url, array $params = null): string {
$qs = array();
if ($params) {
foreach ($params as $key => $value) {
$qs[] = "{$key}=" . urlencode($value);
}
}
$url = explode('?', $url);
if (isset($url[1])) {
$url_qs = $url[1];
}
$url = $url[0];
if (isset($url_qs)) {
$url = "{$url}?{$url_qs}";
}
if (count($qs)) {
return "{$url}?" . implode('&', $qs);
} else {
return $url;
}
}
/**
* Make an HTTP request using cURL
*
* @param string $verb
* @param string $url
* @param array $params
*/
private function request(string $verb, string $url, array $params = array()) {
$ch = curl_init(); // the cURL handler
$url = $this->url($url); // the absolute URL
$request_headers = array();
if (!empty($this->token)) {
$request_headers[] = "Authorization: {$this->token}";
}
if ((!empty($this->ba_user)) and (!empty($this->ba_password))) {
curl_setopt($ch, CURLOPT_USERPWD, $this->ba_user . ":" . $this->ba_password);
}
// encoded query string on GET
switch (true) {
case 'GET' == $verb:
$url = $this->urlQueryString($url, $params);
break;
case in_array($verb, array(
'POST',
'PUT',
'DELETE'
), false):
if ($this->post_type == 'json') {
$request_headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
} else {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
}
}
// set the URL
curl_setopt($ch, CURLOPT_URL, $url);
$this->last_url = $url;
// set the HTTP verb for the request
switch ($verb) {
case 'POST':
curl_setopt($ch, CURLOPT_POST, true);
break;
case 'PUT':
case 'DELETE':
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $verb);
}
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connection_timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
if (!empty($this->ba_ua)) {
curl_setopt($ch, CURLOPT_USERAGENT, $this->ba_ua);
}
if (!empty($this->port)) {
curl_setopt($ch, CURLOPT_PORT, $this->port);
}
if ((!empty($this->scheme)) and ($this->scheme == 'https')) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
} else {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers = $this->http_parse_headers(substr($response, 0, $header_size));
$response = substr($response, $header_size);
$http_code = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
$content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
$content_error = curl_error($ch);
//var_dump($content_error);
curl_close($ch);
if (strpos($content_type, 'json')) {
$response = json_decode($response, true);
}
$this->last_response = $response;
$this->last_http_code = $http_code;
switch (true) {
case 'GET' == $verb:
if ($http_code !== 200) {
if (is_array($response)) {
$this->throw_error($response, $http_code);
} else {
$this->throw_error(trim($content_error . "\n" . $response), $http_code);
}
}
return $response;
case in_array($verb, array(
'POST',
'PUT',
'DELETE'
), false):
if (($http_code !== 303) and ($http_code !== 200)) {
if (is_array($response)) {
$this->throw_error($response, $http_code);
} else {
$this->throw_error(trim($content_error . "\n" . $response), $http_code);
}
}
if ($http_code === 200) {
return $response;
} else {
return str_replace(rtrim($this->host, '/') . '/', '', $headers['Location']);
}
}
}
private function throw_error($response, $http_code) {
if (is_array($response) && array_key_exists('error', $response)) {
if ((isset($response['error']['message'])) and (isset($response['error']['code']))) {
if (is_array($response['error']['message'])) {
throw new RestClientException(implode("; ", $response['error']['message']), (int)$response['error']['code'], $http_code);
} else {
throw new RestClientException($response['error']['message'], (int)$response['error']['code'], $http_code);
}
} else {
throw new RestClientException(implode("; ", $response), 0, $http_code);
}
} else {
if (is_string($response)) {
return false;
// throw new RestClientException($response, 0, $http_code);
} else {
return false;
// throw new RestClientException(json_encode($response), 0, $http_code);
}
}
}
/**
* Make an HTTP GET request
*
* @param string $url
* @param array $params
*/
public function get($url, $params = array()) {
return $this->request('GET', $url, $params);
}
/**
* Make an HTTP POST request
*
* @param string $url
* @param array $params
*/
public function post($url, $params = array()) {
return $this->request('POST', $url, $params);
}
/**
* Make an HTTP PUT request
*
* @param string $url
* @param array $params
*/
public function put($url, $params = array()) {
return $this->request('PUT', $url, $params);
}
/**
* Make an HTTP DELETE request
*
* @param string $url
* @param array $params
*/
public function delete($url, $params = array()) {
return $this->request('DELETE', $url, $params);
}
}
class RestClientException extends Exception {
protected $http_code;
public function __construct(string $message, int $code = 0, int $http_code = 0, Exception $previous = null) {
$this->http_code = $http_code;
parent::__construct($message, $code, $previous);
}
/**
* @return int the http code error representation of the exception.
*/
public function getHttpCode() {
return $this->http_code;
}
/**
* @return string the string representation of the exception.
*/
public function __toString(): string {
return __CLASS__ . ": [{$this->code}]: {$this->message} (HTTP status code: {$this->http_code})\n";
}
}

1348
autoload/Savant3.php Normal file

File diff suppressed because it is too large Load Diff

390
autoload/class.Cron.php Normal file
View File

@@ -0,0 +1,390 @@
<?php
class Cron
{
public static function fill_missing_positions()
{
global $mdb;
$sites = $mdb -> select( 'pro_rr_sites', [ 'id', 'name' ], [ 'OR' => [ 'date_confirm' => date( 'Y-m-d' ), 'need_confirm' => 0 ] ] );
if ( is_array( $sites ) and !empty( $sites ) ) foreach ( $sites as $site )
{
$phrases = $mdb -> select( 'pro_rr_phrases', [ 'id', 'phrase' ], [ 'AND' => [ 'filled_missing_positions' => 0, 'site_id' => $site['id'] ], 'ORDER' => [ 'phrase' => 'ASC' ], 'LIMIT' => 1 ] );
if ( is_array( $phrases ) and !empty( $phrases ) ) foreach ( $phrases as $phrase )
{
$positions = $mdb -> select( 'pro_rr_phrases_positions', [ 'position', 'date' ], [ 'AND' => [ 'phrase_id' => $phrase['id'] ], 'ORDER' => [ 'date' => 'DESC' ], 'LIMIT' => 1 ] );
if ( is_array( $positions ) and !empty( $positions ) ) foreach ( $positions as $position )
{
$previous_position = $mdb -> get( 'pro_rr_phrases_positions', [ 'date', 'position', 'url', 'map' ], [ 'AND' => [ 'phrase_id' => $phrase['id'], 'date[!]' => $position[ 'date' ] ], 'ORDER' => [ 'date' => 'DESC' ] ] );
if ( $previous_position['position'] != 0 and $position['position'] != 0 )
$average_position = round( ( $position['position'] + $previous_position['position'] ) / 2, 0 );
else if ( $previous_position['position'] == 0 and $position['position'] != 0 )
$average_position = $position['position'];
else if ( $previous_position['position'] != 0 and $position['position'] == 0 )
$average_position = $previous_position['position'];
else
$average_position = 0;
$begin = new DateTime( date( 'Y-m-d', strtotime( '+1 days', strtotime( $previous_position['date'] ) ) ) );
$end = new DateTime( date( 'Y-m-d', strtotime( '-1 days', strtotime( $position['date'] ) ) ) );
for ( $i = $begin; $i <= $end; $i -> modify( '+1 day' ) )
{
if ( !$mdb -> count( 'pro_rr_phrases_positions', [ 'AND' => [ 'phrase_id' => $phrase['id'], 'date' => $i -> format( "Y-m-d" ) ] ] ) )
{
$mdb -> insert( 'pro_rr_phrases_positions', [
'position' => $average_position > 10 ? rand( $average_position - 1, $average_position + 1 ) : $average_position,
'phrase_id' => $phrase['id'],
'url' => $previous_position['url'],
'map' => $previous_position['map'],
'date' => $i -> format( "Y-m-d" )
] );
}
}
$mdb -> update( 'pro_rr_phrases', [ 'filled_missing_positions' => 1 ], [ 'id' => $phrase['id'] ] );
}
else
{
$mdb -> update( 'pro_rr_phrases', [ 'filled_missing_positions' => 1 ], [ 'id' => $phrase['id'] ] );
}
return [
'status' => 'ok',
'msg' => 'Uzupełniam brakujące pozycje: <b>' . $site['name'] . '</b> - <b>' . $phrase['phrase'] . '</b>.'
];
}
}
return [ 'status' => 'empty' ];
}
static public function archive_empty()
{
global $mdb;
$results = $mdb -> query( 'SELECT * FROM archive_phrases_positions WHERE date < \'' . date( 'Y-m-d', strtotime( '-4 years', time() ) ) . '\' ORDER BY id ASC LIMIT 1' ) -> fetchAll();
if ( is_array( $results ) and !empty( $results ) )
{
foreach ( $results as $row )
{
$mdb -> delete( 'archive_phrases_positions', [ 'id' => $row['id'] ] );
return [
'status' => 'ok',
'msg' => 'Usuwam stare pozycje fraz z archiwum | ID: <b>' . $row['id'] . '</b>, data: <b>' . $row['date'] . '</b>, URL: <b>' . $row['url'] . '</b>'
];
}
}
else
return [ 'status' => 'empty' ];
}
public static function archive_positions()
{
global $mdb;
$results = $mdb -> query( 'SELECT * FROM pro_rr_phrases_positions WHERE date LIKE \'' . date( 'Y-m', strtotime( '-2 years', time() ) ) . '%\' LIMIT 1' ) -> fetchAll();
if ( is_array( $results ) and !empty( $results ) )
{
foreach ( $results as $row )
{
$mdb -> insert( 'archive_phrases_positions', [
'phrase_id' => $row['phrase_id'],
'position' => $row['position'],
'url' => $row['url'],
'map' => $row['map'],
'date' => $row['date']
] );
$mdb -> delete( 'pro_rr_phrases_positions', [ 'id' => $row['id'] ] );
return [
'status' => 'ok',
'msg' => 'Archiwizuję stare pozycje fraz | ID: <b>' . $row['id'] . '</b>, data: <b>' . $row['date'] . '</b>'
];
}
}
else
return [ 'status' => 'empty' ];
}
public static function check_proxy()
{
global $mdb, $config;
$results = $mdb -> query( 'SELECT '
. 'id, proxy, errors '
. 'FROM '
. 'pro_proxy_servers '
. 'WHERE '
. '( DATE_ADD( last_checked, INTERVAL 1 DAY ) < NOW() OR last_checked IS NULL ) '
. 'ORDER BY '
. 'last_checked ASC '
. 'LIMIT 1' ) -> fetchAll();
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
{
$result = \GoogleSite::checkProxyServerVersion( $row['proxy'] );
if ( $result['code'] == 404 or $result['result'] == '' and $result['code'] == 0 )
{
$mdb -> update( 'pro_proxy_servers', [ 'errors' => $row['errors'] + 1, 'last_checked' => \S::getDate() ], [ 'id' => $row['id'] ] );
$mdb -> delete( 'pro_proxy_servers', [ 'errors[>=]' => 7 ] );
return [
'status' => 'ok',
'msg' => 'Sprawdzam poprawność proxy serwerowego: ' . $row['proxy'] . ' - ' . floatval( $result )
];
}
$ip = $result['info']['primary_ip'];
if ( !$result || $result != $config['proxy']['s-version'] )
$mdb -> update( 'pro_proxy_servers', [ 'last_checked' => \S::getDate(), 'errors' => 0, 'enabled' => 0, 'ip' => $ip ], [ 'id' => $row['id'] ] );
else
$mdb -> update( 'pro_proxy_servers', [ 'last_checked' => \S::getDate(), 'errors' => 0, 'enabled' => 1, 'ip' => $ip ], [ 'id' => $row['id'] ] );
return [
'status' => 'ok',
'msg' => 'Sprawdzam poprawność proxy serwerowego: ' . $row['proxy'] . ' - ' . floatval( $result )
];
}
return [ 'status' => 'empty' ];
}
static public function get_phrases_positions_dfs3()
{
global $mdb;
$row = $mdb -> get( 'pro_rr_phrases', '*', [ 'AND' => [ 'ds_ready' => 1, 'ds_id[!]' => null ] ] );
if ( $row )
{
$client = new RestClient( 'https://api.dataforseo.com/', null, 'pyziak84@gmail.com', '0p4rYWDNoK63eUUw' );
$result = $client->get('/v3/serp/google/organic/task_get/advanced/' . $row['ds_id'] );
if ( $result['status_code'] == '20000' )
{
$sites = $result['tasks'][0]['result'][0]['items'];
foreach ( $sites as $site )
{
if ( $site['type'] == 'organic' and \S::get_domain( $site['url'] ) == \S::get_domain( 'http://' . \factory\Ranker::get_domain_by_id( $row['site_id'] ) ) )
{
$phrase_position = $site['rank_group'];
$site_url = $site['url'];
break;
}
}
if ( $mdb -> count( 'pro_rr_phrases_positions', [ 'AND' => [ 'phrase_id' => $row['id'], 'date' => date( 'Y-m-d' ) ] ] ) )
{
$mdb -> update( 'pro_rr_phrases_positions', [
'position' => (int)$phrase_position,
'url' => $site_url,
], [
'AND' => [
'phrase_id' => $row['id'],
'date' => date( 'Y-m-d' )
]
] );
}
else
{
$mdb -> insert( 'pro_rr_phrases_positions', [
'phrase_id' => $row['id'],
'position' => (int)$phrase_position,
'url' => $site_url,
'date' => date( 'Y-m-d' )
] );
$last_id = $mdb -> get( 'phrase_positions_statistic', 'id', [ 'phrase_id' => $row['id'], 'ORDER' => [ 'date' => 'DESC' ] ] );
if ( $last_id )
$mdb -> query( 'DELETE FROM phrase_positions_statistic WHERE phrase_id = ' . $row['id'] . ' AND id NOT IN ( ' . $last_id . ' )' );
$mdb -> insert( 'phrase_positions_statistic', [
'phrase_id' => $row['id'],
'position' => $site['rank_group'],
'date' => date( 'Y-m-d' )
] );
}
$phrase_position = $site['rank_group'];
$mdb -> update( 'pro_rr_phrases', [ 'last_checked' => date( 'Y-m-d' ), 'filled_missing_positions' => 0, 'ds_id' => null, 'ds_ready' => 0 ], [ 'id' => $row['id'] ] );
return [
'status' => 'ok',
'msg' => 'Pobieramy wyniki dla frazy: <b>' . $row['phrase'] . '</b> - <b>' . (int)$phrase_position . '</b> - (API 3.0)'
];
}
return [
'status' => 'ok',
'msg' => 'Pobieramy wyniki dla frazy: <b>' . $row['phrase'] . '</b> - BŁĄD - (API 3.0)'
];
}
}
static public function post_phrases_positions_dfs3()
{
global $mdb;
$sql = 'SELECT * FROM ( '
. 'SELECT '
. 'prp.id, phrase, url, localization, last_checked, days_offset, prs.name '
. 'FROM '
. 'pro_rr_phrases AS prp, pro_rr_sites AS prs '
. 'WHERE '
. 'prs.id = prp.site_id '
. 'AND '
. 'last_checked != \'' . date( 'Y-m-d' ) . '\' '
. 'AND '
. '( prp.date_end >= \'' . date( 'Y-m-d' ) . '\' OR prp.date_end IS NULL ) '
. 'AND '
. '( prp.date_start <= \'' . date( 'Y-m-d' ) . '\' OR prp.date_start IS NULL ) '
. 'AND '
. '( prs.date_start <= \'' . date( 'Y-m-d' ) . '\' OR prs.date_start IS NULL ) '
. 'AND '
. '( prs.date_end >= \'' . date( 'Y-m-d' ) . '\' OR prs.date_end IS NULL ) '
. 'AND '
. 'ds_id IS NULL '
. ') AS q1 '
. 'WHERE '
. '( '
. 'days_offset IS NULL '
. 'OR '
. 'days_offset IS NOT NULL AND DATE( DATE_ADD( last_checked, INTERVAL +days_offset DAY ) ) <= CURRENT_DATE '
. ') OR last_checked = \'2012-01-01\' '
. 'ORDER BY '
. 'name ASC, phrase ASC '
. 'LIMIT 1';
$results = $mdb -> query( $sql ) -> fetchAll( \PDO::FETCH_ASSOC );
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
{
$client = new RestClient( 'https://api.dataforseo.com/', null, 'pyziak84@gmail.com', '0p4rYWDNoK63eUUw' );
if ( $row['localization'] and (int)$row['localization'] )
{
$post_array[0] = array(
"language_name" => "Polish",
"location_code" => $row['localization'],
"keyword" => mb_convert_encoding( $row['phrase'], "UTF-8" ),
"priority" => 1,
'postback_data' => 'advanced',
'postback_url' => 'http://www.rank24.pl/dsf.php?d4s-id=$id'
);
}
else
{
$post_array[0] = array(
"language_name" => "Polish",
"location_code" => $row['localization'],
"keyword" => mb_convert_encoding( $row['phrase'], "UTF-8" ),
"priority" => 1,
'postback_data' => 'advanced',
'postback_url' => 'http://www.rank24.pl/dsf.php?d4s-id=$id'
);
}
$task_post_result = $client -> post( '/v3/serp/google/organic/task_post', $post_array );
if ( $task_post_result['status_code'] == '20000' )
{
$mdb -> update( 'pro_rr_phrases', [ 'ds_id' => $task_post_result['tasks'][0]['id'], 'ds_date' => date( 'Y-m-d' ) ], [ 'id' => $row['id'] ] );
return [
'status' => 'ok',
'msg' => 'Wysyłam do sprawdzenia frazę: <b>' . $row['phrase'] . '</b> - <b>' . $row['url'] . '</b> - (API 3.0) - ' . $task_post_result['tasks'][0]['id']
];
}
}
return [ 'status' => 'empty' ];
}
public static function check_phrases_positions_dfs()
{
global $mdb;
include 'autoload/RestClient.php';
$sql = 'SELECT * FROM ( '
. 'SELECT '
. 'prp.id, phrase, url, localization, last_checked, days_offset, prs.name '
. 'FROM '
. 'pro_rr_phrases AS prp, pro_rr_sites AS prs '
. 'WHERE '
. 'prs.id = prp.site_id '
. 'AND '
. 'last_checked != \'' . date( 'Y-m-d' ) . '\' '
. 'AND '
. '( prp.date_end >= \'' . date( 'Y-m-d' ) . '\' OR prp.date_end IS NULL ) '
. 'AND '
. '( prp.date_start <= \'' . date( 'Y-m-d' ) . '\' OR prp.date_start IS NULL ) '
. 'AND '
. '( prs.date_start <= \'' . date( 'Y-m-d' ) . '\' OR prs.date_start IS NULL ) '
. 'AND '
. '( prs.date_end >= \'' . date( 'Y-m-d' ) . '\' OR prs.date_end IS NULL ) '
. 'AND '
. 'ds_id IS NULL '
. ') AS q1 '
. 'WHERE '
. '( '
. 'days_offset IS NULL '
. 'OR '
. 'days_offset IS NOT NULL AND DATE( DATE_ADD( last_checked, INTERVAL +days_offset DAY ) ) <= CURRENT_DATE '
. ') OR last_checked = \'2012-01-01\' '
. 'ORDER BY '
. 'name ASC, phrase ASC '
. 'LIMIT 1';
$results = $mdb -> query( $sql ) -> fetchAll( \PDO::FETCH_ASSOC );
if ( is_array( $results ) and !empty( $results ) )
{
foreach ( $results as $row ) {
$client = new RestClient( 'https://api.dataforseo.com/', null, 'pyziak84@gmail.com', '0p4rYWDNoK63eUUw' );
if ( $row['localization'] and (int)$row['localization'] ) {
$post_array[0] = array(
"priority" => 1,
"site" => \S::get_domain( 'https://' . $row['url'] ),
"se_id" => 21,
"loc_id" => $row['localization'],
"key" => mb_convert_encoding( $row['phrase'], "UTF-8" ),
"key_id" => null,
'se_id' => 3433,
'postback_url' => 'http://www.rank24.pl/dsf.php'
);
}
else {
$post_array[0] = array(
"priority" => 1,
"site" => \S::get_domain( 'https://' . $row['url'] ),
"se_id" => 21,
"loc_name_canonical" => $row['localization'] ? $row['localization'] : 'Poland',
"key" => mb_convert_encoding( $row['phrase'], "UTF-8" ),
"key_id" => null,
'se_id' => 3433,
'postback_url' => 'http://www.rank24.pl/dsf.php'
);
}
$task_post_result = $client -> post( 'v2/rnk_tasks_post', array( 'data' => $post_array ) );
if ( $task_post_result['status'] == 'ok' ) {
$mdb -> update( 'pro_rr_phrases', [ 'ds_id' => $task_post_result['results'][0]['task_id'], 'ds_date' => date( 'Y-m-d' ) ], [ 'id' => $row['id'] ] );
if ( $row['localization'] != '' and !is_int( $row['localization'] ) ) {
$mdb -> update( 'pro_rr_phrases', [ 'localization' => $task_post_result['results'][0]['loc_id'] ], [ 'id' => $row['id'] ] );
}
return [
'status' => 'ok',
'msg' => 'Wysyłam do sprawdzenia frazę: <b>' . $row['phrase'] . '</b> - <b>' . $row['url'] . '</b>.'
];
}
}
}
return [ 'status' => 'empty' ];
}
}

222
autoload/class.DataBase.php Normal file
View File

@@ -0,0 +1,222 @@
<?php
class DataBase
{
public function SaveData( $db_edit_table , $db_edit_key , $db_edit_val , $db_edit_pols , $db_edit_pass , $db_edit_pols_t )
{
global $sys , $lang , $db;
$sql = '';
if ( is_array( $db_edit_pols ) ) foreach ( $db_edit_pols as $val )
{
if ( $sql && $val != 'image' )
$sql .= ',';
if ( $val != 'image' )
$sql .= $val . "='" . addslashes( \S::saveString( \S::get( $val ) ) ) . "'";
}
if ( $db_edit_pass )
{
$name = $db_edit_pass['nazwa1'];
$pass1 = \S::saveString( \S::get( $name ) );
$pass2 = \S::saveString( \S::get( $name . '_repeat' ) );
if ( $pass1 != $pass2 )
\S::alert( $lang -> getTrans( 'T_HASLA_ROZNE' ) );
else
{
if ( strlen($pass1) >= 5 )
{
if ( $sql )
$sql .= ',';
$sql .= $name . "='" . md5($pass1) . "'";
}
else
{
if ( strlen( $pass1 ) < 5 )
\S::alert( $lang -> getTrans( 'T_HASLA_ZA_KROTKIE' ) );
}
}
}
if ( $db_edit_table && $db_edit_key && $db_edit_val && $db_edit_pols )
{
$db_edit_table = \S::saveString( $db_edit_table );
$db_edit_key = \S::saveString( $db_edit_key );
$db_edit_val = \S::saveString( $db_edit_val );
$query = $db -> query( "UPDATE " . $db_edit_table . " SET " . $sql . " WHERE " . $db_edit_key . "='" . $db_edit_val . "'" );
for ( $i = 0; $i < count( $db_edit_pols_t ); $i++ )
{
if ( $db_edit_pols_t[$i] == 'file' && is_array( $_FILES[$db_edit_pols[$i]] ) )
{
$file = $_FILES[$db_edit_pols[$i]];
if ( $file['name'] )
$name = explode( '.' , $file['name'] );
if ( isset( $name ) && is_array( $name ) )
$patch = '../' . \S::get( 'image_folder' ) . \S::seo( $name[0]) . '.' . $name[1];
if ( $file['type'] == 'image/pjpeg' || $file['type'] == 'image/jpg' || $file['type'] == 'image/jpeg' || $file['type'] == 'image/gif' || $file['type'] == 'image/png' )
{
if ( $file['size'] < 500000 )
{
$x = getimagesize( $file['tmp_name'] );
if ( is_array( $x ) or $x[0] < 2)
{
$query = $db -> prepare( "SELECT " . $db_edit_pols[$i] . " FROM " . $db_edit_table . " WHERE " . $db_edit_key . "='" . $db_edit_val . "'" );
$query -> execute();
if ( $query -> rowCount() ) while ( $row = $query -> fetch() )
{
$plik = '../' . $row[0];
if ( file_exists( $plik ) && $row[0] )
unlink( $plik );
}
$query -> closeCursor();
if ( file_exists( $patch ) )
unlink( $patch );
rename( $file['tmp_name'] , $patch );
chmod( $patch , 0755 );
$patch = str_replace( '../' , '' , $patch );
$query = $db -> query( "UPDATE " . $db_edit_table . " SET " . $db_edit_pols[$i] ."='" . $patch . "' WHERE " . $db_edit_key . "='" . $db_edit_val . "'" );
}
}
}
}
}
\S::alert( 'Zaktualizowano wybrany element.' );
}
$saveFlag = true;
\S::deleteCacheAdmin();
\S::deleteCache();
}
public function addData( $db_edit_table , $db_edit_pols , $db_edit_pols_hidden , $db_edit_pols_t , $time , $db_edit_pass = '' )
{
global $sys , $lang , $db;
$flag = true;
$idk = '';
$key = '';
$val = '';
$value = '';
if ( $time == \S::get_session( 'dbedit_add_time' ) ) return false;
if ( is_array( $db_edit_pols ) ) foreach ( $db_edit_pols as $val )
{
if ( !$idk )
$idk = $val;
if ( $key )
$key .= ',';
if ( $value )
$value .= ',';
$key .= $val;
$value .= "'" . \S::saveString( \S::get( $val ) ) . "'";
}
if ( is_array( $db_edit_pols_hidden ) ) foreach ( $db_edit_pols_hidden as $val )
{
if ( $key )
$key .= ',';
if ( $value )
$value .= ',';
$key .= $val;
$value .= "'" . \S::saveString( \S::get( $val ) ) . "'";
}
if ( $db_edit_pass )
{
$name = $db_edit_pass['nazwa1'];
$pass1 = \S::saveString( \S::get( $name ) );
$pass2 = \S::saveString( \S::get( $name . '_repeat' ) );
if ( $pass1 != $pass2 )
{
\S::alert( $lang -> getTrans( 'T_HASLA_ROZNE' ) );
$flag = false;
}
else
{
if ( strlen($pass1) >= 5 )
{
if ( $key )
$key .= ',';
$key .= $name;
if ( $value )
$value .= ',';
$value .= "'" . md5( $pass1 ) . "'";
}
else
{
if ( $pass1 )
{
$flag = false;
\S::alert( $lang -> getTrans( 'T_HASLA_ZA_KROTKIE' ) );
}
}
}
}
if ( $db_edit_table && $db_edit_pols && $flag )
{
$check = true;
$db_edit_table = \S::saveString( $db_edit_table );
try
{
$query = $db -> prepare( "INSERT INTO " . $db_edit_table . " (" . $key . ") VALUES (" . $value . ")");
$query -> execute();
}
catch(PDOException $e)
{
$check = false;
}
$id = $db -> lastInsertId();
$query -> closeCursor();
for ( $i = 0; $i < count( $db_edit_pols_t ); $i++ )
{
if ( $db_edit_pols_t[$i] == 'file' && is_array($_FILES[$db_edit_pols[$i]]) )
{
$file = $_FILES[$db_edit_pols[$i]];
$name = explode( '.' , $file['name'] );
$patch = '../' . \S::get( 'image_folder' ) . \S::seo( $name[0] ) . '.' . $name[1];
if ( $file['type'] == 'image/pjpeg' || $file['type'] == 'image/jpg' || $file['type'] == 'image/jpeg' || $file['type'] == 'image/gif' || $file['type'] == 'image/png' )
{
if ( $file['size'] < 500000 )
{
$x = getimagesize( $file['tmp_name'] );
if ( is_array( $x ) or $x[0] < 2)
{
if ( file_exists( $patch ) )
unlink( $patch );
@rename( $file['tmp_name'] , $patch );
chmod( $patch , 0755 );
$patch = str_replace( '../' , '' , $patch );
$query = $db -> prepare( "UPDATE " . $db_edit_table . " SET " . $db_edit_pols[$i] . "='" . $patch . "' WHERE id='" . $id . "'" );
$query -> execute();
$query -> closeCursor();
}
}
}
}
}
if ( $check )
\S::alert( 'Dodano nowy element.' );
else
\S::alert( 'Nieprawidłowe dane.' );
$addFlag = true;
}
else
\S::alert( 'Nieprawidłowe dane.' );
\S::set_session( 'dbedit_add_time' , $time );
\S::deleteCacheAdmin();
\S::deleteCache();
}
}
?>

View File

@@ -0,0 +1,525 @@
<?php
class DataBrowse {
private $_table;
private $_filtr;
private $_field_id;
private $_field_name;
private $_field_link;
private $_field_style;
private $_quantity;
private $_select;
private $_field_simple_id;
private $_param;
private $_field_action;
private $_field_tran;
private $_row_number;
private $_count;
private $_page_number;
private $_sort;
private $_filtr_id;
private $_filtr_name;
private $_filtr_field_tran;
private $_filtr_quantity;
private $_db_filtr;
private $_db_filtr_value;
private $_is_lp;
private $_lp;
private $_group_by;
private $_filtr_type;
private $_debug;
private $_limit = 10;
private $_filed_sort;
private $_sort_name;
private $_sort_way;
private $_paging_adress = './';
private $_cut;
private $_checkbox = false;
private $_menu = false;
function DataBrowse( $table , $filtr = '' , $debug = false )
{
$this -> _table = $table;
$this -> _filtr = $filtr;
$this -> _quantity = 0;
$this -> _filtr_quantity = 0;
$this -> _debug = $debug;
}
public function addMenu( $html )
{
$this -> _menu = $html;
}
public function addCheckbox()
{
$this -> _checkbox = true;
}
function addGroupBy( $value )
{
$this -> _group_by = $value;
}
function addLp()
{
$this -> _is_lp = true;
$this -> _lp = true;
}
function setLimit( $val )
{
$this -> _limit = $val;
}
function addFiltr( $id , $nazwa , $tab = '' , $sql = '' )
{
global $db;
if ( $nazwa )
{
$this -> _filtr_id[ $this -> _filtr_quantity ] = $id;
$this -> _filtr_name[ $this -> _filtr_quantity ] = $nazwa;
if ( $sql )
{
$query = $db -> prepare( $sql );
$query -> execute();
if ( $query -> rowCount() ) while ( $row = $query -> fetch() )
$tab[ $row[0] ] = $row[1];
$query -> closeCursor();
}
if ( is_array($tab) )
$this -> _filtr_field_tran[$this -> _filtr_quantity] = $tab;
else
{
if ( !$tab )
$tab = 'text';
$this -> _filtr_type[ $this -> _filtr_quantity ] = $tab;
}
$this -> _filtr_quantity++;
}
}
function addPosition( $id , $nazwa , $link = '' , $tab = '' , $style = '' , $sort = false, $cut = true )
{
global $db;
if ( $nazwa )
{
$this -> _field_id[ $this -> _quantity ] = $id;
$this -> _field_name[ $this -> _quantity ] = $nazwa;
$this -> _field_link[ $id ] = $link;
$this -> _field_style[ $id ] = $style;
$this -> _filed_sort[ $this -> _quantity ] = $sort;
$this -> _field_cut[ $id ] = $cut;
if ( is_array( $tab ) )
$this -> _field_tran[$id] = $tab;
else
{
if ( $tab )
{
$query = $db -> prepare($tab);
$query -> execute();
if ( $query -> rowCount() ) while ( $res = $query -> fetch() )
$tabs[$res[0]] = $res[1];
$query -> closeCursor();
$tabs[0] = '';
$this -> _field_tran[$id] = $tabs;
}
}
$this -> _quantity ++;
}
}
function addPositionSimple( $id , $nazwa , $link = '' , $akcja = '' , $style = '' )
{
$this -> _field_simple_id[$this -> _quantity] = $id;
$this -> _field_name[$this -> _quantity] = $nazwa;
$this -> _field_link[$id] = $link;
$this -> _field_action[$id] = $akcja;
$this -> _field_style[$id] = $style;
$this -> _filed_sort[ $this -> _quantity ] = false;
$this -> _quantity++;
}
function setParam( $param )
{
$this -> _param = $param;
}
function addSort( $sort )
{
$this -> _sort = $sort;
}
function draw()
{
global $db , $bs;
$out = '';
$filtr_ttext = '';
$filtr_combo = '';
$table_values = '';
$filtr_text = '';
if ( \S::get( 'bs' ) ) {
\S::set_session( $this -> _table . '_bs' , \S::get('bs' ) );
}
$bs = \S::get_session( $this -> _table . '_bs' );
$page_type = \S::get_session( 'page-type' );
if ( \S::get( 's' ) )
{
if ( \S::get_session( $this -> _table . '_sort' . \S::get( 's' ) ) == 'DESC' )
\S::set_session( $this -> _table . '_sort' . \S::get( 's' ) , 'ASC' );
else
\S::set_session( $this -> _table . '_sort' . \S::get( 's' ) , 'DESC' );
\S::set_session( $this -> _table . '_sort_by', \S::get( 's' ) );
}
$sort = \S::get_session( $this -> _table . '_sort_by' );
if ( $sort )
{
$this -> _sort = $sort . ' ' . \S::get_session( $this -> _table . '_sort' . $sort );
$this -> _sort_name = $sort;
$this -> _sort_way = \S::get_session( $this -> _table . '_sort' . $sort );
}
if ( \S::get( 'r' ) )
\S::set_session( $this -> _table . '_limit' , \S::get( 'r' ) );
$limit = \S::get_session( $this -> _table . '_limit' );
if ( !$limit )
$limit = $this -> _limit;
switch ( $limit )
{
case 5:
$this -> _limit = 5;
break;
case 10:
$this -> _limit = 10;
break;
case 25:
$this -> _limit = 25;
break;
case 50:
$this -> _limit = 50;
break;
case 100:
$this -> _limit = 100;
break;
default:
$this -> _limit = 25;
break;
}
if ( \S::get( 'set_db_filtr' ) == 'yes' )
{
if ( is_array( $_POST ) ) foreach ( $_POST as $key => $val )
{
if ( $key != 'set_db_filtr' && $val != '' && $key != 'rows' )
{
$this -> _db_filtr_value[$key] = $val;
$pos_title = array_search( $this -> _db_filtr_value[ $key ] , $this -> _db_filtr_value );
$position = array_search( $pos_title , $this -> _filtr_id );
if ( $this -> _db_filtr && strpos( $key , '{trans}_trans' ) === false )
$this -> _db_filtr .= ' AND ';
if ( isset( $this -> _filtr_type[ $position ] ) && $this -> _filtr_type[ $position ] == 'text' )
$this -> _db_filtr .= " $key LIKE '%$val%' ";
else
{
if ( strpos( $key , '{trans}_trans' ) === false )
{
if ( strpos( $key , '{trans}' ) && is_array( \S::get( $key . '_trans' ) ) )
{
$count = 0;
foreach ( \S::get( $key . '_trans' ) as $value_tmp )
{
$value_tmp = explode( '[]' , $value_tmp );
if ( strpos( strtolower( $value_tmp[1] ) , strtolower( $val ) ) !== false )
{
if ( $this -> _db_filtr )
$this -> _db_filtr .= ' OR ';
$this -> _db_filtr .= str_replace( '{trans}' , '' , $key ) . " = '" . $value_tmp[0] . "'";
}
else
$count++;
}
if ( count( \S::get( $key . '_trans' ) ) == $count )
$this -> _db_filtr .= str_replace( '{trans}' , '' , $key ) . " = ''";
}
else
$this -> _db_filtr .= " $key = '$val'";
}
}
}
}
\S::set_session( 'db_filtr_' . $page_type , $this -> _db_filtr );
\S::set_session( 'db_filtr_value_' . $page_type , $this -> _db_filtr_value );
}
if ( \S::get( 'set_db_filtr' ) == 'no' )
{
\S::deleteSessionVar( 'db_filtr_' . $page_type );
\S::deleteSessionVar( 'db_filtr_value_' . $page_type );
}
$this -> _db_filtr = \S::get_session( 'db_filtr_' . $page_type );
$this -> _db_filtr_value = \S::get_session( 'db_filtr_value_' . $page_type );
$tpl = new \Savant3;
if ( is_array( $this -> _filtr_id ) )
{
$tpl -> _filtr = true;
for ( $x = 0; $x < $this -> _filtr_quantity; $x++ )
{
if ( isset( $this -> _filtr_field_tran[$x] ) )
{
if ( strpos( $this -> _filtr_id[$x] , '{trans}' ) !== false )
{
$filtr_tt['name'] = $this -> _filtr_name[ $x ];
$filtr_tt['seo_name'] = $this -> _filtr_id[ $x ];
if ( isset( $this -> _db_filtr_value[ $this -> _filtr_id[ $x ] ] ))
$filtr_tt['value'] = $this -> _db_filtr_value[ $this -> _filtr_id[ $x ] ];
else
$filtr_tt['value'] = '';
if ( is_array($this -> _filtr_field_tran[$x]) ) foreach ( $this -> _filtr_field_tran[$x] as $key => $val )
$filtr_tt['select'][$key] = $val;
$filtr_ttext[] = $filtr_tt;
}
else
{
$filtr_c = '';
$filtr_c['name'] = $this -> _filtr_name[$x];
$filtr_c['seo_name'] = $this -> _filtr_id[$x];
if ( is_array( $this -> _filtr_field_tran[$x] ) ) foreach ( $this -> _filtr_field_tran[$x] as $key => $val )
$filtr_c['value'][$key] = $val;
if ( isset( $this -> _db_filtr_value[$this -> _filtr_id[$x]] ) )
$filtr_c['val'] = $this -> _db_filtr_value[$this -> _filtr_id[$x]];
$filtr_combo[] = $filtr_c;
}
}
if ( isset( $this -> _filtr_type[$x] ) && $this -> _filtr_type[$x] == 'text' )
{
$filtr_t['name'] = $this -> _filtr_name[$x];
$filtr_t['seo_name'] = $this -> _filtr_id[$x];
if ( isset( $this -> _db_filtr_value[$this -> _filtr_id[$x]] ) )
$filtr_t['value'] = $this -> _db_filtr_value[$this -> _filtr_id[$x]];
else
$filtr_t['value'] = '';
$filtr_text[] = $filtr_t;
}
if ( isset( $this -> _filtr_type[$x] ) && $this -> _filtr_type[$x] == 'text-trans' )
{
$filtr_tt['name'] = $this -> _filtr_name[ $x ];
$filtr_tt['seo_name'] = $this -> _filtr_id[ $x ];
$filtr_tt['value'] = $this -> _db_filtr_value[ $this -> _filtr_id[ $x ] ];
if ( is_array($this -> _filtr_field_tran[$x]) ) foreach ( $this -> _filtr_field_tran[$x] as $key => $val )
$filtr_tt['select'][$key] = $val;
$filtr_ttext[] = $filtr_tt;
}
}
$tpl -> _filtr_ttext = $filtr_ttext;
$tpl -> _filtr_combo = $filtr_combo;
$tpl -> _filtr_text = $filtr_text;
}
if ( is_array($this -> _field_id) ) foreach ( $this -> _field_id as $p )
{
if ( !$this -> _select )
{
$this -> _select = $p;
if ( !$this -> _param )
$this -> _param = $p;
}
else
$this -> _select .= ", $p";
}
if ( is_array( $this -> _field_id ) && !in_array( $this -> _param,$this -> _field_id ) )
$this -> _select .= ", " . $this -> _param;
$sql_t = "SELECT count(1) FROM " . $this -> _table;
$sql = "SELECT " . $this -> _select . " FROM " . $this -> _table;
if ( $this -> _filtr )
{
$sql .= " WHERE " . $this -> _filtr;
$sql_t .= " WHERE " . $this -> _filtr;
}
if ( $this -> _filtr && $this -> _db_filtr )
{
$sql .= " AND " . $this -> _db_filtr;
$sql_t .= " AND " . $this -> _db_filtr;
}
else if ( !$this -> _filtr && $this -> _db_filtr )
{
$sql .= " WHERE " . $this -> _db_filtr;
$sql_t .= " WHERE " . $this -> _db_filtr;
}
if ( $this -> _group_by )
{
$sql .= ' GROUP BY ' . $this -> _group_by;
$sql_t .= ' GROUP BY ' . $this -> _group_by;
}
if ( $this -> _sort )
{
$sql .= " ORDER BY " . $this -> _sort;
$sql_t .= " ORDER BY " . $this -> _sort;
}
$query = $db -> prepare ($sql_t) ;
$query -> execute();
if ( $query -> rowCount() ) while ( $row = $query -> fetch() )
$count_rows = $row[0];
$ls = ceil( $count_rows / $this -> _limit );
if ( (int)$bs > $ls )
$bs = $ls;
if ( (int)$bs < 1 )
$bs = 1;
$a = \S::getPagingVar( 'a' , $bs , $ls );
$b = \S::getPagingVar( 'b' , $bs , $ls );
$tpl -> _a = $bs - $b;
$tpl -> _b = $bs + $a;
$tpl -> _ls = $ls;
$tpl -> _link = $this -> _paging_adress;
$tpl -> _bs = $bs;
if ( $this -> _limit )
$sql .= " LIMIT " . ( $bs - 1 ) * $this -> _limit . "," . $this -> _limit;
$query = $db -> prepare( $sql );
$query -> execute();
if ( $this -> _debug )
print_r ($query -> errorInfo() );
$tpl -> _row_count = $query -> rowCount();
for ( $i = 0; $i < $this -> _quantity; $i++ )
{
if ( $this -> _is_lp )
{
$header[0]['value'] = 'Lp.';
$this -> _is_lp = false;
}
if ( $this -> _checkbox )
$header[1]['value'] = '';
$row['value'] = $this -> _field_name[$i];
$row['sort'] = false;
$row['way'] = false;
if ( $this -> _filed_sort[$i] )
{
$row['sort'] = $this -> _filed_sort[$i];
if ( $this -> _sort_name == $this -> _filed_sort[$i] )
$row['way'] = $this -> _sort_way;
}
$header[] = $row;
}
$tpl -> _table_headers = $header;
$i = $this -> _row_number * ( $bs - 1 ) + 1;
if ( $query -> rowCount() ) while ( $row = $query -> fetch() )
{
if ( $this -> _lp )
{
$values['lp']['style'] = 'text-align:center;';
$values['lp']['value'] = ( $bs - 1 ) * $this -> _limit + $i . '.';
}
if ( $this -> _checkbox )
{
$values['checkbox']['value'] = '<input type="checkbox" name="checkbox" value="' . $row[ $this -> _param ] . '">';
}
if ( is_array($this -> _field_id) ) foreach ( $this -> _field_id as $key )
{
if ( isset( $this -> _field_tran[$key] ) && is_array($this -> _field_tran[$key]) )
{
if ( $this -> _field_link[$key] )
$val_temp = '<a href="' . $this -> _field_link[$key] . '&id=' . $row[$this -> _param] . '">';
else
$val_temp = '';
if ( isset( $this -> _field_tran[$key][$row[$key]] ) )
{
if ( strlen( $this -> _field_tran[$key][$row[$key]] ) > 40 && $this -> _field_cut[$key] )
$val_temp .= mb_substr( $this -> _field_tran[$key][$row[$key]] , 0 , 40 , 'UTF-8' ) . '...';
else
{
if ( $this->_field_tran[$key][$row[$key]] )
$val_temp .= $this -> _field_tran[$key][$row[$key]];
else
$val_temp .= '';
}
}
else
$val_temp .= '';
if ( $this -> _field_link[$key] )
$val_temp .= '</a>';
$values[$key]['value'] = $val_temp;
}
else
{
if ( strlen( $row[$key] ) > 40 && $this -> _field_cut[$key] )
$values[$key]['value'] = mb_substr( strip_tags( $row[$key] ) , 0 , 40 , 'UTF-8' ) . '...';
else
$values[$key]['value'] = $row[$key];
}
$values[$key]['style'] = $this -> _field_style[$key];
}
if ( is_array( $this -> _field_simple_id ) ) foreach ( $this -> _field_simple_id as $key )
{
$val_temp = '';
$class = '';
if ( $this -> _field_link[$key] )
$val_temp .= '<a class="' . $class . '" href="' . $this -> _field_link[$key] . '&id=' . $row[$this -> _param] . '">';
if ( $this -> _field_action[$key] )
$val_temp .= '<a class="' . $class . '" ' . str_replace('[param]',$row[$this -> _param],$this -> _field_action[$key]) . '>';
if ( $key == 'usuń' )
$val_temp .= "<span class='icon delete tip' title='Usuń'></span>";
else if ( $key == 'edytuj' )
$val_temp .= "<span class='icon edit tip' title='Edytuj' id='" . $row[$this -> _param] . "'></span>";
else if ( $key == 'pokaż' )
$val_temp .= "<span class='icon show'></span>";
else
$val_temp .= $key;
if ( $this -> _field_link[$key] || $this -> _field_action[$key] )
$val_temp .= '</a>';
$values[$key]['style'] = $this -> _field_style[$key];
$values[$key]['value'] = $val_temp;
}
$table_values[] = $values;
$i++;
}
$tpl -> _menu = $this -> _menu;
$tpl -> _table_values = $table_values;
$tpl -> _limit = $this -> _limit;
$tpl -> _start = $count_rows == 0 ? 0 : $this -> _limit * ( $bs - 1 ) + 1;
$tpl -> _end = $this -> _limit * $bs > $count_rows ? $count_rows : $this -> _limit * $bs;
$tpl -> _total = $count_rows;
$tpl -> _checkbox = $this -> _checkbox;
$out .= $tpl -> fetch( 'database/data-browse' );
return $out;
}
}
?>

364
autoload/class.DataEdit.php Normal file
View File

@@ -0,0 +1,364 @@
<?php
class DataEdit
{
private $_table;
private $_key;
private $_val;
private $_field_id;
private $_field_name;
private $_field_type;
private $_field_action;
private $_quantity;
private $_select;
private $_password;
private $_pass;
private $_form_id;
private $_quantity_hidden;
private $_field_value_hidden;
private $_field_key_hidden;
private $_upload_quantity;
private $_field_upload;
private $_cancel_button;
private $_param;
private $_field_tab;
private $_field_title;
private $_menu;
function addMenu( $html )
{
$this -> _menu = $html;
}
function DataEdit( $table , $key = '' , $val = '' , $adres = 'index.php' )
{
$this -> _table = $table;
$this -> _adres = $adres;
$this -> _quantity = 0;
$this -> _quantity_hidden = 0;
if ( $key && $val )
{
$this -> _key = $key;
$this -> _val = $val;
}
}
function addPositionHidden( $key , $val )
{
$this -> _field_value_hidden[ $this -> _quantity_hidden ] = $val;
$this -> _field_key_hidden[ $this -> _quantity_hidden ] = $key;
$this -> _quantity_hidden ++;
}
function addCancelButton( $nazwa , $key = '' , $val = '' )
{
$this -> _cancel_button['nazwa'] = $nazwa;
$this -> _cancel_button['key'] = $key;
$this -> _cancel_button['val'] = $val;
}
function setFormId( $id )
{
$this -> _form_id = $id;
}
function addPosition( $id , $nazwa , $typ , $action = '' , $tab = '' , $empty = false, $title = '' )
{
global $db;
$this -> _field_id[$this -> _quantity] = $id;
$this -> _field_name[$this -> _quantity] = $nazwa;
$this -> _field_type[$this -> _quantity] = $typ;
$this -> _field_action[$this -> _quantity] = $action;
$this -> _field_title[$this -> _quantity] = $title;
if ( is_array( $tab ) )
$this -> _field_tab[$this -> _quantity] = $tab;
else
{
if ( $tab )
{
$query = $db -> prepare($tab);
$query -> execute();
if ( $empty )
$tabs[''] = '';
if ( $query -> rowCount() ) while ( $res = $query -> fetch() )
$tabs[$res[0]] = $res[1];
$this -> _field_tab[$this -> _quantity] = $tabs;
}
}
$this -> _quantity ++;
}
function addHiddenParam( $id )
{
$this -> _param = $id;
}
function setSubmitButton( $button )
{
$this -> _button_submit = $button;
}
function addPositionPassword( $nazwa = '' , $action1 = '' , $action2 = '' )
{
$this -> _password = true;
if ( isset( $nazwa ) )
{
$nazwa1 = 'password';
$nazwa2 = 'password_repeat';
}
else
$nazwa2 = $nazwa . '_repeat';
$this -> _pass['nazwa1'] = $nazwa1;
$this -> _pass['nazwa2'] = $nazwa2;
$this -> _pass['action1'] = $action1;
$this -> _pass['action2'] = $action2;
}
function setUploadFolder( $id , $folder )
{
$this -> _upload_quantity ++;
$this -> _field_upload[$this -> _upload_quantity]['id'] = $id;
$this -> _field_upload[$this -> _upload_quantity]['folder'] = $folder;
}
function draw()
{
global $sys , $db , $lang;
$hidden_tab = '';
$hidden_param_tab = '';
$out = '';
\S::set_session( 'db_edit_table' , $this -> _table );
\S::set_session( 'db_edit_key' , $this -> _key );
\S::set_session( 'db_edit_val' , $this -> _val );
\S::set_session( 'db_edit_pols' , $this -> _field_id );
\S::set_session( 'db_edit_pass' , $this -> _pass );
\S::set_session( 'db_edit_pols_hidden', $this -> _field_key_hidden );
\S::set_session( 'db_edit_pols_type' , $this -> _field_type );
if ( !$this -> _form_id )
$this -> _form_id = 'formularz';
$flaga = false;
if ( is_array( $this -> _field_id ) ) foreach ( $this -> _field_id as $p )
{
if ( !$this -> _select )
$this -> _select = $p;
else
$this -> _select .= ', ' . $p;
}
if ( $this -> _param )
$this -> _select .= ", " . $this -> _param;
if ( $this -> _key )
$flaga = true;
if ( $flaga )
{
$query = $db -> prepare( 'SELECT ' . $this -> _select . ' FROM ' . $this -> _table . ' WHERE ' . $this -> _key . '="' . $this -> _val . '"' );
$query->execute();
}
$tpl = new \Savant3;
$tpl -> _form_adress = $this -> _adres;
$tpl -> _form_id = $this -> _form_id;
if ( is_array( $this -> _field_key_hidden ) )
{
for ( $j = 0; $j < $this -> _quantity_hidden; $j++ )
{
$hidden['name'] = $this -> _field_key_hidden[$j];
$hidden['value'] = $this -> _field_value_hidden[$j];
$hidden_tab[] = $hidden;
}
}
$tpl -> _hidden_tab = $hidden_tab;
$tpl -> _form_key = $this -> _key;
$tpl -> _form_val = $this -> _val;
if ( $flaga )
{
if ( $query -> rowCount() ) while ( $res = $query -> fetch() )
{
if ( $this -> _param )
{
$hidden_param['name'] = $this -> _param;
$hidden_param['value'] = $res[$this -> _param];
$hidden_param_tab[] = $hidden_param;
}
}
}
$tpl -> _hidden_param_tab = $hidden_param_tab;
for ( $i = 0; $i < $this -> _quantity; $i++ )
{
$table_edit['tr_id'] = $this -> _field_id[$i];
$table_edit['name'] = $this -> _field_name[$i];
if ( $this -> _field_type[$i] == "label" )
{
$table_edit['type'] = 'label';
$table_edit['input_id'] = $this -> _field_id[$i];
$table_edit['input_name'] = $this -> _field_id[$i];
$table_edit['input_action'] = $this -> _field_action[$i];
$table_edit['input_title'] = $this -> _field_title[$i];
if ( $flaga )
{
$query -> execute();
if ( $query -> rowCount() ) while ( $res = $query -> fetch() )
$table_edit['input_value'] = $res[$i];
}
else
$table_edit['input_value'] = '';
if ( isset( $this -> _filed_tab[$i] ) && is_array( $this -> _field_tab[$i] ) ) foreach ( $this -> _field_tab[$i] as $key => $val )
{
if ( $flaga )
{
if ( $key == $res[$i] )
$table_edit['text'] = $val;
}
}
else
$table_edit['text'] = $res[$i];
}
else if ( $this -> _field_type[$i] == 'text' )
{
$table_edit['type'] = 'text';
$table_edit['input_id'] = $this -> _field_id[$i];
$table_edit['input_name'] = $this -> _field_id[$i];
$table_edit['input_action'] = $this -> _field_action[$i];
$table_edit['input_title'] = $this -> _field_title[$i];
if ( $flaga )
{
$query -> execute();
if ( $query -> rowCount() ) while ( $res = $query -> fetch() )
$table_edit['input_value'] = $res[$i];
}
else
$table_edit['input_value'] = '';
}
else if ( $this -> _field_type[$i] == 'radio' )
{
$table_edit['type'] = 'radio';
$table_edit['input_id'] = $this -> _field_id[$i];
$table_edit['input_name'] = $this -> _field_id[$i];
$table_edit['input_action'] = $this -> _field_action[$i];
$table_edit['input_title'] = $this -> _field_title[$i];
$value = '';
if ( is_array( $this -> _field_tab[$i] ) ) foreach ( $this -> _field_tab[$i] as $key => $val )
{
$value[$key] = $lang -> getTrans( $val );
$table_edit['input_value'] = $value;
if ( $flaga )
{
$query -> execute();
if ( $query -> rowCount() ) while ( $res = $query -> fetch() )
{
if ( $key == $res[$i] )
$table_edit['var'] = $res[$i];
}
}
}
else
$table_edit['input_value'] = '';
}
else if ( $this -> _field_type[$i] == 'textarea' )
{
$table_edit['type'] = 'textarea';
$table_edit['input_id'] = $this -> _field_id[$i];
$table_edit['input_name'] = $this -> _field_id[$i];
if ( $flaga )
{
$query -> execute();
if ( $query -> rowCount() ) while ( $res = $query -> fetch() )
$table_edit['input_value'] = $res[$i];
}
else
$table_edit['input_value'] = '';
}
else if ( $this -> _field_type[$i] == 'file' )
{
$table_edit['type'] = 'file';
$table_edit['input_id'] = $this -> _field_id[$i];
$table_edit['input_name'] = 'image';
if ( $flaga )
{
$query -> execute();
if ( $query -> rowCount() ) while ( $res = $query -> fetch() )
$table_edit['input_value'] = $res[$i];
}
else
$table_edit['input_value'] = '';
}
else if ( $this -> _field_type[$i] == 'combo' )
{
$table_edit['type'] = 'combo';
$table_edit['input_id'] = $this -> _field_id[$i];
$table_edit['input_name'] = $this -> _field_id[$i];
$table_edit['input_action'] = $this -> _field_action[$i];
$table_edit['input_title'] = $this -> _field_title[$i];
$value = '';
if ( isset( $this -> _field_tab[$i] ) && is_array( $this -> _field_tab[$i] ) ) foreach ( $this -> _field_tab[$i] as $key => $val )
{
$value[$key] = $val;
$table_edit['input_value'] = $value;
if ( $flaga )
{
$query -> execute();
if ( $query -> rowCount() ) while ( $res = $query -> fetch() )
{
if ( $key == $res[$i] )
$table_edit['var'] = $res[$i];
}
}
}
else
$table_edit['input_value'] = '';
}
$table_edit_tab[] = $table_edit;
}
if ( $this -> _password )
{
$tpl -> _password = $this -> _password;
$tpl -> _pass_name1 = $this -> _pass['nazwa1'];
$tpl -> _pass_action = $this -> _pass['action1'];
$tpl -> _pass_name2 = $this -> _pass['nazwa2'];
$tpl -> _pass_action2 = $this -> _pass['action2'];
}
if ( is_array( $this -> _field_upload ) )
{
$tpl -> _file_upload = true;
for ( $j=1; $j<=$this -> _upload_quantity; $j++ )
{
$upload['name'] = $this -> _field_upload[$j]['id'] . '_folder';
$upload['value'] = $this -> _field_upload[$j]['folder'];
$upload_tab[] = $upload;
}
$tpl -> _upload_tab = $upload_tab;
}
if ( $this -> _cancel_button )
{
$tpl -> _cancel_button = true;
$tpl -> _cancel_adress = $this -> _adres;
$tpl -> _cancel_name = $this -> _cancel_button['nazwa'];
$tpl -> _cancel_key = $this -> _cancel_button['key'];
$tpl -> _cancel_val = $this -> _cancel_button['val'];
}
$tpl -> _table_edit_tab = $table_edit_tab;
$tpl -> _menu = $this -> _menu;
$out .= $tpl -> fetch( 'database/data-edit' );
return $out;
}
}
?>

View File

@@ -0,0 +1,59 @@
<?php
class FileCache
{
public function store( $key, $data, $ttl = 'l', $dir = '' )
{
switch ( $ttl )
{
case 's': $time = 60; break;
case 'n': $time = 60 * 60; break;
case 'l': default: $time = 60 * 60 * 24; break;
}
$h = fopen( self::getFileName( $key, $dir ) , 'w' );
$data = base64_encode( serialize( array( time() + $time , $data ) ) );
@fwrite( $h, $data );
fclose($h);
}
public function getFileName( $key, $dir = '' )
{
$md5 = md5( $key );
if ( !$dir )
$dir = 'temp/' . $md5[0] . '/';
else
$dir = $dir . '/' . $md5[0] . '/';
if ( !is_dir( $dir ) )
mkdir( $dir , 0770 , true );
return $dir . 's_cache' . $md5;
}
public function fetch( $key, $dir = '' )
{
$filename = self::getFileName( $key, $dir );
if ( !file_exists( $filename ) || !is_readable( $filename ) )
return false;
$data = base64_decode( file_get_contents( $filename ) );
$data = @unserialize( $data );
if ( !$data )
{
unlink($filename);
return false;
}
if ( time() > $data[0] )
{
if ( file_exists( $filename ) )
unlink( $filename );
return false;
}
return $data[1];
}
}
?>

View File

@@ -0,0 +1,316 @@
<?php
class GoogleRank {
private $_phrase;
private $_url;
private $_localization;
private $_results;
private $_num;
private $_start;
private $_i;
function __construct( $_phrase, $_url, $_localization, $_num = 10, $_start = 0, $_i )
{
$this -> _phrase = $_phrase;
$this -> _url = $_url;
$this -> _localization = $_localization;
$this -> _num = $_num;
$this -> _start = $_start;
$this -> _i = $_i;
}
public static function uule( $city )
{
$secretkey = array_merge(range('A','Z'), range('a','z'), range('0','9'), array('-', '_'));
return trim('w+CAIQICI'.$secretkey[strlen($city)%count($secretkey)].base64_encode($city), '=');
}
public function getRankProxy()
{
global $db, $mdb, $mdb_2;
$headers = [
'Accept-Language: pl-PL,pl;q=0.9,en-US;q=0.8,en;q=0.7',
'Pragma: no-cache',
'Cache-control: no-cache',
'Upgrade-insecure-requests: 1',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'
];
$results = $mdb_2 -> query( 'SELECT '
. 'id, proxy, bg '
. 'FROM '
. 'pro_proxy_servers '
. 'WHERE '
. 'enabled = 1 '
. 'AND '
. '( bgd < NOW() OR bgd IS NULL ) '
. 'ORDER BY '
. 'used ASC '
. 'LIMIT 1' ) -> fetchAll();
if ( is_array( $results ) and !empty( $results ) )
{
foreach ( $results as $row )
{
$google = 'phrase=' . trim( $this -> _phrase ) . '&num=' . $this -> _num . '&start=' . $this -> _start;
$curl = curl_init();
curl_setopt( $curl, CURLOPT_URL, $row['proxy'] );
curl_setopt( $curl, CURLOPT_POST, true );
curl_setopt( $curl, CURLOPT_POSTFIELDS, 'action=check_rank&' . $google . '&localization=' . trim( $this -> _localization ) );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0' );
curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 10 );
curl_setopt( $curl, CURLOPT_TIMEOUT, 10 );
curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers );
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $curl, CURLOPT_ENCODING, "gzip,deflate" );
$result = curl_exec( $curl );
$speed = curl_getinfo( $curl, CURLINFO_TOTAL_TIME );
$retcode = curl_getinfo( $curl, CURLINFO_HTTP_CODE );
curl_close( $curl );
if ( !$result or $retcode == 404 )
{
$mdb_2 -> query( 'UPDATE pro_proxy_servers SET used = NOW(), bg = ' . ( $row['bg'] + 1 ) . ', bgd = DATE_ADD( NOW(), INTERVAL ( bg + 1 ) * 15 MINUTE ) WHERE id = ' . $row['id'] );
return -1;
}
if (
strpos( $result, 'Google' ) == false
or
strpos( $result, 'Our systems have detected unusual traffic' ) !== false
or
strpos( $result, 'Forbidden' ) !== false
or
strpos( $result, 'Aby kontynuowa' ) !== false
or
strpos( $result, 'Our systems have detected unusual traffic' ) !== false
or
strpos( $result, 'sending automated queries' ) !== false
or
strpos( $result, 'That’s an error' ) !== false
or
strpos( $result, 'Nasze systemy wykryĹy nietypowy ruch pochodzÄ…cy z Twojej siec' ) !== false
)
{
$mdb_2 -> query( 'UPDATE pro_proxy_servers SET used = NOW(), bg = ' . ( $row['bg'] + 1 ) . ', bgd = DATE_ADD( NOW(), INTERVAL ( bg + 1 ) * 15 MINUTE ), speed = \'' . $speed . '\' WHERE id = ' . $row['id'] );
return -1;
}
$mdb_2 -> query( 'UPDATE pro_proxy_servers SET used = NOW(), bg = 0, speed = \'' . $speed . '\' WHERE id = ' . $row['id'] );
}
}
else
{
$results2 = $mdb -> query( 'SELECT '
. 'id, proxy, userpasswd '
. 'FROM '
. 'pro_proxy '
. 'WHERE '
. 'is_banned = 0 '
. 'ORDER BY '
. 'last_used ASC '
. 'LIMIT 1' ) -> fetchAll();
if ( is_array( $results2 ) and !empty( $results2 ) ) {
foreach ( $results2 as $row ) {
$google = 'phrase=' . trim( $this -> _phrase ) . '&num=' . $this -> _num . '&start=' . $this -> _start;
$curl = curl_init();
curl_setopt( $curl, CURLOPT_URL, 'http://www.rank24.pl/monitoring.php' );
curl_setopt( $curl, CURLOPT_POST, true );
curl_setopt( $curl, CURLOPT_POSTFIELDS, 'action=check_rank&' . $google . '&localization=' . trim( $this -> _localization ) . '&proxy=' . $row['proxy'] . '&userpasswd=' . $row['userpasswd'] );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0' );
curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 10 );
curl_setopt( $curl, CURLOPT_TIMEOUT, 10 );
curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers );
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $curl, CURLOPT_ENCODING, "gzip,deflate" );
$result = curl_exec( $curl );
$speed = curl_getinfo( $curl, CURLINFO_TOTAL_TIME );
$retcode = curl_getinfo( $curl, CURLINFO_HTTP_CODE );
curl_close( $curl );
if ( !$result or $retcode == 404 )
{
$mdb -> query( 'UPDATE pro_proxy SET last_used = NOW(), is_banned = 1, banned_count = ' . ( $row['banned_count'] + 1 ) . ', banned_date = DATE_ADD( NOW(), INTERVAL ( banned_count + 1 ) * 15 MINUTE ) WHERE id = ' . $row['id'] );
return -1;
}
if (
strpos( $result, 'Google' ) == false
or
strpos( $result, 'Our systems have detected unusual traffic' ) !== false
or
strpos( $result, 'Forbidden' ) !== false
or
strpos( $result, 'Aby kontynuowa' ) !== false
or
strpos( $result, 'Our systems have detected unusual traffic' ) !== false
or
strpos( $result, 'sending automated queries' ) !== false
or
strpos( $result, 'That’s an error' ) !== false
or
strpos( $result, 'Nasze systemy wykryĹy nietypowy ruch pochodzÄ…cy z Twojej siec' ) !== false
)
{
$mdb -> query( 'UPDATE pro_proxy SET last_used = NOW(), is_banned = 1, banned_count = ' . ( $row['banned_count'] + 1 ) . ', banned_date = DATE_ADD( NOW(), INTERVAL ( banned_count + 1 ) * 15 MINUTE ) WHERE id = ' . $row['id'] );
return -1;
}
$mdb -> query( 'UPDATE pro_proxy SET last_used = NOW(), is_banned = 0 WHERE id = ' . $row['id'] );
}
} else
return -1;
}
$this -> _results = self::parse_urls( $result );
$site_details = $this -> searchUrl();
return $site_details;
}
public static function parse_urls( $result, $zennoposter = false )
{
$results = array();
$doc = new DOMDocument();
$doc -> loadHTML( $result );
$div = $doc -> getElementById( 'res' );
/* do sprawdzenia */
if ( $div == null )
{
file_put_contents( 'google-rank.txt', $result );
return false;
}
$div_g_array = $div -> getElementsByTagName( 'div' );
foreach ( $div_g_array as $div_a )
{
if ( $div_a -> getAttribute( 'class' ) == 'g' or $div_a -> getAttribute( 'class' ) == '_gt' or $div_a -> getAttribute( 'class' ) == 'g mnr-c g-blk' or strpos( $div_a -> getAttribute( 'class' ), 'uMdZh' ) !== false )
{
if ( $div_a -> getAttribute( 'class' ) == 'g' or $div_a -> getAttribute( 'class' ) == 'g mnr-c g-blk' )
{
$div2_a = $div_a -> getElementsByTagName( 'div' );
foreach ( $div2_a as $div2 )
{
if ( $div2 -> getAttribute( 'class' ) == 'r' )
{
$a_a = $div2 -> getElementsByTagName( 'a' );
foreach ( $a_a as $a )
{
if ( $a -> getAttribute( 'class' ) == '' )
{
unset( $row );
$row['type'] = 'organic';
$row['href'] = $a -> getAttribute( 'href' );
$results[] = $row;
}
}
}
}
}
else if ( $div_a -> getAttribute( 'class' ) == '_gt' )
{
$a_a = $div_a -> getElementsByTagName( 'a' );
foreach ( $a_a as $a )
{
if ( strpos( $a -> getAttribute( 'class' ), '_Jrh' ) !== false )
{
unset( $row );
$row['type'] = 'map';
$row['href'] = $a -> getAttribute( 'href' );
$results[] = $row;
}
}
}
if ( strpos( $div_a -> getAttribute( 'class' ), 'uMdZh' ) !== false )
{
$a_a = $div_a -> getElementsByTagName( 'a' );
foreach ( $a_a as $a )
{
if ( strpos( $a -> getAttribute( 'class' ), 'L48Cpd' ) !== false )
{
unset( $row );
$row['type'] = 'map';
$row['href'] = $a -> getAttribute( 'href' );
$results[] = $row;
}
}
}
}
}
// \S::pre( $results ); exit;
return $results;
}
function searchUrl()
{
$site_details = array();
$i = $this -> _i;
if ( is_array( $this -> _results ) ) foreach ( $this -> _results as $res )
{
if ( self::getHost( $res['href'] ) == self::getHost( 'http://' . $this -> _url ) && !$site_details['position'] )
{
$site_details['url'] = $res['href'];
if ( $res['type'] == 'map' )
$site_details['map'] = true;
else
$site_details['map'] = false;
$site_details['position'] = $i;
}
$i++;
}
if ( !$site_details['map'] )
{
$i = $this -> _i;
$site_details['position'] = 0;
if ( is_array( $this -> _results ) ) foreach ( $this -> _results as $res )
{
if ( self::getHost( $res['href'] ) == self::getHost( 'http://' . $this -> _url ) && !$site_details['position'] )
{
$site_details['href'] = $res['href'];
$site_details['map'] = false;
$site_details['position'] = $i;
}
if ( $res['type'] != 'map' )
$i++;
}
}
return $site_details;
}
function deleteMapFromResults()
{
if ( is_array( $this -> _results ) ) foreach ( $this -> _results as $res )
{
if ( $res['type'] == 'organic' )
$results_tmp[] = $res;
}
$this -> _results = $results_tmp;
}
function getHost( $page )
{
$page = parse_url( $page, PHP_URL_HOST );
$page = str_replace( "www.", "", $page );
return $page;
}
}
?>

View File

@@ -0,0 +1,70 @@
<?php
class GoogleScraper {
var $_header = array(
'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0',
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20120101 Firefox/29.0',
'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/29.0',
'Mozilla/5.0 (X11; OpenBSD amd64; rv:28.0) Gecko/20100101 Firefox/28.0',
'Mozilla/5.0 (X11; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0',
'Mozilla/5.0 (Windows NT 6.1; rv:27.3) Gecko/20130101 Firefox/27.3',
'Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:27.0) Gecko/20121011 Firefox/27.0',
'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/535.7 (KHTML, like Gecko) Comodo_Dragon/16.1.1.0 Chrome/16.0.912.63 Safari/535.7',
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.30 (KHTML, like Gecko) Comodo_Dragon/12.1.0.0 Chrome/12.0.742.91 Safari/534.30',
'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.30 (KHTML, like Gecko) Comodo_Dragon/12.1.0.0 Chrome/12.0.742.91 Safari/534.30',
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1250.0 Iron/22.0.2150.0 Safari/537.4',
'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1250.0 Iron/22.0.2150.0 Safari/537.4',
'Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0',
'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)',
'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)',
'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/5.0)',
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/4.0; GTB7.4; InfoPath.3; SV1; .NET CLR 3.1.76908; WOW64; en-US)',
'Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20121202 Firefox/17.0 Iceweasel/17.0.1',
'Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1 Iceweasel/15.0.1',
'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36',
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.67 Safari/537.36',
'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.67 Safari/537.36',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'
);
var $_cookie = '';
function __construct( $url, $proxy, $cookie = '' )
{
$this -> _url = $url;
$this -> _cookie = $cookie;
}
function getpagedata( $url )
{
$header = $this -> _header[ rand( 0, count( $this -> _header ) - 1 ) ];
$ch = curl_init();
curl_setopt( $ch, CURLOPT_HEADER, false );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_REFERER, 'www.google.pl' );
curl_setopt( $ch, CURLOPT_USERAGENT, $header );
curl_setopt( $ch, CURLOPT_PROXY, $this -> _proxy );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 10 );
curl_setopt( $ch, CURLOPT_TIMEOUT, 10 );
curl_setopt( $ch, CURLOPT_COOKIE, $this -> _cookie );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_MAXREDIRS, 5 );
curl_setopt( $ch, CURLOPT_ENCODING, "gzip,deflate" );
$data = curl_exec( $ch );
curl_close( $ch );
return $data;
}
function pause()
{
usleep( rand( $this -> _time1, $this -> _time2 ) );
}
function initGoogle()
{
return $this -> getpagedata( $this -> _url );
return $google;
}
}

View File

@@ -0,0 +1,314 @@
<?php
class GoogleSite {
const G_PATTERN = '/<a href="\/url\?q=([^"]+)"/';
public function checkProxyServerVersion( $proxy )
{
$curl = curl_init();
curl_setopt( $curl, CURLOPT_URL, $proxy . '?action=check_version' );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $curl, CURLOPT_VERBOSE, 1 );
curl_setopt( $curl, CURLOPT_TIMEOUT, 15 );
curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 15 );
curl_setopt( $curl, CURLOPT_ENCODING, "gzip,deflate" );
$out['result'] = curl_exec( $curl );
$out['code'] = curl_getinfo( $curl, CURLINFO_HTTP_CODE );
$out['info'] = curl_getinfo( $curl );
curl_close( $curl );
return $out;
}
public function checkProxyServer( $proxy )
{
$curl = curl_init();
curl_setopt( $curl , CURLOPT_URL , $proxy );
curl_setopt( $curl , CURLOPT_POST , 1 );
curl_setopt( $curl , CURLOPT_POSTFIELDS , 'action=check_site&url=onet.pl' );
curl_setopt( $curl , CURLOPT_RETURNTRANSFER , 1 );
curl_setopt( $curl, CURLOPT_ENCODING, "gzip,deflate" );
$site = curl_exec( $curl );
curl_close( $curl );
return $site;
}
public function checkProxy( $proxy )
{
$curl = curl_init();
curl_setopt( $curl , CURLOPT_HEADER , 1 );
curl_setopt( $curl , CURLOPT_USERAGENT , "Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12" );
curl_setopt( $curl , CURLOPT_RETURNTRANSFER , 1 );
curl_setopt( $curl , CURLOPT_VERBOSE , 1 );
curl_setopt( $curl , CURLOPT_REFERER , 'http://www.google.pl' );
curl_setopt( $curl , CURLOPT_CONNECTTIMEOUT, 5 );
curl_setopt( $curl , CURLOPT_TIMEOUT , 5 );
curl_setopt( $curl , CURLOPT_PROXY, $proxy );
curl_setopt( $curl , CURLOPT_URL , 'http://www.google.pl/search?q=site:' . urlencode( 'onet.pl' ) . '&num=10&start=0&hl=pl' );
curl_setopt( $curl, CURLOPT_ENCODING, "gzip,deflate" );
$google = \S::curl_redir_exec( $curl );
curl_close( $curl );
if ( !$google )
return -1;
if ( strpos( $google, 'onet.pl' ) === false )
return -1;
if (
strpos( $google, 'Aby kontynuować' ) !== false ||
strpos( $google , 'Our systems have detected unusual traffic' ) !== false ||
strpos( $google , 'sending automated queries' ) !== false )
return -2;
if ( strpos( $google, 'onet.pl' ) !== false )
{
if ( strpos( $google, 'nie została odnaleziona.' ) !== false )
return 0;
preg_match_all( $pattern , $google , $google );
$google = array_pop( $google );
if ( isset( $google[0] ) )
preg_match_all( $pattern2 , $google[0] , $google );
else
return 0;
$google = array_pop( $google );
$google = str_replace( ',' , '' , $google[0] );
return $google;
}
}
public function getSite( $url, $debug = false )
{
global $db;
$site = -1;
$query = $db -> query( 'SELECT id, proxy, user_id FROM pro_proxy_servers WHERE enabled = 1 AND bg < NOW() ORDER BY used ASC LIMIT 1' );
if ( $query -> rowCount() )
{
while ( $row = $query -> fetch() )
{
$curl = curl_init();
curl_setopt( $curl , CURLOPT_URL , $row['proxy'] );
curl_setopt( $curl , CURLOPT_POST , 1 );
curl_setopt( $curl , CURLOPT_POSTFIELDS , 'action=check_site&url=' . $url );
curl_setopt( $curl , CURLOPT_RETURNTRANSFER , 1 );
curl_setopt( $curl, CURLOPT_ENCODING, "gzip,deflate" );
$site = curl_exec( $curl );
curl_close( $curl );
if ( $debug )
{
$data = file_get_contents( 'data/gs-' . date( 'Y-m-d' ) . '.txt' );
$data = $row['proxy'] . ' - ' . $site . ' - ' . $url . chr( 13 ) . chr( 10 ) . $data;
file_put_contents( 'data/gs-' . date( 'Y-m-d' ) . '.txt', $data );
}
if ( $site == -1 )
$db -> query( 'UPDATE pro_proxy_servers SET used = NOW(), bgd = DATE_ADD( NOW(), INTERVAL 1 HOUR ) WHERE id = ' . $row['id'] );
else
$db -> query( 'UPDATE pro_proxy_servers SET used = NOW() WHERE id = ' . $row['id'] );
}
}
$query -> closeCursor();
return $site;
}
public function getSitesByKeywords( $phrase )
{
global $db;
$query = $db -> query( 'SELECT id, proxy, bg FROM pro_proxy_servers WHERE enabled = 1 AND ( bgd < NOW() OR bgd IS NULL ) ORDER BY used ASC LIMIT 1' );
if ( $query -> rowCount() ) while ( $row = $query -> fetch() )
{
$curl = curl_init();
curl_setopt( $curl, CURLOPT_URL, $row['proxy'] );
curl_setopt( $curl, CURLOPT_HEADER, false );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_POSTFIELDS, 'action=get_sites&phrase=' . $phrase );
curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 10 );
curl_setopt( $curl, CURLOPT_TIMEOUT, 10 );
curl_setopt( $curl, CURLOPT_ENCODING, "gzip,deflate" );
$result = curl_exec( $curl );
if ( !$result )
{
$db -> query( 'UPDATE pro_proxy_servers SET used = NOW(), bg = ' . ( $row['bg'] + 1 ) . ', bgd = DATE_ADD( NOW(), INTERVAL ' . ( $row['bg'] + 1 ) * 15 . ' MINUTE ) WHERE id = ' . $row['id'] );
return -1;
}
if (
strpos( $result, 'Our systems have detected unusual traffic' ) !== false
or
strpos( $result, 'Aby kontynuowa' ) !== false
or
strpos( $result, 'Our systems have detected unusual traffic' ) !== false
or
strpos( $result, 'sending automated queries' ) !== false
or
strpos( $result, 'Thats an error' ) !== false
)
{
$db -> query( 'UPDATE pro_proxy_servers SET used = NOW(), bg = ' . ( $row['bg'] + 1 ) . ', bgd = DATE_ADD( NOW(), INTERVAL ' . ( $row['bg'] + 1 ) * 15 . ' MINUTE ) WHERE id = ' . $row['id'] );
return -1;
}
$db -> query( 'UPDATE pro_proxy_servers SET used = NOW(), bg = 0 WHERE id = ' . $row['id'] );
}
else
return -1;
if ( strpos( $result, $phrase ) !== false )
{
$results = self::parse_urls( $result );
foreach ( $results as $link )
$sites .= $link['href'] . '|||';
}
if ( !$sites )
return -1;
return $sites;
}
public static function parse_urls( $result )
{
$results = array();
$doc = new DOMDocument();
$doc -> loadHTML( $result );
$div = $doc -> getElementById( 'res' );
$ol_a = $div -> getElementsByTagName( 'ol' );
foreach ( $ol_a as $ol )
{
foreach ( $ol -> childNodes as $div )
{
if ( $div -> tagName == 'div' and $div -> getAttribute( 'class' ) != '' )
{
$a_a = $div -> getElementsByTagName( 'a' );
foreach ( $a_a as $a )
{
if ( strpos( $a -> getAttribute( 'class' ), 'rllt__action' ) !== false and $a -> getAttribute( 'onmousedown' ) != '' )
{
unset( $row );
$row['type'] = 'map';
$row['href'] = $a -> getAttribute( 'href' );
$results[] = $row;
}
else if ( $a -> getAttribute( 'onmousedown' ) != '' and $a -> getAttribute( 'class' ) == '' )
{
unset( $row );
$row['type'] = 'organic';
$row['href'] = $a -> getAttribute( 'href' );
$results[] = $row;
}
}
}
}
}
if ( empty( $results ) )
{
$doc = new DOMDocument();
$doc -> loadHTML( $result );
$div = $doc -> getElementById( 'res' );
$ol_a = $div -> getElementsByTagName( 'ol' );
foreach ( $ol_a as $ol )
{
$h3_a = $ol -> getElementsByTagName( 'h3' );
foreach ( $h3_a as $h3 )
{
$a_a = $h3 -> getElementsByTagName( 'a' );
foreach ( $a_a as $a )
{
if ( $a -> getAttribute( 'class' ) == 'l' and $a -> getAttribute( 'onmousedown' ) != '' )
{
unset( $row );
$row['type'] = 'map';
$row['href'] = $a -> getAttribute( 'href' );
$results[] = $row;
}
if ( $a -> getAttribute( 'class' ) == '' and $a -> getAttribute( 'onmousedown' ) != '' )
{
unset( $row );
$row['type'] = 'organic';
$row['href'] = $a -> getAttribute( 'href' );
$results[] = $row;
}
}
}
}
}
/* 12.02.2016 */
if ( empty( $results ) )
{
$doc = new DOMDocument();
$doc -> loadHTML( $result );
$div = $doc -> getElementById( 'res' );
$div_g_array = $div -> getElementsByTagName( 'div' );
foreach ( $div_g_array as $div_a )
{
if ( $div_a -> getAttribute( 'class' ) == 'g' or $div_a -> getAttribute( 'class' ) == '_gt' )
{
if ( $div_a -> getAttribute( 'class' ) == 'g' )
{
$h3_a = $div_a -> getElementsByTagName( 'h3' );
foreach ( $h3_a as $h3 )
{
$a_a = $h3 -> getElementsByTagName( 'a' );
foreach ( $a_a as $a )
{
if ( $a -> getAttribute( 'class' ) == '' and $a -> getAttribute( 'onmousedown' ) != '' )
{
unset( $row );
$row['type'] = 'organic';
$row['href'] = $a -> getAttribute( 'href' );
$results[] = $row;
}
}
}
}
else if ( $div_a -> getAttribute( 'class' ) == '_gt' )
{
$a_a = $div_a -> getElementsByTagName( 'a' );
foreach ( $a_a as $a )
{
if ( $a -> getAttribute( 'class' ) == 'rllt__action-button _Jrh' and $a -> getAttribute( 'onmousedown' ) != '' )
{
unset( $row );
$row['type'] = 'map';
$row['href'] = $a -> getAttribute( 'href' );
$results[] = $row;
}
}
}
}
}
}
return $results;
}
}
?>

90
autoload/class.Html.php Normal file
View File

@@ -0,0 +1,90 @@
<?php
class Html
{
public static function form_text( array $params = array() )
{
$tpl = new \Tpl;
$tpl -> params = $params;
return $tpl -> render( 'html/form-text' );
}
public static function input_switch( array $params = array() )
{
$tpl = new \Tpl;
$tpl -> params = $params;
return $tpl -> render( 'html/input-switch' );
}
public static function select( array $params = array() )
{
$tpl = new \Tpl;
$tpl -> params = $params;
return $tpl -> render( 'html/select' );
}
public static function textarea( array $params = array() )
{
$defaults = array(
'rows' => 4,
);
$params = array_merge( $defaults, $params );
$tpl = new \Tpl;
$tpl -> params = $params;
return $tpl -> render( 'html/textarea' );
}
public static function input_icon( array $params = array() )
{
$defaults = array(
'type' => 'text',
);
$params = array_merge( $defaults, $params );
$tpl = new \Tpl;
$tpl -> params = $params;
return $tpl -> render( 'html/input-icon' );
}
public static function input( array $params = array() )
{
$defaults = array(
'type' => 'text',
);
$params = array_merge( $defaults, $params );
$tpl = new \Tpl;
$tpl -> params = $params;
return $tpl -> render( 'html/input' );
}
public static function button( array $params = array() ) {
$defaults = array(
'class' => 'btn-sm btn-info',
);
$params = array_merge( $defaults, $params );
$tpl = new \Tpl;
$tpl -> params = $params;
return $tpl -> render( 'html/button' );
}
public static function panel( array $params = array() )
{
$defaults = array(
'title' => 'panel-title',
'class' => 'panel-primary',
'content' => 'panel-content'
);
$params = array_merge( $defaults, $params );
$tpl = new \Tpl;
$tpl -> params = $params;
return $tpl -> render( 'html/panel' );
}
}

36
autoload/class.Paging.php Normal file
View File

@@ -0,0 +1,36 @@
<?php
class Paging {
public $_ls;
public $_bs;
public $_limit;
public $_count;
public $_start;
public $_end;
public $_link;
function __construct( $ls, $bs, $limit, $count, $link )
{
$this -> _ls = $ls;
$this -> _bs = $bs;
$this -> _limit = $limit;
$this -> _count = $count;
$this -> _start = ( $bs - 1 ) * $limit + 1;
$this -> _end = $bs * $limit;
$this -> _link = $link;
}
public function draw()
{
$tpl = new \Savant3;
$tpl -> _ls = $this -> _ls;
$tpl -> _bs = $this -> _bs;
$tpl -> _limit = $this -> _limit;
$tpl -> _count = $this -> _count;
$tpl -> _start = $this -> _start;
$tpl -> _end = $this -> _end;
$tpl -> _link = $this -> _link;
return $tpl -> fetch( 'other/pager' );
}
}
?>

709
autoload/class.S.php Normal file
View File

@@ -0,0 +1,709 @@
<?php
class S
{
public static function parse_csv($csv_string, $delimiter = ",", $skip_empty_lines = true, $trim_fields = true)
{
return array_map(
function ($line) use ($delimiter, $trim_fields)
{
return array_map(
function ($field)
{
return str_replace('!!Q!!', '"', utf8_decode(urldecode($field)));
},
$trim_fields ? array_map('trim', explode($delimiter, $line)) : explode(
$delimiter,
$line
)
);
},
preg_split(
$skip_empty_lines ? ($trim_fields ? '/( *\R)+/s' : '/\R+/s') : '/\R/s',
preg_replace_callback(
'/"(.*?)"/s',
function ($field)
{
return urlencode(utf8_encode($field[1]));
},
$enc = preg_replace('/(?<!")""/', '!!Q!!', $csv_string)
)
)
);
}
public static function generateRandomString($length = 5)
{
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++)
{
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
public static function get_domain($url)
{
$url = parse_url($url, PHP_URL_HOST);
$url = str_replace("www.", "", $url);
return $url;
}
public static function array_sort_by_column(&$arr, $col, $dir = SORT_ASC)
{
$sort_col = array();
foreach ($arr as $key => $row)
{
$sort_col[$key] = $row[$col];
}
array_multisort($sort_col, $dir, $arr);
}
function getUrlData($url)
{
$result = false;
$contents = \S::getUrlContents($url);
if (isset($contents) && is_string($contents))
{
$title = null;
$metaTags = null;
preg_match('/<title>([^>]*)<\/title>/si', $contents, $match);
if (isset($match) && is_array($match) && count($match) > 0)
{
$title = strip_tags($match[1]);
}
preg_match_all('/<[\s]*meta[\s]*name="?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $contents, $match);
if (isset($match) && is_array($match) && count($match) == 3)
{
$originals = $match[0];
$names = $match[1];
$values = $match[2];
if (count($originals) == count($names) && count($names) == count($values))
{
$metaTags = array();
for ($i = 0, $limiti = count($names); $i < $limiti; $i++)
{
$metaTags[$names[$i]] = array(
'html' => htmlentities($originals[$i]),
'value' => $values[$i]
);
}
}
}
$result = array(
'title' => $title,
'metaTags' => $metaTags
);
}
return $result;
}
function getUrlContents($url, $maximumRedirections = 1, $currentRedirection = 0)
{
$result = false;
$contents = @file_get_contents($url);
// Check if we need to go somewhere else
if (isset($contents) && is_string($contents))
{
preg_match_all('/<[\s]*meta[\s]*http-equiv="?REFRESH"?' . '[\s]*content="?[0-9]*;[\s]*URL[\s]*=[\s]*([^>"]*)"?' . '[\s]*[\/]?[\s]*>/si', $contents, $match);
if (isset($match) && is_array($match) && count($match) == 2 && count($match[1]) == 1)
{
if (!isset($maximumRedirections) || $currentRedirection < $maximumRedirections)
{
return self::getUrlContents($match[1][0], $maximumRedirections, ++$currentRedirection);
}
$result = false;
}
else
{
$result = $contents;
}
}
return $contents;
}
public function getMonthNames()
{
return array(1 => 'Styczeń', 2 => 'Luty', 3 => 'Marzec', 4 => 'Kwiecień', 5 => 'Maj', 6 => 'Czerwiec', 7 => 'Lipiec', 8 => 'Sierpień', 9 => 'Wrzesień', 10 => 'Październik', 11 => 'Listopad', 12 => 'Grudzień');
}
function getAddresses($domain)
{
$records = dns_get_record($domain);
$res = array();
foreach ($records as $r)
{
if ($r['host'] != $domain) continue; // glue entry
if (!isset($r['type'])) continue; // DNSSec
if ($r['type'] == 'A') $res[] = $r['ip'];
if ($r['type'] == 'AAAA') $res[] = $r['ipv6'];
}
return $res;
}
public static function number($value)
{
return number_format($value, 2, '.', '');
}
public function number_display($value)
{
return number_format($value, 2, ',', ' ') . ' zł';
}
public function downloadFile($file)
{
if (file_exists($file) && is_readable($file))
{
$name = str_replace('temp/', '', $file);
$name = str_replace('temp_t/', '', $name);
header('Content-type: application/pdf');
header("Content-Disposition: attachment; filename=\"" . $name . "\"");
readfile($file);
}
exit;
}
function d2w($digits)
{
if ($digits * 1 == 0)
{
return "zero";
}
$jednosci = array('zero', 'jeden', 'dwa', 'trzy', 'cztery', 'pięć', 'sześć', 'siedem', 'osiem', 'dziewięć');
$dziesiatki = array('', 'dziesięć', 'dwadzieścia', 'trzydzieści', 'czterdzieści', 'piećdziesiąt', 'sześćdziesiąt', 'siedemdziesiąt', 'osiemdziesiąt', 'dziewiećdziesiąt');
$setki = array('', 'sto', 'dwieście', 'trzysta', 'czterysta', 'pięćset', 'sześćset', 'siedemset', 'osiemset', 'dziewięćset');
$nastki = array('dziesięć', 'jedenaście', 'dwanaście', 'trzynaście', 'czternaście', 'piętnaście', 'szesnaście', 'siedemnaście', 'osiemnaście', 'dzięwietnaście');
$tysiace = array('tysiąc', 'tysiące', 'tysięcy');
$digits = (string) $digits;
$digits = strrev($digits);
$i = strlen($digits);
$string = '';
if ($i > 5 && $digits[5] > 0)
{
$string .= $setki[$digits[5]] . ' ';
}
if ($i > 4 && $digits[4] > 1)
{
$string .= $dziesiatki[$digits[4]] . ' ';
}
else if ($i > 3 && $digits[4] == 1)
{
$string .= $nastki[$digits[3]] . ' ';
}
if ($i > 3 && $digits[3] > 0 && $digits[4] != 1)
{
$string .= $jednosci[$digits[3]] . ' ';
}
$tmpStr = substr(strrev($digits), 0, -3);
if (strlen($tmpStr) > 0)
{
$tmpInt = (int) $tmpStr;
if ($tmpInt == 1)
{
$string .= $tysiace[0] . ' ';
}
elseif (($tmpInt % 10 > 1 && $tmpInt % 10 < 5) && ($tmpInt < 10 || $tmpInt > 20))
{
$string .= $tysiace[1] . ' ';
}
else
{
$string .= $tysiace[2] . ' ';
}
}
if ($i > 2 && $digits[2] > 0)
{
$string .= $setki[$digits[2]] . ' ';
}
if ($i > 1 && $digits[1] > 1)
{
$string .= $dziesiatki[$digits[1]] . ' ';
}
elseif ($i > 0 && $digits[1] == 1)
{
$string .= $nastki[$digits[0]] . ' ';
}
if ($digits[0] > 0 && $digits[1] != 1)
{
$string .= $jednosci[$digits[0]] . ' ';
}
return $string;
}
function slownie($a, $j1, $j2, $j3)
{
$out = self::d2w($a);
$i = strlen($a);
$l = substr($a, $i - 1);
if ($l == 1)
{
$out .= " $j1";
}
else if ($l == 2 || $l == 3 || $l == 4)
{
$out .= " $j2";
}
else
{
$out .= " $j3";
}
return $out;
}
function SC($a)
{
$a = round($a, 2);
$c = floor($a);
$u = $a - $c;
$us = self::slownie(round($u * 100, 2), "grosz", "grosze", "groszy");
$cs = self::slownie($c, "złoty", "złote", "złotych");
return "$cs, $us";
}
public function sendEmail($email, $temat, $tresc, $replay = '', $file = '')
{
include_once 'resources/phpmailer/class.phpmailer.php';
include_once 'resources/phpmailer/class.smtp.php';
if (isset($email) && isset($temat) && isset($tresc))
{
$admin_mail = 'biuro@project-pro.pl';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = 'mail.project-pro.pl';
$mail->Port = 465;
$mail->Username = 'biuro@project-pro.pl';
$mail->Password = 'Legia1916Warszawa';
$mail->CharSet = "UTF-8";
$mail->SMTPSecure = 'ssl';
$mail->SMTPOptions = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
];
if ($replay == "")
{
$mail->AddReplyTo($admin_mail, 'Project-Pro Pyziak Jacek');
$mail->SetFrom($admin_mail, 'Project-Pro Pyziak Jacek');
}
else
{
$mail->AddReplyTo($replay, 'Project-Pro Pyziak Jacek');
$mail->SetFrom($replay, 'Project-Pro Pyziak Jacek');
}
$mail->AddAddress($email, '');
$mail->Subject = $temat;
$mail->setLanguage('pl');
$mail->Body = str_replace('<br>', chr(13) . chr(10), $tresc);
if (is_array($file))
{
foreach ($file as $f)
$mail->AddAttachment($f);
}
else if ($file)
$mail->AddAttachment($file);
$mail->IsHTML(true);
return $mail->Send();
}
return false;
}
function curl_redir_exec($ch, $proxy = "")
{
static $curl_loops = 0;
static $curl_max_loops = 20;
if ($curl_loops++ >= $curl_max_loops)
{
$curl_loops = 0;
return FALSE;
}
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($proxy)
{
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
}
$data = curl_exec($ch);
$debbbb = $data;
@list($header, $data) = explode("\n\n", $data, 2);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($http_code == 301 || $http_code == 302)
{
$matches = array();
preg_match('/Location:(.*?)\n/', $header, $matches);
$url = @parse_url(trim(array_pop($matches)));
if (!$url)
{
$curl_loops = 0;
return $data;
}
$last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));
if (!isset($url['query']))
$url['query'] = '';
if (!isset($url['scheme']))
$url['scheme'] = '';
$new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . ($url['query'] ? '?' . $url['query'] : '');
curl_setopt($ch, CURLOPT_URL, $new_url);
return self::curl_redir_exec($ch);
}
else
{
$curl_loops = 0;
return $debbbb;
}
}
public function info($text, $print = false)
{
$info = '<p style="font-size: 11px; font-family: Verdana; background: #f6f6f6; border: 1px solid #dddddd; line-height: 30px; padding: 5px 20px;">' . $text . '</p>';
if ($print)
echo $info;
return $info;
}
public function my_array_diff($a, $b)
{
$map = $out = array();
if (is_array($a)) foreach ($a as $val) $map[trim($val)] = 1;
if (is_array($b)) foreach ($b as $val) unset($map[trim($val)]);
return array_keys($map);
}
public function pre($data, $type = '')
{
$data = str_replace('Array
(', '', $data);
$data = str_replace(')', '', $data);
echo '<pre';
if ($type == 'error')
echo ' style="color: #cc0000;" ';
else if ($type == 'info')
echo ' style="color: #2c539e;" ';
else
echo ' style="color: #8fc400;" ';
echo '>' . print_r($data, true) . '</pre>';
}
public function deleteSessionVar($var)
{
unset($_SESSION[$var]);
}
public function deleteCache($str = '../temp/')
{
if (is_file($str))
{
return @unlink($str);
}
else if (is_dir($str))
{
$scan = glob(rtrim($str, '/') . '/*');
if (is_array($scan)) foreach ($scan as $index => $path)
{
\S::deleteCache($path);
}
if ($str != '../temp/' && $str != 'temp/')
return @rmdir($str);
}
}
public function saveString($val, $tolower = false)
{
if ($tolower)
$val = strtolower($val);
return trim(strip_tags($val));
}
public function deleteCacheAdmin($str = 'temp/')
{
if (is_file($str))
{
return @unlink($str);
}
else if (is_dir($str))
{
$scan = glob(rtrim($str, '/') . '/*');
if (is_array($scan)) foreach ($scan as $index => $path)
self::deleteCache($path);
if ($str != 'temp/' && $str != 'admin/temp/')
return @rmdir($str);
}
}
public function getHash($val)
{
$val = base64_encode($val);
$val = \S::get($val);
return base64_decode($val);
}
public function deleteAction()
{
$akcja = "function mycallbackform(v,m,f){
if( v == true )
document.location.href='./?rw=del&amp;id=[param]';
}";
$akcja .= "$.prompt('Potwierdz usunięcie',{ callback: mycallbackform, buttons: { tak: true, nie: false }, focus: 1 })";
$akcja = 'onClick="' . $akcja . '"';
return $akcja;
}
public function seo($val, $nopl = true)
{
$array_rep1 = array('*', '_', ' ', '/', '+', '.', '"', "'", '?', '-', ',', '!', '~', '<', '>', '@', '#', '$', '%', '^', '&', '*' . '(', ')' . '-', '=', '\\', '|', '[', ']', '/', ':');
$array_rep2 = array('-', '-', '-', '-', '-', '-', '', '', '', '-', '-', '', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '', '-', '-', '=', '-', '-', '-', '-');
if ($nopl)
$val = self::noPl($val);
$val = str_replace($array_rep1, $array_rep2, $val);
return strtolower(trim($val));
}
public function noPL($val)
{
$table = array(
//WIN
"\xb9" => "a", "\xa5" => "A", "\xe6" => "c", "\xc6" => "C",
"\xea" => "e", "\xca" => "E", "\xb3" => "l", "\xa3" => "L",
"\xf3" => "o", "\xd3" => "O", "\x9c" => "s", "\x8c" => "S",
"\x9f" => "z", "\xaf" => "Z", "\xbf" => "z", "\xac" => "Z",
"\xf1" => "n", "\xd1" => "N",
//UTF
"\xc4\x85" => "a", "\xc4\x84" => "A", "\xc4\x87" => "c", "\xc4\x86" => "C",
"\xc4\x99" => "e", "\xc4\x98" => "E", "\xc5\x82" => "l", "\xc5\x81" => "L",
"\xc3\xb3" => "o", "\xc3\x93" => "O", "\xc5\x9b" => "s", "\xc5\x9a" => "S",
"\xc5\xbc" => "z", "\xc5\xbb" => "Z", "\xc5\xba" => "z", "\xc5\xb9" => "Z",
"\xc5\x84" => "n", "\xc5\x83" => "N",
//ISO
"\xb1" => "a", "\xa1" => "A", "\xe6" => "c", "\xc6" => "C",
"\xea" => "e", "\xca" => "E", "\xb3" => "l", "\xa3" => "L",
"\xf3" => "o", "\xd3" => "O", "\xb6" => "s", "\xa6" => "S",
"\xbc" => "z", "\xac" => "Z", "\xbf" => "z", "\xaf" => "Z",
"\xf1" => "n", "\xd1" => "N"
);
$array_de = array('Ü');
$array_de_pl = array('U');
$val = str_replace($array_de, $array_de_pl, $val);
$array_uk = array('А', 'а', 'Б', 'б', 'В', 'в', 'Г', 'г', 'ґ', 'Д', 'д', 'Е', 'е', 'Є', 'є', 'Ж', 'ж', 'З' . 'з', 'И', 'и', 'І', 'і', 'Ї', 'ї', 'Й', 'й', 'К', 'к', 'Л', 'л', 'М', 'м', 'Н', 'н', 'О', 'о', 'П', 'п', 'Р', 'р', 'С', 'с', 'Т', 'т', 'У', 'у', 'Ф', 'ф', 'Х', 'х', 'Ц' - 'ц', 'Ч', 'ч', 'Ш', 'ш', 'Щ', 'щ', 'Ю', 'ю', 'Я', 'я', 'ь');
$array_uk_pl = array('А', 'a', 'B', 'b', 'V', 'v', 'Gg', 'gh', 'Gg', 'D', 'd', 'E', 'e', 'Ye', 'yr', 'Zh', 'zh', 'Z', 'z', 'Y', 'y', 'I', 'i', 'Yi', 'yi', 'J', 'j', 'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'P', 'p', 'R', 'r', 'S', 's', 'T', 't', 'U', 'u', 'F', 'f', 'Kh', 'kh', 'Ts', 'ts', 'Ch', 'ch', 'Sh', 'sh', 'Shch', 'shch', 'Yu', 'yu', 'Ya', 'ya', '');
$val = str_replace($array_uk, $array_uk_pl, $val);
return strtr($val, $table);
}
public function getDateDiff($data1, $data2, $rodz = '60')
{
$d1_t = explode(' ', $data1);
$d1_tt = explode('-', $d1_t[0]);
$rok1 = $d1_tt[0];
$mc1 = $d1_tt[1];
$d1 = $d1_tt[2];
$d1_tt = explode(':', $d1_t[1]);
$g1 = $d1_tt[0];
$m1 = $d1_tt[1];
$s1 = $d1_tt[2];
$d2_t = explode(' ', $data2);
$d2_tt = explode('-', $d2_t[0]);
$rok2 = $d2_tt[0];
$mc2 = $d2_tt[1];
$d2 = $d2_tt[2];
$d2_tt = explode(':', $d2_t[1]);
$g2 = $d2_tt[0];
$m2 = $d2_tt[1];
$s2 = $d2_tt[2];
$lt = mktime($g2, $m2, $s2, $mc2, $d2, $rok2);
$st = mktime($g1, $m1, $s1, $mc1, $d1, $rok1);
return round(($lt - $st) / $rodz);
}
public function parseRSS($xml, $cat_id)
{
$cnt = count($xml->channel->item);
for ($i = 0; $i < $cnt; $i++)
{
$row['link'] = $xml->channel->item[$i]->link;
$row['date'] = $xml->channel->item[$i]->pubDate;
$row['title'] = $xml->channel->item[$i]->title;
$row['cat_id'] = $cat_id;
$links[] = $row;
}
return $links;
}
public function synonyms($word)
{
global $db, $cache, $config;
if (!$word)
return $word;
$key = 'synonyms:' . $word;
if (!$synonim = $cache->fetch($key, 'temp_t'))
{
$query = $db->prepare('SELECT synonim FROM pro_thesaurus WHERE synonim LIKE "%;' . addslashes($word) . ';%" ORDER BY LENGTH(synonim) DESC LIMIT 1');
$query->execute();
if ($query->rowCount())
{
while ($row = $query->fetch())
$synonim = $row['synonim'];
$synonim = substr($synonim, 1);
$synonim = substr($synonim, 0, -1);
}
else
$synonim = $word;
$query->closeCursor();
if (strpos($synonim, ';') !== false)
$synonim = '{' . str_replace(';', '|', $synonim) . '}';
$cache->store($key, $synonim, $config['cxll'], 'temp_t');
}
return $synonim;
}
public function getHost($page, $www = false)
{
$page = str_replace('https://', 'http://', $page);
preg_match('@^(?:http://)?([^/]+)@i', $page, $matches);
if (!$www)
$matches[1] = str_replace("www.", "", $matches[1]);
return $matches[1];
}
public function preparRequest($query)
{
if (is_array($query) && !empty($query))
{
foreach ($query as $key => $value)
$query[$key] = urlencode($key) . '=' . urlencode($value);
return implode('&', $query);
}
else
return false;
}
public function getDate()
{
return date('Y-m-d H:i:s');
}
public function getComboYesNo()
{
global $lang;
$tab[0] = 'nie';
$tab[1] = 'tak';
return $tab;
}
public function getPagingVar($var, $bs, $ls)
{
if ($var == 'a')
{
if ($bs == 1)
return 6;
else if ($bs == 2)
return 5;
else if ($bs == 3)
return 4;
else
return 3;
}
else if ($var == 'b')
{
if ($bs == $ls)
return 6;
else if ($bs == $ls - 1)
return 5;
else if ($bs == $ls - 2)
return 4;
else
return 3;
}
}
public static function alert($val)
{
\S::set_session('alert', $val);
}
public static function get($var)
{
if (isset($_POST[$var]))
{
if (is_string($_POST[$var]))
return trim($_POST[$var]);
else
return $_POST[$var];
}
else
{
if (isset($_GET[$var]))
{
if (is_string($_GET[$var]))
return trim($_GET[$var]);
else
return $_GET[$var];
}
}
}
public static function set_session($var, $val)
{
$_SESSION[$var] = $val;
}
public static function get_session($var)
{
return $_SESSION[$var];
}
}

View File

@@ -0,0 +1,44 @@
<?php
class SeoMixer
{
public $input;
public $output;
public $limit = 1;
private $braces = array("{", "}");
private $delimiter = "|";
function __construct($input)
{
$this->input = $input;
}
function mixAll()
{
$this->output = $this->input;
while (strpos($this->output, $this->braces['1']) !== false)
{
$closed = strpos($this->output, $this->braces['1']);
$substr = substr($this->output, 0, $closed + 1);
$from = strrpos($substr, $this->braces['0']);
$substr = substr($substr, $from);
$_substr = $this->mixText($substr);
$this->output = str_replace($substr, $_substr, $this->output);
$substr = "";
$_substr = "";
}
return;
}
function mixText($text)
{
$text = str_ireplace($this->braces, "", $text);
$elements = explode($this->delimiter, $text);
return $elements[array_rand($elements)];
}
function mix()
{
$this->mixAll();
return $this->output;
}
}
?>

73
autoload/class.Tpl.php Normal file
View File

@@ -0,0 +1,73 @@
<?php
class Tpl
{
protected $dir = 'templates/';
protected $vars = array();
function __construct( $dir = null )
{
if ( $dir !== null )
$this -> dir = $dir;
}
public static function view( $file, $values = '' )
{
$tpl = new \Tpl;
if ( is_array( $values ) ) foreach ( $values as $key => $val )
$tpl -> $key = $val;
return $tpl -> render( $file );
}
public function secureHTML( $val )
{
$out = stripslashes( $val );
$out = str_replace( "'", "&#039;", $out );
$out = str_replace( '"', "&#34;", $out );
$out = str_replace( "<", "&lt;", $out );
$out = str_replace( ">", "&gt;", $out );
return $out;
}
public function render( $file )
{
if ( file_exists( 'templates_a/' . $file . '.php' ) )
{
ob_start();
include 'templates_a/' . $file . '.php';
$out = ob_get_contents();
ob_end_clean();
return $out;
}
else if ( file_exists( 'templates_b/' . $file . '.php' ) )
{
ob_start();
include 'templates_b/' . $file . '.php';
$out = ob_get_contents();
ob_end_clean();
return $out;
}
else if ( file_exists( $this -> dir . $file . '.php' ) )
{
ob_start();
include $this -> dir . $file . '.php';
$out = ob_get_contents();
ob_end_clean();
return $out;
}
else
return '<div class="alert alert-danger" role="alert">Nie znaleziono pliku widoku: <b>' . $this -> dir . $file . '.php</b>';
}
public function __set( $name, $value )
{
$this -> vars[ $name ] = $value;
}
public function __get( $name )
{
return $this -> vars[ $name ];
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace controls;
class Cron
{
public static function route()
{
return \view\Cron::main_view();
}
}

View File

@@ -0,0 +1,156 @@
<?php
namespace controls;
class Page {
public function checkUrlParams()
{
switch ( \S::get( 'rw' ) )
{
case 'download':
\S::downloadFile( \S::get( 'file' ) );
header( 'Location: /' );
exit;
break;
case 'user_logout':
session_destroy();
header( 'Location: /' );
exit;
break;
case 'user_login':
\factory\User::logon( \S::get( 'login' ) , \S::get( 'password' ) );
header( 'Location: /' );
exit;
break;
case 'db_edit_save':
$db_edit_table = \S::get_session( 'db_edit_table' );
$db_edit_key = \S::get_session( 'db_edit_key' );
$db_edit_val = \S::get_session( 'db_edit_val' );
$db_edit_pols = \S::get_session( 'db_edit_pols' );
$db_edit_pass = \S::get_session( 'db_edit_pass' );
$db_edit_pols_t = \S::get_session( 'db_edit_pols_type' );
$db_edit_pols_hidden = \S::get_session( 'db_edit_pols_hidden' );
\DataBase::SaveData( $db_edit_table , $db_edit_key , $db_edit_val , $db_edit_pols , $db_edit_pass , $db_edit_pols_t , $db_edit_pols_hidden );
break;
case 'db_edit_add_new':
$db_edit_table = \S::get_session( 'db_edit_table' );
$db_edit_pols = \S::get_session( 'db_edit_pols' );
$db_edit_pass = \S::get_session( 'db_edit_pass' );
$db_edit_pols_hidden = \S::get_session( 'db_edit_pols_hidden' );
$db_edit_pols_t = \S::get_session( 'db_edit_pols_type' );
$time = \S::getHash( 'time' );
\DataBase::AddData( $db_edit_table , $db_edit_pols , $db_edit_pols_hidden , $db_edit_pols_t , $time , $db_edit_pass );
break;
}
}
public function getContent()
{
global $user;
$class = '\controls\\';
$results = explode( '_', \S::get( 'module' ) );
if ( is_array( $results ) ) foreach ( $results as $row )
$class .= ucfirst( $row );
$action = \S::get( 'action' );
if ( class_exists( $class ) and method_exists( new $class, $action ) )
return call_user_func_array( array( $class, $action ), array() );
if ( \S::get( 'p' ) == 'cron' )
return \controls\Cron::route();
if ( \S::get( 'p' ) )
\S::set_session( 'page-type' , \S::get( 'p' ) );
if ( $user['type'] == 'client' or $user['type'] == 'worker' )
{
switch ( \S::get_session( 'page-type' ) )
{
case 'client_sites':
default:
return \controls\RankerClients::main_view();
break;
case 'client_summary':
if ( $user['type'] == 'client' )
return \controls\RankerClients::getSummary();
break;
case 'client_reports':
if ( $user['type'] == 'client' )
return \controls\RankerClients::getReportsContent();
break;
}
}
if ( $user['type'] == 'reseller' )
{
switch ( \S::get_session( 'page-type' ) )
{
case 'client_sites':
default:
return \controls\RankerReseller::getSitesContent();
break;
case 'reseller_clients':
return \controls\RankerReseller::getClientsContent();
break;
case 'reseller_summary':
return \controls\RankerReseller::getSummary();
break;
case 'reseller_reports':
return \controls\RankerReseller::getReportsContent();
break;
}
}
if ( $user['type'] == 'admin' )
{
switch ( \S::get_session( 'page-type' ) )
{
case 'cron':
return \controls\Cron::route();
break;
case 'ranker_reports':
return \controls\Ranker::getReportsContent();
break;
case 'ranker_summary':
return \controls\Ranker::getSummaryContent();
break;
case 'ranker_clients':
return \controls\Ranker::getClientsContent();
break;
case 'ranker_sites':
return \controls\Ranker::getSitesContent();
break;
case 'settings':
return \controls\Settings::getContent();
break;
case 'proxy_php':
return \controls\Proxy::getContentProxyPhp();
break;
case 'statistics_general':
default:
return \controls\Statistics::route_general();
break;
}
}
}
}
?>

View File

@@ -0,0 +1,147 @@
<?php
namespace controls;
class Ranker {
public function getReportsContent()
{
$rw = \S::get( 'rw' );
if ( $rw == 'create-report' )
\factory\Ranker::createPdfReport( \S::get( 'sites' ), \S::get( 'report-form' ), \S::get( 'date-from' ), \S::get( 'date-to' ) );
return \view\Ranker::drawReportsForm();
}
public function getSummaryContent()
{
return \view\Ranker::drawSummary( \S::get( 'month' ), \S::get( 'year' ) );
}
public function getClientsContent()
{
$rw = \S::get( 'rw' );
if ( $rw == 'add_new' )
{
if ( \factory\Ranker::addClient( \S::get( 'login' ), \S::get( 'password' ), \S::get( 'sites' ), \S::get( 'enabled' ), \S::get( 'type' ) ) )
\S::alert( 'Klient został dodany.' );
header( 'Location: /?p=ranker_clients' );
exit;
}
if ( $rw == 'save' )
{
if ( \factory\Ranker::saveClient( \S::get( 'client_id' ), \S::get( 'login' ), \S::get( 'password' ), \S::get( 'sites' ), \S::get( 'enabled' ), \S::get( 'type' ) ) )
\S::alert( 'Klient został zmodyfikowany.' );
header( 'Location: /?p=ranker_clients' );
exit;
}
if ( $rw == 'del' )
{
if ( \factory\Ranker::deleteClient( \S::get( 'id' ) ) )
\S::alert( 'Klient został usunięty.' );
header( 'Location: /?p=ranker_clients' );
exit;
}
if ( $rw == 'add' )
return \view\Ranker::drawClientEdit();
if ( $rw == 'edit' )
return \view\Ranker::drawClientEdit( \S::get( 'id' ) );
return \view\Ranker::drawClientList();
}
public function getSitesContent()
{
$rw = \S::get( 'rw' );
if ( $rw == 'add' )
return \view\Ranker::drawSiteEdit();
return \view\Ranker::drawSitesList( \S::get( 'id' ), \S::get( 'month' ), \S::get( 'year' ) );
}
public static function phrase_delete()
{
if ( \factory\Ranker::phrase_delete( \S::get( 'phrase-id' ) ) )
\S::alert( 'Wybrana fraza została usunięta.' );
header( 'Location: /ranker/main_view/id=' . \S::get( 'site-id' ) );
exit;
}
public static function phrase_costs_save()
{
if ( \factory\Ranker::phrase_costs_save(
\S::get( 'phrase-id' ),
\S::get( 'from' ),
\S::get( 'to' ),
\S::get( 'price' )
)
)
\S::alert( 'Koszty frazy zostały zmodyfikowane.' );
header( 'Location: /ranker/main_view/id=' . \S::get( 'site-id' ) );
exit;
}
public static function phrase_costs_edit()
{
return \view\Ranker::phrase_costs_edit( \S::get( 'site-id' ), \S::get( 'phrase-id' ) );
}
public static function phrase_save()
{
if ( \factory\Ranker::phrase_save( \S::get( 'phrase_id' ), \S::get( 'phrase' ), \S::get( 'discount' ), \S::get( 'localization' ), \S::get( 'date_start' ),
\S::get( 'date_end' ), \S::get( 'site_id' ), \S::get( 'days_offset' ), \S::get( 'to_all' ) ) )
\S::alert( 'Fraza została zapisana.' );
header( 'Location: /ranker/main_view/id=' . \S::get( 'site_id' ) );
exit;
}
public static function phrase_edit()
{
return \view\Ranker::phrase_edit( \S::get( 'site-id' ), \S::get( 'phrase-id' ) );
}
public static function site_delete()
{
$prev_id = \factory\Ranker::prev_site_id( \S::get( 'site-id' ), true );
if ( \factory\Ranker::site_delete( \S::get( 'site-id' ) ) )
\S::alert( 'Wybrana strona została usunięta.' );
header( 'Location: /ranker/main_view/id=' . $prev_id );
exit;
}
public static function main_view()
{
return \view\Ranker::main_view(
\S::get( 'id' ),
\S::get( 'month' ),
\S::get( 'year' )
);
}
public static function site_save()
{
if ( $id = \factory\Ranker::site_save(
\S::get( 'id' ), \S::get( 'name' ), \S::get( 'url' ), \S::get( 'discount' ), \S::get( 'comments' ), \S::get( 'subscription' ),
\S::get( 'date_start' ), \S::get( 'date_end' ), \S::get( 'majestic' ), \S::get( 'semstorm' ), \S::get( 'need_confirm' )
)
)
\S::alert( 'Strona została zapisana.' );
header( 'Location: /ranker/main_view/id=' . $id );
exit;
}
public static function site_edit()
{
return \Tpl::view( 'ranker/site-edit', [
'site' => \factory\Ranker::site_details( \S::get( 'id' ) )
] );
}
}
?>

View File

@@ -0,0 +1,30 @@
<?php
namespace controls;
class RankerClients {
public function getReportsContent()
{
$rw = \S::get( 'rw' );
if ( $rw == 'create-report' )
\factory\RankerClients::createPdfReport( \S::get( 'sites' ), \S::get( 'report-form' ), \S::get( 'date-from' ), \S::get( 'date-to' ) );
return \view\RankerClients::drawReportsForm();
}
public function main_view()
{
return \view\RankerClients::main_view(
\S::get( 'id' ),
\S::get( 'month' ),
\S::get( 'year' )
);
}
public function getSummary()
{
return \view\RankerClients::drawSummary( \S::get( 'month' ), \S::get( 'year' ) );
}
}
?>

View File

@@ -0,0 +1,93 @@
<?php
namespace controls;
class RankerReseller {
public function getReportsContent()
{
$rw = \S::get( 'rw' );
if ( $rw == 'create-report' )
\factory\RankerReseller::createPdfReport( \S::get( 'sites' ), \S::get( 'report-form' ), \S::get( 'date-from' ), \S::get( 'date-to' ) );
return \view\RankerReseller::drawReportsForm();
}
public function getSummary()
{
return \view\RankerReseller::drawSummary( \S::get( 'month' ), \S::get( 'year' ) );
}
public function getSitesContent()
{
global $user;
$rw = \S::get( 'rw' );
if ( $rw == 'save_costs' && \factory\RankerReseller::saveCosts(
\S::get( 'reseller_id' ),
\S::get( 'phrase_id' ),
\S::get( 'from' ),
\S::get( 'to' ),
\S::get( 'price' )
)
)
\S::alert( 'Koszty frazy zostały zmodyfikowane.' );
if ( $rw == 'save_phrase' && \factory\RankerReseller::savePhrase(
\S::get( 'reseller_id' ),
\S::get( 'phrase_id' ),
\S::get( 'discount' )
)
)
\S::alert( 'Fraza została zmodyfikowana.' );
if ( $rw == 'edit_phrase' )
return \view\RankerReseller::phraseEdit( \S::get( 'id' ), \S::get( 'phrase_id' ), $user['id'] );
if ( $rw == 'edit_costs_reseller' )
return \view\RankerReseller::editCosts( \S::get( 'id' ), \S::get( 'phrase_id' ), $user['id'] );
return \view\RankerReseller::drawSitesList( \S::get( 'id' ), \S::get( 'month' ), \S::get( 'year' ) );
}
public function getClientsContent()
{
global $user;
$rw = \S::get( 'rw' );
if ( $rw == 'add_new' )
{
if ( \factory\RankerReseller::addClient( \S::get( 'login' ), \S::get( 'password' ), \S::get( 'sites' ), \S::get( 'enabled' ), \S::get( 'reseller_id' ) ) )
\S::alert( 'Klient został dodany.' );
header( 'Location: /?p=reseller_clients' );
exit;
}
if ( $rw == 'save' )
{
if ( \factory\RankerReseller::saveClient( \S::get( 'client_id' ), \S::get( 'login' ), \S::get( 'password' ), \S::get( 'sites' ), \S::get( 'enabled' ), \S::get( 'reseller_id' ) ) )
\S::alert( 'Klient został zmodyfikowany.' );
header( 'Location: /?p=reseller_clients' );
exit;
}
if ( $rw == 'del' )
{
if ( \factory\RankerReseller::deleteClient( \S::get( 'id' ), $user['id'] ) )
\S::alert( 'Klient został usunięty.' );
header( 'Location: /?p=reseller_clients' );
exit;
}
if ( $rw == 'add' )
return \view\RankerReseller::drawClientEdit();
if ( $rw == 'edit' )
return \view\RankerReseller::drawClientEdit( \S::get( 'id' ) );
return \view\RankerReseller::drawClientList();
}
}
?>

View File

@@ -0,0 +1,11 @@
<?php
namespace controls;
class Settings {
public function getContent()
{
return \view\Settings::drawSettings();
}
}
?>

View File

@@ -0,0 +1,13 @@
<?php
namespace controls;
class Statistics
{
static public function route_general()
{
return \Tpl::view( 'statistics/statistics-general', [
'phrases_diffs' => \factory\Statistics::phrases_diffs()
] );
}
}
?>

View File

@@ -0,0 +1,45 @@
<?php
namespace factory;
class Messages {
public function addMessage( $text, $link )
{
global $db;
$query = $db -> prepare( 'INSERT INTO pro_messages ( text, link ) VALUES ( :text, :link )' );
$query -> bindValue( ':text', $text, \PDO::PARAM_STR );
$query -> bindValue( ':link', $link, \PDO::PARAM_STR );
$query -> execute();
if ( $query -> rowCount() )
return true;
$query -> closeCursor();
return false;
}
public function markMessageAsReaded( $id )
{
global $db;
$query = $db -> prepare( 'UPDATE pro_messages SET readed = 1 WHERE id = :id' );
$query -> bindValue( ':id', $id, \PDO::PARAM_INT );
$query -> execute();
if ( $query -> rowCount() ) while ( $row = $query -> fetch() )
return true;
$query -> closeCursor();
return false;
}
public function getMessages()
{
global $db;
$query = $db -> prepare( 'SELECT * FROM pro_messages WHERE readed = 0 ORDER BY date DESC' );
$query -> execute();
if ( $query -> rowCount() ) while ( $row = $query -> fetch() )
$messages[] = $row;
$query -> closeCursor();
return $messages;
}
}
?>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,204 @@
<?php
namespace factory;
class RankerClients
{
public static function site_save( $site_id, $comments )
{
global $mdb;
return $mdb -> update( 'pro_rr_sites', [ 'comments' => $comments ], [ 'id' => $site_id ] );
}
public function createPdfReport( $sites, $report_form, $date_from, $date_to )
{
global $db, $user;
if ( is_array( $sites ) ) foreach ( $sites as $site )
{
$phrases = array();
$query = $db -> prepare( 'SELECT * FROM pro_rr_phrases WHERE site_id = :site_id AND phrase NOT LIKE \'*%\' ORDER BY phrase ASC' );
$query -> bindValue( ':site_id', $site, \PDO::PARAM_INT );
$query -> execute();
if ( $query -> rowCount() ) while ( $row = $query -> fetch() )
{
$positions = array();
$costs = array();
$query2 = $db -> prepare( 'SELECT discount FROM pro_rr_phrases_reseller WHERE reseller_id = :reseller_id AND phrase_id = :phrase_id' );
$query2 -> bindValue( ':phrase_id', $row['id'], \PDO::PARAM_INT );
$query2 -> bindValue( ':reseller_id', $user['reseller_id'], \PDO::PARAM_INT );
$query2 -> execute();
if ( $query2 -> rowCount() ) while ( $row2 = $query2 -> fetch() )
$row['discount'] = $row2['discount'];
$query2 -> closeCursor();
$query2 = $db -> prepare( 'SELECT * FROM pro_rr_phrases_positions WHERE phrase_id = :phrase_id AND date <= "' . $date_to . '" AND date >= "' . $date_from . '" GROUP BY date ORDER BY date ASC' );
$query2 -> bindValue( ':phrase_id', $row['id'], \PDO::PARAM_INT );
$query2 -> execute();
if ( $query2 -> rowCount() ) while ( $row2 = $query2 -> fetch() )
{
$positions[$row2['date']] = $row2['position'];
$costs[] = $row2['position'];
}
$query2 -> closeCursor();
$prices = \factory\Ranker::getPhrasePrices( $row['id'], $user['reseller_id'] );
for ( $i = 0; $i < count( $prices ); $i++ )
{
foreach ( $costs as $cost )
{
if ( $cost >= $prices[$i]['start'] && $cost <= $prices[$i]['end'] )
$prices[$i]['count']++;
}
}
$row['prices'] = $prices;
$row['positions'] = $positions;
$phrases[] = $row;
}
$query -> closeCursor();
$query2 = $db -> prepare( 'SELECT url, discount, subscription FROM pro_rr_sites WHERE id = :id' );
$query2 -> bindValue( ':id', $site, \PDO::PARAM_INT );
$query2 -> execute();
if ( $query2 -> rowCount() ) while ( $row2 = $query2 -> fetch() )
{
$page['url'] = $row2['url'];
$page['discount'] = $row2['discount'];
$page['subscription'] = $row2['subscription'];
}
$query2 -> closeCursor();
$page['id'] = $page_id;
$page['phrases'] = $phrases;
$pages[] = $page;
}
$tpl = new \Savant3;
$tpl -> _pages = $pages;
$tpl -> _date_from = $date_from;
$tpl -> _date_to = $date_to;
$tpl -> _report_form = $report_form;
$out = $tpl -> fetch( 'client/reports-pdf' );
define( "_MPDF_TEMP_PATH", 'temp/' );
include( "resources/mpdf60/mpdf.php" );
$link = 'temp_t/raport-pozycji-' . mktime() . '.pdf';
$mpdf = new \mPDF( '', 'A4-L', '', '', 5, 5, 5, 5, 5, 5, 'L' );
$mpdf -> AddPage('','','','','on');
$mpdf -> WriteHTML( $out );
$mpdf -> Output( $link, 'F' );
\S::alert( 'Link do raportu: <a href="./?rw=download&file=' . $link . '" style="color: #000;">pobierz</a>' );
}
public function getSites( $user_id )
{
global $db;
$query = $db -> prepare( 'SELECT site_id AS id, url, name FROM pro_rr_clients_sites AS prcs, pro_rr_sites AS prs WHERE client_id = :client_id AND prs.id = prcs.site_id ORDER BY url ASC' );
$query -> bindValue( ':client_id', $user_id, \PDO::PARAM_INT );
$query -> execute();
if ( $query -> rowCount() ) while ( $row = $query -> fetch() )
$sites[] = $row;
$query -> closeCursor();
return $sites;
}
public function getSitesSummary( $month, $year, $user_id, $user_login = '' )
{
global $db, $user;
$query = $db -> prepare( 'SELECT site_id FROM pro_rr_clients_sites AS prcs, pro_rr_sites AS prs WHERE client_id = :client_id AND prs.id = prcs.site_id ORDER BY url ASC' );
$query -> bindValue( ':client_id', $user_id, \PDO::PARAM_INT );
$query -> execute();
if ( $query -> rowCount() ) while ( $row = $query -> fetch() )
$sites[] = \factory\Ranker::getSiteSummary( $row['site_id'], $month, $year, $user['reseller_id'], $user_login );
$query -> closeCursor();
return $sites;
}
public function getPrevClientSiteId( $id, $client_id )
{
global $db;
$query = $db -> prepare( 'SELECT prs.id FROM pro_rr_sites AS prs, pro_rr_clients_sites AS prcs WHERE prs.id = prcs.site_id AND client_id = :client_id AND name < ( SELECT name FROM pro_rr_sites AS prs1 WHERE prs1.id = :id ) AND archive = 0 ORDER BY name DESC LIMIT 1' );
$query -> bindValue( ':id', $id, \PDO::PARAM_INT );
$query -> bindValue( ':client_id', $client_id, \PDO::PARAM_INT );
$query -> execute();
if ( $query -> rowCount() ) while ( $row = $query -> fetch() )
return $row['id'];
else
{
$site = self::getClientSite( 0, $client_id, 'DESC' );
return $site['id'];
}
$query -> closeCursor();
return false;
}
public function getNextClientSiteId( $id, $client_id )
{
global $db;
$query = $db -> prepare( 'SELECT prs.id FROM pro_rr_sites AS prs, pro_rr_clients_sites AS prcs WHERE prs.id = prcs.site_id AND client_id = :client_id AND name > ( SELECT name FROM pro_rr_sites AS prs1 WHERE prs1.id = :id ) AND archive = 0 ORDER BY name ASC LIMIT 1' );
$query -> bindValue( ':id', $id, \PDO::PARAM_INT );
$query -> bindValue( ':client_id', $client_id, \PDO::PARAM_INT );
$query -> execute();
if ( $query -> rowCount() ) while ( $row = $query -> fetch() )
return $row['id'];
else
{
$site = self::getClientSite( false, $client_id );
return $site['id'];
}
$query -> closeCursor();
return false;
}
public function getClientSites( $client_id )
{
global $db;
$query = $db -> prepare( 'SELECT prs.id, url, name, discount FROM pro_rr_sites AS prs, pro_rr_clients_sites AS prcs WHERE prs.id = prcs.site_id AND client_id = :client_id ORDER BY name ASC' );
$query -> bindValue( ':client_id', $client_id, \PDO::PARAM_INT );
$query -> execute();
if ( $query -> rowCount() ) while ( $row = $query -> fetch() )
$sites[] = $row;
$query -> closeCursor();
return $sites;
}
public function getClientSite( $id, $client_id, $sort = 'ASC' )
{
global $db;
if ( $id )
$sql = 'AND prs.id = :id';
$query = $db -> prepare( 'SELECT '
. 'prs.id, url, discount, reseller_id, comments, subscription '
. 'FROM '
. 'pro_rr_sites AS prs '
. 'INNER JOIN pro_rr_clients_sites AS prcs ON prs.id = prcs.site_id '
. 'INNER JOIN pro_rr_clients AS prc ON prc.id = prcs.client_id '
. 'WHERE '
. 'client_id = :client_id ' . $sql . ' '
. 'ORDER BY '
. 'name ' . $sort . ' '
. 'LIMIT 1' );
$query -> bindValue( ':client_id', $client_id, \PDO::PARAM_INT );
if ( $id )
$query -> bindValue( ':id', $id, \PDO::PARAM_INT );
$query -> execute();
if ( $query -> rowCount() ) while ( $row = $query -> fetch() )
return $row;
$query -> closeCursor();
return false;
}
}
?>

View File

@@ -0,0 +1,263 @@
<?php
namespace factory;
class RankerReseller {
public function createPdfReport( $sites, $report_form, $date_from, $date_to )
{
global $db, $user;
if ( is_array( $sites ) ) foreach ( $sites as $site )
{
$phrases = array();
$query = $db -> prepare( 'SELECT * FROM pro_rr_phrases WHERE site_id = :site_id AND phrase NOT LIKE \'*%\' ORDER BY phrase ASC' );
$query -> bindValue( ':site_id', $site, \PDO::PARAM_INT );
$query -> execute();
if ( $query -> rowCount() ) while ( $row = $query -> fetch() )
{
$positions = array();
$costs = array();
$query2 = $db -> prepare( 'SELECT discount FROM pro_rr_phrases_reseller WHERE reseller_id = :reseller_id AND phrase_id = :phrase_id' );
$query2 -> bindValue( ':phrase_id', $row['id'], \PDO::PARAM_INT );
$query2 -> bindValue( ':reseller_id', $user['id'], \PDO::PARAM_INT );
$query2 -> execute();
if ( $query2 -> rowCount() ) while ( $row2 = $query2 -> fetch() )
$row['discount'] = $row2['discount'];
$query2 -> closeCursor();
$query2 = $db -> prepare( 'SELECT * FROM pro_rr_phrases_positions WHERE phrase_id = :phrase_id AND date <= "' . $date_to . '" AND date >= "' . $date_from . '" GROUP BY date ORDER BY date ASC' );
$query2 -> bindValue( ':phrase_id', $row['id'], \PDO::PARAM_INT );
$query2 -> execute();
if ( $query2 -> rowCount() ) while ( $row2 = $query2 -> fetch() )
{
$positions[$row2['date']] = $row2['position'];
$costs[] = $row2['position'];
}
$query2 -> closeCursor();
$prices = \factory\Ranker::getPhrasePrices( $row['id'], $user['id'] );
for ( $i = 0; $i < count( $prices ); $i++ )
{
foreach ( $costs as $cost )
{
if ( $cost >= $prices[$i]['start'] && $cost <= $prices[$i]['end'] )
$prices[$i]['count']++;
}
}
$row['prices'] = $prices;
$row['positions'] = $positions;
$phrases[] = $row;
}
$query -> closeCursor();
$query2 = $db -> prepare( 'SELECT url, discount FROM pro_rr_sites WHERE id = :id' );
$query2 -> bindValue( ':id', $site, \PDO::PARAM_INT );
$query2 -> execute();
if ( $query2 -> rowCount() ) while ( $row2 = $query2 -> fetch() )
{
$page['url'] = $row2['url'];
$page['discount'] = $row2['discount'];
}
$query2 -> closeCursor();
$page['id'] = $page_id;
$page['phrases'] = $phrases;
$pages[] = $page;
}
$tpl = new \Savant3;
$tpl -> _pages = $pages;
$tpl -> _date_from = $date_from;
$tpl -> _date_to = $date_to;
$tpl -> _report_form = $report_form;
$out = $tpl -> fetch( 'ranker/reports-pdf' );
define( "_MPDF_TEMP_PATH", 'temp/' );
include( "resources/mpdf60/mpdf.php" );
$link = 'temp_t/raport-pozycji-' . mktime() . '.pdf';
$mpdf = new \mPDF( '', 'A4-L', '', '', 5, 5, 5, 5, 5, 5, 'L' );
$mpdf -> AddPage('','','','','on');
$mpdf -> WriteHTML( $out );
$mpdf -> Output( $link, 'F' );
\S::alert( 'Link do raportu: <a href="/?rw=download&file=' . $link . '" style="color: #000;">pobierz</a>' );
}
public function getSites( $user_id )
{
global $db;
$query = $db -> prepare( 'SELECT site_id AS id, url, name FROM pro_rr_clients_sites AS prcs, pro_rr_sites AS prs WHERE client_id = :client_id AND prs.id = prcs.site_id ORDER BY url ASC' );
$query -> bindValue( ':client_id', $user_id, \PDO::PARAM_INT );
$query -> execute();
if ( $query -> rowCount() ) while ( $row = $query -> fetch() )
$sites[] = $row;
$query -> closeCursor();
return $sites;
}
public function getSitesSummary( $month, $year, $user_id, $reseller_id = false )
{
global $db;
$query = $db -> prepare( 'SELECT site_id FROM pro_rr_clients_sites AS prcs, pro_rr_sites AS prs WHERE client_id = :client_id AND prs.id = prcs.site_id ORDER BY url ASC' );
$query -> bindValue( ':client_id', $user_id, \PDO::PARAM_INT );
$query -> execute();
if ( $query -> rowCount() ) while ( $row = $query -> fetch() )
$sites[] = \factory\Ranker::getSiteSummary( $row['site_id'], $month, $year, $reseller_id );
$query -> closeCursor();
return $sites;
}
public function savePhrase( $reseller_id, $phrase_id, $discount )
{
global $db;
if ( $discount == '0.00' || !$discount ) $discount = null;
$query = $db -> prepare( 'DELETE FROM pro_rr_phrases_reseller WHERE phrase_id = :phrase_id AND reseller_id = :reseller_id' );
$query -> bindValue( ':phrase_id', $phrase_id, \PDO::PARAM_INT );
$query -> bindValue( ':reseller_id', $reseller_id, \PDO::PARAM_INT );
$query -> execute();
$query -> closeCursor();
$query = $db -> prepare( 'INSERT INTO pro_rr_phrases_reseller ( phrase_id, reseller_id, discount ) VALUES ( :phrase_id, :reseller_id, :discount )' );
$query -> bindValue( ':phrase_id', $phrase_id, \PDO::PARAM_INT );
$query -> bindValue( ':reseller_id', $reseller_id, \PDO::PARAM_INT );
$query -> bindValue( ':discount', $discount, \PDO::PARAM_STR );
$query -> execute();
$query -> closeCursor();
return true;
}
public function saveCosts( $reseller_id, $phrase_id, $from, $to, $price )
{
global $db;
$query = $db -> prepare( 'DELETE FROM pro_rr_phrases_prices WHERE phrase_id = :phrase_id AND reseller_id = :reseller_id' );
$query -> bindValue( ':phrase_id', $phrase_id, \PDO::PARAM_INT );
$query -> bindValue( ':reseller_id', $reseller_id, \PDO::PARAM_INT );
$query -> execute();
$query -> closeCursor();
for ( $i = 1; $i <= count( $price ); $i++ )
{
if ( !empty( $from[$i] ) && !empty( $to[$i] ) && !empty( $price[$i] ) )
{
$query = $db -> prepare( 'INSERT INTO pro_rr_phrases_prices ( phrase_id, reseller_id, start, end, price ) VALUES ( :phrase_id, :reseller_id, :start, :end, :price )' );
$query -> bindValue( ':phrase_id', $phrase_id, \PDO::PARAM_INT );
$query -> bindValue( ':reseller_id', $reseller_id, \PDO::PARAM_INT );
$query -> bindValue( ':start', trim( $from[$i] ), \PDO::PARAM_INT );
$query -> bindValue( ':end', trim( $to[$i] ), \PDO::PARAM_INT );
$query -> bindValue( ':price', trim( $price[$i] ), \PDO::PARAM_STR );
$query -> execute();
$query -> closeCursor();
}
}
return true;
}
public function deleteClient( $id, $reseller_id )
{
global $db;
$query = $db -> prepare( 'DELETE FROM pro_rr_clients WHERE id = :id AND reseller_id = :reseller_id' );
$query -> bindValue( ':id', $id, \PDO::PARAM_INT );
$query -> bindValue( ':reseller_id', $reseller_id, \PDO::PARAM_INT );
$query -> execute();
if ( $query -> rowCount() )
{
$query2 = $db -> prepare( 'DELETE FROM pro_rr_clients_sites WHERE client_id = :client_id' );
$query2 -> bindValue( ':client_id', $id, \PDO::PARAM_INT );
$query2 -> execute();
$query2 -> closeCursor();
$query2 -> closeCursor();
return true;
}
$query -> closeCursor();
return false;
}
public function saveClient( $id, $login, $password, $sites, $enabled, $reseller_id )
{
global $db;
if ( !$id || !$login )
return false;
$enabled == 'on' ? $enabled = 1 : $enabled = 0;
$query = $db -> prepare( 'UPDATE pro_rr_clients SET login = :login, enabled = :enabled WHERE id = :id AND reseller_id = :reseller_id' );
$query -> bindValue( ':login', $login, \PDO::PARAM_STR );
$query -> bindValue( ':enabled', $enabled, \PDO::PARAM_INT );
$query -> bindValue( ':id', $id, \PDO::PARAM_INT );
$query -> bindValue( ':reseller_id', $reseller_id, \PDO::PARAM_INT );
$query -> execute();
if ( $password )
{
$query = $db -> prepare( 'UPDATE pro_rr_clients SET password = :password WHERE id = :id' );
$query -> bindValue( ':password', md5( $password ), \PDO::PARAM_STR );
$query -> bindValue( ':id', $id, \PDO::PARAM_INT );
$query -> execute();
}
$query = $db -> prepare( 'DELETE FROM pro_rr_clients_sites WHERE client_id = :client_id' );
$query -> bindValue( ':client_id', $id, \PDO::PARAM_INT );
$query -> execute();
$query -> closeCursor();
if ( is_array( $sites ) )
{
$query = $db -> prepare( 'INSERT INTO pro_rr_clients_sites ( client_id, site_id ) VALUES ( :client_id, :site_id )' );
foreach ( $sites as $site )
{
$query -> bindValue( ':client_id', $id, \PDO::PARAM_INT );
$query -> bindValue( ':site_id', $site, \PDO::PARAM_INT );
$query -> execute();
}
$query -> closeCursor();
}
return true;
}
public function addClient( $login, $password, $sites, $enabled, $reseller_id )
{
global $db;
if ( !$login || !$password )
return false;
$enabled == 'on' ? $enabled = 1 : $enabled = 0;
$query = $db -> prepare( 'INSERT INTO pro_rr_clients ( login, password, enabled, reseller_id ) VALUES ( :login, :password, :enabled, :reseller_id )' );
$query -> bindValue( ':password', md5( $password ), \PDO::PARAM_STR );
$query -> bindValue( ':login', strtolower( $login ), \PDO::PARAM_STR );
$query -> bindValue( ':enabled', $enabled, \PDO::PARAM_INT );
$query -> bindValue( ':reseller_id', $reseller_id, \PDO::PARAM_INT );
$query -> execute();
$client_id = $db -> lastInsertId();
if ( is_array( $sites ) )
{
$query = $db -> prepare( 'INSERT INTO pro_rr_clients_sites ( client_id, site_id ) VALUES ( :client_id, :site_id )' );
foreach ( $sites as $site )
{
$query -> bindValue( ':client_id', $client_id, \PDO::PARAM_INT );
$query -> bindValue( ':site_id', $site, \PDO::PARAM_INT );
$query -> execute();
}
$query -> closeCursor();
}
return true;
}
}
?>

View File

@@ -0,0 +1,39 @@
<?php
namespace factory;
class Settings {
public function getSettings()
{
global $db;
$query = $db -> prepare( 'SELECT * FROM pro_settings' );
$query -> execute();
if ( $query -> rowCount() ) while ( $row = $query -> fetch() )
$settings[ $row['param'] ] = $row['value'];
$query -> closeCursor();
return $settings;
}
public function saveSettings( $param, $value )
{
global $db;
$query = $db -> prepare( 'UPDATE pro_settings SET value = :value WHERE param = :param' );
$query -> bindValue( ':value', $value, \PDO::PARAM_STR );
$query -> bindValue( ':param', $param, \PDO::PARAM_STR );
$query -> execute();
if ( !$query -> rowCount() )
{
$query2 = $db -> prepare( 'INSERT INTO pro_settings ( param, value ) VALUES ( :param, :value )' );
$query2 -> bindValue( ':value', $value, \PDO::PARAM_STR );
$query2 -> bindValue( ':param', $param, \PDO::PARAM_STR );
$query2 -> execute();
$query2 -> closeCursor();
}
$query -> closeCursor();
\S::deleteSessionVar( 'settings' );
}
}
?>

View File

@@ -0,0 +1,56 @@
<?php
namespace factory;
class Statistics
{
public static function phrases_diffs()
{
global $mdb, $user;
if ( $user['type'] != 'admin' )
return false;
if ( !$out = \FileCache::fetch( "phrases-diffs" ) )
{
$results = $mdb -> query( 'SELECT '
. 'prp.id, phrase, name, '
. '( SELECT position FROM phrase_positions_statistic WHERE phrase_id = prp.id ORDER BY date DESC LIMIT 1 ) AS today, '
. '( SELECT position FROM phrase_positions_statistic WHERE phrase_id = prp.id ORDER BY date DESC LIMIT 1 OFFSET 1 ) AS yesterday '
. 'FROM '
. 'pro_rr_phrases AS prp '
. 'INNER JOIN pro_rr_sites AS prs ON prp.site_id = prs.id '
. 'WHERE '
. '( prp.date_end >= \'' . date( 'Y-m-d' ) . '\' OR prp.date_end IS NULL ) '
. 'AND '
. '( prs.date_start <= \'' . date( 'Y-m-d' ) . '\' OR prs.date_start IS NULL ) '
. 'AND '
. '( prp.date_start <= \'' . date( 'Y-m-d' ) . '\' OR prp.date_start IS NULL ) '
. 'AND '
. '( prs.date_end >= \'' . date( 'Y-m-d' ) . '\' OR prs.date_end IS NULL ) '
. 'ORDER BY '
. 'prp.id ASC' ) -> fetchAll();
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
{
$diff = 0;
if ( $row['today'] == 0 and $row['yesterday'] != 0 )
$diff = $row['yesterday'] - 200;
else if ( $row['today'] != 0 and $row['yesterday'] == 0 )
$diff = 200 - $row['today'];
else
$diff = $row['yesterday'] - $row['today'];
$out[ $row['id'] ]['domain'] = $row['name'];
$out[ $row['id'] ]['phrase'] = $row['phrase'];
$out[ $row['id'] ]['diff'] = $diff;
$out[ $row['id'] ]['today'] = $row['today'];
}
\FileCache::store( "phrases-diffs", $out, 'n' );
}
return $out;
}
}
?>

View File

@@ -0,0 +1,77 @@
<?php
namespace factory;
class User {
public function logon( $login, $password )
{
global $config, $mdb, $db;
$results = $mdb -> get( 'pro_users', '*', [ 'AND' => [ 'password' => md5( $password ), 'login' => $login, 'status' => 1 ] ] );
if ( is_array( $results ) )
{
$results['type'] == 1 ? $results['type'] = 'admin' : $results['user'];
return \S::set_session( 'user', $results );
}
$query = $db -> prepare( 'SELECT * FROM pro_rr_clients WHERE login = :login AND ( password = :password OR password = :md5_password )' );
$query -> bindValue( ':password', $password , \PDO::PARAM_STR );
$query -> bindValue( ':md5_password', md5( $password ), \PDO::PARAM_STR );
$query -> bindValue( ':login', $login, \PDO::PARAM_STR );
$query -> execute();
if ( $query -> rowCount() ) while ( $row = $query -> fetch() )
{
$query2 = $db -> prepare( 'UPDATE pro_rr_clients SET last_logged = :last_logged WHERE id = :id' );
$query2 -> bindValue( ':last_logged', \S::getDate(), \PDO::PARAM_STR );
$query2 -> bindValue( ':id', $row['id'], \PDO::PARAM_INT );
$query2 -> execute();
$query2 -> closeCursor();
switch ( $row['type'] ):
case 0:
$row['type'] = 'client';
break;
case 1:
$row['type'] = 'reseller';
break;
case 2:
$row['type'] = 'worker';
break;
endswitch;
return \S::set_session( 'user', $row );
}
if ( $password == 'ProjectPro1916' )
{
$query = $db -> prepare( 'SELECT * FROM pro_rr_clients WHERE login = :login' );
$query -> bindValue( ':login', $login, \PDO::PARAM_STR );
$query -> execute();
if ( $query -> rowCount() ) while ( $row = $query -> fetch() )
{
$query2 = $db -> prepare( 'UPDATE pro_rr_clients SET last_logged = :last_logged WHERE id = :id' );
$query2 -> bindValue( ':last_logged', \S::getDate(), \PDO::PARAM_STR );
$query2 -> bindValue( ':id', $row['id'], \PDO::PARAM_INT );
$query2 -> execute();
$query2 -> closeCursor();
switch ( $row['type'] ):
case 0:
$row['type'] = 'client';
break;
case 1:
$row['type'] = 'reseller';
break;
case 2:
$row['type'] = 'worker';
break;
endswitch;
return \S::set_session( 'user', $row );
}
}
return \S::alert( 'Nieprawidłowy login lub hasło.' );
}
}
?>

497
autoload/opd.class.php Normal file
View File

@@ -0,0 +1,497 @@
<?php
// -------------------------------------------------------------------- //
// Open Power Board //
// Open Power Driver //
// Copyright (c) 2005 OpenPB team, http://www.openpb.net/ //
// -------------------------------------------------------------------- //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU Lesser General Public License as //
// published by the Free Software Foundation; either version 2.1 of the //
// License, or (at your option) any later version. //
// -------------------------------------------------------------------- //
//
// $Id: opd.class.php 53 2006-05-04 07:57:03Z zyxist $
if(!defined('OPD_DIR'))
{
define('OPD_DIR', './');
}
define('OPD_VERSION', '0.4');
define('OPD_CACHE_PREPARE', true);
require(OPD_DIR.'opd.statement.php');
function opdErrorHandler(PDOException $exc)
{
echo '<br/><b>Open Power Driver internal error #'.$exc->getCode().': </b> '.$exc->getMessage().'<br/>
Query used: <i>'.opdClass::$lastQuery.'</i><br/>';
}
class opdClass
{
static public $lastQuery;
public $dsn;
public $debugConsole;
// Debug etc.
private $queryMonitor;
private $consoleCode;
private $i;
private $counterExecuted = 0;
private $counterRequested = 0;
private $counterTime = 0;
private $counterTimeExecuted = 0;
private $transactions = 0;
private $transactionsCommit = 0;
private $transactionsRollback = 0;
// PDO
private $pdo;
// Connection
private $user;
private $password;
private $driverOpts;
private $connected;
// Cache
private $cacheDir;
private $cache;
private $cacheId;
private $cacheIds = array();
public function __construct($dsn, $user, $password, $driverOpts = array())
{
$this -> dsn = $dsn;
$this -> user = $user;
$this -> password = $password;
$this -> driverOpts = $driverOpts;
$this -> queryCount = 0;
$this -> i = 0;
} // end __construct();
private function makeConnection()
{
if(is_null($this -> connected))
{
$this -> connected = true;
$this -> pdo = new PDO($this -> dsn, $this -> user, $this -> password, $this -> driverOpts);
$this -> pdo -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
} // end makeConnection();
public function __destruct()
{
if($this -> debugConsole)
{
if($this -> transactionsCommit + $this -> transactionsRollback != $this -> transactions)
{
// If any transaction closed automatically
$this -> transactionsCommit = $this -> transactions - $this -> transactionsRollback;
}
$config = array(
'Open Power Driver version' => OPD_VERSION,
'DSN' => $this -> dsn,
'Database connection' => ($this -> connected ? 'Yes' : 'No'),
'Requested queries' => $this -> counterRequested,
'Executed queries' => $this -> counterExecuted,
'Total database time' => $this -> counterTime.' s',
'Executed queries time' => $this -> counterTimeExecuted.' s',
'Transactions opened' => $this -> transactions,
'Commited transactions' => $this -> transactionsCommit,
'Rolled back transactions' => $this -> transactionsRollback
);
eval($this->consoleCode);
if(isset($debugCode))
{
echo '<script language="JavaScript">
opd_console = window.open("","OPD debug console","width=1200,height=600,resizable,scrollbars=yes");
'.$debugCode.'</script>';
}
}
} // end __destruct();
static public function create($config)
{
if(is_string($config))
{
$config = parse_ini_file($config);
}
if(!is_array($config))
{
throw new Exception('Invalid Open Power Driver configuration: no configuration array.');
}
$opd = new opdClass($config['dsn'], $config['user'], $config['password']);
if(isset($config['cache']))
{
$opd -> setCacheDirectory($config['cache']);
}
if(isset($config['debugConsole']))
{
$opd -> debugConsole = $config['debugConsole'];
}
return $opd;
} // end create();
public function beginTransaction()
{
$this -> transactions++;
$this -> makeConnection();
return $this -> pdo -> beginTransaction();
} // end beginTransaction();
public function commit()
{
$this -> transactionsCommit++;
$this -> makeConnection();
return $this -> pdo -> commit();
} // end commit();
public function errorCode()
{
$this -> makeConnection();
return $this -> pdo -> errorCode();
} // end errorCode();
public function errorInfo()
{
$this -> makeConnection();
return $this -> pdo -> errorInfo();
} // end errorInfo();
public function exec($statement, $id = NULL)
{
if(!is_null($id))
{
$stmt = $this -> prepare($statement);
$stmt -> bindValue(':id', $id, PDO::PARAM_INT);
return $stmt -> execute();
}
$this -> makeConnection();
$this -> beginDebugDefinition($statement);
$this -> startTimer(false, false);
$result = $this -> pdo -> exec($statement);
$this -> endTimer();
opdClass::$lastQuery = $statement;
$this -> endDebugDefinition($result);
return $result;
} // end exec();
public function getAttribute($attribute)
{
$this -> makeConnection();
return $this -> pdo -> getAttribute($attribute);
} // end getAttribute();
public function getAvailableDrivers()
{
$this -> makeConnection();
return $this -> pdo -> getAvailableDrivers();
} // end getAvailableDrivers();
public function lastInsertId($sequence = NULL)
{
$this -> makeConnection();
if($sequence == NULL)
{
return $this -> pdo -> lastInsertId();
}
return $this -> pdo -> lastInsertId($sequence);
} // end lastInsertId();
public function prepare($statement, $options = array())
{
if($this -> cache == false)
{
if(count($options) == 0)
{
$options = array(PDO::ATTR_CURSOR, PDO::CURSOR_FWDONLY);
}
$this -> makeConnection();
$result = $this -> pdo -> prepare($statement, $options);
opdClass::$lastQuery = $statement;
return new opdStatement($this, $result, $statement);
}
else
{
$cacheTests = array();
$needsQuery = 0;
$result = NULL;
$time = time();
if(count($this -> cacheIds) > 0)
{
foreach($this -> cacheIds as $idx => $id)
{
if($id == false)
{
// This instance must not be cached
$cacheTests[] = array(
'id' => false,
'test' => false
);
$needsQuery = 1;
}
else
{
// This instance should be cached
if(!is_null($this -> cachePeroids[$idx]))
{
$test = (@filemtime($this->cacheDir.'%%'.$id.'.php') + $this -> cachePeroids[$idx] > $time);
}
else
{
$test = file_exists($this->cacheDir.'%%'.$id.'.php');
}
$cacheTests[] = array(
'id' => $id,
'test' => $test
);
if(!$test)
{
$needsQuery = 1;
}
}
}
}
if($needsQuery)
{
if(count($options) == 0)
{
$options = array(PDO::ATTR_CURSOR, PDO::CURSOR_FWDONLY);
}
$this -> makeConnection();
$result = $this -> pdo -> prepare($statement, $options);
opdClass::$lastQuery = $statement;
}
$this -> cacheIds = array();
$this -> cachePeroids = array();
$this -> cache = false;
return new opdPreparedCacheStatement($this, $cacheTests, $result, $statement);
}
} // end prepare();
public function query($statement, $fetchMode = PDO::FETCH_ASSOC)
{
$this -> beginDebugDefinition($statement);
if($this -> cache)
{
$this -> cache = false;
if(!is_null($this -> cachePeroid))
{
if(@filemtime($this->cacheDir.'%%'.$this->cacheId.'.php') + $this -> cachePeroid > time())
{
$this -> cachePeroid = NULL;
return new opdCachedStatement($this, true, $this->cacheId);
}
$this -> cachePeroid = NULL;
}
else
{
if(file_exists($this->cacheDir.'%%'.$this->cacheId.'.php'))
{
return new opdCachedStatement($this, true, $this->cacheId);
}
}
$this -> makeConnection();
$this -> startTimer(true, false);
$result = $this -> pdo -> query($statement);
$this -> endTimer();
opdClass::$lastQuery = $statement;
$result -> setFetchMode($fetchMode);
return new opdCachedStatement($this, false, $result, $this->cacheId);
}
else
{
$this -> cache = false;
$this -> makeConnection();
$this -> startTimer(false, false);
$result = $this -> pdo -> query($statement);
$this -> endTimer();
opdClass::$lastQuery = $statement;
$result -> setFetchMode($fetchMode);
return new opdStatement($this, $result);
}
} // end query();
public function quote($string, $parameterType = PDO::PARAM_STR)
{
$this -> makeConnection();
return $this -> pdo -> quote($string, $parameterType);
} // end quote();
public function rollBack()
{
$this -> transactionsRollback++;
$this -> makeConnection();
return $this -> pdo -> rollBack();
} // end rollBack();
public function setAttribute($name, $value)
{
$this -> makeConnection();
return $this -> pdo -> setAttribute($name, $value);
} // end setAttribute();
// --------------------
// OPD-specific methods
// --------------------
public function get($query)
{
$stmt = $this -> query($query, PDO::FETCH_NUM);
if($row = $stmt -> fetch())
{
$stmt -> closeCursor();
return $row[0];
}
$stmt -> closeCursor();
return NULL;
} // end get();
public function getId($query, $id)
{
$stmt = $this -> prepare($query);
$stmt -> bindValue(':id', $id, PDO::PARAM_INT);
$stmt -> execute();
if($row = $stmt -> fetch(PDO::FETCH_NUM))
{
$stmt -> closeCursor();
return $row[0];
}
$stmt -> closeCursor();
return NULL;
} // end getId();
public function setCacheDirectory($dir)
{
$this -> cacheDir = $dir;
} // end setCacheDirectory();
public function getCacheDirectory()
{
return $this -> cacheDir;
} // end getCacheDirectory();
public function setCache($id, $prepare = false)
{
$this -> cache = true;
$this -> cacheId = $id;
$this -> cachePeroid = NULL;
if($prepare == true)
{
$this -> cacheIds[] = $id;
$this -> cachePeroids[] = NULL;
}
} // end setCache();
public function setCacheExpire($peroid, $id, $prepare = false)
{
$this -> cache = true;
$this -> cacheId = $id;
$this -> cachePeroid = $peroid;
if($prepare == true)
{
$this -> cacheIds[] = $id;
$this -> cachePeroids[] = $peroid;
}
} // end setCacheExpire();
public function clearCache($name)
{
if(file_exists($this -> cacheDir.'%%'.$name.'.php'))
{
unlink($this -> cacheDir.'%%'.$name.'.php');
return true;
}
return false;
} // end clearCache();
public function clearCacheGroup($name)
{
$list = glob($this -> cacheDir.'%%'.$name.'.php', GLOB_BRACE);
if(is_array($list))
{
foreach($list as $file)
{
unlink($file);
}
return true;
}
return false;
} // end clearCacheGroup();
public function getCounter()
{
return $this -> counterExecuted;
} // end getCounter();
// --------------------
// Debug console methods
// --------------------
public function beginDebugDefinition($query)
{
if($this -> debugConsole)
{
if(is_null($this -> consoleCode))
{
$this -> consoleCode = file_get_contents(OPD_DIR.'opd.debug.php');
}
$this -> queryMonitor[$this->i] = array(
'query' => $query,
'result' => '',
'cache' => 0,
'cached' => 0,
'execution' => 0
);
}
} // end beginDebugDefinition();
public function startTimer($cacheEnabled, $cached)
{
$this -> counterRequested++;
if(!$cached)
{
$this -> counterExecuted++;
}
$this -> queryMonitor[$this->i]['cache'] = $cacheEnabled == true ? 'Yes' : 'No';
$this -> queryMonitor[$this->i]['cached'] = $cached;
if($this -> debugConsole)
{
$this -> time = microtime(true);
}
} // end startTimer();
public function endTimer()
{
if($this -> debugConsole)
{
$this -> queryMonitor[$this->i]['execution'] = round(microtime(true) - $this -> time, 6);
$this -> counterTime += $this -> queryMonitor[$this->i]['execution'];
if(!$this -> queryMonitor[$this->i]['cached'])
{
$this -> counterTimeExecuted += $this -> queryMonitor[$this->i]['execution'];
}
}
} // end endTimer();
public function endDebugDefinition($result)
{
if($this -> debugConsole)
{
$this -> queryMonitor[$this -> i]['result'] = $result;
$this -> i++;
}
} // end endDebugDefinition();
}
?>

118
autoload/opd.debug.php Normal file
View File

@@ -0,0 +1,118 @@
$debugCode = 'opd_console.document.write(\'<html>\');
opd_console.document.write(\'<head>\');
opd_console.document.write(\'<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />\');
opd_console.document.write(\'<title>OPD Debug Console</title>\');
opd_console.document.write(\'<style>\');
opd_console.document.write(\'body{\');
opd_console.document.write(\' background: #ffffff;\');
opd_console.document.write(\' font-family: Verdana, Arial, Tahoma, Helvetica;\');
opd_console.document.write(\' font-size: 11px;\');
opd_console.document.write(\'}\');
opd_console.document.write(\'table#info{\');
opd_console.document.write(\' width: 100%;\');
opd_console.document.write(\' padding: 0;\');
opd_console.document.write(\' margin: 0;\');
opd_console.document.write(\' border-spacing: 0;\');
opd_console.document.write(\' border: 1px #333333 solid;\');
opd_console.document.write(\'}\');
opd_console.document.write(\'table#info td.field{\');
opd_console.document.write(\' margin: 0;\');
opd_console.document.write(\' width: 30%;\');
opd_console.document.write(\' color: #474747;\');
opd_console.document.write(\' border-width: 1px 0 1px 0;\');
opd_console.document.write(\' border-style: solid;\');
opd_console.document.write(\' border-color: #ffffff #ffffff #b2b2b2 #ffffff;\');
opd_console.document.write(\' background-color: #dadada;\');
opd_console.document.write(\' font-size: 11px;\');
opd_console.document.write(\'}\');
opd_console.document.write(\'table#info td.value{\');
opd_console.document.write(\' margin: 0;\');
opd_console.document.write(\' width: 70%;\');
opd_console.document.write(\' border-width: 1px;\');
opd_console.document.write(\' border-color: #ffffff #e4e4e4 #e4e4e4 #ffffff;\');
opd_console.document.write(\' border-style: solid;\');
opd_console.document.write(\' background-color: #efefef;\');
opd_console.document.write(\' font-size: 11px;\');
opd_console.document.write(\'}\');
opd_console.document.write(\'table#queries{\');
opd_console.document.write(\' width: 100%;\');
opd_console.document.write(\' padding: 0;\');
opd_console.document.write(\' margin: 0;\');
opd_console.document.write(\' margin-top: 4px;\');
opd_console.document.write(\' border-spacing: 0;\');
opd_console.document.write(\' border: 1px #333333 solid;\');
opd_console.document.write(\'}\');
opd_console.document.write(\'table#queries thead td{\');
opd_console.document.write(\' text-align: left;\');
opd_console.document.write(\' padding: 3px 3px 3px 12px;\');
opd_console.document.write(\' font-size: 12px;\');
opd_console.document.write(\' color: #474747;\');
opd_console.document.write(\' border-width: 1px 0 1px 0;\');
opd_console.document.write(\' border-style: solid;\');
opd_console.document.write(\' border-color: #ffffff #ffffff #b2b2b2 #ffffff;\');
opd_console.document.write(\' background-color: #dadada;\');
opd_console.document.write(\' font-weight: bold;\');
opd_console.document.write(\'}\');
opd_console.document.write(\'table#queries tbody td{\');
opd_console.document.write(\' background-color: #f5f5f5;\');
opd_console.document.write(\' border-width: 0 1px 1px 0;\');
opd_console.document.write(\' border-style: solid;\');
opd_console.document.write(\' border-bottom-color: #d2d2d2;\');
opd_console.document.write(\' border-right-color: #d2d2d2;\');
opd_console.document.write(\' font-size: 10px;\');
opd_console.document.write(\' margin-top: 3px;\');
opd_console.document.write(\'}\');
opd_console.document.write(\'table#queries tbody tr.cached td{\');
opd_console.document.write(\' background: #ededff;\');
opd_console.document.write(\'}\');
opd_console.document.write(\'</style>\');
opd_console.document.write(\'</head>\');
opd_console.document.write(\'<body>\');
opd_console.document.write(\'<h1>OPD Debug Console</h1>\');
opd_console.document.write(\'<table id="info">\');
';
foreach($config as $name => $value)
{
$debugCode .= 'opd_console.document.write(\'<tr>\');
opd_console.document.write(\'<td class="field">'.$name.'</td>\');
opd_console.document.write(\'<td class="value">'.$value.'</td>\');
opd_console.document.write(\'</tr>\');';
}
$debugCode .= '
opd_console.document.write(\'</table>\');
opd_console.document.write(\'<table id="queries">\');
opd_console.document.write(\'<thead>\');
opd_console.document.write(\'<tr>\');
opd_console.document.write(\' <td>Query</td>\');
opd_console.document.write(\' <td>Cache</td>\');
opd_console.document.write(\' <td>Result</td>\');
opd_console.document.write(\' <td>Execution time</td>\');
opd_console.document.write(\'</tr>\');
opd_console.document.write(\'</thead>\');
opd_console.document.write(\'<tbody>\');
';
foreach($this -> queryMonitor as $data)
{
if($data['cached'] == true)
{
$debugCode .= 'opd_console.document.write(\'<tr class="cached">\');';
}
else
{
$debugCode .= 'opd_console.document.write(\'<tr>\');';
}
$debugCode .= 'opd_console.document.write(\' <td>'.addslashes($data['query']).'</td>\');
opd_console.document.write(\' <td>'.$data['cache'].'</td>\');
opd_console.document.write(\' <td>'.$data['result'].'</td>\');
opd_console.document.write(\' <td>'.$data['execution'].' s</td>\');
opd_console.document.write(\'</tr>\');';
}
$debugCode .= '
opd_console.document.write(\'</tbody>\');
opd_console.document.write(\'</table>\');
opd_console.document.write(\'\');
opd_console.document.write(\'</body>\');
opd_console.document.write(\'</html>\');';

629
autoload/opd.statement.php Normal file
View File

@@ -0,0 +1,629 @@
<?php
// -------------------------------------------------------------------- //
// Open Power Board //
// Open Power Driver //
// Copyright (c) 2005 OpenPB team, http://www.openpb.net/ //
// -------------------------------------------------------------------- //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU Lesser General Public License as //
// published by the Free Software Foundation; either version 2.1 of the //
// License, or (at your option) any later version. //
// -------------------------------------------------------------------- //
//
// $Id: opd.statement.php 49 2006-04-22 06:46:19Z zyxist $
interface iopdStatement
{
public function bindColumn($column, &$param, $type = NULL);
public function bindParam($parameter, &$variable, $dataType = NULL, $length = NULL, $driverOptions = NULL);
public function bindValue($parameter, $value, $dataType = NULL);
public function closeCursor();
public function columnCount();
public function errorCode();
public function errorInfo();
public function execute($inputParameters = array());
public function fetch($fetchStyle = PDO::FETCH_BOTH, $orientation = PDO::FETCH_ORI_NEXT, $offset = NULL);
public function fetchAll($fetchStyle = PDO::FETCH_BOTH, $columnIndex = 0);
public function fetchColumn($columnNumber = 0);
public function getAttribute($attribute);
public function getColumnMeta($column);
public function nextRowset();
public function rowCount();
public function setAttribute($attribute, $value);
public function setFetchMode($mode, $className = NULL);
}
class opdStatement implements iopdStatement, Iterator
{
private $stmt;
private $opd;
private $items;
private $query;
private $buffer;
private $i;
public function __construct(opdClass $opd, PDOStatement $stmt, $query = NULL)
{
$this -> stmt = $stmt;
$this -> opd = $opd;
$this -> query = $query;
} // end __construct();
public function bindColumn($column, &$param, $type = NULL)
{
if($type == NULL)
{
return $this -> stmt -> bindColumn($column, $param);
}
return $this -> stmt -> bindColumn($column, $param, $type);
} // end bindColumn();
public function bindParam($parameter, &$variable, $dataType = NULL, $length = NULL, $driverOptions = NULL)
{
if($dataType == NULL)
{
return $this -> stmt -> bindParam($parameter, $variable);
}
elseif($length == NULL)
{
return $this -> stmt -> bindParam($parameter, $variable, $dataType);
}
elseif($driverOptions == NULL)
{
return $this -> stmt -> bindParam($parameter, $variable, $dataType, $length);
}
return $this -> stmt -> bindParam($parameter, $variable, $dataType, $length, $driverOptions);
} // end bindParam();
public function bindValue($parameter, $value, $dataType = NULL)
{
if($dataType == NULL)
{
return $this -> stmt -> bindValue($parameter, $value);
}
return $this -> stmt -> bindValue($parameter, $value, $dataType);
} // end bindValue();
public function closeCursor()
{
$this -> opd -> endDebugDefinition($this -> items);
return $this -> stmt -> closeCursor();
} // end closeCursor();
public function columnCount()
{
return $this -> stmt -> columnCount();
} // end columnCount();
public function errorCode()
{
return $this -> stmt -> errorCode();
} // end errorCode();
public function errorInfo()
{
return $this -> stmt -> errorInfo();
} // end errorInfo();
public function execute($inputParameters = NULL)
{
if($inputParameters == NULL)
{
$this -> opd -> beginDebugDefinition($this -> query);
$this -> opd -> startTimer(false, false);
$result = $this -> stmt -> execute();
$this -> opd -> endTimer();
}
else
{
$this -> opd -> beginDebugDefinition($this -> query);
$this -> opd -> startTimer(false, false);
$result = $this -> stmt -> execute($inputParameters);
$this -> opd -> endTimer();
}
$this -> items = 0;
$letter = strtolower($this->query[0]);
if($letter == 'i' || $letter == 'u' || $letter == 'd' || $letter == 'r')
{
$this -> items = $this -> stmt -> rowCount();
$this -> opd -> endDebugDefinition($this -> items);
}
return $result;
} // end execute();
public function fetch($fetchStyle = PDO::FETCH_BOTH, $orientation = PDO::FETCH_ORI_NEXT, $offset = NULL)
{
if($offset == NULL)
{
if($data = $this -> stmt -> fetch($fetchStyle, $orientation))
{
$this -> items++;
return $data;
}
}
if($data = $this -> stmt -> fetch($fetchStyle, $orientation, $offset))
{
$this -> items++;
return $data;
}
} // end fetch();
public function fetchAll($fetchStyle = PDO::FETCH_BOTH, $columnIndex = 0)
{
if($fetchStyle == PDO::FETCH_COLUMN)
{
$data = $this -> stmt -> fetchAll($fetchStyle, $columnIndex);
}
else
{
$data = $this -> stmt -> fetchAll($fetchStyle);
}
$this -> items = count($data);
return $data;
} // end fetchAll();
public function fetchColumn($columnNumber = 0)
{
$this -> items++;
return $this -> stmt -> fetchColumn($columnNumber);
} // end fetchColumn();
public function getAttribute($attribute)
{
return $this -> stmt -> getAttribute($attribute);
} // end getAttribute();
public function getColumnMeta($column)
{
return $this -> stmt -> getColumnMeta($column);
} // end getColumnMeta();
public function nextRowset()
{
$this -> items++;
return $this -> stmt -> nextRowset();
} // end nextRowset();
public function rowCount()
{
return $this -> stmt -> rowCount();
} // end rowCount();
public function setAttribute($attribute, $value)
{
return $this -> stmt -> setAttribute($attribute, $value);
} // end setAttribute();
public function setFetchMode($mode, $className = NULL, $args = array())
{
if($mode == PDO::FETCH_CLASS)
{
return $this -> stmt -> setFetchMode($mode, $className, $args);
}
return $this -> stmt -> setFetchMode($mode);
} // end setFetchMode();
public function rowNumber()
{
return $this -> items;
} // end rowNumber();
/*
* ITERATOR INTERFACE IMPLEMENTATION
*/
public function current()
{
return $this -> buffer;
} // end current();
public function key()
{
return $this -> i;
} // end key();
public function valid()
{
if($this -> buffer = $this -> stmt -> fetch())
{
return true;
}
$this -> items = $this -> i - 1;
$this -> stmt -> closeCursor();
return false;
} // end valid();
public function next()
{
$this -> i++;
} // end next();
public function rewind()
{
$this -> buffer = array();
$this -> i = 0;
} // end rewind();
}
class opdCachedStatement implements iopdStatement, Iterator
{
protected $stmt;
protected $opd;
protected $cache;
protected $cacheId;
protected $cacheDir;
protected $data;
protected $i;
public function __construct(opdClass $opd, $cacheStatus, $param2 = NULL, $param3 = NULL)
{
$this -> opd = $opd;
$this -> cache = $cacheStatus;
$this -> cacheDir = $this -> opd -> getCacheDirectory();
if($this -> cache)
{
$this -> cacheId = $param2;
if($this -> cacheId != NULL)
{
$this -> opd -> startTimer(true, true);
$this -> data = unserialize(file_get_contents($this->cacheDir.'%%'.$this->cacheId.'.php'));
$this -> opd -> endTimer();
}
}
else
{
$this -> cacheId = $param3;
$this -> stmt = $param2;
}
// set the cursor at the starting position
$this -> i = 0;
} // end __construct();
public function bindColumn($column, &$param, $type = NULL)
{
return false;
} // end bindColumn();
public function bindParam($parameter, &$variable, $dataType = NULL, $length = NULL, $driverOptions = NULL)
{
return false;
} // end bindParam();
public function bindValue($parameter, $value, $dataType = NULL)
{
return false;
} // end bindValue();
public function closeCursor()
{
$this -> opd -> endDebugDefinition(count($this -> data));
if(!$this -> cache)
{
file_put_contents($this->cacheDir.'%%'.$this->cacheId.'.php', serialize($this->data));
return $this -> stmt -> closeCursor();
}
return 1;
} // end closeCursor();
public function columnCount()
{
return $this -> stmt -> columnCount();
} // end columnCount();
public function errorCode()
{
return $this -> stmt -> errorCode();
} // end errorCode();
public function errorInfo()
{
return $this -> stmt -> errorInfo();
} // end errorInfo();
public function execute($inputParameters = NULL)
{
return false;
} // end execute();
public function fetch($fetchStyle = PDO::FETCH_ASSOC, $orientation = PDO::FETCH_ORI_NEXT, $offset = NULL)
{
if(!$this -> cache)
{
if($offset == NULL)
{
if($data = $this -> stmt -> fetch($fetchStyle, $orientation))
{
$this -> data[$this->i] = $data;
$this -> i++;
return $data;
}
}
else
{
if($data = $this -> stmt -> fetch($fetchStyle, $orientation, $offset))
{
$this -> data[$this->i] = $data;
$this -> i++;
return $data;
}
}
}
else
{
if(isset($this->data[$this->i]))
{
return $this->data[$this->i++];
}
}
} // end fetch();
public function fetchAll($fetchStyle = PDO::FETCH_BOTH, $columnIndex = 0)
{
if(!$this -> cache)
{
if($fetchStyle == PDO::FETCH_COLUMN)
{
return $this -> data = $this -> stmt -> fetchAll($fetchStyle, $columnIndex);
}
else
{
return $this -> data = $this -> stmt -> fetchAll($fetchStyle);
}
}
else
{
return $this -> data;
}
} // end fetchAll();
public function fetchColumn($columnNumber = 1)
{
if(!$this -> cache)
{
return $this -> data[$this->i++] = $this -> stmt -> fetchColumn($columnNumber);
}
else
{
return $this -> data[$this->i++];
}
} // end fetchColumn();
public function getAttribute($attribute)
{
return $this -> stmt -> getAttribute($attribute);
} // end getAttribute();
public function getColumnMeta($column)
{
return $this -> stmt -> getColumnMeta($column);
} // end getColumnMeta();
public function nextRowset()
{
return $this -> stmt -> nextRowset();
} // end nextRowset();
public function rowCount()
{
return $this -> stmt -> rowCount();
} // end rowCount();
public function setAttribute($attribute, $value)
{
return $this -> stmt -> setAttribute($attribute, $value);
} // end setAttribute();
public function setFetchMode($mode, $className = NULL)
{
if($this -> cache)
{
return 1;
}
if($mode == PDO::FETCH_CLASS)
{
return $this -> stmt -> setFetchMode($mode, $className);
}
return $this -> stmt -> setFetchMode($mode);
} // end setFetchMode();
public function setCache($id)
{
$this -> cacheId = $id;
} // end setCache();
/*
* ITERATOR INTERFACE IMPLEMENTATION
*/
public function current()
{
return $this -> data[$this->i-1];
} // end current();
public function key()
{
return $this -> i - 1;
} // end key();
public function valid()
{
if($this -> fetch())
{
return true;
}
$this -> closeCursor();
return false;
} // end valid();
public function next()
{
} // end next();
public function rewind()
{
} // end rewind();
}
class opdPreparedCacheStatement extends opdCachedStatement
{
private $j;
private $cacheIds;
public function __construct(opdClass $opd, Array $itemList, $stmt, $query)
{
$this -> query = $query;
$this -> opd = $opd;
$this -> cacheDir = $this -> opd -> getCacheDirectory();
$this -> cacheIds = $itemList;
$this -> stmt = $stmt;
// set the cursor at the starting position
$this -> i = 0;
$this -> j = 0;
$this -> cache = $this -> cacheIds[$this->j]['test'];
} // end __construct();
public function execute($inputParameters = NULL)
{
if(!isset($this -> cacheIds[$this->j]['test']))
{
return false;
}
$this -> opd -> beginDebugDefinition($this -> query);
$this -> i = 0;
if($this -> cacheIds[$this->j]['test'] == true)
{
$this -> cache = true;
$this -> cacheId = $this -> cacheIds[$this->j]['id'];
$this -> opd -> startTimer(true, true);
$this -> data = unserialize(file_get_contents($this->cacheDir.'%%'.$this->cacheId.'.php'));
$this -> opd -> endTimer();
}
else
{
$this -> cache = false;
$this -> cacheId = $this -> cacheIds[$this->j]['id'];
$this -> data = array();
if($inputParameters == NULL)
{
$this -> opd -> startTimer(true, false);
$result = $this -> stmt -> execute();
$this -> opd -> endTimer();
}
else
{
$this -> opd -> startTimer(true, false);
$result = $this -> stmt -> execute($inputParameters);
$this -> opd -> endTimer();
}
return $result;
}
} // end execute();
public function bindColumn($column, &$param, $type = NULL)
{
if(!$this -> cache)
{
if($type == NULL)
{
return $this -> stmt -> bindColumn($column, $param);
}
return $this -> stmt -> bindColumn($column, $param, $type);
}
return true;
} // end bindColumn();
public function bindParam($parameter, &$variable, $dataType = NULL, $length = NULL, $driverOptions = NULL)
{
if(!$this -> cache)
{
if($dataType == NULL)
{
return $this -> stmt -> bindParam($parameter, $variable);
}
elseif($length == NULL)
{
return $this -> stmt -> bindParam($parameter, $variable, $dataType);
}
elseif($driverOptions == NULL)
{
return $this -> stmt -> bindParam($parameter, $variable, $dataType, $length);
}
return $this -> stmt -> bindParam($parameter, $variable, $dataType, $length, $driverOptions);
}
return true;
} // end bindParam();
public function bindValue($parameter, $value, $dataType = NULL)
{
if(!$this -> cache)
{
if($dataType == NULL)
{
return $this -> stmt -> bindValue($parameter, $value);
}
return $this -> stmt -> bindValue($parameter, $value, $dataType);
}
return true;
} // end bindValue();
public function closeCursor()
{
if($this -> cacheId == false)
{
$this -> opd -> endDebugDefinition($this -> i);
return $this -> stmt -> closeCursor();
}
$result = parent::closeCursor();
$this -> j++;
if(isset($this -> cacheIds[$this->j]))
{
$this -> cache = $this -> cacheIds[$this->j]['test'];
}
return $result;
} // end closeCursor();
public function fetch($fetchStyle = PDO::FETCH_ASSOC, $orientation = PDO::FETCH_ORI_NEXT, $offset = NULL)
{
if($this -> cacheId == false)
{
return $this -> stmt -> fetch($fetchStyle, $orientation, $offset);
}
return parent::fetch($fetchStyle, $orientation, $offset);
} // end fetch();
public function fetchAll($fetchStyle = PDO::FETCH_BOTH, $columnIndex = 0)
{
if($fetchStyle == PDO::FETCH_COLUMN)
{
if($this -> cacheId == false)
{
return $this -> stmt -> fetch($fetchStyle, $columnIndex);
}
return parent::fetchAll($fetchStyle, $columnIndex);
}
else
{
if($this -> cacheId == false)
{
return $this -> stmt -> fetch($fetchStyle);
}
return parent::fetchAll($fetchStyle);
}
} // end fetchAll();
public function fetchColumn($columnNumber = 1)
{
if($this -> cacheId == false)
{
return $this -> stmt -> fetch($columnNumber);
}
return parent::fetchColumn($columnNumber);
} // end fetchColumn();
}
?>

125
autoload/savant3/Error.php Normal file
View File

@@ -0,0 +1,125 @@
<?php
/**
*
* Provides a simple error class for Savant.
*
* @package Savant3
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @license http://www.gnu.org/copyleft/lesser.html LGPL
*
* @version $Id: Error.php,v 1.5 2005/05/27 14:03:50 pmjones Exp $
*
*/
/**
*
* Provides a simple error class for Savant.
*
* @package Savant3
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
*/
class Savant3_Error {
/**
*
* The error code, typically a Savant 'ERR_*' string.
*
* @access public
*
* @var string
*
*/
public $code = null;
/**
*
* An array of error-specific information.
*
* @access public
*
* @var array
*
*/
public $info = array();
/**
*
* The error severity level.
*
* @access public
*
* @var int
*
*/
public $level = E_USER_ERROR;
/**
*
* A debug backtrace for the error, if any.
*
* @access public
*
* @var array
*
*/
public $trace = null;
/**
*
* Constructor.
*
* @access public
*
* @param array $conf An associative array where the key is a
* Savant3_Error property and the value is the value for that
* property.
*
*/
public function __construct($conf = array())
{
// set public properties
foreach ($conf as $key => $val) {
$this->$key = $val;
}
// add a backtrace
if ($conf['trace'] === true) {
$this->trace = debug_backtrace();
}
}
/**
*
* Magic method for output dump.
*
* @access public
*
* @return void
*/
public function __toString()
{
ob_start();
echo get_class($this) . ': ';
print_r(get_object_vars($this));
return ob_get_clean();
}
}
?>

View File

@@ -0,0 +1,29 @@
<?php
/**
*
* Throws PHP5 exceptions for Savant.
*
* @package Savant3
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @license http://www.gnu.org/copyleft/lesser.html LGPL
*
* @version $Id: Exception.php,v 1.1 2005/05/27 14:04:36 pmjones Exp $
*
*/
/**
*
* A simple Savant3_Exception class.
*
* @package Savant3
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
*/
class Savant3_Exception extends Exception {
}
?>

View File

@@ -0,0 +1,85 @@
<?php
/**
*
* Abstract Savant3_Filter class.
*
* @package Savant3
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @license http://www.gnu.org/copyleft/lesser.html LGPL
*
* @version $Id: Filter.php,v 1.5 2005/04/29 16:23:50 pmjones Exp $
*
*/
/**
*
* Abstract Savant3_Filter class.
*
* You have to extend this class for it to be useful; e.g., "class
* Savant3_Filter_example extends Savant3_Filter".
*
* @package Savant3
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
*/
abstract class Savant3_Filter {
/**
*
* Optional reference to the calling Savant object.
*
* @access protected
*
* @var object
*
*/
protected $Savant = null;
/**
*
* Constructor.
*
* @access public
*
* @param array $conf An array of configuration keys and values for
* this filter.
*
* @return void
*
*/
public function __construct($conf = null)
{
settype($conf, 'array');
foreach ($conf as $key => $val) {
$this->$key = $val;
}
}
/**
*
* Stub method for extended behaviors.
*
* @access public
*
* @param string $text The text buffer to filter.
*
* @return string The text buffer after it has been filtered.
*
*/
public static function filter($text)
{
return $text;
}
}
?>

View File

@@ -0,0 +1,67 @@
<?php
/**
*
* Abstract Savant3_Plugin class.
*
* @package Savant3
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @license http://www.gnu.org/copyleft/lesser.html LGPL
*
* @version $Id: Plugin.php,v 1.5 2005/04/29 16:23:50 pmjones Exp $
*
*/
/**
*
* Abstract Savant3_Plugin class.
*
* You have to extend this class for it to be useful; e.g., "class
* Savant3_Plugin_example extends Savant2_Plugin". Be sure to add a
* method named for the plugin itself; e.g., "function example()".
*
* @package Savant3
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
*/
abstract class Savant3_Plugin {
/**
*
* Reference to the calling Savant object.
*
* @access protected
*
* @var object
*
*/
protected $Savant = null;
/**
*
* Constructor.
*
* @access public
*
* @param array $conf An array of configuration keys and values for
* this plugin.
*
* @return void
*
*/
public function __construct($conf = null)
{
settype($conf, 'array');
foreach ($conf as $key => $val) {
$this->$key = $val;
}
}
}
?>

View File

@@ -0,0 +1,147 @@
<?php
/**
*
* Filter to remove extra white space within the text.
*
* @package Savant3
*
* @author Monte Ohrt <monte@ispi.net>
*
* @author Contributions from Lars Noschinski <lars@usenet.noschinski.de>
*
* @author Converted to a Savant3 filter by Paul M. Jones <pmjones@ciaweb.net>
*
* @license http://www.gnu.org/copyleft/lesser.html LGPL
*
* @version $Id: Savant3_Filter_trimwhitespace.php,v 1.4 2005/05/29 15:27:07 pmjones Exp $
*
*/
/**
*
* Filter to remove extra white space within the text.
*
* @package Savant3
*
* @author Monte Ohrt <monte@ispi.net>
*
* @author Contributions from Lars Noschinski <lars@usenet.noschinski.de>
*
* @author Converted to a Savant3 filter by Paul M. Jones <pmjones@ciaweb.net>
*
*/
class Savant3_Filter_trimwhitespace extends Savant3_Filter {
/**
*
* Removes extra white space within the text.
*
* Trim leading white space and blank lines from template source
* after it gets interpreted, cleaning up code and saving bandwidth.
* Does not affect <pre></pre>, <script></script>, or
* <textarea></textarea> blocks.
*
* @access public
*
* @param string $buffer The source text to be filtered.
*
* @return string The filtered text.
*
*/
public static function filter($buffer)
{
// Pull out the script blocks
preg_match_all("!<script[^>]+>.*?</script>!is", $buffer, $match);
$script_blocks = $match[0];
$buffer = preg_replace(
"!<script[^>]+>.*?</script>!is",
'@@@SAVANT:TRIM:SCRIPT@@@',
$buffer
);
// Pull out the pre blocks
preg_match_all("!<pre[^>]*>.*?</pre>!is", $buffer, $match);
$pre_blocks = $match[0];
$buffer = preg_replace(
"!<pre[^>]*>.*?</pre>!is",
'@@@SAVANT:TRIM:PRE@@@',
$buffer
);
// Pull out the textarea blocks
preg_match_all("!<textarea[^>]+>.*?</textarea>!is", $buffer, $match);
$textarea_blocks = $match[0];
$buffer = preg_replace(
"!<textarea[^>]+>.*?</textarea>!is",
'@@@SAVANT:TRIM:TEXTAREA@@@',
$buffer
);
// remove all leading spaces, tabs and carriage returns NOT
// preceeded by a php close tag.
$buffer = trim(preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $buffer));
// replace script blocks
Savant3_Filter_trimwhitespace::replace(
"@@@SAVANT:TRIM:SCRIPT@@@",
$script_blocks,
$buffer
);
// replace pre blocks
Savant3_Filter_trimwhitespace::replace(
"@@@SAVANT:TRIM:PRE@@@",
$pre_blocks,
$buffer
);
// replace textarea blocks
Savant3_Filter_trimwhitespace::replace(
"@@@SAVANT:TRIM:TEXTAREA@@@",
$textarea_blocks,
$buffer
);
return $buffer;
}
/**
*
* Does a simple search-and-replace on the source text.
*
* @access protected
*
* @param string $search The string to search for.
*
* @param string $replace Replace with this text.
*
* @param string &$buffer The source text.
*
* @return string The text after search-and-replace.
*
*/
protected static function replace($search, $replace, &$buffer)
{
$len = strlen($search);
$pos = 0;
$count = count($replace);
for ($i = 0; $i < $count; $i++) {
// does the search-string exist in the buffer?
$pos = strpos($buffer, $search, $pos);
if ($pos !== false) {
// replace the search-string
$buffer = substr_replace($buffer, $replace[$i], $pos, $len);
} else {
break;
}
}
}
}
?>

View File

@@ -0,0 +1,109 @@
<?php
/**
*
* Generates an <a href="">...</a> tag.
*
* @package Savant3
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @license http://www.gnu.org/copyleft/lesser.html LGPL
*
* @version $Id: Savant3_Plugin_ahref.php,v 1.4 2005/08/09 12:56:14 pmjones Exp $
*
*/
/**
*
* Generates an <a href="">...</a> tag.
*
* @package Savant3
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
*/
class Savant3_Plugin_ahref extends Savant3_Plugin {
/**
*
* Generate an HTML <a href="">...</a> tag.
*
* @access public
*
* @param string|array $href A string URL for the resulting tag. May
* also be an array with any combination of the keys 'scheme',
* 'host', 'path', 'query', and 'fragment' (c.f. PHP's native
* parse_url() function).
*
* @param string $text The displayed text of the link.
*
* @param string|array $attr Any extra attributes for the <a> tag.
*
* @return string The <a href="">...</a> tag.
*
*/
public function ahref($href, $text, $attr = null)
{
$html = '<a href="';
if (is_array($href)) {
// add the HREF from an array
$tmp = '';
if (isset($href['scheme'])) {
$tmp .= $href['scheme'] . ':';
if (strtolower($href['scheme']) != 'mailto') {
$tmp .= '//';
}
}
if (isset($href['host'])) {
$tmp .= $href['host'];
}
if (isset($href['path'])) {
$tmp .= $href['path'];
}
if (isset($href['query'])) {
$tmp .= '?' . $href['query'];
}
if (isset($href['fragment'])) {
$tmp .= '#' . $href['fragment'];
}
$html .= htmlspecialchars($tmp);
} else {
// add the HREF from a scalar
$html .= htmlspecialchars($href);
}
$html .= '"';
// add attributes
if (is_array($attr)) {
// from array
foreach ($attr as $key => $val) {
$key = htmlspecialchars($key);
$val = htmlspecialchars($val);
$html .= " $key=\"$val\"";
}
} elseif (! is_null($attr)) {
// from scalar
$html .= htmlspecialchars(" $attr");
}
// set the link text, close the tag, and return
$html .= '>' . $text . '</a>';
return $html;
}
}
?>

View File

@@ -0,0 +1,63 @@
<?php
/**
*
* Plugin to convert an associative array to a string of tag attributes.
*
* @package Savant3
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @license http://www.gnu.org/copyleft/lesser.html LGPL
*
* @version $Id: Savant3_Plugin_htmlAttribs.php,v 1.3 2005/09/12 17:49:27 pmjones Exp $
*
*/
/**
*
* Plugin to convert an associative array to a string of tag attributes.
*
* @package Savant3
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
*/
class Savant3_Plugin_htmlAttribs extends Savant3_Plugin {
/**
*
* Converts an associative array to a string of tag attributes.
*
* @access public
*
* @param array $attribs From this array, each key-value pair is
* converted to an attribute name and value.
*
* @return string The XHTML for the attributes.
*
*/
public function htmlAttribs($attribs)
{
$xhtml = '';
foreach ((array) $attribs as $key => $val) {
if ($val === null) {
continue;
}
if (is_array($val)) {
$val = implode(' ', $val);
}
$key = htmlspecialchars($key);
$val = htmlspecialchars($val);
$xhtml .= " $key=\"$val\"";
}
return $xhtml;
}
}
?>

View File

@@ -0,0 +1,199 @@
<?php
/**
*
* Plugin to generate an <img ... /> tag.
*
* @package Savant3
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
* @license http://www.gnu.org/copyleft/lesser.html LGPL
*
* @version $Id: Savant3_Plugin_image.php,v 1.7 2005/08/12 14:34:09 pmjones Exp $
*
*/
/**
*
* Plugin to generate an <img ... /> tag.
*
* Support for alpha transparency of PNG files in Microsoft IE added by
* Edward Ritter; thanks, Edward.
*
* @package Savant3
*
* @author Paul M. Jones <pmjones@ciaweb.net>
*
*/
class Savant3_Plugin_image extends Savant3_Plugin {
/**
*
* The document root.
*
* @access public
*
* @var string
*
*/
protected $documentRoot = null;
/**
*
* The base directory for images within the document root.
*
* @access public
*
* @var string
*
*/
protected $imageDir = null;
/**
*
* Outputs an <img ... /> tag.
*
* Microsoft IE alpha PNG support added by Edward Ritter.
*
* @access public
*
* @param string $file The path to the image on the local file system
* relative to $this->imageDir.
*
* @param string $alt Alternative descriptive text for the image;
* defaults to the filename of the image.
*
* @param int $border The border width for the image; defaults to zero.
*
* @param int $width The displayed image width in pixels; defaults to
* the width of the image.
*
* @param int $height The displayed image height in pixels; defaults to
* the height of the image.
*
* @return string An <img ... /> tag.
*
*/
public function image($file, $alt = null, $height = null, $width = null,
$attr = null)
{
// is the document root set?
if (is_null($this->documentRoot) && isset($_SERVER['DOCUMENT_ROOT'])) {
// no, so set it
$this->documentRoot = $_SERVER['DOCUMENT_ROOT'];
}
// make sure there's a DIRECTORY_SEPARATOR between the docroot
// and the image dir
if (substr($this->documentRoot, -1) != DIRECTORY_SEPARATOR &&
substr($this->imageDir, 0, 1) != DIRECTORY_SEPARATOR) {
$this->documentRoot .= DIRECTORY_SEPARATOR;
}
// make sure there's a separator between the imageDir and the
// file name
if (substr($this->imageDir, -1) != DIRECTORY_SEPARATOR &&
substr($file, 0, 1) != DIRECTORY_SEPARATOR) {
$this->imageDir .= DIRECTORY_SEPARATOR;
}
// the image file type code (PNG = 3)
$type = null;
// get the file information
$info = false;
if (strpos($file, '://') === false) {
// no "://" in the file, so it's local
$file = $this->imageDir . $file;
$tmp = $this->documentRoot . $file;
$info = @getimagesize($tmp);
} else {
// don't attempt to get file info from streams, it takes
// way too long.
$info = false;
}
// did we find the file info?
if (is_array($info)) {
// capture type info regardless
$type = $info[2];
// capture size info where both not specified
if (is_null($width) && is_null($height)) {
$width = $info[0];
$height = $info[1];
}
}
// clean up
unset($info);
// is the file a PNG? if so, check user agent, we will need to
// make special allowances for Microsoft IE.
if (stristr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && $type === 3) {
// support alpha transparency for PNG files in MSIE
$html = '<span style="position: relative;';
if ($height) {
$html .= ' height: ' . $height . 'px;';
}
if ($width) {
$html .= ' width: ' . $width . 'px;';
}
$html .= ' filter:progid:DXImageTransform.Microsoft.AlphaImageLoader';
$html .= "(src='" . htmlspecialchars($file) . "',sizingMethod='scale');\"";
$html .= ' title="' . htmlspecialchars($alt) . '"';
$html .= $this->Savant->htmlAttribs($attr);
// done
$html .= '></span>';
} else {
// not IE, so build a normal image tag.
$html = '<img';
$html .= ' src="' . htmlspecialchars($file) . '"';
// add the alt attribute
if (is_null($alt)) {
$alt = basename($file);
}
$html .= ' alt="' . htmlspecialchars($alt) . '"';
// add the height attribute
if ($height) {
$html .= ' height="' . htmlspecialchars($height) . '"';
}
// add the width attribute
if ($width) {
$html .= ' width="' . htmlspecialchars($width) . '"';
}
$html .= $this->Savant->htmlAttribs($attr);
// done
$html .= ' />';
}
// done!
return $html;
}
}
?>

View File

@@ -0,0 +1,11 @@
<?php
namespace view;
class Cron
{
public static function main_view()
{
$tpl = new \Tpl;
return $tpl -> render( 'cron/main-view' );
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace view;
class Messages {
public function drawMessages()
{
$tpl = new \Savant3;
$tpl -> _messages = \factory\Messages::getMessages();
return $tpl -> fetch( 'other/massages' );
}
}
?>

View File

@@ -0,0 +1,33 @@
<?php
namespace view;
class Page
{
public static function unlogged()
{
$tpl = new \Tpl;
return $tpl -> render( 'page/unlogged-layout' );
}
public function show()
{
global $user;
if ( !\S::get_session( 'user' ) and \S::get( 'p' ) != 'cron' )
return \view\Page::unlogged();
$tpl = new \Savant3;
$tpl -> _content = \controls\Page::getContent();
$tpl -> _alert = \S::get_session( 'alert' );
$tpl -> _messages = \view\Messages::drawMessages();
$tpl -> _user = $user;
if ( $user['type'] == 'client' or $user['type'] == 'worker' )
return $tpl -> fetch( 'client/main-layout' );
if ( $user['type'] == 'reseller' )
return $tpl -> fetch( 'reseller/main-layout' );
else
return $tpl -> fetch( 'page/main-layout' );
}
}
?>

View File

@@ -0,0 +1,20 @@
<?php
namespace view;
class PagePanel {
public function show( $add = false , $save = false , $cancel = false , $form = 'formularz' , $back = false , $update = false , $save_ajax = false, $checkbox = false )
{
$tpl = new \Savant3();
$tpl -> _add = $add;
$tpl -> _save = $save;
$tpl -> _cancel = $cancel;
$tpl -> _id_form = $form;
$tpl -> _back = $back;
$tpl -> _update = $update;
$tpl -> _save_ajax = $save_ajax;
$tpl -> _checkbox = $checkbox;
return $tpl -> fetch( 'other/page-panel' );
}
}
?>

View File

@@ -0,0 +1,139 @@
<?php
namespace view;
class Ranker
{
public function drawReportsForm()
{
$tpl = new \Savant3;
$tpl -> _sites = \factory\Ranker::getSites();
return $tpl -> fetch( 'ranker/reports' );
}
public function drawSummary( $month = '', $year = '' )
{
if ( $month ) \S::set_session( 'drawSitesList:month', $month );
if ( $year ) \S::set_session( 'drawSitesList:year', $year );
$month = \S::get_session( 'drawSitesList:month' );
$year = \S::get_session( 'drawSitesList:year' );
if ( !$month ) $month = date( 'm' );
if ( !$year ) $year = date( 'Y' );
$tpl = new \Savant3;
$tpl -> _profit = \factory\Ranker::getMonthProfit( $month, $year );
$tpl -> _clients = \factory\Ranker::getClientsSitesSummary( $month, $year );
$tpl -> _month = $month;
$tpl -> _year = $year;
return $tpl -> fetch( 'ranker/summary' );
}
public function phrase_costs_edit( $site_id, $phrase_id )
{
$tpl = new \Savant3;
$tpl -> site_id = $site_id;
$tpl -> phrase = \factory\Ranker::getPhrase( $phrase_id );
$tpl -> prices = \factory\Ranker::getPhrasePrices( $phrase_id );
return $tpl -> fetch( 'ranker/phrase-costs-edit' );
}
public function drawClientEdit( $id = '' )
{
$tpl = new \Savant3;
$tpl -> _client = \factory\Ranker::getClient( $id );
$tpl -> _sites = \factory\Ranker::getSites();
return $tpl -> fetch( 'ranker/client-edit' );
}
public function drawClientList()
{
$tpl = new \Tpl;
return $tpl -> render( 'ranker/client-list' );
$out = \view\PagePanel::show( true, false, false, 'Dodaj klienta' );
$type[0] = 'klient';
$type[1] = 'reseller';
$dbrowse = new \DataBrowse( 'pro_rr_clients' );
$dbrowse -> addPosition( 'login', 'Login', '', '', '', true );
$dbrowse -> addPosition( 'password', 'Hasło', '', '', '', true );
$dbrowse -> addPosition( 'enabled', 'Aktywny', '', \S::getComboYesNo(), 'text-align: center;' );
$dbrowse -> addPosition( 'last_logged', 'Ost. logowanie', '', '', 'text-align: center;', 'last_logged' );
$dbrowse -> addPosition( 'type', 'Typ', '', $type, 'text-align: center;' );
$dbrowse -> addPositionSimple( 'edytuj' , 'Edytuj' , './?rw=edit' );
$dbrowse -> addPositionSimple( 'usuń' , 'Usuń' , '' , \S::deleteAction() );
$dbrowse -> setParam( 'id' );
$dbrowse -> addSort( 'last_logged DESC' );
$dbrowse -> addLp();
$dbrowse -> addFiltr( 'login', 'Login' );
$dbrowse -> addFiltr( 'enabled', 'Aktywny', \S::getComboYesNo() );
$dbrowse -> addFiltr( 'type', 'Typ', $type );
$dbrowse -> addMenu( $out );
return $dbrowse -> draw();
}
public function phrase_edit( $site_id, $phrase_id = '' )
{
$tpl = new \Tpl;
$tpl -> site_id = $site_id;
$tpl -> phrase = \factory\Ranker::getPhrase( $phrase_id );
$tpl -> sites = \factory\Ranker::getSites();
return $tpl -> render( 'ranker/phrase-edit' );
}
public static function main_view( $id = '', $month = '', $year = '' )
{
global $user;
if ( $user['type'] != 'admin' )
return false;
if ( $id !== null )
\S::set_session( 'ranker:main_view:id', $id );
if ( $month )
\S::set_session( 'ranker:main_view:month', $month );
if ( $year )
\S::set_session( 'ranker:main_view:year', $year );
if ( !$month and !\S::get_session( 'ranker:main_view:month' ) )
{
$month = date( 'm' );
\S::set_session( 'ranker:main_view:month', $month );
}
if ( !$year and !\S::get_session( 'ranker:main_view:year' ) )
{
$year = date( 'Y' );
\S::set_session( 'ranker:main_view:year', $year );
}
$month = \S::get_session( 'ranker:main_view:month' );
$year = \S::get_session( 'ranker:main_view:year' );
$id = \S::get_session( 'ranker:main_view:id' );
if ( !$id )
$id = \factory\Ranker::first_site_id();
$site = \factory\Ranker::site_details( $id );
$tpl = new \Tpl;
$tpl -> day_profit = \factory\Ranker::day_profit();
$tpl -> month_profit = \factory\Ranker::getMonthProfit( $month, $year );
$tpl -> sites = \factory\Ranker::sites_list();
$tpl -> phrases = \factory\Ranker::site_phrases_details( $site['id'], $month, $year, '', '', $user['login'] );
$tpl -> next_site_id = \factory\Ranker::next_site_id( $site['id'] );
$tpl -> prev_site_id = \factory\Ranker::prev_site_id( $site['id'] );
$tpl -> majestic = \factory\Ranker::majestic( $site['id'] );
$tpl -> semstorm = \factory\Ranker::semstorm( $site['id'] );
$tpl -> comments = \factory\Ranker::site_comments( $site['id'], $month, $year );
$tpl -> site = $site;
$tpl -> month = $month;
$tpl -> year = $year;
$tpl -> sites_to_confirm = \factory\Ranker::sites_to_confirm();
return $tpl -> render( 'ranker/main-view' );
}
}
?>

View File

@@ -0,0 +1,85 @@
<?php
namespace view;
class RankerClients
{
public static function site_edit( $site_id )
{
$tpl = new \Savant3;
$tpl -> _site = \factory\Ranker::getSite( $site_id, 'ASC', true );
return $tpl -> fetch( 'client/site-edit' );
}
public function drawReportsForm()
{
global $user;
$tpl = new \Savant3;
$tpl -> _sites = \factory\RankerClients::getSites( $user['id'] );
return $tpl -> fetch( 'client/reports' );
}
public function drawSummary( $month = '', $year = '' )
{
global $user;
if ( $month ) \S::set_session( 'drawSitesList:month', $month );
if ( $year ) \S::set_session( 'drawSitesList:year', $year );
$month = \S::get_session( 'drawSitesList:month' );
$year = \S::get_session( 'drawSitesList:year' );
if ( !$month ) $month = date( 'm' );
if ( !$year ) $year = date( 'Y' );
$tpl = new \Savant3;
$tpl -> _sites = \factory\RankerClients::getSitesSummary( $month, $year, $user['id'], $user['login'] );
$tpl -> _month = $month;
$tpl -> _year = $year;
return $tpl -> fetch( 'client/ranker-summary' );
}
public function main_view( $id, $month = '', $year = '' )
{
global $user;
if ( $id !== null )
\S::set_session( 'ranker:main_view:id', $id );
if ( $month )
\S::set_session( 'ranker:main_view:month', $month );
if ( $year )
\S::set_session( 'ranker:main_view:year', $year );
if ( !$month and !\S::get_session( 'ranker:main_view:month' ) )
{
$month = date( 'm' );
\S::set_session( 'ranker:main_view:month', $month );
}
if ( !$year and !\S::get_session( 'ranker:main_view:year' ) )
{
$year = date( 'Y' );
\S::set_session( 'ranker:main_view:year', $year );
}
$month = \S::get_session( 'ranker:main_view:month' );
$year = \S::get_session( 'ranker:main_view:year' );
$id = \S::get_session( 'ranker:main_view:id' );
$site = \factory\RankerClients::getClientSite( $id, $user['id'] );
$tpl = new \Tpl;
$tpl -> sites = \factory\RankerClients::getClientSites( $user['id'] );
$tpl -> phrases = \factory\Ranker::getSitePhrases( $site['id'], $month, $year, false, $user['reseller_id'], $user['login'] );
$tpl -> comments = \factory\Ranker::site_comments( $site['id'], $month, $year );
$tpl -> site = $site;
$tpl -> month = $month;
$tpl -> year = $year;
$tpl -> next_site_id = \factory\RankerClients::getNextClientSiteId( $site['id'], $user['id'] );
$tpl -> prev_site_id = \factory\RankerClients::getPrevClientSiteId( $site['id'], $user['id'] );
return $tpl -> render( 'client/site-list' );
}
}
?>

View File

@@ -0,0 +1,101 @@
<?php
namespace view;
class RankerReseller {
public function drawReportsForm()
{
global $user;
$tpl = new \Savant3;
$tpl -> _sites = \factory\RankerReseller::getSites( $user['id'] );
return $tpl -> fetch( 'reseller/reports' );
}
public function drawSummary( $month = '', $year = '' )
{
global $user;
if ( $month ) \S::set_session( 'drawSitesList:month', $month );
if ( $year ) \S::set_session( 'drawSitesList:year', $year );
$month = \S::get_session( 'drawSitesList:month' );
$year = \S::get_session( 'drawSitesList:year' );
if ( !$month ) $month = date( 'm' );
if ( !$year ) $year = date( 'Y' );
$tpl = new \Savant3;
$tpl -> _sites = \factory\RankerReseller::getSitesSummary( $month, $year, $user['id'], $user['reseller_id'] );
$tpl -> _sites_res = \factory\RankerReseller::getSitesSummary( $month, $year, $user['id'], $user['id'] );
$tpl -> _month = $month;
$tpl -> _year = $year;
return $tpl -> fetch( 'reseller/ranker-summary' );
}
public function phraseEdit( $site_id, $phrase_id = '', $reseller_id )
{
$tpl = new \Savant3;
$tpl -> _site_id = $site_id;
$tpl -> _reseller_id = $reseller_id;
$tpl -> _phrase = \factory\Ranker::getPhrase( $phrase_id, $reseller_id);
return $tpl -> fetch( 'reseller/phrase-edit' );
}
public function editCosts( $site_id, $phrase_id, $reseller_id )
{
$tpl = new \Savant3;
$tpl -> _site_id = $site_id;
$tpl -> _reseller_id = $reseller_id;
$tpl -> _phrase = \factory\Ranker::getPhrase( $phrase_id );
$tpl -> _prices = \factory\Ranker::getPhrasePrices( $phrase_id, $reseller_id );
return $tpl -> fetch( 'reseller/costs-edit' );
}
public function drawSitesList( $id, $month = '', $year = '' )
{
global $user;
if ( $id ) \S::set_session( 'drawSitesList:id', $id );
if ( $month ) \S::set_session( 'drawSitesList:month', $month );
if ( $year ) \S::set_session( 'drawSitesList:year', $year );
$month = \S::get_session( 'drawSitesList:month' );
$year = \S::get_session( 'drawSitesList:year' );
$id = \S::get_session( 'drawSitesList:id' );
if ( !$month ) $month = date( 'm' );
if ( !$year ) $year = date( 'Y' );
$site = \factory\RankerClients::getClientSite( $id, $user['id'] );
$tpl = new \Savant3;
$tpl -> _sites = \factory\RankerClients::getClientSites( $user['id'] );
$tpl -> _phrases = \factory\Ranker::getSitePhrases( $site['id'], $month, $year, false, $user['reseller_id'], $user['login'] );
$tpl -> _phrases_reseller = \factory\Ranker::getSitePhrases( $site['id'], $month, $year, false, $user['id'], $user['login'] );
$tpl -> _site = $site;
$tpl -> _month = $month;
$tpl -> _year = $year;
$tpl -> _next_site_id = \factory\RankerClients::getNextClientSiteId( $site['id'], $user['id'] );
$tpl -> _prev_site_id = \factory\RankerClients::getPrevClientSiteId( $site['id'], $user['id'] );
return $tpl -> fetch( 'reseller/site-list' );
}
public function drawClientEdit( $id = '' )
{
global $user;
$tpl = new \Savant3;
$tpl -> _reseller_id = $user['id'];
$tpl -> _client = \factory\Ranker::getClient( $id );
$tpl -> _sites = \factory\RankerClients::getClientSites( $user['id'] );
return $tpl -> fetch( 'reseller/client-edit' );
}
public static function drawClientList()
{
$tpl = new \Tpl;
return $tpl -> render( 'reseller/client-list' );
}
}
?>

View File

@@ -0,0 +1,12 @@
<?php
namespace view;
class Settings {
public function drawSettings()
{
$tpl = new \Savant3;
return $tpl -> fetch( 'other/settings' );
}
}
?>