function __construct()
 {
     $count = getInput("count");
     $email = getInput("email");
     $password = getInput("password");
     $x = 0;
     while ($x < $count) {
         $first_name = $this->names[mt_rand(0, sizeof($this->names) - 1)];
         $last_name = $this->surnames[mt_rand(0, sizeof($this->surnames) - 1)];
         $user = new User();
         $user->password = md5($password);
         $user->random = true;
         $user->verified = "true";
         $user->profile_type = "default";
         $user->access_id = "system";
         $user->first_name = $first_name;
         $user->last_name = $last_name;
         $user->email = "tester" . $x . "@" . $email;
         $user->full_name = $first_name . " " . $last_name;
         $user->save();
         $x++;
     }
     new SystemMessage("Random users have been generated");
     forward();
 }
 function __construct()
 {
     adminGateKeeper();
     $ip = pageArray(2);
     if ($ip) {
         new BlacklistIp($ip);
         $params = array("type" => "User", "metadata_name_value_pairs" => array(array("name" => "ip1", "value" => $ip), array("name" => "ip2", "value" => $ip)), "metadata_name_value_pairs_operand" => "OR");
         $users = getEntities($params);
         $tables = Dbase::getAllTables(false);
         foreach ($users as $user) {
             new BlacklistEmail($user->email);
             $guid = $user->guid;
             foreach ($tables as $table) {
                 $entities = getEntities(array("type" => $table, "metadata_name_value_pairs" => array(array("name" => "owner_guid", "value" => $guid), array("name" => "container_guid", "value" => $guid)), "metadata_name_value_pairs_operand" => "OR"));
                 if ($entities) {
                     foreach ($entities as $entity) {
                         $entity->delete();
                     }
                 }
             }
             $user->delete();
         }
         new SystemMessage("Ip {$ip} has been banned, and all users using it have been deleted.");
         forward("home");
     }
 }
Example #3
0
File: cron.php Project: elgg/elgg
/**
 * Cron handler
 *
 * @param array $page Pages
 *
 * @return bool
 * @throws CronException
 * @access private
 */
function _elgg_cron_page_handler($page)
{
    if (!isset($page[0])) {
        forward();
    }
    if (PHP_SAPI !== 'cli' && elgg_get_config('security_protect_cron')) {
        elgg_signed_request_gatekeeper();
    }
    $period = strtolower($page[0]);
    $allowed_periods = elgg_get_config('elgg_cron_periods');
    if ($period != 'run' && !in_array($period, $allowed_periods)) {
        throw new \CronException("{$period} is not a recognized cron period.");
    }
    if ($period == 'run') {
        _elgg_cron_run();
    } else {
        // Get a list of parameters
        $params = array();
        $params['time'] = time();
        // Data to return to
        $old_stdout = "";
        ob_start();
        $msg_key = "cron_latest:{$period}:msg";
        $msg = elgg_echo('admin:cron:started', [$period, date('r', time())]);
        elgg_get_site_entity()->setPrivateSetting($msg_key, $msg);
        $old_stdout = elgg_trigger_plugin_hook('cron', $period, $params, $old_stdout);
        $std_out = ob_get_clean();
        $msg = $std_out . $old_stdout;
        echo $msg;
        elgg_get_site_entity()->setPrivateSetting($msg_key, $msg);
    }
    return true;
}
Example #4
0
/**
 * Route page requests
 *
 * @param array $page Array of url parameters
 * @return bool
 */
function notifications_page_handler($page)
{
    gatekeeper();
    $current_user = elgg_get_logged_in_user_entity();
    // default to personal notifications
    if (!isset($page[0])) {
        $page[0] = 'personal';
    }
    if (!isset($page[1])) {
        forward("notifications/{$page[0]}/{$current_user->username}");
    }
    $user = get_user_by_username($page[1]);
    if ($user->guid != $current_user->guid && !$current_user->isAdmin()) {
        forward();
    }
    $base = elgg_get_plugins_path() . 'notifications';
    // note: $user passed in
    switch ($page[0]) {
        case 'group':
            require "{$base}/groups.php";
            break;
        case 'personal':
            require "{$base}/index.php";
            break;
        default:
            return false;
    }
    return true;
}
Example #5
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 #6
0
/**
 * Serves pages for twitter.
 *
 * @param array $page
 */
function twitter_api_pagehandler($page)
{
    if (!isset($page[0])) {
        forward();
    }
    switch ($page[0]) {
        case 'authorize':
            twitter_api_authorize();
            break;
        case 'revoke':
            twitter_api_revoke();
            break;
        case 'forward':
            twitter_api_forward();
            break;
        case 'login':
            twitter_api_login();
            break;
        case 'interstitial':
            gatekeeper();
            // only let twitter users do this.
            $guid = elgg_get_logged_in_user_guid();
            $twitter_name = elgg_get_plugin_user_setting('twitter_name', $guid, 'twitter_api');
            if (!$twitter_name) {
                register_error(elgg_echo('twitter_api:invalid_page'));
                forward();
            }
            $pages = dirname(__FILE__) . '/pages/twitter_api';
            include "{$pages}/interstitial.php";
            break;
        default:
            forward();
            break;
    }
}
 public function __construct()
 {
     Setting::set("allow_video_uploads", getInput("allow_video_uploads"));
     Setting::set("ffmpeg_ffmprobe_executable_path", getInput("ffmpeg_ffmprobe_executable_path"));
     new SystemMessage("Your settings have been updated.");
     forward();
 }
Example #8
0
/**
 * Route page requests
 *
 * @param array $page Array of url parameters
 * @return bool
 */
function notifications_page_handler($page)
{
    elgg_gatekeeper();
    $current_user = elgg_get_logged_in_user_entity();
    // default to personal notifications
    if (!isset($page[0])) {
        $page[0] = 'personal';
    }
    if (!isset($page[1])) {
        forward("notifications/{$page[0]}/{$current_user->username}");
    }
    set_input('username', $page[1]);
    // note: $user passed in
    switch ($page[0]) {
        case 'group':
            echo elgg_view_resource('notifications/groups');
            break;
        case 'personal':
            echo elgg_view_resource('notifications/index');
            break;
        default:
            return false;
    }
    return true;
}
Example #9
0
/**
 * 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;
}
 public function __construct()
 {
     if (!pageArray(2) || !pageArray(3)) {
         return false;
     }
     $email = pageArray(2);
     $code = pageArray(3);
     runHook("action:verify_email:before");
     $access = getIgnoreAccess();
     setIgnoreAccess();
     $user = getEntities(array("type" => "User", "metadata_name_value_pairs" => array(array("name" => "email", "value" => $email), array("name" => "email_verification_code", "value" => $code))));
     setIgnoreAccess($access);
     if (!$user) {
         new SystemMessage(translate("system_message:email_could_not_be_verified"));
         forward("home");
     }
     $user = $user[0];
     $user->email_verification_code = NULL;
     $user->verified = "true";
     $user->save();
     runHook("action:verify_email:after");
     new SystemMessage(translate("system_message:email_verified"));
     new Activity($user->guid, "activity:joined", array($user->getURL(), $user->full_name));
     forward("login");
 }
/**
 * Profile page handler
 *
 * @param array $page Array of URL segments passed by the page handling mechanism
 * @return bool
 */
function profile_page_handler($page)
{
    if (isset($page[0])) {
        $username = $page[0];
        $user = get_user_by_username($username);
        elgg_set_page_owner_guid($user->guid);
    } elseif (elgg_is_logged_in()) {
        forward(elgg_get_logged_in_user_entity()->getURL());
    }
    // short circuit if invalid or banned username
    if (!$user || $user->isBanned() && !elgg_is_admin_logged_in()) {
        register_error(elgg_echo('profile:notfound'));
        forward();
    }
    $action = NULL;
    if (isset($page[1])) {
        $action = $page[1];
    }
    if ($action == 'edit') {
        // use the core profile edit page
        $base_dir = elgg_get_root_path();
        require "{$base_dir}pages/profile/edit.php";
        return true;
    }
    $content = elgg_view('profile/layout', array('entity' => $user));
    $body = elgg_view_layout('one_column', array('content' => $content));
    echo elgg_view_page($user->name, $body);
    return true;
}
Example #12
0
function elgg_modifications_pagesetup()
{
    $user = elgg_get_logged_in_user_entity();
    if (!$user) {
        return;
    }
    if (elgg_in_context("accept_terms")) {
        return;
    }
    $site = elgg_get_site_entity();
    if ($site->isPublicPage()) {
        return;
    }
    if (!empty($_SESSION["terms_accepted"])) {
        return;
    }
    if (elgg_get_plugin_setting("accept_terms", "elgg_modifications") === "no") {
        return;
    }
    $user_ts = $user->getPrivateSetting("general_terms_accepted");
    if (empty($user_ts)) {
        $_SESSION["terms_forward_from"] = current_page_url();
        forward("accept_terms");
    } else {
        // user has accepted the terms, so don't check again
        $_SESSION["terms_accepted"] = $user_ts;
    }
}
/**
 * Cron handler for redirecting pages.
 *
 * @param unknown_type $page
 */
function cron_page_handler($page)
{
    global $CONFIG;
    if ($page[0]) {
        switch (strtolower($page[0])) {
            case 'minute':
            case 'fiveminute':
            case 'fifteenmin':
            case 'halfhour':
            case 'hourly':
            case 'daily':
            case 'weekly':
            case 'monthly':
            case 'yearly':
            case 'reboot':
                set_input('period', $page[0]);
                break;
            default:
                throw new CronException(sprintf(elgg_echo('CronException:unknownperiod'), $page[0]));
        }
        // Include cron handler
        include $CONFIG->path . "engine/handlers/cron_handler.php";
    } else {
        forward();
    }
}
Example #14
0
/**
 * Page handler for generic comments manipulation.
 *
 * @param array $page
 * @return bool
 * @access private
 */
function _elgg_comments_page_handler($page)
{
    switch ($page[0]) {
        case 'edit':
            elgg_gatekeeper();
            if (empty($page[1])) {
                register_error(elgg_echo('generic_comment:notfound'));
                forward(REFERER);
            }
            $comment = get_entity($page[1]);
            if (!$comment instanceof \ElggComment || !$comment->canEdit()) {
                register_error(elgg_echo('generic_comment:notfound'));
                forward(REFERER);
            }
            $target = $comment->getContainerEntity();
            if (!$target instanceof \ElggEntity) {
                register_error(elgg_echo('generic_comment:notfound'));
                forward(REFERER);
            }
            $title = elgg_echo('generic_comments:edit');
            elgg_push_breadcrumb($target->getDisplayName(), $target->getURL());
            elgg_push_breadcrumb($title);
            $params = array('entity' => $target, 'comment' => $comment, 'is_edit_page' => true);
            $content = elgg_view_form('comment/save', null, $params);
            $params = array('content' => $content, 'title' => $title, 'filter' => '');
            $body = elgg_view_layout('content', $params);
            echo elgg_view_page($title, $body);
            return true;
            break;
        default:
            return false;
            break;
    }
}
 public function __construct()
 {
     $guid = pageArray(2);
     adminGateKeeper();
     $plugin = getEntity($guid);
     Setting::updateSettingsTable();
     clearCache();
     Cache::clear();
     Cache::clear();
     if ($plugin->enable()) {
         new SystemMessage("Plugin Enabled");
         new Cache("enabled_plugins_", false, "site");
         new Cache("enabled_plugins_reversed", false, "site");
         Systemvariable::set("setup_complete", false);
         forward("admin/plugins");
     }
     Setting::updateSettingsTable();
     clearCache();
     Cache::clear();
     Cache::clear();
     Admintab::deleteAll();
     $translations = getEntities(array("type" => "Translationentity"));
     if ($translations) {
         foreach ($translations as $translation) {
             $translation->delete();
         }
     }
     new SystemMessage("Your plugin can't be enabled.  Check requirements");
     forward("admin/plugins");
 }
Example #16
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 #17
0
/**
 * The birthday page handler
 *
 * @param array $page the url segments
 *
 * @return bool
 */
function birthdays_page_handler($page)
{
    switch ($page[0]) {
        case "upcoming":
            include dirname(dirname(__FILE__)) . "/pages/upcoming.php";
            break;
        case "day":
            if (isset($page[1])) {
                set_input("limit_month", $page[1]);
            }
            if (isset($page[2])) {
                set_input("limit_day", $page[2]);
            }
            include dirname(dirname(__FILE__)) . "/pages/day.php";
            break;
        case "friends":
            include dirname(dirname(__FILE__)) . "/pages/friends.php";
            break;
        case "group":
            include dirname(dirname(__FILE__)) . "/pages/group.php";
            break;
        default:
            forward("birthdays/upcoming");
            break;
    }
    return true;
}
Example #18
0
/**
 * Cron handler
 *
 * @param array $page Pages
 *
 * @return bool
 * @throws CronException
 * @access private
 */
function _elgg_cron_page_handler($page)
{
    if (!isset($page[0])) {
        forward();
    }
    $period = strtolower($page[0]);
    $allowed_periods = elgg_get_config('elgg_cron_periods');
    if ($period != 'run' && !in_array($period, $allowed_periods)) {
        throw new \CronException("{$period} is not a recognized cron period.");
    }
    if ($period == 'run') {
        _elgg_cron_run();
    } else {
        // Get a list of parameters
        $params = array();
        $params['time'] = time();
        // Data to return to
        $old_stdout = "";
        ob_start();
        $old_stdout = elgg_trigger_plugin_hook('cron', $period, $params, $old_stdout);
        $std_out = ob_get_clean();
        echo $std_out . $old_stdout;
    }
    return true;
}
Example #19
0
 static function draw()
 {
     $page = self::urlArray(0);
     if ($page != "setupcomplete" && $page != "action" && file_exists(getSitePath() . "install/")) {
         forward("setupcomplete");
     }
     $body = $header = $nav = $footer = NULL;
     if ($page) {
         $page_handler_class = "SocialApparatus\\" . ucfirst($page) . "PageHandler";
     } else {
         $page_handler_class = "SocialApparatus\\HomePageHandler";
     }
     Vars::clear();
     if (class_exists($page_handler_class)) {
         $body = (new $page_handler_class())->view();
     } else {
         new SystemMessage("Page not found.");
         forward("home");
     }
     Vars::clear();
     $header = display("page_elements/header");
     Vars::clear();
     $nav = display("page_elements/navigation");
     Vars::clear();
     $footer = display("page_elements/footer");
     Vars::clear();
     echo $header;
     echo $nav;
     echo $body;
     echo $footer;
     Debug::clear();
     Dbase::con()->close();
     die;
 }
Example #20
0
/**
 * Serves pages for twitter.
 *
 * @param array $page
 * @return bool
 */
function twitter_api_pagehandler($page)
{
    if (!isset($page[0])) {
        return false;
    }
    switch ($page[0]) {
        case 'authorize':
            twitter_api_authorize();
            break;
        case 'revoke':
            twitter_api_revoke();
            break;
        case 'forward':
            twitter_api_forward();
            break;
        case 'login':
            twitter_api_login();
            break;
        case 'interstitial':
            elgg_gatekeeper();
            // only let twitter users do this.
            $guid = elgg_get_logged_in_user_guid();
            $twitter_name = elgg_get_plugin_user_setting('twitter_name', $guid, 'twitter_api');
            if (!$twitter_name) {
                register_error(elgg_echo('twitter_api:invalid_page'));
                forward();
            }
            echo elgg_view('resources/twitter_api/interstitial');
            break;
        default:
            return false;
    }
    return true;
}
Example #21
0
/**
 * User settings page handler
 *
 * @param array $segments URL segments
 * @return bool
 */
function user_settings_page_handler($segments)
{
    elgg_gatekeeper();
    $page = array_shift($segments);
    $username = array_shift($segments);
    if (!$page) {
        $page = 'user';
    }
    if (!$username) {
        $user = elgg_get_logged_in_user_entity();
    } else {
        $user = get_user_by_username($username);
    }
    if (!$user) {
        forward('', '404');
    }
    if (!$user->canEdit()) {
        forward('', '403');
    }
    elgg_set_page_owner_guid($user->guid);
    $resource = elgg_view_resource("settings/{$page}", array('username' => $user->username, 'entity' => $user, 'segments' => $segments));
    if ($resource) {
        echo $resource;
        return true;
    }
    return false;
}
Example #22
0
/**
 * Cron handler
 *
 * @param array $page Pages
 *
 * @return void
 */
function cron_page_handler($page)
{
    global $CONFIG;
    if (!isset($page[0])) {
        forward();
    }
    $period = strtolower($page[0]);
    $allowed_periods = array('minute', 'fiveminute', 'fifteenmin', 'halfhour', 'hourly', 'daily', 'weekly', 'monthly', 'yearly', 'reboot');
    if (!in_array($period, $allowed_periods)) {
        throw new CronException(elgg_echo('CronException:unknownperiod', array($period)));
    }
    // Get a list of parameters
    $params = array();
    $params['time'] = time();
    foreach ($CONFIG->input as $k => $v) {
        $params[$k] = $v;
    }
    // Data to return to
    $std_out = "";
    $old_stdout = "";
    ob_start();
    $old_stdout = elgg_trigger_plugin_hook('cron', $period, $params, $old_stdout);
    $std_out = ob_get_clean();
    echo $std_out . $old_stdout;
}
Example #23
0
File: start.php Project: elgg/elgg
/**
 * Profile page handler
 *
 * @param array $page Array of URL segments passed by the page handling mechanism
 * @return bool
 */
function profile_page_handler($page)
{
    if (isset($page[0])) {
        $username = $page[0];
        $user = get_user_by_username($username);
        elgg_set_page_owner_guid($user->guid);
    } elseif (elgg_is_logged_in()) {
        forward(elgg_get_logged_in_user_entity()->getURL());
    }
    // short circuit if invalid or banned username
    if (!$user || $user->isBanned() && !elgg_is_admin_logged_in()) {
        register_error(elgg_echo('profile:notfound'));
        forward();
    }
    $action = NULL;
    if (isset($page[1])) {
        $action = $page[1];
    }
    if ($action == 'edit') {
        // use the core profile edit page
        echo elgg_view_resource('profile/edit');
        return true;
    }
    echo elgg_view_resource('profile/view', ['username' => $page[0]]);
    return true;
}
Example #24
0
/**
 * List friends' chats that user is member of.
 *
 * @param int $user_guid GUID of the user
 * @return array
 */
function chat_friends($user_guid)
{
    $user = get_user($user_guid);
    if (!$user) {
        forward('chat/all');
    }
    $params = array();
    $params['filter_context'] = 'friends';
    $params['title'] = elgg_echo('chat:title:friends');
    $crumbs_title = $user->name;
    elgg_push_breadcrumb($crumbs_title, "chat/owner/{$user->username}");
    elgg_push_breadcrumb(elgg_echo('friends'));
    elgg_register_title_button();
    $options = array('type' => 'object', 'subtype' => 'chat', 'relationship' => 'member', 'relationship_guid' => $user_guid, 'inverse_relationship' => false, 'limit' => 10, 'pagination' => true, 'full_view' => false);
    if ($friends = get_user_friends($user_guid, ELGG_ENTITIES_ANY_VALUE, 0)) {
        foreach ($friends as $friend) {
            $options['container_guids'][] = $friend->getGUID();
        }
        $params['content'] = elgg_list_entities_from_relationship($options);
    }
    if (empty($params['content'])) {
        $params['content'] = elgg_echo('chat:none');
    }
    return $params;
}
Example #25
0
File: start.php Project: rasul/Elgg
/**
 * Profile page handler
 *
 * @param array $page Array of page elements, forwarded by the page handling mechanism
 */
function profile_page_handler($page)
{
    if (isset($page[0])) {
        $username = $page[0];
        $user = get_user_by_username($username);
        elgg_set_page_owner_guid($user->guid);
    }
    // short circuit if invalid or banned username
    if (!$user || $user->isBanned() && !elgg_is_admin_logged_in()) {
        register_error(elgg_echo('profile:notfound'));
        forward();
    }
    $action = NULL;
    if (isset($page[1])) {
        $action = $page[1];
    }
    if ($action == 'edit') {
        // use the core profile edit page
        $base_dir = elgg_get_root_path();
        require "{$base_dir}pages/profile/edit.php";
        return;
    }
    // main profile page
    $params = array('content' => elgg_view('profile/wrapper'), 'num_columns' => 3);
    $content = elgg_view_layout('widgets', $params);
    $body = elgg_view_layout('one_column', array('content' => $content));
    echo elgg_view_page($title, $body);
}
Example #26
0
 function logout()
 {
     foreach ($_SESSION as $key => $value) {
         unset($_SESSION[$key]);
     }
     forward('?c=guest');
 }
Example #27
0
function subsite_manager_siteid_hook($hook, $type, $return, $params)
{
    global $SUBSITE_MANAGER_CUSTOM_DOMAIN;
    $result = false;
    elgg_register_classes(dirname(__FILE__) . "/classes/");
    if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "") {
        $protocol = "https";
    } else {
        $protocol = "http";
    }
    if (strpos($_SERVER["HTTP_HOST"], "www.") === 0) {
        $alt_host = str_replace("www.", "", $_SERVER["HTTP_HOST"]);
    } else {
        $alt_host = "www." . $_SERVER["HTTP_HOST"];
    }
    $url = $protocol . "://" . $_SERVER["HTTP_HOST"] . "/";
    $alt_url = $protocol . "://" . $alt_host . "/";
    if ($site = get_site_by_url($url)) {
        $result = $site->getGUID();
    } elseif ($site = get_site_by_url($alt_url)) {
        $result = $site->getGUID();
    } else {
        // no site found, forward to main site
        $default_site_guid = (int) datalist_get("default_site");
        $default_site = get_entity($default_site_guid);
        forward($default_site->url);
    }
    return $result;
}
 public function __construct()
 {
     gateKeeper();
     $guid = getInput("guid");
     $title = getInput("blog_title");
     $description = getInput("description");
     $access_id = getInput("access_id");
     $container_guid = getInput("container_guid");
     $owner_guid = getLoggedInUserGuid();
     if ($guid) {
         $blog = getEntity($guid);
     } else {
         $blog = new Blog();
     }
     $blog->title = $title;
     $blog->description = $description;
     $blog->access_id = $access_id;
     $blog->owner_guid = $owner_guid;
     $blog->status = "published";
     $blog->container_guid = $container_guid;
     $blog->save();
     new Activity(getLoggedInUserGuid(), "blog:add", array(getLoggedInUser()->getURL(), getLoggedInUser()->full_name, $blog->getURL(), $blog->title, truncate($blog->description)), "", $access_id);
     new SystemMessage("Your blog has been published");
     forward("blogs/all_blogs");
 }
Example #29
0
File: hooks.php Project: n8b/VMN
/**
 * hook called on route, all
 * check if $returnvalue['handler'] to see if we need to replace it
 * if the handler is an original handler, we want to foward it to the new url
 * 
 * @param type $hook
 * @param type $type
 * @param type $returnvalue
 * @param type $params
 * @return array
 */
function router($hook, $type, $returnvalue, $params)
{
    if (elgg_get_config('pagehandler_hijack')) {
        return $returnvalue;
    }
    $handlers = get_replacement_handlers();
    if (in_array($returnvalue['handler'], array_keys($handlers))) {
        // we have been given an old handler -> we should forward to the replacement
        // probably from an old link or something
        $currenturl = current_page_url();
        //get everything after the pagehandler
        $afterhandler = str_replace(elgg_get_site_url() . $returnvalue['handler'], "", $currenturl);
        $newurl = elgg_get_site_url() . $handlers[$returnvalue['handler']] . $afterhandler;
        // forward to the new url
        forward($newurl);
    }
    if (in_array($returnvalue['handler'], $handlers)) {
        // we need to do something about it
        // get the original handler
        $original = array_search($returnvalue['handler'], $handlers);
        if (!empty($original)) {
            // reset the context for non-hijack aware code
            elgg_set_context($original);
            // let the system load content for the original handler
            $returnvalue['handler'] = $original;
            $returnvalue['identifier'] = $original;
            // set a flag so we don't infinite loop ourselves in route hooks
            elgg_set_config('pagehandler_hijack', true);
            return elgg_trigger_plugin_hook('route', $original, null, $returnvalue);
        }
    }
}
Example #30
0
/**
 * @param $hook
 * @param $type
 * @param $returnvalue
 * @param $params
 *
 * @return bool
 *
 * function called when the below plugin trigger is initiated
 * @see /engine/lib/actions.php
 * @see elgg_trigger_plugin_hook('action', $action, null, $event_result);
 *
 * this hook is triggered for the action = "register"
 * this hooks is called before the default "register" action handler at /actions/register.php
 * checks if recaptcha is valid - if not register an error
 */
function recaptcha_check_form($hook, $type, $returnvalue, $params)
{
    // retain entered form values and re-populate form fields if validation error
    elgg_make_sticky_form('register');
    /*-- check if the 'Use Recaptcha for user registration' Plugin setting is enabled --*/
    //fetch the plugin settings
    $plugin_entity = elgg_get_plugin_from_id('recaptcha');
    $plugin_settings = $plugin_entity->getAllSettings();
    if (array_key_exists('recaptcha_verified', $_SESSION) && $_SESSION['recaptcha_verified'] == 1) {
        //do nothing
    } else {
        if ($plugin_settings['require_recaptcha'] == 'on') {
            //if the setting is enabled
            // include the recaptcha lib
            require_once 'lib/recaptchalib.php';
            // check the recaptcha
            $resp = recaptcha_check_answer($plugin_settings['recaptcha_private_key'], $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
            if (!$resp->is_valid) {
                register_error(elgg_echo('recaptcha:human_verification_failed'));
                forward(REFERER);
            } else {
                /* note that the user has successfully passed the captcha
                 * in case the form submission fails due to other factors, we do not want to
                 * ask the user to fill in the captcha details again
                 * so we store it in a session variable and destroy it after the form is successfully submitted
                 */
                $_SESSION['recaptcha_verified'] = 1;
            }
        }
    }
    return true;
}