/**
  * This function will unlink tmp editor files for content
  * that has never been saved.
  *
  * @since 1.0.0
  */
 public function remove_old_tmp_files()
 {
     $plugin = H5P_Plugin::get_instance();
     $h5p_path = $plugin->get_h5p_path();
     $editor_path = $h5p_path . DIRECTORY_SEPARATOR . 'editor';
     if (!is_dir($h5p_path) || !is_dir($editor_path)) {
         return;
     }
     foreach (glob($editor_path . DIRECTORY_SEPARATOR . '*') as $dir) {
         if (is_dir($dir)) {
             foreach (glob($dir . DIRECTORY_SEPARATOR . '*') as $file) {
                 if (time() - filemtime($file) > 86400) {
                     // Not modified in over a day
                     unlink($file);
                 }
             }
         }
     }
 }
 /**
  * Print settings, adds JavaScripts and stylesheets necessary for providing
  * a data view.
  *
  * @since 1.2.0
  * @param string $name of the data view
  * @param string $source URL for data
  * @param array $headers for the table
  */
 public function print_data_view_settings($name, $source, $headers, $filters, $empty, $order)
 {
     // Add JS settings
     $data_views = array();
     $data_views[$name] = array('source' => $source, 'headers' => $headers, 'filters' => $filters, 'order' => $order, 'l10n' => array('loading' => __('Loading data.', $this->plugin_slug), 'ajaxFailed' => __('Failed to load data.', $this->plugin_slug), 'noData' => __("There's no data available that matches your criteria.", $this->plugin_slug), 'currentPage' => __('Page $current of $total', $this->plugin_slug), 'nextPage' => __('Next page', $this->plugin_slug), 'previousPage' => __('Previous page', $this->plugin_slug), 'search' => __('Search', $this->plugin_slug), 'empty' => $empty));
     $plugin = H5P_Plugin::get_instance();
     $settings = array('dataViews' => $data_views);
     $plugin->print_settings($settings);
     // Add JS
     H5P_Plugin_Admin::add_script('jquery', 'h5p-php-library/js/jquery.js');
     H5P_Plugin_Admin::add_script('utils', 'h5p-php-library/js/h5p-utils.js');
     H5P_Plugin_Admin::add_script('data-view', 'h5p-php-library/js/h5p-data-view.js');
     H5P_Plugin_Admin::add_script('data-views', 'admin/scripts/h5p-data-views.js');
     H5P_Plugin_Admin::add_style('admin', 'h5p-php-library/styles/h5p-admin.css');
 }
Exemplo n.º 3
0
 /**
  * AJAX loading of libraries for content upgrade script.
  *
  * @since 1.1.0
  * @param string $name
  * @param int $major
  * @param int $minor
  */
 public function ajax_upgrade_library()
 {
     header('Cache-Control: no-cache');
     $library_string = filter_input(INPUT_GET, 'library');
     if (!$library_string) {
         print __('Error, missing library!', $this->plugin_slug);
         exit;
     }
     $library_parts = explode('/', $library_string);
     if (count($library_parts) !== 4) {
         print __('Error, invalid library!', $this->plugin_slug);
         exit;
     }
     $library = (object) array('name' => $library_parts[1], 'version' => (object) array('major' => $library_parts[2], 'minor' => $library_parts[3]));
     $plugin = H5P_Plugin::get_instance();
     $core = $plugin->get_h5p_instance('core');
     $library->semantics = $core->loadLibrarySemantics($library->name, $library->version->major, $library->version->minor);
     if ($library->semantics === NULL) {
         print __('Error, could not library semantics!', $this->plugin_slug);
         exit;
     }
     // TODO: Library development mode
     //    if ($core->development_mode & H5PDevelopment::MODE_LIBRARY) {
     //      $dev_lib = $core->h5pD->getLibrary($library->name, $library->version->major, $library->version->minor);
     //    }
     if (isset($dev_lib)) {
         $upgrades_script_path = $upgrades_script_url = $dev_lib['path'] . '/upgrades.js';
     } else {
         $suffix = '/libraries/' . $library->name . '-' . $library->version->major . '.' . $library->version->minor . '/upgrades.js';
         $upgrades_script_path = $plugin->get_h5p_path() . $suffix;
         $upgrades_script_url = $plugin->get_h5p_url() . $suffix;
     }
     if (file_exists($upgrades_script_path)) {
         $library->upgradesScript = $upgrades_script_url;
     }
     header('Content-type: application/json');
     print json_encode($library);
     exit;
 }
 /**
  * Provide data for content results view.
  *
  * @since 1.2.0
  */
 public function ajax_content_results()
 {
     $id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
     if (!$id) {
         return;
         // Missing id
     }
     $plugin = H5P_Plugin::get_instance();
     $content = $plugin->get_content($id);
     if (is_string($content) || !$this->current_user_can_edit($content)) {
         return;
         // Error loading content or no access
     }
     $plugin_admin = H5P_Plugin_Admin::get_instance();
     $plugin_admin->print_results($id);
 }
Exemplo n.º 5
0
/**
 * Fired when the h5p plugin is uninstalled.
 *
 * @package   H5P
 * @author    Joubel <*****@*****.**>
 * @license   MIT
 * @link      http://joubel.com
 * @copyright 2014 Joubel
 */
// If uninstall not called from WordPress, then exit
if (!defined('WP_UNINSTALL_PLUGIN')) {
    exit;
}
require_once plugin_dir_path(__FILE__) . 'autoloader.php';
$plugin = H5P_Plugin::get_instance();
$plugin->get_library_updates();
global $wp_roles;
if (!isset($wp_roles)) {
    $wp_roles = new WP_Roles();
}
// Remove capabilities
$all_roles = $wp_roles->roles;
foreach ($all_roles as $role_name => $role_info) {
    $role = get_role($role_name);
    if (isset($role_info['capabilities']['manage_h5p_libraries'])) {
        $role->remove_cap('manage_h5p_libraries');
    }
    if (isset($role_info['capabilities']['edit_others_h5p_contents'])) {
        $role->remove_cap('edit_others_h5p_contents');
    }
Exemplo n.º 6
0
 /**
  * Helper
  */
 private function getH5pPath()
 {
     $plugin = H5P_Plugin::get_instance();
     return $plugin->get_h5p_path();
 }
 /**
  * Implements alterLibrarySemantics
  *
  * Gives you a chance to alter all the library files.
  */
 public function alterLibraryFiles(&$files, $libraries)
 {
     $plugin = H5P_Plugin::get_instance();
     $plugin->alter_assets($files, $libraries, 'editor');
 }
 /**
  * Implements getUploadedH5PPath
  */
 public function getUploadedH5pPath()
 {
     static $path;
     if (is_null($path)) {
         $plugin = H5P_Plugin::get_instance();
         $core = $plugin->get_h5p_instance('core');
         $path = $core->fs->getTmpPath() . '.h5p';
     }
     return $path;
 }