Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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