Changeset 7284 for extensions/gvideo/admin
- Timestamp:
- Oct 19, 2010, 11:57:57 PM (14 years ago)
- Location:
- extensions/gvideo/admin
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/gvideo/admin/add_page.php
r3946 r7284 2 2 3 3 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 4 5 include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php'); 4 6 5 7 $video_types = array('google', 'youtube', 'dailymotion', 'wideo', 'vimeo', 'wat'); … … 120 122 else 121 123 { 122 $cat = $_POST['parent']; 124 // current date 125 list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();')); 126 123 127 $video['name'] = str_replace(" ", "_", $_POST['pywaie_add_name']); 124 $catpath = get_fulldirs(array($cat)); 125 $path_file = $catpath[$cat] . '/' . $video['name'] . '.' . $video['ext']; 126 $thefile = substr($path_file, 2); 127 if (file_exists($path_file)) 128 { 129 array_push($page['errors'], sprintf(l10n('py_error6'), $thefile)); 130 } 128 $file_name = $video['name'].'.'.$video['ext']; 129 130 // prepare database registration 131 $insert = array( 132 'file' => $file_name, 133 'date_available' => $dbnow, 134 ); 135 136 $optional_fields = array('author', 'name', 'comment'); 137 foreach ($optional_fields as $field) 138 { 139 if (isset($_POST[$field]) and !empty($_POST[$field])) 140 { 141 $insert[$field] = $_POST[$field]; 142 } 143 } 144 145 check_input_parameter('parent', $_POST, false, PATTERN_ID); 146 $category_id = $_POST['parent']; 147 148 $query = ' 149 SELECT 150 c.id, 151 c.name, 152 c.permalink, 153 c.dir, 154 c.site_id, 155 s.galleries_url 156 FROM '.CATEGORIES_TABLE.' AS c 157 LEFT JOIN '.SITES_TABLE.' AS s ON s.id = c.site_id 158 WHERE c.id = '.$category_id.' 159 ;'; 160 $result = pwg_query($query); 161 $category = pwg_db_fetch_assoc($result); 162 163 // is the category virtual or is the category on a remote site? 164 $use_galleries_directory = true; 165 if (empty($category['dir'])) 166 { 167 $use_galleries_directory = false; 168 } 169 if (!empty($category['galleries_url']) and url_is_remote($category['galleries_url'])) 170 { 171 $use_galleries_directory = false; 172 } 173 174 if (!$use_galleries_directory) 175 { 176 list($year, $month, $day) = preg_split('/[^\d]/', $dbnow, 4); 177 178 // upload directory hierarchy 179 $upload_dir = sprintf( 180 PHPWG_ROOT_PATH.$conf['upload_dir'].'/%s/%s/%s', 181 $year, 182 $month, 183 $day 184 ); 185 prepare_directory($upload_dir); 186 187 $file_path = $upload_dir.'/'.$file_name; 188 $thumb_path = file_path_for_type($file_path, 'thumb'); 189 $thumb_dir = dirname($thumb_path); 190 prepare_directory($thumb_dir); 191 } 192 // or physical and local 131 193 else 132 194 { 133 $file = @fopen($thefile , 'w'); 134 135 // Ecriture du fichier et attribution des messages 136 if (@!fwrite ($file, stripslashes($video['id']) . '/' . $_POST['pywaie_add_h'] . '/' . $_POST['pywaie_add_w'] . '/' . $_POST['pywaie_add_start'])) 195 $catpath = get_fulldirs(array($category_id)); 196 $file_path = $catpath[$category_id].'/'.$file_name; 197 198 $insert['storage_category_id'] = $category_id; 199 } 200 201 $insert['path'] = $file_path; 202 203 if (file_exists($file_path)) 204 { 205 array_push($page['errors'], sprintf(l10n('py_error6'), $file_path)); 206 } 207 else 208 { 209 // Write fake file with video settings inside 210 // 211 // TODO: store these information in a specific database table instead 212 $file_content = stripslashes($video['id']); 213 $file_content.= '/'.$_POST['pywaie_add_h']; 214 $file_content.= '/'.$_POST['pywaie_add_w']; 215 $file_content.= '/'.$_POST['pywaie_add_start']; 216 217 $bytes_written = file_put_contents($file_path, $file_content); 218 if (false === $bytes_written) 137 219 { 138 array_push($page['errors'], sprintf(l10n('py_error7'), $thefile), sprintf(l10n('py_error8'), $catpath[$cat])); 220 array_push( 221 $page['errors'], 222 223 sprintf( 224 l10n('py_error7'), 225 $file_path 226 ), 227 228 sprintf( 229 l10n('py_error8'), 230 dirname($file_path) 231 ) 232 ); 233 139 234 } 140 235 else 141 236 { 142 // Miniatures143 $thumb_extension = 'NULL';237 // thumbnail 238 $thumb_extension = null; 144 239 if ($_POST['thumbnail'] == 'thumb_from_server' or $_POST['thumbnail'] == 'thumb_from_user') 145 240 { 146 include_once ('thumbnails.php'); 241 include_once ('thumbnails.php'); 242 $insert['tn_ext'] = $thumb_extension; 147 243 } 244 245 // database registration 246 mass_inserts( 247 IMAGES_TABLE, 248 array_keys($insert), 249 array($insert) 250 ); 148 251 149 // Synchronisation avec la base de donnees 150 $infos['name'] = (!empty($_POST['name']) ? '"' . $_POST['name'] . '"' : 'NULL'); 151 $infos['description'] = (!empty($_POST['description']) ? '"' . $_POST['description'] . '"' : 'NULL'); 152 $infos['author'] = (!empty($_POST['author']) ? '"' . $_POST['author'] . '"' : 'NULL'); 153 154 $query = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id FROM ' . IMAGES_TABLE . ' ;'; 155 list($next_element_id) = mysql_fetch_array(pwg_query($query)); 156 157 pwg_query('INSERT INTO ' . IMAGES_TABLE . ' ( id , file , date_available , date_creation , tn_ext , name , comment , author , hit , filesize , width , height , representative_ext , date_metadata_update , average_rate , has_high , path , storage_category_id , high_filesize ) 158 VALUES ( ' . $next_element_id . ', "' . $video['name'] . '.' . $video['ext'] . '", NOW() , NULL , ' . $thumb_extension . ' , ' . $infos['name'] . ' , ' . $infos['description'] . ' , ' . $infos['author'] . ' , 0 , NULL , NULL , NULL , NULL , NULL , NULL , NULL , "' . $path_file . '", ' . $cat . ', NULL);'); 159 pwg_query('INSERT INTO ' . IMAGE_CATEGORY_TABLE . ' ( image_id , category_id ) 160 VALUES ( ' . $next_element_id . ', ' . $cat . ');'); 161 162 $query = 'SELECT representative_picture_id FROM ' . CATEGORIES_TABLE . ' WHERE id =' . $cat . ';'; 163 list($result) = mysql_fetch_array(pwg_query($query)); 164 if ($result === NULL) 165 { 166 pwg_query('UPDATE ' . CATEGORIES_TABLE . ' SET representative_picture_id=' . $next_element_id . ' WHERE id = ' . $cat . ' LIMIT 1'); 167 } 168 252 $image_id = pwg_db_insert_id(IMAGES_TABLE); 253 associate_images_to_categories(array($image_id), array($category_id)); 169 254 invalidate_user_cache(); 170 array_unshift($page['infos'], sprintf(l10n('py_info3'), $thefile)); 171 array_push($page['infos'], sprintf(l10n('py_show_file'), PHPWG_ROOT_PATH . 'picture.php?/' . $next_element_id . '/category/' . $cat)); 172 @fclose($file); 255 256 // success information to display 257 array_unshift($page['infos'], sprintf(l10n('py_info3'), $file_path)); 258 259 array_push( 260 $page['infos'], 261 sprintf( 262 l10n('py_show_file'), 263 make_picture_url( 264 array( 265 'image_id' => $image_id, 266 'section' => 'categories', 267 'category' => $category, 268 ) 269 ) 270 ) 271 ); 173 272 } 174 273 } … … 178 277 179 278 180 // Affichage de la liste des categories 181 $site_locaux = array(); 279 // display list of all categories 182 280 $query = ' 183 SELECT id , galleries_url 184 FROM ' . SITES_TABLE . ' 185 ORDER by id'; 186 $result = pwg_query($query); 187 188 if (mysql_num_rows($result) > 0) 189 { 190 while (list($id , $galleries_url) = mysql_fetch_row($result)) 191 { 192 if (!url_is_remote($galleries_url)) array_push($site_locaux , $id); 193 } 194 } 195 if (empty($site_locaux)) 196 { 197 array_push($page['errors'], l10n('py_error1')); 198 $site_locaux = array(0); 199 } 200 201 $query = ' 202 SELECT id,name,uppercats,global_rank 203 FROM ' . CATEGORIES_TABLE . ' 204 WHERE site_id IN (' . implode("," , $site_locaux) . ');'; 205 206 if (isset($_POST['parent'])) $selected = array($_POST['parent']); 207 else $selected = array(); 281 SELECT 282 id, 283 name, 284 uppercats, 285 global_rank 286 FROM '.CATEGORIES_TABLE.' 287 ;'; 288 289 if (isset($_POST['parent'])) 290 { 291 $selected = array($_POST['parent']); 292 } 293 else 294 { 295 $selected = array(); 296 } 208 297 209 298 display_select_cat_wrapper($query, $selected , 'category_option_parent', false); … … 224 313 'NAME' => $_POST['name'], 225 314 'AUTHOR' => $_POST['author'], 226 ' DESCRIPTION' => $_POST['description']));315 'COMMENT' => $_POST['comment'])); 227 316 } 228 317 else -
extensions/gvideo/admin/add_page.tpl
r6225 r7284 127 127 <td>{'Description'|@translate}</td> 128 128 <td> 129 <textarea rows="4" cols="42" name=" description">{$DESCRIPTION}</textarea></td>129 <textarea rows="4" cols="42" name="comment">{$COMMENT}</textarea></td> 130 130 </tr> 131 131 -
extensions/gvideo/admin/thumbnails.php
r3609 r7284 112 112 { 113 113 $video['thumb_url'] = str_replace('&', '&', $video['thumb_url']); 114 if (($ path = mkget_thumbnail_dir($catpath[$cat], $error)) == false)114 if (($thumb_dir = mkget_thumbnail_dir(dirname($file_path), $error)) == false) 115 115 { 116 116 array_push($page['errors'], l10n('py_error9')); … … 118 118 else 119 119 { 120 $ path .= '/' . $conf['prefix_thumbnail'] . $video['name'] . '.jpg';121 if (file_exists($ path))120 $thumb_path = file_path_for_type($file_path, 'thumb'); 121 if (file_exists($thumb_path)) 122 122 { 123 123 array_push($page['errors'], sprintf(l10n('py_error11'), $path), l10n('py_error9')); … … 125 125 else 126 126 { 127 if (Py_RatioResizeImg($video['thumb_url'], $ path, $_POST['thumb_width'], $_POST['thumb_hight']))127 if (Py_RatioResizeImg($video['thumb_url'], $thumb_path, $_POST['thumb_width'], $_POST['thumb_hight'])) 128 128 { 129 129 array_push($page['infos'], l10n('py_info2')); 130 $thumb_extension = ' "jpg"';130 $thumb_extension = 'jpg'; 131 131 } 132 132 else … … 148 148 { 149 149 $ext = get_extension($_FILES['picture']['name']); 150 if (($ path = mkget_thumbnail_dir($catpath[$cat], $error)) == false)150 if (($thumb_dir = mkget_thumbnail_dir(dirname($file_path), $error)) == false) 151 151 { 152 152 array_push($page['errors'], l10n('py_error9')); … … 154 154 else 155 155 { 156 $ path .= '/' . $conf['prefix_thumbnail'] . $video['name'] . '.' .$ext;157 if (file_exists($ path))156 $thumb_path = get_filename_wo_extension(file_path_for_type($file_path, 'thumb')).'.'.$ext; 157 if (file_exists($thumb_path)) 158 158 { 159 array_push($page['errors'], sprintf(l10n('py_error11'), $ path), l10n('py_error9'));159 array_push($page['errors'], sprintf(l10n('py_error11'), $thumb_path), l10n('py_error9')); 160 160 } 161 161 else 162 162 { 163 if (Py_RatioResizeImg($_FILES['picture']['tmp_name'], $ path, $_POST['thumb_width'], $_POST['thumb_hight']))163 if (Py_RatioResizeImg($_FILES['picture']['tmp_name'], $thumb_path, $_POST['thumb_width'], $_POST['thumb_hight'])) 164 164 { 165 $thumb_extension = "\"$ext\"";165 $thumb_extension = $ext; 166 166 array_push($page['infos'], l10n('py_info2')); 167 167 }
Note: See TracChangeset
for help on using the changeset viewer.