Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 869 lines (768 sloc) 34.618 kb
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
1 <?php
2 /**
a39e6451 » xxing
2007-01-06 rename some methods in BitDbBase to meet bitweaver standards. all cha…
3 * @version $Header: /cvsroot/bitweaver/_bit_articles/BitArticle.php,v 1.104 2007/01/06 09:46:09 squareing Exp $
d403bf61 » lsces
2005-10-30 Add PHPDoc headings to package
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 *
a39e6451 » xxing
2007-01-06 rename some methods in BitDbBase to meet bitweaver standards. all cha…
12 * $Id: BitArticle.php,v 1.104 2007/01/06 09:46:09 squareing Exp $
d403bf61 » lsces
2005-10-30 Add PHPDoc headings to package
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>
a39e6451 » xxing
2007-01-06 rename some methods in BitDbBase to meet bitweaver standards. all cha…
19 * @version $Revision: 1.104 $ $Date: 2007/01/06 09:46:09 $ $Author: squareing $
d403bf61 » lsces
2005-10-30 Add PHPDoc headings to package
20 */
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
21
22 /**
d403bf61 » lsces
2005-10-30 Add PHPDoc headings to package
23 * Required setup
24 */
04136bdb » xxing
2005-08-26 get article submissions working
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' );
c4f74cea » spiderr
2006-11-18 comment out incomplete statistics feature
29 // feature incomplete require_once( ARTICLES_PKG_PATH.'BitArticleStatistics.php' );
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
30
c83a84ec » xxing
2005-12-18 merge recent changes into HEAD
31 define( 'ARTICLE_SPLIT_REGEX', "/\.{3}split\.{3}[\r\n]?/i" );
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
32
d403bf61 » lsces
2005-10-30 Add PHPDoc headings to package
33 /**
34 * @package article
35 */
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
36 class BitArticle extends LibertyAttachable {
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
37 /**
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
38 * Primary key for articles
cf7b0879 » xxing
2005-09-04 add some documentation
39 * @access public
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
40 */
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
41 var $mArticleId;
42 var $mTypeId;
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
43 var $mTopicId;
cf7b0879 » xxing
2005-09-04 add some documentation
44
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
45 /**
ec0a861d » xxing
2005-09-11 add some more documentation
46 * Initiate the articles class
cf7b0879 » xxing
2005-09-04 add some documentation
47 * @param $pArticleId article id of the article we want to view
48 * @param $pContentId content id of the article we want to view
49 * @access private
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
50 **/
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
51 function BitArticle( $pArticleId=NULL, $pContentId=NULL ) {
52 $this->mArticleId = $pArticleId;
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
53 $this->mTypeId = NULL;
54 $this->mTopicId = NULL;
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
55
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
56 LibertyAttachable::LibertyAttachable();
c31efa15 » xxing
2005-08-27 fix admin screen and set more usable defaults in schema
57 $this->registerContentType( BITARTICLE_CONTENT_TYPE_GUID, array(
58 'content_description' => 'Article',
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
59 'handler_class' => 'BitArticle',
60 'handler_package' => 'articles',
61 'handler_file' => 'BitArticle.php',
62 'maintainer_url' => 'http://www.bitweaver.org'
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
63 ) );
64 $this->mContentId = $pContentId;
65 $this->mContentTypeGuid = BITARTICLE_CONTENT_TYPE_GUID;
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
66 if( ! @$this->verifyId( $this->mArticleId ) ) {
67 $this->mArticleId = NULL;
68 }
69 if( ! @$this->verifyId( $this->mContentId ) ) {
70 $this->mContentId = NULL;
71 }
1f9adbef » xxing
2005-08-25 make "read more" links conditional, depending on whether there is mor…
72 }
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
73
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
74 /**
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
75 * Load the data from the database
cf7b0879 » xxing
2005-09-04 add some documentation
76 * @access public
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
77 **/
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
78 function load( $pVersion = 0 ) {
79 $pVersion = intval( $pVersion );
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
80 if( @$this->verifyId( $this->mArticleId ) || @$this->verifyId( $this->mContentId ) ) {
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
81 // LibertyContent::load()assumes you have joined already, and will not execute any sql!
82 // This is a significant performance optimization
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
83 $lookupColumn = @$this->verifyId( $this->mArticleId ) ? 'article_id' : 'content_id';
ce4e5d17 » xxing
2006-02-14 use correct hash in query()
84 $bindVars[] = $lookupId = @BitBase::verifyId( $this->mArticleId ) ? $this->mArticleId : $this->mContentId;
35561720 » xxing
2006-02-14 rename content_load_function to content_load_sql_function
85 $this->getServicesSql( 'content_load_sql_function', $selectSql, $joinSql, $whereSql, $bindVars );
838a838b » lsces
2006-02-10 Add ServicesSQL facility
86
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
87 $query = "SELECT a.*, ".( !empty( $pVersion ) ? "lch.`hits`, lc.`title`" : "lc.*" ).", atype.*, atopic.*,
ce4e5d17 » xxing
2006-02-14 use correct hash in query()
88 uue.`login` AS `modifier_user`, uue.`real_name` AS `modifier_real_name`,
89 uuc.`login` AS `creator_user`, uuc.`real_name` AS `creator_real_name` ,
90 lf.`storage_path` as `image_storage_path` $selectSql
91 FROM `".BIT_DB_PREFIX."articles` a
92 LEFT OUTER JOIN `".BIT_DB_PREFIX."article_types` atype ON( atype.`article_type_id` = a.`article_type_id` )
93 LEFT OUTER JOIN `".BIT_DB_PREFIX."article_topics` atopic ON( atopic.`topic_id` = a.`topic_id` )
b7cc1a18 » Hash9
2006-08-29 add the factility to view the history of articles, and an auto approv…
94 INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON( lc.`content_id` = a.`content_id` ) ".
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
95 ( !empty( $pVersion ) ? "LEFT JOIN `".BIT_DB_PREFIX."liberty_content_history` lch ON( lch.`content_id` = a.`content_id` )" : "" ) . "
ce4e5d17 » xxing
2006-02-14 use correct hash in query()
96 LEFT JOIN `".BIT_DB_PREFIX."users_users` uue ON( uue.`user_id` = lc.`modifier_user_id` )
97 LEFT JOIN `".BIT_DB_PREFIX."users_users` uuc ON( uuc.`user_id` = lc.`user_id` )
98 LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_attachments` la ON( la.`attachment_id` = a.`image_attachment_id` )
99 LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_files` lf ON( lf.`file_id` = la.`foreign_id` ) $joinSql
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
100 WHERE a.`$lookupColumn`=? $whereSql ".( !empty( $pVersion ) ? " AND lch.version = ?" : "" );
101 if( !empty( $pVersion ) ) {
102 $bindVars[]=$pVersion;
103 }
ce4e5d17 » xxing
2006-02-14 use correct hash in query()
104 $result = $this->mDb->query( $query, $bindVars );
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
105
106 global $gBitSystem;
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
107 if( $result && $result->numRows() ) {
b548033a » spiderr
2006-01-25 fix ->fields calls
108 $this->mInfo = $result->fetchRow();
b99c4167 » xxing
2005-08-26 get topic image on load()
109
8c5f3098 » xxing
2005-08-28 clean up articles custom image upload stuff
110 // if a custom image for the article exists, use that, then use an attachment, then use the topic image
539fa019 » xxing
2005-08-28 rename img_url to image_url
111 $this->mInfo['image_url'] = BitArticle::getImageUrl( $this->mInfo );
b99c4167 » xxing
2005-08-26 get topic image on load()
112
b548033a » spiderr
2006-01-25 fix ->fields calls
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'];
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
117
ea85f9e9 » xxing
2006-02-16 new API for parseData(); please view ApiChangeLog for details
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'] );
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
120 $this->mInfo['display_url'] = $this->getDisplayUrl();
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
121 $this->mInfo['raw'] = $this->mInfo['data'];
ea85f9e9 » xxing
2006-02-16 new API for parseData(); please view ApiChangeLog for details
122 $this->mInfo['data'] = preg_replace( ARTICLE_SPLIT_REGEX, "", $this->mInfo['data'] );
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
123
fa7948e6 » xxing
2006-02-14 concatenate whereSql
124 $comment = &new LibertyComment();
125 $this->mInfo['num_comments'] = $comment->getNumComments( $this->mInfo['content_id'] );
adcc311d » xxing
2006-04-29 get html per article working as well and reduce load by only parsing …
126
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
127 LibertyAttachable::load();
adcc311d » xxing
2006-04-29 get html per article working as well and reduce load by only parsing …
128
129 $this->mInfo['parsed_data'] = $this->parseData();
838a838b » lsces
2006-02-10 Add ServicesSQL facility
130 } else {
131 $this->mArticleId = NULL;
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
132 }
133 }
c58fe865 » nickpalmer
2006-11-28 Fixed bug with load of article with no hits.
134
5e14ed22 » xxing
2005-08-30 clean up author name code
135 return( count( $this->mInfo ) );
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
136 }
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
137
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
138 /**
ec0a861d » xxing
2005-09-11 add some more documentation
139 * Store article data after submission
cf7b0879 » xxing
2005-09-04 add some documentation
140 * @param array pParamHash of values that will be used to store the page
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
141 * @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why
142 * @access public
143 **/
ee831c6a » xxing
2005-08-26 get custom article image working
144 function store( &$pParamHash ) {
145 global $gBitSystem;
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
146 if( $this->verify( $pParamHash )&& LibertyAttachable::store( $pParamHash ) ) {
f210a14d » bitweaver.org
2006-01-31 massive table de-tikification. changed all tiki_ table prefixes with …
147 $table = BIT_DB_PREFIX."articles";
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
148 $this->mDb->StartTrans();
ee831c6a » xxing
2005-08-26 get custom article image working
149
5a597327 » xxing
2005-08-28 use $this->isValid() to check for $this->mArticleId
150 if( $this->isValid() ) {
8d929a01 » spiderr
2006-02-08 major change of BitDbBase::associateUpdate method - it now takes a si…
151 $result = $this->mDb->associateUpdate( $table, $pParamHash['article_store'], array( "article_id" => $pParamHash['article_id'] ) );
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
152 } else {
153 $pParamHash['article_store']['content_id'] = $pParamHash['content_id'];
154 if( isset( $pParamHash['article_id'] )&& is_numeric( $pParamHash['article_id'] ) ) {
ee831c6a » xxing
2005-08-26 get custom article image working
155 // if pParamHash['article_id'] is set, someone is requesting a particular article_id. Use with caution!
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
156 $pParamHash['article_store']['article_id'] = $pParamHash['article_id'];
157 } else {
f210a14d » bitweaver.org
2006-01-31 massive table de-tikification. changed all tiki_ table prefixes with …
158 $pParamHash['article_store']['article_id'] = $this->mDb->GenID( 'articles_article_id_seq' );
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
159 }
160 $this->mArticleId = $pParamHash['article_store']['article_id'];
161 $result = $this->mDb->associateInsert( $table, $pParamHash['article_store'] );
162 }
163
8c5f3098 » xxing
2005-08-28 clean up articles custom image upload stuff
164 // we need to store any custom image that has been uploaded
971f3d0e » xxing
2006-11-01 fix image return url. this really needs to be cleaned up.
165 if( !empty( $_FILES['article_image']['name'] ) ) {
28cd2155 » spiderr
2006-07-14 check for article_image before passing in to store
166 $this->storeImage( $pParamHash, $_FILES['article_image'] );
167 }
8c5f3098 » xxing
2005-08-28 clean up articles custom image upload stuff
168
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
169 $this->mDb->CompleteTrans();
170 $this->load();
171 }
6f9ed7ac » xxing
2005-08-28 add a link to remove a custom image
172 return ( count( $this->mErrors ) == 0 );
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
173 }
174
175 /**
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
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 **/
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
182 function verify( &$pParamHash ) {
183 global $gBitUser, $gBitSystem;
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
184
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
185 // make sure we're all loaded up of we have a mArticleId
186 if( $this->mArticleId && empty( $this->mInfo ) ) {
187 $this->load();
188 }
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
189
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
190 if( @$this->verifyId( $this->mInfo['content_id'] ) ) {
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
191 $pParamHash['content_id'] = $this->mInfo['content_id'];
192 }
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
193
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
194 // It is possible a derived class set this to something different
04136bdb » xxing
2005-08-26 get article submissions working
195 if( empty( $pParamHash['content_type_guid'] )&& !empty( $this->mContentTypeGuid ) ) {
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
196 $pParamHash['content_type_guid'] = $this->mContentTypeGuid;
197 }
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
198
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
199 if( @$this->verifyId( $pParamHash['content_id'] ) ) {
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
200 $pParamHash['article_store']['content_id'] = $pParamHash['content_id'];
201 }
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
202
04136bdb » xxing
2005-08-26 get article submissions working
203 if( !empty( $pParamHash['author_name'] ) ) {
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
204 $pParamHash['article_store']['author_name'] = $pParamHash['author_name'];
205 }
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
206
daf5fbe9 » xxing
2005-08-28 existing image attachment working as well now - w00t!
207 // if no image attachment id is given, we set it null. this way a user can remove an attached image
47348b53 » xxing
2005-12-07 clean up image attachments for articles, allow custom size for resize…
208 // TODO: since we allow custom image size for article images, we should create a resized image of the original here.
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
209 if( @$this->verifyId( $pParamHash['image_attachment_id'] ) ) {
daf5fbe9 » xxing
2005-08-28 existing image attachment working as well now - w00t!
210 $pParamHash['article_store']['image_attachment_id'] = ( int )$pParamHash['image_attachment_id'];
211 } else {
212 $pParamHash['article_store']['image_attachment_id'] = NULL;
213 }
214
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
215 if( @$this->verifyId( $pParamHash['topic_id'] ) ) {
04136bdb » xxing
2005-08-26 get article submissions working
216 $pParamHash['article_store']['topic_id'] =( int )$pParamHash['topic_id'];
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
217 }
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
218
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
219 if( @$this->verifyId( $pParamHash['article_type_id'] ) ) {
04136bdb » xxing
2005-08-26 get article submissions working
220 $pParamHash['article_store']['article_type_id'] =( int )$pParamHash['article_type_id'];
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
221 }
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
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.
04136bdb » xxing
2005-08-26 get article submissions working
228 if( !empty( $pParamHash['edit'] ) ) {
4158723e » xxing
2005-08-13 fix article preview
229 $pParamHash['content_store']['data'] = $pParamHash['edit'];
230 }
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
231
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
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?
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
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'];
04136bdb » xxing
2005-08-26 get article submissions working
239 $pParamHash['article_store']['description'] = substr( $bodyText,0, DEFAULT_ARTICLE_DESCR_LEN ).( strlen( $bodyText )> DEFAULT_ARTICLE_DESCR_LEN ? '...' : '' );
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
240 } else {
241 $pParamHash['article_store']['description'] = $pParamHash['description'];
242 }*/
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
243
04136bdb » xxing
2005-08-26 get article submissions working
244 if( !empty( $pParamHash['rating'] ) ) {
245 $pParamHash['article_store']['rating'] =( int )( $pParamHash['rating'] );
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
246 }
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
247
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
248 // check for name issues, first truncate length if too long
249 if( !empty( $pParamHash['title'] ) ) {
5a597327 » xxing
2005-08-28 use $this->isValid() to check for $this->mArticleId
250 if( !$this->isValid() ) {
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
251 if( empty( $pParamHash['title'] ) ) {
8e166770 » Sylvie Greverend
2006-05-05 change the error message name to title to reuse the term used in the …
252 $this->mErrors['title'] = 'You must specify a title.';
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
253 } else {
f9dba4aa » Wakeworks
2006-06-15 support BIT_CONTENT_MAX_TITLE_LEN for hand tinkering databases to hav…
254 $pParamHash['content_store']['title'] = substr( $pParamHash['title'], 0, BIT_CONTENT_MAX_TITLE_LEN );
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
255 }
256 } else {
f9dba4aa » Wakeworks
2006-06-15 support BIT_CONTENT_MAX_TITLE_LEN for hand tinkering databases to hav…
257 $pParamHash['content_store']['title'] =( isset( $pParamHash['title'] ))? substr( $pParamHash['title'], 0, BIT_CONTENT_MAX_TITLE_LEN ): '';
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
258 }
259 } else if( empty( $pParamHash['title'] ) ) {
260 // no name specified
8e166770 » Sylvie Greverend
2006-05-05 change the error message name to title to reuse the term used in the …
261 $this->mErrors['title'] = 'You must specify a title';
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
262 }
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
263
04136bdb » xxing
2005-08-26 get article submissions working
264 if( !empty( $pParamHash['publish_Month'] ) ) {
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
265 $dateString = $pParamHash['publish_Year'].'-'.$pParamHash['publish_Month'].'-'.$pParamHash['publish_Day'].' '.$pParamHash['publish_Hour'].':'.$pParamHash['publish_Minute'];
b99c4167 » xxing
2005-08-26 get topic image on load()
266 //$timestamp = strtotime( $dateString );
267 $timestamp = $gBitSystem->mServerTimestamp->getUTCFromDisplayDate( strtotime( $dateString ) );
04136bdb » xxing
2005-08-26 get article submissions working
268 if( $timestamp !== -1 ) {
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
269 $pParamHash['publish_date'] = $timestamp;
270 }
271 }
5cbc7ece » xxing
2005-08-26 get permissions sorted when trying to view submitted article
272 if( !empty( $pParamHash['publish_date'] ) ) {
273 $pParamHash['article_store']['publish_date'] = $pParamHash['publish_date'];
274 }
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
275
04136bdb » xxing
2005-08-26 get article submissions working
276 if( !empty( $pParamHash['expire_Month'] ) ) {
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
277 $dateString = $pParamHash['expire_Year'].'-'.$pParamHash['expire_Month'].'-'.$pParamHash['expire_Day'].' '.$pParamHash['expire_Hour'].':'.$pParamHash['expire_Minute'];
b99c4167 » xxing
2005-08-26 get topic image on load()
278 //$timestamp = strtotime( $dateString );
279 $timestamp = $gBitSystem->mServerTimestamp->getUTCFromDisplayDate( strtotime( $dateString ) );
04136bdb » xxing
2005-08-26 get article submissions working
280 if( $timestamp !== -1 ) {
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
281 $pParamHash['expire_date'] = $timestamp;
282 }
283 }
04136bdb » xxing
2005-08-26 get article submissions working
284 if( !empty( $pParamHash['expire_date'] ) ) {
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
285 $pParamHash['article_store']['expire_date'] = $pParamHash['expire_date'];
286 }
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
287
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
288 if( @$this->verifyId( $pParamHash['status_id'] ) ) {
04136bdb » xxing
2005-08-26 get article submissions working
289 if( $pParamHash['status_id'] > ARTICLE_STATUS_PENDING ) {
1987dafa » xxing
2006-04-11 more permissions housekeeping and tidyup
290 if( $gBitUser->hasPermission( 'p_articles_approve_submission' ) || $gTikiuser->hasPermission( 'p_articles_auto_approve' ) ) {
04136bdb » xxing
2005-08-26 get article submissions working
291 $pParamHash['article_store']['status_id'] =( int )( $pParamHash['status_id'] );
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
292 } else {
293 $pParamHash['article_store']['status_id'] = ARTICLE_STATUS_PENDING;
294 }
295 } else {
04136bdb » xxing
2005-08-26 get article submissions working
296 $pParamHash['article_store']['status_id'] =( int )( $pParamHash['status_id'] );
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
297 }
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
298 } elseif( @$this->verifyId( $this->mInfo['status_id'] ) ) {
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
299 $pParamHash['article_store']['status_id'] = $this->mInfo['status_id'];
300 } else {
1987dafa » xxing
2006-04-11 more permissions housekeeping and tidyup
301 if( $gBitUser->hasPermission( 'p_articles_approve_submission' ) || $gBitUser->hasPermission( 'p_articles_auto_approve' ) ) {
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
302 $pParamHash['article_store']['status_id'] = ARTICLE_STATUS_APPROVED;
303 } else {
304 $pParamHash['article_store']['status_id'] = ARTICLE_STATUS_PENDING; // Default status
305 }
306 }
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
307
adcc311d » xxing
2006-04-29 get html per article working as well and reduce load by only parsing …
308 // content preferences
309 $prefs = array();
310 if( $gBitUser->hasPermission( 'p_liberty_enter_html' ) ) {
311 $prefs[] = 'content_enter_html';
312 }
313
314 foreach( $prefs as $pref ) {
315 if( !empty( $pParamHash['preferences'][$pref] ) ) {
316 $pParamHash['preferences_store'][$pref] = $pParamHash['preferences'][$pref];
317 } else {
318 $pParamHash['preferences_store'][$pref] = NULL;
319 }
320 }
321
322 if ( array_search( $pParamHash['article_store']['status_id'], array( ARTICLE_STATUS_DENIED, ARTICLE_STATUS_DRAFT, ARTICLE_STATUS_PENDING ) ) ) {
5330bc51 » Sean Lee
2006-02-20 Merge recent changes to HEAD
323 $this->mInfo["no_index"] = true ;
324 }
325
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
326 return( count( $this->mErrors )== 0 );
327 }
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
328
cf7b0879 » xxing
2005-09-04 add some documentation
329 /**
ec0a861d » xxing
2005-09-11 add some more documentation
330 * Store article image
cf7b0879 » xxing
2005-09-04 add some documentation
331 * @param array pParamHash of values that will be used to store the page
332 * @param array pFileHash hash returned by $_FILES[<name>]
333 * @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why
334 * @access public
335 **/
336 function storeImage( &$pParamHash, $pFileHash ) {
337 global $gBitSystem;
338 if( $this->isValid() ) {
339 if( !empty( $pFileHash['tmp_name'] ) ) {
340 $tmpImagePath = $this->getArticleImageStoragePath( $this->mArticleId, TRUE ).$pFileHash['name'];
341 if( !move_uploaded_file( $pFileHash['tmp_name'], $tmpImagePath ) ) {
342 $this->mErrors['article_image'] = "Error during attachment of article image";
343 } else {
3de046fc » xxing
2007-01-01 use liberty_get_function() to determine image processing function
344 $resizeFunc = liberty_get_function( 'resize' );
cf7b0879 » xxing
2005-09-04 add some documentation
345 $storeHash['source_file'] = $tmpImagePath;
71849121 » xxing
2005-09-14 use constants instead of hardcoded package names and ensure that imag…
346 $storeHash['dest_path'] = STORAGE_PKG_NAME.'/'.ARTICLES_PKG_NAME.'/';
cf7b0879 » xxing
2005-09-04 add some documentation
347 $storeHash['dest_base_name'] = 'article_'.$this->mArticleId;
348 $storeHash['max_width'] = ARTICLE_TOPIC_THUMBNAIL_SIZE;
349 $storeHash['max_height'] = ARTICLE_TOPIC_THUMBNAIL_SIZE;
350 $storeHash['type'] = $pFileHash['type'];
351
352 if( !( $resizeFunc( $storeHash ) ) ) {
353 $this->mErrors[] = 'Error while resizing article image';
354 }
355 @unlink( $tmpImagePath );
356 }
357 } elseif( !empty( $pParamHash['preview_image_path'] ) && is_file( $pParamHash['preview_image_path'] ) ) {
358 // if this article has been previewed with an image, we can copy it to the destination place
71849121 » xxing
2005-09-14 use constants instead of hardcoded package names and ensure that imag…
359 rename( $pParamHash['preview_image_path'], STORAGE_PKG_PATH.ARTICLES_PKG_NAME.'/article_'.$this->mArticleId.'.jpg' );
cf7b0879 » xxing
2005-09-04 add some documentation
360 }
361 }
362 return ( count( $this->mErrors ) == 0 );
363 }
364
365 /**
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
366 * Get the name of the article image file
367 *
368 * @param array $pArticleId article id
369 * @access public
370 * @return TRUE on success, FALSE on failure
371 */
372 function getArticleImageStorageName( $pArticleId = NULL ) {
373 if( !@BitBase::verifyId( $pArticleId ) ) {
374 if( $this->isValid() ) {
375 $pArticleId = $this->mArticleId;
376 } else {
377 return NULL;
378 }
379 }
380
381 return "article_$pArticleId.jpg";
382 }
383
384 /**
ec0a861d » xxing
2005-09-11 add some more documentation
385 * Work out the path to the image for this article
cf7b0879 » xxing
2005-09-04 add some documentation
386 * @param $pArticleId id of the article we need the image path for
387 * @param $pBasePathOnly bool TRUE / FALSE - specify whether you want full path or just base path
388 * @return path on success, FALSE on failure
389 * @access public
390 **/
391 function getArticleImageStoragePath( $pArticleId = NULL, $pBasePathOnly = FALSE ) {
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
392 $path = STORAGE_PKG_PATH.ARTICLES_PKG_NAME.'/';
393 if( !is_dir( $path ) ) {
394 mkdir_p( $path );
395 }
396
397 if( $pBasePathOnly ) {
398 return $path;
399 }
400
401 if( !@BitBase::verifyId( $pArticleId ) ) {
402 if( $this->isValid() ) {
403 $pArticleId = $this->mArticleId;
404 } else {
405 return NULL;
406 }
407 }
408
409 if( !empty( $pArticleId ) ) {
410 return $path.BitArticle::getArticleImageStorageName( $pArticleId );
411 } else {
412 return FALSE;
cf7b0879 » xxing
2005-09-04 add some documentation
413 }
414 }
415
416 /**
ec0a861d » xxing
2005-09-11 add some more documentation
417 * Work out the URL to the image for this article
cf7b0879 » xxing
2005-09-04 add some documentation
418 * @param $pArticleId id of the article we need the image path for
419 * @param $pBasePathOnly bool TRUE / FALSE - specify whether you want full path or just base path
420 * @return URL on success, FALSE on failure
421 * @access public
422 **/
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
423 function getArticleImageStorageUrl( $pArticleId = NULL, $pBasePathOnly = FALSE, $pForceRefresh = FALSE ) {
cf7b0879 » xxing
2005-09-04 add some documentation
424 global $gBitSystem;
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
425 $url = STORAGE_PKG_URL.ARTICLES_PKG_NAME.'/';
cf7b0879 » xxing
2005-09-04 add some documentation
426 if( $pBasePathOnly ) {
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
427 return $url;
cf7b0879 » xxing
2005-09-04 add some documentation
428 }
429
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
430 if( !@BitBase::verifyId( $pArticleId ) ) {
cf7b0879 » xxing
2005-09-04 add some documentation
431 if( $this->isValid() ) {
432 $pArticleId = $this->mArticleId;
433 } else {
434 return NULL;
435 }
436 }
437
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
438 if( is_file( BitArticle::getArticleImageStoragePath( NULL, TRUE ).BitArticle::getArticleImageStorageName( $pArticleId ) ) ) {
439 return $url.BitArticle::getArticleImageStorageName( $pArticleId ).( $pForceRefresh ? "?".$gBitSystem->getUTCTime() : '' );
cf7b0879 » xxing
2005-09-04 add some documentation
440 } else {
441 return FALSE;
442 }
443 }
444
ec0a861d » xxing
2005-09-11 add some more documentation
445 /**
446 * Deal with images and text, modify them apprpriately that they can be returned to the form.
447 * @param $previewData data submitted by form - generally $_REQUEST
448 * @return array of data compatible with article form
449 * @access public
450 **/
71849121 » xxing
2005-09-14 use constants instead of hardcoded package names and ensure that imag…
451 function preparePreview( $pParamHash ) {
4fea2832 » xxing
2005-08-28 get image upload working with preview and subsequent save
452 global $gBitSystem, $gBitUser;
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
453
71849121 » xxing
2005-09-14 use constants instead of hardcoded package names and ensure that imag…
454 $data = $pParamHash;
04136bdb » xxing
2005-08-26 get article submissions working
455 $this->verify( $data );
71849121 » xxing
2005-09-14 use constants instead of hardcoded package names and ensure that imag…
456 $data = array_merge( $pParamHash, $data['content_store'], $data['article_store'] );
c24c28c1 » xxing
2006-12-13 fix articles preview
457 $data['raw'] = $data['edit'];
4fea2832 » xxing
2005-08-28 get image upload working with preview and subsequent save
458
04136bdb » xxing
2005-08-26 get article submissions working
459 if( empty( $data['user_id'] ) ) {
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
460 $data['user_id'] = $gBitUser->mUserId;
461 }
4fea2832 » xxing
2005-08-28 get image upload working with preview and subsequent save
462
04136bdb » xxing
2005-08-26 get article submissions working
463 if( empty( $data['hits'] ) ) {
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
464 $data['hits'] = 0;
465 }
4fea2832 » xxing
2005-08-28 get image upload working with preview and subsequent save
466
04136bdb » xxing
2005-08-26 get article submissions working
467 if( empty( $data['publish_date'] ) ) {
4fea2832 » xxing
2005-08-28 get image upload working with preview and subsequent save
468 $data['publish_date'] = $gBitSystem->getUTCTime();
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
469 }
4fea2832 » xxing
2005-08-28 get image upload working with preview and subsequent save
470
04136bdb » xxing
2005-08-26 get article submissions working
471 if( empty( $data['article_type_id'] ) ) {
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
472 $data['article_type_id'] = 1;
473 }
4fea2832 » xxing
2005-08-28 get image upload working with preview and subsequent save
474
04136bdb » xxing
2005-08-26 get article submissions working
475 if( empty( $data['topic_id'] ) ) {
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
476 $data['topic_id'] = 1;
477 }
4fea2832 » xxing
2005-08-28 get image upload working with preview and subsequent save
478
04136bdb » xxing
2005-08-26 get article submissions working
479 if( empty( $data['parsed_data'] ) ) {
ca235b00 » xxing
2006-06-20 allow caching to various files by allowing specification of cache fil…
480 $data['no_cache'] = TRUE;
ea85f9e9 » xxing
2006-02-16 new API for parseData(); please view ApiChangeLog for details
481 $data['parsed_data'] = $this->parseData( $data );
ca235b00 » xxing
2006-06-20 allow caching to various files by allowing specification of cache fil…
482 // replace the split syntax with a horizontal rule
483 $data['parsed_data'] = preg_replace( ARTICLE_SPLIT_REGEX, "<hr />", $data['parsed_data'] );
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
484 }
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
485
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
486 if( @$this->verifyId( $data['image_attachment_id'] ) ) {
daf5fbe9 » xxing
2005-08-28 existing image attachment working as well now - w00t!
487 $data['image_attachment_id'] = ( int )$data['image_attachment_id'];
fbe5d527 » xxing
2006-02-01 detikify liberty
488 $query = "SELECT lf.storage_path AS image_storage_path
489 FROM `".BIT_DB_PREFIX."liberty_attachments` a
490 LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_files` lf ON( lf.file_id = a.foreign_id )
f210a14d » bitweaver.org
2006-01-31 massive table de-tikification. changed all tiki_ table prefixes with …
491 WHERE a.attachment_id=?";
daf5fbe9 » xxing
2005-08-28 existing image attachment working as well now - w00t!
492 $data['image_storage_path'] = $this->mDb->getOne( $query, array( $data['image_attachment_id'] ) );
539fa019 » xxing
2005-08-28 rename img_url to image_url
493 $data['image_url'] = BitArticle::getImageUrl( $data );
4fea2832 » xxing
2005-08-28 get image upload working with preview and subsequent save
494 }
495
71849121 » xxing
2005-09-14 use constants instead of hardcoded package names and ensure that imag…
496 if( !empty( $_FILES['article_image']['name'] ) ) {
daf5fbe9 » xxing
2005-08-28 existing image attachment working as well now - w00t!
497 // store the image in temp/articles/
71849121 » xxing
2005-09-14 use constants instead of hardcoded package names and ensure that imag…
498 $tmpImagePath = TEMP_PKG_PATH.ARTICLES_PKG_NAME.'/'.'temp_'.$_FILES['article_image']['name'];
daf5fbe9 » xxing
2005-08-28 existing image attachment working as well now - w00t!
499 $tmpImageName = preg_replace( "/(.*)\..*?$/", "$1", $_FILES['article_image']['name'] );
71849121 » xxing
2005-09-14 use constants instead of hardcoded package names and ensure that imag…
500 if( !is_dir( TEMP_PKG_PATH.ARTICLES_PKG_NAME ) ) {
501 mkdir( TEMP_PKG_PATH.ARTICLES_PKG_NAME );
daf5fbe9 » xxing
2005-08-28 existing image attachment working as well now - w00t!
502 }
503
504 if( !move_uploaded_file( $_FILES['article_image']['tmp_name'], $tmpImagePath ) ) {
505 $this->mErrors['article_image'] = "Error during attachment of article image";
506 } else {
3de046fc » xxing
2007-01-01 use liberty_get_function() to determine image processing function
507 $resizeFunc = liberty_get_function( 'resize' );
daf5fbe9 » xxing
2005-08-28 existing image attachment working as well now - w00t!
508 $pFileHash['source_file'] = $tmpImagePath;
3397a678 » xxing
2006-10-04 fix undefined constant - we need to fix the url / path mix in here (t…
509 $pFileHash['dest_path'] = preg_replace( '!/+!', '', str_replace( BIT_ROOT_PATH, '', TEMP_PKG_PATH ) ).'/'.ARTICLES_PKG_NAME.'/';
daf5fbe9 » xxing
2005-08-28 existing image attachment working as well now - w00t!
510 // remove the extension
511 $pFileHash['dest_base_name'] = $tmpImageName;
512 $pFileHash['max_width'] = ARTICLE_TOPIC_THUMBNAIL_SIZE;
513 $pFileHash['max_height'] = ARTICLE_TOPIC_THUMBNAIL_SIZE;
514 $pFileHash['type'] = $_FILES['article_image']['type'];
515
516 if( !( $resizeFunc( $pFileHash ) ) ) {
517 $this->mErrors[] = 'Error while resizing article image';
518 }
519 @unlink( $tmpImagePath );
71849121 » xxing
2005-09-14 use constants instead of hardcoded package names and ensure that imag…
520 $data['image_url'] = $data['preview_image_url'] = TEMP_PKG_URL.ARTICLES_PKG_NAME.'/'.$tmpImageName.'.jpg';
3397a678 » xxing
2006-10-04 fix undefined constant - we need to fix the url / path mix in here (t…
521 $data['show_image'] = TRUE;
71849121 » xxing
2005-09-14 use constants instead of hardcoded package names and ensure that imag…
522 $data['preview_image_path'] = TEMP_PKG_PATH.ARTICLES_PKG_NAME.'/'.$tmpImageName.'.jpg';
4fea2832 » xxing
2005-08-28 get image upload working with preview and subsequent save
523 }
71849121 » xxing
2005-09-14 use constants instead of hardcoded package names and ensure that imag…
524 } elseif( !empty( $data['preview_image_path'] ) && is_file( $data['preview_image_path'] ) ) {
525 $data['image_url'] = $data['preview_image_url'];
4fea2832 » xxing
2005-08-28 get image upload working with preview and subsequent save
526 }
527
04136bdb » xxing
2005-08-26 get article submissions working
528 $articleType = &new BitArticleType( $data['article_type_id'] );
529 $articleTopic = &new BitArticleTopic( $data['topic_id'] );
530 $data = array_merge( $data, $articleType->mInfo, $articleTopic->mInfo );
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
531
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
532 return $data;
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
533 }
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
534
ec0a861d » xxing
2005-09-11 add some more documentation
535 /**
536 * Get the URL for any given article image
537 * @param $pParamHash pass in full set of data returned from article query
538 * @return url to image
539 * @access public
540 **/
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
541 function getImagePath() {
542 $ret = NULL;
543 if( $this->isValid() && BitArticle::getArticleImageStoragePath( $this->mArticleId ) ) {
544 $ret = BitArticle::getArticleImageStoragePath( $this->mArticleId );
545 }
546 return $ret;
547 }
548
549 /**
550 * Get the URL for any given article image
551 * @param $pParamHash pass in full set of data returned from article query
552 * @return url to image
553 * @access public
554 **/
daf5fbe9 » xxing
2005-08-28 existing image attachment working as well now - w00t!
555 function getImageUrl( $pParamHash ) {
556 $ret = NULL;
557 // if a custom image for the article exists, use that, then use an attachment, then use the topic image
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
558 if( @$this->verifyId( $pParamHash['article_id'] ) && BitArticle::getArticleImageStorageUrl( $pParamHash['article_id'] ) ) {
daf5fbe9 » xxing
2005-08-28 existing image attachment working as well now - w00t!
559 $ret = BitArticle::getArticleImageStorageUrl( $pParamHash['article_id'] );
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
560 } elseif( @$this->verifyId( $pParamHash['image_attachment_id'] ) && $pParamHash['image_attachment_id'] ) {
47348b53 » xxing
2005-12-07 clean up image attachments for articles, allow custom size for resize…
561 // TODO: clean up the small url stuff. shouldn't be hardcoded.
315f7703 » xxing
2005-08-29 first check if attached image is available
562 // perhaps we should make a copy of the image file and reduce it to article size settings.
71849121 » xxing
2005-09-14 use constants instead of hardcoded package names and ensure that imag…
563 // this will be necessary as soon as we allow custom image sizes for article image
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
564 //$image = preg_replace( "/(.*)\/.*?$/", "$1/small.jpg", $pParamHash['image_storage_path'] );
565 $image = basename( $pParamHash['image_storage_path'] )."/small.jpg";
315f7703 » xxing
2005-08-29 first check if attached image is available
566 if( is_file( BIT_ROOT_PATH.$image ) ) {
567 $ret = BIT_ROOT_URL.$image;
568 }
daf5fbe9 » xxing
2005-08-28 existing image attachment working as well now - w00t!
569 } elseif( !empty( $pParamHash['has_topic_image'] ) && $pParamHash['has_topic_image'] == 'y' ) {
570 $ret = BitArticleTopic::getTopicImageStorageUrl( $pParamHash['topic_id'] );
571 }
572 return $ret;
573 }
574
ec0a861d » xxing
2005-09-11 add some more documentation
575 /**
576 * Remove a custom article image - will result in the usage of the default image if a topic with image is selected
577 * @param $pArticleId ID of the article that needs the image removed
578 * @param $pImagePath path to the image that needs removing - generally used during preview - will override article id
579 * @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why
580 * @access public
581 **/
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
582 function expungeImage( $pArticleId = NULL, $pImagePath = NULL ) {
583 if( !empty( $pImagePath ) && is_file( $pImagePath ) && !@unlink( $pImagePath ) ) {
584 $this->mErrors['remove_image'] = tra( 'The image could not be removed because we don\'t have the correct permission to do so.' );
6f9ed7ac » xxing
2005-08-28 add a link to remove a custom image
585 }
586
5a597327 » xxing
2005-08-28 use $this->isValid() to check for $this->mArticleId
587 if( empty( $pArticleId ) && $this->isValid() ) {
588 $pArticleId = $this->mArticleId;
589 }
590
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
591 if( is_file( $image = BitArticle::getArticleImageStoragePath( $pArticleId ) ) ) {
6f9ed7ac » xxing
2005-08-28 add a link to remove a custom image
592 if( !@unlink( $image ) ) {
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
593 $this->mErrors['remove_image'] = tra( 'The article image could not be removed because this article doesn\'t seem to have an image associated with it.' );
6f9ed7ac » xxing
2005-08-28 add a link to remove a custom image
594 }
595 }
596 return ( count( $this->mErrors ) == 0 );
597 }
598
ec0a861d » xxing
2005-09-11 add some more documentation
599 /**
600 * Removes currently loaded article
601 * @return bool TRUE on success, FALSE on failure
602 * @access public
603 **/
4fea2832 » xxing
2005-08-28 get image upload working with preview and subsequent save
604 function expunge() {
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
605 $ret = FALSE;
606 if( $this->isValid() ) {
8c5f3098 » xxing
2005-08-28 clean up articles custom image upload stuff
607 $this->mDb->StartTrans();
f210a14d » bitweaver.org
2006-01-31 massive table de-tikification. changed all tiki_ table prefixes with …
608 $query = "DELETE FROM `".BIT_DB_PREFIX."articles` WHERE `content_id` = ?";
8c5f3098 » xxing
2005-08-28 clean up articles custom image upload stuff
609 $result = $this->mDb->query( $query, array( $this->mContentId ) );
5a597327 » xxing
2005-08-28 use $this->isValid() to check for $this->mArticleId
610 // remove article image if it exists
611 $this->expungeImage();
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
612 if( LibertyAttachable::expunge() ) {
613 $ret = TRUE;
614 $this->mDb->CompleteTrans();
615 } else {
616 $this->mDb->RollbackTrans();
8c5f3098 » xxing
2005-08-28 clean up articles custom image upload stuff
617 }
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
618 }
619 return $ret;
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
620 }
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
621
ec0a861d » xxing
2005-09-11 add some more documentation
622 /**
623 * Check if there is an article loaded
624 * @return bool TRUE on success, FALSE on failure
625 * @access public
626 **/
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
627 function isValid() {
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
628 return( $this->verifyId( $this->mArticleId ) && $this->verifyId( $this->mContentId ) );
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
629 }
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
630
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
631 /**
fbe5d527 » xxing
2006-02-01 detikify liberty
632 * This function generates a list of records from the liberty_content database for use in a list page
ec0a861d » xxing
2005-09-11 add some more documentation
633 * @param $pParamHash contains an array of conditions to sort by
d403bf61 » lsces
2005-10-30 Add PHPDoc headings to package
634 * @return array
635 * ['data'] which contains all articles that match pParamHash conditions
636 * ['cant'] which contains the number of articles that matched the pParamHash conditions
ec0a861d » xxing
2005-09-11 add some more documentation
637 * @access public
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
638 **/
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
639 function getList( &$pParamHash ) {
b7cc1a18 » Hash9
2006-08-29 add the factility to view the history of articles, and an auto approv…
640 global $gBitSystem, $gBitUser, $gLibertySystem;
641
c4f74cea » spiderr
2006-11-18 comment out incomplete statistics feature
642 /*
643 feature incomplete
b7cc1a18 » Hash9
2006-08-29 add the factility to view the history of articles, and an auto approv…
644 if ($gBitSystem->isFeatureActive('articles_auto_approve') && empty($pParamHash['no_update'])) {
645 BitArticleStatistics::autoApprove();
646 }
c4f74cea » spiderr
2006-11-18 comment out incomplete statistics feature
647 */
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
648
fe614d15 » xxing
2005-09-11 apply default sort_mode before LibertyContent::prepGetList();
649 if( empty( $pParamHash['sort_mode'] ) ) {
d3426e6a » spiderr
2006-08-30 fix majorly busted ORDER BY changes
650 $pParamHash['sort_mode'] = $gBitSystem->isFeatureActive('articles_auto_approve') ? 'order_key_desc' : 'publish_date_desc';
fe614d15 » xxing
2005-09-11 apply default sort_mode before LibertyContent::prepGetList();
651 }
652
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
653 LibertyContent::prepGetList( $pParamHash );
654
838a838b » lsces
2006-02-10 Add ServicesSQL facility
655 $joinSql = '';
656 $selectSql = '';
657 $bindVars = array();
658 array_push( $bindVars, $this->mContentTypeGuid );
35561720 » xxing
2006-02-14 rename content_load_function to content_load_sql_function
659 $this->getServicesSql( 'content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars );
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
660
838a838b » lsces
2006-02-10 Add ServicesSQL facility
661 $find = $pParamHash['find'];
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
662 if( is_array( $find ) ) {
c6e286d2 » xxing
2005-08-31 add more options to limit getList() by
663 // you can use an array of articles
fa7948e6 » xxing
2006-02-14 concatenate whereSql
664 $whereSql .= " AND lc.`title` IN( ".implode( ',',array_fill( 0, count( $find ),'?' ) )." )";
962a29ab » lsces
2006-02-10 Tidy array merges
665 $bindVars = array_merge( $bindVars, $find );
d5686685 » xxing
2005-09-04 fix user_id where clause
666 } elseif( is_string( $find ) ) {
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
667 // or a string
fa7948e6 » xxing
2006-02-14 concatenate whereSql
668 $whereSql .= " AND UPPER( lc.`title` ) LIKE ? ";
962a29ab » lsces
2006-02-10 Tidy array merges
669 $bindVars[] = '%'.strtoupper( $find ).'%';
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
670 } elseif( @$this->verifyId( $pParamHash['user_id'] ) ) {
d5686685 » xxing
2005-09-04 fix user_id where clause
671 // or gate on a user
fa7948e6 » xxing
2006-02-14 concatenate whereSql
672 $whereSql .= " AND lc.`creator_user_id` = ? ";
838a838b » lsces
2006-02-10 Add ServicesSQL facility
673 $bindVars[] = array( $pParamHash['user_id'] );
d6cf45cf » xxing
2005-08-30 add option to select by topic name
674 }
675
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
676 if( @$this->verifyId( $pParamHash['status_id'] ) ) {
838a838b » lsces
2006-02-10 Add ServicesSQL facility
677 $whereSql .= " AND a.`status_id` = ? ";
678 $bindVars[] = $pParamHash['status_id'];
c6e286d2 » xxing
2005-08-31 add more options to limit getList() by
679 }
680
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
681 if( @$this->verifyId( $pParamHash['type_id'] ) ) {
838a838b » lsces
2006-02-10 Add ServicesSQL facility
682 $whereSql .= " AND a.`article_type_id` = ? ";
683 $bindVars[] = ( int )$pParamHash['type_id'];
c6e286d2 » xxing
2005-08-31 add more options to limit getList() by
684 }
685
9090a1df » spiderr
2006-04-10 remove old spell checking
686 // TODO: we need to check if the article wants to be viewed before / after respective dates
687 // someone better at SQL please get this working without an additional db call - xing
688 if( empty( $pParamHash['show_expired'] ) ) {
689 $timestamp = $gBitSystem->getUTCTime();
690 $whereSql .= " AND a.`publish_date` < ? AND a.`expire_date` > ? ";
691 $bindVars[] = ( int )$timestamp;
692 $bindVars[] = ( int )$timestamp;
693 }
694
0b9692b0 » xxing
2006-01-26 merge recent changes into HEAD
695 if( @$this->verifyId( $pParamHash['topic_id'] ) ) {
838a838b » lsces
2006-02-10 Add ServicesSQL facility
696 $whereSql .= " AND a.`topic_id` = ? ";
697 $bindVars[] = ( int )$pParamHash['topic_id'];
0b9692b0 » xxing
2006-01-26 merge recent changes into HEAD
698 } elseif( !empty( $pParamHash['topic'] ) ) {
ea85f9e9 » xxing
2006-02-16 new API for parseData(); please view ApiChangeLog for details
699 $whereSql .= " AND UPPER( atopic.`topic_name` ) = ? ";
838a838b » lsces
2006-02-10 Add ServicesSQL facility
700 $bindVars[] = strtoupper( $pParamHash['topic'] );
0b9692b0 » xxing
2006-01-26 merge recent changes into HEAD
701 } else {
44c943dd » lsces
2006-02-19 Fix reserved word field names
702 $whereSql .= " AND ( atopic.`active_topic` != 'n' OR atopic.`active_topic` IS NULL ) ";
703 //$whereSql .= " AND atopic.`active_topic` != 'n' ";
0b9692b0 » xxing
2006-01-26 merge recent changes into HEAD
704 }
705
c4f74cea » spiderr
2006-11-18 comment out incomplete statistics feature
706 /*
707 feature incomplete
b7cc1a18 » Hash9
2006-08-29 add the factility to view the history of articles, and an auto approv…
708 if ($gBitSystem->isFeatureActive('articles_auto_approve')) {
709 $as = new BitArticleStatistics();
971f3d0e » xxing
2006-11-01 fix image return url. this really needs to be cleaned up.
710 $obj = null;
711 if (isset($this)) {
712 $obj = $this;
713 }
714 $selectSql .= $as->getSQLRank($obj);
715 }
c4f74cea » spiderr
2006-11-18 comment out incomplete statistics feature
716 */
b7cc1a18 » Hash9
2006-08-29 add the factility to view the history of articles, and an auto approv…
717
42b75615 » bitweaver.org
2006-02-27 explicit column names to get around oracle pain ORA-00918
718 // Oracle is very particular about naming multiple columns, so need to explicity name them ORA-00918: column ambiguously defined
299e4781 » xxing
2006-12-05 add missing lch.`hits`
719 $query = "
720 SELECT
721 a.`article_id`, a.`description`, a.`author_name`, a.`image_attachment_id`, a.`publish_date`, a.`expire_date`, a.`rating`,
722 atopic.`topic_id`, atopic.`topic_name`, atopic.`has_topic_image`, atopic.`active_topic`,
723 astatus.`status_id`, astatus.`status_name`,
724 lch.`hits`, lf.`storage_path` as `image_storage_path`,
725 atype.*, lc.* $selectSql
f210a14d » bitweaver.org
2006-01-31 massive table de-tikification. changed all tiki_ table prefixes with …
726 FROM `".BIT_DB_PREFIX."articles` a
b7cc1a18 » Hash9
2006-08-29 add the factility to view the history of articles, and an auto approv…
727 INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON lc.`content_id` = a.`content_id`
728 INNER JOIN `".BIT_DB_PREFIX."article_status` astatus ON astatus.`status_id` = a.`status_id`
729 LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content_hits` lch ON lc.`content_id` = lch.`content_id`
730 LEFT OUTER JOIN `".BIT_DB_PREFIX."article_topics` atopic ON atopic.`topic_id` = a.`topic_id`
731 LEFT OUTER JOIN `".BIT_DB_PREFIX."article_types` atype ON atype.`article_type_id` = a.`article_type_id`
732 LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_attachments` la ON la.`attachment_id` = a.`image_attachment_id`
733 LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_files` lf ON lf.`file_id` = la.`foreign_id` $joinSql
fa7948e6 » xxing
2006-02-14 concatenate whereSql
734 WHERE lc.`content_type_guid` = ? $whereSql
a39e6451 » xxing
2007-01-06 rename some methods in BitDbBase to meet bitweaver standards. all cha…
735 ORDER BY ".$this->mDb->convertSortmode( $pParamHash['sort_mode'] );
04136bdb » xxing
2005-08-26 get article submissions working
736
f210a14d » bitweaver.org
2006-01-31 massive table de-tikification. changed all tiki_ table prefixes with …
737 $query_cant = "SELECT COUNT( * )FROM `".BIT_DB_PREFIX."articles` a
ea85f9e9 » xxing
2006-02-16 new API for parseData(); please view ApiChangeLog for details
738 INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON lc.`content_id` = a.`content_id`
739 LEFT OUTER JOIN `".BIT_DB_PREFIX."article_topics` atopic ON atopic.`topic_id` = a.`topic_id` $joinSql
838a838b » lsces
2006-02-10 Add ServicesSQL facility
740 WHERE lc.`content_type_guid` = ? $whereSql";
80fa1d92 » spiderr
2006-01-25 Added uspport for multiple database backend support. This necessitate…
741
838a838b » lsces
2006-02-10 Add ServicesSQL facility
742 $result = $this->mDb->query( $query, $bindVars, $pParamHash['max_records'], $pParamHash['offset'] );
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
743 $ret = array();
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
744 $comment = &new LibertyComment();
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
745 while( $res = $result->fetchRow() ) {
539fa019 » xxing
2005-08-28 rename img_url to image_url
746 $res['image_url'] = BitArticle::getImageUrl( $res );
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
747
ea85f9e9 » xxing
2006-02-16 new API for parseData(); please view ApiChangeLog for details
748 // deal with the parsing
ca235b00 » xxing
2006-06-20 allow caching to various files by allowing specification of cache fil…
749 $parseHash['format_guid'] = $res['format_guid'];
750 $parseHash['content_id'] = $res['content_id'];
751 $parseHash['cache_extension'] = 'desc';
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
752 if( preg_match( ARTICLE_SPLIT_REGEX, $res['data'] ) ) {
753 $parts = preg_split( ARTICLE_SPLIT_REGEX, $res['data'] );
e8889416 » xxing
2006-12-19 make sure read_more stuff isn't applied when ...split... is added to …
754 if( empty( $parts[1] ) ) {
755 $res['has_more'] = FALSE;
756 }
ea85f9e9 » xxing
2006-02-16 new API for parseData(); please view ApiChangeLog for details
757 $parseHash['data'] = $parts[0];
adcc311d » xxing
2006-04-29 get html per article working as well and reduce load by only parsing …
758 } else {
0d9032df » xxing
2006-04-14 change article config setting names to <pkg>_setting
759 $parseHash['data'] = substr( $res['data'], 0, $gBitSystem->getConfig( 'articles_description_length' ) );
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
760 }
8bf536e2 » bitweaver.org
2006-06-19 remove maketoc from articles preview
761 // description shouldn't containg {maketoc}
762 $parseHash['data'] = preg_replace( "/\{maketoc[^\}]*\}/i", "", $parseHash['data'] );
ea85f9e9 » xxing
2006-02-16 new API for parseData(); please view ApiChangeLog for details
763 $res['parsed_description'] = $this->parseData( $parseHash );
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
764
ea85f9e9 » xxing
2006-02-16 new API for parseData(); please view ApiChangeLog for details
765 // this is needed to remove trailing stuff from the parser and insert a link to the actual article
086d0bc1 » xxing
2006-01-10 merge recent changes into HEAD
766 $trailing_junk_pattern = "/(<br[^>]*>)*$/i";
adcc311d » xxing
2006-04-29 get html per article working as well and reduce load by only parsing …
767 if( $res['data'] != $parseHash['data'] ) {
086d0bc1 » xxing
2006-01-10 merge recent changes into HEAD
768 $res['parsed_description'] = preg_replace( $trailing_junk_pattern, "", $res['parsed_description'] );
e8889416 » xxing
2006-12-19 make sure read_more stuff isn't applied when ...split... is added to …
769 if( !isset( $res['has_more'] ) || ( isset( $res['has_more'] ) && $res['has_more'] === TRUE ) ) {
770 $res['parsed_description'] .= '<a class="more" href="'.$this->getDisplayUrl( $res['article_id'] ).'" title="'.$this->getTitle( $res ).'">&hellip;</a>';
771 $res['has_more'] = TRUE;
772 }
086d0bc1 » xxing
2006-01-10 merge recent changes into HEAD
773 } else {
774 $res['parsed_description'] = preg_replace( $trailing_junk_pattern, "", $res['parsed_description'] );
775 }
776
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
777 $res['num_comments'] = $comment->getNumComments( $res['content_id'] );
6130c1dd » xxing
2006-01-31 fix various article submission related issues
778 $res['display_url'] = $this->getDisplayUrl( $res['article_id'] );
779 $res['display_link'] = $this->getDisplayLink( $res['title'], $res );
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
780 $ret[] = $res;
781 }
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
782
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
783 $pParamHash["data"] = $ret;
838a838b » lsces
2006-02-10 Add ServicesSQL facility
784 $pParamHash["cant"] = $this->mDb->getOne( $query_cant, $bindVars );
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
785
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
786 LibertyContent::postGetList( $pParamHash );
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
787
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
788 return $pParamHash;
789 }
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
790
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
791 /**
cf7b0879 » xxing
2005-09-04 add some documentation
792 * Generates the URL to the article
793 * @return the link to the full article
7f0e5d8c » xxing
2005-08-13 more work on getting articles going
794 */
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
795 function getDisplayUrl( $pArticleId = NULL) {
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
796 global $gBitSystem;
797
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
798 $ret = NULL;
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
799 if( !@BitBase::verifyId( $pArticleId ) && $this->isValid() ) {
800 $pArticleId = $this->mArticleId;
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
801 }
802
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
803 if( @$this->verifyId( $pArticleId ) ) {
475f2243 » xxing
2006-02-13 another batch of kernel_prefs name cleanup. this should be it
804 if( $gBitSystem->isFeatureActive( 'pretty_urls_extended' ) ) {
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
805 // Not needed since it's a number: $ret = ARTICLES_PKG_URL."view/".$this->mArticleId;
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
806 $ret = ARTICLES_PKG_URL.$pArticleId;
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
807 } else if( $gBitSystem->isFeatureActive( 'pretty_urls' ) ) {
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
808 $ret = ARTICLES_PKG_URL.$pArticleId;
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
809 } else {
122e288d » xxing
2006-12-16 finally seperated URL from PATH stuff for article and topic images
810 $ret = ARTICLES_PKG_URL."read.php?article_id=$pArticleId";
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
811 }
47d932ad » xxing
2005-08-26 parsed_description only needed when loading articles front page
812 }
813 return $ret;
814 }
cf7b0879 » xxing
2005-09-04 add some documentation
815
816 /**
817 * get a list of all available statuses
818 * @return an array of available statuses
819 * @access public
820 **/
821 function getStatusList() {
822 global $gBitSystem;
f210a14d » bitweaver.org
2006-01-31 massive table de-tikification. changed all tiki_ table prefixes with …
823 $query = "SELECT * FROM `".BIT_DB_PREFIX."article_status`";
cf7b0879 » xxing
2005-09-04 add some documentation
824 $result = $gBitSystem->mDb->query( $query );
825 return $result->getRows();
826 }
827
828 /**
829 * set the status of an article
830 * @param $pStatusId new status id of the article
831 * @param $pArticleId of the article that is being changed - if not set, it will attemtp to change the currently loaded article
832 * @return new status of article on success - else returns NULL
833 * @access public
834 **/
5330bc51 » Sean Lee
2006-02-20 Merge recent changes to HEAD
835 function setStatus( $pStatusId, $pArticleId = NULL, $pContentId = NULL ) {
9090a1df » spiderr
2006-04-10 remove old spell checking
836 global $gBitSystem;
cf7b0879 » xxing
2005-09-04 add some documentation
837 $validStatuses = array( ARTICLE_STATUS_DENIED, ARTICLE_STATUS_DRAFT, ARTICLE_STATUS_PENDING, ARTICLE_STATUS_APPROVED, ARTICLE_STATUS_RETIRED );
838
839 if( !in_array( $pStatusId, $validStatuses ) ) {
840 $this->mErrors[] = "Invalid article status";
841 return FALSE;
842 }
843
5330bc51 » Sean Lee
2006-02-20 Merge recent changes to HEAD
844 if( empty( $pContentId ) and $this->isValid()) $pContentId = $this->mContentId ;
845 if( empty( $pArticleId ) and $this->isValid()) $pArticleId = $this->mArticleId ;
846 if( !empty( $pContentId ) and !$this->isValid()) $this->mContentId = $pContentId ;
847 if( !empty( $pArticleId ) and !$this->isValid()) $this->mArticleId = $pArticleId ;
848
cf7b0879 » xxing
2005-09-04 add some documentation
849 if( empty( $pArticleId ) && $this->isValid() ) {
850 $pArticleId = $this->mArticleId;
851 }
852
54fb5b7c » xxing
2005-12-26 merge recent changes into HEAD
853 if( @$this->verifyId( $pArticleId ) ) {
f210a14d » bitweaver.org
2006-01-31 massive table de-tikification. changed all tiki_ table prefixes with …
854 $sql = "UPDATE `".BIT_DB_PREFIX."articles` SET `status_id` = ? WHERE `article_id` = ?";
cf7b0879 » xxing
2005-09-04 add some documentation
855 $rs = $this->mDb->query( $sql, array( $pStatusId, $pArticleId ));
5330bc51 » Sean Lee
2006-02-20 Merge recent changes to HEAD
856 // Calling the index function for approved articles ...
857 if( $gBitSystem->isPackageActive( 'search' ) ) {
858 include_once( SEARCH_PKG_PATH.'refresh_functions.php' );
859 if ($pStatusId == ARTICLE_STATUS_APPROVED) {
860 refresh_index($this);
b7cc1a18 » Hash9
2006-08-29 add the factility to view the history of articles, and an auto approv…
861 } elseif (!$pStatusId == ARTICLE_STATUS_RETIRED) {
5330bc51 » Sean Lee
2006-02-20 Merge recent changes to HEAD
862 delete_index($pContentId); // delete it from the search index unless retired ...
863 }
864 }
cf7b0879 » xxing
2005-09-04 add some documentation
865 return $pStatusId;
866 }
867 }
75f897b0 » bitweaver.org
2005-06-30 IMPORT TikiPro CLYDE FINAL
868 }
869 ?>
Something went wrong with that request. Please try again.