plugins/gallery/functions.php
changeset 45 740bbe1f4dd5
parent 42 7c6e2e97aa08
equal deleted inserted replaced
44:17cfc3da0dcc 45:740bbe1f4dd5
   432  * @param string Filename
   432  * @param string Filename
   433  * @param int Folder, defaults to NULL (root)
   433  * @param int Folder, defaults to NULL (root)
   434  * @return int image ID
   434  * @return int image ID
   435  */
   435  */
   436 
   436 
   437 function snapr_insert_image($path, $folder_id = NULL)
   437 function snapr_insert_image($path, $folder_id = NULL, $orig_filename = false)
   438 {
   438 {
   439 	global $db, $session, $paths, $template, $plugins; // Common objects
   439 	global $db, $session, $paths, $template, $plugins; // Common objects
   440 	
   440 	
   441 	$ext = get_file_extension($path);
   441 	$usename = $orig_filename ? $orig_filename : $path;
       
   442 	$ext = get_file_extension($usename);
   442 	$ourfilename = gallery_make_filename() . "." . strtolower($ext);
   443 	$ourfilename = gallery_make_filename() . "." . strtolower($ext);
   443 	if ( !snapr_extension_allowed($ext) )
   444 	if ( !snapr_extension_allowed($ext) )
   444 		return false;
   445 	{
       
   446 		echo "Banned extension: $ext";
       
   447 		return false;
       
   448 	}
   445 	
   449 	
   446 	// copy the file to the storage folder
   450 	// copy the file to the storage folder
   447 	if ( !rename($path, ENANO_ROOT . "/files/$ourfilename") )
   451 	if ( !rename($path, ENANO_ROOT . "/files/$ourfilename") )
   448 		return false;
   452 	{
       
   453 		echo "Rename failed: $path -> files/$ourfilename";
       
   454 		return false;
       
   455 	}
   449 	
   456 	
   450 	// insert the image into the database
   457 	// insert the image into the database
   451 	$folder = $folder_id === NULL ? 'NULL' : strval(intval($folder_id));
   458 	$folder = $folder_id === NULL ? 'NULL' : strval(intval($folder_id));
   452 	$title = ucwords(str_replace('_', ' ', basename($path)));
   459 	$title = ucwords(str_replace('_', ' ', $usename));
   453 	$title = preg_replace("/\.{$ext}\$/i", '', $title);
   460 	$title = preg_replace("/\.{$ext}\$/i", '', $title);
   454 	$sz = serialize(array());
   461 	$sz = serialize(array());
   455 	$now = time();
   462 	$now = time();
   456 	$q = $db->sql_query('INSERT INTO ' . table_prefix . "gallery(is_folder, folder_parent, img_title, print_sizes, img_filename, img_time_upload, img_time_mod, img_tags, img_author, processed) VALUES\n"
   463 	$q = $db->sql_query('INSERT INTO ' . table_prefix . "gallery(is_folder, folder_parent, img_title, print_sizes, img_filename, img_time_upload, img_time_mod, img_tags, img_author, processed) VALUES\n"
   457 		              . "	(0, $folder, '$title', '$sz', '$ourfilename', $now, $now, '[]', $session->user_id, 0);");
   464 		              . "	(0, $folder, '$title', '$sz', '$ourfilename', $now, $now, '[]', $session->user_id, 0);");