/** * Insert a new row * @access public * @param primary_resource_id, file_name, language_code * @return table rows * @author Cindy Qi Li */ public function Create($primary_resource_id, $file_name, $lang) { global $addslashes; $primary_resource_id = intval($primary_resource_id); $file_name = $addslashes(convertAmp($file_name)); $lang = $addslashes($lang); $sql = "INSERT INTO " . TABLE_PREFIX . "secondary_resources \n\t\t SET primary_resource_id={$primary_resource_id}, \n\t\t secondary_resource='{$file_name}', \n\t\t language_code='{$lang}'"; return $this->execute($sql); }
function populate_a4a($cid, $content, $formatting) { global $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 TR_INCLUDE_PATH . 'classes/A4a/A4a.class.php'; include_once TR_INCLUDE_PATH . 'classes/XML/XML_HTMLSax/XML_HTMLSax.php'; /* for XML_HTMLSax */ include_once TR_INCLUDE_PATH . 'classes/ContentOutputParser.class.php'; /* for parser */ // initialize content_base_href; used in format_content if (!isset($content_base_href)) { $content_row = $contentManager->getContentPage($cid); // return if the cid is not found if (!is_array($content_row)) { return; } $content_base_href = $content_row["content_path"] . '/'; } $body = ContentUtility::formatContent($content, $formatting); $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 = ContentUtility::convertYoutubePlayURLToWatchURL($file); $resources[] = convertAmp($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']); } } }