Example #1
0
 /**
  * Filter content run parameters, rebuild content dependecy cache and export file.
  *
  * @param Object $content
  * @return Object NULL on failure.
  */
 public function filterParameters(&$content)
 {
     if (isset($content['filtered']) && $content['filtered'] !== '') {
         return $content['filtered'];
     }
     // Validate and filter against main library semantics.
     $validator = new H5PContentValidator($this->h5pF, $this);
     $params = (object) array('library' => H5PCore::libraryToString($content['library']), 'params' => json_decode($content['params']));
     if (!$params->params) {
         return NULL;
     }
     $validator->validateLibrary($params, (object) array('options' => array($params->library)));
     $params = json_encode($params->params);
     // Update content dependencies.
     $content['dependencies'] = $validator->getDependencies();
     // Sometimes the parameters are filtered before content has been created
     if ($content['id']) {
         $this->h5pF->deleteLibraryUsage($content['id']);
         $this->h5pF->saveLibraryUsage($content['id'], $content['dependencies']);
         if (!$content['slug']) {
             $content['slug'] = $this->generateContentSlug($content);
             // Remove old export file
             $oldExport = $this->path . '/exports/' . $content['id'] . '.h5p';
             if (file_exists($oldExport)) {
                 unlink($oldExport);
             }
         }
         if ($this->exportEnabled) {
             // Recreate export file
             $exporter = new H5PExport($this->h5pF, $this);
             $exporter->createExportFile($content);
         }
         // Cache.
         $this->h5pF->updateContentFields($content['id'], array('filtered' => $params, 'slug' => $content['slug']));
     }
     return $params;
 }
Example #2
0
 private function _validateFilelike(&$file, $semantics, $typevalidkeys = array())
 {
     // Make sure path and mime does not have any special chars
     $file->path = htmlspecialchars($file->path, ENT_QUOTES, 'UTF-8', FALSE);
     if (isset($file->mime)) {
         $file->mime = htmlspecialchars($file->mime, ENT_QUOTES, 'UTF-8', FALSE);
     }
     // Remove attributes that should not exist, they may contain JSON escape
     // code.
     $validkeys = array_merge(array('path', 'mime', 'copyright'), $typevalidkeys);
     if (isset($semantics->extraAttributes)) {
         $validkeys = array_merge($validkeys, $semantics->extraAttributes);
         // TODO: Validate extraAttributes
     }
     $this->filterParams($file, $validkeys);
     if (isset($file->width)) {
         $file->width = intval($file->width);
     }
     if (isset($file->height)) {
         $file->height = intval($file->height);
     }
     if (isset($file->codecs)) {
         $file->codecs = htmlspecialchars($file->codecs, ENT_QUOTES, 'UTF-8', FALSE);
     }
     if (isset($file->quality)) {
         if (!is_object($file->quality) || !isset($file->quality->level) || !isset($file->quality->label)) {
             unset($file->quality);
         } else {
             $this->filterParams($file->quality, array('level', 'label'));
             $file->quality->level = intval($file->quality->level);
             $file->quality->label = htmlspecialchars($file->quality->label, ENT_QUOTES, 'UTF-8', FALSE);
         }
     }
     if (isset($file->copyright)) {
         $this->validateGroup($file->copyright, H5PContentValidator::getCopyrightSemantics());
     }
 }
 /**
  * Add assets and JavaScript settings for the editor.
  *
  * @since 1.1.0
  * @param int $id optional content identifier
  */
 public function add_editor_assets($id = NULL)
 {
     $plugin = H5P_Plugin::get_instance();
     $plugin->add_core_assets();
     // Make sure the h5p classes are loaded
     $plugin->get_h5p_instance('core');
     $this->get_h5peditor_instance();
     // Add JavaScript settings
     $settings = $plugin->get_settings();
     $cache_buster = '?ver=' . H5P_Plugin::VERSION;
     // Use jQuery and styles from core.
     $assets = array('css' => $settings['core']['styles'], 'js' => $settings['core']['scripts']);
     // Use relative URL to support both http and https.
     $upload_dir = plugins_url('h5p/h5p-editor-php-library');
     $url = '/' . preg_replace('/^[^:]+:\\/\\/[^\\/]+\\//', '', $upload_dir) . '/';
     // Add editor styles
     foreach (H5peditor::$styles as $style) {
         $assets['css'][] = $url . $style . $cache_buster;
     }
     // Add editor JavaScript
     foreach (H5peditor::$scripts as $script) {
         // We do not want the creator of the iframe inside the iframe
         if ($script !== 'scripts/h5peditor-editor.js') {
             $assets['js'][] = $url . $script . $cache_buster;
         }
     }
     // Add JavaScript with library framework integration (editor part)
     H5P_Plugin_Admin::add_script('editor-editor', 'h5p-editor-php-library/scripts/h5peditor-editor.js');
     H5P_Plugin_Admin::add_script('editor', 'admin/scripts/h5p-editor.js');
     // Add translation
     $language = $plugin->get_language();
     $language_script = 'h5p-editor-php-library/language/' . $language . '.js';
     if (!file_exists(plugin_dir_path(__FILE__) . '../' . $language_script)) {
         $language_script = 'h5p-editor-php-library/language/en.js';
     }
     H5P_Plugin_Admin::add_script('language', $language_script);
     // Add JavaScript settings
     $settings['editor'] = array('filesPath' => $plugin->get_h5p_url() . '/editor', 'fileIcon' => array('path' => plugins_url('h5p/h5p-editor-php-library/images/binary-file.png'), 'width' => 50, 'height' => 50), 'ajaxPath' => admin_url('admin-ajax.php?action=h5p_'), 'libraryUrl' => plugin_dir_url('h5p/h5p-editor-php-library/h5peditor.class.php'), 'copyrightSemantics' => H5PContentValidator::getCopyrightSemantics(), 'assets' => $assets, 'deleteMessage' => __('Are you sure you wish to delete this content?', $this->plugin_slug));
     if ($id !== NULL) {
         $settings['editor']['nodeVersionId'] = $id;
     }
     $plugin->print_settings($settings);
 }