Ejemplo n.º 1
0
 /**
  * Retrieve image thumbnail
  * 
  * @param  string $mime
  * @return string
  */
 function get_thumbnail($mime, $forImage)
 {
     if (is_image($mime)) {
         return $forImage;
     } elseif (is_video($mime)) {
         return "/vendor/inoplate-media/images/medias/video_128px.png";
     } elseif (is_audio($mime)) {
         return "/vendor/inoplate-media/images/medias/music_128px.png";
     } elseif ($mime == 'application/excel' || $mime == 'application/vnd.ms-excel' || $mime == 'application/x-excel' || $mime == 'application/x-msexcel') {
         return "/vendor/inoplate-media/images/medias/xls_128px.png";
     } elseif ($mime == 'application/mspowerpoint' || $mime == 'application/powerpoint' || $mime == 'application/vnd.ms-powerpoint' || $mime == 'application/x-mspowerpoint') {
         return "/vendor/inoplate-media/images/medias/xls_128px.png";
     } else {
         return "/vendor/inoplate-media/images/medias/file_128px.png";
     }
 }
Ejemplo n.º 2
0
function is_known_filetype($file)
{
    return is_image($file) || is_movie($file) || is_audio($file) || is_document($file);
}
Ejemplo n.º 3
0
 /**
  * Compare two strings in multiple ways
  * @param: { string } { $str1  } { first string of comparison }
  * @param: { string } { $str2 } { second string of comaparison }
  * @param: { string } { $action } { what to do with strings. See documentation for detail }
  * @param: { boolean } { $msg } { false by default. shows error if true }
  * @param: { boolean / string } { $hasWord } { false by default. if true, it is word to search in strings }
  */
 function str_vs_str($str1, $str2, $action, $msg = false, $hasWord = false)
 {
     if (empty($str1) || empty($str2)) {
         if ($msg) {
             echo 'One of provided string is empty';
         }
         return false;
     } elseif (!is_nan($str1) || !is_nan($str2)) {
         if ($msg) {
             echo 'One of provided strings is invalid';
         }
         return false;
     } elseif ($str1 == $str2) {
         if ($msg) {
             echo 'Strings must not be equal';
         }
         return false;
     } else {
         switch ($action) {
             case 'longer':
                 if (strlen($str1) > strlen($str2)) {
                     if ($msg) {
                         echo $str1 . ' is longer';
                     }
                     return $str1;
                 } else {
                     if ($msg) {
                         echo $str1 . ' is not longer';
                         return false;
                     }
                     return false;
                 }
                 break;
             case 'shorter':
                 if (strlen($str1) < strlen($str2)) {
                     if ($msg) {
                         echo $str1 . ' is shorter';
                     }
                     return $str1;
                 } else {
                     if ($msg) {
                         echo $str1 . ' is not shorter';
                         return false;
                     }
                     return false;
                 }
                 break;
             case 'hasWord':
                 if (empty($hasWord)) {
                     if ($msg) {
                         echo 'Word not provided';
                     }
                 } elseif (strrpos($str1, $hasWord)) {
                     if ($msg) {
                         echo $str1 . ' has word ' . $hasWord;
                     }
                     return $str1;
                 } elseif (strpos($str2, $hasWord)) {
                     if ($msg) {
                         echo $str2 . ' has word ' . $hasWord;
                     }
                     return $str2;
                 } else {
                     if ($msg) {
                         echo 'Word was not found';
                     }
                     return false;
                 }
                 break;
             case 'same_web':
                 if (!$this->is_url($str1) || !$this->is_url($str2)) {
                     if ($msg) {
                         echo 'One of provided is not a URL';
                     }
                     return false;
                 } elseif ($this->which_site($str1) != $this->which_site($str2)) {
                     if ($msg) {
                         echo 'URL are not of same website';
                     }
                 } elseif ($this->which_site($str1) == $this->which_site($str2)) {
                     if ($msg) {
                         echo 'URL are of same website';
                     }
                     return $this->which_site($str1);
                 } else {
                     if ($msg) {
                         echo 'Error occured trying to compare URL';
                     }
                     return false;
                 }
                 break;
             case 'same_type':
                 $str1_type = pathinfo($str1_type, PATHINFO_EXTENSION);
                 $str2_type = pathinfo($str2_type, PATHINFO_EXTENSION);
                 if ($str1_type == $str2_type) {
                     if ($msg) {
                         echo 'Both files are of same format';
                     }
                     return $str1_type;
                 } else {
                     if ($msg) {
                         echo 'Files are not of same type';
                     }
                     return false;
                 }
                 break;
             case 'are_videos':
                 $str1_vid = is_video($sr1);
                 $str2_vid = is_video($str2);
                 if ($str1_vid && $str2_vid) {
                     if ($msg) {
                         echo 'Both are videos';
                     }
                     return $str1_vid;
                 } elseif ($str1_vid && !$str2_vid) {
                     if ($msg) {
                         echo 'Second file is not video';
                     }
                     return false;
                 } elseif (!$str1_vid && $str2_vid) {
                     if ($msg) {
                         echo 'First file is not video';
                     }
                     return false;
                 } else {
                     if ($msg) {
                         echo 'Could not determine file types';
                     }
                     return false;
                 }
                 break;
             case 'are_photos':
                 $str1_photo = is_photo($sr1);
                 $str2_photo = is_photo($str2);
                 if ($str1_photo && $str2_photo) {
                     if ($msg) {
                         echo 'Both are photos';
                     }
                     return $str1_photo;
                 } elseif ($str1_photo && !$str2_photo) {
                     if ($msg) {
                         echo 'Second file is not photo';
                     }
                     return false;
                 } elseif (!$str1_photo && $str2_photo) {
                     if ($msg) {
                         echo 'First file is not photo';
                     }
                     return false;
                 } else {
                     if ($msg) {
                         echo 'Could not determine file types';
                     }
                     return false;
                 }
                 break;
             case 'are_sounds':
                 $str1_audio = is_audio($sr1);
                 $str2_audio = is_audio($str2);
                 if ($str1_audio && $str2_audio) {
                     if ($msg) {
                         echo 'Both are audios';
                     }
                     return $str1_audio;
                 } elseif ($str1_audio && !$str2_audio) {
                     if ($msg) {
                         echo 'Second file is not audio';
                     }
                     return false;
                 } elseif (!$str1_audio && $str2_audio) {
                     if ($msg) {
                         echo 'First file is not audio';
                     }
                     return false;
                 } else {
                     if ($msg) {
                         echo 'Could not determine file types';
                     }
                     return false;
                 }
                 break;
             case 'are_links':
                 $str1_url = $this->is_url($sr1);
                 $str2_url = $this->is_url($str2);
                 if ($str1_url && $str2_url) {
                     if ($msg) {
                         echo 'Both are URLs';
                     }
                     return $str1_url;
                 } elseif ($str1_url && !$str2_url) {
                     if ($msg) {
                         echo 'Second file is not URL';
                     }
                     return false;
                 } elseif (!$str1_url && $str2_url) {
                     if ($msg) {
                         echo 'First file is not URL';
                     }
                     return false;
                 } else {
                     if ($msg) {
                         echo 'Could not determine file types';
                     }
                     return false;
                 }
                 break;
             case 'are_excu':
                 if (is_executable($str1) && is_executable($str2)) {
                     if ($msg) {
                         echo 'Both files are executable';
                     }
                     return $str1;
                 } elseif (!is_executable($str1) && is_executable($str2)) {
                     if ($msg) {
                         echo 'First file is not executable';
                     }
                     return false;
                 } elseif (is_executable($str1) && !is_executable($str2)) {
                     if ($msg) {
                         echo 'Second file is not executable';
                     }
                     return false;
                 } else {
                     //
                 }
                 break;
             default:
                 # code...
                 break;
         }
     }
 }
Ejemplo n.º 4
0
 $form_array = array(array($lang_upload_php['album'], 'album', 2), array($lang_upload_php['pic_title'], 'title', 0, 255, 1, $title), array($captionLabel, 'caption', 3, $CONFIG['max_img_desc_length'], isset($iptc['Caption']) ? $iptc['Caption'] : ''), array($lang_upload_php['keywords'], 'keywords', 0, 255, 1, isset($iptc['Keywords']) ? implode(' ', $iptc['Keywords']) : ''), array('control', 'phase_2', 4), array('unique_ID', $_POST['unique_ID'], 4));
 // Check for user defined fields.
 if (!empty($CONFIG['user_field1_name'])) {
     $form_array[] = array($CONFIG['user_field1_name'], 'user1', 0, 255, 1);
 }
 if (!empty($CONFIG['user_field2_name'])) {
     $form_array[] = array($CONFIG['user_field2_name'], 'user2', 0, 255, 1);
 }
 if (!empty($CONFIG['user_field3_name'])) {
     $form_array[] = array($CONFIG['user_field3_name'], 'user3', 0, 255, 1);
 }
 if (!empty($CONFIG['user_field4_name'])) {
     $form_array[] = array($CONFIG['user_field4_name'], 'user4', 0, 255, 1);
 }
 // Check for movies and audio, and create width and height boxes if true.
 if (is_movie($file_set[1]) or is_audio($file_set[1])) {
     //Add width and height boxes to the form.
     $form_array[] = array($lang_admin_php['th_wd'], 'movie_wd', 0, 4, 1);
     $form_array[] = array($lang_admin_php['th_ht'], 'movie_ht', 0, 4, 1);
 }
 // Create the form and echo more instructions.
 create_form($form_array);
 // More instructions.
 if (count($escrow_array) > '1') {
     form_statement($lang_upload_php['place_instr_2']);
 }
 // Make button say 'Continue.'
 close_form($lang_continue);
 // Close the table, create footers, and flush the output buffer.
 endtable();
 pagefooter();
Ejemplo n.º 5
0
    symlink($target, $local_path);
}
// If the original exists //
if (file_exists($origin_path)) {
    // Create Directory //
    if (!file_exists($local_dir)) {
        mkdir($local_dir, 0644, true);
        // Recursive //
    }
    // If we have an output extension, then we know we're doing something //
    if ($file_out_ext) {
        $src_is_image = is_image($file_ext);
        $src_is_video = is_video($file_ext);
        $src_is_audio = is_audio($file_ext);
        // Audio to Audio //
        if ($src_is_audio && is_audio($file_out_ext)) {
            // Bail if using any extra arguments (so we don't regenerate useless files) //
            if ($file_out_args > 0) {
                EmitErrorAndExit("ERROR: A2A extra args");
            }
            //			header("Content-Type: text/plain");
            //			print_r( get_media_info($origin_path) );
            EmitErrorAndExit("ERROR: A2A conversion not supported");
            // Video to Audio //
            // ffmpeg -i input-video.avi -vn -acodec copy output-audio.aac
            // -vn = no video
            // -acoced copy = copy the audio
        } else {
            if (($src_is_video || $file_ext == 'gif') && is_video($file_out_ext)) {
                // Bail if using any extra arguments (so we don't regenerate useless files) //
                if ($file_out_args > 0) {
Ejemplo n.º 6
0
function add_picture($aid, $filepath, $filename, $title = '', $caption = '', $keywords = '', $user1 = '', $user2 = '', $user3 = '', $user4 = '', $category = 0)
{
    global $xoopsModuleConfig, $ERROR, $USER_DATA, $PIC_NEED_APPROVAL;
    global $xoopsDB, $xoopsUser, $picinID, $_SERVER;
    $myts =& MyTextSanitizer::getInstance();
    // MyTextSanitizer object
    $image = $xoopsModuleConfig['fullpath'] . $filepath . $filename;
    $normal = $xoopsModuleConfig['fullpath'] . $filepath . $xoopsModuleConfig['normal_pfx'] . $filename;
    $thumb = $xoopsModuleConfig['fullpath'] . $filepath . $xoopsModuleConfig['thumb_pfx'] . $filename;
    $imagesize = getimagesize($image);
    if (!$imagesize) {
        if (is_movie($image)) {
            $filename_wo_ext = substr($filename, 0, strrpos($filename, '.'));
            $thm_image = get_real_path() . $filepath . $filename_wo_ext . ".thm";
            if (file_exists($thm_image)) {
                copy($thm_image, $thumb);
                copy($thm_image, $normal);
            } else {
                copy(XOOPS_ROOT_PATH . "/modules/xcgal/images/thumb_avi.jpg", $thumb);
                copy(XOOPS_ROOT_PATH . "/modules/xcgal/images/thumb_avi.jpg", $normal);
            }
            $imagesize[0] = 320;
            $imagesize[1] = 240;
        } elseif (is_audio($image)) {
            $filename_wo_ext = substr($filename, 0, strrpos($filename, '.'));
            $thm_image = get_real_path() . $filepath . $filename_wo_ext . ".thm";
            if (file_exists($thm_image)) {
                copy($thm_image, $thumb);
                copy($thm_image, $normal);
            } else {
                copy(XOOPS_ROOT_PATH . "/modules/xcgal/images/thumb_mp3.jpg", $thumb);
                copy(XOOPS_ROOT_PATH . "/modules/xcgal/images/thumb_mp3.jpg", $normal);
            }
            $imagesize[0] = 320;
            $imagesize[1] = 240;
        }
    } else {
        if (!file_exists($thumb)) {
            if (!resize_image($image, $thumb, $xoopsModuleConfig['thumb_width'], $xoopsModuleConfig['thumb_method'])) {
                return false;
            }
        }
        if (max($imagesize[0], $imagesize[1]) > $xoopsModuleConfig['picture_width'] && $xoopsModuleConfig['make_intermediate'] && !file_exists($normal)) {
            if (!resize_image($image, $normal, $xoopsModuleConfig['picture_width'], $xoopsModuleConfig['thumb_method'])) {
                return false;
            }
        }
    }
    $image_filesize = filesize($image);
    $total_filesize = $image_filesize + (file_exists($normal) ? filesize($normal) : 0) + filesize($thumb);
    // Test if disk quota exceeded
    if (!USER_IS_ADMIN && $USER_DATA['group_quota']) {
        if (is_object($xoopsUser)) {
            $quota_opt = "owner_id = '" . USER_ID . "'";
        } else {
            $quota_opt = "ip = '" . $_SERVER['REMOTE_ADDR'] . "'";
        }
        $result = $xoopsDB->query("SELECT sum(total_filesize) FROM " . $xoopsDB->prefix("xcgal_pictures") . " WHERE {$quota_opt}");
        $record = $xoopsDB->fetchArray($result);
        $total_space_used = $record['sum(total_filesize)'];
        //echo $total_space_used;
        $xoopsDB->freeRecordSet($result);
        if ($total_space_used + $total_filesize > $USER_DATA['group_quota'] << 10) {
            @unlink($image);
            @unlink($normal);
            @unlink($thumb);
            $msg = strtr(_MD_QUOTA_EXCEEDED, array('[quota]' => $USER_DATA['group_quota'], '[space]' => $total_space_used >> 10));
            redirect_header('index.php', 2, $msg);
        }
    }
    // Test if picture requires approval
    if (!$USER_DATA['priv_upl_need_approval'] && $category == FIRST_USER_CAT + USER_ID) {
        $approved = 'YES';
    } elseif (!$USER_DATA['pub_upl_need_approval']) {
        $approved = 'YES';
    } else {
        $approved = 'NO';
    }
    $PIC_NEED_APPROVAL = $approved == 'NO';
    // User ID is not recorded when in admin mode (ie. for batch uploads)
    $user_id = USER_ID;
    $user_name = USER_NAME;
    $query = "INSERT INTO " . $xoopsDB->prefix("xcgal_pictures") . " (aid, filepath, filename, filesize, total_filesize, pwidth, pheight, mtime, ctime, owner_id, owner_name, title, caption, keywords, approved, user1, user2, user3, user4, ip) VALUES ('{$aid}', '" . $myts->makeTboxData4Save($filepath) . "', '" . $myts->makeTboxData4Save($filename) . "', '{$image_filesize}', '{$total_filesize}', '{$imagesize[0]}', '{$imagesize[1]}','" . time() . "', '" . time() . "', '{$user_id}','{$user_name}', '{$title}', '{$caption}', '{$keywords}', '{$approved}', '{$user1}', '{$user2}', '{$user3}', '{$user4}','" . $_SERVER['REMOTE_ADDR'] . "')";
    $result = $xoopsDB->queryf($query);
    if ($approved == 'YES') {
        $picinID = $xoopsDB->getInsertId();
    }
    if ($approved == 'YES' && is_object($xoopsUser)) {
        $xoopsUser->incrementPost();
    }
    return $result;
}
Ejemplo n.º 7
0
 }
 $uploaded_pic = $dest_dir . $picture_name;
 // Move the picture into its final location
 if (!move_uploaded_file($_FILES['userpicture']['tmp_name'], $uploaded_pic)) {
     redirect_header('index.php', 2, sprintf(_MD_DB_ERR_MOVE, $picture_name, $dest_dir));
 }
 // Change file permission
 chmod($uploaded_pic, octdec($xoopsModuleConfig['default_file_mode']));
 // Get picture information
 $imginfo = getimagesize($uploaded_pic);
 //media
 if (!$imginfo && is_movie($uploaded_pic)) {
     $imginfo[0] = 320;
     $imginfo[1] = 240;
     $movie_picture = true;
 } elseif (!$imginfo && is_audio($uploaded_pic)) {
     $imginfo[0] = 320;
     $imginfo[1] = 240;
     $movie_picture = true;
 } elseif (!$imginfo && is_document($uploaded_pic)) {
     $imginfo[0] = 320;
     $imginfo[1] = 240;
     $movie_picture = true;
 } else {
     $movie_picture = false;
 }
 // Check that picture size (in pixels) is lower than the maximum allowed
 if (max($imginfo[0], $imginfo[1]) > $xoopsModuleConfig['max_upl_width_height']) {
     @unlink($uploaded_pic);
     redirect_header('index.php', 2, sprintf(_MD_DB_ERR_PIC_SIZE, $xoopsModuleConfig['max_upl_width_height'], $xoopsModuleConfig['max_upl_width_height']));
     // Check that picture file size is lower than the maximum allowed