/** * Send push notifications if event is added to the activity river * * @param string $event name of the event * @param string $type type of the event * @param ElggRiverItem $river_item river item object * * @return void */ function ws_pack_created_river_event_handler($event, $type, $river_item) { if (!empty($river_item) && $river_item instanceof ElggRiverItem) { if (!function_exists('str_get_html')) { elgg_load_library("simple_html_dom"); } $message = ""; $html_view = elgg_view_river_item($river_item); if ($res = str_get_html($html_view)) { // get the river summary if ($summary_element = $res->find("div.elgg-river-summary")) { $summary_element = $summary_element[0]; $text = $summary_element->innertext(); list($left, $right) = explode("<span class=\"elgg-river-timestamp\">", $text); $message = trim(elgg_strip_tags($left)); } } if (!empty($message)) { $user_guids = false; switch ($river_item->access_id) { case ACCESS_PRIVATE: // do nothing break; case ACCESS_PUBLIC: case ACCESS_LOGGED_IN: // notify everyone $site_user_options = array("type" => "user", "limit" => false, "relationship" => "member_of_site", "relationship_guid" => elgg_get_site_entity()->getGUID(), "inverse_relationship" => true, "callback" => "ws_pack_row_to_guid"); $user_guids = elgg_get_entities_from_relationship($site_user_options); break; case ACCESS_FRIENDS: // notify friends of subject_guid $friends_options = array("type" => "user", "limit" => false, "relationship" => "friend", "relationship_guid" => $river_item->subject_guid, "callback" => "ws_pack_row_to_guid", "joins" => array("JOIN " . elgg_get_config("dbprefix") . "entity_relationships r2 ON e.guid = r2.guid_one"), "wheres" => array("(r2.relationship = 'member_of_site' AND r2.guid_two = " . elgg_get_site_entity()->getGUID() . ")")); $user_guids = elgg_get_entities_from_relationship($friends_options); break; default: // probably some acl, so notify members of the acl $user_guids = get_members_of_access_collection($river_item->access_id, true); break; } // we found potential interested users, so push if (!empty($user_guids) && is_array($user_guids)) { $api_application_options = array("type" => "object", "subtype" => APIApplication::SUBTYPE, "limit" => false, "annotation_name" => "push_notification_service"); if ($api_applications = elgg_get_entities_from_annotations($api_application_options)) { foreach ($api_applications as $api_application) { $api_application->sendPushNotification($message, $user_guids); } } } } } }
/** * 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; }
/** * Get exportable entity values * * @param ElggEntity $entity * @return array */ function elgg_tokeninput_export_entity($entity) { if (!elgg_instanceof($entity)) { if ($entity_from_guid = get_entity($entity)) { $entity = $entity_from_guid; } else { return elgg_tokeninput_export_metadata($entity); } } $type = $entity->getType(); $subtype = $entity->getSubtype(); $icon = elgg_view_entity_icon($entity, 'small', array('use_hover' => false)); if (elgg_instanceof($entity, 'user')) { $title = "{$entity->name} ({$entity->username})"; } else { if (elgg_instanceof($entity, 'group')) { $title = $entity->name; } else { $title = $entity->getDisplayName(); if (!$title) { $title = elgg_echo('untitled'); } $metadata[] = elgg_echo('byline', array($entity->getOwnerEntity()->name)); } } if ($entity->description) { $metadata[] = elgg_get_excerpt(elgg_strip_tags($entity->description), 100); } if ($entity->location) { $metadata[] = $entity->location; } $export = array('label' => $title, 'value' => $entity->guid, 'metadata' => $metadata ? implode('<br />', $metadata) : '', 'icon' => $icon, 'type' => $type, 'subtype' => $subtype, 'html_result' => elgg_view_exists("tokeninput/{$type}/{$subtype}") ? elgg_view("tokeninput/{$type}/{$subtype}", array('entity' => $entity, 'for' => 'result')) : null, 'html_token' => elgg_view_exists("tokeninput/{$type}/{$subtype}") ? elgg_view("tokeninput/{$type}/{$subtype}", array('entity' => $entity, 'for' => 'token')) : null); $export = elgg_trigger_plugin_hook('tokeninput:entity:export', $type, array('entity' => $entity), $export); array_walk_recursive($export, function (&$value) { $value = is_string($value) ? html_entity_decode($value, ENT_QUOTES, 'UTF-8') : $value; }); return $export; }
/** * NOTE - this is only used in Elgg 1.8 as comments are annotations * * @param type $hook * @param type $type * @param type $return * @param type $params * @return null */ function elgg_solr_comment_search($hook, $type, $return, $params) { $entities = array(); $select = array('start' => $params['offset'], 'rows' => $params['limit'] ? $params['limit'] : 10, 'fields' => array('id', 'container_guid', 'description', 'owner_guid', 'time_created', 'score')); if ($params['select'] && is_array($params['select'])) { $select = array_merge($select, $params['select']); } // create a client instance $client = elgg_solr_get_client(); // get an update query instance $query = $client->createSelect($select); $default_sort = array('score' => 'desc', 'time_created' => 'desc'); $sorts = $params['sorts'] ? $params['sorts'] : $default_sort; $query->addSorts($sorts); $description_boost = elgg_solr_get_description_boost(); // get the dismax component and set a boost query $dismax = $query->getEDisMax(); $qf = "description^{$description_boost}"; if ($params['qf']) { $qf = $params['qf']; } $dismax->setQueryFields($qf); $boostQuery = elgg_solr_get_boost_query(); if ($boostQuery) { $dismax->setBoostQuery($boostQuery); } // this query is now a dismax query $query->setQuery($params['query']); // make sure we're only getting comments $params['fq']['type'] = 'type:annotation'; $params['fq']['subtype'] = 'subtype:generic_comment'; $default_fq = elgg_solr_get_default_fq($params); if ($params['fq']) { $filter_queries = array_merge($default_fq, $params['fq']); } else { $filter_queries = $default_fq; } if (!empty($filter_queries)) { foreach ($filter_queries as $key => $value) { $query->createFilterQuery($key)->setQuery($value); } } // get highlighting component and apply settings $hl = $query->getHighlighting(); $hl->setFields(array('description')); $hl->setSimplePrefix('<span data-hl="elgg-solr">'); $hl->setSimplePostfix('</span>'); $fragsize = elgg_solr_get_fragsize(); if (isset($params['fragsize'])) { $fragsize = (int) $params['fragsize']; } $hl->setFragSize($fragsize); // this executes the query and returns the result try { $resultset = $client->select($query); } catch (Exception $e) { error_log($e->getMessage()); return null; } // Get the highlighted snippet try { $highlighting = $resultset->getHighlighting(); } catch (Exception $e) { error_log($e->getMessage()); return null; } // Count the total number of documents found by solr $count = $resultset->getNumFound(); $hl_prefix = elgg_solr_get_hl_prefix(); $hl_suffix = elgg_solr_get_hl_suffix(); $show_score = elgg_get_plugin_setting('show_score', 'elgg_solr'); $config = HTMLPurifier_Config::createDefault(); $purifier = new HTMLPurifier($config); foreach ($resultset as $document) { // comments entity_guid stored as container_guid in solr $entity = get_entity($document->container_guid); if (!$entity) { $entity = new ElggObject(); $entity->setVolatileData('search_unavailable_entity', TRUE); } // highlighting results can be fetched by document id (the field defined as uniquekey in this schema) $highlightedDoc = $highlighting->getResult($document->id); if ($highlightedDoc) { foreach ($highlightedDoc as $highlight) { $snippet = implode(' (...) ', $highlight); // get our highlight based on the wrapped tokens // note, this is to prevent partial html from breaking page layouts $match = array(); preg_match('/<span data-hl="elgg-solr">(.*)<\\/span>/', $snippet, $match); if ($match[1]) { $snippet = str_replace($match[1], $hl_prefix . $match[1] . $hl_suffix, $snippet); $snippet = $purifier->purify($snippet); } } } if (!$snippet) { $snippet = search_get_highlighted_relevant_substrings(elgg_get_excerpt($document->description), $params['query']); } if ($show_score == 'yes' && elgg_is_admin_logged_in()) { $snippet .= elgg_view('output/longtext', array('value' => elgg_echo('elgg_solr:relevancy', array($document->score)), 'class' => 'elgg-subtext')); } $comments_data = $entity->getVolatileData('search_comments_data'); if (!$comments_data) { $comments_data = array(); } $comments_data[] = array('annotation_id' => substr(strstr(elgg_strip_tags($document->id), ':'), 1), 'text' => $snippet, 'owner_guid' => $document->owner_guid, 'time_created' => $document->time_created); $entity->setVolatileData('search_comments_data', $comments_data); $entities[] = $entity; } return array('entities' => $entities, 'count' => $count); }
/** * It hijacks the email sender to encrypt the messages if needed. * * @param string $hook * @param string $type * @param bool $return * @param array $params Includes $from, $to, $subject, $body and $headers * * @return bool */ function elggpg_send_email_handler($hook, $type, $return, $params) { $from = $params['from']; $to = $params['to']; $subject = $params['subject']; $body = $params['body']; $headers = $params['headers']; $receiver = current(get_user_by_email($to)); // Format message $body = html_entity_decode($body, ENT_COMPAT, 'UTF-8'); // Decode any html entities $body = elgg_strip_tags($body); // Strip tags from message $body = preg_replace("/(\r\n|\r)/", "\n", $body); // Convert to unix line endings in body $body = preg_replace("/^From/", ">From", $body); // Change lines starting with From to >From $body = wordwrap($body); // Encrypting if (elgg_get_plugin_user_setting('encrypt_emails', $receiver->guid, 'elggpg') != 'no') { elgg_load_library('elggpg'); $encrypted_body = elggpg_encrypt($body, $receiver, false); if ($encrypted_body) { $body = $encrypted_body; } } // The following code is the same that in elgg's $header_eol = "\r\n"; if (elgg_get_config('broken_mta')) { // Allow non-RFC 2822 mail headers to support some broken MTAs $header_eol = "\n"; } // Windows is somewhat broken, so we use just address for to and from if (strtolower(substr(PHP_OS, 0, 3)) == 'win') { // strip name from to and from if (strpos($to, '<')) { preg_match('/<(.*)>/', $to, $matches); $to = $matches[1]; } if (strpos($from, '<')) { preg_match('/<(.*)>/', $from, $matches); $from = $matches[1]; } } if (empty($headers)) { $headers = "From: {$from}{$header_eol}" . "Content-Type: text/plain; charset=UTF-8; format=flowed{$header_eol}" . "MIME-Version: 1.0{$header_eol}" . "Content-Transfer-Encoding: 8bit{$header_eol}"; } // Sanitise subject by stripping line endings $subject = preg_replace("/(\r\n|\r|\n)/", " ", $subject); // this is because Elgg encodes everything and matches what is done with body $subject = html_entity_decode($subject, ENT_COMPAT, 'UTF-8'); // Decode any html entities if (is_callable('mb_encode_mimeheader')) { $subject = mb_encode_mimeheader($subject, "UTF-8", "B"); } return mail($to, $subject, $body, $headers); }
// if the form comes back from a failed save we can't use the presets $sticky_form = (bool) elgg_extract('group_tools_presets', $vars, false); $presets = false; if (!$sticky_form) { $presets = group_tools_get_tool_presets(); } // we need to be able to tell if we came from a sticky form echo elgg_view('input/hidden', ['name' => 'group_tools_presets', 'value' => '1']); // new group can choose from preset (if any) if (empty($entity) && !empty($presets)) { echo elgg_view('output/longtext', ['value' => elgg_echo('group_tools:create_group:tool_presets:description')]); $preset_selectors = ''; $preset_descriptions = ''; $presets_tools = []; foreach ($presets as $index => $values) { $preset_selectors .= elgg_view('output/url', ['text' => elgg_extract('title', $values), 'href' => '#', 'class' => 'elgg-button elgg-button-action mrm', 'rel' => $index, 'title' => elgg_strip_tags(elgg_extract('description', $values))]); $preset_tools = elgg_extract('tools', $values); foreach ($preset_tools as $tool_name => $tool) { if ($tool == 'yes') { $presets_tools[$tool_name][] = "group-tools-preset-{$index}"; } } $preset_descriptions .= elgg_format_element('div', ['id' => "group-tools-preset-description-{$index}", 'class' => 'hidden'], elgg_extract('description', $values)); } // blank preset $preset_selectors .= elgg_view('output/url', ['text' => elgg_echo('group_tools:create_group:tool_presets:blank:title'), 'href' => '#', 'class' => 'elgg-button elgg-button-action mrm', 'rel' => 'blank']); $preset_descriptions .= elgg_format_element('div', ['id' => 'group-tools-preset-description-blank', 'class' => 'hidden'], elgg_echo('group_tools:create_group:tool_presets:blank:description')); echo elgg_format_element('label', ['class' => 'mbs'], elgg_echo('group_tools:create_group:tool_presets:select')) . ':'; echo elgg_format_element('div', ['id' => 'group-tools-preset-selector'], $preset_selectors); echo elgg_format_element('div', ['id' => 'group-tools-preset-descriptions'], $preset_descriptions); $more_link = elgg_view('output/url', ['text' => elgg_echo('group_tools:create_group:tool_presets:show_more'), 'href' => '#group-tools-preset-more', 'rel' => 'toggle', 'class' => 'float-alt']);
$md_entities = elgg_extract("entities", $vars); $selected_guid = (int) get_input("multi_dashboard_guid", 0); $tabs = array(); // add the default tab $default_tab = array("text" => elgg_echo("dashboard"), "href" => "dashboard", "title" => elgg_echo("dashboard"), "class" => "widget-manager-multi-dashboard-tab-widgets"); if (empty($selected_guid)) { $default_tab["selected"] = true; } $tabs[0] = $default_tab; if (!empty($md_entities)) { foreach ($md_entities as $key => $entity) { $selected = false; if ($entity->getGUID() == $selected_guid) { $selected = true; } $tab_title = elgg_strip_tags($entity->title); if (strlen($tab_title) > $max_tab_title_length) { $tab_title = substr($tab_title, 0, $max_tab_title_length); } $order = $entity->order ? $entity->order : $entity->time_created; $tabs[$order] = array("text" => $tab_title . elgg_view_icon("settings-alt", "widget-manager-multi-dashboard-tabs-edit"), "href" => $entity->getURL(), "title" => $entity->title, "selected" => $selected, "rel" => $entity->getGUID(), "id" => $entity->getGUID(), "class" => "widget-manager-multi-dashboard-tab widget-manager-multi-dashboard-tab-" . $entity->getDashboardType()); } } ksort($tabs); // add tab tab if (is_array($md_entities) && count($md_entities) < MULTI_DASHBOARD_MAX_TABS) { $tabs[] = array("text" => elgg_view_icon("round-plus", "widget-manager-multi-dashboard-tabs-add"), "href" => "multi_dashboard/edit", "title" => elgg_echo('widget_manager:multi_dashboard:add'), "id" => "widget-manager-multi-dashboard"); } echo elgg_view("navigation/tabs", array("id" => "widget-manager-multi-dashboard-tabs", "tabs" => $tabs)); ?> <script type="text/javascript">
/** * Hook to strip tags from selected entity fields * * @param string $hook the name of the hook * @param string $type the type of the hook * @param string $returnvalue current return value * @param array $params supplied params * * @return void */ public static function stripTags($hook, $type, $returnvalue, $params) { if (!elgg_in_context('search:index')) { return; } $fields = ['title', 'name', 'description']; foreach ($fields as $field) { if (!isset($returnvalue->{$field})) { continue; } $curval = $returnvalue->{$field}; if (empty($curval)) { continue; } $curval = html_entity_decode($curval, ENT_QUOTES, 'UTF-8'); $returnvalue->{$field} = elgg_strip_tags($curval); } return $returnvalue; }
/** * Export river items * * @param array $items river items to export * * @return boolean|array */ function ws_pack_export_river_items($items) { elgg_load_library("simple_html_dom"); $result = false; if (!empty($items) && is_array($items)) { $result = array(); foreach ($items as $item) { if ($item instanceof ElggRiverItem) { $tmp_result = array(); // default export values $export_values = array("id", "subject_guid", "object_guid", "annotation_id", "type", "subtype", "action_type", "posted"); foreach ($export_values as $field_name) { $tmp_result[$field_name] = $item->{$field_name}; } // add object and subject entities $tmp_result["object"] = ws_pack_export_entity($item->getObjectEntity()); $tmp_result["subject"] = ws_pack_export_entity($item->getSubjectEntity()); // add some html views // set viewtype to default $viewtype = elgg_get_viewtype(); elgg_set_viewtype("default"); $tmp_result["html_view"] = elgg_view_river_item($item); // parse the html to get some usefull information if ($res = str_get_html($tmp_result["html_view"])) { // get the river summary if ($summary_element = $res->find("div.elgg-river-summary")) { $summary_element = $summary_element[0]; $text = $summary_element->innertext(); list($left, $right) = explode("<span class=\"elgg-river-timestamp\">", $text); $tmp_result["summary"] = trim(elgg_strip_tags($left)); } // get the river message (optional) if ($message_element = $res->find("div.elgg-river-message")) { $message_element = $message_element[0]; $tmp_result["message"] = trim(elgg_strip_tags($message_element->innertext())); } // get river attachments (optional) if ($attachment_element = $res->find("div.elgg-river-attachments")) { $attachment_element = $attachment_element[0]; $tmp_result["attachments"] = array(); // find images if ($images = $attachment_element->find("img")) { $image_urls = array(); foreach ($images as $img) { $image_urls[] = $img->src; } $tmp_result["attachments"]["images"] = $image_urls; } // find links if ($links = $attachment_element->find("a")) { $link_urls = array(); foreach ($links as $link) { $link_urls[] = $link->href; } $tmp_result["attachments"]["links"] = $link_urls; } } } // add friendly time $friendly_time = elgg_view_friendly_time($item->posted); $tmp_result["friendly_time"] = trim(elgg_strip_tags($friendly_time)); // restore viewtype elgg_set_viewtype($viewtype); // add this item to the result set $result[] = $tmp_result; } } } return $result; }
<?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;
<?php namespace hypeJunction\Gallery; $entity = elgg_extract('entity', $vars, false); $full = elgg_extract('full_view', $vars, false); $size = elgg_extract('size', $vars, '325x200'); if (!elgg_instanceof($entity, 'object', hjAlbum::SUBTYPE)) { return true; } $title = elgg_view('output/url', array('text' => $entity->title, 'href' => $entity->getURL(), 'title' => elgg_strip_tags($entity->description), 'is_trusted' => true)); $count = $entity->getContainedFiles(array('count' => true)); if ($count) { $cover = elgg_view_entity_icon($entity, $size); $cover .= elgg_view('output/url', array('text' => '<i class="gallery-icon-slideshow gallery-icon-small"></i>', 'title' => elgg_echo('gallery:slideshow'), 'class' => 'gallery-popup', 'href' => '#', 'data-guid' => $entity->guid)); } else { $cover = "<div class=\"gallery-album-cover-placeholder\" style=\"display:block;width:100%;height:200px;\"></div>"; } $owner = get_entity($entity->owner_guid); if ($owner) { $author = elgg_view('output/url', array('text' => elgg_view('output/img', array('src' => $owner->getIconURL('small'))), 'href' => $owner->getURL(), 'title' => $owner->name)); $owner_link = elgg_view('output/url', array('href' => $owner->getURL(), 'text' => $owner->name, 'is_trusted' => true)); } $info_link = elgg_view('output/url', array('text' => '<i class="gallery-icon-info icon-small"></i>', 'href' => "#gallery-info-{$entity->guid}", 'rel' => 'toggle')); $info .= elgg_view('object/hjalbum/meta', $vars); $info .= elgg_view('output/longtext', array('value' => $entity->description, 'class' => 'gallery-description')); $subtitle = elgg_echo('gallery:byline', array($owner_link, elgg_view_friendly_time($entity->time_created))); $menu = elgg_view_menu('entity', array('entity' => $entity, 'sort_by' => 'priority', 'class' => 'gallery-media-menu')); if (!$full) { $summary = elgg_view('object/elements/summary', array('entity' => $entity, 'title' => false, 'subtitle' => $subtitle, 'tags' => $entity->tags, 'content' => $info)); $html = <<<__HTML
wet-boew.github.io/wet-boew/License-en.html / wet-boew.github.io/wet-boew/Licence-fr.html --> <meta content="width=device-width, initial-scale=1" name="viewport" /> <!-- Meta data --> <?php //Load in global variable with entity to create metadata tags global $my_page_entity; if ($my_page_entity) { /* echo elgg_get_excerpt($my_page_entity->title) . '<br>'; echo date ("Y-m-d", elgg_get_excerpt($my_page_entity->time_created)) . '<br>'; echo date ("Y-m-d", elgg_get_excerpt($my_page_entity->time_updated)); */ if (elgg_instanceof($my_page_entity, 'group')) { $desc = elgg_strip_tags(elgg_get_excerpt($my_page_entity->description)); $briefdesc = $my_page_entity->briefdescription; } else { if (elgg_instanceof($my_page_entity, 'user')) { $desc = elgg_echo('profile:title', array($my_page_entity->name)); $briefdesc = elgg_echo('profile:title', array($my_page_entity->name)); } else { $desc = $my_page_entity->title; $briefdesc = $my_page_entity->title; } } $pubDate = date("Y-m-d", elgg_get_excerpt($my_page_entity->time_created)); $lastModDate = date("Y-m-d", elgg_get_excerpt($my_page_entity->time_updated)); $datemeta = '<meta name="dcterms.issued" title="W3CDTF" content="' . $pubDate . '"/>'; $datemeta .= '<meta name="dcterms.modified" title="W3CDTF" content="' . $lastModDate . '" />'; } else {
* @author Jeff Tilson * @copyright THINK Global School 2010 - 2013 * @link http://www.thinkglobalschool.com/ * */ $podcast = elgg_extract('entity', $vars, FALSE); if (!elgg_instanceof($podcast, 'object', 'podcast')) { return TRUE; } $owner = $podcast->getOwnerEntity(); $container = $podcast->getContainerEntity(); $owner_url = "podcasts/owner/{$owner->username}"; $owner_name = $owner->name; $episode_title = elgg_echo('podcasts:episode_title', array(podcasts_get_episode_number($podcast), $podcast->title)); $subtitle = elgg_get_excerpt($podcast->description); $summary = trim(elgg_strip_tags($podcast->description)); $image = $owner->getIconURL('large'); $image = str_replace("&", "&", $image); $guid = $podcast->getURL(); // For iTunes $pubDate = date("r", $podcast->time_created); // RFC 2822 $duration_string = podcasts_sec_toHHMMSS($podcast->duration); // Build keyword string if ($podcast->tags) { $keywords = "<itunes:keywords>"; for ($i = 0; $i < count($podcast->tags); $i++) { $keywords .= $podcast->tags[$i]; if ($i != count($podcast->tags) - 1) { $keywords .= ", "; }
// if the form comes back from a failed save we can't use the presets $sticky_form = (bool) elgg_extract('group_tools_presets', $vars, false); $presets = false; if (!$sticky_form) { $presets = group_tools_get_tool_presets(); } // we need to be able to tell if we came from a sticky form echo elgg_view('input/hidden', array('name' => 'group_tools_presets', 'value' => '1')); // new group can choose from preset (if any) if (empty($entity) && !empty($presets)) { echo elgg_view("output/longtext", array("value" => elgg_echo("group_tools:create_group:tool_presets:description"))); $preset_selectors = ""; $preset_descriptions = ""; $presets_tools = array(); foreach ($presets as $index => $values) { $preset_selectors .= elgg_view("output/url", array("text" => elgg_extract("title", $values), "href" => "#", "class" => "elgg-button elgg-button-action mrm", "rel" => $index, "title" => elgg_strip_tags(elgg_extract("description", $values)))); $preset_tools = elgg_extract("tools", $values); foreach ($preset_tools as $tool_name => $tool) { if ($tool == "yes") { $presets_tools[$tool_name][] = "group-tools-preset-" . $index; } } $preset_descriptions .= "<div id='group-tools-preset-description-" . $index . "' class='hidden'>" . elgg_extract("description", $values) . "</div>"; } // blank preset $preset_selectors .= elgg_view("output/url", array("text" => elgg_echo("group_tools:create_group:tool_presets:blank:title"), "href" => "#", "class" => "elgg-button elgg-button-action mrm", "rel" => "blank")); $preset_descriptions .= "<div id='group-tools-preset-description-blank' class='hidden'>" . elgg_echo("group_tools:create_group:tool_presets:blank:description") . "</div>"; echo "<label class='mbs'>" . elgg_echo("group_tools:create_group:tool_presets:select") . ":</label>"; echo "<div id='group-tools-preset-selector'>" . $preset_selectors . "</div>"; echo "<div id='group-tools-preset-descriptions'>" . $preset_descriptions . "</div>"; $more_link = elgg_view("output/url", array("text" => elgg_echo("group_tools:create_group:tool_presets:show_more"), "href" => "#group-tools-preset-more", "rel" => "toggle", "class" => "float-alt"));
/** * Notifies an user of the RSVP * * @param string $type type of the RSVP * @param string $to guid of the user * * @return void */ protected function notifyOnRsvp($type, $to = null) { if ($type == EVENT_MANAGER_RELATION_ATTENDING_PENDING) { return; } $ia = elgg_set_ignore_access(true); if ($to === null) { $to = elgg_get_logged_in_user_guid(); } $to_entity = get_entity($to); if (empty($to_entity)) { elgg_set_ignore_access($ia); return; } // can we make nice links in the emails $html_email_handler_enabled = elgg_is_active_plugin("html_email_handler"); // do we have a registration link $registrationLink = ""; $unsubscribeLink = ""; if ($type == EVENT_MANAGER_RELATION_ATTENDING) { if ($this->registration_needed) { $link = elgg_get_site_url() . 'events/registration/view/' . $this->getGUID() . '?u_g=' . $to . '&k=' . elgg_build_hmac([$this->time_created, $to])->getToken(); $registrationLink = PHP_EOL . PHP_EOL; $registrationLink .= elgg_echo('event_manager:event:registration:notification:program:linktext'); $registrationLink .= PHP_EOL . PHP_EOL; if ($html_email_handler_enabled) { $registrationLink .= elgg_view("output/url", array("text" => $link, "href" => $link)); } else { $registrationLink .= $link; } } if ($this->register_nologin) { $link = elgg_get_site_url() . "events/unsubscribe/" . $this->getGUID() . "/" . elgg_get_friendly_title($this->title) . "?e=" . $to_entity->email; $unsubscribeLink = PHP_EOL . PHP_EOL; $unsubscribeLink .= elgg_echo('event_manager:event:registration:notification:unsubscribe:linktext'); $unsubscribeLink .= PHP_EOL . PHP_EOL; if ($html_email_handler_enabled) { $unsubscribeLink .= elgg_view("output/url", array("text" => $link, "href" => $link)); } else { $unsubscribeLink .= $link; } } if ($html_email_handler_enabled) { // add addthisevent banners in footer $registrationLink .= elgg_view('event_manager/email/addevent', ['entity' => $this]); } } // make the event title for in the e-mail if ($html_email_handler_enabled) { $event_title_link = elgg_view("output/url", array("text" => $this->title, "href" => $this->getURL())); } else { $event_title_link = $this->title; } // notify the owner of the event $this->notifyOwnerOnRSVP($type, $to_entity, $event_title_link, $registrationLink); // notify the attending user $user_subject = elgg_echo('event_manager:event:registration:notification:user:subject'); $user_message = elgg_echo('event_manager:event:registration:notification:user:text:' . $type, [$to_entity->name, $event_title_link]); $completed_text = elgg_strip_tags($this->registration_completed, '<a>'); if (!empty($completed_text)) { $completed_text = str_ireplace('[NAME]', $to_entity->name, $completed_text); $completed_text = str_ireplace('[EVENT]', $this->title, $completed_text); $user_message .= PHP_EOL . $completed_text; } $user_message .= $registrationLink . $unsubscribeLink; if ($to_entity instanceof ElggUser) { // use notification system for real users $summary = elgg_echo('event_manager:event:registration:notification:user:summary:' . $type, [$this->title]); // set params for site notifications $params = ['summary' => $summary, 'object' => $this, 'action' => 'rsvp']; notify_user($to, $this->getOwnerGUID(), $user_subject, $user_message, $params); } else { // send e-mail for non users $to_email = $to_entity->name . "<" . $to_entity->email . ">"; $site = elgg_get_site_entity($this->site_guid); $site_from = $this->getSiteEmailAddress($site); elgg_send_email($site_from, $to_email, $user_subject, $user_message); } elgg_set_ignore_access($ia); }
/** * Send an email to any email address * * @param string $from Email address or string: "name <email>" * @param string $to Email address or string: "name <email>" * @param string $subject The subject of the message * @param string $body The message body * @param array $params Optional parameters (none used in this function) * * @return bool * @throws NotificationException * @since 1.7.2 */ function elgg_send_email($from, $to, $subject, $body, array $params = null) { global $CONFIG; if (!$from) { $msg = "Missing a required parameter, '" . 'from' . "'"; throw new \NotificationException($msg); } if (!$to) { $msg = "Missing a required parameter, '" . 'to' . "'"; throw new \NotificationException($msg); } $headers = array("Content-Type" => "text/plain; charset=UTF-8; format=flowed", "MIME-Version" => "1.0", "Content-Transfer-Encoding" => "8bit"); // return true/false to stop elgg_send_email() from sending $mail_params = array('to' => $to, 'from' => $from, 'subject' => $subject, 'body' => $body, 'headers' => $headers, 'params' => $params); // $mail_params is passed as both params and return value. The former is for backwards // compatibility. The latter is so handlers can now alter the contents/headers of // the email by returning the array $result = elgg_trigger_plugin_hook('email', 'system', $mail_params, $mail_params); if (is_array($result)) { foreach (array('to', 'from', 'subject', 'body', 'headers') as $key) { if (isset($result[$key])) { ${$key} = $result[$key]; } } } elseif ($result !== null) { return $result; } $header_eol = "\r\n"; if (isset($CONFIG->broken_mta) && $CONFIG->broken_mta) { // Allow non-RFC 2822 mail headers to support some broken MTAs $header_eol = "\n"; } // Windows is somewhat broken, so we use just address for to and from if (strtolower(substr(PHP_OS, 0, 3)) == 'win') { // strip name from to and from if (strpos($to, '<')) { preg_match('/<(.*)>/', $to, $matches); $to = $matches[1]; } if (strpos($from, '<')) { preg_match('/<(.*)>/', $from, $matches); $from = $matches[1]; } } // make sure From is set if (empty($headers['From'])) { $headers['From'] = $from; } // stringify headers $headers_string = ''; foreach ($headers as $key => $value) { $headers_string .= "{$key}: {$value}{$header_eol}"; } // Sanitise subject by stripping line endings $subject = preg_replace("/(\r\n|\r|\n)/", " ", $subject); // this is because Elgg encodes everything and matches what is done with body $subject = html_entity_decode($subject, ENT_QUOTES, 'UTF-8'); // Decode any html entities if (is_callable('mb_encode_mimeheader')) { $subject = mb_encode_mimeheader($subject, "UTF-8", "B"); } // Format message $body = html_entity_decode($body, ENT_QUOTES, 'UTF-8'); // Decode any html entities $body = elgg_strip_tags($body); // Strip tags from message $body = preg_replace("/(\r\n|\r)/", "\n", $body); // Convert to unix line endings in body $body = preg_replace("/^From/", ">From", $body); // Change lines starting with From to >From $body = wordwrap($body); return mail($to, $subject, $body, $headers_string); }
$original_message = get_entity($original_msg_guid); $sender_guid = elgg_get_logged_in_user_guid(); $recipient_guids = EntitySet::create(get_input('recipients', []))->guids(); $subject = htmlspecialchars(get_input('subject', ''), ENT_QUOTES, 'UTF-8'); $body = get_input('body'); if (empty($recipient_guids)) { register_error(elgg_echo('inbox:send:error:no_recipients')); forward(REFERRER); } if (empty(elgg_strip_tags($body))) { register_error(elgg_echo('inbox:send:error:no_body')); forward(REFERRER); } $enable_html = elgg_get_plugin_setting('enable_html', 'hypeInbox'); if (!$enable_html) { $body = elgg_strip_tags($body); } $message_hash = ''; $message_type = get_input('message_type', Message::TYPE_PRIVATE); if ($original_message instanceof Message) { $message_hash = $original_message->getHash(); $message_type = $original_message->getMessageType(); } $message = Message::factory(array('sender' => $sender_guid, 'recipients' => $recipient_guids, 'subject' => $subject, 'body' => $body, 'hash' => $message_hash, 'message_type' => $message_type)); $guid = $message->send(); if (!$guid) { register_error(elgg_echo('inbox:send:error:generic')); forward(REFERRER); } $new_message = get_entity($guid); $sender = $new_message->getSender();
namespace hypeJunction\Gallery; $entity = elgg_extract('entity', $vars); $requested_size = $size = elgg_extract('size', $vars); $gallery_config = get_icon_sizes($entity); if (array_key_exists($requested_size, $gallery_config)) { $values = elgg_extract($requested_size, $gallery_config); $requested_w = $values['w']; if ($values['square']) { $requested_h = $values['h']; } } else { list($requested_w, $requested_h) = explode('x', $requested_size); } $class = elgg_extract('img_class', $vars, 'gallery-album-icon centered'); $title = htmlspecialchars($entity->title, ENT_QUOTES, 'UTF-8', false); $url = $entity->getURL(); if (isset($vars['href'])) { $url = $vars['href']; } $img = elgg_view('output/img', array('src' => $entity->getIconURL($vars['size']), 'class' => $class, 'width' => $requested_w, 'height' => $requested_h)); if ($url) { $params = array('href' => $url, 'text' => $img, 'title' => $title . ": " . elgg_strip_tags($entity->description), 'is_trusted' => true, 'data-guid' => $entity->guid); if ($class) { $params['class'] = $class; } echo elgg_view('output/url', $params); } else { echo $img; }
/** * Send an email to any email address * * @param mixed $from Email address or string: "name <email>" * @param mixed $to Email address or string: "name <email>" * @param string $subject The subject of the message * @param string $body The message body * @param array $params Optional parameters * @return bool * @throws NotificationException */ function notifications_html_handler_send_email($from, $to, $subject, $body, array $params = null) { $options = array('to' => $to, 'from' => $from, 'subject' => $subject, 'body' => $body, 'params' => $params, 'headers' => array("Content-Type" => "text/html; charset=UTF-8; format=flowed", "MIME-Version" => "1.0", "Content-Transfer-Encoding" => "8bit")); // $mail_params is passed as both params and return value. The former is for backwards // compatibility. The latter is so handlers can now alter the contents/headers of // the email by returning the array $options = elgg_trigger_plugin_hook('email', 'system', $options, $options); if (!is_array($options)) { // don't need null check: Handlers can't set a hook value to null! return (bool) $options; } try { if (empty($options['from'])) { $msg = "Missing a required parameter, '" . 'from' . "'"; throw new \NotificationException($msg); } if (empty($options['to'])) { $msg = "Missing a required parameter, '" . 'to' . "'"; throw new \NotificationException($msg); } $options['to'] = \Elgg\Mail\Address::fromString($options['to']); $options['from'] = \Elgg\Mail\Address::fromString($options['from']); $options['subject'] = elgg_strip_tags($options['subject']); $options['subject'] = html_entity_decode($options['subject'], ENT_QUOTES, 'UTF-8'); // Sanitise subject by stripping line endings $options['subject'] = preg_replace("/(\r\n|\r|\n)/", " ", $options['subject']); $options['subject'] = elgg_get_excerpt(trim($options['subject'], 80)); $message = new \Zend\Mail\Message(); foreach ($options['headers'] as $headerName => $headerValue) { $message->getHeaders()->addHeaderLine($headerName, $headerValue); } $message->setEncoding('UTF-8'); $message->addFrom($options['from']); $message->addTo($options['to']); $message->setSubject($options['subject']); $body = new Zend\Mime\Message(); $html = new \Zend\Mime\Part($options['body']); $html->type = "text/html"; $body->addPart($html); $files = elgg_extract('attachments', $options['params']); if (!empty($files) && is_array($files)) { foreach ($files as $file) { if (!$file instanceof \ElggFile) { continue; } $attachment = new \Zend\Mime\Part(fopen($file->getFilenameOnFilestore(), 'r')); $attachment->type = $file->getMimeType() ?: $file->detectMimeType(); $attachment->filename = $file->originalfilename ?: basename($file->getFilename()); $attachment->disposition = Zend\Mime\Mime::DISPOSITION_ATTACHMENT; $attachment->encoding = Zend\Mime\Mime::ENCODING_BASE64; $body->addPart($attachment); } } $message->setBody($body); $transport = notifications_html_handler_get_transport(); if (!$transport instanceof Zend\Mail\Transport\TransportInterface) { throw new \NotificationException("Invalid Email transport"); } $transport->send($message); } catch (\Exception $e) { elgg_log($e->getMessage(), 'ERROR'); return false; } return true; }
/** * Send an email to any email address * * @param string $from Email address or string: "name <email>" * @param string $to Email address or string: "name <email>" * @param string $subject The subject of the message * @param string $body The message body * @param array $params Optional parameters (none used in this function) * * @return bool * @throws NotificationException * @since 1.7.2 */ function elgg_send_email($from, $to, $subject, $body, array $params = null) { if (!$from) { $msg = "Missing a required parameter, '" . 'from' . "'"; throw new \NotificationException($msg); } if (!$to) { $msg = "Missing a required parameter, '" . 'to' . "'"; throw new \NotificationException($msg); } $headers = array("Content-Type" => "text/plain; charset=UTF-8; format=flowed", "MIME-Version" => "1.0", "Content-Transfer-Encoding" => "8bit"); // return true/false to stop elgg_send_email() from sending $mail_params = array('to' => $to, 'from' => $from, 'subject' => $subject, 'body' => $body, 'headers' => $headers, 'params' => $params); // $mail_params is passed as both params and return value. The former is for backwards // compatibility. The latter is so handlers can now alter the contents/headers of // the email by returning the array $result = _elgg_services()->hooks->trigger('email', 'system', $mail_params, $mail_params); if (!is_array($result)) { // don't need null check: Handlers can't set a hook value to null! return (bool) $result; } // strip name from to and from $to_address = Address::fromString($result['to']); $from_address = Address::fromString($result['from']); $subject = elgg_strip_tags($result['subject']); $subject = html_entity_decode($subject, ENT_QUOTES, 'UTF-8'); // Sanitise subject by stripping line endings $subject = preg_replace("/(\r\n|\r|\n)/", " ", $subject); $subject = trim($subject); $body = elgg_strip_tags($result['body']); $body = html_entity_decode($body, ENT_QUOTES, 'UTF-8'); $body = wordwrap($body); $message = new Message(); $message->setEncoding('UTF-8'); $message->addFrom($from_address); $message->addTo($to_address); $message->setSubject($subject); $message->setBody($body); foreach ($result['headers'] as $headerName => $headerValue) { $message->getHeaders()->addHeaderLine($headerName, $headerValue); } try { _elgg_services()->mailer->send($message); } catch (\Zend\Mail\Exception\RuntimeException $e) { _elgg_services()->logger->error($e->getMessage()); return false; } return true; }
public function filterSite($object) { $return = array(); foreach (self::$entity_fields as $field) { $return[$field] = $object->{$field}; } $return['title'] = $object->title; $return['description'] = elgg_strip_tags($return['description']); // remove HTML $return['url'] = $object->url; return $return; }
/** * Send an email to any email address * * @param string $from Email address or string: "name <email>" * @param string $to Email address or string: "name <email>" * @param string $subject The subject of the message * @param string $body The message body * @param array $params Optional parameters (none used in this function) * * @return bool * @since 1.7.2 */ function elgg_send_email($from, $to, $subject, $body, array $params = NULL) { global $CONFIG; if (!$from) { $msg = elgg_echo('NotificationException:MissingParameter', array('from')); throw new NotificationException($msg); } if (!$to) { $msg = elgg_echo('NotificationException:MissingParameter', array('to')); throw new NotificationException($msg); } // return TRUE/FALSE to stop elgg_send_email() from sending $mail_params = array('to' => $to, 'from' => $from, 'subject' => $subject, 'body' => $body, 'params' => $params); $result = elgg_trigger_plugin_hook('email', 'system', $mail_params, NULL); if ($result !== NULL) { return $result; } $header_eol = "\r\n"; if (isset($CONFIG->broken_mta) && $CONFIG->broken_mta) { // Allow non-RFC 2822 mail headers to support some broken MTAs $header_eol = "\n"; } // Windows is somewhat broken, so we use just address for to and from if (strtolower(substr(PHP_OS, 0, 3)) == 'win') { // strip name from to and from if (strpos($to, '<')) { preg_match('/<(.*)>/', $to, $matches); $to = $matches[1]; } if (strpos($from, '<')) { preg_match('/<(.*)>/', $from, $matches); $from = $matches[1]; } } $headers = "From: {$from}{$header_eol}" . "Content-Type: text/plain; charset=UTF-8; format=flowed{$header_eol}" . "MIME-Version: 1.0{$header_eol}" . "Content-Transfer-Encoding: 8bit{$header_eol}"; // Sanitise subject by stripping line endings $subject = preg_replace("/(\r\n|\r|\n)/", " ", $subject); if (is_callable('mb_encode_mimeheader')) { $subject = mb_encode_mimeheader($subject, "UTF-8", "B"); } // Format message $body = html_entity_decode($body, ENT_COMPAT, 'UTF-8'); // Decode any html entities $body = elgg_strip_tags($body); // Strip tags from message $body = preg_replace("/(\r\n|\r)/", "\n", $body); // Convert to unix line endings in body $body = preg_replace("/^From/", ">From", $body); // Change lines starting with From to >From return mail($to, $subject, wordwrap($body), $headers); }
function plugin_search($hook, $type, $return, $params) { $select = array('start' => $params['offset'], 'rows' => $params['limit'], 'fields' => array('id', 'title', 'description')); if ($params['select'] && is_array($params['select'])) { $select = array_merge($select, $params['select']); } // create a client instance $client = elgg_solr_get_client(); // get an update query instance $query = $client->createSelect($select); $sorts = array('score' => 'desc', 'time_created' => 'desc'); if ($params['sorts'] && is_array($params['sorts'])) { $sorts = $params['sorts']; } $query->addSorts($sorts); $title_boost = elgg_solr_get_title_boost(); $description_boost = elgg_solr_get_description_boost(); // get the dismax component and set a boost query $dismax = $query->getDisMax(); $qf = "title^{$title_boost} description^{$description_boost}"; if ($params['qf']) { $qf = $params['qf']; } $dismax->setQueryFields($qf); $dismax->setQueryAlternative('*:*'); $boostQuery = elgg_solr_get_boost_query(); if ($boostQuery) { $dismax->setBoostQuery($boostQuery); } // this query is now a dismax query $query->setQuery($params['query']); // make sure we're only getting objects:plugin_project $params['fq']['type'] = 'type:object'; $params['fq']['subtype'] = 'subtype:plugin_project'; if (($category = get_input('category')) && $category != 'all') { $params['fq']['plugincat'] = 'tags:"' . elgg_solr_escape_special_chars('plugincat%%' . $category) . '"'; } $default_fq = elgg_solr_get_default_fq($params); if ($params['fq']) { $filter_queries = array_merge($default_fq, $params['fq']); } else { $filter_queries = $default_fq; } if (!empty($filter_queries)) { foreach ($filter_queries as $key => $value) { $query->createFilterQuery($key)->setQuery($value); } } // get highlighting component and apply settings $hl = $query->getHighlighting(); $hl->setFields(array('title', 'description')); $hl->setSimplePrefix('<strong class="search-highlight search-highlight-color1">'); $hl->setSimplePostfix('</strong>'); // this executes the query and returns the result try { $resultset = $client->select($query); } catch (Exception $e) { error_log($e->getMessage()); return null; } // Get the highlighted snippet try { $highlighting = $resultset->getHighlighting(); } catch (Exception $e) { error_log($e->getMessage()); return null; } // Count the total number of documents found by solr $count = $resultset->getNumFound(); $search_results = array(); foreach ($resultset as $document) { $search_results[$document->id] = array(); $snippet = ''; // highlighting results can be fetched by document id (the field defined as uniquekey in this schema) $highlightedDoc = $highlighting->getResult($document->id); if ($highlightedDoc) { foreach ($highlightedDoc as $field => $highlight) { $snippet = implode(' (...) ', $highlight); $snippet = search_get_highlighted_relevant_substrings(elgg_strip_tags($snippet), $params['query']); $search_results[$document->id][$field] = $snippet; } } } // get the entities $entities = array(); $entities_unsorted = array(); if ($search_results) { $entities_unsorted = elgg_get_entities(array('guids' => array_keys($search_results), 'limit' => false)); } foreach ($search_results as $guid => $matches) { foreach ($entities_unsorted as $e) { if ($e->guid == $guid) { if ($matches['title']) { $e->setVolatileData('search_matched_title', $matches['title']); } else { $e->setVolatileData('search_matched_title', $e->title); } if ($matches['description']) { $e->setVolatileData('search_matched_description', $matches['description']); } else { $e->setVolatileData('search_matched_description', elgg_get_excerpt($e->description, 100)); } $entities[] = $e; } } } return array('entities' => $entities, 'count' => $count); }
function elgg_solr_index_annotation($annotation) { $client = elgg_solr_get_client(); $commit = elgg_get_config('elgg_solr_nocommit') ? false : true; $query = $client->createUpdate(); // add document $doc = $query->createDocument(); $doc->id = 'annotation:' . $annotation->id; $doc->type = 'annotation'; $doc->subtype = $annotation->name; $doc->owner_guid = $annotation->owner_guid; $doc->container_guid = $annotation->entity_guid; $doc->access_id = $annotation->access_id; $doc->description = elgg_strip_tags($annotation->value); $doc->time_created = $annotation->time_created; $doc->enabled = $annotation->enabled; $doc = elgg_trigger_plugin_hook('elgg_solr:index', 'annotation', array('annotation' => $annotation), $doc); if (!$doc) { return true; // a plugin has stopped the index } $query->addDocument($doc); if ($commit) { $query->addCommit($commit); } // this executes the query and returns the result try { $client->update($query); } catch (Exception $exc) { error_log($exc->getMessage()); } }
$region = $fees = $type = $tags = ""; $region = $vevent->getProperty('X-PROP-REGION'); $fees = $vevent->getProperty('X-PROP-FEES'); $event_type = $vevent->getProperty('X-PROP-TYPE'); $tags = $vevent->getProperty('X-PROP-TAGS'); $contact = $vevent->getProperty('X-PROP-CONTACT'); $long_description = $vevent->getProperty('X-PROP-LONG-DESC'); if (empty($long_description[1])) { $long_description = array(1 => $description); } set_input('event_action', 'add_event'); set_input('event_id', 0); if ($container_guid) { set_input('group_guid', $container_guid); } set_input('title', elgg_strip_tags($summary)); set_input('venue', $venue); if ($event_calendar_times == 'yes') { set_input('start_time_hour', $starttime->format('H')); set_input('start_time_minute', $starttime->format('i')); set_input('end_time_hour', $endtime->format('H')); set_input('end_time_minute', $endtime->format('i')); } $strdate = $starttime->format('Y-m-d'); set_input('start_date', $strdate); $enddate = $endtime->format('Y-m-d'); set_input('end_date', $enddate); set_input('brief_description', nl2br($description)); if ($event_calendar_region_display == 'yes') { set_input('region', $region[1]); }