function oauth_assign_template_vars($u_redirect = null)
{
    global $template, $conf, $hybridauth_conf, $user;
    $conf['oauth']['include_common_template'] = true;
    if ($template->get_template_vars('OAUTH') == null) {
        if (!empty($user['oauth_id'])) {
            list($provider, $identifier) = explode('---', $user['oauth_id'], 2);
            if ($provider == 'Persona') {
                $persona_email = $identifier;
            }
        }
        $template->assign('OAUTH', array('conf' => $conf['oauth'], 'u_login' => get_root_url() . OAUTH_PATH . 'auth.php?provider=', 'providers' => $hybridauth_conf['providers'], 'persona_email' => @$persona_email, 'key' => get_ephemeral_key(0)));
        $template->assign(array('OAUTH_PATH' => OAUTH_PATH, 'OAUTH_ABS_PATH' => realpath(OAUTH_PATH) . '/', 'ABS_ROOT_URL' => rtrim(get_gallery_home_url(), '/') . '/'));
    }
    if (isset($u_redirect)) {
        $template->append('OAUTH', compact('u_redirect'), true);
    }
}
Esempio n. 2
0
        }
    }
    register_user($_POST['login'], $_POST['password'], $_POST['mail_address'], true, $page['errors'], isset($_POST['send_password_by_mail']));
    if (count($page['errors']) == 0) {
        // email notification
        if (isset($_POST['send_password_by_mail']) and email_check_format($_POST['mail_address'])) {
            $_SESSION['page_infos'][] = l10n('Successfully registered, you will soon receive an email with your connection settings. Welcome!');
        }
        // log user and redirect
        $user_id = get_userid($_POST['login']);
        log_user($user_id, false);
        redirect(make_index_url());
    }
    $registration_post_key = get_ephemeral_key(2);
} else {
    $registration_post_key = get_ephemeral_key(6);
}
$login = !empty($_POST['login']) ? htmlspecialchars(stripslashes($_POST['login'])) : '';
$email = !empty($_POST['mail_address']) ? htmlspecialchars(stripslashes($_POST['mail_address'])) : '';
//----------------------------------------------------- template initialization
//
// Start output of page
//
$title = l10n('Registration');
$page['body_id'] = 'theRegisterPage';
$template->set_filenames(array('register' => 'register.tpl'));
$template->assign(array('U_HOME' => make_index_url(), 'F_KEY' => $registration_post_key, 'F_ACTION' => 'register.php', 'F_LOGIN' => $login, 'F_EMAIL' => $email, 'obligatory_user_mail_address' => $conf['obligatory_user_mail_address']));
// include menubar
$themeconf = $template->get_template_vars('themeconf');
if (!isset($themeconf['hide_menu_on']) or !in_array('theRegisterPage', $themeconf['hide_menu_on'])) {
    include PHPWG_ROOT_PATH . 'include/menubar.inc.php';
        if (is_admin()) {
            if ($row['validated'] != 'true') {
                $tpl_comment['U_VALIDATE'] = add_url_params($url_self, array('action' => 'validate_comment', 'comment_to_validate' => $row['id'], 'pwg_token' => get_pwg_token()));
            }
        }
        $template->append('comments', $tpl_comment);
    }
}
$show_add_comment_form = !is_a_guest() || $conf['guestbook']['guest_can_add'];
if (isset($edit_comment)) {
    $show_add_comment_form = false;
}
if ($show_add_comment_form) {
    foreach (array('content', 'author', 'website', 'email') as $el) {
        ${$el} = '';
        if ('reject' === @$comment_action and !empty($comm[$el])) {
            ${$el} = htmlspecialchars(stripslashes($comm[$el]));
        }
    }
    if (is_classic_user()) {
        $author = $user['username'];
        $email = $user['email'];
    }
    if (empty($conf['comments_email_mandatory'])) {
        $conf['comments_email_mandatory'] = false;
    }
    $template->assign('comment_add', array('F_ACTION' => $url_self, 'KEY' => get_ephemeral_key(3), 'CONTENT' => $content, 'IS_LOGGED' => is_classic_user(), 'AUTHOR' => $author, 'WEBSITE' => $website, 'EMAIL' => $email, 'ACTIVATE_RATING' => $conf['guestbook']['activate_rating'], 'EMAIL_MANDATORY' => $conf['comments_email_mandatory']));
}
$template->assign(array('GUESTBOOK_PATH' => GUESTBOOK_PATH, 'ABS_GUESTBOOK_PATH' => realpath(GUESTBOOK_PATH) . '/'));
$template->set_filename('guestbook', realpath(GUESTBOOK_PATH . 'template/guestbook.tpl'));
$template->assign_var_from_handle('CONTENT', 'guestbook');
Esempio n. 4
0
                    $tpl_comment['PWG_TOKEN'] = get_pwg_token();
                    $tpl_comment['U_CANCEL'] = $url_self;
                }
            }
            if (is_admin()) {
                $tpl_comment['EMAIL'] = $email;
                if ($row['validated'] != 'true') {
                    $tpl_comment['U_VALIDATE'] = add_url_params($url_self, array('action' => 'validate_comment', 'comment_to_validate' => $row['id'], 'pwg_token' => get_pwg_token()));
                }
            }
            $template->append('comments', $tpl_comment);
        }
    }
    $show_add_comment_form = true;
    if (isset($edit_comment)) {
        $show_add_comment_form = false;
    }
    if (is_a_guest() and !$conf['comments_forall']) {
        $show_add_comment_form = false;
    }
    if ($show_add_comment_form) {
        $key = get_ephemeral_key(3, $page['image_id']);
        $tpl_var = array('F_ACTION' => $url_self, 'KEY' => $key, 'CONTENT' => '', 'SHOW_AUTHOR' => !is_classic_user(), 'AUTHOR_MANDATORY' => $conf['comments_author_mandatory'], 'AUTHOR' => '', 'WEBSITE_URL' => '', 'SHOW_EMAIL' => !is_classic_user() or empty($user['email']), 'EMAIL_MANDATORY' => $conf['comments_email_mandatory'], 'EMAIL' => '', 'SHOW_WEBSITE' => $conf['comments_enable_website']);
        if ('reject' == @$comment_action) {
            foreach (array('content', 'author', 'website_url', 'email') as $k) {
                $tpl_var[strtoupper($k)] = htmlspecialchars(stripslashes(@$_POST[$k]));
            }
        }
        $template->assign('comment_add', $tpl_var);
    }
}
Esempio n. 5
0
            if (!empty($comment['email'])) {
                $email = $comment['email'];
            }
        }
        $tpl_comment = array('ID' => $comment['comment_id'], 'U_PICTURE' => $url, 'src_image' => $src_image, 'ALT' => $name, 'AUTHOR' => trigger_change('render_comment_author', $comment['author']), 'WEBSITE_URL' => $comment['website_url'], 'DATE' => format_date($comment['date'], array('day_name', 'day', 'month', 'year', 'time')), 'CONTENT' => trigger_change('render_comment_content', $comment['content']));
        if (is_admin()) {
            $tpl_comment['EMAIL'] = $email;
        }
        if (can_manage_comment('delete', $comment['author_id'])) {
            $tpl_comment['U_DELETE'] = add_url_params($url_self, array('delete' => $comment['comment_id'], 'pwg_token' => get_pwg_token()));
        }
        if (can_manage_comment('edit', $comment['author_id'])) {
            $tpl_comment['U_EDIT'] = add_url_params($url_self, array('edit' => $comment['comment_id']));
            if (isset($edit_comment) and $comment['comment_id'] == $edit_comment) {
                $tpl_comment['IN_EDIT'] = true;
                $key = get_ephemeral_key(2, $comment['image_id']);
                $tpl_comment['KEY'] = $key;
                $tpl_comment['IMAGE_ID'] = $comment['image_id'];
                $tpl_comment['CONTENT'] = $comment['content'];
                $tpl_comment['PWG_TOKEN'] = get_pwg_token();
                $tpl_comment['U_CANCEL'] = $url_self;
            }
        }
        if (can_manage_comment('validate', $comment['author_id'])) {
            if ('true' != $comment['validated']) {
                $tpl_comment['U_VALIDATE'] = add_url_params($url_self, array('validate' => $comment['comment_id'], 'pwg_token' => get_pwg_token()));
            }
        }
        $template->append('comments', $tpl_comment);
    }
}
Esempio n. 6
0
/**
 * API method
 * Returns detailed information for an element
 * @param mixed[] $params
 *    @option int image_id
 *    @option int comments_page
 *    @option int comments_per_page
 */
function ws_images_getInfo($params, $service)
{
    global $user, $conf;
    $query = '
SELECT *
  FROM ' . IMAGES_TABLE . '
  WHERE id=' . $params['image_id'] . get_sql_condition_FandF(array('visible_images' => 'id'), ' AND') . '
LIMIT 1
;';
    $result = pwg_query($query);
    if (pwg_db_num_rows($result) == 0) {
        return new PwgError(404, 'image_id not found');
    }
    $image_row = pwg_db_fetch_assoc($result);
    $image_row = array_merge($image_row, ws_std_get_urls($image_row));
    //-------------------------------------------------------- related categories
    $query = '
SELECT id, name, permalink, uppercats, global_rank, commentable
  FROM ' . IMAGE_CATEGORY_TABLE . '
    INNER JOIN ' . CATEGORIES_TABLE . ' ON category_id = id
  WHERE image_id = ' . $image_row['id'] . get_sql_condition_FandF(array('forbidden_categories' => 'category_id'), ' AND') . '
;';
    $result = pwg_query($query);
    $is_commentable = false;
    $related_categories = array();
    while ($row = pwg_db_fetch_assoc($result)) {
        if ($row['commentable'] == 'true') {
            $is_commentable = true;
        }
        unset($row['commentable']);
        $row['url'] = make_index_url(array('category' => $row));
        $row['page_url'] = make_picture_url(array('image_id' => $image_row['id'], 'image_file' => $image_row['file'], 'category' => $row));
        $row['id'] = (int) $row['id'];
        $related_categories[] = $row;
    }
    usort($related_categories, 'global_rank_compare');
    if (empty($related_categories)) {
        return new PwgError(401, 'Access denied');
    }
    //-------------------------------------------------------------- related tags
    $related_tags = get_common_tags(array($image_row['id']), -1);
    foreach ($related_tags as $i => $tag) {
        $tag['url'] = make_index_url(array('tags' => array($tag)));
        $tag['page_url'] = make_picture_url(array('image_id' => $image_row['id'], 'image_file' => $image_row['file'], 'tags' => array($tag)));
        unset($tag['counter']);
        $tag['id'] = (int) $tag['id'];
        $related_tags[$i] = $tag;
    }
    //------------------------------------------------------------- related rates
    $rating = array('score' => $image_row['rating_score'], 'count' => 0, 'average' => null);
    if (isset($rating['score'])) {
        $query = '
SELECT COUNT(rate) AS count, ROUND(AVG(rate),2) AS average
  FROM ' . RATE_TABLE . '
  WHERE element_id = ' . $image_row['id'] . '
;';
        $row = pwg_db_fetch_assoc(pwg_query($query));
        $rating['score'] = (double) $rating['score'];
        $rating['average'] = (double) $row['average'];
        $rating['count'] = (int) $row['count'];
    }
    //---------------------------------------------------------- related comments
    $related_comments = array();
    $where_comments = 'image_id = ' . $image_row['id'];
    if (!is_admin()) {
        $where_comments .= ' AND validated="true"';
    }
    $query = '
SELECT COUNT(id) AS nb_comments
  FROM ' . COMMENTS_TABLE . '
  WHERE ' . $where_comments . '
;';
    list($nb_comments) = query2array($query, null, 'nb_comments');
    $nb_comments = (int) $nb_comments;
    if ($nb_comments > 0 and $params['comments_per_page'] > 0) {
        $query = '
SELECT id, date, author, content
  FROM ' . COMMENTS_TABLE . '
  WHERE ' . $where_comments . '
  ORDER BY date
  LIMIT ' . (int) $params['comments_per_page'] . '
  OFFSET ' . (int) ($params['comments_per_page'] * $params['comments_page']) . '
;';
        $result = pwg_query($query);
        while ($row = pwg_db_fetch_assoc($result)) {
            $row['id'] = (int) $row['id'];
            $related_comments[] = $row;
        }
    }
    $comment_post_data = null;
    if ($is_commentable and (!is_a_guest() or is_a_guest() and $conf['comments_forall'])) {
        $comment_post_data['author'] = stripslashes($user['username']);
        $comment_post_data['key'] = get_ephemeral_key(2, $params['image_id']);
    }
    $ret = $image_row;
    foreach (array('id', 'width', 'height', 'hit', 'filesize') as $k) {
        if (isset($ret[$k])) {
            $ret[$k] = (int) $ret[$k];
        }
    }
    foreach (array('path', 'storage_category_id') as $k) {
        unset($ret[$k]);
    }
    $ret['rates'] = array(WS_XML_ATTRIBUTES => $rating);
    $ret['categories'] = new PwgNamedArray($related_categories, 'category', array('id', 'url', 'page_url'));
    $ret['tags'] = new PwgNamedArray($related_tags, 'tag', ws_std_get_tag_xml_attributes());
    if (isset($comment_post_data)) {
        $ret['comment_post'] = array(WS_XML_ATTRIBUTES => $comment_post_data);
    }
    $ret['comments_paging'] = new PwgNamedStruct(array('page' => $params['comments_page'], 'per_page' => $params['comments_per_page'], 'count' => count($related_comments), 'total_count' => $nb_comments));
    $ret['comments'] = new PwgNamedArray($related_comments, 'comment', array('id', 'date'));
    if ($service->_responseFormat != 'rest') {
        return $ret;
        // for backward compatibility only
    } else {
        return array('image' => new PwgNamedStruct($ret, null, array('name', 'comment')));
    }
}