source: extensions/BatchDownloader/main.inc.php @ 23539

Last change on this file since 23539 was 23323, checked in by mistic100, 11 years ago

move remove_image.php code to a trigger on init

File size: 3.4 KB
Line 
1<?php 
2/*
3Plugin Name: Batch Downloader
4Version: auto
5Description: Allows users to download pictures sets in ZIP. Compatible with User Collections.
6Plugin URI: auto
7Author: Mistic
8Author URI: http://www.strangeplanet.fr
9*/
10
11defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
12
13global $conf, $prefixeTable;
14
15defined('BATCH_DOWNLOAD_ID') or define('BATCH_DOWNLOAD_ID', basename(dirname(__FILE__)));
16define('BATCH_DOWNLOAD_PATH',    PHPWG_PLUGINS_PATH . BATCH_DOWNLOAD_ID . '/');
17define('BATCH_DOWNLOAD_TSETS',   $prefixeTable . 'download_sets');
18define('BATCH_DOWNLOAD_TIMAGES', $prefixeTable . 'download_sets_images');
19define('IMAGE_SIZES_TABLE',      $prefixeTable . 'image_sizes');
20define('BATCH_DOWNLOAD_LOCAL',   PHPWG_ROOT_PATH . $conf['data_location'] . 'download_archives/');
21define('BATCH_DOWNLOAD_ADMIN',   get_root_url() . 'admin.php?page=plugin-' . BATCH_DOWNLOAD_ID);
22define('BATCH_DOWNLOAD_PUBLIC',  get_absolute_root_url() . make_index_url(array('section' => 'download')) . '/');
23define('BATCH_DOWNLOAD_VERSION', 'auto');
24
25
26add_event_handler('init', 'batch_download_init');
27
28if (defined('IN_ADMIN'))
29{
30  add_event_handler('get_admin_plugin_menu_links', 'batch_download_admin_menu');
31}
32else
33{
34  add_event_handler('init', 'batch_downloader_remove_image');
35 
36  add_event_handler('loc_end_section_init', 'batch_download_section_init');
37  add_event_handler('loc_end_index', 'batch_download_page');
38
39  add_event_handler('loc_end_index', 'batch_download_clean');
40
41  add_event_handler('loc_end_index', 'batch_download_index_button', EVENT_HANDLER_PRIORITY_NEUTRAL+10);
42
43  add_event_handler('blockmanager_register_blocks', 'batch_download_add_menublock');
44  add_event_handler('blockmanager_apply', 'batch_download_applymenu');
45}
46
47
48include_once(BATCH_DOWNLOAD_PATH . 'include/BatchDownloader.class.php');
49include_once(BATCH_DOWNLOAD_PATH . 'include/functions.inc.php');
50include_once(BATCH_DOWNLOAD_PATH . 'include/events.inc.php');
51
52
53
54/**
55 * update plugin & unserialize conf & load language
56 */
57function batch_download_init()
58{
59  global $conf, $pwg_loaded_plugins;
60 
61  if (
62    BATCH_DOWNLOAD_VERSION == 'auto' or
63    $pwg_loaded_plugins[BATCH_DOWNLOAD_ID]['version'] == 'auto' or
64    version_compare($pwg_loaded_plugins[BATCH_DOWNLOAD_ID]['version'], BATCH_DOWNLOAD_VERSION, '<')
65  )
66  {
67    include_once(BATCH_DOWNLOAD_PATH . 'include/install.inc.php');
68    batch_download_install();
69   
70    if ( $pwg_loaded_plugins[BATCH_DOWNLOAD_ID]['version'] != 'auto' and BATCH_DOWNLOAD_VERSION != 'auto' )
71    {
72      $query = '
73UPDATE '. PLUGINS_TABLE .'
74SET version = "'. BATCH_DOWNLOAD_VERSION .'"
75WHERE id = "'. BATCH_DOWNLOAD_ID .'"';
76      pwg_query($query);
77     
78      $pwg_loaded_plugins[BATCH_DOWNLOAD_ID]['version'] = BATCH_DOWNLOAD_VERSION;
79     
80      if (defined('IN_ADMIN'))
81      {
82        $_SESSION['page_infos'][] = 'BatchDownloader updated to version '. BATCH_DOWNLOAD_VERSION;
83      }
84    }
85  }
86 
87  $conf['batch_download'] = unserialize($conf['batch_download']);
88  $conf['batch_download']['allowed_ext'] = $conf['picture_ext'];
89  if (!empty($conf['batch_download_additional_ext']))
90  {
91    $conf['batch_download']['allowed_ext'] = array_merge($conf['batch_download']['allowed_ext'], $conf['batch_download_additional_ext']);
92  }
93 
94  load_language('plugin.lang', BATCH_DOWNLOAD_PATH);
95}
96
97/**
98 * admin plugins menu
99 */
100function batch_download_admin_menu($menu) 
101{
102  array_push($menu, array(
103    'NAME' => 'Batch Downloader',
104    'URL' => BATCH_DOWNLOAD_ADMIN,
105  ));
106  return $menu;
107}
108
109?>
Note: See TracBrowser for help on using the repository browser.