source: extensions/Copyrights/image.php @ 20461

Last change on this file since 20461 was 11844, checked in by Mattias, 13 years ago

fixed a bug in image.php when the extended author plugin is deactivated, but there is a -1 copyright

also added primary key to CR_media (the media_id)
and changed CR_id to NOT NULL

File size: 3.0 KB
RevLine 
[11076]1<?php
2
[11678]3// Add an event handler for a prefilter
[11423]4add_event_handler('loc_begin_picture', 'copyrights_set_prefilter_add_to_pic_info', 55 );
[11076]5
[11439]6// Change the variables used by the function that changes the template
[11621]7add_event_handler('loc_begin_picture', 'copyrights_add_image_vars_to_template');
[11423]8
[11678]9// Add the prefilter to the template
[11423]10function copyrights_set_prefilter_add_to_pic_info()
[11076]11{
12        global $template;
[11423]13        $template->set_prefilter('picture', 'copyrights_add_to_pic_info');
[11076]14}
15
[11678]16// Insert the template for the copyright display
[11423]17function copyrights_add_to_pic_info($content, &$smarty)
[11076]18{
[11621]19        // Add the information after the author - so before the createdate
[11076]20        $search = '#<tr id="datecreate">#';
21       
22        $replacement = '
23        <tr id="Copyrights_name">
[11292]24                <td class="label">{\'Copyright\'|@translate}</td>
[11084]25                <td class="value">
[11143]26                        {if $CR_INFO_NAME}
[11635]27                        <a target="_blanc" href="{$CR_INFO_URL}" title="{$CR_INFO_NAME}: {$CR_INFO_DESCR}">{$CR_INFO_NAME}</a>
[11292]28                        {else}{\'N/A\'|@translate}{/if}
[11084]29                </td>
[11076]30        </tr>
31        <tr id="datecreate">';
32
33        return preg_replace($search, $replacement, $content);
34}
35
[11678]36// Assign values to the variables in the template
[11621]37function copyrights_add_image_vars_to_template()
[11076]38{
[11439]39        global $page, $template, $prefixeTable;
[11076]40
41        // Show block only on the photo page
[11439]42        if ( !empty($page['image_id']) )
[11076]43        {
[11675]44                // Get the copyright name, url and description that belongs to the current media_item
[11678]45                $query = sprintf('
[11794]46                  select cr_id, name, url, descr
[11678]47                  FROM %s NATURAL JOIN %s
48                  WHERE media_id = %s
[11143]49                  AND visible = 1
[11794]50                ;',
51                COPYRIGHTS_ADMIN, COPYRIGHTS_MEDIA, $page['image_id']);
[11076]52                $result = pwg_query($query);
[11794]53                $row = pwg_db_fetch_assoc($result);
[11635]54                $name = '';
55                $url = '';
56                $descr = '';
[11794]57                if (count($row) > 0) {
[11844]58                        // If its the authors default copyright, get the data from the author table, instead of the copyright table
[11794]59                        if ($row['cr_id'] == -1) {
[11844]60                                // Check if the extended author plugin is active
61                                $query = '
62                                        SELECT *
63                                        FROM '.$prefixeTable.'plugins
64                                        WHERE id=\'Extended_author\'
65                                        AND state=\'active\'
66                                        ;';
67                                $result = pwg_query($query);
68                                $row = pwg_db_fetch_assoc($result);
69                               
70                                // Only get the authors default copyright when it is active.
71                                if (count($row) > 0) {
72                                        $query = sprintf('
73                                                SELECT name, url, descr
74                                                FROM %s
75                                                WHERE cr_id IN (
76                                                        SELECT a.copyright
77                                                        FROM '.$prefixeTable.'images i, '.$prefixeTable.'author_extended a
78                                                        WHERE i.id = %d
79                                                        AND i.author = a.name
80                                                )
[11794]81                                                ;',
82                                                COPYRIGHTS_ADMIN, $page['image_id']);
[11844]83                                        $result = pwg_query($query);
84                                        $row = pwg_db_fetch_assoc($result);
85                                }
[11794]86                        }
[11505]87                }
[11844]88                // Get the data from the chosen row
[11794]89                if (count($row) > 0) {
90                        $name = $row['name'];
91                        $url = $row['url'];
92                        $descr = $row['descr'];
93                }
[11076]94                       
95                // Sending data to the template
[11678]96    $template->assign(
97      array     (
98        'CR_INFO_NAME' => $name,
99        'CR_INFO_URL' => $url,
100        'CR_INFO_DESCR' => $descr
101      )
102    );
[11076]103        }
104}
105
[11678]106?>
Note: See TracBrowser for help on using the repository browser.