[26979] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
| 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
| 5 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 6 | // | it under the terms of the GNU General Public License as published by | |
---|
| 7 | // | the Free Software Foundation | |
---|
| 8 | // | | |
---|
| 9 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 10 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 11 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 12 | // | General Public License for more details. | |
---|
| 13 | // | | |
---|
| 14 | // | You should have received a copy of the GNU General Public License | |
---|
| 15 | // | along with this program; if not, write to the Free Software | |
---|
| 16 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 17 | // | USA. | |
---|
| 18 | // +-----------------------------------------------------------------------+ |
---|
| 19 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
| 20 | { |
---|
| 21 | die ("Hacking attempt!"); |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 25 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php'); |
---|
| 26 | |
---|
| 27 | $admin_base_url = get_root_url().'admin.php?page=plugin-Add_tags_mass-update'; |
---|
| 28 | |
---|
| 29 | // +-----------------------------------------------------------------------+ |
---|
| 30 | // | Checks | |
---|
| 31 | // +-----------------------------------------------------------------------+ |
---|
| 32 | |
---|
| 33 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | // +-----------------------------------------------------------------------+ |
---|
| 37 | // | Actions | |
---|
| 38 | // +-----------------------------------------------------------------------+ |
---|
| 39 | if (isset($_POST['submit'])){ |
---|
| 40 | |
---|
| 41 | if (isset($_POST['tagname']) and $_POST['tagname'] != "") |
---|
| 42 | { |
---|
| 43 | $starttime = get_moment(); |
---|
| 44 | |
---|
| 45 | $raw = stripslashes($_POST['tagname']); |
---|
| 46 | $raw_lines = explode("\n", $raw); |
---|
| 47 | array_walk($raw_lines, 'trim_value'); |
---|
| 48 | $raw_lines = array_filter($raw_lines); |
---|
| 49 | $raw_lines = array_values($raw_lines); |
---|
| 50 | |
---|
| 51 | $query = 'SELECT name FROM '.TAGS_TABLE.';'; |
---|
| 52 | $existing_tags = array_from_query($query, 'name'); |
---|
| 53 | array_walk($existing_tags, 'trim_value'); |
---|
| 54 | |
---|
| 55 | $update_files = array(); |
---|
| 56 | $missing_files = array(); |
---|
| 57 | |
---|
| 58 | foreach ($raw_lines as $tag_name) |
---|
| 59 | { |
---|
| 60 | |
---|
| 61 | if (!in_array($tag_name, $existing_tags)) |
---|
| 62 | { |
---|
| 63 | $update_files[$tag_name] = true; |
---|
| 64 | mass_inserts( |
---|
| 65 | TAGS_TABLE, |
---|
| 66 | array('name', 'url_name'), |
---|
| 67 | array( |
---|
| 68 | array( |
---|
| 69 | 'name' => addslashes($tag_name), |
---|
[30370] | 70 | 'url_name' => trigger_change('render_tag_url', $tag_name), |
---|
[26979] | 71 | ) |
---|
| 72 | ) |
---|
| 73 | ); |
---|
| 74 | } |
---|
| 75 | else |
---|
| 76 | { |
---|
| 77 | $missing_files[$tag_name] = true; |
---|
| 78 | } |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | $endtime = get_moment(); |
---|
| 82 | |
---|
| 83 | $elapsed = ($endtime - $starttime); |
---|
| 84 | |
---|
| 85 | array_push($page['infos'],stripslashes(sprintf(l10n('%d Add tags: %s'),count($update_files),implode(', ', array_keys($update_files))))); |
---|
| 86 | |
---|
| 87 | if (count($missing_files) > 0) |
---|
| 88 | { |
---|
| 89 | array_push($page['errors'],stripslashes(sprintf(l10n('%d Not add tags: %s'),count($missing_files),implode(', ', array_keys($missing_files))))); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | } |
---|
| 93 | else |
---|
| 94 | { |
---|
| 95 | $page['errors'][] = l10n('No tags'); |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | // +-----------------------------------------------------------------------+ |
---|
| 100 | // | form options | |
---|
| 101 | // +-----------------------------------------------------------------------+ |
---|
| 102 | |
---|
| 103 | // image level options |
---|
| 104 | $selected_level = isset($_POST['level']) ? $_POST['level'] : 0; |
---|
| 105 | $template->assign( |
---|
| 106 | array( |
---|
| 107 | 'level_options'=> get_privacy_level_options(), |
---|
| 108 | 'level_options_selected' => array($selected_level) |
---|
| 109 | ) |
---|
| 110 | ); |
---|
| 111 | |
---|
| 112 | // +-----------------------------------------------------------------------+ |
---|
| 113 | // | add function | |
---|
| 114 | // +-----------------------------------------------------------------------+ |
---|
| 115 | function trim_value(&$value) |
---|
| 116 | { |
---|
| 117 | $value = trim($value); |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | function encodeToUtf8($string) |
---|
| 121 | { |
---|
| 122 | return mb_convert_encoding($string, "UTF-8", mb_detect_encoding($string, "UTF-8, ISO-8859-15, ISO-8859-1", true)); |
---|
| 123 | } |
---|
[30370] | 124 | ?> |
---|