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 = '#class="imageInfoTable">#'; |
---|
21 | |
---|
22 | $replacement = 'class="imageInfoTable"> |
---|
23 | <div id="Copyrights_name" class="imageInfo"> |
---|
24 | <dt>{\'Copyright\'|@translate}</dt> |
---|
25 | <dd> |
---|
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} |
---|
29 | {\'N/A\'|@translate} |
---|
30 | {/if} |
---|
31 | </dd> |
---|
32 | </div>'; |
---|
33 | |
---|
34 | return preg_replace($search, $replacement, $content, 1); |
---|
35 | } |
---|
36 | |
---|
37 | // Assign values to the variables in the template |
---|
38 | function copyrights_add_image_vars_to_template() |
---|
39 | { |
---|
40 | global $page, $template, $prefixeTable; |
---|
41 | |
---|
42 | // Show block only on the photo page |
---|
43 | if ( !empty($page['image_id']) ) |
---|
44 | { |
---|
45 | // Get the copyright name, url and description that belongs to the current media_item |
---|
46 | $query = sprintf(' |
---|
47 | select cr_id, name, url, descr |
---|
48 | FROM %s NATURAL JOIN %s |
---|
49 | WHERE media_id = %s |
---|
50 | AND visible = 1 |
---|
51 | ;', |
---|
52 | COPYRIGHTS_ADMIN, COPYRIGHTS_MEDIA, $page['image_id']); |
---|
53 | $result = pwg_query($query); |
---|
54 | $row = pwg_db_fetch_assoc($result); |
---|
55 | $name = ''; |
---|
56 | $url = ''; |
---|
57 | $descr = ''; |
---|
58 | if (isset($row) and count($row) > 0) { |
---|
59 | // If its the authors default copyright, get the data from the author table, instead of the copyright table |
---|
60 | if ($row['cr_id'] == -1) { |
---|
61 | // Check if the extended author plugin is active |
---|
62 | $query = ' |
---|
63 | SELECT * |
---|
64 | FROM '.$prefixeTable.'plugins |
---|
65 | WHERE id=\'Extended_author\' |
---|
66 | AND state=\'active\' |
---|
67 | ;'; |
---|
68 | $result = pwg_query($query); |
---|
69 | $row = pwg_db_fetch_assoc($result); |
---|
70 | |
---|
71 | // Only get the authors default copyright when it is active. |
---|
72 | if (count($row) > 0) { |
---|
73 | $query = sprintf(' |
---|
74 | SELECT name, url, descr |
---|
75 | FROM %s |
---|
76 | WHERE cr_id IN ( |
---|
77 | SELECT a.copyright |
---|
78 | FROM '.$prefixeTable.'images i, '.$prefixeTable.'author_extended a |
---|
79 | WHERE i.id = %d |
---|
80 | AND i.author = a.name |
---|
81 | ) |
---|
82 | ;', |
---|
83 | COPYRIGHTS_ADMIN, $page['image_id']); |
---|
84 | $result = pwg_query($query); |
---|
85 | $row = pwg_db_fetch_assoc($result); |
---|
86 | } |
---|
87 | } |
---|
88 | } |
---|
89 | // Get the data from the chosen row |
---|
90 | if (isset($row) and count($row) > 0) { |
---|
91 | $name = $row['name']; |
---|
92 | $url = $row['url']; |
---|
93 | $descr = $row['descr']; |
---|
94 | } |
---|
95 | |
---|
96 | // Sending data to the template |
---|
97 | $template->assign( |
---|
98 | array ( |
---|
99 | 'CR_INFO_NAME' => $name, |
---|
100 | 'CR_INFO_URL' => $url, |
---|
101 | 'CR_INFO_DESCR' => $descr |
---|
102 | ) |
---|
103 | ); |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | ?> |
---|