Example #1
0
/**
 * Post a Wire
 *
 * @param string $text   Content of the wire
 * @param int    $parent Parent GUID
 *
 * @return SuccessResult|ErrorResult
 */
function my_post_to_wire($text, $parent)
{
    $result = false;
    $user = elgg_get_logged_in_user_entity();
    $api_application = ws_pack_get_current_api_application();
    if (!empty($user) && !empty($api_application)) {
        $text = substr($text, 0, 140);
        // returns guid of wire post
        $post_wire = thewire_save_post($text, $user->guid, 2, $parent);
        if ($post_wire !== false) {
            $result = new SuccessResult($post_wire);
        }
        if ($result === false) {
            $result = new ErrorResult(elgg_echo("ws_pack:error:notfound"));
        }
        return $result;
    }
}
Example #2
0
/**
 * Web service for making a wire post
 *
 * @param string $username username of author
 * @param string $text     the content of wire post
 * @param string $acess    access level for post{-1, 0, 1, 2, -2}
 * @param string $password password of user
 *
 * @return bool
 */
function wire_save_post($username, $text, $access = ACCESS_PUBLIC)
{
    $user = get_user_by_username($username);
    if (!$user) {
        throw new InvalidParameterException('registration:usernamenotvalid');
    }
    $return['success'] = false;
    if (empty($text)) {
        $return['message'] = elgg_echo("thewire:blank");
        return $return;
    }
    $access_id = strip_tags($access);
    $guid = thewire_save_post($text, $user->guid, $access_id, "api");
    if (!$guid) {
        $return['message'] = elgg_echo("thewire:error");
        return $return;
    }
    $return['success'] = true;
    return $return;
}
Example #3
0
File: add.php Project: eokyere/elgg
$access_id = get_default_access();
$location = get_input('location');
$method = get_input('method');
$parent = (int) get_input('parent', 0);
if (!$parent) {
    $parent = 0;
}
// convert the shout body into tags
$tagarray = filter_string($body);
// Make sure the title / description aren't blank
if (empty($body)) {
    register_error(elgg_echo("thewire:blank"));
    forward("mod/thewire/add.php");
    // Otherwise, save the thewire post
} else {
    if (!thewire_save_post($body, $access_id, $parent, $method)) {
        register_error(elgg_echo("thewire:error"));
        if ($location == "activity") {
            forward("mod/riverdashboard/");
        } else {
            forward("mod/thewire/add.php");
        }
    }
    // Now let's add tags. We can pass an array directly to the object property! Easy.
    if (is_array($tagarray)) {
        $thewire->tags = $tagarray;
    }
    // Success message
    system_message(elgg_echo("thewire:posted"));
    // Forward
    if ($location == "activity") {
Example #4
0
/**
 * @param $parent_guid
 * @param $text
 * @param int $access
 * @param string $wireMethod
 * @param $username
 * @return mixed
 * @throws InvalidParameterException
 */
function wire_post_comment($parent_guid, $text, $access = ACCESS_PUBLIC, $wireMethod = "api", $username)
{
    if (!$username) {
        $user = elgg_get_logged_in_user_entity();
    } else {
        $user = get_user_by_username($username);
        if (!$user) {
            throw new InvalidParameterException('registration:usernamenotvalid');
        }
    }
    $return['success'] = false;
    if (empty($text)) {
        $return['message'] = elgg_echo("thewire:blank");
        return $return;
    }
    if ($access == 'ACCESS_FRIENDS') {
        $access_id = -2;
    } elseif ($access == 'ACCESS_PRIVATE') {
        $access_id = 0;
    } elseif ($access == 'ACCESS_LOGGED_IN') {
        $access_id = 1;
    } elseif ($access == 'ACCESS_PUBLIC') {
        $access_id = 2;
    } else {
        $access_id = -2;
    }
    $guid = thewire_save_post($text, $user->guid, $access_id, $parent_guid, $wireMethod);
    if (!$guid) {
        $return['message'] = elgg_echo("thewire:error");
        return $return;
    }
    $return['success'] = true;
    return $return;
}
Example #5
0
<?php

/**
 * Action for adding a wire post
 * 
 */
// don't filter since we strip and filter escapes some characters
$body = get_input('body', '', false);
$access_id = ACCESS_PUBLIC;
$method = 'site';
$parent_guid = (int) get_input('parent_guid');
// make sure the post isn't blank
if (empty($body)) {
    register_error(elgg_echo("thewire:blank"));
    forward(REFERER);
}
$guid = thewire_save_post($body, elgg_get_logged_in_user_guid(), $access_id, $parent_guid, $method);
if ($guid) {
    $options = array('pagination' => false, 'limit' => 1);
    $output = elgg_list_river($options);
    echo $output;
}
system_message(elgg_echo("thewire:posted"));
forward(REFERER);
Example #6
0
function pleio_api_send_tweio($message, $access_id = "", $reply = 0, $group_id = 0)
{
    $access_ids = explode(",", $access_id);
    $user = elgg_get_logged_in_user_entity();
    $user_id = $user !== false ? $user->guid : 0;
    $method = "api";
    $parent_guid = $reply;
    $guid = false;
    $group_id = intval($group_id);
    foreach ($access_ids as $access_id) {
        $access = get_access_collection($access_id);
        if ($access || $access_id < 3) {
            $site_guid = false;
            if ($access && strpos($access->name, "subsite_acl_") === 0) {
                $site_guid = intval(substr($access->name, 12));
            }
            $guid = thewire_save_post($message, $user_id, $access_id, $parent_guid, $method);
            if ($site_guid) {
                $site_guid = $site_guid;
                // site_guid wordt niet gezet door thewire_save_post
                update_data(sprintf("update %sentities set site_guid = %d where guid = %d", get_config("dbprefix"), $site_guid, $guid));
                update_data(sprintf("update %sriver set site_guid = %d where object_guid = %d", get_config("dbprefix"), $site_guid, $guid));
            }
            if ($group_id) {
                // container_guid wordt niet gezet door thewire_save_post
                update_data(sprintf("update %sentities set container_guid = %d where guid = %d", get_config("dbprefix"), $group_id, $guid));
            }
        }
    }
    if ($guid) {
        return new SuccessResult(elgg_echo("thewire:posted"));
    } else {
        return new ErrorResult(elgg_echo("thewire:error"));
    }
}
/**
 * Listen and process incoming SMS'
 */
function thewire_incoming_sms($event, $object_type, $object)
{
    if ($object && $object->subtype == get_subtype_id('object', 'sms')) {
        // Get user from phone number
        if (is_plugin_enabled('smsclient') && is_plugin_enabled('smslogin')) {
            // By this stage the owner should be logged in (requires SMS Login)
            if (thewire_save_post($object->description, get_default_access(), 0, 'sms')) {
                return false;
            }
        }
    }
    return true;
    // always create the shout even if it can't be sent
}
}
elgg_set_page_owner_guid($container->guid);
if (!$subtype) {
    $subtype = WALL_SUBTYPE;
}
if (!$status && !$address) {
    register_error(elgg_echo('wall:error:empty_form'));
    forward(REFERER);
}
if ($poster->guid == $container_guid) {
    $title = elgg_echo('wall:post:status_update', array(elgg_echo('wall:byline', array($poster->name))));
} else {
    $title = elgg_echo('wall:post:wall_to_wall', array(elgg_echo('wall:byline', array($poster->name))));
}
if ($subtype == 'thewire' && is_callable('thewire_save_post')) {
    $guid = thewire_save_post($status, $poster->guid, $access_id, 0, 'wall');
    $wall_post = get_entity($guid);
} else {
    $wall_post = new ElggObject();
    $wall_post->subtype = $subtype;
    $wall_post->access_id = $access_id;
    $wall_post->owner_guid = $poster->guid;
    $wall_post->container_guid = $container->guid;
    $wall_post->title = $title;
    $wall_post->description = $status;
    if ($guid = $wall_post->save()) {
        // Create a river entry for this wall post
        $river_id = elgg_create_river_item(array('view' => 'river/object/hjwall/create', 'action_type' => 'create', 'subject_guid' => $wall_post->getOwnerGUID(), 'object_guid' => $wall_post->getGUID(), 'target_guid' => $wall_post->getContainerGUID()));
    }
}
if ($guid && $wall_post) {
Example #9
0
function thewire_hook_handler($hook, $type, $returnvalue, $params)
{
    $access_id = ACCESS_PUBLIC;
    $method = 'site';
    $parent_guid = (int) get_input('parent_guid');
    thewire_save_post($params['body'], elgg_get_logged_in_user_guid(), $access_id, $parent_guid, $method);
    return true;
}
Example #10
0
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     if (!$this->post) {
         if ($this->subtype == 'thewire' && is_callable('thewire_save_post')) {
             $guid = thewire_save_post($this->status, $this->poster->guid, $this->access_id, 0, 'wall');
             $this->post = get_entity($guid);
         } else {
             $this->post = new Post();
             $this->post->subtype = $this->subtype;
             $this->post->owner_guid = $this->poster->guid;
             $this->post->container_guid = $this->container->guid;
             $guid = $this->post->save();
         }
     }
     $this->post->title = $this->title;
     $this->post->description = $this->status;
     $this->post->access_id = $this->access_id;
     if (!$this->post->guid) {
         $this->result->addError(elgg_echo('wall:create:error'));
         return;
     }
     if (Integration::isElggVersionBelow('1.9.0')) {
         $river_id = add_to_river('river/object/hjwall/create', 'create', $this->poster->guid, $this->post->guid);
     } else {
         // Create a river entry for this wall post
         $river_id = elgg_create_river_item(array('view' => 'river/object/hjwall/create', 'action_type' => 'create', 'subject_guid' => $this->post->owner_guid, 'object_guid' => $this->post->guid, 'target_guid' => $this->post->container_guid));
     }
     $river = elgg_get_river(array('ids' => $river_id));
     $this->river = $river ? $river[0] : null;
     $this->post->origin = 'wall';
     $qualifiers = elgg_trigger_plugin_hook('extract:qualifiers', 'wall', array('source' => $this->post->description), array());
     if (count($qualifiers['hashtags'])) {
         $this->post->tags = $qualifiers['hashtags'];
     }
     if (count($qualifiers['usernames'])) {
         foreach ($qualifiers['usernames'] as $username) {
             $user = get_user_by_username($username);
             if (elgg_instanceof($user) && !in_array($user->guid, $this->friend_guids)) {
                 $this->friend_guids[] = $user->guid;
             }
         }
     }
     // Add 'tagged_in' relationships
     // If the access level for the post is not set to private, also create a river item
     // with the access level specified in their settings by the tagged user
     if (!empty($this->friend_guids)) {
         foreach ($this->friend_guids as $friend_guid) {
             if (add_entity_relationship($friend_guid, 'tagged_in', $this->post->guid)) {
                 if (!in_array($this->access_id, array(ACCESS_PRIVATE, ACCESS_LOGGED_IN, ACCESS_PUBLIC))) {
                     $river_access_id = elgg_get_plugin_user_setting('river_access_id', $friend_guid, 'hypeWall');
                     if (!is_null($river_access_id) && $river_access_id !== ACCESS_PRIVATE) {
                         $river_id = elgg_create_river_item(array('view' => 'river/relationship/tagged/create', 'action_type' => 'tagged', 'subject_guid' => $friend_guid, 'object_guid' => $this->post->getGUID(), 'target_guid' => $this->post->getContainerGUID(), 'access_id' => $river_access_id));
                     }
                 }
             }
         }
     }
     // Wall post access id is set to private, which means it should be visible only to the poster and tagged users
     // Creating a new ACL for that
     if ($this->access_id == ACCESS_PRIVATE && count($this->friend_guids)) {
         $members = $this->friend_guids;
         $members[] = $this->poster->guid;
         $members[] = $this->container->guid;
         $acl_id = AccessCollection::create($members);
         $this->post->access_id = $acl_id;
         $this->post->save();
     }
     if (!empty($this->attachment_guids)) {
         foreach ($this->attachment_guids as $attachment_guid) {
             add_entity_relationship($attachment_guid, 'attached', $this->post->guid);
         }
     }
     // files being uploaded via $_FILES
     $uploads = hypeApps()->uploader->handle('upload_guids');
     $uploaded_file_guids = [];
     if ($uploads) {
         foreach ($uploads as $upload) {
             if ($upload instanceof \ElggFile) {
                 $file_obj = $upload;
             } else {
                 if ($upload instanceof \hypeJunction\Files\Upload) {
                     $file_obj = $upload->file;
                 }
             }
             if ($file_obj->guid) {
                 $uploaded_file_guids[] = $file_obj->guid;
             }
         }
     }
     // Something is broken in the hypeApps setter, so doing this hack for now
     $this->upload_guids = array_merge($this->upload_guids, $uploaded_file_guids);
     if (!empty($this->upload_guids)) {
         foreach ($this->upload_guids as $upload_guid) {
             $upload = get_entity($upload_guid);
             if ($upload) {
                 $upload->description = $this->post->description;
                 $upload->origin = 'wall';
                 $upload->access_id = $this->post->access_id;
                 $upload->container_guid = $this->container->canWriteToContainer($this->poster->guid, 'object', 'file') ? $this->container->guid : ELGG_ENTITIES_ANY_VALUE;
                 if ($upload->save()) {
                     add_entity_relationship($upload_guid, 'attached', $this->post->guid);
                 }
             }
         }
     }
     $this->post->setLocation($this->location);
     $this->post->address = $this->address;
     if ($this->post->address && $this->make_bookmark) {
         $document = elgg_trigger_plugin_hook('extract:meta', 'wall', array('src' => $this->post->address));
         $bookmark = new ElggObject();
         $bookmark->subtype = "bookmarks";
         $bookmark->container_guid = $this->container->canWriteToContainer($this->poster->guid, 'object', 'bookmarks') ? $this->container->guid : ELGG_ENTITIES_ANY_VALUE;
         $bookmark->address = $this->post->address;
         $bookmark->access_id = $this->post->access_id;
         $bookmark->origin = 'wall';
         if (!$document) {
             $bookmark->title = $this->post->title;
             $bookmark->description = $this->post->description;
             $bookmark->tags = $this->post->tags;
         } else {
             $bookmark->title = filter_tags($document->meta->title);
             $bookmark->description = filter_tags($document->meta->description);
             $bookmark->tags = string_to_tag_array(filter_tags($document->meta->keywords));
         }
         $bookmark->save();
         $this->bookmark = $bookmark;
     }
     if ($this->post->save()) {
         $message = $this->post->formatMessage();
         $params = array('entity' => $this->post, 'user' => $this->poster, 'message' => $message, 'url' => $this->post->getURL(), 'origin' => 'wall');
         elgg_trigger_plugin_hook('status', 'user', $params);
         // Trigger a publish event, so that we can send out notifications
         elgg_trigger_event('publish', 'object', $this->post);
         if (get_input('widget')) {
             elgg_push_context('widgets');
         }
         if (elgg_is_xhr()) {
             $this->result->output .= elgg_list_river(array('object_guids' => $this->post->guid, 'pagination' => false, 'pagination_type' => false, 'limit' => 0));
         }
         $this->result->addMessage(elgg_echo('wall:create:success'));
         if ($this->container instanceof \ElggUser) {
             $this->result->setForwardURL(hypeWall()->router->normalize("owner/{$this->container->username}"));
         } else {
             $this->result->setForwardURL(hypeWall()->router->normalize("container/{$this->container->guid}"));
         }
     } else {
         $this->result->addError(elgg_echo('wall:create:error'));
     }
 }
Example #11
0
function eg_wire_post($wire_post)
{
    error_log('here is wirepost - ' . $wire_post);
    $userid = elgg_get_logged_in_user_guid();
    $access_id = "public";
    $return['guid'] = thewire_save_post($wire_post, $userid, $access_id);
    return $return;
}