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

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

update for 2.6

File size: 3.4 KB
Line 
1<?php
2defined('PBASE_PATH') or die('Hacking attempt!');
3
4include_once(PBASE_PATH.'include/functions.inc.php');
5
6$step = null;
7
8if (!test_remote_download())
9{
10  $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      $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(), 'category_parent_options');
68   
69    $template->assign(array(
70      'nb_categories' => $nb_categories-1, // don't count root
71      'nb_pictures' => $nb_pictures,
72      'F_ACTION' => PBASE_ADMIN.'-import&amp;action=init_import',
73      'RESET_LINK' => PBASE_ADMIN.'-import&amp;action=reset_tree',
74      'TREE' => print_tree($tree, 0, 'select'),
75      ));
76    break;
77  }
78 
79  case 'init_import':
80  {
81    $categories = $_POST['categories'];
82    $nb_categories = $nb_pictures = 0;
83   
84    if (isset($_POST['recursive']))
85    {
86      // we don't add "root", only it's children
87      if (@$categories[0] == '/root')
88      {
89        $temp = &get_current_cat($tree, '/root');
90        $categories = array_merge($categories, array_values(array_unique_deep($temp['categories'], 'path')));
91        $categories = array_unique($categories);
92        unset($categories[0]);
93      }
94     
95      // remove duplicate categories (in case of recursive mode)
96      foreach ($categories as &$path)
97      {
98        if ( ($matches = array_pos('#'.$path.'/([\w/]+)#', $categories, true, true)) !== false)
99        {
100          foreach ($matches as $i) unset($categories[$i]);
101        }
102      }
103      unset($path);
104    }
105   
106    // count pictures and cats
107    $temp_cats = $categories;
108    foreach ($temp_cats as $path)
109    {
110      count_pictures_cats($tree, $path, $nb_pictures, $nb_categories, isset($_POST['recursive']));
111    }
112   
113    if ($nb_pictures == 0)
114    {
115      $_SESSION['pbase_empty_error'] = true;
116      redirect(PBASE_ADMIN.'-import');
117    }
118   
119    $template->assign(array(
120      'nb_pictures' => $nb_pictures,
121      'nb_categories' => $nb_categories,
122      'categories' => $categories,
123      'PARENT_CATEGORY' => $_POST['parent_category'],
124      'RECURSIVE' => boolean_to_string(isset($_POST['recursive'])),
125      'FILLS' => implode(',', @$_POST['fills']),
126      'MANAGE_LINK' => get_root_url().'admin.php?page=batch_manager&amp;cat=recent',
127      ));
128    break;
129  }
130}
131
132$template->assign('STEP', $_GET['action']);
133
134$template->set_filename('pbase2piwigo', realpath(PBASE_PATH . 'admin/template/import.tpl'));
Note: See TracBrowser for help on using the repository browser.