source: trunk/core/lib_photos.php @ 782

Revision 782, 6.3 KB checked in by r2, 13 months ago (diff)

копирайты

  • Property svn:executable set to *
Line 
1<?php
2/******************************************************************************/
3//                                                                            //
4//                             InstantCMS v1.8                                //
5//                        http://www.instantcms.ru/                           //
6//                                                                            //
7//                   written by InstantCMS Team, 2007-2010                    //
8//                produced by InstantSoft, (www.instantsoft.ru)               //
9//                                                                            //
10//                        LICENSED BY GNU/GPL v2                              //
11//                                                                            //
12/******************************************************************************/
13
14if(!defined('VALID_CMS')) { die('ACCESS DENIED'); }
15
16function albumCreateRoot($user_id, $differ='', $title=''){
17    $inDB = cmsDatabase::getInstance();
18    $inCore = cmsCore::getInstance();
19        $ns = $inCore->nestedSetsInit('cms_photo_albums');
20        $album_id = $ns->AddRootNode($differ);
21       
22        $sql = "UPDATE cms_photo_albums
23                        SET user_id = '$user_id',
24                                title = '-Êîðíåâîé àëüáîì êëóáà $title-',
25                                orderform=0
26                        WHERE id = '$album_id'";
27        $inDB->query($sql);
28       
29        return $album_id;
30}
31
32function albumCreate($differ='', $parent_id, $title, $description, $user_id){
33    $inCore = cmsCore::getInstance();
34    $inDB = cmsDatabase::getInstance();
35        $ns = $inCore->nestedSetsInit('cms_photo_albums');
36        $album_id = $ns->AddNode($parent_id, -1, $differ);
37       
38        $sql = "UPDATE cms_photo_albums
39                        SET title='$title',
40                                description='$description',
41                                published=1,
42                                showdate=1,
43                                iconurl='',
44                                pubdate=NOW(),
45                                orderby='pubdate',
46                                orderto='desc',
47                                public=1,
48                                perpage=16,
49                                cssprefix='',
50                                thumb1=96,
51                                thumb2=600,
52                                thumbsqr=1,
53                                showtype='lightbox',
54                                nav=1,
55                                uplimit=100,
56                                maxcols=4,
57                                orderform=1,
58                                showtags=1,
59                                bbcode=1,
60                                user_id=$user_id
61                        WHERE id = $album_id";
62        $inDB->query($sql);
63        return ($inDB->errno()) ? false: true;
64}
65
66function albumEdit($album_id, $parent_id, $title, $description, $differ=''){
67    $inCore = cmsCore::getInstance();
68    $inDB = cmsDatabase::getInstance();
69        $old_parent = dbGetField('cms_photo_albums', 'id='.$album_id, 'parent_id');
70       
71        if ($old_parent!=$parent_id){
72                $ns = $inCore->nestedSetsInit('cms_photo_albums');
73                $ns->MoveNode($album_id, $parent_id, -1, $differ);
74        }
75
76        $sql = "UPDATE cms_photo_albums
77                        SET title='$title',
78                                description='$description'
79                        WHERE id = $album_id";
80        $inDB->query($sql);
81        return ($inDB->errno()) ? false: true;
82}
83
84function albumDelete($album_id, $differ=''){
85    $inCore = cmsCore::getInstance();
86    $inDB = cmsDatabase::getInstance();
87        $inCore->loadLib('tags');
88        $sql = "SELECT id, file FROM cms_photo_files WHERE album_id = $album_id";
89        $result = $inDB->query($sql) ;
90        //DELETE ALL PHOTOS IN ALBUM
91        if ($inDB->num_rows($result)){
92                while($photo = $inDB->fetch_assoc($result)){
93                        cmsClearTags('photo', $photo['id']);   
94                        $inDB->query("DELETE FROM cms_photo_files WHERE id = ".$photo['id']) ;
95            $inCore->deleteComments('photo', $photo['id']);
96            $inCore->deleteRatings('photo', $photo['id']);
97                        @unlink($_SERVER['DOCUMENT_ROOT'].'/images/photos/'.$photo['file']);   
98                        @unlink($_SERVER['DOCUMENT_ROOT'].'/images/photos/thumb/'.$photo['file'].'.jpg');       
99                }                       
100        }
101        //DELETE ALBUM
102        $ns = $inCore->nestedSetsInit('cms_photo_albums');
103    $inCore->deleteComments('palbum', $album_id);
104        return $ns->DeleteNode($album_id, $differ);
105}
106
107function cmsPhotoList($album){
108    $inCore = cmsCore::getInstance();
109    $inDB = cmsDatabase::getInstance();
110        ob_start();             
111                //SHOW ALBUM CONTENT
112                $sql = "SELECT * FROM cms_photo_albums WHERE id = '{$album['id']}' LIMIT 1";                           
113                $result = $inDB->query($sql) ;
114                               
115                if ($inDB->num_rows($result)==1){
116                        $album_row = $inDB->fetch_assoc($result);
117                                                                                                                               
118                        //SQL BUILD                     
119                        $sql = "SELECT f.*, IFNULL(r.total_rating, 0) as rating
120                                        FROM cms_photo_files f
121                                        LEFT JOIN cms_ratings_total r ON r.item_id=f.id AND r.target='photo'
122                                        WHERE f.album_id = '{$album['id']}' AND f.published = 1
123                                        ";
124                       
125                        //ORDERING
126                        if (isset($album['orderby'])) { 
127                                $orderby = $album['orderby']; 
128                        } else {
129                                $orderby = 'pubdate'; 
130                        }
131                       
132                        if (isset($album['orderto'])) { 
133                                $orderto = $album['orderto']; 
134                        } else {
135                                $orderto = 'desc';
136                        }
137
138                        $sql .=  " ORDER BY ".$orderby." ".$orderto." \n";
139                       
140                        if ($album['max']){
141                                $sql .= "LIMIT ".$album['max'];
142                        }
143                       
144                        $result = $inDB->query($sql) ;
145                       
146                        $col = 1; $maxcols = $album['maxcols'];
147                       
148                        if ($inDB->num_rows($result)){
149                       
150                                if ($album['header']){
151                                        echo '<div class="con_photos_header">'.$album['header'].'</div>';
152                                }
153                       
154                                //VIEW AS GALLERY (SIMPLE)                     
155                                        echo '<table width="100%" cellpadding="0" cellspacing="0" border="0" class="con_photos">';
156                                        while($con = $inDB->fetch_assoc($result)){
157                                                $photolink = '/photos/photo'.$con['id'].'.html';
158                                                $photolink2 = '/photos/photo'.$con['id'].'.html';
159                                                if ($col==1) { echo '<tr>'; } echo '<td align="center" valign="middle">';
160                                                echo '<div class="photo_thumb">';
161                                                echo '<table width="100%" height="100" cellspacing="0" cellpadding="0">
162                                                          <tr>
163                                                          <td valign="middle" align="center">';
164                                                                echo '<a href="'.$photolink.'" title="'.$con['title'].'">';
165                                                                        echo '<img class="photo_thumb_img" src="/images/photos/small/'.$con['file'].'" alt="'.$con['title'].'" border="0" />';
166                                                                echo '</a>';
167                                                echo '</td></tr>';
168                                                if ($album['titles']){
169                                                        echo '<tr><td align="center"><a href="'.$photolink2.'" title="'.$con['title'].'">'.$con['title'].'</a></td></tr>';
170                                                }
171                                                echo '</table>';
172                                                echo '</div>';
173                                               
174                                                echo '</td>'; if ($col==$maxcols) { echo '</tr>'; $col=1; } else { $col++; }
175                                        }
176                                        if ($col>1) { echo '<td colspan="'.($maxcols-$col+1).'">&nbsp;</td></tr>'; }
177                                        echo '</table>';
178                               
179                        } else { 
180                                         if($id != $root['id']) { echo '<p>Íåò ôîòîãðàôèé â ýòîì àëüáîìå.</p>'; }
181                                        }
182                                       
183                }//END - ALBUM CONTENT
184               
185                return ob_get_clean(); 
186}
187
188?>
Note: See TracBrowser for help on using the repository browser.