1 | <?php |
---|
2 | |
---|
3 | // Add an event handler for a prefilter |
---|
4 | add_event_handler('loc_begin_picture', 'EA_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', 'EA_add_image_vars_to_template'); |
---|
8 | |
---|
9 | // Add the prefilter to the template |
---|
10 | function EA_set_prefilter_add_to_pic_info() |
---|
11 | { |
---|
12 | global $template; |
---|
13 | $template->set_prefilter('picture', 'EA_add_to_pic_info'); |
---|
14 | } |
---|
15 | |
---|
16 | // Insert the template for the author display |
---|
17 | function EA_add_to_pic_info($content, &$smarty) |
---|
18 | { |
---|
19 | // Add the information after the author - so before the createdate |
---|
20 | $search = '/<tr id="Author">.*?<\/tr>/is'; |
---|
21 | |
---|
22 | $replacement = ' |
---|
23 | <tr id="extended_author"> |
---|
24 | <td class="label">{\'Author\'|@translate}</td> |
---|
25 | <td class="value"> |
---|
26 | {if $EA_INFO_NAME} |
---|
27 | {if $EA_INFO_URL} |
---|
28 | <a target="_blanc" href="{$EA_INFO_URL}" title="{$EA_INFO_NAME}"> |
---|
29 | {/if} |
---|
30 | {$EA_INFO_NAME} |
---|
31 | {if $EA_INFO_URL} |
---|
32 | </a> |
---|
33 | {/if} |
---|
34 | {else} |
---|
35 | {\'N/A\'|@translate} |
---|
36 | {/if} |
---|
37 | </td> |
---|
38 | </tr>'; |
---|
39 | |
---|
40 | return preg_replace($search, $replacement, $content); |
---|
41 | } |
---|
42 | |
---|
43 | // Assign values to the variables in the template |
---|
44 | function EA_add_image_vars_to_template() |
---|
45 | { |
---|
46 | global $page, $template; |
---|
47 | |
---|
48 | // Show block only on the photo page |
---|
49 | if ( !empty($page['image_id']) ) |
---|
50 | { |
---|
51 | // Get the author name and url that belongs to the current media_item |
---|
52 | $query = sprintf(' |
---|
53 | select a.name, a.url |
---|
54 | FROM %s i, %s a |
---|
55 | WHERE i.author = a.name |
---|
56 | AND i.id = %d |
---|
57 | ;', |
---|
58 | IMAGES, AUTHORS, $page['image_id']); |
---|
59 | $result = pwg_query($query); |
---|
60 | $row = pwg_db_fetch_row($result); |
---|
61 | $name = ''; |
---|
62 | $url = ''; |
---|
63 | if(count($row) > 0) { |
---|
64 | $name = $row[0]; |
---|
65 | $url = $row[1]; |
---|
66 | } |
---|
67 | |
---|
68 | // Sending data to the template |
---|
69 | $template->assign( |
---|
70 | array( |
---|
71 | 'EA_INFO_NAME' => $name, |
---|
72 | 'EA_INFO_URL' => $url |
---|
73 | ) |
---|
74 | ); |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | ?> |
---|