Пример #1
0
 static function on_index_thumbnails_ajax($thumbs)
 {
     global $template;
     $template->assign('thumbnails', $thumbs);
     header('Content-Type: text/html; charset=' . get_pwg_charset());
     $template->pparse('index_thumbnails');
     exit;
 }
function osm_render_category()
{
    global $template, $page, $conf, $filter;
    include_once dirname(__FILE__) . '/include/functions.php';
    include_once dirname(__FILE__) . '/include/functions_map.php';
    osm_load_language();
    load_language('plugin.lang', OSM_PATH);
    // TF, 20160102: pass config as parameter
    $js_data = osm_get_items($conf, $page);
    if ($js_data != array()) {
        $local_conf = array();
        $local_conf['contextmenu'] = 'false';
        $local_conf['control'] = true;
        $local_conf['img_popup'] = false;
        $local_conf['popup'] = 1;
        $local_conf['center_lat'] = 0;
        $local_conf['center_lng'] = 0;
        $local_conf['zoom'] = 2;
        $local_conf['auto_center'] = 1;
        // TF, 20160102: pass config as parameter
        $local_conf['paths'] = osm_get_gps($conf, $page);
        $height = isset($conf['osm_conf']['category_description']['height']) ? $conf['osm_conf']['category_description']['height'] : '200';
        $width = isset($conf['osm_conf']['category_description']['width']) ? $conf['osm_conf']['category_description']['width'] : 'auto';
        $js = osm_get_js($conf, $local_conf, $js_data);
        $template->set_filename('map', dirname(__FILE__) . '/template/osm-category.tpl');
        $template->assign(array('CONTENT_ENCODING' => get_pwg_charset(), 'OSM_PATH' => embellish_url(get_gallery_home_url() . OSM_PATH), 'HOME' => make_index_url(), 'HOME_PREV' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : get_absolute_root_url(), 'HOME_NAME' => l10n("Home"), 'HOME_PREV_NAME' => l10n("Previous"), 'OSMJS' => $js, 'HEIGHT' => $height, 'WIDTH' => $width));
        $osm_content = $template->parse('map', true);
        //$osm_content = '<div id="osmmap"><div class="map_title">'.l10n('EDIT_MAP').'</div>' . $osm_content . '</div>';
        $index = isset($conf['osm_conf']['category_description']['index']) ? $conf['osm_conf']['category_description']['index'] : 0;
        // 0 - PLUGIN_INDEX_CONTENT_BEGIN
        // 1 - PLUGIN_INDEX_CONTENT_COMMENT
        // 2 - PLUGIN_INDEX_CONTENT_END
        if ($index <= 1) {
            // From index category comment at L300
            if ($page['start'] == 0 and !isset($page['chronology_field'])) {
                if (empty($page['comment'])) {
                    $page['comment'] = $osm_content;
                } else {
                    if ($index == 0) {
                        $page['comment'] = '<div>' . $osm_content . $page['comment'] . '</div>';
                    } else {
                        $page['comment'] = '<div>' . $page['comment'] . $osm_content . '</div>';
                    }
                }
            }
        } else {
            $osm_content = '<div id="osmmap">' . $osm_content . '</div>';
            $template->concat('PLUGIN_INDEX_CONTENT_END', "\n" . $osm_content);
        }
    }
}
Пример #3
0
/**
 * API method
 * Returns info about the current user
 * @param mixed[] $params
 */
function ws_session_getStatus($params, &$service)
{
    global $user, $conf;
    $res['username'] = is_a_guest() ? 'guest' : stripslashes($user['username']);
    foreach (array('status', 'theme', 'language') as $k) {
        $res[$k] = $user[$k];
    }
    $res['pwg_token'] = get_pwg_token();
    $res['charset'] = get_pwg_charset();
    list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
    $res['current_datetime'] = $dbnow;
    $res['version'] = PHPWG_VERSION;
    if (is_admin()) {
        $res['upload_file_types'] = implode(',', array_unique(array_map('strtolower', $conf['upload_form_all_types'] ? $conf['file_ext'] : $conf['picture_ext'])));
        $res['upload_form_chunk_size'] = $conf['upload_form_chunk_size'];
    }
    return $res;
}
Пример #4
0
        $theme = $conf['mobile_theme'];
    }
    $template = new Template(PHPWG_ROOT_PATH . 'themes', $theme);
}
if (!isset($conf['no_photo_yet'])) {
    include PHPWG_ROOT_PATH . 'include/no_photo_yet.inc.php';
}
if (isset($user['internal_status']['guest_must_be_guest']) and $user['internal_status']['guest_must_be_guest'] === true) {
    $header_msgs[] = l10n('Bad status for user "guest", using default status. Please notify the webmaster.');
}
if ($conf['gallery_locked']) {
    $header_msgs[] = l10n('The gallery is locked for maintenance. Please, come back later.');
    if (script_basename() != 'identification' and !is_admin()) {
        set_status_header(503, 'Service Unavailable');
        @header('Retry-After: 900');
        header('Content-Type: text/html; charset=' . get_pwg_charset());
        echo '<a href="' . get_absolute_root_url(false) . 'identification.php">' . l10n('The gallery is locked for maintenance. Please, come back later.') . '</a>';
        echo str_repeat(' ', 512);
        //IE6 doesn't error output if below a size
        exit;
    }
}
if ($conf['check_upgrade_feed']) {
    include_once PHPWG_ROOT_PATH . 'admin/include/functions_upgrade.php';
    if (check_upgrade_feed()) {
        $header_msgs[] = 'Some database upgrades are missing, ' . '<a href="' . get_absolute_root_url(false) . 'upgrade_feed.php">upgrade now</a>';
    }
}
if (count($header_msgs) > 0) {
    $template->assign('header_msgs', $header_msgs);
    $header_msgs = array();
Пример #5
0
/**
 * return a cleaned IPTC value.
 *
 * @param string $value
 * @return string
 */
function clean_iptc_value($value)
{
    // strip leading zeros (weird Kodak Scanner software)
    while (isset($value[0]) and $value[0] == chr(0)) {
        $value = substr($value, 1);
    }
    // remove binary nulls
    $value = str_replace(chr(0x0), ' ', $value);
    if (preg_match('/[\\x80-\\xff]/', $value)) {
        // apparently mac uses some MacRoman crap encoding. I don't know
        // how to detect it so a plugin should do the trick.
        $value = trigger_change('clean_iptc_value', $value);
        if (($qual = qualify_utf8($value)) != 0) {
            // has non ascii chars
            if ($qual > 0) {
                $input_encoding = 'utf-8';
            } else {
                $input_encoding = 'iso-8859-1';
                if (function_exists('iconv') or function_exists('mb_convert_encoding')) {
                    // using windows-1252 because it supports additional characters
                    // such as "oe" in a single character (ligature). About the
                    // difference between Windows-1252 and ISO-8859-1: the characters
                    // 0x80-0x9F will not convert correctly. But these are control
                    // characters which are almost never used.
                    $input_encoding = 'windows-1252';
                }
            }
            $value = convert_charset($value, $input_encoding, get_pwg_charset());
        }
    }
    return $value;
}
Пример #6
0
 /**
  * Encodes a response and sends it back to the browser.
  */
 function sendResponse($response)
 {
     $encodedResponse = $this->_responseEncoder->encodeResponse($response);
     $contentType = $this->_responseEncoder->getContentType();
     @header('Content-Type: ' . $contentType . '; charset=' . get_pwg_charset());
     print_r($encodedResponse);
     trigger_notify('sendResponse', $encodedResponse);
 }
Пример #7
0
/**
 * Sends an email, using Piwigo specific informations.
 *
 * @param string|array $to
 * @param array $args
 *       o from: sender [default value webmaster email]
 *       o Cc: array of carbon copy receivers of the mail. [default value empty]
 *       o Bcc: array of blind carbon copy receivers of the mail. [default value empty]
 *       o subject [default value 'Piwigo']
 *       o content: content of mail [default value '']
 *       o content_format: format of mail content [default value 'text/plain']
 *       o email_format: global mail format [default value $conf_mail['default_email_format']]
 *       o theme: theme to use [default value $conf_mail['mail_theme']]
 *       o mail_title: main title of the mail [default value $conf['gallery_title']]
 *       o mail_subtitle: subtitle of the mail [default value subject]
 * @param array $tpl - use these options to define a custom content template file
 *       o filename
 *       o dirname (optional)
 *       o assign (optional)
 *
 * @return boolean
 */
function pwg_mail($to, $args = array(), $tpl = array())
{
    global $conf, $conf_mail, $lang_info, $page;
    if (empty($to) and empty($args['Cc']) and empty($args['Bcc'])) {
        return true;
    }
    if (!isset($conf_mail)) {
        $conf_mail = get_mail_configuration();
    }
    include_once PHPWG_ROOT_PATH . 'include/phpmailer/class.phpmailer.php';
    $mail = new PHPMailer();
    foreach (get_clean_recipients_list($to) as $recipient) {
        $mail->addAddress($recipient['email'], $recipient['name']);
    }
    $mail->WordWrap = 76;
    $mail->CharSet = 'UTF-8';
    // Compute root_path in order have complete path
    set_make_full_url();
    if (empty($args['from'])) {
        $from = array('email' => $conf_mail['email_webmaster'], 'name' => $conf_mail['name_webmaster']);
    } else {
        $from = unformat_email($args['from']);
    }
    $mail->setFrom($from['email'], $from['name']);
    $mail->addReplyTo($from['email'], $from['name']);
    // Subject
    if (empty($args['subject'])) {
        $args['subject'] = 'Piwigo';
    }
    $args['subject'] = trim(preg_replace('#[\\n\\r]+#s', '', $args['subject']));
    $mail->Subject = $args['subject'];
    // Cc
    if (!empty($args['Cc'])) {
        foreach (get_clean_recipients_list($args['Cc']) as $recipient) {
            $mail->addCC($recipient['email'], $recipient['name']);
        }
    }
    // Bcc
    $Bcc = get_clean_recipients_list(@$args['Bcc']);
    if ($conf_mail['send_bcc_mail_webmaster']) {
        $Bcc[] = array('email' => get_webmaster_mail_address(), 'name' => '');
    }
    if (!empty($Bcc)) {
        foreach ($Bcc as $recipient) {
            $mail->addBCC($recipient['email'], $recipient['name']);
        }
    }
    // theme
    if (empty($args['theme']) or !in_array($args['theme'], array('clear', 'dark'))) {
        $args['theme'] = $conf_mail['mail_theme'];
    }
    // content
    if (!isset($args['content'])) {
        $args['content'] = '';
    }
    // try to decompose subject like "[....] ...."
    if (!isset($args['mail_title']) and !isset($args['mail_subtitle'])) {
        if (preg_match('#^\\[(.*)\\](.*)$#', $args['subject'], $matches)) {
            $args['mail_title'] = $matches[1];
            $args['mail_subtitle'] = $matches[2];
        }
    }
    if (!isset($args['mail_title'])) {
        $args['mail_title'] = $conf['gallery_title'];
    }
    if (!isset($args['mail_subtitle'])) {
        $args['mail_subtitle'] = $args['subject'];
    }
    // content type
    if (empty($args['content_format'])) {
        $args['content_format'] = 'text/plain';
    }
    $content_type_list = array();
    if ($conf_mail['mail_allow_html'] and @$args['email_format'] != 'text/plain') {
        $content_type_list[] = 'text/html';
    }
    $content_type_list[] = 'text/plain';
    $contents = array();
    foreach ($content_type_list as $content_type) {
        // key compose of indexes witch allow to cache mail data
        $cache_key = $content_type . '-' . $lang_info['code'];
        if (!isset($conf_mail[$cache_key])) {
            // instanciate a new Template
            if (!isset($conf_mail[$cache_key]['theme'])) {
                $conf_mail[$cache_key]['theme'] = get_mail_template($content_type);
                trigger_notify('before_parse_mail_template', $cache_key, $content_type);
            }
            $template =& $conf_mail[$cache_key]['theme'];
            $template->set_filename('mail_header', 'header.tpl');
            $template->set_filename('mail_footer', 'footer.tpl');
            $template->assign(array('GALLERY_URL' => get_gallery_home_url(), 'GALLERY_TITLE' => isset($page['gallery_title']) ? $page['gallery_title'] : $conf['gallery_title'], 'VERSION' => $conf['show_version'] ? PHPWG_VERSION : '', 'PHPWG_URL' => defined('PHPWG_URL') ? PHPWG_URL : '', 'CONTENT_ENCODING' => get_pwg_charset(), 'CONTACT_MAIL' => $conf_mail['email_webmaster']));
            if ($content_type == 'text/html') {
                if ($template->smarty->templateExists('global-mail-css.tpl')) {
                    $template->set_filename('global-css', 'global-mail-css.tpl');
                    $template->assign_var_from_handle('GLOBAL_MAIL_CSS', 'global-css');
                }
                if ($template->smarty->templateExists('mail-css-' . $args['theme'] . '.tpl')) {
                    $template->set_filename('css', 'mail-css-' . $args['theme'] . '.tpl');
                    $template->assign_var_from_handle('MAIL_CSS', 'css');
                }
            }
        }
        $template =& $conf_mail[$cache_key]['theme'];
        $template->assign(array('MAIL_TITLE' => $args['mail_title'], 'MAIL_SUBTITLE' => $args['mail_subtitle']));
        // Header
        $contents[$content_type] = $template->parse('mail_header', true);
        // Content
        // Stored in a temp variable, if a content template is used it will be assigned
        // to the $CONTENT template variable, otherwise it will be appened to the mail
        if ($args['content_format'] == 'text/plain' and $content_type == 'text/html') {
            // convert plain text to html
            $mail_content = '<p>' . nl2br(preg_replace('/(https?:\\/\\/([-\\w\\.]+[-\\w])+(:\\d+)?(\\/([\\w\\/_\\.\\#-]*(\\?\\S+)?[^\\.\\s])?)?)/i', '<a href="$1">$1</a>', htmlspecialchars($args['content']))) . '</p>';
        } else {
            if ($args['content_format'] == 'text/html' and $content_type == 'text/plain') {
                // convert html text to plain text
                $mail_content = strip_tags($args['content']);
            } else {
                $mail_content = $args['content'];
            }
        }
        // Runtime template
        if (isset($tpl['filename'])) {
            if (isset($tpl['dirname'])) {
                $template->set_template_dir($tpl['dirname'] . '/' . $content_type);
            }
            if ($template->smarty->templateExists($tpl['filename'] . '.tpl')) {
                $template->set_filename($tpl['filename'], $tpl['filename'] . '.tpl');
                if (!empty($tpl['assign'])) {
                    $template->assign($tpl['assign']);
                }
                $template->assign('CONTENT', $mail_content);
                $contents[$content_type] .= $template->parse($tpl['filename'], true);
            } else {
                $contents[$content_type] .= $mail_content;
            }
        } else {
            $contents[$content_type] .= $mail_content;
        }
        // Footer
        $contents[$content_type] .= $template->parse('mail_footer', true);
    }
    // Undo Compute root_path in order have complete path
    unset_make_full_url();
    // Send content to PHPMailer
    if (isset($contents['text/html'])) {
        $mail->isHTML(true);
        $mail->Body = move_css_to_body($contents['text/html']);
        if (isset($contents['text/plain'])) {
            $mail->AltBody = $contents['text/plain'];
        }
    } else {
        $mail->isHTML(false);
        $mail->Body = $contents['text/plain'];
    }
    if ($conf_mail['use_smtp']) {
        // now we need to split port number
        if (strpos($conf_mail['smtp_host'], ':') !== false) {
            list($smtp_host, $smtp_port) = explode(':', $conf_mail['smtp_host']);
        } else {
            $smtp_host = $conf_mail['smtp_host'];
            $smtp_port = 25;
        }
        $mail->IsSMTP();
        // enables SMTP debug information (for testing) 2 - debug, 0 - no message
        $mail->SMTPDebug = 0;
        $mail->Host = $smtp_host;
        $mail->Port = $smtp_port;
        if (!empty($conf_mail['smtp_secure']) and in_array($conf_mail['smtp_secure'], array('ssl', 'tls'))) {
            $mail->SMTPSecure = $conf_mail['smtp_secure'];
        }
        if (!empty($conf_mail['smtp_user'])) {
            $mail->SMTPAuth = true;
            $mail->Username = $conf_mail['smtp_user'];
            $mail->Password = $conf_mail['smtp_password'];
        }
    }
    $ret = true;
    $pre_result = trigger_change('before_send_mail', true, $to, $args, $mail);
    if ($pre_result) {
        $ret = $mail->send();
        if (!$ret and (!ini_get('display_errors') or is_admin())) {
            trigger_error('Mailer Error: ' . $mail->ErrorInfo, E_USER_WARNING);
        }
        if ($conf['debug_mail']) {
            pwg_send_mail_test($ret, $mail, $args);
        }
    }
    return $ret;
}
Пример #8
0
 /**
  *  Get languages defined in the language directory
  */
 function get_fs_languages($target_charset = null)
 {
     if (empty($target_charset)) {
         $target_charset = get_pwg_charset();
     }
     $target_charset = strtolower($target_charset);
     $dir = opendir(PHPWG_ROOT_PATH . 'language');
     while ($file = readdir($dir)) {
         if ($file != '.' and $file != '..') {
             $path = PHPWG_ROOT_PATH . 'language/' . $file;
             if (is_dir($path) and !is_link($path) and preg_match('/^[a-zA-Z0-9-_]+$/', $file) and file_exists($path . '/common.lang.php')) {
                 $language = array('name' => $file, 'code' => $file, 'version' => '0', 'uri' => '', 'author' => '');
                 $plg_data = implode('', file($path . '/common.lang.php'));
                 if (preg_match("|Language Name:\\s*(.+)|", $plg_data, $val)) {
                     $language['name'] = trim($val[1]);
                     $language['name'] = convert_charset($language['name'], 'utf-8', $target_charset);
                 }
                 if (preg_match("|Version:\\s*([\\w.-]+)|", $plg_data, $val)) {
                     $language['version'] = trim($val[1]);
                 }
                 if (preg_match("|Language URI:\\s*(https?:\\/\\/.+)|", $plg_data, $val)) {
                     $language['uri'] = trim($val[1]);
                 }
                 if (preg_match("|Author:\\s*(.+)|", $plg_data, $val)) {
                     $language['author'] = trim($val[1]);
                 }
                 if (preg_match("|Author URI:\\s*(https?:\\/\\/.+)|", $plg_data, $val)) {
                     $language['author uri'] = trim($val[1]);
                 }
                 if (!empty($language['uri']) and strpos($language['uri'], 'extension_view.php?eid=')) {
                     list(, $extension) = explode('extension_view.php?eid=', $language['uri']);
                     if (is_numeric($extension)) {
                         $language['extension'] = $extension;
                     }
                 }
                 // IMPORTANT SECURITY !
                 $language = array_map('htmlspecialchars', $language);
                 $this->fs_languages[$file] = $language;
             }
         }
     }
     closedir($dir);
     @uasort($this->fs_languages, 'name_compare');
 }
Пример #9
0
    function encodeResponse($response)
    {
        $respClass = strtolower(@get_class($response));
        if ($respClass == 'pwgerror') {
            $ret = '<?xml version="1.0"?>
<rsp stat="fail">
	<err code="' . $response->code() . '" msg="' . htmlspecialchars($response->message()) . '" />
</rsp>';
            return $ret;
        }
        $this->_writer = new PwgXmlWriter();
        $this->encode($response);
        $ret = $this->_writer->getOutput();
        $ret = '<?xml version="1.0" encoding="' . get_pwg_charset() . '" ?>
<rsp stat="ok">
' . $ret . '
</rsp>';
        return $ret;
    }
Пример #10
0
function osm_gen_template($conf, $js, $js_data, $tmpl, $template)
{
    $linkname = isset($conf['osm_conf']['left_menu']['link']) ? $conf['osm_conf']['left_menu']['link'] : l10n('OSWorldMap');
    $template->set_filename('map', dirname(__FILE__) . '/../template/' . $tmpl);
    $template->assign(array('CONTENT_ENCODING' => get_pwg_charset(), 'OSM_PATH' => embellish_url(get_gallery_home_url() . OSM_PATH), 'GALLERY_TITLE' => $linkname . ' - ' . $conf['gallery_title'], 'HOME' => make_index_url(), 'HOME_PREV' => isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : get_absolute_root_url(), 'HOME_NAME' => l10n("Home"), 'HOME_PREV_NAME' => l10n("Previous"), 'TOTAL' => sprintf(l10n('ITEMS'), count($js_data)), 'OSMJS' => $js, 'MYROOT_URL' => get_absolute_root_url(), 'default_baselayer' => $conf['osm_conf']['map']['baselayer']));
    if ($conf['osm_conf']['map']['baselayer'] == 'custom') {
        $iconbaselayer = $conf['osm_conf']['map']['custombaselayerurl'];
        $iconbaselayer = str_replace('{s}', 'a', $iconbaselayer);
        $iconbaselayer = str_replace('{z}', '5', $iconbaselayer);
        $iconbaselayer = str_replace('{x}', '15', $iconbaselayer);
        $iconbaselayer = str_replace('{y}', '11', $iconbaselayer);
        $template->assign(array('custombaselayer' => $conf['osm_conf']['map']['custombaselayer'], 'custombaselayerurl' => $conf['osm_conf']['map']['custombaselayerurl'], 'iconbaselayer' => $iconbaselayer));
    }
    $template->pparse('map');
    $template->p();
}
Пример #11
0
        $user = build_user($feed_row['user_id'], true);
    }
} else {
    $image_only = true;
    if (!is_a_guest()) {
        // auto session was created - so switch to guest
        $user = build_user($conf['guest_id'], true);
    }
}
// Check the status now after the user has been loaded
check_status(ACCESS_GUEST);
list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
include_once PHPWG_ROOT_PATH . 'include/feedcreator.class.php';
set_make_full_url();
$rss = new UniversalFeedCreator();
$rss->encoding = get_pwg_charset();
$rss->title = $conf['gallery_title'];
$rss->title .= ' (as ' . stripslashes($user['username']) . ')';
$rss->link = get_gallery_home_url();
// +-----------------------------------------------------------------------+
// |                            Feed creation                              |
// +-----------------------------------------------------------------------+
$news = array();
if (!$image_only) {
    $news = news($feed_row['last_check'], $dbnow, true, true);
    if (count($news) > 0) {
        $item = new FeedItem();
        $item->title = l10n('New on %s', format_date($dbnow));
        $item->link = get_gallery_home_url();
        // content creation
        $item->description = '<ul>';
Пример #12
0
        }
    } else {
        if (isset($_GET['init_auth'])) {
            $params = array();
            if ($provider == 'OpenID') {
                $params['openid_identifier'] = $_GET['openid_identifier'];
            }
            // try to authenticate
            $adapter = $hybridauth->authenticate($provider, $params);
        } else {
            if (!verify_ephemeral_key(@$_GET['key'])) {
                throw new Exception('Forbidden', 403);
            }
            $template->assign('LOADING', '&openid_identifier=' . @$_GET['openid_identifier'] . '&init_auth=1');
        }
    }
} catch (Exception $e) {
    switch ($e->getCode()) {
        case 5:
            $template->assign('ERROR', l10n('Authentication canceled'));
            break;
        case 404:
            $template->assign('ERROR', l10n('User not found'));
            break;
        default:
            $template->assign('ERROR', l10n('An error occured, please contact the gallery owner. <i>Error code : %s</i>', '<span title="' . $e->getMessage() . '">' . $e->getCode() . '</span>'));
    }
}
$template->assign(array('GALLERY_TITLE' => $conf['gallery_title'], 'CONTENT_ENCODING' => get_pwg_charset(), 'U_HOME' => get_gallery_home_url(), 'OAUTH_PATH' => OAUTH_PATH, 'PROVIDER' => $hybridauth_conf['providers'][$provider]['name'], 'SELF_URL' => OAUTH_PATH . 'auth.php?provider=' . $provider));
$template->set_filename('index', realpath(OAUTH_PATH . 'template/auth.tpl'));
$template->pparse('index');