/** * Gestor de páginas * * @param array $page Array of page routing elements * @return bool */ function trip_companions_page_handler($page) { //system_message("page handler " . elgg_extract(0, $page)); // only logged in users can do things elgg_gatekeeper(); if (elgg_extract(0, $page) === 'add' && elgg_is_xhr()) { echo elgg_view('resources/evaluationcontent/add_form'); return true; } if (elgg_extract(0, $page) === 'import') { echo elgg_view('resources/trip_companions/add_form'); return true; } $friends = $groups = 0; switch ($page[0]) { case 'groups': $groups = 10; break; default: $friends = $groups = 10; break; } $page_owner = elgg_get_logged_in_user_entity(); elgg_set_page_owner_guid($page_owner->guid); elgg_set_context("trip_companions"); $content = elgg_view('resources/trip_companions/list', array('owner' => $page_owner, 'friends' => $friends, 'groups' => $groups)); if ($content) { echo $content; return true; } return false; }
public function execute() { $this->uploads = hypeApps()->uploader->handle('dropzone', array('subtype' => $this->subtype, 'container_guid' => $this->container_guid, 'access_id' => ACCESS_PRIVATE)); $this->output = array(); if (!elgg_is_xhr()) { return; } foreach ($this->uploads as $upload) { $messages = array(); $success = true; if ($upload->error) { $messages[] = $upload->error; $success = false; $guid = false; } else { $file = $upload->file; if (!$file instanceof \ElggEntity) { $messages[] = elgg_echo('dropzone:file_not_entity'); $success = false; } else { $guid = $file->getGUID(); $html = elgg_view('input/hidden', array('name' => $this->input_name, 'value' => $file->getGUID())); } } $file_output = array('messages' => $messages, 'success' => $success, 'guid' => $guid, 'html' => $html); $output[] = elgg_trigger_plugin_hook('upload:after', 'dropzone', array('upload' => $upload), $file_output); } $this->result->output = json_encode($output); }
/** * Stripe related pages * * @param array $page * @param string $handler * @return boolean */ function stripe_page_handler($page, $handler) { gatekeeper(); $username = elgg_extract(0, $page, false); if ($username) { $user = get_user_by_username($username); } if (!elgg_instanceof($user) || !$user->canEdit()) { $user = elgg_get_logged_in_user_entity(); forward("{$handler}/{$user->username}"); } elgg_set_context('settings'); elgg_set_page_owner_guid($user->guid); elgg_push_breadcrumb(elgg_echo('stripe:billing'), 'billing'); $context = elgg_extract(1, $page, 'cards'); $action = elgg_extract(2, $page, 'all'); $view = "stripe/pages/{$context}/{$action}"; if (elgg_view_exists($view)) { $params = array('entity' => $user, 'id' => elgg_extract(3, $page, false), 'context' => $page); $title = elgg_echo("stripe:{$context}:{$action}"); $content = elgg_view($view, $params); $sidebar = elgg_view('stripe/sidebar', $params); $filter = elgg_view("stripe/filters/{$context}/{$action}", $params); } if ($content) { if (elgg_is_xhr()) { echo $content; } else { $layout = elgg_view_layout('content', array('title' => $title, 'content' => $content, 'sidebar' => $sidebar, 'filter' => $filter)); echo elgg_view_page($title, $layout); } return true; } return false; }
/** * Page handler for static sites * * This page handler will behave like a REST-ful api endpoint for GET request * Since static sites 'containers' are groups, the resource naming and endpoints * will look like: * * GET - {elgg_url}/staticsites/{group_guid}/page/{id} * GET - {elgg_url}/staticsites/{group_guid}/pages * */ function staticsites_page_handler($params) { // Logged in only gatekeeper(); $is_xhr = elgg_is_xhr(); $is_xhr = 1; // Debug if ($is_xhr && $params[0]) { // Check for container_guid as first param if (is_numeric($params[0])) { $container_guid = $params[0]; unset($params[0]); $params = array_values($params); } switch ($params[0]) { case "page": staticsites_handle_page_request($params, $container_guid); break; case "pages": staticsites_handle_pages_request($params, $container_guid); break; default: return FALSE; break; } } else { return FALSE; } return TRUE; }
/** * Handles embedded URLs * * @param array $page URL segments * @return boolean */ function handlePages($page) { $url = get_input('url'); $handle = get_input('handle'); $iframe = get_input('iframe', false); $site = elgg_get_site_entity(); if (!$handle) { $handle = $site->guid; } if (!$url || !$handle) { return false; } $parse = elgg_is_logged_in(); switch ($page[0]) { default: $data = $this->model->get($url, $handle, $parse); $layout = elgg_view('output/card', array('href' => $url, 'handle' => $handle)); if (elgg_is_xhr()) { echo $layout; } else { $shell = $iframe ? 'iframe' : 'default'; echo elgg_view_page($data['title'], $layout, $shell); } break; case 'json': $data = $this->model->get($url, $handle, $parse); header('Content-Type: application/json'); echo json_encode($data); exit; } return true; }
function file_tools_page_handler($page) { $include_file = false; switch ($page[0]) { case "list": if (elgg_is_xhr() && !empty($page[1])) { elgg_set_page_owner_guid($page[1]); if (get_input("folder_guid", false) !== false) { set_input("draw_page", false); } if (isset($page[2])) { set_input("folder_guid", $page[2]); } $include_file = dirname(dirname(__FILE__)) . "/pages/list.php"; } break; case "folder": if ($page[1] == 'new') { if (!empty($page[2])) { elgg_set_page_owner_guid($page[2]); } $include_file = dirname(dirname(__FILE__)) . "/pages/folder/new.php"; } elseif ($page[1] == 'edit') { if (!empty($page[2])) { set_input("folder_guid", $page[2]); $include_file = dirname(dirname(__FILE__)) . "/pages/folder/edit.php"; } } break; case "file": if ($page[1] == 'new') { if (!empty($page[2])) { elgg_set_page_owner_guid($page[2]); } $include_file = dirname(dirname(__FILE__)) . "/pages/file/new.php"; } elseif ($page[1] == 'edit') { set_input("guid", $page[2]); $include_file = dirname(dirname(__FILE__)) . "/pages/file/edit.php"; } elseif ($page[1] == 'download') { $include_file = dirname(dirname(__FILE__)) . "/pages/file/download.php"; } break; case "proc": if (file_exists(dirname(dirname(__FILE__)) . "/procedures/" . $page[1] . "/" . $page[2] . ".php")) { $include_file = dirname(dirname(__FILE__)) . "/procedures/" . $page[1] . "/" . $page[2] . ".php"; } else { echo json_encode(array('valid' => 0)); exit; } break; } if (!empty($include_file)) { include $include_file; return true; } else { forward("file/all"); } }
/** * Reported content page handler * * Serves the add report page * * @param array $page Array of page routing elements * @return bool */ function reportedcontent_page_handler($page) { // only logged in users can report things elgg_gatekeeper(); if (elgg_extract(0, $page) === 'add' && elgg_is_xhr()) { echo elgg_view('resources/reportedcontent/add_form'); return true; } echo elgg_view('resources/reportedcontent/add'); return true; }
/** * Page handler for embeds * * @param array $page */ function embed_page_handler($page) { $params = array('output' => '', 'status' => 0, 'system_messages' => array('error' => array(), 'success' => array())); $container_guid = get_input('container_guid'); if ($container_guid && get_entity($container_guid)) { elgg_set_page_owner_guid($container_guid); } switch ($page[0]) { default: case 'tab': $default_tab = elgg_is_active_plugin('file') ? 'file' : 'content_items'; $embed_tab = elgg_extract(1, $page, $default_tab); $title = elgg_echo("embed:embed"); $filter = elgg_view('embed/filter', array('filter_context' => $embed_tab)); $view = "embed/tab/{$embed_tab}"; if (elgg_view_exists($view)) { $content = elgg_view($view); } else { $embed_tab = elgg_get_config('embed_tab'); if ($embed_tab instanceof \ElggMenuItem) { $view = $embed_tab->getData('view'); $options = $embed_tab->getData('options'); if ($view) { $content = elgg_view($view); } else { if ($options) { $content = elgg_view('embed/get_list', array('options' => $options)); } } } } if (empty($content)) { $content = elgg_autop(elgg_echo('embed:section:invalid')); } $params['output'] = elgg_view_layout('one_column', array('title' => $title, 'content' => $filter . $content, 'class' => 'embed-wrapper')); break; } $system_messages = system_messages(NULL, ""); if (isset($system_messages['success'])) { $params['system_messages']['success'] = $system_messages['success']; } if (isset($system_messages['error'])) { $params['system_messages']['error'] = $system_messages['error']; $params['status'] = -1; } // We do not want to serve this page via non-xhr requests if (!elgg_is_xhr()) { register_error(elgg_echo('embed:error:non_xhr_request')); return false; } echo json_encode($params); exit; }
/** * Filter AJAX output * * @param string $hook Equals 'view' * @param string $type Equals 'all' * @param string $return View output * @param array $params Additional params * @staticvar string $maps_ajax_output * @return string Filtered output */ function ajax_list_view($hook, $type, $return, $params) { static $maps_ajax_output; if (!elgg_is_xhr() || !get_input('mapbox')) { return $return; } $vars = elgg_extract('vars', $params); $map = elgg_extract('list', $vars); if ($type == 'page/components/mapbox' && $map instanceof ElggMap && (!get_input('hash') || $map->getHash() == get_input('hash'))) { $maps_ajax_output = $return; } if ($type == 'page/default' || ($type = 'page/layouts/maps_ajax')) { return $maps_ajax_output; } return elgg_in_context('mapbox') ? $return : ''; }
/** * Reported content page handler * * Serves the add report page * * @param array $page Array of page routing elements * @return bool */ function reportedcontent_page_handler($page) { // only logged in users can report things elgg_gatekeeper(); if (elgg_extract(0, $page) === 'add' && elgg_is_xhr()) { echo elgg_view('resources/reportedcontent/add_form'); return true; } $title = elgg_echo('reportedcontent:this'); $content = elgg_view_form('reportedcontent/add'); $sidebar = elgg_echo('reportedcontent:instructions'); $params = array('title' => $title, 'content' => $content, 'sidebar' => $sidebar); $body = elgg_view_layout('one_sidebar', $params); echo elgg_view_page($title, $body); return true; }
function hj_framework_view_list($list_id, $getter_options = array(), $list_options = array(), $viewer_options = array(), $getter = 'elgg_get_entities') { $default_list_options = array('list_type' => 'list', 'list_class' => null, 'item_class' => null, 'base_url' => current_page_url(), 'num_pages' => 5, 'pagination' => true, 'limit_key' => "__lim_{$list_id}", 'offset_key' => "__off_{$list_id}", 'order_by_key' => "__ord_{$list_id}", 'direction_key' => "__dir_{$list_id}", 'reverse_list' => false); $list_options = array_merge($default_list_options, $list_options); if (!isset($getter_options['limit'])) { $getter_options['limit'] = get_input($list_options['limit_key'], 10); } if (!isset($getter_options['offset'])) { $getter_options['offset'] = get_input($list_options['offset_key'], 0); } $porder_by = get_input($list_options['order_by_key'], ''); $pdirection = get_input($list_options['direction_key'], 'DESC'); $getter_options = hj_framework_get_order_by_clause($porder_by, $pdirection, $getter_options); if (isset($list_options['filter_callback']) && is_callable($list_options['filter_callback'])) { $getter_options = call_user_func_array($list_options['filter_callback'], array($list_id, $getter_options)); } $getter_options = elgg_trigger_plugin_hook('custom_sql_clause', 'framework:lists', array('list_id' => $list_id, 'list_options' => $list_options, 'viewer_options' => $viewer_options), $getter_options); $getter_options['count'] = true; $count = $getter($getter_options); //error_log(print_r($getter_options, true)); $getter_options['count'] = false; $entities = $getter($getter_options); if ($list_options['reverse_list']) { $entities = array_reverse($entities); } $params = array('list_id' => $list_id, 'entities' => $entities, 'count' => $count, 'list_options' => $list_options, 'getter_options' => $getter_options, 'viewer_options' => $viewer_options, 'getter' => $getter); if (elgg_view_exists("page/components/grids/{$list_options['list_type']}")) { $list = elgg_view("page/components/grids/{$list_options['list_type']}", $params, false, false, 'default'); } else { $list = elgg_view("page/components/grids/list", $params, false, false, 'default'); } if (elgg_is_xhr() && get_input('view') == 'xhr') { if (elgg_view_exists("page/components/grids/{$list_options['list_type']}")) { $json_list = elgg_view("page/components/grids/{$list_options['list_type']}", $params, false, false, 'xhr'); } else { $json_list = elgg_view("page/components/grids/list", $params, false, false, 'xhr'); } global $XHR_GLOBAL; $XHR_GLOBAL['lists'][$list_id] = $json_list; } return elgg_view('page/components/grids/wrapper', array('body' => $list)); }
/** * Change menu item in the longtext menu * * @param string $hook 'prepare' * @param string $type 'menu:longtext' * @param ElggMenuItem[] $return_value the current menu items * @param array $params supplied params * * @return ElggMenuItem[] */ public static function longtextMenuPrepare($hook, $type, $return_value, $params) { if (!is_array($return_value)) { return; } foreach ($return_value as $section => $menu_items) { if (!is_array($menu_items)) { continue; } foreach ($menu_items as $menu_item) { if ($menu_item->getName() !== 'embed') { continue; } if (elgg_is_xhr()) { echo elgg_format_element('script', [], 'require(["embed_extended/site"]);'); } else { elgg_require_js('embed_extended/site'); } $link_class = $menu_item->getLinkClass(); $link_class = str_ireplace('elgg-lightbox', 'elgg-embed-lightbox', $link_class); $menu_item->setLinkClass($link_class); } } }
<?php //hack! Elgg engine should take care of this, or blog/save form should be coded better if (elgg_is_xhr() && isset($vars['entity_guid'])) { elgg_set_page_owner_guid($vars['entity_guid']); } echo elgg_view_form('messageboard/add', array(), $vars);
} $offset = abs((int) elgg_extract('offset', $vars, 0)); // because you can say $vars['limit'] = 0 if (!($limit = (int) elgg_extract('limit', $vars, elgg_get_config('default_limit')))) { $limit = 10; } $offset_key = elgg_extract('offset_key', $vars, 'offset'); $url_fragment = elgg_extract('url_fragment', $vars, ''); // some views pass an empty string for base_url if (isset($vars['base_url']) && $vars['base_url']) { $base_url = $vars['base_url']; } else { if (isset($vars['baseurl']) && $vars['baseurl']) { elgg_deprecated_notice("Use 'base_url' instead of 'baseurl' for the navigation/pagination view", 1.8); $base_url = $vars['baseurl']; } elseif (elgg_is_xhr() && !empty($_SERVER['HTTP_REFERER'])) { $base_url = $_SERVER['HTTP_REFERER']; } else { $base_url = current_page_url(); } } $base_url_has_fragment = preg_match('~#.~', $base_url); $get_href = function ($offset) use($base_url, $base_url_has_fragment, $offset_key, $url_fragment) { $link = elgg_http_add_url_query_elements($base_url, array($offset_key => $offset)); if (!$base_url_has_fragment && $offset) { $link .= "#{$url_fragment}"; } return $link; }; if ($count <= $limit && $offset == 0) { // no need for pagination
/** * Require that the current request be an XHR. If not, execution of the current function * will end and a 400 response page will be sent. * * @return void * @since 1.12.0 */ function elgg_ajax_gatekeeper() { if (!elgg_is_xhr()) { register_error(_elgg_services()->translator->translate('ajax:not_is_xhr')); forward(null, '400'); } }
/** * Page handler for 'messages' * @param array $page An array of URL segments * @return boolean Outputs a page or returns false on failure */ function hj_inbox_page_handler($page) { gatekeeper(); elgg_load_css('inbox.base.css'); // Due to varying segmentation in earlier version of messages plugin, let's iterate through segments and find the page owner foreach ($page as $segment) { $current_user = get_user_by_username($segment); if (elgg_instanceof($current_user, 'user')) { break; } } if (elgg_instanceof($current_user, 'user') && !$current_user->canEdit()) { forward("messages/{$current_user->username}"); } else { $current_user = elgg_get_logged_in_user_entity(); } elgg_set_page_owner_guid($current_user->guid); elgg_push_breadcrumb(elgg_echo("hj:inbox"), "messages/{$current_user->username}"); switch ($page[0]) { default: case 'inbox': case 'incoming': hj_inbox_title_menu_setup(); elgg_load_js('inbox.user.js'); $message_type = get_input('message_type', HYPEINBOX_PRIVATE); elgg_push_breadcrumb(elgg_echo("hj:inbox"), "messages/inbox/{$current_user->username}"); elgg_push_breadcrumb(elgg_echo("item:object:message:{$message_type}:plural")); $params = array('message_type' => $message_type); $title = elgg_echo("hj:inbox:inbox"); $content = elgg_view("framework/inbox/inbox", $params); $filter = elgg_view("framework/inbox/filters/inbox", $params); $sidebar = elgg_view('framework/inbox/sidebar', $params); break; case 'outbox': case 'outgoing': case 'sent': hj_inbox_title_menu_setup(); elgg_load_js('inbox.user.js'); $message_type = get_input('message_type', HYPEINBOX_PRIVATE); elgg_push_breadcrumb(elgg_echo("hj:inbox:sent"), "messages/sent/{$current_user->username}"); elgg_push_breadcrumb(elgg_echo("item:object:message:{$message_type}:plural")); $params = array('message_type' => $message_type); $title = elgg_echo("hj:inbox:sent"); $content = elgg_view("framework/inbox/sent", $params); $filter = elgg_view("framework/inbox/filters/sent", $params); $sidebar = elgg_view('framework/inbox/sidebar', $params); break; case 'read': case 'view': case 'reply': $entity = get_entity($page[1]); hj_inbox_title_menu_setup($entity); if (!elgg_instanceof($entity, 'object', 'messages')) { $title = elgg_echo('hj:inbox:message_not_found'); $content = elgg_view('framework/inbox/notfound'); } else { elgg_push_breadcrumb(elgg_echo("hj:inbox:inbox"), "messages/inbox/{$current_user->username}"); elgg_push_breadcrumb(elgg_echo("item:object:message:{$entity->msgType}:plural"), "messages/inbox/{$current_user->username}?message_type={$entity->msgType}"); elgg_push_breadcrumb($entity->title); $title = elgg_echo('hj:inbox:message', array($entity->title)); $content = elgg_view('framework/inbox/thread', array('entity' => $entity)); } $filter = false; $sidebar = elgg_view('framework/inbox/sidebar', array('entity' => $entity, 'message_type' => $entity->msgType)); break; case 'thread': $hash = elgg_extract(1, $page, false); if (!$hash) { return false; } $entities = elgg_get_entities_from_metadata(array('owner_guid' => $current_user->guid, 'metadata_name_value_pairs' => array('name' => 'msgHash', 'value' => $hash), 'order_by' => 'e.time_created ASC', 'limit' => 1)); $entity = $entities[0]; hj_inbox_title_menu_setup($entity); if (!elgg_instanceof($entity, 'object', 'messages')) { $title = elgg_echo('hj:inbox:message_not_found'); $content = elgg_view('framework/inbox/notfound'); } else { elgg_push_breadcrumb(elgg_echo("hj:inbox:inbox"), "messages/inbox/{$current_user->username}"); elgg_push_breadcrumb(elgg_echo("item:object:message:{$entity->msgType}:plural"), "messages/inbox/{$current_user->username}?message_type={$entity->msgType}"); elgg_push_breadcrumb($entity->title); $title = elgg_echo('hj:inbox:message', array($entity->title)); $content = elgg_view('framework/inbox/thread', array('entity' => $entity, 'message_hash' => $hash)); } $filter = false; $sidebar = elgg_view('framework/inbox/sidebar', array('entity' => $entity, 'message_type' => $entity->msgType)); break; case 'compose': case 'add': $message_type = get_input('message_type', HYPEINBOX_PRIVATE); $entity = get_entity($page[1]); $title = elgg_echo("hj:inbox:compose", array("item:object:message:{$message_type}:singular")); elgg_push_breadcrumb(elgg_echo("item:object:message:{$message_type}:plural")); elgg_push_breadcrumb($title); $params = hj_inbox_prepare_form_vars((int) get_input('send_to'), $message_type, $entity); $content = elgg_view("framework/inbox/compose", $params); $filter = false; $sidebar = elgg_view('framework/inbox/sidebar', $params); break; case 'userpicker': $sender = elgg_get_logged_in_user_entity(); $message_type = get_input('message_type', HYPEINBOX_PRIVATE); $letter = get_input('letter', false); $output = array('counters' => array(), 'items' => array()); $getter_options = hj_inbox_get_userpicker_options($message_type, $sender); $dbprefix = elgg_get_config('dbprefix'); if ($letter) { $options = $getter_options; $options['limit'] = 0; $options['joins'][] = "JOIN {$dbprefix}users_entity ue_query ON e.guid = ue_query.guid"; $options['wheres'][] = "LOWER(ue_query.name) LIKE '{$letter}%'"; $options['order_by'] = "ue_query.name ASC"; $items = new ElggBatch('elgg_get_entities', $options); if ($items) { foreach ($items as $item) { $output['items'][] = elgg_view('input/messages/userpicker/item', array('entity' => $item, 'name' => get_input('name'), 'multiple' => get_input('multiple', false), 'checked' => in_array($item->guid, get_input('value', array()))), false, false, 'default'); } } } else { foreach (range('a', 'z') as $letter) { $letters[] = "'{$letter}'"; $letter = sanitize_string($letter); $options = $getter_options; $options['joins'][] = "JOIN {$dbprefix}users_entity ue_query ON e.guid = ue_query.guid"; $options['wheres'][] = "LOWER(ue_query.name) LIKE '{$letter}%'"; $options['order_by'] = "ue_query.name ASC"; $options['count'] = true; $count = elgg_get_entities($options); $output['counters'][$letter] = (int) $count; } $letters_in = implode(',', $letters); $options = $getter_options; $options['joins'][] = "JOIN {$dbprefix}users_entity ue_query ON e.guid = ue_query.guid"; $options['wheres'][] = "LOWER(LEFT(ue_query.name,1)) NOT IN ({$letters_in})"; $options['order_by'] = "ue_query.name ASC"; $options['count'] = true; $count = elgg_get_entities($options); $output['counters']['*'] = (int) $count; } header("Content-type: application/json"); echo json_encode($output); exit; break; } $params = array('title' => $title, 'filter' => $filter, 'content' => $content, 'sidebar' => $sidebar, 'class' => 'inbox-layout'); if (elgg_is_xhr()) { print json_encode($params); forward(); } else { $layout = elgg_view_layout('content', $params); echo elgg_view_page($title, $layout); } return true; }
/** * Buffer all output echo'd directly in the action for inclusion in the returned JSON. * @return void * @access private */ function ajax_action_hook() { if (elgg_is_xhr()) { ob_start(); } }
/** * Elgg delete like action * */ // Support deleting by id in case we're deleting another user's likes $id = (int) get_input('id'); $like = NULL; if ($id) { $like = elgg_get_annotation_from_id($id); } if (!$like) { $likes = elgg_get_annotations(array('guid' => (int) get_input('guid'), 'annotation_owner_guid' => elgg_get_logged_in_user_guid(), 'annotation_name' => 'likes')); $like = $likes[0]; } if ($like && $like->canEdit()) { $entity = $like->getEntity(); $like->delete(); system_message(elgg_echo("likes:deleted")); if ($entity && elgg_is_xhr()) { $num_of_likes = likes_count($entity); if ($num_of_likes == 1) { $likes_string = elgg_echo('likes:userlikedthis', array($num_of_likes)); } else { $likes_string = elgg_echo('likes:userslikedthis', array($num_of_likes)); } echo json_encode(['text' => $likes_string, 'selector' => "[data-likes-guid={$entity->guid}]", 'num_likes' => $num_of_likes]); } forward(REFERER); } register_error(elgg_echo("likes:notdeleted")); forward(REFERER);
<?php /** * Settings form body * * @uses $vars['values'] */ if (!elgg_is_xhr()) { echo '<p>' . elgg_echo('elgg_dev_tools:settings:explanation') . '</p>'; } foreach ($vars['data'] as $name => $info) { $label = $info['readonly'] ? '<label class="elgg-state-disabled">' : '<label>'; $class = $info['readonly'] ? 'elgg-state-disabled' : ''; $echo_vars = $name === 'show_gear' ? ['<span class="elgg-icon-settings-alt elgg-icon"></span>'] : []; echo '<div>'; if ($info['type'] == 'checkbox') { echo $label; echo elgg_view("input/checkbox", array('name' => $name, 'value' => $info['value'], 'checked' => $info['checked'], 'class' => $class)); echo ' ' . elgg_echo("developers:label:{$name}", $echo_vars) . '</label>'; } else { echo $label . elgg_echo("developers:label:{$name}") . ' '; echo elgg_view("input/{$info['type']}", array('name' => $name, 'value' => $info['value'], 'options_values' => $info['options_values'], 'class' => $class)); echo '</label>'; } echo '<span class="elgg-text-help">' . elgg_echo("developers:help:{$name}") . '</span>'; if ($info['readonly']) { echo '<span class="elgg-text-help">' . elgg_echo('admin:settings:in_settings_file') . '</span>'; } echo '</div>'; } echo '<div class="elgg-foot">';
/** * Make sure users follow the wizard * * @return void|Wizard */ function wizard_check_wizards() { $user = elgg_get_logged_in_user_entity(); if (empty($user)) { // only logged in users return; } if (elgg_is_xhr()) { // only check on regular pages return; } if (elgg_in_context('wizard') || elgg_in_context('admin')) { // deadloop prevention and /admin is allowed return; } $SESSION = elgg_get_session(); if ($SESSION->has('wizards')) { if ($SESSION->get('wizards') === true) { return; } else { foreach ($SESSION->get('wizards', []) as $index => $guid) { $wizard = get_entity($guid); if (!$wizard instanceof Wizard) { unset($SESSION['wizards'][$index]); continue; } return $wizard; } if ($SESSION->get('wizards')) { $SESSION->set('wizards', true); } } } $dbprefix = elgg_get_config('dbprefix'); $endtime_id = elgg_get_metastring_id('endtime'); $entities = elgg_get_entities_from_metadata(['type' => 'object', 'subtype' => \Wizard::SUBTYPE, 'limit' => false, 'metadata_name_value_pairs' => [['name' => 'starttime', 'value' => time(), 'operand' => '<=']], 'joins' => ["JOIN {$dbprefix}metadata mde ON e.guid = mde.entity_guid", "JOIN {$dbprefix}metastrings mse ON mde.value_id = mse.id"], 'wheres' => ["(e.guid NOT IN (SELECT guid_one\n\t\t\t\tFROM {$dbprefix}entity_relationships\n\t\t\t\tWHERE relationship = 'done'\n\t\t\t\tAND guid_two = {$user->getGUID()}\n\t\t\t))", "(mde.name_id = {$endtime_id} AND mse.string = 0 OR mse.string > " . time() . ")"]]); if (empty($entities)) { $SESSION->set('wizards', true); return; } $guids = []; $new_users_guids = []; $user_need_new_user_wizards = $user->getPrivateSetting('wizard_check_first_login_wizards'); foreach ($entities as $e) { if ($e->show_users == 'new_users') { if ($user_need_new_user_wizards) { $new_users_guids[] = $e->getGUID(); } } else { $guids[] = $e->getGUID(); } } if (($user_need_new_user_wizards || $user_need_new_user_wizards === null) && empty($new_users_guids)) { // there are no more new user wizards to show, so report the user as done $user->setPrivateSetting('wizard_check_first_login_wizards', false); } if (empty($new_users_guids) && empty($guids)) { $SESSION->set('wizards', true); return; } if (!empty($new_users_guids)) { $SESSION->set('wizards', $new_users_guids); } else { $SESSION->set('wizards', $guids); } $wizards = $SESSION->get('wizards'); return get_entity($wizards[0]); }
foreach ($custom_types as $type) { $label = "search_types:{$type}"; $count = ""; if (array_key_exists($label, $search_result_counters)) { $total = $search_result_counters[$label]; if ($total > 0) { $count = " <span class='elgg-quiet'>(" . $total . ")</span>"; } } if (!empty($count)) { $data = htmlspecialchars(http_build_query(array('q' => $query, 'search_type' => $type, 'container_guid' => $container_guid))); $url = "search?{$data}"; $menu_item = new ElggMenuItem($label, elgg_echo($label) . $count, $url); elgg_register_menu_item('page', $menu_item); } } // this is passed the original params because we don't care what actually // matched (which is out of date now anyway). // we want to know what search type it is. if (elgg_is_xhr() && !$loader) { echo $body; } elseif (elgg_is_xhr() && $loader) { $layout_view = search_get_search_view($params, 'layout'); $layout = elgg_view($layout_view, array('params' => $params, 'body' => $body)); echo $layout; } else { $layout_view = search_get_search_view($params, 'layout'); $layout = elgg_view($layout_view, array('params' => $params, 'body' => $body)); $title = elgg_echo('search:results', array("\"{$display_query}\"")); echo elgg_view_page($title, $layout); }
/** * Halts bootup and redirects to the site front page * if site is in walled garden mode, no user is logged in, * and the URL is not a public page. * * @return void * @since 1.8.0 */ public function checkWalledGarden() { global $CONFIG; // command line calls should not invoke the walled garden check if (PHP_SAPI === 'cli') { return; } if ($CONFIG->walled_garden) { if ($CONFIG->default_access == ACCESS_PUBLIC) { $CONFIG->default_access = ACCESS_LOGGED_IN; } _elgg_services()->hooks->registerHandler('access:collections:write', 'all', '_elgg_walled_garden_remove_public_access', 9999); if (!_elgg_services()->session->isLoggedIn()) { // override the front page elgg_register_page_handler('', '_elgg_walled_garden_index'); if (!$this->isPublicPage()) { if (!elgg_is_xhr()) { _elgg_services()->session->set('last_forward_from', current_page_url()); } register_error(_elgg_services()->translator->translate('loggedinrequired')); forward('', 'walled_garden'); } } } }
/** * @see ajax_action_hook * @access private */ public function ajaxActionHook() { if (elgg_is_xhr()) { ob_start(); } }
/** * Send an updated CSRF token * * @access private */ function _elgg_csrf_token_refresh() { if (!elgg_is_xhr()) { return false; } $ts = time(); $token = generate_action_token($ts); $data = array('__elgg_ts' => $ts, '__elgg_token' => $token, 'logged_in' => elgg_is_logged_in()); header("Content-Type: application/json"); echo json_encode($data); return true; }
<?php elgg_push_context('widgets'); echo elgg_list_entities_from_metadata(array('type' => 'object', 'subtype' => 'notification', 'owner_guid' => (int) elgg_get_logged_in_user_guid(), 'order_by_metadata' => array('name' => 'status', 'direction' => 'DESC'), 'list_class' => 'elgg-list-notifier', 'full_view' => false, 'pagination' => !elgg_is_xhr())); elgg_pop_context();
$search_with_loader = true; } $title = elgg_extract('title', $vars); $content = elgg_extract('body', $vars); $class = elgg_extract('class', $vars); $search_params = (array) elgg_extract('params', $vars, []); // register menu items search_advanced_register_menu_items($vars); if (is_array($content)) { $content = implode('', $content); } if (empty($content)) { $content = elgg_view('search/no_results'); } else { $menu = elgg_view_menu('search_list', ['sort_by' => 'priority', 'class' => 'float-alt elgg-menu-hz', 'search_params' => $search_params]); if (!empty($menu)) { $menu = '<div class="clearfix">' . $menu . '</div>'; $content = $menu . $content; } } // add search form if (!elgg_is_xhr() || $search_with_loader && $loader) { $form = elgg_view_form('search_advanced/search', ['action' => 'search', 'method' => 'GET', 'disable_security' => true], $search_params); $content = $form . $content; } if (!elgg_is_xhr() || $loader) { $sidebar = elgg_view('search/sidebar', $vars); echo elgg_view_layout('one_sidebar', ['title' => $title, 'content' => $content, 'sidebar' => $sidebar, 'class' => $class]); } else { echo $content; }
/** * Intercepts, logs, and displays uncaught exceptions. * * To use a viewtype other than failsafe, create the views: * <viewtype>/messages/exceptions/admin_exception * <viewtype>/messages/exceptions/exception * See the json viewtype for an example. * * @warning This function should never be called directly. * * @see http://www.php.net/set-exception-handler * * @param Exception $exception The exception being handled * * @return void * @access private */ function _elgg_php_exception_handler($exception) { $timestamp = time(); error_log("Exception #{$timestamp}: {$exception}"); // Wipe any existing output buffer ob_end_clean(); // make sure the error isn't cached header("Cache-Control: no-cache, must-revalidate", true); header('Expires: Fri, 05 Feb 1982 00:00:00 -0500', true); // we don't want the 'pagesetup', 'system' event to fire global $CONFIG; $CONFIG->pagesetupdone = true; try { // allow custom scripts to trigger on exception // $CONFIG->exception_include can be set locally in settings.php // value should be a system path to a file to include if (!empty($CONFIG->exception_include) && is_file($CONFIG->exception_include)) { ob_start(); include $CONFIG->exception_include; $exception_output = ob_get_clean(); // if content is returned from the custom handler we will output // that instead of our default failsafe view if (!empty($exception_output)) { echo $exception_output; exit; } } if (elgg_is_xhr()) { elgg_set_viewtype('json'); $response = new \Symfony\Component\HttpFoundation\JsonResponse(null, 500); } else { elgg_set_viewtype('failsafe'); $response = new \Symfony\Component\HttpFoundation\Response('', 500); } if (elgg_is_admin_logged_in()) { $body = elgg_view("messages/exceptions/admin_exception", array('object' => $exception, 'ts' => $timestamp)); } else { $body = elgg_view("messages/exceptions/exception", array('object' => $exception, 'ts' => $timestamp)); } $response->setContent(elgg_view_page(elgg_echo('exception:title'), $body)); $response->send(); } catch (Exception $e) { $timestamp = time(); $message = $e->getMessage(); echo "Fatal error in exception handler. Check log for Exception #{$timestamp}"; error_log("Exception #{$timestamp} : fatal error in exception handler : {$message}"); } }
/** * The file_tools page handler * * @param array $page page elements * * @return bool */ function file_tools_page_handler($page) { $include_file = false; switch ($page[0]) { case "list": if (elgg_is_xhr() && !empty($page[1])) { elgg_set_page_owner_guid($page[1]); if (get_input("folder_guid", false) !== false) { set_input("draw_page", false); } if (isset($page[2])) { set_input("folder_guid", $page[2]); } $include_file = dirname(dirname(__FILE__)) . "/pages/list.php"; } break; case "folder": if ($page[1] == "new") { if (!empty($page[2])) { elgg_set_page_owner_guid($page[2]); } $include_file = dirname(dirname(__FILE__)) . "/pages/folder/new.php"; } elseif ($page[1] == "edit") { if (!empty($page[2])) { set_input("folder_guid", $page[2]); $include_file = dirname(dirname(__FILE__)) . "/pages/folder/edit.php"; } } break; case "file": if ($page[1] == "new") { if (!empty($page[2])) { elgg_set_page_owner_guid($page[2]); } $include_file = dirname(dirname(__FILE__)) . "/pages/file/new.php"; } elseif ($page[1] == "download") { $include_file = dirname(dirname(__FILE__)) . "/pages/file/download.php"; } break; case "proc": if (file_exists(dirname(dirname(__FILE__)) . "/procedures/" . $page[1] . "/" . $page[2] . ".php")) { $include_file = dirname(dirname(__FILE__)) . "/procedures/" . $page[1] . "/" . $page[2] . ".php"; } else { echo json_encode(array("valid" => 0)); exit; } break; case "sort": set_input('groupGuid', $_POST['group_guid']); set_input('sort', $_POST['sort']); set_input('sortDir', $_POST['sort_direction']); $include_file = dirname(dirname(__FILE__)) . "/pages/file/sortFolders.php"; break; } if (!empty($include_file)) { include $include_file; return true; } else { forward("file/all"); } }
<?php $guid = elgg_extract('guid', $vars); if (!is_numeric($guid)) { $user = get_user_by_username($guid); if ($user) { $guid = $user->guid; } } elgg_entity_gatekeeper($guid); $target = get_entity($guid); elgg_set_page_owner_guid($guid); $content = elgg_view('discussion/listing/owner', ['entity' => $target]); if (elgg_is_xhr()) { echo $content; return; } if ($target instanceof ElggGroup) { // Before Elgg 2.0 only groups could work as containers for discussions. // Back then the URL that listed all discussions within a group was // "discussion/owner/<guid>". Now that any entity can be used as a // container, we use the standard "<content type>/group/<guid>" URL // also with discussions. forward("discussion/group/{$guid}", '301'); } elgg_push_breadcrumb(elgg_echo('item:object:discussion')); elgg_register_title_button(); $title = elgg_echo('item:object:discussion'); $site_wide_discussions = elgg_get_plugin_setting('site_wide_discussions', 'hypeDiscussions'); $filter = $site_wide_discussions ? null : ''; $params = array('content' => $content, 'title' => $title, 'sidebar' => elgg_view('discussion/sidebar'), 'filter' => $filter, 'filter_context' => $target->guid == elgg_get_logged_in_user_guid() ? 'mine' : false);
fseek($f, $cursor--, SEEK_END); $char = fgetc($f); } /** * Read until the start of file or first newline char */ while ($char !== false && $char !== "\n" && $char !== "\r") { /** * Prepend the new char */ $line = $char . $line; fseek($f, $cursor--, SEEK_END); $char = fgetc($f); } } if (elgg_is_xhr() && !elgg_extract('full_view', $vars, false)) { // all we need to supply is the line echo $line; return; } $download_link = elgg_view('output/url', array('text' => elgg_echo('csv_process:log:download'), 'href' => 'action/csv_process/log_download?time=' . $vars['time'], 'is_action' => true)); echo '<div id="csv-process-results"></div>'; echo elgg_view('output/longtext', array('value' => elgg_echo('csv_process:log:download:blurb', array($download_link)), 'class' => 'elgg-subtext')); ?> <script> require(['csv_process/ajax/progress'], function (Progress) { var p = new Progress(<?php echo json_encode($time); ?> ); p.addLine(<?php