[17225] | 1 | <?php |
---|
[26201] | 2 | defined('PBASE_PATH') or die('Hacking attempt!'); |
---|
[17225] | 3 | |
---|
| 4 | include_once(PBASE_PATH.'include/functions.inc.php'); |
---|
| 5 | |
---|
| 6 | $step = null; |
---|
| 7 | |
---|
[26201] | 8 | if (!test_remote_download()) |
---|
[17225] | 9 | { |
---|
[26201] | 10 | $page['errors'][] = l10n('No download method available. PBase2piwigo needs cURL extension or allow_url_fopen=true'); |
---|
[17225] | 11 | } |
---|
| 12 | else |
---|
| 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 | |
---|
| 43 | switch ($_GET['action']) |
---|
| 44 | { |
---|
| 45 | case 'analyze': |
---|
| 46 | { |
---|
| 47 | break; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | case 'config': |
---|
| 51 | { |
---|
[17314] | 52 | if (isset($_SESSION['pbase_empty_error'])) |
---|
| 53 | { |
---|
[26201] | 54 | $page['errors'][] = l10n('Import queue is empty'); |
---|
[17314] | 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 = ' |
---|
| 64 | SELECT id, name, uppercats, global_rank |
---|
| 65 | FROM '.CATEGORIES_TABLE.' |
---|
| 66 | ;'; |
---|
| 67 | display_select_cat_wrapper($query, array(), 'category_parent_options'); |
---|
| 68 | |
---|
[17225] | 69 | $template->assign(array( |
---|
[17314] | 70 | 'nb_categories' => $nb_categories-1, // don't count root |
---|
| 71 | 'nb_pictures' => $nb_pictures, |
---|
[17225] | 72 | 'F_ACTION' => PBASE_ADMIN.'-import&action=init_import', |
---|
| 73 | 'RESET_LINK' => PBASE_ADMIN.'-import&action=reset_tree', |
---|
| 74 | 'TREE' => print_tree($tree, 0, 'select'), |
---|
| 75 | )); |
---|
| 76 | break; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | case 'init_import': |
---|
| 80 | { |
---|
| 81 | $categories = $_POST['categories']; |
---|
[17314] | 82 | $nb_categories = $nb_pictures = 0; |
---|
[17225] | 83 | |
---|
| 84 | if (isset($_POST['recursive'])) |
---|
| 85 | { |
---|
[17314] | 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) |
---|
[17225] | 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 | |
---|
[17314] | 113 | if ($nb_pictures == 0) |
---|
| 114 | { |
---|
| 115 | $_SESSION['pbase_empty_error'] = true; |
---|
| 116 | redirect(PBASE_ADMIN.'-import'); |
---|
| 117 | } |
---|
| 118 | |
---|
[17225] | 119 | $template->assign(array( |
---|
| 120 | 'nb_pictures' => $nb_pictures, |
---|
| 121 | 'nb_categories' => $nb_categories, |
---|
| 122 | 'categories' => $categories, |
---|
[17314] | 123 | 'PARENT_CATEGORY' => $_POST['parent_category'], |
---|
[17225] | 124 | 'RECURSIVE' => boolean_to_string(isset($_POST['recursive'])), |
---|
| 125 | 'FILLS' => implode(',', @$_POST['fills']), |
---|
| 126 | 'MANAGE_LINK' => get_root_url().'admin.php?page=batch_manager&cat=recent', |
---|
| 127 | )); |
---|
| 128 | break; |
---|
| 129 | } |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | $template->assign('STEP', $_GET['action']); |
---|
| 133 | |
---|
[26201] | 134 | $template->set_filename('pbase2piwigo', realpath(PBASE_PATH . 'admin/template/import.tpl')); |
---|