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
|
<?php
/**
* $Header: /cvsroot/bitweaver/_bit_boards/Attic/BitBoardForum.php,v 1.2 2006/07/26 22:45:29 hash9 Exp $
* $Id: BitBoardForum.php,v 1.2 2006/07/26 22:45:29 hash9 Exp $
*/
/**
* BitBoardBoard class to illustrate best practices when creating a new bitweaver package that
* builds on core bitweaver functionality, such as the Liberty CMS engine
*
* @date created 2004/8/15
* @author spider <spider@steelsun.com>
* @version $Revision: 1.2 $ $Date: 2006/07/26 22:45:29 $ $Author: hash9 $
* @class BitBoardBoard
*/
require_once( LIBERTY_PKG_PATH.'LibertyAttachable.php' );
class BitBoardForum extends LibertyAttachable {
/**
* During initialisation, be sure to call our base constructors
**/
function BitBoardForum() {
LibertyAttachable::LibertyAttachable();
}
function loadContent($contentId) {
global $gBitDb;
global $gBitUser;
//var_dump($GLOBALS);
if( LibertyContent::verifyId( $contentId ) ) {
// LibertyContent::load()assumes you have joined already, and will not execute any sql!
// This is a significant performance optimization
$bindVars = array();
$selectSql = $joinSql = $whereSql = '';
array_push( $bindVars, $contentId );
$gBitUser->getServicesSql( 'content_load_sql_function', $selectSql, $joinSql, $whereSql, $bindVars );
$query = "SELECT lc.*, uue.`login` AS modifier_user, uue.`real_name` AS modifier_real_name, uuc.`login` AS creator_user, uuc.`real_name` AS creator_real_name $selectSql
FROM `".BIT_DB_PREFIX."liberty_content` lc $joinSql
LEFT JOIN `".BIT_DB_PREFIX."users_users` uue ON( uue.`user_id` = lc.`modifier_user_id` )
LEFT JOIN `".BIT_DB_PREFIX."users_users` uuc ON( uuc.`user_id` = lc.`user_id` )
WHERE lc.`content_id`=? $whereSql";
$result = $gBitDb->query( $query, $bindVars );
$ret = array();
if( $result && $result->numRows() ) {
$ret = $result->fields;
$ret['creator'] =( isset( $result->fields['creator_real_name'] )? $result->fields['creator_real_name'] : $result->fields['creator_user'] );
$ret['editor'] =( isset( $result->fields['modifier_real_name'] )? $result->fields['modifier_real_name'] : $result->fields['modifier_user'] );
$ret['display_url'] = BIT_ROOT_URL."index.php?content_id=$contentId";
}
}
return( $ret );
}
/**
* This function generates a list of records from the liberty_content database for use in a list page
**/
function getFullList( &$pParamHash ) {
global $gBitSystem, $gBitUser;
$BIT_DB_PREFIX=BIT_DB_PREFIX;
// this makes sure parameters used later on are set
LibertyAttachable::prepGetList( $pParamHash );
$selectSql = $joinSql = $whereSql = '';
$bindVars = array();
$this->getServicesSql( 'content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars );
// this will set $find, $sort_mode, $max_records and $offset
extract( $pParamHash );
if( is_array( $find ) ) {
// you can use an array of pages
$whereSql .= " AND lc.`title` IN( ".implode( ',',array_fill( 0,count( $find ),'?' ) )." )";
$bindVars = array_merge ( $bindVars, $find );
} elseif( is_string( $find ) ) {
// or a string
$whereSql .= " AND UPPER( lc.`title` )like ? ";
$bindVars[] = '%' . strtoupper( $find ). '%';
}
if (empty($pParamHash['ct'])) {
$query= "SELECT DISTINCT lcom.`root_id` AS root_id, lc.`content_id` AS content_id, lc.`title` AS title, lc.`content_type_guid` AS content_type_guid,
( SELECT count(*) FROM `".BIT_DB_PREFIX."liberty_comments` slcom WHERE slcom.`root_id`=slcom.`parent_id` AND slcom.`root_id`=lc.`content_id` ) AS post_count
$selectSql
FROM ".BIT_DB_PREFIX."liberty_content lc
INNER JOIN ".BIT_DB_PREFIX."liberty_comments lcom ON( lc.`content_id`=lcom.`root_id` )
$joinSql
WHERE TRUE $whereSql
";
$query_cant= "SELECT COUNT(DISTINCT lcom.root_id)
FROM ".BIT_DB_PREFIX."liberty_content lc
INNER JOIN ".BIT_DB_PREFIX."liberty_comments lcom ON( lc.content_id=lcom.root_id )
$joinSql
WHERE TRUE $whereSql
";
} else {
$whereSql .= " AND lc.`content_type_guid`= '{$pParamHash['ct']}'";
$query= "SELECT lc.`content_id` AS content_id, lc.`title` AS title, lc.`content_type_guid` AS content_type_guid,
( SELECT count(*) FROM `".BIT_DB_PREFIX."liberty_comments` lcom WHERE lcom.`root_id`=lcom.`parent_id` AND lcom.`root_id`=lc.`content_id` ) AS post_count
$selectSql
FROM ".BIT_DB_PREFIX."liberty_content lc
$joinSql
WHERE TRUE $whereSql
";
$query_cant= "SELECT COUNT(*)
FROM ".BIT_DB_PREFIX."liberty_content lc
$joinSql
WHERE TRUE $whereSql
";
}
$result = $this->mDb->query( $query, $bindVars, $max_records, $offset );
$ret = array();
while( $res = $result->fetchRow() ) {
$res['url']= BITBOARDS_PKG_URL."index.php?c={$res['content_id']}";
$ret[] = $res;
}
$pParamHash["cant"] = $this->mDb->getOne( $query_cant, $bindVars );
// add all pagination info to pParamHash
LibertyAttachable::postGetList( $pParamHash );
return $ret;
}
function getForumBoardSelectList() {
global $gBitDb;
$query = "SELECT lc.`content_id` as content_id, lc.`title` as title,
( SELECT count(*)
FROM `".BIT_DB_PREFIX."forum_map` AS map
INNER JOIN `".BIT_DB_PREFIX."liberty_comments` lcom ON (map.`topic_content_id` = lcom.`root_id`)
WHERE lcom.`root_id`=lcom.`parent_id` AND map.`board_content_id`=lc.`content_id`
) AS post_count
FROM `".BIT_DB_PREFIX."forum_board` b
INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON( lc.`content_id` = b.`content_id` )
ORDER BY lc.`title` ASC";
$result = $gBitDb->getAll( $query);
$ret = array();
while( $res = $result->fetchRow() ) {
$ret[] = $res;
}
return $ret;
}
/**
* Generates the URL to the bitboard page
* @return the link to display the page.
*/
function getForumDisplayUrl(&$lcontent) {
global $gBitDb;
$ret = NULL;
if( @$lcontent->verifyId( $lcontent->mContentId ) ) {
if ($lcontent->mInfo['content_type_guid']=='bitforum') {
$bId = $gBitDb->getOne("SELECT `board_id` FROM `".BIT_DB_PREFIX."forum_board` s WHERE s.`content_id`=?",array($lcontent->mContentId));
$ret = BITBOARDS_PKG_URL."index.php?b=$bId";
} else {
$ret = BITBOARDS_PKG_URL."index.php?c=".$lcontent->mContentId;
}
}
return $ret;
}
}
?>
|