source: trunk/core/lib_tags.php @ 782

Revision 782, 8.5 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 cmsInsertTags($tagstr, $target, $item_id){
17    $inDB = cmsDatabase::getInstance();
18        $inDB->query("DELETE FROM cms_tags WHERE target='$target' AND item_id = $item_id");
19
20        if ($tagstr){
21                $tagstr = str_replace(', ', ',', $tagstr);
22                $tagstr = str_replace(' ,', ',', $tagstr);
23                $tags = explode(',', $tagstr);
24                foreach ($tags as $key=>$tag){
25                        if(strlen($tag)>1){
26                                if (strlen($tag>15) && !(strstr($tag, ' ') || strstr($tag, '-'))) { $tag = substr($tag, 0, 15); }
27                       
28                                $tag = str_replace("\\", '', $tag);
29                                $tag = str_replace('"', '', $tag);
30                                $tag = str_replace("'", '', $tag);
31                                $tag = str_replace("&", '', $tag);
32                                $tag = strtolower($tag);
33                                $sql = "INSERT INTO cms_tags (tag, target, item_id) VALUES ('$tag', '$target', $item_id)";
34                                $inDB->query($sql);
35                        }
36                }
37        }
38        return;
39}
40
41function cmsClearTags($target, $item_id){
42    $inDB = cmsDatabase::getInstance();
43        $inDB->query("DELETE FROM cms_tags WHERE target='$target' AND item_id = $item_id");
44        return;
45}
46
47
48function cmsTagLine($target, $item_id, $links=true, $selected=''){
49    $inDB = cmsDatabase::getInstance();
50        $sql = "SELECT tag
51                        FROM cms_tags
52                        WHERE target='$target' AND item_id=$item_id
53                        ORDER BY tag DESC";
54        $rs = $inDB->query($sql) or die('Error while building tagline');
55        $html = '';
56        $tags = $inDB->num_rows($rs);
57        if ($tags){
58                $t = 1;
59                while ($tag=$inDB->fetch_assoc($rs)){
60                        if ($links){
61                                if ($selected==$tag['tag']){
62                                        $html .= '<a href="/search/tag/'.urlencode($tag['tag']).'" style="font-weight:bold;text-decoration:underline">'.$tag['tag'].'</a>';                     
63                                } else {
64                                        $html .= '<a href="/search/tag/'.urlencode($tag['tag']).'">'.$tag['tag'].'</a>';
65                                }
66                        } else {
67                                $html .= $tag['tag'];           
68                        }
69                        if ($t < $tags) { $html .= ', '; $t++; }
70                }
71        } else {
72                $html = '';
73        }
74        return $html;
75}
76
77function cmsTagBar($target, $item_id, $selected=''){
78    $inDB = cmsDatabase::getInstance();
79        if ($tagline = cmsTagLine($target, $item_id, true, $selected)){
80                return '<div class="taglinebar"><span class="label">Òåãè: </span><span class="tags">'.$tagline.'</span></div>';
81        } else {
82                return '';
83        }
84}
85
86function cmsTagItemLink($target, $item_id){
87    $inDB = cmsDatabase::getInstance();
88        switch ($target){
89                case 'content': $sql = "SELECT i.title as title, c.title as cat, i.seolink as seolink, c.seolink as cat_seolink
90                                                                FROM cms_content i
91                                                                LEFT JOIN cms_category c ON c.id = i.category_id
92                                                                WHERE i.id = '$item_id' AND i.published = 1";
93                                                $rs = $inDB->query($sql) ;
94                                                if ($inDB->num_rows($rs)){
95                                                        $item = $inDB->fetch_assoc($rs);
96                                                        $link =  '<a href="/'.$item['cat_seolink'].'" class="tag_searchcat">'.$item['cat'].'</a> &rarr; ';
97                                                        $link .= '<a href="/'.$item['seolink'].'.html" class="tag_searchitem">'.$item['title'].'</a>';
98                                                }
99                                                break; 
100                case 'blogpost': $sql = "SELECT i.title as title, i.id as item_id, c.title as cat, c.id as cat_id, c.owner as owner, c.user_id user_id, i.seolink as seolink, c.seolink as bloglink
101                                                                FROM cms_blog_posts i
102                                                                LEFT JOIN cms_blogs c ON c.id = i.blog_id
103                                                                WHERE i.id = '$item_id'";
104                                                $rs = $inDB->query($sql) ;
105                                                if ($inDB->num_rows($rs)){
106                                                        $item = $inDB->fetch_assoc($rs);
107                                                        if ($item['owner'] == 'club') { $item['cat'] = dbGetField('cms_clubs','id='.$item['user_id'],'title'); }
108                                                        $link =  '<a href="/blogs/'.$item['bloglink'].'" class="tag_searchcat">'.$item['cat'].'</a> &rarr; ';
109                                                        $link .= '<a href="/blogs/'.$item['bloglink'].'/'.$item['seolink'].'.html" class="tag_searchitem">'.$item['title'].'</a>';
110                                                }
111                                                break; 
112                case 'photo': $sql = "SELECT i.title as title, i.id as item_id, c.title as cat, c.id as cat_id
113                                                                FROM cms_photo_files i
114                                                                LEFT JOIN cms_photo_albums c ON c.id = i.album_id
115                                                                WHERE i.id = '$item_id'";
116                                                $rs = $inDB->query($sql) ;
117                                                if ($inDB->num_rows($rs)){
118                                                        $item = $inDB->fetch_assoc($rs);
119                                                        $link =  '<a href="/photos/'.$item['cat_id'].'" class="tag_searchcat">'.$item['cat'].'</a> &rarr; ';
120                                                        $link .= '<a href="/photos/photo'.$item['item_id'].'.html" class="tag_searchitem">'.$item['title'].'</a>';
121                                                }
122                                                break; 
123                case 'userphoto': $sql = "SELECT i.title as title, i.id as item_id, c.nickname as cat, c.id as cat_id, c.login as login
124                                                                FROM cms_user_photos i
125                                                                LEFT JOIN cms_users c ON c.id = i.user_id
126                                                                WHERE i.id = '$item_id'";
127                                                $rs = $inDB->query($sql) ;
128                                                if ($inDB->num_rows($rs)){
129                                                        $item = $inDB->fetch_assoc($rs);
130                                                        $link =  '<a href="'.cmsUser::getProfileURL($item['login']).'" class="tag_searchcat">'.$item['cat'].'</a> &rarr; ';
131                                                        $link .= '<a href="/users/'.$item['cat_id'].'/photo'.$item['item_id'].'.html" class="tag_searchitem">'.$item['title'].'</a>';
132                                                }
133                                                break; 
134                case 'catalog': $sql = "SELECT i.title as title, i.id as item_id, c.title as cat, c.id as cat_id
135                                                                FROM cms_uc_items i
136                                                                LEFT JOIN cms_uc_cats c ON c.id = i.category_id
137                                                                WHERE i.id = '$item_id'";
138                                                $rs = $inDB->query($sql) ;
139                                                if ($inDB->num_rows($rs)){
140                                                        $item = $inDB->fetch_assoc($rs);
141                                                        $link =  '<a href="/catalog/'.$item['cat_id'].'" class="tag_searchcat">'.$item['cat'].'</a> &rarr; ';
142                                                        $link .= '<a href="/catalog/item'.$item['item_id'].'.html" class="tag_searchitem">'.$item['title'].'</a>';
143                                                }
144                                                break; 
145                case 'video': $sql = "SELECT i.title as title, i.id as item_id, c.title as cat, c.id as cat_id
146                                                                FROM cms_video_movie i
147                                                                LEFT JOIN cms_video_category c ON c.id = i.cat_id
148                                                                WHERE i.id = '$item_id'";
149                                                $rs = $inDB->query($sql) ;
150                                                if ($inDB->num_rows($rs)){
151                                                        $item = $inDB->fetch_assoc($rs);
152                                                        $link =  '<a href="/video/'.$item['cat_id'].'" class="tag_searchcat">'.$item['cat'].'</a> &rarr; ';
153                                                        $link .= '<a href="/video/movie'.$item['item_id'].'.html" class="tag_searchitem">'.$item['title'].'</a>';
154                                                }
155                                                break;
156                case 'shop': $sql = "SELECT i.title as title, i.seolink as seolink, c.title as cat, c.seolink as cat_seolink
157                                                         FROM cms_shop_items i
158                                                         LEFT JOIN cms_shop_cats c ON c.id = i.category_id
159                                                         WHERE i.id = '$item_id'";
160                                                $rs = $inDB->query($sql) ;
161                                                if ($inDB->num_rows($rs)){
162                                                        $item = $inDB->fetch_assoc($rs);
163                                                        $link =  '<a href="/shop/'.$item['cat_seolink'].'" class="tag_searchcat">'.$item['cat'].'</a> &rarr; ';
164                                                        $link .= '<a href="/shop/'.$item['seolink'].'.html" class="tag_searchitem">'.$item['title'].'</a>';
165                                                }
166                                                break;
167                case 'maps': $sql = "SELECT i.title as title, i.seolink as seolink, c.title as cat, c.seolink as cat_seolink
168                                                         FROM cms_maps_items i
169                                                         LEFT JOIN cms_maps_cats c ON c.id = i.category_id
170                                                         WHERE i.id = '$item_id'";
171                                                $rs = $inDB->query($sql) ;
172                                                if ($inDB->num_rows($rs)){
173                                                        $item = $inDB->fetch_assoc($rs);
174                                                        $link =  '<a href="/maps/'.$item['cat_seolink'].'" class="tag_searchcat">'.$item['cat'].'</a> &rarr; ';
175                                                        $link .= '<a href="/maps/'.$item['seolink'].'.html" class="tag_searchitem">'.$item['title'].'</a>';
176                                                }
177                                                break;
178        }
179        return $link;
180}
181
182function cmsTagsList(){
183    $inDB = cmsDatabase::getInstance();
184        $html = '';             
185        $sql = "SELECT t.tag, COUNT(t.tag) as num
186                        FROM cms_tags t
187                        GROUP BY t.tag
188                        ORDER BY t.tag";       
189        $result = $inDB->query($sql) ;
190        if ($inDB->num_rows($result)>0){
191                while($tag = $inDB->fetch_assoc($result)){
192                        if ($tag['tag']){
193                                $html .= '<a href="/search/tag/'.urlencode($tag['tag']).'">'.$tag['tag'].'</a> ('.$tag['num'].') ';
194                        }
195                }
196        }               
197        return $html;
198}
199?>
Note: See TracBrowser for help on using the repository browser.