Changeset 29970


Ignore:
Timestamp:
Oct 9, 2014, 10:10:48 PM (10 years ago)
Author:
plg
Message:

compatibility with Piwigo 2.7

For now, we keep uploadify (Flash) on Community because it is more compatible
with old browsers like IE8/IE9. Once the new HTML5 upload form will be more
mature, we will replace uploadify on Community too.

Location:
extensions/community
Files:
8 added
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • extensions/community/add_photos.php

    r29266 r29970  
    7171}
    7272
    73 include_once(PHPWG_ROOT_PATH.'admin/include/photos_add_direct_process.inc.php');
     73include_once(COMMUNITY_PATH.'include/photos_add_direct_process.inc.php');
    7474
    7575// +-----------------------------------------------------------------------+
     
    379379$template->set_filenames(array('add_photos' => dirname(__FILE__).'/add_photos.tpl'));
    380380
     381// +-----------------------------------------------------------------------+
     382// | Uploaded photos                                                       |
     383// +-----------------------------------------------------------------------+
     384
     385if (isset($page['thumbnails']))
     386{
     387  $template->assign(
     388    array(
     389      'thumbnails' => $page['thumbnails'],
     390      )
     391    );
     392
     393  // only display the batch link if we have more than 1 photo
     394  if (count($page['thumbnails']) > 1)
     395  {
     396    $template->assign(
     397      array(
     398        'batch_link' => $page['batch_link'],
     399        'batch_label' => sprintf(
     400          l10n('Manage this set of %d photos'),
     401          count($page['thumbnails'])
     402          ),
     403        )
     404      );
     405  }
     406}
     407
    381408include_once(PHPWG_ROOT_PATH.'admin/include/photos_add_direct_prepare.inc.php');
    382409
     
    412439}
    413440
     441$upload_modes = array('html', 'multiple');
     442$upload_mode = isset($conf['upload_mode']) ? $conf['upload_mode'] : 'multiple';
     443
     444if (isset($_GET['upload_mode']) and $upload_mode != $_GET['upload_mode'] and in_array($_GET['upload_mode'], $upload_modes))
     445{
     446  $upload_mode = $_GET['upload_mode'];
     447  conf_update_param('upload_mode', $upload_mode);
     448}
     449
     450// what is the upload switch mode
     451$index_of_upload_mode = array_flip($upload_modes);
     452$upload_mode_index = $index_of_upload_mode[$upload_mode];
     453$upload_switch = $upload_modes[ ($upload_mode_index + 1) % 2 ];
     454
    414455$template->assign(
    415456  array(
     457    'uploadify_path' => COMMUNITY_PATH.'uploadify',
    416458    'upload_file_types' => implode(', ', $unique_exts),
    417459    'uploadify_fileTypeExts' => implode(';', prepend_append_array_items($uploadify_exts, '*.', '')),
     460    'upload_mode' => $upload_mode,
     461    'form_action' => PHOTOS_ADD_BASE_URL.'&upload_mode='.$upload_mode.'&processed=1',
     462    'switch_url' => PHOTOS_ADD_BASE_URL.'&upload_mode='.$upload_switch,
     463    'upload_id' => md5(rand()),
     464    'session_id' => session_id(),
     465    'another_upload_link' => PHOTOS_ADD_BASE_URL.'&upload_mode='.$upload_mode,
    418466    )
    419467  );
  • extensions/community/add_photos.tpl

    r27037 r29970  
    11{if $upload_mode eq 'multiple'}
    22{combine_script id='jquery.jgrowl' load='footer' require='jquery' path='themes/default/js/plugins/jquery.jgrowl_minimized.js' }
    3 {combine_script id='jquery.uploadify' load='footer' require='jquery' path='admin/include/uploadify/jquery.uploadify.v3.0.0.min.js' }
     3{combine_script id='jquery.uploadify' load='footer' require='jquery' path='plugins/community/uploadify/jquery.uploadify.v3.0.0.min.js' }
    44{combine_script id='jquery.ui.progressbar' load='footer'}
    55{combine_css path="themes/default/js/plugins/jquery.jgrowl.css"}
    6 {combine_css path="admin/include/uploadify/uploadify.css"}
     6{combine_css path="plugins/community/uploadify/uploadify.css"}
    77{/if}
    88
     
    260260    'langFile'       : uploadify_path + '/uploadifyLang_en.js',
    261261    'swf'            : uploadify_path + '/uploadify.swf',
     262    'checkExisting'  : false,
    262263
    263264    buttonCursor     : 'pointer',
     
    497498      {'Parent album'|@translate}<br>
    498499      <select id ="category_parent" name="category_parent">
     500{if $create_whole_gallery}
    499501        <option value="0">------------</option>
     502{/if}
    500503        {html_options options=$category_parent_options selected=$category_parent_options_selected}
    501504      </select>
  • extensions/community/main.inc.php

    r27038 r29970  
    2424define('COMMUNITY_PERMISSIONS_TABLE', $prefixeTable.'community_permissions');
    2525define('COMMUNITY_PENDINGS_TABLE', $prefixeTable.'community_pendings');
    26 define('COMMUNITY_VERSION', 'auto');
    2726
    2827include_once(COMMUNITY_PATH.'include/functions_community.inc.php');
     
    3837function community_init()
    3938{
    40   global $conf, $user, $pwg_loaded_plugins;
    41 
    42   // apply upgrade if needed
    43   if (
    44     COMMUNITY_VERSION == 'auto' or
    45     $pwg_loaded_plugins[COMMUNITY_ID]['version'] == 'auto' or
    46     safe_version_compare($pwg_loaded_plugins[COMMUNITY_ID]['version'], COMMUNITY_VERSION, '<')
    47   )
    48   {
    49     // call install function
    50     include_once(COMMUNITY_PATH.'include/install.inc.php');
    51     community_install();
    52 
    53     // update plugin version in database
    54     if ( $pwg_loaded_plugins[COMMUNITY_ID]['version'] != 'auto' and COMMUNITY_VERSION != 'auto' )
    55     {
    56       $query = '
    57 UPDATE '. PLUGINS_TABLE .'
    58 SET version = "'. COMMUNITY_VERSION .'"
    59 WHERE id = "'. COMMUNITY_ID .'"';
    60       pwg_query($query);
    61 
    62       $pwg_loaded_plugins[COMMUNITY_ID]['version'] = COMMUNITY_VERSION;
    63     }
    64   }
     39  global $conf, $user;
    6540
    6641  // prepare plugin configuration
    67   $conf['community'] = unserialize($conf['community']);
     42  $conf['community'] = safe_unserialize($conf['community']);
    6843
    6944  // TODO: generate permissions in $user['community_permissions'] if ws.php
     
    416391    {
    417392      $row['name'] = strip_tags(
    418         trigger_event(
     393        trigger_change(
    419394          'render_category_name',
    420395          $row['name'],
     
    425400   
    426401    $row['comment'] = strip_tags(
    427       trigger_event(
     402      trigger_change(
    428403        'render_category_description',
    429404        $row['comment'],
  • extensions/community/maintain.class.php

    r29905 r29970  
    22defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');
    33
    4 if (!defined("COMMUNITY_PATH"))
     4class community_maintain extends PluginMaintain
    55{
    6   define('COMMUNITY_PATH', PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)));
    7 }
     6  private $installed = false;
    87
    9 include_once(COMMUNITY_PATH.'/include/install.inc.php');
    10 
    11 function plugin_install()
    12 {
    13   community_install();
    14   define('community_installed', true);
    15 }
    16 
    17 function plugin_uninstall()
    18 {
    19   global $prefixeTable;
    20  
    21   $query = 'DROP TABLE '.$prefixeTable.'community_permissions;';
    22   pwg_query($query);
    23 
    24   $query = 'DROP TABLE '.$prefixeTable.'community_pendings;';
    25   pwg_query($query);
    26 
    27   $query = 'ALTER TABLE '.$prefixeTable.'categories drop column community_user;';
    28   pwg_query($query);
    29 
    30   // delete configuration
    31   pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param IN ("community", "community_cache_key");');
    32 }
    33 
    34 function plugin_activate()
    35 {
    36   global $prefixeTable;
    37  
    38   if (!defined('community_installed')) // a plugin is activated just after its installation
     8  function __construct($plugin_id)
    399  {
    40     community_install();
     10    parent::__construct($plugin_id);
    4111  }
    4212
    43   community_get_data_from_core21();
    44   community_get_data_from_community21();
     13  function install($plugin_version, &$errors=array())
     14  {
     15    global $conf, $prefixeTable;
     16   
     17    $query = '
     18CREATE TABLE IF NOT EXISTS '.$prefixeTable.'community_permissions (
     19  id int(11) NOT NULL AUTO_INCREMENT,
     20  type varchar(255) NOT NULL,
     21  group_id smallint(5) unsigned DEFAULT NULL,
     22  user_id mediumint(8) unsigned DEFAULT NULL,
     23  category_id smallint(5) unsigned DEFAULT NULL,
     24  user_album enum(\'true\',\'false\') NOT NULL DEFAULT \'false\',
     25  recursive enum(\'true\',\'false\') NOT NULL DEFAULT \'true\',
     26  create_subcategories enum(\'true\',\'false\') NOT NULL DEFAULT \'false\',
     27  moderated enum(\'true\',\'false\') NOT NULL DEFAULT \'true\',
     28  nb_photos int DEFAULT NULL,
     29  storage int DEFAULT NULL,
     30  PRIMARY KEY (id)
     31) ENGINE=MyISAM DEFAULT CHARSET=utf8
     32;';
     33    pwg_query($query);
    4534
    46   $query = '
     35    $query = '
     36CREATE TABLE IF NOT EXISTS '.$prefixeTable.'community_pendings (
     37  image_id mediumint(8) unsigned NOT NULL,
     38  state varchar(255) NOT NULL,
     39  added_on datetime NOT NULL,
     40  validated_by mediumint(8) unsigned DEFAULT NULL
     41) ENGINE=MyISAM DEFAULT CHARSET=utf8
     42;';
     43    pwg_query($query);
     44
     45    // column community_permissions.nb_photos added for version 2.5.d
     46    $result = pwg_query('SHOW COLUMNS FROM `'.$prefixeTable.'community_permissions` LIKE "nb_photos";');
     47    if (!pwg_db_num_rows($result))
     48    {     
     49      pwg_query('ALTER TABLE `'.$prefixeTable .'community_permissions` ADD `nb_photos` INT DEFAULT NULL;');
     50    }
     51 
     52    // column community_permissions.storage added for version 2.5.d
     53    $result = pwg_query('SHOW COLUMNS FROM `'.$prefixeTable.'community_permissions` LIKE "storage";');
     54    if (!pwg_db_num_rows($result))
     55    {     
     56      pwg_query('ALTER TABLE `'.$prefixeTable .'community_permissions` ADD `storage` INT DEFAULT NULL;');
     57    }
     58
     59    // column community_permissions.user_album added for version 2.5.d
     60    $result = pwg_query('SHOW COLUMNS FROM `'.$prefixeTable.'community_permissions` LIKE "user_album";');
     61    if (!pwg_db_num_rows($result))
     62    {     
     63      pwg_query('ALTER TABLE `'.$prefixeTable .'community_permissions` ADD `user_album` enum(\'true\',\'false\') NOT NULL DEFAULT \'false\' after `category_id`;');
     64    }
     65
     66    // column categories.community_user added for version 2.5.d
     67    $result = pwg_query('SHOW COLUMNS FROM `'.$prefixeTable.'categories` LIKE "community_user";');
     68    if (!pwg_db_num_rows($result))
     69    {     
     70      pwg_query('ALTER TABLE `'.$prefixeTable .'categories` ADD `community_user` mediumint unsigned DEFAULT NULL;');
     71    }
     72
     73    // Piwigo 2.7 enlarges user ids, from smallint to mediumint
     74    $to_enlarge_ids = array(
     75      $prefixeTable.'community_permissions.user_id',
     76      $prefixeTable.'community_pendings.validated_by',
     77      $prefixeTable.'categories.community_user',
     78      );
     79
     80    foreach ($to_enlarge_ids as $to_enlarge_id)
     81    {
     82      list($table, $column) = explode('.', $to_enlarge_id);
     83
     84      $row = pwg_db_fetch_assoc(pwg_query('SHOW COLUMNS FROM `'.$table.'` LIKE "'.$column.'";'));
     85      if ($row['Type'] != 'mediumint')
     86      {
     87        $query = 'ALTER TABLE '.$table.' CHANGE '.$column.' '.$column.' MEDIUMINT UNSIGNED DEFAULT NULL;';
     88        pwg_query($query);
     89      }
     90    }
     91
     92    if (!isset($conf['community']))
     93    {
     94      $community_default_config = array(
     95        'user_albums' => false,
     96        );
     97     
     98      conf_update_param('community', $community_default_config, true);
     99    }
     100   
     101    $this->installed = true;
     102  }
     103
     104  function activate($plugin_version, &$errors=array())
     105  {
     106    global $prefixeTable;
     107   
     108    if (!$this->installed)
     109    {
     110      $this->install($plugin_version, $errors);
     111    }
     112   
     113    $query = '
    47114SELECT
    48115    COUNT(*)
    49116  FROM '.$prefixeTable.'community_permissions
    50117;';
    51   list($counter) = pwg_db_fetch_row(pwg_query($query));
    52   if (0 == $counter)
    53   {
    54     community_create_default_permission();
    55   }
    56 
    57   include_once(dirname(__FILE__).'/include/functions_community.inc.php');
    58   community_update_cache_key();
    59 }
    60 
    61 function community_get_data_from_core21()
    62 {
    63   global $conf, $prefixeTable;
    64  
    65   $from_piwigo21_file = $conf['data_location'].'/plugins/core_user_upload_to_community.php';
    66   if (is_file($from_piwigo21_file))
    67   {
    68     include($from_piwigo21_file);
    69     $user_upload_conf = unserialize($user_upload_conf);
    70    
    71     $user_upload_conf['upload_user_access'] = 1;
    72 
    73     if (isset($user_upload_conf['uploadable_categories']) and is_array($user_upload_conf['uploadable_categories']))
     118    list($counter) = pwg_db_fetch_row(pwg_query($query));
     119    if (0 == $counter)
    74120    {
    75       $type = 'any_registered_user';
    76       if (isset($user_upload_conf['upload_user_access']) and 1 == $user_upload_conf['upload_user_access'])
    77       {
    78         $type = 'any_visitor';
    79       }
    80 
    81       $inserts = array();
    82    
    83       foreach ($user_upload_conf['uploadable_categories'] as $category_id)
    84       {
    85         array_push(
    86           $inserts,
    87           array(
    88             'type' => $type,
    89             'category_id' => $category_id,
    90             'recursive' => 'false',
    91             'create_subcategories' => 'false',
    92             'moderated' => 'true',
    93             )
    94           );
    95       }
    96      
    97       if (count($inserts) > 0)
    98       {
    99         mass_inserts(
    100           $prefixeTable.'community_permissions',
    101           array_keys($inserts[0]),
    102           $inserts
    103           );
    104       }
    105     }
    106    
    107     if (isset($user_upload_conf['waiting_rows']) and is_array($user_upload_conf['waiting_rows']))
    108     {
    109       $id_of_user = array();
    110      
     121      // is there a "Community" album?
    111122      $query = '
    112 SELECT
    113     '.$conf['user_fields']['id'].' AS id,
    114     '.$conf['user_fields']['username'].' AS username
    115   FROM '.USERS_TABLE.'
    116 ;';
    117       $result = pwg_query($query);
    118       while ($row = pwg_db_fetch_assoc($result))
    119       {
    120         $id_of_user[ $row['username'] ] = $row['id'];
    121       }
    122      
    123       $inserts = array();
    124      
    125       foreach ($user_upload_conf['waiting_rows'] as $pending)
    126       {
    127         $source_path = get_complete_dir($pending['storage_category_id']).$pending['file'];
    128        
    129         if (is_file($source_path))
    130         {
    131           $image_id = add_uploaded_file($source_path, $pending['file'], array($pending['storage_category_id']), 16);
    132          
    133           array_push(
    134             $inserts,
    135             array(
    136               'image_id' => $image_id,
    137               'added_on' => date ('Y-m-d H:i:s', $pending['date']),
    138               'state' => 'moderation_pending',
    139               )
    140             );
    141 
    142           $data = array();
    143          
    144           if (isset($pending['username']) and isset($id_of_user[ $pending['username'] ]))
    145           {
    146             $data['added_by'] = $id_of_user[ $pending['username'] ];
    147           }
    148          
    149           foreach (array('date_creation', 'author', 'name', 'comment') as $field)
    150           {
    151             $value = getAttribute($pending['infos'], $field);
    152             if (!empty($value))
    153             {
    154             $data[$field] = pwg_db_real_escape_string($value);
    155             }
    156           }
    157          
    158           if (count($data) > 0)
    159           {
    160             $data['id'] = $image_id;
    161            
    162             mass_updates(
    163               IMAGES_TABLE,
    164               array(
    165                 'primary' => array('id'),
    166                 'update'  => array_keys($data)
    167                 ),
    168               array($data)
    169               );
    170           }
    171          
    172           // deletion
    173           unlink($source_path);
    174           if (!isset($pending['tn_ext']))
    175           {
    176             $pending['tn_ext'] = 'jpg';
    177           }
    178           @unlink(get_thumbnail_path(array('path'=>$source_path, 'tn_ext'=>$pending['tn_ext'])));
    179         }
    180       }
    181      
    182       if (count($inserts) > 0)
    183       {
    184         mass_inserts(
    185           $prefixeTable.'community_pendings',
    186           array_keys($inserts[0]),
    187           $inserts
    188           );
    189       }
    190     }
    191     unlink($from_piwigo21_file);
    192   }
    193 }
    194 
    195 function community_get_data_from_community21()
    196 {
    197   global $prefixeTable;
    198  
    199   $old_community_table = $prefixeTable.'community';
    200   $query = 'SHOW TABLES;';
    201   $result = pwg_query($query);
    202   while ($row = pwg_db_fetch_row($result))
    203   {
    204     if ($old_community_table == $row[0])
    205     {
    206       $inserts = array();
    207      
    208       $query = '
    209 SELECT
    210     *
    211   FROM '.$old_community_table.'
    212 ;';
    213       $result = pwg_query($query);
    214       while ($row = pwg_db_fetch_assoc($result))
    215       {
    216         array_push(
    217           $inserts,
    218           array(
    219             'type' => 'user',
    220             'user_id' => $row['user_id'],
    221             'category_id' => null,
    222             'recursive' => 'true',
    223             'create_subcategories' => $row['permission_level'] == 2 ? 'true' : 'false',
    224             'moderated' => 'false',
    225             )
    226           );
    227       }
    228      
    229       if (count($inserts) > 0)
    230       {
    231         mass_inserts(
    232           $prefixeTable.'community_permissions',
    233           array_keys($inserts[0]),
    234           $inserts
    235           );
    236       }
    237      
    238       $query = 'DROP TABLE '.$old_community_table.';';
    239       pwg_query($query);
    240      
    241       break;
    242     }
    243   }
    244 }
    245 
    246 function community_create_default_permission()
    247 {
    248   global $prefixeTable;
    249 
    250   // is there a "Community" album?
    251   $query = '
    252123SELECT
    253124    id
     
    255126  WHERE name = \'Community\'
    256127;';
    257   $result = pwg_query($query);
    258   while ($row = pwg_db_fetch_assoc($result))
    259   {
    260     $category_id = $row['id'];
    261     break;
     128      $result = pwg_query($query);
     129      while ($row = pwg_db_fetch_assoc($result))
     130      {
     131        $category_id = $row['id'];
     132        break;
     133      }
     134
     135      if (!isset($category_id))
     136      {
     137        // create an album "Community"
     138        include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     139        $category_info = create_virtual_category('Community');
     140        $category_id = $category_info['id'];
     141      }
     142
     143      single_insert(
     144        $prefixeTable.'community_permissions',
     145        array(
     146          'type' => 'any_registered_user',
     147          'category_id' => $category_id,
     148          'recursive' => 'true',
     149          'create_subcategories' => 'true',
     150          'moderated' => 'true',
     151          )
     152        );
     153    }
     154
     155    include_once(dirname(__FILE__).'/include/functions_community.inc.php');
     156    community_update_cache_key();
    262157  }
    263158
    264   if (!isset($category_id))
     159  function update($old_version, $new_version, &$errors=array())
    265160  {
    266     // create an album "Community"
    267     include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
    268     $category_info = create_virtual_category('Community');
    269     $category_id = $category_info['id'];
     161    $this->install($new_version, $errors);
     162  }
     163 
     164  function deactivate()
     165  {
    270166  }
    271167
    272   $insert = array(
    273     'type' => 'any_registered_user',
    274     'category_id' => $category_id,
    275     'recursive' => 'true',
    276     'create_subcategories' => 'true',
    277     'moderated' => 'true',
    278     );
    279 
    280   mass_inserts($prefixeTable.'community_permissions', array_keys($insert), array($insert));
     168  function uninstall()
     169  {
     170    global $prefixeTable;
     171 
     172    $query = 'DROP TABLE '.$prefixeTable.'community_permissions;';
     173    pwg_query($query);
     174   
     175    $query = 'DROP TABLE '.$prefixeTable.'community_pendings;';
     176    pwg_query($query);
     177   
     178    $query = 'ALTER TABLE '.$prefixeTable.'categories drop column community_user;';
     179    pwg_query($query);
     180   
     181    // delete configuration
     182    pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param IN ("community", "community_cache_key");');
     183  }
    281184}
    282185?>
Note: See TracChangeset for help on using the changeset viewer.