Example #1
0
 function setSecondaryResource($primary_resource_id, $file_name, $lang)
 {
     global $addslashes, $db;
     $primary_resource_id = intval($primary_resource_id);
     $file_name = $addslashes(convert_amp($file_name));
     $lang = $addslashes($lang);
     $sql = "INSERT INTO " . TABLE_PREFIX . "secondary_resources SET primary_resource_id={$primary_resource_id}, secondary_resource='{$file_name}', language_code='{$lang}'";
     $result = mysql_query($sql, $db);
     if ($result) {
         return mysql_insert_id();
     }
     return false;
 }
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 &amp;
    }
    $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']);
        }
    }
}
Example #3
0
 function setSecondaryResource($primary_resource_id, $file_name, $lang)
 {
     global $addslashes;
     $primary_resource_id = intval($primary_resource_id);
     $file_name = $addslashes(convert_amp($file_name));
     $lang = $addslashes($lang);
     $sql = "INSERT INTO %ssecondary_resources SET primary_resource_id=%d, secondary_resource='%s', language_code='%s'";
     $result = queryDB($sql, array(TABLE_PREFIX, $primary_resource_id, $file_name, $lang));
     if ($result > 0) {
         return at_insert_id();
     }
     return false;
 }