public function put_image() { $event = 0 + $this->data('event'); $image = 0 + $this->data('image'); if (!$event) { return $this->error(31); } if (!$image) { return $this->error(18); } $this->event()->get($event); if ($this->event()->user != Bootstrap::$main->user['id']) { return $this->error(19); } $imageModel = new imageModel($image); if (!$imageModel->user) { return $this->error(18); } return $this->status(null, $imageModel->removeEvent($event)); }
public function delete() { require_once __DIR__ . '/../models/paymentModel.php'; require_once __DIR__ . '/../models/imageLabelModel.php'; require_once __DIR__ . '/../models/rateModel.php'; require_once __DIR__ . '/../models/guestModel.php'; require_once __DIR__ . '/../models/tagModel.php'; $this->requiresLogin(); if ($this->id && $this->id != Bootstrap::$main->user['id']) { $this->requiresLogin(true); } $user_id = $this->id ?: Bootstrap::$main->user['id']; $backup = []; $backup['user'] = $this->user($user_id)->data(); $md5hash = $backup['user']['md5hash']; $images = new imageModel(); $labels = new imageLabelModel(); $rates = new rateModel(); $guests = new guestModel(); $events = new eventModel(); $tags = new tagModel(); $payments = new paymentModel(); $backup['image'] = $images->getUsersImages($user_id) ?: []; $backup['imageLabels'] = []; foreach ($backup['image'] as $img) { $backup['imageLabels'] = array_merge($backup['imageLabels'], $labels->select(['image' => $img['id']]) ?: []); } $backup['event'] = $events->select(['user' => $user_id]) ?: []; $backup['tag'] = $tags->select(['user' => $user_id]) ?: []; foreach ($backup['event'] as $event) { $backup['tag'] = array_merge($backup['tag'], $tags->select(['event' => $event['id']]) ?: []); } $backup['rate'] = $rates->select(['user' => $user_id]) ?: []; $backup['rate'] = array_merge($backup['rate'], $rates->select(['host' => $user_id]) ?: []); $backup['guest'] = $guests->select(['user' => $user_id]) ?: []; $backup['payment'] = []; foreach ($backup['guest'] as $guest) { $backup['payment'] = array_merge($backup['payment'], $payments->select(['guest' => $guest['id']]) ?: []); } $backup_json = json_encode($backup, JSON_NUMERIC_CHECK); $path = 'arch/' . $md5hash . '/' . Bootstrap::$main->human_datetime_format(Bootstrap::$main->now); Tools::save($path . '/data.json', $backup_json); Tools::save($path . '/img', null, 'img/' . $md5hash); Tools::log('remove-user', Bootstrap::$main->user['id']); $this->user()->remove(); if (!$this->id || $this->id == Bootstrap::$main->user['id']) { return $this->get_logout(); } return $this->status(); }
protected function editpost() { //$post global $rep, $view; $data = array(); if (isset($_POST['edit'])) { //we edit switch ($_POST['edit']) { case 'edit': $post_Id = isset($_POST['post_id']) ? $_POST['post_id'] : NULL; $post_title = isset($_POST['post_title']) ? $_POST['post_title'] : NULL; $post_content = isset($_POST['post_content']) ? $_POST['post_content'] : NULL; $data['uploadfile'] = NULL; //if you upload a file if ($_FILES['imagepost']['name'] != NULL) { ///check error upload if ($_FILES['imagepost']['error'] > 0) { if ($_FILES['imagepost']['error'] == UPLOAD_ERR_FORM_SIZE) { $data['uploadfile'] = 'The file must not be bigger than 5mo.'; } else { $data['uploadfile'] = 'The upload failed. Please try again, if this persists, contact the admin.'; } //setup the error code } $valid_extensions = array('jpg', 'jpeg', 'gif', 'png'); $extension_upload = strtolower(substr(strrchr($_FILES['imagepost']['name'], '.'), 1)); if (!in_array($extension_upload, $valid_extensions)) { $data['uploadfile'] = 'The extension isn\'t valid. The picture must be a jpg, jpeg, gig or png file.'; //setup the error code } /// end check error upload /// check error move $uploaddir = './images/posts/' . $post_Id . '/'; //create the directory of theprofile pic if (!is_dir($uploaddir)) { mkdir($uploaddir, 0777, true); } //give this image a random name (for multiple images) $temp = explode(".", $_FILES["imagepost"]["name"]); $newfilename = round(microtime(true)) . '.' . end($temp); $uploadfile = $uploaddir . $newfilename; if (file_exists($uploadfile)) { $data['uploadfile'] = 'Error during the upload. Please try again, if this persists, contact the admin.'; //setup the error code } elseif (!move_uploaded_file($_FILES['imagepost']['tmp_name'], $uploadfile)) { //if error moving file if (is_dir_empty($uploaddir)) { rmdir($uploaddir); } //remove the directory IF NOT EMPTY $data['uploadfile'] = 'Error during the upload. Please try again, if this persists, contact the admin.'; //setup the error code } if ($data['uploadfile'] != NULL) { $post = postModel::getPost($post_Id); require_once $view['editpost']; break; } else { imageModel::addImagePost($post_Id, $_SESSION['username'], $newfilename); } } postModel::updatePost($post_Id, $post_title, $post_content); $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $extra = 'editpost/' . $post_Id; header("Location: http://{$host}{$uri}/{$extra}"); break; case 'deletepost': $post_Id = isset($_POST['post_id']) ? $_POST['post_id'] : NULL; postModel::deletePost($post_Id); $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $extra = 'dashboard'; header("Location: http://{$host}{$uri}/{$extra}"); break; case 'deleteimg': $post_Id = isset($_POST['post_id']) ? $_POST['post_id'] : NULL; $img_id = isset($_POST['img_id']) ? $_POST['img_id'] : NULL; imageModel::deleteImg($img_id); $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $extra = 'editpost/' . $post_Id; header("Location: http://{$host}{$uri}/{$extra}"); break; default: $data[0] = 'Unknow Error'; $data[1] = 'We couldnt handle that request'; $data[0] = '<a href="dashboard" >Dashboard</a>'; require_once $view['error']; } } else { //otherwise we show the post $postId = isset($_GET['arg1']) ? $_GET['arg1'] : NULL; if ($postId == NULL) { $data = array(); $data[0] = "We're sorry, something somewhere went wrong..."; $data[1] = "Please tell us which post you want to edit first."; require_once $view['error']; } elseif (postModel::getPost($postId) == NULL) { $data = array(); $data[0] = "We're sorry, something somewhere went wrong..."; $data[1] = "The post you're trying to edit doesn't exist!"; require_once $view['error']; } else { $post = postModel::getPost($postId); require_once $view['editpost']; } } }
<?php require_once __DIR__ . '/../base.php'; require_once __DIR__ . '/../../rest/models/eventModel.php'; require_once __DIR__ . '/../../rest/models/imageModel.php'; require_once __DIR__ . '/../../rest/models/userModel.php'; $event = new eventModel(); $image = new imageModel(); $user = new userModel(); $events = $event->getEventsToPay(24 * 3600) ?: []; Bootstrap::$main->human_datetime_format(); foreach ($events as $e) { $e['img'] = $image->get($e['img']); $data = ['guest' => $user->get($e['guest']), 'host' => $user->get($e['user'])]; Bootstrap::$main->session('time_delta', $data['host']['delta']); $data['event'] = $event->get($e['id']); $data['event']['img'] = $e['img']; echo $data['guest']['firstname'] . ' ' . $data['guest']['lastname'] . ' (' . $data['guest']['email'] . '), ' . $data['guest']['lang']; echo ' » '; echo $data['event']['name'] . ' (' . $data['event']['event_start'] . ')'; echo '<br/>'; Tools::observe('payment-reminder', $data); }
protected function paid(paymentModel $payment, $amount) { if (0.9 * $payment->amount < $amount) { $image = new imageModel(); $guest = new guestModel($payment->guest); if ($guest->d_payment) { return; } $guest->d_payment = Bootstrap::$main->now; $guest->save(); $e = $this->event()->get($guest->event); Tools::userHasAccessToEvent($guest->event, $guest->user, true); $data = []; $data['event'] = $this->event()->data(); $user = new userModel($data['event']['user']); $data['host'] = $user->data(); Bootstrap::$main->session('time_delta', $user->delta); Bootstrap::$main->human_datetime_format(); $data['event'] = $this->event()->get($guest->event); $data['event']['img'] = $image->get($data['event']['img']); $user->get($guest->user); $data['guest'] = $user->data(); $data['data'] = $guest->data(); $data['payment'] = $payment->data(); if (isset($data['payment']['notify'])) { $data['notify'] = json_decode($data['payment']['notify'], true); } $ics = Ics::invitation($e, $data['host'], $data['guest'], $e['create'], $guest->create); Tools::observe('event-paid-to-host', $data); Tools::observe('event-paid-to-guest', $data, [['invite.ics' => $ics]]); Tools::log('guest', $data); $eventController = new eventController(); $eventController->recalculate_fullhouse($guest->event); } }
protected function upload_file($tmp, $name) { //mydie($this->_media_dir,$this->_media); $ext = @strtolower(end(explode('.', $name))); $user = Bootstrap::$main->user; if (isset($this->data['flowIdentifier'])) { $lp = $this->data['flowIdentifier']; } else { $lp = 1 + $this->image()->getUsersCount($user['id']); } $name = $this->_prefix . '/' . $user['md5hash'] . '/' . md5($lp . '-' . $name) . '.' . $ext; $chunks = false; $original_name = $name; if (isset($this->data['flowTotalChunks']) && $this->data['flowTotalChunks'] > 1 && isset($this->data['flowChunkNumber'])) { $chunks = true; $name .= '.part' . $this->data['flowChunkNumber']; } if ($this->_appengine) { $file = 'gs://' . CloudStorageTools::getDefaultGoogleStorageBucketName() . '/' . $name; move_uploaded_file($tmp, $file); } else { $file = $this->_media_dir . '/' . $name; @mkdir(dirname($file), 0755, true); move_uploaded_file($tmp, $file); //mydie(exif_read_data($tmp)); } if ($chunks) { if (!$this->checkChunks($file)) { return false; } $name = $original_name; $file = preg_replace('/\\.part[0-9]+$/', '', $file); } if (!file_exists($file) || !filesize($file)) { $this->error(18); } $model = new imageModel(); $model->user = $user['id']; $model->src = $name; $model->d_uploaded = Bootstrap::$main->now; $exif = []; $imagesize = @getimagesize($file, $exif); if (!is_array($imagesize) || !$imagesize[0]) { $imagesize = [5000, 5000]; } if (is_array($exif)) { foreach ($exif as $k => $a) { if (substr($a, 0, 4) == 'Exif') { $matches = []; preg_match_all('/[0-9]{4}:[0-9]{2}:[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/', $a, $matches); $d = ''; if (isset($matches[0][1])) { $d = $matches[0][1]; } elseif (isset($matches[0][0])) { $d = $matches[0][0]; } if ($d) { $d = preg_replace('/([0-9]{4}):([0-9]{2}):([0-9]{2})/', '\\1-\\2-\\3', $d); $model->d_taken = $this->strtotime($d); } } } } if ($this->_appengine) { $model->url = CloudStorageTools::getImageServingUrl($file, ['size' => 0 + Bootstrap::$main->getConfig('image_size'), 'secure_url' => Bootstrap::$main->getConfig('protocol') == 'https']); $full = CloudStorageTools::getImageServingUrl($file, ['size' => 1234, 'secure_url' => Bootstrap::$main->getConfig('protocol') == 'https']); $model->full = str_replace('=s1234', '=s' . Bootstrap::$main->getConfig('full_size'), $full); $model->thumbnail = CloudStorageTools::getImageServingUrl($file, ['size' => 0 + Bootstrap::$main->getConfig('thumbnail_size'), 'secure_url' => Bootstrap::$main->getConfig('protocol') == 'https']); $model->square = CloudStorageTools::getImageServingUrl($file, ['size' => 0 + Bootstrap::$main->getConfig('square_size'), 'secure_url' => Bootstrap::$main->getConfig('protocol') == 'https', 'crop' => true]); } else { $image = new Image($file); $w = $h = 0; if ($imagesize[0] > Bootstrap::$main->getConfig('image_size')) { $w = Bootstrap::$main->getConfig('image_size'); $img = preg_replace("/\\.{$ext}\$/", '-i.' . $ext, $file); $image->min($img, $w, $h, true); $model->url = 'http://' . $_SERVER['HTTP_HOST'] . $this->_media . '/' . preg_replace("/\\.{$ext}\$/", '-i.' . $ext, $name); } else { $model->url = 'http://' . $_SERVER['HTTP_HOST'] . $this->_media . '/' . $name; } $w = $h = 0; if ($imagesize[0] > Bootstrap::$main->getConfig('full_size')) { $w = Bootstrap::$main->getConfig('full_size'); $img = preg_replace("/\\.{$ext}\$/", '-f.' . $ext, $file); $image->min($img, $w, $h, true); $model->full = 'http://' . $_SERVER['HTTP_HOST'] . $this->_media . '/' . preg_replace("/\\.{$ext}\$/", '-f.' . $ext, $name); } else { $model->full = 'http://' . $_SERVER['HTTP_HOST'] . $this->_media . '/' . $name; } $w = $h = 0; if ($image->w() > $image->h()) { $w = Bootstrap::$main->getConfig('thumbnail_size'); } else { $h = Bootstrap::$main->getConfig('thumbnail_size'); } $thmb = preg_replace("/\\.{$ext}\$/", '-t.' . $ext, $file); $image->min($thmb, $w, $h, true); $model->thumbnail = 'http://' . $_SERVER['HTTP_HOST'] . $this->_media . '/' . preg_replace("/\\.{$ext}\$/", '-t.' . $ext, $name); $w = $h = Bootstrap::$main->getConfig('square_size'); $square = preg_replace("/\\.{$ext}\$/", '-s.' . $ext, $file); $image->min($square, $w, $h, false, true); $model->square = 'http://' . $_SERVER['HTTP_HOST'] . $this->_media . '/' . preg_replace("/\\.{$ext}\$/", '-s.' . $ext, $name); } $model->save(); $ret = $model->data(); if ($ctx = Bootstrap::$main->session('image_ctx')) { $model->setLabels($ctx); $ret['labels'] = $model->getLabels(); if (is_array($ctx)) { foreach ($ctx as $k => $e) { if ($k == 'event') { $event = new eventModel($e); if ($event->user == Bootstrap::$main->user['id'] && !$event->img) { $event->img = $model->id; $event->save(); } $model->title = $event->name; $model->save(); } } } } return $this->status($ret); }
/** * 生成指定目录不重名的文件名 * * @access public * @param string $dir 要检查是否有同名文件的目录 * * @return string 文件名 */ function unique_name($dir) { $filename = ''; while (empty($filename)) { $filename = imageModel::random_filename(); if (file_exists($dir . $filename . '.jpg') || file_exists($dir . $filename . '.gif') || file_exists($dir . $filename . '.png')) { $filename = ''; } } return $filename; }