示例#1
0
function get_custom_style_from_metadata($user, $metadata_name)
{
    $returnArray = false;
    $user = get_entity($user);
    $customstyle_object = $user->getObjects($metadata_name, 1, 0);
    $customConfig = get_metadata_for_entity($customstyle_object[0]->guid);
    if ($customConfig) {
        foreach ($customConfig as $metadataObject) {
            $returnArray[$metadataObject['name']] = $metadataObject['value'];
        }
    }
    return $returnArray;
}
示例#2
0
 public static function getMetadata($entity_guid)
 {
     $return = array();
     $metadata = get_metadata_for_entity($entity_guid);
     if ($metadata) {
         foreach ($metadata as $data) {
             if (!isset($return[$data->name])) {
                 $return[$data->name] = $data->value;
                 $return[$data->name . '_access_id'] = $data->access_id;
             } else {
                 $return[$data->name] = array_merge((array) $return[$data->name], (array) $data->value);
             }
         }
     }
     return $return;
 }
function form_get_data_from_profile($form_id, $entity)
{
    $metadata = get_metadata_for_entity($entity->getGUID());
    // beginning of workaround
    // sadly Elgg 1.1 fails to enforce access controls for get_metadata_for_entity
    // see http://trac.elgg.org/elgg/ticket/531
    // so I need to do this dance to workaround this
    $good_metadata = array();
    if ($metadata) {
        foreach ($metadata as $m) {
            // get_metadata does enforce the access controls, so use that
            $good_m = get_metadata($m->id);
            if ($good_m) {
                $good_metadata[] = $good_m;
            }
        }
    }
    $metadata = $good_metadata;
    // end of workaround
    $data = array();
    $fields = form_get_fields($form_id);
    if ($fields) {
        foreach ($fields as $field) {
            $internalname = $field->internal_name;
            // not too efficient but the metadata doesn't seem to be keyed
            foreach ($metadata as $m) {
                // set an array if there are multiple metadata items with the same name
                // otherwise a single value
                // currently only the tags and checkbox groups fields return multiple values
                if ($m->name == $internalname) {
                    if (!isset($data[$internalname])) {
                        $data[$internalname] = new StdClass();
                        $data[$internalname]->value = $m->value;
                    } else {
                        if (is_array($data[$internalname]->value)) {
                            $data[$internalname]->value[] = $m->value;
                        } else {
                            $data[$internalname]->value = array($data[$internalname]->value, $m->value);
                        }
                    }
                    $data[$internalname]->access_id = $m->access_id;
                }
            }
        }
    }
    return $data;
}
/**
 * Get the notification settings for a given user.
 *
 * @param int $user_guid The user id
 * @return stdClass
 */
function get_user_notification_settings($user_guid = 0)
{
    $user_guid = (int) $user_guid;
    if ($user_guid == 0) {
        $user_guid = get_loggedin_userid();
    }
    $all_metadata = get_metadata_for_entity($user_guid);
    if ($all_metadata) {
        $prefix = "notification:method:";
        $return = new stdClass();
        foreach ($all_metadata as $meta) {
            $name = substr($meta->name, strlen($prefix));
            $value = $meta->value;
            if (strpos($meta->name, $prefix) === 0) {
                $return->{$name} = $value;
            }
        }
        return $return;
    }
    return false;
}
示例#5
0
<?php

/**
 * Elgg Entity export.
 * Displays an entity using the current view.
 *
 * @package Elgg
 * @subpackage Core
 * @author Curverider Ltd
 * @link http://elgg.org/
 */
$entity = $vars['entity'];
if (!$entity) {
    throw new InvalidParameterException(elgg_echo('InvalidParameterException:NoEntityFound'));
}
$metadata = get_metadata_for_entity($entity->guid);
$annotations = get_annotations($entity->guid);
$relationships = get_entity_relationships($entity->guid);
$exportable_values = $entity->getExportableValues();
?>
<div>
<h2><?php 
echo elgg_echo('Entity');
?>
</h2>
	<?php 
foreach ($entity as $k => $v) {
    if (in_array($k, $exportable_values) || isadminloggedin()) {
        ?>
			<p class="margin_none"><b><?php 
        echo $k;
示例#6
0
function westorElggMan_get_metadata($guid)
{
    if (function_exists("elgg_get_matadata")) {
        return elgg_get_matadata($guid);
    } else {
        return get_metadata_for_entity($guid);
    }
}
示例#7
0
文件: metadata.php 项目: eokyere/elgg
/**
 * Handler called by trigger_plugin_hook on the "export" event.
 */
function export_metadata_plugin_hook($hook, $entity_type, $returnvalue, $params)
{
    // Sanity check values
    if (!is_array($params) && !isset($params['guid'])) {
        throw new InvalidParameterException(elgg_echo('InvalidParameterException:GUIDNotForExport'));
    }
    if (!is_array($returnvalue)) {
        throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonArrayReturnValue'));
    }
    $guid = (int) $params['guid'];
    $name = $params['name'];
    $result = get_metadata_for_entity($guid);
    if ($result) {
        foreach ($result as $r) {
            $returnvalue[] = $r->export();
        }
    }
    return $returnvalue;
}
示例#8
0
 /**
  * Clone an entity
  *
  * Resets the guid so that the entity can be saved as a distinct entity from
  * the original. Creation time will be set when this new entity is saved.
  * The owner and container guids come from the original entity. The clone
  * method copies metadata but does not copy over annotations, or private settings.
  *
  * Note: metadata will have its owner and access id set when the entity is saved
  * and it will be the same as that off the entity.
  */
 public function __clone()
 {
     $orig_entity = get_entity($this->guid);
     if (!$orig_entity) {
         elgg_log("Failed to clone entity with GUID {$this->guid}", "ERROR");
         return;
     }
     $metadata_array = get_metadata_for_entity($this->guid);
     $this->attributes['guid'] = "";
     // copy metadata over to new entity - slightly convoluted due to
     // handling of metadata arrays
     if (is_array($metadata_array)) {
         // create list of metadata names
         $metadata_names = array();
         foreach ($metadata_array as $metadata) {
             $metadata_names[] = $metadata['name'];
         }
         // arrays are stored with multiple enties per name
         $metadata_names = array_unique($metadata_names);
         // move the metadata over
         foreach ($metadata_names as $name) {
             $this->set($name, $orig_entity->{$name});
         }
     }
 }
示例#9
0
文件: table.php 项目: eokyere/elgg
Filter Status: <select id="statusFilter"><option value="All">All</option> </select>
Filter Worker: <select id="workerFilter"><option value="All">All</option> </select>

<table style="width:100%;" id="taskTable">
<thead>
	<tr>
		<th>name</th>
		<th>status</th>
		<th>assigned to</th>
		<th>type</th>
	</tr>
</thead>
<tbody>	
<?php 
foreach ($items as $task) {
    $metadata = get_metadata_for_entity($task->guid);
    $meta_arr = array();
    foreach ($metadata as $meta) {
        $meta_arr[$meta['name']] = $meta['value'];
    }
    $type = elgg_echo("tasks:task_type_{$task->task_type}");
    $status = elgg_echo("tasks:task_status_{$task->status}");
    if ($status == '') {
        $status = 'Open';
    }
    if ($type == '') {
        $type = 'Dev';
    }
    if ($status != 'Closed') {
        $manage_link = "<a href=\"{$url}mod/tasks/manage.php?task=" . $task->getGUID() . "\">" . $task->title . "</a>&nbsp;";
        $worker = get_entity($task->assigned_to);
 protected function load($guid)
 {
     if (!parent::load($guid)) {
         return false;
     }
     if ($metadata = get_metadata_for_entity($guid)) {
         if (!is_array($this->meta_cache)) {
             $this->meta_cache = array();
         }
         foreach ($metadata as $md) {
             $this->meta_cache[$md->name] = $md->value;
         }
     }
     return true;
 }
function form_view_entities($entities, $form, $viewtype)
{
    global $CONFIG;
    $html = '';
    $qs = $_SERVER["QUERY_STRING"];
    if (is_array($entities) && sizeof($entities) > 0) {
        if (in_array($viewtype, array('list', 'display'))) {
            $commentable = $form->allow_comments;
            $recommendable = $form->allow_recommendations;
        } else {
            $commentable = $false;
            $recommendable = $false;
        }
        foreach ($entities as $entity) {
            $form_data_id = $entity->getGUID();
            $entity_url = $entity->getURL();
            $md_get = get_metadata_for_entity($form_data_id);
            $md = array();
            foreach ($md_get as $m) {
                if (isset($md[$m->name])) {
                    if (!is_array($md[$m->name]->value)) {
                        $md[$m->name]->value = array($md[$m->name]->value);
                    }
                    $md[$m->name]->value[] = $m->value;
                } else {
                    $md[$m->name] = new StdClass();
                    $md[$m->name]->value = $m->value;
                    $md[$m->name]->name = $m->name;
                }
            }
            // add title and description
            $extras = array('title' => $entity->title, 'description' => $entity->description);
            foreach ($extras as $k => $v) {
                $md[$k] = new StdClass();
                $md[$k]->value = $v;
                $md[$k]->name = $k;
            }
            $vars = array();
            $form_id = $form->getGUID();
            $fields = form_get_fields($form_id);
            if ($fields) {
                foreach ($fields as $field) {
                    $internalname = $field->internal_name;
                    if (isset($md[$internalname])) {
                        $item = $md[$internalname];
                        $vars[$item->name] = form_get_field_output($form, $field, $item->value);
                        if ($field->field_type == 'image_upload') {
                            $vars[$item->name . ':thumb'] = elgg_view($view, array('value' => $item->value, 'size' => 'small'));
                        } else {
                            if ($field->field_type == 'video_box') {
                                $vars[$item->name . ':thumb'] = elgg_view($view, array('value' => $item->value, 'size' => 'thumb'));
                            }
                        }
                    } else {
                        // just return empty strings
                        $vars[$internalname] = '';
                        if ($field->field_type == 'image_upload') {
                            $vars[$internalname . ':thumb'] = '';
                        } else {
                            if ($field->field_type == 'video_box') {
                                $vars[$internalname . ':thumb'] = '';
                            }
                        }
                    }
                }
            }
            $comment_bit = '';
            $recommend_bit = '';
            if ($commentable) {
                if ($viewtype == 'display') {
                    $comment_bit = elgg_view_comments($entity);
                } else {
                    $num_comments = elgg_count_comments($entity);
                    if ($num_comments == 1) {
                        $comment_bit = $num_comments . elgg_echo('form:comment');
                    } else {
                        $comment_bit = $num_comments . elgg_echo('form:comments');
                    }
                }
            }
            if ($recommendable) {
                $number_of_recommendations = count_annotations($form_data_id, 'object', 'form_data', 'form:recommendation');
                // count_annotations had a bug, but should be fixed now, so comment out this workaround
                //$number_of_recommendations = form_count(get_annotations($form_data_id, 'object', 'form_data', 'form:recommendation', 1, 0, 500));
                if (isloggedin() && $viewtype == 'display') {
                    $number_of_my_recommendations = form_count(get_annotations($form_data_id, 'object', 'form_data', 'form:recommendation', 1, $_SESSION['user']->getGUID()));
                    $user_guid = $_SESSION['user']->getGUID();
                    if ($number_of_my_recommendations == 0) {
                        $recommendation_template = '<a href="%s">' . elgg_echo("form:recommend_this") . '</a>';
                        $my_recommend_bit = ' [' . sprintf($recommendation_template, $CONFIG->wwwroot . 'action/form/manage_form_data?form_action=recommend&d=' . $form_data_id) . ']';
                    } else {
                        $my_recommend_bit = '';
                    }
                } else {
                    $my_recommend_bit = '';
                }
                if ($number_of_recommendations == 1) {
                    $recommend_bit = sprintf(elgg_echo('form:recommendation'), $number_of_recommendations) . $my_recommend_bit;
                } else {
                    $recommend_bit = sprintf(elgg_echo('form:recommendations'), $number_of_recommendations) . $my_recommend_bit;
                }
            }
            if ($viewtype == 'list') {
                if ($recommend_bit && $comment_bit) {
                    $annotation_bit = $recommend_bit . ', ' . $comment_bit;
                } else {
                    $annotation_bit = $recommend_bit . $comment_bit;
                }
            } else {
                $annotation_bit = $recommend_bit . '<br /><br />' . $comment_bit;
            }
            if (trim($form->list_template) || trim($form->display_template)) {
                $vars['_url'] = $CONFIG->wwwroot;
                $vars['_user_message_link'] = '<a href="' . $CONFIG->wwwroot . 'mod/messages/send.php?send_to=' . $entity->owner_guid . '">' . elgg_echo('form:send_a_message') . '</a>';
                $vars['_full_view_link'] = '<a href="' . $entity_url . '">' . elgg_echo('form:full_view') . '</a>';
                $vars['_full_view_url'] = $entity_url;
                $vars['_friendlytime'] = friendly_time($entity->time_created);
                $owner_entity = $entity->getOwnerEntity();
                $owner_url = $owner_entity->getUrl();
                $vars['_owner_url'] = $owner_url;
                $vars['_owner_name'] = $owner_entity->name;
                $vars['_owner_username'] = $owner_entity->username;
                $vars['_owner_message_link'] = $vars['_user_message_link'];
                $vars['_owner_icon'] = elgg_view("profile/icon", array('entity' => $owner_entity, 'size' => 'small'));
                $vars['_annotations'] = $annotation_bit;
            }
            if ($viewtype == 'display') {
                $template = $form->display_template;
                if (trim($template)) {
                    $content = form_parse_template($template, $vars);
                    $content = form_language_template($content);
                } else {
                    $content = elgg_view('form/default_form_data_display', array('entity' => $entity, 'annotations' => $annotation_bit));
                }
            } else {
                if ($viewtype == 'list') {
                    $template = $form->list_template;
                    if (trim($template)) {
                        $content = form_parse_template($template, $vars);
                        $content = form_language_template($content);
                    } else {
                        $content = elgg_view('form/default_form_data_listing', array('entity' => $entity, 'annotations' => $annotation_bit));
                    }
                } else {
                    $content = sprintf(elgg_echo('form:submitted'), friendly_time($entity->time_created));
                    if ($entity->time_updated != $entity->time_created) {
                        $content .= ", " . sprintf(elgg_echo('form:updated'), friendly_time($entity->time_updated));
                    }
                }
            }
            $html .= $content;
        }
    }
    return $html;
}
示例#12
0
 /**
  * Return a filestore suitable for saving this file.
  * This filestore is either a pre-registered filestore, a filestore loaded from metatags saved
  * along side this file, or the system default.
  */
 protected function getFilestore()
 {
     // Short circuit if already set.
     if ($this->filestore) {
         return $this->filestore;
     }
     // If filestore meta set then retrieve filestore TODO: Better way of doing this?
     $metas = get_metadata_for_entity($this->guid);
     $parameters = array();
     if (is_array($metas)) {
         foreach ($metas as $meta) {
             if (strpos($meta->name, "filestore::") !== false) {
                 // Filestore parameter tag
                 $comp = explode("::", $meta->name);
                 $name = $comp[1];
                 $parameters[$name] = $meta->value;
             }
         }
     }
     // If parameters loaded then create new filestore
     if (count($parameters) != 0) {
         // Create new filestore object
         if (!isset($parameters['filestore']) || !class_exists($parameters['filestore'])) {
             throw new ClassNotFoundException(elgg_echo('ClassNotFoundException:NotFoundNotSavedWithFile'));
         }
         // if dir_root is not set, we use default filestore
         if (isset($parameters['dir_root'])) {
             $this->filestore = new $parameters['filestore']($parameters['dir_root']);
         }
     }
     // if still nothing then set filestore to default
     if (!$this->filestore) {
         $this->filestore = get_default_filestore();
     }
     return $this->filestore;
 }
示例#13
0
文件: listing.php 项目: eokyere/elgg
 * 
 * @uses $vars['entity'] The user entity
 */
$icon = elgg_view("profile/icon", array('entity' => $vars['entity'], 'size' => 'small'));
$banned = $vars['entity']->isBanned();
// Simple XFN
$rel = "";
if (page_owner() == $vars['entity']->guid) {
    $rel = 'me';
} else {
    if (check_entity_relationship(page_owner(), 'friend', $vars['entity']->guid)) {
        $rel = 'friend';
    }
}
if (!$banned) {
    $meta = get_metadata_for_entity($vars['entity']->guid);
    $wants_str = '';
    $skills_str = '';
    $validated = "1";
    foreach ($meta as $md) {
        if ($md->name == 'skills') {
            if (!empty($skills_str)) {
                $skills_str .= ', ';
            }
            $skills_str .= $md->value;
        } else {
            if ($md->name == 'wants') {
                if (!empty($wants_str)) {
                    $wants_str .= ', ';
                }
                $wants_str .= $md->value;