Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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