Exemple #1
0
 /**
  * Add a menu item to the follow_tag
  *
  * @param string          $hook         the name of the hook
  * @param string          $type         the type of the hook
  * @param \ElggMenuItem[] $return_value current return value
  * @param mixed           $params       supplied params
  *
  * @return void|\ElggMenuItem[]
  */
 public static function registerFollowTag($hook, $type, $return_value, $params)
 {
     if (!elgg_is_logged_in()) {
         return;
     }
     $tag = elgg_extract('tag', $params);
     if (is_null($tag) || $tag === '') {
         return;
     }
     $encoded_tag = htmlspecialchars($tag, ENT_QUOTES, 'UTF-8', false);
     $following = tag_tools_is_user_following_tag($tag);
     $action_url = elgg_http_add_url_query_elements('action/tag_tools/follow_tag', ['tag' => $encoded_tag]);
     $return_value[] = \ElggMenuItem::factory(['name' => 'follow_tag_on', 'text' => elgg_view_icon('refresh'), 'title' => elgg_echo('tag_tools:follow_tag:menu:on'), 'href' => $action_url, 'is_action' => true, 'item_class' => $following ? 'hidden' : '']);
     $return_value[] = \ElggMenuItem::factory(['name' => 'follow_tag_off', 'text' => elgg_view_icon('refresh-hover'), 'title' => elgg_echo('tag_tools:follow_tag:menu:off'), 'href' => $action_url, 'is_action' => true, 'item_class' => $following ? '' : 'hidden']);
     return $return_value;
 }
 /**
  * Make the tag tools notification
  *
  * @param string                           $hook         the name of the hook
  * @param string                           $type         the type of the hook
  * @param \Elgg\Notifications\Notification $return_value current return value
  * @param array                            $params       supplied params
  *
  * @return void|\Elgg\Notifications\Notification
  */
 public static function prepareMessage($hook, $type, $return_value, $params)
 {
     if (!self::validateNotificationEvent($params)) {
         return;
     }
     $recipient = $return_value->getRecipient();
     $method = elgg_extract('method', $params);
     $relationship = elgg_extract('object', $params);
     $language = elgg_extract('language', $params);
     $entity = get_entity($relationship->guid_two);
     $sending_tags = tag_tools_get_unsent_tags($entity);
     $tag = [];
     foreach ($sending_tags as $sending_tag) {
         if (!tag_tools_is_user_following_tag($sending_tag, $recipient->getGUID())) {
             // user is not following this tag
             continue;
         }
         if (!tag_tools_check_user_tag_notification_method($sending_tag, $method, $recipient->getGUID())) {
             continue;
         }
         $tag[] = $sending_tag;
     }
     $tag = implode(', ', $tag);
     // is this a new entity of an update on an existing
     $time_diff = (int) $entity->time_updated - (int) $entity->time_created;
     if ($time_diff < 60) {
         // new entity
         $return_value->subject = elgg_echo('tag_tools:notification:follow:subject', [$tag], $language);
         $return_value->summary = elgg_echo('tag_tools:notification:follow:summary', [$tag], $language);
         $return_value->body = elgg_echo('tag_tools:notification:follow:message', [$tag, $entity->getURL()], $language);
     } else {
         // updated entity
         $return_value->subject = elgg_echo('tag_tools:notification:follow:update:subject', [$tag], $language);
         $return_value->summary = elgg_echo('tag_tools:notification:follow:update:summary', [$tag], $language);
         $return_value->body = elgg_echo('tag_tools:notification:follow:update:message', [$tag, $entity->getURL()], $language);
     }
     return $return_value;
 }
Exemple #3
0
if (!empty($vars['type'])) {
    $query_params["type"] = $vars['type'];
}
if (!empty($vars['subtype'])) {
    $query_params["subtype"] = $vars['subtype'];
}
if (!empty($vars['base_url'])) {
    $url = $vars['base_url'];
} else {
    $url = elgg_get_site_url() . "search";
}
$http_query = http_build_query($query_params);
if ($http_query) {
    $url .= "?" . $http_query;
}
echo elgg_view('output/url', array('href' => $url, 'text' => $vars['value'], 'encode_text' => true, 'rel' => 'tag'));
if (elgg_is_logged_in()) {
    $encoded_tag = htmlspecialchars($vars["value"], ENT_QUOTES, "UTF-8", false);
    $on_class = "";
    $off_class = "hidden";
    if (tag_tools_is_user_following_tag($encoded_tag)) {
        $on_class = "hidden";
        $off_class = "";
    }
    $urlencoded_tag = urlencode($encoded_tag);
    echo "<ul class='elgg-menu elgg-menu-hz elgg-menu-follow-tag'><li class='elgg-menu-item-follow-tag-on {$on_class}'>";
    echo elgg_view("output/url", array("text" => elgg_view_icon("refresh"), "href" => "action/tag_tools/follow_tag?tag=" . $urlencoded_tag, "title" => elgg_echo("tag_tools:follow_tag:menu:on"), "is_action" => true));
    echo "</li><li class='elgg-menu-item-follow-tag-off {$off_class}'>";
    echo elgg_view("output/url", array("text" => elgg_view_icon("refresh-hover"), "href" => "action/tag_tools/follow_tag?tag=" . $urlencoded_tag, "title" => elgg_echo("tag_tools:follow_tag:menu:off"), "is_action" => true));
    echo "</li></ul>";
}
Exemple #4
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);
}