source: extensions/Copyrights/image.php @ 11619

Last change on this file since 11619 was 11505, checked in by Mattias, 13 years ago
  • Some changes in image.php (pwg_db instead of mysql)
  • batch_single.php adds an extra <tr> between the author and the creation date
File size: 2.6 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_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 
27
28 // This function is called by the set_prefilter_add_to_pic_info function. It has something to do with the prefilter stuff, whatever it may be :p
29function copyrights_add_to_pic_info($content, &$smarty)
30{
31        // Voeg de informatie toe na de auteur - dus voor de datum dat ie gemaakt is...
32        $search = '#<tr id="datecreate">#';
33       
34        $replacement = '
35        <tr id="Copyrights_name">
36                <td class="label">{\'Copyright\'|@translate}</td>
37                <td class="value">
38                        {if $CR_INFO_NAME}
39                        <a target="_blanc" href="{$CR_INFO_URL}" title="{$CR_INFO_NAME}">{$CR_INFO_NAME}</a>
40                        {else}{\'N/A\'|@translate}{/if}
41                </td>
42        </tr>
43        <tr id="datecreate">';
44
45        return preg_replace($search, $replacement, $content);
46}
47
48function copyrights_add_vars_to_template()
49{
50        // For as far as i know i only need the $prefixtable, $page and $template
51        //global $conf, $page, $template, $tab, $cit, $nbr, $prefixeTable;
52        global $page, $template, $prefixeTable;
53        //load_language('plugin.lang', ADDINFO_PATH);
54        //load_language('lang', PHPWG_ROOT_PATH.'local/', array('no_fallback'=>true, 'local'=>true) );
55
56        // Show block only on the photo page
57        if ( !empty($page['image_id']) )
58        {
59                // Get the copyright name and url (FROM cr_admin) that belongs to the current media_item (FROM cr_media)
60                $query = '
61                  select name, url
62                  FROM '.COPYRIGHTS_ADMIN.' NATURAL JOIN '.COPYRIGHTS_MEDIA.'
63                  WHERE media_id = '.$page['image_id'].'
64                  AND visible = 1
65                  ;';
66                $result = pwg_query($query);
67                $row = pwg_db_fetch_row($result);
68                if(count($row) > 0) {
69                        $name = $row[0];
70                        $url = $row[1];
71                }
72                else {
73                        $name = '';
74                        $url = '';
75                }
76                       
77                // Sending data to the template
78                $template->assign(
79                array   (
80                'CR_INFO_NAME' => $name,
81                'CR_INFO_URL' => $url
82                                ));
83        }
84}
85
86?>
Note: See TracBrowser for help on using the repository browser.