function send_msg() { $this->de = $this->session->userdata('id'); $this->para = $this->input->post('para'); $this->fecha = mdate('%d%m%Y', time()); $this->date = time(); $this->titulo = $this->input->post('titulo'); $this->texto = $this->input->post('texto'); $this->leido = 1; $this->db->insert('mensajeria', $this); activity_add($this->session->userdata('id'), 2, $this->input->post('para')); }
if (!$existing) { $id = $db->insert('project_module', $data); $result = 'NEW'; } // crop module thumbnail require LIBRARY . 'image.php'; $path = 'upload/modules/' . $screen['project'] . '/' . md5($id . config('security.general.hash')) . '.png'; cropScreen($screen['id'], array('x' => $x, 'y' => $y, 'width' => $width, 'height' => $height), array('width' => 150, 'height' => 120), $path); $thumbnail = R . $path; // update module count for screen $db->query("UPDATE screen SET count_module = count_module + 1 WHERE id = " . $screen['id'] . ""); // add reference to module $data = array('created' => date('Y-m-d H:i:s'), 'creator' => userid(), 'screen' => $screen['id'], 'module' => $id, 'x' => $x, 'y' => $y, 'width' => $width, 'height' => $height); $id = $db->insert('module', $data); // add to activity stream activity_add('{actor} defined module {object} on screen {target}', userid(), OBJECT_TYPE_USER, user('name'), ACTIVITY_VERB_DEFINE, $id, OBJECT_TYPE_MODULE, $name, $screen['id'], OBJECT_TYPE_SCREEN, 'Screen Title'); $data['id'] = $id; $data['result'] = $result; $data['name'] = $name; $data['skin'] = $skin; $data['thumbnail'] = $thumbnail; header('Content-Type: application/json'); echo json_encode($data); break; case API_MODULE_RECAPTURE: $screen = intval($route[4]); $x = intval($route[5]); $y = intval($route[6]); $width = intval($route[7]); $height = intval($route[8]); $module = intval($route[9]);
case API_PROJECT_SETTING: lock(); $project = intval($route[4]); $setting = $route[5]; switch ($setting) { case 'name': $value = $route[6]; $db->update('project', array('name' => urldecode($value)), array('id' => $project, 'creator' => userid())); break; } break; case API_PROJECT_ADD: $data = array('created' => date('Y-m-d H:i:s'), 'creator' => userid(), 'name' => $db->escape($_REQUEST['name']), 'slug' => slug($_REQUEST['name'])); $id = $db->insert('project', $data); // add to activity stream activity_add('{actor} created a new project {object}', userid(), OBJECT_TYPE_USER, user('name'), ACTIVITY_VERB_CREATE, $id, OBJECT_TYPE_PROJECT, $data['name']); $data['id'] = $id; $data['url'] = R . 'project/' . userid() . '/' . $data['slug'] . '/'; echo json_encode($data); break; case API_PROJECT_DELETE: $project = intval($route[4]); $screens = $db->data("SELECT id FROM screen WHERE project = " . $project . " AND creator = " . userid()); // TODO: load colors referenced by this screen and delete // color form library if it doesn't exist on another // screen foreach ($screens as $screen) { $db->delete('color', array('screen' => $screen['id'])); $db->delete('comment', array('screen' => $screen['id'])); $db->delete('measure', array('screen' => $screen['id'])); $db->delete('screen', array('id' => $screen['id']));
public function upload_img() { $name = $_FILES['userfile']['name']; $name = strtr($name, 'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ', 'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy'); // remplacer les caracteres autres que lettres, chiffres et point par _ $name = preg_replace('/([^.a-z0-9]+)/i', '_', $name); //Your upload directory, see CI user guide $config['upload_path'] = $this->getPath_img_upload_folder(); $config['allowed_types'] = 'gif|jpg|png|JPG|GIF|PNG'; $config['max_size'] = '1000'; $config['file_name'] = time() . '_' . md5($name); //Load the upload library $this->load->library('upload', $config); if ($this->do_upload()) { //redim_imagen('./'.$this->getPath_img_upload_folder().'/'.$config['file_name'], './'.$this->getPath_img_thumb_upload_folder().'/'.$config['file_name'], 240, 240, 1); //If you want to resize /*$config['new_image'] = $this->getPath_img_thumb_upload_folder(); $config['image_library'] = 'gd2'; $config['source_image'] = $this->getPath_img_upload_folder() . $name; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = 193; $config['height'] = 94; $this->load->library('image_lib', $config); $this->image_lib->resize();*/ //redim_imagen($config['source_image'], "./upload/thumb_".$file_upload, 240, 240, 1); $data = $this->upload->data(); //Get info $info = new stdClass(); $info->name = $data['orig_name']; $info->size = $data['file_size']; $info->type = $data['file_type']; $info->url = $this->getPath_img_upload_folder() . $data['orig_name']; $info->thumbnail_url = $this->getPath_img_thumb_upload_folder() . $data['orig_name']; //I set this to original file since I did not create thumbs. change to thumbnail directory if you do = $upload_path_url .'/thumbs' .$name $info->delete_url = $this->getDelete_img_url() . $name; $info->delete_type = 'DELETE'; redim_imagen('./' . $info->url, './' . $info->thumbnail_url, 240, 240, 1); $query = array('id' => '', 'author' => $this->session->userdata('id'), 'fecha' => time(), 'path' => $info->url, 'thumb' => $info->thumbnail_url, 'active' => '0'); $this->db->insert('galeria', $query); activity_add($this->session->userdata('id'), '3'); //Return JSON data if (IS_AJAX) { //this is why we put this in the constants to pass only json data echo json_encode(array($info)); //this has to be the only the only data returned or you will get an error. //if you don't give this a json array it will give you a Empty file upload result error //it you set this without the if(IS_AJAX)...else... you get ERROR:TRUE (my experience anyway) } else { // so that this will still work if javascript is not enabled $file_data['upload_data'] = $this->upload->data(); echo json_encode(array($info)); } } else { // the display_errors() function wraps error messages in <p> by default and these html chars don't parse in // default view on the forum so either set them to blank, or decide how you want them to display. null is passed. $error = array('error' => $this->upload->display_errors('', '')); echo json_encode(array($error)); } }
$x = intval($route[5]); $y = intval($route[6]); if ($screen < 1) { die('Please provide a screen id'); } $max = $db->single("SELECT MAX(nr) as current FROM comment WHERE screen = '" . $screen . "'"); if ($max === null) { die; } $nr = $max['current'] + 1; $comment = array('created' => date('Y-m-d H:i:s'), 'creator' => userid(), 'screen' => $screen, 'nr' => intval($nr), 'x' => $x, 'y' => $y); $id = $db->insert('comment', $comment); $db->query("UPDATE screen SET count_comment = count_comment + 1 WHERE id = " . $screen . ""); $comment['id'] = $id; // add to activity stream activity_add('{actor} left a comment on screen {target}', userid(), OBJECT_TYPE_USER, user('name'), ACTIVITY_VERB_COMMENT, $id, OBJECT_TYPE_COMMENT, "", $screen, OBJECT_TYPE_SCREEN, 'Title'); echo json_encode($comment); break; case API_COMMENT_REMOVE: $id = intval($route[4]); if ($id < 1) { die('Please provide a comment id'); } $comment = $db->single('SELECT screen FROM comment WHERE id = ' . $id . ' AND creator = ' . userid()); if (!$comment) { die; } $db->delete('comment', array('id' => $id)); $db->query("UPDATE screen SET count_comment = count_comment - 1 WHERE id = " . $comment['screen'] . ""); break; case API_COMMENT_MOVE:
function activity_delete_meeting($meeting_id) { $CI =& get_instance(); $CI->load->model(array('Hotspot', 'Screen', 'Project')); $CI->load->model(array('Meeting', 'Project')); $meeting = $CI->Meeting->load($meeting_id); $user = $CI->User->load($meeting->creator_id); $project = $CI->Project->load($meeting->project_id); if ($project && $project->team_id) { $title = $user->fullname . " deleted a hotspot on the '" . $project->name . "' Project."; activity_add($user->id, $project->team_id, $project->id, $meeting->id, ACTIVITY_TYPE_MEETING_DELETE, $title); } }
private function handle_file_upload($uploaded_file, $name, $size, $type, $error) { // create new screen entry global $db; $ext = substr($name, strrpos($name, '.') + 1); if (!in_array(strtolower($ext), array('png', 'jpg', 'jpeg'))) { die; } list($width, $height, $itype, $attr) = @getimagesize($uploaded_file); $screen = array('created' => date('Y-m-d H:i:s'), 'creator' => userid(), 'title' => substr(basename($name), 0, -(strlen($ext) + 1)), 'type' => $type, 'width' => $width, 'height' => $height, 'ext' => substr($type, strpos($type, '/') + 1), 'project' => $this->project, 'code' => gen_uuid(userid() . '-screen')); $id = $db->insert('screen', $screen); // add to activity stream activity_add('{actor} added a new screen {object} to project {target}', userid(), OBJECT_TYPE_USER, user('name'), ACTIVITY_VERB_ADD, $id, OBJECT_TYPE_SCREEN, $screen['title'], $this->project, OBJECT_TYPE_PROJECT, 'Project Title'); $db->query("UPDATE project SET screen_count = screen_count + 1 WHERE id = " . $this->project); $file = new stdClass(); $file->name = $this->trim_file_name($name, $type); $file->size = intval($size); $file->type = $type; $file->newname = md5($id . config('security.general.hash')) . '.' . substr($type, strpos($type, '/') + 1); $error = $this->has_error($uploaded_file, $file, $error); if (!$error && $file->name) { $file_path = $this->options['upload_dir'] . $file->newname; $append_file = !$this->options['discard_aborted_uploads'] && is_file($file_path) && $file->size > filesize($file_path); clearstatcache(); if ($uploaded_file && is_uploaded_file($uploaded_file)) { // multipart/formdata uploads (POST method uploads) if ($append_file) { file_put_contents($file_path, fopen($uploaded_file, 'r'), FILE_APPEND); } else { move_uploaded_file($uploaded_file, $file_path); } } else { // Non-multipart uploads (PUT method support) file_put_contents($file_path, fopen('php://input', 'r'), $append_file ? FILE_APPEND : 0); } $file_size = filesize($file_path); if ($file_size === $file->size) { if ($this->options['orient_image']) { $this->orient_image($file_path); } foreach ($this->options['image_versions'] as $version => $options) { if ($this->create_scaled_image($file->newname, $options)) { $file->{$version . '_url'} = $options['upload_url'] . rawurlencode($file->newname); } } } else { if ($this->options['discard_aborted_uploads']) { unlink($file_path); $file->error = 'abort'; } } $file->size = $file_size; $file->delete_url = $this->options['script_url'] . '?file=' . rawurlencode($file->name); $file->delete_type = 'DELETE'; } else { $file->error = $error; } return $file; }
// update color count for screen $db->query("UPDATE screen SET count_color = count_color + 1 WHERE id = " . $screen['id'] . ""); // add reference to color $data = array('created' => date('Y-m-d H:i:s'), 'creator' => userid(), 'screen' => $screen['id'], 'color' => $id, 'x' => $x, 'y' => $y); $id = $db->insert('color', $data); $data['id'] = $id; $data['r'] = $r; $data['g'] = $g; $data['b'] = $b; $data['hex'] = $hex; $data['alpha'] = $a; $data['result'] = $result; $data['name'] = $match[0]; $data['match'] = $match[1]; // add to activity stream activity_add('{actor} picked {object} on screen {target}', userid(), OBJECT_TYPE_USER, user('name'), ACTIVITY_VERB_PICK, $id, OBJECT_TYPE_COLOR, '#' . $hex, $screen['id'], OBJECT_TYPE_SCREEN, 'Title'); header('Content-Type: application/json'); echo json_encode($data); break; case API_COLOR_EXPORT: $project = intval($route[4]); $type = strtolower($route[5]); if ($project < 1) { die('Please provide a project id'); } if (empty($type)) { die('Please provide a type to export to'); } switch ($type) { case 'aco': // get the aco-library
function send_upload() { if ($this->session->userdata('status')) { $id_user = $this->uri->segment(4); error_reporting(E_ALL ^ E_NOTICE); //remove notice for json invalidation $uploadPath = $_REQUEST['ax-file-path']; if (is_dir($uploadPath)) { //echo json_encode(array('path' => $uploadPath, 'MSG' => "Path no encontado")); //die(); } $fileName = $_REQUEST['ax-file-name']; $currByte = $_REQUEST['ax-start-byte']; $maxFileSize = $_REQUEST['ax-maxFileSize']; $html5fsize = $_REQUEST['ax-fileSize']; $isLast = $_REQUEST['isLast']; //if set generates thumbs only on images type files $thumbHeight = $_REQUEST['ax-thumbHeight']; $thumbWidth = $_REQUEST['ax-thumbWidth']; $thumbPostfix = $_REQUEST['ax-thumbPostfix']; $thumbPath = $_REQUEST['ax-thumbPath']; $thumbFormat = $_REQUEST['ax-thumbFormat']; $allowExt = empty($_REQUEST['ax-allow-ext']) ? array() : explode('|', $_REQUEST['ax-allow-ext']); $uploadPath .= !in_array(substr($uploadPath, -1), array('\\', '/')) ? DIRECTORY_SEPARATOR : ''; //normalize path if (!file_exists($uploadPath) && !empty($uploadPath)) { mkdir($uploadPath, 0777, true); } if (!file_exists($thumbPath) && !empty($thumbPath)) { mkdir($thumbPath, 0777, true); } //with gd library function createThumbGD($filepath, $thumbPath, $postfix, $maxwidth, $maxheight, $format = 'jpg', $quality = 75) { if ($maxwidth <= 0 && $maxheight <= 0) { return 'No valid width and height given'; } $gd_formats = array('jpg', 'jpeg', 'png', 'gif'); //web formats $file_name = pathinfo($filepath); if (empty($format)) { $format = $file_name['extension']; } if (!in_array(strtolower($file_name['extension']), $gd_formats)) { return false; } $thumb_name = $file_name['filename'] . $postfix . '.' . $format; if (empty($thumbPath)) { $thumbPath = $file_name['dirname']; } $thumbPath .= !in_array(substr($thumbPath, -1), array('\\', '/')) ? DIRECTORY_SEPARATOR : ''; //normalize path // Get new dimensions list($width_orig, $height_orig) = getimagesize($filepath); if ($width_orig > 0 && $height_orig > 0) { $ratioX = $maxwidth / $width_orig; $ratioY = $maxheight / $height_orig; $ratio = min($ratioX, $ratioY); $ratio = $ratio == 0 ? max($ratioX, $ratioY) : $ratio; $newW = $width_orig * $ratio; $newH = $height_orig * $ratio; // Resample $thumb = imagecreatetruecolor($newW, $newH); $image = imagecreatefromstring(file_get_contents($filepath)); imagecopyresampled($thumb, $image, 0, 0, 0, 0, $newW, $newH, $width_orig, $height_orig); // Output switch (strtolower($format)) { case 'png': imagepng($thumb, $thumbPath . $thumb_name, 9); break; case 'gif': imagegif($thumb, $thumbPath . $thumb_name); break; default: imagejpeg($thumb, $thumbPath . $thumb_name, $quality); break; } imagedestroy($image); imagedestroy($thumb); } else { return false; } } //for image magick function createThumbIM($filepath, $thumbPath, $postfix, $maxwidth, $maxheight, $format) { $file_name = pathinfo($filepath); $thumb_name = $file_name['filename'] . $postfix . '.' . $format; if (empty($thumbPath)) { $thumbPath = $file_name['dirname']; } $thumbPath .= !in_array(substr($thumbPath, -1), array('\\', '/')) ? DIRECTORY_SEPARATOR : ''; //normalize path $image = new Imagick($filepath); $image->thumbnailImage($maxwidth, $maxheight); $images->writeImages($thumbPath . $thumb_name); } function checkFilename($fileName, $size, $newName = '') { global $allowExt, $uploadPath, $maxFileSize; //------------------max file size check from js $maxsize_regex = preg_match("/^(?'size'[\\d]+)(?'rang'[a-z]{0,1})\$/i", $maxFileSize, $match); $maxSize = 4 * 1024 * 1024; //default 4 M if ($maxsize_regex && is_numeric($match['size'])) { switch (strtoupper($match['rang'])) { case 'K': $maxSize = $match[1] * 1024; break; case 'M': $maxSize = $match[1] * 1024 * 1024; break; case 'G': $maxSize = $match[1] * 1024 * 1024 * 1024; break; case 'T': $maxSize = $match[1] * 1024 * 1024 * 1024 * 1024; break; default: $maxSize = $match[1]; //default 4 M } } if (!empty($maxFileSize) && $size > $maxSize) { echo json_encode(array('name' => $fileName, 'size' => $size, 'status' => 'error', 'info' => 'File size not allowed.')); return false; } //-----------------End max file size check //comment if not using windows web server $windowsReserved = array('CON', 'PRN', 'AUX', 'NUL', 'COM1', 'COM2', 'COM3', 'COM4', 'COM5', 'COM6', 'COM7', 'COM8', 'COM9', 'LPT1', 'LPT2', 'LPT3', 'LPT4', 'LPT5', 'LPT6', 'LPT7', 'LPT8', 'LPT9'); $badWinChars = array_merge(array_map('chr', range(0, 31)), array("<", ">", ":", '"', "/", "\\", "|", "?", "*")); $fileName = str_replace($badWinChars, '', $fileName); $fileInfo = pathinfo($fileName); $fileExt = $fileInfo['extension']; $fileBase = $fileInfo['filename']; //check if legal windows file name if (in_array($fileName, $windowsReserved)) { echo json_encode(array('name' => $fileName, 'size' => 0, 'status' => 'error', 'info' => 'File name not allowed. Windows reserverd.')); return false; } //check if is allowed extension if (!in_array($fileExt, $allowExt) && count($allowExt)) { echo json_encode(array('name' => $fileName, 'size' => 0, 'status' => 'error', 'info' => "Extension [{$fileExt}] not allowed.")); return false; } $fullPath = $uploadPath . $fileName; $c = 0; while (file_exists($fullPath)) { $c++; $fileName = $fileBase . "({$c})." . $fileExt; $fullPath = $uploadPath . $fileName; } return $fullPath; } if (isset($_FILES['ax-files'])) { //for eahc theorically runs only 1 time, since i upload i file per time foreach ($_FILES['ax-files']['error'] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $newName = !empty($fileName) ? $fileName : $_FILES['ax-files']['name'][$key]; $fullPath = checkFilename($newName, $_FILES['ax-files']['size'][$key]); if ($fullPath) { move_uploaded_file($_FILES['ax-files']['tmp_name'][$key], $fullPath); if (!empty($thumbWidth) || !empty($thumbHeight)) { createThumbGD($fullPath, $thumbPath, $thumbPostfix, $thumbWidth, $thumbHeight, $thumbFormat); } echo json_encode(array('name' => basename($fullPath), 'size' => filesize($fullPath), 'status' => 'uploaded', 'info' => 'File uploaded')); } } else { echo json_encode(array('name' => basename($_FILES['ax-files']['name'][$key]), 'size' => $_FILES['ax-files']['size'][$key], 'status' => 'error', 'info' => $error)); } } } elseif (isset($_REQUEST['ax-file-name'])) { //check only the first peice $fullPath = $currByte != 0 ? $uploadPath . $fileName : checkFilename($fileName, $html5fsize); if ($fullPath) { $flag = $currByte == 0 ? 0 : FILE_APPEND; $receivedBytes = file_get_contents('php://input'); //strange bug on very fast connections like localhost, some times cant write on file //TODO future version save parts on different files and then make join of parts while (@file_put_contents($fullPath, $receivedBytes, $flag) === false) { usleep(50); } if ($isLast == 'true') { createThumbGD($fullPath, $thumbPath, $thumbPostfix, $thumbWidth, $thumbHeight, $thumbFormat); } redim_imagen("./upload/" . $fullPath, "./upload/thumb_" . $fullPath, 240, 240, 1); $query = array('id' => '', 'author' => $id_user, 'fecha' => time(), 'path' => $fullPath, 'thumb' => 'thumb_' . $fullPath, 'active' => '0'); $this->db->insert('galeria', $query); activity_add($this->session->userdata('id'), '3'); echo json_encode(array('name' => basename($fullPath), 'size' => $currByte, 'status' => 'uploaded', 'info' => 'File/chunk uploaded')); } } } else { redirect('perfil'); } }