connect(); * ... do something... * $ws->disconnect(); * */ class DummyWaramu { function __call($name, $arguments) { } } function _helper_recur(&$result, $node) { /* if ( !$result['@schema'] && $node->getAttribute('xmlns')) { $result['@schema'][] = $node->getAttribute('xmlns'); }*/ if (!$result['@schema'] && $node->namespaceURI) { $result['@schema'][] = $node->namespaceURI; } $name = $node->nodeName; $type = $node->nodeType; //$result[$name] = $type; if ( $node->hasChildNodes() ) { $children = $node->childNodes; for ( $i=0; $i<$children->length; $i++ ) { $subresult = array(); $item = $children->item($i); $nodename = $item->nodeName; if ( $item->nodeType == XML_TEXT_NODE || $item->nodeType == XML_CDATA_SECTION_NODE) { $result[] = $item->nodeValue; } else { _helper_recur($subresult, $item); if ( $item->hasAttributes() ) { $atts = $item->attributes; if ( !is_null($atts) ) { $subresult['@attributes'] = array(); foreach( $atts as $index=>$attr ) { $subresult['@attributes'][$attr->name] = $attr->value; } } } $result[$nodename][] = $subresult; } } } } function to_object($xmlstring) { $dom = new DOMDocument(); $dom->loadXML($xmlstring); $dom->normalizeDocument(); $result = array(); if ($dom->hasChildNodes() ) { $children = $dom->childNodes; for ( $i=0; $i<$children->length; $i++ ) { _helper_recur($result, $children->item($i) ); } } return $result; } function wrap_object($uid, $xmlstring) { $arr = to_object($xmlstring); return new WaramuResource($uid, $arr, $xmlstring); } class WaramuResource { public $ds; public $source; public $uid = null; public $defaultlangs = array('et', 'en'); public $isLocal = false; function __construct($uid, $arr, $xm) { $this->uid = $uid; if ( is_null($arr) ) { $arr = to_object($xm); } $this->ds = $arr; $this->source = $xm; } function getSchema() { if ( array_key_exists('schema', $this->ds)) { // old infos/xml $typeid = $this->ds['schema'][0][0]; if ($typeid == "5") { return "http://koolielu.ee/schemas/Material"; } elseif ($typeid == "2") { return "http://koolielu.ee/schemas/Reference"; } } if ( $this->ds == "") { return $_SESSION['schema']; } if ($this->ds['data'][0]['@schema'][0] == "") { return $_SESSION['schema']; } return $this->ds['data'][0]['@schema'][0]; } function getAllLanguages() { if ( is_null($this->uid) ) { return $this->defaultlangs; } $langs = array(); $w = waramu_get(); $td = $w->describeType($this->getSchema()); foreach( $td->listFields() as $field ) { $name = $field['@attributes']['name']; if ( $field['@attributes']['multiLingual'] == '1' ) { $x = $this->ds['data'][0][$name]; foreach($x as $fvals) { if ( !in_array($fvals['@attributes']['lang'], $langs) ) { $langs[] = $fvals['@attributes']['lang']; } } } } return $langs; } function get($f, $lang=null) { if ( is_null($this->uid) ) { if ( isset($_SESSION[$f]) ) return array($_SESSION[$f]); return array(""); } $x = $this->ds['data'][0][$f]; $v = null; if ( !is_null($lang) ) { foreach($x as $y) { if ( $y['@attributes']['lang'] == $lang ) { $v = $y; } } if ( is_null($v) ) { $v = array(""); } } else { $v = $x[0]; } $val = $v; if ( is_array($v) ) { if ( array_key_exists("value", $v) ) { $val = $v['value']; } } unset($val['@schema']); return $val; } /** * get multivalued field as an array * */ function getMVArray($fname, $lang=null) { $r = array(); $vals = $this->get($fname, $lang); foreach($vals as $v) { $r[] = $v[0]; } return $r; } function getMetadataLanguage() { return $this->ds['data'][0]['mdLanguage'][0][0]; } function getTitle($getfirst=false) { //$mdl = $this->getMetadataLanguage(); $mdl = "et"; $got = false; $res = ""; if ( !$this->ds['data'][0]['title'] ) { /*translation:(untitled)*/ return elgg_echo("koolielu:resource_untitled"); } foreach ($this->ds['data'][0]['title'] as $tles) { if ( $getfirst ) { return $tles[0]; } if ( !$got && $tles['@attributes']['lang'] == $mdl ) { $res = $tles[0]; $got = true; } } if (!$got) $res = $this->getTitle(true); if ( strlen($res) == 0 ) { /*translation:(untitled)*/ return elgg_echo("koolielu:resource_untitled"); } return $res; } function getDescription($chars=null) { $mdl = "et"; //defaulting to ET $res = null; foreach ($this->ds['data'][0]['desc'] as $descs) { if ($descs['@attributes']['lang'] == $mdl) { $res = $descs[0]; } } if (is_null($res)) { foreach ($this->ds['data'][0]['desc'] as $descs) { if ($descs['@attributes']['lang'] == $this->getMetadataLanguage()) { $res = $descs[0]; } } } if (is_null($res)) { $res = ""; } if (!is_null($chars)) { $ds = $res; $ds = strip_tags($ds); if (mb_strlen($ds)>$chars) { $ds = mb_substr($ds, 0,$chars); $ds = mb_substr($ds, 0, mb_strrpos($ds, ' ')); $ds .= '...'; } return $ds; } return $res; } // returns array of all resource keywords (in every language) function getKeywords() { $langs = $this->getAllLanguages(); $keywords = array(); foreach ( $langs as $l ) { $kws = $this->get("keywords", $l); foreach( $kws as $kw) { $keywords[] = $kw[0]; } } return $keywords; } function getAuthor() { return $this->ds['data'][0]['vauthor'][0][0]; } function getURL() { return $this->ds['data'][0]['url'][0][0]; } function getIconURL() { global $CONFIG; if (!strcmp(getCollectionSchema(), $this->getSchema())) { if (count($this->getItems())>1) { return $CONFIG->url . "mod/waramu/views/default/_graphics/icons/collection_many.png"; } else { return $CONFIG->url . "mod/waramu/views/default/_graphics/icons/collection_one.png"; } } $lotype = $this->get("lotype"); $lotype = $lotype[0][0]; $iconed_types = array_keys(serveAllSuitableLotypes()); if (in_array($lotype, $iconed_types)) { return $CONFIG->url . "mod/waramu/views/default/_graphics/icons/lotype_" . str_replace(" ", "_", $lotype) . ".png"; } else { return $CONFIG->url . "mod/waramu/views/default/_graphics/icons/lotype_other.png"; } } function getLotypeLabel($lotype=null) { if (!$lotype) { $lotype = $this->get("lotype"); $lotype = $lotype[0][0]; } $iconed_types = serveAllSuitableLotypes(); $iconed_types_keys = array_keys($iconed_types); if (in_array($lotype, $iconed_types_keys)) { return $iconed_types[$lotype]; } else { return $iconed_types["other"]; } } function getDate() { $tim = strtotime($this->ds['created'][0][0]); return $tim; } function getCurriculumSubjects() { $csm = $this->get("curriculumSubject"); //Array ( [0] => Array ( [0] => 334901 ) ) //Array ( [0] => Array ( [0] => 334901 ) [1] => Array ( [0] => 140101 ) ) $res = array(); foreach ( $csm as $cs ) { if ( trim($cs[0]) ) { if ( substr($cs[0], 0, 1) != '@') { $res[] = getSubjectID(getCurriculumMainSubjectNS($cs['@schema'][0], $cs[0])); } } } return $res; } function hasAttachments() { $o1 = isset($this->ds['attachments']); if ( !$o1 ) { return false; } if ( count($this->ds['attachments']) == 1 && count($this->ds['attachments'][0]) == 0 ) { return false; } return $o1; } function getNumberOfAttachments() { return isset($this->ds['attachments'][0]['attachment']) ? count($this->ds['attachments'][0]['attachment']):0; } function listAttachments() { return $this->ds['attachments'][0]['attachment']; } /** * returns an owner of the metadata * */ function getOwner() { return $this->ds['acl'][0]['owner'][0][0]; } function getOwnerPrintable() { $own = $this->ds['acl'][0]['owner'][0][0]; $own = substr($own, 0, strpos($own, '@')); // TODO: check suffix $u = get_user_by_username($own); if ($u) return array($u, $u->name); return array(null, $own); } /** * returns a list of $sub who have $mode rights * $sub - groups or users * $mode - view, edit, down * example: getACL("groups", "edit") - returns a list of groups who have edit permission * */ function getACL($sub, $mode) { $r = array(); if ( !isset($this->ds['acl'][0][$mode]) ) { return $r; } else { $x = $this->ds['acl'][0][$mode][0][$sub][0]['value']; foreach ( $x as $gv ) { $g = $gv[0]; $r[] = $g; } } return $r; } /** * checks permission for $mode * $mode - view, edit, down * TODO: if view is restricted, this method will propably fail. * TODO: integrate isModerator in here * */ function hasPermissionTo($mode) { if ( !isLoggedIn() ) { if ( $mode == 'view' && count($this->getACL("groups", "view")) == 0 && count($this->getACL("users", "view")) == 0) { // no view restrictions set, go ahead return true; } return false; // deny } $wner = $this->getOwner(); $curruname = get_loggedin_user()->username; $w = waramu_get(); $identity = $w->Identify(); $suffix = $identity['identity'][0]['suffix'][0][0]; $curruname .= "@".$suffix; if ( $wner == $curruname ) return true; // owner always has permission $aclist = $this->getACL("users", $mode); foreach ($aclist as $ac ) { if ( $ac == $curruname ) return true; } $sublist = get_loggedin_user()->subjects; $aclist = $this->getACL("groups", $mode); // In case of just one subject, we will be dealing with a string if ($sublist && !is_array($sublist)) { // Now we make it a list $sublist = array($sublist); } foreach ( $sublist as $sub ) { foreach ($aclist as $ac) { if ( $sub."@".$suffix == $ac ) return true; } } if ( isEditor() ) { foreach ($aclist as $ac) { if ( $ac == "editor@".$suffix ) return true; } } return false; } function getAnnotationByName($name) { if ( !isset($this->ds['annotations']) ) { return null; } foreach ($this->ds['annotations'][0]['annotation'] as $anno) { if ( !strcmp($anno['name'][0][0], $name) ) { return new AnnotationWrapper($anno); } } return null; } function isPublished() { if ( $this->getAnnotationByName('koolielu') != null) { return true; } return false; } function getCollectionIDs() { $res = array(); if ( !isset($this->ds['collections']) ) { return $res; } foreach ($this->ds['collections'][0]['value'] as $coll) { $res[] = $coll[0]; } return $res; } /** * Collection only * */ function getItems() { $items = $this->get("items"); $fi = array(); foreach($items as $i) { //$c .= "