[Comoblog-commit] comoblog/admin post_add.php,1.5,1.6 post_edit.php,1.7,1.8
Status: Inactive
Brought to you by:
markwallis
|
From: iamdecal <iam...@us...> - 2005-12-07 21:05:10
|
Update of /cvsroot/comoblog/comoblog/admin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6387/admin Modified Files: post_add.php post_edit.php Log Message: added change post_ctype to edit and add forms.. i find it useful sometimes to be able to change the ctype of a post as i post from lots of different places using different clients and some of them go screwy.... the real fix is of course to make sure we support all email senders properly, but i doubt thats realsitic. Index: post_add.php =================================================================== RCS file: /cvsroot/comoblog/comoblog/admin/post_add.php,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- post_add.php 8 Oct 2005 13:14:24 -0000 1.5 +++ post_add.php 7 Dec 2005 21:04:49 -0000 1.6 @@ -1,172 +1,172 @@ -<?php -require ('include/admin.inc.php'); - -$tpl = new XTemplate('templates/post_add.tpl.htm'); - -// date localization -setlocale (LC_TIME, $SET_LOCALE); - -if (strtoupper($_SERVER['REQUEST_METHOD'] == 'POST')) { - - $errors = array(); - - foreach ($_POST as $k => $v) - $post[$k] = trim($v); - - $i = 0; - foreach($_FILES as $k => $v) { - if ($v['error'] == '0') { - $images[$i] = $v; - $i++; - } - } - - for ($i = 0; $i < count($images); $i++) { - $imgsize = @getimagesize($images[$i]['tmp_name']); - if ($imgsize) { - $images[$i]['width'] = $imgsize[0]; - $images[$i]['height'] = $imgsize[1]; - - if ($imgsize[2] == 1) { $images[$i]['ctype'] = 'image/gif'; $images[$i]['ext'] = 'gif'; } - elseif($imgsize[2] == 2) { $images[$i]['ctype'] = 'image/jpg'; $images[$i]['ext'] = 'jpg'; } - elseif($imgsize[2] == 3) { $images[$i]['ctype'] = 'image/png'; $images[$i]['ext'] = 'png'; } - else { - $errors[] = 'Image: not supported format (use gif, jpg or png)'; - } - } - else { - $errors[] = 'Image: not supported format (use gif, jpg or png)'; - } - } - - if ($post['post_mail_subject'] == '') $errors[] = 'Subject: required'; - if ($post['post_mail_body'] == '') $errors[] = 'Body: required'; - if ($post['post_mail_from'] == '') $errors[] = 'Posted by: required'; - - if (count($errors) == 0) { - - foreach($post as $k => $v) { - if (get_magic_quotes_gpc() == 1) - $post[$k] = stripslashes($v); - } - - // apply post filters - if (count($POST_PRE_FILTERS) > 0) { - for ($filter_cnt = 0; $filter_cnt < count($POST_PRE_FILTERS); $filter_cnt++) { - include_once (CFG_BASE_PATH.'/modules/'.$POST_PRE_FILTERS[$filter_cnt].'/'.$POST_PRE_FILTERS[$filter_cnt].'_post_filter.php'); - } - } - - foreach($post as $k => $v) { - $post[$k] = addslashes($v); - } - - if ($post['post_date_option'] == "now") - { - $post['post_mail_date'] = time(); - } - else if ($post['post_date_option'] == "change") - { - $post['post_mail_date'] = strtotime($post['post_mail_date']); - } - - // add post entry in the database - $query = " - insert into ".CFG_MYSQL_TABPREFIX."posts ( - post_added, post_ctype, post_images, post_mail_from, post_mail_date, post_mail_subject, post_mail_body, topic_id - ) - values ( - '".$post['post_mail_date']."', - 'text/plain', - '0', - '".$post['post_mail_from']."', - '".$post['post_mail_date']."', - '".$post['post_mail_subject']."', - '".$post['post_mail_body']."', - '".$post['topic_id']."' - ) - "; - $res = mysql_query($query); - - $post['post_id'] = mysql_insert_id(); - - // apply post filters - if (count($POST_POST_FILTERS) > 0) { - for ($filter_cnt = 0; $filter_cnt < count($POST_POST_FILTERS); $filter_cnt++) { - include_once (CFG_BASE_PATH.'/modules/'.$POST_POST_FILTERS[$filter_cnt].'/'.$POST_POST_FILTERS[$filter_cnt].'_post_filter.php'); - } - } - - for ($i = 0; $i < count($images); $i++) { - $query = "insert into ".CFG_MYSQL_TABPREFIX."images (img_mime,img_extension,post_id,img_display,img_thumb) values ('".$images[$i]['ctype']."','".$images[$i]['ext']."','".$post['post_id']."','attach','N')"; - - $res = mysql_query($query); - $img_id = mysql_insert_id(); - - // copy new image - move_uploaded_file ($images[$i]['tmp_name'], CFG_BASE_PATH.'/img/posts/'.$img_id.'.'.$images[$i]['ext']); - - // create thumbnail - $thumb = create_thumbnail ($img_id, $images[$i]['ext'], CFG_IMG_MAX_W, CFG_IMG_MAX_H, CFG_GD_VERSION); - - if ($thumb) { - $query = "update ".CFG_MYSQL_TABPREFIX."images set img_thumb = 'Y', img_height = '".$images[$i]['height']."', img_width = '".$images[$i]['width']."' where img_id = '".$img_id."'"; - $res = mysql_query($query); - } - } - - $query = "update ".CFG_MYSQL_TABPREFIX."posts set post_images = '".count($images)."' where post_id = '".$post['post_id']."'"; - $res = mysql_query($query); - - // end - msg_page ('Post added succesfully!', 'ok'); - exit(); - } - - else { - foreach($errors as $k => $v) { - $tpl->assign('ERROR', $v); - $tpl->parse('main.errors.error'); - } - $tpl->parse('main.errors'); - } -} - - -if (strtoupper($_SERVER['REQUEST_METHOD'] == 'POST')) { - $post = $_POST; - $tpl->assign('POST', $post); -} - -// topics -$query = "select t.*, concat(i.img_id,'.',i.img_extension) as img - from ".CFG_MYSQL_TABPREFIX."topics t - left join ".CFG_MYSQL_TABPREFIX."images i - on t.img_id = i.img_id - order by t.topic_name"; -$res = mysql_query($query); - -if (mysql_num_rows($res) > 0) { - while ($row = mysql_fetch_assoc($res)) { - $tpl->assign('TOPIC', $row); - if ($row['topic_id'] == $post['topic_id']) - $tpl->parse('main.topics.topic.selected'); - $tpl->parse('main.topics.topic'); - } - $tpl->parse('main.topics'); -} - -for ($i = 0; $i < 4; $i++) { - $tpl->assign('COUNTER', $i); - $tpl->assign('COUNTER_TXT', $i + 1); - $tpl->parse('main.images.image'); -} -$tpl->parse('main.images'); - -$tpl->assign('NOW_DATE', strftime($CAL_DATE_FORMAT." %H:%M", time())); - -$tpl->assign('ACTION', basename($_SERVER['PHP_SELF'])); - -$tpl->parse('main'); -$tpl->out('main'); -?> +<?php +require ('include/admin.inc.php'); + +$tpl = new XTemplate('templates/post_add.tpl.htm'); + +// date localization +setlocale (LC_TIME, $SET_LOCALE); + +if (strtoupper($_SERVER['REQUEST_METHOD'] == 'POST')) { + + $errors = array(); + + foreach ($_POST as $k => $v) + $post[$k] = trim($v); + + $i = 0; + foreach($_FILES as $k => $v) { + if ($v['error'] == '0') { + $images[$i] = $v; + $i++; + } + } + + for ($i = 0; $i < count($images); $i++) { + $imgsize = @getimagesize($images[$i]['tmp_name']); + if ($imgsize) { + $images[$i]['width'] = $imgsize[0]; + $images[$i]['height'] = $imgsize[1]; + + if ($imgsize[2] == 1) { $images[$i]['ctype'] = 'image/gif'; $images[$i]['ext'] = 'gif'; } + elseif($imgsize[2] == 2) { $images[$i]['ctype'] = 'image/jpg'; $images[$i]['ext'] = 'jpg'; } + elseif($imgsize[2] == 3) { $images[$i]['ctype'] = 'image/png'; $images[$i]['ext'] = 'png'; } + else { + $errors[] = 'Image: not supported format (use gif, jpg or png)'; + } + } + else { + $errors[] = 'Image: not supported format (use gif, jpg or png)'; + } + } + + if ($post['post_mail_subject'] == '') $errors[] = 'Subject: required'; + if ($post['post_mail_body'] == '') $errors[] = 'Body: required'; + if ($post['post_mail_from'] == '') $errors[] = 'Posted by: required'; + + if (count($errors) == 0) { + + foreach($post as $k => $v) { + if (get_magic_quotes_gpc() == 1) + $post[$k] = stripslashes($v); + } + + // apply post filters + if (count($POST_PRE_FILTERS) > 0) { + for ($filter_cnt = 0; $filter_cnt < count($POST_PRE_FILTERS); $filter_cnt++) { + include_once (CFG_BASE_PATH.'/modules/'.$POST_PRE_FILTERS[$filter_cnt].'/'.$POST_PRE_FILTERS[$filter_cnt].'_post_filter.php'); + } + } + + foreach($post as $k => $v) { + $post[$k] = addslashes($v); + } + + if ($post['post_date_option'] == "now") + { + $post['post_mail_date'] = time(); + } + else if ($post['post_date_option'] == "change") + { + $post['post_mail_date'] = strtotime($post['post_mail_date']); + } + + // add post entry in the database + $query = " + insert into ".CFG_MYSQL_TABPREFIX."posts ( + post_added, post_ctype, post_images, post_mail_from, post_mail_date, post_mail_subject, post_mail_body, topic_id + ) + values ( + '".$post['post_mail_date']."', + '".$post['post_ctype']."', + '0', + '".$post['post_mail_from']."', + '".$post['post_mail_date']."', + '".$post['post_mail_subject']."', + '".$post['post_mail_body']."', + '".$post['topic_id']."' + ) + "; + $res = mysql_query($query); + + $post['post_id'] = mysql_insert_id(); + + // apply post filters + if (count($POST_POST_FILTERS) > 0) { + for ($filter_cnt = 0; $filter_cnt < count($POST_POST_FILTERS); $filter_cnt++) { + include_once (CFG_BASE_PATH.'/modules/'.$POST_POST_FILTERS[$filter_cnt].'/'.$POST_POST_FILTERS[$filter_cnt].'_post_filter.php'); + } + } + + for ($i = 0; $i < count($images); $i++) { + $query = "insert into ".CFG_MYSQL_TABPREFIX."images (img_mime,img_extension,post_id,img_display,img_thumb) values ('".$images[$i]['ctype']."','".$images[$i]['ext']."','".$post['post_id']."','attach','N')"; + + $res = mysql_query($query); + $img_id = mysql_insert_id(); + + // copy new image + move_uploaded_file ($images[$i]['tmp_name'], CFG_BASE_PATH.'/img/posts/'.$img_id.'.'.$images[$i]['ext']); + + // create thumbnail + $thumb = create_thumbnail ($img_id, $images[$i]['ext'], CFG_IMG_MAX_W, CFG_IMG_MAX_H, CFG_GD_VERSION); + + if ($thumb) { + $query = "update ".CFG_MYSQL_TABPREFIX."images set img_thumb = 'Y', img_height = '".$images[$i]['height']."', img_width = '".$images[$i]['width']."' where img_id = '".$img_id."'"; + $res = mysql_query($query); + } + } + + $query = "update ".CFG_MYSQL_TABPREFIX."posts set post_images = '".count($images)."' where post_id = '".$post['post_id']."'"; + $res = mysql_query($query); + + // end + msg_page ('Post added succesfully!', 'ok'); + exit(); + } + + else { + foreach($errors as $k => $v) { + $tpl->assign('ERROR', $v); + $tpl->parse('main.errors.error'); + } + $tpl->parse('main.errors'); + } +} + + +if (strtoupper($_SERVER['REQUEST_METHOD'] == 'POST')) { + $post = $_POST; + $tpl->assign('POST', $post); +} + +// topics +$query = "select t.*, concat(i.img_id,'.',i.img_extension) as img + from ".CFG_MYSQL_TABPREFIX."topics t + left join ".CFG_MYSQL_TABPREFIX."images i + on t.img_id = i.img_id + order by t.topic_name"; +$res = mysql_query($query); + +if (mysql_num_rows($res) > 0) { + while ($row = mysql_fetch_assoc($res)) { + $tpl->assign('TOPIC', $row); + if ($row['topic_id'] == $post['topic_id']) + $tpl->parse('main.topics.topic.selected'); + $tpl->parse('main.topics.topic'); + } + $tpl->parse('main.topics'); +} + +for ($i = 0; $i < 4; $i++) { + $tpl->assign('COUNTER', $i); + $tpl->assign('COUNTER_TXT', $i + 1); + $tpl->parse('main.images.image'); +} +$tpl->parse('main.images'); + +$tpl->assign('NOW_DATE', strftime($CAL_DATE_FORMAT." %H:%M", time())); + +$tpl->assign('ACTION', basename($_SERVER['PHP_SELF'])); + +$tpl->parse('main'); +$tpl->out('main'); +?> Index: post_edit.php =================================================================== RCS file: /cvsroot/comoblog/comoblog/admin/post_edit.php,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- post_edit.php 23 Nov 2005 04:24:45 -0000 1.7 +++ post_edit.php 7 Dec 2005 21:04:49 -0000 1.8 @@ -135,8 +135,9 @@ post_mail_subject = '".$post['post_mail_subject'] ."', post_mail_body = '".$post['post_mail_body'] ."', post_images = '".$post['post_images'] ."', - post_mail_date = '".$post['post_mail_date'] ."', - post_added = '".$post['post_mail_date'] ."', + post_mail_date = '".$post['post_mail_date'] ."', + post_ctype = '".$post['post_ctype'] ."', + post_added = '".$post['post_mail_date'] ."', topic_id = '".$post['topic_id'] ."' where post_id = '".$post['post_id'] ."' |