1<?php
2
3/*
4	[UCenter] (C)2001-2099 Comsenz Inc.
5	This is NOT a freeware, use is subject to license terms
6
7	$Id: tag.php 1059 2011-03-01 07:25:09Z monkey $
8*/
9
10!defined('IN_UC') && exit('Access Denied');
11
12class tagmodel {
13
14	var $db;
15	var $base;
16
17	function __construct(&$base) {
18		$this->tagmodel($base);
19	}
20
21	function tagmodel(&$base) {
22		$this->base = $base;
23		$this->db = $base->db;
24	}
25
26	function get_tag_by_name($tagname) {
27		$arr = $this->db->fetch_all("SELECT * FROM ".UC_DBTABLEPRE."tags WHERE tagname='$tagname'");
28		return $arr;
29	}
30
31	function get_template($appid) {
32		$result = $this->db->result_first("SELECT tagtemplates FROM ".UC_DBTABLEPRE."applications WHERE appid='$appid'");
33		return $result;
34	}
35
36	function updatedata($appid, $data) {
37		$appid = intval($appid);
38		include_once UC_ROOT.'lib/xml.class.php';
39		$data = xml_unserialize($data);
40		$this->base->load('app');
41		$data[0] = addslashes($data[0]);
42		$datanew = array();
43		if(is_array($data[1])) {
44			foreach($data[1] as $r) {
45				$datanew[] = $_ENV['misc']->array2string($r);
46			}
47		}
48		$tmp = $_ENV['app']->get_apps('type', "appid='$appid'");
49		$datanew = addslashes($tmp[0]['type']."\t".implode("\t", $datanew));
50		if(!empty($data[0])) {
51			$return = $this->db->result_first("SELECT count(*) FROM ".UC_DBTABLEPRE."tags WHERE tagname='$data[0]' AND appid='$appid'");
52			if($return) {
53				$this->db->query("UPDATE ".UC_DBTABLEPRE."tags SET data='$datanew', expiration='".$this->base->time."' WHERE tagname='$data[0]' AND appid='$appid'");
54			} else {
55				$this->db->query("INSERT INTO ".UC_DBTABLEPRE."tags (tagname, appid, data, expiration) VALUES ('$data[0]', '$appid', '$datanew', '".$this->base->time."')");
56			}
57		}
58	}
59
60	function formatcache($appid, $tagname) {
61		$return = $this->db->result_first("SELECT count(*) FROM ".UC_DBTABLEPRE."tags WHERE tagname='$tagname' AND appid='$appid'");
62		if($return) {
63			$this->db->query("UPDATE ".UC_DBTABLEPRE."tags SET expiration='0' WHERE tagname='$tagname' AND appid='$appid'");
64		} else {
65			$this->db->query("INSERT INTO ".UC_DBTABLEPRE."tags (tagname, appid, expiration) VALUES ('$tagname', '$appid', '0')");
66		}
67	}
68
69}
70
71?>