Пример #1
0
 function mdo_generate_default_xml_metadata()
 {
     global $iso639_2_code, $ieee_xml;
     $xhtDoc = new xhtdoc($ieee_xml);
     $_user = api_get_user_info();
     if ($xhtDoc->htt_error) {
         give_up('IEEE XML (metadata/md_funcs): ' . $xhtDoc->htt_error);
     }
     $xhtDoc->xht_get_lang = 'get_lang';
     $xhtDoc->xht_xmldoc = new xmddoc('');
     if ($xhtDoc->xht_xmldoc->error) {
         give_up($xhtDoc->xht_xmldoc->error);
     }
     $xhtDoc->xht_param['siteUri'] = make_uri();
     $xhtDoc->xht_param['entry'] = $this->mdo_course['sysCode'] . '.Link.' . $this->mdo_id;
     // 2005-05-30: path->sysCode
     $xhtDoc->xht_param['location'] = $this->mdo_url . '';
     $xhtDoc->xht_param['mdlang'] = strtolower($iso639_2_code);
     $xhtDoc->xht_param['lang'] = strtolower($iso639_2_code);
     $xhtDoc->xht_param['title'] = $this->mdo_title ? $this->mdo_title : get_lang('MdTitle');
     if ($d = $this->mdo_description) {
         if ($keywords = $this->_find_keywords($d)) {
             $d = array_pop($keywords);
         }
         $xhtDoc->xht_param['description'] = $d;
     } else {
         $xhtDoc->xht_param['description'] = get_lang('MdDescription');
     }
     $xhtDoc->xht_param['coverage'] = $this->mdo_category_title ? $this->mdo_category_title : get_lang('MdCoverage');
     if (isset($_user)) {
         $xhtDoc->xht_param['author'] = "BEGIN:VCARD\\nFN:" . api_get_person_name($_user['firstName'], $_user['lastName'], null, PERSON_NAME_EMAIL_ADDRESS) . "\\nEMAIL:" . $_user['mail'] . "\\nEND:VCARD\\n";
     }
     $xhtDoc->xht_param['dateTime'] = date('Y-m-d');
     $xhtDoc->xht_param['format'] = '';
     $xhtDoc->xht_param['size'] = '0';
     if (count($keywords)) {
         $xd = new xmddoc(explode("\n", $mdt = $xhtDoc->xht_fill_template('XML')));
         if ($xd->error) {
             return $mdt;
         }
         // and worry later
         $this->_add_keywords($xd, $keywords);
         return $xd->xmd_xml();
     }
     return $xhtDoc->xht_fill_template('XML');
 }
Пример #2
0
 /** Parse CLI arguments into options
  * @return void
  */
 public function parse_args($argv)
 {
     reset($argv);
     $attrs = $this::get_attr_def();
     $commands = array();
     while ($arg = array_shift($argv)) {
         if (strpos($arg, '-') !== false) {
             foreach ($attrs as $long => $info) {
                 if ($arg == '--' . $long && ($t = 'l') || isset($info['short']) && $arg == '-' . $info['short'] && ($t = 's')) {
                     if ($info['type'] == 'bool') {
                         $this->{$long} = true;
                     } else {
                         switch ($info[0]) {
                             case 'string':
                                 if ($t == 's') {
                                     $value = array_shift($argv);
                                     if (any($value)) {
                                         $this->{$long} = $value;
                                     }
                                     give_up("Option " . $arg . " requires value");
                                 } else {
                                     if (strpos($arg, '=') > 0) {
                                         list($key, $value) = explode('=', $arg, 2);
                                         if (any($value)) {
                                             $this->{$long} = $value;
                                         } else {
                                             give_up("Option " . $arg . " requires value");
                                         }
                                     } else {
                                         give_up("Option " . $arg . " requires value");
                                     }
                                 }
                                 break;
                         }
                     }
                 }
             }
         } else {
             $commands[] = $arg;
         }
     }
     return $commands;
 }
Пример #3
0
 function mdo_generate_default_xml_metadata()
 {
     global $iso639_2_code, $ieee_xml;
     $xhtDoc = new xhtdoc($ieee_xml);
     $_user = api_get_user_info();
     if ($xhtDoc->htt_error) {
         give_up('IEEE XML (metadata/md_funcs): ' . $xhtDoc->htt_error);
     }
     $xhtDoc->xht_get_lang = 'get_lang';
     $xhtDoc->xht_xmldoc = new xmddoc('');
     if ($xhtDoc->xht_xmldoc->error) {
         give_up($xhtDoc->xht_xmldoc->error);
     }
     $xhtDoc->xht_param['siteUri'] = make_uri();
     $xhtDoc->xht_param['entry'] = $this->mdo_course['sysCode'] . '.Document.' . $this->mdo_id;
     // 2005-05-30: path->sysCode
     $xhtDoc->xht_param['location'] = api_get_path(WEB_PATH) . 'main/metadata/openobject.php?cidReq=' . urlencode($this->mdo_course['sysCode']) . '&eid=' . urlencode($this->mdo_eid);
     $xhtDoc->xht_param['mdlang'] = strtolower($iso639_2_code);
     $xhtDoc->xht_param['lang'] = strtolower($iso639_2_code);
     $xhtDoc->xht_param['title'] = $this->mdo_title ? $this->mdo_title : ($this->mdo_path ? $this->mdo_path : get_lang('MdTitle', ''));
     $xhtDoc->xht_param['description'] = $this->mdo_comment ? $this->mdo_comment : get_lang('MdDescription', '');
     $xhtDoc->xht_param['coverage'] = get_lang('MdCoverage', '');
     if (isset($_user)) {
         $xhtDoc->xht_param['author'] = "BEGIN:VCARD\\nFN:" . api_get_person_name($_user['firstName'], $_user['lastName'], null, PERSON_NAME_EMAIL_ADDRESS) . "\\nEMAIL:" . $_user['mail'] . "\\nEND:VCARD\\n";
     }
     $xhtDoc->xht_param['dateTime'] = date('Y-m-d');
     if ($this->mdo_filetype == 'folder') {
         $format = "inode/directory";
     } else {
         require_once api_get_path(LIBRARY_PATH) . 'document.lib.php';
         $format = DocumentManager::file_get_mime_type($this->mdo_path);
     }
     $xhtDoc->xht_param['format'] = $format;
     $xhtDoc->xht_param['size'] = ($s = filesize(get_course_path() . $this->mdo_course['path'] . '/document' . $this->mdo_path)) ? $s : '0';
     return $xhtDoc->xht_fill_template('XML');
 }
Пример #4
0
define('WORDS_CHARS_LATIN1', '[:alnum:]��ߵ');

foreach (array( 'A'=>'������', 'a'=>'������', 'O'=>'������', 'o'=>'������',
                'E'=>'����', 'e'=>'����', 'C'=>'�', 'c'=>'�', 'I'=>'����',
                'i'=>'����', 'U'=>'����', 'u'=>'����', 'Y'=>'�', 'y'=>'��',
                'N'=>'�', 'n'=>'�') as $without => $allwith)
    foreach (explode('!', chunk_split($allwith, 1, '!')) as $with)
    if ($with)  // because last one will be empty!
    {
        $letterswithout .= $without; $letterswith .= $with;
    }
define('LETTERS_WITH_ACCENTS', $letterswith);
define('SAME_WITHOUT_ACCENTS', $letterswithout);

(strlen(LETTERS_WITH_ACCENTS) == strlen(SAME_WITHOUT_ACCENTS))
    or give_up('LETTERS_WITH_ACCENTS problem in md_phpdig.php');


function find_site($url)
{
    $site_url = "site_url = '" . addslashes($url) . "'";

    $result = Database::query("SELECT site_id FROM " . PHPDIG_DB_PREFIX .
        "sites WHERE " . $site_url);  // find site

    if (Database::num_rows($result) == 1)
    {
        $row = Database::fetch_array($result); return (int) $row['site_id'];
    }
    else
    {
Пример #5
0
$nameTools = get_lang('Tool');
if (!isset($sdisub)) {
    $sdisub = '';
}
$sdisub = substr(ereg_replace("[^0-9A-Za-z]", "", $sdisub), 0, 4);
// $sdisub is for split manifests - Scorm.NNN.$sdisub_xxx e.g. Scorm.3.1979_12
define('MFFNAME', 'imsmanifest');
define('MFFDEXT', '.xml');
define('HTF', 'mdp_scorm.htt');
$regs = array();
$nameTools && get_lang('Sorry') or give_up('Language file ' . $language_file . " doesn't define 'Tool' and 'Sorry'");
$_course = api_get_course_info();
isset($_course) or give_up(get_lang('Sorry'));
$is_allowed_to_edit = isset($_user['user_id']) && $is_courseMember && api_is_allowed_to_edit();
if (!$is_allowed_to_edit) {
    give_up(get_lang('Denied'));
}
$baseWorkDir = get_course_path() . ($courseDir = $_course['path'] . '/scorm');
$mdStore = new mdstore($is_allowed_to_edit);
// create table if needed
require api_get_path(LIBRARY_PATH) . 'xmd.lib.php';
require api_get_path(LIBRARY_PATH) . 'xht.lib.php';
require 'md_phpdig.php';
// SET CURRENT SCORM DIRECTORY - HEADER --------------------------------------->
if (isset($workWith)) {
    $scormdocument = Database::get_course_table(TABLE_LP_MAIN);
    $sql = "SELECT id FROM {$scormdocument} WHERE path='" . Database::escape_string(api_substr($workWith, 1)) . "' OR path='" . Database::escape_string(substr($workWith, 1)) . "/.'";
    $result = Database::query($sql);
    if (Database::num_rows($result) == 1) {
        if ($row = Database::fetch_array($result)) {
            $sdi = $row['id'];
Пример #6
0
if (!isset($sdisub)) $sdisub = '';
$sdisub = substr(ereg_replace("[^0-9A-Za-z]", "", $sdisub), 0, 4);
// $sdisub is for split manifests - Scorm.NNN.$sdisub_xxx e.g. Scorm.3.1979_12

define('MFFNAME', 'imsmanifest'); define('MFFDEXT', '.xml');
define('HTF', 'mdp_scorm.htt');

$regs = array();

($nameTools && get_lang('Sorry')) or give_up(
    'Language file ' . $language_file . " doesn't define 'Tool' and 'Sorry'");

$_course = api_get_course_info(); isset($_course) or give_up(get_lang('Sorry'));

$is_allowed_to_edit = isset($_user['user_id']) && $is_courseMember && api_is_allowed_to_edit();
if (!$is_allowed_to_edit) give_up(get_lang('Denied'));

$baseWorkDir = get_course_path() . ($courseDir = $_course['path'] . '/scorm');

$mdStore = new mdstore($is_allowed_to_edit);  // create table if needed

require(api_get_path(LIBRARY_PATH) . 'xmd.lib.php');
require(api_get_path(LIBRARY_PATH) . 'xht.lib.php');
require(api_get_path(LIBRARY_PATH) . 'fileManage.lib.php');

require('md_phpdig.php');


// SET CURRENT SCORM DIRECTORY - HEADER --------------------------------------->

if (isset($workWith))  // explicit in URL, or selected at bottom of screen
$before_first = $id_range_first ? TRUE : FALSE;
$after_last = FALSE;
foreach ($xhtxmldoc->xmd_select_elements('child') as $chEl) {
    $chId = $xhtxmldoc->attributes[$chEl]['identifier'];
    // no get_att yet...
    if ($after_last || ($before_first = $before_first && $chId != $id_range_first)) {
        $xhtxmldoc->xmd_remove_element($chEl);
        continue;
    }
    if (($mdt_rec = $mdStore->mds_get(BID . '.' . $chId)) === FALSE) {
        $mdt = $mdObj->mdo_generate_default_xml_metadata();
    } else {
        $mdt = $mdt_rec;
    }
    $xhtxmldocchild = new xmddoc(explode("\n", $mdt));
    !$xhtxmldocchild->error or give_up($chId . ': ' . $xhtxmldocchild->error);
    // make stuff below a parameter? copy some already in importmanifest?
    $xhtxmldoc->xmd_copy_foreign_child($xhtxmldocchild, $xhtxmldocchild->xmd_select_single_element('title'), $chEl);
    $xhtxmldoc->xmd_copy_foreign_child($xhtxmldocchild, $xhtxmldocchild->xmd_select_single_element('resource'), $chEl);
    $after_last = $after_last || $chId == $id_range_last;
}
$xhtDoc = define_htt(HTT . '.htt', $urlp, $_course['path']);
$xhtDoc->xht_xmldoc = $xhtxmldoc;
$xhtDoc->xht_param['mdt'] = $xhtxmldoc->xmd_xml();
// GENERATE OUTPUT ------------------------------------------------------------>
foreach (explode("\n", $xhtDoc->htt_array['HTTP']) as $httpXtra) {
    if ($httpXtra) {
        $httpHeadXtra[] = $httpXtra;
    }
}
$xhtDoc->xht_get_lang = 'get_lang';
Пример #8
0
 function xhtdoc($htt_file_contents)
 {
     $htt_file_contents = str_replace("\r", "\n", str_replace("\r\n", "\n", $htt_file_contents));
     while (api_substr($htt_file_contents, -1) == "\n") {
         $htt_file_contents = api_substr($htt_file_contents, 0, -1);
     }
     $last_line = api_strrchr($htt_file_contents, "\n");
     $this->htt_error = '';
     if (api_strlen($last_line) < 12 || api_substr($last_line, 0, 6) != "\n<!-- " || api_strlen($last_line) % 2 != 0 || api_substr($last_line, -4) != " -->") {
         $this->htt_error = 'last line must be of the form <!-- {--} -->';
         return;
     }
     define('XHT_PL', (int) (api_strlen($last_line) - 10) / 2);
     // Parentheses Lth
     define('XHT_LP', api_substr($last_line, 6, XHT_PL));
     // Left Par
     define('XHT_RP', api_substr($last_line, 6 + XHT_PL, XHT_PL));
     // Right Par
     if (XHT_LP == XHT_RP) {
         $this->htt_error = 'parentheses in last line <!-- {--} --> must not be identical';
         return;
     }
     $this->htt_array = array();
     // named elements are arrays and strings
     foreach (explode("\n<!-- " . XHT_LP, "\n" . $htt_file_contents) as $name_and_text) {
         if ($name_length = api_strpos($name_and_text, XHT_RP . " -->\n")) {
             $template_name = trim(api_substr($name_and_text, 0, $name_length));
             if (api_strpos($template_name, ' ') !== FALSE) {
                 give_up('Template ' . $template_name . ' has a space in its name');
             }
             $httext = api_substr($name_and_text, $name_length + XHT_PL + 5);
             while (api_substr($httext, 0, 1) == "\n") {
                 $httext = api_substr($httext, 1);
             }
             while (api_substr($httext, -1) == "\n") {
                 $httext = api_substr($httext, 0, -1);
             }
             $this->xht_add_template($template_name, $httext);
         }
     }
     define('XHT_SUBS1', '^(C|H|L|P|U|V|W|X) +(.*)$');
     // substitution types 1:
     // Call, Htmlchars, Lang, Param, Urlencode, Value, Wchars, Xvalue
     define('XHT_SUBS2', '^(D|E|R|T) +([^ ]+) +(.*)$');
     // substitution types 2:
     // Define, Escape, Repeat, Test
     $this->xht_dbgo = '';
     $this->xht_param = array(0 => '0', 1 => '1', '' => '', 'empty' => '', 'rdepth' => 0);
     $this->_prev_param = $this->xht_param;
     // empty:  {-R * P empty-} puts the number of subelements in {-P number-}
     // rdepth: current number of nested R's
     // rdepth1, rdepth2, ...: key or number, see R
 }
Пример #9
0
    }
}
echo '<br>';
$xmlDoc = new xmddoc(explode("\n", $mdStore->mds_get($eid = EID_TYPE . '.1002')));
if ($xmlDoc->error) {
    give_up($xmlDoc->error);
}
$mdObj = new mdobject($_course, '1002');
$mda = "~~";
// delete metadata of 'Document.1002'
$mdt = $mdStore->mds_update_xml_and_mdt($mdObj, $xmlDoc, $mda, $eid, $trace);
// note: $xmlDoc and $trace are passed by reference...
$mdObj = new mdobject($_course, '1003');
$xmlDoc = new xmddoc(explode("\n", $mdStore->mds_get($eid = EID_TYPE . '.1003')));
if ($xmlDoc->error) {
    give_up($xmlDoc->error);
}
$map_lang = 'string/@language';
$dcmap_e_kwplace = 'metadata/lom/general';
$dcmap_e_kwelem = 'keyword';
$dcmap_e_keyword = $dcmap_e_kwplace . '/' . $dcmap_e_kwelem;
$mda = $mdObj->mdo_dcmap_v['Description'] . '=Nouvelle description' . "\n" . $mdObj->mdo_dcmap_e['Coverage'] . "~" . "\n" . $dcmap_e_kwplace . '!' . $dcmap_e_kwelem . "\n" . $dcmap_e_keyword . "[-1]!string=afrique" . "\n" . $dcmap_e_keyword . "[-1]/" . $map_lang . "=en" . "\n" . $mdObj->mdo_dcmap_e['Title'] . ',' . $mdObj->mdo_dcmap_e['Description'] . ',' . $dcmap_e_keyword . ";" . $map_lang . "=fr" . "";
// update metadata of 'Document.1003' - see md_funcs
// note we don't go far with IEEE independence...
$mdt = $mdStore->mds_update_xml_and_mdt($mdObj, $xmlDoc, $mda, $eid, $trace);
echo htmlspecialchars($trace), '<br><br>';
// The simplest API calls: store and fetch DC metadata element values:
$mdObj = new mdobject($_course, '1003');
$mdStore->mds_put_dc_elements($mdObj, array('Coverage' => 'broad...', 'Type' => 'aggressive text'));
// Coverage won't work, because that element has been removed above...
$dcelem = $mdStore->mds_get_dc_elements($mdObj);
Пример #10
0
<?php

/** 
 * Chamilo metadata/openobject.php
 * 2004/08/27
 * Copyright (C) 2006 rene.haentjens@UGent.be -  see metadata/md_funcs.php
 * @package chamilo.metadata
 */
/**
 *	Chamilo Metadata: general script for opening an object
 *   URL parameters:
 *   - eid=  entry-id = object-id = type.identifier, e.g. 'Document.12';
 */
require "md_funcs.php";
// name of the language file that needs to be included
/*
$language_file = 'Whatever';
*/
require "../inc/global.inc.php";
$this_section = SECTION_COURSES;
getpar('EID', 'Entry IDentifier');
if (!($dotpos = strpos(EID, '.'))) {
    give_up('No . in ' . EID);
}
require 'md_' . strtolower(substr(EID, 0, $dotpos)) . '.php';
$mdObj = new mdobject($_course, substr(EID, $dotpos + 1));
header('Location: ' . $mdObj->mdo_url);
exit;
Пример #11
0
//define('PHPDIG_ENCODING', 'iso-8859-1');
define('PHPDIG_ENCODING', strtolower($charset));
define('SMALL_WORDS_SIZE', 2);
define('MAX_WORDS_SIZE', 50);
define('WORDS_CHARS_LATIN1', '[:alnum:]��ߵ');
foreach (array('A' => '������', 'a' => '������', 'O' => '������', 'o' => '������', 'E' => '����', 'e' => '����', 'C' => '�', 'c' => '�', 'I' => '����', 'i' => '����', 'U' => '����', 'u' => '����', 'Y' => '�', 'y' => '��', 'N' => '�', 'n' => '�') as $without => $allwith) {
    foreach (explode('!', chunk_split($allwith, 1, '!')) as $with) {
        if ($with) {
            $letterswithout .= $without;
            $letterswith .= $with;
        }
    }
}
define('LETTERS_WITH_ACCENTS', $letterswith);
define('SAME_WITHOUT_ACCENTS', $letterswithout);
strlen(LETTERS_WITH_ACCENTS) == strlen(SAME_WITHOUT_ACCENTS) or give_up('LETTERS_WITH_ACCENTS problem in md_phpdig.php');
function find_site($url)
{
    $site_url = "site_url = '" . addslashes($url) . "'";
    $result = Database::query("SELECT site_id FROM " . PHPDIG_DB_PREFIX . "sites WHERE " . $site_url);
    // find site
    if (Database::num_rows($result) == 1) {
        $row = Database::fetch_array($result);
        return (int) $row['site_id'];
    } else {
        $result = Database::query("INSERT INTO " . PHPDIG_DB_PREFIX . "sites SET " . $site_url);
        // new site
        $site_id = Database::insert_id();
        $result = Database::query("INSERT INTO " . PHPDIG_DB_PREFIX . "site_page (site_id,num_page) VALUES ('{$site_id}', '0')");
        return $site_id;
    }
Пример #12
0
 function mds_get($eid, $column = 'mdxmltext', $must_exist = '') {
     // none: FALSE
     if (($mdt = Database::fetch_array(Database::query("SELECT " . $column ." FROM ".MDS_TABLE." WHERE eid = '$eid' AND c_id = {$this->course_id} ")))) 
         return $mdt[$column];    
     if ($must_exist) give_up($must_exist . $this->_coldat('eid', $eid));
 
     return FALSE;
 }
Пример #13
0
    $urlp .= '&lfn=' . urlencode(LFN);
}
if (HTT != LFN) {
    $urlp .= '&htt=' . urlencode(HTT);
}
if (DBG) {
    $urlp .= '&dbg=' . urlencode(DBG);
}
// name of the language file that needs to be included
$language_file = LFN;
require_once "../inc/global.inc.php";
$this_section = SECTION_COURSES;
$nameTools = get_lang('Tool');
$nameTools && get_lang('Sorry') or give_up('Language file ' . LFN . " doesn't define 'Tool' and 'Sorry'");
$_course = api_get_course_info();
isset($_course) or give_up(get_lang('Sorry'));
require api_get_path(LIBRARY_PATH) . 'xmd.lib.php';
require api_get_path(LIBRARY_PATH) . 'xht.lib.php';
$mdObj = new mdobject($_course, EID_ID);
// see 'md_' . EID_TYPE . '.php'
// Construct assoclist $langLangs from language table ------------------------->
$result = Database::query("SELECT isocode FROM " . Database::get_main_table(TABLE_MAIN_LANGUAGE) . " WHERE available='1' ORDER BY isocode ASC");
$sep = ":";
$langLangs = $sep . "xx" . $sep . "xx";
while ($row = Database::fetch_array($result)) {
    if ($isocode = $row['isocode']) {
        $langLangs .= ",, " . $isocode . $sep . $isocode;
    }
}
// XML and DB STUFF ----------------------------------------------------------->
$is_allowed_to_edit = isset($_user['user_id']) && $is_courseMember && api_is_allowed_to_edit();
Пример #14
0
 private function import_sql($file)
 {
     if (file_exists($file)) {
         shell_exec(self::assemble_mysql_command("mysql", true) . " < " . $file);
     } else {
         give_up("File not found: " . $file);
     }
     return $this;
 }
Пример #15
0
            $words .= ", " . $word;
            $where .= " AND indexabletext " . ($word[0] != '-' ? "LIKE '%" . addslashes($word) . "%'" : "NOT LIKE '%" . addslashes(substr($word, 1)) . "%'");
        }
    }
    if ($where) {
        $whereclause = substr($where, 5);
        // remove first " AND "
        $xhtDoc->xht_xmldoc->xmd_add_text_element('query', $whereclause);
        $xhtDoc->xht_param['traceinfo'] = substr($words, 2);
        $result = $mdStore->mds_get_many('eid,mdxmltext', $whereclause);
        while ($myrow = @Database::fetch_array($result)) {
            // not quite a real manifest, but very much like one...
            $eid = $myrow['eid'];
            $xmlDoc = new xmddoc($myrow['mdxmltext']);
            if ($xmlDoc->error) {
                give_up('Entry ' . $eid . ': ' . $xmlDoc->error);
            }
            $mdObj = new mdobject($_course, $eid);
            // md_mix.php
            $xhtDoc->xht_xmldoc->xmd_copy_foreign_child($xmlDoc);
            $newItem = $xhtDoc->xht_xmldoc->xmd_select_single_element('item[-1]');
            $xhtDoc->xht_xmldoc->xmd_set_attribute($newItem, 'eid', $eid);
            $xhtDoc->xht_xmldoc->xmd_set_attribute($newItem, 'url', $mdObj->mdo_url);
            if ($mdObj->mdo_type == 'Scorm') {
                $xhtDoc->xht_xmldoc->xmd_set_attribute($newItem, 'brl', $mdObj->mdo_base_url);
            }
        }
    }
}
function check_is_thumb($p)
{