Plugin Directory

Changeset 1952436


Ignore:
Timestamp:
10/06/2018 03:56:52 AM (7 years ago)
Author:
sanjayks992
Message:

update with submenus and naming updates

Location:
find-remote-file/trunk
Files:
3 added
1 edited

Legend:

Unmodified
Added
Removed
  • find-remote-file/trunk/find-remote-file.php

    r1951806 r1952436  
    11<?php
    22
    3 /**
    4  * The plugin bootstrap file
    5  *
    6  * This Find Remote File Plugin is basically for finding the file details by passing remote url..
    7  *
    8  * @link              http://onlinewebtutorhub.blogspot.com/p/find-remote-file.html
    9  * @since             1.0.0
    10  * @package           Find_Remote_File
    11  *
     3/*
    124 * @wordpress-plugin
    13  * Plugin Name:       Find Remote File
    14  * Plugin URI:        http://onlinewebtutorhub.blogspot.com/p/find-remote-file.html
     5 * Plugin Name:       Find Remote File1
     6 * Plugin URI:        http://findremotefile.blogspot.com/p/find-remote-file.html
    157 * Description:       This Find Remote File Plugin is basically for finding the file details by passing remote url.
    168 * Version:           1.0.0
    179 * Author:            Sanjay Kumar
    18  * Author URI:        http://onlinewebtutorhub.blogspot.com
     10 * Author URI:        http://findremotefile.blogspot.com
    1911 * License:           GPL-2.0+
    2012 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
     
    2315 */
    2416
    25 // If this file is called directly, abort.
    26 if ( ! defined( 'WPINC' ) ) {
    27     die;
    28 }
    29 
    30 /**
    31  * Currently plugin version.
    32  * Start at version 1.0.0 and use SemVer - https://semver.org
    33  * Rename this for your plugin and update it as you release new versions.
    34  */
    3517define('FIND_REMOTE_FILE_VERSION', '1.0.0');
    3618define('FIND_REMOTE_FILE_DIR_PATH', plugin_dir_path(__FILE__));
    3719define('FIND_REMOTE_FILE_PLUGIN_URL', plugin_dir_url(__FILE__));
    3820
    39 /**
    40  * The code that runs during plugin activation.
    41  * This action is documented in includes/class-find-remote-file-activator.php
    42  */
    43 function activate_find_remote_file() {
    44     require_once plugin_dir_path( __FILE__ ) . 'includes/class-find-remote-file-activator.php';
    45     Find_Remote_File_Activator::activate();
     21add_action('admin_enqueue_scripts', 'frf_enqueue_styles');
     22add_action('admin_enqueue_scripts', 'frf_enqueue_scripts');
     23
     24add_action('admin_menu', 'wpl_rd_admin_menus');
     25add_action('wp_ajax_wpl_file_url_validator_library', 'wpl_rd_ajax_lib_call');
     26
     27function frf_enqueue_styles() {
     28
     29    $page = isset($_REQUEST['page']) ? esc_attr(trim($_REQUEST['page'])) : "";
     30
     31    if ($page == "find-remote-file") {
     32        wp_enqueue_style("bootstrap", FIND_REMOTE_FILE_PLUGIN_URL . 'assets/css/bootstrap.min.css', array(), '1.0.0', 'all');
     33        wp_enqueue_style("notifybar", FIND_REMOTE_FILE_PLUGIN_URL . 'assets/css/jquery.notifyBar.css', array(), '1.0.0', 'all');
     34        wp_enqueue_style("find-remote-file", plugin_dir_url(__FILE__) . 'assets/css/find-remote-file-admin.css', array(), '1.0.0', 'all');
     35    }
    4636}
    4737
    48 /**
    49  * The code that runs during plugin deactivation.
    50  * This action is documented in includes/class-find-remote-file-deactivator.php
    51  */
    52 function deactivate_find_remote_file() {
    53     require_once plugin_dir_path( __FILE__ ) . 'includes/class-find-remote-file-deactivator.php';
    54     Find_Remote_File_Deactivator::deactivate();
     38function frf_enqueue_scripts() {
     39
     40    $page = isset($_REQUEST['page']) ? esc_attr(trim($_REQUEST['page'])) : "";
     41
     42    if ($page == "find-remote-file") {
     43        wp_enqueue_script("jquery");
     44        wp_enqueue_script("notifybar-js", FIND_REMOTE_FILE_PLUGIN_URL . 'assets/js/jquery.notifyBar.js', array('jquery'), "1.0.0", true);
     45        wp_enqueue_script("validate-js", FIND_REMOTE_FILE_PLUGIN_URL . 'assets/js/jquery.validate.js', array('jquery'), "1.0.0", true);
     46        wp_enqueue_script("find-remote-file", plugin_dir_url(__FILE__) . 'assets/js/find-remote-file-admin.js', array('jquery'), "1.0.0", true);
     47        wp_localize_script("find-remote-file", "wpl_find_remote_file", array(
     48            "ajaxurl" => admin_url('admin-ajax.php')
     49        ));
     50    }
    5551}
    5652
    57 register_activation_hook( __FILE__, 'activate_find_remote_file' );
    58 register_deactivation_hook( __FILE__, 'deactivate_find_remote_file' );
     53function wpl_rd_admin_menus() {
    5954
    60 /**
    61  * The core plugin class that is used to define internationalization,
    62  * admin-specific hooks, and public-facing site hooks.
    63  */
    64 require plugin_dir_path( __FILE__ ) . 'includes/class-find-remote-file.php';
     55    add_menu_page("Find Remote File", "Find Remote File", "manage_options", "find-remote-file", 'wpl_rd_find_remote_file_fn', "
     56dashicons-update", 69);
     57}
    6558
    66 /**
    67  * Begins execution of the plugin.
    68  *
    69  * Since everything within the plugin is registered via hooks,
    70  * then kicking off the plugin from this point in the file does
    71  * not affect the page life cycle.
    72  *
    73  * @since    1.0.0
    74  */
    75 function run_find_remote_file() {
     59function wpl_rd_find_remote_file_fn() {
    7660
    77     $plugin = new Find_Remote_File();
    78     $plugin->run();
     61    ob_start();
     62    include_once FIND_REMOTE_FILE_DIR_PATH . 'views/find-remote-file-dashboard.php';
     63    $template = ob_get_contents();
     64    ob_end_clean();
    7965
     66    echo $template;
    8067}
    81 run_find_remote_file();
     68
     69function wpl_rd_ajax_lib_call() {
     70
     71    global $wpdb;
     72
     73    $param = isset($_REQUEST['param']) ? esc_attr(trim($_REQUEST['param'])) : "";
     74    if (!empty($param)) {
     75
     76        if ($param == "url_validator") {
     77
     78            $url = isset($_REQUEST['text_url']) ? sanitize_text_field($_REQUEST['text_url']) : "";
     79
     80            $extension = pathinfo($url, PATHINFO_EXTENSION);
     81
     82            if (!empty($extension)) {
     83
     84                $filesize = getRemoteFilesize($url);
     85                $valid_images = array("png", "jpeg", "jpeg", "gif", "bmp", "svg");
     86                $valid_audio = array("mp3");
     87                $valid_vedio = array("mp4", "webm", "mkv", "3gp");
     88                $fileType = '';
     89
     90                if (in_array($extension, $valid_images)) {
     91                    $fileType = "Image";
     92                } elseif (in_array($extension, $valid_audio)) {
     93                    $fileType = "Audio";
     94                } elseif (in_array($extension, $valid_vedio)) {
     95                    $fileType = "Video";
     96                } else {
     97                    $fileType = "File";
     98                }
     99
     100                $fileName = explode("/", $url);
     101                $fileName = $fileName[count($fileName) - 1];
     102
     103                $file_prev_details = array(
     104                    "size" => $filesize,
     105                    "filetype" => $fileType,
     106                    "filename" => $fileName,
     107                    "preview" => $url,
     108                    "extension" => $extension,
     109                    "url" => $url
     110                );
     111
     112                ob_start();
     113                include_once FIND_REMOTE_FILE_DIR_PATH . 'views/file-details-preview.php';
     114                $template = ob_get_contents();
     115                ob_end_clean();
     116
     117                json(1, "File details", array(
     118                    "template" => $template
     119                ));
     120            } else {
     121                json(0, "URL has no file to fetch details");
     122            }
     123        }
     124    }
     125
     126    wp_die();
     127}
     128
     129function getRemoteFilesize($file_url, $formatSize = true) {
     130    $head = array_change_key_case(get_headers($file_url, 1));
     131    // content-length of download (in bytes), read from Content-Length: field
     132
     133    $clen = isset($head['content-length']) ? $head['content-length'] : 0;
     134
     135    // cannot retrieve file size, return "-1"
     136    if (!$clen) {
     137        return -1;
     138    }
     139
     140    if (!$formatSize) {
     141        return $clen;
     142        // return size in bytes
     143    }
     144
     145    $size = $clen;
     146    switch ($clen) {
     147        case $clen < 1024:
     148            $size = $clen . ' B';
     149            break;
     150        case $clen < 1048576:
     151            $size = round($clen / 1024, 2) . ' KB';
     152            break;
     153        case $clen < 1073741824:
     154            $size = round($clen / 1048576, 2) . ' MB';
     155            break;
     156        case $clen < 1099511627776:
     157            $size = round($clen / 1073741824, 2) . ' GB';
     158            break;
     159    }
     160
     161    return $size;
     162    // return formatted size
     163}
     164
     165function json($sts, $msg, $arr = array()) {
     166    $ar = array('sts' => $sts, 'msg' => $msg, 'arr' => $arr);
     167    print_r(json_encode($ar));
     168    die;
     169}
Note: See TracChangeset for help on using the changeset viewer.