function make_new_avatar($array = null) { global $cbphoto, $userquery, $photo, $db, $cbcollection; if (is_null($array)) { $array = $_POST; } /* include resizer class */ include_once 'includes/classes/resizer.class.php'; $date_dir = get_photo_date_folder($photo); /* get original photo */ $p = get_original_photo($photo); /* define source and decode photo details */ $source = PHOTOS_DIR . '/' . $date_dir . '/' . $p; $pd = json_decode($photo['photo_details'], true); /* coordinates */ $x = mysql_clean($array['start_x']); $x2 = mysql_clean($array['end_x']); $y = mysql_clean($array['start_y']); $y2 = mysql_clean($array['end_y']); if (!is_numeric($x) || !is_numeric($x2) || !is_numeric($y) || !is_numeric($y2)) { e('Unable to crop. Coordinates were unrealiable.'); } else { /* * We will be using the original photo to crop the avatar. * First we'll covert the posted pixels to percentage * Second get pixels from original photo using percentage * Using newly computed pixels crop from original photo * Save it in avatar collection, make it source and start making avatars */ $xx = $x / $pd['l']['width'] * 100; // compute percentage $xx2 = $x2 / $pd['l']['width'] * 100; // compute percentage $newX = $xx * $pd['o']['width'] / 100; // compute pixels $newX2 = $xx2 * $pd['o']['width'] / 100; // compute pixels $yy = $y / $pd['l']['height'] * 100; // compute percentage $yy2 = $y2 / $pd['l']['height'] * 100; // compute percentage $newY = $yy * $pd['o']['height'] / 100; // compute pixels $newY2 = $yy2 * $pd['o']['height'] / 100; // compute pixels /* set source */ $r = new CB_Resizer($source); $filename = cb_filename(); $photopath = PHOTOS_DIR . '/' . createDataFolders(PHOTOS_DIR); $avatar_dir = USER_THUMBS_DIR . '/'; $uid = $userquery->udetails['userid']; $ext = $photo['ext']; $cid = cb_create_user_avatar_collection($userquery->udetails); /* Save the cropped as original source of photo. */ $new_photo = $r->target = $photopath . '/' . $filename . "." . $photo['ext']; $r->_crop($newX, $newY, $newX2, $newY2); $r->save(); $fields = array('photo_title' => 'Avatar', 'photo_description' => ' ', 'photo_tags' => ' ', 'filename' => $filename, 'userid' => $uid, 'ext' => $photo['ext'], 'is_avatar' => true, 'collection_id' => $cid); /* Inserting photo in user's avatar collection */ $photo_id = $cbphoto->insert_photo($fields); $avatar = $uid . '_' . $filename . '.' . $ext; $avatarpath = $avatar_dir . $avatar; /* Make $new_photo the source */ $r->source = $r->target; /* Big Thumb */ $r->target = $avatarpath; $r->_resize(AVATAR_SIZE, AVATAR_SIZE); $r->save(); /* Small Thumb */ $r->target = USER_THUMBS_DIR . '/' . $uid . '_' . $filename . '-small.' . $photo['ext']; $r->_resize(AVATAR_SMALL_SIZE, AVATAR_SMALL_SIZE); $r->save(); /* Update user avatar field */ $db->update(tbl('users'), array('avatar'), array($avatar), " userid = '" . $uid . "' "); /* Update cover photo of collection */ $cbcollection->set_cover_photo($photo_id, $cid); /* go back to photo */ redirect_to($cbphoto->photo_links($photo, 'view_photo')); /* go to user profile */ //redirect_to( $userquery->profile_link(userid()) ); } }
$mode = "upload"; } if ($_POST['insertVideo']) { $mode = "insert_video"; } if ($_POST['getForm']) { $mode = "get_form"; } if ($_POST['updateVideo'] == 'yes') { $mode = "update_video"; } switch ($mode) { case "insert_video": $title = getName($_POST['title']); $file_name = $_POST['file_name']; $file_directory = createDataFolders(); //dump($file_directory); $vidDetails = array('title' => $title, 'description' => $title, 'tags' => genTags(str_replace(' ', ', ', $title)), 'category' => array($cbvid->get_default_cid()), 'file_name' => $file_name, 'file_directory' => $file_directory, 'userid' => userid(), 'video_version' => '2.7'); $vid = $Upload->submit_upload($vidDetails); // sending curl request to content .ok $call_bk = PLUG_URL . "/cb_multiserver/api/call_back.php"; $ch = curl_init($call_bk); $ch_opts = array(CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_HTTPHEADER => array("Expect:")); $array = array("update" => TRUE); //curl_setopt($ch,CURLOPT_POSTFIELDS,$array); $charray = $ch_opts; $charray[CURLOPT_POSTFIELDS] = $array; curl_setopt_array($ch, $charray); curl_exec($ch); curl_close($ch); // inserting into video views as well
function create_dated_folder($headFolder = NULL, $custom_date = NULL) { return createDataFolders($headFolder, $custom_date); }
echo json_encode(array('success' => true, 'photo_id' => $photo_id, 'photo_preview' => $image_url)); } else { echo json_encode(array('error' => error())); } break; case "insert_photo": /* $_POST['photo_title'] = genTags(str_replace(array('_','-'),' ',$_POST['photo_title'])); $_POST['photo_description'] = genTags(str_replace(array('_','-'),' ',$_POST['photo_description'])); $_POST['photo_tags'] = genTags(str_replace(array(' ','_','-'),', ',$_POST['photo_tags'])); $_POST['server_url'] = mysql_clean($_POST['server_url']); $_POST['folder'] = str_replace('..','',mysql_clean($_POST['folder'])); */ $name = mysql_clean($_POST['title']); $filename = cb_filename(); $extension = GetExt($name); $name = str_replace('.' . $extension, '', $name); $photo_dir = createDataFolders(PHOTOS_DIR); $post_data = array('photo_title' => $name, 'photo_description' => $name, 'photo_tags' => genTags(str_replace(array(' ', '_', '-'), ', ', $name)), 'filename' => $filename, 'folder' => $photo_dir, 'collection_id' => mysql_clean($_POST['collection']), 'ext' => $extension); $insert_id = $cbphoto->insert_photo($post_data); if (error()) { $response['error'] = error(); } if (msg()) { $response['success'] = true; $response['id'] = $insert_id; $response['file'] = $filename; $response['extension'] = $extension; $response['file_directory'] = $photo_dir; } echo json_encode($response); break; case "update_photo":
$collection = $_POST['collection']; $photoArray = array("photo_title" => $name, "photo_description" => $name, "photo_tags" => $name, "collection_id" => $collection); assign("uniqueID", $_POST['objID']); assign("photoArray", $photoArray); $form = Fetch("/blocks/upload/photo_form.html"); echo json_encode(array("form" => $form)); break; case "insert_photo": $_POST['photo_title'] = genTags(str_replace(array('_', '-'), ' ', $_POST['photo_title'])); $_POST['photo_description'] = genTags(str_replace(array('_', '-'), ' ', $_POST['photo_description'])); $_POST['photo_tags'] = genTags(str_replace(array(' ', '_', '-'), ', ', $_POST['photo_tags'])); $_POST['collection_id'] = $_POST['collection_id']; $_POST['server_url'] = mysql_clean($_POST['server_url']); $_POST['active'] = 'no'; $_POST['folder'] = str_replace('..', '', mysql_clean($_POST['folder'])); $_POST['folder'] = createDataFolders(PHOTOS_DIR); $_POST['filename'] = mysql_clean($_POST['file_name']); $insert_id = $cbphoto->insert_photo(); if (error()) { $response['error'] = error('single'); } if (msg()) { $response['success'] = msg('single'); $response['photoID'] = $insert_id; $details = $cbphoto->get_photo($insert_id); $details["filename"] = $_POST["file_name"]; $details["ext"] = getExt($_POST["title"]); $cbphoto->generate_photos($details); //var_dump($details); $params = array("details" => $details, "size" => "m"); //var_dump($params);
//Finish Writing File fclose($temp_fo); //var_dump($curlOpt); sleep(2); $details = $logDetails; //file_get_contents($log_file); //$details = json_decode($details,true); $targetFileName = $file_name . '.' . $ext; $Upload->add_conversion_queue($targetFileName); if (file_exists($log_file)) { unlink($log_file); } if (file_exists($dummy_file)) { unlink($dummy_file); } $quick_conv = config('quick_conv'); $use_crons = config('use_crons'); //Inserting data $title = urldecode(mysql_clean(getName($file))); $title = $title ? $title : "Untitled"; $vidDetails = array('title' => $title, 'description' => $title, 'duration' => $total, 'tags' => genTags(str_replace(' ', ', ', $title)), 'category' => array($cbvid->get_default_cid()), 'file_name' => $file_name, 'userid' => userid(), 'file_directory' => createDataFolders()); $vid = $Upload->submit_upload($vidDetails); echo json_encode(array('vid' => $vid)); if ($quick_conv == 'yes' || $use_crons == 'no') { //exec(php_path()." -q ".BASEDIR."/actions/video_convert.php &> /dev/null &"); if (stristr(PHP_OS, 'WIN')) { exec(php_path() . " -q " . BASEDIR . "/actions/video_convert.php {$targetFileName} sleep"); } else { exec(php_path() . " -q " . BASEDIR . "/actions/video_convert.php {$targetFileName} sleep&> /dev/null &"); } }