Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 779 lines (686 sloc) 32.038 kb
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
1 <?php
2 /**
9090a1d @spiderr remove old spell checking
spiderr authored
3 * @version $Header: /cvsroot/bitweaver/_bit_articles/BitArticle.php,v 1.77 2006/04/10 17:55:55 spiderr Exp $
d403bf6 @lsces Add PHPDoc headings to package
lsces authored
4 * @package article
5 *
6 * Copyright( c )2004 bitweaver.org
7 * Copyright( c )2003 tikwiki.org
8 * Copyright( c )2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
9 * All Rights Reserved. See copyright.txt for details and a complete list of authors.
10 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details
11 *
9090a1d @spiderr remove old spell checking
spiderr authored
12 * $Id: BitArticle.php,v 1.77 2006/04/10 17:55:55 spiderr Exp $
d403bf6 @lsces Add PHPDoc headings to package
lsces authored
13 *
14 * Article class is used when accessing BitArticles. It is based on TikiSample
15 * and builds on core bitweaver functionality, such as the Liberty CMS engine.
16 *
17 * created 2004/8/15
18 * @author wolffy <wolff_borg@yahoo.com.au>
9090a1d @spiderr remove old spell checking
spiderr authored
19 * @version $Revision: 1.77 $ $Date: 2006/04/10 17:55:55 $ $Author: spiderr $
d403bf6 @lsces Add PHPDoc headings to package
lsces authored
20 */
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
21
22 /**
d403bf6 @lsces Add PHPDoc headings to package
lsces authored
23 * Required setup
24 */
04136bd @xxing get article submissions working
xxing authored
25 require_once( LIBERTY_PKG_PATH.'LibertyAttachable.php' );
26 require_once( ARTICLES_PKG_PATH.'BitArticleTopic.php' );
27 require_once( ARTICLES_PKG_PATH.'BitArticleType.php' );
28 require_once( LIBERTY_PKG_PATH.'LibertyComment.php' );
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
29
c83a84e @xxing merge recent changes into HEAD
xxing authored
30 define( 'ARTICLE_SPLIT_REGEX', "/\.{3}split\.{3}[\r\n]?/i" );
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
31
d403bf6 @lsces Add PHPDoc headings to package
lsces authored
32 /**
33 * @package article
34 */
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
35 class BitArticle extends LibertyAttachable {
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
36 /**
7f0e5d8 @xxing more work on getting articles going
xxing authored
37 * Primary key for articles
cf7b087 @xxing add some documentation
xxing authored
38 * @access public
7f0e5d8 @xxing more work on getting articles going
xxing authored
39 */
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
40 var $mArticleId;
41 var $mTypeId;
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
42 var $mTopicId;
cf7b087 @xxing add some documentation
xxing authored
43
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
44 /**
ec0a861 @xxing add some more documentation
xxing authored
45 * Initiate the articles class
cf7b087 @xxing add some documentation
xxing authored
46 * @param $pArticleId article id of the article we want to view
47 * @param $pContentId content id of the article we want to view
48 * @access private
7f0e5d8 @xxing more work on getting articles going
xxing authored
49 **/
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
50 function BitArticle( $pArticleId=NULL, $pContentId=NULL ) {
51 $this->mArticleId = $pArticleId;
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
52 $this->mTypeId = NULL;
53 $this->mTopicId = NULL;
7f0e5d8 @xxing more work on getting articles going
xxing authored
54
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
55 LibertyAttachable::LibertyAttachable();
c31efa1 @xxing fix admin screen and set more usable defaults in schema
xxing authored
56 $this->registerContentType( BITARTICLE_CONTENT_TYPE_GUID, array(
57 'content_description' => 'Article',
7f0e5d8 @xxing more work on getting articles going
xxing authored
58 'handler_class' => 'BitArticle',
59 'handler_package' => 'articles',
60 'handler_file' => 'BitArticle.php',
61 'maintainer_url' => 'http://www.bitweaver.org'
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
62 ) );
63 $this->mContentId = $pContentId;
64 $this->mContentTypeGuid = BITARTICLE_CONTENT_TYPE_GUID;
54fb5b7 @xxing merge recent changes into HEAD
xxing authored
65 if( ! @$this->verifyId( $this->mArticleId ) ) {
66 $this->mArticleId = NULL;
67 }
68 if( ! @$this->verifyId( $this->mContentId ) ) {
69 $this->mContentId = NULL;
70 }
1f9adbe @xxing make "read more" links conditional, depending on whether there is more t...
xxing authored
71 }
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
72
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
73 /**
7f0e5d8 @xxing more work on getting articles going
xxing authored
74 * Load the data from the database
cf7b087 @xxing add some documentation
xxing authored
75 * @access public
7f0e5d8 @xxing more work on getting articles going
xxing authored
76 **/
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
77 function load() {
54fb5b7 @xxing merge recent changes into HEAD
xxing authored
78 if( @$this->verifyId( $this->mArticleId ) || @$this->verifyId( $this->mContentId ) ) {
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
79 // LibertyContent::load()assumes you have joined already, and will not execute any sql!
80 // This is a significant performance optimization
54fb5b7 @xxing merge recent changes into HEAD
xxing authored
81 $lookupColumn = @$this->verifyId( $this->mArticleId ) ? 'article_id' : 'content_id';
ce4e5d1 @xxing use correct hash in query()
xxing authored
82 $bindVars[] = $lookupId = @BitBase::verifyId( $this->mArticleId ) ? $this->mArticleId : $this->mContentId;
3556172 @xxing rename content_load_function to content_load_sql_function
xxing authored
83 $this->getServicesSql( 'content_load_sql_function', $selectSql, $joinSql, $whereSql, $bindVars );
838a838 @lsces Add ServicesSQL facility
lsces authored
84
ce4e5d1 @xxing use correct hash in query()
xxing authored
85 $query = "SELECT a.*, lc.*, atype.*, atopic.*,
86 uue.`login` AS `modifier_user`, uue.`real_name` AS `modifier_real_name`,
87 uuc.`login` AS `creator_user`, uuc.`real_name` AS `creator_real_name` ,
88 lf.`storage_path` as `image_storage_path` $selectSql
89 FROM `".BIT_DB_PREFIX."articles` a
90 LEFT OUTER JOIN `".BIT_DB_PREFIX."article_types` atype ON( atype.`article_type_id` = a.`article_type_id` )
91 LEFT OUTER JOIN `".BIT_DB_PREFIX."article_topics` atopic ON( atopic.`topic_id` = a.`topic_id` )
92 INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON( lc.`content_id` = a.`content_id` )
93 LEFT JOIN `".BIT_DB_PREFIX."users_users` uue ON( uue.`user_id` = lc.`modifier_user_id` )
94 LEFT JOIN `".BIT_DB_PREFIX."users_users` uuc ON( uuc.`user_id` = lc.`user_id` )
95 LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_attachments` la ON( la.`attachment_id` = a.`image_attachment_id` )
96 LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_files` lf ON( lf.`file_id` = la.`foreign_id` ) $joinSql
97 WHERE a.`$lookupColumn`=? $whereSql";
98 $result = $this->mDb->query( $query, $bindVars );
7f0e5d8 @xxing more work on getting articles going
xxing authored
99
100 global $gBitSystem;
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
101 if( $result && $result->numRows() ) {
b548033 @spiderr fix ->fields calls
spiderr authored
102 $this->mInfo = $result->fetchRow();
b99c416 @xxing get topic image on load()
xxing authored
103
8c5f309 @xxing clean up articles custom image upload stuff
xxing authored
104 // if a custom image for the article exists, use that, then use an attachment, then use the topic image
539fa01 @xxing rename img_url to image_url
xxing authored
105 $this->mInfo['image_url'] = BitArticle::getImageUrl( $this->mInfo );
b99c416 @xxing get topic image on load()
xxing authored
106
b548033 @spiderr fix ->fields calls
spiderr authored
107 $this->mContentId = $this->mInfo['content_id'];
108 $this->mArticleId = $this->mInfo['article_id'];
109 $this->mTopicId = $this->mInfo['topic_id'];
110 $this->mTypeId = $this->mInfo['article_type_id'];
7f0e5d8 @xxing more work on getting articles going
xxing authored
111
ea85f9e @xxing new API for parseData(); please view ApiChangeLog for details
xxing authored
112 $this->mInfo['creator'] = ( isset( $this->mInfo['creator_real_name'] )? $this->mInfo['creator_real_name'] : $this->mInfo['creator_user'] );
113 $this->mInfo['editor'] = ( isset( $this->mInfo['modifier_real_name'] )? $this->mInfo['modifier_real_name'] : $this->mInfo['modifier_user'] );
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
114 $this->mInfo['display_url'] = $this->getDisplayUrl();
ea85f9e @xxing new API for parseData(); please view ApiChangeLog for details
xxing authored
115 $this->mInfo['data'] = preg_replace( ARTICLE_SPLIT_REGEX, "", $this->mInfo['data'] );
116 $this->mInfo['parsed_data'] = $this->parseData();
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
117
9adba87 @xxing display article publication time as time that has passed since
xxing authored
118 /* get the "ago" time */
caa8305 @spiderr move BitSystem:: preferences methods to get/set/load/storeConfig to avoi...
spiderr authored
119 $this->mInfo['time_difference'] = BitDate::calculateTimeDifference( $this->mInfo['publish_date'], NULL, $gBitSystem->getConfig( 'article_date_display_format' ) );
9adba87 @xxing display article publication time as time that has passed since
xxing authored
120
fa7948e @xxing concatenate whereSql
xxing authored
121 $comment = &new LibertyComment();
122 $this->mInfo['num_comments'] = $comment->getNumComments( $this->mInfo['content_id'] );
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
123 LibertyAttachable::load();
838a838 @lsces Add ServicesSQL facility
lsces authored
124 } else {
125 $this->mArticleId = NULL;
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
126 }
127 }
5e14ed2 @xxing clean up author name code
xxing authored
128 return( count( $this->mInfo ) );
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
129 }
7f0e5d8 @xxing more work on getting articles going
xxing authored
130
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
131 /**
ec0a861 @xxing add some more documentation
xxing authored
132 * Store article data after submission
cf7b087 @xxing add some documentation
xxing authored
133 * @param array pParamHash of values that will be used to store the page
7f0e5d8 @xxing more work on getting articles going
xxing authored
134 * @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why
135 * @access public
136 **/
ee831c6 @xxing get custom article image working
xxing authored
137 function store( &$pParamHash ) {
138 global $gBitSystem;
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
139 if( $this->verify( $pParamHash )&& LibertyAttachable::store( $pParamHash ) ) {
f210a14 massive table de-tikification. changed all tiki_ table prefixes with teh...
bitweaver.org authored
140 $table = BIT_DB_PREFIX."articles";
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
141 $this->mDb->StartTrans();
ee831c6 @xxing get custom article image working
xxing authored
142
5a59732 @xxing use $this->isValid() to check for $this->mArticleId
xxing authored
143 if( $this->isValid() ) {
8d929a0 @spiderr major change of BitDbBase::associateUpdate method - it now takes a simpl...
spiderr authored
144 $result = $this->mDb->associateUpdate( $table, $pParamHash['article_store'], array( "article_id" => $pParamHash['article_id'] ) );
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
145 } else {
146 $pParamHash['article_store']['content_id'] = $pParamHash['content_id'];
147 if( isset( $pParamHash['article_id'] )&& is_numeric( $pParamHash['article_id'] ) ) {
ee831c6 @xxing get custom article image working
xxing authored
148 // if pParamHash['article_id'] is set, someone is requesting a particular article_id. Use with caution!
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
149 $pParamHash['article_store']['article_id'] = $pParamHash['article_id'];
150 } else {
f210a14 massive table de-tikification. changed all tiki_ table prefixes with teh...
bitweaver.org authored
151 $pParamHash['article_store']['article_id'] = $this->mDb->GenID( 'articles_article_id_seq' );
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
152 }
153 $this->mArticleId = $pParamHash['article_store']['article_id'];
154 $result = $this->mDb->associateInsert( $table, $pParamHash['article_store'] );
155 }
156
8c5f309 @xxing clean up articles custom image upload stuff
xxing authored
157 // we need to store any custom image that has been uploaded
158 $this->storeImage( $pParamHash, $_FILES['article_image'] );
159
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
160 $this->mDb->CompleteTrans();
161 $this->load();
162 }
6f9ed7a @xxing add a link to remove a custom image
xxing authored
163 return ( count( $this->mErrors ) == 0 );
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
164 }
165
166 /**
7f0e5d8 @xxing more work on getting articles going
xxing authored
167 * Make sure the data is safe to store
168 * @param pParamHash be sure to pass by reference in case we need to make modifcations to the hash
169 * @param array pParams reference to hash of values that will be used to store the page, they will be modified where necessary
170 * @return bool TRUE on success, FALSE if verify failed. If FALSE, $this->mErrors will have reason why
171 * @access private
172 **/
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
173 function verify( &$pParamHash ) {
174 global $gBitUser, $gBitSystem;
7f0e5d8 @xxing more work on getting articles going
xxing authored
175
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
176 // make sure we're all loaded up of we have a mArticleId
177 if( $this->mArticleId && empty( $this->mInfo ) ) {
178 $this->load();
179 }
7f0e5d8 @xxing more work on getting articles going
xxing authored
180
54fb5b7 @xxing merge recent changes into HEAD
xxing authored
181 if( @$this->verifyId( $this->mInfo['content_id'] ) ) {
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
182 $pParamHash['content_id'] = $this->mInfo['content_id'];
183 }
7f0e5d8 @xxing more work on getting articles going
xxing authored
184
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
185 // It is possible a derived class set this to something different
04136bd @xxing get article submissions working
xxing authored
186 if( empty( $pParamHash['content_type_guid'] )&& !empty( $this->mContentTypeGuid ) ) {
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
187 $pParamHash['content_type_guid'] = $this->mContentTypeGuid;
188 }
7f0e5d8 @xxing more work on getting articles going
xxing authored
189
54fb5b7 @xxing merge recent changes into HEAD
xxing authored
190 if( @$this->verifyId( $pParamHash['content_id'] ) ) {
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
191 $pParamHash['article_store']['content_id'] = $pParamHash['content_id'];
192 }
7f0e5d8 @xxing more work on getting articles going
xxing authored
193
04136bd @xxing get article submissions working
xxing authored
194 if( !empty( $pParamHash['author_name'] ) ) {
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
195 $pParamHash['article_store']['author_name'] = $pParamHash['author_name'];
196 }
7f0e5d8 @xxing more work on getting articles going
xxing authored
197
daf5fbe @xxing existing image attachment working as well now - w00t!
xxing authored
198 // if no image attachment id is given, we set it null. this way a user can remove an attached image
47348b5 @xxing clean up image attachments for articles, allow custom size for resizes, ...
xxing authored
199 // TODO: since we allow custom image size for article images, we should create a resized image of the original here.
54fb5b7 @xxing merge recent changes into HEAD
xxing authored
200 if( @$this->verifyId( $pParamHash['image_attachment_id'] ) ) {
daf5fbe @xxing existing image attachment working as well now - w00t!
xxing authored
201 $pParamHash['article_store']['image_attachment_id'] = ( int )$pParamHash['image_attachment_id'];
202 } else {
203 $pParamHash['article_store']['image_attachment_id'] = NULL;
204 }
205
54fb5b7 @xxing merge recent changes into HEAD
xxing authored
206 if( @$this->verifyId( $pParamHash['topic_id'] ) ) {
04136bd @xxing get article submissions working
xxing authored
207 $pParamHash['article_store']['topic_id'] =( int )$pParamHash['topic_id'];
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
208 }
7f0e5d8 @xxing more work on getting articles going
xxing authored
209
54fb5b7 @xxing merge recent changes into HEAD
xxing authored
210 if( @$this->verifyId( $pParamHash['article_type_id'] ) ) {
04136bd @xxing get article submissions working
xxing authored
211 $pParamHash['article_store']['article_type_id'] =( int )$pParamHash['article_type_id'];
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
212 }
7f0e5d8 @xxing more work on getting articles going
xxing authored
213
214 if( !empty( $pParamHash['format_guid'] ) ) {
215 $pParamHash['content_store']['format_guid'] = $pParamHash['format_guid'];
216 }
217
218 // we do the substr on load. otherwise we need to store the same data twice.
04136bd @xxing get article submissions working
xxing authored
219 if( !empty( $pParamHash['edit'] ) ) {
4158723 @xxing fix article preview
xxing authored
220 $pParamHash['content_store']['data'] = $pParamHash['edit'];
221 }
7f0e5d8 @xxing more work on getting articles going
xxing authored
222
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
223 // check some lengths, if too long, then truncate
224 /* DrewSlater - Killed article description storage. Any reason to use this instead of just a substr of the article body?
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
225 if( $this->isValid()&& !empty( $this->mInfo['description'] )&& empty( $pParamHash['description'] ) ) {
226 // someone has deleted the description, we need to null it out
227 $pParamHash['article_store']['description'] = '';
228 } else if( empty( $pParamHash['description'] ) ) {
229 $bodyText = $pParamHash['content_store']['data'];
04136bd @xxing get article submissions working
xxing authored
230 $pParamHash['article_store']['description'] = substr( $bodyText,0, DEFAULT_ARTICLE_DESCR_LEN ).( strlen( $bodyText )> DEFAULT_ARTICLE_DESCR_LEN ? '...' : '' );
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
231 } else {
232 $pParamHash['article_store']['description'] = $pParamHash['description'];
233 }*/
7f0e5d8 @xxing more work on getting articles going
xxing authored
234
04136bd @xxing get article submissions working
xxing authored
235 if( !empty( $pParamHash['rating'] ) ) {
236 $pParamHash['article_store']['rating'] =( int )( $pParamHash['rating'] );
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
237 }
7f0e5d8 @xxing more work on getting articles going
xxing authored
238
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
239 // check for name issues, first truncate length if too long
240 if( !empty( $pParamHash['title'] ) ) {
5a59732 @xxing use $this->isValid() to check for $this->mArticleId
xxing authored
241 if( !$this->isValid() ) {
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
242 if( empty( $pParamHash['title'] ) ) {
243 $this->mErrors['title'] = 'You must enter a name for this page.';
244 } else {
245 $pParamHash['content_store']['title'] = substr( $pParamHash['title'], 0, 160 );
246 }
247 } else {
248 $pParamHash['content_store']['title'] =( isset( $pParamHash['title'] ))? substr( $pParamHash['title'], 0, 160 ): '';
249 }
250 } else if( empty( $pParamHash['title'] ) ) {
251 // no name specified
252 $this->mErrors['title'] = 'You must specify a name';
253 }
7f0e5d8 @xxing more work on getting articles going
xxing authored
254
04136bd @xxing get article submissions working
xxing authored
255 if( !empty( $pParamHash['publish_Month'] ) ) {
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
256 $dateString = $pParamHash['publish_Year'].'-'.$pParamHash['publish_Month'].'-'.$pParamHash['publish_Day'].' '.$pParamHash['publish_Hour'].':'.$pParamHash['publish_Minute'];
b99c416 @xxing get topic image on load()
xxing authored
257 //$timestamp = strtotime( $dateString );
258 $timestamp = $gBitSystem->mServerTimestamp->getUTCFromDisplayDate( strtotime( $dateString ) );
04136bd @xxing get article submissions working
xxing authored
259 if( $timestamp !== -1 ) {
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
260 $pParamHash['publish_date'] = $timestamp;
261 }
262 }
5cbc7ec @xxing get permissions sorted when trying to view submitted article
xxing authored
263 if( !empty( $pParamHash['publish_date'] ) ) {
264 $pParamHash['article_store']['publish_date'] = $pParamHash['publish_date'];
265 }
7f0e5d8 @xxing more work on getting articles going
xxing authored
266
04136bd @xxing get article submissions working
xxing authored
267 if( !empty( $pParamHash['expire_Month'] ) ) {
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
268 $dateString = $pParamHash['expire_Year'].'-'.$pParamHash['expire_Month'].'-'.$pParamHash['expire_Day'].' '.$pParamHash['expire_Hour'].':'.$pParamHash['expire_Minute'];
b99c416 @xxing get topic image on load()
xxing authored
269 //$timestamp = strtotime( $dateString );
270 $timestamp = $gBitSystem->mServerTimestamp->getUTCFromDisplayDate( strtotime( $dateString ) );
04136bd @xxing get article submissions working
xxing authored
271 if( $timestamp !== -1 ) {
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
272 $pParamHash['expire_date'] = $timestamp;
273 }
274 }
04136bd @xxing get article submissions working
xxing authored
275 if( !empty( $pParamHash['expire_date'] ) ) {
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
276 $pParamHash['article_store']['expire_date'] = $pParamHash['expire_date'];
277 }
7f0e5d8 @xxing more work on getting articles going
xxing authored
278
54fb5b7 @xxing merge recent changes into HEAD
xxing authored
279 if( @$this->verifyId( $pParamHash['status_id'] ) ) {
04136bd @xxing get article submissions working
xxing authored
280 if( $pParamHash['status_id'] > ARTICLE_STATUS_PENDING ) {
581b321 @xxing refine submissions, add confirmation note after submission.
xxing authored
281 if( $gBitUser->hasPermission( 'bit_p_approve_submission' ) ||
282 $gBitUser->hasPermission( 'bit_p_admin_received_articles' ) ||
04136bd @xxing get article submissions working
xxing authored
283 $gTikiuser->hasPermission( 'bit_p_autoapprove_submission' ) ) {
284 $pParamHash['article_store']['status_id'] =( int )( $pParamHash['status_id'] );
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
285 } else {
286 $pParamHash['article_store']['status_id'] = ARTICLE_STATUS_PENDING;
287 }
288 } else {
04136bd @xxing get article submissions working
xxing authored
289 $pParamHash['article_store']['status_id'] =( int )( $pParamHash['status_id'] );
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
290 }
54fb5b7 @xxing merge recent changes into HEAD
xxing authored
291 } elseif( @$this->verifyId( $this->mInfo['status_id'] ) ) {
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
292 $pParamHash['article_store']['status_id'] = $this->mInfo['status_id'];
293 } else {
581b321 @xxing refine submissions, add confirmation note after submission.
xxing authored
294 if( $gBitUser->hasPermission( 'bit_p_approve_submission' ) ||
295 $gBitUser->hasPermission( 'bit_p_admin_received_articles' ) ||
04136bd @xxing get article submissions working
xxing authored
296 $gBitUser->hasPermission( 'bit_p_autoapprove_submission' ) ) {
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
297 $pParamHash['article_store']['status_id'] = ARTICLE_STATUS_APPROVED;
298 } else {
299 $pParamHash['article_store']['status_id'] = ARTICLE_STATUS_PENDING; // Default status
300 }
301 }
7f0e5d8 @xxing more work on getting articles going
xxing authored
302
5330bc5 Merge recent changes to HEAD
Sean Lee authored
303 if ( array_search($pParamHash['article_store']['status_id'],
304 array(ARTICLE_STATUS_DENIED, ARTICLE_STATUS_DRAFT, ARTICLE_STATUS_PENDING))) {
305 $this->mInfo["no_index"] = true ;
306 }
307
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
308 return( count( $this->mErrors )== 0 );
309 }
7f0e5d8 @xxing more work on getting articles going
xxing authored
310
cf7b087 @xxing add some documentation
xxing authored
311 /**
ec0a861 @xxing add some more documentation
xxing authored
312 * Store article image
cf7b087 @xxing add some documentation
xxing authored
313 * @param array pParamHash of values that will be used to store the page
314 * @param array pFileHash hash returned by $_FILES[<name>]
315 * @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why
316 * @access public
317 **/
318 function storeImage( &$pParamHash, $pFileHash ) {
319 global $gBitSystem;
320 if( $this->isValid() ) {
321 if( !empty( $pFileHash['tmp_name'] ) ) {
322 $tmpImagePath = $this->getArticleImageStoragePath( $this->mArticleId, TRUE ).$pFileHash['name'];
323 if( !move_uploaded_file( $pFileHash['tmp_name'], $tmpImagePath ) ) {
324 $this->mErrors['article_image'] = "Error during attachment of article image";
325 } else {
caa8305 @spiderr move BitSystem:: preferences methods to get/set/load/storeConfig to avoi...
spiderr authored
326 $resizeFunc = ( $gBitSystem->getConfig( 'image_processor' ) == 'imagick' ) ? 'liberty_imagick_resize_image' : 'liberty_gd_resize_image';
cf7b087 @xxing add some documentation
xxing authored
327 $storeHash['source_file'] = $tmpImagePath;
7184912 @xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
328 $storeHash['dest_path'] = STORAGE_PKG_NAME.'/'.ARTICLES_PKG_NAME.'/';
cf7b087 @xxing add some documentation
xxing authored
329 $storeHash['dest_base_name'] = 'article_'.$this->mArticleId;
330 $storeHash['max_width'] = ARTICLE_TOPIC_THUMBNAIL_SIZE;
331 $storeHash['max_height'] = ARTICLE_TOPIC_THUMBNAIL_SIZE;
332 $storeHash['type'] = $pFileHash['type'];
333
334 if( !( $resizeFunc( $storeHash ) ) ) {
335 $this->mErrors[] = 'Error while resizing article image';
336 }
337 @unlink( $tmpImagePath );
338 }
339 } elseif( !empty( $pParamHash['preview_image_path'] ) && is_file( $pParamHash['preview_image_path'] ) ) {
340 // if this article has been previewed with an image, we can copy it to the destination place
7184912 @xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
341 rename( $pParamHash['preview_image_path'], STORAGE_PKG_PATH.ARTICLES_PKG_NAME.'/article_'.$this->mArticleId.'.jpg' );
cf7b087 @xxing add some documentation
xxing authored
342 }
343 }
344 return ( count( $this->mErrors ) == 0 );
345 }
346
347 /**
ec0a861 @xxing add some more documentation
xxing authored
348 * Work out the path to the image for this article
cf7b087 @xxing add some documentation
xxing authored
349 * @param $pArticleId id of the article we need the image path for
350 * @param $pBasePathOnly bool TRUE / FALSE - specify whether you want full path or just base path
351 * @return path on success, FALSE on failure
352 * @access public
353 **/
354 function getArticleImageStoragePath( $pArticleId = NULL, $pBasePathOnly = FALSE ) {
355 $relativeUrl = BitArticleTopic::getTopicImageStorageUrl( $pArticleId, $pBasePathOnly );
356 $ret = NULL;
357 if( $relativeUrl ) {
358 $ret = BIT_ROOT_PATH.$relativeUrl;
359 }
360 return $ret;
361 }
362
363 /**
ec0a861 @xxing add some more documentation
xxing authored
364 * Work out the URL to the image for this article
cf7b087 @xxing add some documentation
xxing authored
365 * @param $pArticleId id of the article we need the image path for
366 * @param $pBasePathOnly bool TRUE / FALSE - specify whether you want full path or just base path
367 * @return URL on success, FALSE on failure
368 * @access public
369 **/
370 function getArticleImageStorageUrl( $pArticleId = NULL, $pBasePathOnly = FALSE ) {
371 global $gBitSystem;
7184912 @xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
372 if( !is_dir( STORAGE_PKG_PATH.ARTICLES_PKG_NAME ) ) {
373 mkdir( STORAGE_PKG_PATH.ARTICLES_PKG_NAME );
cf7b087 @xxing add some documentation
xxing authored
374 }
375
376 if( $pBasePathOnly ) {
7184912 @xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
377 return STORAGE_PKG_NAME.'/'.ARTICLES_PKG_NAME;
cf7b087 @xxing add some documentation
xxing authored
378 }
379
380 $ret = NULL;
381 if( !$pArticleId ) {
382 if( $this->isValid() ) {
383 $pArticleId = $this->mArticleId;
384 } else {
385 return NULL;
386 }
387 }
388
7184912 @xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
389 if( is_file( STORAGE_PKG_PATH.ARTICLES_PKG_NAME.'/article_'.$pArticleId.'.jpg' ) ) {
390 return STORAGE_PKG_URL.ARTICLES_PKG_NAME.'/article_'.$pArticleId.'.jpg';
cf7b087 @xxing add some documentation
xxing authored
391 } else {
392 return FALSE;
393 }
394 }
395
ec0a861 @xxing add some more documentation
xxing authored
396 /**
397 * Deal with images and text, modify them apprpriately that they can be returned to the form.
398 * @param $previewData data submitted by form - generally $_REQUEST
399 * @return array of data compatible with article form
400 * @access public
401 **/
7184912 @xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
402 function preparePreview( $pParamHash ) {
4fea283 @xxing get image upload working with preview and subsequent save
xxing authored
403 global $gBitSystem, $gBitUser;
7f0e5d8 @xxing more work on getting articles going
xxing authored
404
7184912 @xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
405 $data = $pParamHash;
04136bd @xxing get article submissions working
xxing authored
406 $this->verify( $data );
7184912 @xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
407 $data = array_merge( $pParamHash, $data['content_store'], $data['article_store'] );
4fea283 @xxing get image upload working with preview and subsequent save
xxing authored
408
04136bd @xxing get article submissions working
xxing authored
409 if( empty( $data['user_id'] ) ) {
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
410 $data['user_id'] = $gBitUser->mUserId;
411 }
4fea283 @xxing get image upload working with preview and subsequent save
xxing authored
412
04136bd @xxing get article submissions working
xxing authored
413 if( empty( $data['hits'] ) ) {
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
414 $data['hits'] = 0;
415 }
4fea283 @xxing get image upload working with preview and subsequent save
xxing authored
416
04136bd @xxing get article submissions working
xxing authored
417 if( empty( $data['publish_date'] ) ) {
4fea283 @xxing get image upload working with preview and subsequent save
xxing authored
418 $data['publish_date'] = $gBitSystem->getUTCTime();
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
419 }
4fea283 @xxing get image upload working with preview and subsequent save
xxing authored
420
04136bd @xxing get article submissions working
xxing authored
421 if( empty( $data['article_type_id'] ) ) {
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
422 $data['article_type_id'] = 1;
423 }
4fea283 @xxing get image upload working with preview and subsequent save
xxing authored
424
04136bd @xxing get article submissions working
xxing authored
425 if( empty( $data['topic_id'] ) ) {
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
426 $data['topic_id'] = 1;
427 }
4fea283 @xxing get image upload working with preview and subsequent save
xxing authored
428
04136bd @xxing get article submissions working
xxing authored
429 if( empty( $data['parsed_data'] ) ) {
ea85f9e @xxing new API for parseData(); please view ApiChangeLog for details
xxing authored
430 $data['data'] = preg_replace( ARTICLE_SPLIT_REGEX, "", $data['data'] );
431 $data['parsed_data'] = $this->parseData( $data );
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
432 }
7f0e5d8 @xxing more work on getting articles going
xxing authored
433
54fb5b7 @xxing merge recent changes into HEAD
xxing authored
434 if( @$this->verifyId( $data['image_attachment_id'] ) ) {
daf5fbe @xxing existing image attachment working as well now - w00t!
xxing authored
435 $data['image_attachment_id'] = ( int )$data['image_attachment_id'];
fbe5d52 @xxing detikify liberty
xxing authored
436 $query = "SELECT lf.storage_path AS image_storage_path
437 FROM `".BIT_DB_PREFIX."liberty_attachments` a
438 LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_files` lf ON( lf.file_id = a.foreign_id )
f210a14 massive table de-tikification. changed all tiki_ table prefixes with teh...
bitweaver.org authored
439 WHERE a.attachment_id=?";
daf5fbe @xxing existing image attachment working as well now - w00t!
xxing authored
440 $data['image_storage_path'] = $this->mDb->getOne( $query, array( $data['image_attachment_id'] ) );
539fa01 @xxing rename img_url to image_url
xxing authored
441 $data['image_url'] = BitArticle::getImageUrl( $data );
4fea283 @xxing get image upload working with preview and subsequent save
xxing authored
442 }
443
7184912 @xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
444 if( !empty( $_FILES['article_image']['name'] ) ) {
daf5fbe @xxing existing image attachment working as well now - w00t!
xxing authored
445 // store the image in temp/articles/
7184912 @xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
446 $tmpImagePath = TEMP_PKG_PATH.ARTICLES_PKG_NAME.'/'.'temp_'.$_FILES['article_image']['name'];
daf5fbe @xxing existing image attachment working as well now - w00t!
xxing authored
447 $tmpImageName = preg_replace( "/(.*)\..*?$/", "$1", $_FILES['article_image']['name'] );
7184912 @xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
448 if( !is_dir( TEMP_PKG_PATH.ARTICLES_PKG_NAME ) ) {
449 mkdir( TEMP_PKG_PATH.ARTICLES_PKG_NAME );
daf5fbe @xxing existing image attachment working as well now - w00t!
xxing authored
450 }
451
452 if( !move_uploaded_file( $_FILES['article_image']['tmp_name'], $tmpImagePath ) ) {
453 $this->mErrors['article_image'] = "Error during attachment of article image";
454 } else {
caa8305 @spiderr move BitSystem:: preferences methods to get/set/load/storeConfig to avoi...
spiderr authored
455 $resizeFunc = ( $gBitSystem->getConfig( 'image_processor' ) == 'imagick' ) ? 'liberty_imagick_resize_image' : 'liberty_gd_resize_image';
daf5fbe @xxing existing image attachment working as well now - w00t!
xxing authored
456 $pFileHash['source_file'] = $tmpImagePath;
7184912 @xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
457 $pFileHash['dest_path'] = TEMP_PKG_NAME.'/'.ARTICLES_PKG_NAME.'/';
daf5fbe @xxing existing image attachment working as well now - w00t!
xxing authored
458 // remove the extension
459 $pFileHash['dest_base_name'] = $tmpImageName;
460 $pFileHash['max_width'] = ARTICLE_TOPIC_THUMBNAIL_SIZE;
461 $pFileHash['max_height'] = ARTICLE_TOPIC_THUMBNAIL_SIZE;
462 $pFileHash['type'] = $_FILES['article_image']['type'];
463
464 if( !( $resizeFunc( $pFileHash ) ) ) {
465 $this->mErrors[] = 'Error while resizing article image';
466 }
467 @unlink( $tmpImagePath );
7184912 @xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
468 $data['image_url'] = $data['preview_image_url'] = TEMP_PKG_URL.ARTICLES_PKG_NAME.'/'.$tmpImageName.'.jpg';
469 $data['preview_image_path'] = TEMP_PKG_PATH.ARTICLES_PKG_NAME.'/'.$tmpImageName.'.jpg';
4fea283 @xxing get image upload working with preview and subsequent save
xxing authored
470 }
7184912 @xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
471 } elseif( !empty( $data['preview_image_path'] ) && is_file( $data['preview_image_path'] ) ) {
472 $data['image_url'] = $data['preview_image_url'];
4fea283 @xxing get image upload working with preview and subsequent save
xxing authored
473 }
474
04136bd @xxing get article submissions working
xxing authored
475 $articleType = &new BitArticleType( $data['article_type_id'] );
476 $articleTopic = &new BitArticleTopic( $data['topic_id'] );
477 $data = array_merge( $data, $articleType->mInfo, $articleTopic->mInfo );
7f0e5d8 @xxing more work on getting articles going
xxing authored
478
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
479 return $data;
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
480 }
7f0e5d8 @xxing more work on getting articles going
xxing authored
481
ec0a861 @xxing add some more documentation
xxing authored
482 /**
483 * Get the URL for any given article image
484 * @param $pParamHash pass in full set of data returned from article query
485 * @return url to image
486 * @access public
487 **/
daf5fbe @xxing existing image attachment working as well now - w00t!
xxing authored
488 function getImageUrl( $pParamHash ) {
489 $ret = NULL;
490 // if a custom image for the article exists, use that, then use an attachment, then use the topic image
54fb5b7 @xxing merge recent changes into HEAD
xxing authored
491 if( @$this->verifyId( $pParamHash['article_id'] ) && BitArticle::getArticleImageStorageUrl( $pParamHash['article_id'] ) ) {
daf5fbe @xxing existing image attachment working as well now - w00t!
xxing authored
492 $ret = BitArticle::getArticleImageStorageUrl( $pParamHash['article_id'] );
54fb5b7 @xxing merge recent changes into HEAD
xxing authored
493 } elseif( @$this->verifyId( $pParamHash['image_attachment_id'] ) && $pParamHash['image_attachment_id'] ) {
47348b5 @xxing clean up image attachments for articles, allow custom size for resizes, ...
xxing authored
494 // TODO: clean up the small url stuff. shouldn't be hardcoded.
315f770 @xxing first check if attached image is available
xxing authored
495 // perhaps we should make a copy of the image file and reduce it to article size settings.
7184912 @xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
496 // this will be necessary as soon as we allow custom image sizes for article image
47348b5 @xxing clean up image attachments for articles, allow custom size for resizes, ...
xxing authored
497 $image = preg_replace( "/(.*)\/.*?$/", "$1/small.jpg", $pParamHash['image_storage_path'] );
315f770 @xxing first check if attached image is available
xxing authored
498 if( is_file( BIT_ROOT_PATH.$image ) ) {
499 $ret = BIT_ROOT_URL.$image;
500 }
daf5fbe @xxing existing image attachment working as well now - w00t!
xxing authored
501 } elseif( !empty( $pParamHash['has_topic_image'] ) && $pParamHash['has_topic_image'] == 'y' ) {
502 $ret = BitArticleTopic::getTopicImageStorageUrl( $pParamHash['topic_id'] );
503 }
504 return $ret;
505 }
506
ec0a861 @xxing add some more documentation
xxing authored
507 /**
508 * Remove a custom article image - will result in the usage of the default image if a topic with image is selected
509 * @param $pArticleId ID of the article that needs the image removed
510 * @param $pImagePath path to the image that needs removing - generally used during preview - will override article id
511 * @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why
512 * @access public
513 **/
5e14ed2 @xxing clean up author name code
xxing authored
514 function expungeImage( $pArticleId=NULL, $pImagePath=NULL ) {
6f9ed7a @xxing add a link to remove a custom image
xxing authored
515 if( is_file( $pImagePath) ) {
516 if( !@unlink( $pImagePath) ) {
ec0a861 @xxing add some more documentation
xxing authored
517 $this->mErrors['remove_image'] = tra( 'The image could not be removed because the path supplied does not exist.' );
6f9ed7a @xxing add a link to remove a custom image
xxing authored
518 }
519 }
520
5a59732 @xxing use $this->isValid() to check for $this->mArticleId
xxing authored
521 if( empty( $pArticleId ) && $this->isValid() ) {
522 $pArticleId = $this->mArticleId;
523 }
524
6f9ed7a @xxing add a link to remove a custom image
xxing authored
525 if( $image = is_file( BitArticle::getArticleImageStoragePath( $pArticleId ) ) ) {
526 if( !@unlink( $image ) ) {
ec0a861 @xxing add some more documentation
xxing authored
527 $this->mErrors['remove_image'] = tra( 'The article image could not be removed because this article doesn\'t seem to have an article associated with it.' );
6f9ed7a @xxing add a link to remove a custom image
xxing authored
528 }
529 }
530 return ( count( $this->mErrors ) == 0 );
531 }
532
ec0a861 @xxing add some more documentation
xxing authored
533 /**
534 * Removes currently loaded article
535 * @return bool TRUE on success, FALSE on failure
536 * @access public
537 **/
4fea283 @xxing get image upload working with preview and subsequent save
xxing authored
538 function expunge() {
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
539 $ret = FALSE;
540 if( $this->isValid() ) {
8c5f309 @xxing clean up articles custom image upload stuff
xxing authored
541 $this->mDb->StartTrans();
f210a14 massive table de-tikification. changed all tiki_ table prefixes with teh...
bitweaver.org authored
542 $query = "DELETE FROM `".BIT_DB_PREFIX."articles` WHERE `content_id` = ?";
8c5f309 @xxing clean up articles custom image upload stuff
xxing authored
543 $result = $this->mDb->query( $query, array( $this->mContentId ) );
5a59732 @xxing use $this->isValid() to check for $this->mArticleId
xxing authored
544 // remove article image if it exists
545 $this->expungeImage();
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
546 if( LibertyAttachable::expunge() ) {
547 $ret = TRUE;
548 $this->mDb->CompleteTrans();
549 } else {
550 $this->mDb->RollbackTrans();
8c5f309 @xxing clean up articles custom image upload stuff
xxing authored
551 }
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
552 }
553 return $ret;
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
554 }
7f0e5d8 @xxing more work on getting articles going
xxing authored
555
ec0a861 @xxing add some more documentation
xxing authored
556 /**
557 * Check if there is an article loaded
558 * @return bool TRUE on success, FALSE on failure
559 * @access public
560 **/
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
561 function isValid() {
54fb5b7 @xxing merge recent changes into HEAD
xxing authored
562 return( $this->verifyId( $this->mArticleId ) && $this->verifyId( $this->mContentId ) );
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
563 }
7f0e5d8 @xxing more work on getting articles going
xxing authored
564
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
565 /**
fbe5d52 @xxing detikify liberty
xxing authored
566 * This function generates a list of records from the liberty_content database for use in a list page
ec0a861 @xxing add some more documentation
xxing authored
567 * @param $pParamHash contains an array of conditions to sort by
d403bf6 @lsces Add PHPDoc headings to package
lsces authored
568 * @return array
569 * ['data'] which contains all articles that match pParamHash conditions
570 * ['cant'] which contains the number of articles that matched the pParamHash conditions
ec0a861 @xxing add some more documentation
xxing authored
571 * @access public
7f0e5d8 @xxing more work on getting articles going
xxing authored
572 **/
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
573 function getList( &$pParamHash ) {
a2bfaee @lsces Filter lists of content by group_id ( only enabled when gatekeeper is of...
lsces authored
574 global $gBitSystem, $gBitUser;
7f0e5d8 @xxing more work on getting articles going
xxing authored
575
fe614d1 @xxing apply default sort_mode before LibertyContent::prepGetList();
xxing authored
576 if( empty( $pParamHash['sort_mode'] ) ) {
577 $pParamHash['sort_mode'] = 'publish_date_desc';
578 }
579
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
580 LibertyContent::prepGetList( $pParamHash );
581
838a838 @lsces Add ServicesSQL facility
lsces authored
582 $joinSql = '';
583 $selectSql = '';
584 $bindVars = array();
585 array_push( $bindVars, $this->mContentTypeGuid );
3556172 @xxing rename content_load_function to content_load_sql_function
xxing authored
586 $this->getServicesSql( 'content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars );
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
587
838a838 @lsces Add ServicesSQL facility
lsces authored
588 $find = $pParamHash['find'];
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
589 if( is_array( $find ) ) {
c6e286d @xxing add more options to limit getList() by
xxing authored
590 // you can use an array of articles
fa7948e @xxing concatenate whereSql
xxing authored
591 $whereSql .= " AND lc.`title` IN( ".implode( ',',array_fill( 0, count( $find ),'?' ) )." )";
962a29a @lsces Tidy array merges
lsces authored
592 $bindVars = array_merge( $bindVars, $find );
d568668 @xxing fix user_id where clause
xxing authored
593 } elseif( is_string( $find ) ) {
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
594 // or a string
fa7948e @xxing concatenate whereSql
xxing authored
595 $whereSql .= " AND UPPER( lc.`title` ) LIKE ? ";
962a29a @lsces Tidy array merges
lsces authored
596 $bindVars[] = '%'.strtoupper( $find ).'%';
54fb5b7 @xxing merge recent changes into HEAD
xxing authored
597 } elseif( @$this->verifyId( $pParamHash['user_id'] ) ) {
d568668 @xxing fix user_id where clause
xxing authored
598 // or gate on a user
fa7948e @xxing concatenate whereSql
xxing authored
599 $whereSql .= " AND lc.`creator_user_id` = ? ";
838a838 @lsces Add ServicesSQL facility
lsces authored
600 $bindVars[] = array( $pParamHash['user_id'] );
d6cf45c @xxing add option to select by topic name
xxing authored
601 }
602
54fb5b7 @xxing merge recent changes into HEAD
xxing authored
603 if( @$this->verifyId( $pParamHash['status_id'] ) ) {
838a838 @lsces Add ServicesSQL facility
lsces authored
604 $whereSql .= " AND a.`status_id` = ? ";
605 $bindVars[] = $pParamHash['status_id'];
c6e286d @xxing add more options to limit getList() by
xxing authored
606 }
607
54fb5b7 @xxing merge recent changes into HEAD
xxing authored
608 if( @$this->verifyId( $pParamHash['type_id'] ) ) {
838a838 @lsces Add ServicesSQL facility
lsces authored
609 $whereSql .= " AND a.`article_type_id` = ? ";
610 $bindVars[] = ( int )$pParamHash['type_id'];
c6e286d @xxing add more options to limit getList() by
xxing authored
611 }
612
9090a1d @spiderr remove old spell checking
spiderr authored
613 // TODO: we need to check if the article wants to be viewed before / after respective dates
614 // someone better at SQL please get this working without an additional db call - xing
615 if( empty( $pParamHash['show_expired'] ) ) {
616 $timestamp = $gBitSystem->getUTCTime();
617 $whereSql .= " AND a.`publish_date` < ? AND a.`expire_date` > ? ";
618 $bindVars[] = ( int )$timestamp;
619 $bindVars[] = ( int )$timestamp;
620 }
621
0b9692b @xxing merge recent changes into HEAD
xxing authored
622 if( @$this->verifyId( $pParamHash['topic_id'] ) ) {
838a838 @lsces Add ServicesSQL facility
lsces authored
623 $whereSql .= " AND a.`topic_id` = ? ";
624 $bindVars[] = ( int )$pParamHash['topic_id'];
0b9692b @xxing merge recent changes into HEAD
xxing authored
625 } elseif( !empty( $pParamHash['topic'] ) ) {
ea85f9e @xxing new API for parseData(); please view ApiChangeLog for details
xxing authored
626 $whereSql .= " AND UPPER( atopic.`topic_name` ) = ? ";
838a838 @lsces Add ServicesSQL facility
lsces authored
627 $bindVars[] = strtoupper( $pParamHash['topic'] );
0b9692b @xxing merge recent changes into HEAD
xxing authored
628 } else {
44c943d @lsces Fix reserved word field names
lsces authored
629 $whereSql .= " AND ( atopic.`active_topic` != 'n' OR atopic.`active_topic` IS NULL ) ";
630 //$whereSql .= " AND atopic.`active_topic` != 'n' ";
0b9692b @xxing merge recent changes into HEAD
xxing authored
631 }
632
42b7561 explicit column names to get around oracle pain ORA-00918
bitweaver.org authored
633 // Oracle is very particular about naming multiple columns, so need to explicity name them ORA-00918: column ambiguously defined
c7b9230 oops, forgot one explicit column - status_id, add some backticks
bitweaver.org authored
634 $query = "SELECT a.`article_id`, a.`description`, a.`author_name`, a.`image_attachment_id`, a.`publish_date`, a.`expire_date`, a.`rating`, lc.*, atopic.`topic_id`, atopic.`topic_name`, atopic.`has_topic_image`, atopic.`active_topic`, atype.*, astatus.`status_id`, astatus.`status_name`, lf.`storage_path` as `image_storage_path` $selectSql
f210a14 massive table de-tikification. changed all tiki_ table prefixes with teh...
bitweaver.org authored
635 FROM `".BIT_DB_PREFIX."articles` a
9437fe9 @xxing replace tp alias with either atp (article_topic) or wp (wiki_page)
xxing authored
636 INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON lc.`content_id` = a.`content_id`
637 INNER JOIN `".BIT_DB_PREFIX."article_status` astatus ON astatus.`status_id` = a.`status_id`
ea85f9e @xxing new API for parseData(); please view ApiChangeLog for details
xxing authored
638 LEFT OUTER JOIN `".BIT_DB_PREFIX."article_topics` atopic ON atopic.`topic_id` = a.`topic_id`
9437fe9 @xxing replace tp alias with either atp (article_topic) or wp (wiki_page)
xxing authored
639 LEFT OUTER JOIN `".BIT_DB_PREFIX."article_types` atype ON atype.`article_type_id` = a.`article_type_id`
640 LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_attachments` la ON la.`attachment_id` = a.`image_attachment_id`
4cc2a03 Changed "top" alias to "tp" to prevent problems with TOP keyword in mssq...
Sean Lee authored
641 LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_files` lf ON lf.`file_id` = la.`foreign_id` $joinSql
fa7948e @xxing concatenate whereSql
xxing authored
642 WHERE lc.`content_type_guid` = ? $whereSql
0b9692b @xxing merge recent changes into HEAD
xxing authored
643 ORDER BY ".$this->mDb->convert_sortmode( $pParamHash['sort_mode'] );
04136bd @xxing get article submissions working
xxing authored
644
f210a14 massive table de-tikification. changed all tiki_ table prefixes with teh...
bitweaver.org authored
645 $query_cant = "SELECT COUNT( * )FROM `".BIT_DB_PREFIX."articles` a
ea85f9e @xxing new API for parseData(); please view ApiChangeLog for details
xxing authored
646 INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON lc.`content_id` = a.`content_id`
647 LEFT OUTER JOIN `".BIT_DB_PREFIX."article_topics` atopic ON atopic.`topic_id` = a.`topic_id` $joinSql
838a838 @lsces Add ServicesSQL facility
lsces authored
648 WHERE lc.`content_type_guid` = ? $whereSql";
80fa1d9 @spiderr Added uspport for multiple database backend support. This necessitates r...
spiderr authored
649
838a838 @lsces Add ServicesSQL facility
lsces authored
650 $result = $this->mDb->query( $query, $bindVars, $pParamHash['max_records'], $pParamHash['offset'] );
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
651 $ret = array();
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
652 $comment = &new LibertyComment();
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
653 while( $res = $result->fetchRow() ) {
539fa01 @xxing rename img_url to image_url
xxing authored
654 $res['image_url'] = BitArticle::getImageUrl( $res );
caa8305 @spiderr move BitSystem:: preferences methods to get/set/load/storeConfig to avoi...
spiderr authored
655 $res['time_difference'] = BitDate::calculateTimeDifference( $res['publish_date'], NULL, $gBitSystem->getConfig( 'article_date_threshold' ) );
7f0e5d8 @xxing more work on getting articles going
xxing authored
656
ea85f9e @xxing new API for parseData(); please view ApiChangeLog for details
xxing authored
657 // deal with the parsing
658 $parseHash['format_guid'] = $res['format_guid'];
f81edc0 @xxing add the content_id to the parseHash
xxing authored
659 $parseHash['content_id'] = $res['content_id'];
7f0e5d8 @xxing more work on getting articles going
xxing authored
660 if( preg_match( ARTICLE_SPLIT_REGEX, $res['data'] ) ) {
661 $parts = preg_split( ARTICLE_SPLIT_REGEX, $res['data'] );
ea85f9e @xxing new API for parseData(); please view ApiChangeLog for details
xxing authored
662 $parseHash['data'] = $parts[0];
663 } else {
caa8305 @spiderr move BitSystem:: preferences methods to get/set/load/storeConfig to avoi...
spiderr authored
664 $parseHash['data'] = substr( $res['data'], 0, $gBitSystem->getConfig( 'article_description_length' ) );
7f0e5d8 @xxing more work on getting articles going
xxing authored
665 }
ea85f9e @xxing new API for parseData(); please view ApiChangeLog for details
xxing authored
666 $res['parsed_description'] = $this->parseData( $parseHash );
7f0e5d8 @xxing more work on getting articles going
xxing authored
667
ea85f9e @xxing new API for parseData(); please view ApiChangeLog for details
xxing authored
668 $parseHash['data'] = preg_replace( ARTICLE_SPLIT_REGEX, "", $res['data'] );
669 $res['parsed_data'] = $this->parseData( $parseHash );
7f0e5d8 @xxing more work on getting articles going
xxing authored
670
ea85f9e @xxing new API for parseData(); please view ApiChangeLog for details
xxing authored
671 // this is needed to remove trailing stuff from the parser and insert a link to the actual article
086d0bc @xxing merge recent changes into HEAD
xxing authored
672 $trailing_junk_pattern = "/(<br[^>]*>)*$/i";
673 if( strlen( $res['parsed_description'] ) != strlen( $res['parsed_data'] ) ) {
674 $res['parsed_description'] = preg_replace( $trailing_junk_pattern, "", $res['parsed_description'] );
675 $res['parsed_description'] .= '<a href="'.$this->getDisplayUrl( $res['article_id'] ).'" title="'.$this->getTitle( $res ).'">&hellip;</a>';
676 $res['has_more'] = TRUE;
677 } else {
678 $res['parsed_description'] = preg_replace( $trailing_junk_pattern, "", $res['parsed_description'] );
679 }
680
7f0e5d8 @xxing more work on getting articles going
xxing authored
681 $res['num_comments'] = $comment->getNumComments( $res['content_id'] );
6130c1d @xxing fix various article submission related issues
xxing authored
682 $res['display_url'] = $this->getDisplayUrl( $res['article_id'] );
683 $res['display_link'] = $this->getDisplayLink( $res['title'], $res );
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
684 $ret[] = $res;
685 }
7f0e5d8 @xxing more work on getting articles going
xxing authored
686
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
687 $pParamHash["data"] = $ret;
838a838 @lsces Add ServicesSQL facility
lsces authored
688 $pParamHash["cant"] = $this->mDb->getOne( $query_cant, $bindVars );
7f0e5d8 @xxing more work on getting articles going
xxing authored
689
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
690 LibertyContent::postGetList( $pParamHash );
7f0e5d8 @xxing more work on getting articles going
xxing authored
691
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
692 return $pParamHash;
693 }
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
694
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
695 /**
cf7b087 @xxing add some documentation
xxing authored
696 * Generates the URL to the article
697 * @return the link to the full article
7f0e5d8 @xxing more work on getting articles going
xxing authored
698 */
54fb5b7 @xxing merge recent changes into HEAD
xxing authored
699 function getDisplayUrl( $articleId = NULL) {
700 global $gBitSystem;
701
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
702 $ret = NULL;
54fb5b7 @xxing merge recent changes into HEAD
xxing authored
703 if( ! $articleId ) {
704 $articleId = $this->mArticleId;
705 }
706
707 if( @$this->verifyId( $articleId ) ) {
475f224 @xxing another batch of kernel_prefs name cleanup. this should be it
xxing authored
708 if( $gBitSystem->isFeatureActive( 'pretty_urls_extended' ) ) {
54fb5b7 @xxing merge recent changes into HEAD
xxing authored
709 // Not needed since it's a number: $ret = ARTICLES_PKG_URL."view/".$this->mArticleId;
710 $ret = ARTICLES_PKG_URL.$articleId;
711 } else if( $gBitSystem->isFeatureActive( 'pretty_urls' ) ) {
712 $ret = ARTICLES_PKG_URL.$articleId;
713 } else {
714 $ret = ARTICLES_PKG_URL."read.php?article_id=$articleId";
715 }
47d932a @xxing parsed_description only needed when loading articles front page
xxing authored
716 }
717 return $ret;
718 }
cf7b087 @xxing add some documentation
xxing authored
719
720 /**
721 * get a list of all available statuses
722 * @return an array of available statuses
723 * @access public
724 **/
725 function getStatusList() {
726 global $gBitSystem;
f210a14 massive table de-tikification. changed all tiki_ table prefixes with teh...
bitweaver.org authored
727 $query = "SELECT * FROM `".BIT_DB_PREFIX."article_status`";
cf7b087 @xxing add some documentation
xxing authored
728 $result = $gBitSystem->mDb->query( $query );
729 return $result->getRows();
730 }
731
732 /**
733 * set the status of an article
734 * @param $pStatusId new status id of the article
735 * @param $pArticleId of the article that is being changed - if not set, it will attemtp to change the currently loaded article
736 * @return new status of article on success - else returns NULL
737 * @access public
738 **/
5330bc5 Merge recent changes to HEAD
Sean Lee authored
739 function setStatus( $pStatusId, $pArticleId = NULL, $pContentId = NULL ) {
9090a1d @spiderr remove old spell checking
spiderr authored
740 global $gBitSystem;
cf7b087 @xxing add some documentation
xxing authored
741 $validStatuses = array( ARTICLE_STATUS_DENIED, ARTICLE_STATUS_DRAFT, ARTICLE_STATUS_PENDING, ARTICLE_STATUS_APPROVED, ARTICLE_STATUS_RETIRED );
742
743 if( !in_array( $pStatusId, $validStatuses ) ) {
744 $this->mErrors[] = "Invalid article status";
745 return FALSE;
746 }
747
5330bc5 Merge recent changes to HEAD
Sean Lee authored
748 if( empty( $pContentId ) and $this->isValid()) $pContentId = $this->mContentId ;
749 if( empty( $pArticleId ) and $this->isValid()) $pArticleId = $this->mArticleId ;
750 if( !empty( $pContentId ) and !$this->isValid()) $this->mContentId = $pContentId ;
751 if( !empty( $pArticleId ) and !$this->isValid()) $this->mArticleId = $pArticleId ;
752
cf7b087 @xxing add some documentation
xxing authored
753 if( empty( $pArticleId ) && $this->isValid() ) {
754 $pArticleId = $this->mArticleId;
755 }
756
54fb5b7 @xxing merge recent changes into HEAD
xxing authored
757 if( @$this->verifyId( $pArticleId ) ) {
f210a14 massive table de-tikification. changed all tiki_ table prefixes with teh...
bitweaver.org authored
758 $sql = "UPDATE `".BIT_DB_PREFIX."articles` SET `status_id` = ? WHERE `article_id` = ?";
cf7b087 @xxing add some documentation
xxing authored
759 $rs = $this->mDb->query( $sql, array( $pStatusId, $pArticleId ));
5330bc5 Merge recent changes to HEAD
Sean Lee authored
760 // Calling the index function for approved articles ...
761 if( $gBitSystem->isPackageActive( 'search' ) ) {
762 include_once( SEARCH_PKG_PATH.'refresh_functions.php' );
763 if ($pStatusId == ARTICLE_STATUS_APPROVED) {
764 refresh_index($this);
765 } elseif (!$pStatusId == ARTICLE_STATUS_RETIRED) {
766 delete_index($pContentId); // delete it from the search index unless retired ...
767 }
768 }
cf7b087 @xxing add some documentation
xxing authored
769 return $pStatusId;
770 }
771 }
772
9adba87 @xxing display article publication time as time that has passed since
xxing authored
773 /* TODO: write this function...
ec0a861 @xxing add some more documentation
xxing authored
774 function prepGetList( &$pParamHash ) {
775 }
776 */
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
777 }
778 ?>
Something went wrong with that request. Please try again.