Ejemplo n.º 1
0
	public function set_connection($base) {
		if ($this->mode != $base && def::db($base.'_db')) {
			mysql_select_db(def::db($base.'_db'), $this->connection);
			mysql_query("SET NAMES 'UTF8'");
			$this->mode = $base;
		}
	}
Ejemplo n.º 2
0
 protected function author($data)
 {
     $worker = new Transform_Meta();
     $author = $worker->parse($data['author'], def::user('author'));
     $author = $worker->author($author);
     $this->model['author'] = $author;
 }
Ejemplo n.º 3
0
 protected function process()
 {
     $torrent = new Transform_Torrent($this->file);
     if (!$torrent->is_valid()) {
         throw new Error_Upload(Error_Upload::NOT_A_TORRENT);
     }
     $torrent->delete('announce-list');
     $torrent->set('announce', def::tracker('announce'));
     $data = $torrent->encode();
     $hash = $torrent->get_hash();
     $post_id = Database::get_field('post_torrent', 'post_id', 'hash = ?', $hash);
     if ($post_id) {
         throw new Error_Upload(Error_Upload::ALREADY_EXISTS);
     }
     $filename = pathinfo(urldecode($this->name), PATHINFO_FILENAME);
     $filename = Transform_File::make_name($filename);
     $filename = substr($filename, 0, 200) . '.torrent';
     if (!is_dir(FILES . SL . 'torrent' . SL . $hash)) {
         mkdir(FILES . SL . 'torrent' . SL . $hash, 0755);
     }
     $newfile = FILES . SL . 'torrent' . SL . $hash . SL . $filename;
     file_put_contents($newfile, $data);
     $size = $torrent->get_size();
     $size = Transform_File::weight_short($size);
     $return_data = '<input size="24%" type="text" name="torrent[0][name]" value="Скачать" />:' . "\n" . '<input readonly size="24%" type="text" name="torrent[0][file]" value="' . $filename . '" />' . "\n" . '<input type="hidden" name="torrent[0][hash]" value="' . $hash . '" />' . "\n" . '<input readonly size="4%" type="text" name="torrent[0][size]" value="' . $size . '" />' . "\n" . '<input type="submit" class="disabled sign remove_link" rel="torrent" value="-" />';
     $this->set(array('success' => true, 'data' => $return_data, 'file' => $filename, 'hash' => $hash, 'name' => 'Скачать', 'size' => $size));
 }
Ejemplo n.º 4
0
 public function insert()
 {
     $this->set('pretty_date', Transform_Text::rudate());
     $this->set('sortdate', ceil(microtime(true) * 1000));
     $this->set('area', def::area(1));
     parent::insert();
     return $this;
 }
Ejemplo n.º 5
0
	function title() {
		$url = query::$url;
		$func = 'title_'.$url[1];
		if (method_exists($this, $func) && $return = $this->$func($url)) {
			return def::site('short_name') . ' ' . $return;
		}

		return def::site('name');
	}
Ejemplo n.º 6
0
 public function insert()
 {
     $this->set('pretty_date', Transform_Text::rudate());
     $this->set('sortdate', ceil(microtime(true) * 1000));
     $this->set('area', def::area(0));
     parent::insert();
     Database::update('post', array('update_count' => '++'), $this->get('post_id'));
     $this->add_children();
     return $this;
 }
Ejemplo n.º 7
0
 public function main()
 {
     $post = $this->correct_main_data($this->reader->get_data());
     if (!$post['title'] || !$post['link'] && !$post['torrent']) {
         $this->writer->set_message('Не все обязательные поля заполнены.')->set_error(Error_Create::MISSING_INPUT);
         return;
     }
     if ($post['author'] != def::user('name') && $post['author']) {
         $cookie = new dynamic__cookie();
         $cookie->inner_set('user.name', $post['author']);
     }
     $worker = new Transform_Meta();
     $parsed_tags = $worker->parse_array($post['tag']);
     $tags = $worker->add_tags($parsed_tags);
     $category = $worker->category($post['category']);
     $language = $worker->language($post['language']);
     $parsed_author = $worker->parse($post['author'], def::user('author'));
     $author = $worker->author($parsed_author);
     $text = Transform_Text::format($post['text']);
     $links = Transform_Link::parse($post['link']);
     $extras = Transform_Link::parse($post['bonus_link']);
     $images = $post['image'];
     $torrents = $post['torrent'];
     $files = $post['file'];
     $item = new Model_Post();
     $item->set_array(array('title' => $post['title'], 'text' => $text, 'pretty_text' => undo_safety($post['text']), 'author' => $author, 'category' => $category, 'language' => $language, 'tag' => $tags));
     foreach ($images as $image) {
         $image = explode('.', $image);
         $image = new Model_Post_Image(array('file' => $image[0], 'extension' => $image[1]));
         $item->add_image($image);
     }
     foreach ($links as $link) {
         $link = new Model_Post_Link($link);
         $item->add_link($link);
     }
     foreach ($torrents as $torrent) {
         $torrent = new Model_Post_Torrent($torrent);
         $item->add_torrent($torrent);
     }
     foreach ($extras as $extra) {
         $extra = new Model_Post_Extra($extra);
         $item->add_extra($extra);
     }
     foreach ($files as $file) {
         $file = new Model_Post_File($file);
         $item->add_file($file);
     }
     $item->insert();
     // TODO: перемести input__common::transfer в Model_Common
     if (!empty($post['transfer_to'])) {
         input__common::transfer(array('sure' => 1, 'do' => array('post', 'transfer'), 'where' => $post['transfer_to'], 'id' => $item->get_id()));
     }
     $this->writer->set_success()->set_message('Ваша запись успешно добавлена, и доступна по адресу ' . '<a href="/post/' . $item->get_id() . '/">http://4otaku.org/post/' . $item->get_id() . '/</a> или в ' . '<a href="/post/' . def::area(1) . '/">мастерской</a>.')->set_param('id', $item->get_id());
 }
Ejemplo n.º 8
0
 public function execute($function)
 {
     if (is_callable(array($this, $function))) {
         try {
             $this->{$function}();
         } catch (Error_Cron $e) {
             $mail = new mail(def::notify('mail'));
             $mail->text(serialize($e))->send();
         }
     }
 }
Ejemplo n.º 9
0
 protected function get_title()
 {
     $short = def::site('short_name') . ' ';
     if (count($this->data['items']) == 1) {
         $item = reset($this->data['items']);
         if (empty($item['in_batch'])) {
             return $short . $item['title'];
         }
     }
     return def::site('name');
 }
Ejemplo n.º 10
0
 protected static function init_db($name)
 {
     $config = array('server' => def::db('host'), 'login' => def::db('user'), 'password' => def::db('pass'), 'prefix' => '', 'database' => def::db($name . '_db'));
     if (empty($config['database'])) {
         die("Конфиг для базы данных {$name} не найден.");
     }
     $dsn = "mysql:dbname={$config['database']};host={$config['server']}";
     $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8");
     $worker = new PDO($dsn, $config["login"], $config["password"], $options);
     $object = new Database_Instance($worker, $config["prefix"]);
     return $object;
 }
Ejemplo n.º 11
0
 public function main()
 {
     $post = $this->correct_main_data($this->reader->get_data());
     if (!is_array($post['images'])) {
         $this->writer->set_message('Не все обязательные поля заполнены.')->set_error(Error_Create::MISSING_INPUT);
         return;
     }
     if (query::$url[2] == 'pool' && is_numeric(query::$url[3])) {
         $pool = new Model_Art_Pool(query::$url[3]);
         if (!$pool->correct_password($post['password'])) {
             $this->writer->set_message('Неправильный пароль от группы.')->set_error(Error_Create::INCORRECT_INPUT);
             return;
         }
     } else {
         $pool = false;
     }
     $worker = new Transform_Meta();
     $parsed_tags = $worker->parse_array($post['tag']);
     $tags = $worker->add_tags($parsed_tags);
     $category = $worker->category($post['category']);
     $parsed_author = $worker->parse($post['author'], def::user('author'));
     $author = $worker->author($parsed_author);
     $similar = $this->check_similar($post['images']);
     foreach ($post['images'] as $image_key => $image) {
         if (empty($image['tags'])) {
             $local_tags = $tags;
         } else {
             $parsed_tags = $worker->parse_array($image['tags']);
             $local_tags = $worker->add_tags($parsed_tags);
         }
         $art = new Model_Art();
         $art->set_array(array('md5' => $image['md5'], 'thumb' => $image['thumb'], 'extension' => $image['extension'], 'resized' => $image['resized'], 'animated' => (int) $image['animated'], 'author' => $author, 'category' => $category, 'tag' => $local_tags, 'source' => $post['source']));
         $art->insert();
         if (!empty($similar[$image_key])) {
             foreach ($similar[$image_key] as $item) {
                 $art->add_similar($item);
             }
         }
         if (!empty($pool)) {
             $pool->add_art($art);
         }
         // TODO: перемести input__common::transfer в Model_Common
         if (!empty($post['transfer_to'])) {
             input__common::transfer(array('sure' => 1, 'do' => array('art', 'transfer'), 'where' => $post['transfer_to'], 'id' => $art->get_id()));
         }
     }
     $this->writer->set_success();
     if (count($post['images']) > 1) {
         $this->writer->set_message('Ваши изображения успешно добавлены, и доступны в ' . '<a href="/art/' . def::area(1) . '/">очереди на премодерацию</a>.');
     } else {
         $this->writer->set_message('Ваше изображение успешно добавлено, и доступно по адресу ' . '<a href="/art/' . $art->get_id() . '/">http://4otaku.org/art/' . $art->get_id() . '/</a> или в ' . '<a href="/art/' . def::area(1) . '/">очереди на премодерацию</a>.')->set_param('id', $art->get_id());
     }
 }
Ejemplo n.º 12
0
 public function process_actions()
 {
     $redirect = null;
     foreach ($this->actions as $type => $actions) {
         if ($type == 'redirect') {
             $redirect = array_pop($actions);
         }
     }
     if ($redirect !== null) {
         $redirect = 'http://' . def::site('domain') . (empty($redirect) ? $_SERVER["REQUEST_URI"] : $redirect);
         engine::redirect($redirect);
     }
 }
Ejemplo n.º 13
0
 function shutdown_handler()
 {
     $error = error_get_last();
     if ($error && ($error['type'] == E_ERROR || $error['type'] == E_PARSE || $error['type'] == E_COMPILE_ERROR)) {
         if (strpos($error['message'], 'Allowed memory size') === 0) {
             ob_end_clean();
             $mail = new mail(def::notify('mail'));
             $mail->text(serialize(query::$url) . serialize($error))->send();
         } else {
             ob_end_clean();
             $mail = new mail(def::notify('mail'));
             $mail->text(serialize(query::$url) . serialize($error))->send();
         }
     }
 }
Ejemplo n.º 14
0
	function edit_personal_menu () {
		$id = (int) query::$get['id'];

		$return = Database::get_full_row('head_menu_user', $id);

		if (!empty($return)) {
			$return['count'] = Database::get_count('head_menu_user',
				'cookie = ?',
				query::$cookie
			);

			if ($return['url']{0} == '/') {
				$return['url'] = 'http://'.def::site('domain').$return['url'];
			}
		}

		return $return;
	}
Ejemplo n.º 15
0
 protected function check_resize($target)
 {
     $resized = false;
     $this->sizes = $this->worker->get_image_width() . 'x' . $this->worker->get_image_height();
     $resize_width = def::art('resizewidth') * def::art('resizestep');
     if ($this->worker->get_image_width() > $resize_width || $this->info[0] > $resize_width) {
         if ($this->scale(def::art('resizewidth'), $target, 95, false)) {
             $resized = $this->sizes;
         }
     } elseif ($sizefile > def::art('resizeweight')) {
         if ($this->scale(false, $target, 95, false)) {
             $resized = $this->sizes;
         }
     }
     if (!empty($resized)) {
         $resized .= 'px; ' . Transform_File::weight_short($this->size);
     }
     return $resized;
 }
Ejemplo n.º 16
0
 public function main()
 {
     $post = $this->correct_main_data($this->reader->get_data());
     if (!$post['title']) {
         $this->writer->set_message('Вы забыли указать заголовок для видео.')->set_error(Error_Create::MISSING_INPUT);
         return;
     }
     if (!$post['link']) {
         $this->writer->set_message('Вы не предоставили ссылки, или же ссылка почему-то битая.')->set_error(Error_Create::MISSING_INPUT);
         return;
     }
     $test = new Transform_Video($post['link']);
     if (!$test->enable_nico()->get_html()) {
         $this->writer->set_message('Ссылка не ведет на видео, либо этот видеохостинг не поддерживается')->set_error(Error_Create::INCORRECT_INPUT);
         return;
     }
     $already_have = Database::get_field('video', 'id', 'link = ?', $post['link']);
     if ($already_have) {
         $error = 'Это видео уже у нас есть, оно находится по адресу <a href="/video/' . $already_have . '/">http://4otaku.org/video/' . $already_have . '/</a>.';
         $this->writer->set_message($error)->set_error(Error_Create::ALREADY_EXISTS);
         return;
     }
     if ($post['author'] != def::user('name') && $post['author']) {
         $cookie = new dynamic__cookie();
         $cookie->inner_set('user.name', $post['author']);
     }
     $worker = new Transform_Meta();
     $parsed_tags = $worker->parse_array($post['tag']);
     $tags = $worker->add_tags($parsed_tags);
     $category = $worker->category($post['category']);
     $parsed_author = $worker->parse($post['author'], def::user('author'));
     $author = $worker->author($parsed_author);
     $text = Transform_Text::format($post['text']);
     $item = new Model_Video();
     $item->set_array(array('title' => $post['title'], 'link' => $post['link'], 'text' => $text, 'pretty_text' => undo_safety($post['text']), 'author' => $author, 'category' => $category, 'tag' => $tags));
     $item->insert();
     // TODO: перемести input__common::transfer в Model_Common
     if (!empty($post['transfer_to'])) {
         input__common::transfer(array('sure' => 1, 'do' => array('video', 'transfer'), 'where' => $post['transfer_to'], 'id' => $item->get_id()));
     }
     $this->writer->set_success()->set_message('Ваша видео успешно добавлено, и доступно по адресу ' . '<a href="/video/' . $item->get_id() . '/">http://4otaku.org/video/' . $item->get_id() . '/</a> или в ' . '<a href="/video/' . def::area(1) . '/">очереди на премодерацию</a>.')->set_param('id', $item->get_id());
 }
Ejemplo n.º 17
0
 protected function process()
 {
     $md5 = md5_file($this->file);
     $extension = strtolower(pathinfo($this->name, PATHINFO_EXTENSION));
     $newname = $md5 . '.' . $extension;
     $newfile = IMAGES . SL . 'board' . SL . 'full' . SL . $newname;
     chmod($this->file, 0755);
     if (!file_exists($newfile)) {
         if (!move_uploaded_file($this->file, $newfile)) {
             file_put_contents($newfile, file_get_contents($this->file));
         }
     }
     $thumb = md5(microtime(true));
     $newthumb = IMAGES . SL . 'board' . SL . 'thumbs' . SL . $thumb . '.jpg';
     $this->worker = Transform_Image::get_worker($newfile);
     $width = $this->worker->get_image_width();
     $height = $this->worker->get_image_height();
     $this->scale(array(def::board('thumbwidth'), def::board('thumbheight')), $newthumb);
     $this->set(array('success' => true, 'image' => SITE_DIR . '/images/board/thumbs/' . $thumb . '.jpg', 'data' => $newname . '#' . $thumb . '.jpg#' . $this->size . '#' . $width . 'x' . $height, 'full' => $newname, 'thumb' => $thumb, 'size' => $this->size, 'width' => $width, 'height' => $height));
 }
Ejemplo n.º 18
0
 public function main()
 {
     $post = $this->correct_main_data($this->reader->get_data());
     if (!$post['title']) {
         $this->writer->set_message('Вы забыли указать заголовок для новости.');
         return;
     }
     if ($post['author'] != def::user('name') && $post['author']) {
         $cookie = new dynamic__cookie();
         $cookie->inner_set('user.name', $post['author']);
     }
     $worker = new Transform_Meta();
     $category = $worker->category($post['category']);
     $parsed_author = $worker->parse($post['author'], def::user('author'));
     $author = $worker->author($parsed_author);
     $text = Transform_Text::format($post['text']);
     $item = new Model_News();
     $item->set_array(array('title' => $post['title'], 'text' => $text, 'pretty_text' => undo_safety($post['text']), 'image' => $post['image']['image'], 'extension' => $post['image']['extension'], 'author' => $author, 'category' => $category));
     $item->insert();
     $this->writer->set_success()->set_message('Ваша новость успешно добавлена, и доступна по адресу ' . '<a href="/news/' . $item->get_id() . '/">http://4otaku.org/news/' . $item->get_id() . '/</a>.');
 }
Ejemplo n.º 19
0
 public function insert()
 {
     if (!Check::is_hash($this->get('md5')) || !Check::is_hash($this->get('thumb')) || !$this->get('extension') || Database::get_count('art', 'md5 = ?', $this->get('md5'))) {
         return $this;
     }
     if ($this->get('resized') == 1) {
         $this->calculate_resize();
     }
     $this->set('pretty_date', Transform_Text::rudate());
     $this->set('sortdate', ceil(microtime(true) * 1000));
     if (!$this->get('area')) {
         $this->set('area', def::area(1));
     }
     $this->correct_tags();
     parent::insert();
     if (function_exists('puzzle_fill_cvec_from_file') && function_exists('puzzle_compress_cvec')) {
         $imagelink = IMAGES . SL . 'booru' . SL . 'thumbs' . SL . 'large_' . $this->get('thumb') . '.jpg';
         $vector = puzzle_fill_cvec_from_file($imagelink);
         $vector = base64_encode(puzzle_compress_cvec($vector));
         Database::insert('art_similar', array('id' => $this->get_id(), 'vector' => $vector));
     }
     return $this;
 }
Ejemplo n.º 20
0
	function art_tags() {
		global $data; global $url;

		if (in_array($url['area'], def::get('area')) && $url['area'] != 'workshop') {
			$area = $url['area'];
		} else {
			$area = def::get('area',0);
		}
		$prefix = $url['area'].'/';

		$tags = array();
		$page_flag = false;
		if (is_array($data['main']['art']['thumbs'])) {
			$page_flag = true;
			foreach ($data['main']['art']['thumbs'] as $art) {
				if (is_array($art['meta']['tag'])) {
					foreach ($art['meta']['tag'] as $alias => $tag) {
						if (isset($tags[$alias])) {
							$tags[$alias]['count']++;
						} else {
							$tags[$alias] = array('name' => $tag['name'], 'color' => $tag['color'], 'count' => 1, 'description' => $tag['have_description']);
						}
					}
				}
			}
		} elseif (is_array($data['main']['art'][0]['meta']['tag'])) {
			foreach ($data['main']['art'][0]['meta']['tag'] as $alias => $tag) {
				if (isset($tags[$alias])) {
					$tags[$alias]['count']++;
				} else {
					$tags[$alias] = array('name' => $tag['name'], 'color' => $tag['color'], 'count' => 1, 'description' => $tag['have_description']);
				}
			}
		}
		unset($tags['prostavte_tegi'],$tags['tagme'],$tags['deletion_request']);

		if (!empty($tags)) {
			$where = 'where alias="'.implode('" or alias="',array_keys($tags)).'"';
			$global = obj::db()->sql('select alias, art_'.$area.' from tag '.$where,'alias');
			if ($page_flag) {
				foreach ($global as $alias => $global_count) {
					$ret_key = ((int) $tags[$alias]['count'] * (int) $global_count).'.'.rand(0,10000);
					$return[$ret_key] = array('alias' => $alias, 'num' => $global_count) + $tags[$alias];
				}

				krsort($return);
				$return = array_slice($return,0,25);
				shuffle($return);
			} else {
				foreach ($global as $alias => $global_count) {
					$return[$alias] = array('alias' => $alias, 'num' => $global_count) + $tags[$alias];
				}
			}

			foreach ($return as $key => $tag) {
				$return[$key]['alias'] = $prefix.'tag/'.$tag['alias'];
			}

			uasort($return, 'transform__array::meta_sort');
			return $return;
		}
	}
Ejemplo n.º 21
0
echo $image['id'];
?>
/">
					<img align="left" src="<?php 
echo $def['site']['dir'];
?>
/images/board/thumbs/<?php 
echo $image['thumb'];
?>
.jpg">
				</a>
		<? } }		
		if (!empty($thread['content']['flash'])) { 
			foreach ($thread['content']['flash'] as $flash) { ?>
				<a href="http://<?php 
echo def::site('domain');
echo $def['site']['dir'];
?>
/images/board/full/<?php 
echo $flash['full'];
?>
">
					<img align="left" src="<?php 
echo $def['site']['dir'];
?>
/images/flash.png">
				</a>		
		<? } } ?>
		<div class="posttext">
			<?php 
echo $thread['text'];
Ejemplo n.º 22
0
						<? } ?>
					</span>
				</div>
			</span>
		<? } ?>
		<? if ($thread['images_count'] > 0) { ?>
			<span class="link_right">
				<a href="#" rel="Свернуть все" class="board_unfold_all">
					Развернуть все
				</a>
			</span>
		<? } ?>
	<? } ?>
	<? if (
        $thread['cookie'] && query::$cookie === $thread['cookie'] ||
        query::$cookie === def::get('board', 'moderator')
    ) { ?>
		<span class="link_delete">
			 <img src="<?php 
echo $def['site']['dir'];
?>
/images/comment_delete.png" alt="удалить" rel="<?php 
echo $id;
?>
" class="delete_from_board">
		</span>
	<? } ?>
	<span class="author">
		<?php 
echo $thread['name'];
?>
Ejemplo n.º 23
0
<? if ($url['area'] == def::get('area',3) && $url[1] == def::get('type',2)) { ?>
	<div class="mini-shell margin10">
		Графические ресурсы для создания любительских ВН. 
		<a href="http://wiki.4otaku.org/%D0%A1%D0%BE%D0%B7%D0%B4%D0%B0%D0%BD%D0%B8%D0%B5_%D0%BB%D1%8E%D0%B1%D0%B8%D1%82%D0%B5%D0%BB%D1%8C%D1%81%D0%BA%D0%BE%D0%B9_%D0%92%D0%9D">
			Статья про создание
		</a> 
		(в процессе написания).
	</div>
<? } ?>
<?
	$lang['add'] = array(
		$def['type'][0] => 'Добавить материал',
		$def['type'][1] => 'Добавить видео',
		$def['type'][2] => 'Загрузить картинки',
		'order' => 'Оставить заказ (не забудьте прочитать правила)',
		'pool' => 'Добавить новую группу',
		'board' => 'Открыть новый тред',
		'thread' => 'Ответить в тред',
		'soku' => 'Загрузить реплей',
	);
	
	if (is_array($data['top']['board_list'])) {
		$board_list = $data['top']['board_list'];
		include_once(TEMPLATE_DIR.SL.'main'.SL.'board'.SL.'menu.php');
	}
	if ($data['top']['add_bar']) {
		if (!$data['top']['add_bar']['name']) $data['top']['add_bar']['name'] = $data['top']['add_bar']['type'];
		?>
			<div class="addborder">
				<div id="downscroller" rel="<?php 
Ejemplo n.º 24
0
	$redirect = 'http://'.def::site('domain').'/'. (empty($url[3]) ?
		'news/' :
		$url[3].'/'. ($url[4] == 'all' ? '' : $url[4].'/'.$url[5])
	);
	engine::redirect($redirect);
}

if (isset(query::$post['do'])) {
	query::$post['do'] = explode('.', query::$post['do']);
	if (count(query::$post['do']) == 2) {
		$input_class = 'input__'.query::$post['do'][0];
		$input = new $input_class;
		$input_function = query::$post['do'][1];
		$input->$input_function(query::$post);
	}
	$redirect = 'http://'.def::site('domain').(empty($input->redirect) ? $_SERVER["REQUEST_URI"] : $input->redirect);
	engine::redirect($redirect);
} elseif (isset(query::$post['action']) &&
	in_array(query::$post['action'], array('Create', 'Update', 'Delete'))) {

	$class = query::$post['action'] . '_' . ucfirst($url[1]);

	if (class_exists($class)) {

		$worker = new $class();

		$function = empty(query::$post['function']) ?
			'main' : query::$post['function'];

		if ($worker->check_access($function)) {
Ejemplo n.º 25
0
 protected function get_max_size()
 {
     return def::post('picturesize');
 }
Ejemplo n.º 26
0
	protected static function image_encode ($img) {
		$img = $img[0];
		preg_match('/src="([^"]+)"/is',$img,$src);
		$src = $src[1];

		$data = fread(fopen(ROOT_DIR.SL.$src,'r'),filesize(ROOT_DIR.SL.$src));
		$data = chunk_split(base64_encode($data));

		$ext = end(explode('.',$src));

		switch ($ext) {
			case 'jpg':
			case 'jpeg':
				return str_replace($src,'data:image/jpeg;base64,'.$data,$img);
			case 'gif':
				return str_replace($src,'data:image/gif;base64,'.$data,$img);
			case 'png':
				return str_replace($src,'data:image/png;base64,'.$data,$img);
			default:
				return str_replace($src,'http://'.def::site('domain').$src,$img);
		}
	}
Ejemplo n.º 27
0
    include_once ROOT_DIR . SL . 'engine' . SL . 'twig_init.php';
}
if (_TYPE_ != 'cron') {
    list($get, $post) = query::get_globals($_GET, $_POST);
}
include_once ROOT_DIR . SL . 'engine' . SL . 'metafunctions.php';
// Тут мы работаем с сессиями
if (_TYPE_ != 'cron' && _TYPE_ != 'api') {
    // Логично, что у крона или апи сессии нет.
    // Удалим все левые куки, нечего захламлять пространство
    foreach ($_COOKIE as $key => $cook) {
        if ($key != 'settings') {
            setcookie($key, "", time() - 3600);
        }
    }
    $cookie_domain = (def::site('domain') != 'localhost' ? def::site('domain') : '') . SITE_DIR;
    // Хэш. Берем либо из cookie, если валиден, либо генерим новый
    query::$cookie = !empty($_COOKIE['settings']) && $check->hash($_COOKIE['settings']) ? $_COOKIE['settings'] : md5(microtime(true));
    // Пробуем прочитать настройки для хэша
    $sess = Database::get_row('settings', array('data', 'lastchange'), 'cookie = ?', query::$cookie);
    // Проверяем полученные настройки
    if (isset($sess['data']) && isset($sess['lastchange'])) {
        // Настройки есть
        // Обновляем cookie еще на 2 мес у клиента, если она поставлена больше месяца назад
        if (intval($sess['lastchange']) < time() - 3600 * 24 * 30) {
            setcookie('settings', query::$cookie, time() + 3600 * 24 * 60, '/', $cookie_domain);
            // Фиксируем факт обновления в БД
            Database::update('settings', array('lastchange' => time()), 'cookie = ?', query::$cookie);
        }
        // Проверяем валидность настроек и исправляем, если что-то не так
        if (base64_decode($sess['data']) !== false && is_array(unserialize(base64_decode($sess['data'])))) {
Ejemplo n.º 28
0
 protected function get_max_size()
 {
     return def::art('packsize');
 }
Ejemplo n.º 29
0
 protected function get_title()
 {
     $short = def::site('short_name') . ' ';
     if (count($this->data['items']) == 1) {
         $item = reset($this->data['items']);
         if (empty($item['in_batch'])) {
             return $short . $item->get_title();
         }
     }
     if (count($this->meta) > 1) {
         return $short . 'Записи. Просмотр сложной выборки.';
     }
     if (count($this->meta) == 1) {
         $meta = reset($this->meta);
         if (!$meta->is_simple()) {
             return $short . 'Записи. Просмотр сложной выборки.';
         }
         $type = $meta->get_type();
         $alias = $meta->get_meta();
         $name = Database::get_field($type, 'name', 'alias = ?', $alias);
         $meta_name = $meta->get_type_rus();
         return $short . 'Записи. ' . $meta_name . ': ' . $name;
     }
     return def::site('name');
 }
Ejemplo n.º 30
0
	function process_content(&$array) {
		global $url;
		$images_count = 0; $video_count = 0; $flash_count = 0;
		if (!empty($array)) {
			$ids = array_keys($array);
			$content_array = (array) obj::db()->sql('
				SELECT * FROM board_attachment
				WHERE post_id in ('.implode(',',$ids).')
				ORDER BY `order`
			');

			foreach ($array as $key => $item) {
				$array[$key]['content'] = array(
					'image' => array(),
					'flash' => array(),
					'video' => array(),
				);
			}


			foreach ($content_array as $content) {
				$array[$content['post_id']]['content'][$content['type']][] =
					unserialize(base64_decode($content['data']));
			}

			foreach ($array as $key => $item) {

				if (!empty($item['content'])) {
					$content = $item['content'];
					$current_count = 0;

					if (!empty($content['image'])) {
						foreach ($content['image'] as $image_key => $image) {
							$content['image'][$image_key]['full_size_info'] =
								obj::transform('file')->weight($image['weight']) .
								', ' . $image['sizes'] . ' пикселей';

							$images_count++;
							$current_count++;
						}
					}

					if (!empty($content['random'])) {
						foreach ($content['random'] as $random_key => $image) {
							$content['random'][$random_key]['full_size_info'] =
								obj::transform('file')->weight($image['size']) .
								', ' . $image['width'] . 'x' . $image['height'] . ' пикселей';

							$images_count++;
							$current_count++;
						}
					}

					if (!empty($content['flash'])) {
						foreach ($content['flash'] as $flash_key => $flash) {
							$content['flash'][$flash_key]['full_size_info'] =
								obj::transform('file')->weight($flash['weight']);

							$flash_count++;
							$current_count++;
						}
					}

					if (!empty($content['video'])) {
						$width = def::board('thumbwidth');

						foreach ($content['video'] as $video_key => $video) {
							$height = $width * $video['aspect'];

							$content['video'][$video_key]['object'] = str_replace(
								array('%video_width%','%video_height%'),
								array($width,$height),
								$video['object']
							);

							$content['video'][$video_key]['height'] = $height;

							$video_count++;
							$current_count++;
						}
					}

					$array[$key]['content'] = $content;
				}

				if (!empty($item['boards'])) {
					$array[$key]['boards'] = array_values(array_filter(array_unique(explode('|',$item['boards']))));
				}
				if ($url[2] && strlen($url[2]) < 3) {
					$array[$key]['current_board'] = $url[2];
				} elseif (!empty($array[$key]['categories'])) {
					$c_key = array_rand($array[$key]['categories']);
					$array[$key]['current_board'] = $array[$key]['categories'][$c_key]['alias'];
				}

				if (!empty($item['text'])) {
					preg_match_all('/&gt;&gt;(\d+)(\s|$|<br[^>]*>)/',$item['text'],$inner_links);
					foreach ($inner_links[1] as $inner_link) {
						$this->inner_links[] = $inner_link;
					}
				}

				if ($current_count > 1) {
					$array[$key]['multi_content'] = true;
				}
			}
		}
		return array($images_count, $flash_count, $video_count);
	}