Changeset 17671 for extensions/properties_mass_update
- Timestamp:
- Aug 30, 2012, 6:02:48 PM (12 years ago)
- Location:
- extensions/properties_mass_update
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/properties_mass_update/admin_update.php
r15389 r17671 31 31 32 32 // +-----------------------------------------------------------------------+ 33 // | Check Access and exit when user status is not ok|33 // | Checks | 34 34 // +-----------------------------------------------------------------------+ 35 35 36 36 check_status(ACCESS_ADMINISTRATOR); 37 37 38 $regex_for_separator = array( 39 'tab' => '/^([^\t]+)\t+(.*)$/', 40 'space' => '/^([^\s]+)\s+(.*)$/', 41 'comma' => '/^([^,]+),+(.*)$/', 42 'semicolon' => '/^([^;]+);+(.*)$/', 43 ); 44 45 if (isset($_POST['submit'])) 46 { 47 if (!in_array($_POST['separator'], array_keys($regex_for_separator))) 48 { 49 die('Hacking attempt!'); 50 } 51 52 if (!in_array($_POST['property'], array('name', 'comment', 'author', 'tags'))) 53 { 54 die('Hacking attempt!'); 55 } 56 } 57 38 58 // +-----------------------------------------------------------------------+ 39 // | actions|59 // | Actions | 40 60 // +-----------------------------------------------------------------------+ 41 61 … … 60 80 $raw_lines = explode("\n", $raw); 61 81 62 $query = 'SELECT file FROM '.IMAGES_TABLE.';';82 $query = 'SELECT id, file FROM '.IMAGES_TABLE.';'; 63 83 $existing_files = hash_from_query($query, 'file'); 64 84 … … 66 86 $update_files = array(); 67 87 $missing_files = array(); 88 $tags_of = array(); 68 89 69 90 foreach ($raw_lines as $raw_line) 70 91 { 71 if (!preg_match( '/^([^\t]+)\t+(.*)$/', $raw_line, $matches))92 if (!preg_match($regex_for_separator[$_POST['separator']], $raw_line, $matches)) 72 93 { 73 94 continue; … … 81 102 82 103 if (isset($existing_files[$matches[1]])) 83 { 104 { 84 105 $update_files[$matches[1]] = true; 106 $image_id = $existing_files[$matches[1]]['id']; 107 108 if ('tags' == $_POST['property']) 109 { 110 $tags_of[$image_id] = array(); 111 $raw_tags = explode(',', $matches[2]); 112 foreach ($raw_tags as $tag) 113 { 114 $tag = trim($tag); 115 if (empty($tag)) 116 { 117 continue; 118 } 119 $tag_id = tag_id_from_tag_name($tag); 120 array_push($tags_of[$image_id], $tag_id); 121 } 122 } 123 else 124 { 125 array_push( 126 $updates, 127 array( 128 'id' => $image_id, 129 $_POST['property'] => pwg_db_real_escape_string($matches[2]), // TODO right trim 130 ) 131 ); 132 } 85 133 } 86 134 else 87 135 { 88 136 $missing_files[$matches[1]] = true; 89 continue;90 137 } 91 92 array_push( 93 $updates, 138 } 139 140 if ('tags' == $_POST['property']) 141 { 142 set_tags_of($tags_of); 143 } 144 else 145 { 146 mass_updates( 147 IMAGES_TABLE, 94 148 array( 95 'file' => pwg_db_real_escape_string($matches[1]), 96 'comment' => pwg_db_real_escape_string($matches[2]), // TODO right trim 97 ) 149 'primary' => array('id'), 150 'update' => array($_POST['property']), 151 ), 152 $updates 98 153 ); 99 154 } 100 101 mass_updates(102 IMAGES_TABLE,103 array(104 'primary' => array('file'),105 'update' => array('comment'),106 ),107 $updates108 );109 155 110 156 $endtime = get_moment(); … … 115 161 sprintf( 116 162 l10n('%d photos updated'), 117 count( $updates)163 count(array_keys($update_files)) 118 164 ) 119 165 ); … … 134 180 else 135 181 { 136 array_push($page['errors'], $_FILES[' mascarille_update']['error']);182 array_push($page['errors'], $_FILES['update']['error']); 137 183 } 138 184 } -
extensions/properties_mass_update/admin_update.tpl
r15389 r17671 11 11 </p> 12 12 <input type="file" name="update"> 13 </fieldset> 14 15 <fieldset> 16 <legend>{'Options'|@translate}</legend> 17 18 <p style="margin:0 0 15px 0;"> 19 <strong>{'Separator'|@translate}</strong> 20 <br> 21 <select name="separator"> 22 <option value="tab">{'tab'|@translate}</option> 23 <option value="space">{'space'|@translate}</option> 24 <option value="comma">, ({'comma'|@translate})</option> 25 <option value="semicolon">; ({'semicolon'|@translate})</option> 26 </select> 27 </p> 28 29 <p style="margin:0;"> 30 <strong>{'Property to update'|@translate}</strong> 31 <br> 32 <select name="property"> 33 <option value="name">{'Title'|@translate}</option> 34 <option value="comment">{'Description'|@translate}</option> 35 <option value="author">{'Author'|@translate}</option> 36 <option value="tags">{'Tags'|@translate} {'(comma separated)'|@translate}</option> 37 </select> 38 </p> 39 40 </fieldset> 41 13 42 <p style="text-align:left"> 14 43 <input class="submit" type="submit" name="validate" value="{'Submit'|@translate}"> 15 44 </p> 16 </fieldset>17 45 </form> -
extensions/properties_mass_update/language/en_UK/plugin.lang.php
r15389 r17671 9 9 $lang['Wrong file, please select a plain text file'] = 'Wrong file, please select a plain text file'; 10 10 $lang['Update'] = 'Update'; 11 $lang['tab'] = 'tabulation'; 12 $lang['space'] = 'space'; 13 $lang['comma'] = 'comma'; 14 $lang['semicolon'] = 'semicolon'; 15 $lang['(comma separated)'] = '(comma separated)'; 11 16 ?> -
extensions/properties_mass_update/language/fr_FR/plugin.lang.php
r15508 r17671 21 21 // | USA. | 22 22 // +-----------------------------------------------------------------------+ 23 23 24 $lang['%d photos are missing in Piwigo: %s'] = '%d photos sont manquantes dans Piwigo : %s'; 24 25 $lang['%d photos updated'] = '%d photos mises à jour'; … … 30 31 $lang['Update'] = 'Mettre à jour'; 31 32 $lang['Wrong file, please select a plain text file'] = 'Mauvais type de fichier, veuillez sélectionner un fichier texte'; 33 $lang['tab'] = 'tabulation'; 34 $lang['space'] = 'espace'; 35 $lang['comma'] = 'virgule'; 36 $lang['semicolon'] = 'point virgule'; 37 $lang['(comma separated)'] = '(séparés par des virgules)'; 32 38 ?>
Note: See TracChangeset
for help on using the changeset viewer.