source: extensions/pbase2piwigo/admin/import.php @ 17314

Last change on this file since 17314 was 17314, checked in by mistic100, 12 years ago
  • many small improvements
  • protect "generic" functions
  • complete localization
File size: 3.5 KB
Line 
1<?php
2if (!defined('PBASE_PATH')) die('Hacking attempt!');
3
4include_once(PBASE_PATH.'include/functions.inc.php');
5
6$step = null;
7
8if (test_remote_download() === false)
9{
10  array_push($page['errors'], l10n('No download method available. PBase2piwigo needs cURL extension or allow_url_fopen=true'));
11}
12else
13{
14  if (isset($_GET['action']))
15  {
16    switch ($_GET['action'])
17    {
18      case 'reset_tree':
19        unlink(PBASE_FS_CACHE.'tree.json');
20        redirect(PBASE_ADMIN.'-import');
21        break;
22    }
23  }
24  else
25  {
26    if (!file_exists(PBASE_FS_CACHE.'tree.json'))
27    {
28      $_GET['action'] = 'analyze';
29    }
30    else
31    {
32      $_GET['action'] = 'config';
33    }
34  }
35 
36  if (file_exists(PBASE_FS_CACHE.'tree.json'))
37  {
38    $tree = json_decode(file_get_contents(PBASE_FS_CACHE.'tree.json'), true);
39  }
40}
41
42
43switch ($_GET['action'])
44{
45  case 'analyze':
46  {
47    break;
48  }
49 
50  case 'config':
51  {
52    if (isset($_SESSION['pbase_empty_error']))
53    {
54      array_push($page['errors'], l10n('Import queue is empty'));
55      unset($_SESSION['pbase_empty_error']);
56    }
57   
58    // counters
59    $nb_categories = $nb_pictures = 0;
60    count_pictures_cats($tree, '/root', $nb_pictures, $nb_categories, true);
61   
62    // get piwigo categories
63    $query = '
64SELECT id, name, uppercats, global_rank
65  FROM '.CATEGORIES_TABLE.'
66;';
67    display_select_cat_wrapper($query, array(), 'associate_options');
68    display_select_cat_wrapper($query, array(), 'category_parent_options');
69   
70    $template->assign(array(
71      'nb_categories' => $nb_categories-1, // don't count root
72      'nb_pictures' => $nb_pictures,
73      'F_ACTION' => PBASE_ADMIN.'-import&amp;action=init_import',
74      'RESET_LINK' => PBASE_ADMIN.'-import&amp;action=reset_tree',
75      'TREE' => print_tree($tree, 0, 'select'),
76      ));
77    break;
78  }
79 
80  case 'init_import':
81  {
82    $categories = $_POST['categories'];
83    $nb_categories = $nb_pictures = 0;
84   
85    if (isset($_POST['recursive']))
86    {
87      // we don't add "root", only it's children
88      if (@$categories[0] == '/root')
89      {
90        $temp = &get_current_cat($tree, '/root');
91        $categories = array_merge($categories, array_values(array_unique_deep($temp['categories'], 'path')));
92        $categories = array_unique($categories);
93        unset($categories[0]);
94      }
95     
96      // remove duplicate categories (in case of recursive mode)
97      foreach ($categories as &$path)
98      {
99        if ( ($matches = array_pos('#'.$path.'/([\w/]+)#', $categories, true, true)) !== false)
100        {
101          foreach ($matches as $i) unset($categories[$i]);
102        }
103      }
104      unset($path);
105    }
106   
107    // count pictures and cats
108    $temp_cats = $categories;
109    foreach ($temp_cats as $path)
110    {
111      count_pictures_cats($tree, $path, $nb_pictures, $nb_categories, isset($_POST['recursive']));
112    }
113   
114    if ($nb_pictures == 0)
115    {
116      $_SESSION['pbase_empty_error'] = true;
117      redirect(PBASE_ADMIN.'-import');
118    }
119   
120    $template->assign(array(
121      'nb_pictures' => $nb_pictures,
122      'nb_categories' => $nb_categories,
123      'categories' => $categories,
124      'PARENT_CATEGORY' => $_POST['parent_category'],
125      'RECURSIVE' => boolean_to_string(isset($_POST['recursive'])),
126      'FILLS' => implode(',', @$_POST['fills']),
127      'MANAGE_LINK' => get_root_url().'admin.php?page=batch_manager&amp;cat=recent',
128      ));
129    break;
130  }
131}
132
133$template->assign('STEP', $_GET['action']);
134
135$template->set_filename('pbase2piwigo', dirname(__FILE__) . '/template/import.tpl');
136
137?>
Note: See TracBrowser for help on using the repository browser.