Changeset 11656


Ignore:
Timestamp:
Jul 7, 2011, 1:27:50 PM (13 years ago)
Author:
J.Commelin
Message:

Refactored code and added comments

Location:
extensions/Copyrights
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/Copyrights/admin.php

    r11635 r11656  
    3232check_status(ACCESS_ADMINISTRATOR);
    3333
    34 // Default is to create, if changed to 1, show edit page
     34// Default is to create a copyright, if changed to 1, show the edit page
    3535$edit = 0;
    3636
     
    4444// Do managing of copyrights
    4545if (isset($_GET['tab'])) {
     46  // Create a new copyright
    4647  if ($_GET['tab'] == 'create') {
     48    // Fetch the values from the form
    4749    $name = pwg_db_real_escape_string($_REQUEST['name']);
    4850    $url = pwg_db_real_escape_string($_REQUEST['url']);
    4951    $descr = pwg_db_real_escape_string($_REQUEST['descr']);
    5052    $visible = (isset($_REQUEST['visible']) ? 1 : 0);
     53
     54    // Check whether a copyright with such a name exists
     55    // Therefore count the number of copyrights with that name
    5156    $query = sprintf(
    5257      'SELECT COUNT(*)
     
    5661      COPYRIGHTS_ADMIN, $name);
    5762    list($counter) = pwg_db_fetch_row(pwg_query($query));
    58     if ($counter != 0) {
     63
     64    if ($counter != 0) { // The copyright exists already
    5965      array_push($page['errors'], l10n('This copyright already exists'));
    60     } else {
     66    } else { // The copyright did not yet exist
     67      // Compose a query to insert the copyright
    6168      $query = sprintf(
    6269        'INSERT INTO %s
     
    6572        ;',
    6673        COPYRIGHTS_ADMIN, $name, $url, $descr, $visible);
    67       pwg_query($query);
     74      pwg_query($query); // Execute the query
    6875    }
    6976  }
    7077
     78  // Edit an existing copyright
    7179  if ($_GET['tab'] == 'edit') {
    72     $edit = 1;
    73     $CRid = $_REQUEST['id'];
     80    $edit = 1; // Show the edit page
     81    $CRid = $_REQUEST['id']; // Fetch the id of the copyright to be edited
     82
     83    // Fetch the current attributes to the copyright
    7484    $query = sprintf(
    7585      'SELECT *
     
    8090    $result = pwg_query($query);
    8191    $row = pwg_db_fetch_assoc($result);
     92
     93    // Save the attributes in convenient variables
    8294    $CRname = $row['name'];
    8395    $CRurl = $row['url'];
     
    8698  }
    8799
     100  // Update an existing copyright
    88101  if ($_GET['tab'] == 'update') {
     102    // Fetch the values from the edit form
    89103    $id = pwg_db_real_escape_string($_REQUEST['id']);
    90104    $name = pwg_db_real_escape_string($_REQUEST['name']);
     
    92106    $descr= pwg_db_real_escape_string($_REQUEST['descr']);
    93107    $visible = (isset($_REQUEST['visible']) ? 1 : 0);
     108
     109    // Compose a query to update the copyright
    94110    $query = sprintf(
    95111      'UPDATE %s
     
    98114      ;',
    99115      COPYRIGHTS_ADMIN, $name, $url, $descr, $visible, $id);
    100     pwg_query($query);
     116    pwg_query($query); // Execute the query
    101117  }
    102  
     118
     119  // Delete an existing copyright
    103120  if ($_GET['tab'] == 'delete') {
    104     $id = $_REQUEST['id'];
     121    $id = $_REQUEST['id']; // Fetch the id of the copyright to be deleted
     122
     123    // Compose a query to delete the copyright
    105124    $query = sprintf(
    106125      'DELETE FROM %s
     
    108127      ;',
    109128      COPYRIGHTS_ADMIN, $id);
    110     pwg_query($query);
     129    pwg_query($query); // Execute the query
    111130  }
    112131}
    113132
    114 // Create page template
     133/* Assign variables to the template */
    115134global $template;
    116135
     136// Add the admin.tpl template
    117137$template->set_filenames(
    118138  array(
     
    121141);
    122142
     143// Select the existing copyrights
    123144$query = sprintf(
    124145  'SELECT *
     
    128149$result = pwg_query($query);
    129150
     151// Append the copyrights to the Smarty array
    130152while ($row = pwg_db_fetch_assoc($result)) {
    131153  $template->append(
     
    141163}
    142164
     165// Assign the path for URL forming
    143166$template->assign(
    144167  'COPYRIGHTS_PATH',
     
    146169);
    147170
     171// Assign all the variables we constructed above
    148172$template->assign('edit', $edit);
    149173$template->assign('CRid', $CRid);
     
    153177$template->assign('CRvisible', $CRvisible);
    154178
     179// Get it up and running
    155180$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
    156181
  • extensions/Copyrights/admin.tpl

    r11624 r11656  
    33</div>
    44
     5<!-- Create the form for creating and editing copyrights -->
    56<form action='{$COPYRIGHTS_PATH}-{if $edit == 0}create{else}update{/if}'
    67      method='POST'>
     
    89    <legend>{if $edit == 0}{'Create copyright'|@translate}
    910            {else}{'Update copyright'|@translate}{/if}</legend>
     11      <!-- If $edit != 0 we should remember the id of the copyright that is
     12           edited -->
    1013      {if $edit != 0}<input type='hidden' name='id' id='id' value='{$CRid}' />{/if}
     14      <!-- Put all the attributes of the copyright in a nice table -->
    1115      <table>
    1216        <tr>
     
    3741  </fieldset>
    3842</form>
     43
     44<!-- If we are on the 'homepage', show a table of all copyrights -->
    3945{if $edit == 0}
    4046<form>
     
    4349    <table>
    4450      <tr>
     51        <!-- Create a nice header row -->
    4552        <th>{'Name'|@translate}</th>
    4653        <th>{'URL'|@translate}</th>
     
    4956        <th>{'Actions'|@translate}</th>
    5057      </tr>
     58    <!-- Loop over all copyrights -->
    5159    {if not empty($CRs)}
    5260    {foreach from=$CRs item=CR}
    5361    {strip}
    54       <tr class="{cycle values="row1,row2"}">
     62      <tr class="{cycle values="row1,row2"}"> <!-- This gives nicely colored
     63                                                   table rows -->
    5564        <td>{$CR.name}</td>
    5665        <td><a href="{$CR.url}">{$CR.url}</a></td>
  • extensions/Copyrights/image.php

    r11635 r11656  
    33This php file will insert the names of the copyrights into the images description,
    44so you can see below the image what copyright it has.
    5 
    6 Mattias
    7 
    8 thanks to the AddInfo plugin by ddtddt!
    95*/
    106
    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
    14 
    15 // Add a prefilter - whatever a prefilter may be
     7// Add a prefilter
    168add_event_handler('loc_begin_picture', 'copyrights_set_prefilter_add_to_pic_info', 55 );
    179
  • extensions/Copyrights/main.inc.php

    r11638 r11656  
    4646 * +-----------------------------------------------------------------------+ */
    4747
    48 
    49  // Add to the menu, dont do anything right now
     48// Add an entry to the plugins menu
    5049add_event_handler('get_admin_plugin_menu_links', 'copyrights_admin_menu');
    5150function copyrights_admin_menu($menu) {
     
    8887 * +-----------------------------------------------------------------------+ */
    8988
    90 // Add Copyrights dropdown menu to picture_modify
     89// Add the Copyrights dropdown menu to picture_modify
    9190include_once(dirname(__FILE__).'/modify.php');
    9291
Note: See TracChangeset for help on using the changeset viewer.