public function __construct($user = null) { if ($user === null) { return; } $item = Model::factory('kwalbum_item'); $item->user_id = $user->id; $item->hide_level = Kwalbum_ItemAdder::get_visibility($user); $item->location = trim(htmlspecialchars(@$_POST['loc'])); $tags = explode(',', htmlspecialchars(@$_POST['tags'])); for ($i = 0; $i < count($tags); $i++) { $tags[$i] = trim($tags[$i]); } $item->tags = $tags; $item->visible_date = $item->sort_date = Kwalbum_Helper::replaceBadDate(@$_POST['date'] . $_POST['time']); $this->_item = $item; }
public function before() { parent::before(); if (!empty($_POST['kwalbum_mass_check'])) { $location = trim(htmlspecialchars(@$_POST['loc'])); $visibility = null; if (!empty($_POST['vis'])) { $visibility = Kwalbum_ItemAdder::get_visibility($this->user); } $tags_to_add = array(); $tags_to_remove = array(); $persons_to_add = array(); $persons_to_remove = array(); if (!empty($_POST['tags_add'])) { $tags_to_add = explode(',', $_POST['tags_add']); foreach ($tags_to_add as $i => $tag) { $tags_to_add[$i] = trim(htmlspecialchars($tag)); } } if (!empty($_POST['tags_rem'])) { $tags_to_remove = explode(',', $_POST['tags_rem']); foreach ($tags_to_remove as $i => $tag) { $tags_to_remove[$i] = trim(htmlspecialchars($tag)); } } if (!empty($_POST['persons_add'])) { $persons_to_add = explode(',', $_POST['persons_add']); foreach ($persons_to_add as $i => $name) { $persons_to_add[$i] = trim(htmlspecialchars($name)); } } if (!empty($_POST['persons_rem'])) { $persons_to_remove = explode(',', $_POST['persons_rem']); foreach ($persons_to_remove as $i => $name) { $persons_to_remove[$i] = trim(htmlspecialchars($name)); } } foreach ($_POST['kwalbum_mass_check'] as $item_id) { $item = new Model_Kwalbum_Item($item_id); if ($location) { $item->location = $location; } if ($visibility !== null) { $item->hide_level = $visibility; } if ($tags_to_add) { $item->tags = array_merge($item->tags, $tags_to_add); } if ($tags_to_add) { $tags = $item->tags; foreach ($tags_to_remove as $tag) { $key = array_search($tag, $tags); if ($key !== false) { unset($tags[$key]); } } $item->tags = $tags; } if ($persons_to_add) { $item->persons = array_merge($item->persons, $persons_to_add); } if ($persons_to_remove) { $persons = $item->persons; foreach ($persons_to_remove as $name) { $key = array_search($name, $persons); if ($key !== false) { unset($persons[$key]); } } $item->persons = $persons; } $item->save(); } $tags = explode(',', htmlspecialchars(@$_POST['tags'])); for ($i = 0; $i < count($tags); $i++) { $tags[$i] = trim($tags[$i]); } $item->tags = $tags; } }
function action_write() { $user = $this->user; if (!$user->can_add) { $this->template->content = new View('kwalbum/invalidpermission'); return; } $date = $this->date; if (!$date) { $date = date('Y-m-d'); } $time = date('H:i'); $content = new View('kwalbum/user/write'); $content->user_is_admin = $user->is_admin; $content->location = $this->location; $content->tags = 'news,'; if (isset($_POST['group_option'])) { $content->same_group = $_POST['group_option'] == 'existing'; } else { $content->same_group = false; } if (isset($this->tags)) { $content->tags .= implode(',', $this->tags); } $content->date = $date; $content->time = $time; if (isset($_POST['act'])) { $adder = new Kwalbum_ItemAdder($this->user); $id = $adder->save_write(); if ($id) { $content->message = "There has been success in saving your words!<br/><a href='{$this->url}/~{$id}'>Go read them now to make sure they are correct.</a>"; $content->same_group = true; } else { Kohana::$log->add('~user/write', 'ItemAdder failed to save_write item'); $content->message = 'Your words were not saved. Try again or report the error and save your message somewhere else for now.'; $content->location = $_POST['loc']; $content->tags = $_POST['tags']; $content->date = $_POST['date']; $content->time = $_POST['time']; $content->description = $_POST['description']; } } $template = $this->template; $template->content = $content; $template->title = 'Write'; $template->head .= html::script('kwalbum/media/ajax/write.js'); }
public function action_upload() { if (!$this->user->is_logged_in) { if (!isset($_SERVER['PHP_AUTH_USER'])) { header('WWW-Authenticate: Basic realm="Upload"'); header('HTTP/1.1 401 Unauthorized'); die('Invalid login'); } $this->user = Model_Kwalbum_User::login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); if (!$this->user) { die('Invalid login'); } } if (!$this->user->can_add) { $this->request->response()->status(500); die('You do not have permission to add items'); } if (!empty($_FILES)) { $adder = new Kwalbum_ItemAdder($this->user); $errors = array(); $files = array(); if (isset($_FILES['files'])) { $files = is_array($_FILES['files']) ? $_FILES['files'] : array($_FILES['files']); } elseif (isset($_FILES['userfile'])) { $files = array($_FILES['userfile']); } try { foreach ($files as $file) { $result = $adder->save_upload($file); if ($result != (int) $result) { $errors[] = $result; } } } catch (Exception $e) { $errors[] = $e->getMessage(); } if (!empty($errors)) { $this->request->response()->status(500); echo json_encode(array('errors' => $errors)); } else { echo 'success'; } return; } $this->request->response()->status(500); echo 'No files sent'; }