Ignore:
Timestamp:
Aug 4, 2012, 4:15:54 PM (8 years ago)
Author:
mistic100
Message:
  • simplify add page
  • simplify migration task
  • add option to add film effect on element edition page
File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/gvideo/admin/add.php

    r17310 r17383  
    1212    array_push($page['errors'], l10n('Please fill the video URL'));
    1313  }
    14   if ($_POST['name_server'] == 'false' and empty($_POST['name']))
    15   {
    16     array_push($page['errors'], l10n('Please fill the video name'));
    17   }
    18   if ($_POST['thumbnail_server'] == 'false' and empty($_FILES['thumbnail_src']))
    19   {
    20     array_push($page['errors'], l10n('Please add a thumbnail'));
    21   }
    2214  if ( !empty($_POST['url']) and ($video = parse_video_url($_POST['url'])) === false )
    2315  {
     
    2820  {
    2921    // download thumbnail
    30     $thumb_name = $video['type'].'-'.$video['id'].'-'.uniqid();
    31     if ($_POST['thumbnail_server'] == 'true')
     22    $thumb_name = $video['type'].'-'.$video['id'].'-'.uniqid().'.'.get_extension($video['thumbnail']);
     23    $thumb_source = $conf['data_location'].$thumb_name;
     24    if (download_remote_file($video['thumbnail'], $thumb_source) !== true)
    3225    {
    33       $thumb_name.= '.'.get_extension($video['thumbnail']);
    34       $thumb_source = $conf['data_location'].$thumb_name;
    35       if (download_remote_file($video['thumbnail'], $thumb_source) !== true)
    36       {
    37         $thumb_source = $conf['data_location'].get_filename_wo_extension($thumb_name).'.jpg';
    38         copy(GVIDEO_PATH.'mimetypes/'.$video['type'].'.jpg', $thumb_source);
    39       }
    40     }
    41     // upload thumbnail
    42     else
    43     {
    44       if ($_FILES['thumbnail_src']['error'] > 0)
    45       {
    46         array_push($page['errors'], l10n('Unknown upload error'));
    47       }
    48       else if ( !in_array($_FILES['thumbnail_src']['type'], array('image/jpeg','image/png','image/gif')) )
    49       {
    50         array_push($page['errors'], l10n('Incorrect file type,').' '.sprintf(l10n('Allowed file types: %s.'), 'jpg, png, gif'));
    51       }
    52      
    53       $thumb_name.= '.'.get_extension($_FILES['thumbnail_src']['name']);
    54       $thumb_source = $_FILES['thumbnail_src']['tmp_name'];
     26      $thumb_source = $conf['data_location'].get_filename_wo_extension($thumb_name).'.jpg';
     27      copy(GVIDEO_PATH.'mimetypes/'.$video['type'].'.jpg', $thumb_source);
    5528    }
    5629   
    57     if (count($page['errors']) == 0)
     30    if (isset($_POST['add_film_frame']))
    5831    {
    59       if (isset($_POST['add_film_frame']))
    60       {
    61         add_film_frame($thumb_source);
    62       }
     32      add_film_frame($thumb_source);
     33    }
     34   
     35    // add image and update infos
     36    $image_id = add_uploaded_file($thumb_source, $thumb_name, array($_POST['category']));
     37   
     38    $updates = array(
     39      'name' => pwg_db_real_escape_string($video['title']),
     40      'comment' => pwg_db_real_escape_string($video['description']),
     41      'author' => pwg_db_real_escape_string($video['author']),
     42      );
     43   
     44    single_update(
     45      IMAGES_TABLE,
     46      $updates,
     47      array('id' => $image_id),
     48      true
     49      );
     50   
     51    // register video
     52    if ($_POST['size_common'] == 'true')
     53    {
     54      $_POST['width'] = $_POST['height'] = '';
     55    }
     56    if ($_POST['autoplay_common'] == 'true')
     57    {
     58      $_POST['autoplay'] = '';
     59    }
     60   
     61    $insert = array(
     62      'picture_id' => $image_id,
     63      'url' => $video['url'],
     64      'type' => $video['type'],
     65      'video_id' => $video['id'],
     66      'width' => $_POST['width'],
     67      'height' => $_POST['height'],
     68      'autoplay' => $_POST['autoplay'],
     69      );
    6370     
    64       // add image and update infos
    65       $image_id = add_uploaded_file($thumb_source, $thumb_name, array($_POST['category']));
     71    single_insert(
     72      GVIDEO_TABLE,
     73      $insert
     74      );
    6675     
    67       if ($_POST['name_server'] == 'true')        $_POST['name'] = $video['title'];
    68       if ($_POST['description_server'] == 'true') $_POST['description'] = $video['description'];
    69       if ($_POST['author_server'] == 'true')      $_POST['author'] = $video['author'];
    70      
    71       $updates = array(
    72         'name' => pwg_db_real_escape_string($_POST['name']),
    73         'comment' => pwg_db_real_escape_string(@$_POST['description']),
    74         'author' => pwg_db_real_escape_string(@$_POST['author']),
    75         );
    76      
    77       single_update(
    78         IMAGES_TABLE,
    79         $updates,
    80         array('id' => $image_id),
    81         true
    82         );
    83      
    84       // register video
    85       if ($_POST['size_common'] == 'true')
    86       {
    87         $_POST['width'] = $_POST['height'] = '';
    88       }
    89       if ($_POST['autoplay_common'] == 'true')
    90       {
    91         $_POST['autoplay'] = '';
    92       }
    93      
    94       $insert = array(
    95         'picture_id' => $image_id,
    96         'type' => $video['type'],
    97         'video_id' => $video['id'],
    98         'width' => $_POST['width'],
    99         'height' => $_POST['height'],
    100         'autoplay' => $_POST['autoplay'],
    101         );
    102        
    103       single_insert(
    104         GVIDEO_TABLE,
    105         $insert
    106         );
    107        
    108       array_push($page['infos'], sprintf(
    109         l10n('Video successfully added. <a href="%s">View</a>'),
    110         make_picture_url(array(
    111           'image_id' => $image_id,
    112           'category' => array(
    113             'id' => $_POST['category'],
    114             'name' => '',
    115             'permalink' => '',
    116             ),
    117           ))
    118         ));
    119       unset($_POST);
    120     }
     76    array_push($page['infos'], sprintf(
     77      l10n('Video successfully added. <a href="%s">View</a>'),
     78      make_picture_url(array(
     79        'image_id' => $image_id,
     80        'category' => array(
     81          'id' => $_POST['category'],
     82          'name' => '',
     83          'permalink' => '',
     84          ),
     85        ))
     86      ));
     87    unset($_POST);
    12188  }
    12289}
     
    143110  'upload_max_filesize' => $upload_max_filesize,
    144111  'upload_max_filesize_shorthand' => $upload_max_filesize_shorthand,
     112  'gd_available' => function_exists('imagecreatetruecolor'),
    145113  'gvideo' => $conf['gvideo'],
    146114  'POST' => @$_POST,
Note: See TracChangeset for help on using the changeset viewer.