示例#1
0
/**
 * Handles voting on an entity
 *
 * @param  integer  $guid  The entity guid being voted on
 * @param  integer  $vote The vote
 * @return string   A status message to be returned to the client
 */
function elggx_fivestar_vote($guid, $vote)
{
    $entity = get_entity($guid);
    $annotation_owner = elgg_get_logged_in_user_guid();
    $msg = null;
    if ($annotation = elgg_get_annotations(array('guid' => $entity->guid, 'type' => $entity->type, 'annotation_name' => 'fivestar', 'annotation_owner_guid' => $annotation_owner, 'limit' => 1))) {
        if ($vote == 0 && (int) elgg_get_plugin_setting('change_cancel', 'elggx_fivestar', 1)) {
            if (!elgg_trigger_plugin_hook('elggx_fivestar:cancel', 'all', array('entity' => $entity), false)) {
                elgg_delete_annotations(array('annotation_id' => $annotation[0]->id));
                $msg = elgg_echo('elggx_fivestar:deleted');
            }
        } else {
            if ((int) elgg_get_plugin_setting('change_cancel', 'elggx_fivestar', 1)) {
                update_annotation($annotation[0]->id, 'fivestar', $vote, 'integer', $annotation_owner, 2);
                $msg = elgg_echo('elggx_fivestar:updated');
            } else {
                $msg = elgg_echo('elggx_fivestar:nodups');
            }
        }
    } else {
        if ($vote > 0) {
            if (!elgg_trigger_plugin_hook('elggx_fivestar:vote', 'all', array('entity' => $entity), false)) {
                $entity->annotate('fivestar', $vote, 2, $annotation_owner);
            }
        } else {
            $msg = elgg_echo('elggx_fivestar:novote');
        }
    }
    elggx_fivestar_setRating($entity);
    return $msg;
}
示例#2
0
文件: Poll.php 项目: iionly/poll
 /**
  * Delete all votes associated with this poll, reset vote counters and delete associated vote river items
  */
 public function deleteVotes()
 {
     elgg_delete_river(array('view' => 'river/object/poll/vote', 'action_type' => 'vote', 'object_guid' => $this->guid));
     elgg_delete_annotations(array('guid' => $this->guid, 'type' => "object", 'subtype' => "poll", 'annotation_name' => "vote"));
     $this->responses_by_choice = array();
     $this->response_count = 0;
 }
示例#3
0
/**
 * called on daily cron - cleans up ip address cache
 * 
 * @param type $hook
 * @param type $entity_type
 * @param type $returnvalue
 * @param type $params
 */
function daily_cron($hook, $entity_type, $returnvalue, $params)
{
    $ia = elgg_set_ignore_access(true);
    //Retrieve the ips older than one week
    $week_ago = time() - 604800;
    //(7 * 24 * 60 * 60);
    elgg_delete_annotations(array('guid' => elgg_get_site_entity()->guid, 'annotation_names' => 'spam_login_filter_ip', 'annotation_created_time_upper' => $week_ago, 'limit' => false));
    elgg_set_ignore_access($ia);
}
示例#4
0
 public function testElggDeleteAnnotations()
 {
     $e = new ElggObject();
     $e->save();
     for ($i = 0; $i < 30; $i++) {
         $e->annotate('test_annotation', rand(0, 10000));
     }
     $options = array('guid' => $e->getGUID(), 'limit' => 0);
     $annotations = elgg_get_annotations($options);
     $this->assertIdentical(30, count($annotations));
     $this->assertTrue(elgg_delete_annotations($options));
     $annotations = elgg_get_annotations($options);
     $this->assertTrue(empty($annotations));
     $this->assertTrue($e->delete());
 }
示例#5
0
function shoutout_edit($guid, $attached_guid, $text, $access_id, $attachments, $video_url = '')
{
    // TODO: handle video URL if any
    $user_guid = elgg_get_logged_in_user_guid();
    if ($guid) {
        $shoutout = get_entity($guid);
        if (!elgg_instanceof($shoutout, 'object', 'shoutout')) {
            return FALSE;
        }
    } else {
        $shoutout = new ElggObject();
        $shoutout->subtype = 'shoutout';
        $shoutout->owner_guid = $user_guid;
        $shoutout->container_guid = $user_guid;
        $shoutout->title = elgg_echo('shoutout:entity_title');
    }
    $shoutout->access_id = $access_id;
    $shoutout->description = $text;
    shoutout_handle_video($shoutout, $video_url);
    if ($shoutout->save()) {
        if ($guid) {
            // clear attachment annotations
            elgg_delete_annotations(array('guid' => $guid, 'annotation_name' => 'shoutout_attachment'));
            // clear attached entity
            remove_entity_relationships($guid, 'shoutout_attached_entity');
        }
        if ($attachments) {
            foreach ($attachments as $a) {
                $time_bit = $a['timeBit'];
                $file_name = urldecode($a['fileName']);
                $value = "{$time_bit}|{$file_name}";
                create_annotation($shoutout->guid, 'shoutout_attachment', $value, '', $user_guid, ACCESS_PUBLIC);
            }
        }
        if ($attached_guid) {
            add_entity_relationship($shoutout->guid, 'shoutout_attached_entity', $attached_guid);
        }
        if (!$guid) {
            add_to_river('river/object/shoutout/create', 'create', elgg_get_logged_in_user_guid(), $shoutout->guid);
        }
        return TRUE;
    } else {
        return FALSE;
    }
}
示例#6
0
文件: events.php 项目: socialweb/PiGo
function group_tools_join_group_event($event, $type, $params)
{
    global $NOTIFICATION_HANDLERS;
    static $auto_notification;
    // only load plugin setting once
    if (!isset($auto_notification)) {
        $auto_notification = false;
        if (elgg_get_plugin_setting("auto_notification", "group_tools") == "yes") {
            $auto_notification = true;
        }
    }
    if (!empty($params) && is_array($params)) {
        $group = elgg_extract("group", $params);
        $user = elgg_extract("user", $params);
        if ($user instanceof ElggUser && $group instanceof ElggGroup) {
            if ($auto_notification && !empty($NOTIFICATION_HANDLERS) && is_array($NOTIFICATION_HANDLERS)) {
                // only auto subscribe to site and email notifications
                $auto_notification_handlers = array("site", "email");
                foreach ($NOTIFICATION_HANDLERS as $method => $dummy) {
                    if (in_array($method, $auto_notification_handlers)) {
                        add_entity_relationship($user->getGUID(), "notify" . $method, $group->getGUID());
                    }
                }
            }
            // cleanup invites
            remove_entity_relationship($group->getGUID(), "invited", $user->getGUID());
            // and requests
            remove_entity_relationship($user->getGUID(), "membership_request", $group->getGUID());
            // cleanup email invitations
            $options = array("annotation_name" => "email_invitation", "annotation_value" => group_tools_generate_email_invite_code($group->getGUID(), $user->email), "limit" => false);
            if (elgg_is_logged_in()) {
                elgg_delete_annotations($options);
            } elseif ($annotations = elgg_get_annotations($options)) {
                group_tools_delete_annotations($annotations);
            }
        }
    }
}
示例#7
0
 /**
  * Listen to the create member_of_site relationship event to handle new users
  *
  * @param string            $event        the name of the event
  * @param string            $type         the type of the event
  * @param \ElggRelationship $relationship supplied param
  *
  * @return void
  */
 public static function siteJoinGroupInviteCode($event, $type, $relationship)
 {
     if (!self::validateSiteJoinRelationship($relationship)) {
         return;
     }
     $user_guid = (int) $relationship->guid_one;
     $user = get_user($user_guid);
     // check for manual email invited groups
     $group_invitecode = get_input('group_invitecode');
     if (empty($group_invitecode)) {
         return;
     }
     // ignore access
     $ia = elgg_set_ignore_access(true);
     $group = group_tools_check_group_email_invitation($group_invitecode);
     if (empty($group)) {
         // restore access settings
         elgg_set_ignore_access($ia);
         return;
     }
     // join the group
     $group->join($user);
     // cleanup the invite code
     $group_invitecode = sanitise_string($group_invitecode);
     elgg_delete_annotations(['guid' => $group->getGUID(), 'annotation_name' => 'email_invitation', 'wheres' => ["(v.string = '{$group_invitecode}' OR v.string LIKE '{$group_invitecode}|%')"], 'annotation_owner_guid' => $group->getGUID(), 'limit' => 1]);
     // restore access settings
     elgg_set_ignore_access($ia);
 }
示例#8
0
function elgg_poll_set_poll($guid, $poll, $event_length)
{
    $event = get_entity($guid);
    if (elgg_instanceof($event, 'object', 'event_calendar') && $event->canEdit()) {
        // TODO as workaround simply remove database entries related to any former event poll votings in case it is an existing poll that gets edited
        // long time solution for editing polls might be to keep voting data if appropriate and former poll details are preserved
        elgg_delete_annotations(array('guid' => $event->guid, 'annotation_name' => 'event_poll_vote', 'limit' => false));
        remove_entity_relationships($event->guid, 'event_poll_voted', true);
        // sort the poll by time within date
        event_poll_set_time_limits($event, $poll, $event_length);
        $event->event_poll = serialize($poll);
        $event->is_event_poll = 1;
    }
    return '';
}
 public function testElggGetAnnotationsAnnotationOwnerGuids()
 {
     $options = array('annotation_owner_guids' => array());
     $a_e_map = array();
     // create test annotations on a single entity
     for ($i = 0; $i < 3; $i++) {
         do {
             $e = $this->entities[array_rand($this->entities)];
         } while (in_array($e->guid, $a_e_map));
         // remove annotations left over from previous tests.
         elgg_delete_annotations(array('annotation_owner_guid' => $e->guid));
         $annotations = $this->createRandomAnnotations($e);
         foreach ($annotations as $a) {
             $options['annotation_owner_guids'][] = $e->guid;
             $a_e_map[$a->id] = $e->guid;
         }
     }
     $as = elgg_get_annotations($options);
     $this->assertEqual(count($a_e_map), count($as));
     foreach ($as as $a) {
         $this->assertEqual($a_e_map[$a->id], $a->owner_guid);
     }
 }
示例#10
0
<?php

/**
 * Decline an email invitation
 */
$invitecode = get_input("invitecode");
if (!empty($invitecode)) {
    $options = array("annotation_name" => "email_invitation", "annotation_value" => $invitecode, "limit" => false);
    if (elgg_delete_annotations($options)) {
        system_message(elgg_echo("groups:invitekilled"));
    } else {
        register_error(elgg_echo("group_tools:action:groups:decline_email_invitation:error:delete"));
    }
} else {
    register_error(elgg_echo("group_tools:action:groups:email_invitation:error:input"));
}
forward(REFERER);
 /**
  * Called after each test method.
  */
 public function tearDown()
 {
     access_show_hidden_entities(true);
     elgg_delete_annotations(array('guid' => $this->object->guid));
     access_show_hidden_entities(false);
 }
示例#12
0
/**
 * Event when the user joins a site, mostly when registering
 *
 * @param string           $event        create
 * @param string           $type         member_of_site
 * @param ElggRelationship $relationship the membership relation
 *
 * @return void
 */
function group_tools_join_site_handler($event, $type, $relationship)
{
    if (!empty($relationship) && $relationship instanceof ElggRelationship) {
        $user_guid = $relationship->guid_one;
        $site_guid = $relationship->guid_two;
        $user = get_user($user_guid);
        if (!empty($user)) {
            // ignore access
            $ia = elgg_set_ignore_access(true);
            // add user to the auto join groups
            $auto_joins = elgg_get_plugin_setting("auto_join", "group_tools");
            if (!empty($auto_joins)) {
                $auto_joins = string_to_tag_array($auto_joins);
                foreach ($auto_joins as $group_guid) {
                    $group = get_entity($group_guid);
                    if (!empty($group) && $group instanceof ElggGroup) {
                        if ($group->site_guid == $site_guid) {
                            // join the group
                            $group->join($user);
                        }
                    }
                }
            }
            // auto detect email invited groups
            $groups = group_tools_get_invited_groups_by_email($user->email, $site_guid);
            if (!empty($groups)) {
                foreach ($groups as $group) {
                    // join the group
                    $group->join($user);
                }
            }
            // check for manual email invited groups
            $group_invitecode = get_input("group_invitecode");
            if (!empty($group_invitecode)) {
                $group = group_tools_check_group_email_invitation($group_invitecode);
                if (!empty($group)) {
                    // join the group
                    $group->join($user);
                    // cleanup the invite code
                    $group_invitecode = sanitise_string($group_invitecode);
                    $options = array("guid" => $group->getGUID(), "annotation_name" => "email_invitation", "wheres" => array("(v.string = '" . $group_invitecode . "' OR v.string LIKE '" . $group_invitecode . "|%')"), "annotation_owner_guid" => $group->getGUID(), "limit" => 1);
                    // ignore access in order to cleanup the invitation
                    $ia = elgg_set_ignore_access(true);
                    elgg_delete_annotations($options);
                    // restore access
                    elgg_set_ignore_access($ia);
                }
            }
            // find domain based groups
            $groups = group_tools_get_domain_based_groups($user, $site_guid);
            if (!empty($groups)) {
                foreach ($groups as $group) {
                    // join the group
                    $group->join($user);
                }
            }
            // restore access settings
            elgg_set_ignore_access($ia);
        }
    }
}
示例#13
0
/**
 * Add or remove a tag from the follow list of a user
 *
 * @param string $tag       the tag to (un)follow
 * @param int    $user_guid the user to save the setting for
 * @param bool   $track     add/remove the tag
 *
 * @return void
 */
function tag_tools_toggle_following_tag($tag, $user_guid = 0, $track = null)
{
    if (empty($tag)) {
        return;
    }
    $user_guid = sanitise_int($user_guid, false);
    if (empty($user_guid)) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    $user = get_user($user_guid);
    if (empty($user)) {
        return;
    }
    if ($track === null) {
        $track = !tag_tools_is_user_following_tag($tag, $user_guid);
    }
    // remove the tag from the follow list
    $ia = elgg_set_ignore_access(true);
    elgg_delete_annotations(['guid' => $user_guid, 'limit' => false, 'annotation_name' => 'follow_tag', 'annotation_value' => $tag]);
    tag_tools_remove_tag_from_notification_settings($tag, $user_guid);
    elgg_set_ignore_access($ia);
    // did the user want to follow the tag
    if ($track) {
        $user->annotate('follow_tag', $tag, ACCESS_PUBLIC);
    }
    // reset cache
    tag_tools_get_user_following_tags($user_guid, true);
}
示例#14
0
 /**
  * Reset the number of unread messages for an user.
  *
  * @param obj $user
  * @return boolean
  */
 public function resetUnreadMessageCount($user = null)
 {
     if (!$user) {
         $user = elgg_get_logged_in_user_entity();
     }
     return elgg_delete_annotations(array('annotation_owner_guids' => $user->getGUID(), 'annotation_names' => 'unread_messages', 'guid' => $this->getGUID()));
 }
示例#15
0
文件: ElggEntity.php 项目: elgg/elgg
 /**
  * Deletes all annotations owned by this object (annotations.owner_guid = $this->guid).
  * If you pass a name, only annotations matching that name will be deleted.
  *
  * @param null|string $name The name of annotations to delete.
  * @return bool
  * @since 1.8
  */
 public function deleteOwnedAnnotations($name = null)
 {
     // access is turned off for this because they might
     // no longer have access to an entity they created annotations on.
     $ia = elgg_set_ignore_access(true);
     $options = array('annotation_owner_guid' => $this->guid, 'limit' => 0);
     if ($name) {
         $options['annotation_name'] = $name;
     }
     $r = elgg_delete_annotations($options);
     elgg_set_ignore_access($ia);
     return $r;
 }
示例#16
0
 /**
  * Remove existing answer from this user
  *
  * @param ElggUser $user The user whose vote is being removed
  * @return bool True on success
  */
 public function removeVote(ElggUser $user)
 {
     return elgg_delete_annotations(array('guid' => $this->guid, 'annotation_owner_guid' => $user->guid, 'annotation_name' => 'scheduling_poll_answer', 'limit' => 0));
 }
示例#17
0
$current_day = 0;
$count = 0;
$annotations_removed = 0;
$annotations_stack = array();
foreach ($downloads as $download) {
    $day = (int) floor(($download->time_created - $start_date) / (3600 * 24));
    if ($current_day == $day) {
        $count++;
        $annotation_stack[] = $download;
    } else {
        // if this day is out of the ordinary, reduce to median
        if ($count > $cutoff) {
            if (!$preview) {
                while (count($annotation_stack) > $median) {
                    $annotation = array_pop($annotation_stack);
                    elgg_delete_annotations(array('annotation_id' => $annotation->id));
                }
            }
            $annotations_removed += $count - $median;
        }
        // reset to handle the next day
        $count = 1;
        $annotation_stack = array($download);
        $current_day = $day;
    }
}
if (!$preview) {
    system_message(elgg_echo('plugins:action:normalize:notpreview'));
} else {
    system_message(elgg_echo('plugins:action:normalize:preview'));
}
示例#18
0
/**
 * Clear all annotations belonging to a given owner_guid
 *
 * @param int $owner_guid The owner
 *
 * @return int Number of annotations deleted
 * @deprecated 1.8 Use elgg_delete_annotations()
 */
function clear_annotations_by_owner($owner_guid)
{
    elgg_deprecated_notice('clear_annotations_by_owner() is deprecated by elgg_delete_annotations()', 1.8);
    if (!$owner_guid) {
        return false;
    }
    $options = array('annotation_owner_guid' => $owner_guid, 'limit' => 0);
    return elgg_delete_annotations($options);
}
示例#19
0
 /**
  * delete reminder annotations for a time period
  * use the $all override to delete all reminder annotations period
  * 
  * @param type $starttime
  * @param type $endtime
  * @param type $all
  */
 public function removeReminders($starttime, $endtime, $all = false)
 {
     $starttime = sanitize_int($starttime);
     $endtime = sanitize_int($endtime);
     $options = array('guid' => $this->guid, 'annotation_names' => array('reminder'), 'limit' => false);
     if (!$all) {
         $options['wheres'] = "CAST(v.string as SIGNED) BETWEEN {$starttime} AND {$endtime}";
     }
     return elgg_delete_annotations($options);
 }