/** * Import nodes and connections from the given CIF url for the selected nodeids into the given map. * The node import limit is set by '$CFG->ImportLimit'. * @param url the url for the CIF data to load * @param mapid the id of the map to get alerts for * @param selectedids an array of the CIF node ides to import * @param poses an array of the positions of the nodes in the map each array item is in * the format 'x:y' and the position in the array should correspond ot the position of * its node in the selectednodeids array. * before it is considered out of date and should be refetched and recalculated. * Defaults to 60 seconds. * @param private true if the data should be created as private, else false. * @return View object of the map or Error. * */ function addNodesAndConnectionsFromJsonld($url, $mapid, $selectedids, $poses, $private) { global $USER, $HUB_FLM, $CFG, $ERROR; require_once $HUB_FLM->getCodeDirPath("core/io/catalyst/catalyst_jsonld_reader.class.php"); require_once $HUB_FLM->getCodeDirPath("core/lib/url-validation.class.php"); //error_log(print_r($selectedids, true)); if (count($selectedids) > $CFG->ImportLimit) { $ERROR = new error(); $ERROR->createAccessDeniedError(); return $ERROR; } //error_log(print_r($poses, true)); // Check if the map is in a group and if so get the group id. $groupid = ""; $v = new View($mapid); $view = $v->load(); if (!$view instanceof Error) { if (isset($view->viewnode->groups)) { $groups = $view->viewnode->groups; if (count($groups) > 0) { $groupid = $groups[0]->groupid; } } } else { return $view; } // make sure current user in group, if group set. if ($groupid != "") { $group = new Group($groupid); if (!$group instanceof Error) { if (!$group->ismember($USER->userid)) { $error = new Error(); return $error->createNotInGroup($group->name); } } } $withhistory = false; $withvotes = false; $reader = new catalyst_jsonld_reader(); $reader = $reader->load($url, $withhistory, $withvotes); if (!$reader instanceof Error) { $nodeset = $reader->nodeSet; $nodes = $nodeset->nodes; $count = count($nodes); $newnodeSet = new NodeSet(); $newNodeCheck = array(); for ($i = 0; $i < $count; $i++) { $node = $nodes[$i]; $position = array_search($node->nodeid, $selectedids); //error_log("position:".$position); if ($position !== FALSE) { $position = intval($position); $positem = $poses[$position]; $positemArray = explode(":", $positem); $xpos = ""; $ypos = ""; if (count($positemArray) == 2) { $xpos = $positemArray[0]; $ypos = $positemArray[1]; } //error_log("xpos:".$xpos.":ypos:".$ypos); $role = getRoleByName($node->rolename); $description = ""; if (isset($node->description)) { $description = $node->description; } $newnode = addNode($node->name, $description, $private, $role->roleid); //error_log(print_r($newnode, true)); if (!$newnode instanceof Error) { $newNodeCheck[$node->nodeid] = $newnode; //error_log($node->nodeid); // if we have positioning information add the node to the map. if ($xpos != "" && $ypos != "") { $viewnode = $view->addNode($newnode->nodeid, $xpos, $ypos); //if (!$viewnode instanceof Error) { } if (isset($node->homepage) && $node->homepage != "") { $URLValidator = new mrsnk_URL_validation($node->homepage, MRSNK_URL_DO_NOT_PRINT_ERRORS, MRSNK_URL_DO_NOT_CONNECT_2_URL); if ($URLValidator->isValid()) { $urlObj = addURL($node->homepage, $node->homepage, "", $private, "", "", "", "cohere", ""); $newnode->addURL($urlObj->urlid, ""); // Add url to group? - not done on forms at present } else { error_log('Invalid node homepage: ' . $node->homepage . ': for ' . $node->nodeid); } } if (isset($node->users[0])) { $user = $node->users[0]; if (isset($user->homepage) && $user->homepage != "") { $URLValidator = new mrsnk_URL_validation($user->homepage, MRSNK_URL_DO_NOT_PRINT_ERRORS, MRSNK_URL_DO_NOT_CONNECT_2_URL); if ($URLValidator->isValid()) { $urlObj = addURL($user->homepage, $user->homepage, "", $private, "", "", "", "cohere", ""); $newnode->addURL($urlObj->urlid, ""); // Add url to group? - not done on forms at present } else { error_log('Invalid user homepage: ' . $user->homepage . ': for ' . $user->userid); } } } //if ($groupid != "") { // $newnode->addGroup($groupid); //} $newnodeSet->add($newnode); } else { error_log(print_r($newnode, true)); } } } $connectionset = $reader->connectionSet; $connections = $connectionset->connections; $count = count($connections); for ($i = 0; $i < $count; $i++) { $conn = $connections[$i]; $from = $conn->from; $to = $conn->to; $fromrole = $conn->fromrole; $torole = $conn->torole; if (isset($newNodeCheck[$from->nodeid]) && isset($newNodeCheck[$to->nodeid])) { $newFromNode = $newNodeCheck[$from->nodeid]; $newToNode = $newNodeCheck[$to->nodeid]; // Might not need this as it might be done already //if ($newFromNode->role->name != $fromrole->name) { // updateNodeRole($newFromNode->nodeid,$fromrole->name); //} $linklabelname = $conn->linklabelname; //error_log($linklabelname); $lt = getLinkTypeByLabel($linklabelname); if (!$lt instanceof Error) { $linkType = $lt->linktypeid; //$frole = getRoleByName($fromrole->name); //$trole = getRoleByName($torole->name); $connection = addConnection($newFromNode->nodeid, $newFromNode->role->roleid, $linkType, $newToNode->nodeid, $newToNode->role->roleid, 'N', ""); //error_log(print_r($connection, true)); if (!$connection instanceof Error) { // add to group if (isset($groupid) && $groupid != "") { $connection->addGroup($groupid); } $viewcon = $view->addConnection($connection->connid); //error_log(print_r($viewcon,true)); } else { error_log(print_r($connection, true)); } } else { error_log("for label:" . $linklabelname . ":" . print_r($lt, true)); } } } } else { return $reader; } return $view; }
/** * Clean the passed parameter * * @param mixed $param the variable we are cleaning * @param int $type expected format of param after cleaning. * @return mixed */ function clean_param($param, $type) { global $CFG, $ERROR, $HUB_FLM; if (is_array($param)) { $newparam = array(); foreach ($param as $key => $value) { $newparam[$key] = clean_param($value, $type); } return $newparam; } switch ($type) { case PARAM_TEXT: // leave only tags needed for multilang if (is_numeric($param)) { return $param; } $param = stripslashes($param); $param = clean_text($param); $param = strip_tags($param, '<lang><span>'); $param = str_replace('+', '+', $param); $param = str_replace('(', '(', $param); $param = str_replace(')', ')', $param); $param = str_replace('=', '=', $param); $param = str_replace('"', '"', $param); $param = str_replace('\'', ''', $param); return $param; case PARAM_HTML: // keep as HTML, no processing $param = stripslashes($param); $param = clean_text($param); return trim($param); case PARAM_INT: return (int) $param; case PARAM_NUMBER: return (double) $param; case PARAM_ALPHA: // Remove everything not a-z return preg_replace('/([^a-zA-Z])/i', '', $param); case PARAM_ALPHANUM: // Remove everything not a-zA-Z0-9 return preg_replace('/([^A-Za-z0-9])/i', '', $param); case PARAM_ALPHAEXT: // Remove everything not a-zA-Z/_- return preg_replace('/([^a-zA-Z\\/_-])/i', '', $param); case PARAM_ALPHANUMEXT: // Remove everything not a-zA-Z0-9- return preg_replace('/([^a-zA-Z0-9-])/i', '', $param); case PARAM_BOOL: // Convert to 1 or 0 $tempstr = strtolower($param); if ($tempstr == 'on' or $tempstr == 'yes' or $tempstr == 'true') { $param = 1; } else { if ($tempstr == 'off' or $tempstr == 'no' or $tempstr == 'false') { $param = 0; } else { $param = empty($param) ? 0 : 1; } } return $param; case PARAM_BOOLTEXT: // check is an allowed text type boolean $tempstr = strtolower($param); if ($tempstr == 'on' or $tempstr == 'yes' or $tempstr == 'true' or $tempstr == 'off' or $tempstr == 'no' or $tempstr == 'false' or $tempstr == '0' or $tempstr == '1') { $param = $param; } else { $param = ""; } return $param; case PARAM_PATH: // Strip all suspicious characters from file path $param = str_replace('\\\'', '\'', $param); $param = str_replace('\\"', '"', $param); $param = str_replace('\\', '/', $param); $param = ereg_replace('[[:cntrl:]]|[<>"`\\|\':]', '', $param); $param = ereg_replace('\\.\\.+', '', $param); $param = ereg_replace('//+', '/', $param); return ereg_replace('/(\\./)+', '/', $param); case PARAM_URL: // allow safe ftp, http, mailto urls include_once $CFG->dirAddress . 'core/lib/url-validation.class.php'; $URLValidator = new mrsnk_URL_validation($param, MRSNK_URL_DO_NOT_PRINT_ERRORS, MRSNK_URL_DO_NOT_CONNECT_2_URL); if (!empty($param) && $URLValidator->isValid()) { // all is ok, param is respected } else { $param = ''; // not really ok } return $param; case PARAM_EMAIL: if (validEmail($param)) { return $param; } else { $ERROR = new error(); $ERROR->createInvalidEmailError(); include_once $HUB_FLM->getCodeDirPath("core/formaterror.php"); die; } case PARAM_XML: $param = parseFromXML($param); return $param; default: include_once $HUB_FLM->getCodeDirPath("core/formaterror.php"); $ERROR = new error(); $ERROR->createInvalidParameterError($type); die; } }
if (empty($errors)) { // remove all the existing urls so they can be re-added below $issuenode->removeAllURLs(); $i = 0; foreach ($resourceurlarray as $resourceurl) { $resourcetitle = trim($resourcetitlearray[$i]); // If they have entered nothing, don't do anything. if ($resourcetitle == "" && ($resourceurl == "http://" || $resourceurl == "")) { break; } //check all fields entered if ($resourcetitle != "" && ($resourceurl == "http://" || $resourceurl == "")) { array_push($errors, $LNG->FORM_RESOURCE_URL_REQUIRED); break; } $URLValidator = new mrsnk_URL_validation($resourceurl, MRSNK_URL_DO_NOT_PRINT_ERRORS, MRSNK_URL_DO_NOT_CONNECT_2_URL); if ($resourceurl != "" && !$URLValidator->isValid()) { array_push($errors, $LNG->FORM_RESOURCE_URL_FORMAT_ERROR); break; } if ($resourcetitle == "") { $resourcetitle = $resourceurl; } // ADD URL TO REF and EVIDENCE $clip = ""; $clippath = ""; $identifier = ""; if (isset($resourcecliparray[$i])) { $clip = $resourcecliparray[$i]; } if (isset($resourceclippatharray[$i])) {
if (strlen($password) < 8) { array_push($errors, $LNG->LOGIN_PASSWORD_LENGTH); } if ($fullname == "") { array_push($errors, $LNG->FORM_ERROR_NAME_MISSING); } // check password & confirm password match if ($password != $confirmpassword) { array_push($errors, $LNG->FORM_ERROR_PASSWORD_MISMATCH); } // check url if ($homepage == "http://") { $homepage = ""; } if ($homepage != "") { $URLValidator = new mrsnk_URL_validation($homepage, MRSNK_URL_DO_NOT_PRINT_ERRORS, MRSNK_URL_DO_NOT_CONNECT_2_URL); if ($homepage != "" && !$URLValidator->isValid()) { array_push($errors, $LNG->FORM_ERROR_URL_INVALID); } } if (empty($errors)) { // check email not already in use $u = new User(); $u->setEmail($email); $user = $u->getByEmail(); if ($user instanceof User) { array_push($errors, $LNG->FORM_ERROR_EMAIL_USED); } else { if ($CFG->CAPTCHA_ON) { //check recaptcha is valid $resp = recaptcha_check_answer($CFG->CAPTCHA_PRIVATE, $_SERVER["REMOTE_ADDR"], $recaptcha_challenge_field, $recaptcha_response_field);