forked from 4ducky/4ducky
mirror
This commit is contained in:
+649
@@ -0,0 +1,649 @@
|
||||
<?php
|
||||
/**
|
||||
* Generate a simple api
|
||||
*
|
||||
* @author Daniel Leitner
|
||||
* @version 1.2
|
||||
* @link mail@danielleitner.de
|
||||
*/
|
||||
|
||||
class Api {
|
||||
|
||||
/**
|
||||
* Mysql connection
|
||||
*
|
||||
* @var resource
|
||||
* @access private
|
||||
*/
|
||||
private $_db;
|
||||
|
||||
/**
|
||||
* Store namcespaces
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
private $_namespaces = array();
|
||||
|
||||
/**
|
||||
* Working namespace name
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
private $_current_namaspace;
|
||||
|
||||
/**
|
||||
* Namespace which is rendered
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
private $_render_namepsace;
|
||||
|
||||
/**
|
||||
* Url data
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
private $_route_data;
|
||||
|
||||
/**
|
||||
* Class options
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
private $_options = array(
|
||||
'output_types' => array(
|
||||
'json', 'xml', 'csv', 'yaml'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Rules to check the route
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
private $_rules = array(
|
||||
'alpha_numeric', 'numeric'
|
||||
);
|
||||
|
||||
/**
|
||||
* Select result for api
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_result = array();
|
||||
|
||||
/**
|
||||
* Let the magic start ;)
|
||||
*
|
||||
* @param resource $db
|
||||
* @access public
|
||||
*/
|
||||
public function __construct($db) {
|
||||
|
||||
$this->_db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register new namespace
|
||||
*
|
||||
* @param type $namespace
|
||||
* @todo Set defaults to array
|
||||
* @access public
|
||||
* @return Api
|
||||
*/
|
||||
public function register($namespace) {
|
||||
|
||||
if( ! isset($this->_namespaces[$namespace]) ) {
|
||||
$this->_namespaces[$namespace] = array(
|
||||
'key' => false,
|
||||
'sort' => false,
|
||||
'request' => false,
|
||||
'limit' => false,
|
||||
'cache' => false,
|
||||
'conditions' => false
|
||||
);
|
||||
|
||||
$this->_current_namaspace = $namespace;
|
||||
} else {
|
||||
$this->_error('Namespace already exists.');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $message
|
||||
* @access private
|
||||
* @todo output
|
||||
* @return Api
|
||||
*/
|
||||
private function _error($message) {
|
||||
header("Content-Type: application/json");
|
||||
|
||||
die(json_encode($message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set table name
|
||||
*
|
||||
* @param string $table
|
||||
* @return Api
|
||||
*/
|
||||
public function setTable($table) {
|
||||
|
||||
if( is_string($table) ) {
|
||||
$this->_namespaces[$this->_current_namaspace]['table'] = $table;
|
||||
} else {
|
||||
$this->_error('Table name musst be a string.');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set output type
|
||||
*
|
||||
* @access public
|
||||
* @param array|string $output
|
||||
* @return Api
|
||||
*/
|
||||
public function setOutput($output) {
|
||||
|
||||
if( is_array($output) ) {
|
||||
foreach($output as $o) {
|
||||
if( ! in_array($o, $this->_options['output_types']) ) {
|
||||
$this->_error('Output as '.$o.' is not supported.');
|
||||
}
|
||||
}
|
||||
|
||||
$this->_namespaces[$this->_current_namaspace]['output'] = $output;
|
||||
} else {
|
||||
|
||||
if( ! in_array($output, $this->_options['output_types']) ) {
|
||||
$this->_error('Output as '.$output.' is not supported.');
|
||||
}
|
||||
|
||||
$this->_namespaces[$this->_current_namaspace]['output'] = $output;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if unique key is required (false = default)
|
||||
*
|
||||
* @access public
|
||||
* @param boolean $key
|
||||
* @return Api
|
||||
*/
|
||||
public function setKey($key) {
|
||||
|
||||
if( is_bool($key) ) {
|
||||
$this->_namespaces[$this->_current_namaspace]['key'] = $key;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set request limit per hour. (false = default)
|
||||
*
|
||||
* @access public
|
||||
* @param integer $limit
|
||||
* @return Api
|
||||
*/
|
||||
public function setLimit($limit) {
|
||||
|
||||
if( is_integer($limit) ) {
|
||||
$this->_namespaces[$this->_current_namaspace]['limit'] = $limit;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Limit output
|
||||
public function setRequest($request) {
|
||||
|
||||
if( is_integer($request) ) {
|
||||
$this->_namespaces[$this->_current_namaspace]['request'] = $request;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
// Sort output
|
||||
public function setSort($sort) {
|
||||
|
||||
if( is_string($sort) ) {
|
||||
$this->_namespaces[$this->_current_namaspace]['sort'] = $sort;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate cache
|
||||
*
|
||||
* @param integer $time
|
||||
* @param string $folder
|
||||
* @return Api
|
||||
*/
|
||||
public function setCache($time, $folder) {
|
||||
|
||||
if( ! is_dir($folder) ) {
|
||||
$this->_error('Cache folder musst be a folder.');
|
||||
}
|
||||
|
||||
if( ! is_integer($time) ) {
|
||||
$this->_error('Cache time musst be integer.');
|
||||
}
|
||||
|
||||
$this->_namespaces[$this->_current_namaspace]['cache'] = array(
|
||||
'folder' => $folder,
|
||||
'time' => $time
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set columns which should be displayed
|
||||
*
|
||||
* @param array $columns
|
||||
* @return Api
|
||||
*/
|
||||
public function setColumns($columns) {
|
||||
|
||||
if( is_array($columns) ) {
|
||||
$this->_namespaces[$this->_current_namaspace]['columns'] = $columns;
|
||||
} else {
|
||||
$this->_error('Columns musst be given as array.');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set conditions for data
|
||||
*
|
||||
* @param array $conditions
|
||||
* @return Api
|
||||
*/
|
||||
public function setWhere($conditions) {
|
||||
|
||||
if( is_array($conditions) ) {
|
||||
$this->_namespaces[$this->_current_namaspace]['conditions'] = $conditions;
|
||||
} else {
|
||||
$this->_error('Where conditions musst be given as array.');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output data
|
||||
*
|
||||
* @access public
|
||||
* @param arra $route
|
||||
*/
|
||||
public function render($route) {
|
||||
if( ! isset($route['namespace']) || ! isset($this->_namespaces[$route['namespace']]) || strlen($route['namespace']) == 0 ) {
|
||||
$this->_error('No namespace found.');
|
||||
}
|
||||
|
||||
$this->_render_namepsace = $route['namespace'];
|
||||
|
||||
// secure input
|
||||
foreach($route as $key => $value) {
|
||||
$route[strip_tags($key)] = strip_tags($value);
|
||||
}
|
||||
|
||||
$this->_route_data = $route;
|
||||
|
||||
// check if connection is working
|
||||
if( ! mysql_ping($this->_db) ) {
|
||||
$this->_error('Database connection is not working.');
|
||||
}
|
||||
|
||||
// check if request limit is reached
|
||||
if( ! $this->_check_key() ) {
|
||||
$this->_error('Soory, but your api key is not valid.');
|
||||
}
|
||||
|
||||
// check if request limit is reached
|
||||
if( ! $this->_check_request() ) {
|
||||
$this->_error('Soory, you reached the maximum request limit per hour ('.$this->_namespaces[$this->_render_namepsace]['limit'].').');
|
||||
}
|
||||
|
||||
// get data from mysql table
|
||||
if( ! $this->_create() ) {
|
||||
$this->_error('Soory, but the system was not able to generate data.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the user key is valid
|
||||
*
|
||||
* @access private
|
||||
* @return boolean
|
||||
*/
|
||||
private function _check_key() {
|
||||
if( $this->_namespaces[$this->_render_namepsace]['key'] == true ) {
|
||||
$result = mysql_query('SELECT id FROM api_keys WHERE hash = "'.mysql_real_escape_string($this->_route_data['key']).'"', $this->_db) or die(mysql_error());
|
||||
|
||||
if( mysql_num_rows($result) == false ) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if request limit is reached
|
||||
*
|
||||
* @access prviate
|
||||
* @return boolean
|
||||
*/
|
||||
private function _check_request() {
|
||||
|
||||
if( $this->_namespaces[$this->_render_namepsace]['limit'] != false ) {
|
||||
// check request limit
|
||||
|
||||
// delete old requests
|
||||
if( $this->_namespaces[$this->_render_namepsace]['key'] == true ) {
|
||||
// request limit with key
|
||||
|
||||
// delete old requests
|
||||
mysql_query('DELETE FROM api_requests WHERE hash = "'.mysql_real_escape_string($this->_route_data['key']).'" AND ((UNIX_TIMESTAMP() - time) > 3600) AND namespace = "'.$this->_render_namepsace.'"', $this->_db) or die(mysql_error());
|
||||
|
||||
// count stored requests
|
||||
$result = mysql_query('SELECT COUNT(time) AS requests FROM api_requests WHERE hash = "'.mysql_real_escape_string($this->_route_data['key']).'" AND ((UNIX_TIMESTAMP() - time) < 3600) AND namespace = "'.$this->_render_namepsace.'"', $this->_db) or die(mysql_error());
|
||||
|
||||
$total_requests = mysql_fetch_array($result);
|
||||
|
||||
if( $total_requests['requests'] >= $this->_namespaces[$this->_render_namepsace]['limit'] ) {
|
||||
// request limit reached
|
||||
return false;
|
||||
} else {
|
||||
|
||||
// insert new request
|
||||
mysql_query('INSERT INTO api_requests (namespace, hash, ip, time) VALUES("'.$this->_render_namepsace.'", "'.mysql_real_escape_string($this->_route_data['key']).'", "'.$_SERVER['REMOTE_ADDR'].'", "'.time().'")', $this->_db) or die(mysql_error());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} else {
|
||||
// request limit without key
|
||||
|
||||
// delete old requests
|
||||
mysql_query('DELETE FROM api_requests WHERE ((UNIX_TIMESTAMP() - time) > 3600) AND namespace = "'.$this->_render_namepsace.'"', $this->_db) or die(mysql_error());
|
||||
|
||||
// count stored requests
|
||||
$result = mysql_query('SELECT COUNT(time) AS requests FROM api_requests WHERE ((UNIX_TIMESTAMP() - time) < 3600) AND namespace = "'.$this->_render_namepsace.'"', $this->_db) or die(mysql_error());
|
||||
|
||||
$total_requests = mysql_fetch_array($result);
|
||||
|
||||
if( $total_requests['requests'] >= $this->_namespaces[$this->_render_namepsace]['limit'] ) {
|
||||
// request limit reached
|
||||
return false;
|
||||
} else {
|
||||
|
||||
// insert new request
|
||||
mysql_query('INSERT INTO api_requests (namespace, ip, time) VALUES("'.$this->_render_namepsace.'", "'.$_SERVER['REMOTE_ADDR'].'", "'.time().'")', $this->_db) or die(mysql_error());
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// no limit is set
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Array to json
|
||||
*
|
||||
* @access private
|
||||
* @return json
|
||||
*/
|
||||
private function _write_json() {
|
||||
|
||||
header("Content-Type: application/json");
|
||||
|
||||
return json_encode($this->_result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Array to xml
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
private function _write_xml() {
|
||||
|
||||
header("Content-Type: application/xml");
|
||||
|
||||
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
||||
|
||||
$xml .= "<root>";
|
||||
|
||||
foreach($this->_result as $key => $value) {
|
||||
$xml .= "<{$this->_render_namepsace}>\n";
|
||||
|
||||
foreach($value as $k => $d) {
|
||||
$xml .= "<{$k}>{$d}</{$k}>\n";
|
||||
}
|
||||
|
||||
$xml .= "</{$this->_render_namepsace}>\n";
|
||||
}
|
||||
|
||||
$xml .= "</root>";
|
||||
|
||||
return $xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array to csv
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
private function _write_csv() {
|
||||
$lines = array();
|
||||
|
||||
foreach ($this->_result as $key => $value) {
|
||||
|
||||
$lines[] = implode(';', array_filter($value, function($var) {
|
||||
return $var;
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
return implode("\n", $lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* Array to yaml
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
private function _write_yaml() {
|
||||
$yaml = "---\n";
|
||||
|
||||
$yaml .= "{$this->_render_namepsace}: \n";
|
||||
|
||||
foreach($this->_result as $key => $value) {
|
||||
$yaml .= "-";
|
||||
$count = 0;
|
||||
|
||||
foreach($value as $k => $d) {
|
||||
if( $count != 0 ) {
|
||||
$yaml .= " ";
|
||||
}
|
||||
|
||||
$yaml .= " {$k}: {$d} \n";
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
return $yaml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets data from database
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
private function _get() {
|
||||
|
||||
foreach($this->_namespaces[$this->_render_namepsace]['columns'] as $c) {
|
||||
$columns .= $c.', ';
|
||||
}
|
||||
|
||||
$sql = 'SELECT '.substr($columns, 0, -2).' FROM ' .
|
||||
$this->_namespaces[$this->_render_namepsace]['table'];
|
||||
|
||||
if( $this->_namespaces[$this->_render_namepsace]['conditions'] != false ) {
|
||||
$sql .= ' WHERE ';
|
||||
|
||||
foreach($this->_namespaces[$this->_render_namepsace]['conditions'] as $where => $data) {
|
||||
|
||||
if( ! isset($this->_route_data[$data['route']]) ) {
|
||||
$this->_error('Route '.$data['route'].' is required.');
|
||||
}
|
||||
|
||||
// validate
|
||||
if( isset($data['rule']) ) {
|
||||
if( ! in_array($data['rule'], $this->_rules) ) {
|
||||
$this->_error('Rule '.$data['rule'].' is not avaiable.');
|
||||
}
|
||||
|
||||
$rule = '_'.$data['rule'];
|
||||
|
||||
if( ! $this->$rule($this->_route_data[$data['route']]) ) {
|
||||
$this->_error('Wrong route format.');
|
||||
}
|
||||
}
|
||||
|
||||
$sql .= $where.' = "'.mysql_real_escape_string($this->_route_data[$data['route']]).'"';
|
||||
|
||||
if( isset($data['connect']) ) {
|
||||
$sql .= ' '.$data['connect'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( $this->_namespaces[$this->_render_namepsace]['sort'] != false ) {
|
||||
$sql .= ' ORDER BY ' . $this->_namespaces[$this->_render_namepsace]['sort'];
|
||||
}
|
||||
|
||||
if( $this->_namespaces[$this->_render_namepsace]['request'] != false ) {
|
||||
$sql .= ' LIMIT ' . $this->_namespaces[$this->_render_namepsace]['request'];
|
||||
}
|
||||
|
||||
$result = mysql_query($sql, $this->_db) or die(mysql_error());
|
||||
|
||||
if( mysql_num_rows($result) == false ) {
|
||||
$this->_error('No results found.');
|
||||
}
|
||||
|
||||
// write data to a nice array
|
||||
for($i = 0; $i < mysql_num_rows($result); $i++)
|
||||
{
|
||||
$dump[$i] = mysql_fetch_array($result, MYSQL_ASSOC);
|
||||
}
|
||||
|
||||
$this->_result = $dump;
|
||||
}
|
||||
|
||||
private function _alpha_numeric($validate) {
|
||||
if( ctype_alnum($validate) ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function _numeric($validate) {
|
||||
if( ctype_digit($validate) ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function _create() {
|
||||
|
||||
|
||||
if( $this->_namespaces[$this->_render_namepsace]['cache'] == false ) {
|
||||
|
||||
$this->_get();
|
||||
|
||||
} else {
|
||||
// cache is turned on
|
||||
if( $this->_namespaces[$this->_render_namepsace]['key'] == false ) {
|
||||
// key musst truned off
|
||||
|
||||
$file = $this->_namespaces[$this->_render_namepsace]['cache']['folder'].sha1($this->_render_namepsace).'.txt';
|
||||
|
||||
if( ! file_exists($file) || (time() - filemtime($file) > $this->_namespaces[$this->_render_namepsace]['cache']['time']) ) {
|
||||
|
||||
// write to cache and delete old file
|
||||
@unlink($file);
|
||||
|
||||
$f = fopen($file, 'w');
|
||||
|
||||
$this->_get();
|
||||
|
||||
$cache = new stdClass;
|
||||
$cache->result = $this->_result;
|
||||
|
||||
fwrite($f, serialize($cache));
|
||||
|
||||
fclose($f);
|
||||
}
|
||||
|
||||
// read from cache
|
||||
$data = unserialize(file_get_contents($file));
|
||||
|
||||
$this->_result = $data->result;
|
||||
|
||||
|
||||
} else {
|
||||
$this->_namespaces[$this->_render_namepsace]['cache'] = false;
|
||||
|
||||
$this->_create();
|
||||
}
|
||||
}
|
||||
|
||||
$type_function = '_write_';
|
||||
|
||||
if( is_array($this->_namespaces[$this->_render_namepsace]['output']) ) {
|
||||
if( isset($this->_route_data['output']) ) {
|
||||
$type_function .= $this->_route_data['output'];
|
||||
} else {
|
||||
$type_function .= $this->_namespaces[$this->_render_namepsace]['output'][0];
|
||||
}
|
||||
} else {
|
||||
$type_function .= $this->_namespaces[$this->_render_namepsace]['output'];
|
||||
}
|
||||
|
||||
|
||||
die($this->$type_function());
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
class SimpleBBCode {
|
||||
|
||||
protected $bbcodes = array();
|
||||
|
||||
public function __construct() {
|
||||
|
||||
//standard bbcodes hinzufügen
|
||||
$this->assign('\[b\](.*)\[/b\]', '<strong>$1</strong>');
|
||||
$this->assign('\[i\](.*)\[/i\]', '<em>$1</em>');
|
||||
$this->assign('\[u\](.*)\[/u\]', '<u>$1</u>');
|
||||
$this->assign('\[quote\](?s)(.*)\[/quote\]', '<span class="quote">$1</span>');
|
||||
$this->assign('\[img\](.*)\[/img\]', '"<a href=\"" . htmlentities(\'\\1\', ENT_COMPAT) . "\" rel=\"lightbox[more]\" target=\"_blank\"><img onError=\"this.src=\'/media/dolan404.jpg\';\" src=\"" . htmlentities(\'\\1\', ENT_COMPAT) . "\" border=\"0\" class=\"imgbbcode\"></a>"', true);
|
||||
$this->assign('\[youtube\](.*)\[/youtube\]', '$this->handleYoutubeBBcode(\'\\1\')', true);
|
||||
$this->assign('\[xxx\](.*)\[/xxx\]', '$this->handlePornBBcode(\'\\1\')', true);
|
||||
$this->assign('\[link\](.*)\[/link\]', '$this->handleLinkBBcode(\'\\1\')', true);
|
||||
$this->assign('\[spoiler\](?s)(.*)\[/spoiler\]', '<span class="Spoiler">$1</span>');
|
||||
}
|
||||
|
||||
public function parse($content) {
|
||||
if(!count($this->bbcodes)) return $content;
|
||||
|
||||
foreach($this->bbcodes as $bbcode) {
|
||||
while(preg_match('~' . $bbcode['find'] . '~U', $content)) {
|
||||
if(isset($bbcode['eval']))
|
||||
$content = preg_replace('~' . $bbcode['find'] . '~Ue', $bbcode['eval'], $content);
|
||||
else $content = preg_replace('~' . $bbcode['find'] . '~U', $bbcode['replace'], $content);
|
||||
}
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function assign($find, $replace, $eval = false) {
|
||||
$pattern = array('find' => $find);
|
||||
$pattern[(($eval === true) ? 'eval' : 'replace')] = $replace;
|
||||
$this->bbcodes[] = $pattern;
|
||||
}
|
||||
|
||||
protected function handleYoutubeBBcode($url) {
|
||||
|
||||
if(preg_match("/youtube/i",$url)) {
|
||||
$stack = array();
|
||||
preg_match('/v=([A-z0-9=\-]+?)(&.*)?$/i', $url, $stack);
|
||||
if(empty($stack[1])) return '';
|
||||
$watch = $stack[1]; //\w kann nur a-zA-Z0-9_. sein, kein risiko
|
||||
} else {
|
||||
$watch = preg_replace('~\W+~', '', $url);
|
||||
if(empty($watch)) return '';
|
||||
}
|
||||
|
||||
return "<a href=\"javascript:;\" id=\"YTbutton\" onclick=\"toggle('YT" . $watch . "')\">[youtube]</a><iframe id=\"YT" . $watch . "\" width=\"425\" style=\"display:none;\" height=\"344\" src=\"http://www.youtube.com/embed/".$watch."\" frameborder=\"0\" allowfullscreen></iframe>";
|
||||
}
|
||||
|
||||
protected function handlePornBBcode($url) {
|
||||
|
||||
if(preg_match("/xvideo/i",$url)) {
|
||||
$source = "http://flashservice.xvideos.com/embedframe/";
|
||||
preg_match_all("/.*?(\d+)/is", $url, $matches);
|
||||
$watch=$matches[1][0];
|
||||
}
|
||||
/*else if(preg_match("/pornhub/i",$url)){
|
||||
$source = "http://www.pornhub.com/embed/";
|
||||
preg_match_all("/.*?(\d+)/is", $url, $matches);
|
||||
$watch=$matches[1][0];
|
||||
}*/
|
||||
else{
|
||||
if(empty($watch)) return '';
|
||||
}
|
||||
|
||||
return "<a href=\"javascript:;\" id=\"Pornbutton\" onclick=\"toggle('Porn" . $watch . "')\">[xxx]</a><iframe id=\"Porn" .$watch. "\" width=\"425\" height=\"344\" style=\"display:none;\" src=\"".$source.$watch."\" frameborder=\"0\"></iframe>";
|
||||
}
|
||||
|
||||
protected function handleLinkBBcode($text) {
|
||||
if (!empty($text)){
|
||||
if (preg_match("/is.gd/i", $text)) {
|
||||
$text = preg_replace('#(?<!\w)((http://)|(www\.))([^\s<>]+)#i', "<a target=\"_blank\" href=\"http://$3$4\">$text</a>",$text);
|
||||
return($text);
|
||||
}
|
||||
else {
|
||||
$link = $text;
|
||||
$text = preg_replace('#(?<!\w)((http://)|(www\.))([^\s<>]+)#i', "<a target=\"_blank\" href=\"http://$3$4\">$link</a>",$text);
|
||||
return($text);
|
||||
}
|
||||
}
|
||||
else{
|
||||
return("Link-Fail");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
function short($url){
|
||||
$res = "";
|
||||
$handle = @fopen("http://is.gd/api.php?longurl=".urlencode($url), "rb");
|
||||
if($handle){
|
||||
while (!feof($handle)) {
|
||||
$res .= fgets($handle,2000);
|
||||
}
|
||||
fclose($handle);
|
||||
}
|
||||
else{
|
||||
throw new Exception("Link kann nicht gekürzt werden!");
|
||||
}
|
||||
return $res;
|
||||
}*/
|
||||
?>
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
The Cache class reads and writes complete pages from the cache.
|
||||
The name of a cache file is based on its URL
|
||||
*/
|
||||
|
||||
class Cache {
|
||||
private $fileName = '';
|
||||
private $path = '';
|
||||
private $enabled = true;
|
||||
private $captured = false;
|
||||
|
||||
public function __construct( $path, $pageName ) {
|
||||
$this->path = $path;
|
||||
$this->fileName = $this->path . strtr( $pageName, '?&', '--' ) . '.html';
|
||||
|
||||
if( $_SERVER['REQUEST_METHOD'] != 'GET' ) {
|
||||
$this->enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function disable() {
|
||||
$this->enabled = false;
|
||||
}
|
||||
|
||||
public function forceEnable() {
|
||||
$this->enabled = true;
|
||||
}
|
||||
|
||||
public function lookup() {
|
||||
if( $this->enabled && file_exists($this->fileName) ) {
|
||||
$fp = fopen($this->fileName, 'rb');
|
||||
fpassthru($fp);
|
||||
fclose($fp);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
public function capture() {
|
||||
if( $this->enabled ) {
|
||||
ob_start();
|
||||
$this->captured = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function clear( $pattern = '' ) {
|
||||
require_once( 'lib/filesystem.php' );
|
||||
if( empty($pattern) && !empty($this->path) ) {
|
||||
Filesystem::rmdirr( $this->path, true );
|
||||
} else {
|
||||
$files = glob( $this->path . 'all/view/' . strtr( $pattern, '?&', '--' ) . '.html' );
|
||||
foreach( $files as $f ) {
|
||||
unlink( $f );
|
||||
}
|
||||
$files = glob( $this->path . 'user/*/view/' . strtr( $pattern, '?&', '--' ) . '.html' );
|
||||
foreach( $files as $f ) {
|
||||
unlink( $f );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function write() {
|
||||
if( $this->captured ) {
|
||||
require_once( 'lib/filesystem.php' );
|
||||
Filesystem::mkdirr( dirname($this->fileName) );
|
||||
file_put_contents( $this->fileName, ob_get_contents() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,323 @@
|
||||
<?php
|
||||
define('FORUMPATH', realpath(dirname(__FILE__)).Config::$vbbIntegration['path']);
|
||||
|
||||
function userdata_convert(&$userdata) {
|
||||
$vbuser = array( 'username' => $userdata['name'] );
|
||||
if (isset($userdata['email']))
|
||||
$vbuser['email'] = $userdata['email'];
|
||||
if (isset($userdata['pass']))
|
||||
$vbuser['password'] = $userdata['pass'];
|
||||
|
||||
return $vbuser;
|
||||
}
|
||||
|
||||
|
||||
define('REGISTERED_USERGROUP', 2); // typical default for registered users
|
||||
define('PERMANENT_COOKIE', false); // false=session cookies (recommended)
|
||||
|
||||
define('THIS_SCRIPT', __FILE__);
|
||||
$cwd = getcwd();
|
||||
chdir(FORUMPATH);
|
||||
require_once('./includes/init.php'); // includes class_core.php
|
||||
require_once('./includes/class_dm.php'); // for class_dm_user.php
|
||||
require_once('./includes/class_dm_user.php'); // for user functions
|
||||
require_once('./includes/functions.php'); // vbsetcookie etc.
|
||||
require_once('./includes/functions_login.php'); // process login/logout
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// This function duplicates the functionality of fetch_userinfo(),
|
||||
// using the user name instead of numeric ID as the argument.
|
||||
// See comments in includes/functions.php for documentation.
|
||||
//---------------------------------------------------------------------
|
||||
function fetch_userinfo_from_username(&$username, $option=0, $languageid=0)
|
||||
{
|
||||
global $vbulletin;
|
||||
$useridq = $vbulletin->db->query_first_slave("SELECT userid FROM "
|
||||
. TABLE_PREFIX . "user WHERE username='{$username}'");
|
||||
if (!$useridq) return $useridq;
|
||||
$userid = $useridq['userid'];
|
||||
return fetch_userinfo($userid, $option, $languageid);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// CLASS ForumOps
|
||||
//---------------------------------------------------------------------
|
||||
class ForumOps extends vB_DataManager_User {
|
||||
var $userdm;
|
||||
|
||||
// *********************************************************************************************************
|
||||
|
||||
function __construct( &$vbulletin ) // constructor
|
||||
{
|
||||
$this->vbulletin =& $vbulletin;
|
||||
$this->userdm =& datamanager_init('user', $vbulletin, ERRTYPE_ARRAY);
|
||||
}
|
||||
|
||||
function ForumOps() // constructor
|
||||
{
|
||||
global $vbulletin;
|
||||
$this->userdm =& datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);
|
||||
}
|
||||
|
||||
// *********************************************************************************************************
|
||||
|
||||
//======== USER REGISTRATION / UPDATE / DELETE ========
|
||||
|
||||
function register_newuser(&$userdata, $login = true)
|
||||
{
|
||||
global $vbulletin;
|
||||
$vbuser = userdata_convert($userdata);
|
||||
foreach($vbuser as $key => $value)
|
||||
$this->userdm->set($key, $value);
|
||||
$this->userdm->set('usergroupid', REGISTERED_USERGROUP);
|
||||
$this->userdm->set('timezoneoffset', 1);
|
||||
|
||||
// Bitfields; set to desired defaults.
|
||||
// Comment out those you have set as defaults
|
||||
// in the vBuleltin admin control panel
|
||||
$this->userdm->set_bitfield('options', 'adminemail', 1);
|
||||
$this->userdm->set_bitfield('options', 'showsignatures', 1);
|
||||
$this->userdm->set_bitfield('options', 'showavatars', 0);
|
||||
$this->userdm->set_bitfield('options', 'showimages', 1);
|
||||
$this->userdm->set_bitfield('options', 'showemail', 0);
|
||||
|
||||
if ($login) $this->login($vbuser);
|
||||
|
||||
//$this->userdm->errors contains error messages
|
||||
if (empty($this->userdm->errors))
|
||||
$vbulletin->userinfo['userid'] = $this->userdm->save();
|
||||
else
|
||||
return implode('<br>', $this->userdm->errors);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// *********************************************************************************************************
|
||||
|
||||
function update_user(&$userdata)
|
||||
{
|
||||
global $vbulletin;
|
||||
$vbuser = userdata_convert($userdata);
|
||||
|
||||
if (!($existing_user = fetch_userinfo_from_username($vbuser['username'])))
|
||||
return 'fetch_userinfo_from_username() failed.';
|
||||
|
||||
$this->userdm->set_existing($existing_user);
|
||||
foreach($vbuser as $key => $value)
|
||||
$this->userdm->set($key, $value);
|
||||
|
||||
// reset password cookie in case password changed
|
||||
if (isset($vbuser['password']))
|
||||
vbsetcookie('password',
|
||||
md5($vbulletin->userinfo['password'].COOKIE_SALT),
|
||||
PERMANENT_COOKIE, true, true);
|
||||
|
||||
if (count($this->userdm->errors))
|
||||
return implode('<br>', $this->userdm->errors);
|
||||
$vbulletin->userinfo['userid'] = $this->userdm->save();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// *********************************************************************************************************
|
||||
|
||||
function update_avatar(&$userdata) {
|
||||
global $vbulletin;
|
||||
$vbuser = userdata_convert($userdata);
|
||||
|
||||
if (!($existing_user = fetch_userinfo_from_username($vbuser['username'])))
|
||||
return 'fetch_userinfo_from_username() failed.';
|
||||
|
||||
$this->userdm->set_existing($existing_user);
|
||||
|
||||
// update avatar in case it should be
|
||||
if (!empty($vbuser['avatarurl'])) {
|
||||
//~ echo"<pre>";
|
||||
//~ print_r ($existing_user);
|
||||
//~ echo "</pre>";
|
||||
|
||||
// begin custom avatar code
|
||||
require_once(DIR . '/includes/class_upload.php');
|
||||
require_once(DIR . '/includes/class_image.php');
|
||||
|
||||
$upload = new vB_Upload_Userpic($vbulletin);
|
||||
|
||||
$upload->data =& datamanager_init('Userpic_Avatar', $vbulletin, ERRTYPE_STANDARD, 'userpic');
|
||||
$upload->image =& vB_Image::fetch_library($vbulletin);
|
||||
$upload->userinfo =& $existing_user;
|
||||
cache_permissions($existing_user, false);
|
||||
$upload->maxwidth = $vbulletin->userinfo['permissions']['avatarmaxwidth'];
|
||||
$upload->maxheight = $vbulletin->userinfo['permissions']['avatarmaxheight'];
|
||||
if (!$upload->process_upload($vbuser['avatarurl'])) {
|
||||
echo $upload->fetch_error();
|
||||
}
|
||||
}
|
||||
else { // no avatar used!
|
||||
$userpic =& datamanager_init('Userpic_Avatar', $vbulletin, ERRTYPE_CP, 'userpic');
|
||||
$userpic->condition = "userid = " . $existing_user['userid'];
|
||||
$userpic->delete();
|
||||
}
|
||||
$this->userdm->set_existing($vbulletin->userinfo);
|
||||
|
||||
($hook = vBulletinHook::fetch_hook('profile_updateavatar_complete')) ? eval($hook) : false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// *********************************************************************************************************
|
||||
|
||||
function delete_user(&$username)
|
||||
{
|
||||
// The vBulletin documentation suggests using userdm->delete()
|
||||
// to delete a user, but upon examining the code, this doesn't
|
||||
// delete everything associated with the user. The following
|
||||
// is adapted from admincp/user.php instead.
|
||||
// NOTE: THIS MAY REQUIRE MAINTENANCE WITH NEW VBULLETIN UPDATES.
|
||||
|
||||
global $vbulletin;
|
||||
$db = &$vbulletin->db;
|
||||
$userdata = $db->query_first_slave("SELECT userid FROM "
|
||||
. TABLE_PREFIX . "user WHERE username='{$username}'");
|
||||
$userid = $userdata['userid'];
|
||||
if ($userid) {
|
||||
|
||||
// from admincp/user.php 'do prune users (step 1)'
|
||||
|
||||
// delete subscribed forums
|
||||
$db->query_write("DELETE FROM " . TABLE_PREFIX
|
||||
. "subscribeforum WHERE userid={$userid}");
|
||||
// delete subscribed threads
|
||||
$db->query_write("DELETE FROM " . TABLE_PREFIX
|
||||
. "subscribethread WHERE userid={$userid}");
|
||||
// delete events
|
||||
$db->query_write("DELETE FROM " . TABLE_PREFIX
|
||||
. "event WHERE userid={$userid}");
|
||||
// delete event reminders
|
||||
$db->query_write("DELETE FROM " . TABLE_PREFIX
|
||||
. "subscribeevent WHERE userid={$userid}");
|
||||
// delete custom avatars
|
||||
$db->query_write("DELETE FROM " . TABLE_PREFIX
|
||||
. "customavatar WHERE userid={$userid}");
|
||||
$customavatars = $db->query_read("SELECT userid, avatarrevision FROM "
|
||||
. TABLE_PREFIX . "user WHERE userid={$userid}");
|
||||
while ($customavatar = $db->fetch_array($customavatars)) {
|
||||
@unlink($vbulletin->options['avatarpath'] . "/avatar{$customavatar['userid']}_{$customavatar['avatarrevision']}.gif");
|
||||
}
|
||||
// delete custom profile pics
|
||||
$db->query_write("DELETE FROM " . TABLE_PREFIX
|
||||
. "customprofilepic WHERE userid={$userid}");
|
||||
$customprofilepics = $db->query_read(
|
||||
"SELECT userid, profilepicrevision FROM "
|
||||
. TABLE_PREFIX . "user WHERE userid={$userid}");
|
||||
while ($customprofilepic = $db->fetch_array($customprofilepics)) {
|
||||
@unlink($vbulletin->options['profilepicpath'] . "/profilepic$customprofilepic[userid]_$customprofilepic[profilepicrevision].gif");
|
||||
}
|
||||
// delete user forum access
|
||||
$db->query_write("DELETE FROM " . TABLE_PREFIX
|
||||
. "access WHERE userid={$userid}");
|
||||
// delete moderator
|
||||
$db->query_write("DELETE FROM " . TABLE_PREFIX
|
||||
. "moderator WHERE userid={$userid}");
|
||||
// delete private messages
|
||||
$db->query_write("DELETE FROM " . TABLE_PREFIX
|
||||
. "pm WHERE userid={$userid}");
|
||||
$db->query_write("DELETE FROM " . TABLE_PREFIX
|
||||
. "pmreceipt WHERE userid={$userid}");
|
||||
$db->query_write("DELETE FROM " . TABLE_PREFIX
|
||||
. "session WHERE userid={$userid}");
|
||||
// delete user group join requests
|
||||
$db->query_write("DELETE FROM " . TABLE_PREFIX
|
||||
. "usergrouprequest WHERE userid={$userid}");
|
||||
// delete bans
|
||||
$db->query_write("DELETE FROM " . TABLE_PREFIX
|
||||
. "userban WHERE userid={$userid}");
|
||||
// delete user notes
|
||||
$db->query_write("DELETE FROM " . TABLE_PREFIX
|
||||
. "usernote WHERE userid={$userid}");
|
||||
|
||||
// from admincp/users.php 'do prune users (step 2)'
|
||||
|
||||
// update deleted user's posts with userid=0
|
||||
$db->query_write("UPDATE " . TABLE_PREFIX
|
||||
. "thread SET postuserid = 0, postusername = '"
|
||||
. $db->escape_string($username)
|
||||
. "' WHERE postuserid = $userid");
|
||||
$db->query_write("UPDATE " . TABLE_PREFIX
|
||||
. "post SET userid = 0, username = '"
|
||||
. $db->escape_string($username)
|
||||
. "' WHERE userid = $userid");
|
||||
|
||||
// finally, delete the user
|
||||
$db->query_write("DELETE FROM " . TABLE_PREFIX
|
||||
. "usertextfield WHERE userid={$userid}");
|
||||
$db->query_write("DELETE FROM " . TABLE_PREFIX
|
||||
. "userfield WHERE userid={$userid}");
|
||||
$db->query_write("DELETE FROM " . TABLE_PREFIX
|
||||
. "user WHERE userid={$userid}");
|
||||
}
|
||||
/*
|
||||
the following is suggested in the documentation but doesn't work:
|
||||
|
||||
$existing_user = fetch_userinfo_from_username($username);
|
||||
$this->userdm->set_existing($existing_user);
|
||||
return $this->userdm->delete();
|
||||
*/
|
||||
}
|
||||
|
||||
function set_email( $username, $email ) {
|
||||
global $vbulletin;
|
||||
$db = &$vbulletin->db;
|
||||
$db->query_write("UPDATE " . TABLE_PREFIX . "user SET email = '"
|
||||
.mysql_real_escape_string($email)."' WHERE username = '"
|
||||
.mysql_real_escape_string($username)."'"
|
||||
);
|
||||
}
|
||||
|
||||
function set_pass( $username, $pass ) {
|
||||
global $vbulletin;
|
||||
$db = &$vbulletin->db;
|
||||
$pass = md5($pass);
|
||||
$salt = $this->fetch_user_salt();
|
||||
$db->query_write("UPDATE " . TABLE_PREFIX . "user SET password = '"
|
||||
.mysql_real_escape_string(md5($pass.$salt))."',
|
||||
salt = '".mysql_real_escape_string($salt)."' WHERE username = '"
|
||||
.mysql_real_escape_string($username)."'"
|
||||
);
|
||||
}
|
||||
|
||||
function fetch_user_salt($length = SALT_LENGTH) {
|
||||
$salt = '';
|
||||
|
||||
for ($i = 0; $i < $length; $i++)
|
||||
{
|
||||
$salt .= chr(rand(33, 126));
|
||||
}
|
||||
|
||||
return $salt;
|
||||
}
|
||||
|
||||
// ======== USER LOGIN / LOGOUT ========
|
||||
|
||||
function login($vbuser)
|
||||
{
|
||||
global $vbulletin;
|
||||
$vbulletin->userinfo = fetch_userinfo_from_username($vbuser['username']);
|
||||
// set cookies
|
||||
vbsetcookie('userid', $vbulletin->userinfo['userid'],
|
||||
PERMANENT_COOKIE, true, true);
|
||||
vbsetcookie('password',
|
||||
md5($vbulletin->userinfo['password'].COOKIE_SALT),
|
||||
PERMANENT_COOKIE, true, true);
|
||||
// create session stuff
|
||||
process_new_login('', 1, '');
|
||||
}
|
||||
|
||||
|
||||
function logout()
|
||||
{
|
||||
process_logout(); // unsets all cookies and session data
|
||||
}
|
||||
|
||||
} // end class ForumOps
|
||||
chdir($cwd);
|
||||
?>
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
All config settings are defined in this file. Please refer to your readme
|
||||
for an in depth explanation of each value.
|
||||
*/
|
||||
|
||||
class Config {
|
||||
|
||||
// Names and URLs for your installation
|
||||
public static $absolutePath = '/';
|
||||
public static $frontendPath = 'http://www.4ducky.com/';
|
||||
public static $siteName = '4ducky';
|
||||
public static $siteTitle = '4ducky.com - fol witzik';
|
||||
|
||||
public static $sessionCookie = 'sid';
|
||||
public static $rememberCookie = 'remember';
|
||||
|
||||
// Spam protection
|
||||
public static $ipLockTime = 3600;
|
||||
public static $uploadLockTime = 7200;
|
||||
public static $maxNumUploads = 50;
|
||||
|
||||
// User score
|
||||
public static $votingScore = 5;
|
||||
public static $postScore = 10;
|
||||
public static $tagScorePerChar = 0.5;
|
||||
public static $tagScoreMax = 20;
|
||||
|
||||
// Misc settings
|
||||
public static $usersPerPage = 100;
|
||||
public static $defaultChmod = 0777;
|
||||
public static $templates = 'templates/';
|
||||
public static $keywordWordSeperator = '-';
|
||||
|
||||
public static $colorSearchDev = 50;
|
||||
|
||||
public static $maxRandomThumbs = 10;
|
||||
public static $minRandomScore = 10.0;
|
||||
|
||||
// vbb Forum integration
|
||||
public static $vbbIntegration = array(
|
||||
'enabled' => false,
|
||||
'path' => '/../forum'
|
||||
);
|
||||
|
||||
// Cache settings
|
||||
public static $cache = array(
|
||||
'enabled' => false,
|
||||
'path' => 'cache/',
|
||||
'clearEvery' => 10
|
||||
);
|
||||
|
||||
// Database settings
|
||||
public static $db = array(
|
||||
'host' => 'localhost',
|
||||
'database' => 'name',
|
||||
'user' => 'usernmae',
|
||||
'password' => 'passwort',
|
||||
'prefix' => 'pl_'
|
||||
);
|
||||
|
||||
// Image processing and thumbnail creation
|
||||
public static $images = array(
|
||||
'thumbsPerPage' => 125,
|
||||
'imagePath' => 'data/images/',
|
||||
'thumbPath' => 'data/thumbs/',
|
||||
'avatarsPath' => 'data/avatars/',
|
||||
'maxDownload' => 8097152,
|
||||
'jpegQuality' => 100,
|
||||
'sharpen' => false
|
||||
);
|
||||
|
||||
// Grid Solver settings
|
||||
public static $gridView = array(
|
||||
'gridSize' => 64,
|
||||
'gridWidth' => 12,
|
||||
'borderWidth' => 2,
|
||||
|
||||
// Definition of all Thumbnail classes ---------------------------
|
||||
// KEY: CSS-className
|
||||
// width/ height: Size of the thumb in grid units
|
||||
// percentage: Percentage of thumbnails in this size
|
||||
// dir: Name of the subdir with thumbs in this size
|
||||
'classes' => array(
|
||||
'b2' => array( 'width'=>1, 'height'=>1, 'percentage'=>0.6, 'dir'=>'64x64' ),
|
||||
'b1' => array( 'width'=>2, 'height'=>2, 'percentage'=>0.35, 'dir'=>'128x128' ),
|
||||
'b0' => array( 'width'=>3, 'height'=>3, 'percentage'=>0.05, 'dir'=>'192x192' )
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Edit below this line only if you know what you're doing!
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
// MySQL Table names
|
||||
define( 'TABLE_IMAGES', Config::$db['prefix'].'images' );
|
||||
define( 'TABLE_IMAGECOLORS',Config::$db['prefix'].'imagecolors' );
|
||||
define( 'TABLE_USERS', Config::$db['prefix'].'users' );
|
||||
define( 'TABLE_IPLOCK', Config::$db['prefix'].'iplock' );
|
||||
define( 'TABLE_UPLOADLOCK', Config::$db['prefix'].'uploadlock' );
|
||||
define( 'TABLE_TAGLOG', Config::$db['prefix'].'taglog' );
|
||||
define( 'TABLE_COMMENTS', Config::$db['prefix'].'comments' );
|
||||
|
||||
// MagicQuotes undo
|
||||
if( function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() ) {
|
||||
$_GET = array_map( 'stripslashes', $_GET );
|
||||
$_POST = array_map( 'stripslashes', $_POST );
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
This class handles all database IO. To prevent SQL-Injections, all variables
|
||||
that are passed to the database must be specified as additional parameters to
|
||||
your query. e.g.
|
||||
$res = DB::query( 'SELECT * FROM images WHERE user = :1 AND tags LIKE :2', 'testuser', 'funny' );
|
||||
|
||||
query() and getRow() return a 2-dimensional array instead of a result resource.
|
||||
*/
|
||||
|
||||
require_once( 'config.php' );
|
||||
|
||||
class DB {
|
||||
private static $link = null;
|
||||
public static $result;
|
||||
public static $sql;
|
||||
public static $numQueries = 0;
|
||||
|
||||
private static function connect() {
|
||||
self::$link = @mysql_connect( Config::$db['host'], Config::$db['user'], Config::$db['password'] )
|
||||
or die( "Couldn't establish link to database-server: ".Config::$db['host'] );
|
||||
mysql_select_db( Config::$db['database'] )
|
||||
or die( "Couldn't select Database: ".Config::$db['database'] );
|
||||
mysql_query( 'SET NAMES utf8', self::$link );
|
||||
}
|
||||
|
||||
public static function foundRows() {
|
||||
$r = self::query( 'SELECT FOUND_ROWS() AS foundRows' );
|
||||
return $r[0]['foundRows'];
|
||||
}
|
||||
|
||||
public static function numRows() {
|
||||
return mysql_num_rows( self::$result );
|
||||
}
|
||||
|
||||
public static function affectedRows() {
|
||||
return mysql_affected_rows( self::$link );
|
||||
}
|
||||
public static function getresult() {
|
||||
return (self::$result);
|
||||
}
|
||||
public static function insertId() {
|
||||
return mysql_insert_id( self::$link );
|
||||
}
|
||||
|
||||
public static function query( $q, $params = array() ) {
|
||||
if( self::$link === null ) {
|
||||
self::connect();
|
||||
}
|
||||
|
||||
if( !is_array( $params ) ) {
|
||||
$params = array_slice( func_get_args(), 1 );
|
||||
}
|
||||
|
||||
if( !empty( $params ) ) {
|
||||
$q = preg_replace('/:(\d+)/e', 'self::quote($params[$1 - 1])', $q );
|
||||
}
|
||||
self::$numQueries++;
|
||||
self::$sql = $q;
|
||||
self::$result = mysql_query( $q, self::$link );
|
||||
|
||||
echo self::getError();
|
||||
if( !self::$result ) {
|
||||
return false;
|
||||
}
|
||||
else if( !is_resource( self::$result ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$rset = array();
|
||||
while ( $row = mysql_fetch_assoc( self::$result ) ) {
|
||||
$rset[] = $row;
|
||||
}
|
||||
return $rset;
|
||||
}
|
||||
|
||||
public static function getRow( $q, $params = array() ) {
|
||||
if( !is_array( $params ) ) {
|
||||
$params = array_slice( func_get_args(), 1 );
|
||||
}
|
||||
|
||||
$r = self::query( $q, $params );
|
||||
return array_shift($r);
|
||||
}
|
||||
|
||||
public static function updateRow( $table, $idFields, $updateFields ) {
|
||||
$updateString = implode( ',', self::quoteArray( $updateFields, true ) );
|
||||
$idString = implode( ' AND ', self::quoteArray( $idFields, true ) );
|
||||
return self::query( "UPDATE $table SET $updateString WHERE $idString" );
|
||||
}
|
||||
|
||||
public static function insertRow( $table, $insertFields ) {
|
||||
$insertString = implode( ',', self::quoteArray( $insertFields, true ) );
|
||||
return self::query( "INSERT INTO $table SET $insertString" );
|
||||
}
|
||||
|
||||
public static function getError() {
|
||||
if( $e = mysql_error( self::$link ) ) {
|
||||
return "MySQL reports: '$e' on query\n".self::$sql;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function quote( $s ) {
|
||||
if( self::$link === null ) {
|
||||
self::connect();
|
||||
}
|
||||
if( !isset($s) || $s === false ) {
|
||||
return 0;
|
||||
}
|
||||
else if( $s === true ) {
|
||||
return 1;
|
||||
}
|
||||
else if( is_numeric( $s ) ) {
|
||||
return $s;
|
||||
}
|
||||
else {
|
||||
return "'".mysql_real_escape_string( $s )."'";
|
||||
}
|
||||
}
|
||||
|
||||
public static function quoteArray( &$fields, $useKeys = false ) {
|
||||
$r = array();
|
||||
foreach( $fields as $key => &$value ) {
|
||||
$r[] = ( $useKeys ? "`$key`=":'' ) . self::quote( $value );
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
This class handles all database IO. To prevent SQL-Injections, all variables
|
||||
that are passed to the database must be specified as additional parameters to
|
||||
your query. e.g.
|
||||
$res = DB::query( 'SELECT * FROM images WHERE user = :1 AND tags LIKE :2', 'testuser', 'funny' );
|
||||
|
||||
query() and getRow() return a 2-dimensional array instead of a result resource.
|
||||
*/
|
||||
|
||||
require_once( 'lib/config.php' );
|
||||
|
||||
class DB {
|
||||
private static $link = null;
|
||||
public static $result;
|
||||
public static $sql;
|
||||
public static $numQueries = 0;
|
||||
|
||||
private static function connect() {
|
||||
self::$link = @mysql_connect( Config::$db['host'], Config::$db['user'], Config::$db['password'] )
|
||||
or die( "Couldn't establish link to database-server: ".Config::$db['host'] );
|
||||
mysql_select_db( Config::$db['database'] )
|
||||
or die( "Couldn't select Database: ".Config::$db['database'] );
|
||||
mysql_query( 'SET NAMES utf8', self::$link );
|
||||
}
|
||||
|
||||
public static function foundRows() {
|
||||
$r = self::query( 'SELECT FOUND_ROWS() AS foundRows' );
|
||||
return $r[0]['foundRows'];
|
||||
}
|
||||
|
||||
public static function numRows() {
|
||||
return mysql_num_rows( self::$result );
|
||||
}
|
||||
|
||||
public static function affectedRows() {
|
||||
return mysql_affected_rows( self::$link );
|
||||
}
|
||||
public static function getresult() {
|
||||
return (self::$result);
|
||||
}
|
||||
public static function insertId() {
|
||||
return mysql_insert_id( self::$link );
|
||||
}
|
||||
|
||||
public static function query( $q, $params = array() ) {
|
||||
if( self::$link === null ) {
|
||||
self::connect();
|
||||
}
|
||||
|
||||
if( !is_array( $params ) ) {
|
||||
$params = array_slice( func_get_args(), 1 );
|
||||
}
|
||||
|
||||
if( !empty( $params ) ) {
|
||||
$q = preg_replace('/:(\d+)/e', 'self::quote($params[$1 - 1])', $q );
|
||||
}
|
||||
self::$numQueries++;
|
||||
self::$sql = $q;
|
||||
self::$result = mysql_query( $q, self::$link );
|
||||
|
||||
echo self::getError();
|
||||
if( !self::$result ) {
|
||||
return false;
|
||||
}
|
||||
else if( !is_resource( self::$result ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$rset = array();
|
||||
while ( $row = mysql_fetch_assoc( self::$result ) ) {
|
||||
$rset[] = $row;
|
||||
}
|
||||
return $rset;
|
||||
}
|
||||
|
||||
public static function getRow( $q, $params = array() ) {
|
||||
if( !is_array( $params ) ) {
|
||||
$params = array_slice( func_get_args(), 1 );
|
||||
}
|
||||
|
||||
$r = self::query( $q, $params );
|
||||
return array_shift($r);
|
||||
}
|
||||
|
||||
public static function updateRow( $table, $idFields, $updateFields ) {
|
||||
$updateString = implode( ',', self::quoteArray( $updateFields, true ) );
|
||||
$idString = implode( ' AND ', self::quoteArray( $idFields, true ) );
|
||||
return self::query( "UPDATE $table SET $updateString WHERE $idString" );
|
||||
}
|
||||
|
||||
public static function insertRow( $table, $insertFields ) {
|
||||
$insertString = implode( ',', self::quoteArray( $insertFields, true ) );
|
||||
return self::query( "INSERT INTO $table SET $insertString" );
|
||||
}
|
||||
|
||||
public static function getError() {
|
||||
if( $e = mysql_error( self::$link ) ) {
|
||||
return "MySQL reports: '$e' on query\n".self::$sql;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function quote( $s ) {
|
||||
if( self::$link === null ) {
|
||||
self::connect();
|
||||
}
|
||||
if( !isset($s) || $s === false ) {
|
||||
return 0;
|
||||
}
|
||||
else if( $s === true ) {
|
||||
return 1;
|
||||
}
|
||||
else if( is_numeric( $s ) ) {
|
||||
return $s;
|
||||
}
|
||||
else {
|
||||
return "'".mysql_real_escape_string( $s )."'";
|
||||
}
|
||||
}
|
||||
|
||||
public static function quoteArray( &$fields, $useKeys = false ) {
|
||||
$r = array();
|
||||
foreach( $fields as $key => &$value ) {
|
||||
$r[] = ( $useKeys ? "`$key`=":'' ) . self::quote( $value );
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
Various functions regarding file handling
|
||||
*/
|
||||
|
||||
require_once( 'lib/config.php' );
|
||||
|
||||
class Filesystem {
|
||||
|
||||
public static function rmdirr( $dir, $clearOnly = false ) {
|
||||
$dh = opendir( $dir );
|
||||
while ( $file = readdir( $dh ) ) {
|
||||
if( $file != '.' && $file != '..' ) {
|
||||
$fullpath = $dir.'/'.$file;
|
||||
if( !is_dir( $fullpath ) ) {
|
||||
@unlink( $fullpath );
|
||||
}
|
||||
else {
|
||||
self::rmdirr( $fullpath );
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir( $dh );
|
||||
|
||||
if( !$clearOnly && @rmdir( $dir ) ) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function mkdirr( $pathname ) {
|
||||
// Check if directory already exists
|
||||
if( empty($pathname) || is_dir($pathname) ) {
|
||||
return true;
|
||||
}
|
||||
if ( is_file($pathname) ) {
|
||||
return false;
|
||||
}
|
||||
// Crawl up the directory tree
|
||||
$nextPathname = substr( $pathname, 0, strrpos( $pathname, '/' ) );
|
||||
if( self::mkdirr( $nextPathname ) ) {
|
||||
if( !file_exists( $pathname ) ) {
|
||||
$oldUmask = umask(0);
|
||||
$success = @mkdir( $pathname, Config::$defaultChmod );
|
||||
umask( $oldUmask );
|
||||
return $success;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function download( $url, $target, $maxSize = 2097152, $referer) {
|
||||
$contents = '';
|
||||
$bytesRead = 0;
|
||||
|
||||
|
||||
//$referer = false;
|
||||
/*if( $referer ) {
|
||||
$opts = array(
|
||||
'http'=>array(
|
||||
'method'=>"GET",
|
||||
'header'=>"Referer: $referer\r\n"
|
||||
)
|
||||
);
|
||||
$context = stream_context_create($opts);
|
||||
$fp = fopen( $url, 'r', false, $context );
|
||||
} else {
|
||||
|
||||
}*/
|
||||
|
||||
$contents= file_get_contents($url);
|
||||
$savefile = fopen($target, "w");
|
||||
fwrite($savefile, $contents);
|
||||
fclose($savefile);
|
||||
return true;
|
||||
/*
|
||||
try {
|
||||
$fp = @fopen( $url, 'r' );
|
||||
}
|
||||
catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while ( !feof( $fp ) ) {
|
||||
$chunk = fread( $fp, 8192 );
|
||||
$bytesRead += strlen( $chunk );
|
||||
if( $bytesRead > $maxSize) {
|
||||
return false;
|
||||
}
|
||||
$contents .= $chunk;
|
||||
}
|
||||
fclose( $fp );
|
||||
|
||||
file_put_contents( $target, $contents );
|
||||
return true;*/
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
header("Content-type: text/html; charset=UTF-8");
|
||||
|
||||
|
||||
function shorter($input, $length)
|
||||
{
|
||||
//no need to trim, already shorter than trim length
|
||||
if (strlen($input) <= $length) {
|
||||
return $input;
|
||||
}
|
||||
|
||||
//find last space within length
|
||||
$last_space = strrpos(substr($input, 0, $length), ' ');
|
||||
if(!$last_space) $last_space = $length;
|
||||
$trimmed_text = substr($input, 0, $last_space);
|
||||
|
||||
//add ellipses (...)
|
||||
$trimmed_text .= '...';
|
||||
|
||||
return $trimmed_text;
|
||||
}
|
||||
|
||||
|
||||
require_once( 'lib/config.php' );
|
||||
require_once( 'lib/db.php' );
|
||||
|
||||
$comments = DB::query('SELECT * FROM pl_comments WHERE c_like="0" ORDER BY created DESC LIMIT 40');
|
||||
|
||||
foreach (array_keys($comments) as $c) {
|
||||
$posterinfo = DB::getRow("SELECT * FROM pl_users WHERE id=:1",$comments[$c]["userId"]);
|
||||
$commentimg = DB::getRow("SELECT * FROM pl_commentuploads WHERE c_id=:1",$comments[$c]["id"]);
|
||||
$imageinfo = DB::getRow("SELECT * FROM pl_images WHERE id=:1",$comments[$c]["imageId"]);
|
||||
$blockedrow = DB::getRow("SELECT id,users FROM pl_blocked WHERE id=:1",$user->id);
|
||||
$blockeduser = array_map('strtolower', unserialize($blockedrow['users']));
|
||||
$lower = strtolower($posterinfo["name"]);
|
||||
|
||||
if(!($commentimg && ($comments[$c]["userId"] == $imageinfo["user"]))){
|
||||
|
||||
if (!in_array($lower,$blockeduser)){
|
||||
if ($imageinfo && $posterinfo){
|
||||
|
||||
?>
|
||||
|
||||
<div id="commentbar">
|
||||
<a href="<?php echo (Config::$absolutePath.'all/view/'.$imageinfo["keyword"]); ?>">
|
||||
<div id="commentimg">
|
||||
<img width="28" height="28" src="<?php echo(Config::$absolutePath.$posterinfo["avatar"]); ?>" />
|
||||
</div>
|
||||
<div id="commenttext">
|
||||
<strong><?php echo(shorter(strip_tags($posterinfo["name"]),"10")); ?>: </strong><?php echo(shorter(strip_tags($comments[$c]["content"]),"50")); ?>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<?php }}}}?>
|
||||
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
This class takes an array of images and sorts them into a grid view.
|
||||
This is the equivalent of the javascript gridSolve function in picturelicious.js
|
||||
with the difference that it runs server side of course.
|
||||
*/
|
||||
|
||||
require_once( 'lib/config.php' );
|
||||
|
||||
class GridView {
|
||||
|
||||
public $height = 0;
|
||||
protected $grid = array();
|
||||
protected $gridWidth = 20;
|
||||
|
||||
public function __construct( $gridWidth = 20 ) {
|
||||
$this->gridWidth = $gridWidth;
|
||||
$this->grid = array_fill( 0, $this->gridWidth, 0 );
|
||||
}
|
||||
|
||||
// solve expects an array with thumbnails with the keys name and score
|
||||
public function solve( &$thumbs ) {
|
||||
if( !is_array( $thumbs ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Order thumbs by importance (score), but leave the keys as they are
|
||||
uasort( $thumbs, array( $this, 'compareScore' ) );
|
||||
|
||||
// How many thumbs get which CSS-Class? The first n thumbnails
|
||||
// get the biggest box etc.
|
||||
$total = count( $thumbs );
|
||||
$classCounts = array();
|
||||
$currentCount = 0;
|
||||
foreach( Config::$gridView['classes'] as $className => $gc ) {
|
||||
$currentCount += $gc['percentage'] * $total;
|
||||
$classCounts[$className] = ceil( $currentCount );
|
||||
}
|
||||
|
||||
// Assign a CSS-Class to each thumb
|
||||
$currentMax = -1;
|
||||
$currentClass = '';
|
||||
$j = 0;
|
||||
foreach( array_keys( $thumbs ) as $i ) {
|
||||
if( $j >= $currentMax ) {
|
||||
list( $currentClass, $currentMax ) = each( $classCounts );
|
||||
}
|
||||
$j++;
|
||||
$thumbs[$i]['class'] = $currentClass;
|
||||
$thumbs[$i]['thumb'] = Config::$absolutePath . Config::$images['thumbPath'] .
|
||||
str_replace( '-', '/', substr( $thumbs[$i]['logged'], 0, 7 ) )
|
||||
.'/'. Config::$gridView['classes'][$currentClass]['dir']
|
||||
.'/'. $thumbs[$i]['thumb'];
|
||||
}
|
||||
|
||||
// Sort the thumbs back in the order we got them
|
||||
ksort( $thumbs );
|
||||
|
||||
// Now that every thumb has a CSS-Class, we can sort them into our grid
|
||||
for( $i = 0; $i < $total; $i++ ) {
|
||||
list( $x, $y ) = $this->insert(
|
||||
Config::$gridView['classes'][$thumbs[$i]['class']]['width'],
|
||||
Config::$gridView['classes'][$thumbs[$i]['class']]['height']
|
||||
);
|
||||
$thumbs[$i]['left'] = $x * Config::$gridView['gridSize'];
|
||||
$thumbs[$i]['top'] = $y * Config::$gridView['gridSize'];
|
||||
}
|
||||
|
||||
// Calculate the final grid height
|
||||
for( $i = 0; $i < $this->gridWidth; $i++ ) {
|
||||
if( $this->grid[$i] > $this->height ) {
|
||||
$this->height = $this->grid[$i];
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Callback for uasort()
|
||||
protected function compareScore( $a, $b ) {
|
||||
return $a['score'] > $b['score'] ?
|
||||
1 :
|
||||
( $a['score'] == $b['score'] && $a['votes'] > $b['votes'] ?
|
||||
1 :
|
||||
-1
|
||||
);
|
||||
}
|
||||
|
||||
protected function insert( $boxWidth, $boxHeight ) {
|
||||
|
||||
// Height of the grid
|
||||
$maxHeight = 0;
|
||||
|
||||
// Height of the grid at the last position
|
||||
$currentHeight = $this->grid[0];
|
||||
|
||||
// Find free spots within the grid and collect them in an arry
|
||||
// A spot is a area in the grid with equal height
|
||||
$spotWidth = 0; // Width of the spot in grid units
|
||||
$spotLeft = 0; // Position in the grid (relative to left border)
|
||||
$freeSpots = array();
|
||||
|
||||
for( $i = 0; $i < $this->gridWidth; $i++ ) {
|
||||
|
||||
// Height is the same as at the last position?
|
||||
// -> increase the size of this spot
|
||||
if( $currentHeight == $this->grid[$i] ) {
|
||||
$spotWidth++;
|
||||
}
|
||||
|
||||
// The height is different from the last position, and our current spot
|
||||
// is wider than 0
|
||||
if( ( $currentHeight != $this->grid[$i] || $i+1 == $this->gridWidth) && $spotWidth > 0 ) {
|
||||
$freeSpots[] = array( 'width' =>$spotWidth, 'left' => $spotLeft, 'height' => $currentHeight );
|
||||
$spotWidth = 1;
|
||||
$spotLeft = $i;
|
||||
|
||||
// Make sure we don't miss the last one
|
||||
if( $currentHeight != $this->grid[$i] && $i+1 == $this->gridWidth ) {
|
||||
$freeSpots[] = array( 'width' =>$spotWidth, 'left' => $spotLeft, 'height' => $this->grid[$i] );
|
||||
}
|
||||
}
|
||||
|
||||
$currentHeight = $this->grid[$i];
|
||||
$maxHeight = max( $maxHeight, $this->grid[$i] );
|
||||
}
|
||||
|
||||
// Loop through all found spots and rate them, based on their size and height
|
||||
// This way the smallest possible spot in the lowest possible height is filled
|
||||
$targetHeight = 0;
|
||||
$targetLeft = 0;
|
||||
|
||||
// Default spot (left border) if we don't find a better one
|
||||
for( $i = 0; $i < $boxWidth; $i++ ) {
|
||||
if( $this->grid[$i] > $targetHeight ) {
|
||||
$targetHeight = $this->grid[$i];
|
||||
}
|
||||
}
|
||||
|
||||
$bestScore = -1;
|
||||
foreach( array_keys( $freeSpots ) as $i ) {
|
||||
|
||||
// Difference of the height of this spot to the total height of the grid
|
||||
$heightScore = ( $maxHeight - $freeSpots[$i]['height'] );
|
||||
|
||||
// Relation of the required and the available space
|
||||
$widthScore = $boxWidth / $freeSpots[$i]['width'];
|
||||
|
||||
// The score for this spot is calculated by these both criteria
|
||||
$score = $heightScore * $heightScore + $widthScore * 2;
|
||||
|
||||
// Is the score for this spot higher than for the last one we found?
|
||||
if( $freeSpots[$i]['width'] >= $boxWidth && $score > $bestScore ) {
|
||||
$targetHeight = $freeSpots[$i]['height'];
|
||||
$targetLeft = $freeSpots[$i]['left'];
|
||||
$bestScore = $score;
|
||||
}
|
||||
}
|
||||
|
||||
$newHeight = $targetHeight + $boxHeight;
|
||||
|
||||
// Adjust grid height
|
||||
for( $j = 0; $j < $boxWidth; $j++ ) {
|
||||
$this->grid[$targetLeft + $j] = $newHeight;
|
||||
}
|
||||
|
||||
return array( $targetLeft, $targetHeight );
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,258 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
ImageBrowser loads a set of images specified by a search term, user and page.
|
||||
*/
|
||||
|
||||
require_once( 'lib/imagecatalog.php' );
|
||||
|
||||
class ImageBrowser extends ImageCatalog {
|
||||
protected $page = 0;
|
||||
public $thumbsPerPage = 0;
|
||||
protected $commentBool = false;
|
||||
protected $FavBool = false;
|
||||
protected $unreadBool = false;
|
||||
protected $userID = 0;
|
||||
protected $grid = false;
|
||||
public $thumbs = array();
|
||||
public $pages = array();
|
||||
|
||||
|
||||
public function __construct( $thumbsPerPage = 20 ) {
|
||||
$this->thumbsPerPage = abs(intval($thumbsPerPage));
|
||||
}
|
||||
|
||||
public function setPage( $page ) {
|
||||
$page = intval($page);
|
||||
$this->page = $page > 0 ? $page - 1 : 0;
|
||||
}
|
||||
public function setComment( $cmt,$un ) {
|
||||
$this->commentBool = $cmt ;
|
||||
$this->unreadBool = $un;
|
||||
}
|
||||
public function setFav( $fav ) {
|
||||
$this->FavBool = $fav ;
|
||||
}
|
||||
public function setuserID( $id ) {
|
||||
$this->userID = $id ;
|
||||
}
|
||||
|
||||
public function sortByOneKey(array $array, $key, $asc = true) {
|
||||
$result = array();
|
||||
|
||||
$values = array();
|
||||
foreach ($array as $id => $value) {
|
||||
$values[$id] = isset($value[$key]) ? $value[$key] : '';
|
||||
}
|
||||
|
||||
if ($asc) {
|
||||
asort($values);
|
||||
}
|
||||
else {
|
||||
arsort($values);
|
||||
}
|
||||
|
||||
foreach ($values as $key => $value) {
|
||||
$result[$key] = $array[$key];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function multi_unique($myArray)
|
||||
{
|
||||
if(!is_array($myArray))
|
||||
return $myArray;
|
||||
|
||||
foreach ($myArray as &$myvalue){
|
||||
$myvalue=serialize($myvalue);
|
||||
}
|
||||
|
||||
$myArray=array_unique($myArray);
|
||||
|
||||
foreach ($myArray as &$myvalue){
|
||||
$myvalue=unserialize($myvalue);
|
||||
}
|
||||
|
||||
return $myArray;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function load() {
|
||||
$this->grid=true;
|
||||
|
||||
if( !empty( $this->searchColor ) ) { // ----------------------------------- color search
|
||||
$this->thumbs = DB::query(
|
||||
'SELECT SQL_CALC_FOUND_ROWS
|
||||
i.logged, UNIX_TIMESTAMP(i.logged) AS loggedTS,
|
||||
i.keyword, i.thumb, i.score, i.votes,
|
||||
u.name AS userName,
|
||||
MIN( ABS(ic.r - :3) + ABS(ic.g - :4) + ABS(ic.b - :5) ) AS deviation
|
||||
FROM '.TABLE_IMAGES.' i
|
||||
LEFT JOIN '.TABLE_USERS.' u
|
||||
ON u.id = i.user
|
||||
LEFT JOIN '.TABLE_IMAGECOLORS.' ic
|
||||
ON ic.imageId = i.id
|
||||
WHERE
|
||||
ic.r BETWEEN :3 - :6 AND :3 + :6
|
||||
AND
|
||||
ic.g BETWEEN :4 - :6 AND :4 + :6
|
||||
AND
|
||||
ic.b BETWEEN :5 - :6 AND :5 + :6
|
||||
GROUP BY i.id
|
||||
ORDER BY deviation, i.id DESC
|
||||
LIMIT :1, :2',
|
||||
$this->page * $this->thumbsPerPage,
|
||||
$this->thumbsPerPage,
|
||||
|
||||
$this->searchColor['r'],
|
||||
$this->searchColor['g'],
|
||||
$this->searchColor['b'],
|
||||
Config::$colorSearchDev
|
||||
);
|
||||
}
|
||||
else if( $this->searchTerm ) { // ------------------------ fulltext search
|
||||
$ftq = preg_replace( '/\s+/',' +', $this->searchTerm );
|
||||
$this->thumbs = DB::query(
|
||||
'SELECT SQL_CALC_FOUND_ROWS
|
||||
i.logged, UNIX_TIMESTAMP(i.logged) AS loggedTS,
|
||||
i.keyword, i.thumb, i.score, i.votes,
|
||||
u.name AS userName
|
||||
FROM '.TABLE_IMAGES.' i
|
||||
LEFT JOIN '.TABLE_USERS.' u
|
||||
ON u.id = i.user
|
||||
WHERE
|
||||
i.image LIKE :3
|
||||
OR MATCH( i.tags ) AGAINST ( :4 IN BOOLEAN MODE )
|
||||
ORDER BY i.id DESC
|
||||
LIMIT :1, :2',
|
||||
$this->page * $this->thumbsPerPage,
|
||||
$this->thumbsPerPage,
|
||||
|
||||
'%'.$this->searchTerm.'%',
|
||||
$ftq
|
||||
);
|
||||
}
|
||||
|
||||
elseif ($this->commentBool) {
|
||||
|
||||
if($this->unreadBool) {
|
||||
|
||||
$this->thumbs = DB::query("SELECT SQL_CALC_FOUND_ROWS i.logged, UNIX_TIMESTAMP(i.logged) as loggedTS,i.keyword as keyword, i.thumb as thumb, i.score as score, i.votes as votes, us.name as userName FROM pl_images as i, pl_unread as u, pl_users as us WHERE u.userid = :1 AND u.imageid=i.id AND us.id=i.user ORDER BY loggedTS DESC LIMIT :2, :3",$this->userID,
|
||||
$this->page * $this->thumbsPerPage,$this->thumbsPerPage);
|
||||
if (count($this->thumbs) < $this->thumbsPerPage){
|
||||
$this->thumbsPerPage = count($this->thumbs);}
|
||||
|
||||
}else{
|
||||
$this->thumbs = DB::query('SELECT SQL_CALC_FOUND_ROWS i.logged, UNIX_TIMESTAMP(i.logged) as loggedTS,i.keyword as keyword, i.thumb as thumb, i.score as score, i.votes as votes, u.name as userName FROM pl_comments as c, pl_images as i, pl_users as u WHERE c.c_like=0 AND c.userId=u.id AND c.userId=:1 AND i.id=c.imageId GROUP BY c.imageId ORDER BY loggedTS DESC LIMIT :2, :3',$this->userID,
|
||||
$this->page * $this->thumbsPerPage,$this->thumbsPerPage);
|
||||
|
||||
}
|
||||
|
||||
|
||||
$this->commentState = true;
|
||||
$this->basePath = "comments/";
|
||||
|
||||
|
||||
|
||||
|
||||
}elseif ($this->FavBool) {
|
||||
$this->thumbs = DB::query("SELECT SQL_CALC_FOUND_ROWS i.logged, UNIX_TIMESTAMP( i.logged ) AS loggedTS, i.keyword AS keyword, i.thumb AS thumb, i.score AS score, i.votes AS votes, u.name AS userName
|
||||
FROM pl_fav AS c, pl_images AS i, pl_users AS u
|
||||
WHERE c.user = u.id
|
||||
AND c.user =:1
|
||||
AND i.id = c.imageId
|
||||
GROUP BY c.imageId
|
||||
ORDER BY loggedTS DESC LIMIT :2, :3",$this->userID,
|
||||
$this->page * $this->thumbsPerPage,$this->thumbsPerPage);
|
||||
$this->basePath = "favorites/";
|
||||
$this->FavState = true;
|
||||
|
||||
|
||||
}else { // -------------------------------------------------------- user/all
|
||||
$conditions = '';
|
||||
if( !empty($this->user) ) {
|
||||
$conditions .= ' AND i.user = :3';
|
||||
}
|
||||
|
||||
$this->thumbs = DB::query(
|
||||
'SELECT SQL_CALC_FOUND_ROWS
|
||||
i.logged, UNIX_TIMESTAMP(i.logged) AS loggedTS,
|
||||
i.keyword, i.thumb, i.score, i.votes,
|
||||
u.name AS userName
|
||||
FROM '.TABLE_IMAGES.' i
|
||||
LEFT JOIN '.TABLE_USERS.' u
|
||||
ON u.id = i.user
|
||||
WHERE 1 '.$conditions.'
|
||||
ORDER BY i.id DESC
|
||||
LIMIT :1, :2',
|
||||
|
||||
|
||||
|
||||
$this->page * $this->thumbsPerPage,
|
||||
$this->thumbsPerPage,
|
||||
$this->user['id']
|
||||
);
|
||||
|
||||
$this->grid=true;
|
||||
if(count($this->thumbs) > 3){
|
||||
$this->thumbs[0]["score"] = "100";
|
||||
$this->thumbs[1]["score"] = "10";
|
||||
$this->thumbs[2]["score"] = "10";
|
||||
|
||||
$thumbsCount = count($this->thumbs);
|
||||
if ($thumbsCount > 50){
|
||||
for ($i=$thumbsCount-40; $i<$thumbsCount; $i++){
|
||||
$this->thumbs[$i]["score"] = "0";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->totalResults = DB::foundRows();
|
||||
|
||||
|
||||
// compute previoues, current and next page
|
||||
if( $this->totalResults > 0 ) {
|
||||
$this->pages['current'] = $this->page+1;
|
||||
$this->pages['total'] = ceil($this->totalResults / $this->thumbsPerPage);
|
||||
if( $this->page > 0 ) {
|
||||
$this->pages['prev'] = $this->page;
|
||||
}
|
||||
if( $this->totalResults > $this->thumbsPerPage * $this->page + $this->thumbsPerPage ) {
|
||||
$this->pages['next'] = $this->page + 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function loadRandom( $minScore, $thumbSize ) {
|
||||
$this->thumbs = DB::query(
|
||||
'SELECT SQL_CALC_FOUND_ROWS
|
||||
i.logged, UNIX_TIMESTAMP(i.logged) AS loggedTS,
|
||||
i.keyword, i.thumb, i.score, i.votes,
|
||||
u.name AS userName
|
||||
FROM '.TABLE_IMAGES.' i
|
||||
LEFT JOIN '.TABLE_USERS.' u
|
||||
ON u.id = i.user
|
||||
WHERE i.score >= :2
|
||||
ORDER BY RAND()
|
||||
LIMIT :1',
|
||||
|
||||
$this->thumbsPerPage,
|
||||
$minScore
|
||||
);
|
||||
|
||||
foreach( array_keys( $this->thumbs ) as $i ) {
|
||||
$this->thumbs[$i]['thumb'] = Config::$images['thumbPath'] .
|
||||
str_replace( '-', '/', substr( $this->thumbs[$i]['logged'], 0, 7 ) )
|
||||
.'/'. $thumbSize
|
||||
.'/'. $this->thumbs[$i]['thumb'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
ImageCatalog is the abstract base class for ImageBrowser and ImageViewer. It provides
|
||||
the basic functionality to help build queries to get the images out of the database.
|
||||
*/
|
||||
|
||||
require_once( 'lib/config.php' );
|
||||
require_once( 'lib/db.php' );
|
||||
|
||||
class ImageCatalog {
|
||||
public $user = array();
|
||||
public $searchTerm = '';
|
||||
public $searchColor = array();
|
||||
public $totalResults = 0;
|
||||
|
||||
public $basePath = 'all/';
|
||||
|
||||
public function setUser( $name ) {
|
||||
$this->user = DB::getRow(
|
||||
'SELECT id, name, score, images, avatar, website
|
||||
FROM '.TABLE_USERS.'
|
||||
WHERE
|
||||
valid = 1 AND
|
||||
name = :1',
|
||||
$name
|
||||
);
|
||||
if( !empty($this->user) ) {
|
||||
$this->basePath = 'user/'.$this->user['name'].'/';
|
||||
}
|
||||
}
|
||||
|
||||
public function setSearch( $term ) {
|
||||
|
||||
$this->basePath = 'search/'.htmlspecialchars($term).'/';
|
||||
|
||||
if( preg_match( '/^\s*0x([0-9a-f]{6})\s*$/i', $term, $m ) ) {
|
||||
$c = str_split( $m[1], 2 );
|
||||
$this->searchColor = array(
|
||||
'r' => hexdec($c[0]),
|
||||
'g' => hexdec($c[1]),
|
||||
'b' => hexdec($c[2]),
|
||||
);
|
||||
}
|
||||
else if( !empty($term) ) {
|
||||
$this->searchTerm = $term;
|
||||
$ftq = preg_replace( '/\s+/',' +', $this->searchTerm );
|
||||
$this->seachCondition .= " AND (
|
||||
i.image LIKE ".DB::quote('%'.$this->searchTerm.'%')."
|
||||
OR MATCH( i.tags ) AGAINST ( ".DB::quote($ftq)." IN BOOLEAN MODE )
|
||||
)";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function load() {
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
Various functions regarding thumbnail creation and color extraction
|
||||
*/
|
||||
|
||||
require_once( 'lib/config.php' );
|
||||
|
||||
class Image {
|
||||
|
||||
public static function createThumb( $imgPath, $thumbPath, $thumbWidth, $thumbHeight ) {
|
||||
list( $srcWidth, $srcHeight, $type ) = getimagesize( $imgPath );
|
||||
$srcX = 0;
|
||||
$srcY = 0;
|
||||
if(
|
||||
$srcWidth < 1 || $srcWidth > 10000
|
||||
|| $srcHeight < 1 || $srcHeight > 10000
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( $type == IMAGETYPE_JPEG ) {
|
||||
$imgcreate = 'ImageCreateFromJPEG';
|
||||
} else if( $type == IMAGETYPE_GIF ) {
|
||||
$imgcreate = 'ImageCreateFromGIF';
|
||||
} else if( $type == IMAGETYPE_PNG ) {
|
||||
$imgcreate = 'ImageCreateFromPNG';
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
$thumbDirName = dirname( $thumbPath );
|
||||
|
||||
if( ( $srcWidth/$srcHeight ) > ( $thumbWidth/$thumbHeight ) ) {
|
||||
$zoom = ($srcWidth/$srcHeight) / ($thumbWidth/$thumbHeight);
|
||||
$srcX = ($srcWidth - $srcWidth / $zoom) / 2;
|
||||
$srcWidth = $srcWidth / $zoom;
|
||||
}
|
||||
else {
|
||||
$zoom = ($thumbWidth/$thumbHeight) / ($srcWidth/$srcHeight);
|
||||
$srcY = ($srcHeight - $srcHeight / $zoom) / 2;
|
||||
$srcHeight = $srcHeight / $zoom;
|
||||
}
|
||||
|
||||
$thumb = Imagecreatetruecolor( $thumbWidth, $thumbHeight );
|
||||
$orig = $imgcreate( $imgPath );
|
||||
Imagecopyresampled($thumb, $orig, 0, 0, $srcX, $srcY, $thumbWidth, $thumbHeight, $srcWidth, $srcHeight);
|
||||
|
||||
if( Config::$images['sharpen'] && function_exists('imageconvolution') ) {
|
||||
$sharpenMatrix = array( array(-1,-1,-1), array(-1,16,-1), array(-1,-1,-1) );
|
||||
imageconvolution($thumb, $sharpenMatrix, 8, 0);
|
||||
}
|
||||
imagejpeg( $thumb, $thumbPath, Config::$images['jpegQuality'] );
|
||||
|
||||
// clean up
|
||||
Imagedestroy( $thumb );
|
||||
Imagedestroy( $orig );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getColors( $imgPath, $size ) {
|
||||
list( $srcWidth, $srcHeight, $type ) = getimagesize( $imgPath );
|
||||
|
||||
if( $type == IMAGETYPE_JPEG ) {
|
||||
$imgcreate = 'ImageCreateFromJPEG';
|
||||
} else if( $type == IMAGETYPE_GIF ) {
|
||||
$imgcreate = 'ImageCreateFromGIF';
|
||||
} else if( $type == IMAGETYPE_PNG ) {
|
||||
$imgcreate = 'ImageCreateFromPNG';
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
|
||||
$orig = $imgcreate( $imgPath );
|
||||
|
||||
$thumb = Imagecreatetruecolor( $size, $size );
|
||||
Imagecopyresampled($thumb, $orig, 0, 0, 0, 0, $size, $size, $srcWidth, $srcHeight);
|
||||
|
||||
$colors = array();
|
||||
for( $x = 0; $x < $size; $x++ ) {
|
||||
for( $y = 0; $y < $size; $y++ ) {
|
||||
$rgb = ImageColorAt($thumb, $x, $y);
|
||||
$r = ($rgb >> 16) & 0xFF;
|
||||
$g = ($rgb >> 8) & 0xFF;
|
||||
$b = $rgb & 0xFF;
|
||||
$colors[] = array(
|
||||
'r' => $r,
|
||||
'g' => $g,
|
||||
'b' => $b
|
||||
);
|
||||
}
|
||||
}
|
||||
return $colors;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,324 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
The ImageUploader class handles the insertion of images into the system -
|
||||
whether they were uploaded or should be copied from a remote URL
|
||||
*/
|
||||
|
||||
require_once( 'lib/config.php' );
|
||||
require_once( 'lib/db.php' );
|
||||
require_once( 'lib/filesystem.php' );
|
||||
require_once( 'lib/images.php' );
|
||||
require_once( 'lib/users.php' );
|
||||
require_once( 'lib/keyword.php' );
|
||||
|
||||
class ImageUploader {
|
||||
|
||||
|
||||
public static function writeError($error) {
|
||||
|
||||
$handle = fopen('./import/log.txt', 'a');
|
||||
fwrite($handle, $error);
|
||||
fclose($handle);
|
||||
|
||||
}
|
||||
|
||||
public static function copyFromUrl( $url, $tags, $referer, &$errors,$commentUpload=false,$cid=0) {
|
||||
|
||||
$upl = DB::getRow("SELECT * FROM pl_settings");
|
||||
if ($upl["upload"] != 1){
|
||||
$errors['notLoggedIn'] = 'Upload disabled.';
|
||||
return false;
|
||||
}
|
||||
|
||||
$url = str_replace("https", "http", $url);
|
||||
|
||||
if( stripos( $url, 'http://' ) !== 0 ) {
|
||||
$url = 'http://'.$url;
|
||||
}
|
||||
// no recursion, no non-images
|
||||
if(
|
||||
stripos( $url, Config::$frontendPath ) !== false ||
|
||||
!preg_match( '/([^\/]*?)\.(gif|jpg|jpeg|png)$/i', $url, $fileMatch )
|
||||
) {
|
||||
$errors['downloadFailed'] = 'The Image could not be downloaded!';
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$fileName = $fileMatch[1];
|
||||
// use the domain name as part of the keyword
|
||||
$urlParts = parse_url( $url );
|
||||
if( preg_match( '/(^|\.)([\w\-]+)\.\w+$/', $urlParts['host'], $m ) ) {
|
||||
$fileName = strtolower($m[2]).'-'.$fileName;
|
||||
}
|
||||
$fileName = Keyword::get( $fileName ).'.'.$fileMatch[2];
|
||||
$targetPath = './import/'.$fileName;
|
||||
|
||||
if( !Filesystem::download( $url, $targetPath, Config::$images['maxDownload'], $referer ) ) {
|
||||
$errors['downloadFailed'] = 'The Image could not be downloaded!';
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if( self::process( $fileName, $targetPath, $tags, false, $errors, $url,$commentUpload,$cid) ) {
|
||||
return true;
|
||||
} else {
|
||||
@unlink( $targetPath );
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function process( $name, $localPath, $tags, $uploaded, &$errors, $source, $commentUpload=false,$cid=0) {
|
||||
|
||||
$upl = DB::getRow("SELECT * FROM pl_settings");
|
||||
if ($upl["upload"] != 1){
|
||||
$errors['downloadFailed'] = 'Upload disabled.';
|
||||
return false;
|
||||
}
|
||||
|
||||
self::writeError("test");
|
||||
|
||||
$user = new User();
|
||||
$user->login();
|
||||
|
||||
if( !$user->id ) {
|
||||
$errors['notLoggedIn'] = 'You are not logged in!';
|
||||
return false;
|
||||
}
|
||||
|
||||
// no non-images
|
||||
if(
|
||||
!preg_match( '/([^\/]*?)\.(gif|jpg|jpeg|png)$/i', $name, $fileMatch )
|
||||
) {
|
||||
$errors['wrongExtension'] = 'Your file has not the right extension (gif, jpg or png)!';
|
||||
self::writeError("1");
|
||||
return false;
|
||||
}
|
||||
|
||||
$time = time();
|
||||
$keyword = Keyword::get( $fileMatch[1] );
|
||||
|
||||
// Iterate over all keywords, if this one is allready taken
|
||||
$taken = array();
|
||||
$r = DB::query( 'SELECT keyword FROM '.TABLE_IMAGES.' WHERE keyword LIKE :1', date('Y/m/',$time).$keyword.'%' );
|
||||
foreach( $r as $v ) {
|
||||
$taken[] = substr($v['keyword'],8); // Keyword without date!
|
||||
}
|
||||
$keyword = Keyword::iterate( $keyword, $taken );
|
||||
|
||||
list( $srcWidth, $srcHeight, $type, $attr ) = getimagesize($localPath);
|
||||
|
||||
if( $type == IMAGETYPE_JPEG ) {
|
||||
$extension = 'jpg';
|
||||
} else if( $type == IMAGETYPE_GIF ) {
|
||||
$extension = 'gif';
|
||||
} else if( $type == IMAGETYPE_PNG ) {
|
||||
$extension = 'png';
|
||||
} else if($uploaded == false) {
|
||||
if(preg_match( '/([^\/]*?)\.(jpg|jpeg)$/i', $localPath, $fileMatch )) {
|
||||
$extension = 'jpg';
|
||||
}
|
||||
else if(preg_match( '/([^\/]*?)\.(png)$/i', $localPath, $fileMatch )) {
|
||||
$extension = 'png';
|
||||
}
|
||||
else if(preg_match( '/([^\/]*?)\.(gif)$/i', $localPath, $fileMatch )) {
|
||||
$extension = 'gif';
|
||||
}
|
||||
|
||||
} else {
|
||||
self::writeError("2");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$thumbName = $keyword.".jpg"; // all thumbs are jpegs!
|
||||
$name = $keyword.".".$extension;
|
||||
$imageDir = Config::$images['imagePath'] . date('Y/m', $time);
|
||||
$thumbDir = Config::$images['thumbPath'] . date('Y/m', $time);
|
||||
$imagePath = $imageDir.'/'.$name;
|
||||
|
||||
if( !Filesystem::mkdirr($imageDir) || !Filesystem::mkdirr($thumbDir) ) {
|
||||
$errors['downloadFailed'] = 'folder failed';
|
||||
self::writeError("3");
|
||||
return false;
|
||||
}
|
||||
|
||||
if( $uploaded ) {
|
||||
if( !@move_uploaded_file( $localPath, $imagePath ) ) {
|
||||
$errors['downloadFailed'] = 'move failed';
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if( !@rename( $localPath, $imagePath ) ) {
|
||||
$errors['downloadFailed'] = 'rename failed';
|
||||
self::writeError($extension);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
self::writeError($imagePath);
|
||||
|
||||
if($commentUpload == false && $cid == 0){
|
||||
$hash = md5_file( $imagePath );
|
||||
$c = DB::getRow('SELECT id,keyword FROM '.TABLE_IMAGES.' WHERE hash = :1', $hash);
|
||||
if( !empty( $c ) ) {
|
||||
|
||||
unlink( $imagePath );
|
||||
$errors['duplicate'] =
|
||||
'This image is already in our database!'."<br /><a href='http://www.4ducky.com/all/".'view/'.end($c)."'>Click <u>here</u> to comment it.</a>";
|
||||
self::writeError("5");
|
||||
return false;
|
||||
|
||||
}else{
|
||||
$c = DB::query('SELECT id FROM pl_bannedimages WHERE hash = :1', $hash);
|
||||
if( !empty( $c ) ) {
|
||||
unlink( $imagePath );
|
||||
$errors['duplicate'] = 'This image is already in our database!';
|
||||
self::writeError("6");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// make thumbs
|
||||
foreach( Config::$gridView['classes'] as $gc ) {
|
||||
$thumbPath = $thumbDir.'/'.$gc['dir'].'/'.$thumbName;
|
||||
Filesystem::mkdirr($thumbDir.'/'.$gc['dir']);
|
||||
if( !Image::createThumb( $imagePath, $thumbPath,
|
||||
$gc['width'] * Config::$gridView['gridSize'] - Config::$gridView['borderWidth'],
|
||||
$gc['height'] * Config::$gridView['gridSize'] - Config::$gridView['borderWidth']
|
||||
)) {
|
||||
unlink( $imagePath );
|
||||
$errors['internalError'] = 'Error generating thumbnails!';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
///watermark
|
||||
watermark($imagePath,"media/watermark.png",$imagePath);
|
||||
///watermark
|
||||
|
||||
$user->increaseScore( Config::$postScore );
|
||||
|
||||
|
||||
|
||||
|
||||
if (($commentUpload) && ($cid != 0)){
|
||||
|
||||
DB::query('INSERT INTO pl_commentuploads (c_id,image_link,thumb_link) VALUES (:1,:2,:3)',$cid,$imagePath,"data/thumbs/".date('Y/m/', $time)."64x64/".$thumbName);
|
||||
|
||||
|
||||
|
||||
|
||||
/*DB::insertRow( "pl_commentuploads",array('c_id' => $cid,"image_link" =>$imagePath,"thumb_link" => "data/thumbs/".date('Y/m/', $time)."/128x128/".$name));*/
|
||||
|
||||
}else{
|
||||
$iCount = DB::getRow("SELECT COUNT(*) as c FROM pl_images WHERE user=:1",$user->id);
|
||||
DB::query( 'UPDATE '.TABLE_USERS.' SET images =:2 WHERE id = :1', $user->id,(int)$iCount["c"]);
|
||||
|
||||
DB::insertRow( TABLE_IMAGES,
|
||||
array(
|
||||
'logged' => date('Y-m-d H:i:s', $time),
|
||||
'user' => $user->id,
|
||||
'score' => 1,
|
||||
'votes' => 0,
|
||||
'keyword' => date('Y/m/', $time).$keyword,
|
||||
'tags' => $tags,
|
||||
'image' => $name,
|
||||
'thumb' => $thumbName,
|
||||
'hash' => $hash,
|
||||
'source' => $source
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$imageId = DB::insertId();
|
||||
|
||||
/*$colors = Image::getColors( $imagePath, 4 );
|
||||
foreach( $colors as $c ) {
|
||||
DB::insertRow( TABLE_IMAGECOLORS,
|
||||
array(
|
||||
'imageId' => $imageId,
|
||||
'r' => $c['r'],
|
||||
'g' => $c['g'],
|
||||
'b' => $c['b']
|
||||
)
|
||||
);
|
||||
}*/
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function watermark($SourceFile, $WatermarkFile, $SaveToFile = NULL)
|
||||
|
||||
{
|
||||
|
||||
list( $srcWidth, $srcHeight, $type ) = getimagesize( $SourceFile );
|
||||
if( $type != IMAGETYPE_GIF ) {
|
||||
|
||||
$watermark = @imagecreatefrompng($WatermarkFile)
|
||||
|
||||
|
||||
or exit('Cannot open the watermark file.');
|
||||
|
||||
imageAlphaBlending($watermark, false);
|
||||
|
||||
imageSaveAlpha($watermark, true);
|
||||
|
||||
$image_string = @file_get_contents($SourceFile)
|
||||
|
||||
|
||||
or exit('Cannot open image file.');
|
||||
|
||||
$image = @imagecreatefromstring($image_string)
|
||||
|
||||
|
||||
or exit('Not a valid image format.');
|
||||
|
||||
/*$tmp = imagecreatetruecolor($srcWidth,($srcHeight + 30));*/
|
||||
|
||||
/*$back = imagecolorallocatealpha($image, 0, 0, 0,60);
|
||||
imagefilledrectangle($image,0, $srcHeight - 20,$srcWidth,$srcHeight ,$back); */
|
||||
|
||||
/*imagecopy($tmp,$image,0,0,0,0,$srcWidth,$srcHeight);
|
||||
|
||||
$image = $tmp;*/
|
||||
|
||||
|
||||
$imageWidth=imageSX($image);
|
||||
$imageHeight=imageSY($image);
|
||||
|
||||
$watermarkWidth=imageSX($watermark);
|
||||
$watermarkHeight=imageSY($watermark);
|
||||
|
||||
$coordinate_X = ( $imageWidth) - ( $watermarkWidth);
|
||||
$coordinate_Y = ( $imageHeight) - ( $watermarkHeight);
|
||||
|
||||
imagecopy($image, $watermark, $coordinate_X, $coordinate_Y, 0, 0, $watermarkWidth, $watermarkHeight);
|
||||
|
||||
if(!($SaveToFile)) header('Content-Type: image/jpeg');
|
||||
|
||||
imagejpeg ($image, $SaveToFile, 100);
|
||||
|
||||
|
||||
imagedestroy($image);
|
||||
|
||||
imagedestroy($watermark);
|
||||
|
||||
if(!($SaveToFile)) exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
ImageViewer loads a single image and its comments specified by a keyword.
|
||||
*/
|
||||
|
||||
require_once( 'lib/imagecatalog.php' );
|
||||
|
||||
class ImageViewer extends ImageCatalog {
|
||||
protected $position = 0;
|
||||
protected $keyword = '';
|
||||
|
||||
public $Fav = '';
|
||||
|
||||
public $image = array();
|
||||
public $stream = array();
|
||||
public $userInfo = array();
|
||||
public $uploadid;
|
||||
|
||||
public $datenow;
|
||||
|
||||
|
||||
public function setCurrent( $keyword ) {
|
||||
$this->keyword = $keyword;
|
||||
}
|
||||
public function setFav( $case ) {
|
||||
$this->Fav = $case;
|
||||
}
|
||||
public function CommentSpam( $userId) {
|
||||
|
||||
}
|
||||
|
||||
public function addComment( $userId, $comment,$iname="") {
|
||||
|
||||
|
||||
$countcomments = DB::getRow("SELECT COUNT(*) as c FROM pl_comments WHERE created > now() - INTERVAL 10 SECOND AND userId=:1",$userId);
|
||||
$sp = DB::getRow("SELECT spamblocked, time FROM pl_users WHERE id=:1",$userId);
|
||||
|
||||
if (intval($countcomments["c"]) > 2 || $sp["spamblocked"] == 1) {
|
||||
if (int($sp["time"]) > 0){
|
||||
$timeAdd = int($sp["time"]) + 1800;
|
||||
}else{
|
||||
$timeAdd = time() + 1800;
|
||||
}
|
||||
DB::updateRow("pl_users",array("id" => $userId),array("spamblocked" => 1,"spam_reason"=>"Commentspam","time" => $timeAdd));
|
||||
return false;
|
||||
}else{
|
||||
|
||||
if( $this->image['id'] && $userId && !empty($comment)) {
|
||||
|
||||
|
||||
$datenow = date( 'Y.m.d H:i:s' );
|
||||
|
||||
if (strlen($iname) > 0){
|
||||
DB::insertRow( TABLE_COMMENTS, array(
|
||||
'imageId' => $this->image['id'],
|
||||
'userId' => $userId,
|
||||
'created' => $datenow,
|
||||
'content' => $comment,
|
||||
'thumb' => 1));
|
||||
|
||||
|
||||
}else{
|
||||
DB::insertRow( TABLE_COMMENTS, array(
|
||||
'imageId' => $this->image['id'],
|
||||
'userId' => $userId,
|
||||
'created' => $datenow,
|
||||
'content' => $comment,
|
||||
'thumb' =>0));
|
||||
}
|
||||
if ($this->image['user'] != $userId){
|
||||
DB::query("UPDATE pl_images SET score=score+1 WHERE id=:1",$this->image['id']);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$comments_load = DB::query(
|
||||
'SELECT userId FROM pl_comments WHERE imageid=:1',
|
||||
$this->image['id']
|
||||
);
|
||||
|
||||
|
||||
|
||||
foreach( array_keys($comments_load) as $i ) {
|
||||
|
||||
|
||||
$counter = DB::getRow("SELECT COUNT(*) as c FROM pl_unread WHERE userid=:1 AND imageid=:2",$comments_load[$i]["userId"],$this->image['id']);
|
||||
|
||||
if (($counter["c"] == 0) && $comments_load[$i]["userId"] != $userId){
|
||||
DB::insertRow( "pl_unread", array('imageid' =>$this->image['id'], 'userid' => $comments_load[$i]["userId"],'keyword' => $this->keyword, 'createdby' => $userId));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
$counter = DB::getRow("SELECT COUNT(*) as c FROM pl_unread WHERE userid=:1 AND imageid=:2",$this->image["user"],$this->image['id']);
|
||||
if ($counter["c"] == 0 && $this->image["user"] != $userId){
|
||||
DB::insertRow( "pl_unread", array('imageid' =>$this->image['id'], 'userid' => $this->image["user"],'keyword' => $this->keyword, 'createdby' => $userId));}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function load() {
|
||||
|
||||
|
||||
$conditions = '';
|
||||
if( !empty($this->user) ) {
|
||||
$conditions .= ' AND i.user = :2';
|
||||
$this->userInfo = $this->user;
|
||||
}
|
||||
$this->image = DB::getRow(
|
||||
'SELECT
|
||||
i.id, i.logged, UNIX_TIMESTAMP(i.logged) AS loggedTS,
|
||||
i.keyword, i.image, i.score, i.votes,
|
||||
tags, u.name AS userName, i.user, u.color
|
||||
FROM '.TABLE_IMAGES.' i
|
||||
LEFT JOIN '.TABLE_USERS.' u
|
||||
ON u.id = i.user
|
||||
WHERE i.keyword = :1 '.$conditions,
|
||||
$this->keyword,
|
||||
$this->user['id']
|
||||
);
|
||||
$this->image['path'] = date('Y/m/', $this->image['loggedTS']).$this->image['image'];
|
||||
|
||||
if( empty( $this->user) ) {
|
||||
$this->userInfo = DB::getRow(
|
||||
'SELECT id, name, score, images, avatar, website, color
|
||||
FROM '.TABLE_USERS.'
|
||||
WHERE
|
||||
id = :1',
|
||||
$this->image['user']
|
||||
);
|
||||
}
|
||||
|
||||
// compute previoues and next page
|
||||
$next = DB::getRow(
|
||||
'SELECT i.keyword
|
||||
FROM '.TABLE_IMAGES.' i
|
||||
WHERE i.id < :1 '.$conditions.'
|
||||
ORDER BY id DESC
|
||||
LIMIT 1',
|
||||
$this->image['id'],
|
||||
$this->user['id']
|
||||
);
|
||||
|
||||
$prev = DB::getRow(
|
||||
'SELECT i.keyword
|
||||
FROM '.TABLE_IMAGES.' i
|
||||
WHERE i.id > :1 '.$conditions.'
|
||||
ORDER BY id ASC
|
||||
LIMIT 1',
|
||||
$this->image['id'],
|
||||
$this->user['id']
|
||||
);
|
||||
|
||||
|
||||
|
||||
if( !empty($next) ) {
|
||||
$this->stream['next'] = $next['keyword'];
|
||||
}
|
||||
if( !empty($prev) ) {
|
||||
$this->stream['prev'] = $prev['keyword'];
|
||||
}
|
||||
}
|
||||
|
||||
public function howlong($a=0, $b=0) {
|
||||
if (!is_numeric($a)) $a = strtotime($a); if (!is_numeric($b)) $b = strtotime($b);
|
||||
if ($a == 0) $a = time(); if ($b == 0) $b = time();
|
||||
if ($a == $b) return "at the same time";
|
||||
if ($a > $b) { $aa = $b; $b = $a; $a = $aa; $q = "away"; } else { $q = "ago"; }
|
||||
$value = $b-$a;
|
||||
if ($value == 1) return "1 sec $q";
|
||||
if ($value < 60) return "$value sec $q";
|
||||
$value /= 60;
|
||||
if (round($value) == 1) return "1 min $q";
|
||||
if ($value < 60) return round($value) . " min $q";
|
||||
$value /= 60;
|
||||
if (round($value) == 1) return "1 hour $q";
|
||||
if ($value < 24) return round($value) . " hours $q";
|
||||
$value /= 24;
|
||||
if (round($value) == 1) if ($q == "ago") return "yesterday"; else return "tomorrow";
|
||||
if ($value < 31) return round($value) . " days $q";
|
||||
$value /= 31;
|
||||
if (round($value) == 1) return "1 month $q";
|
||||
if ($value < 12) return round($value) . " months $q";
|
||||
$value /= 12;
|
||||
if (round($value) == 1) return "1 year $q";
|
||||
return round($value) . " years $q";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function loadComments() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
require_once( 'lib/config.php' );
|
||||
|
||||
class Keyword {
|
||||
// Get a keyword from a string
|
||||
// ----------------------------------------------------------------------------
|
||||
public static function get( $kw ) {
|
||||
// narf, since the .php source files are saved as 8859-1 (php doesn't like BOMs)
|
||||
// utf8_decode is invoked, so str_replace actually finds something for these 8859-1
|
||||
// encoded special chars
|
||||
|
||||
$kw = utf8_decode( $kw );
|
||||
$kw = str_replace( array( 'Ä','Ö','Ü','ä','ö','ü','ß',"'" ), array( 'Ae','Oe','Ue','ae','oe','ue','ss','' ), $kw );
|
||||
$kw = preg_replace( '/[^a-zA-Z\d]+/', '#', $kw );
|
||||
$kw = preg_replace( '/^\#+|\#+$/', '', $kw ); // Trim seperators
|
||||
$kw = str_replace( '#', Config::$keywordWordSeperator, $kw ); // replace # with final word seperator
|
||||
|
||||
if( $kw == "" ) {// no keyword?
|
||||
$kw = 'Untitled'; // Assign default keyword
|
||||
}
|
||||
$kw = strtolower( $kw );
|
||||
return $kw;
|
||||
}
|
||||
|
||||
// Check if a keyword has allready been taken. if so, return $keyword-N, where N is an increasing number
|
||||
// ----------------------------------------------------------------------------
|
||||
public static function iterate( $kw, $taken ) {
|
||||
$kwLower = strtolower( $kw );
|
||||
if( in_array( $kwLower, $taken ) ) {
|
||||
for( $i = 2; in_array( $kwLower, $taken); $i++ ) {
|
||||
$kwLower = strtolower( $kw . Config::$keywordWordSeperator . $i );
|
||||
}
|
||||
return $kw . Config::$keywordWordSeperator . ( $i-1 );
|
||||
}
|
||||
else {
|
||||
return $kw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,635 @@
|
||||
<?php
|
||||
|
||||
/* --------------------------------------------------------------------------------
|
||||
*
|
||||
* AXELS CLASS TO MERGE JS AND CSS DATA
|
||||
* V0.9
|
||||
*
|
||||
* License: GPL 3.0 - http://www.gnu.org/licenses/gpl-3.0.html
|
||||
* THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE
|
||||
* LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
* OTHER PARTIES PROVIDE THE PROGRAM ?AS IS? WITHOUT WARRANTY OF ANY KIND,
|
||||
* EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
|
||||
* ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.
|
||||
* SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
|
||||
* SERVICING, REPAIR OR CORRECTION.
|
||||
*
|
||||
* --------------------------------------------------------------------------------
|
||||
* project home:
|
||||
* http://www.axel-hahn.de/php_staticfiles.php
|
||||
* --------------------------------------------------------------------------------
|
||||
*
|
||||
* How it works:
|
||||
*
|
||||
* This script collects all static files per type and saves merged code into a
|
||||
* single file (grouped by defer type for javacscript and media for css).
|
||||
*
|
||||
* It uses caching for the merged files.
|
||||
*
|
||||
* In comparison to other combining scripts this one
|
||||
* - detects relative urls in css files and rewrites them.
|
||||
* - in develop environment you can diasable the merging and debug with
|
||||
* original files
|
||||
* - caching uses a dirty time before cache will be compared with included files
|
||||
*
|
||||
* --------------------------------------------------------------------------------
|
||||
*
|
||||
* --- typical usage:
|
||||
* see readme.txt
|
||||
*
|
||||
* --- KNOWN LIMITS
|
||||
* - static files must be added with absolute path (this class shows you an error)
|
||||
* - don't forget to add gzip compression for .js and .css in your webserver or in .htaccess
|
||||
*
|
||||
* --- TODO/ IDEAS
|
||||
* - html 5: static in js
|
||||
* - merge all css of all media with @media [name]{} sections http://de.selfhtml.org/css/formate/einbinden.htm#media
|
||||
* - cleanup in cache directory
|
||||
* - setter functions have no prameter check
|
||||
* - setter for compression needed?
|
||||
*
|
||||
* --- history:
|
||||
* 2011-08-06 first version
|
||||
* 2011-08-14 rewritten as php class
|
||||
* 2011-08-19 first public version
|
||||
* 2011-08-27 comments added
|
||||
* 2012-02-06 little code rewrite: private functions start with "_"; sortorder of methods, ...
|
||||
* 2012-06-30 css fixed for cachefile in debug mode; css: handle media queries
|
||||
* 2012-07-05 remove css comments in compress function; css default media is "all" now (it was "screen" before)
|
||||
* --------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
class Staticfiles {
|
||||
// set everything to false - they will be set in function setDefaults()
|
||||
|
||||
/**
|
||||
* configuration array
|
||||
* @var array
|
||||
*/
|
||||
private $_aStatic = array(
|
||||
'js' => array(
|
||||
'files' => array(), // will be filled with addMedia()
|
||||
'tplHtml' => '<script type="text/javascript" SRC DEFER></script>',
|
||||
'fRewrite' => '',
|
||||
'fCompress' => 'compressJs',
|
||||
),
|
||||
'css' => array(
|
||||
'files' => array(), // will be filled with addMedia()
|
||||
'tplHtml' => '<link rel="stylesheet" type="text/css" HREF MEDIA TITLE />',
|
||||
'fRewrite' => 'rewriteCss',
|
||||
'fCompress' => 'compressCss',
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* flag: show debug output? If it is true then you see the merged files,
|
||||
* replacements and statistic data in the html header section (as comment)
|
||||
* @var boolean
|
||||
*/
|
||||
var $bDebug = false; // debug enables additional infos
|
||||
|
||||
/**
|
||||
* flag: merge files into a cachefile? If it is false then the source
|
||||
* files will be used. This is helpful in the development environment to
|
||||
* debug code with original files.
|
||||
* @var boolean
|
||||
*/
|
||||
var $bMerging = false; // use compressed files; false links to original files
|
||||
|
||||
/**
|
||||
* flag: overwrite cachefile on each request?
|
||||
* You can use it in your development environment. It overrides the setting
|
||||
* of $this->iMinCacheTime and regenerates merged cachefiles on each request.
|
||||
* debug code with original files.
|
||||
* @var boolean
|
||||
*/
|
||||
var $bRewriteOnEachRequest = false;
|
||||
|
||||
/**
|
||||
* minimum time to cache js and css cachefile on server - even one of the
|
||||
* source files have been changed.
|
||||
* @var integer
|
||||
*/
|
||||
var $iMinCacheTime = 3600;
|
||||
|
||||
/**
|
||||
* name for basepath behind webroot
|
||||
* @var string
|
||||
*/
|
||||
var $sCacheBase = '/~cache/';
|
||||
|
||||
/**
|
||||
* absolute path of cache directory; it will be set in the method
|
||||
* setDefaults to [document root]/$this->sCacheBase/
|
||||
* @var string
|
||||
*/
|
||||
var $sCacheDir = false;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// INIT
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* init function; it sets defaults.
|
||||
* @return bool (dummy)
|
||||
*/
|
||||
public function __construct() {
|
||||
return $this->setDefaults();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// private functions
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* generate html code to link the cachefile (or original files if cache is disabled)
|
||||
* @param string $sType type; one of css|js
|
||||
* @param array $aFile array with filedata (keys are attributes)
|
||||
* @return string html code
|
||||
*/
|
||||
private function _genHtml($sType, $aFile) {
|
||||
$s = $this->_aStatic[$sType]["tplHtml"];
|
||||
|
||||
// TODO: autodetect with pregmatch
|
||||
$aReplace = array("SRC", "DEFER", "HREF", "MEDIA", "TITLE");
|
||||
|
||||
foreach ($aReplace as $sFrom) {
|
||||
$sKey = strtolower($sFrom);
|
||||
$sTo = "";
|
||||
if ($aFile[$sKey])
|
||||
$sTo = " $sKey=\"" . $aFile[$sKey] . "\" ";
|
||||
$s = str_replace($sFrom, $sTo, $s);
|
||||
}
|
||||
$s = str_replace('defer="execution"', " ", $s);
|
||||
$s = str_replace(" ", " ", $s);
|
||||
$s = str_replace(" ", " ", $s);
|
||||
$s = str_replace(" >", ">", $s);
|
||||
return $s;
|
||||
}
|
||||
|
||||
/**
|
||||
* show some statistics info about code compression an gzip
|
||||
* @param type $sOrig
|
||||
* @param type $sCrunched
|
||||
* @param type $sCommment
|
||||
* @return type
|
||||
*/
|
||||
private function _getStats($sOrig, $sCrunched, $sCommment) {
|
||||
if (!$this->bDebug)
|
||||
return "";
|
||||
|
||||
$iOrigSize = strlen($sOrig);
|
||||
$iNewSize = strlen($sCrunched);
|
||||
$igzSize1 = strlen(gzencode($sOrig));
|
||||
$igzSize2 = strlen(gzencode($sCrunched));
|
||||
return $sCommment . "
|
||||
statistics:
|
||||
... orig size: $iOrigSize bytes
|
||||
... compression function: " . $iNewSize . " byte (" . (100 - round($iNewSize / $iOrigSize * 100)) . "% less)
|
||||
|
||||
... gzip
|
||||
...... orig " . $igzSize1 . " byte (" . (100 - round($igzSize1 / $iOrigSize * 100)) . "% less)
|
||||
...... compressed: " . $igzSize2 . " byte (" . (100 - round($igzSize2 / $iNewSize * 100)) . "% less than crunched; " . (100 - round($igzSize2 / $iOrigSize * 100)) . "% less than original)
|
||||
";
|
||||
}
|
||||
|
||||
/**
|
||||
* write logging information (only if debug is enabled)
|
||||
* @param type $s
|
||||
* @return type
|
||||
*/
|
||||
private function _log($s) {
|
||||
if (!$this->bDebug)
|
||||
return true;
|
||||
|
||||
if ($s == "===")
|
||||
$s = "================================================================================";
|
||||
if ($s == "---")
|
||||
$s = "................................................................................";
|
||||
echo "<!-- DEBUG: " . $s . " -->\n";
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// add media files
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* add a css file to this object
|
||||
* @param string $sFile path and filename of css file like in href attribute
|
||||
* @param string $sMedia media type
|
||||
* @param title $sTitle title (will be ignored so far)
|
||||
* @return bool (dummy)
|
||||
*/
|
||||
public function addCss($sFile, $sMedia = 'all', $sTitle = '') {
|
||||
return $this->addMedia("css", array(
|
||||
'file' => $sFile,
|
||||
'href' => $sFile,
|
||||
'media' => $sMedia,
|
||||
'title' => $sTitle,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* add a js file to the js array
|
||||
* @param string $sFile file to load
|
||||
* @param string $sDefer
|
||||
* @return type
|
||||
*/
|
||||
public function addJs($sFile, $defer = "execution") {
|
||||
return $this->addMedia("js", array(
|
||||
'file' => $sFile,
|
||||
'src' => $sFile,
|
||||
'defer' => $defer,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* add media file to array; it is called by addJs() and addCss()
|
||||
* @param string $sType one of css|js
|
||||
* @param array $aFiledata; Keys: file: filename; other: attributes
|
||||
* @return type
|
||||
*/
|
||||
public function addMedia($sType, $aFiledata) {
|
||||
$sGroup = false;
|
||||
if ($sType == "css")
|
||||
$sGroup = $aFiledata["media"];
|
||||
if ($sType == "js")
|
||||
$sGroup = $aFiledata["defer"];
|
||||
if (!$sGroup)
|
||||
return false;
|
||||
return $this->_aStatic[$sType]["files"][$sGroup][] = $aFiledata;
|
||||
}
|
||||
|
||||
/**
|
||||
* compress css code: remove spaces, tabs, line breaks
|
||||
* @param string $s css data
|
||||
* @return string rewritten css data
|
||||
*/
|
||||
public function compressCss($s) {
|
||||
// remove unneded spaces, tabs, new lines
|
||||
$s = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ',), '', $s);
|
||||
|
||||
/* remove unnecessary spaces */
|
||||
foreach (explode(" ", "{ } ; , ; ( ) ") as $char) {
|
||||
$s = str_replace('\ *' . $char . '\ *', '{', $s);
|
||||
}
|
||||
// remove comments
|
||||
$s = preg_replace('#\/\*.*\*\/#U', '', $s);
|
||||
return $s;
|
||||
}
|
||||
|
||||
/**
|
||||
* compress js code
|
||||
* @param string $s js code
|
||||
* @return string with new js code
|
||||
*/
|
||||
public function compressJs($s) {
|
||||
/* remove tabs, spaces, new lines, etc. */
|
||||
$s = str_replace(array("\t", ' ', ' '), ' ', $s);
|
||||
|
||||
/* remove unnecessary spaces */
|
||||
foreach (explode(" ", "{ } ; , ; ( ) ") as $char) {
|
||||
$s = str_replace('\ *' . $char . '\ *', '{', $s);
|
||||
}
|
||||
return $s;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// getter
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* get current basepath of cache
|
||||
* @return boolean
|
||||
*/
|
||||
public function getCacheBase() {
|
||||
return $this->sCacheBase;
|
||||
}
|
||||
|
||||
/**
|
||||
* get full path of current cache directory
|
||||
* @return boolean
|
||||
*/
|
||||
public function getCacheDir() {
|
||||
return $this->sCacheDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* get current debug flag
|
||||
* @return boolean
|
||||
*/
|
||||
public function getDebug() {
|
||||
return $this->bDebug;
|
||||
}
|
||||
|
||||
/**
|
||||
* get current merge flag
|
||||
* @return boolean
|
||||
*/
|
||||
public function getMerging() {
|
||||
return $this->bMerging;
|
||||
}
|
||||
|
||||
/**
|
||||
* get current caching time on server
|
||||
* @return integer
|
||||
*/
|
||||
public function getMinCacheTime() {
|
||||
return $this->iMinCacheTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* get current flag to rewrite the cache
|
||||
* @return boolean
|
||||
*/
|
||||
public function getRewriteCache() {
|
||||
return $this->bRewriteOnEachRequest;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* rewrite urls in css data; this function finds relative
|
||||
* pathes and rewrites them to absolute pathes
|
||||
* @param string $s css content
|
||||
* @param string $sFile filename of included css (to detect the "current" path)
|
||||
* @return string the reswritten css code
|
||||
*/
|
||||
public function rewriteCss($s, $sFile) {
|
||||
|
||||
$aFrom = array();
|
||||
$aTo = array();
|
||||
$treffer = array();
|
||||
preg_match_all("/url\((.*)\)/", $s, $treffer, PREG_OFFSET_CAPTURE);
|
||||
foreach ($treffer[1] as $sUrl) {
|
||||
if (strpos($sUrl[0], "../") or true) {
|
||||
|
||||
$sTo = $sUrl[0];
|
||||
$sWrap = $sTo[0];
|
||||
if ($sWrap == "'" or $sWrap == '"') {
|
||||
$sTo = str_replace($sWrap, "", $sTo);
|
||||
} else
|
||||
$sWrap = "";
|
||||
|
||||
// if there is no absolute path then try to rewrite
|
||||
if ($sTo[0] != "/") {
|
||||
$sTo = str_replace($sWrap, "", $sTo);
|
||||
|
||||
// do replacements
|
||||
$sDir = dirname($sFile);
|
||||
$sTo = str_replace("../", "", $sTo, $count);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$sDir = str_replace(basename($sDir), "", $sDir);
|
||||
}
|
||||
$sTo = $sDir . "/" . $sTo;
|
||||
$sTo = str_replace("//", "/", $sTo);
|
||||
$sTo = str_replace("./", "", $sTo);
|
||||
|
||||
// add wrapping characters
|
||||
$sTo = $sWrap . $sTo . $sWrap;
|
||||
|
||||
$aFrom[] = $sUrl[0];
|
||||
$aTo[] = $sTo;
|
||||
$this->_log("replacing " . $sUrl[0] . " to: " . $sTo . " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($aFrom))
|
||||
$s = str_replace($aFrom, $aTo, $s);
|
||||
return $s;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// setter
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* set another basepath (behind webroot)
|
||||
* @param string new basepath
|
||||
* @return boolean
|
||||
*/
|
||||
public function setCacheBase($str) {
|
||||
$this->sCacheDir = $_SERVER["DOCUMENT_ROOT"] . $str;
|
||||
return $this->sCacheBase = $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* set another cache directory.
|
||||
* @param string new basepath (below webroot)
|
||||
* @return boolean
|
||||
*/
|
||||
public function setCacheDir($str) {
|
||||
return $this->sCacheDir = $_SERVER["DOCUMENT_ROOT"] . $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* set debug flag (for development environment)
|
||||
* @param boolean set true to enable debug output
|
||||
* @return boolean
|
||||
*/
|
||||
public function setDebug($bool) {
|
||||
return $this->bDebug = (bool) $bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* set debug default settings
|
||||
* @return bool (always true)
|
||||
*/
|
||||
public function setDebugDefaults() {
|
||||
$this->iMinCacheTime = 0;
|
||||
$this->bDebug = true;
|
||||
$this->bMerging = true; // set to false that you can debug with original files
|
||||
$this->bRewriteOnEachRequest = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* set all vars to initial values
|
||||
* @return bool (always true)
|
||||
*/
|
||||
public function setDefaults() {
|
||||
$this->sCacheBase = '/~cache/'; // added to url
|
||||
$this->iMinCacheTime = 3600; // force using the cachefile and don't update it
|
||||
$this->bDebug = false; // debug enables additional infos
|
||||
$this->bMerging = true; // use compressed files
|
||||
$this->sCacheDir = $_SERVER["DOCUMENT_ROOT"] . $this->sCacheBase; // local file
|
||||
$this->bRewriteOnEachRequest = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* set merge flag (for development environment)
|
||||
* @param boolean set false to disable the generation of merged cachefiles
|
||||
* @return boolean
|
||||
*/
|
||||
public function setMerging($bool) {
|
||||
return $this->bMerging = (bool) $bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* set minimum cachetime on server for merged js and css files
|
||||
* @param integer value in seconds
|
||||
* @return boolean
|
||||
*/
|
||||
public function setMinCacheTime($int) {
|
||||
return $this->iMinCacheTime = (int) $int;
|
||||
}
|
||||
|
||||
/**
|
||||
* set flag bRewriteOnEachRequest (for development environment)
|
||||
* @param boolean set true to ignore caching time
|
||||
* @return type
|
||||
*/
|
||||
public function setRewriteCache($bool) {
|
||||
return $this->bRewriteOnEachRequest = (bool) $bool;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Merge original files of a group to a single cachefile. It updates or just touches the cachefile.
|
||||
* Output is the html code to include the cached css/ js in the html header.
|
||||
* @param string $sType one of css|js
|
||||
* @return bool (dummy)
|
||||
*/
|
||||
public function writeMedia($sType) {
|
||||
$sHtml = ''; // generated html output to document
|
||||
$aFiles = $this->_aStatic[$sType]["files"];
|
||||
$this->_log("===");
|
||||
$this->_log("type: $sType");
|
||||
$this->_log("THANKS FOR USING MY PHP CLASS STATICFILES!\n (this message and debug stuff below is shown with enabled debug only)\n www.axel-hahn.de");
|
||||
|
||||
// if caching is disabled then generate output with original files and return
|
||||
if (!$this->bMerging) {
|
||||
$this->_log("You disabled the merging feature - here you get the links to the original files.");
|
||||
foreach ($aFiles as $sGroup => $aFiledata) {
|
||||
foreach ($aFiledata as $aFile) {
|
||||
$sHtml.=$this->_genHtml($sType, $aFile);
|
||||
}
|
||||
}
|
||||
echo $sHtml;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// step 1: get all files of a group
|
||||
$aFileList = array();
|
||||
foreach ($aFiles as $sGroup => $aFiledata) {
|
||||
foreach ($aFiledata as $aFile) {
|
||||
$aFileList[$sGroup][] = $aFile['file'];
|
||||
}
|
||||
}
|
||||
|
||||
// check / regenerate cache file
|
||||
foreach ($aFiles as $sGroup => $aFiledata) {
|
||||
$bCompress = true;
|
||||
$iNewest = 0;
|
||||
$sData = '';
|
||||
|
||||
// get cachefile and check age
|
||||
$sCacheFile = $sType . "_cache_" . md5($sGroup . implode($aFileList[$sGroup])) . "." . $sType;
|
||||
$sCacheFullFile = $this->sCacheDir . $sCacheFile;
|
||||
|
||||
$this->_log("===");
|
||||
$this->_log("$sType-group: \"$sGroup\"");
|
||||
$this->_log("cachefile = " . $sCacheFullFile);
|
||||
if (file_exists($sCacheFullFile)) {
|
||||
$bCompress = false;
|
||||
$aStatCache = stat($sCacheFullFile);
|
||||
$iCacheAge = date("U") - $aStatCache['mtime'];
|
||||
if ($iCacheAge > $this->iMinCacheTime)
|
||||
$bCompress = true;
|
||||
$this->_log("age of cachefile = $iCacheAge s (cachefile will be used $this->iMinCacheTime s; " . ($this->iMinCacheTime - $iCacheAge) . " s left)");
|
||||
} else {
|
||||
$this->_log("cachefile does not exist yet");
|
||||
}
|
||||
|
||||
// if there is no cachefile or cachefile is out of date
|
||||
// then compare with newest filestamp
|
||||
if ($bCompress) {
|
||||
|
||||
// merge all files into $sData
|
||||
// and get timestamp of newest file $iNewest
|
||||
foreach ($aFiledata as $aFile) {
|
||||
$this->_log("---");
|
||||
$sFile = $aFile["file"];
|
||||
$sFullFile = $_SERVER["DOCUMENT_ROOT"] . $sFile;
|
||||
if (!file_exists($sFullFile))
|
||||
die("ERROR: writeMedia() failed. File not found: $sFullFile.");
|
||||
$aTmp = stat($sFullFile);
|
||||
if ($aTmp['mtime'] > $iNewest)
|
||||
$iNewest = $aTmp['mtime'];
|
||||
$s = file_get_contents($sFullFile);
|
||||
$this->_log("checking $sFile - \tunix ts: " . $aTmp['mtime'] . ";\t" . strlen($s) . " byte (group: " . $sGroup . ")");
|
||||
if ($this->_aStatic[$sType]["fRewrite"]) {
|
||||
$this->_log("rewrite with \$this->" . $this->_aStatic[$sType]["fRewrite"]);
|
||||
$sRewritten = $this->{$this->_aStatic[$sType]["fRewrite"]}($s, $sFile);
|
||||
if (strlen($sRewritten) == 0) {
|
||||
$this->_log("OOOPS rewrite function for file $sFile - " . $this->_aStatic[$sType]["fRewrite"] . " returns ZERO(!!!) bytes");
|
||||
} else
|
||||
$s = $sRewritten;
|
||||
}
|
||||
$sData.=$s;
|
||||
}
|
||||
$this->_log("unix ts of cachefile " . $aStatCache['mtime']);
|
||||
|
||||
if (($aStatCache['mtime'] - $iMinCacheTime) < $iNewest || $this->bRewriteOnEachRequest) {
|
||||
$this->_log("Need to (re)generate cache. A static file is newer than cache or cache did not exist.");
|
||||
$sOrig = $sData;
|
||||
|
||||
if ($this->_aStatic[$sType]["fCompress"]) {
|
||||
$this->_log("compress with \$this->" . $this->_aStatic[$sType]["fCompress"] . " ");
|
||||
$sData = $this->{$this->_aStatic[$sType]["fCompress"]}($sData);
|
||||
if (strlen($sData) == 0) {
|
||||
$this->_log("OOOPS compress function for type $sType - " . $this->_aStatic[$sType]["fCompress"] . " returns ZERO(!!!) bytes");
|
||||
$this->_log("orig: " . strlen($sOrig) . " byte - files: \n" . print_r($aFileList[$sGroup], true) . " ");
|
||||
$sData = $sOrig;
|
||||
}
|
||||
} else {
|
||||
$this->_log("no compression for type " . $sType . " ");
|
||||
}
|
||||
$sStats = $this->_getStats($sOrig, $sData, " ");
|
||||
$this->_log($sStats);
|
||||
if ($this->bDebug)
|
||||
$sData = "/* AXEL HAHN - CACHED " . $sType . " MERGE FILE ... created " . date("Y-m-d H:i:s") . " " . $sStats . " (you see this only if debug is enabled) */ \n" . $sData;
|
||||
$this->_log("writing cachefile");
|
||||
if (!file_exists(dirname($sCacheFullFile)))
|
||||
mkdir(dirname($sCacheFullFile));
|
||||
file_put_contents($sCacheFullFile, $sData);
|
||||
} else {
|
||||
$this->_log("just touching cachefile to use it further $this->iMinCacheTime s");
|
||||
touch($sCacheFullFile);
|
||||
}
|
||||
}
|
||||
|
||||
// generate html output: link to the cacheile
|
||||
if ($sType == "css")
|
||||
$aCachefileoptions = array(
|
||||
'file' => $this->sCacheBase . $sCacheFile,
|
||||
'href' => $this->sCacheBase . $sCacheFile,
|
||||
'media' => $sGroup,
|
||||
);
|
||||
if ($sType == "js") {
|
||||
$aCachefileoptions = array(
|
||||
'file' => $this->sCacheBase . $sCacheFile,
|
||||
'src' => $this->sCacheBase . $sCacheFile,
|
||||
);
|
||||
}
|
||||
if ($aCachefileoptions)
|
||||
$sHtml.=$this->_genHtml($sType, $aCachefileoptions) . "\n";
|
||||
}
|
||||
|
||||
echo $sHtml . "\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
The UserList class loads a number of users from the database, specified by a page
|
||||
*/
|
||||
|
||||
require_once( 'lib/config.php' );
|
||||
require_once( 'lib/db.php' );
|
||||
|
||||
class UserList {
|
||||
protected $page = 0;
|
||||
|
||||
protected $usersPerPage = 0;
|
||||
protected $totalResults = 0;
|
||||
|
||||
public $users = array();
|
||||
public $pages = array();
|
||||
|
||||
public function __construct( $usersPerPage ) {
|
||||
$this->usersPerPage = abs(intval($usersPerPage));
|
||||
}
|
||||
|
||||
public function setPage( $page ) {
|
||||
$page = intval($page);
|
||||
$this->page = $page > 0 ? $page - 1 : 0;
|
||||
}
|
||||
|
||||
public function load() {
|
||||
$this->users = DB::query(
|
||||
'SELECT SQL_CALC_FOUND_ROWS
|
||||
UNIX_TIMESTAMP( u.registered ) as registered,
|
||||
u.name, u.score, u.images, u.avatar, u.website
|
||||
FROM '.TABLE_USERS.' u
|
||||
WHERE valid = 1
|
||||
GROUP BY u.id
|
||||
ORDER BY u.id ASC
|
||||
LIMIT :1, :2',
|
||||
$this->page * $this->usersPerPage,
|
||||
$this->usersPerPage
|
||||
);
|
||||
$this->totalResults = DB::foundRows();
|
||||
|
||||
// compute previoues, current and next page
|
||||
if( $this->totalResults > 0 ) {
|
||||
$this->pages['current'] = $this->page+1;
|
||||
$this->pages['total'] = ceil($this->totalResults / $this->usersPerPage);
|
||||
if( $this->page > 0 ) {
|
||||
$this->pages['prev'] = $this->page;
|
||||
}
|
||||
if( $this->totalResults > $this->usersPerPage * $this->page + $this->usersPerPage ) {
|
||||
$this->pages['next'] = $this->page + 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,601 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
An object of this class represents a user on the site. All user
|
||||
related tasks (registration, login, profile etc.) are handled here.
|
||||
|
||||
A user object is created and attempted to login on each page load.
|
||||
*/
|
||||
|
||||
require_once( 'config.php' );
|
||||
require_once( 'db-mobile.php' );
|
||||
|
||||
class User {
|
||||
public $name = '';
|
||||
public $id = 0;
|
||||
public $validationString = '';
|
||||
public $admin = 0;
|
||||
public $website = 0;
|
||||
public $color = "0";
|
||||
public $stylecolor = "black";
|
||||
public $avatar = "data/avatars/default.png";
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
public function validate( $id ) {
|
||||
$u = DB::getRow(
|
||||
'SELECT id, name, admin, website, color, style, avatar FROM '.TABLE_USERS.' WHERE valid = 0 AND remember = :1',
|
||||
$id
|
||||
);
|
||||
$reg = DB::getRow("SELECT * FROM pl_settings");
|
||||
if ($reg["register"] != 1){
|
||||
return false;
|
||||
}
|
||||
if( empty($u) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DB::updateRow( TABLE_USERS, array('id' => $u['id']), array( 'valid' => 0) );
|
||||
|
||||
session_name( Config::$sessionCookie );
|
||||
session_start();
|
||||
$_SESSION['id'] = $this->id = $u['id'];
|
||||
$_SESSION['name'] = $this->name = $u['name'];
|
||||
$_SESSION['admin'] = $this->admin = $u['admin'];
|
||||
$_SESSION['website'] = $this->website = $u['website'];
|
||||
$_SESSION['color'] = $this->color = $u['color'];
|
||||
$_SESSION['stylecolor'] = $this->stylecolor = $u['style'];
|
||||
$_SESSION['avatar'] = $this->avatar = $u['avatar'];
|
||||
|
||||
setcookie( Config::$rememberCookie, $id, time() + 3600 * 24 * 365, Config::$absolutePath );
|
||||
|
||||
if( Config::$vbbIntegration['enabled'] ) {
|
||||
global $vbulletin;
|
||||
$forum = new ForumOps($vbulletin);
|
||||
$forum->login(array('username' => $u['name']));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isSpamLocked() {
|
||||
// delete all ips older than IP_LOCK_TIME
|
||||
DB::query( 'DELETE FROM '.TABLE_UPLOADLOCK.' WHERE ts < :1', time() - Config::$uploadLockTime );
|
||||
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
$r = DB::getRow( 'SELECT COUNT(*) AS c FROM '.TABLE_UPLOADLOCK.'
|
||||
WHERE ip = :1',
|
||||
$ip
|
||||
);
|
||||
|
||||
if( $r['c'] > Config::$maxNumUploads ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function isSpamer() {
|
||||
|
||||
|
||||
$r = DB::getRow( 'SELECT logged FROM pl_images
|
||||
WHERE user = :1 order by logged desc',
|
||||
$this->id
|
||||
);
|
||||
$time = strtotime($r["logged"]);
|
||||
|
||||
if( (time() - (integer)$time) < 10 ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function isSpamming() {
|
||||
$block = DB::getRow("SELECT spamblocked,time FROM pl_users WHERE id=:1",$this->id);
|
||||
if ( (int)$block["spamblocked"] == 1)
|
||||
{
|
||||
if ((int)$block["time"] != 0){
|
||||
$now = time();
|
||||
$then = (int)$block["time"];
|
||||
if ($now > $then) {
|
||||
DB::updateRow("pl_users",array("id" => $this->id),array("time" => 0,"spamblocked" => 0));
|
||||
return false;
|
||||
}else{
|
||||
return $block["time"];
|
||||
exit();
|
||||
}
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$count = DB::getRow( 'SELECT COUNT(*) as c FROM pl_images
|
||||
WHERE user = :1',
|
||||
$this->id
|
||||
);
|
||||
|
||||
if ( $count["c"] >= 3){
|
||||
|
||||
$r = DB::query( 'SELECT id,image,keyword,logged FROM pl_images
|
||||
WHERE user = :1 LIMIT '.((integer)$count["c"]-3).',2',
|
||||
$this->id
|
||||
);
|
||||
|
||||
|
||||
$r0 = DB::getRow( 'SELECT image,keyword,logged FROM pl_images
|
||||
WHERE user = :1 LIMIT '.((integer)$count["c"]-1).',1',
|
||||
$this->id
|
||||
);
|
||||
|
||||
require_once("img_class.php");
|
||||
$ban =0;
|
||||
foreach ($r as $checkable) {
|
||||
|
||||
|
||||
|
||||
if ((strtotime($r0["logged"]) - strtotime($checkable["logged"])) < 60){
|
||||
|
||||
|
||||
|
||||
$splitter = split("/",$checkable["keyword"]);
|
||||
$file2 = $splitter[0]."/".$splitter[1]."/".$checkable["image"];
|
||||
$splitter = split("/",$r0["keyword"]);
|
||||
$file1 = $splitter[0]."/".$splitter[1]."/".$r0["image"];
|
||||
|
||||
$diff = new imagediff("data/images/".$file2, "data/images/".$file1);
|
||||
$dif = $diff->diff();
|
||||
|
||||
if ($dif > 0.92){
|
||||
$ban += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($ban >= 2){
|
||||
foreach ($r as $checkable) {
|
||||
DB::query("DELETE FROM pl_images WHERE id=:1",$checkable["id"]);
|
||||
}
|
||||
DB::updateRow("pl_users",array("id" => $this->id),array("spamblocked" => 1,"spam_reason"=>"Imagespam","time" => time() + (7 * 24 * 60 * 60)));
|
||||
return true;
|
||||
}else{
|
||||
return false;}
|
||||
}else{ return false;}
|
||||
}
|
||||
|
||||
public function logUpload() {
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
DB::insertRow( TABLE_UPLOADLOCK, array('ip' => $ip, 'ts' => time(),'user' => $this->id) );
|
||||
}
|
||||
|
||||
public function login() {
|
||||
|
||||
// attempt to login via post, session or remeber cookie
|
||||
|
||||
|
||||
|
||||
session_name( Config::$sessionCookie );
|
||||
|
||||
if( isset($_POST['login']) ) { // post login
|
||||
|
||||
|
||||
$u = DB::getRow(
|
||||
'SELECT id, name, admin, website, color, style,avatar FROM '.TABLE_USERS.' WHERE name = :1 AND pass = :2 and valid = 1',
|
||||
$_POST['name'], md5($_POST['pass'])
|
||||
);
|
||||
$banstate = DB::getRow("SELECT * FROM pl_banned WHERE id=:1",$u['id']);
|
||||
if ($banstate){
|
||||
return "ban/".$banstate["reason"];
|
||||
}
|
||||
|
||||
if( !empty($u) ) {
|
||||
$c = DB::getRow('SELECT ip, created, COUNT(*) as c from pl_registerlock WHERE ip=:1 GROUP BY ip',$_SERVER['REMOTE_ADDR']);
|
||||
if ((int)$c["c"] == 0){
|
||||
DB::insertRow( "pl_registerlock", array("ip"=>$_SERVER['REMOTE_ADDR'],"created"=>date('Y-m-d H:i:s')));}else{
|
||||
DB::query("DELETE FROM pl_registerlock WHERE ip=:1",$_SERVER['REMOTE_ADDR']);
|
||||
DB::insertRow("pl_registerlock",array('ip'=>$_SERVER['REMOTE_ADDR'],'created'=>date('Y-m-d H:i:s')));
|
||||
}
|
||||
|
||||
session_start();
|
||||
$_SESSION['id'] = $this->id = $u['id'];
|
||||
$_SESSION['name'] = $this->name = $u['name'];
|
||||
$_SESSION['admin'] = $this->admin = $u['admin'];
|
||||
$_SESSION['website'] = $this->website = $u['website'];
|
||||
$_SESSION['color'] = $this->color = $u['color'];
|
||||
$_SESSION['stylecolor'] = $this->stylecolor = $u['style'];
|
||||
$_SESSION['avatar'] = $this->avatar = $u['avatar'];
|
||||
|
||||
if( !empty($_POST['remember']) ) {
|
||||
$r = md5(uniqid(rand()));
|
||||
DB::updateRow( TABLE_USERS, array('id' => $this->id), array('remember' => $r ) );
|
||||
setcookie( Config::$rememberCookie, $r, time() + 3600 * 24 * 365, Config::$absolutePath );
|
||||
}
|
||||
|
||||
if( Config::$vbbIntegration['enabled'] ) {
|
||||
global $vbulletin;
|
||||
$forum = new ForumOps($vbulletin);
|
||||
$forum->login(array('username' => $u['name']));
|
||||
}
|
||||
}else{return "wronglogin";}
|
||||
|
||||
}
|
||||
|
||||
else if( !empty($_COOKIE[Config::$sessionCookie]) ) { // session running
|
||||
session_start();
|
||||
$c = DB::getRow('SELECT ip, created, COUNT(*) as c from pl_registerlock WHERE ip=:1 GROUP BY ip',$_SERVER['REMOTE_ADDR']);
|
||||
if ((int)$c["c"] == 0){
|
||||
DB::insertRow( "pl_registerlock", array("ip"=>$_SERVER['REMOTE_ADDR'],"created"=>date('Y-m-d H:i:s')));}else{
|
||||
DB::query("DELETE FROM pl_registerlock WHERE ip=:1",$_SERVER['REMOTE_ADDR']);
|
||||
DB::insertRow("pl_registerlock",array('ip'=>$_SERVER['REMOTE_ADDR'],'created'=>date('Y-m-d H:i:s')));
|
||||
}
|
||||
if( empty($_SESSION['id']) ) {
|
||||
setcookie(Config::$sessionCookie, false, time() - 3600, Config::$absolutePath );
|
||||
} else {
|
||||
$this->id = $_SESSION['id'];
|
||||
$this->name = $_SESSION['name'];
|
||||
$this->admin = $_SESSION['admin'];
|
||||
$this->website = $_SESSION['website'];
|
||||
$this->color = $u['color'];
|
||||
$this->stylecolor = $u['stylecolor'];
|
||||
$this->avatar = $u['avatar'];
|
||||
|
||||
|
||||
}
|
||||
if (DB::getRow("SELECT id FROM pl_banned WHERE id=:1",$this->id)){
|
||||
$this->logout();
|
||||
return "banned";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
else if( !empty($_COOKIE[Config::$rememberCookie]) ) { // remember cookie found
|
||||
$u = DB::getRow(
|
||||
'SELECT id, name, admin, website, style, color, avatar FROM '.TABLE_USERS.' WHERE remember = :1',
|
||||
$_COOKIE[Config::$rememberCookie]
|
||||
);
|
||||
|
||||
if( !empty($u) ) {
|
||||
|
||||
session_start();
|
||||
$_SESSION['id'] = $this->id = $u['id'];
|
||||
$_SESSION['name'] = $this->name = $u['name'];
|
||||
$_SESSION['admin'] = $this->admin = $u['admin'];
|
||||
$_SESSION['website'] = $this->website = $u['website'];
|
||||
$_SESSION['color'] = $this->color = $u['color'];
|
||||
$_SESSION['stylecolor'] = $this->stylecolor = $u['style'];
|
||||
$_SESSION['avatar'] = $this->avatar = $u['avatar'];
|
||||
// refresh for another year
|
||||
setcookie( Config::$rememberCookie, $_COOKIE[Config::$rememberCookie], time() + 3600 * 24 * 365, Config::$absolutePath );
|
||||
|
||||
|
||||
$c = DB::getRow('SELECT ip, created, COUNT(*) as c from pl_registerlock WHERE ip=:1 GROUP BY ip',$_SERVER['REMOTE_ADDR']);
|
||||
if ((int)$c["c"] == 0){
|
||||
DB::insertRow( "pl_registerlock", array("ip"=>$_SERVER['REMOTE_ADDR'],"created"=>date('Y-m-d H:i:s')));}else{
|
||||
DB::query("DELETE FROM pl_registerlock WHERE ip=:1",$_SERVER['REMOTE_ADDR']);
|
||||
DB::insertRow("pl_registerlock",array('ip'=>$_SERVER['REMOTE_ADDR'],'created'=>date('Y-m-d H:i:s')));
|
||||
}
|
||||
|
||||
if (DB::getRow("SELECT id FROM pl_banned WHERE id=:1",$u['id'])){
|
||||
$this->logout();
|
||||
return "banned";
|
||||
}
|
||||
if( Config::$vbbIntegration['enabled'] ) {
|
||||
global $vbulletin;
|
||||
$forum = new ForumOps($vbulletin);
|
||||
$forum->login(array('username' => $u['name']));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function profile( $localFile, &$messages ) {
|
||||
$upd = array( 'website' => $_POST['website'] );
|
||||
|
||||
$_SESSION['website'] = $_POST['website'];
|
||||
|
||||
if( Config::$vbbIntegration['enabled'] ) {
|
||||
global $vbulletin;
|
||||
$forum = new ForumOps($vbulletin);
|
||||
}
|
||||
|
||||
$p = trim($_POST['cpass']);
|
||||
if( !empty( $p ) ) {
|
||||
if( strlen($_POST['cpass']) < 6 ) {
|
||||
$messages['passToShort'] = true;
|
||||
}
|
||||
else if( $_POST['cpass'] != $_POST['cpass2'] ) {
|
||||
$messages['passNotEqual'] = true;
|
||||
}
|
||||
else {
|
||||
$upd['pass'] = md5($_POST['cpass2']);
|
||||
if( Config::$vbbIntegration['enabled'] ) {
|
||||
$forum->set_pass( $_SESSION['name'], $_POST['cpass2']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !empty( $localFile ) ) {
|
||||
require_once( 'lib/images.php' );
|
||||
|
||||
list( $imgWidth, $imgHeight, $imgtype ) = getimagesize($localFile);
|
||||
|
||||
if ( $imgWidth == 64 && $imgHeight == 64 && $imgtype == IMAGETYPE_GIF){
|
||||
$name = Config::$images['avatarsPath'].uniqid().'.gif';
|
||||
if (!move_uploaded_file($localFile,$name)){
|
||||
$messages['avatarFailed'] = true;
|
||||
$upd['avatar'] = Config::$images['avatarsPath']."default.png";
|
||||
}else{
|
||||
$upd['avatar'] = $name;
|
||||
}
|
||||
}else{
|
||||
$name = Config::$images['avatarsPath'].uniqid().'.jpg';
|
||||
|
||||
if( Image::createThumb( $localFile, $name, 64,64 ) ) {
|
||||
$upd['avatar'] = $name;
|
||||
} else {
|
||||
$messages['avatarFailed'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($_POST['color'])){
|
||||
if(preg_match('/^[a-f0-9]{6}$/i', $_POST['color'])){
|
||||
if ( strtolower($_POST['color']) != "ffffff"){
|
||||
$upd['color'] = $_POST['color'];
|
||||
}else{
|
||||
$upd['color'] = "0";
|
||||
}
|
||||
}else{
|
||||
$messages['colorFailed'] = true;
|
||||
}
|
||||
}
|
||||
//--------------------------------------------------------------------blockuser
|
||||
if(!empty($_POST['blockuser'])){
|
||||
if(preg_match('/^\w{2,20}$/', $_POST['blockuser'])){
|
||||
$blockedusers = array();
|
||||
$blockedusers = DB::getRow("SELECT id, users FROM pl_blocked WHERE id=:1",$this->id);
|
||||
|
||||
if(!empty($blockedusers)){
|
||||
$blockedusers = unserialize($blockedusers['users']);
|
||||
if (in_array(strtolower ($_POST['blockuser']),$blockedusers)){
|
||||
$messages['blockAlready'] = true;
|
||||
}else{
|
||||
if(DB::query('SELECT * FROM pl_users WHERE name=:1', strtolower ($_POST['blockuser']))){
|
||||
|
||||
array_push($blockedusers,$_POST['blockuser']);
|
||||
if(DB::query('UPDATE pl_blocked SET users=:1 WHERE id=:2', serialize($blockedusers),$this->id)){
|
||||
$messages['blocked'] = true;
|
||||
}else{
|
||||
$messages['blockFailed'] = true;
|
||||
}
|
||||
}else{
|
||||
$messages['userFailed'] = true;
|
||||
}
|
||||
|
||||
}
|
||||
}else{
|
||||
if(DB::query('SELECT * FROM pl_users WHERE name=:1', $_POST['blockuser'])){
|
||||
$newarray = array();
|
||||
array_push($newarray,strtolower ($_POST['blockuser']));
|
||||
|
||||
if(DB::query("INSERT INTO pl_blocked (id,users) VALUES (:1,:2)",$this->id,serialize($newarray))){
|
||||
$messages['blocked'] = true;
|
||||
}else{
|
||||
$messages['blockFailed'] = true;
|
||||
}
|
||||
|
||||
}else{
|
||||
$messages['userFailed'] = true;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$messages['blockFailed'] = true;
|
||||
}
|
||||
|
||||
}
|
||||
//--------------------------------------------------------------------UNblockuser
|
||||
function remove_item_by_value($array, $val = '', $preserve_keys = true) {
|
||||
if (count($array) == 1) return false;
|
||||
if (empty($array) || !is_array($array)) return false;
|
||||
if (!in_array($val, $array)) return $array;
|
||||
|
||||
foreach($array as $key => $value) {
|
||||
if ($value == $val) unset($array[$key]);
|
||||
}
|
||||
|
||||
return ($preserve_keys === true) ? $array : array_values($array);
|
||||
}
|
||||
//--------------------------------------------------------------------UNblockuser
|
||||
if(!empty($_POST['unblockuser'])){
|
||||
if ($_POST['unblockuser'] != "select"){
|
||||
if(preg_match('/^\w{2,20}$/', $_POST['unblockuser'])){
|
||||
if(DB::query('SELECT * FROM pl_users WHERE name=:1', $_POST['unblockuser'])){
|
||||
$blockedusers = array();
|
||||
$blockedusers = DB::getRow("SELECT id, users FROM pl_blocked WHERE id=:1",$this->id);
|
||||
if(!empty($blockedusers)){
|
||||
$blockedusers = unserialize($blockedusers['users']);
|
||||
if (in_array($_POST['unblockuser'],$blockedusers)){
|
||||
$blockedusers = remove_item_by_value($blockedusers,$_POST['unblockuser']);
|
||||
if ($blockedusers){
|
||||
DB::query('UPDATE pl_blocked SET users=:1 WHERE id=:2', serialize($blockedusers),$this->id);
|
||||
$messages['unblocked'] = true;
|
||||
}else{
|
||||
DB::query('DELETE FROM pl_blocked WHERE id=:1',$this->id);
|
||||
$messages['unblocked'] = true;
|
||||
}
|
||||
}else{$messages['notBlocked'] = true;}
|
||||
}else{$messages['unblockFailed'] = true;}
|
||||
}else{$messages['userFailed'] = true;}
|
||||
}else{$messages['unblockFailed'] = true;}
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------STYLE
|
||||
|
||||
if(isset($_POST['stylecolor'])) {
|
||||
if($_POST['stylecolor'] == 'white') {
|
||||
|
||||
$upd['style'] = $_POST['stylecolor'];
|
||||
|
||||
} elseif($_POST['stylecolor'] == 'black') {
|
||||
$upd['style'] = $_POST['stylecolor'];
|
||||
} else{
|
||||
$upd['style'] = $_POST['black'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if( empty($this->email) &&
|
||||
preg_match('/^[\.\w\-]{1,}@[\.\w\-]{2,}\.[\w]{2,}$/', $_POST['email'])
|
||||
) {
|
||||
if( Config::$vbbIntegration['enabled'] ) {
|
||||
$forum->set_email( $_SESSION['name'], $_POST['email']);
|
||||
}
|
||||
$upd['email'] = $_POST['email'];
|
||||
}
|
||||
|
||||
DB::updateRow( TABLE_USERS, array( 'id' => $this->id ), $upd );
|
||||
}
|
||||
|
||||
public function loadEmail() {
|
||||
$tmp = DB::getRow(
|
||||
'SELECT email,color,style,avatar FROM '.TABLE_USERS.' WHERE id = :1',
|
||||
$this->id
|
||||
);
|
||||
$this->email = $tmp['email'];
|
||||
$this->color = $tmp['color'];
|
||||
$this->stylecolor = $tmp['style'];
|
||||
$this->avatar = $u['avatar'];
|
||||
}
|
||||
|
||||
public function logout() {
|
||||
session_unset();
|
||||
session_destroy();
|
||||
$_SESSION = array();
|
||||
setcookie( Config::$rememberCookie, false, time() - 3600, Config::$absolutePath );
|
||||
setcookie( Config::$sessionCookie, false, time() - 3600, Config::$absolutePath );
|
||||
|
||||
if( Config::$vbbIntegration['enabled'] ) {
|
||||
global $vbulletin;
|
||||
$forum = new ForumOps($vbulletin);
|
||||
$forum->logout();
|
||||
}
|
||||
}
|
||||
|
||||
public function increaseScore( $amount ) {
|
||||
DB::query(
|
||||
'UPDATE '.TABLE_USERS.' SET score = score + :1 WHERE id = :2',
|
||||
intval( $amount ),
|
||||
$this->id
|
||||
);
|
||||
}
|
||||
|
||||
public function register( &$messages,$inviteC=false ) {
|
||||
|
||||
DB::query( 'DELETE FROM '.TABLE_USERS.' WHERE valid = 0 AND registered < NOW() - INTERVAL 30 MINUTE' );
|
||||
$iplocks = DB::getRow("DELETE FROM pl_registerlock WHERE created < (NOW() - INTERVAL 1440 MINUTE)");
|
||||
|
||||
|
||||
$reg = DB::getRow("SELECT * FROM pl_settings");
|
||||
$doubleacc = DB::getRow("SELECT COUNT(*) as c FROM pl_registerlock WHERE ip=:1",$_SERVER['REMOTE_ADDR']);
|
||||
|
||||
if($inviteC == false){
|
||||
if ($reg["register"] != 1 || $doubleacc["c"] > 0){
|
||||
$messages['registerClosed'] = true;
|
||||
}
|
||||
}else{
|
||||
if ($doubleacc["c"] > 0){
|
||||
DB::updateRow("pl_invites",array("code"=>$inviteC),array("used"=>1,"usedby"=>1));
|
||||
$inviteC = false;
|
||||
$messages['registerClosed'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( !preg_match('/^\w{2,20}$/', $_POST['name']) ) {
|
||||
$messages['nameInvalid'] = true;
|
||||
} else {
|
||||
$u = DB::getRow( 'SELECT * FROM '.TABLE_USERS.' WHERE name = :1', $_POST['name'] );
|
||||
if( !empty($u) ) {
|
||||
$messages['nameInUse'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( strlen($_POST['pass']) < 6 ) {
|
||||
$messages['passToShort'] = true;
|
||||
}
|
||||
else if( $_POST['pass'] != $_POST['pass2'] ) {
|
||||
$messages['passNotEqual'] = true;
|
||||
}
|
||||
|
||||
if( !preg_match( '/^[\.\w\-]{1,}@[\.\w\-]{2,}\.[\w]{2,}$/', $_POST['email'] ) ) {
|
||||
$messages['wrongEmail'] = true;
|
||||
} else {
|
||||
$u = DB::getRow( 'SELECT * FROM '.TABLE_USERS.' WHERE email = :1', $_POST['email'] );
|
||||
if( !empty($u) ) {
|
||||
$messages['emailInUse'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( !empty($messages) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$this->validationString = md5(uniqid(rand()));
|
||||
|
||||
DB::insertRow( TABLE_USERS, array(
|
||||
'registered' => date('Y-m-d H:i:s'),
|
||||
'name' => $_POST['name'],
|
||||
'pass' => md5($_POST['pass']),
|
||||
'valid' => 1,
|
||||
'score' => 0,
|
||||
'images' => 0,
|
||||
'website' => '',
|
||||
'avatar' => Config::$images['avatarsPath'].'default.png',
|
||||
'remember' => $this->validationString,
|
||||
'admin' => 0,
|
||||
'email' => $_POST['email'],
|
||||
'color' => '0',
|
||||
'style' => 'black',
|
||||
'invite' => $inviteC
|
||||
));
|
||||
|
||||
if($inviteC != false){
|
||||
$lastid= DB::getRow("SELECT LAST_INSERT_ID() as id");
|
||||
DB::updateRow("pl_invites",array("code"=>$inviteC),array("used"=>1,"usedby"=>$lastid["id"]));
|
||||
}
|
||||
|
||||
DB::insertRow( "pl_registerlock", array("ip"=>$_SERVER['REMOTE_ADDR'],"created"=>date('Y-m-d H:i:s')));
|
||||
|
||||
if( Config::$vbbIntegration['enabled'] ) {
|
||||
global $vbulletin;
|
||||
$forum = new ForumOps($vbulletin);
|
||||
$user['name'] = $_POST['name'];
|
||||
$user['pass'] = $_POST['pass'];
|
||||
$user['email'] = $_POST['email'];
|
||||
echo $forum->register_newuser($user, false);
|
||||
}
|
||||
|
||||
$mail = file_get_contents( Config::$templates.'registrationmail.txt' );
|
||||
preg_match( '/From: (?<from>.*?)\r?\nSubject: (?<subject>.*?)\r?\n\r?\n(?<text>.*)/sim', $mail, $mail );
|
||||
$mail['text'] = str_replace( '%validationString%', $this->validationString, $mail['text'] );
|
||||
$mail['text'] = str_replace( '%siteName%', Config::$siteName, $mail['text'] );
|
||||
$mail['text'] = str_replace( '%frontendPath%', Config::$frontendPath, $mail['text'] );
|
||||
$mail['text'] = str_replace( '%userName%', $_POST['name'], $mail['text'] );
|
||||
|
||||
$mail['subject'] = str_replace( '%siteName%', Config::$siteName, $mail['subject'] );
|
||||
$mail['subject'] = str_replace( '%userName%', $_POST['name'], $mail['subject'] );
|
||||
|
||||
//mail( $_POST['email'], $mail['subject'], $mail['text'], 'FROM: '.$mail['from'] );
|
||||
mail($_POST['email'],$mail['subject'],$mail['text'],"FROM:".$mail['from']);
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
+601
@@ -0,0 +1,601 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
An object of this class represents a user on the site. All user
|
||||
related tasks (registration, login, profile etc.) are handled here.
|
||||
|
||||
A user object is created and attempted to login on each page load.
|
||||
*/
|
||||
|
||||
require_once( 'lib/config.php' );
|
||||
require_once( 'lib/db.php' );
|
||||
|
||||
class User {
|
||||
public $name = '';
|
||||
public $id = 0;
|
||||
public $validationString = '';
|
||||
public $admin = 0;
|
||||
public $website = 0;
|
||||
public $color = "0";
|
||||
public $stylecolor = "black";
|
||||
public $avatar = "data/avatars/default.png";
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
public function validate( $id ) {
|
||||
$u = DB::getRow(
|
||||
'SELECT id, name, admin, website, color, style, avatar FROM '.TABLE_USERS.' WHERE valid = 0 AND remember = :1',
|
||||
$id
|
||||
);
|
||||
$reg = DB::getRow("SELECT * FROM pl_settings");
|
||||
if ($reg["register"] != 1){
|
||||
return false;
|
||||
}
|
||||
if( empty($u) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
DB::updateRow( TABLE_USERS, array('id' => $u['id']), array( 'valid' => 0) );
|
||||
|
||||
session_name( Config::$sessionCookie );
|
||||
session_start();
|
||||
$_SESSION['id'] = $this->id = $u['id'];
|
||||
$_SESSION['name'] = $this->name = $u['name'];
|
||||
$_SESSION['admin'] = $this->admin = $u['admin'];
|
||||
$_SESSION['website'] = $this->website = $u['website'];
|
||||
$_SESSION['color'] = $this->color = $u['color'];
|
||||
$_SESSION['stylecolor'] = $this->stylecolor = $u['style'];
|
||||
$_SESSION['avatar'] = $this->avatar = $u['avatar'];
|
||||
|
||||
setcookie( Config::$rememberCookie, $id, time() + 3600 * 24 * 365, Config::$absolutePath );
|
||||
|
||||
if( Config::$vbbIntegration['enabled'] ) {
|
||||
global $vbulletin;
|
||||
$forum = new ForumOps($vbulletin);
|
||||
$forum->login(array('username' => $u['name']));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isSpamLocked() {
|
||||
// delete all ips older than IP_LOCK_TIME
|
||||
DB::query( 'DELETE FROM '.TABLE_UPLOADLOCK.' WHERE ts < :1', time() - Config::$uploadLockTime );
|
||||
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
$r = DB::getRow( 'SELECT COUNT(*) AS c FROM '.TABLE_UPLOADLOCK.'
|
||||
WHERE ip = :1',
|
||||
$ip
|
||||
);
|
||||
|
||||
if( $r['c'] > Config::$maxNumUploads ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function isSpamer() {
|
||||
|
||||
|
||||
$r = DB::getRow( 'SELECT logged FROM pl_images
|
||||
WHERE user = :1 order by logged desc',
|
||||
$this->id
|
||||
);
|
||||
$time = strtotime($r["logged"]);
|
||||
|
||||
if( (time() - (integer)$time) < 10 ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function isSpamming() {
|
||||
$block = DB::getRow("SELECT spamblocked,time FROM pl_users WHERE id=:1",$this->id);
|
||||
if ( (int)$block["spamblocked"] == 1)
|
||||
{
|
||||
if ((int)$block["time"] != 0){
|
||||
$now = time();
|
||||
$then = (int)$block["time"];
|
||||
if ($now > $then) {
|
||||
DB::updateRow("pl_users",array("id" => $this->id),array("time" => 0,"spamblocked" => 0));
|
||||
return false;
|
||||
}else{
|
||||
return $block["time"];
|
||||
exit();
|
||||
}
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$count = DB::getRow( 'SELECT COUNT(*) as c FROM pl_images
|
||||
WHERE user = :1',
|
||||
$this->id
|
||||
);
|
||||
|
||||
if ( $count["c"] >= 3){
|
||||
|
||||
$r = DB::query( 'SELECT id,image,keyword,logged FROM pl_images
|
||||
WHERE user = :1 LIMIT '.((integer)$count["c"]-3).',2',
|
||||
$this->id
|
||||
);
|
||||
|
||||
|
||||
$r0 = DB::getRow( 'SELECT image,keyword,logged FROM pl_images
|
||||
WHERE user = :1 LIMIT '.((integer)$count["c"]-1).',1',
|
||||
$this->id
|
||||
);
|
||||
|
||||
require_once("img_class.php");
|
||||
$ban =0;
|
||||
foreach ($r as $checkable) {
|
||||
|
||||
|
||||
|
||||
if ((strtotime($r0["logged"]) - strtotime($checkable["logged"])) < 60){
|
||||
|
||||
|
||||
|
||||
$splitter = split("/",$checkable["keyword"]);
|
||||
$file2 = $splitter[0]."/".$splitter[1]."/".$checkable["image"];
|
||||
$splitter = split("/",$r0["keyword"]);
|
||||
$file1 = $splitter[0]."/".$splitter[1]."/".$r0["image"];
|
||||
|
||||
$diff = new imagediff("data/images/".$file2, "data/images/".$file1);
|
||||
$dif = $diff->diff();
|
||||
|
||||
if ($dif > 0.92){
|
||||
$ban += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($ban >= 2){
|
||||
foreach ($r as $checkable) {
|
||||
DB::query("DELETE FROM pl_images WHERE id=:1",$checkable["id"]);
|
||||
}
|
||||
DB::updateRow("pl_users",array("id" => $this->id),array("spamblocked" => 1,"spam_reason"=>"Imagespam","time" => time() + (7 * 24 * 60 * 60)));
|
||||
return true;
|
||||
}else{
|
||||
return false;}
|
||||
}else{ return false;}
|
||||
}
|
||||
|
||||
public function logUpload() {
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
DB::insertRow( TABLE_UPLOADLOCK, array('ip' => $ip, 'ts' => time(),'user' => $this->id) );
|
||||
}
|
||||
|
||||
public function login() {
|
||||
|
||||
// attempt to login via post, session or remeber cookie
|
||||
|
||||
|
||||
|
||||
session_name( Config::$sessionCookie );
|
||||
|
||||
if( isset($_POST['login']) ) { // post login
|
||||
|
||||
|
||||
$u = DB::getRow(
|
||||
'SELECT id, name, admin, website, color, style,avatar FROM '.TABLE_USERS.' WHERE name = :1 AND pass = :2 and valid = 1',
|
||||
$_POST['name'], md5($_POST['pass'])
|
||||
);
|
||||
$banstate = DB::getRow("SELECT * FROM pl_banned WHERE id=:1",$u['id']);
|
||||
if ($banstate){
|
||||
return "ban/".$banstate["reason"];
|
||||
}
|
||||
|
||||
if( !empty($u) ) {
|
||||
$c = DB::getRow('SELECT ip, created, COUNT(*) as c from pl_registerlock WHERE ip=:1 GROUP BY ip',$_SERVER['REMOTE_ADDR']);
|
||||
if ((int)$c["c"] == 0){
|
||||
DB::insertRow( "pl_registerlock", array("ip"=>$_SERVER['REMOTE_ADDR'],"created"=>date('Y-m-d H:i:s')));}else{
|
||||
DB::query("DELETE FROM pl_registerlock WHERE ip=:1",$_SERVER['REMOTE_ADDR']);
|
||||
DB::insertRow("pl_registerlock",array('ip'=>$_SERVER['REMOTE_ADDR'],'created'=>date('Y-m-d H:i:s')));
|
||||
}
|
||||
|
||||
session_start();
|
||||
$_SESSION['id'] = $this->id = $u['id'];
|
||||
$_SESSION['name'] = $this->name = $u['name'];
|
||||
$_SESSION['admin'] = $this->admin = $u['admin'];
|
||||
$_SESSION['website'] = $this->website = $u['website'];
|
||||
$_SESSION['color'] = $this->color = $u['color'];
|
||||
$_SESSION['stylecolor'] = $this->stylecolor = $u['style'];
|
||||
$_SESSION['avatar'] = $this->avatar = $u['avatar'];
|
||||
|
||||
if( !empty($_POST['remember']) ) {
|
||||
$r = md5(uniqid(rand()));
|
||||
DB::updateRow( TABLE_USERS, array('id' => $this->id), array('remember' => $r ) );
|
||||
setcookie( Config::$rememberCookie, $r, time() + 3600 * 24 * 365, Config::$absolutePath );
|
||||
}
|
||||
|
||||
if( Config::$vbbIntegration['enabled'] ) {
|
||||
global $vbulletin;
|
||||
$forum = new ForumOps($vbulletin);
|
||||
$forum->login(array('username' => $u['name']));
|
||||
}
|
||||
}else{return "wronglogin";}
|
||||
|
||||
}
|
||||
|
||||
else if( !empty($_COOKIE[Config::$sessionCookie]) ) { // session running
|
||||
session_start();
|
||||
$c = DB::getRow('SELECT ip, created, COUNT(*) as c from pl_registerlock WHERE ip=:1 GROUP BY ip',$_SERVER['REMOTE_ADDR']);
|
||||
if ((int)$c["c"] == 0){
|
||||
DB::insertRow( "pl_registerlock", array("ip"=>$_SERVER['REMOTE_ADDR'],"created"=>date('Y-m-d H:i:s')));}else{
|
||||
DB::query("DELETE FROM pl_registerlock WHERE ip=:1",$_SERVER['REMOTE_ADDR']);
|
||||
DB::insertRow("pl_registerlock",array('ip'=>$_SERVER['REMOTE_ADDR'],'created'=>date('Y-m-d H:i:s')));
|
||||
}
|
||||
if( empty($_SESSION['id']) ) {
|
||||
setcookie(Config::$sessionCookie, false, time() - 3600, Config::$absolutePath );
|
||||
} else {
|
||||
$this->id = $_SESSION['id'];
|
||||
$this->name = $_SESSION['name'];
|
||||
$this->admin = $_SESSION['admin'];
|
||||
$this->website = $_SESSION['website'];
|
||||
$this->color = $u['color'];
|
||||
$this->stylecolor = $u['stylecolor'];
|
||||
$this->avatar = $u['avatar'];
|
||||
|
||||
|
||||
}
|
||||
if (DB::getRow("SELECT id FROM pl_banned WHERE id=:1",$this->id)){
|
||||
$this->logout();
|
||||
return "banned";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
else if( !empty($_COOKIE[Config::$rememberCookie]) ) { // remember cookie found
|
||||
$u = DB::getRow(
|
||||
'SELECT id, name, admin, website, style, color, avatar FROM '.TABLE_USERS.' WHERE remember = :1',
|
||||
$_COOKIE[Config::$rememberCookie]
|
||||
);
|
||||
|
||||
if( !empty($u) ) {
|
||||
|
||||
session_start();
|
||||
$_SESSION['id'] = $this->id = $u['id'];
|
||||
$_SESSION['name'] = $this->name = $u['name'];
|
||||
$_SESSION['admin'] = $this->admin = $u['admin'];
|
||||
$_SESSION['website'] = $this->website = $u['website'];
|
||||
$_SESSION['color'] = $this->color = $u['color'];
|
||||
$_SESSION['stylecolor'] = $this->stylecolor = $u['style'];
|
||||
$_SESSION['avatar'] = $this->avatar = $u['avatar'];
|
||||
// refresh for another year
|
||||
setcookie( Config::$rememberCookie, $_COOKIE[Config::$rememberCookie], time() + 3600 * 24 * 365, Config::$absolutePath );
|
||||
|
||||
|
||||
$c = DB::getRow('SELECT ip, created, COUNT(*) as c from pl_registerlock WHERE ip=:1 GROUP BY ip',$_SERVER['REMOTE_ADDR']);
|
||||
if ((int)$c["c"] == 0){
|
||||
DB::insertRow( "pl_registerlock", array("ip"=>$_SERVER['REMOTE_ADDR'],"created"=>date('Y-m-d H:i:s')));}else{
|
||||
DB::query("DELETE FROM pl_registerlock WHERE ip=:1",$_SERVER['REMOTE_ADDR']);
|
||||
DB::insertRow("pl_registerlock",array('ip'=>$_SERVER['REMOTE_ADDR'],'created'=>date('Y-m-d H:i:s')));
|
||||
}
|
||||
|
||||
if (DB::getRow("SELECT id FROM pl_banned WHERE id=:1",$u['id'])){
|
||||
$this->logout();
|
||||
return "banned";
|
||||
}
|
||||
if( Config::$vbbIntegration['enabled'] ) {
|
||||
global $vbulletin;
|
||||
$forum = new ForumOps($vbulletin);
|
||||
$forum->login(array('username' => $u['name']));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function profile( $localFile, &$messages ) {
|
||||
$upd = array( 'website' => $_POST['website'] );
|
||||
|
||||
$_SESSION['website'] = $_POST['website'];
|
||||
|
||||
if( Config::$vbbIntegration['enabled'] ) {
|
||||
global $vbulletin;
|
||||
$forum = new ForumOps($vbulletin);
|
||||
}
|
||||
|
||||
$p = trim($_POST['cpass']);
|
||||
if( !empty( $p ) ) {
|
||||
if( strlen($_POST['cpass']) < 6 ) {
|
||||
$messages['passToShort'] = true;
|
||||
}
|
||||
else if( $_POST['cpass'] != $_POST['cpass2'] ) {
|
||||
$messages['passNotEqual'] = true;
|
||||
}
|
||||
else {
|
||||
$upd['pass'] = md5($_POST['cpass2']);
|
||||
if( Config::$vbbIntegration['enabled'] ) {
|
||||
$forum->set_pass( $_SESSION['name'], $_POST['cpass2']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !empty( $localFile ) ) {
|
||||
require_once( 'lib/images.php' );
|
||||
|
||||
list( $imgWidth, $imgHeight, $imgtype ) = getimagesize($localFile);
|
||||
|
||||
if ( $imgWidth == 64 && $imgHeight == 64 && $imgtype == IMAGETYPE_GIF){
|
||||
$name = Config::$images['avatarsPath'].uniqid().'.gif';
|
||||
if (!move_uploaded_file($localFile,$name)){
|
||||
$messages['avatarFailed'] = true;
|
||||
$upd['avatar'] = Config::$images['avatarsPath']."default.png";
|
||||
}else{
|
||||
$upd['avatar'] = $name;
|
||||
}
|
||||
}else{
|
||||
$name = Config::$images['avatarsPath'].uniqid().'.jpg';
|
||||
|
||||
if( Image::createThumb( $localFile, $name, 64,64 ) ) {
|
||||
$upd['avatar'] = $name;
|
||||
} else {
|
||||
$messages['avatarFailed'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($_POST['color'])){
|
||||
if(preg_match('/^[a-f0-9]{6}$/i', $_POST['color'])){
|
||||
if ( strtolower($_POST['color']) != "ffffff"){
|
||||
$upd['color'] = $_POST['color'];
|
||||
}else{
|
||||
$upd['color'] = "0";
|
||||
}
|
||||
}else{
|
||||
$messages['colorFailed'] = true;
|
||||
}
|
||||
}
|
||||
//--------------------------------------------------------------------blockuser
|
||||
if(!empty($_POST['blockuser'])){
|
||||
if(preg_match('/^\w{2,20}$/', $_POST['blockuser'])){
|
||||
$blockedusers = array();
|
||||
$blockedusers = DB::getRow("SELECT id, users FROM pl_blocked WHERE id=:1",$this->id);
|
||||
|
||||
if(!empty($blockedusers)){
|
||||
$blockedusers = unserialize($blockedusers['users']);
|
||||
if (in_array(strtolower ($_POST['blockuser']),$blockedusers)){
|
||||
$messages['blockAlready'] = true;
|
||||
}else{
|
||||
if(DB::query('SELECT * FROM pl_users WHERE name=:1', strtolower ($_POST['blockuser']))){
|
||||
|
||||
array_push($blockedusers,$_POST['blockuser']);
|
||||
if(DB::query('UPDATE pl_blocked SET users=:1 WHERE id=:2', serialize($blockedusers),$this->id)){
|
||||
$messages['blocked'] = true;
|
||||
}else{
|
||||
$messages['blockFailed'] = true;
|
||||
}
|
||||
}else{
|
||||
$messages['userFailed'] = true;
|
||||
}
|
||||
|
||||
}
|
||||
}else{
|
||||
if(DB::query('SELECT * FROM pl_users WHERE name=:1', $_POST['blockuser'])){
|
||||
$newarray = array();
|
||||
array_push($newarray,strtolower ($_POST['blockuser']));
|
||||
|
||||
if(DB::query("INSERT INTO pl_blocked (id,users) VALUES (:1,:2)",$this->id,serialize($newarray))){
|
||||
$messages['blocked'] = true;
|
||||
}else{
|
||||
$messages['blockFailed'] = true;
|
||||
}
|
||||
|
||||
}else{
|
||||
$messages['userFailed'] = true;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$messages['blockFailed'] = true;
|
||||
}
|
||||
|
||||
}
|
||||
//--------------------------------------------------------------------UNblockuser
|
||||
function remove_item_by_value($array, $val = '', $preserve_keys = true) {
|
||||
if (count($array) == 1) return false;
|
||||
if (empty($array) || !is_array($array)) return false;
|
||||
if (!in_array($val, $array)) return $array;
|
||||
|
||||
foreach($array as $key => $value) {
|
||||
if ($value == $val) unset($array[$key]);
|
||||
}
|
||||
|
||||
return ($preserve_keys === true) ? $array : array_values($array);
|
||||
}
|
||||
//--------------------------------------------------------------------UNblockuser
|
||||
if(!empty($_POST['unblockuser'])){
|
||||
if ($_POST['unblockuser'] != "select"){
|
||||
if(preg_match('/^\w{2,20}$/', $_POST['unblockuser'])){
|
||||
if(DB::query('SELECT * FROM pl_users WHERE name=:1', $_POST['unblockuser'])){
|
||||
$blockedusers = array();
|
||||
$blockedusers = DB::getRow("SELECT id, users FROM pl_blocked WHERE id=:1",$this->id);
|
||||
if(!empty($blockedusers)){
|
||||
$blockedusers = unserialize($blockedusers['users']);
|
||||
if (in_array($_POST['unblockuser'],$blockedusers)){
|
||||
$blockedusers = remove_item_by_value($blockedusers,$_POST['unblockuser']);
|
||||
if ($blockedusers){
|
||||
DB::query('UPDATE pl_blocked SET users=:1 WHERE id=:2', serialize($blockedusers),$this->id);
|
||||
$messages['unblocked'] = true;
|
||||
}else{
|
||||
DB::query('DELETE FROM pl_blocked WHERE id=:1',$this->id);
|
||||
$messages['unblocked'] = true;
|
||||
}
|
||||
}else{$messages['notBlocked'] = true;}
|
||||
}else{$messages['unblockFailed'] = true;}
|
||||
}else{$messages['userFailed'] = true;}
|
||||
}else{$messages['unblockFailed'] = true;}
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------STYLE
|
||||
|
||||
if(isset($_POST['stylecolor'])) {
|
||||
if($_POST['stylecolor'] == 'white') {
|
||||
|
||||
$upd['style'] = $_POST['stylecolor'];
|
||||
|
||||
} elseif($_POST['stylecolor'] == 'black') {
|
||||
$upd['style'] = $_POST['stylecolor'];
|
||||
} else{
|
||||
$upd['style'] = $_POST['black'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if( empty($this->email) &&
|
||||
preg_match('/^[\.\w\-]{1,}@[\.\w\-]{2,}\.[\w]{2,}$/', $_POST['email'])
|
||||
) {
|
||||
if( Config::$vbbIntegration['enabled'] ) {
|
||||
$forum->set_email( $_SESSION['name'], $_POST['email']);
|
||||
}
|
||||
$upd['email'] = $_POST['email'];
|
||||
}
|
||||
|
||||
DB::updateRow( TABLE_USERS, array( 'id' => $this->id ), $upd );
|
||||
}
|
||||
|
||||
public function loadEmail() {
|
||||
$tmp = DB::getRow(
|
||||
'SELECT email,color,style,avatar FROM '.TABLE_USERS.' WHERE id = :1',
|
||||
$this->id
|
||||
);
|
||||
$this->email = $tmp['email'];
|
||||
$this->color = $tmp['color'];
|
||||
$this->stylecolor = $tmp['style'];
|
||||
$this->avatar = $u['avatar'];
|
||||
}
|
||||
|
||||
public function logout() {
|
||||
session_unset();
|
||||
session_destroy();
|
||||
$_SESSION = array();
|
||||
setcookie( Config::$rememberCookie, false, time() - 3600, Config::$absolutePath );
|
||||
setcookie( Config::$sessionCookie, false, time() - 3600, Config::$absolutePath );
|
||||
|
||||
if( Config::$vbbIntegration['enabled'] ) {
|
||||
global $vbulletin;
|
||||
$forum = new ForumOps($vbulletin);
|
||||
$forum->logout();
|
||||
}
|
||||
}
|
||||
|
||||
public function increaseScore( $amount ) {
|
||||
DB::query(
|
||||
'UPDATE '.TABLE_USERS.' SET score = score + :1 WHERE id = :2',
|
||||
intval( $amount ),
|
||||
$this->id
|
||||
);
|
||||
}
|
||||
|
||||
public function register( &$messages,$inviteC=false ) {
|
||||
|
||||
DB::query( 'DELETE FROM '.TABLE_USERS.' WHERE valid = 0 AND registered < NOW() - INTERVAL 30 MINUTE' );
|
||||
$iplocks = DB::getRow("DELETE FROM pl_registerlock WHERE created < (NOW() - INTERVAL 1440 MINUTE)");
|
||||
|
||||
|
||||
$reg = DB::getRow("SELECT * FROM pl_settings");
|
||||
$doubleacc = DB::getRow("SELECT COUNT(*) as c FROM pl_registerlock WHERE ip=:1",$_SERVER['REMOTE_ADDR']);
|
||||
|
||||
if($inviteC == false){
|
||||
if ($reg["register"] != 1 || $doubleacc["c"] > 0){
|
||||
$messages['registerClosed'] = true;
|
||||
}
|
||||
}else{
|
||||
if ($doubleacc["c"] > 0){
|
||||
DB::updateRow("pl_invites",array("code"=>$inviteC),array("used"=>1,"usedby"=>1));
|
||||
$inviteC = false;
|
||||
$messages['registerClosed'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( !preg_match('/^\w{2,20}$/', $_POST['name']) ) {
|
||||
$messages['nameInvalid'] = true;
|
||||
} else {
|
||||
$u = DB::getRow( 'SELECT * FROM '.TABLE_USERS.' WHERE name = :1', $_POST['name'] );
|
||||
if( !empty($u) ) {
|
||||
$messages['nameInUse'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
if( strlen($_POST['pass']) < 6 ) {
|
||||
$messages['passToShort'] = true;
|
||||
}
|
||||
else if( $_POST['pass'] != $_POST['pass2'] ) {
|
||||
$messages['passNotEqual'] = true;
|
||||
}
|
||||
|
||||
if( !preg_match( '/^[\.\w\-]{1,}@[\.\w\-]{2,}\.[\w]{2,}$/', $_POST['email'] ) ) {
|
||||
$messages['wrongEmail'] = true;
|
||||
} else {
|
||||
$u = DB::getRow( 'SELECT * FROM '.TABLE_USERS.' WHERE email = :1', $_POST['email'] );
|
||||
if( !empty($u) ) {
|
||||
$messages['emailInUse'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( !empty($messages) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$this->validationString = md5(uniqid(rand()));
|
||||
|
||||
DB::insertRow( TABLE_USERS, array(
|
||||
'registered' => date('Y-m-d H:i:s'),
|
||||
'name' => $_POST['name'],
|
||||
'pass' => md5($_POST['pass']),
|
||||
'valid' => 1,
|
||||
'score' => 0,
|
||||
'images' => 0,
|
||||
'website' => '',
|
||||
'avatar' => Config::$images['avatarsPath'].'default.png',
|
||||
'remember' => $this->validationString,
|
||||
'admin' => 0,
|
||||
'email' => $_POST['email'],
|
||||
'color' => '0',
|
||||
'style' => 'black',
|
||||
'invite' => $inviteC
|
||||
));
|
||||
|
||||
if($inviteC != false){
|
||||
$lastid= DB::getRow("SELECT LAST_INSERT_ID() as id");
|
||||
DB::updateRow("pl_invites",array("code"=>$inviteC),array("used"=>1,"usedby"=>$lastid["id"]));
|
||||
}
|
||||
|
||||
DB::insertRow( "pl_registerlock", array("ip"=>$_SERVER['REMOTE_ADDR'],"created"=>date('Y-m-d H:i:s')));
|
||||
|
||||
if( Config::$vbbIntegration['enabled'] ) {
|
||||
global $vbulletin;
|
||||
$forum = new ForumOps($vbulletin);
|
||||
$user['name'] = $_POST['name'];
|
||||
$user['pass'] = $_POST['pass'];
|
||||
$user['email'] = $_POST['email'];
|
||||
echo $forum->register_newuser($user, false);
|
||||
}
|
||||
|
||||
$mail = file_get_contents( Config::$templates.'registrationmail.txt' );
|
||||
preg_match( '/From: (?<from>.*?)\r?\nSubject: (?<subject>.*?)\r?\n\r?\n(?<text>.*)/sim', $mail, $mail );
|
||||
$mail['text'] = str_replace( '%validationString%', $this->validationString, $mail['text'] );
|
||||
$mail['text'] = str_replace( '%siteName%', Config::$siteName, $mail['text'] );
|
||||
$mail['text'] = str_replace( '%frontendPath%', Config::$frontendPath, $mail['text'] );
|
||||
$mail['text'] = str_replace( '%userName%', $_POST['name'], $mail['text'] );
|
||||
|
||||
$mail['subject'] = str_replace( '%siteName%', Config::$siteName, $mail['subject'] );
|
||||
$mail['subject'] = str_replace( '%userName%', $_POST['name'], $mail['subject'] );
|
||||
|
||||
//mail( $_POST['email'], $mail['subject'], $mail['text'], 'FROM: '.$mail['from'] );
|
||||
mail($_POST['email'],$mail['subject'],$mail['text'],"FROM:".$mail['from']);
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
Reference in New Issue
Block a user