Changeset 11423


Ignore:
Timestamp:
Jun 18, 2011, 9:16:29 PM (9 years ago)
Author:
Mattias
Message:
  • batch renamed to batch_global and moved to a distinct file
  • created batch_single.php
  • some comments here and there
Location:
extensions/Copyrights
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/Copyrights/TODO

    r11422 r11423  
    11=== TODO ===
    22- Implement single mode Batch Manager
    3     Probably use prefilters combined with loc_begin_element_set_unit
     3    Probably use prefilters combined with "loc_begin_element_set_unit" (found in event tracer)
     4        SOURCES: "loc_begin_admin": http://piwigo.org/forum/viewtopic.php?id=17468
     5                         "use prefilters": http://piwigo.org/forum/viewtopic.php?id=17551&p=2
    46- Add Icon field to copyrights
    57- Show the copyright when image is displayed
     
    911        - If you create a new copyright with a name that's already used
    1012        - Description doesnt show with the copyright info (on the admin page)
     13        - The warning triangle saying our plugin does not seem compatible - no clue
  • extensions/Copyrights/image.php

    r11292 r11423  
    99*/
    1010
    11 
     11// What do these prefilters do?
     12// First they use loc_begin_picture to set some template variables
     13// Then they use the same event to set a prefilter, who on his turn will change the content
    1214
    1315// Add a prefilter - whatever a prefilter may be
    14 add_event_handler('loc_begin_picture', 'set_prefilter_add_to_pic_info', 55 );
     16add_event_handler('loc_begin_picture', 'copyrights_set_prefilter_add_to_pic_info', 55 );
    1517
    16 function set_prefilter_add_to_pic_info()
     18// Another function of which i cant see the use ;-)
     19add_event_handler('loc_begin_picture', 'copyrights_add_vars_to_template');
     20
     21function copyrights_set_prefilter_add_to_pic_info()
    1722{
    1823        global $template;
    19         $template->set_prefilter('picture', 'add_to_pic_info');
     24        $template->set_prefilter('picture', 'copyrights_add_to_pic_info');
    2025}
    2126 
    2227
    2328 // This function is called by the set_prefilter_add_to_pic_info function. It has something to do with the prefilter stuff, whatever it may be :p
    24 function add_to_pic_info($content, &$smarty)
     29function copyrights_add_to_pic_info($content, &$smarty)
    2530{
    2631        // Voeg de informatie toe na de auteur - dus voor de datum dat ie gemaakt is...
     
    4247}
    4348
    44 // Another function of which i cant see the use ;-)
    45 add_event_handler('loc_begin_picture', 'add_vars_to_template');
    46 
    47 function add_vars_to_template()
     49function copyrights_add_vars_to_template()
    4850{
    4951// For as far as i know i only need the $prefixtable, $page and $template
    50 global $conf, $page, $template, $tab, $cit, $nbr, $prefixeTable;
     52//global $conf, $page, $template, $tab, $cit, $nbr, $prefixeTable;
     53global $page, $template, $prefixeTable;
    5154//load_language('plugin.lang', ADDINFO_PATH);
    5255//load_language('lang', PHPWG_ROOT_PATH.'local/', array('no_fallback'=>true, 'local'=>true) );
  • extensions/Copyrights/main.inc.php

    r11422 r11423  
    3232if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    3333
    34 define('COPYRIGHTS_PATH', PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)) . '/'); // The plugin path
    35 define('COPYRIGHTS_WEB_PATH', get_root_url().'admin.php?page=plugin-Copyrights');
    36 // Whats the difference between "COPYRIGHTS_PATH" and "COPYRIGHTS_WEB_PATH" ???
     34define('COPYRIGHTS_PATH', PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)) . '/');  // The plugin path
     35define('COPYRIGHTS_WEB_PATH', get_root_url().'admin.php?page=plugin-Copyrights'); // The path used in admin.php
    3736
    3837global $prefixeTable;
     
    4847
    4948
     49 // Add to the menu, dont do anything right now
    5050add_event_handler('get_admin_plugin_menu_links', 'copyrights_admin_menu');
    5151function copyrights_admin_menu($menu) {
     
    6666
    6767
    68 //if (script_basename() == 'picture') // Why should i want this here?
     68// Add information to the picture's description (The copyright's name)
    6969include_once(dirname(__FILE__).'/image.php');
    7070
     
    7474 * +-----------------------------------------------------------------------+ */
    7575
     76 
     77 // Global mode
     78include_once(dirname(__FILE__).'/batch_global.php');
    7679
    77 // @Johan: Misschien een goed idee om dit ook in een apart php scriptje te zetten, voor de overzichtelijkheid.
    78 // En om deze reden (Citaat uit de piwigo docs http://piwigo.org/doc/doku.php?id=en:plugins):
    79 // Code size
    80 // When PWG loads the plugins, it will include every main.inc.php.
    81 // Don't put in your main.inc.php 3000 lines of code just to add a page on the administration menu.
    82 // Split you main.inc.php in several files and feel free to add include_once inside functions defined in main.inc.php as much as you want.
    83 
    84 
    85 // Add copyrights drop down menu to the batch manager
    86 add_event_handler('loc_end_element_set_global', 'copyrights_batch');
    87 // Add handler to the submit event of the batch manager
    88 add_event_handler('element_set_global_action', 'copyrights_batch_submit', 50, 2);
    89 
    90 function copyrights_batch()
    91 {
    92   global $template;
    93 
    94   load_language('plugin.lang', dirname(__FILE__).'/');                                  // Engels is voorlopig goed zat
    95 
    96   // Assign the template for batch management
    97   $template->set_filename('batch', dirname(__FILE__).'/batch.tpl');
    98 
    99   // Fetch all the copyrights and assign them to the template
    100   $query = sprintf(
    101     'SELECT `cr_id`,`name`
    102     FROM %s
    103     WHERE `visible`<>0
    104     ;',
    105     COPYRIGHTS_ADMIN);
    106   $result = pwg_query($query);
    107   $CRoptions = array();
    108   while ($row = pwg_db_fetch_assoc($result)) {
    109     $CRoptions[$row['cr_id']] = $row['name'];
    110   }
    111   $template->assign('CRoptions', $CRoptions);
    112 
    113  
    114   // Goed, ik weet dus echt niet waarom dit hieronder gedaan wordt...
    115   // AHA!!!! - dit is er zodat de "choose action" optie deze plugin gebruikt....
    116   $template->append('element_set_global_plugins_actions', array(
    117     'ID' => 'copyrights',       // ID of the batch manager action
    118     'NAME' => l10n('Edit copyright'), // Description of the batch manager action
    119     'CONTENT' => $template->parse('batch', true)
    120     )
    121   );
    122 }
    123 
    124 // * Deze functie wordt een keer aangeroepen, nadat de gebruiker submit.
    125 // * Fietst met een foreach loop over de geselecteerde fotos
    126 // * Rammelt alle toevoegingen in 1x met mass_updates naar de db.
    127 function copyrights_batch_submit($action, $collection)
    128 {
    129   if ($action == 'copyrights')
    130   {
    131           $crID = pwg_db_real_escape_string($_POST['copyrightID']);
    132    
    133     if (count($collection) > 0) {
    134       $query = sprintf(
    135         'DELETE
    136         FROM %s
    137         WHERE media_id IN (%s)
    138         ;',
    139         COPYRIGHTS_MEDIA, implode(',', $collection));
    140       pwg_query($query);
    141     }
    142 
    143     $edits = array();
    144     foreach ($collection as $image_id)
    145     {
    146       array_push(
    147         $edits,
    148         array(
    149           'media_id' => $image_id,
    150           'cr_id' => $crID,
    151           )
    152         );
    153     }
    154 
    155     mass_inserts(
    156       COPYRIGHTS_MEDIA, // Table name
    157       array_keys($edits[0]), //Columns
    158       $edits // Data
    159     );
    160   }
    161 }
     80// Single mode - TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST
     81// should become a include_once !!!
     82include(dirname(__FILE__).'/batch_single.php');
    16283
    16384?>
Note: See TracChangeset for help on using the changeset viewer.