Example #1
0
 /**
  * Listen to the delete of a membership request
  *
  * @param stirng            $event        the name of the event
  * @param stirng            $type         the type of the event
  * @param \ElggRelationship $relationship the relationship
  *
  * @return void
  */
 public static function deleteRequest($event, $type, $relationship)
 {
     if (!$relationship instanceof \ElggRelationship) {
         return;
     }
     if ($relationship->relationship !== 'membership_request') {
         // not a membership request
         return;
     }
     $action_pattern = '/action\\/groups\\/killrequest/i';
     if (!preg_match($action_pattern, current_page_url())) {
         // not in the action, so do nothing
         return;
     }
     $group = get_entity($relationship->guid_two);
     $user = get_user($relationship->guid_one);
     if (empty($user) || !$group instanceof \ElggGroup) {
         return;
     }
     if ($user->getGUID() === elgg_get_logged_in_user_guid()) {
         // user kills own request
         return;
     }
     $reason = get_input('reason');
     if (empty($reason)) {
         $body = elgg_echo('group_tools:notify:membership:declined:message', array($user->name, $group->name, $group->getURL()));
     } else {
         $body = elgg_echo('group_tools:notify:membership:declined:message:reason', array($user->name, $group->name, $reason, $group->getURL()));
     }
     $subject = elgg_echo('group_tools:notify:membership:declined:subject', array($group->name));
     $params = array('object' => $group, 'action' => 'delete');
     notify_user($user->getGUID(), $group->getGUID(), $subject, $body, $params);
 }
Example #2
0
function spam_login_filter_verify_action_hook($hook, $entity_type, $returnvalue, $params)
{
    //Check against stopforumspam and domain blacklist
    $email = get_input('email');
    $ip = spam_login_filter_get_ip();
    if (spam_login_filter_check_spammer($email, $ip)) {
        return true;
    } else {
        //Check if the ip exists
        $options = array("type" => "object", "subtype" => "spam_login_filter_ip", "metadata_name_value_pairs" => array("name" => "ip_address", "value" => $ip), "count" => TRUE);
        $ia = elgg_set_ignore_access(true);
        $spam_login_filter_ip_list = elgg_get_entities_from_metadata($options);
        if ($spam_login_filter_ip_list == 0) {
            //Create the banned ip
            $ip_obj = new ElggObject();
            $ip_obj->subtype = 'spam_login_filter_ip';
            $ip_obj->access_id = ACCESS_PRIVATE;
            $ip_obj->ip_address = $ip;
            $ip_obj->owner_guid = elgg_get_site_entity()->guid;
            $ip_obj->container_guid = elgg_get_site_entity()->guid;
            $ip_obj->save();
        }
        elgg_set_ignore_access($ia);
        //return false;
        forward();
    }
}
Example #3
0
File: start.php Project: rasul/Elgg
/**
 * Serves pages for upload and embed.
 *
 * @param $page
 */
function embed_page_handler($page)
{
    if (!isset($page[0])) {
        $page[0] = 'embed';
    }
    switch ($page[0]) {
        case 'upload':
            echo elgg_view('embed/upload');
            break;
        case 'embed':
        default:
            // trigger hook to get section tabs
            // use views for embed/section/
            //	listing
            //	item
            // default to embed/listing | item if not found.
            // @todo trigger for all right now. If we categorize these later we can trigger
            // for certain categories.
            $sections = elgg_trigger_plugin_hook('embed_get_sections', 'all', NULL, array());
            $upload_sections = elgg_trigger_plugin_hook('embed_get_upload_sections', 'all', NULL, array());
            elgg_sort_3d_array_by_value($sections, 'name');
            elgg_sort_3d_array_by_value($upload_sections, 'name');
            $active_section = get_input('active_section', NULL);
            $internal_name = get_input('internal_name', NULL);
            echo elgg_view('embed/embed', array('sections' => $sections, 'active_section' => $active_section, 'upload_sections' => $upload_sections, 'internal_name' => $internal_name));
            break;
    }
    // exit because this is in a modal display.
    exit;
}
Example #4
0
/**
 * Get security token, forward to action.
 *
 * @param unknown_type $page
 * @return unknown_type
 */
function uservalidationbyemail_page_handler($page)
{
    global $CONFIG;
    if (isset($page[0]) && $page[0] == 'confirm') {
        $code = sanitise_string(get_input('c', FALSE));
        $user_guid = get_input('u', FALSE);
        // new users are not enabled by default.
        $access_status = access_get_show_hidden_status();
        access_show_hidden_entities(true);
        $user = get_entity($user_guid);
        if ($code && $user) {
            if (uservalidationbyemail_validate_email($user_guid, $code)) {
                system_message(elgg_echo('email:confirm:success'));
                $user = get_entity($user_guid);
                $user->enable();
                notify_user($user_guid, $CONFIG->site->guid, sprintf(elgg_echo('email:validate:success:subject'), $user->username), sprintf(elgg_echo('email:validate:success:body'), $user->name), NULL, 'email');
            } else {
                register_error(elgg_echo('email:confirm:fail'));
            }
        } else {
            register_error(elgg_echo('email:confirm:fail'));
        }
        access_show_hidden_entities($access_status);
    } else {
        register_error(elgg_echo('email:confirm:fail'));
    }
    forward();
}
Example #5
0
File: Router.php Project: n8b/VMN
 /**
  * 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));
             $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;
 }
Example #6
0
File: start.php Project: n8b/VMN
/**
 * Init function for Menu Builder
 *
 * @return void
 */
function menu_builder_init()
{
    elgg_extend_view("navigation/menu/site", "menu_builder/site_menu_extend");
    elgg_extend_view("css/elgg", "menu_builder/css/site");
    // register pagehandler for nice URL's
    elgg_register_page_handler("menu_builder", "menu_builder_page_handler");
    // switch mode
    if (elgg_is_admin_logged_in()) {
        elgg_register_plugin_hook_handler("access:collections:write", "user", "menu_builder_write_access_hook");
        if (get_input("menu_builder_edit_mode") == "on") {
            $_SESSION["menu_builder_edit_mode"] = true;
        } elseif (get_input("menu_builder_edit_mode") == "off") {
            unset($_SESSION["menu_builder_edit_mode"]);
            unset($_SESSION["menu_builder_logged_out"]);
        }
        if (get_input("menu_builder_logged_out") == "on") {
            $_SESSION["menu_builder_logged_out"] = true;
        } elseif (get_input("menu_builder_logged_out") == "off") {
            unset($_SESSION["menu_builder_logged_out"]);
        }
    } else {
        unset($_SESSION["menu_builder_edit_mode"]);
        unset($_SESSION["menu_builder_logged_out"]);
    }
    // register url handler for menu_builder objects
    elgg_register_entity_url_handler("object", MENU_BUILDER_SUBTYPE, "menu_builder_menu_item_url_handler");
    // take control of menu setup
    elgg_unregister_plugin_hook_handler('prepare', 'menu:site', 'elgg_site_menu_setup');
    elgg_register_plugin_hook_handler('prepare', 'menu:site', 'menu_builder_site_menu_prepare');
    elgg_register_plugin_hook_handler('register', 'menu:site', 'menu_builder_site_menu_register');
}
 /**
  * Save the wire_tools preferences for the user
  *
  * @param string $hook         the name of the hook
  * @param stirng $type         the type of the hook
  * @param array  $return_value the current return value
  * @param array  $params       supplied values
  *
  * @return void
  */
 public static function saveUserNotificationsSettings($hook, $type, $return_value, $params)
 {
     $NOTIFICATION_HANDLERS = _elgg_services()->notifications->getMethods();
     if (empty($NOTIFICATION_HANDLERS) || !is_array($NOTIFICATION_HANDLERS)) {
         return;
     }
     $user_guid = (int) get_input('guid');
     if (empty($user_guid)) {
         return;
     }
     $user = get_user($user_guid);
     if (empty($user) || !$user->canEdit()) {
         return;
     }
     $methods = [];
     foreach ($NOTIFICATION_HANDLERS as $method) {
         $setting = get_input("thewire_tools_{$method}");
         if (!empty($setting)) {
             $methods[] = $method;
         }
     }
     if (!empty($methods)) {
         elgg_set_plugin_user_setting('notification_settings', implode(',', $methods), $user->getGUID(), 'thewire_tools');
     } else {
         elgg_unset_plugin_user_setting('notification_settings', $user->getGUID(), 'thewire_tools');
     }
     // set flag for correct fallback behaviour
     elgg_set_plugin_user_setting('notification_settings_saved', '1', $user->getGUID(), 'thewire_tools');
 }
Example #8
0
/**
 * Page handler for the avatar_service url
 *
 * @param array $page url parts
 *
 * @return true
 */
function avatar_service_page_handler($page)
{
    $md5_parts = elgg_extract(0, $page);
    $md5 = '';
    // strip optional extension
    if (!empty($md5_parts)) {
        list($md5) = explode('.', $md5_parts);
    }
    $size = (int) get_input('s', get_input('size', 80));
    // size (in pixels) min 1px and max 2048px
    if ($size < 1 || $size > 2048) {
        $size = 80;
    }
    $params = ['size' => $size, 'user' => avatar_service_get_user_by_md5($md5)];
    $image_data = avatar_service_get_image($params);
    $content_length = strlen($image_data);
    // If is the same ETag, content didn't changed.
    $etag = md5($image_data);
    if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == "\"{$etag}\"") {
        header("HTTP/1.1 304 Not Modified");
        return true;
    }
    header('Content-type: image/jpeg');
    header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', strtotime('+6 months')), true);
    header('Pragma: public');
    header('Cache-Control: public');
    header("Content-Length: {$content_length}");
    header("ETag: \"{$etag}\"");
    echo $image_data;
    return true;
}
Example #9
0
/**
 * Init proposals plugin.
 */
function proposals_init()
{
    if (!elgg_is_active_plugin('crud')) {
        return;
    }
    // register proposals library
    elgg_register_library('elgg:proposals', elgg_get_plugins_path() . 'proposals/lib/proposals.php');
    // add to the main css
    elgg_extend_view('css/elgg', 'proposals/css');
    // Add group option
    add_group_tool_option('proposals', elgg_echo('proposals:enableproposals'), false);
    elgg_extend_view('groups/tool_latest', 'proposals/group_module');
    //
    $action_path = elgg_get_plugins_path() . 'proposals/actions/proposals';
    elgg_register_action("proposals/vote", "{$action_path}/vote.php");
    elgg_register_plugin_hook_handler('permissions_check:annotate', 'object', 'proposals_user_can_vote');
    // data types
    $variables = array('title' => 'text', 'description' => 'longtext', 'access_id' => 'access');
    $crud = crud_register_type('decision', $variables);
    $crud->children_type = 'proposal';
    // the following is to not overwrite module if assemblies set it
    // before, since we don't need explicit module.
    if ($crud->module == 'decision') {
        $crud->module = 'proposals';
    }
    //$crud->module = 'proposals';
    $crud->owner_menu = 'group';
    $variables = array('title' => 'text', 'description' => 'longtext', 'tags' => 'tags', 'access_id' => 'access', 'improves_guid' => array('type' => 'url', 'input_view' => 'hidden', 'output_view' => 'proposal', 'default_value' => get_input('improves')));
    $crud = crud_register_type('proposal', $variables);
    #$crud->children_type = 'agenda_point';
    $crud->module = 'proposals';
}
Example #10
0
File: events.php Project: n8b/VMN
/**
 * Performs action when a widget is created
 *
 * @param string $event       name of the system event
 * @param string $object_type type of the event
 * @param mixed  $object      object related to the event
 *
 * @return void
 */
function widget_manager_create_object_handler($event, $object_type, $object)
{
    if (elgg_instanceof($object, "object", "widget", "ElggWidget")) {
        $owner = $object->getOwnerEntity();
        // Updates access for privately created widgets in a group or on site
        if ((int) $object->access_id === ACCESS_PRIVATE) {
            $old_ia = elgg_set_ignore_access();
            if ($owner instanceof ElggGroup) {
                $object->access_id = $owner->group_acl;
                $object->save();
            } elseif ($owner instanceof ElggSite) {
                $object->access_id = ACCESS_PUBLIC;
                $object->save();
            }
            elgg_set_ignore_access($old_ia);
        }
        // Adds a relation between a widget and a multidashboard object
        $dashboard_guid = get_input("multi_dashboard_guid");
        if ($dashboard_guid && widget_manager_multi_dashboard_enabled()) {
            $dashboard = get_entity($dashboard_guid);
            if (elgg_instanceof($dashboard, "object", MultiDashboard::SUBTYPE, "MultiDashboard")) {
                add_entity_relationship($object->getGUID(), MultiDashboard::WIDGET_RELATIONSHIP, $dashboard->getGUID());
            }
        }
    }
}
Example #11
0
 /**
  * Handle /file_tools URLs
  *
  * @param array $page URL segments
  *
  * @return bool
  */
 public static function fileTools($page)
 {
     switch (elgg_extract(0, $page)) {
         case 'list':
             elgg_ajax_gatekeeper();
             $params = [];
             elgg_set_page_owner_guid(elgg_extract(1, $page));
             $folder_guid = get_input('folder_guid', false);
             if ($folder_guid !== false) {
                 $params['folder_guid'] = (int) $folder_guid;
                 $params['draw_page'] = false;
             }
             if (isset($page[2])) {
                 $params['folder_guid'] = (int) $page[2];
             }
             echo elgg_view_resource('file_tools/file/list', $params);
             return true;
             break;
         case 'folder':
             switch (elgg_extract(1, $page)) {
                 case 'new':
                     elgg_set_page_owner_guid(elgg_extract(2, $page));
                     echo elgg_view_resource('file_tools/folder/new');
                     return true;
                     break;
                 case 'edit':
                     $params = ['folder_guid' => (int) elgg_extract(2, $page)];
                     echo elgg_view_resource('file_tools/folder/edit', $params);
                     return true;
                     break;
             }
             break;
     }
     return false;
 }
function readMultipleValues($fieldID, $mainFieldName = "", $dependantFields = array())
{
    if ($mainFieldName == "") {
        $mainFieldName = $fieldID;
    }
    $nrOfFields = get_input($mainFieldName . "_nr");
    $values = array();
    $values[$fieldID] = array();
    for ($j = 0; $j < count($dependantFields); $j++) {
        $values[$dependantFields[$j]] = array();
    }
    for ($i = 0; $i <= $nrOfFields; $i++) {
        $val = get_input($fieldID . '_' . $i);
        if ($val != "") {
            $values[$fieldID][] = $val;
            for ($j = 0; $j < count($dependantFields); $j++) {
                $values[$dependantFields[$j]][] = get_input($dependantFields[$j] . '_' . $i);
            }
        }
    }
    //reverse the array
    array_reverse($values, true);
    if (count($dependantFields) == 0) {
        return join(",", $values[$fieldID]);
    } else {
        return $values;
    }
}
Example #13
0
function view_adm_permission($entities, $vars = array(), $offset = 0, $limit = 10, $full_view = true, $listTypeToggle = true, $pagination = true)
{
    if (!is_int($offset)) {
        $offset = (int) get_input('offset', 0);
    }
    // list type can be passed as request parameter
    $listType = get_input('list_type', 'list');
    if (get_input('listtype')) {
        elgg_deprecated_notice("'listtype' has been deprecated by 'list_type' for lists", 1.8);
        $listType = get_input('listtype');
    }
    if (is_array($vars)) {
        // new function
        $defaults = array('items' => $entities, 'list_class' => 'elgg-list-entity', 'full_view' => true, 'pagination' => true, 'list_type' => $list_type, 'list_type_toggle' => false, 'offset' => $offset, 'limit' => null);
        $vars = array_merge($defaults, $vars);
    } else {
        // old function parameters
        elgg_deprecated_notice("Please update your use of elgg_view_entity_list()", 1.8);
        $vars = array('items' => $entities, 'count' => (int) $vars, 'offset' => $offset, 'limit' => (int) $limit, 'full_view' => $full_view, 'pagination' => $pagination, 'list_type' => $list_type, 'list_type_toggle' => $listTypeToggle, 'list_class' => 'elgg-list-entity');
    }
    if (!$vars["limit"] && !$vars["offset"]) {
        // no need for pagination if listing is unlimited
        $vars["pagination"] = false;
    }
    if ($vars['view_path_list']) {
        return elgg_view($vars['view_path_list'], $vars);
    }
    if ($vars['list_type'] != 'list') {
        return elgg_view('page/components/gallery', $vars);
    } else {
        return elgg_view('page/components/list', $vars);
    }
}
Example #14
0
 protected function validate($name, $rule)
 {
     $input = get_input($name);
     switch ($rule) {
         case "required":
             if ($input == "" || is_null($input)) {
                 $this->setMessage($name, "{$name} field is required");
                 return false;
             }
             return true;
             break;
         case "email":
             if (!filter_var($input, FILTER_VALIDATE_EMAIL)) {
                 $this->setMessage($name, "{$name} field is not a valid email");
                 return false;
             }
             return true;
             break;
         case "numeric":
             if (!filter_var($input, FILTER_VALIDATE_INT | FILTER_VALIDATE_FLOAT)) {
                 $this->setMessage($name, "{$name} field is not numeric");
                 return false;
             }
             return true;
             break;
     }
 }
Example #15
0
 /**
  * Adds menu items to the user hover menu
  *
  * @param string $hook        hook name
  * @param string $entity_type hook type
  * @param array  $returnvalue current return value
  * @param array  $params      parameters
  *
  * @return array
  */
 public static function registerUserHover($hook, $entity_type, $returnvalue, $params)
 {
     $guid = get_input('guid');
     $user = elgg_extract('entity', $params);
     if (empty($guid) || empty($user)) {
         return;
     }
     $event = get_entity($guid);
     if (!$event instanceof \Event) {
         return;
     }
     if (!$event->canEdit()) {
         return;
     }
     $result = $returnvalue;
     // kick from event (assumes users listed on the view page of an event)
     $href = 'action/event_manager/event/rsvp?guid=' . $event->getGUID() . '&user='******'&type=' . EVENT_MANAGER_RELATION_UNDO;
     $item = \ElggMenuItem::factory(['name' => 'event_manager_kick', 'text' => elgg_echo('event_manager:event:relationship:kick'), 'href' => $href, 'is_action' => true, 'section' => 'action']);
     $result[] = $item;
     $user_relationship = $event->getRelationshipByUser($user->getGUID());
     if ($user_relationship == EVENT_MANAGER_RELATION_ATTENDING_PENDING) {
         // resend confirmation
         $href = 'action/event_manager/event/resend_confirmation?guid=' . $event->getGUID() . '&user='******'name' => 'event_manager_resend_confirmation', 'text' => elgg_echo("event_manager:event:menu:user_hover:resend_confirmation"), 'href' => $href, 'is_action' => true, 'section' => 'action']);
         $result[] = $item;
     }
     if (in_array($user_relationship, [EVENT_MANAGER_RELATION_ATTENDING_PENDING, EVENT_MANAGER_RELATION_ATTENDING_WAITINGLIST])) {
         // move to attendees
         $href = 'action/event_manager/attendees/move_to_attendees?guid=' . $event->getGUID() . '&user='******'name' => 'event_manager_move_to_attendees', 'text' => elgg_echo('event_manager:event:menu:user_hover:move_to_attendees'), 'href' => $href, 'is_action' => true, 'section' => 'action']);
         $result[] = $item;
     }
     return $result;
 }
 /**
  * dropzone/upload action handler
  * @return array
  */
 public function handleUploads()
 {
     $subtype = get_input('subtype');
     if (!$subtype) {
         $subtype = elgg_get_plugin_setting('default_upload_subtype', 'hypeDropzone', 'file');
     }
     $uploads = $this->saveUploadedFiles('dropzone', ['owner_guid' => elgg_get_logged_in_user_guid(), 'container_guid' => get_input('container_guid') ?: ELGG_ENTITIES_ANY_VALUE, 'subtype' => $subtype, 'access_id' => ACCESS_PRIVATE, 'origin' => get_input('origin', 'dropzone')]);
     $output = array();
     foreach ($uploads as $upload) {
         $messages = array();
         $success = true;
         if ($upload->error) {
             $messages[] = $upload->error;
             $success = false;
             ${$guid} = false;
         } else {
             $file = $upload->file;
             $guid = $file->guid;
             $html = elgg_view('input/hidden', array('name' => get_input('input_name', 'guids[]'), 'value' => $file->guid));
         }
         $file_output = array('messages' => $messages, 'success' => $success, 'guid' => $guid, 'html' => $html);
         $output[] = elgg_trigger_plugin_hook('upload:after', 'dropzone', array('upload' => $upload), $file_output);
     }
     return $output;
 }
Example #17
0
/**
 * Listen to the usersettings save hook for some notifications to the user
 *
 * @param string $hook         usersettings:save
 * @param string $type         user
 * @param bool   $return_value not supplied for this hook
 * @param null   $params       not supplied for this hook
 *
 * @return void
 */
function security_tools_usersettings_save_handler($hook, $type, $return_value, $params)
{
    $user_guid = (int) get_input("guid");
    if (empty($user_guid)) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    if (empty($user_guid)) {
        return $return_value;
    }
    $user = get_user($user_guid);
    if (empty($user) || !$user->canEdit()) {
        return $return_value;
    }
    // passwords are different
    if (_elgg_set_user_password() === true) {
        // do we need to notify the user about a password change
        $setting = elgg_get_plugin_setting("mails_password_change", "security_tools");
        if ($setting != "no") {
            $site = elgg_get_site_entity();
            $subject = elgg_echo("security_tools:notify_user:password:subject");
            $message = elgg_echo("security_tools:notify_user:password:message", array($user->name, $site->name, $site->url));
            notify_user($user->getGUID(), $site->getGUID(), $subject, $message, null, "email");
        }
    }
    // email are also different
    $setting = elgg_get_plugin_setting("mails_verify_email_change", "security_tools");
    if ($setting != "no" && $user->getGUID() == elgg_get_logged_in_user_guid()) {
        // verify new email address
        security_tools_prepare_email_change();
    } else {
        // old way, or admin changes your email
        _elgg_set_user_email();
    }
}
Example #18
0
function group_tools_route_groups_handler($hook, $type, $return_value, $params)
{
    /**
     * $return_value contains:
     * $return_value['handler'] => requested handler
     * $return_value['segments'] => url parts ($page)
     */
    $result = $return_value;
    if (!empty($return_value) && is_array($return_value)) {
        $page = $return_value['segments'];
        switch ($page[0]) {
            case "all":
                $filter = get_input("filter");
                if (empty($filter) && ($default_filter = elgg_get_plugin_setting("group_listing", "group_tools"))) {
                    $filter = $default_filter;
                    set_input("filter", $default_filter);
                }
                if (in_array($filter, array("open", "closed", "alpha"))) {
                    // we will handle the output
                    $result = false;
                    include dirname(dirname(__FILE__)) . "/pages/groups/all.php";
                }
                break;
            case "requests":
                $result = false;
                set_input("group_guid", $page[1]);
                include dirname(dirname(__FILE__)) . "/pages/groups/membershipreq.php";
                break;
            case "invite":
                $result = false;
                set_input("group_guid", $page[1]);
                include dirname(dirname(__FILE__)) . "/pages/groups/invite.php";
                break;
            case "mail":
                $result = false;
                set_input("group_guid", $page[1]);
                include dirname(dirname(__FILE__)) . "/pages/mail.php";
                break;
            case "group_invite_autocomplete":
                $result = false;
                include dirname(dirname(__FILE__)) . "/procedures/group_invite_autocomplete.php";
                break;
            case "add":
                if (group_tools_is_group_creation_limited()) {
                    admin_gatekeeper();
                }
                break;
            default:
                // check if we have an old group profile link
                if (isset($page[0]) && is_numeric($page[0])) {
                    if (($group = get_entity($page[0])) && elgg_instanceof($group, "group", null, "ElggGroup")) {
                        register_error(elgg_echo("changebookmark"));
                        forward($group->getURL());
                    }
                }
                break;
        }
    }
    return $result;
}
Example #19
0
/**
 * Listen to the saving of plugin settings, if the plugin is this plugin invalidate simplecache
 *
 * @param string $hook 'action'
 * @param string $type 'plugins/settings/save'
 * @param bool $returnvalue false to stop the action
 * @param null $params null
 *
 * @return void
 */
function target_blank_plugins_settings_save_action_hook($hook, $type, $returnvalue, $params)
{
    $plugin_id = get_input("plugin_id");
    if ($plugin_id === "target_blank") {
        elgg_invalidate_simplecache();
    }
}
Example #20
0
function jssor_entity_menu_setup($hook, $type, $return, $params)
{
    if (elgg_in_context('widgets')) {
        return $return;
    }
    $entity = $params['entity'];
    $handler = elgg_extract('handler', $params, false);
    if ($handler != 'photos') {
        return $return;
    }
    if (elgg_instanceof($entity, 'object', 'image')) {
        $album = $entity->getContainerEntity();
        $url = 'jssor/album?guid=' . $album->getGUID() . '&i=' . $entity->getGUID();
        $params = array('href' => $url, 'text' => elgg_echo('jssor:gallery:view'));
        $text = elgg_view('output/url', $params);
        $options = array('name' => 'gallery_view', 'text' => $text, 'priority' => 40);
        $return[] = ElggMenuItem::factory($options);
    }
    if (elgg_instanceof($entity, 'object', 'album')) {
        $album = $entity;
        $offset = get_input('offset');
        if ($offset) {
            $url = 'jssor/album?guid=' . $album->getGUID() . '&o=' . get_input('offset');
        } else {
            $url = 'jssor/album?guid=' . $album->getGUID();
        }
        $params = array('href' => $url, 'text' => elgg_echo('jssor:gallery:view'));
        $text = elgg_view('output/url', $params);
        $options = array('name' => 'gallery_view', 'text' => $text, 'priority' => 40);
        $return[] = ElggMenuItem::factory($options);
    }
    return $return;
}
Example #21
0
/**
 * Filter profile fields by blacklist
 */
function community_spam_profile_blacklist()
{
    $blacklist = elgg_get_plugin_setting('profile_blacklist', 'community_spam_tools');
    $blacklist = explode(",", $blacklist);
    $blacklist = array_map('trim', $blacklist);
    foreach ($_REQUEST as $key => $value) {
        if (is_string($value)) {
            foreach ($blacklist as $word) {
                if (stripos($value, $word) !== false) {
                    ban_user(elgg_get_logged_in_user_guid(), "used '{$word}' on profile");
                    $user->automated_ban = true;
                    return false;
                }
            }
        }
    }
    // if the email address is a phrase, block
    $profile_fields = elgg_get_config('profile_fields');
    foreach ($profile_fields as $name => $type) {
        if ($type == 'email') {
            $value = get_input($name);
            if ($value && substr_count($value, ' ') > 1) {
                ban_user(elgg_get_logged_in_user_guid(), "Used multiple spaces in email field.");
                $user->automated_ban = true;
                return false;
            }
        }
    }
}
Example #22
0
/**
 * Custom clauses for forum keyword search
 */
function hj_forum_filter_forum_list($hook, $type, $options, $params)
{
    if (!is_array($options['subtypes'])) {
        if (isset($options['subtype'])) {
            $options['subtypes'] = array($options['subtype']);
            unset($options['subtype']);
        } elseif (isset($options['subtypes'])) {
            $options['subtypes'] = array($options['subtypes']);
        } else {
            return $options;
        }
    }
    if (!in_array('hjforum', $options['subtypes']) && !in_array('hjforumtopic', $options['subtypes'])) {
        return $options;
    }
    $query = get_input("__q", false);
    if (!$query || empty($query)) {
        return $options;
    }
    $query = sanitise_string(urldecode($query));
    $dbprefix = elgg_get_config('dbprefix');
    $options['joins'][] = "JOIN {$dbprefix}objects_entity oe_q ON e.guid = oe_q.guid";
    $options['wheres'][] = "MATCH(oe_q.title, oe_q.description) AGAINST ('{$query}')";
    return $options;
}
Example #23
0
/**
 * Listen to the saving of plugin settings, if the plugin is this plugin invalidate simplecache
 * 
 * @param string $hook        'action'
 * @param string $type        'plugins/settings/save'
 * @param bool   $returnvalue false to stop the action
 * @param null   $params      null
 * 
 * @return void
 */
function ckeditor_extended_plugins_settings_save_action_hook($hook, $type, $returnvalue, $params)
{
    $plugin_id = get_input("plugin_id");
    if ($plugin_id === "ckeditor_extended") {
        elgg_invalidate_simplecache();
    }
}
Example #24
0
function search_by_proximity_hook($hook, $type, $return, $params)
{
    $query = $params['query'];
    $coords = elgg_geocode_location($query);
    if (!$coords) {
        return $return;
    }
    $registered_entities = elgg_get_config('registered_entities');
    $options = array('types' => array('object', 'user', 'group'), 'subtypes' => array_merge($registered_entities['object'], $registered_entities['user'], $registered_entities['group']), 'limit' => get_input('limit', 20), 'offset' => get_input('proximity_offset', 0), 'offset_key' => 'proximity_offset', 'count' => true);
    $options = add_order_by_proximity_clauses($options, $coords['lat'], $coords['long']);
    $options = add_distance_constraint_clauses($options, $coords['lat'], $coords['long'], SEARCH_RADIUS);
    $count = elgg_get_entities($options);
    if ($count) {
        $options['count'] = false;
        $entities = elgg_get_entities($options);
    }
    if ($entities) {
        foreach ($entities as $entity) {
            $name = search_get_highlighted_relevant_substrings(isset($entity->name) ? $entity->name : $entity->title, $query);
            $entity->setVolatileData('search_matched_title', $name);
            $location = search_get_highlighted_relevant_substrings($entity->getLocation(), $query);
            $entity->setVolatileData('search_matched_location', $location);
            $distance = get_distance($entity->getLatitude(), $entity->getLongitude(), $coords['lat'], $coords['long']);
            // distance in metres
            $distance = round($distance / 1000, 2);
            // distance in km
            $distance_str = elgg_echo('geo:search:proximity', array($query, $distance));
            $entity->setVolatileData('search_proximity', $distance_str);
        }
    }
    return array('entities' => $entities, 'count' => $count);
}
Example #25
0
/**
 * function to handle the nice urls for Custom Profile Fields
 * 
 * @param $page
 * @return unknown_type
 */
function profile_manager_page_handler($page)
{
    switch ($page[0]) {
        case "forms":
            $form = $page[1];
            if (!empty($form) && elgg_is_admin_logged_in()) {
                set_input("guid", $page[2]);
                include dirname(__FILE__) . "/pages/forms/" . $form . ".php";
                return true;
            }
            break;
        case "validate_username":
            if (elgg_is_logged_in()) {
                $new_username = get_input("username");
                $valid = false;
                if (!empty($new_username)) {
                    $valid = profile_manager_validate_username($new_username);
                }
                $result = array("valid" => $valid);
                echo json_encode($result);
                return true;
            }
            break;
        case "user_summary_control":
            include dirname(__FILE__) . "/pages/user_summary_control/preview.php";
            return true;
    }
}
Example #26
0
function action_submit($h, $t, $r, $p)
{
    $granular_inputs = get_input('granular_access_names');
    if (!is_array($granular_inputs)) {
        return $r;
    }
    foreach ($granular_inputs as $name) {
        $input = get_input('ga_build_' . $name);
        $original = get_input($name);
        if ($original != 'granular') {
            continue;
        }
        if (!$input && is_numeric($original)) {
            // leave it alone
            continue;
        } elseif (!$input && $original == 'granular') {
            set_input($name, ACCESS_PRIVATE);
            continue;
        }
        // lets build a collection
        $access_id = get_access_for_guids($input);
        set_input($name, $access_id);
    }
    set_input('granular_access_names', null);
    return $r;
}
Example #27
0
 /**
  * Sanitizes and validates user input
  * @throws GraphException
  * @return Parameter
  */
 public function prepare()
 {
     $this->value = get_input($this->name, $this->default);
     if ($this->value !== null) {
         if ($this->type == self::TYPE_ENUM) {
             if (!in_array($this->value, $this->enum_values)) {
                 $msg = elgg_echo('Exception:UnsupportedEnumValue', array($this->value, $this->name, implode(', ', $this->enum_values)));
                 throw new GraphException($msg);
             }
         } else {
             // Cast values to specified type
             if (!settype($this->value, $this->type)) {
                 if (isset($this->default)) {
                     $this->value = $this->default;
                 } else {
                     $msg = elgg_echo('Exception:UnrecognisedTypeCast', array($this->type, $this->name));
                     throw new GraphException($msg);
                 }
             }
         }
     }
     // Validate required values
     if ($this->required) {
         if ($this->type == Parameter::TYPE_ARRAY && empty($this->value) || $this->value === '' || $this->value === null) {
             $msg = elgg_echo('Exception:MissingParameterInMethod', array($this->name));
             throw new GraphException($msg);
         }
     }
     if ($this->name == 'limit' && $this->value > Graph::LIMIT_MAX) {
         $this->value = Graph::LIMIT_MAX;
     }
     return $this;
 }
Example #28
0
 function displayList()
 {
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         //Remove Reminder
         if (isset($_POST['action']) && $_POST['action'] == "delete") {
             //delete is pressed
             echo "Question " . $_POST['action2'] . " has been removed from the test.</br>";
             if (isset($this->reminders[$_POST['action2']])) {
                 unset($this->reminders[$_POST['action2']]);
                 $this->reminders = array_values($this->reminders);
                 save();
             }
         } else {
             if (isset($_POST['action5']) && $_POST['action5'] == "add3") {
                 //edit confirmed
                 $this->reminders[$_POST['action6']]->edit(get_input($_POST['recipient']), get_input(get_input($_POST['time'])));
                 save();
             }
         }
     }
     for ($i = 0; $i < count($this->reminders); $i++) {
         $this->reminders[$i]->display($i);
         if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['action3']) && $_POST['action3'] == $i) {
             echo "<form  method='post'>";
             echo "<input type='text' name = 'recipient' value='Recipient Email'>";
             echo "<input type='text' name = 'time' value='Time to Email'>";
             echo "<input type='submit' name = 'submit' value='Confirm Edit'>";
             echo "<input type='hidden' name='action5' value='add3'>";
             echo "<input type='hidden' name='action6' value='" . $_POST['action4'] . "'>";
             echo "</form>";
         }
     }
 }
Example #29
0
function file_tools_object_handler_delete($event, $type, $object)
{
    static $delete_files;
    if (!empty($object) && elgg_instanceof($object, "object", FILE_TOOLS_SUBTYPE)) {
        // find subfolders
        $options = array("type" => "object", "subtype" => FILE_TOOLS_SUBTYPE, "container_guid" => $object->getContainerGUID(), "limit" => false, "metadata_name_value_pairs" => array("name" => "parent_guid", "value" => $object->getGUID()), "wheres" => array("(e.guid <> " . $object->getGUID() . ")"));
        if ($subfolders = elgg_get_entities_from_metadata($options)) {
            // delete subfolders
            foreach ($subfolders as $subfolder) {
                $subfolder->delete();
            }
        }
        // fill the static, to delete files in a folder
        if (!isset($delete_files)) {
            $delete_files = false;
            if (get_input("files") == "yes") {
                $delete_files = true;
            }
        }
        // should we remove files?
        if ($delete_files) {
            // find file in this folder
            $options = array("type" => "object", "subtype" => "file", "container_guid" => $object->getContainerGUID(), "limit" => false, "relationship" => FILE_TOOLS_RELATIONSHIP, "relationship_guid" => $object->getGUID());
            if ($files = elgg_get_entities_from_relationship($options)) {
                // delete files in folder
                foreach ($files as $file) {
                    $file->delete();
                }
            }
        }
    }
}
Example #30
0
/**
 * Wrap list views into a container that can be manipulated
 *
 * @param string $hook   "view"
 * @param string $type   "page/components/list" or "page/components/gallery"
 * @param string $view   View
 * @param array  $params Hook params
 * @return string Wrapped view
 */
function wrap_list_view_hook($hook, $type, $view, $params)
{
    $viewtype = elgg_extract('viewtype', $params, 'default');
    if ($viewtype !== 'default') {
        return;
    }
    $vars = elgg_extract('vars', $params);
    $pagination = elgg_extract('pagination', $vars, false);
    $pagination_type = elgg_extract('pagination_type', $vars, elgg_get_plugin_setting('pagination_type', 'hypeLists'));
    if (!$pagination || !$pagination_type) {
        return $view;
    }
    $no_results = elgg_extract('no_results', $vars, '');
    $no_results_str = $no_results instanceof Closure ? $no_results() : $no_results;
    $list_classes = $type == 'page/components/gallery' ? ['elgg-gallery'] : ['elgg-list'];
    if (isset($vars['list_class'])) {
        $list_classes[] = $vars['list_class'];
    }
    $list_id = isset($vars['list_id']) ? $vars['list_id'] : '';
    if (!$list_id) {
        $list_id = md5(serialize(array(elgg_extract('container_class', $vars), implode(' ', $list_classes), elgg_extract('item_class', $vars), $no_results_str, elgg_extract('pagination', $vars), elgg_extract('base_url', $vars))));
    }
    $container_class = array_filter(array('elgg-list-container', elgg_extract('container_class', $vars)));
    $wrapper_params = array('class' => implode(' ', $container_class), 'data-list-id' => $list_id, 'data-base-url' => elgg_extract('base_url', $vars), 'data-count' => elgg_extract('count', $vars, 0), 'data-pagination' => $pagination_type, 'data-pagination-position' => elgg_extract('position', $vars, $pagination_type === 'infinite' ? 'both' : 'after'), 'data-pagination-num-pages' => (int) elgg_extract('num_pages', $vars, 10), 'data-text-no-results' => $no_results_str, 'data-limit' => elgg_extract('limit', $vars, 10), 'data-offset' => elgg_extract('offset', $vars, 0), 'data-offset-key' => elgg_extract('offset_key', $vars, 'offset'), 'data-lazy-load' => (int) elgg_extract('lazy_load', $vars, 6), 'data-auto-refresh' => elgg_extract('auto_refresh', $vars, false), 'data-reversed' => elgg_extract('reversed', $vars, false), 'data-list-time' => get_input('list_time', time()), 'data-list-classes' => implode(' ', $list_classes));
    foreach ($vars as $key => $val) {
        if (substr($key, 0, 5) === 'data-' && !array_key_exists($key, $wrapper_params)) {
            $wrapper_params[$key] = $val;
        }
    }
    $view .= elgg_view('js/framework/lists/require');
    return elgg_format_element('div', $wrapper_params, $view);
}