/**
 * @param 
 * @param   int     course id, which should be in $_SESSION, but during export to AContent,
 *                  SESSION is not available, thus we will have to use parameters
 */
function get_html_resources($text, $course_id = 0)
{
    $resources = array();
    if ($course_id == 0) {
        $course_id = $_SESSION['course_id'];
    }
    $handler = new XML_HTMLSax_Handler();
    $parser = new XML_HTMLSax();
    $parser->set_object($handler);
    $parser->set_element_handler('openHandler', 'closeHandler');
    $parser->parse($text);
    foreach ($handler->resources as $resource) {
        $url_parts = @parse_url($resource);
        if (isset($url_parts['scheme'])) {
            // we don't want full urls
            continue;
        }
        if (substr($resource, 0, 1) == '/') {
            // we don't want absolute urls
            continue;
        }
        // make sure this resource exists in this course's content directory:
        $resource_server_path = realpath(AT_CONTENT_DIR . $course_id . '/' . $resource);
        if (file_exists($resource_server_path) && is_file($resource_server_path)) {
            $resources[$resource] = $resource_server_path;
        }
    }
    return $resources;
}
Ejemplo n.º 2
0
    }
}
/* get all the content */
$handler = new MyHandler();
$parser = new XML_HTMLSax();
$parser->set_object($handler);
$parser->set_element_handler('openHandler', 'closeHandler');
/* generate the resources and save the HTML files */
global $parser, $my_files;
global $course_id;
/* add the resource dependancies */
$my_files = array();
$content_files = "\n";
//in order to control if some [media] is in the body_text
//$body = ContentUtility::embedMedia($body_t);
$parser->parse($body);
// find all [media] resources
preg_match_all("/\\[media[0-9a-z\\|]*\\](.*)\\[\\/media\\]/i", $body, $media_matches);
$my_files = array_merge($media_matches[1], $my_files);
// add by Cindy Li.
// This resolves the problem introduced by [media] tag: when [media] is
// parsed into <object>, same resource appears a few times in <object> with different
// format to cater for different browsers or players. This way creates problem that different
// formats in <object> are all parsed and considered as different resource. array_unique()
// call solves this problem. But, it introduces the new problem that when a same resource
// appears at different places in the content and users do want to have them with different
// alternatives. With this solution, this same resource only shows up once at "adapt content"
// and only can have one alternative associated with. Table and scripts need to be re-designed
// to solve this problem, for example, include line number in table.
$my_files = array_unique($my_files);
/* handle @import */
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']);
        }
    }
}
Ejemplo n.º 4
0
	if ($_REQUEST['dictionary'] != "") {
		$GLOBALS['dict'] = $_REQUEST['dictionary'];
	}
}
*/
/*
// leave out the dicrtionary support for the moment
if ($_REQUEST['init'] == 1) {
	// don't put spaces between these as js is going to tokenize them up
	echo "<div id='HA-spellcheck-dictionaries'>en,en_GB,en_US,en_CA,sv_SE,de_DE,pt_PT</div>";
}
*/
if (get_magic_quotes_gpc()) {
    foreach ($_REQUEST as $k => $v) {
        $_REQUEST["{$k}"] = stripslashes($v);
    }
}
require_once DIRNAME(__FILE__) . '/spell_parser.inc';
require_once 'XML/XML_HTMLSax.php';
$handler = new Spell_Parser();
$handler->setLanguage($GLOBALS['dict']);
$parser = new XML_HTMLSax();
$parser->set_object($handler);
$parser->set_element_handler('openHandler', 'closeHandler');
$parser->set_data_handler('dataHandler');
$string_to_parse = stripslashes($_POST['content']);
$parser->parse($string_to_parse);
?>
	<body>
</html>
Ejemplo n.º 5
0
/**
 * Get PukiWiki Page List via http using cmd=filelist
 * @access public
 * @param string $url PukiWiki URL (cmd=filelist)
 * @return array 
 *     Page list whose each element has keys 'href', 'page', 'file'. 
 *     FALSE if HTTP GET failed. 
 * @uses PKWKFilelistHandler
 * @uses PEAR XML/XML_HTMLSax.php
 * @uses $GLOBALS['ADMINPASS']
 * @uses $GLOBALS['USERNAME']
 * @uses $GLOBALS['USERPASS']
 */
function &pkwk_get_existpages($url, $filter = NULL, $except = NULL)
{
    $parsed = parse_url($url);
    $queries = array();
    parse_str($parsed['query'], $queries);
    $cmd = $queries['cmd'];
    if ($cmd == 'filelist' && $GLOBALS['ADMINPASS'] != '') {
        // POST adminpass
        require_once 'HTTP/Request.php';
        $req = new HTTP_Request($url);
        $req->setMethod(HTTP_REQUEST_METHOD_POST);
        $req->addPostData('pass', $GLOBALS['ADMINPASS']);
        $req->setBasicAuth($GLOBALS['USERNAME'], $GLOBALS['USERPASS']);
        if (PEAR::isError($req->sendRequest())) {
            return FALSE;
        }
        $html = $req->getResponseBody();
    } else {
        if (($html = http_get_contents($url, $GLOBALS['USERNAME'], $GLOBALS['USERPASS'])) === FALSE) {
            return FALSE;
        }
    }
    require_once 'XML/XML_HTMLSax.php';
    $parser = new XML_HTMLSax();
    $handler = new PKWKFilelistHandler();
    $parser->set_object($handler);
    $parser->set_element_handler('openHandler', 'closeHandler');
    $parser->set_data_handler('dataHandler');
    $parser->parse($html);
    if ($filter !== NULL) {
        $pregfilter = '/' . str_replace('/', '\\/', $filter) . '/';
        foreach ($handler->pages as $i => $page) {
            if (!preg_match($pregfilter, $page['page'])) {
                unset($handler->pages[$i]);
            }
        }
    }
    if ($except !== NULL) {
        $pregexcept = '/' . str_replace('/', '\\/', $except) . '/';
        foreach ($handler->pages as $i => $page) {
            if (preg_match($pregexcept, $page['page'])) {
                unset($handler->pages[$i]);
            }
        }
    }
    if ($cmd != 'filelist') {
        foreach ($handler->pages as $i => $page) {
            $handler->pages[$i]['file'] = get_wikifilename($page['page']);
        }
    }
    // unique (probably this can be done in html parsing process concurrently, though)
    $uniq_pages = array();
    foreach ($handler->pages as $page) {
        $uniq_pages[] = $page['page'];
    }
    $uniq_pages = array_unique($uniq_pages);
    $pages = array();
    foreach ($uniq_pages as $i => $page) {
        $pages[] = $handler->pages[$i];
    }
    return $pages;
}