source: extensions/gvideo/batch.php @ 26524

Last change on this file since 26524 was 26524, checked in by mistic100, 10 years ago

add link in Admin Tools 'Edit' menu if available

File size: 3.1 KB
Line 
1<?php
2/*
3Plugin Name: EVideo Batch Import
4Version: 1.0
5Author: Mistic100
6*/
7
8global $gvideo_links, $gvideo_safe, $gvideo_film_frame, $gvideo_category;
9
10$gvideo_safe = false;
11$gvideo_film_frame = true;
12$gvideo_category = 0;
13$gvideo_links = '';
14
15
16add_event_handler('loc_begin_admin', 'gvideo_batch');
17
18function gvideo_batch()
19{
20  global $conf, $page, $gvideo_links, $gvideo_safe, $gvideo_film_frame, $gvideo_category;
21 
22  if (!defined('GVIDEO_PATH')) return;
23  if (@$_GET['page'] != 'plugin-gvideo') return;
24  if ($gvideo_category == 0 or empty($gvideo_links)) return;
25 
26  set_time_limit(600);
27 
28  $links = str_replace("\r\n", "\n", $gvideo_links);
29  $links = explode("\n", $links);
30  $links = array_map('trim', $links);
31 
32  include_once(GVIDEO_PATH.'include/functions.inc.php');
33  include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php');
34
35  foreach ($links as $url)
36  {
37    if (empty($url)) continue;
38    $error = false;
39   
40   
41    // check url
42    if ( ($video = parse_video_url($url, $gvideo_safe)) === false )
43    {
44      if ($gvideo_safe)
45      {
46        array_push($page['errors'], $url.' : '.l10n('an error happened'));
47        $error = true;
48      }
49      else
50      {
51        array_push($page['errors'], $url.' : '.l10n('Unable to contact host server'));
52        array_push($page['errors'], $url.' : '.l10n('Try in safe-mode'));
53        $error = true;
54      }
55    }
56   
57    if ($error) continue;
58   
59   
60    // download thumbnail
61    $thumb_ext = empty($video['thumbnail']) ? 'jpg' : get_extension($video['thumbnail']);
62    $thumb_name = $video['type'].'-'.$video['video_id'].'-'.uniqid().'.'.$thumb_ext;
63    $thumb_source = $conf['data_location'].$thumb_name;
64    if ( empty($video['thumbnail']) or gvideo_download_remote_file($video['thumbnail'], $thumb_source) !== true )
65    {
66      $thumb_source = $conf['data_location'].get_filename_wo_extension($thumb_name).'.jpg';
67      copy(GVIDEO_PATH.'mimetypes/'.$video['type'].'.jpg', $thumb_source);
68    }
69   
70    if ($gvideo_film_frame)
71    {
72      add_film_frame($thumb_source);
73    }
74   
75   
76    // add image and update infos
77    $image_id = add_uploaded_file($thumb_source, $thumb_name, array($gvideo_category));
78   
79    $updates = array(
80      'name' => pwg_db_real_escape_string($video['title']),
81      'author' => pwg_db_real_escape_string($video['author']),
82      'is_gvideo' => 1,
83      );
84   
85    if ( !empty($video['description']) )
86    {
87      $updates['comment'] = pwg_db_real_escape_string($video['description']);
88    }
89    if ( !empty($video['tags']) )
90    {
91      set_tags(get_tag_ids(str_replace("'", "\'", implode(',', $video['tags']))), $image_id);
92    }
93   
94    single_update(
95      IMAGES_TABLE,
96      $updates,
97      array('id' => $image_id),
98      true
99      );
100   
101    // register video
102    $insert = array(
103      'picture_id' => $image_id,
104      'url' => $video['url'],
105      'type' => $video['type'],
106      'video_id' => $video['video_id'],
107      'width' => '',
108      'height' => '',
109      'autoplay' => '',
110      );
111     
112    single_insert(
113      GVIDEO_TABLE,
114      $insert
115      );
116   
117    array_push($page['infos'], $url.' : '.l10n('Video successfully added'));
118  }
119}
120 
121?>
Note: See TracBrowser for help on using the repository browser.