/** * Initialize IG Library. * * @return void */ public static function init() { global $pagenow; if ('admin-ajax.php' == $pagenow && isset($_GET['action']) && in_array($_GET['action'], self::$actions)) { // Init WordPress Filesystem Abstraction IG_Init_File_System::get_instance(); // Register Ajax actions switch ($_GET['action']) { case 'ig-addons-management': IG_Product_Addons::hook(); break; } } // Add filter to fine-tune uploaded file name add_filter('wp_handle_upload_prefilter', array(__CLASS__, 'wp_handle_upload_prefilter')); // Do 'ig_init' action do_action('ig_init'); }
/** * Detect plugin file of installed add-on and activate plugin. * * @param string $addon Identified name of add-on (as defined in InnoGears server). * @param string $action Last executed action. * * return void */ protected static function activate($addon, $action = '') { // Check capabilities if (!current_user_can('activate_plugins')) { throw new Exception(__('You do not have sufficient permissions to activate plugins for this site.')); } // Get WordPress's WordPress Filesystem Abstraction object $wp_filesystem = IG_Init_File_System::get_instance(); // Get plugin slug $plugin = self::check($addon, false); if (empty($plugin)) { throw new Exception(__('Cannot detect plugin to activate.', IG_LIBRARY_TEXTDOMAIN)); } // Activate plugin $result = activate_plugin($plugin, '', is_network_admin()); if (is_wp_error($result)) { return array('success' => true, 'addon' => $addon, 'action' => $action, 'message' => $result->get_error_message()); } }
/** * Get all available data converters. * * @return array */ public static function get_converters() { global $post; // Initialize WordPress Filesystem Abstraction $wp_filesystem = IG_Init_File_System::get_instance(); // Get available data converter $files = $wp_filesystem->dirlist(dirname(__FILE__)); $converters = array(); foreach ($files as $file) { if ('converter.php' != $file['name']) { $converter = substr($file['name'], 0, -4); // Generate data converter class name $class = explode('-', $converter); $class = array_map('ucfirst', $class); $class = 'IG_Pb_Converter_' . implode('_', $class); if (class_exists($class, true)) { // Check if there is data to convert if (call_user_func(array($class, 'check'), $post)) { $converters[$converter] = ucwords(str_replace('-', ' ', substr($file['name'], 0, -4))); } } } } // Allow 3rd-party plugin to hook into data conversion $converters = apply_filters('ig_pb_get_data_converters', $converters); return $converters; }
/** * Get latest product info from InnoGears server. * * @return array */ protected static function info() { global $pagenow; // Get WordPress's WordPress Filesystem Abstraction object $wp_filesystem = IG_Init_File_System::get_instance(); // Request InnoGears server for product info only if not available if (!isset(self::$product_info_data)) { // Generate path to cache file $path = wp_upload_dir(); $path = $path['basedir'] . '/innogears/cache'; if (!@is_dir($path)) { $result = explode('/', str_replace('\\', '/', $path)); $path = array(); while (count($result)) { $path[] = current($result); if (!@is_dir(implode('/', $path))) { $wp_filesystem->mkdir(implode('/', $path), 0755); } // Shift paths array_shift($result); } } $path = (is_array($path) ? implode('/', $path) : $path) . '/product_info.json'; // Check if we need to get product info from InnoGears.com server $refresh = false; if ('admin.php' == $pagenow && isset($_GET['page']) && preg_match('/^ig-.+-addons$/', $_GET['page'])) { $refresh = true; } if (!$wp_filesystem->is_file($path) || self::$cache_time < time() - $wp_filesystem->mtime($path)) { $refresh = true; } if ($refresh) { // Request InnoGears.com server for product info $result = download_url(self::$product_info); if (!is_wp_error($result)) { self::$product_info_data = json_decode($wp_filesystem->get_contents($result)); if (self::$product_info_data) { // Move temporary file to cache folder $wp_filesystem->move($result, $path, true); } else { // Remove temporary file $wp_filesystem->delete($result); } } } else { // Get product info from cache file self::$product_info_data = json_decode($wp_filesystem->get_contents($path)); } } return self::$product_info_data; }