/** * Returns a human-readable list of annotations on a particular entity. * * @param int $entity_guid The entity GUID * @param string $name The name of the kind of annotation * @param int $limit The number of annotations to display at once * @param true|false $asc Whether or not the annotations are displayed in ascending order. (Default: true) * @return string HTML (etc) version of the annotation list */ function list_annotations($entity_guid, $name = "", $limit = 25, $asc = true) { if ($asc) { $asc = "asc"; } else { $asc = "desc"; } $count = count_annotations($entity_guid, "", "", $name); $offset = (int) get_input("annoff", 0); $annotations = get_annotations($entity_guid, "", "", $name, "", "", $limit, $offset, $asc); return elgg_view_annotation_list($annotations, $count, $offset, $limit); }
/** * Has the photo been tagged with "in this photo" tags * * @return true/false */ public function isPhotoTagged() { $num_tags = count_annotations($this->getGUID(), 'object', 'image', 'phototag'); if ($num_tags > 0) { return true; } else { return false; } }
$user = get_entity($vars['item']->subject_guid); } //get the right annotation type //*todo - use the same for comments, everywhere e.g. comment switch ($vars['item']->subtype) { case 'thewire': $annotation_comment = 'wire_reply'; break; default: $annotation_comment = 'generic_comment'; break; } //count comment annotations $comment_count = count_annotations($vars['item']->object_guid, $vars['item']->type, $vars['item']->subtype, $annotation_comment); //count like annotations $likes = count_annotations($vars['item']->object_guid, $vars['item']->type, $vars['item']->subtype, "likes"); //get last two comments display $get_comments = get_annotations($vars['item']->object_guid, "", "", $annotation_comment, "", "", 3, 0, "desc"); if ($get_comments) { //reverse the array so we can display comments in the right order $get_comments = array_reverse($get_comments); } //minus two off the comment total as we display two by default if ($comment_count < 3) { $num_comments = 0; } else { $num_comments = $comment_count - 3; } ?> <div class="river_item"> <span class="river_item_useravatar">
/** * Return the count of all downloads * Adds 1.2M to the figure to account for downloads before this system as implemented. * * @return int */ function plugins_get_all_download_count() { // see revision [7001] if interested in cached calculations on downloads $c = count_annotations(0, 'object', 'plugin_project', 'download', '', NULL); return $c + 1200000; }
/** * Return the annotations for the entity. * * @param string $name The type of annotation. */ function countAnnotations($name = "") { return count_annotations($this->getGUID(), "", "", $name); }
} else { $user = get_loggedin_user(); } $form_id = $form->getGUID(); $offset = (int) get_input('offset', 0); $limit = 10; $entities = array(); if ($form_view == 'recommendations') { // get all the form data with recommendations, sorted with the most recommended at the top // TODO: replace with more efficient SQL $all_entities = get_entities_from_annotations("object", "form_data", "form:recommendation", "", 0, 0, 5000); if ($all_entities) { $entity_list = array(); foreach ($all_entities as $entity) { if ($entity->form_id == $form_id) { $count = count_annotations($entity->getGUID(), "object", "form_data", "form:recommendation"); $item = new StdClass(); $item->entity = $entity; $item->count = $count; $entity_list[] = $item; } } $sorted = form_vsort($entity_list, 'count', true); foreach ($sorted as $item) { $entities[] = $item->entity; } $entities = array_slice($entities, $offset, $limit); } } else { if ($form_view == 'mine') { $user_guid = $user->getGUID();
/** * Count the number of comments attached to an entity * * @param ElggEntity $entity * @return int Number of comments */ function elgg_count_comments($entity) { if ($commentno = trigger_plugin_hook('comments:count', $entity->getType(), array('entity' => $entity), false)) { return $commentno; } else { return count_annotations($entity->getGUID(), "", "", "generic_comment"); } }
} } foreach ($plugin_defaults_array as $key => $value) { $plugin->{$key} = $value; } // copy download annotations to the project $q = "SELECT * FROM elggannotations WHERE entity_guid = {$plugin->getGUID()}"; $r = mysql_query($q); while ($row = mysql_fetch_assoc($r)) { $q = "INSERT INTO elggannotations\n\t\t\t\t(id, entity_guid, name_id, value_id, value_type, owner_guid, access_id, time_created, enabled) VALUES\n\t\t\t\t('', '{$project->getGUID()}', '{$row['name_id']}', '{$row['value_id']}', '{$row['value_type']}', '{$row['owner_guid']}',\n\t\t\t\t\t'{$row['access_id']}', '{$row['time_created']}', '{$row['enabled']}')"; var_dump($q); mysql_query($q); var_dump(mysql_error()); } var_dump("Plugin: {$plugin->getGUID()}\n"); if ($tmp = elgg_get_entities_from_relationship(array('relationship' => 'prev_version', 'relationship_guid' => $prev_version_guid))) { $prev_version_guid = $tmp[0]->guid; } else { $prev_version_guid = FALSE; } } // set the project's creation and update time to the earliest plugin file's $q = "UPDATE elggentities SET time_created={$plugin->time_created} WHERE guid={$project->getGUID()}"; var_dump($q); mysql_query($q); var_dump(mysql_error()); } // set site md for download count $count = count_annotations(0, "object", "plugins", "download"); $CONFIG->site->plugins_download_count = $count; echo "Ding!";
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; }
<?php /** * Recommend view */ $project = $vars['project']; $num_diggs = count_annotations($project->guid, "object", "plugin_project", "plugin_digg"); ?> <div id="plugins_recommend"> <div id="num_recommend"> <p><?php echo $num_diggs; ?> </p> </div> <div class="clearfloat"></div> <div id="recommend_action"> <?php if (!plugins_is_dugg($project) && isloggedin()) { $url = "{$vars['url']}action/plugins/digg?guid={$project->guid}"; $url = elgg_add_action_tokens_to_url($url); echo "<a href=\"{$url}\">Recommend</a>"; } else { ?> <p>Recommendations</p> <?php } ?> </div> </div>
<?php /** * All site bookmark stats **/ $count_bookmarks = elgg_get_entities("object", "bookmarks", 0, "", 10, 0, true, 0, null, 0, 0); $count_bookmark_comments = count_annotations(0, "object", "bookmarks", "generic_comment"); echo "<h3>Bookmark stats</h3>"; echo "<p>" . $count_bookmarks . " resources bookmarked.</p>";
<?php /** * Check for new activity. * Outputs # of new activity items since $_GET['last_checked'] time */ // Load Elgg engine will not include plugins require_once dirname(dirname(dirname(dirname(__FILE__)))) . "/engine/start.php"; // check for last checked time if (!($seconds_passed = get_input('seconds_passed', 0))) { echo ''; exit; } $last_reload = time() - $seconds_passed; //grab any new annotations $annotations = count_annotations('', '', '', '', '', '', '', $last_reload); if (!$annotations) { $annotations = 0; } //grab all new objects created $entity_creation = elgg_get_entities(array('count' => TRUE, 'created_time_lower' => $last_reload, 'wheres' => array('e.type != \'user\''))); if (!$entity_creation) { $entity_creation = 0; } //grab any entities updated $entity_update = elgg_get_entities(array('count' => TRUE, 'modified_time_lower' => $last_reload, 'wheres' => array('e.type != \'user\''))); if (!$entity_update) { $entity_update = 0; } //get any relationships, such as friending - this is not working quite right yet //$relationship_action = elgg_get_entities_from_relationship(array('count' => TRUE));