/**
 * Flag suspicious messages
 *
 * @param string     $event  "create"
 * @param string     $type   "object"
 * @param ElggObject $entity Message
 * @return void
 */
function hypeapps_inbox_monitor_flag_suspicious_messages($event, $type, $entity)
{
    if ($entity->getSubtype() != 'messages') {
        return;
    }
    $policy = elgg_get_plugin_setting('policy', 'hypeInboxMonitor', 'nothing');
    $blacklist = hypeapps_inbox_monitor_get_blacklist();
    $options = array('also_check' => $blacklist);
    $filter = new \JCrowe\BadWordFilter\BadWordFilter($options);
    $badWords = $filter->getDirtyWordsFromString("{$entity->title} {$entity->description}");
    $entity->badwords = $badWords;
    switch ($policy) {
        case 'mask':
            $entity->title = $filter->clean($entity->title);
            $entity->description = $filter->clean($entity->title);
            break;
        case 'silence':
            $replacement = '<span rel="bwsilent">$0</span>';
            $entity->title = $filter->clean($entity->title, $replacement);
            $entity->description = $filter->clean($entity->description, $replacement);
            break;
        case 'remove':
            $replacement = '<span rel="bwremoved">[' . elgg_echo('inbox:monitor:removed') . ']</span>';
            $entity->title = $filter->clean($entity->title, $replacement);
            $entity->description = $filter->clean($entity->description, $replacement);
            break;
    }
    $entity->save();
}
Beispiel #2
0
/**
 * ban user if sending too many messages
 *
 * @param string     $event
 * @param string     $type
 * @param ElggObject $object
 * @return bool
 */
function community_spam_messages_throttle($event, $type, $object)
{
    if ($object->getSubtype() !== 'messages') {
        return;
    }
    if (community_spam_is_new_user()) {
        $msg_limit = elgg_get_plugin_setting('new_user_msg_limit', 'community_spam_tools');
    } else {
        $msg_limit = elgg_get_plugin_setting('msg_limit', 'community_spam_tools');
    }
    if (!$msg_limit) {
        return;
    }
    // two message objects created per message but after they are saved,
    // both are set to private so we only have access to one later on
    $msg_limit = $msg_limit + 1;
    $params = array('type' => 'object', 'subtype' => 'messages', 'created_time_lower' => time() - 5 * 60, 'metadata_names' => 'fromId', 'metadata_values' => elgg_get_logged_in_user_guid(), 'count' => true);
    $num_msgs = elgg_get_entities_from_metadata($params);
    if ($num_msgs > $msg_limit) {
        $spammer = elgg_get_logged_in_user_entity();
        $spammer->annotate('banned', 1);
        // this integrates with ban plugin
        $spammer->ban("Sent {$num_msgs} in 5 minutes");
        return false;
    }
}
Beispiel #3
0
 public function testGetSubtype()
 {
     $guid = $this->entity->guid;
     $this->assertEqual($this->entity->getSubtype(), 'elgg_entity_test_subtype');
     _elgg_services()->entityCache->remove($guid);
     $this->entity = null;
     $this->entity = get_entity($guid);
     $this->assertEqual($this->entity->getSubtype(), 'elgg_entity_test_subtype');
 }
Beispiel #4
0
 public function testGetSubtype()
 {
     $guid = $this->entity->guid;
     $this->assertEqual($this->entity->getSubtype(), 'elgg_entity_test_subtype');
     _elgg_invalidate_cache_for_entity($guid);
     $this->entity = null;
     $this->entity = get_entity($guid);
     $this->assertEqual($this->entity->getSubtype(), 'elgg_entity_test_subtype');
 }
Beispiel #5
0
/**
 * Format and return the URL for crud object.
 *
 * @param ElggObject $entity Assembly object
 * @return string URL of crud object.
 */
function crud_url_handler($entity)
{
    if (!$entity->getOwnerEntity()) {
        // default to a standard view if no owner.
        return FALSE;
    }
    /*if (!$entity->testAssembly()) {
    		return FALSE;
    	}*/
    //$friendly_title = elgg_get_friendly_title($entity->title);
    return $entity->getSubtype() . "/view/{$entity->guid}";
}
Beispiel #6
0
/**
 * Event handler for videolist
 *
 * @param string $event
 * @param string $object_type
 * @param ElggObject $object
 */
function videolist_object_notifications($event, $object_type, $object)
{
    static $flag;
    if (!isset($flag)) {
        $flag = 0;
    }
    if (is_callable('object_notifications')) {
        if ($object instanceof ElggObject) {
            if ($object->getSubtype() == 'videolist_item') {
                if ($flag == 0) {
                    $flag = 1;
                    object_notifications($event, $object_type, $object);
                }
            }
        }
    }
}
Beispiel #7
0
/**
 * Change the access of all file in a folder
 *
 * @param ElggObject $folder the folder to change the file access for
 *
 * @return void
 */
function file_tools_change_files_access($folder)
{
    if (!empty($folder) && $folder instanceof ElggObject) {
        if ($folder->getSubtype() == FILE_TOOLS_SUBTYPE) {
            // change access on files in this folder
            $options = array("type" => "object", "subtype" => "file", "container_guid" => $folder->getContainerGUID(), "limit" => false, "relationship" => FILE_TOOLS_RELATIONSHIP, "relationship_guid" => $folder->getGUID());
            if ($files = elgg_get_entities_from_relationship($options)) {
                // need to unregister an event listener
                elgg_unregister_event_handler("update", "object", "file_tools_object_handler");
                foreach ($files as $file) {
                    $file->access_id = $folder->access_id;
                    $file->save();
                }
            }
        }
    }
}
Beispiel #8
0
/**
 * When given a widget entity and a new requested location, saves the new location
 * and also provides a sensible ordering for all widgets in that column
 *
 * @param \ElggObject $widget The widget entity
 * @param int        $order  The order within the column
 * @param int        $column The column (1, 2 or 3)
 *
 * @return bool Depending on success
 * @deprecated 1.8 use \ElggWidget::move()
 */
function save_widget_location(\ElggObject $widget, $order, $column)
{
    elgg_deprecated_notice('save_widget_location() is deprecated', 1.8);
    if ($widget instanceof \ElggObject) {
        if ($widget->getSubtype() == "widget") {
            // If you can't move the widget, don't save a new location
            if (!$widget->draggable) {
                return false;
            }
            // Sanitise the column value
            if ($column != 1 || $column != 2 || $column != 3) {
                $column = 1;
            }
            $widget->column = (int) $column;
            $ordertmp = array();
            $params = array('context' => $widget->context, 'column' => $column);
            if ($entities = get_entities_from_metadata_multi($params, 'object', 'widget')) {
                foreach ($entities as $entity) {
                    $entityorder = $entity->order;
                    if ($entityorder < $order) {
                        $ordertmp[$entityorder] = $entity;
                    }
                    if ($entityorder >= $order) {
                        $ordertmp[$entityorder + 10000] = $entity;
                    }
                }
            }
            $ordertmp[$order] = $widget;
            ksort($ordertmp);
            $orderticker = 10;
            foreach ($ordertmp as $orderval => $entity) {
                $entity->order = $orderticker;
                $orderticker += 10;
            }
            return true;
        } else {
            register_error($widget->getSubtype());
        }
    }
    return false;
}
Beispiel #9
0
/**
 * Listen to entity ownership changes and update icon ownership by moving
 * icons to their new owner's directory on filestore.
 *
 * This will only transfer icons that have a custom location on filestore
 * and are owned by the entity's owner (instead of the entity itself).
 * Even though core icon service does not store icons in the entity's owner
 * directory, there are plugins that do (e.g. file plugin) - this handler
 * helps such plugins avoid ownership mismatch.
 *
 * @param string     $event  "update:after"
 * @param string     $type   "object"|"group"
 * @param ElggObject $entity Entity
 * @return void
 * @access private
 */
function _elgg_filestore_move_icons($event, $type, $entity)
{
    $original_attributes = $entity->getOriginalAttributes();
    if (empty($original_attributes['owner_guid'])) {
        return;
    }
    $previous_owner_guid = $original_attributes['owner_guid'];
    $new_owner_guid = $entity->owner_guid;
    $sizes = elgg_get_icon_sizes($entity->getType(), $entity->getSubtype());
    foreach ($sizes as $size => $opts) {
        $new_icon = $entity->getIcon($size);
        if ($new_icon->owner_guid == $entity->guid) {
            // we do not need to update icons that are owned by the entity itself
            continue;
        }
        if ($new_icon->owner_guid != $new_owner_guid) {
            // a plugin implements some custom logic
            continue;
        }
        $old_icon = new \ElggIcon();
        $old_icon->owner_guid = $previous_owner_guid;
        $old_icon->setFilename($new_icon->getFilename());
        if (!$old_icon->exists()) {
            // there is no icon to move
            continue;
        }
        if ($new_icon->exists()) {
            // there is already a new icon
            // just removing the old one
            $old_icon->delete();
            elgg_log("Entity {$entity->guid} has been transferred to a new owner but an icon was left behind under {$old_icon->getFilenameOnFilestore()}. " . "Old icon has been deleted", 'NOTICE');
            continue;
        }
        $old_icon->transfer($new_icon->owner_guid, $new_icon->getFilename());
        elgg_log("Entity {$entity->guid} has been transferred to a new owner. " . "Icon was moved from {$old_icon->getFilenameOnFilestore()} to {$new_icon->getFilenameOnFilestore()}.", 'NOTICE');
    }
}
Beispiel #10
0
/**
 * Push breadcrumbs from the given crud object going up in the parent hirarchy
 *
 * @param ElggObject $last Ending object
 * @param ElggObject $entity Current object
 * @param CrudTemplate $crud Crud template object
 */
function crud_push_breadcrumb($last, $entity, $crud = NULL)
{
    if (empty($crud)) {
        $crud = crud_get_handler($entity->getSubtype());
    }
    if ($entity->parent_guid) {
        $parent = get_entity($entity->parent_guid);
        crud_push_breadcrumb($last, $parent);
    } else {
        $group = $entity->getContainerEntity();
        elgg_push_breadcrumb($group->name, "{$crud->crud_type}/owner/{$entity->container_guid}");
    }
    $title = $entity->title;
    if (empty($title)) {
        $title = elgg_echo("{$crud->module}:{$crud->crud_type}");
    }
    if ($entity == $last) {
        elgg_push_breadcrumb($title);
    } else {
        elgg_push_breadcrumb($title, "{$crud->crud_type}/view/{$entity->guid}");
    }
}
Beispiel #11
0
 /**
  * @SWG\Definition(
  *  definition="FileFolder",
  *  required={"guid","subtype","title"},
  *  @SWG\Property(property="guid", type="integer"),
  *  @SWG\Property(property="subtype", type="string", enum={"file", "folder"}),
  *  @SWG\Property(property="title", type="string"),
  *  @SWG\Property(property="time_created", type="string")
  * )
  */
 private function parseObject(\ElggObject $object)
 {
     $subtype = $object->getSubtype();
     $data = array('guid' => $object->guid, 'subtype' => $subtype, 'title' => html_entity_decode($object->title, ENT_QUOTES), 'time_created' => date('c', $object->time_created));
     if ($subtype == "file") {
         $data['url'] = elgg_normalize_url('file/download/' . $object->guid);
     } else {
         $data['url'] = $object->getURL();
     }
     return $data;
 }