/** * kvieciama komentuojant darba */ function event_work_comment() { global $url, $subject, $comment, $parent_id, $g_user_id, $g_usr, $g_tpl; if (empty($comment)) { $this->error .= 'tuðèias komentaras<br>'; } if (empty($parent_id)) { $this->error .= 'neþinomas darbas<br>'; } if (empty($g_user_id)) { $this->error .= 'reikia prisijungti prie sistemos<br>'; } if (!$g_usr->can_i_comment()) { $this->error .= 'ðiuo metu negali komentuoti'; } if ($this->error) { return true; } $comment = do_ubb($comment); $comment = smartWrap($comment, 30); // [alias] skaidom ilgus piktybiðkus þodþius $subject = htmlchars($subject); // patikrinam kad nebutu netyciom dubliu $this->db->query("SELECT * FROM avcomments\n\t\t\tWHERE table_name='{$this->table}' AND parent_id={$parent_id} AND subject='{$subject}' AND info='{$comment}' LIMIT 1"); if ($this->db->not_empty()) { $this->error .= 'nesiøsk dukart<br>'; } if ($this->error) { return true; } $this->db->query("INSERT INTO avcomments (subject, info, posted, parent_id, table_name, user_id) \n\t\t\tVALUES ('{$subject}', '{$comment}', NOW(), {$parent_id}, '{$this->table}', {$g_user_id})"); $this->db->query("UPDATE avworks_stat SET comment_count = comment_count + 1 WHERE work_id={$parent_id}"); $this->db->clear_cache_tables('avcomments'); // siunciam meila autoriui $work = $this->db->get_array("SELECT * FROM avworks WHERE id='{$parent_id}'"); $author = $work['submiter']; $user_info = $this->db->get_array("SELECT * FROM u_user_info WHERE uid='{$author}'"); $this->db->clear_cache_name('workcomments'); if ($user_info['mail_comments'] && $author != $g_user_id) { $user = $this->db->get_array("SELECT * FROM u_users WHERE id='{$author}'"); $g_tpl->set_file('comment', 'darbai/tpl/mail_comment.txt'); $g_tpl->set_var('id', $parent_id); $g_tpl->set_var('work_title', $work['subject']); $g_tpl->set_var('title', $subject); $g_tpl->set_var('username', $g_usr->username); $g_tpl->set_var('info', undo_ubb($comment)); $g_tpl->set_var('date', date('Y.m.d')); mail($user['email'], 'komentaras apie tavo darbà', $g_tpl->process('', 'comment'), "MIME-Version: 1.0\nContent-Type: text/plain; charset=Windows-1257\nContent-Transfer-Encoding: 8bit\nFrom: art.scene automatas <*****@*****.**>\n", "*****@*****.**"); } redirect($url); }
function event_work_submit() { global $url, $subject, $info, $work, $category, $thumbnail, $color, $g_user_id, $g_usr, $g_tpl; if (empty($subject)) { $this->error = 'reikia pavadinimo<br>'; } if (empty($category)) { $this->error .= 'reikia kategorijos<br>'; } $work = $_FILES['work']; if (empty($work) || 'none' == $work) { $this->error .= 'reikia atsiøsti darbà<br>'; } if (!isset($g_user_id)) { $this->error .= 'reikia prisijungti prie sistemos<br>'; } if ($error = $this->check_cannot_post()) { $this->error .= $error; } if ($this->error) { return true; } $work_name = $_FILES['work']['name']; $work_size = $_FILES['work']['size']; $work_types = array('gif', 'jpg', 'png', 'swf'); $work_type = substr($work_name, strlen($work_name) - 3, 3); if (!in_array(strtolower($work_type), $work_types)) { $this->error .= 'blogas darbo failas, gali bûti tik .jpg, .gif, .png, .swf<br>'; } if ($thumbnail != '' && $thumbnail != 'none') { $thumb_name = $_FILES['thumbnail']['name']; $thumb_size = $_FILES['thumbnail']['size']; $thumb_types = array('gif', 'jpg', 'png'); $thumb_type = substr($thumb_name, strlen($thumb_name) - 3, 3); if (!in_array(strtolower($thumb_type), $thumb_types)) { $this->error .= 'blogas maþas paveiksliukas, gali bûti tik .jpg, .gif, .png<br>'; } } if ($work_size < 10240) { $this->error .= 'per maþas darbo failas, limitas 10kb<br>'; } if ($this->flash_category != $category && $work_size > 30720000) { $this->error .= 'per didelis darbo failas, limitas 300kb<br>'; } if ($this->error) { return true; } // kopijuojam darba! $work_name = clean_name($work_name); $work_dest = $this->ini->read_var('avworks', 'works_dir') . $work_name; while (file_exists($work_dest)) { $work_name = "_" . $work_name; $work_dest = $this->ini->read_var('avworks', 'works_dir') . $work_name; } $work = $_FILES['work']['tmp_name']; copy($work, $work_dest); unlink($work); // gaminam thumbnaila // jei ok dedam atsiusta thumbnail if ($thumbnail != 'none') { // vadinam taip pat kaip darba, kad nereiktu tikrinti dublikatu $thumbnail = $_FILES['thumbnail']['tmp_name']; $thumb_dest = $this->ini->read_var('avworks', 'thumbnails_dir') . $work_name . '.jpg'; $exec_src = $this->ini->read_var('avworks', 'convert_exec') . " -resize " . $this->thumb_x . "x" . $this->thumb_y . " {$thumbnail} jpg:{$thumb_dest}"; exec($exec_src); $thumbnail_name = $work_name . '.jpg'; if (!file_exists($thumb_dest)) { //galbut animuotas gifas? padarom pirma kadra if (file_exists($thumb_dest . '.0')) { $this->error = ''; rename($thumb_dest . '.0', $thumb_dest); } else { $this->error .= 'nepavyko padaryti maþo paveiksliuko<br>'; } } else { $this->error = ''; } } // jei problemos, gaminam is atsiusto darbo if (($thumbnail == 'none' || $this->error) && $category != $this->flash_category) { // vadinam taip pat kaip darba, kad nereiktu tikrinti dublikatu $thumb_dest = $this->ini->read_var('avworks', 'thumbnails_dir') . $work_name . '.jpg'; $exec_src = $this->ini->read_var('avworks', 'convert_exec') . " -resize " . $this->thumb_x . "x" . $this->thumb_y . " {$work_dest} jpg:{$thumb_dest}"; exec($exec_src); $thumbnail_name = $work_name . '.jpg'; if (!file_exists($thumb_dest)) { //galbut animuotas gifas? padarom pirma kadra if (file_exists($thumb_dest . '.0')) { $this->error = ''; rename($thumb_dest . '.0', $thumb_dest); } else { $this->error .= 'nepavyko padaryti maþo paveiksliuko<br>'; } } else { $this->error = ''; } } elseif ($this->error) { $this->error .= 'nepavyko padaryti maþo paveiksliuko<br>'; } // jei problemos, dedam default if ($this->error || empty($thumbnail_name)) { $thumbnail_name = 'nothumbnail.gif'; } isset($color) || ($color = ''); isset($info) || ($info = ''); //wordwrap($comment, 30, " ", true) // senas variantas //smartWrap($text,30); // naujas variantas $info = smartWrap(do_ubb($info), 30); $subject = wordwrap(htmlchars($subject), 20, " ", true); // cia html'o nebus, todel standartinis wordwrap $color = clean_hex($color); $this->db->query("INSERT INTO avworks (subject, info, posted, thumbnail, file, submiter, category_id, color, file_size)\n\t\t\t\t\t\t\tVALUES ('{$subject}', '{$info}', NOW(), '{$thumbnail_name}', '{$work_name}', {$g_user_id}, {$category}, '{$color}', {$work_size})"); // TODO: update avworks_stat $last_id = $this->db->get_insert_id(); $this->db->query("insert into avworks_stat \n (work_id, subject, info, posted, thumbnail, file, submiter, category_id, \n views, color, file_size, submiter_name, category_name) \nselect w.id, w.subject, w.info, w.posted, w.thumbnail, w.file, w.submiter, w.category_id, \n w.views, w.color, w.file_size, \n u.username, c.name from avworks w, u_users u, avworkcategory c\nwhere w.submiter = u.id AND c.id = w.category_id AND w.id={$last_id}"); $g_tpl->set_file('new_work', 'darbai/tpl/mail_new_work.txt'); $g_tpl->set_var('id', $this->db->get_insert_id()); $g_tpl->set_var('title', $subject); $g_tpl->set_var('username', $g_usr->username); $g_tpl->set_var('info', undo_ubb($info)); $g_tpl->set_var('date', date('Y.m.d')); $this->db->clear_cache_tables('avworks'); // $g_usr->mass_mail('art.scene naujas darbas', $g_tpl->process('temp', 'new_work'), 'mail_works'); $this->result = true; return true; }