Пример #1
0
function app2_blog_save($title, $text, $excerpt, $tags, $access, $container_guid)
{
    $user = elgg_get_logged_in_user_entity();
    if (!$user) {
        throw new InvalidParameterException('registration:usernamenotvalid');
    }
    $obj = new ElggObject();
    $obj->subtype = "blog";
    $obj->owner_guid = $user->guid;
    $obj->container_guid = $container_guid;
    $obj->access_id = strip_tags($access);
    $obj->method = "api";
    $obj->description = strip_tags($text);
    $obj->title = elgg_substr(strip_tags($title), 0, 140);
    $obj->status = 'published';
    $obj->comments_on = 'On';
    $obj->excerpt = strip_tags($excerpt);
    $obj->tags = strip_tags($tags);
    $guid = $obj->save();
    elgg_create_river_item('river/object/blog/create', 'create', $user->guid, $obj->guid);
    if ($guid) {
        return true;
    } else {
        return false;
    }
}
Пример #2
0
/**
 * Create a new wire post, the TGS way
 *
 * @param string $text           The post text
 * @param int    $userid         The user's guid
 * @param int    $access_id      Public/private etc
 * @param int    $parent_guid    Parent post guid (if any)
 * @param string $method         The method (default: 'site')
 * @param int    $container_guid Container guid (for group wire posts)
 * @return guid or false if failure
 */
function tgswire_save_post($text, $userid, $access_id, $parent_guid = 0, $method = "site", $container_guid = NULL)
{
    $post = new ElggObject();
    $post->subtype = "thewire";
    $post->owner_guid = $userid;
    $post->access_id = $access_id;
    // Check if we're removing the limit
    if (elgg_get_plugin_setting('limit_wire_chars', 'wire-extender') == 'yes') {
        // only 200 characters allowed
        $text = elgg_substr($text, 0, 200);
    }
    // If supplied with a container_guid, use it
    if ($container_guid) {
        $post->container_guid = $container_guid;
    }
    // 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 ($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->owner_guid, $post->guid);
        // 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;
}
Пример #3
0
/**
 * Returns an excerpt.
 * Will return up to n chars stopping at the nearest space.
 * If no spaces are found (like in Japanese) will crop off at the
 * n char mark. Adds ... if any text was chopped.
 *
 * @param string $text      The full text to excerpt
 * @param int    $num_chars Return a string up to $num_chars long
 *
 * @return string
 * @since 1.7.2
 */
function elgg_get_excerpt($text, $num_chars = 250)
{
    $text = trim(elgg_strip_tags($text));
    $string_length = elgg_strlen($text);
    if ($string_length <= $num_chars) {
        return $text;
    }
    // handle cases
    $excerpt = elgg_substr($text, 0, $num_chars);
    $space = elgg_strrpos($excerpt, ' ', 0);
    // don't crop if can't find a space.
    if ($space === false) {
        $space = $num_chars;
    }
    $excerpt = trim(elgg_substr($excerpt, 0, $space));
    if ($string_length != elgg_strlen($excerpt)) {
        $excerpt .= '...';
    }
    return $excerpt;
}
Пример #4
0
function hypefaker_add_wire($owner, $parent = null)
{
    $locale = elgg_get_plugin_setting('locale', 'hypeFaker', 'en_US');
    $faker = Factory::create($locale);
    $wire = new ElggObject();
    $wire->subtype = 'thewire';
    $wire->owner_guid = $owner->guid;
    $tags = $faker->words(5);
    $text = $faker->text(80);
    foreach ($tags as $tag) {
        $text .= " #{$tag}";
    }
    if ($parent) {
        $wire->reply = true;
        $username = $parent->getOwnerEntity()->username;
        $text = "@{$username} {$text}";
    }
    $limit = elgg_get_plugin_setting('limit', 'thewire');
    if ($limit > 0) {
        $text = elgg_substr($text, 0, $limit);
    }
    $wire->description = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
    $wire->tags = $tags;
    $wire->method = 'faker';
    $wire->access_id = ACCESS_PUBLIC;
    $wire->__faker = true;
    if ($wire->save()) {
        if ($parent) {
            $wire->addRelationship($parent->guid, 'parent');
            $wire->wire_thread = $parent->wire_thread;
        } else {
            $wire->wire_thread = $wire->guid;
        }
        elgg_create_river_item(array('view' => 'river/object/thewire/create', 'action_type' => 'create', 'subject_guid' => $wire->owner_guid, 'object_guid' => $wire->guid));
        $params = array('entity' => $wire, 'user' => $owner, 'message' => $wire->description, 'url' => $wire->getURL(), 'origin' => 'thewire');
        elgg_trigger_plugin_hook('status', 'user', $params);
        return $wire;
    }
    return false;
}
Пример #5
0
/**
 * Web service for making a blog post
 *
 * @param string $username username of author
 * @param string $title    the title of blog
 * @param string $excerpt  the excerpt of blog
 * @param string $text     the content of blog
 * @param string $tags     tags for blog
 * @param string $access   Access level of blog
 *
 * @return bool
 */
function blog_save($username, $title, $text, $excerpt = "", $tags = "blog", $access = ACCESS_PUBLIC)
{
    $user = get_user_by_username($username);
    if (!$user) {
        throw new InvalidParameterException('registration:usernamenotvalid');
    }
    $obj = new ElggObject();
    $obj->subtype = "blog";
    $obj->owner_guid = $user->guid;
    $obj->access_id = strip_tags($access);
    $obj->method = "api";
    $obj->description = strip_tags($text);
    $obj->title = elgg_substr(strip_tags($title), 0, 140);
    $obj->status = 'published';
    $obj->comments_on = 'On';
    $obj->excerpt = strip_tags($excerpt);
    $obj->tags = strip_tags($tags);
    $guid = $obj->save();
    add_to_river('river/object/blog/create', 'create', $user->guid, $obj->guid);
    $return['success'] = true;
    $return['message'] = elgg_echo('blog:message:saved');
    return $return;
}
/**
 * Return a string with highlighted matched queries and relevant context
 * Determins context based upon occurance and distance of words with each other.
 *
 * @param string $haystack
 * @param string $query
 * @param int $min_match_context = 30
 * @param int $max_length = 300
 * @return string
 */
function search_get_highlighted_relevant_substrings($haystack, $query, $min_match_context = 30, $max_length = 300)
{
    global $CONFIG;
    $haystack = strip_tags($haystack);
    $haystack_length = elgg_strlen($haystack);
    $haystack_lc = elgg_strtolower($haystack);
    $words = search_remove_ignored_words($query, 'array');
    // if haystack < $max_length return the entire haystack w/formatting immediately
    if ($haystack_length <= $max_length) {
        $return = search_highlight_words($words, $haystack);
        return $return;
    }
    // get the starting positions and lengths for all matching words
    $starts = array();
    $lengths = array();
    foreach ($words as $word) {
        $word = elgg_strtolower($word);
        $count = elgg_substr_count($haystack_lc, $word);
        $word_len = elgg_strlen($word);
        // find the start positions for the words
        if ($count > 1) {
            $offset = 0;
            while (FALSE !== ($pos = elgg_strpos($haystack_lc, $word, $offset))) {
                $start = $pos - $min_match_context > 0 ? $pos - $min_match_context : 0;
                $starts[] = $start;
                $stop = $pos + $word_len + $min_match_context;
                $lengths[] = $stop - $start;
                $offset += $pos + $word_len;
            }
        } else {
            $pos = elgg_strpos($haystack_lc, $word);
            $start = $pos - $min_match_context > 0 ? $pos - $min_match_context : 0;
            $starts[] = $start;
            $stop = $pos + $word_len + $min_match_context;
            $lengths[] = $stop - $start;
        }
    }
    $offsets = search_consolidate_substrings($starts, $lengths);
    // figure out if we can adjust the offsets and lengths
    // in order to return more context
    $total_length = array_sum($offsets);
    $add_length = 0;
    if ($total_length < $max_length) {
        $add_length = floor(($max_length - $total_length) / count($offsets) / 2);
        $starts = array();
        $lengths = array();
        foreach ($offsets as $offset => $length) {
            $start = $offset - $add_length > 0 ? $offset - $add_length : 0;
            $length = $length + $add_length;
            $starts[] = $start;
            $lengths[] = $length;
        }
        $offsets = search_consolidate_substrings($starts, $lengths);
    }
    // sort by order of string size descending (which is roughly
    // the proximity of matched terms) so we can keep the
    // substrings with terms closest together and discard
    // the others as needed to fit within $max_length.
    arsort($offsets);
    $return_strs = array();
    $total_length = 0;
    foreach ($offsets as $start => $length) {
        $string = trim(elgg_substr($haystack, $start, $length));
        // continue past if adding this substring exceeds max length
        if ($total_length + $length > $max_length) {
            continue;
        }
        $total_length += $length;
        $return_strs[$start] = $string;
    }
    // put the strings in order of occurence
    ksort($return_strs);
    // add ...s where needed
    $return = implode('...', $return_strs);
    if (!array_key_exists(0, $return_strs)) {
        $return = "...{$return}";
    }
    // add to end of string if last substring doesn't hit the end.
    $starts = array_keys($return_strs);
    $last_pos = $starts[count($starts) - 1];
    if ($last_pos + elgg_strlen($return_strs[$last_pos]) < $haystack_length) {
        $return .= '...';
    }
    $return = search_highlight_words($words, $return);
    return $return;
}
Пример #7
0
/**
 * Create a new wire post.
 *
 * @param string $text        The post text
 * @param int    $userid      The user's guid
 * @param int    $access_id   Public/private etc
 * @param int    $parent_guid Parent post guid (if any)
 * @param string $method      The method (default: 'site')
 * @return guid or false if failure
 */
function thewire_save_post($text, $userid, $access_id, $parent_guid = 0, $method = "site")
{
    $post = new ElggObject();
    $post->subtype = "thewire";
    $post->owner_guid = $userid;
    $post->access_id = $access_id;
    // Character limit is now from config
    $limit = elgg_get_plugin_setting('limit', 'thewire');
    if ($limit > 0) {
        $text = elgg_substr($text, 0, $limit);
    }
    // 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 ($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) {
        elgg_create_river_item(array('view' => 'river/object/thewire/create', 'action_type' => 'create', 'subject_guid' => $post->owner_guid, 'object_guid' => $post->guid));
        // 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;
}
Пример #8
0
/**
 * Create a new wire post.
 *
 * @param string $text        The post text
 * @param int    $userid      The user's guid
 * @param int    $access_id   Public/private etc
 * @param int    $parent_guid Parent post guid (if any)
 * @param string $method      The method (default: 'site')
 * @return guid or false if failure
 */
function thewire_save_post($text, $userid, $access_id, $parent_guid = 0, $method = "site")
{
    $post = new ElggObject();
    $post->subtype = "thewire";
    $post->owner_guid = $userid;
    $post->access_id = $access_id;
    // only 200 characters allowed
    $text = elgg_substr($text, 0, 200);
    // 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 ($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->owner_guid, $post->guid);
    }
    return $guid;
}
Пример #9
0
 /**
  * Tokenize the ECML tag attributes
  *
  * @param string $string Attribute string
  * @param bool $success
  * @return array
  */
 protected function tokenizeAttributes($string, &$success = null)
 {
     $success = true;
     $string = trim($string);
     if (empty($string)) {
         return array();
     }
     $attributes = array();
     $pos = 0;
     $char = elgg_substr($string, $pos, 1);
     // working var for assembling name and values
     $operand = $name = '';
     while ($char !== false && $char !== '') {
         switch ($char) {
             // handle quoted names/values
             case '"':
             case "'":
                 $quote = $char;
                 $next_char = elgg_substr($string, ++$pos, 1);
                 while ($next_char != $quote) {
                     // note: mb_substr returns "" instead of false...
                     if ($next_char === false || $next_char === '') {
                         // no matching quote. bail.
                         $success = false;
                         return array();
                     } elseif ($next_char === '\\') {
                         // allow escaping quotes
                         $after_escape = elgg_substr($string, $pos + 1, 1);
                         if ($after_escape === $quote) {
                             $operand .= $quote;
                             $pos += 2;
                             // skip escape and quote
                             $next_char = elgg_substr($string, $pos, 1);
                             continue;
                         }
                     }
                     $operand .= $next_char;
                     $next_char = elgg_substr($string, ++$pos, 1);
                 }
                 break;
             case self::ATTR_SEPARATOR:
                 $this->setAttribute($operand, $name, $attributes);
                 break;
             case self::ATTR_OPERATOR:
                 // save name, switch to value
                 $name = $operand;
                 $operand = '';
                 break;
             default:
                 $operand .= $char;
                 break;
         }
         $char = elgg_substr($string, ++$pos, 1);
     }
     // need to get the last attr
     $this->setAttribute($operand, $name, $attributes);
     return $attributes;
 }
Пример #10
0
$file->description = $desc;
$file->access_id = $access_id;
$file->container_guid = $container_guid;
$file->tags = string_to_tag_array($tags);
// we have a file upload, so process it
if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) {
    $prefix = "file/";
    // if previous file, delete it
    if ($new_file == false) {
        $filename = $file->getFilenameOnFilestore();
        if (file_exists($filename)) {
            unlink($filename);
        }
        // use same filename on the disk - ensures thumbnails are overwritten
        $filestorename = $file->getFilename();
        $filestorename = elgg_substr($filestorename, elgg_strlen($prefix));
    } else {
        $filestorename = elgg_strtolower(time() . $_FILES['upload']['name']);
    }
    $file->setFilename($prefix . $filestorename);
    /*$indexOfExt = strrpos($_FILES['upload']['name'], ".") + 1;
    	$ext = substr($_FILES['upload']['name'],$indexOfExt);
    	error_log($ext);*/
    $ext = pathinfo($_FILES['upload']['name'], PATHINFO_EXTENSION);
    if ($ext == "ppt") {
        $mime_type = 'application/vnd.ms-powerpoint';
    } else {
        $mime_type = ElggFile::detectMimeType($_FILES['upload']['tmp_name'], $_FILES['upload']['type'], $_FILES['upload']['name']);
    }
    // hack for Microsoft zipped formats
    $info = pathinfo($_FILES['upload']['name']);
Пример #11
0
<?php

/**
 * Elgg plugin project creation action
 */
// Get variables
$title = strip_tags(get_input("title"));
$description = plugins_strip_tags(get_input("description"));
$tags = get_input("tags");
$summary = strip_tags(elgg_substr(get_input('summary'), 0, 250));
$homepage = strip_tags(get_input('homepage'));
$donate = strip_tags(get_input('donate'));
$repo = strip_tags(get_input('repo'));
$license = get_input('license');
$plugincat = get_input('plugincat', 'uncategorized');
$project_access_id = get_input("project_access_id", ACCESS_PUBLIC);
$plugin_type = get_input('plugin_type');
if ($plugin_type != 'theme' && $plugin_type != 'languagepack') {
    $plugin_type = 'plugin';
}
$release_notes = plugins_strip_tags(get_input('release_notes'));
$elgg_version = get_input('elgg_version', 'Not specified');
$comments = get_input('comments', 'yes');
$version = strip_tags(get_input('version', 'Not specified'));
$recommended = get_input('recommended', FALSE);
$release_access_id = get_input('release_access_id', ACCESS_PUBLIC);
$user = get_loggedin_user();
// validate data
if (!$title) {
    register_error(elgg_echo('plugins:error:notitle'));
    forward(REFERER);
Пример #12
0
/**
 * Web service for making a blog post
 *
 * @param string $title the title of blog
 * @param $body
 * @param $comment_status
 * @param string $access Access level of blog
 *
 * @param $status
 * @param $username
 * @param string $tags tags for blog
 * @param string $excerpt the excerpt of blog
 * @return bool
 * @throws InvalidParameterException
 * @internal param $description
 * @internal param $container_guid
 * @internal param string $text the content of blog
 * @internal param string $username username of author
 */
function blog_save_post($title, $body, $comment_status, $access, $status, $username, $tags, $excerpt)
{
    if (!$username) {
        $user = elgg_get_logged_in_user_entity();
    } else {
        $user = get_user_by_username($username);
        if (!$user) {
            throw new InvalidParameterException('registration:usernamenotvalid');
        }
    }
    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;
    }
    $blog = new ElggBlog();
    $blog->subtype = "blog";
    $blog->owner_guid = $user->guid;
    $blog->container_guid = $user->guid;
    $blog->access_id = $access_id;
    $blog->description = $body;
    $blog->title = elgg_substr(strip_tags($title), 0, 140);
    $blog->status = $status;
    $blog->comments_on = $comment_status;
    $blog->excerpt = strip_tags($excerpt);
    $blog->tags = string_to_tag_array($tags);
    $guid = $blog->save();
    $newStatus = $blog->status;
    if ($guid > 0 && $newStatus == 'published') {
        elgg_create_river_item(array('view' => 'river/object/blog/create', 'action_type' => 'create', 'subject_guid' => $blog->owner_guid, 'object_guid' => $blog->getGUID()));
        elgg_trigger_event('publish', 'object', $blog);
        if ($guid) {
            $blog->time_created = time();
            $blog->save();
        }
        $return['guid'] = $guid;
        $return['message'] = $newStatus;
    } else {
        $return['guid'] = $guid;
        $return['message'] = $status;
    }
    return $return;
}
Пример #13
0
function create_file($container_guid, $title, $desc, $access_id, $guid, $tags, $new_file)
{
    // register_error("Creating file: " . $container_guid . ", vars: " . print_r(array($title, $desc, $access_id, $guid, $tags, $new_file), true));
    if ($new_file) {
        // must have a file if a new file upload
        if (empty($_FILES['upload']['name'])) {
            // cache information in session
            $_SESSION['uploadtitle'] = $title;
            $_SESSION['uploaddesc'] = $desc;
            $_SESSION['uploadtags'] = $tags;
            $_SESSION['uploadaccessid'] = $access_id;
            register_error(elgg_echo('file:nofile') . "no file new");
            forward($_SERVER['HTTP_REFERER']);
        }
        $file = new FilePluginFile();
        $file->subtype = "file";
        // if no title on new upload, grab filename
        if (empty($title)) {
            $title = $_FILES['upload']['name'];
        }
    } else {
        // load original file object
        $file = get_entity($guid);
        if (!$file) {
            register_error(elgg_echo('file:cannotload') . 'can"t load existing');
            forward($_SERVER['HTTP_REFERER']);
        }
        // user must be able to edit file
        if (!$file->canEdit()) {
            register_error(elgg_echo('file:noaccess') . 'no access to existing');
            forward($_SERVER['HTTP_REFERER']);
        }
    }
    $file->title = $title;
    $file->description = $desc;
    $file->access_id = $access_id;
    $file->container_guid = $container_guid;
    $tags = explode(",", $tags);
    $file->tags = $tags;
    // we have a file upload, so process it
    if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) {
        $prefix = "file/";
        // if previous file, delete it
        if ($new_file == false) {
            $filename = $file->getFilenameOnFilestore();
            if (file_exists($filename)) {
                unlink($filename);
            }
            // use same filename on the disk - ensures thumbnails are overwritten
            $filestorename = $file->getFilename();
            $filestorename = elgg_substr($filestorename, elgg_strlen($prefix));
        } else {
            $filestorename = elgg_strtolower(time() . $_FILES['upload']['name']);
        }
        $file->setFilename($prefix . $filestorename);
        $file->setMimeType($_FILES['upload']['type']);
        $file->originalfilename = $_FILES['upload']['name'];
        $file->simpletype = get_general_file_type($_FILES['upload']['type']);
        $file->open("write");
        $file->write(get_uploaded_file('upload'));
        $file->close();
        $guid = $file->save();
        // if image, we need to create thumbnails (this should be moved into a function)
        if ($guid && $file->simpletype == "image") {
            $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 60, 60, true);
            if ($thumbnail) {
                $thumb = new ElggFile();
                $thumb->setMimeType($_FILES['upload']['type']);
                $thumb->setFilename($prefix . "thumb" . $filestorename);
                $thumb->open("write");
                $thumb->write($thumbnail);
                $thumb->close();
                $file->thumbnail = $prefix . "thumb" . $filestorename;
                unset($thumbnail);
            }
            $thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 153, 153, true);
            if ($thumbsmall) {
                $thumb->setFilename($prefix . "smallthumb" . $filestorename);
                $thumb->open("write");
                $thumb->write($thumbsmall);
                $thumb->close();
                $file->smallthumb = $prefix . "smallthumb" . $filestorename;
                unset($thumbsmall);
            }
            $thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 600, 600, false);
            if ($thumblarge) {
                $thumb->setFilename($prefix . "largethumb" . $filestorename);
                $thumb->open("write");
                $thumb->write($thumblarge);
                $thumb->close();
                $file->largethumb = $prefix . "largethumb" . $filestorename;
                unset($thumblarge);
            }
        }
    } else {
        // not saving a file but still need to save the entity to push attributes to database
        $file->save();
    }
    return array($file, $guid);
}
Пример #14
0
/**
 * Test if two URLs are functionally identical.
 *
 * @tip If $ignore_params is used, neither the name nor its value will be considered when comparing.
 *
 * @tip The order of GET params doesn't matter.
 *
 * @param string $url1          First URL
 * @param string $url2          Second URL
 * @param array  $ignore_params GET params to ignore in the comparison
 *
 * @return bool
 * @since 1.8.0
 */
function elgg_http_url_is_identical($url1, $url2, $ignore_params = array('offset', 'limit'))
{
    global $CONFIG;
    // if the server portion is missing but it starts with / then add the url in.
    // @todo use elgg_normalize_url()
    if (elgg_substr($url1, 0, 1) == '/') {
        $url1 = elgg_get_site_url() . ltrim($url1, '/');
    }
    if (elgg_substr($url1, 0, 1) == '/') {
        $url2 = elgg_get_site_url() . ltrim($url2, '/');
    }
    // @todo - should probably do something with relative URLs
    if ($url1 == $url2) {
        return TRUE;
    }
    $url1_info = parse_url($url1);
    $url2_info = parse_url($url2);
    if (isset($url1_info['path'])) {
        $url1_info['path'] = trim($url1_info['path'], '/');
    }
    if (isset($url2_info['path'])) {
        $url2_info['path'] = trim($url2_info['path'], '/');
    }
    // compare basic bits
    $parts = array('scheme', 'host', 'path');
    foreach ($parts as $part) {
        if (isset($url1_info[$part]) && isset($url2_info[$part]) && $url1_info[$part] != $url2_info[$part]) {
            return FALSE;
        } elseif (isset($url1_info[$part]) && !isset($url2_info[$part])) {
            return FALSE;
        } elseif (!isset($url1_info[$part]) && isset($url2_info[$part])) {
            return FALSE;
        }
    }
    // quick compare of get params
    if (isset($url1_info['query']) && isset($url2_info['query']) && $url1_info['query'] == $url2_info['query']) {
        return TRUE;
    }
    // compare get params that might be out of order
    $url1_params = array();
    $url2_params = array();
    if (isset($url1_info['query'])) {
        if ($url1_info['query'] = html_entity_decode($url1_info['query'])) {
            $url1_params = elgg_parse_str($url1_info['query']);
        }
    }
    if (isset($url2_info['query'])) {
        if ($url2_info['query'] = html_entity_decode($url2_info['query'])) {
            $url2_params = elgg_parse_str($url2_info['query']);
        }
    }
    // drop ignored params
    foreach ($ignore_params as $param) {
        if (isset($url1_params[$param])) {
            unset($url1_params[$param]);
        }
        if (isset($url2_params[$param])) {
            unset($url2_params[$param]);
        }
    }
    // array_diff_assoc only returns the items in arr1 that aren't in arrN
    // but not the items that ARE in arrN but NOT in arr1
    // if arr1 is an empty array, this function will return 0 no matter what.
    // since we only care if they're different and not how different,
    // add the results together to get a non-zero (ie, different) result
    $diff_count = count(array_diff_assoc($url1_params, $url2_params));
    $diff_count += count(array_diff_assoc($url2_params, $url1_params));
    if ($diff_count > 0) {
        return FALSE;
    }
    return TRUE;
}
/**
 * Create a new wire post.
 *
 * @param string $post The post
 * @param int $access_id Public/private etc
 * @param int $parent Parent post (if any)
 * @param string $method The method (default: 'site')
 * @return bool
 */
function thewire_save_post($post, $access_id, $parent = 0, $method = "site")
{
    global $SESSION;
    // Initialise a new ElggObject
    $thewire = new ElggObject();
    // Tell the system it's a thewire post
    $thewire->subtype = "thewire";
    // Set its owner to the current user
    $thewire->owner_guid = get_loggedin_userid();
    // For now, set its access to public (we'll add an access dropdown shortly)
    $thewire->access_id = $access_id;
    // Set its description appropriately
    $thewire->description = elgg_substr(strip_tags($post), 0, 160);
    /*if (is_callable('mb_substr'))
    			$thewire->description = mb_substr(strip_tags($post), 0, 160);
    		else
    			$thewire->description = substr(strip_tags($post), 0, 160);*/
    // add some metadata
    $thewire->method = $method;
    //method, e.g. via site, sms etc
    $thewire->parent = $parent;
    //used if the note is a reply
    //save
    $save = $thewire->save();
    if ($save) {
        add_to_river('river/object/thewire/create', 'create', $SESSION['user']->guid, $thewire->guid);
    }
    return $save;
}
Пример #16
0
/**
 * Create a new wire post.
 *
 * @param string $text        The post text
 * @param int    $userid      The user's guid
 * @param int    $access_id   Public/private etc
 * @param int    $parent_guid Parent post guid (if any)
 * @param string $method      The method (default: 'site')
 * @return guid or false if failure
 */
function wire_save_post($text, $userid, $entity_guid, $access_id, $parent_guid = 0, $method = "site")
{
    $post = new ElggObject();
    $post->subtype = "wire";
    $post->owner_guid = $userid;
    $post->access_id = $access_id;
    $post->entity_guid = $entity_guid;
    // only 200 characters allowed
    $text = elgg_substr($text, 0, 200);
    // no html tags allowed so we escape
    $post->description = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
    $post->method = $method;
    //method: site, email, api, ...
    $tags = wire_get_hashtags($text);
    if ($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/wire/create', 'create', $post->owner_guid, $post->guid);
        // let other plugins know we are setting a user status
        $params = array('entity' => $post, 'user' => $post->getOwnerEntity(), 'message' => $post->description, 'url' => $post->getURL(), 'origin' => 'wire');
        elgg_trigger_plugin_hook('status', 'user', $params);
    }
    //fordebug register_error("in save entity_guid {$post->entity_guid}");
    return $guid;
}
Пример #17
0
/**
 * Process uploaded files
 *
 * @param mixed $files		Uploaded files
 * @param mixed $entity		If an entity is set and it doesn't belong to one of the file subtypes, uploaded files will be converted into hjFile objects and attached to the entity
 * @return void
 */
function hj_framework_process_file_upload($name, $entity = null)
{
    // Normalize the $_FILES array
    if (is_array($_FILES[$name]['name'])) {
        $files = hj_framework_prepare_files_global($_FILES);
        $files = $files[$name];
    } else {
        $files = $_FILES[$name];
        $files = array($files);
    }
    if (elgg_instanceof($entity)) {
        if (!$entity instanceof hjFile) {
            $is_attachment = true;
        }
        $subtype = $entity->getSubtype();
    }
    foreach ($files as $file) {
        if (!is_array($file) || $file['error']) {
            continue;
        }
        if ($is_attachment) {
            $filehandler = new hjFile();
        } else {
            $filehandler = new hjFile($entity->guid);
        }
        $prefix = 'hjfile/';
        if ($entity instanceof hjFile) {
            $filename = $filehandler->getFilenameOnFilestore();
            if (file_exists($filename)) {
                unlink($filename);
            }
            $filestorename = $filehandler->getFilename();
            $filestorename = elgg_substr($filestorename, elgg_strlen($prefix));
        } else {
            $filestorename = elgg_strtolower(time() . $file['name']);
        }
        $filehandler->setFilename($prefix . $filestorename);
        $filehandler->title = $file['name'];
        $mime_type = ElggFile::detectMimeType($file['tmp_name'], $file['type']);
        // hack for Microsoft zipped formats
        $info = pathinfo($file['name']);
        $office_formats = array('docx', 'xlsx', 'pptx');
        if ($mime_type == "application/zip" && in_array($info['extension'], $office_formats)) {
            switch ($info['extension']) {
                case 'docx':
                    $mime_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                    break;
                case 'xlsx':
                    $mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    break;
                case 'pptx':
                    $mime_type = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
                    break;
            }
        }
        // check for bad ppt detection
        if ($mime_type == "application/vnd.ms-office" && $info['extension'] == "ppt") {
            $mime_type = "application/vnd.ms-powerpoint";
        }
        $filehandler->setMimeType($mime_type);
        $filehandler->originalfilename = $file['name'];
        $filehandler->simpletype = hj_framework_get_simple_type($mime_type);
        $filehandler->filesize = $file['size'];
        $filehandler->open("write");
        $filehandler->close();
        move_uploaded_file($file['tmp_name'], $filehandler->getFilenameOnFilestore());
        if ($filehandler->save()) {
            if ($is_attachment && elgg_instanceof($entity)) {
                make_attachment($entity->guid, $filehandler->getGUID());
            }
            // Generate icons for images
            if ($filehandler->simpletype == "image") {
                if (!elgg_instanceof($entity) || $is_attachment) {
                    // no entity provided or this is an attachment generating icons for self
                    hj_framework_generate_entity_icons($filehandler, $filehandler);
                } else {
                    if (elgg_instanceof($entity)) {
                        hj_framework_generate_entity_icons($entity, $filehandler);
                    }
                }
                // the settings tell us not to keep the original image file, so downsizing to master
                if (!HYPEFRAMEWORK_FILES_KEEP_ORIGINALS) {
                    $icon_sizes = hj_framework_get_thumb_sizes($subtype);
                    $values = $icon_sizes['master'];
                    $master = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), $values['w'], $values['h'], $values['square'], 0, 0, 0, 0, $values['upscale']);
                    $filehandler->open('write');
                    $filehandler->write($master);
                    $filehandler->close();
                }
            }
            $return[$file['name']] = $filehandler->getGUID();
        } else {
            $return[$file['name']] = false;
        }
    }
    return $return;
}
Пример #18
0
<?php

/**
 * Output view for elgg_get_excerpt
 *
 * @uses $vars['text'] The text to get the excerpt for
 * @uses $vars['num_chars'] The max number of characters of the excerpt 
 * @uses $vars['suffix'] The suffix to be added if text is cut 
 */
$text = elgg_extract('text', $vars);
$text = trim(elgg_strip_tags($text));
$suffix = elgg_extract('suffix', $vars, '...');
$string_length = elgg_strlen($text);
$num_chars = (int) elgg_extract('num_chars', $vars, 250);
if ($string_length <= $num_chars) {
    echo $text;
    return;
}
// handle cases
$excerpt = elgg_substr($text, 0, $num_chars);
$space = elgg_strrpos($excerpt, ' ', 0);
// don't crop if can't find a space.
if ($space === false) {
    $space = $num_chars;
}
$excerpt = trim(elgg_substr($excerpt, 0, $space));
if ($string_length != elgg_strlen($excerpt)) {
    $excerpt .= $suffix;
}
echo $excerpt;
Пример #19
0
/**
 * Import Tweets of a user to thewire
 *
 * @param string $hook        the name of the hook
 * @param string $type        the type of the hook
 * @param mixed  $returnvalue current return value
 * @param array  $params      supplied params
 *
 * @return void
 */
function socialink_twitter_in_cron_hook($hook, $type, $returnvalue, $params)
{
    global $CONFIG, $SESSION;
    $setting_name = "plugin:settings:socialink:twitter_in";
    $setting_value = "yes";
    $options = array("type" => "user", "limit" => false, "relationship" => "member_of_site", "relationship_guid" => $CONFIG->site_guid, "inverse_relationship" => true, "joins" => array("JOIN " . $CONFIG->dbprefix . "private_settings ps ON e.guid = ps.entity_guid"), "wheres" => array("(ps.name='" . $setting_name . "' AND ps.value = '" . $setting_value . "')"));
    if ($users = elgg_get_entities_from_relationship($options)) {
        // this could take a long time
        set_time_limit(0);
        foreach ($users as $user) {
            $SESSION["user"] = $user;
            if ($keys = socialink_twitter_is_connected($user->getGUID())) {
                $since_id = elgg_get_plugin_user_setting("twitter_in_since_id", $user->getGUID(), "socialink");
                $filter = elgg_get_plugin_user_setting("twitter_in_filter", $user->getGUID(), "socialink");
                if ($api = socialink_twitter_get_api_object($keys)) {
                    try {
                        $url = "statuses/user_timeline";
                        $params = array("since_id" => $since_id, "include_rts" => true, "count" => 200);
                        $response = $api->get($url, $params);
                        if (!empty($response) && empty($response->error)) {
                            // proces tweets oldest to newest
                            $response = array_reverse($response);
                            // determen access_id
                            $access_id = get_default_access($user);
                            if ($access_id == ACCESS_PRIVATE) {
                                $access_id = ACCESS_LOGGED_IN;
                            }
                            foreach ($response as $tweet) {
                                $since_id = $tweet->id_str;
                                $text = elgg_substr(strip_tags($tweet->text), 0, 160);
                                if (empty($filter) || stristr($text, $filter)) {
                                    $post = new ElggObject();
                                    $post->subtype = "thewire";
                                    $post->owner_guid = $user->getGUID();
                                    $post->container_guid = $user->getGUID();
                                    $post->access_id = $access_id;
                                    $post->description = $text;
                                    $post->method = "Twitter";
                                    $post->parent = 0;
                                    if ($post->save()) {
                                        if ($created = strtotime($tweet->created_at)) {
                                            $sql = "UPDATE " . $CONFIG->dbprefix . "entities SET time_created = " . $created . ", time_updated = " . $created . " WHERE guid = " . $post->getGUID();
                                            update_data($sql);
                                        }
                                    }
                                }
                            }
                            // update since_id
                            elgg_set_plugin_user_setting("twitter_in_since_id", $since_id, $user->getGUID(), "socialink");
                        }
                    } catch (Exception $e) {
                    }
                }
            }
            unset($SESSION["user"]);
        }
    }
}
Пример #20
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;
}
Пример #21
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;
}
Пример #22
0
function blog_save_json($title, $text, $excerpt, $tags, $access, $container_guid)
{
    $user = elgg_get_logged_in_user_entity();
    if (!$user) {
        throw new InvalidParameterException('registration:usernamenotvalid');
    }
    $obj = new ElggObject();
    $obj->subtype = "blog";
    $obj->owner_guid = $user->guid;
    $obj->container_guid = $container_guid;
    $obj->access_id = strip_tags($access);
    $obj->method = "api";
    $obj->description = strip_tags($text);
    $obj->title = elgg_substr(strip_tags($title), 0, 140);
    $obj->status = 'published';
    $obj->comments_on = 'On';
    $obj->excerpt = strip_tags($excerpt);
    $obj->tags = strip_tags($tags);
    $guid = $obj->save();
    elgg_create_river_item('river/object/blog/create', 'create', $user->guid, $obj->guid);
    if ($guid) {
        $return['addblog'] = true;
        $return['message'] = elgg_echo('blog:message:saved');
        return json_encode($return, true);
        //$return="saved";
        //return true;
    } else {
        $return['addblog'] = false;
        $return['message'] = elgg_echo('blog:error:cannot_save');
        return json_encode($return, true);
        //$return="not saved!";
        //return false;
    }
    //return $return;
}
Пример #23
0
            }
            ?>
</table>

<?php 
        }
        ?>
			
				</div>
			</div>
<?php 
        $letpos++;
        if ($letpos == elgg_strlen($chararray)) {
            break;
        }
        $letter = elgg_substr($chararray, $letpos, 1);
    }
    ?>
		</div>		
	</div>
	</div>
	
<?php 
} else {
    echo $vars['replacement'];
}
if (!$callback) {
    ?>
			
	</div>
</div>
Пример #24
0
$video->tags = $tags;
// Save the entity to push attributes to database
// and to get access to guid if adding a new video
$video->save();
// we have a video upload, so process it
if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) {
    $prefix = "video/{$video->getGUID()}/";
    // if previous video, delete it
    if ($new_video == false) {
        $videoname = $video->getFilenameOnFilestore();
        if (file_exists($videoname)) {
            unlink($videoname);
        }
        // use same videoname on the disk - ensures thumbnails are overwritten
        $videostorename = $video->getFilename();
        $videostorename = elgg_substr($videostorename, elgg_strlen($prefix));
    } else {
        $videostorename = elgg_strtolower($_FILES['upload']['name']);
    }
    $video->setFilename($prefix . $videostorename);
    $mime_type = ElggFile::detectMimeType($_FILES['upload']['tmp_name'], $_FILES['upload']['type']);
    $video->setMimeType($mime_type);
    $video->originalvideoname = $_FILES['upload']['name'];
    $video->simpletype = 'video';
    // Open the video to guarantee the directory exists
    $video->open("write");
    $video->close();
    move_uploaded_file($_FILES['upload']['tmp_name'], $video->getFilenameOnFilestore());
    // Change the directory mode
    chmod($video->getFileDirectory(), 0775);
    $guid = $video->save();
Пример #25
0
function TopicAddNew($username, $groupId, $text)
{
    //check user name
    $user = get_user_by_username($username);
    if (!$user) {
        throw new InvalidParameterException("Bad username");
    }
    // check topic id
    $topic = get_entity((int) $topicId);
    if (!$topic) {
        throw new InvalidParameterException("Bad Topic Id");
    }
    // check text
    $text = elgg_substr(strip_tags($text), 0, 140);
    if (empty($text)) {
        throw new InvalidParameterException("Empty Text");
    }
    $comment = new ElggObject();
    $comment->subtype = 'groupforumtopic';
    $comment->title = $text;
    $comment->description = $text;
    $comment->status = "status what?";
    $comment->access_id = 0;
    //ACCESS_PUBLIC;
    $comment->container_guid = (int) $topicId;
    $comment->tags = "tag what?";
    $comment->guid = (int) $topicId;
    $result = $comment->save();
    //	add_to_river('river/object/groupforumtopic/create', 'create', elgg_get_logged_in_user_guid(), $topic->guid);
    if ($result) {
        return "true";
    } else {
        return "false";
    }
}
Пример #26
0
/**
 * Get entities with tags that match the search parameters.
 *
 * @param string $hook   Hook name
 * @param string $type   Hook type
 * @param array  $value  Empty array
 * @param array  $params Search parameters
 * @return array
 */
function search_tags_hook($hook, $type, $value, $params)
{
    $params['joins'] = (array) elgg_extract('joins', $params, array());
    $params['wheres'] = (array) elgg_extract('wheres', $params, array());
    $db_prefix = elgg_get_config('dbprefix');
    $valid_tag_names = elgg_get_registered_tag_metadata_names();
    // @todo will need to split this up to support searching multiple tags at once.
    $query = sanitise_string($params['query']);
    // if passed a tag metadata name, only search on that tag name.
    // tag_name isn't included in the params because it's specific to
    // tag searches.
    if ($tag_names = get_input('tag_names')) {
        if (is_array($tag_names)) {
            $search_tag_names = $tag_names;
        } else {
            $search_tag_names = array($tag_names);
        }
        // check these are valid to avoid arbitrary metadata searches.
        foreach ($search_tag_names as $i => $tag_name) {
            if (!in_array($tag_name, $valid_tag_names)) {
                unset($search_tag_names[$i]);
            }
        }
    } else {
        $search_tag_names = $valid_tag_names;
    }
    if (!$search_tag_names) {
        return array('entities' => array(), 'count' => $count);
    }
    // don't use elgg_get_entities_from_metadata() here because of
    // performance issues.  since we don't care what matches at this point
    // use an IN clause to grab everything that matches at once and sort
    // out the matches later.
    $params['joins'][] = "JOIN {$db_prefix}metadata md on e.guid = md.entity_guid";
    $params['joins'][] = "JOIN {$db_prefix}metastrings msn on md.name_id = msn.id";
    $params['joins'][] = "JOIN {$db_prefix}metastrings msv on md.value_id = msv.id";
    $access = _elgg_get_access_where_sql(array('table_alias' => 'md'));
    $sanitised_tags = array();
    foreach ($search_tag_names as $tag) {
        $sanitised_tags[] = '"' . sanitise_string($tag) . '"';
    }
    $tags_in = implode(',', $sanitised_tags);
    $params['wheres'][] = "(msn.string IN ({$tags_in}) AND msv.string = '{$query}' AND {$access})";
    $params['count'] = TRUE;
    $count = elgg_get_entities($params);
    // no need to continue if nothing here.
    if (!$count) {
        return array('entities' => array(), 'count' => $count);
    }
    $params['count'] = FALSE;
    if (isset($params['sort']) || !isset($params['order_by'])) {
        $params['order_by'] = search_get_order_by_sql('e', null, $params['sort'], $params['order']);
    }
    $entities = elgg_get_entities($params);
    // add the volatile data for why these entities have been returned.
    foreach ($entities as $entity) {
        $matched_tags_strs = array();
        // get tags for each tag name requested to find which ones matched.
        foreach ($search_tag_names as $tag_name) {
            $tags = $entity->getTags($tag_name);
            // @todo make one long tag string and run this through the highlight
            // function.  This might be confusing as it could chop off
            // the tag labels.
            if (in_array(strtolower($query), array_map('strtolower', $tags))) {
                if (is_array($tags)) {
                    $tag_name_str = elgg_echo("tag_names:{$tag_name}");
                    $matched_tags_strs[] = "{$tag_name_str}: " . implode(', ', $tags);
                }
            }
        }
        // different entities have different titles
        switch ($entity->type) {
            case 'site':
            case 'user':
            case 'group':
                $title_tmp = $entity->name;
                break;
            case 'object':
                $title_tmp = $entity->title;
                break;
        }
        // Nick told me my idea was dirty, so I'm hard coding the numbers.
        $title_tmp = strip_tags($title_tmp);
        if (elgg_strlen($title_tmp) > 297) {
            $title_str = elgg_substr($title_tmp, 0, 297) . '...';
        } else {
            $title_str = $title_tmp;
        }
        $desc_tmp = strip_tags($entity->description);
        if (elgg_strlen($desc_tmp) > 297) {
            $desc_str = elgg_substr($desc_tmp, 0, 297) . '...';
        } else {
            $desc_str = $desc_tmp;
        }
        $tags_str = implode('. ', $matched_tags_strs);
        $tags_str = search_get_highlighted_relevant_substrings($tags_str, $params['query'], 30, 300, true);
        $entity->setVolatileData('search_matched_title', $title_str);
        $entity->setVolatileData('search_matched_description', $desc_str);
        $entity->setVolatileData('search_matched_extra', $tags_str);
    }
    return array('entities' => $entities, 'count' => $count);
}
Пример #27
0
function file_tools_generate_thumbs($file)
{
    $formats = array("thumbnail" => 60, "smallthumb" => 153, "largethumb" => 600);
    $file->icontime = time();
    $filestorename = $file->getFilename();
    $filestorename = elgg_substr($filestorename, elgg_strlen("file/"));
    foreach ($formats as $name => $size) {
        $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), $size, $size, true);
        if ($thumbnail) {
            $filename = "file/{$name}" . $filestorename;
            $thumb = new ElggFile();
            $thumb->setFilename($filename);
            $thumb->open("write");
            $thumb->write($thumbnail);
            $thumb->close();
            $file->{$name} = $filename;
            unset($thumbnail);
        }
    }
}
Пример #28
0
     if ($index < $num_highlighted) {
         $icon = "";
         if ($show_avatar) {
             $icon = elgg_view_entity_icon($entity->getOwnerEntity(), "small");
         }
         $text = elgg_view("output/url", array("href" => $entity_url, "text" => $entity->title, "target" => $target));
         $text .= "<br />";
         $description = elgg_get_excerpt($entity->description, 170);
         if ($show_timestamp) {
             $text .= "<span title='" . date("r", $entity->time_created) . "'>" . substr(date("r", $entity->time_created), 0, 16) . "</span>";
             if (!empty($description)) {
                 $text .= " - ";
             }
         }
         $text .= $description;
         if (elgg_substr($description, -3, 3) == '...') {
             $text .= " <a href=\"{$entity->getURL()}\">" . strtolower(elgg_echo('more')) . '</a>';
         }
         $result .= elgg_view_image_block($icon, $text);
     } else {
         $result .= "<div>";
         if ($show_timestamp) {
             $result .= "<span title='" . strftime("%c", $entity->time_created) . "'>" . strftime("%d %b", $entity->time_created) . "</span> - ";
         }
         $result .= "<a href='" . $entity_url . "'>" . $entity->title . "</a>";
         $result .= "</div>";
     }
 } else {
     // simple
     $owner = $entity->getOwnerEntity();
     $icon = "";
Пример #29
0
/**
 * Process uploaded files
 *
 * @param string $name           Name of the HTML file input
 * @param string $subtype        Object subtype to be assigned to newly created objects
 * @param type   $guid           GUID of an existing object
 * @param type   $container_guid GUID of the container entity
 * @return array An associative array of original file names and guids (or false) of created object
 */
function process_file_upload($name, $subtype = hjAlbumImage::SUBTYPE, $guid = null, $container_guid = null)
{
    // Normalize the $_FILES array
    if (is_array($_FILES[$name]['name'])) {
        $files = prepare_files_global($_FILES);
        $files = $files[$name];
    } else {
        $files = $_FILES[$name];
        $files = array($files);
    }
    foreach ($files as $file) {
        if (!is_array($file) || $file['error']) {
            continue;
        }
        $filehandler = new ElggFile($guid);
        $prefix = 'hjfile/';
        if ($guid) {
            $filename = $filehandler->getFilenameOnFilestore();
            if (file_exists($filename)) {
                unlink($filename);
            }
            $filestorename = $filehandler->getFilename();
            $filestorename = elgg_substr($filestorename, elgg_strlen($prefix));
        } else {
            $filehandler->subtype = $subtype;
            $filehandler->container_guid = $container_guid;
            $filestorename = elgg_strtolower(time() . $file['name']);
        }
        $filehandler->setFilename($prefix . $filestorename);
        $filehandler->title = $file['name'];
        $mime_type = ElggFile::detectMimeType($file['tmp_name'], $file['type']);
        // hack for Microsoft zipped formats
        $info = pathinfo($file['name']);
        $office_formats = array('docx', 'xlsx', 'pptx');
        if ($mime_type == "application/zip" && in_array($info['extension'], $office_formats)) {
            switch ($info['extension']) {
                case 'docx':
                    $mime_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                    break;
                case 'xlsx':
                    $mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    break;
                case 'pptx':
                    $mime_type = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
                    break;
            }
        }
        // check for bad ppt detection
        if ($mime_type == "application/vnd.ms-office" && $info['extension'] == "ppt") {
            $mime_type = "application/vnd.ms-powerpoint";
        }
        $filehandler->setMimeType($mime_type);
        $filehandler->originalfilename = $file['name'];
        $filehandler->simpletype = get_simple_type($mime_type);
        $filehandler->filesize = $file['size'];
        $filehandler->open("write");
        $filehandler->close();
        move_uploaded_file($file['tmp_name'], $filehandler->getFilenameOnFilestore());
        if ($filehandler->save()) {
            // Generate icons for images
            if ($filehandler->simpletype == "image") {
                generate_entity_icons($filehandler);
                // the settings tell us not to keep the original image file, so downsizing to master
                if (elgg_get_plugin_setting('remove_original_files', 'hypeGallery')) {
                    $icon_sizes = elgg_get_config('icon_sizes');
                    $values = $icon_sizes['master'];
                    $master = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), $values['w'], $values['h'], $values['square'], 0, 0, 0, 0, $values['upscale']);
                    $filehandler->open('write');
                    $filehandler->write($master);
                    $filehandler->close();
                }
            }
            $return[$file['name']] = $filehandler->getGUID();
        } else {
            $return[$file['name']] = false;
        }
    }
    return $return;
}