Changeset 17671


Ignore:
Timestamp:
Aug 30, 2012, 6:02:48 PM (12 years ago)
Author:
plg
Message:

new feature: ability to select the property to update (title, description, author, tags)

new feature: ability to select the separator (tab, space, comma, semicolon)

Location:
extensions/properties_mass_update
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/properties_mass_update/admin_update.php

    r15389 r17671  
    3131
    3232// +-----------------------------------------------------------------------+
    33 // | Check Access and exit when user status is not ok                      |
     33// | Checks                                                                |
    3434// +-----------------------------------------------------------------------+
    3535
    3636check_status(ACCESS_ADMINISTRATOR);
    3737
     38$regex_for_separator = array(
     39  'tab' => '/^([^\t]+)\t+(.*)$/',
     40  'space' => '/^([^\s]+)\s+(.*)$/',
     41  'comma' => '/^([^,]+),+(.*)$/',
     42  'semicolon' => '/^([^;]+);+(.*)$/',
     43  );
     44
     45if (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
    3858// +-----------------------------------------------------------------------+
    39 // |                                actions                                |
     59// | Actions                                                               |
    4060// +-----------------------------------------------------------------------+
    4161
     
    6080      $raw_lines = explode("\n", $raw);
    6181     
    62       $query = 'SELECT file FROM '.IMAGES_TABLE.';';
     82      $query = 'SELECT id, file FROM '.IMAGES_TABLE.';';
    6383      $existing_files = hash_from_query($query, 'file');
    6484           
     
    6686      $update_files = array();
    6787      $missing_files = array();
     88      $tags_of = array();
    6889     
    6990      foreach ($raw_lines as $raw_line)
    7091      {
    71         if (!preg_match('/^([^\t]+)\t+(.*)$/', $raw_line, $matches))
     92        if (!preg_match($regex_for_separator[$_POST['separator']], $raw_line, $matches))
    7293        {
    7394          continue;
     
    81102
    82103        if (isset($existing_files[$matches[1]]))
    83         {       
     104        {
    84105          $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          }
    85133        }
    86134        else
    87135        {
    88136          $missing_files[$matches[1]] = true;
    89           continue;
    90137        }
    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,
    94148          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
    98153          );
    99154      }
    100      
    101       mass_updates(
    102         IMAGES_TABLE,
    103           array(
    104             'primary' => array('file'),
    105             'update' => array('comment'),
    106           ),
    107           $updates
    108         );
    109155
    110156      $endtime = get_moment();
     
    115161        sprintf(
    116162          l10n('%d photos updated'),
    117           count($updates)
     163          count(array_keys($update_files))
    118164          )
    119165        );
     
    134180  else
    135181  {
    136     array_push($page['errors'], $_FILES['mascarille_update']['error']);
     182    array_push($page['errors'], $_FILES['update']['error']);
    137183  }
    138184}
  • extensions/properties_mass_update/admin_update.tpl

    r15389 r17671  
    1111  </p>
    1212<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
    1342<p style="text-align:left">
    1443<input class="submit" type="submit" name="validate" value="{'Submit'|@translate}">
    1544</p>
    16 </fieldset>
    1745</form>
  • extensions/properties_mass_update/language/en_UK/plugin.lang.php

    r15389 r17671  
    99$lang['Wrong file, please select a plain text file'] = 'Wrong file, please select a plain text file';
    1010$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)';
    1116?>
  • extensions/properties_mass_update/language/fr_FR/plugin.lang.php

    r15508 r17671  
    2121// | USA.                                                                  |
    2222// +-----------------------------------------------------------------------+
     23
    2324$lang['%d photos are missing in Piwigo: %s'] = '%d photos sont manquantes dans Piwigo : %s';
    2425$lang['%d photos updated'] = '%d photos mises à jour';
     
    3031$lang['Update'] = 'Mettre à jour';
    3132$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)';
    3238?>
Note: See TracChangeset for help on using the changeset viewer.