/
LibertyItag.php
198 lines (173 loc) · 6.51 KB
/
LibertyItag.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
/**
* @version $Header$
* created 2006/08/01
* @author Will <will@onnyturf.com>
*
* @package geo
*/
/**
* Initialize
*/
require_once( KERNEL_PKG_PATH.'BitBase.php' );
/**
* @package geo
*/
class LibertyItag extends LibertyBase {
var $mAttachementId;
function LibertyItag( $pAttachementId=NULL ) {
LibertyBase::LibertyBase();
$this->mAttachementId = $pAttachementId;
}
/**
* Load the data from the database
* @param pParamHash be sure to pass by reference in case we need to make modifcations to the hash
**/
function load() {
// if( $this->isValid() ) {
$query = "SELECT iia.`comment_id` as tag_no, lc.`title` as description, iia.*
FROM `".BIT_DB_PREFIX."itags_image_areas` iia
JOIN `".BIT_DB_PREFIX."liberty_comments` lcm ON lcm.`comment_id` = iia.`comment_id`
JOIN `".BIT_DB_PREFIX."liberty_content` lc ON lc.`content_id` = lcm.`content_id`
WHERE iia.`attachment_id` = ?";
$this->mInfo['itags'] = $this->mDb->getAssoc( $query, array( $this->mAttachementId ) );
// }
return( count( $this->mInfo ) );
}
/**
* @param array pParams hash of values that will be used to store the page
* @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why
* @access public
**/
function store( &$pParamHash ) {
if( $this->verify( $pParamHash ) ) {
$this->mDb->StartTrans();
$storeComment = new LibertyComment( @BitBase::verifyId( $pParamHash['comment_id'] ) ? $pParamHash['comment_id'] : NULL );
if ( $this->verifyId( $storeComment->mCommentId ) ) {
$this->mDb->query( "DELETE FROM `".BIT_DB_PREFIX."itags_image_areas` WHERE `attachment_id`=? and `comment_id`=?", array( $this->mAttachmentId, $storeComment->mCommentId ) );
}
if( $storeComment->storeComment( $pParamHash['comment'] )) {
// store successful
$storeComment->loadComment();
$this->mDb->query( "INSERT INTO `".BIT_DB_PREFIX."itags_image_areas` ( `attachment_id`, `comment_id`, `itag_top`, `itag_left`, `itag_width`, `itag_height` )
VALUES ( ?, ?, ?, ?, ?, ? )",
array( $this->mAttachementId, $storeComment->mCommentId, $pParamHash['top'], $pParamHash['left'], $pParamHash['width'], $pParamHash['height'] ) );
}
$this->mDb->CompleteTrans();
$this->load();
}
return( count( $this->mErrors )== 0 );
}
/**
* Make sure the data is safe to store
* @param array pParams reference to hash of values that will be used to store the page, they will be modified where necessary
* @return bool TRUE on success, FALSE if verify failed. If FALSE, $this->mErrors will have reason why
* @access private
**/
function verify( &$pParamHash ) {
$pParamHash['itags_store'] = array();
$pParamHash['comment']['content_id'] = $this->mAttachementId;
$pParamHash['comment']['comments_parent_id'] = $this->mAttachementId;
$pParamHash['comment']['comment_title'] = $pParamHash['description'];
$pParamHash['comment']['comment_data'] = $pParamHash['description'];
return( count( $this->mErrors )== 0 );
}
/**
* check if the mAttachemntId is set and valid
*/
function isValid() {
return( @BitBase::verifyId( $this->mAttachemntId ) );
}
/**
* This function removes a set of image area tags
**/
function expunge() {
$ret = FALSE;
if( $this->isValid() ) {
$query = "DELETE FROM `".BIT_DB_PREFIX."itags_image_areas` WHERE `attachment_id` = ?";
$result = $this->mDb->query( $query, array( $this->mAttachemntId ) );
}
return $ret;
}
/**
* This function removes a single image area tag
**/
function expunge_tag( $itagId ) {
$ret = FALSE;
$storeComment = new LibertyComment( @BitBase::verifyId( $itagId ) ? $itagId : NULL );
$storeComment->mDb->StartTrans();
if ( $storeComment->verifyId( $storeComment->mCommentId ) ) {
$storeComment->mDb->query( "DELETE FROM `".BIT_DB_PREFIX."itags_image_areas` WHERE `attachment_id`=? and `comment_id`=?"
, array( $this->mAttachementId, $storeComment->mCommentId ) );
}
$storeComment->expunge();
$storeComment->mDb->CompleteTrans();
$this->load();
return $ret;
}
/**
* This function gets a list of tags
**/
function getList( &$pListHash ) {
global $gBitUser, $gBitSystem;
$this->prepGetList( $pListHash );
$query = "SELECT DISTINCT iia.`attachment_id`
FROM `".BIT_DB_PREFIX."itags_image_areas` iia";
$ret = $this->mDb->getAssoc( $query );
}
}
/********* SERVICE FUNCTIONS *********/
function itags_content_display( &$pObject ) {
global $gBitSystem, $gBitSmarty, $gBitUser;
if( method_exists( $pObject, 'getContentType' ) && $gBitSystem->isFeatureActive( 'tags_tag_'.$pObject->getContentType()) ){
if ( $gBitSystem->isPackageActive( 'itags' ) ) {
if( $gBitUser->hasPermission( 'p_itags_view' ) ) {
$tag = new LibertyItag( $pObject->mAttachmentId );
if( $tag->load() ) {
$gBitSmarty->assign( 'itagData', !empty( $tag->mInfo['itags'] ) ? $tag->mInfo['itags'] : NULL );
}
}
}
}
}
function itags_content_load_sql() {
global $gBitSystem;
$ret = array();
$ret['select_sql'] = " , itags.`comment_id` , itags.`itag_top`, itags.`itag_left`, itags.`itag_width`, itags.`itag_height`";
$ret['join_sql'] = " LEFT JOIN `".BIT_DB_PREFIX."itags_image_areas` itags ON ( la.`attachment_id`=itags.`attachment_id` )";
return $ret;
}
/**
* @param $pParamHash['up']['lng'], $pParamHash['up']['lat'], $pParamHash['down']['lng'], $pParamHash['down']['lat']
**/
function itags_content_list_sql( &$pObject, $pParamHash=NULL ) {
global $gBitSystem;
$ret = array();
if ( !empty( $pObject->mInfo['attachment_id'] ) ) {
$ret['select_sql'] = " , itags.`comment_id` , itags.`itag_top`, itags.`itag_left`, itags.`itag_width`, itags.`itag_height`";
$ret['join_sql'] = " LEFT JOIN `".BIT_DB_PREFIX."itags_image_areas` itags ON ( itags.`attachment_id` = ".$pObject->mInfo['attachment_id'].")";
$ret['where_sql'] = "";
}
return $ret;
}
function itags_content_store( &$pObject, &$pParamHash ) {
global $gBitSystem;
$errors = NULL;
// If a content access system is active and we have geo in our store hash, let's call it
if( $gBitSystem->isPackageActive( 'itags' ) && !empty( $pParamHash['itags'] ) ) {
$itags = new LibertyItag( $pObject->mAttachmentId );
// if both lat and lng fields are empty then the user is trying to clear geo data
if( empty( $pParamHash['itags']['top'] ) && empty( $pParamHash['itags']['left'] ) ) {
$geo->expunge();
// store the geo data
} elseif ( !$itags->store( $pParamHash ) ) {
$errors=$itags->mErrors;
}
}
return( $errors );
}
function itags_content_expunge( &$pObject ) {
// $itags = new LibertyItag( $pObject->mAttachmentId );
// $itags->expunge();
}
?>