/** * Get information for this content * @return the xml content */ function getAlternative() { $resources = parent::getPrimaryResources(); foreach ($resources as $rid => $prop) { $resources_types = parent::getPrimaryResourcesTypes($rid); if (empty($resources_types)) { //if there are no resource types, then don't use it. continue; } $temp = array(); $secondary_array = array(); foreach ($resources_types as $rtid) { $sec_resources['secondary_resources'] = parent::getSecondaryResources($rid); //determine secondary resource type foreach ($sec_resources['secondary_resources'] as $sec_id => $sec_resource) { $current_sec_file = $sec_resource['resource']; $secondary_array['secondary_resources'][] = $current_sec_file; //add to secondary file array if it's not there if (!isset($this->original_files[$current_sec_file]) || empty($this->original_files[$current_sec_file])) { //TODO merge these values i think $this->original_files[$current_sec_file] = $sec_resource; $this->original_files[$current_sec_file]['resource_type'][$prop['resource']][] = parent::getSecondaryResourcesTypes($sec_id); } else { $this->original_files[$current_sec_file]['resource_type'][$prop['resource']][] = parent::getSecondaryResourcesTypes($sec_id); } //add this primary file ref, and the resources type to the secondary file $this->original_files[$current_sec_file]['primary_resources'][$prop['resource']] = $rtid; // $this->original_files[$current_sec_file]['primary_resources'][$prop['resource']]['language_code'] = $sec_resource['language_code']; } } $res_type['resource_type'] = $rtid; //could be 1+ $temp = array_merge($prop, $res_type, $secondary_array); if (isset($this->original_files[$temp['resource']])) { //use the existing temp array values, but merge in the secondary_array $temp = array_merge($this->original_files[$temp['resource']], $secondary_array); } if (!empty($temp)) { $this->original_files[$temp['resource']] = $temp; } } return $this->original_files; }
function populate_a4a($cid, $content, $formatting) { global $db, $my_files, $content_base_href, $contentManager; // Defining alternatives is only available for content type "html". // But don't clean up the a4a tables at other content types in case the user needs them back at html. if ($formatting != 1) { return; } include_once AT_INCLUDE_PATH . '../mods/_core/imsafa/classes/A4a.class.php'; include_once AT_INCLUDE_PATH . 'classes/XML/XML_HTMLSax/XML_HTMLSax.php'; /* for XML_HTMLSax */ include_once AT_INCLUDE_PATH . 'classes/ContentOutputParser.class.php'; /* for parser */ // initialize content_base_href; used in format_content if (!isset($content_base_href)) { $result = $contentManager->getContentPage($cid); // return if the cid is not found foreach ($result as $content_row) { if (count($content_row) < 1) { return; } else { $content_base_href = $content_row["content_path"] . '/'; } } } $body = format_content($content, $formatting, array()); $handler = new ContentOutputParser(); $parser = new XML_HTMLSax(); $parser->set_object($handler); $parser->set_element_handler('openHandler', 'closeHandler'); $my_files = array(); $parser->parse($body); $my_files = array_unique($my_files); foreach ($my_files as $file) { /* filter out full urls */ $url_parts = @parse_url($file); // file should be relative to content if (substr($file, 0, 1) == '/') { continue; } // The URL of the movie from youtube.com has been converted above in embed_media(). // For example: http://www.youtube.com/watch?v=a0ryB0m0MiM is converted to // http://www.youtube.com/v/a0ryB0m0MiM to make it playable. This creates the problem // that the parsed-out url (http://www.youtube.com/v/a0ryB0m0MiM) does not match with // the URL saved in content table (http://www.youtube.com/watch?v=a0ryB0m0MiM). // The code below is to convert the URL back to original. $file = convert_youtube_playURL_to_watchURL($file); $resources[] = convert_amp($file); // converts & to & } $a4a = new A4a($cid); $db_primary_resources = $a4a->getPrimaryResources(); // clean up the removed resources foreach ($db_primary_resources as $primary_rid => $db_resource) { //if this file from our table is not found in the $resource, then it's not used. if (count($resources) == 0 || !in_array($db_resource['resource'], $resources)) { $a4a->deletePrimaryResource($primary_rid); } } if (count($resources) == 0) { return; } // insert the new resources foreach ($resources as $primary_resource) { if (!$a4a->getPrimaryResourceByName($primary_resource)) { $a4a->setPrimaryResource($cid, $primary_resource, $_SESSION['lang']); } } }
echo ' <div id="' . $pid . '_' . $alternative_type . '">' . "\n"; echo ' <input type="button" value="' . _AT('add') . '" title="' . _AT('new_window') . '" onclick="ATutor.poptastic(\'' . AT_BASE_HREF . 'mods/_core/file_manager/index.php?framed=1' . SEP . 'popup=1' . SEP . 'cp=' . $content_row['content_path'] . SEP . 'cid=' . $content_id . SEP . 'pid=' . $pid . SEP . 'a_type=' . $alternative_type . '\');return false;" />' . "\n"; echo ' </div>' . "\n"; } echo ' </td>' . "\n"; } // Main program if ($_POST['formatting'] != 1) { $msg->addFeedback('NO_A4A_FOR_PLAIN_TEXT'); $msg->printAll(); } else { global $db, $content_row, $stripslashes; populate_a4a($cid, $stripslashes($_POST['body_text']), $_POST['formatting']); include_once AT_INCLUDE_PATH . '../mods/_core/imsafa/classes/A4a.class.php'; $a4a = new A4a($cid); $primary_resources = $a4a->getPrimaryResources(); if (count($primary_resources) == 0) { $msg->addFeedback('NO_RESOURCES'); $msg->printAll(); } else { $is_post_indicator_set = false; // get all resource types $sql = "SELECT * FROM %sresource_types"; $rows_resource_types = queryDB($sql, array(TABLE_PREFIX)); echo '<table class="data" rules="all">' . "\n"; echo ' <thead>' . "\n"; echo ' <tr>' . "\n"; echo ' <th rowspan="2" id="header1">' . _AT('original_resource') . '</th>' . "\n"; echo ' <th rowspan="2" id="header2">' . _AT('resource_type') . '</th>' . "\n"; echo ' <th colspan="4">' . _AT('alternatives') . '</th>' . "\n"; echo ' </tr>' . "\n";