source: extensions/Copyrights/image.php @ 11682

Last change on this file since 11682 was 11678, checked in by J.Commelin, 13 years ago

Finished adding comments to the code

File size: 2.0 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 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_row($result);
54                $name = '';
55                $url = '';
56                $descr = '';
57                if(count($row) > 0) {
58                        $name = $row[0];
59                        $url = $row[1];
60                        $descr = $row[2];
61                }
62                       
63                // Sending data to the template
64    $template->assign(
65      array     (
66        'CR_INFO_NAME' => $name,
67        'CR_INFO_URL' => $url,
68        'CR_INFO_DESCR' => $descr
69      )
70    );
71        }
72}
73
74?>
Note: See TracBrowser for help on using the repository browser.