Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 870 lines (768 sloc) 34.618 kb
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
1 <?php
2 /**
a39e645 xxing rename some methods in BitDbBase to meet bitweaver standards. all change...
xxing authored
3 * @version $Header: /cvsroot/bitweaver/_bit_articles/BitArticle.php,v 1.104 2007/01/06 09:46:09 squareing Exp $
d403bf6 Lester Caine 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 *
a39e645 xxing rename some methods in BitDbBase to meet bitweaver standards. all change...
xxing authored
12 * $Id: BitArticle.php,v 1.104 2007/01/06 09:46:09 squareing Exp $
d403bf6 Lester Caine 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>
a39e645 xxing rename some methods in BitDbBase to meet bitweaver standards. all change...
xxing authored
19 * @version $Revision: 1.104 $ $Date: 2007/01/06 09:46:09 $ $Author: squareing $
d403bf6 Lester Caine Add PHPDoc headings to package
lsces authored
20 */
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
21
22 /**
d403bf6 Lester Caine Add PHPDoc headings to package
lsces authored
23 * Required setup
24 */
04136bd xxing get article submissions working
xxing authored
25 require_once( LIBERTY_PKG_PATH.'LibertyAttachable.php' );
26 require_once( ARTICLES_PKG_PATH.'BitArticleTopic.php' );
27 require_once( ARTICLES_PKG_PATH.'BitArticleType.php' );
28 require_once( LIBERTY_PKG_PATH.'LibertyComment.php' );
c4f74ce spiderr comment out incomplete statistics feature
spiderr authored
29 // feature incomplete require_once( ARTICLES_PKG_PATH.'BitArticleStatistics.php' );
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
30
c83a84e xxing merge recent changes into HEAD
xxing authored
31 define( 'ARTICLE_SPLIT_REGEX', "/\.{3}split\.{3}[\r\n]?/i" );
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
32
d403bf6 Lester Caine Add PHPDoc headings to package
lsces authored
33 /**
34 * @package article
35 */
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
36 class BitArticle extends LibertyAttachable {
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
37 /**
7f0e5d8 xxing more work on getting articles going
xxing authored
38 * Primary key for articles
cf7b087 xxing add some documentation
xxing authored
39 * @access public
7f0e5d8 xxing more work on getting articles going
xxing authored
40 */
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
41 var $mArticleId;
42 var $mTypeId;
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
43 var $mTopicId;
cf7b087 xxing add some documentation
xxing authored
44
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
45 /**
ec0a861 xxing add some more documentation
xxing authored
46 * Initiate the articles class
cf7b087 xxing add some documentation
xxing authored
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
7f0e5d8 xxing more work on getting articles going
xxing authored
50 **/
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
51 function BitArticle( $pArticleId=NULL, $pContentId=NULL ) {
52 $this->mArticleId = $pArticleId;
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
53 $this->mTypeId = NULL;
54 $this->mTopicId = NULL;
7f0e5d8 xxing more work on getting articles going
xxing authored
55
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
56 LibertyAttachable::LibertyAttachable();
c31efa1 xxing fix admin screen and set more usable defaults in schema
xxing authored
57 $this->registerContentType( BITARTICLE_CONTENT_TYPE_GUID, array(
58 'content_description' => 'Article',
7f0e5d8 xxing more work on getting articles going
xxing authored
59 'handler_class' => 'BitArticle',
60 'handler_package' => 'articles',
61 'handler_file' => 'BitArticle.php',
62 'maintainer_url' => 'http://www.bitweaver.org'
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
63 ) );
64 $this->mContentId = $pContentId;
65 $this->mContentTypeGuid = BITARTICLE_CONTENT_TYPE_GUID;
54fb5b7 xxing merge recent changes into HEAD
xxing authored
66 if( ! @$this->verifyId( $this->mArticleId ) ) {
67 $this->mArticleId = NULL;
68 }
69 if( ! @$this->verifyId( $this->mContentId ) ) {
70 $this->mContentId = NULL;
71 }
1f9adbe xxing make "read more" links conditional, depending on whether there is more t...
xxing authored
72 }
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
73
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
74 /**
7f0e5d8 xxing more work on getting articles going
xxing authored
75 * Load the data from the database
cf7b087 xxing add some documentation
xxing authored
76 * @access public
7f0e5d8 xxing more work on getting articles going
xxing authored
77 **/
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
78 function load( $pVersion = 0 ) {
79 $pVersion = intval( $pVersion );
54fb5b7 xxing merge recent changes into HEAD
xxing authored
80 if( @$this->verifyId( $this->mArticleId ) || @$this->verifyId( $this->mContentId ) ) {
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
81 // LibertyContent::load()assumes you have joined already, and will not execute any sql!
82 // This is a significant performance optimization
54fb5b7 xxing merge recent changes into HEAD
xxing authored
83 $lookupColumn = @$this->verifyId( $this->mArticleId ) ? 'article_id' : 'content_id';
ce4e5d1 xxing use correct hash in query()
xxing authored
84 $bindVars[] = $lookupId = @BitBase::verifyId( $this->mArticleId ) ? $this->mArticleId : $this->mContentId;
3556172 xxing rename content_load_function to content_load_sql_function
xxing authored
85 $this->getServicesSql( 'content_load_sql_function', $selectSql, $joinSql, $whereSql, $bindVars );
838a838 Lester Caine Add ServicesSQL facility
lsces authored
86
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
87 $query = "SELECT a.*, ".( !empty( $pVersion ) ? "lch.`hits`, lc.`title`" : "lc.*" ).", atype.*, atopic.*,
ce4e5d1 xxing use correct hash in query()
xxing authored
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` )
b7cc1a1 add the factility to view the history of articles, and an auto approve f...
Hash9 authored
94 INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON( lc.`content_id` = a.`content_id` ) ".
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
95 ( !empty( $pVersion ) ? "LEFT JOIN `".BIT_DB_PREFIX."liberty_content_history` lch ON( lch.`content_id` = a.`content_id` )" : "" ) . "
ce4e5d1 xxing use correct hash in query()
xxing authored
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
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
100 WHERE a.`$lookupColumn`=? $whereSql ".( !empty( $pVersion ) ? " AND lch.version = ?" : "" );
101 if( !empty( $pVersion ) ) {
102 $bindVars[]=$pVersion;
103 }
ce4e5d1 xxing use correct hash in query()
xxing authored
104 $result = $this->mDb->query( $query, $bindVars );
7f0e5d8 xxing more work on getting articles going
xxing authored
105
106 global $gBitSystem;
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
107 if( $result && $result->numRows() ) {
b548033 spiderr fix ->fields calls
spiderr authored
108 $this->mInfo = $result->fetchRow();
b99c416 xxing get topic image on load()
xxing authored
109
8c5f309 xxing clean up articles custom image upload stuff
xxing authored
110 // if a custom image for the article exists, use that, then use an attachment, then use the topic image
539fa01 xxing rename img_url to image_url
xxing authored
111 $this->mInfo['image_url'] = BitArticle::getImageUrl( $this->mInfo );
b99c416 xxing get topic image on load()
xxing authored
112
b548033 spiderr fix ->fields calls
spiderr authored
113 $this->mContentId = $this->mInfo['content_id'];
114 $this->mArticleId = $this->mInfo['article_id'];
115 $this->mTopicId = $this->mInfo['topic_id'];
116 $this->mTypeId = $this->mInfo['article_type_id'];
7f0e5d8 xxing more work on getting articles going
xxing authored
117
ea85f9e xxing new API for parseData(); please view ApiChangeLog for details
xxing authored
118 $this->mInfo['creator'] = ( isset( $this->mInfo['creator_real_name'] )? $this->mInfo['creator_real_name'] : $this->mInfo['creator_user'] );
119 $this->mInfo['editor'] = ( isset( $this->mInfo['modifier_real_name'] )? $this->mInfo['modifier_real_name'] : $this->mInfo['modifier_user'] );
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
120 $this->mInfo['display_url'] = $this->getDisplayUrl();
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
121 $this->mInfo['raw'] = $this->mInfo['data'];
ea85f9e xxing new API for parseData(); please view ApiChangeLog for details
xxing authored
122 $this->mInfo['data'] = preg_replace( ARTICLE_SPLIT_REGEX, "", $this->mInfo['data'] );
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
123
fa7948e xxing concatenate whereSql
xxing authored
124 $comment = &new LibertyComment();
125 $this->mInfo['num_comments'] = $comment->getNumComments( $this->mInfo['content_id'] );
adcc311 xxing get html per article working as well and reduce load by only parsing con...
xxing authored
126
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
127 LibertyAttachable::load();
adcc311 xxing get html per article working as well and reduce load by only parsing con...
xxing authored
128
129 $this->mInfo['parsed_data'] = $this->parseData();
838a838 Lester Caine Add ServicesSQL facility
lsces authored
130 } else {
131 $this->mArticleId = NULL;
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
132 }
133 }
c58fe86 Nick Palmer Fixed bug with load of article with no hits.
nickpalmer authored
134
5e14ed2 xxing clean up author name code
xxing authored
135 return( count( $this->mInfo ) );
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
136 }
7f0e5d8 xxing more work on getting articles going
xxing authored
137
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
138 /**
ec0a861 xxing add some more documentation
xxing authored
139 * Store article data after submission
cf7b087 xxing add some documentation
xxing authored
140 * @param array pParamHash of values that will be used to store the page
7f0e5d8 xxing more work on getting articles going
xxing authored
141 * @return bool TRUE on success, FALSE if store could not occur. If FALSE, $this->mErrors will have reason why
142 * @access public
143 **/
ee831c6 xxing get custom article image working
xxing authored
144 function store( &$pParamHash ) {
145 global $gBitSystem;
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
146 if( $this->verify( $pParamHash )&& LibertyAttachable::store( $pParamHash ) ) {
f210a14 massive table de-tikification. changed all tiki_ table prefixes with teh...
bitweaver.org authored
147 $table = BIT_DB_PREFIX."articles";
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
148 $this->mDb->StartTrans();
ee831c6 xxing get custom article image working
xxing authored
149
5a59732 xxing use $this->isValid() to check for $this->mArticleId
xxing authored
150 if( $this->isValid() ) {
8d929a0 spiderr major change of BitDbBase::associateUpdate method - it now takes a simpl...
spiderr authored
151 $result = $this->mDb->associateUpdate( $table, $pParamHash['article_store'], array( "article_id" => $pParamHash['article_id'] ) );
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
152 } else {
153 $pParamHash['article_store']['content_id'] = $pParamHash['content_id'];
154 if( isset( $pParamHash['article_id'] )&& is_numeric( $pParamHash['article_id'] ) ) {
ee831c6 xxing get custom article image working
xxing authored
155 // if pParamHash['article_id'] is set, someone is requesting a particular article_id. Use with caution!
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
156 $pParamHash['article_store']['article_id'] = $pParamHash['article_id'];
157 } else {
f210a14 massive table de-tikification. changed all tiki_ table prefixes with teh...
bitweaver.org authored
158 $pParamHash['article_store']['article_id'] = $this->mDb->GenID( 'articles_article_id_seq' );
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
159 }
160 $this->mArticleId = $pParamHash['article_store']['article_id'];
161 $result = $this->mDb->associateInsert( $table, $pParamHash['article_store'] );
162 }
163
8c5f309 xxing clean up articles custom image upload stuff
xxing authored
164 // we need to store any custom image that has been uploaded
971f3d0 xxing fix image return url. this really needs to be cleaned up.
xxing authored
165 if( !empty( $_FILES['article_image']['name'] ) ) {
28cd215 spiderr check for article_image before passing in to store
spiderr authored
166 $this->storeImage( $pParamHash, $_FILES['article_image'] );
167 }
8c5f309 xxing clean up articles custom image upload stuff
xxing authored
168
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
169 $this->mDb->CompleteTrans();
170 $this->load();
171 }
6f9ed7a xxing add a link to remove a custom image
xxing authored
172 return ( count( $this->mErrors ) == 0 );
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
173 }
174
175 /**
7f0e5d8 xxing more work on getting articles going
xxing 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 xxing parsed_description only needed when loading articles front page
xxing authored
182 function verify( &$pParamHash ) {
183 global $gBitUser, $gBitSystem;
7f0e5d8 xxing more work on getting articles going
xxing authored
184
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
185 // make sure we're all loaded up of we have a mArticleId
186 if( $this->mArticleId && empty( $this->mInfo ) ) {
187 $this->load();
188 }
7f0e5d8 xxing more work on getting articles going
xxing authored
189
54fb5b7 xxing merge recent changes into HEAD
xxing authored
190 if( @$this->verifyId( $this->mInfo['content_id'] ) ) {
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
191 $pParamHash['content_id'] = $this->mInfo['content_id'];
192 }
7f0e5d8 xxing more work on getting articles going
xxing authored
193
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
194 // It is possible a derived class set this to something different
04136bd xxing get article submissions working
xxing authored
195 if( empty( $pParamHash['content_type_guid'] )&& !empty( $this->mContentTypeGuid ) ) {
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
196 $pParamHash['content_type_guid'] = $this->mContentTypeGuid;
197 }
7f0e5d8 xxing more work on getting articles going
xxing authored
198
54fb5b7 xxing merge recent changes into HEAD
xxing authored
199 if( @$this->verifyId( $pParamHash['content_id'] ) ) {
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
200 $pParamHash['article_store']['content_id'] = $pParamHash['content_id'];
201 }
7f0e5d8 xxing more work on getting articles going
xxing authored
202
04136bd xxing get article submissions working
xxing 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 xxing more work on getting articles going
xxing authored
206
daf5fbe xxing existing image attachment working as well now - w00t!
xxing authored
207 // if no image attachment id is given, we set it null. this way a user can remove an attached image
47348b5 xxing clean up image attachments for articles, allow custom size for resizes, ...
xxing authored
208 // TODO: since we allow custom image size for article images, we should create a resized image of the original here.
54fb5b7 xxing merge recent changes into HEAD
xxing authored
209 if( @$this->verifyId( $pParamHash['image_attachment_id'] ) ) {
daf5fbe xxing existing image attachment working as well now - w00t!
xxing authored
210 $pParamHash['article_store']['image_attachment_id'] = ( int )$pParamHash['image_attachment_id'];
211 } else {
212 $pParamHash['article_store']['image_attachment_id'] = NULL;
213 }
214
54fb5b7 xxing merge recent changes into HEAD
xxing authored
215 if( @$this->verifyId( $pParamHash['topic_id'] ) ) {
04136bd xxing get article submissions working
xxing authored
216 $pParamHash['article_store']['topic_id'] =( int )$pParamHash['topic_id'];
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
217 }
7f0e5d8 xxing more work on getting articles going
xxing authored
218
54fb5b7 xxing merge recent changes into HEAD
xxing authored
219 if( @$this->verifyId( $pParamHash['article_type_id'] ) ) {
04136bd xxing get article submissions working
xxing authored
220 $pParamHash['article_store']['article_type_id'] =( int )$pParamHash['article_type_id'];
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
221 }
7f0e5d8 xxing more work on getting articles going
xxing 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 xxing get article submissions working
xxing authored
228 if( !empty( $pParamHash['edit'] ) ) {
4158723 xxing fix article preview
xxing authored
229 $pParamHash['content_store']['data'] = $pParamHash['edit'];
230 }
7f0e5d8 xxing more work on getting articles going
xxing 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 xxing parsed_description only needed when loading articles front page
xxing 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 xxing get article submissions working
xxing authored
239 $pParamHash['article_store']['description'] = substr( $bodyText,0, DEFAULT_ARTICLE_DESCR_LEN ).( strlen( $bodyText )> DEFAULT_ARTICLE_DESCR_LEN ? '...' : '' );
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
240 } else {
241 $pParamHash['article_store']['description'] = $pParamHash['description'];
242 }*/
7f0e5d8 xxing more work on getting articles going
xxing authored
243
04136bd xxing get article submissions working
xxing authored
244 if( !empty( $pParamHash['rating'] ) ) {
245 $pParamHash['article_store']['rating'] =( int )( $pParamHash['rating'] );
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
246 }
7f0e5d8 xxing more work on getting articles going
xxing authored
247
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
248 // check for name issues, first truncate length if too long
249 if( !empty( $pParamHash['title'] ) ) {
5a59732 xxing use $this->isValid() to check for $this->mArticleId
xxing authored
250 if( !$this->isValid() ) {
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
251 if( empty( $pParamHash['title'] ) ) {
8e16677 change the error message name to title to reuse the term used in the for...
Sylvie Greverend authored
252 $this->mErrors['title'] = 'You must specify a title.';
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
253 } else {
f9dba4a support BIT_CONTENT_MAX_TITLE_LEN for hand tinkering databases to have l...
Wakeworks authored
254 $pParamHash['content_store']['title'] = substr( $pParamHash['title'], 0, BIT_CONTENT_MAX_TITLE_LEN );
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
255 }
256 } else {
f9dba4a support BIT_CONTENT_MAX_TITLE_LEN for hand tinkering databases to have l...
Wakeworks authored
257 $pParamHash['content_store']['title'] =( isset( $pParamHash['title'] ))? substr( $pParamHash['title'], 0, BIT_CONTENT_MAX_TITLE_LEN ): '';
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
258 }
259 } else if( empty( $pParamHash['title'] ) ) {
260 // no name specified
8e16677 change the error message name to title to reuse the term used in the for...
Sylvie Greverend authored
261 $this->mErrors['title'] = 'You must specify a title';
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
262 }
7f0e5d8 xxing more work on getting articles going
xxing authored
263
04136bd xxing get article submissions working
xxing 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 xxing get topic image on load()
xxing authored
266 //$timestamp = strtotime( $dateString );
267 $timestamp = $gBitSystem->mServerTimestamp->getUTCFromDisplayDate( strtotime( $dateString ) );
04136bd xxing get article submissions working
xxing authored
268 if( $timestamp !== -1 ) {
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
269 $pParamHash['publish_date'] = $timestamp;
270 }
271 }
5cbc7ec xxing get permissions sorted when trying to view submitted article
xxing authored
272 if( !empty( $pParamHash['publish_date'] ) ) {
273 $pParamHash['article_store']['publish_date'] = $pParamHash['publish_date'];
274 }
7f0e5d8 xxing more work on getting articles going
xxing authored
275
04136bd xxing get article submissions working
xxing 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 xxing get topic image on load()
xxing authored
278 //$timestamp = strtotime( $dateString );
279 $timestamp = $gBitSystem->mServerTimestamp->getUTCFromDisplayDate( strtotime( $dateString ) );
04136bd xxing get article submissions working
xxing authored
280 if( $timestamp !== -1 ) {
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
281 $pParamHash['expire_date'] = $timestamp;
282 }
283 }
04136bd xxing get article submissions working
xxing 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 xxing more work on getting articles going
xxing authored
287
54fb5b7 xxing merge recent changes into HEAD
xxing authored
288 if( @$this->verifyId( $pParamHash['status_id'] ) ) {
04136bd xxing get article submissions working
xxing authored
289 if( $pParamHash['status_id'] > ARTICLE_STATUS_PENDING ) {
1987daf xxing more permissions housekeeping and tidyup
xxing authored
290 if( $gBitUser->hasPermission( 'p_articles_approve_submission' ) || $gTikiuser->hasPermission( 'p_articles_auto_approve' ) ) {
04136bd xxing get article submissions working
xxing authored
291 $pParamHash['article_store']['status_id'] =( int )( $pParamHash['status_id'] );
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
292 } else {
293 $pParamHash['article_store']['status_id'] = ARTICLE_STATUS_PENDING;
294 }
295 } else {
04136bd xxing get article submissions working
xxing authored
296 $pParamHash['article_store']['status_id'] =( int )( $pParamHash['status_id'] );
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
297 }
54fb5b7 xxing merge recent changes into HEAD
xxing authored
298 } elseif( @$this->verifyId( $this->mInfo['status_id'] ) ) {
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
299 $pParamHash['article_store']['status_id'] = $this->mInfo['status_id'];
300 } else {
1987daf xxing more permissions housekeeping and tidyup
xxing authored
301 if( $gBitUser->hasPermission( 'p_articles_approve_submission' ) || $gBitUser->hasPermission( 'p_articles_auto_approve' ) ) {
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
302 $pParamHash['article_store']['status_id'] = ARTICLE_STATUS_APPROVED;
303 } else {
304 $pParamHash['article_store']['status_id'] = ARTICLE_STATUS_PENDING; // Default status
305 }
306 }
7f0e5d8 xxing more work on getting articles going
xxing authored
307
adcc311 xxing get html per article working as well and reduce load by only parsing con...
xxing authored
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 ) ) ) {
5330bc5 Merge recent changes to HEAD
Sean Lee authored
323 $this->mInfo["no_index"] = true ;
324 }
325
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
326 return( count( $this->mErrors )== 0 );
327 }
7f0e5d8 xxing more work on getting articles going
xxing authored
328
cf7b087 xxing add some documentation
xxing authored
329 /**
ec0a861 xxing add some more documentation
xxing authored
330 * Store article image
cf7b087 xxing add some documentation
xxing authored
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 {
3de046f xxing use liberty_get_function() to determine image processing function
xxing authored
344 $resizeFunc = liberty_get_function( 'resize' );
cf7b087 xxing add some documentation
xxing authored
345 $storeHash['source_file'] = $tmpImagePath;
7184912 xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
346 $storeHash['dest_path'] = STORAGE_PKG_NAME.'/'.ARTICLES_PKG_NAME.'/';
cf7b087 xxing add some documentation
xxing authored
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
7184912 xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
359 rename( $pParamHash['preview_image_path'], STORAGE_PKG_PATH.ARTICLES_PKG_NAME.'/article_'.$this->mArticleId.'.jpg' );
cf7b087 xxing add some documentation
xxing authored
360 }
361 }
362 return ( count( $this->mErrors ) == 0 );
363 }
364
365 /**
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
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 /**
ec0a861 xxing add some more documentation
xxing authored
385 * Work out the path to the image for this article
cf7b087 xxing add some documentation
xxing authored
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 ) {
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
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;
cf7b087 xxing add some documentation
xxing authored
413 }
414 }
415
416 /**
ec0a861 xxing add some more documentation
xxing authored
417 * Work out the URL to the image for this article
cf7b087 xxing add some documentation
xxing authored
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 **/
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
423 function getArticleImageStorageUrl( $pArticleId = NULL, $pBasePathOnly = FALSE, $pForceRefresh = FALSE ) {
cf7b087 xxing add some documentation
xxing authored
424 global $gBitSystem;
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
425 $url = STORAGE_PKG_URL.ARTICLES_PKG_NAME.'/';
cf7b087 xxing add some documentation
xxing authored
426 if( $pBasePathOnly ) {
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
427 return $url;
cf7b087 xxing add some documentation
xxing authored
428 }
429
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
430 if( !@BitBase::verifyId( $pArticleId ) ) {
cf7b087 xxing add some documentation
xxing authored
431 if( $this->isValid() ) {
432 $pArticleId = $this->mArticleId;
433 } else {
434 return NULL;
435 }
436 }
437
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
438 if( is_file( BitArticle::getArticleImageStoragePath( NULL, TRUE ).BitArticle::getArticleImageStorageName( $pArticleId ) ) ) {
439 return $url.BitArticle::getArticleImageStorageName( $pArticleId ).( $pForceRefresh ? "?".$gBitSystem->getUTCTime() : '' );
cf7b087 xxing add some documentation
xxing authored
440 } else {
441 return FALSE;
442 }
443 }
444
ec0a861 xxing add some more documentation
xxing authored
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 **/
7184912 xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
451 function preparePreview( $pParamHash ) {
4fea283 xxing get image upload working with preview and subsequent save
xxing authored
452 global $gBitSystem, $gBitUser;
7f0e5d8 xxing more work on getting articles going
xxing authored
453
7184912 xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
454 $data = $pParamHash;
04136bd xxing get article submissions working
xxing authored
455 $this->verify( $data );
7184912 xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
456 $data = array_merge( $pParamHash, $data['content_store'], $data['article_store'] );
c24c28c xxing fix articles preview
xxing authored
457 $data['raw'] = $data['edit'];
4fea283 xxing get image upload working with preview and subsequent save
xxing authored
458
04136bd xxing get article submissions working
xxing authored
459 if( empty( $data['user_id'] ) ) {
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
460 $data['user_id'] = $gBitUser->mUserId;
461 }
4fea283 xxing get image upload working with preview and subsequent save
xxing authored
462
04136bd xxing get article submissions working
xxing authored
463 if( empty( $data['hits'] ) ) {
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
464 $data['hits'] = 0;
465 }
4fea283 xxing get image upload working with preview and subsequent save
xxing authored
466
04136bd xxing get article submissions working
xxing authored
467 if( empty( $data['publish_date'] ) ) {
4fea283 xxing get image upload working with preview and subsequent save
xxing authored
468 $data['publish_date'] = $gBitSystem->getUTCTime();
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
469 }
4fea283 xxing get image upload working with preview and subsequent save
xxing authored
470
04136bd xxing get article submissions working
xxing authored
471 if( empty( $data['article_type_id'] ) ) {
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
472 $data['article_type_id'] = 1;
473 }
4fea283 xxing get image upload working with preview and subsequent save
xxing authored
474
04136bd xxing get article submissions working
xxing authored
475 if( empty( $data['topic_id'] ) ) {
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
476 $data['topic_id'] = 1;
477 }
4fea283 xxing get image upload working with preview and subsequent save
xxing authored
478
04136bd xxing get article submissions working
xxing authored
479 if( empty( $data['parsed_data'] ) ) {
ca235b0 xxing allow caching to various files by allowing specification of cache file e...
xxing authored
480 $data['no_cache'] = TRUE;
ea85f9e xxing new API for parseData(); please view ApiChangeLog for details
xxing authored
481 $data['parsed_data'] = $this->parseData( $data );
ca235b0 xxing allow caching to various files by allowing specification of cache file e...
xxing authored
482 // replace the split syntax with a horizontal rule
483 $data['parsed_data'] = preg_replace( ARTICLE_SPLIT_REGEX, "<hr />", $data['parsed_data'] );
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
484 }
7f0e5d8 xxing more work on getting articles going
xxing authored
485
54fb5b7 xxing merge recent changes into HEAD
xxing authored
486 if( @$this->verifyId( $data['image_attachment_id'] ) ) {
daf5fbe xxing existing image attachment working as well now - w00t!
xxing authored
487 $data['image_attachment_id'] = ( int )$data['image_attachment_id'];
fbe5d52 xxing detikify liberty
xxing authored
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 )
f210a14 massive table de-tikification. changed all tiki_ table prefixes with teh...
bitweaver.org authored
491 WHERE a.attachment_id=?";
daf5fbe xxing existing image attachment working as well now - w00t!
xxing authored
492 $data['image_storage_path'] = $this->mDb->getOne( $query, array( $data['image_attachment_id'] ) );
539fa01 xxing rename img_url to image_url
xxing authored
493 $data['image_url'] = BitArticle::getImageUrl( $data );
4fea283 xxing get image upload working with preview and subsequent save
xxing authored
494 }
495
7184912 xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
496 if( !empty( $_FILES['article_image']['name'] ) ) {
daf5fbe xxing existing image attachment working as well now - w00t!
xxing authored
497 // store the image in temp/articles/
7184912 xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
498 $tmpImagePath = TEMP_PKG_PATH.ARTICLES_PKG_NAME.'/'.'temp_'.$_FILES['article_image']['name'];
daf5fbe xxing existing image attachment working as well now - w00t!
xxing authored
499 $tmpImageName = preg_replace( "/(.*)\..*?$/", "$1", $_FILES['article_image']['name'] );
7184912 xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
500 if( !is_dir( TEMP_PKG_PATH.ARTICLES_PKG_NAME ) ) {
501 mkdir( TEMP_PKG_PATH.ARTICLES_PKG_NAME );
daf5fbe xxing existing image attachment working as well now - w00t!
xxing authored
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 {
3de046f xxing use liberty_get_function() to determine image processing function
xxing authored
507 $resizeFunc = liberty_get_function( 'resize' );
daf5fbe xxing existing image attachment working as well now - w00t!
xxing authored
508 $pFileHash['source_file'] = $tmpImagePath;
3397a67 xxing fix undefined constant - we need to fix the url / path mix in here (this...
xxing authored
509 $pFileHash['dest_path'] = preg_replace( '!/+!', '', str_replace( BIT_ROOT_PATH, '', TEMP_PKG_PATH ) ).'/'.ARTICLES_PKG_NAME.'/';
daf5fbe xxing existing image attachment working as well now - w00t!
xxing authored
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 );
7184912 xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
520 $data['image_url'] = $data['preview_image_url'] = TEMP_PKG_URL.ARTICLES_PKG_NAME.'/'.$tmpImageName.'.jpg';
3397a67 xxing fix undefined constant - we need to fix the url / path mix in here (this...
xxing authored
521 $data['show_image'] = TRUE;
7184912 xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
522 $data['preview_image_path'] = TEMP_PKG_PATH.ARTICLES_PKG_NAME.'/'.$tmpImageName.'.jpg';
4fea283 xxing get image upload working with preview and subsequent save
xxing authored
523 }
7184912 xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
524 } elseif( !empty( $data['preview_image_path'] ) && is_file( $data['preview_image_path'] ) ) {
525 $data['image_url'] = $data['preview_image_url'];
4fea283 xxing get image upload working with preview and subsequent save
xxing authored
526 }
527
04136bd xxing get article submissions working
xxing authored
528 $articleType = &new BitArticleType( $data['article_type_id'] );
529 $articleTopic = &new BitArticleTopic( $data['topic_id'] );
530 $data = array_merge( $data, $articleType->mInfo, $articleTopic->mInfo );
7f0e5d8 xxing more work on getting articles going
xxing authored
531
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
532 return $data;
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
533 }
7f0e5d8 xxing more work on getting articles going
xxing authored
534
ec0a861 xxing add some more documentation
xxing authored
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 **/
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
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 **/
daf5fbe xxing existing image attachment working as well now - w00t!
xxing authored
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
54fb5b7 xxing merge recent changes into HEAD
xxing authored
558 if( @$this->verifyId( $pParamHash['article_id'] ) && BitArticle::getArticleImageStorageUrl( $pParamHash['article_id'] ) ) {
daf5fbe xxing existing image attachment working as well now - w00t!
xxing authored
559 $ret = BitArticle::getArticleImageStorageUrl( $pParamHash['article_id'] );
54fb5b7 xxing merge recent changes into HEAD
xxing authored
560 } elseif( @$this->verifyId( $pParamHash['image_attachment_id'] ) && $pParamHash['image_attachment_id'] ) {
47348b5 xxing clean up image attachments for articles, allow custom size for resizes, ...
xxing authored
561 // TODO: clean up the small url stuff. shouldn't be hardcoded.
315f770 xxing first check if attached image is available
xxing authored
562 // perhaps we should make a copy of the image file and reduce it to article size settings.
7184912 xxing use constants instead of hardcoded package names and ensure that image s...
xxing authored
563 // this will be necessary as soon as we allow custom image sizes for article image
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
564 //$image = preg_replace( "/(.*)\/.*?$/", "$1/small.jpg", $pParamHash['image_storage_path'] );
565 $image = basename( $pParamHash['image_storage_path'] )."/small.jpg";
315f770 xxing first check if attached image is available
xxing authored
566 if( is_file( BIT_ROOT_PATH.$image ) ) {
567 $ret = BIT_ROOT_URL.$image;
568 }
daf5fbe xxing existing image attachment working as well now - w00t!
xxing authored
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
ec0a861 xxing add some more documentation
xxing authored
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 **/
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
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.' );
6f9ed7a xxing add a link to remove a custom image
xxing authored
585 }
586
5a59732 xxing use $this->isValid() to check for $this->mArticleId
xxing authored
587 if( empty( $pArticleId ) && $this->isValid() ) {
588 $pArticleId = $this->mArticleId;
589 }
590
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
591 if( is_file( $image = BitArticle::getArticleImageStoragePath( $pArticleId ) ) ) {
6f9ed7a xxing add a link to remove a custom image
xxing authored
592 if( !@unlink( $image ) ) {
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
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.' );
6f9ed7a xxing add a link to remove a custom image
xxing authored
594 }
595 }
596 return ( count( $this->mErrors ) == 0 );
597 }
598
ec0a861 xxing add some more documentation
xxing authored
599 /**
600 * Removes currently loaded article
601 * @return bool TRUE on success, FALSE on failure
602 * @access public
603 **/
4fea283 xxing get image upload working with preview and subsequent save
xxing authored
604 function expunge() {
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
605 $ret = FALSE;
606 if( $this->isValid() ) {
8c5f309 xxing clean up articles custom image upload stuff
xxing authored
607 $this->mDb->StartTrans();
f210a14 massive table de-tikification. changed all tiki_ table prefixes with teh...
bitweaver.org authored
608 $query = "DELETE FROM `".BIT_DB_PREFIX."articles` WHERE `content_id` = ?";
8c5f309 xxing clean up articles custom image upload stuff
xxing authored
609 $result = $this->mDb->query( $query, array( $this->mContentId ) );
5a59732 xxing use $this->isValid() to check for $this->mArticleId
xxing authored
610 // remove article image if it exists
611 $this->expungeImage();
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
612 if( LibertyAttachable::expunge() ) {
613 $ret = TRUE;
614 $this->mDb->CompleteTrans();
615 } else {
616 $this->mDb->RollbackTrans();
8c5f309 xxing clean up articles custom image upload stuff
xxing authored
617 }
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
618 }
619 return $ret;
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
620 }
7f0e5d8 xxing more work on getting articles going
xxing authored
621
ec0a861 xxing add some more documentation
xxing authored
622 /**
623 * Check if there is an article loaded
624 * @return bool TRUE on success, FALSE on failure
625 * @access public
626 **/
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
627 function isValid() {
54fb5b7 xxing merge recent changes into HEAD
xxing authored
628 return( $this->verifyId( $this->mArticleId ) && $this->verifyId( $this->mContentId ) );
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
629 }
7f0e5d8 xxing more work on getting articles going
xxing authored
630
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
631 /**
fbe5d52 xxing detikify liberty
xxing authored
632 * This function generates a list of records from the liberty_content database for use in a list page
ec0a861 xxing add some more documentation
xxing authored
633 * @param $pParamHash contains an array of conditions to sort by
d403bf6 Lester Caine Add PHPDoc headings to package
lsces authored
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
ec0a861 xxing add some more documentation
xxing authored
637 * @access public
7f0e5d8 xxing more work on getting articles going
xxing authored
638 **/
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
639 function getList( &$pParamHash ) {
b7cc1a1 add the factility to view the history of articles, and an auto approve f...
Hash9 authored
640 global $gBitSystem, $gBitUser, $gLibertySystem;
641
c4f74ce spiderr comment out incomplete statistics feature
spiderr authored
642 /*
643 feature incomplete
b7cc1a1 add the factility to view the history of articles, and an auto approve f...
Hash9 authored
644 if ($gBitSystem->isFeatureActive('articles_auto_approve') && empty($pParamHash['no_update'])) {
645 BitArticleStatistics::autoApprove();
646 }
c4f74ce spiderr comment out incomplete statistics feature
spiderr authored
647 */
7f0e5d8 xxing more work on getting articles going
xxing authored
648
fe614d1 xxing apply default sort_mode before LibertyContent::prepGetList();
xxing authored
649 if( empty( $pParamHash['sort_mode'] ) ) {
d3426e6 spiderr fix majorly busted ORDER BY changes
spiderr authored
650 $pParamHash['sort_mode'] = $gBitSystem->isFeatureActive('articles_auto_approve') ? 'order_key_desc' : 'publish_date_desc';
fe614d1 xxing apply default sort_mode before LibertyContent::prepGetList();
xxing authored
651 }
652
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
653 LibertyContent::prepGetList( $pParamHash );
654
838a838 Lester Caine Add ServicesSQL facility
lsces authored
655 $joinSql = '';
656 $selectSql = '';
657 $bindVars = array();
658 array_push( $bindVars, $this->mContentTypeGuid );
3556172 xxing rename content_load_function to content_load_sql_function
xxing authored
659 $this->getServicesSql( 'content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars );
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
660
838a838 Lester Caine Add ServicesSQL facility
lsces authored
661 $find = $pParamHash['find'];
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
662 if( is_array( $find ) ) {
c6e286d xxing add more options to limit getList() by
xxing authored
663 // you can use an array of articles
fa7948e xxing concatenate whereSql
xxing authored
664 $whereSql .= " AND lc.`title` IN( ".implode( ',',array_fill( 0, count( $find ),'?' ) )." )";
962a29a Lester Caine Tidy array merges
lsces authored
665 $bindVars = array_merge( $bindVars, $find );
d568668 xxing fix user_id where clause
xxing authored
666 } elseif( is_string( $find ) ) {
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
667 // or a string
fa7948e xxing concatenate whereSql
xxing authored
668 $whereSql .= " AND UPPER( lc.`title` ) LIKE ? ";
962a29a Lester Caine Tidy array merges
lsces authored
669 $bindVars[] = '%'.strtoupper( $find ).'%';
54fb5b7 xxing merge recent changes into HEAD
xxing authored
670 } elseif( @$this->verifyId( $pParamHash['user_id'] ) ) {
d568668 xxing fix user_id where clause
xxing authored
671 // or gate on a user
fa7948e xxing concatenate whereSql
xxing authored
672 $whereSql .= " AND lc.`creator_user_id` = ? ";
838a838 Lester Caine Add ServicesSQL facility
lsces authored
673 $bindVars[] = array( $pParamHash['user_id'] );
d6cf45c xxing add option to select by topic name
xxing authored
674 }
675
54fb5b7 xxing merge recent changes into HEAD
xxing authored
676 if( @$this->verifyId( $pParamHash['status_id'] ) ) {
838a838 Lester Caine Add ServicesSQL facility
lsces authored
677 $whereSql .= " AND a.`status_id` = ? ";
678 $bindVars[] = $pParamHash['status_id'];
c6e286d xxing add more options to limit getList() by
xxing authored
679 }
680
54fb5b7 xxing merge recent changes into HEAD
xxing authored
681 if( @$this->verifyId( $pParamHash['type_id'] ) ) {
838a838 Lester Caine Add ServicesSQL facility
lsces authored
682 $whereSql .= " AND a.`article_type_id` = ? ";
683 $bindVars[] = ( int )$pParamHash['type_id'];
c6e286d xxing add more options to limit getList() by
xxing authored
684 }
685
9090a1d spiderr remove old spell checking
spiderr authored
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
0b9692b xxing merge recent changes into HEAD
xxing authored
695 if( @$this->verifyId( $pParamHash['topic_id'] ) ) {
838a838 Lester Caine Add ServicesSQL facility
lsces authored
696 $whereSql .= " AND a.`topic_id` = ? ";
697 $bindVars[] = ( int )$pParamHash['topic_id'];
0b9692b xxing merge recent changes into HEAD
xxing authored
698 } elseif( !empty( $pParamHash['topic'] ) ) {
ea85f9e xxing new API for parseData(); please view ApiChangeLog for details
xxing authored
699 $whereSql .= " AND UPPER( atopic.`topic_name` ) = ? ";
838a838 Lester Caine Add ServicesSQL facility
lsces authored
700 $bindVars[] = strtoupper( $pParamHash['topic'] );
0b9692b xxing merge recent changes into HEAD
xxing authored
701 } else {
44c943d Lester Caine Fix reserved word field names
lsces authored
702 $whereSql .= " AND ( atopic.`active_topic` != 'n' OR atopic.`active_topic` IS NULL ) ";
703 //$whereSql .= " AND atopic.`active_topic` != 'n' ";
0b9692b xxing merge recent changes into HEAD
xxing authored
704 }
705
c4f74ce spiderr comment out incomplete statistics feature
spiderr authored
706 /*
707 feature incomplete
b7cc1a1 add the factility to view the history of articles, and an auto approve f...
Hash9 authored
708 if ($gBitSystem->isFeatureActive('articles_auto_approve')) {
709 $as = new BitArticleStatistics();
971f3d0 xxing fix image return url. this really needs to be cleaned up.
xxing authored
710 $obj = null;
711 if (isset($this)) {
712 $obj = $this;
713 }
714 $selectSql .= $as->getSQLRank($obj);
715 }
c4f74ce spiderr comment out incomplete statistics feature
spiderr authored
716 */
b7cc1a1 add the factility to view the history of articles, and an auto approve f...
Hash9 authored
717
42b7561 explicit column names to get around oracle pain ORA-00918
bitweaver.org authored
718 // Oracle is very particular about naming multiple columns, so need to explicity name them ORA-00918: column ambiguously defined
299e478 xxing add missing lch.`hits`
xxing authored
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
f210a14 massive table de-tikification. changed all tiki_ table prefixes with teh...
bitweaver.org authored
726 FROM `".BIT_DB_PREFIX."articles` a
b7cc1a1 add the factility to view the history of articles, and an auto approve f...
Hash9 authored
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
fa7948e xxing concatenate whereSql
xxing authored
734 WHERE lc.`content_type_guid` = ? $whereSql
a39e645 xxing rename some methods in BitDbBase to meet bitweaver standards. all change...
xxing authored
735 ORDER BY ".$this->mDb->convertSortmode( $pParamHash['sort_mode'] );
04136bd xxing get article submissions working
xxing authored
736
f210a14 massive table de-tikification. changed all tiki_ table prefixes with teh...
bitweaver.org authored
737 $query_cant = "SELECT COUNT( * )FROM `".BIT_DB_PREFIX."articles` a
ea85f9e xxing new API for parseData(); please view ApiChangeLog for details
xxing authored
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
838a838 Lester Caine Add ServicesSQL facility
lsces authored
740 WHERE lc.`content_type_guid` = ? $whereSql";
80fa1d9 spiderr Added uspport for multiple database backend support. This necessitates r...
spiderr authored
741
838a838 Lester Caine Add ServicesSQL facility
lsces authored
742 $result = $this->mDb->query( $query, $bindVars, $pParamHash['max_records'], $pParamHash['offset'] );
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
743 $ret = array();
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
744 $comment = &new LibertyComment();
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
745 while( $res = $result->fetchRow() ) {
539fa01 xxing rename img_url to image_url
xxing authored
746 $res['image_url'] = BitArticle::getImageUrl( $res );
7f0e5d8 xxing more work on getting articles going
xxing authored
747
ea85f9e xxing new API for parseData(); please view ApiChangeLog for details
xxing authored
748 // deal with the parsing
ca235b0 xxing allow caching to various files by allowing specification of cache file e...
xxing authored
749 $parseHash['format_guid'] = $res['format_guid'];
750 $parseHash['content_id'] = $res['content_id'];
751 $parseHash['cache_extension'] = 'desc';
7f0e5d8 xxing more work on getting articles going
xxing authored
752 if( preg_match( ARTICLE_SPLIT_REGEX, $res['data'] ) ) {
753 $parts = preg_split( ARTICLE_SPLIT_REGEX, $res['data'] );
e888941 xxing make sure read_more stuff isn't applied when ...split... is added to the...
xxing authored
754 if( empty( $parts[1] ) ) {
755 $res['has_more'] = FALSE;
756 }
ea85f9e xxing new API for parseData(); please view ApiChangeLog for details
xxing authored
757 $parseHash['data'] = $parts[0];
adcc311 xxing get html per article working as well and reduce load by only parsing con...
xxing authored
758 } else {
0d9032d xxing change article config setting names to <pkg>_setting
xxing authored
759 $parseHash['data'] = substr( $res['data'], 0, $gBitSystem->getConfig( 'articles_description_length' ) );
7f0e5d8 xxing more work on getting articles going
xxing authored
760 }
8bf536e remove maketoc from articles preview
bitweaver.org authored
761 // description shouldn't containg {maketoc}
762 $parseHash['data'] = preg_replace( "/\{maketoc[^\}]*\}/i", "", $parseHash['data'] );
ea85f9e xxing new API for parseData(); please view ApiChangeLog for details
xxing authored
763 $res['parsed_description'] = $this->parseData( $parseHash );
7f0e5d8 xxing more work on getting articles going
xxing authored
764
ea85f9e xxing new API for parseData(); please view ApiChangeLog for details
xxing authored
765 // this is needed to remove trailing stuff from the parser and insert a link to the actual article
086d0bc xxing merge recent changes into HEAD
xxing authored
766 $trailing_junk_pattern = "/(<br[^>]*>)*$/i";
adcc311 xxing get html per article working as well and reduce load by only parsing con...
xxing authored
767 if( $res['data'] != $parseHash['data'] ) {
086d0bc xxing merge recent changes into HEAD
xxing authored
768 $res['parsed_description'] = preg_replace( $trailing_junk_pattern, "", $res['parsed_description'] );
e888941 xxing make sure read_more stuff isn't applied when ...split... is added to the...
xxing authored
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 }
086d0bc xxing merge recent changes into HEAD
xxing authored
773 } else {
774 $res['parsed_description'] = preg_replace( $trailing_junk_pattern, "", $res['parsed_description'] );
775 }
776
7f0e5d8 xxing more work on getting articles going
xxing authored
777 $res['num_comments'] = $comment->getNumComments( $res['content_id'] );
6130c1d xxing fix various article submission related issues
xxing authored
778 $res['display_url'] = $this->getDisplayUrl( $res['article_id'] );
779 $res['display_link'] = $this->getDisplayLink( $res['title'], $res );
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
780 $ret[] = $res;
781 }
7f0e5d8 xxing more work on getting articles going
xxing authored
782
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
783 $pParamHash["data"] = $ret;
838a838 Lester Caine Add ServicesSQL facility
lsces authored
784 $pParamHash["cant"] = $this->mDb->getOne( $query_cant, $bindVars );
7f0e5d8 xxing more work on getting articles going
xxing authored
785
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
786 LibertyContent::postGetList( $pParamHash );
7f0e5d8 xxing more work on getting articles going
xxing authored
787
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
788 return $pParamHash;
789 }
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
790
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
791 /**
cf7b087 xxing add some documentation
xxing authored
792 * Generates the URL to the article
793 * @return the link to the full article
7f0e5d8 xxing more work on getting articles going
xxing authored
794 */
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
795 function getDisplayUrl( $pArticleId = NULL) {
54fb5b7 xxing merge recent changes into HEAD
xxing authored
796 global $gBitSystem;
797
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
798 $ret = NULL;
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
799 if( !@BitBase::verifyId( $pArticleId ) && $this->isValid() ) {
800 $pArticleId = $this->mArticleId;
54fb5b7 xxing merge recent changes into HEAD
xxing authored
801 }
802
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
803 if( @$this->verifyId( $pArticleId ) ) {
475f224 xxing another batch of kernel_prefs name cleanup. this should be it
xxing authored
804 if( $gBitSystem->isFeatureActive( 'pretty_urls_extended' ) ) {
54fb5b7 xxing merge recent changes into HEAD
xxing authored
805 // Not needed since it's a number: $ret = ARTICLES_PKG_URL."view/".$this->mArticleId;
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
806 $ret = ARTICLES_PKG_URL.$pArticleId;
54fb5b7 xxing merge recent changes into HEAD
xxing authored
807 } else if( $gBitSystem->isFeatureActive( 'pretty_urls' ) ) {
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
808 $ret = ARTICLES_PKG_URL.$pArticleId;
54fb5b7 xxing merge recent changes into HEAD
xxing authored
809 } else {
122e288 xxing finally seperated URL from PATH stuff for article and topic images
xxing authored
810 $ret = ARTICLES_PKG_URL."read.php?article_id=$pArticleId";
54fb5b7 xxing merge recent changes into HEAD
xxing authored
811 }
47d932a xxing parsed_description only needed when loading articles front page
xxing authored
812 }
813 return $ret;
814 }
cf7b087 xxing add some documentation
xxing authored
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;
f210a14 massive table de-tikification. changed all tiki_ table prefixes with teh...
bitweaver.org authored
823 $query = "SELECT * FROM `".BIT_DB_PREFIX."article_status`";
cf7b087 xxing add some documentation
xxing authored
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 **/
5330bc5 Merge recent changes to HEAD
Sean Lee authored
835 function setStatus( $pStatusId, $pArticleId = NULL, $pContentId = NULL ) {
9090a1d spiderr remove old spell checking
spiderr authored
836 global $gBitSystem;
cf7b087 xxing add some documentation
xxing authored
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
5330bc5 Merge recent changes to HEAD
Sean Lee authored
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
cf7b087 xxing add some documentation
xxing authored
849 if( empty( $pArticleId ) && $this->isValid() ) {
850 $pArticleId = $this->mArticleId;
851 }
852
54fb5b7 xxing merge recent changes into HEAD
xxing authored
853 if( @$this->verifyId( $pArticleId ) ) {
f210a14 massive table de-tikification. changed all tiki_ table prefixes with teh...
bitweaver.org authored
854 $sql = "UPDATE `".BIT_DB_PREFIX."articles` SET `status_id` = ? WHERE `article_id` = ?";
cf7b087 xxing add some documentation
xxing authored
855 $rs = $this->mDb->query( $sql, array( $pStatusId, $pArticleId ));
5330bc5 Merge recent changes to HEAD
Sean Lee authored
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);
b7cc1a1 add the factility to view the history of articles, and an auto approve f...
Hash9 authored
861 } elseif (!$pStatusId == ARTICLE_STATUS_RETIRED) {
5330bc5 Merge recent changes to HEAD
Sean Lee authored
862 delete_index($pContentId); // delete it from the search index unless retired ...
863 }
864 }
cf7b087 xxing add some documentation
xxing authored
865 return $pStatusId;
866 }
867 }
75f897b IMPORT TikiPro CLYDE FINAL
bitweaver.org authored
868 }
869 ?>
Something went wrong with that request. Please try again.