コード例 #1
0
/**
 * @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;
}
コード例 #2
0
ファイル: ims_export.php プロジェクト: harriswong/AContent
/* to retrieve content resources/medias from at_content[text] */
require_once TR_INCLUDE_PATH . '../home/imscc/include/ims_template.inc.php';
/* for ims templates + print_organizations() */
if (isset($_POST['cancel'])) {
    $msg->addFeedback('EXPORT_CANCELLED');
    header('Location: ../index.php');
    exit;
}
$zipfile = new zipfile();
$zipfile->create_dir('resources/');
/* get all the content */
$content = array();
$paths = array();
$top_content_parent_id = 0;
$handler = new ContentOutputParser();
$parser = new XML_HTMLSax();
$parser->set_object($handler);
$parser->set_element_handler('openHandler', 'closeHandler');
$contentDAO = new ContentDAO();
$rows = $contentDAO->getContentByCourseID($course_id);
//if (authenticate(TR_PRIV_CONTENT, TR_PRIV_RETURN)) {
//	$sql = "SELECT *, UNIX_TIMESTAMP(last_modified) AS u_ts FROM ".TABLE_PREFIX."content WHERE course_id=$course_id ORDER BY content_parent_id, ordering";
//} else {
//	$sql = "SELECT *, UNIX_TIMESTAMP(last_modified) AS u_ts FROM ".TABLE_PREFIX."content WHERE course_id=$course_id ORDER BY content_parent_id, ordering";
//}
//$result = mysql_query($sql, $db);
//$cid = $_REQUEST['cid'];  //takes care of some system which lost the REQUEST[cid]
//while ($row = mysql_fetch_assoc($result)) {
//	if (authenticate(TR_PRIV_CONTENT, TR_PRIV_RETURN) || $contentManager->isReleased($row['content_id']) === TRUE) {
if (is_array($rows)) {
    foreach ($rows as $row) {
コード例 #3
0
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']);
        }
    }
}
コード例 #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>
コード例 #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;
}