Пример #1
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());
 }
Пример #2
0
 protected function language($data)
 {
     $worker = new Transform_Meta();
     $language = $worker->language($data['language']);
     $this->model['language'] = $language;
 }