source: extensions/Copyrights/image.php @ 11794

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

added support for -1 copyright
added an order by cr_id
the plugin handles deletes (no copyright) better

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