/**
  * fetch module info
  * @param $module
  */
 public function modules_info($module)
 {
     global $wp_xmlrpc_server;
     $_module = HW_TGM_Module_Activation::get_register_modules($module);
     if (count($_module)) {
         $_module = $_module[$module];
         $_module['download_link'] = 'http://api.hoangweb.com/modules/download/' . $module;
     }
     return $_module;
 }
 /**
  * get active module by installer
  * @param $module
  * @param $default_module if specific module not exists, get default other module
  */
 private function get_active_module_from_installer($module = '', $default_module = 'hw-importer')
 {
     if (!$module) {
         $module = hw__req('module');
     }
     if (!count(HW_TGM_Module_Activation::get_register_modules(array('active' => 1, 'slug' => $module)))) {
         $module = $default_module;
     }
     if ($module) {
         return HW_Module_Settings_page::get_modules($module);
     }
 }
/**
 * active module by slug
 * @param $module one or more module data
 * @param int|string $pos
 */
function hw_activate_modules($module, $pos = '')
{
    static $actived_modules;
    $modules = array();
    if (!$actived_modules) {
        $actived_modules = hw_get_modules(true);
    }
    $count = count($actived_modules);
    if (isset($module[0]) && !is_array($module[0])) {
        $modules[] = $module;
    } else {
        $modules = $module;
    }
    foreach ($modules as $_module) {
        if (!isset($actived_modules[$_module[0]]) && HW_TGM_Module_Activation::get_modules($_module[0])) {
            //get register module meta data
            $info = HW_TGM_Module_Activation::get_modules($_module[0]);
            if (empty($info['position'])) {
                $info['position'] = count($actived_modules);
            }
            //$actived_modules[$_module[0]] = $_module;
            $actived_modules = hwArray::add_item_keyval($actived_modules, $_module[0], $_module, $info['position']);
            //load new module file for initialize
            HW_HOANGWEB::load_module($_module[0]);
            //activation hook for module
            $activation_hooks = HW_HOANGWEB::register_activation_hook(realpath(HW_HOANGWEB_PLUGINS . '/' . $_module[0]));
            if (is_array($activation_hooks)) {
                foreach ($activation_hooks as $activation_hook) {
                    if (is_callable($activation_hook)) {
                        call_user_func($activation_hook);
                        usleep(200);
                        //sleep in miliseconds
                    }
                }
            }
        }
    }
    //save option to db
    if ($count !== count($actived_modules)) {
        update_option('hw_install_modules', $actived_modules);
        HW_Cache::reset_wp_menus_caches();
        return true;
    }
    return false;
}
 /**
  * process bulk actions for module/plugin
  * @param array $plugins
  * @param $action action bulk
  */
 public function process_bulk_action($plugins = array(), $action = '')
 {
     // Grab plugin data from $_POST.
     #$plugins             = isset( $_POST['plugin'] ) ? (array) $_POST['plugin'] : array();
     $plugins_to_activate = array();
     // Split plugin value into array with plugin file path, plugin source and plugin name.
     $plugins_need2activate = array();
     if (is_array($plugins)) {
         foreach ($plugins as $i => $plugin) {
             $_plugin = explode(',', $plugin);
             if (isset(HW_TGM_Module_Activation::get_instance()->plugins[$_plugin[0]])) {
                 $module_info = HW_TGM_Module_Activation::get_instance()->plugins[$_plugin[0]];
                 $active = array();
                 //local downloaded plugins
                 if (!empty($module_info['require_wp_plugin']) && file_exists(WP_PLUGIN_DIR . '/' . trim($module_info['require_wp_plugin'], '/'))) {
                     $active[] = $module_info['require_wp_plugin'];
                     $active[] = 'repo';
                     $plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/' . trim($module_info['require_wp_plugin'], '/'));
                     $active[] = $plugin_data['Name'];
                 }
                 if (!empty($module_info['require_module'])) {
                     //check module that require an other
                     $require_module = $module_info['require_module'];
                     if (!hw_is_active_module($require_module)) {
                         hw_inline_msg("Xin lỗi, module `{$module_info['name']}` yêu cầu cài trước module " . $require_module);
                         $plugins_to_activate[] = array($module_info['slug'], $module_info['name']);
                     }
                 }
                 if (!empty($module_info['require_wp_plugin']) && !is_plugin_active($module_info['require_wp_plugin']) && !empty($active)) {
                     $plugins_need2activate[] = $active;
                 }
             }
             $plugins_to_activate[] = $_plugin;
         }
     }
     foreach ($plugins_to_activate as $i => $array) {
         if (isset($array[1]) && !preg_match('|.php$|', $array[1])) {
             unset($plugins_to_activate[$i]);
         }
     }
     // Return early if there are no plugins to activate.
     if (empty($plugins_to_activate)) {
         return;
     }
     //activate plugins require for the your modules
     if (count($plugins_need2activate)) {
         $this->hw_activate_plugins($plugins_need2activate);
     }
     if ('tgmpa-bulk-activate' === $action) {
         // Now we are good to go - let's start activating plugins.
         hw_activate_modules($plugins_to_activate);
     } elseif ('tgmpa-bulk-deactivate' === $action) {
         //deactive module
         hw_deactivate_modules($plugins_to_activate);
     }
     // Update recently activated plugins option.
     $recent = (array) get_option('recently_activated');
     foreach ($plugins as $plugin => $time) {
         if (isset($recent[$plugin])) {
             unset($recent[$plugin]);
         }
     }
     update_option('recently_activated', $recent);
 }
    /**
     * Render the settings page
     */
    public function _wxr_settings_page()
    {
        $options = get_option('hw_wxr_settings');
        ?>
        <div class="wrap">
            <div id="icon-tools" class="icon32"><br /></div>
            <h2><?php 
        screen_icon();
        _e('HOANGWEB Settings');
        ?>
</h2>

            <form method="post" action="options.php" class="options_form">
                <?php 
        settings_fields('hw_wxr_settings_group');
        ?>
                <table class="form-table">
                    <!--
                    <tr valign="top">
                        <th scop="row">
                            <label for="hw_wxr_settings[text]"><?php 
        _e('Plugin Text');
        ?>
</label>
                        </th>
                        <td>
                            <input class="regular-text" type="text" id="hw_wxr_settings[text]" style="width: 300px;" name="hw_wxr_settings[text]" value="<?php 
        if (isset($options['text'])) {
            echo esc_attr($options['text']);
        }
        ?>
"/>
                            <p class="description"><?php 
        _e('Enter some text for the plugin here.');
        ?>
</p>
                        </td>
                    </tr>
                    <tr>
                        <th scop="row">
                            <label for="hw_wxr_settings[label]"><?php 
        _e('Label Text');
        ?>
</label>
                        </th>
                        <td>
                            <input class="regular-text" type="text" id="hw_wxr_settings[label]" style="width: 300px;" name="hw_wxr_settings[label]" value="<?php 
        if (isset($options['label'])) {
            echo esc_attr($options['label']);
        }
        ?>
"/>
                            <p class="description"><?php 
        _e('Enter some text for the label here.');
        ?>
</p>
                        </td>
                    </tr>

                    <tr valign="top">
                        <th scop="row">
                            <span><?php 
        _e('Enable Feature');
        ?>
</span>
                        </th>
                        <td>
                            <input class="checkbox" type="checkbox" id="hw_wxr_settings[enabled]" name="hw_wxr_settings[enabled]" value="1" <?php 
        checked(1, isset($options['enabled']));
        ?>
/>
                            <label for="hw_wxr_settings[enabled]"><?php 
        _e('Enable some feature in this plugin?');
        ?>
</label>
                        </td>
                    </tr>
                    -->
                </table>
                <?php 
        #submit_button();
        ?>
            </form>

            <div class="metabox-holder">
                <div class="postbox">
                    <h3><span><?php 
        _e('Export Settings');
        ?>
</span></h3>
                    <div class="inside">
                        <form method="post">
                            <p><label><input type="radio" name="module" value="all" /> Tất cả</label></p>
                        <?php 
        foreach (HW_TGM_Module_Activation::get_modules() as $slug => $plugin) {
            if (empty($plugin['can_export']) || !HW_Module::is_active($slug)) {
                continue;
            }
            ?>
                            <p><label><input type="radio" name="module" value="<?php 
            echo esc_attr($plugin['slug']);
            ?>
" /> <?php 
            echo esc_html($plugin['name']);
            ?>
</label></p>
                        <?php 
        }
        ?>

                        <p><?php 
        _e('Export the plugin settings for this site as a .json file. This allows you to easily import the configuration into another site.');
        ?>
</p>

                            <p><input type="hidden" name="hw_wxr_action" value="export_settings" /></p>
                            <p>
                                <?php 
        wp_nonce_field('hw_wxr_export_nonce', 'hw_wxr_export_nonce');
        ?>
                                <?php 
        submit_button(__('Export'), 'secondary', 'submit', false);
        ?>
                            </p>
                        </form>
                    </div><!-- .inside -->
                </div><!-- .postbox -->

                <div class="postbox">
                    <h3><span><?php 
        _e('Import Settings');
        ?>
</span></h3>
                    <div class="inside">
                        <p><?php 
        _e('Import the plugin settings from a .json file. This file can be obtained by exporting the settings on another site using the form above.');
        ?>
</p>
                        <!--
                        <form method="post" enctype="multipart/form-data">
                            <p>
                                <input type="file" name="import_file"/>
                            </p>
                            <p>
                                <input type="hidden" name="hw_wxr_action" value="import_settings" />
                                <?php 
        wp_nonce_field('hw_wxr_import_nonce', 'hw_wxr_import_nonce');
        ?>
                                <?php 
        submit_button(__('Import'), 'secondary', 'submit', false);
        ?>
                            </p>
                        </form>
                        -->
                        Nhấn <a href="<?php 
        echo admin_url('admin.php?import=hw-wordpress');
        ?>
">vào đây</a> để tiến hành Import dữ liệu.
                    </div><!-- .inside -->
                </div><!-- .postbox -->
            </div><!-- .metabox-holder -->
        </div>
    <?php 
    }
Example #6
0
 /**
  * this call by parent class
  */
 public function register_admin_menu()
 {
     $all_modules = HW_TGM_Module_Activation::get_register_modules();
     $module = $this->_option('module');
     $name = $module->module_name;
     $label = isset($all_modules[$name]) ? $all_modules[$name]['name'] : $name;
     $this->add_help_content(self::load_settings_page_hook_slug(HW_Module_Settings_page::PAGE_SLUG), $name, $label);
 }
 /**
  * prepare items
  */
 public function prepare_items()
 {
     //include( ABSPATH . 'wp-admin/includes/plugin-install.php' );
     include HW_ADMIN_INCLUDES . '/module-install.php';
     global $tabs, $tab, $paged, $type, $term;
     wp_reset_vars(array('tab'));
     $paged = $this->get_pagenum();
     $per_page = 30;
     // These are the tabs which are shown on the page
     $tabs = array();
     if ('search' == $tab) {
         $tabs['search'] = __('Search Results');
     }
     $tabs['featured'] = _x('Featured', 'Plugin Installer');
     $tabs['popular'] = _x('Popular', 'Plugin Installer');
     $tabs['recommended'] = _x('Recommended', 'Plugin Installer');
     $tabs['favorites'] = _x('Favorites', 'Plugin Installer');
     if ($tab === 'beta' || false !== strpos($GLOBALS['wp_version'], '-')) {
         $tabs['beta'] = _x('Beta Testing', 'Plugin Installer');
     }
     if (current_user_can('upload_plugins')) {
         // No longer a real tab. Here for filter compatibility.
         // Gets skipped in get_views().
         $tabs['upload'] = __('Upload Plugin');
     }
     $nonmenu_tabs = array('module-information');
     // Valid actions to perform which do not have a Menu item.
     /**
      * Filter the tabs shown on the Plugin Install screen.
      *
      * @since 2.7.0
      *
      * @param array $tabs The tabs shown on the Plugin Install screen. Defaults include 'featured', 'popular',
      *                    'recommended', 'favorites', and 'upload'.
      */
     $tabs = apply_filters('install_plugins_tabs', $tabs);
     /**
      * Filter tabs not associated with a menu item on the Plugin Install screen.
      *
      * @since 2.7.0
      *
      * @param array $nonmenu_tabs The tabs that don't have a Menu item on the Plugin Install screen.
      */
     $nonmenu_tabs = apply_filters('install_plugins_nonmenu_tabs', $nonmenu_tabs);
     // If a non-valid menu tab has been selected, And it's not a non-menu action.
     if (empty($tab) || !isset($tabs[$tab]) && !in_array($tab, (array) $nonmenu_tabs)) {
         $tab = key($tabs);
     }
     $args = array('page' => $paged, 'per_page' => $per_page, 'fields' => array('last_updated' => true, 'icons' => true, 'active_installs' => true), 'locale' => get_locale(), 'installed_plugins' => $this->get_installed_plugin_slugs());
     switch ($tab) {
         case 'search':
             $type = isset($_REQUEST['type']) ? wp_unslash($_REQUEST['type']) : 'term';
             $term = isset($_REQUEST['s']) ? wp_unslash($_REQUEST['s']) : '';
             switch ($type) {
                 case 'tag':
                     $args['tag'] = sanitize_title_with_dashes($term);
                     break;
                 case 'term':
                     $args['search'] = $term;
                     break;
                 case 'author':
                     $args['author'] = $term;
                     break;
             }
             break;
         case 'featured':
             $args['fields']['group'] = true;
             $this->orderby = 'group';
             // No break!
         // No break!
         case 'popular':
         case 'new':
         case 'beta':
         case 'recommended':
             $args['browse'] = $tab;
             break;
         case 'favorites':
             $user = isset($_GET['user']) ? wp_unslash($_GET['user']) : get_user_option('wporg_favorites');
             update_user_meta(get_current_user_id(), 'wporg_favorites', $user);
             if ($user) {
                 $args['user'] = $user;
             } else {
                 $args = false;
             }
             add_action('install_plugins_favorites', 'install_plugins_favorites_form', 9, 0);
             break;
         default:
             $args = false;
             break;
     }
     /**
      * Filter API request arguments for each Plugin Install screen tab.
      *
      * The dynamic portion of the hook name, `$tab`, refers to the plugin install tabs.
      * Default tabs include 'featured', 'popular', 'recommended', 'favorites', and 'upload'.
      *
      * @since 3.7.0
      *
      * @param array|bool $args Plugin Install API arguments.
      */
     $args = apply_filters("install_plugins_table_api_args_{$tab}", $args);
     if (!$args) {
         return;
     }
     /*$api =new WP_Error(0,'sfdf'); //plugins_api( 'query_plugins', $args );  //in development
     
     		if ( is_wp_error( $api ) ) {
     			$this->error = $api;
     			return;
     		}*/
     //$this->items = $api->plugins;
     $this->items = HW_TGM_Module_Activation::get_register_modules(array('core' => false));
     //$this->get_modules_repositories()
     if ($this->orderby) {
         uasort($this->items, array($this, 'order_callback'));
     }
     $this->set_pagination_args(array('total_items' => count($this->items), 'per_page' => $args['per_page']));
     /*if ( isset( $api->info['groups'] ) ) {
     			$this->groups = $api->info['groups'];
     		}*/
 }
Example #8
0
 /**
  * parse theme config data
  * @return object
  */
 public static function parse_theme_config($config = '')
 {
     //static $theme_config;
     //if(!empty(self::$theme_config[$config])) return self::$theme_config[$config];
     if (!$config) {
         $config = self::get_config_file();
     }
     if (file_exists($config)) {
         if (!isset(self::$theme_config[$config])) {
             self::$theme_config[$config] = new self(null);
         }
         //because call the hook of after_setup_theme before do init hook we open all which to call this method
         //and after_setup_theme cause data load a half so data must tobe refresh, all i know about that
         if (1 || !HW_TGM_Module_Activation::is_complete_load() || empty(self::$theme_config[$config]->configuration)) {
             self::$theme_config[$config]->configuration = self::$theme_config[$config]->parse($config);
         }
     }
     return self::valid_theme_config(self::$theme_config[$config]->configuration) ? self::$theme_config[$config] : null;
 }
    /**
     * Widget Backend
     * @param $instance
     */
    public function form($instance)
    {
        //widget title
        if (isset($instance['title'])) {
            $title = $instance['title'];
        } else {
            $title = __('Chữ chạy', 'hoangweb');
        }
        //$library  = isset($instance['library'])? $instance['library'] : ''; //library
        $current_source = isset($instance['source']) ? $instance['source'] : 'content';
        //data source
        $data = isset($instance['data']) ? $instance['data'] : array();
        //data
        //content scrolling
        $content = isset($data['content']) ? $data['content'] : '';
        //skin
        $skin_setting = isset($instance['skin_settings']) ? $instance['skin_settings'] : '';
        $skin = isset($instance['skin']) ? $instance['skin'] : '';
        // Widget admin form
        ?>
        <p><strong>Lưu ý</strong>: nhấn nút lưu widget trong lần đầu tiên khởi tạo widget.</p>
        <p>
            <label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title:');
        ?>
</label>
            <input class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" name="<?php 
        echo $this->get_field_name('title');
        ?>
" type="text" value="<?php 
        echo esc_attr($title);
        ?>
" />
        </p>
        <!--
        <p>
            <label for="<?php 
        //echo $this->get_field_id('library')
        ?>
"><?php 
        _e('Thư viện');
        ?>
</label><br/>
            <select name="<?php 
        //echo $this->get_field_name('library')
        ?>
" id="<?php 
        //echo $this->get_field_id('library')
        ?>
">
                <?php 
        /*foreach($this->libraries as $lib => $text) {
              $selected = ($library == $lib)? 'selected="selected"' : '';
              printf( '<option value="%s" %s>%s</option>', $lib, $selected, $text);
          }*/
        ?>

            </select>
        </p>
        -->
        <?php 
        if (!empty($this->skin)) {
            ?>
        <p>
            <label for="<?php 
            ?>
"><?php 
            _e('Thư viện');
            ?>
</label>
            <?php 
            echo $this->skin->get_skins_select_tag('skin', null, array('class' => 'widefat'), false);
            ?>
            <!-- show skin options if exists -->
            <?php 
            echo $this->skin->prepare_skin_options_fields('skin_settings', $skin_setting, $skin);
            ?>
        </p>
        <?php 
        }
        ?>
        <p>
            <label for="<?php 
        echo $this->get_field_id('source');
        ?>
"><?php 
        _e('Nguồn');
        ?>
</label><br/>
            <select name="<?php 
        echo $this->get_field_name('source');
        ?>
" id="<?php 
        echo $this->get_field_id('source');
        ?>
">
                <?php 
        foreach ($this->sources as $source => $text) {
            $selected = selected($source, $current_source, false);
            printf('<option %s value="%s">%s</option>', $selected, $source, $text);
        }
        ?>
            </select>
        </p>

        <!-- slides data -->
        <?php 
        if ($current_source == 'slides') {
            $module = HW_TGM_Module_Activation::get_modules('hw-ml-slider', OBJECT);
            if (hw_is_active_module('hw-ml-slider')) {
                $current_slider = isset($data['slider']) ? $data['slider'] : '';
                $slides = hwmq_get_all_mlsliders();
                ?>
        <p id="<?php 
                echo $this->get_field_id('source_slides');
                ?>
" style="">
            <label for="<?php 
                echo $this->get_field_id('slider');
                ?>
"><?php 
                _e('Slider');
                ?>
</label><br/>
            <select name="<?php 
                echo $this->get_field_name('data');
                ?>
[slides]" id="<?php 
                echo $this->get_field_id('slides');
                ?>
">
                <?php 
                foreach ($slides as $id => $name) {
                    $selected = selected($id, $current_slider, false);
                    printf('<option %s value="%s">%s</option>', $selected, $id, $name);
                }
                ?>
            </select>
        </p>
        <?php 
            } else {
                echo __('Vui lòng kích hoạt module ' . $module->name);
            }
        } elseif ($current_source == 'content') {
            //default
            ?>
        <!-- content text -->
        <p id="<?php 
            echo $this->get_field_id('source_content');
            ?>
" style="">
            <label for="<?php 
            echo $this->get_field_id('content');
            ?>
"><?php 
            _e('Nội dung chạy');
            ?>
</label><br/>
            <textarea class="" style="width:100%; min-height:200px" name="<?php 
            echo $this->get_field_name('data');
            ?>
[content]" id="<?php 
            echo $this->get_field_id('content');
            ?>
"><?php 
            echo isset($data['content']) ? $data['content'] : '';
            ?>
</textarea>
        </p>
            <script>
                jQuery(function($){
                    CKEDITOR.config.extraPlugins = "hw_wp_media_button";
                    //CKEDITOR.config.width = 700;
                    var editor = '<?php 
            echo $this->get_field_id('content');
            ?>
',
                        id = '<?php 
            echo $this->number;
            ?>
',
                        editor_obj = CKEDITOR.instances[editor];

                    var config = {
                        language: "vi",
                        //uiColor: "#9AB8F3",
                        width: 700,
                        extraPlugins : "hw_wp_media_button",
                        resize_enabled : true,
                        resize_minWidth: 300,
                        resize_minHeight: 300,
                        resize_maxWidth : 2000,
                        resize_maxHeight: 2000,
                        resize_dir: 'both'
                    };
                    // Replace the <textarea id="editor1"> with a CKEditor
                    // instance, using default configuration.
                    /*if (editor_obj) {
                     editor_obj.destroy(true);
                     CKEDITOR.remove(editor_obj);
                     }*/
                    if(!(!jQuery.isNumeric(id) && editor_obj)) CKEDITOR.replace( editor ,config);

                    $('#<?php 
            echo $this->get_field_id('savewidget');
            ?>
').bind('click', function(e){
                        console.log('savewidget');
                        $('#'+editor).val( CKEDITOR.instances[editor].getData());
                    });
                });

            </script>
            <?php 
        }
        ?>

    <?php 
    }
Example #10
0
 /**
  * init module
  */
 public static final function init()
 {
     $class = get_called_class();
     if ($class) {
         $inst = new $class();
         if (!$inst instanceof HW_Module) {
             return;
         }
         //get file name where a Class was Defined
         $reflector = new ReflectionClass($class);
         //path variables
         $inst->option('module_path', dirname($reflector->getFileName()));
         $module_slug = basename($inst->option('module_path'));
         $inst->option('module_name', $module_slug);
         $modules = HW_TGM_Module_Activation::get_register_modules();
         if (isset($modules[$module_slug])) {
             $info = array_filter(HW_Plugins_Manager::get_module_info($reflector->getFileName()));
             //migrate module information
             if (!empty($info)) {
                 $modules[$module_slug] = array_merge($modules[$module_slug], $info);
             }
             HW_Plugins_Manager::register_module($modules[$module_slug]);
             //update module data
             $inst->option('module_info', $modules[$module_slug]);
         }
         $inst->option('module_url', HW_HOANGWEB_PLUGINS_URL . '/' . $module_slug);
         HW_Module_Settings_page::add_module($module_slug, $inst);
         //setup actions belong to current module instance
         self::setup_actions($inst);
         //occur after all modules loaded
         add_action('hw_modules_loaded', array($inst, 'modules_loaded'));
         //after the module loaded
         if (method_exists($inst, 'module_loaded')) {
             $inst->module_loaded();
         }
         //load cli class for the module
         $command = $inst->get_module_cli_path();
         if (!empty($command) && defined('WP_CLI') && WP_CLI) {
             include_once $command;
             $cli_class = 'HW_CLI_' . HW_Validation::valid_objname($module_slug);
             //command line class
             WP_CLI::add_command($module_slug, strtoupper($cli_class));
             //WP_CLI::get_command(); #wrong
             //add module commands to manager
             HW_CLI_Command_Utilities::get_instance()->register_cli_cmds($module_slug, HW_Core::get_child_class_methods($cli_class, ReflectionMethod::IS_PUBLIC));
         }
         //load oher cli class for module
         $cli_files = $inst->get_commands();
         if (is_array($cli_files)) {
             foreach ($cli_files as $cli) {
                 //not found file to process command line,
                 if (!$cli) {
                     continue;
                 }
                 //!isset($cli['file']) purpose for module->register_cli that more cli class write in one file
                 if (isset($cli['file'])) {
                     include_once $cli['file'];
                 }
                 if (class_exists($cli['class'], false)) {
                     WP_CLI::add_command($cli['command'], $cli['class']);
                     //add module commands to manager
                     HW_CLI_Command_Utilities::get_instance()->register_cli_cmds($cli['command'], HW_Core::get_child_class_methods($cli['class'], ReflectionMethod::IS_PUBLIC));
                 }
             }
         }
     }
 }