示例#1
0
/**
 * This function is called during the "init" event
 *
 * @return void
 */
function thewire_tools_init()
{
    elgg_extend_view("js/elgg", "js/thewire_tools/site");
    elgg_extend_view("css/elgg", "css/thewire_tools/site");
    if (thewire_tools_groups_enabled()) {
        // add widget (for Widget Manager only)
        elgg_register_widget_type("thewire_groups", elgg_echo("widgets:thewire_groups:title"), elgg_echo("widgets:thewire_groups:description"), array("groups"), true);
        // add group tool option
        add_group_tool_option("thewire", elgg_echo("thewire_tools:groups:tool_option"), true);
        // add a menu item to the owner block
        elgg_register_plugin_hook_handler("register", "menu:owner_block", "thewire_tools_owner_block_menu");
    }
    // adds wire post form to the wire widget
    elgg_extend_view("core/river/filter", "thewire_tools/activity_post", 400);
    elgg_extend_view("page/layouts/elements/filter", "thewire_tools/group_activity", 400);
    // settings
    elgg_extend_view("notifications/subscriptions/personal", "thewire_tools/notifications/settings");
    // register ajax view
    elgg_register_ajax_view("thewire_tools/reshare");
    elgg_register_ajax_view("thewire_tools/reshare_list");
    elgg_register_ajax_view("thewire_tools/thread");
    // add some extra widgets (for Widget Manager only)
    elgg_register_widget_type("index_thewire", elgg_echo("widgets:index_thewire:title"), elgg_echo("widgets:index_thewire:description"), array("index"), true);
    elgg_register_widget_type("thewire_post", elgg_echo("widgets:thewire_post:title"), elgg_echo("widgets:thewire_post:description"), array("index", "dashboard"), false);
    // register events
    elgg_register_event_handler("create", "object", "thewire_tools_create_object_event_handler", 100);
    elgg_register_event_handler("upgrade", "system", "thewire_tools_upgrade_system_event_handler");
    // register hooks
    elgg_register_plugin_hook_handler("route", "thewire", "thewire_tools_route_thewire");
    elgg_register_plugin_hook_handler("access:collections:write", "all", "thewire_tools_access_write_hook", 999);
    elgg_register_plugin_hook_handler("entity:url", "object", "thewire_tools_widget_title_url");
    elgg_register_plugin_hook_handler("group_tool_widgets", "widget_manager", "thewire_tools_tool_widgets_handler");
    elgg_register_plugin_hook_handler("register", "menu:entity", "thewire_tools_register_entity_menu_items");
    elgg_register_plugin_hook_handler("register", "menu:entity", array('\\ColdTrick\\TheWireTools\\EntityMenu', 'registerReshare'));
    elgg_register_plugin_hook_handler("register", "menu:river", "thewire_tools_register_river_menu_items");
    elgg_register_plugin_hook_handler("action", "notificationsettings/save", "thewire_tools_notifications_settings_save_hook");
    // upgrade function
    run_function_once("thewire_tools_runonce");
    // overrule default save action
    elgg_unregister_action("thewire/add");
    elgg_register_action("thewire/add", dirname(__FILE__) . "/actions/thewire/add.php");
    elgg_register_action("thewire_tools/mentions_upgrade", dirname(__FILE__) . "/actions/upgrades/mentions.php");
}
示例#2
0
/**
 * This function is called during the 'init' event
 *
 * @return void
 */
function thewire_tools_init()
{
    elgg_extend_view('js/elgg', 'js/thewire_tools.js');
    elgg_extend_view('css/elgg', 'css/thewire_tools.css');
    if (thewire_tools_groups_enabled()) {
        // add widget (for Widget Manager only)
        elgg_register_widget_type('thewire_groups', elgg_echo('widgets:thewire_groups:title'), elgg_echo('widgets:thewire_groups:description'), ['groups'], true);
        // add group tool option
        add_group_tool_option('thewire', elgg_echo('thewire_tools:groups:tool_option'), true);
    }
    // adds wire post form to the wire widget
    elgg_extend_view('core/river/filter', 'thewire_tools/activity_post', 400);
    elgg_extend_view('page/layouts/elements/filter', 'thewire_tools/group_activity', 400);
    // settings
    elgg_extend_view('notifications/subscriptions/personal', 'thewire_tools/notifications/settings');
    // featured
    elgg_extend_view('thewire/sidebar', 'thewire_tools/extends/thewire/sidebar', 400);
    // register ajax view
    elgg_register_ajax_view('thewire_tools/reshare');
    elgg_register_ajax_view('thewire_tools/reshare_list');
    elgg_register_ajax_view('thewire_tools/thread');
    // add some extra widgets (for Widget Manager only)
    elgg_register_widget_type('index_thewire', elgg_echo('widgets:index_thewire:title'), elgg_echo('widgets:index_thewire:description'), ['index'], true);
    elgg_register_widget_type('thewire_post', elgg_echo('widgets:thewire_post:title'), elgg_echo('widgets:thewire_post:description'), ['index', 'dashboard'], false);
    // register events
    elgg_register_event_handler('create', 'object', '\\ColdTrick\\TheWireTools\\Notifications::triggerMentionNotificationEvent');
    // register hooks
    elgg_register_plugin_hook_handler('route', 'thewire', '\\ColdTrick\\TheWireTools\\Router::thewire');
    elgg_register_plugin_hook_handler('access:collections:write', 'all', '\\ColdTrick\\TheWireTools\\Access::collectionsWrite', 999);
    elgg_register_plugin_hook_handler('entity:url', 'object', '\\ColdTrick\\TheWireTools\\Widgets::widgetTitleURL');
    elgg_register_plugin_hook_handler('group_tool_widgets', 'widget_manager', '\\ColdTrick\\TheWireTools\\Widgets::groupToolBasedWidgets');
    elgg_register_plugin_hook_handler('register', 'menu:entity', '\\ColdTrick\\TheWireTools\\Menus::entityRegisterImprove');
    elgg_register_plugin_hook_handler('register', 'menu:entity', '\\ColdTrick\\TheWireTools\\Menus::entityRegisterReshare');
    elgg_register_plugin_hook_handler('register', 'menu:entity', '\\ColdTrick\\TheWireTools\\Menus::entityRegisterFeature');
    elgg_register_plugin_hook_handler('register', 'menu:river', '\\ColdTrick\\TheWireTools\\Menus::riverRegisterReply');
    elgg_register_plugin_hook_handler('register', 'menu:owner_block', '\\ColdTrick\\TheWireTools\\Menus::ownerBlockRegister');
    elgg_register_plugin_hook_handler('action', 'notificationsettings/save', '\\ColdTrick\\TheWireTools\\Notifications::saveUserNotificationsSettings');
    // overrule default save action
    elgg_unregister_action('thewire/add');
    elgg_register_action('thewire/add', dirname(__FILE__) . '/actions/thewire/add.php');
    elgg_register_action('thewire_tools/toggle_feature', dirname(__FILE__) . '/actions/toggle_feature.php');
}
示例#3
0
/**
 * This function is called during the "init" event
 *
 * @return void
 */
function thewire_tools_init()
{
    elgg_extend_view("js/elgg", "thewire_tools/js/site");
    elgg_extend_view("css/elgg", "thewire_tools/css/site");
    // overrule url handler
    elgg_register_entity_url_handler("thewire_tools_url_handler", "object", "thewire");
    if (thewire_tools_groups_enabled()) {
        // add widget (for Widget Manager only)
        elgg_register_widget_type("thewire_groups", elgg_echo("widgets:thewire_groups:title"), elgg_echo("widgets:thewire_groups:description"), "groups", true);
        // add group tool option
        add_group_tool_option("thewire", elgg_echo("thewire_tools:groups:tool_option"), true);
        // add a menu item to the owner block
        elgg_register_plugin_hook_handler("register", "menu:owner_block", "thewire_tools_owner_block_menu");
    }
    // adds wire post form to the wire widget
    elgg_extend_view("widgets/thewire/content", "thewire_tools/thewire_post", 400);
    elgg_extend_view("widgets/index_thewire/content", "thewire_tools/thewire_post", 400);
    elgg_extend_view("core/river/filter", "thewire_tools/activity_post", 400);
    elgg_extend_view("page/layouts/content", "thewire_tools/group_activity", 400);
    // add some extra widgets (for Widget Manager only)
    elgg_register_widget_type("index_thewire", elgg_echo("widgets:index_thewire:title"), elgg_echo("widgets:index_thewire:description"), "index", true);
    elgg_register_widget_type("thewire_post", elgg_echo("widgets:thewire_post:title"), elgg_echo("widgets:thewire_post:description"), "index,dashboard", false);
    // register events
    elgg_register_event_handler("create", "object", "thewire_tools_create_object_event_handler", 100);
    // register hooks
    elgg_register_plugin_hook_handler("route", "thewire", "thewire_tools_route_thewire");
    elgg_register_plugin_hook_handler("access:collections:write", "all", "thewire_tools_access_write_hook", 999);
    elgg_register_plugin_hook_handler("forward", "all", "thewire_tools_forward_hook");
    elgg_register_plugin_hook_handler("widget_url", "widget_manager", "thewire_tools_widget_title_url");
    elgg_register_plugin_hook_handler("register", "menu:entity", "thewire_tools_register_entity_menu_items");
    elgg_register_plugin_hook_handler("register", "menu:river", "thewire_tools_register_river_menu_items");
    // upgrade function
    run_function_once("thewire_tools_runonce");
    // overrule default save action
    elgg_unregister_action("thewire/add");
    elgg_register_action("thewire/add", dirname(__FILE__) . "/actions/thewire/add.php");
}
示例#4
0
/**
 * Save a wire post, overrules the default function because we need to support groups
 *
 * @param string $text        the text of the post
 * @param int    $userid      the owner of the post
 * @param int    $access_id   the access level of the post
 * @param int    $parent_guid is this a reply on another post
 * @param string $method      which method was used
 *
 * @return bool|int the GUID of the new wire post or false
 */
function thewire_tools_save_post($text, $userid, $access_id, $parent_guid = 0, $method = "site")
{
    // set correct container
    $container_guid = $userid;
    // check the access id
    if ($access_id == ACCESS_PRIVATE) {
        // private wire posts aren"t allowed
        $access_id = ACCESS_LOGGED_IN;
    } elseif (thewire_tools_groups_enabled()) {
        // allow the saving of a wire post in a group (if enabled)
        if (!in_array($access_id, array(ACCESS_FRIENDS, ACCESS_LOGGED_IN, ACCESS_PUBLIC))) {
            // try to find a group with access_id
            $group_options = array("type" => "group", "limit" => 1, "metadata_name_value_pairs" => array("group_acl" => $access_id));
            $groups = elgg_get_entities_from_metadata($group_options);
            if (!empty($groups)) {
                $group = $groups[0];
                if ($group->thewire_enable == "no") {
                    // not allowed to post in this group
                    register_error(elgg_echo("thewire_tools:groups:error:not_enabled"));
                    // let creation of object fail
                    return false;
                } else {
                    $container_guid = $group->getGUID();
                }
            }
        }
    }
    // create the new post
    $post = new ElggObject();
    $post->subtype = "thewire";
    $post->owner_guid = $userid;
    $post->container_guid = $container_guid;
    $post->access_id = $access_id;
    // only xxx characters allowed (see plugin setting)
    $text = elgg_substr($text, 0, thewire_tools_get_wire_length());
    // no html tags allowed so we escape
    $post->description = htmlspecialchars($text, ENT_NOQUOTES, "UTF-8");
    $post->method = $method;
    //method: site, email, api, ...
    $tags = thewire_get_hashtags($text);
    if (!empty($tags)) {
        $post->tags = $tags;
    }
    // must do this before saving so notifications pick up that this is a reply
    if ($parent_guid) {
        $post->reply = true;
    }
    $guid = $post->save();
    // set thread guid
    if ($parent_guid) {
        $post->addRelationship($parent_guid, "parent");
        // name conversation threads by guid of first post (works even if first post deleted)
        $parent_post = get_entity($parent_guid);
        $post->wire_thread = $parent_post->wire_thread;
    } else {
        // first post in this thread
        $post->wire_thread = $guid;
    }
    if ($guid) {
        add_to_river("river/object/thewire/create", "create", $post->getOwnerGUID(), $post->getGUID());
        // let other plugins know we are setting a user status
        $params = array("entity" => $post, "user" => $post->getOwnerEntity(), "message" => $post->description, "url" => $post->getURL(), "origin" => "thewire");
        elgg_trigger_plugin_hook("status", "user", $params);
    }
    return $guid;
}
示例#5
0
}
$count_down = "<span>{$char_limit}</span> {$chars_left}";
$num_lines = 2;
if ($char_limit == 0) {
    $num_lines = 3;
    $count_down = "";
} else {
    if ($char_limit > 140) {
        $num_lines = 3;
    }
}
$post_input = elgg_view("input/plaintext", array("name" => "body", "class" => "mtm thewire-textarea", "rows" => $num_lines, "value" => $post_value, "data-max-length" => $char_limit));
$submit_button = elgg_view("input/submit", array("value" => $text, "class" => "elgg-button elgg-button-submit thewire-submit-button"));
$mentions = "";
$access_input = "";
if (thewire_tools_groups_enabled()) {
    if ($post) {
        $access_input = elgg_view("input/hidden", array("name" => "access_id", "value" => $post->access_id));
    } else {
        $page_owner_entity = elgg_get_page_owner_entity();
        if ($page_owner_entity instanceof ElggGroup) {
            // in a group only allow sharing in the current group
            $access_input = elgg_view("input/hidden", array("name" => "access_id", "value" => $page_owner_entity->group_acl));
            $mentions = "<div class='elgg-subtext mbn'>" . elgg_echo("thewire_tools:groups:mentions") . "</div>";
        } else {
            $params = array("name" => "access_id");
            if (elgg_in_context("widgets")) {
                $params["class"] = "thewire-tools-widget-access";
            }
            elgg_push_context("thewire_add");
            $access_input = elgg_view("input/access", $params);
示例#6
0
 /**
  * Optionally extend the group owner block with a link to the wire posts of the group
  *
  * @param string         $hook_name   'register'
  * @param string         $entity_type 'menu:owner_block'
  * @param ElggMenuItem[] $return      all the current menu items
  * @param array          $params      supplied params
  *
  * @return ElggMenuItem[]
  */
 public static function ownerBlockRegister($hook_name, $entity_type, $return, $params)
 {
     $group = elgg_extract('entity', $params);
     if (!elgg_instanceof($group, 'group')) {
         return;
     }
     if (!thewire_tools_groups_enabled()) {
         return;
     }
     if ($group->thewire_enable == 'no') {
         return;
     }
     if (!$group->canEdit() && !$group->isMember()) {
         return;
     }
     $return[] = new \ElggMenuItem('thewire', elgg_echo('thewire_tools:group:title'), "thewire/group/{$group->getGUID()}");
     return $return;
 }
示例#7
0
/**
 * Save a wire post, overrules the default function because we need to support groups
 *
 * @param string $text         the text of the post
 * @param int    $userid       the owner of the post
 * @param int    $access_id    the access level of the post
 * @param int    $parent_guid  is this a reply on another post
 * @param string $method       which method was used
 * @param int    $reshare_guid is the a (re)share of some content item
 *
 * @return bool|int the GUID of the new wire post or false
 */
function thewire_tools_save_post($text, $userid, $access_id, $parent_guid = 0, $method = "site", $reshare_guid = 0)
{
    // set correct container
    $container_guid = $userid;
    // check the access id
    if ($access_id == ACCESS_PRIVATE) {
        // private wire posts aren't allowed
        $access_id = ACCESS_LOGGED_IN;
    } elseif (thewire_tools_groups_enabled()) {
        // allow the saving of a wire post in a group (if enabled)
        if (!in_array($access_id, [ACCESS_FRIENDS, ACCESS_LOGGED_IN, ACCESS_PUBLIC])) {
            // try to find a group with access_id
            $group_options = ['type' => 'group', 'limit' => 1, 'metadata_name_value_pairs' => ['group_acl' => $access_id]];
            $groups = elgg_get_entities_from_metadata($group_options);
            if (!empty($groups)) {
                $group = $groups[0];
                if ($group->thewire_enable == 'no') {
                    // not allowed to post in this group
                    register_error(elgg_echo('thewire_tools:groups:error:not_enabled'));
                    // let creation of object fail
                    return false;
                } else {
                    $container_guid = $group->getGUID();
                }
            }
        }
    }
    // create the new post
    $post = new ElggObject();
    $post->subtype = 'thewire';
    $post->owner_guid = $userid;
    $post->container_guid = $container_guid;
    $post->access_id = $access_id;
    // only xxx characters allowed (see plugin setting of thewire, 0 is unlimited)
    $max_length = thewire_tools_get_wire_length();
    if ($max_length) {
        $text = elgg_substr($text, 0, $max_length);
    }
    // no html tags allowed so we escape
    $post->description = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
    $post->method = $method;
    //method: site, email, api, ...
    $tags = thewire_get_hashtags($text);
    if (!empty($tags)) {
        $post->tags = $tags;
    }
    // must do this before saving so notifications pick up that this is a reply
    if ($parent_guid) {
        $post->reply = true;
    }
    $guid = $post->save();
    if ($guid) {
        // set thread guid
        if ($parent_guid) {
            $post->addRelationship($parent_guid, 'parent');
            // name conversation threads by guid of first post (works even if first post deleted)
            $parent_post = get_entity($parent_guid);
            $post->wire_thread = $parent_post->wire_thread;
        } else {
            // first post in this thread
            $post->wire_thread = $guid;
        }
        // add reshare
        if ($reshare_guid) {
            $post->addRelationship($reshare_guid, 'reshare');
        }
        // add to river
        elgg_create_river_item(['view' => 'river/object/thewire/create', 'action_type' => 'create', 'subject_guid' => $post->getOwnerGUID(), 'object_guid' => $post->getGUID()]);
        // let other plugins know we are setting a user status
        $params = ['entity' => $post, 'user' => $post->getOwnerEntity(), 'message' => $post->description, 'url' => $post->getURL(), 'origin' => 'thewire'];
        elgg_trigger_plugin_hook('status', 'user', $params);
    }
    return $guid;
}