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

Last change on this file since 17225 was 17225, checked in by ddtddt, 12 years ago

[extensions] - pbase2piwigo - new extension by mistic - first release

File size: 2.3 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    $template->assign(array(
53      'F_ACTION' => PBASE_ADMIN.'-import&amp;action=init_import',
54      'RESET_LINK' => PBASE_ADMIN.'-import&amp;action=reset_tree',
55      'TREE' => print_tree($tree, 0, 'select'),
56      ));
57    break;
58  }
59 
60  case 'init_import':
61  {
62    $categories = $_POST['categories'];
63   
64    // remove duplicate categories (in case of recursive mode)
65    if (isset($_POST['recursive']))
66    {
67      foreach ($categories as &$path)
68      {
69        if ( ($matches = array_pos('#'.$path.'/([\w/]+)#', $categories, true, true)) !== false)
70        {
71          foreach ($matches as $i) unset($categories[$i]);
72        }
73      }
74      unset($path);
75    }
76   
77    // count pictures and cats
78    $temp_cats = $categories;
79    $nb_categories = $nb_pictures = 0;
80    foreach ($temp_cats as $path)
81    {
82      count_pictures_cats($tree, $path, $nb_pictures, $nb_categories, isset($_POST['recursive']));
83    }
84   
85    $template->assign(array(
86      'nb_pictures' => $nb_pictures,
87      'nb_categories' => $nb_categories,
88      'categories' => $categories,
89      'RECURSIVE' => boolean_to_string(isset($_POST['recursive'])),
90      'FILLS' => implode(',', @$_POST['fills']),
91      'MANAGE_LINK' => get_root_url().'admin.php?page=batch_manager&amp;cat=recent',
92      ));
93    break;
94  }
95}
96
97$template->assign('STEP', $_GET['action']);
98
99$template->set_filename('pbase2piwigo', dirname(__FILE__) . '/template/import.tpl');
100
101?>
Note: See TracBrowser for help on using the repository browser.