示例#1
0
文件: tag.php 项目: 4otaku/4otaku
 public function process()
 {
     $tag = $this->get('tag');
     $type = $this->get('type');
     if (empty($tag)) {
         throw new Error_Api('Пропущено обязательное поле: tag', Error_Api::MISSING_INPUT);
     }
     if (empty($type)) {
         throw new Error_Api('Пропущено обязательное поле: type', Error_Api::MISSING_INPUT);
     }
     if (!array_key_exists($type, $this->types)) {
         throw new Error_Api('Неправильно заполнено поле: type', Error_Api::INCORRECT_INPUT);
     }
     $color = $this->types[$type];
     $tag = trim(undo_safety($tag));
     $args = array($tag, '|' . $tag . '|', $tag);
     $exists = Database::get_field('tag', 'alias', 'name = ? or locate(?, variants) or alias = ?', $args);
     if ($exists) {
         $alias = $exists;
     } else {
         $alias = Transform_Meta::make_alias($tag);
         Database::insert('tag', array('alias' => $alias, 'name' => $tag, 'variants' => '|'));
         $this->add_error(Error_Api::UNKNOWN_TAG);
     }
     Database::update('tag', array('color' => $color), 'alias = ?', $alias);
     $this->set_success(true);
     $this->add_answer('tag', $alias);
 }
示例#2
0
文件: order.php 项目: 4otaku/4otaku
	function add() {
		global $check; global $def; global $cookie; global $sets;
		if (!$cookie) $cookie = new dynamic__cookie();

		if (query::$post['mail'] && query::$post['subject']) {
			if ($check->email(query::$post['mail'],false) && query::$post['mail'] != $def['user']['mail']) {
				$cookie->inner_set('user.mail',query::$post['mail']);

				if (!trim(query::$post['user'])) query::$post['user'] = $def['user']['author'];
				if (query::$post['user'] != $def['user']['author']) $cookie->inner_set('user.name',query::$post['user']); else unset(query::$post['user']);

				query::$post['user'] = preg_replace('/#.*$/','',query::$post['user']);

				$category = obj::transform('meta')->category(query::$post['category']);
				$text = obj::transform('text')->format(trim(query::$post['description']));
				if (query::$post['subscribe']) query::$post['subscribe'] = 1;

				obj::db()->insert('orders',$insert_data = array(query::$post['subject'],query::$post['user'],query::$post['mail'],query::$post['subscribe'],$text,undo_safety(query::$post['description']),"",
							$category,0,0,obj::transform('text')->rudate(),$time = ceil(microtime(true)*1000),$def['area'][1]));
				obj::db()->insert('versions',array('order',$id = obj::db()->sql('select @@identity from orders',2),
												base64_encode(serialize($insert_data)),$time,$sets['user']['name'],$_SERVER['REMOTE_ADDR']));
				if (query::$post['subscribe']) $this->set_events($id,query::$post['mail']); else $this->set_events($id);
				$this->add_res('Заказ успешно добавлен. Страница заказа: <a href="/order/'.$id.'/">http://4otaku.org/order/'.$id.'</a>');
			}
			else $this->add_res('Вы указали неправильный е-мейл.', true);
		}
		else $this->add_res('Не все обязательные поля заполнены.', true);
	}
示例#3
0
文件: video.php 项目: 4otaku/4otaku
 protected function correct_main_data($data)
 {
     if (empty($data['title'])) {
         $data['title'] = '';
     }
     $data['link'] = Check::link(undo_safety($data['link']));
     return $data;
 }
示例#4
0
文件: common.php 项目: 4otaku/4otaku
	function edit_text() {
		global $check; global $def;
		if ($check->num(query::$post['id']) && $check->lat(query::$post['type'])) {
			$area = obj::db()->sql('select area from '.query::$post['type'].' where id='.query::$post['id'],2);
			if ($area != $def['area'][1]) $check->rights();
			$text = obj::transform('text')->format(query::$post['text']);
			obj::db()->update(query::$post['type'],array('text','pretty_text'),array($text,undo_safety(query::$post['text'])),query::$post['id']);
		}
	}
示例#5
0
文件: check.php 项目: 4otaku/4otaku
	public static function link_array($array) {
		$return = array();
		if (is_array($array)) {
			foreach ($array as $one) {
				$link = explode('&gt;',$one['link']);
				if (count($link) < 3 && self::link(undo_safety(end($link)))) {
					$return[] = $one;
				}
			}
		}
		return $return;
	}
示例#6
0
文件: news.php 项目: 4otaku/4otaku
 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>.');
 }
示例#7
0
文件: tag.php 项目: 4otaku/4otaku
	public function get_all () {
		$where = query::$get['where'];

		if (!is_numeric(query::$get['count']) || !in_array($where, $this->tag_areas)) {
			$this->reply($this->empty_reply);
		}

		$tags = Database::order($where.'_main')->limit(query::$get['count'])
			->get_vector('tag', 'name', $where.'_main > 0');

		$tags = array_values((array) $tags);

		foreach ($tags as &$tag) {
			$tag = html_entity_decode($tag);
			$tag = undo_safety($tag);
		}

		sort($tags);

		$this->reply($tags);
	}
示例#8
0
文件: link.php 项目: 4otaku/4otaku
	public static function parse($links) {
		$alias = Database::get_vector('misc', array('data1', 'data2'), 'type = ?', 'site_alias');
		foreach ($links as $key => $link) {
			$type = 'alias';
			$parts = explode('&gt;',$link['link']);
			$links[$key]['url'] = undo_safety(end($parts));
			if (count($parts) == 2) {
				$links[$key]['alias'] = str_replace('&lt;','',$parts[0]);
				$type = 'search';
			}
			$domain = parse_url($link['link'],PHP_URL_HOST);
			if (substr($domain,0,4) == 'www.') {
				$domain = substr($domain,4);
			}
			if ($alias[$domain]) {
				$links[$key][$type] = $alias[$domain];
			} else {
				$links[$key][$type] = $domain;
			}
		}
		return $links;
	}
示例#9
0
文件: meta.php 项目: 4otaku/4otaku
	public static function make_alias($word) {
		$word = strtolower(self::jap2lat(self::ru2lat(undo_safety($word))));
		$word = str_replace(' ','_',$word);
		$word = preg_replace('/[^a-z_\d]/eui','urlencode("$0")',$word);
		return str_replace('%5C%27', '%27', $word);
	}
示例#10
0
文件: file.php 项目: 4otaku/4otaku
	public static function make_name($word) {
		$word = strtolower(self::jap2lat(self::ru2lat(undo_safety($word))));
		$word = preg_replace('/[^a-z\d\[\]\.\-]/ui', '_', $word);
		return $word;
	}
示例#11
0
文件: post.php 项目: 4otaku/4otaku
 public function update()
 {
     if (!is_numeric(query::$post['id'])) {
         $this->writer->set_message('Что-то странное с формой обновления, сообщите администрации');
         return;
     }
     $author = trim(strip_tags(query::$post['author']));
     if (empty($author)) {
         $this->writer->set_message('Вы забыли указать автора обновления');
         return;
     }
     $text = Transform_Text::format(query::$post['text']);
     if (!trim(strip_tags($text))) {
         $this->writer->set_message('Вы забыли добавить описание обновления');
         return;
     }
     $links = array();
     foreach (query::$post['link'] as $link) {
         if (!empty($link['use'])) {
             unset($link['use']);
             $links[] = $link;
         }
     }
     $links = Transform_Link::parse($links);
     if (empty($links)) {
         $this->writer->set_message('Проверьте ссылки, с ними была какая-то проблема');
         return;
     }
     $update = new Model_Post_Update(array('post_id' => query::$post['id'], 'username' => $author, 'text' => $text, 'pretty_text' => undo_safety(query::$post['text'])));
     foreach ($links as $link) {
         $link = new Model_Post_Update_Link($link);
         $update->add_link($link);
     }
     $update->insert();
     $this->writer->set_success()->set_message('Запись успешно обновлена');
 }
示例#12
0
文件: board.php 项目: 4otaku/4otaku
	function add() {
		global $check; global $def; global $sets; global $cookie; global $add_res;
		if (!$cookie) $cookie = new dynamic__cookie();

		$content = array();
		$count_content = 0;

		if (!empty(query::$post['image']) && is_array(query::$post['image'])) {

			foreach (query::$post['image'] as $add_image) {
				if ($count_content >= def::board('maxcontent')) {
					continue;
				}

				$count_content++;

				if (array_key_exists($add_image, $this->random_codes)) {
					$random_art = $this->get_random_art($this->random_codes[$add_image]);

					if ($random_art) {
						$name = $random_art['md5'] . '.' . $random_art['extension'];
						$path = IMAGES . SL . 'booru' . SL . 'full' . SL . $name;

						try {
							$resizer = new Transform_Upload_Board_Image($path, $name);
							$result = $resizer->process_file();
						} catch (Error_Upload $e) {
							continue;
						}

						if (empty($result['success'])) {
							continue;
						}

						$content['random'][] = array(
							'id' => $random_art['id'],
							'full' => $result['full'],
							'thumb' => $result['thumb'],
							'size' => $result['size'],
							'width' => $result['width'],
							'height' => $result['height'],
						);
					}

					continue;
				}

				$parts = explode('#', $add_image);
				if ($parts[1] == 'flash') {
					$content['flash'][] = array(
						'full' => $parts[0],
						'weight' => $parts[2],
					);
				} else {
					$content['image'][] = array(
						'full' => $parts[0],
						'thumb' => $parts[1],
						'weight' => $parts[2],
						'sizes' => $parts[3],
					);
				}
			}
		}

		if (!empty(query::$post['video']) && is_array(query::$post['video'])) {
			query::$post['video'] = array_unique(query::$post['video']);

			foreach (query::$post['video'] as $add_video) {
				if (empty($add_video) || $count_content >= def::board('maxcontent')) {
					continue;
				}
				$video_link = undo_safety($add_video);
				$video_worker = new Transform_Video($video_link);
				$video_object = $video_worker->disable_nico()->get_html();

				if (empty($video_object)) {
					$this->add_res(
						'Извините, видеосервиса для ссылки '.
						'('.$add_video.') нет в нашей базе, '.
						'либо с вашей ссылкой что-то не так.'
					,true);
					continue;
				}
				$content['video'][] = array(
					'link' => $video_link,
					'object' => $video_object,
					'service_id' => $video_worker->get_id(),
					'aspect' => $video_worker->get_aspect(),
				);
				$count_content++;
			}
		}

		$text = obj::transform('text')->wakaba(query::$post['text']);

		$is_thread = (bool) empty(query::$post['id']);

		if ($is_thread + empty($content) + empty($text) <= 1) {

			$trip = preg_split('/(?<!&)#/', query::$post['user']);
			$user = array_shift($trip);
//			$user = preg_replace('/#.*$/','',$user);
			$trip = array_slice($trip,0,3);

			$tripcode = $trip[0] ? $this->trip($trip[0]) : '';
			$tripcode .= $trip[1] || $trip[2] ? '!'.$this->trip(_crypt($trip[1].$trip[2])) : '';

			if (trim($user) && $user != $def['user']['name']) {
				$cookie->inner_set('user.name',$user);
			}
			if (!empty($trip)) {
				$cookie->inner_set('user.trip',implode('#',$trip));
			} else {
				$cookie->inner_set('user.trip','');
			}

			if ($is_thread) {
				$categories = (array) query::$post['category'];

				$board_categories = obj::db()->sql('
					SELECT id, alias from category
					WHERE locate("|board|",area)
					ORDER BY id
				', 'alias');
				$insert_categories = array();

				$limit = $this->max_threads_in_board - 1;
				$to_flush = array();
				foreach ($categories as $category) {
					if (!array_key_exists($category, $board_categories)) {
						continue;
					}

					if (!in_array($category, $this->storing_boards)) {
						$to_flush = array_merge(
							$to_flush,
							(array) obj::db()->sql('
								SELECT board.id, board_category.category_id
								FROM board LEFT JOIN board_category
								ON board.id=board_category.thread_id
								WHERE
									board.type="thread" AND
									board_category.actual = 1 AND
									board_category.category_id = '.$board_categories[$category].'
								ORDER by board.updated DESC
								LIMIT '.$limit.', 1000
							')
						);
					}

					$insert_categories[] = $board_categories[$category];
				}

				if (!empty($to_flush)) {
					$condition = ''; $check_ids = array();
					foreach ($to_flush as $one) {
						$condition .= ' or
							(thread_id = '.$one['id'].' and category_id = '.$one['category_id'].')';
						$check_ids[] = $one['id'];
					}
					$condition = substr($condition, 4);
					obj::db()->sql('update `board_category` set actual = 0 where'.$condition,0);

					$still_living = array_keys((array) obj::db()->sql('
						SELECT board.id
						FROM board LEFT JOIN board_category
						ON board.id=board_category.thread_id
						WHERE
							board.id in ('.implode(',',$check_ids).') AND
							board_category.actual = 1
					','id'));

					$old_threads = array_diff($check_ids, $still_living);

					obj::db()->sql('update `board` set type = "old" where id in ('.implode(',',$old_threads).')',0);
				}
			}

			$time = ceil(microtime(true)*1000);

			$insert_data = array(
				$is_thread ? 'thread' : 'post',
				query::$post['id'],
				$is_thread ? $time : 0,
				trim($user) ? trim($user) : $def['user']['name'],
				$tripcode,
				undo_safety(query::$post['text']),
				$text,
				date('j.n.y - G:i'),
				$time,
				$cookie->get(),
				$_SERVER['REMOTE_ADDR']
			);

			obj::db()->insert('board',$insert_data);
			$id = obj::db()->sql('select @@identity from board',2);
			foreach ($insert_categories as $category) {
				obj::db()->insert('board_category',array($id,$category,1),false);
			}
			$this->add_content($content, $id);

			if (!empty(query::$post['id'])) {
				obj::db()->update('board','updated',$time,query::$post['id']);
			} else {
				$this->redirect = '/board/'.query::$post['category'][array_rand(query::$post['category'])].'/thread/'.$id;
			}
		} else {
			if (empty(query::$post['id'])) {
				$this->add_res('При создании нового треда вам надо написать текст, а также добавить картинку или видео',true);
			} else {
				$this->add_res('Для ответа надо добавить текст, картинку или видео',true);
			}
		}
	}
示例#13
0
文件: text.php 项目: 4otaku/4otaku
	function wakaba_strike($string) {
		$parts = preg_split('/((?:\^H)+|\{⟯link\d+\})/',$string,null,PREG_SPLIT_DELIM_CAPTURE);
		foreach ($parts as $key => $part) {
			if ($key && $part{0}.$part{1} == '^H' && $parts[$key-1]{1} != '⟯') {
				unset($parts[$key]);
				$parts[$key-1] = undo_safety($parts[$key-1]);

				$parts[$key-1] =
					redo_safety(mb_substr($parts[$key-1], 0, -1/2 * strlen($part))) . '<s>' .
					redo_safety(mb_substr($parts[$key-1], -1/2 * strlen($part))) . '</s>';
			}
		}

		return implode('',$parts);
	}