source: extensions/Copyrights/image.php @ 11621

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

Updates batch_single.php and some minor changes in image.php (mostly comments)

File size: 2.4 KB
Line 
1<?php
2/*
3This php file will insert the names of the copyrights into the images description,
4so you can see below the image what copyright it has.
5
6Mattias
7
8thanks to the AddInfo plugin by ddtddt!
9*/
10
11// What do these prefilters do?
12// First they use loc_begin_picture to set some template variables
13// Then they use the same event to set a prefilter, who on his turn will change the content
14
15// Add a prefilter - whatever a prefilter may be
16add_event_handler('loc_begin_picture', 'copyrights_set_prefilter_add_to_pic_info', 55 );
17
18// Change the variables used by the function that changes the template
19add_event_handler('loc_begin_picture', 'copyrights_add_image_vars_to_template');
20
21function copyrights_set_prefilter_add_to_pic_info()
22{
23        global $template;
24        $template->set_prefilter('picture', 'copyrights_add_to_pic_info');
25}
26
27function copyrights_add_to_pic_info($content, &$smarty)
28{
29        // Add the information after the author - so before the createdate
30        $search = '#<tr id="datecreate">#';
31       
32        $replacement = '
33        <tr id="Copyrights_name">
34                <td class="label">{\'Copyright\'|@translate}</td>
35                <td class="value">
36                        {if $CR_INFO_NAME}
37                        <a target="_blanc" href="{$CR_INFO_URL}" title="{$CR_INFO_NAME}">{$CR_INFO_NAME}</a>
38                        {else}{\'N/A\'|@translate}{/if}
39                </td>
40        </tr>
41        <tr id="datecreate">';
42
43        return preg_replace($search, $replacement, $content);
44}
45
46function copyrights_add_image_vars_to_template()
47{
48        // For as far as i know i only need the $prefixtable, $page and $template
49        //global $conf, $page, $template, $tab, $cit, $nbr, $prefixeTable;
50        global $page, $template, $prefixeTable;
51        //load_language('plugin.lang', ADDINFO_PATH);
52        //load_language('lang', PHPWG_ROOT_PATH.'local/', array('no_fallback'=>true, 'local'=>true) );
53
54        // Show block only on the photo page
55        if ( !empty($page['image_id']) )
56        {
57                // Get the copyright name and url (FROM cr_admin) that belongs to the current media_item (FROM cr_media)
58                $query = '
59                  select name, url
60                  FROM '.COPYRIGHTS_ADMIN.' NATURAL JOIN '.COPYRIGHTS_MEDIA.'
61                  WHERE media_id = '.$page['image_id'].'
62                  AND visible = 1
63                  ;';
64                $result = pwg_query($query);
65                $row = pwg_db_fetch_row($result);
66                if(count($row) > 0) {
67                        $name = $row[0];
68                        $url = $row[1];
69                }
70                else {
71                        $name = '';
72                        $url = '';
73                }
74                       
75                // Sending data to the template
76                $template->assign(
77                array   (
78                'CR_INFO_NAME' => $name,
79                'CR_INFO_URL' => $url
80                                ));
81        }
82}
83
84?>
Note: See TracBrowser for help on using the repository browser.