source: extensions/Copyrights/image.php @ 31975

Last change on this file since 31975 was 31939, checked in by plg, 6 years ago

compatibility PHP 7.2

File size: 3.0 KB
RevLine 
[11076]1<?php
2
[11678]3// Add an event handler for a prefilter
[11423]4add_event_handler('loc_begin_picture', 'copyrights_set_prefilter_add_to_pic_info', 55 );
[11076]5
[11439]6// Change the variables used by the function that changes the template
[11621]7add_event_handler('loc_begin_picture', 'copyrights_add_image_vars_to_template');
[11423]8
[11678]9// Add the prefilter to the template
[11423]10function copyrights_set_prefilter_add_to_pic_info()
[11076]11{
12        global $template;
[11423]13        $template->set_prefilter('picture', 'copyrights_add_to_pic_info');
[11076]14}
15
[11678]16// Insert the template for the copyright display
[11423]17function copyrights_add_to_pic_info($content, &$smarty)
[11076]18{
[11621]19        // Add the information after the author - so before the createdate
[22300]20        $search = '#class="imageInfoTable">#';
[11076]21       
[22300]22        $replacement = 'class="imageInfoTable">
23        <div id="Copyrights_name" class="imageInfo">
24                <dt>{\'Copyright\'|@translate}</dt>
25                <dd>
26{if $CR_INFO_NAME}
[11635]27                        <a target="_blanc" href="{$CR_INFO_URL}" title="{$CR_INFO_NAME}: {$CR_INFO_DESCR}">{$CR_INFO_NAME}</a>
[22300]28{else}
29      {\'N/A\'|@translate}
30{/if}
31    </dd>
32        </div>';
[11076]33
[29235]34        return preg_replace($search, $replacement, $content, 1);
[11076]35}
36
[11678]37// Assign values to the variables in the template
[11621]38function copyrights_add_image_vars_to_template()
[11076]39{
[11439]40        global $page, $template, $prefixeTable;
[11076]41
42        // Show block only on the photo page
[11439]43        if ( !empty($page['image_id']) )
[11076]44        {
[11675]45                // Get the copyright name, url and description that belongs to the current media_item
[11678]46                $query = sprintf('
[11794]47                  select cr_id, name, url, descr
[11678]48                  FROM %s NATURAL JOIN %s
49                  WHERE media_id = %s
[11143]50                  AND visible = 1
[11794]51                ;',
52                COPYRIGHTS_ADMIN, COPYRIGHTS_MEDIA, $page['image_id']);
[11076]53                $result = pwg_query($query);
[11794]54                $row = pwg_db_fetch_assoc($result);
[11635]55                $name = '';
56                $url = '';
57                $descr = '';
[31939]58                if (isset($row) and count($row) > 0) {
[11844]59                        // If its the authors default copyright, get the data from the author table, instead of the copyright table
[11794]60                        if ($row['cr_id'] == -1) {
[11844]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                                                )
[11794]82                                                ;',
83                                                COPYRIGHTS_ADMIN, $page['image_id']);
[11844]84                                        $result = pwg_query($query);
85                                        $row = pwg_db_fetch_assoc($result);
86                                }
[11794]87                        }
[11505]88                }
[11844]89                // Get the data from the chosen row
[31939]90                if (isset($row) and count($row) > 0) {
[11794]91                        $name = $row['name'];
92                        $url = $row['url'];
93                        $descr = $row['descr'];
94                }
[11076]95                       
96                // Sending data to the template
[11678]97    $template->assign(
98      array     (
99        'CR_INFO_NAME' => $name,
100        'CR_INFO_URL' => $url,
101        'CR_INFO_DESCR' => $descr
102      )
103    );
[11076]104        }
105}
106
[11678]107?>
Note: See TracBrowser for help on using the repository browser.