Ejemplo n.º 1
0
/**
 * returns the absolute url to the root of PWG
 * @param boolean with_scheme if false - does not add http://toto.com
 */
function get_absolute_root_url($with_scheme = true)
{
    // TODO - add HERE the possibility to call PWG functions from external scripts
    $url = '';
    if ($with_scheme) {
        $is_https = false;
        if (isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) == 'on' or $_SERVER['HTTPS'] == 1)) {
            $is_https = true;
            $url .= 'https://';
        } else {
            $url .= 'http://';
        }
        if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
            $url .= $_SERVER['HTTP_X_FORWARDED_HOST'];
        } else {
            $url .= $_SERVER['HTTP_HOST'];
            if (!$is_https && $_SERVER['SERVER_PORT'] != 80 || $is_https && $_SERVER['SERVER_PORT'] != 443) {
                $url_port = ':' . $_SERVER['SERVER_PORT'];
                if (strrchr($url, ':') != $url_port) {
                    $url .= $url_port;
                }
            }
        }
    }
    $url .= cookie_path();
    return $url;
}
Ejemplo n.º 2
0
if ($step == 1) {
    $template->assign('install', true);
} else {
    $infos[] = l10n('Congratulations, Piwigo installation is completed');
    if (isset($error_copy)) {
        $errors[] = $error_copy;
    } else {
        session_set_save_handler('pwg_session_open', 'pwg_session_close', 'pwg_session_read', 'pwg_session_write', 'pwg_session_destroy', 'pwg_session_gc');
        if (function_exists('ini_set')) {
            ini_set('session.use_cookies', $conf['session_use_cookies']);
            ini_set('session.use_only_cookies', $conf['session_use_only_cookies']);
            ini_set('session.use_trans_sid', intval($conf['session_use_trans_sid']));
            ini_set('session.cookie_httponly', 1);
        }
        session_name($conf['session_name']);
        session_set_cookie_params(0, cookie_path());
        register_shutdown_function('session_write_close');
        $user = build_user(1, true);
        log_user($user['id'], false);
        // email notification
        if (isset($_POST['send_password_by_mail'])) {
            include_once PHPWG_ROOT_PATH . 'include/functions_mail.inc.php';
            $keyargs_content = array(get_l10n_args('Hello %s,', $admin_name), get_l10n_args('Welcome to your new installation of Piwigo!', ''), get_l10n_args('', ''), get_l10n_args('Here are your connection settings', ''), get_l10n_args('', ''), get_l10n_args('Link: %s', get_absolute_root_url()), get_l10n_args('Username: %s', $admin_name), get_l10n_args('Password: %s', $admin_pass1), get_l10n_args('Email: %s', $admin_mail), get_l10n_args('', ''), get_l10n_args('Don\'t hesitate to consult our forums for any help: %s', PHPWG_URL));
            pwg_mail($admin_mail, array('subject' => l10n('Just another Piwigo gallery'), 'content' => l10n_args($keyargs_content), 'content_format' => 'text/plain'));
        }
    }
}
if (count($errors) != 0) {
    $template->assign('errors', $errors);
}
if (count($infos) != 0) {
Ejemplo n.º 3
0
/**
 * Performs all the cleanup on user logout.
 */
function logout_user()
{
    global $conf;
    trigger_notify('user_logout', @$_SESSION['pwg_uid']);
    $_SESSION = array();
    session_unset();
    session_destroy();
    setcookie(session_name(), '', 0, ini_get('session.cookie_path'), ini_get('session.cookie_domain'));
    setcookie($conf['remember_me_name'], '', 0, cookie_path(), ini_get('session.cookie_domain'));
}
Ejemplo n.º 4
0
function default_picture_content($content, $element_info)
{
    global $conf;
    if (!empty($content)) {
        // someone hooked us - so we skip;
        return $content;
    }
    if (isset($_COOKIE['picture_deriv'])) {
        if (array_key_exists($_COOKIE['picture_deriv'], ImageStdParams::get_defined_type_map())) {
            pwg_set_session_var('picture_deriv', $_COOKIE['picture_deriv']);
        }
        setcookie('picture_deriv', false, 0, cookie_path());
    }
    $deriv_type = pwg_get_session_var('picture_deriv', $conf['derivative_default_size']);
    $selected_derivative = $element_info['derivatives'][$deriv_type];
    $unique_derivatives = array();
    $show_original = isset($element_info['element_url']);
    $added = array();
    foreach ($element_info['derivatives'] as $type => $derivative) {
        if ($type == IMG_SQUARE || $type == IMG_THUMB) {
            continue;
        }
        if (!array_key_exists($type, ImageStdParams::get_defined_type_map())) {
            continue;
        }
        $url = $derivative->get_url();
        if (isset($added[$url])) {
            continue;
        }
        $added[$url] = 1;
        $show_original &= !$derivative->same_as_source();
        $unique_derivatives[$type] = $derivative;
    }
    global $page, $template;
    if ($show_original) {
        $template->assign('U_ORIGINAL', $element_info['element_url']);
    }
    $template->append('current', array('selected_derivative' => $selected_derivative, 'unique_derivatives' => $unique_derivatives), true);
    $template->set_filenames(array('default_content' => 'picture_content.tpl'));
    $template->assign(array('ALT_IMG' => $element_info['file'], 'COOKIE_PATH' => cookie_path()));
    return $template->parse('default_content', true);
}
Ejemplo n.º 5
0
/**
 * Persistently stores a variable in pwg cookie.
 * Set $value to null to delete the cookie.
 *
 * @param string $car
 * @param mixed $value
 * @param int|null $expire
 * @return bool
 */
function pwg_set_cookie_var($var, $value, $expire = null)
{
    if ($value == null or $expire === 0) {
        unset($_COOKIE['pwg_' . $var]);
        return setcookie('pwg_' . $var, false, 0, cookie_path());
    } else {
        $_COOKIE['pwg_' . $var] = $value;
        $expire = is_numeric($expire) ? $expire : strtotime('+10 years');
        return setcookie('pwg_' . $var, $value, $expire, cookie_path());
    }
}
Ejemplo n.º 6
0
function modus_picture_content($content, $element_info)
{
    global $conf, $picture, $template;
    if (!empty($content)) {
        // someone hooked us - so we skip;
        return $content;
    }
    $unique_derivatives = array();
    $show_original = isset($element_info['element_url']);
    $added = array();
    foreach ($element_info['derivatives'] as $type => $derivative) {
        if ($type == IMG_SQUARE || $type == IMG_THUMB) {
            continue;
        }
        if (!array_key_exists($type, ImageStdParams::get_defined_type_map())) {
            continue;
        }
        $url = $derivative->get_url();
        if (isset($added[$url])) {
            continue;
        }
        $added[$url] = 1;
        $show_original &= !$derivative->same_as_source();
        $unique_derivatives[$type] = $derivative;
    }
    if (isset($_COOKIE['picture_deriv'])) {
        // ignore persistence
        setcookie('picture_deriv', false, 0, cookie_path());
    }
    $selected_derivative = null;
    if (isset($_COOKIE['phavsz'])) {
        $available_size = explode('x', $_COOKIE['phavsz']);
    } elseif (($caps = pwg_get_session_var('caps')) && $caps[0] > 1) {
        $available_size = array($caps[0] * $caps[1], $caps[0] * ($caps[2] - 100), $caps[0]);
    }
    if (isset($available_size)) {
        foreach ($unique_derivatives as $derivative) {
            $size = $derivative->get_size();
            if (!$size) {
                break;
            }
            if ($size[0] <= $available_size[0] and $size[1] <= $available_size[1]) {
                $selected_derivative = $derivative;
            } else {
                if ($available_size[2] > 1 || !$selected_derivative) {
                    $selected_derivative = $derivative;
                }
                break;
            }
        }
        if ($available_size[2] > 1 && $selected_derivative) {
            $ratio_w = $size[0] / $available_size[0];
            $ratio_h = $size[1] / $available_size[1];
            if ($ratio_w > 1 || $ratio_h > 1) {
                if ($ratio_w > $ratio_h) {
                    $display_size = array($available_size[0] / $available_size[2], floor($size[1] / $ratio_w / $available_size[2]));
                } else {
                    $display_size = array(floor($size[0] / $ratio_h / $available_size[2]), $available_size[1] / $available_size[2]);
                }
            } else {
                $display_size = array(round($size[0] / $available_size[2]), round($size[1] / $available_size[2]));
            }
            $template->assign(array('rvas_display_size' => $display_size, 'rvas_natural_size' => $size));
        }
        if (isset($picture['next']) and $picture['next']['src_image']->is_original()) {
            $next_best = null;
            foreach ($picture['next']['derivatives'] as $derivative) {
                $size = $derivative->get_size();
                if (!$size) {
                    break;
                }
                if ($size[0] <= $available_size[0] and $size[1] <= $available_size[1]) {
                    $next_best = $derivative;
                } else {
                    if ($available_size[2] > 1 || !$next_best) {
                        $next_best = $derivative;
                    }
                    break;
                }
            }
            if (isset($next_best)) {
                $template->assign('U_PREFETCH', $next_best->get_url());
            }
        }
    }
    $as_pending = false;
    if (!$selected_derivative) {
        $as_pending = true;
        $selected_derivative = $element_info['derivatives'][pwg_get_session_var('picture_deriv', $conf['derivative_default_size'])];
    }
    if ($show_original) {
        $template->assign('U_ORIGINAL', $element_info['element_url']);
    }
    $template->append('current', array('selected_derivative' => $selected_derivative, 'unique_derivatives' => $unique_derivatives), true);
    $template->set_filenames(array('default_content' => 'picture_content_asize.tpl'));
    $template->assign(array('ALT_IMG' => $element_info['file'], 'COOKIE_PATH' => cookie_path(), 'RVAS_PENDING' => $as_pending));
    return $template->parse('default_content', true);
}