예제 #1
0
 /**
  * Display a list of all h5p content libraries.
  *
  * @since 1.1.0
  */
 private function display_content_upgrades($library)
 {
     global $wpdb;
     $plugin = H5P_Plugin::get_instance();
     $core = $plugin->get_h5p_instance('core');
     $interface = $plugin->get_h5p_instance('interface');
     $versions = $wpdb->get_results($wpdb->prepare("SELECT hl2.id, hl2.name, hl2.title, hl2.major_version, hl2.minor_version, hl2.patch_version\n          FROM {$wpdb->prefix}h5p_libraries hl1\n          JOIN {$wpdb->prefix}h5p_libraries hl2\n            ON hl2.name = hl1.name\n          WHERE hl1.id = %d\n          ORDER BY hl2.title ASC, hl2.major_version ASC, hl2.minor_version ASC", $library->id));
     foreach ($versions as $version) {
         if ($version->id === $library->id) {
             $upgrades = $core->getUpgrades($version, $versions);
             break;
         }
     }
     if (count($versions) < 2) {
         H5P_Plugin_Admin::set_error(__('There are no available upgrades for this library.', $this->plugin_slug));
         return NULL;
     }
     // Get num of contents that can be upgraded
     $contents = $interface->getNumContent($library->id);
     if (!$contents) {
         H5P_Plugin_Admin::set_error(__("There's no content instances to upgrade.", $this->plugin_slug));
         return NULL;
     }
     $contents_plural = sprintf(_n('1 content', '%d contents', $contents, $this->plugin_slug), $contents);
     // Add JavaScript settings
     $return = filter_input(INPUT_GET, 'destination');
     $settings = array('containerSelector' => '#h5p-admin-container', 'libraryInfo' => array('message' => sprintf(__('You are about to upgrade %s. Please select upgrade version.', $this->plugin_slug), $contents_plural), 'inProgress' => __('Upgrading to %ver...', $this->plugin_slug), 'error' => __('An error occurred while processing parameters:', $this->plugin_slug), 'errorData' => __('Could not load data for library %lib.', $this->plugin_slug), 'errorContent' => __('Could not upgrade content %id:', $this->plugin_slug), 'errorScript' => __('Could not load upgrades script for %lib.', $this->plugin_slug), 'errorParamsBroken' => __('Parameters are broken.', $this->plugin_slug), 'done' => sprintf(__('You have successfully upgraded %s.', $this->plugin_slug), $contents_plural) . ($return ? '<br/><a href="' . $return . '">' . __('Return', $this->plugin_slug) . '</a>' : ''), 'library' => array('name' => $library->name, 'version' => $library->major_version . '.' . $library->minor_version), 'libraryBaseUrl' => admin_url('admin-ajax.php?action=h5p_content_upgrade_library&library='), 'scriptBaseUrl' => plugins_url('h5p/h5p-php-library/js'), 'buster' => '?ver=' . H5P_Plugin::VERSION, 'versions' => $upgrades, 'contents' => $contents, 'buttonLabel' => __('Upgrade', $this->plugin_slug), 'infoUrl' => admin_url('admin-ajax.php?action=h5p_content_upgrade_progress&id=' . $library->id), 'total' => $contents, 'token' => wp_create_nonce('h5p_content_upgrade')));
     $this->add_admin_assets();
     H5P_Plugin_Admin::add_script('version', 'h5p-php-library/js/h5p-version.js');
     H5P_Plugin_Admin::add_script('content-upgrade', 'h5p-php-library/js/h5p-content-upgrade.js');
     return $settings;
 }
 /**
  * Get input post data field title. Validates.
  *
  * @since 1.1.0
  * @return string
  */
 public function get_input_title()
 {
     $title = $this->get_input('title');
     if ($title === NULL) {
         return NULL;
     }
     // Trim title and check length
     $trimmed_title = trim($title);
     if ($trimmed_title === '') {
         H5P_Plugin_Admin::set_error(sprintf(__('Missing %s.', $this->plugin_slug), 'title'));
         return NULL;
     }
     if (strlen($trimmed_title) > 255) {
         H5P_Plugin_Admin::set_error(__('Title is too long. Must be 256 letters or shorter.', $this->plugin_slug));
         return NULL;
     }
     return $trimmed_title;
 }