1 | <?php |
---|
2 | |
---|
3 | // Add an event handler for a prefilter |
---|
4 | add_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 |
---|
7 | add_event_handler('loc_begin_picture', 'copyrights_add_image_vars_to_template'); |
---|
8 | |
---|
9 | // Add the prefilter to the template |
---|
10 | function 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 |
---|
17 | function 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 |
---|
37 | function 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 its the authors default copyright, get the data from the author table, instead of the copyright table |
---|
59 | if ($row['cr_id'] == -1) { |
---|
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 | ) |
---|
81 | ;', |
---|
82 | COPYRIGHTS_ADMIN, $page['image_id']); |
---|
83 | $result = pwg_query($query); |
---|
84 | $row = pwg_db_fetch_assoc($result); |
---|
85 | } |
---|
86 | } |
---|
87 | } |
---|
88 | // Get the data from the chosen row |
---|
89 | if (count($row) > 0) { |
---|
90 | $name = $row['name']; |
---|
91 | $url = $row['url']; |
---|
92 | $descr = $row['descr']; |
---|
93 | } |
---|
94 | |
---|
95 | // Sending data to the template |
---|
96 | $template->assign( |
---|
97 | array ( |
---|
98 | 'CR_INFO_NAME' => $name, |
---|
99 | 'CR_INFO_URL' => $url, |
---|
100 | 'CR_INFO_DESCR' => $descr |
---|
101 | ) |
---|
102 | ); |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | ?> |
---|