Exemple #1
0
 /**
  * Unserializes the event object stored in the database
  *
  * @param string $serialized Serialized string
  * @return string
  */
 public function unserialize($serialized)
 {
     $data = unserialize($serialized);
     if (isset($data->action)) {
         $this->action = $data->action;
     }
     if (isset($data->object_id) && isset($data->object_type)) {
         switch ($data->object_type) {
             case 'object':
             case 'user':
             case 'group':
             case 'site':
                 $this->object = get_entity($data->object_id);
                 break;
             case 'annotation':
                 $this->object = elgg_get_annotation_from_id($data->object_id);
                 break;
             case 'metadata':
                 $this->object = elgg_get_metadata_from_id($data->object_id);
                 break;
             case 'relationship':
                 $this->object = get_relationship($data->object_id);
         }
     }
     if (isset($data->actor_guid)) {
         $this->actor = get_entity($data->actor_guid);
     }
 }
Exemple #2
0
/**
 * Define an arbitrary relationship between two entities.
 * This relationship could be a friendship, a group membership or a site membership.
 *
 * This function lets you make the statement "$guid_one is a $relationship of $guid_two".
 *
 * @param int    $guid_one     First GUID
 * @param string $relationship Relationship name
 * @param int    $guid_two     Second GUID
 *
 * @return bool
 * @throws InvalidArgumentException
 */
function add_entity_relationship($guid_one, $relationship, $guid_two)
{
    global $CONFIG;
    if (strlen($relationship) > ElggRelationship::RELATIONSHIP_LIMIT) {
        $msg = "relationship name cannot be longer than " . ElggRelationship::RELATIONSHIP_LIMIT;
        throw InvalidArgumentException($msg);
    }
    $guid_one = (int) $guid_one;
    $relationship = sanitise_string($relationship);
    $guid_two = (int) $guid_two;
    $time = time();
    // Check for duplicates
    if (check_entity_relationship($guid_one, $relationship, $guid_two)) {
        return false;
    }
    $id = insert_data("INSERT INTO {$CONFIG->dbprefix}entity_relationships\n\t\t(guid_one, relationship, guid_two, time_created)\n\t\tVALUES ({$guid_one}, '{$relationship}', {$guid_two}, {$time})");
    if ($id !== false) {
        $obj = get_relationship($id);
        // this event has been deprecated in 1.9. Use 'create', 'relationship'
        $result_old = elgg_trigger_event('create', $relationship, $obj);
        $result = elgg_trigger_event('create', 'relationship', $obj);
        if ($result && $result_old) {
            return true;
        } else {
            delete_relationship($result);
        }
    }
    return false;
}
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function get($uid = '')
 {
     switch ($uid) {
         case 'me':
             $uid = "ue" . elgg_get_logged_in_user_guid();
             break;
         case 'site':
             $uid = "se" . elgg_get_site_entity()->guid;
             break;
     }
     $abbr = substr($uid, 0, 2);
     switch ($abbr) {
         case 'an':
             $id = (int) substr($uid, 2);
             $object = elgg_get_annotation_from_id($id);
             break;
         case 'md':
             $id = (int) substr($uid, 2);
             $object = elgg_get_metadata_from_id($id);
             break;
         case 'rl':
             $id = (int) substr($uid, 2);
             $object = get_relationship($id);
             break;
         case 'rv':
             $id = (int) substr($uid, 2);
             $river = elgg_get_river(array('ids' => sanitize_int($id)));
             $object = $river ? $river[0] : false;
             break;
         case 'ue':
         case 'se':
         case 'oe':
         case 'ge':
             $id = (int) substr($uid, 2);
             $object = get_entity($id);
             break;
         default:
             $object = get_user_by_username($uid);
             if (!$object && is_numeric($uid)) {
                 $object = get_entity($uid);
             }
     }
     if (!$this->isExportable($object)) {
         return false;
     }
     return $object;
 }
Exemple #4
0
 /**
  * Get the object of the event
  *
  * @return \ElggData
  */
 public function getObject()
 {
     switch ($this->object_type) {
         case 'object':
         case 'user':
         case 'site':
         case 'group':
             return get_entity($this->object_id);
             break;
         case 'relationship':
             return get_relationship($this->object_id);
             break;
         case 'annotation':
             return elgg_get_annotation_from_id($this->object_id);
             break;
     }
     return null;
 }
Exemple #5
0
 public function testCanUpdate()
 {
     add_entity_relationship($this->user->guid, 'test_self1', $this->user->guid);
     $rel = check_entity_relationship($this->user->guid, 'test_self1', $this->user->guid);
     $res = update_data("\n\t\t\tUPDATE {$this->prefix}entity_relationships\n\t\t\tSET relationship = 'test_self2'\n\t\t\tWHERE id = {$rel->id}\n\t\t");
     $rel = get_relationship($rel->id);
     $this->assertIdentical($res, true);
     $this->assertEqual($rel->relationship, 'test_self2');
     $num_rows = update_data("\n\t\t\tUPDATE {$this->prefix}entity_relationships\n\t\t\tSET relationship = 'test_self3'\n\t\t\tWHERE id = {$rel->id}\n\t\t", [], true);
     $rel = get_relationship($rel->id);
     $this->assertIdentical($num_rows, 1);
     $this->assertEqual($rel->relationship, 'test_self3');
     $num_rows = update_data("\n\t\t\tUPDATE {$this->prefix}entity_relationships\n\t\t\tSET relationship = :rel\n\t\t\tWHERE id = :id\n\t\t", [':rel' => 'test_self4', ':id' => $rel->id], true);
     $rel = get_relationship($rel->id);
     $this->assertIdentical($num_rows, 1);
     $this->assertEqual($rel->relationship, 'test_self4');
     $rel->delete();
 }
Exemple #6
0
         $m->name = $id_or_name;
         $m->entity_guid = $guid;
         $m->time_created = $entity->time_created;
         $m->time_updated = $entity->time_updated;
         $m->owner_guid = $entity->owner_guid;
         $m->id = $id_or_name;
         $m->type = "attr";
         break;
     case 'metadata':
         $m = elgg_get_metadata_from_id($id_or_name);
         break;
     case 'annotation':
         $m = elgg_get_annotation_from_id($id_or_name);
         break;
     case 'relationship':
         $r = get_relationship($id_or_name);
         break;
     case 'volatile':
         $m = elgg_trigger_plugin_hook('volatile', 'metadata', array('guid' => $guid, 'varname' => $id_or_name));
         break;
     default:
         $msg = "Sorry, I don't know how to export '" . $type . "'";
         throw new \InvalidParameterException($msg);
 }
 // Render metadata or relationship
 if (!$m && !$r) {
     throw new \InvalidParameterException("Could not find any data.");
 }
 // Exporting metadata?
 if ($m) {
     if ($m->entity_guid != $entity->guid) {
/**
 * Get the url for a given relationship.
 *
 * @param int $id Relationship ID
 *
 * @return string
 */
function get_relationship_url($id)
{
    global $CONFIG;
    $id = (int) $id;
    if ($relationship = get_relationship($id)) {
        $view = elgg_get_viewtype();
        $guid = $relationship->guid_one;
        $type = $relationship->relationship;
        $url = "";
        $function = "";
        if (isset($CONFIG->relationship_url_handler[$type])) {
            $function = $CONFIG->relationship_url_handler[$type];
        }
        if (isset($CONFIG->relationship_url_handler['all'])) {
            $function = $CONFIG->relationship_url_handler['all'];
        }
        if (is_callable($function)) {
            $url = call_user_func($function, $relationship);
        }
        if ($url == "") {
            $nameid = $relationship->id;
            $url = elgg_get_site_url() . "export/{$view}/{$guid}/relationship/{$nameid}/";
        }
        return $url;
    }
    return false;
}
/**
 * Get the url for a given relationship.
 *
 * @param int $id Relationship ID
 *
 * @return string
 * @deprecated 1.9 Use \ElggRelationship::getURL()
 */
function get_relationship_url($id)
{
    elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \\ElggRelationship::getURL()', 1.9);
    global $CONFIG;
    $id = (int) $id;
    if ($relationship = get_relationship($id)) {
        $view = elgg_get_viewtype();
        $guid = $relationship->guid_one;
        $type = $relationship->relationship;
        $url = "";
        $function = "";
        if (isset($CONFIG->relationship_url_handler[$type])) {
            $function = $CONFIG->relationship_url_handler[$type];
        }
        if (isset($CONFIG->relationship_url_handler['all'])) {
            $function = $CONFIG->relationship_url_handler['all'];
        }
        if (is_callable($function)) {
            $url = call_user_func($function, $relationship);
        }
        if ($url == "") {
            $nameid = $relationship->id;
            $url = elgg_get_site_url() . "export/{$view}/{$guid}/relationship/{$nameid}/";
        }
        return $url;
    }
    return false;
}
 /**
  * For a given ID, return the object associated with it.
  * This is used by the river functionality primarily.
  * This is useful for checking access permissions etc on objects.
  *
  * @param int $id ID
  *
  * @return ElggRelationship
  */
 public function getObjectFromID($id)
 {
     return get_relationship($id);
 }
Exemple #10
0
$guid = (int) get_input('guid');
$type = get_input('type');
$key = get_input('key');
$show_hidden = access_show_hidden_entities(true);
$entity = get_entity($guid);
if (empty($entity) || empty($type) || $key === null) {
    access_show_hidden_entities($show_hidden);
    return elgg_error_response(elgg_echo('error:missing_data'));
}
if (!$entity->canEdit()) {
    access_show_hidden_entities($show_hidden);
    return elgg_error_response(elgg_echo('action:unauthorized'));
}
switch ($type) {
    case 'entity':
        if (!$entity instanceof ElggSite) {
            $entity->delete();
        }
        break;
    case 'metadata':
        unset($entity->{$key});
        break;
    case 'relationship':
        get_relationship($key)->delete();
        break;
    case 'private_setting':
        $entity->removePrivateSetting($key);
        break;
}
access_show_hidden_entities($show_hidden);
forward(REFERER);
Exemple #11
0
function get_associate_relationship_name(WT_Individual $person1, WT_Individual $person2)
{
    if ($person1 === $person2) {
        $label = WT_I18N::translate('self');
    } else {
        $label = get_relationship_name(get_relationship($person1, $person2, true, 4));
    }
    return $label;
}
Exemple #12
0
function cr_facts_localisation_pl(&$factrec, &$fact, &$explode_fact, &$pid)
{
    global $factarray;
    $ct = preg_match_all("/\\d ASSO @(.*)@/", $factrec, $match, PREG_SET_ORDER);
    if ($ct > 0) {
        $pid2 = $match[0][1];
    }
    if (isset($pid2)) {
        $sex1 = Person::getInstance($pid)->getSex();
        $sex2 = Person::getInstance($pid2)->getSex();
        if ($explode_fact[1] == "BIRT") {
            switch ($explode_fact[2]) {
                case "SIBL":
                    if ($sex2 == "M") {
                        $factarray[$fact] = "Narodziny brata";
                    } else {
                        if ($sex2 == "F") {
                            $factarray[$fact] = "Narodziny siostry";
                        }
                    }
                    break;
                case "GCHI":
                    if ($sex2 == "M") {
                        $factarray[$fact] = "Narodziny wnuka";
                    } else {
                        if ($sex2 == "F") {
                            $factarray[$fact] = "Narodziny wnuczki";
                        }
                    }
                    break;
                case "GGCH":
                    if ($sex2 == "M") {
                        $factarray[$fact] = "Narodziny prawnuka";
                    } else {
                        if ($sex2 == "F") {
                            $factarray[$fact] = "Narodziny prawnuczki";
                        }
                    }
                    break;
                case "COUS":
                    if ($sex2 == "M") {
                        $factarray[$fact] = "Narodziny kuzyna";
                    } else {
                        if ($sex2 == "F") {
                            $factarray[$fact] = "Narodziny kuzynki";
                        }
                    }
                    break;
                case "FSIB":
                    if ($sex2 == "M") {
                        $factarray[$fact] = "Narodziny brata ojca";
                    } else {
                        if ($sex2 == "F") {
                            $factarray[$fact] = "Narodziny siostry ojca";
                        }
                    }
                    break;
                case "MSIB":
                    if ($sex2 == "M") {
                        $factarray[$fact] = "Narodziny brata matki";
                    } else {
                        if ($sex2 == "F") {
                            $factarray[$fact] = "Narodziny siostry matki";
                        }
                    }
                    break;
                case "NEPH":
                    $node = get_relationship($pid, $pid2);
                    if (isset($node["path"][1])) {
                        $sex3 = Person::getInstance($node["path"][1])->getSex();
                        if ($sex2 == "M") {
                            if ($sex3 == "M") {
                                $factarray[$fact] = "Narodziny bratanka";
                            } else {
                                if ($sex3 == "F") {
                                    $factarray[$fact] = "Narodziny siostrzeńca";
                                }
                            }
                        } else {
                            if ($sex2 == "F") {
                                if ($sex3 == "M") {
                                    $factarray[$fact] = "Narodziny bratanicy";
                                } else {
                                    if ($sex3 == "F") {
                                        $factarray[$fact] = "Narodziny siostrzenicy";
                                    }
                                }
                            }
                        }
                    }
                    break;
            }
        } else {
            if ($explode_fact[1] != "") {
                switch ($explode_fact[2]) {
                    case "SIBL":
                        if ($sex2 == "M") {
                            $factarray[$fact] = $factarray[$explode_fact[1]] . " brata";
                        } else {
                            if ($sex2 == "F") {
                                $factarray[$fact] = $factarray[$explode_fact[1]] . " siostry";
                            }
                        }
                        break;
                    case "GCHI":
                        if ($sex2 == "M") {
                            $factarray[$fact] = $factarray[$explode_fact[1]] . " wnuka";
                        } else {
                            if ($sex2 == "F") {
                                $factarray[$fact] = $factarray[$explode_fact[1]] . " wnuczki";
                            }
                        }
                        break;
                    case "GGCH":
                        if ($sex2 == "M") {
                            $factarray[$fact] = $factarray[$explode_fact[1]] . " prawnuka";
                        } else {
                            if ($sex2 == "F") {
                                $factarray[$fact] = $factarray[$explode_fact[1]] . " prawnuczki";
                            }
                        }
                        break;
                    case "GPAR":
                        if ($sex2 == "M") {
                            $factarray[$fact] = $factarray[$explode_fact[1]] . " dziadka";
                        } else {
                            if ($sex2 == "F") {
                                $factarray[$fact] = $factarray[$explode_fact[1]] . " babci";
                            }
                        }
                        break;
                    case "GGPA":
                        if ($sex2 == "M") {
                            $factarray[$fact] = $factarray[$explode_fact[1]] . " pradziadka";
                        } else {
                            if ($sex2 == "F") {
                                $factarray[$fact] = $factarray[$explode_fact[1]] . " prababci";
                            }
                        }
                        break;
                    case "COUS":
                        if ($sex2 == "M") {
                            $factarray[$fact] = $factarray[$explode_fact[1]] . " kuzyna";
                        } else {
                            if ($sex2 == "F") {
                                $factarray[$fact] = $factarray[$explode_fact[1]] . " kuzynki";
                            }
                        }
                        break;
                    case "FSIB":
                        if ($sex2 == "M") {
                            $factarray[$fact] = $factarray[$explode_fact[1]] . " brata ojca";
                        } else {
                            if ($sex2 == "F") {
                                $factarray[$fact] = $factarray[$explode_fact[1]] . " siostry ojca";
                            }
                        }
                        break;
                    case "MSIB":
                        if ($sex2 == "M") {
                            $factarray[$fact] = $factarray[$explode_fact[1]] . " brata matki";
                        } else {
                            if ($sex2 == "F") {
                                $factarray[$fact] = $factarray[$explode_fact[1]] . " siostry matki";
                            }
                        }
                        break;
                    case "SPOU":
                        if ($sex2 == "M" || $sex1 == "F") {
                            $factarray[$fact] = $factarray[$explode_fact[1]] . " męża";
                        } else {
                            if ($sex2 == "F" || $sex1 == "M") {
                                $factarray[$fact] = $factarray[$explode_fact[1]] . " żony";
                            }
                        }
                        break;
                    case "NEPH":
                        $node = get_relationship($pid, $pid2);
                        if (isset($node["path"][1])) {
                            $sex3 = Person::getInstance($node["path"][1])->getSex();
                            if ($sex2 == "M") {
                                if ($sex3 == "M") {
                                    $factarray[$fact] = $factarray[$explode_fact[1]] . " bratanka";
                                } else {
                                    if ($sex3 == "F") {
                                        $factarray[$fact] = $factarray[$explode_fact[1]] . " siostrzeńca";
                                    }
                                }
                            } else {
                                if ($sex2 == "F") {
                                    if ($sex3 == "M") {
                                        $factarray[$fact] = $factarray[$explode_fact[1]] . " bratanicy";
                                    } else {
                                        if ($sex3 == "F") {
                                            $factarray[$fact] = $factarray[$explode_fact[1]] . " siostrzenicy";
                                        }
                                    }
                                }
                            }
                        }
                        break;
                }
            }
        }
    }
}
 /**
  * Create a relationship between two entities. E.g. friendship, group membership, site membership.
  *
  * This function lets you make the statement "$guid_one is a $relationship of $guid_two". In the statement,
  * $guid_one is the subject of the relationship, $guid_two is the target, and $relationship is the type.
  *
  * @param int    $guid_one     GUID of the subject entity of the relationship
  * @param string $relationship Type of the relationship
  * @param int    $guid_two     GUID of the target entity of the relationship
  *
  * @return bool
  * @throws InvalidArgumentException
  */
 function add($guid_one, $relationship, $guid_two)
 {
     if (strlen($relationship) > \ElggRelationship::RELATIONSHIP_LIMIT) {
         $msg = "relationship name cannot be longer than " . \ElggRelationship::RELATIONSHIP_LIMIT;
         throw InvalidArgumentException($msg);
     }
     $guid_one = (int) $guid_one;
     $relationship = sanitise_string($relationship);
     $guid_two = (int) $guid_two;
     $time = time();
     // Check for duplicates
     if (check_entity_relationship($guid_one, $relationship, $guid_two)) {
         return false;
     }
     $id = _elgg_services()->db->insertData("INSERT INTO {$this->CONFIG->dbprefix}entity_relationships\n\t\t\t(guid_one, relationship, guid_two, time_created)\n\t\t\tVALUES ({$guid_one}, '{$relationship}', {$guid_two}, {$time})");
     if ($id !== false) {
         $obj = get_relationship($id);
         $result = _elgg_services()->events->trigger('create', 'relationship', $obj);
         if ($result) {
             return true;
         } else {
             delete_relationship($result);
         }
     }
     return false;
 }
Exemple #14
0
 /**
  * Returns a node from it's uid
  *
  * @param string $uid UID of the resource
  * @return mixed
  */
 public function get($uid = '')
 {
     switch ($uid) {
         case 'me':
             $uid = "ue" . elgg_get_logged_in_user_guid();
             break;
         case 'site':
             $uid = "se" . elgg_get_site_entity()->guid;
             break;
     }
     if (substr($uid, 0, 2) == 'an') {
         $id = (int) substr($uid, 2);
         $node = elgg_get_annotation_from_id($id);
     } else {
         if (substr($uid, 0, 2) == 'md') {
             $id = (int) substr($uid, 2);
             $node = elgg_get_metadata_from_id($id);
         } else {
             if (substr($uid, 0, 2) == 'rl') {
                 $id = (int) substr($uid, 2);
                 $node = get_relationship($id);
             } else {
                 if (substr($uid, 0, 2) == 'rv') {
                     $id = (int) substr($uid, 2);
                     $river = elgg_get_river(array('ids' => sanitize_int($id)));
                     $node = $river ? $river[0] : false;
                 } else {
                     if (in_array(substr($uid, 0, 2), array('ue', 'se', 'oe', 'ge'))) {
                         $id = (int) substr($uid, 2);
                         $node = get_entity($id);
                     } else {
                         if (is_numeric($uid)) {
                             $node = get_entity($uid);
                         } else {
                             $node = get_user_by_username($uid);
                         }
                     }
                 }
             }
         }
     }
     if (!$this->isExportable($node)) {
         return false;
     }
     return $node;
 }
Exemple #15
0
}
$Dbheight = $bheight;
$Dbxspacing = 0;
$Dbyspacing = 0;
$Dbasexoffset = 0;
$Dbaseyoffset = 0;
$person1 = WT_Individual::getInstance($pid1);
$person2 = WT_Individual::getInstance($pid2);
$controller->addExternalJavascript(WT_STATIC_URL . 'js/autocomplete.js')->addInlineJavascript('autocomplete();');
if ($person1 && $person1->canShowName() && $person2 && $person2->canShowName()) {
    $controller->setPageTitle(WT_I18N::translate('Relationships between %1$s and %2$s', $person1->getFullName(), $person2->getFullName()))->PageHeader();
    $node = get_relationship($person1, $person2, $followspouse, 0, $path_to_find);
    // If no blood relationship exists, look for relationship via marriage
    if ($path_to_find == 0 && $node == false && $followspouse == false) {
        $followspouse = true;
        $node = get_relationship($person1, $person2, $followspouse, 0, $path_to_find);
    }
    $disp = true;
} else {
    $controller->setPageTitle(WT_I18N::translate('Relationships'))->PageHeader();
    $node = false;
    $disp = false;
}
?>
<div id="relationship-page">
	<h2><?php 
echo $controller->getPageTitle();
?>
</h2>
	<form name="people" method="get" action="?">
		<input type="hidden" name="ged" value="<?php