Custom "Open with" actions
Article ID: 851 | Rating: Unrated | Last Updated: Wed, Nov 22, 2017 at 9:50 AM
Creating a custom “Open with..” file contextual menu option:
The plugin folder structure
-
Create a new empty folder inside “customizables/custom_actions/”. For this example we'll name it “hello”.
-
Create a file “customizables/custom_actions/hello/app.php”
The PHP class
Inside “customizables/custom_actions/hello/app.php”, start with the following example:
<?php class custom_hello {//required class name "custom_<folder-name>" var $online = true; //set this to true if the plugin requires Internet connection. it also makes the option show after the plugins that Web File Share comes with. var $disabled = false; //you can use this or the method bellow function isDisabled() {//optional method for dynamically enabling/disabling this plugin return false; } function init() {//required method //contains only configuration data //no other functionality here $this->JSconfig = array( //required "title" => self::t("Hello World"), "popup" => true, //opens a popup and runs the method run() inside //popup styling 'iconCls' => 'fa fa-fw fa-file-text-o', //CSS class for menu item icon, remove the bellow if using this "icon" => 'url/to/icon.png', //image file for menu item icon, remove the above if using this "loadingMsg" => self::t('The plugin is loading. Please wait.'), "width" => 500, "height" => 500, "external" => true, //makes the popup an actual browser popup instead of an in-page one "ajax" => true, //instead of the popup above, it makes an Ajax call for the run() method "multiple" => true, //show menu item also when multiple files are being selected "onlyMultiple" => true, //show menu item ONLY when multiple files are being selected "folder" => true, //show menu item only for folders 'extensions' => [ 'pdf' //show only for PDF files ], 'useWith' => [//the above setting takes precedence over this one 'txt', //show only for plain text files 'office', //show only for office files 'noext' //.. and files without extension ], "requiredUserPerms" => ["download", "upload"] ); } static function t($text) {//utility method for allowing the plugin to be translated to various languages $section = 'Custom Actions: Hello World'; //the translation section return \WebFileShare\Lang::t($text, $section); } function run() {//called inside the popup, or by the Ajax request \WebFileShare::checkPerms("download");//important security stuff! echo 'Hello World!'; echo '\\'; echo 'Relative file path: '.$this->data['filePath']; echo '\\'; echo 'Full file path: '.$this->data['fileName']; echo '\\'; echo 'File name: '.$this->data['relativePath']; echo '\\'; echo 'Full path of plugin folder: '.$this->path; //add the action to the user activity log \WebFileShare\Log::add(false, "preview", [ "relative_path" => $this->data['relativePath'], "full_path" => $this->data['filePath'], "method" => "Hello" ]); } function dummy() { //your popup can access this method through the following URL: ?module=custom_actions&action=hello&method=dummy } }