Changeset 17671 for extensions/properties_mass_update/admin_update.php
- Timestamp:
- Aug 30, 2012, 6:02:48 PM (12 years ago)
- File:
-
- 1 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 }
Note: See TracChangeset
for help on using the changeset viewer.