id = (int)$_REQUEST['rant_id']; $rant = getrant($rant->id); if( $_POST ) { $rant->published = strtotime( $_POST['rant_date'] ); $rant->status = $_POST['rant_status'] == 'published' ? 'published' : 'draft'; $rant->side = $_POST['rant_side'] == 'left' ? 'left' : 'right'; $rant->author = (int)$_POST['rant_author']; $rant->title = $_POST['title']; $rant->body = preg_replace('/ /', '', $_POST['content']); $rant->link = $_POST['link']; $rant->imagetext = $_POST['rant_imagetext']; if( USING_TIDY ) { $tidy = new tidy; $config = $tidy->getConfig(); $tidy->parseString( $rant->body, $config, 'UTF8' ); $tidy->cleanRepair(); $rant->body = tidy_get_output($tidy); } $action = isset($_POST['publish']) ? 'post' : 'edit'; if( isset( $_POST['publish'] ) ) $rant->status = 'published'; // If [publish] button is used, ignore radio button $source_rantimage_filename = $_FILES['ranterImage']['tmp_name']; extract( pre_upload_rant_image( $source_rantimage_filename ) ); if( $upload_error ) $error.=$upload_error; $source_rantattachment_filename = Array(); for($i = 0; $i < count($_FILES['rant_attachment']['error']); $i++) { if( !is_valid_upload('rant_attachment', $i) ) { $error .= "
Attachment $i was not uploaded properly
"; $source_rantattachment_filename[] = ''; } else { $source_rantattachment_filename[] = $_FILES['rant_attachment']['tmp_name'][$i]; } } switch( $_POST['action'] ) { case 'new_rant': check_nonce('new-rant'); if( ! $doing_upload ) { // Use default rant image for this contributor. $contributor = get_userdatabyid( $rant->author ); $image_data = getimagesize(SITE_PATH_ABS .'/'. SITE_RANT .'/'. $contributor->default_image); $rant->imagetype = $image_data[2] ? $image_data[2] : 'NULL'; $source_rantimage_filename = $contributor->default_image; } else { $rant->imagetype = $upload_imagetype; } $rant->id = insertrant($rant); if( $rant->id === false ) { adminlog("Error on rant insertion: ".mysql_error(), MTS_RANT, MTA_INSERT, E_ERROR); mtdie('There was an error inserting the rant into the database.', 'SQL Error'); } for($i = 0; $i < count($source_rantattachment_filename); $i++) { if('' == $source_rantattachment_filename[$i]) continue; $upload_error = $upload_info = ''; extract( save_upload_rant_attachment($_FILES['rant_attachment']['tmp_name'][$i], $rant->id) ); if( $upload_error ) $error.=$upload_error; if( $upload_info ) { $info .= $upload_info; $rant->body = preg_replace('/(href|src)=\"([^\"]*?)\\{'.($i+1).'\\}(.*?)\"/', '\1="'.get_rantattachment_filename($rant_attachment_id).'"', $rant->body); } } if(count($_FILES['rant_attachment']['error']) > 0) updaterant($rant); if( $doing_upload ) { extract( save_upload_rant_image( $source_rantimage_filename, $rant ) ); if( $upload_info ) $info.=$upload_info; if( $upload_error ) $error.=$upload_error; } elseif($rant->imagetype != 'NULL') { extract( save_stock_rant_image( $source_rantimage_filename, $rant ) ); if( $upload_info ) $info.=$upload_info; if( $upload_error ) $error.=$upload_error; } break; case 'saverant': check_nonce('save-rant-' . $rant->id); if( isset( $_POST['rant_reverttodefaultimage'] ) ) { // Use default rant image for this contributor, copy it into place $contributor = get_userdatabyid( $rant->author ); $imagedata = getimagesize(SITE_PATH_ABS .'/'. SITE_RANT .'/'. $contributor->default_image); $rant->imagetype = $imagedata[2] ? $imagedata[2] : 'NULL'; if($rant->imagetype != 'NULL') extract( save_stock_rant_image( $contributor->default_image, $rant ) ); adminlog("Reverting to user's default rant image for rant ".$rant->id.".", MTS_RANT, MTA_UPDATE); } elseif( $doing_upload ) { $rant->imagetype = $upload_imagetype; extract( save_upload_rant_image( $source_rantimage_filename, $rant ) ); adminlog("Uploading new rant image for rant ".$rant->id.".", MTS_RANT, MTA_UPDATE); if( $upload_info ) $info.=$upload_info; if( $upload_error ) $error.=$upload_error; } foreach($_POST['delete_attachment'] as $attachment) deleteattachment($attachment); $existing_attachments = $mtdb->getAll('SELECT ra.id AS id, extension FROM rant_attachment ra JOIN media_t ON ra.media = media_t.id WHERE ra.rant = '.$rant->id.' ORDER BY id'); for($i = 0; $i < count($existing_attachments); $i++) { $rant->body = preg_replace('/(href|src)=\"([^\"]*?)\\{'.($i+1).'\\}(.*?)\"/', '\1="'.get_rantattachment_filename($existing_attachments[$i]->id).'"', $rant->body); } for($j = $i; $j < count($source_rantattachment_filename) + $i; $j++) { if('' == $source_rantattachment_filename[$j - $i]) continue; $upload_error = $upload_info = ''; extract( save_upload_rant_attachment($_FILES['rant_attachment']['tmp_name'][$j - $i], $rant->id) ); if( $upload_error ) $error.=$upload_error; if( $upload_info ) { $info .= $upload_info; $rant->body = preg_replace('/(href|src)=\"([^\"]*?)\\{'.($i+1).'\\}(.*?)\"/', '\1="'.get_rantattachment_filename($rant_attachment_id).'"', $rant->body); } } updaterant($rant); if($rant->status != 'draft' && $_POST['broadcast'] && ($rant->published <= mktime(0,0,0, date('m'), date('d')-1, date('Y')))) { rsspost('Rant '.$rant->id.' updated.', SITE_HOST.SITE_PATH.'/rant/'.$rant->id); twitterpost('Rant '.$rant->id.' updated: '.SITE_HOST.SITE_PATH.'/rant/'.$rant->id); } break; } if( $error ) $action='edit'; if( 'post' == $action ) _redirect( ADMIN_PATH . '/manage-rants.php?saved=success' ); $info.= '' . ( $rant->status === 'draft' ? 'Rant draft saved.' : sprintf('Rant published. View on site.', SITE_HOST, SITE_PATH, $rant->id) ) . '
'; } elseif( !$rant->id ) { mtdie('Attempted to edit rant with no rantid supplied.', 'Bad Request'); } /////////////////////// Display Edit Form /////////////////////// adminhead('Edit Rant'); adminmenu('manage-rants.php'); ?>