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>

2 (edited by RomanArt 2014-02-09 07:41:52)

Re: Upload Plugins From Plugins List

um, i just tested it after uploading it says wait 3 sec, and then nothing i mean i dont see a plugin i just upload ... i cant istall or even see wht i just uploaded

Monstra – Version 2.3.1

(с) Roman Art
So far So good wink

RomanArt's Website

3 2014-02-09 07:53:00 (edited by RomanArt 2014-02-09 07:59:05)

Re: Upload Plugins From Plugins List

1) the plugin must be in folder
like this:
-contacts.zip
--contacts
---- all files here

cause when i try to upload Awilum plugin he pack it like this
-contacts.zip
-- all files here

2) it works only with .zip tryed .rar nothing smile

3) i repack the plugin contacts made it .zip upload, i can see it in folder with plugins but i dont see it in admin panel so i cant install it Q_Q in install new i have only sandbox
(about 3 i try another one it works, need to report to Awilum abt contacts plugin there are 2 files missing)

(с) Roman Art
So far So good wink

RomanArt's Website

4 2014-02-09 09:18:32 (edited by lucasflynn 2014-02-09 09:23:02)

Re: Upload Plugins From Plugins List

its still a work in progress

5 2014-02-09 09:48:25

Re: Upload Plugins From Plugins List

HI, We already work on this task https://github.com/Awilum/monstra-cms/issues/215 mostly done.

Monstra Loves You! Give some love back!

Re: Upload Plugins From Plugins List

i know, but this is just a simple fix until the final release comes out