summaryrefslogtreecommitdiff
path: root/edit.php
blob: 3329724e60b58c84af6a86acb31dfc3716124263 (plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
// $Header: /cvsroot/bitweaver/_bit_articles/edit.php,v 1.6 2005/08/22 20:48:49 squareing Exp $
// Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.

// Initialization
require_once( '../bit_setup_inc.php' );
require_once( ARTICLES_PKG_PATH . 'BitArticle.php' );

// get plugin help
include_once( LIBERTY_PKG_PATH.'edit_help_inc.php' );

// Is package installed and enabled
$gBitSystem->verifyPackage( 'articles' );

// Now check permissions to access this page
//$gBitSystem->verifyPermission( 'bit_p_edit_article' );


include_once('lookup_article_inc.php');

if ($gBitUser->hasPermission('bit_p_admin_articles') || $gBitUser->hasPermission('bit_p_edit_article') ) {
	$viewerCanEdit = TRUE;
} elseif (!empty($gContent->mInfo['user_id']) && $gContent->mInfo['user_id'] == $gBitUser->mUserId) {
	$viewerCanEdit = TRUE;
} elseif (!$gContent->mArticleId && $gBitUser->hasPermission('bit_p_submit_article')) {
	$viewerCanEdit = TRUE;
}


// Now check permissions to access this page
if ( !$viewerCanEdit ) { //!$gBitSystem->verifyPermission( 'bit_p_edit_article' ) && ( $article_data["author_name"] != $gBitUser->mUserId || $article_data["creator_edit"] != 'y' ) ) {
	$smarty->assign( 'msg', tra( "Permission denied you cannot edit this article" ) );
	$gBitSystem->display( "error.tpl" );
	die;
}

if ($gBitSystem->isPackageActive( 'categories' )) {
	$cat_type = BITARTICLE_CONTENT_TYPE_GUID;
	$cat_objid = $gContent->mContentId;
	include_once( CATEGORIES_PKG_PATH . 'categorize_list_inc.php' );
}

if ($gBitSystem->isPackageActive( 'quicktags' )) {
	include_once( QUICKTAGS_PKG_PATH . 'quicktags_inc.php' );
}


// If we are in preview mode then preview it!
if (isset($_REQUEST["preview"])) {
	$article = $gContent->preparePreview($_REQUEST);
	$smarty->assign('preview', 'y');
	$smarty->assign_by_ref('article', $article);
	$gContent->invokeServices( 'content_preview_function' );
} else {
	$gContent->invokeServices( 'content_edit_function' );
	$smarty->assign_by_ref('article', $gContent->mInfo);
}

if ( !$gBitUser->hasPermission( 'bit_p_use_HTML' )) {
	$_REQUEST["allowhtml"] = 'off';
}

if ( isset( $_REQUEST["template_id"] ) && $_REQUEST["template_id"] > 0 ) {
	$template_data = $tikilib->get_template( $_REQUEST["template_id"] );

	$_REQUEST["preview"] = 1;
	$_REQUEST["body"] = $template_data["content"].$_REQUEST["data"];
}

$publish_date = date( "U" );
$cur_time = getdate();
$expire_date = mktime ( $cur_time["hours"], $cur_time["minutes"], 0, $cur_time["mon"], $cur_time["mday"] + 365, $cur_time["year"] );

$smarty->assign('author_name', $gBitUser->getDisplayName());

if ( isset( $_REQUEST["allowhtml"] ) ) {
	if ( $_REQUEST["allowhtml"] == "on" ) {
		$smarty->assign( 'allowhtml', 'y' );
	}
}

if ( isset( $_REQUEST["save"] ) ) {
	

	if ( isset( $_REQUEST["use_image"] ) && $_REQUEST["use_image"] == 'on' ) {
		$use_image = 'y';
	} else {
		$use_image = 'n';
	}

	if ( isset( $_REQUEST["isfloat"] ) && $_REQUEST["isfloat"] == 'on' ) {
		$isfloat = 'y';
	} else {
		$isfloat = 'n';
	}

	if ( !isset( $_REQUEST["rating"] ) )
		$_REQUEST['rating'] = 0;
	if ( !isset( $_REQUEST['topic_id'] ) || $_REQUEST['topic_id'] == '' ) $_REQUEST['topic_id'] = 0;
	
	
	if ($gContent->store($_REQUEST)) {
		if ( $gBitSystem->isPackageActive('categories') ) {
			$cat_desc = $gLibertySystem->mContentTypes[BITARTICLE_CONTENT_TYPE_GUID]['content_description'].' by '.$gBitUser->getDisplayName( FALSE, array( 'real_name' => $gContent->mInfo['creator_real_name'], 'user' => $gContent->mInfo['creator_user'], 'user_id'=>$gContent->mInfo['user_id'] ) );
			$cat_name = $gContent->getTitle();
			$cat_href = $gContent->getDisplayUrl();
			$cat_objid = $gContent->mContentId;
			$cat_content_id = $gContent->mContentId;
			$cat_obj_type = BITARTICLE_CONTENT_TYPE_GUID;
			include_once( CATEGORIES_PKG_PATH.'categorize_inc.php' );
		}
		header ( "location: " . ARTICLES_PKG_URL. "index.php" );
	}
   
	/*$cat_type = 'article';
	$cat_objid = $artid;
	$cat_desc = substr( $_REQUEST["heading"], 0, 200 );
	$cat_name = $_REQUEST["title"];
	$cat_href = ARTICLES_PKG_URL . "read_article.php?article_id=" . $cat_objid;*/

	
}

// Get a topic list
$topics = BitArticleTopic::listTopics();
$smarty->assign_by_ref( 'topics', $topics );
// get list of valid types
$types = BitArticleType::listTypes();
$smarty->assign_by_ref( 'types', $types );

/*if ( $feature_cms_templates == 'y' && $bit_p_use_content_templates == 'y' ) {
	$templates = $tikilib->list_templates( 'cms', 0, -1, 'name_asc', '' );
}*/

// WYSIWYG and Quicktag variable
$smarty->assign( 'textarea_id', 'editarticle' );

$smarty->assign_by_ref( 'templates', $templates["data"] );

// Display the Index Template
$smarty->assign( 'show_page_bar', 'n' );
$gBitSystem->display( 'bitpackage:articles/edit_article.tpl', tra("articles") );

?>