Topic: Upload Plugins From Plugins List
I have seen a lot of people asking for a way to upload plugins from the plugin in tab, so I wrote a small little script that will allow the user to upload the plugin zip file
navigate to plugins -> box -> plugins -> views -> backend and copy and paste this code into the index.view.php file
<h2><?php echo __('Plugins', 'plugins'); ?></h2>
<br />
<div class="tabbable">
<!-- Plugins_tabs -->
<ul class="nav nav-tabs">
<li class="active"><a href="#installed" data-toggle="tab"><?php echo __('Installed', 'plugins'); ?></a></li>
<li><a href="#installnew" data-toggle="tab"><?php echo __('Install New', 'plugins'); ?> <?php if (count($plugins_to_intall) > 0) { ?><span class="badge"><?php echo count($plugins_to_intall); ?></span><?php } ?></a></li>
</ul>
<!-- /Plugins_tabs -->
<div class="tab-content">
<div class="tab-pane active" id="installed">
<table class="table table-bordered">
<thead>
<tr>
<th><?php echo __('Name', 'plugins'); ?></th>
<th class="hidden-phone"><?php echo __('Description', 'plugins'); ?></th>
<th><?php echo __('Author', 'plugins'); ?></th>
<th><?php echo __('Version', 'plugins'); ?></th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($installed_plugins as $plugin) { if ($plugin['privilege'] !== 'box') { ?>
<tr>
<td>
<?php echo $plugin['title']; ?>
</td>
<td class="hidden-phone">
<?php echo $plugin['description']; ?>
</td>
<td>
<a target="_blank" href="<?php echo $plugin['author_uri']; ?>"><?php echo $plugin['author']; ?></a>
</td>
<td>
<?php echo $plugin['version']; ?>
</td>
<td>
<div class="pull-right">
<?php echo Html::anchor(__('Uninstall', 'plugins'),
'index.php?id=plugins&delete_plugin='.$plugin['id'].'&token='.Security::token(),
array('class' => 'btn btn-small', 'onclick' => "return confirmDelete('".__('Delete plugin :plugin', 'plugins', array(':plugin' => $plugin['title']))."')"));
?>
</div>
</td>
</tr>
<?php } } ?>
</tbody>
</table>
<?php
if($_FILES["zip_file"]["name"]) {
$filename = $_FILES["zip_file"]["name"];
$source = $_FILES["zip_file"]["tmp_name"];
$type = $_FILES["zip_file"]["type"];
$name = explode(".", $filename);
$accepted_types = array('application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/x-compressed');
foreach($accepted_types as $mime_type) {
if($mime_type == $type) {
$okay = true;
break;
}
}
$continue = strtolower($name[1]) == 'zip' ? true : false;
if(!$continue) {
$message = "The file you are trying to upload is not a .zip file. Please try again.";
}
$target_path = "../plugins/".$filename; // change this to the correct site path
if(move_uploaded_file($source, $target_path)) {
$zip = new ZipArchive();
$x = $zip->open($target_path);
if ($x === true) {
$zip->extractTo("../plugins/"); // change this to the correct site path
$zip->close();
unlink($target_path);
header( 'refresh: 3; url=/admin/index.php?id=plugins' ); # redirects to our homepage
}
$message = "Your plugin was uploaded successfully, page will reload in 3 seconds.";
} else {
$message = "There was a problem with the upload. Please try again.";
}
}
?>
<?php if($message) echo "<p>$message</p>"; ?>
<form enctype="multipart/form-data" method="post" action="">
<label>Choose a zip file to upload:<br /><br /> <input type="file" name="zip_file" /></label>
<br />
<input type="submit" name="submit" value="Upload" />
</form>
</div>
<div class="tab-pane" id="installnew">
<table class="table table-bordered">
<thead>
<tr>
<th><?php echo __('Name', 'plugins'); ?></th>
<th class="hidden-phone"><?php echo __('Description', 'plugins'); ?></th>
<th><?php echo __('Author', 'plugins'); ?></th>
<th><?php echo __('Version', 'plugins'); ?></th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($plugins_to_intall as $plug) { $plugin_xml = XML::loadFile($plug['path']); ?>
<tr>
<td>
<?php echo $plugin_xml->plugin_name; ?>
</td>
<td class="hidden-phone">
<?php echo $plugin_xml->plugin_description; ?>
</td>
<td>
<a href="<?php echo $plugin_xml->plugin_author_uri; ?>"><?php echo $plugin_xml->plugin_author; ?></a>
</td>
<td>
<?php echo $plugin_xml->plugin_version; ?>
</td>
<td>
<div class="pull-right">
<?php echo Html::anchor(__('Install', 'plugins'), 'index.php?id=plugins&install='.$plug['plugin'].'&token='.Security::token(), array('class' => 'btn btn-small')); ?>
<?php echo Html::anchor(__('Delete', 'plugins'),
'index.php?id=plugins&delete_plugin_from_server='.Text::lowercase(basename($plug['path'],'.manifest.xml')).'&token='.Security::token(),
array('class' => 'btn btn-small', 'onclick' => "return confirmDelete('".__('Delete plugin :plugin', 'plugins', array(':plugin' => $plugin_xml->plugin_name))."')"));
?>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<!-- /Plugins_to_install_list -->
</div>
</div>