forked from bitweaver/articles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.php
92 lines (80 loc) · 3.62 KB
/
edit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* @version $Header$
* @package articles
* @subpackage functions
*/
// Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
// All Rights Reserved. See below for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details.
/**
* Initialization
*/
require_once '../kernel/setup_inc.php';
require_once( ARTICLES_PKG_PATH . 'BitArticle.php' );
// Is package installed and enabled
$gBitSystem->verifyPackage( 'articles' );
include_once 'lookup_article_inc.php';
if ( $gContent->isValid() ) {
$gContent->verifyUpdatePermission();
} else {
$gContent->verifyCreatePermission();
}
// if we want to remove a custom image, just nuke all custom image settings at once
if( !empty( $_REQUEST['remove_image'] ) ) {
$_REQUEST['image_attachment_id'] = NULL;
$gContent->expungeImage( $gContent->mArticleId, !empty( $_REQUEST['preview_image_path'] ) ? $_REQUEST['preview_image_path'] : NULL );
// set the preview mode to maintain all settings
$_REQUEST['preview'] = 1;
}
if( isset( $_REQUEST["save"] ) ) {
// random image code
if( !( $gContent->hasUserPermission( 'p_articles_approve_submission' ) || $gContent->hasUserPermission( 'p_articles_auto_approve' ) ) && $gBitSystem->isFeatureActive( 'articles_submissions_rnd_img' ) && !$gBitUser->verifyCaptcha( $_REQUEST['captcha'] ) ) {
$feedback['error'] = tra( "You need to supply the correct code to submit." );
$_REQUEST['preview'] = TRUE;
unset( $_REQUEST['save'] );
}
}
// If we are in preview mode then preview it!
if( !empty( $_REQUEST['preview'] ) ) {
$article = $gContent->preparePreview( $_REQUEST );
$gBitSmarty->assign( 'preview', TRUE );
$gContent->invokeServices( 'content_preview_function', $_REQUEST );
$gBitSmarty->assign_by_ref( 'article', $article );
} else {
$gContent->invokeServices( 'content_edit_function' );
if( empty( $gContent->mInfo['author_name'] ) ) {
$gContent->mInfo['author_name'] = $gBitUser->getDisplayName();
}
$gBitSmarty->assign_by_ref('article', $gContent->mInfo);
}
// If the article was saved, show feedback or show result
if( !empty( $_REQUEST['save'] ) ) {
if( empty( $_REQUEST['rating'] ) ) $_REQUEST['rating'] = 0;
if( empty( $_REQUEST['topic_id'] ) ) $_REQUEST['topic_id'] = 0;
if( $gContent->store( $_REQUEST ) ) {
if( isset ($gContent->mInfo['status_id']) and $gContent->mInfo['status_id'] == ARTICLE_STATUS_PENDING ) {
bit_redirect( ARTICLES_PKG_URL. "index.php?feedback=".urlencode( tra( 'Your article has been submitted and is awaiting approval.' ) ) );
} else {
bit_redirect( ARTICLES_PKG_URL . ( ($gBitSystem->isFeatureActive('pretty_urls_extended') || $gBitSystem->isFeatureActive('pretty_urls')) ? $gContent->mArticleId : "read.php?article_id=" . $gContent->mArticleId ) );
}
}
}
// Get a topic list
$topics = BitArticleTopic::getTopicList( array( 'active_topic' => TRUE ) );
$gBitSmarty->assign_by_ref( 'topics', $topics );
if ( !empty( $_REQUEST['topic'] ) ) {
$gBitSmarty->assign( 'topic', $_REQUEST['topic'] );
}
// get list of valid types
$types = BitArticleType::getTypeList();
$gBitSmarty->assign_by_ref( 'types', $types );
if ( !empty( $gContent->mErrors ) || !empty( $feedback ) ) {
$article = $gContent->preparePreview( $_REQUEST );
$gBitSmarty->assign_by_ref( 'article', $article );
}
$gBitSmarty->assign_by_ref( 'errors', $gContent->mErrors );
$gBitSmarty->assign( 'feedback', ( !empty( $feedback ) ? $feedback : NULL ) );
// Display the Index Template
$gBitSmarty->assign( 'show_page_bar', 'n' );
$gBitSystem->display( 'bitpackage:articles/edit_article.tpl', tra( "Articles" ) , array( 'display_mode' => 'edit' ));