Ignore:
Timestamp:
Oct 8, 2011, 8:38:30 PM (12 years ago)
Author:
Mattias
Message:

Small code cleanups - compatible with piwigo

Location:
extensions/Extended_author
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/Extended_author/admin.php

    r11819 r12390  
    33// | Piwigo - a PHP based picture gallery                                  |
    44// +-----------------------------------------------------------------------+
    5 // | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
     5// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
    66// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
    77// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
     
    3939$EAid = 0;
    4040$EAname = '';
     41$EAcode = '';
    4142$EAurl = '';
    4243$EAdescr = '';
     
    6566                // Fetch the values from the form
    6667                $name = pwg_db_real_escape_string($_REQUEST['name']);
     68                $code = pwg_db_real_escape_string($_REQUEST['code']);
    6769                $url = pwg_db_real_escape_string($_REQUEST['url']);
    6870                $descr = pwg_db_real_escape_string($_REQUEST['descr']);
    6971                $copyright = pwg_db_real_escape_string($_REQUEST['copyrightID']);
    7072
    71                 // Check whether an author with such a name exists
    72                 // Therefore count the number of authors with that name
     73                // Check whether an author with such a name or code exists
     74                // Therefore count the number of authors with that name or code
    7375                $query = sprintf(
    7476                        'SELECT COUNT(*)
    7577                        FROM %s
    7678                        WHERE `name` = \'%s\'
    77                         ;',
    78                         AUTHORS, $name);
    79                 list($counter) = pwg_db_fetch_row(pwg_query($query));
    80 
     79                        OR `code` = \'%s\'
     80                        ;',
     81                        AUTHORS, $name, $code);
     82                $result = pwg_query($query);
     83                $counter = pwg_db_num_rows($result);
     84               
    8185                if ($counter != 0) {
    8286                        // The author exists already
     
    8791                        $query = sprintf(
    8892                                'INSERT INTO %s
    89                                 (`name`,`url`,`descr`,`copyright`) VALUES
    90                                 ("%s","%s","%s",%d)
     93                                (`name`,`code`,`url`,`descr`,`copyright`) VALUES
     94                                ("%s","%s","%s","%s",%d)
    9195                                ;',
    92                                 AUTHORS, $name, $url, $descr, $copyright);
     96                                AUTHORS, $name, $code, $url, $descr, $copyright);
    9397                        pwg_query($query); // Execute the query
    9498                }
     
    112116                // Save the attributes in convenient variables
    113117                $EAname = $row['name'];
     118                $EAcode = $row['code'];
    114119                $EAurl = $row['url'];
    115120                $EAdescr = $row['descr'];
     
    122127                $id = pwg_db_real_escape_string($_REQUEST['id']);
    123128                $name = pwg_db_real_escape_string($_REQUEST['name']);
     129                $code = pwg_db_real_escape_string($_REQUEST['code']);
    124130                $url = pwg_db_real_escape_string($_REQUEST['url']);
    125131                $descr = pwg_db_real_escape_string($_REQUEST['descr']);
    126132                $copyright = pwg_db_real_escape_string($_REQUEST['copyrightID']);
    127133
    128                 // Compose a query to update the author
    129                 $query = sprintf(
    130                         'UPDATE %s
    131                         SET `name`="%s", `url`="%s", `descr`="%s", `copyright`=%d
    132                         WHERE `author_id`=%d
    133                         ;',
    134                         AUTHORS, $name, $url, $descr, $copyright, $id);
    135                 pwg_query($query); // Execute the query
     134                // Check whether an author with such a name or code exists
     135                // Therefore count the number of authors with that name or code
     136                $query = sprintf(
     137                        'SELECT COUNT(*)
     138                        FROM %s
     139                        WHERE `name` = \'%s\'
     140                        OR `code` = \'%s\'
     141                        ;',
     142                        AUTHORS, $name, $code);
     143                $result = pwg_query($query);
     144                $counter = pwg_db_num_rows($result);
     145               
     146                if ($counter != 0) {
     147                        // The author exists already
     148                        array_push($page['errors'], l10n('This author already exists.'));
     149                } else {
     150                        // The author did not yet exist
     151                        // Compose a query to update the author
     152                        $query = sprintf(
     153                                'UPDATE %s
     154                                SET `name`="%s", `code`="%s", `url`="%s", `descr`="%s", `copyright`=%d
     155                                WHERE `author_id`=%d
     156                                ;',
     157                                AUTHORS, $name, $code, $url, $descr, $copyright, $id);
     158                        pwg_query($query); // Execute the query
     159                }
    136160        }
    137161
     
    197221                        'author_id' => $row['author_id'],
    198222                        'name'      => $row['name'],
     223                        'code'      => $row['code'],
    199224                        'url'       => $row['url'],
    200225                        'descr'     => $row['descr'],
     
    214239$template->assign('EAid', $EAid);
    215240$template->assign('EAname', $EAname);
     241$template->assign('EAcode', $EAcode);
    216242$template->assign('EAurl', $EAurl);
    217243$template->assign('EAdescr', $EAdescr);
  • extensions/Extended_author/admin.tpl

    r11819 r12390  
    1717          <td>{'Name'|@translate}</td>
    1818          <td><input type='text' name='name' id='name' value='{$EAname}' /></td>
     19        </tr>
     20        <tr>
     21          <td>{'Code'|@translate}</td>
     22          <td><input type='text' name='code' id='code' value='{$EAcode}' /></td>
    1923        </tr>
    2024        <tr>
     
    5256        <!-- create a nice header row -->
    5357        <th>{'Name'|@translate}</th>
     58        <th>{'Code'|@translate}</th>
    5459        <th>{'URL'|@translate}</th>
    5560        <th>{'Description'|@translate}</th>
     
    6469                                                   table rows -->
    6570        <td>{$EA.name}</td>
     71        <td>{$EA.code}</td>
    6672        <td><a href="{$EA.url}">{$EA.url}</a></td>
    6773        <td>{$EA.descr}</td>
  • extensions/Extended_author/maintain.inc.php

    r11846 r12390  
    33// | Piwigo - a PHP based picture gallery                                  |
    44// +-----------------------------------------------------------------------+
    5 // | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
     5// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
    66// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
    77// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
     
    4949          author_id int(11) NOT NULL AUTO_INCREMENT,
    5050      name varchar(255) UNIQUE NOT NULL,
     51          code varchar (4) UNIQUE NOT NULL,
    5152      url varchar(255),
    5253      descr text DEFAULT NULL,
Note: See TracChangeset for help on using the changeset viewer.