Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Need help getting Discussion ID

Here's my code:
<?php if (!defined('APPLICATION')) exit();

$PluginInfo['ImageUpload'] = array(
'Name' => 'ImageUpload',
'Description' => 'lightweight and simple image uploader',
'Version' => '1.1.1',
'RequiredApplications' => array('Vanilla' => '2.0.18.4'),
'RequiredTheme' => FALSE,
'RequiredPlugins' => FALSE,
'MobileFriendly' => TRUE,
// 'HasLocale' => TRUE,
'RegisterPermissions' => FALSE,
'Author' => "chuck911",
'AuthorEmail' => 'contact@with.cat',
'AuthorUrl' => 'http://vanillaforums.cn/profile/chuck911'
);

class ImageUploadPlugin extends Gdn_Plugin {

public function DiscussionController_BeforeBodyField_Handler($Sender)
{
//  echo $Sender->FetchView($this->GetView('upload_button.php'));
}

public function PostController_BeforeBodyInput_Handler($Sender)
{
//  echo $Sender->FetchView($this->GetView('upload_button.php'));
}

public function Base_Render_Before($Sender) {
      if(!in_array(get_class($Sender), array('PostController','DiscussionController', 'MessagesController')))
        return;
    $Sender->AddDefinition('ImageUpload_Url',Url('/post/imageupload'));
    $Sender->AddDefinition('ImageUpload_Multi',C('Plugins.UploadImage.Multi',TRUE));
    $Sender->AddDefinition('ImageUpload_InputFormatter',C('Garden.InputFormatter', 'Html'));
    $Sender->AddDefinition('ImageUpload_MaxFileSize', C('Plugins.UploadImage.MaxFileSize', '2mb'));
    $Sender->AddCssFile('imageupload.css', 'plugins/ImageUpload/css');
    $Sender->AddJsFile('plupload.full.js', 'plugins/ImageUpload');
    $Sender->AddJsFile('imageupload.js', 'plugins/ImageUpload');
}

public function PostController_Imageupload_create()
{
    try {
        $UploadImage = new Gdn_UploadImage();
        $TmpImage = $UploadImage->ValidateUpload('image_file');

$servername = "localhost";
$username = "doncabron";
$password = "Yeahyeah1";
$dbname = "i933842_vf1";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT DiscussionID,LinkImagen FROM vf_Discussion ORDER BY DiscussionID DESC LIMIT 1 ";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {

$DiscussionIDz=$row["DiscussionID"]+1;

   }

} else {
echo "0 results";
}

$conn->close();

        // Generate the target image name.
            // $TargetImage = $UploadImage->GenerateTargetName(PATH_UPLOADS.'/imageupload', '', TRUE);
                        $TargetFolder = PATH_UPLOADS.'/imageupload';
                        $Name = $UploadImage->GetUploadedFileName();
                        $ExtensionSergio= strstr($Name, '.');
                        $TargetImage="$TargetFolder/".$DiscussionIDz.$ExtensionSergio;

//$Discussion = GetValue('Discussion', $this->EventArguments);
//$TargetImage="$TargetFolder/".$Discussion;

        $Props = $UploadImage->SaveImageAs($TmpImage,$TargetImage,C('Plugins.UploadImage.MaxHeight',''),C('Plugins.UploadImage.MaxWidth',650));
        echo json_encode(array('url'=>$Props['Url'],'name'=>$UploadImage->GetUploadedFileName()));
    } catch (Exception $e) {
        header('HTTP/1.0 400', TRUE, 400);
        echo $e;
    }
}

}

I've volded the part where I'm confused, I would like to get the DiscussionID from the discussion I am editing, If it is a new discussion then the image should be named (last discussion ID +1).

Any ideas how to do this (Getting Discussion ID from function:
public function PostController_Imageupload_create()
)

Thanks

Sign In or Register to comment.