Beispiel #1
0
function do_FixMoin($formatter, $options)
{
    global $DBInfo;
    $pagename = rawurldecode(preg_replace('/_([0-9a-f]{2})/i', '%\\1', $formatter->page->name));
    $npage = str_replace(' ', '', $pagename);
    if (!$DBInfo->hasPage($npage)) {
        if (strtolower($DBInfo->charset) == 'utf-8') {
            # is it EUC-KR ?
            $new = iconv('EUC-KR', $DBInfo->charset, $npage);
            if ($new) {
                $npage = $new;
            }
        }
    }
    if (!$npage or !$DBInfo->hasPage($npage)) {
        $options['redirect'] = 1;
        $options['value'] = $formatter->page->name;
        do_goto($formatter, $options);
        return true;
    }
    $options['redirect'] = 1;
    $options['value'] = $npage;
    do_goto($formatter, $options);
    return true;
}
Beispiel #2
0
function do_home($formatter, $options)
{
    global $DBInfo;
    if ($options['id'] and $DBInfo->hasPage($options['id'])) {
        $options['page'] = $options['id'];
    } else {
        $options['page'] = 'FrontPage';
    }
    $options['value'] = $options['page'];
    do_goto($formatter, $options);
    return;
}
Beispiel #3
0
function do_RandomPage($formatter, $options = '')
{
    global $DBInfo;
    if (!empty($options['action_mode']) and $options['action_mode'] == 'ajax') {
        $val = !empty($options['value']) ? intval($options['value']) : '';
        $params = $options;
        $params['call'] = 1;
        $ret = macro_RandomPage($formatter, $val, $params);
        if (function_exists('json_encode')) {
            echo json_encode($ret);
        } else {
            require_once 'lib/JSON.php';
            $json = new Services_JSON();
            echo $json->encode($ret);
        }
        return;
    }
    $max = $DBInfo->getCounter();
    $rand = rand(1, $max);
    $indexer = $DBInfo->lazyLoad('titleindexer');
    $sel_pages = $indexer->getPagesByIds(array($rand));
    $options['value'] = $sel_pages[0];
    do_goto($formatter, $options);
    return;
}
Beispiel #4
0
function do_userform($formatter, $options)
{
    global $DBInfo;
    $user =& $DBInfo->user;
    # get cookie
    $id = !empty($options['login_id']) ? $options['login_id'] : '';
    $use_any = 0;
    if (!empty($DBInfo->use_textbrowsers)) {
        if (is_string($DBInfo->use_textbrowsers)) {
            $use_any = preg_match('/' . $DBInfo->use_textbrowsers . '/', $_SERVER['HTTP_USER_AGENT']) ? 1 : 0;
        } else {
            $use_any = preg_match('/Lynx|w3m|links/', $_SERVER['HTTP_USER_AGENT']) ? 1 : 0;
        }
    }
    $options['msg'] = '';
    # e-mail conformation
    if (!empty($options['ticket']) and $id and $id != 'Anonymous') {
        $userdb =& $DBInfo->udb;
        $suspended = false;
        if ($userdb->_exists($id)) {
            $user = $userdb->getUser($id);
        } else {
            if ($userdb->_exists($id, 1)) {
                // suspended user
                $suspended = true;
                $user = $userdb->getUser($id, 1);
            }
        }
        if ($user->id == $id) {
            if ($user->info['eticket'] == $options['ticket']) {
                list($dummy, $email) = explode('.', $options['ticket'], 2);
                $user->info['email'] = $email;
                $user->info['eticket'] = '';
                if ($suspended) {
                    if (empty($DBInfo->register_confirm_admin)) {
                        $userdb->activateUser($id);
                        $userdb->saveUser($user);
                    } else {
                        $userdb->saveUser($user, array('suspended' => 1));
                    }
                } else {
                    $userdb->saveUser($user);
                }
                $title = _("Successfully confirmed");
                $options['msg'] = _("Your e-mail address is confirmed successfully");
                if (!empty($DBInfo->register_confirm_admin)) {
                    $options['msg'] .= "<br />" . _("Your need to wait until your ID activated by admin");
                }
            } else {
                if ($user->info['nticket'] == $options['ticket']) {
                    $title = _("Successfully confirmed");
                    $user->info['nticket'] = '';
                    $user->info['password'] = $user->info['npassword'];
                    $user->info['npassword'] = '';
                    $userdb->saveUser($user);
                    $options['msg'] = _("Your new password is confirmed successfully");
                } else {
                    $title = _("Confirmation missmatched !");
                    $options['msg'] = _("Please try again to register your e-mail address");
                }
            }
        } else {
            if ($suspended) {
                $title = _("Please wait until your ID is confirmed by admin!");
            } else {
                $title = _("ID does not exist !");
            }
            $options['msg'] = _("Please try again to register your e-mail address");
        }
        $formatter->send_header("", $options);
        $formatter->send_title($title, "", $options);
        $formatter->send_footer("", $options);
        return '';
    }
    $title = '';
    if ($user->id == "Anonymous" and !empty($options['emailreset'])) {
        setcookie('MONI_VERIFIED_EMAIL', '', time() - 3600, get_scriptname());
        $options['msg'] .= '<br />' . _("Verification E-mail removed.");
        $options['verifyemail'] = '';
        $user->verified_email = '';
    } else {
        if ($user->id == "Anonymous" and !empty($options['login']) and !empty($options['verify_email'])) {
            $email = base64_decode($options['login']);
            $ticket = base64_encode(getTicket($_SERVER['REMOTE_ADDR'], $email, 10));
            if ($ticket == $options['verify_email']) {
                $options['msg'] .= '<br />' . _("Your email address is successfully verified.");
                $user->verified_email = $email;
                setcookie('MONI_VERIFIED_EMAIL', $email, time() + 60 * 60 * 24 * 30, get_scriptname());
            } else {
                $options['msg'] .= '<br />' . _("Verification missmatched.");
            }
        } else {
            if ($user->id == "Anonymous" and $options['verify'] == _("Verify E-mail address") and !empty($DBInfo->anonymous_friendly) and !empty($options['verifyemail'])) {
                if (preg_match('/^[a-z][a-z0-9_\\-\\.]+@[a-z][a-z0-9_\\-]+(\\.[a-z0-9_]+)+$/i', $options['verifyemail'])) {
                    if (($ret = verify_email($options['verifyemail'])) < 0) {
                        $ret = -$ret;
                        $options['msg'] .= '<br />' . 'ERROR Code: ' . $ret;
                        $options['msg'] .= '<br/>' . _("Invalid email address or can't verify it.");
                    } else {
                        if (!empty($DBInfo->verify_email)) {
                            if ($DBInfo->verify_email == 1) {
                                $options['msg'] .= '<br/>' . _("Your email address is successfully verified.");
                                setcookie('MONI_VERIFIED_EMAIL', $options['verifyemail'], time() + 60 * 60 * 24 * 30, get_scriptname());
                            } else {
                                $opts = array();
                                $opts['subject'] = "[{$DBInfo->sitename}] " . _("Verify Email address");
                                $opts['email'] = $options['verifyemail'];
                                $opts['id'] = 'nobody';
                                $ticket = base64_encode(getTicket($_SERVER['REMOTE_ADDR'], $opts['email'], 10));
                                $enc = base64_encode($opts['email']);
                                $body = qualifiedUrl($formatter->link_url('UserPreferences', "?action=userform&login={$enc}&verify_email={$ticket}"));
                                $body = _("Please confirm your e-mail address") . "\n" . $body . "\n";
                                $ret = wiki_sendmail($body, $opts);
                                $options['msg'] .= '<br/>' . _("E-mail verification mail sent");
                            }
                        }
                    }
                } else {
                    $options['msg'] .= '<br/>' . _("Your email address is not valid");
                }
            } else {
                if ($user->id == "Anonymous" and !empty($options['login_id']) and isset($options['password']) and !isset($options['passwordagain'])) {
                    if (method_exists($user, 'login')) {
                        $user->login($formatter, $options);
                        $params = array();
                        $params['value'] = $options['page'];
                        do_goto($formatter, $params);
                        return;
                    }
                    # login
                    $userdb = $DBInfo->udb;
                    if ($userdb->_exists($id)) {
                        $user = $userdb->getUser($id);
                        $login_ok = 0;
                        if (!empty($DBInfo->use_safelogin)) {
                            if (isset($options['challenge']) and $options['_chall'] == $options['challenge']) {
                                #print '<pre>';
                                #print $options['password'].'<br />';
                                #print hmac($options['challenge'],$user->info['password']);
                                #print '</pre>';
                                if (hmac($options['challenge'], $user->info['password']) == $options['password']) {
                                    $login_ok = 1;
                                }
                            } else {
                                # with no javascript browsers
                                $md5pw = md5($options['password']);
                                if ($md5pw == $user->info['password']) {
                                    $login_ok = 1;
                                }
                            }
                        }
                        if ($login_ok or $user->checkPasswd($options['password']) === true) {
                            $options['msg'] = sprintf(_("Successfully login as '%s'"), $id);
                            $options['id'] = $user->id;
                            if ($user->id == 'Anonymous') {
                                // special case. login success but ID is not acceptable
                                $options['msg'] = _("Invalid user ID. Please register again");
                            } else {
                                $formatter->header($user->setCookie());
                                if (!isset($user->info['login_success'])) {
                                    $user->info['login_success'] = 0;
                                }
                                if (!isset($user->info['login_fail'])) {
                                    $user->info['login_fail'] = 0;
                                }
                                $user->info['login_success']++;
                                $user->info['last_login'] = gmdate("Y/m/d H:i:s", time());
                                $user->info['login_fail'] = 0;
                                // reset login
                                $user->info['remote'] = $_SERVER['REMOTE_ADDR'];
                                $userdb->saveUser($user);
                                $use_refresh = 1;
                            }
                            $DBInfo->user = $user;
                        } else {
                            $title = sprintf(_("Invalid password !"));
                            if (!isset($user->info['login_fail'])) {
                                $user->info['login_fail'] = 0;
                            }
                            $user->info['login_fail']++;
                            $user->info['remote'] = $_SERVER['REMOTE_ADDR'];
                            $userdb->saveUser($user);
                            $user->setID('Anonymous');
                        }
                    } else {
                        if (isset($options['login_id'][0])) {
                            if ($userdb->_exists($id, 1)) {
                                // suspended user
                                $title = sprintf(_("\"%s\" is waiting for activated by admin !"), $options['login_id']);
                            } else {
                                $title = sprintf(_("\"%s\" does not exist on this wiki !"), $options['login_id']);
                            }
                            $options['login_id'] = '';
                        } else {
                            $title = _("Make new ID on this wiki");
                        }
                        $form = macro_UserPreferences($formatter, '', $options);
                    }
                } else {
                    if (!empty($options['logout'])) {
                        # logout
                        header($user->unsetCookie(), false);
                        if (session_name() != '') {
                            $path = get_scriptname();
                            // for moniwiki internal
                            header('Set-Cookie: ' . session_name() . '=' . $user->id . '; expires=Tuesday, 01-Jan-1999 12:00:00 GMT; Path=' . $path, false);
                            // for some user plugins
                            $params = session_get_cookie_params();
                            header('Set-Cookie: ' . session_name() . '=' . $user->id . '; expires=Tuesday, 01-Jan-1999 12:00:00 GMT; Path=' . $params['path'], false);
                        }
                        // call logout method
                        if (method_exists($user, 'logout')) {
                            $user->logout($formatter, $options);
                        } else {
                            $options['msg'] = _("Cookie deleted !");
                        }
                        $user->id = 'Anonymous';
                        $DBInfo->user = $user;
                        $use_refresh = 1;
                    } else {
                        if (!empty($DBInfo->use_sendmail) and $options['login'] == _("E-mail new password") and $user->id == "Anonymous" and !empty($options['email']) and !empty($options['login_id'])) {
                            # email new password
                            $title = '';
                            if (!$use_any and $DBInfo->use_ticket) {
                                if ($options['__seed'] and $options['check']) {
                                    $mycheck = getTicket($options['__seed'], $_SERVER['REMOTE_ADDR'], 4);
                                    if ($mycheck == $options['check']) {
                                        $ok_ticket = 1;
                                    } else {
                                        $title = _("Invalid ticket !");
                                    }
                                } else {
                                    $title = _("You need a ticket !");
                                }
                            } else {
                                $ok_ticket = 1;
                            }
                            $userdb =& $DBInfo->udb;
                            if ($userdb->_exists($id)) {
                                $user = $userdb->getUser($id);
                            }
                            if ($ok_ticket and $user->id != "Anonymous") {
                                if ($options['email'] == $user->info['email'] and $user->info['eticket'] == '') {
                                    #make new password
                                    $mypass = base64_encode(getTicket(time(), $_SERVER['REMOTE_ADDR'], 10));
                                    $mypass = substr($mypass, 0, 8);
                                    $options['password'] = $mypass;
                                    $old_passwd = $user->info['password'];
                                    if ($DBInfo->use_safelogin) {
                                        $ret = $user->setPasswd(md5($mypass), md5($mypass), 1);
                                    } else {
                                        $ret = $user->setPasswd($mypass, $mypass);
                                    }
                                    $new_passwd = $user->info['password'];
                                    $user->info['password'] = $old_passwd;
                                    $user->info['npassword'] = $new_passwd;
                                    #make ticket
                                    $ticket = md5(time() . $user->id . $options['email']);
                                    $user->info['nticket'] = $ticket . "." . $options['email'];
                                    // save join agreement
                                    if (!empty($DBInfo->use_agreement) and !empty($options['joinagreement'])) {
                                        $user->info['join_agreement'] = 'agree';
                                        if (!empty($DBInfo->agreement_version)) {
                                            $user->info['join_agreement_version'] = $DBInfo->agreement_version;
                                        }
                                    }
                                    $userdb->saveUser($user);
                                    # XXX
                                    $opts['subject'] = "[{$DBInfo->sitename}] " . _("New password confirmation");
                                    $opts['email'] = $options['email'];
                                    $opts['id'] = 'nobody';
                                    $body = qualifiedUrl($formatter->link_url('', "?action=userform&login_id={$user->id}&ticket={$ticket}.{$options['email']}"));
                                    $body = _("Please confirm your new password") . "\n" . $body . "\n";
                                    $body .= sprintf(_("Your new password is %s"), $mypass) . "\n\n";
                                    $body .= _("Please change your password later") . "\n";
                                    $ret = wiki_sendmail($body, $opts);
                                    if (is_array($ret)) {
                                        $title = _("Fail to e-mail notification !");
                                        $options['msg'] = $ret['msg'];
                                    } else {
                                        $title = _("New password is sent to your e-mail !");
                                        $options['msg'] = _("Please check your e-mail");
                                    }
                                } else {
                                    if ($options['email'] != $user->info['email']) {
                                        $title = _("Fail to e-mail notification !");
                                        $options['msg'] = _("E-mail mismatch !");
                                    } else {
                                        $title = _("Invalid request");
                                        $options['msg'] = _("Please confirm your e-mail address first !");
                                    }
                                }
                            } else {
                                if (!$ok_ticket) {
                                    $title = _("Invalid ticket !");
                                } else {
                                    $title = _("ID and e-mail mismatch !");
                                }
                                $options['msg'] = _("Please try again or make a new profile");
                            }
                            $formatter->send_header("", $options);
                            $formatter->send_title($title, "", $options);
                            $formatter->send_footer("", $options);
                            return;
                        } else {
                            if ($user->id == "Anonymous" and !empty($options['login_id']) and ($options['password'] and $options['passwordagain'] or $DBInfo->use_safelogin and $options['email'])) {
                                # create profile
                                $title = '';
                                if (!$use_any and !empty($DBInfo->use_ticket)) {
                                    if ($options['__seed'] and $options['check']) {
                                        $mycheck = getTicket($options['__seed'], $_SERVER['REMOTE_ADDR'], 4);
                                        if ($mycheck == $options['check']) {
                                            $ok_ticket = 1;
                                        } else {
                                            $title = _("Invalid ticket !");
                                        }
                                    } else {
                                        $title = _("You need a ticket !");
                                    }
                                } else {
                                    $ok_ticket = 1;
                                }
                                $id = $user->getID($options['login_id']);
                                if (preg_match('/^[a-z][a-z0-9_\\-\\.]+@[a-z][a-z0-9_\\-]+(\\.[a-z0-9_]+)+$/i', $id)) {
                                    if (($ret = verify_email($id)) < 0) {
                                        $ret = -$ret;
                                        $options['msg'] .= '<br />' . 'ERROR Code: ' . $ret;
                                        $options['msg'] .= '<br/>' . _("Invalid email address or can't verify it.");
                                    } else {
                                        $options['email'] = $id;
                                        $user->setID($id);
                                    }
                                } else {
                                    if (!preg_match("/\\//", $id)) {
                                        $user->setID($id);
                                    }
                                }
                                // protect http:// style id
                                if (!empty($DBInfo->use_agreement) and empty($options['joinagreement'])) {
                                    $title = _("Please check join agreement.");
                                } else {
                                    if ($ok_ticket and $user->id != "Anonymous") {
                                        if (!empty($DBInfo->use_safelogin)) {
                                            $mypass = base64_encode(getTicket(time(), $_SERVER['REMOTE_ADDR'], 10));
                                            $mypass = substr($mypass, 0, 8);
                                            $options['password'] = $mypass;
                                            $ret = $user->setPasswd(md5($mypass), md5($mypass), 1);
                                        } else {
                                            $ret = $user->setPasswd($options['password'], $options['passwordagain']);
                                        }
                                        if (!empty($DBInfo->password_length) and strlen($options['password']) < $DBInfo->password_length) {
                                            $ret = 0;
                                        }
                                        if ($ret <= 0) {
                                            if ($ret == 0) {
                                                $title = _("too short password!");
                                            } else {
                                                if ($ret == -1) {
                                                    $title = _("mismatch password!");
                                                } else {
                                                    if ($ret == -2) {
                                                        $title = _("not acceptable character found in the password!");
                                                    }
                                                }
                                            }
                                        } else {
                                            if ($ret < 8 and empty($DBInfo->use_safelogin)) {
                                                $options['msg'] = _("Your password is too simple to use as a password !");
                                            }
                                            $udb = $DBInfo->udb;
                                            if ($options['email']) {
                                                if (preg_match('/^[a-z][a-z0-9_\\-\\.]+@[a-z][a-z0-9_\\-]+(\\.[a-z0-9_]+)+$/i', $options['email'])) {
                                                    if (($ret = verify_email($options['email'])) < 0) {
                                                        $options['email'] = '';
                                                        // reset email address
                                                        $ret = -$ret;
                                                        $options['msg'] .= '<br />' . 'ERROR Code: ' . $ret;
                                                        $options['msg'] .= '<br/>' . _("Can't verify E-mail address! Please check your email address.");
                                                    }
                                                } else {
                                                    $options['msg'] .= '<br/>' . _("Your email address is not valid");
                                                }
                                            }
                                            if ($udb->isNotUser($user)) {
                                                if (!empty($DBInfo->no_register)) {
                                                    $options['msg'] = _("Fail to register");
                                                    $options['err'] = _("You are not allowed to register on this wiki");
                                                    $options['err'] .= "\n" . _("Please contact WikiMasters");
                                                    do_invalid($formatter, $options);
                                                    return;
                                                }
                                                $title = sprintf(_("Successfully added as '%s'"), _html_escape($user->id));
                                                $options['id'] = $user->id;
                                                $ticket = md5(time() . $user->id . $options['email']);
                                                $user->info['eticket'] = $ticket . "." . $options['email'];
                                                if (!empty($DBInfo->use_safelogin)) {
                                                    $options['msg'] = sprintf(_("Successfully added as '%s'"), $user->id);
                                                    $options['msg'] .= '<br />' . _("Please check your mailbox");
                                                }
                                                $args = array();
                                                if ($options['email'] == $id or !empty($DBInfo->register_confirm_email)) {
                                                    $args = array('suspended' => 1);
                                                }
                                                if (!empty($DBInfo->register_confirm_admin)) {
                                                    $args = array('suspended' => 1);
                                                }
                                                if (!empty($DBInfo->register_confirm_admin)) {
                                                    if (!empty($options['msg'])) {
                                                        $options['msg'] .= '<br />';
                                                    }
                                                    $options['msg'] .= _("Your need to wait until your ID activated by admin");
                                                }
                                                // save join agreement
                                                if (!empty($DBInfo->use_agreement) and !empty($options['joinagreement'])) {
                                                    $user->info['join_agreement'] = 'agree';
                                                    if (!empty($DBInfo->agreement_version)) {
                                                        $user->info['join_agreement_version'] = $DBInfo->agreement_version;
                                                    }
                                                }
                                                if (empty($DBInfo->use_safelogin) && empty($args['suspended'])) {
                                                    $formatter->header($user->setCookie());
                                                }
                                                $ret = $udb->addUser($user, $args);
                                                # XXX
                                                if (!empty($options['email']) and preg_match('/^[a-z][a-z0-9_\\-\\.]+@[a-z][a-z0-9_\\-]+(\\.[a-z0-9_]+)+$/i', $options['email'])) {
                                                    $options['subject'] = "[{$DBInfo->sitename}] " . _("E-mail confirmation");
                                                    $body = '';
                                                    if (!empty($DBInfo->email_register_header) and file_exists($DBInfo->email_register_header)) {
                                                        $body = file_get_contents($DBInfo->email_register_header);
                                                        $body = str_replace(array('@sitename@'), array($DBInfo->sitename), $body);
                                                    }
                                                    $body .= _("Please confirm your email address") . "\n\n";
                                                    $body .= qualifiedUrl($formatter->link_url('', "?action=userform&login_id={$user->id}&ticket={$ticket}.{$options['email']}"));
                                                    $body .= "\n";
                                                    if (!empty($DBInfo->use_safelogin)) {
                                                        $body .= "\n" . sprintf(_("Your initial password is %s"), $mypass) . "\n\n";
                                                        $body .= _("Please change your password later") . "\n";
                                                    }
                                                    $ret = wiki_sendmail($body, $options);
                                                    if (is_array($ret)) {
                                                        $options['msg'] .= $ret['msg'];
                                                    } else {
                                                        $options['msg'] .= '<br/>' . _("Confirmation E-mail sent");
                                                    }
                                                }
                                            } else {
                                                # already exist user
                                                $user = $udb->getUser($user->id);
                                                if ($user->checkPasswd($options['password']) === true) {
                                                    $options['msg'] .= sprintf(_("Successfully login as '%s'"), $id);
                                                    $options['id'] = $user->id;
                                                    $formatter->header($user->setCookie());
                                                    $udb->saveUser($user);
                                                    # XXX
                                                } else {
                                                    $title = _("Invalid password !");
                                                }
                                            }
                                        }
                                    } else {
                                        if (empty($title)) {
                                            $title = _("Invalid username !");
                                        }
                                    }
                                }
                            } else {
                                if ($user->id != "Anonymous") {
                                    # save profile
                                    $udb =& $DBInfo->udb;
                                    $userinfo = $udb->getUser($user->id);
                                    if (!empty($options['password']) and !empty($options['passwordagain'])) {
                                        $chall = 0;
                                        if (!empty($DBInfo->use_safelogin)) {
                                            if (isset($options['_chall'])) {
                                                $chall = $options['challenge'];
                                            } else {
                                                $chall = rand(100000);
                                                $options['password'] = hmac($chall, $options['password']);
                                            }
                                        }
                                        //echo 'chall=',$chall,' ',$options['password'];
                                        if ($userinfo->checkPasswd($options['password'], $chall) === true) {
                                            if ($DBInfo->use_safelogin) {
                                                $mypass = md5($options['passwordagain']);
                                                // XXX
                                                $ret = $userinfo->setPasswd($mypass, $mypass, 1);
                                            } else {
                                                $ret = $userinfo->setPasswd($options['passwordagain']);
                                            }
                                            if ($ret <= 0) {
                                                if ($ret == 0) {
                                                    $title = _("too short password!");
                                                } else {
                                                    if ($ret == -1) {
                                                        $title = _("mismatch password !");
                                                    } else {
                                                        if ($ret == -2) {
                                                            $title = _("not acceptable character found in the password!");
                                                        }
                                                    }
                                                }
                                                $options['msg'] = _("Password is not changed !");
                                            } else {
                                                $title = _("Password is changed !");
                                                if ($ret < 8) {
                                                    $options['msg'] = _("Password is too simple to use as a password !");
                                                }
                                            }
                                        } else {
                                            $title = _("Invalid password !");
                                            $options['msg'] = _("Password is not changed !");
                                        }
                                    }
                                    if (isset($options['user_css'])) {
                                        $userinfo->info['css_url'] = $options['user_css'];
                                    }
                                    if (isset($options['timezone'])) {
                                        list($hour, $min) = explode(':', $options['timezone']);
                                        $min = $min * 60;
                                        $min = $hour < 0 ? -1 * $min : $min;
                                        $tz_offset = $hour * 3600 + $min;
                                        $userinfo->info['tz_offset'] = $tz_offset;
                                    }
                                    if (!empty($DBInfo->use_agreement) and !empty($options['joinagreement'])) {
                                        $userinfo->info['join_agreement'] = 'agree';
                                        if (!empty($DBInfo->agreement_version)) {
                                            $userinfo->info['join_agreement_version'] = $DBInfo->agreement_version;
                                        }
                                    }
                                    $button_check_email_again = !empty($options['button_check_email_again']) ? 1 : 0;
                                    if ($button_check_email_again and !empty($userinfo->info['eticket'])) {
                                        list($dummy, $email) = explode('.', $userinfo->info['eticket'], 2);
                                        if (!empty($email)) {
                                            $options['email'] = $email;
                                        }
                                    }
                                    if (!empty($options['email']) and $options['email'] != $userinfo->info['email']) {
                                        if (preg_match('/^[a-z][a-z0-9_\\-\\.]+@[a-z][a-z0-9_\\-]+(\\.[a-z0-9_]+)+$/i', $options['email'])) {
                                            if (($ret = verify_email($options['email'])) < 0) {
                                                $ret = -$ret;
                                                $options['msg'] .= '<br />' . 'ERROR Code: ' . $ret;
                                                $options['msg'] .= '<br />' . _("Invalid email address or can't verify it.");
                                            } else {
                                                $ticket = md5(time() . $userinfo->info['id'] . $options['email']);
                                                $userinfo->info['eticket'] = $ticket . "." . $options['email'];
                                                $options['subject'] = "[{$DBInfo->sitename}] " . _("E-mail confirmation");
                                                $body = qualifiedUrl($formatter->link_url('', "?action=userform&login_id={$user->id}&ticket={$ticket}.{$options['email']}"));
                                                $body = _("Please confirm your email address") . "\n" . $body;
                                                $ret = wiki_sendmail($body, $options);
                                                if (is_array($ret)) {
                                                    $options['msg'] = $ret['msg'];
                                                } else {
                                                    $options['msg'] = _("E-mail confirmation mail sent");
                                                }
                                            }
                                        } else {
                                            $options['msg'] = _("Your email address is not valid");
                                        }
                                    }
                                    if (!empty($userinfo->info['idtype']) and $userinfo->info['idtype'] == 'openid' and isset($options['nick']) and $options['nick'] != $userinfo->info['nick']) {
                                        $nick = $userinfo->getID($options['nick']);
                                        // nickname check XXX
                                        if (!$udb->_exists($nick)) {
                                            $userinfo->info['nick'] = $nick;
                                        } else {
                                            $options['msg'] = _("Your Nickname already used as ID in this wiki");
                                        }
                                    }
                                    $udb->saveUser($userinfo);
                                    #$options['css_url']=$options['user_css'];
                                    if (!isset($options['msg'])) {
                                        $options['msg'] = _("Profiles are saved successfully !");
                                    }
                                } else {
                                    if ($user->id == "Anonymous" and isset($options['openid_url'])) {
                                        # login with openid
                                        include_once 'lib/openid.php';
                                        session_start();
                                        $process_url = qualifiedUrl($formatter->link_url("UserPreferences", "?action=userform"));
                                        $trust_root = qualifiedUrl($formatter->link_url(""));
                                        $openid = new SimpleOpenID();
                                        $openid->SetIdentity($options['openid_url']);
                                        $openid->SetTrustRoot($trust_root);
                                        $openid->SetRequiredFields(array('nickname', 'email', 'fullname'));
                                        $openid->SetOptionalFields(array('language', 'timezone'));
                                        if ($openid->GetOpenIDServer()) {
                                            $openid->SetApprovedURL($process_url);
                                            // Send Response from OpenID server to this script
                                            $openid->Redirect();
                                            // This will redirect user to OpenID Server
                                            return;
                                        } else {
                                            $error = $openid->GetError();
                                            #echo "ERROR CODE: " . $error['code'] . "<br>";
                                            #echo "ERROR DESCRIPTION: " . $error['description'] . "<br>";
                                            $options["msg"] = sprintf(_("Authentication request was failed: %s"), $error['description']);
                                        }
                                    } else {
                                        if (!empty($options['openid_mode']) and $options['openid_mode'] == 'id_res') {
                                            // OpenID result
                                            include_once 'lib/openid.php';
                                            if (!preg_match('/utf-?8/i', $DBInfo->charset)) {
                                                $options['openid_sreg_nickname'] = iconv('utf-8', $DBInfo->charset, $options['openid_sreg_nickname']);
                                                $options['openid_sreg_fullname'] = iconv('utf-8', $DBInfo->charset, $options['openid_sreg_fullname']);
                                            }
                                            $openid = new SimpleOpenID();
                                            $openid->SetIdentity($options['openid_identity']);
                                            $openid_validation_result = $openid->ValidateWithServer();
                                            if ($openid_validation_result == true) {
                                                // OK HERE KEY IS VALID
                                                $userdb =& $DBInfo->udb;
                                                // XXX
                                                $user->setID($options['openid_identity']);
                                                // XXX
                                                if (!empty($options['openid_language'])) {
                                                    $user->info['language'] = strtolower($options['openid_sreg_language']);
                                                }
                                                //$user->info['tz_offset']=$options['openid_timezone'];
                                                if ($userdb->_exists($options['openid_identity'])) {
                                                    $user = $userdb->getUser($options['openid_identity']);
                                                    $user->info['idtype'] = 'openid';
                                                    $options['msg'] .= sprintf(_("Successfully login as '%s' via OpenID."), $options['openid_identity']);
                                                    $formatter->header($user->setCookie());
                                                    $userdb->saveUser($user);
                                                    // always save
                                                } else {
                                                    if (!empty($DBInfo->no_register) and $DBInfo->no_register == 1) {
                                                        $options['msg'] = _("Fail to register");
                                                        $options['err'] = _("You are not allowed to register on this wiki");
                                                        $options['err'] .= "\n" . _("Please contact WikiMasters");
                                                        do_invalid($formatter, $options);
                                                        return;
                                                    }
                                                    if ($options['openid_sreg_nickname']) {
                                                        $nick = $user->getID($options['openid_sreg_nickname']);
                                                        if (!$userdb->_exists($nick)) {
                                                            $user->info['nick'] = $nick;
                                                        } else {
                                                            $options['msg'] = sprintf(_("Your Nickname %s already used as ID in this Wiki."), $nick);
                                                        }
                                                    }
                                                    $user->info['email'] = $options['openid_sreg_email'];
                                                    $user->info['idtype'] = 'openid';
                                                    $userdb->addUser($user);
                                                    $formatter->header($user->setCookie());
                                                    $userdb->saveUser($user);
                                                    $options["msg"] .= sprintf(_("OpenID Authentication successful and saved as %s."), $options['openid_identity']);
                                                }
                                                $options['id'] = $user->id;
                                            } else {
                                                if ($openid->IsError() == true) {
                                                    // ON THE WAY, WE GOT SOME ERROR
                                                    $error = $openid->GetError();
                                                    $options["msg"] = sprintf(_("Authentication request was failed: %s"), $error['description']);
                                                } else {
                                                    // Signature Verification Failed
                                                    $options["msg"] = _("Invalid OpenID Authentication request");
                                                    echo "INVALID AUTHORIZATION";
                                                }
                                            }
                                        } else {
                                            if (!empty($DBInfo->use_agreement) and $options['login'] == _("Make profile")) {
                                                $options['agreement'] = 1;
                                                $form = macro_UserPreferences($formatter, '', $options);
                                            } else {
                                                $options["msg"] = _("Invalid request");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    $myrefresh = '';
    if (!empty($DBInfo->use_refresh) and !empty($use_refresh)) {
        $sec = $DBInfo->use_refresh - 1;
        if (!empty($options['return_url'])) {
            $lnk = $options['return_url'];
        } else {
            $lnk = $formatter->link_url($formatter->page->urlname, '?action=show');
        }
        $myrefresh = 'Refresh: ' . $sec . '; url=' . qualifiedURL($lnk);
    }
    $formatter->send_header($myrefresh, $options);
    $formatter->send_title($title, "", $options);
    if (!$title && (empty($DBInfo->control_read) or $DBInfo->security->is_allowed('read', $options))) {
        $lnk = $formatter->link_to('?action=show');
        if (empty($form)) {
            echo sprintf(_("return to %s"), $lnk);
        } else {
            echo $form;
        }
    } else {
        if (!empty($form)) {
            print $form;
        }
        #    else $formatter->send_page("Goto UserPreferences");
    }
    $formatter->send_footer("", $options);
}
Beispiel #5
0
function do_AutoGoto($formatter, $options)
{
    global $DBInfo;
    $supported = array('man' => 'Man', 'google' => 'Google', 'macro' => 'Macro', 'tpl' => 'TPL');
    if (!empty($DBInfo->autogoto_options)) {
        if (is_array($DBInfo->autogoto_options)) {
            $supported = array_merge($supported, $DBInfo->autogoto_options);
        } else {
            if (is_string($DBInfo->autogoto_options)) {
                $opts = explode(',', $DBInfo->autogoto_options);
                foreach ($opts as $opt) {
                    $opt = trim($opt);
                    if (empty($opt)) {
                        continue;
                    }
                    $v = explode(' ', $opt);
                    if (!empty($v[1])) {
                        $supported[$v[0]] = $v[1];
                    }
                }
            }
        }
        $v = explode(' ', trim($formatter->page->name));
        if ($v[1] and array_key_exists(strtolower($v[0]), $supported)) {
            $val = urlencode($v[1]);
            $options['value'] = $supported[strtolower($v[0])] . ':' . $val;
            do_goto($formatter, $options);
            return true;
        }
    }
    // automatically make a list of pagenames to check.
    $pages = array();
    $name = trim($formatter->page->name);
    // is this a CamelCase wikiname?
    if (strpos($name, ' ') === false and preg_match('/^[A-Z]([A-Z]+[0-9a-z]|[0-9a-z]+[A-Z])[0-9a-zA-Z]*$/', $name)) {
        // insert spaces
        $name = preg_replace('/([a-z0-9])([A-Z])/', '\\1 \\2', $name);
    }
    $w = preg_split('/\\s+/', $name);
    $pages[] = implode(' ', $w);
    $pages[] = ucwords($pages[0]);
    if (count($w) > 1) {
        $pages[] = ucfirst($pages[0]);
        $pages[] = str_replace(' ', '', $pages[0]);
        $pages[] = str_replace(' ', '', $pages[1]);
    }
    // MediaWiki style naming
    if (strpos($name, '_') !== false) {
        $pages[] = str_replace('_', ' ', $name);
    }
    // normalize slashes
    if (($p = strpos($name, '/')) !== false) {
        $fixed = preg_replace('@/+@', '/', $name);
        if ($fixed != $name) {
            $pages[] = $fixed;
        }
        if ($fixed[0] == '/') {
            $pages[] = substr($fixed, 1);
        }
    }
    $pages = array_unique($pages);
    foreach ($pages as $p) {
        if ($DBInfo->hasPage($p)) {
            $options['value'] = $p;
            do_goto($formatter, $options);
            return true;
        }
    }
    if (function_exists('iconv')) {
        if (strtolower($DBInfo->charset) != 'utf-8') {
            $t = @iconv('UTF-8', $DBInfo->charset, $formatter->page->name);
            if ($t and $DBInfo->hasPage($t)) {
                $options['value'] = $t;
                do_goto($formatter, $options);
                return true;
            }
        } else {
            if (!empty($DBInfo->url_encodings)) {
                $cs = explode(',', $DBInfo->url_encodings);
                foreach ($cs as $c) {
                    $t = @iconv($c, $DBInfo->charset, $formatter->page->name);
                    if ($t and $DBInfo->hasPage($t)) {
                        $options['value'] = $t;
                        do_goto($formatter, $options);
                        return true;
                    }
                }
            }
        }
    }
    $options['value'] = $formatter->page->name;
    $options['check'] = 1;
    $options['noexact'] = !empty($DBInfo->titlesearch_noexact) ? true : false;
    if (do_titlesearch($formatter, $options)) {
        return true;
    }
    // normalize slashes
    $fixed = preg_replace('@/+@', '/', $formatter->page->name);
    $options['value'] = $fixed;
    # do not call AutoGoto recursively
    $options['redirect'] = 1;
    do_goto($formatter, $options);
    return true;
}
Beispiel #6
0
    function send_header($header = "", $options = array())
    {
        global $DBInfo;
        $plain = 0;
        $media = 'media="screen"';
        if (isset($options['action'][0]) and $options['action'] == 'print') {
            $media = '';
        }
        if (empty($options['is_robot']) && isset($this->pi['#redirect'][0]) && !empty($options['pi'])) {
            $options['value'] = $this->pi['#redirect'];
            $options['redirect'] = 1;
            $this->pi['#redirect'] = '';
            do_goto($this, $options);
            return true;
        }
        $header = !empty($header) ? $header : (!empty($options['header']) ? $options['header'] : null);
        if (!empty($header)) {
            foreach ((array) $header as $head) {
                $this->header($head);
                if (preg_match("/^content\\-type: text\\//i", $head)) {
                    $plain = 1;
                }
            }
        }
        $mtime = isset($options['mtime']) ? $options['mtime'] : $this->page->mtime();
        if ($mtime > 0) {
            $modified = $mtime > 0 ? gmdate('Y-m-d\\TH:i:s', $mtime) . '+00:00' : null;
            $lastmod = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
            $meta_lastmod = '<meta http-equiv="last-modified" content="' . $lastmod . '" />' . "\n";
        }
        if (is_static_action($options) or !empty($DBInfo->use_conditional_get) and !empty($mtime) and empty($options['nolastmod']) and $this->page->is_static) {
            $this->header('Last-Modified: ' . $lastmod);
            $etag = $this->page->etag($options);
            if (!empty($options['etag'])) {
                $this->header('ETag: "' . $options['etag'] . '"');
            } else {
                $this->header('ETag: "' . $etag . '"');
            }
        }
        // custom headers
        if (!empty($DBInfo->site_headers)) {
            foreach ((array) $DBInfo->site_headers as $head) {
                $this->header($head);
            }
        }
        $content_type = isset($DBInfo->content_type[0]) ? $DBInfo->content_type : 'text/html';
        $force_charset = '';
        if (!empty($DBInfo->force_charset)) {
            $force_charset = '; charset=' . $DBInfo->charset;
        }
        if (!$plain) {
            $this->header('Content-type: ' . $content_type . $force_charset);
        }
        if (!empty($options['action_mode']) and $options['action_mode'] == 'ajax') {
            return true;
        }
        # disabled
        #$this->header("Vary: Accept-Encoding, Cookie");
        #if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') and function_exists('ob_gzhandler')) {
        #  ob_start('ob_gzhandler');
        #  $etag.= '.gzip';
        #}
        if (!empty($options['metatags'])) {
            $metatags = $options['metatags'];
        } else {
            $metatags = $DBInfo->metatags;
        }
        if (!empty($options['noindex']) || !empty($this->pi['#noindex']) || (!empty($mtime) and !empty($DBInfo->delayindex) and time() - $mtime < $DBInfo->delayindex)) {
            // delay indexing like as dokuwiki
            if (preg_match("/<meta\\s+name=('|\")?robots\\1[^>]+>/i", $metatags)) {
                $metatags = preg_replace("/<meta\\s+name=('|\")?robots\\1[^>]+>/i", '<meta name="robots" content="noindex,nofollow" />', $metatags);
            } else {
                $metatags .= '<meta name="robots" content="noindex,nofollow" />' . "\n";
            }
        }
        if (isset($DBInfo->metatags_extra)) {
            $metatags .= $DBInfo->metatags_extra;
        }
        $js = !empty($DBInfo->js) ? $DBInfo->js : '';
        if (!$plain) {
            if (isset($options['trail'])) {
                $this->set_trailer($options['trail'], $this->page->name);
            } else {
                if ($DBInfo->origin) {
                    $this->set_origin($this->page->name);
                }
            }
            # find upper page
            $up_separator = '/';
            if (!empty($this->use_namespace)) {
                $up_separator .= '|\\:';
            }
            $pos = 0;
            preg_match('@(' . $up_separator . ')@', $this->page->name, $sep);
            # NameSpace/SubPage or NameSpace:SubNameSpacePage
            if (isset($sep[1])) {
                $pos = strrpos($this->page->name, $sep[1]);
            }
            if ($pos > 0) {
                $upper = substr($this->page->urlname, 0, $pos);
            } else {
                if ($this->group) {
                    $upper = _urlencode(substr($this->page->name, strlen($this->group)));
                }
            }
            // setup keywords
            $keywords = '';
            if (!empty($this->pi['#keywords'])) {
                $keywords = _html_escape($this->pi['#keywords']);
            } else {
                $keys = array();
                $dummy = strip_tags($this->page->title);
                $keys = explode(' ', $dummy);
                $keys[] = $dummy;
                $keys = array_unique($keys);
                $keywords = implode(', ', $keys);
            }
            // add redirects as keywords
            if (!empty($DBInfo->use_redirects_as_keywords)) {
                $r = new Cache_Text('redirects');
                $redirects = $r->fetch($this->page->name);
                if ($redirects !== false) {
                    sort($redirects);
                    $keywords .= ', ' . _html_escape(implode(', ', $redirects));
                }
            }
            // add site specific keywords
            if (!empty($DBInfo->site_keywords)) {
                $keywords .= ', ' . $DBInfo->site_keywords;
            }
            $keywords = "<meta name=\"keywords\" content=\"{$keywords}\" />\n";
            # find sub pages
            if (empty($options['action']) and !empty($DBInfo->use_subindex)) {
                $scache = new Cache_text('subpages');
                if (!($subs = $scache->exists($this->page->name))) {
                    if (($p = strrpos($this->page->name, '/')) !== false) {
                        $rule = _preg_search_escape(substr($this->page->name, 0, $p));
                    } else {
                        $rule = _preg_search_escape($this->page->name);
                    }
                    $subs = $DBInfo->getLikePages('^' . $rule . '\\/', 1);
                    if ($subs) {
                        $scache->update($this->page->name, 1);
                    }
                }
                if (!empty($subs)) {
                    $subindices = '';
                    if (empty($DBInfo->use_ajax)) {
                        $subindices = '<div>' . $this->macro_repl('PageList', '', array('subdir' => 1)) . '</div>';
                        $btncls = 'class="close"';
                    } else {
                        $btncls = '';
                    }
                    $this->subindex = "<fieldset id='wikiSubIndex'>" . "<legend title='[+]' {$btncls} onclick='javascript:toggleSubIndex(\"wikiSubIndex\")'></legend>" . $subindices . "</fieldset>\n";
                }
            }
            if (!empty($options['.title'])) {
                $options['title'] = $options['.title'];
            } else {
                if (empty($options['title'])) {
                    $options['title'] = !empty($this->pi['#title']) ? $this->pi['#title'] : $this->page->title;
                    $options['title'] = _html_escape($options['title']);
                } else {
                    $options['title'] = strip_tags($options['title']);
                }
            }
            $theme_type = !empty($this->_newtheme) ? $this->_newtheme : '';
            if (empty($options['css_url'])) {
                $options['css_url'] = $DBInfo->css_url;
            }
            if (empty($this->pi['#nodtd']) and !isset($options['retstr']) and $theme_type != 2) {
                if (!empty($this->html5)) {
                    if (is_string($this->html5)) {
                        echo $this->html5;
                    } else {
                        echo '<!DOCTYPE html>', "\n", '<html xmlns="http://www.w3.org/1999/xhtml">', "\n";
                    }
                } else {
                    echo $DBInfo->doctype;
                }
            }
            if ($theme_type == 2 or isset($options['retstr'])) {
                ob_start();
            } else {
                echo "<head>\n";
            }
            echo '<meta http-equiv="Content-Type" content="' . $content_type . ';charset=' . $DBInfo->charset . "\" />\n";
            echo <<<JSHEAD
<script type="text/javascript">
/*<![CDATA[*/
_url_prefix="{$DBInfo->url_prefix}";
/*]]>*/
</script>
JSHEAD;
            echo $metatags, $js, "\n";
            echo $this->get_javascripts();
            echo $keywords;
            if (!empty($meta_lastmod)) {
                echo $meta_lastmod;
            }
            $sitename = !empty($DBInfo->title_sitename) ? $DBInfo->title_sitename : $DBInfo->sitename;
            if (!empty($DBInfo->title_msgstr)) {
                $site_title = sprintf($DBInfo->title_msgstr, $sitename, $options['title']);
            } else {
                $site_title = $options['title'] . ' - ' . $sitename;
            }
            // set OpenGraph information
            $act = !empty($options['action']) ? strtolower($options['action']) : 'show';
            $is_show = $act == 'show';
            $is_frontpage = $this->page->name == get_frontpage($DBInfo->lang);
            if (!$is_frontpage && !empty($DBInfo->frontpages) && in_array($this->page->name, $DBInfo->frontpages)) {
                $is_frontpage = true;
            }
            if (!empty($DBInfo->canonical_url)) {
                if (($p = strpos($DBInfo->canonical_url, '%s')) !== false) {
                    $page_url = sprintf($DBInfo->canonical_url, $this->page->urlname);
                } else {
                    $page_url = $DBInfo->canonical_url . $this->page->urlname;
                }
            } else {
                $page_url = qualifiedUrl($this->link_url($this->page->urlname));
            }
            if ($is_show && $this->page->exists()) {
                $oc = new Cache_text('opengraph');
                if ($this->refresh || ($val = $oc->fetch($this->page->name, $this->page->mtime())) === false) {
                    $val = array('description' => '', 'image' => '');
                    if (!empty($this->pi['#redirect'])) {
                        $desc = '#redirect ' . $this->pi['#redirect'];
                    } else {
                        $raw = $this->page->_get_raw_body();
                        if (!empty($this->pi['#description'])) {
                            $desc = $this->pi['#description'];
                        } else {
                            $cut_size = 2000;
                            if (!empty($DBInfo->get_description_cut_size)) {
                                $cut_size = $DBInfo->get_description_cut_size;
                            }
                            $cut = mb_strcut($raw, 0, $cut_size, $DBInfo->charset);
                            $desc = get_description($cut);
                            if ($desc !== false) {
                                $desc = mb_strcut($desc, 0, 200, $DBInfo->charset) . '...';
                            } else {
                                $desc = $this->page->name;
                            }
                        }
                    }
                    $val['description'] = _html_escape($desc);
                    if (!empty($this->pi['#image'])) {
                        if (preg_match('@^(ftp|https?)://@', $this->pi['#image'])) {
                            $page_image = $this->pi['#image'];
                        } else {
                            if (preg_match('@^attachment:("[^"]+"|[^\\s]+)@/', $this->pi['#image'], $m)) {
                                $image = $this->macro_repl('attachment', $m[1], array('link_url' => 1));
                                if ($image[0] != 'a') {
                                    $page_image = $image;
                                }
                            }
                        }
                    }
                    if (empty($page_image)) {
                        // extract the first image
                        $punct = '<>"\'}\\]\\|\\!';
                        if (preg_match_all('@(?<=\\b)((?:attachment:(?:"[^' . $punct . ']+"|[^\\s' . $punct . '?]+)|' . '(?:https?|ftp)://(?:[^\\s' . $punct . ']+)\\.(?:png|jpe?g|gif)))@', $raw, $m)) {
                            foreach ($m[1] as $img) {
                                if ($img[0] == 'a') {
                                    $img = substr($img, 11);
                                    // strip attachment:
                                    $image = $this->macro_repl('attachment', $img, array('link_url' => 1));
                                    if ($image[0] != 'a' && preg_match('@\\.(png|jpe?g|gif)$@i', $image)) {
                                        $page_image = $image;
                                        break;
                                    }
                                } else {
                                    $page_image = $img;
                                    break;
                                }
                            }
                        }
                    }
                    if (empty($page_image) && $is_frontpage) {
                        $val['image'] = qualifiedUrl($DBInfo->logo_img);
                    } else {
                        if (!empty($page_image)) {
                            $val['image'] = $page_image;
                        }
                    }
                    $oc->update($this->page->name, $val, time());
                }
                if (empty($this->no_ogp)) {
                    // for OpenGraph
                    echo '<meta property="og:url" content="' . $page_url . '" />', "\n";
                    echo '<meta property="og:site_name" content="' . $sitename . '" />', "\n";
                    echo '<meta property="og:title" content="' . $options['title'] . '" />', "\n";
                    if ($is_frontpage) {
                        echo '<meta property="og:type" content="website" />', "\n";
                    } else {
                        echo '<meta property="og:type" content="article" />', "\n";
                    }
                    if (!empty($val['image'])) {
                        echo '<meta property="og:image" content="', $val['image'], '" />', "\n";
                    }
                    if (!empty($val['description'])) {
                        echo '<meta property="og:description" content="' . $val['description'] . '" />', "\n";
                    }
                }
                // twitter card
                echo '<meta name="twitter:card" content="summary" />', "\n";
                if (!empty($DBInfo->twitter_id)) {
                    echo '<meta name="twitter:site" content="', $DBInfo->twitter_id, '">', "\n";
                }
                echo '<meta name="twitter:domain" content="', $sitename, '" />', "\n";
                echo '<meta name="twitter:title" content="', $options['title'], '">', "\n";
                echo '<meta name="twitter:url" content="', $page_url, '">', "\n";
                if (!empty($val['description'])) {
                    echo '<meta name="twitter:description" content="' . $val['description'] . '" />', "\n";
                }
                if (!empty($val['image'])) {
                    echo '<meta name="twitter:image:src" content="', $val['image'], '" />', "\n";
                }
                // support google sitelinks serachbox
                if (!empty($DBInfo->use_google_sitelinks)) {
                    if ($is_frontpage) {
                        if (!empty($DBInfo->canonical_url)) {
                            $site_url = $DBInfo->canonical_url;
                        } else {
                            $site_url = qualifiedUrl($this->link_url(''));
                        }
                        echo <<<SITELINK
<script type='application/ld+json'>
{"@context":"http://schema.org",
 "@type":"WebSite",
 "url":"{$site_url}",
 "name":"{$sitename}",
 "potentialAction":{
  "@type":"SearchAction",
  "target":"{$site_url}?goto={search_term}",
  "query-input":"required name=search_term"
 }
}
</script>

SITELINK;
                    }
                }
                echo <<<SCHEMA
<script type='application/ld+json'>
{"@context":"http://schema.org",
 "@type":"WebPage",
 "url":"{$page_url}",
 "dateModified":"{$modified}",
 "name":"{$options['title']}"
}
</script>

SCHEMA;
                if (!empty($val['description'])) {
                    echo '<meta name="description" content="' . $val['description'] . '" />', "\n";
                }
            }
            echo '  <title>', $site_title, "</title>\n";
            echo '  <link rel="canonical" href="', $page_url, '" />', "\n";
            # echo '<meta property="og:title" content="'.$options['title'].'" />',"\n";
            if (!empty($upper)) {
                echo '  <link rel="Up" href="', $this->link_url($upper), "\" />\n";
            }
            $raw_url = $this->link_url($this->page->urlname, "?action=raw");
            $print_url = $this->link_url($this->page->urlname, "?action=print");
            echo '  <link rel="Alternate" title="Wiki Markup" href="', $raw_url, "\" />\n";
            echo '  <link rel="Alternate" media="print" title="Print View" href="', $print_url, "\" />\n";
            $css_html = '';
            if ($options['css_url']) {
                $stamp = '?' . filemtime(__FILE__);
                $css_url = _html_escape($options['css_url']);
                $css_html = '  <link rel="stylesheet" type="text/css" ' . $media . ' href="' . $css_url . "\" />\n";
                if (!empty($DBInfo->custom_css) && file_exists($DBInfo->custom_css)) {
                    $css_html .= '  <link rel="stylesheet" media="screen" type="text/css" href="' . $DBInfo->url_prefix . '/' . $DBInfo->custom_css . "{$stamp}\" />\n";
                } else {
                    if (file_exists('./css/_user.css')) {
                        $css_html .= '  <link rel="stylesheet" media="screen" type="text/css" href="' . $DBInfo->url_prefix . "/css/_user.css{$stamp}\" />\n";
                    }
                }
            }
            echo kbd_handler(!empty($options['prefix']) ? $options['prefix'] : '');
            if (isset($this->_newtheme) and $this->_newtheme == 2 or isset($options['retstr'])) {
                $ret = ob_get_contents();
                ob_end_clean();
                if (isset($options['retstr'])) {
                    $options['retstr'] = $ret;
                }
                $this->header_html = $ret;
                $this->css_html = $css_html;
            } else {
                echo $css_html;
                echo "</head>\n";
            }
        }
        return true;
    }
Beispiel #7
0
function do_man_get($formatter, $options)
{
    global $DBInfo;
    $supported = array('C', 'bg', 'de', 'en', 'fr', 'hu', 'ja', 'pt', 'ru', 'sr', 'cs', 'de_DE', 'es', 'fr_FR', 'id', 'ko', 'nl', 'pt_BR', 'sk', 'sv', 'da', 'el', 'fi', 'hr', 'it', 'pl', 'ro', 'sl');
    if (!$options['man']) {
        $options['title'] = _("No manpage selected");
        do_invalid($formatter, $options);
        return;
    }
    $LANG = '';
    if ($options['lang'] and in_array($options['lang'], $supported)) {
        $LANG = 'LANG=' . $options['lang'];
    }
    if ($options['sec'] != intval($options['sec'])) {
        unset($options['sec']);
    }
    $cmd = $LANG . " man {$options['sec']} -a -w {$options['man']}";
    $formatter->errlog();
    $fp = popen(escapeshellcmd($cmd) . $formatter->LOG, 'r');
    if (is_resource($fp)) {
        $fnames = array();
        while ($l = fgets($fp, 1024)) {
            if (preg_match('/\\.gz$/', $l)) {
                $fnames[] = trim($l);
            }
        }
        pclose($fp);
    }
    $err = $formatter->get_errlog();
    if ($err) {
        $err = '<pre class="errlog">' . $err . '</pre>';
    }
    if (!$fnames) {
        $options['title'] = _("No manpage found");
        $options['msg'] = $err;
        // XXX
        do_invalid($formatter, $options);
        return;
    }
    $sz = count($fnames);
    $man = array();
    if ($sz >= 1) {
        foreach ($fnames as $fname) {
            $man[] = $tmp = preg_replace("/\\.gz\$/", "", basename($fname));
        }
        $options['page'] = "ManPage/{$man['0']}";
        $fname = $fnames[0];
    }
    if ($DBInfo->hasPage($options['page'])) {
        $options['value'] = $options['page'];
        do_goto($formatter, $options);
        return;
    }
    if (function_exists('gzfile')) {
        $raw = gzfile($fname);
        $raw = join('', $raw);
    } else {
        exec("zcat {$fname}", $raw);
        $raw = join("\n", $raw);
    }
    if ($sz > 1) {
        $lnk = array();
        foreach ($fnames as $f) {
            $tmp = preg_match("@/([^/]+)?/man./([^/]+).(.)\\.gz\$@", $f, $m);
            $lang = 'en';
            if ($m) {
                if ($m[1] != 'man') {
                    $lang = $m[1];
                }
                $myman = $m[2];
                $mysec = $m[3];
                $tag = '';
                if ($lang) {
                    $tag = $lang == 'ko' ? '(' . $lang . ')' : '';
                    $lang = '&amp;lang=' . $lang;
                }
                $lnk[] = $formatter->link_tag('ManPage/' . $myman . '.' . $mysec, '?action=man_get&amp;man=' . $myman . '&amp;sec=' . $mysec . $lang, $myman . '.' . $mysec) . $tag;
            }
        }
        if (sizeof($lnk) > 0) {
            $options['msgtitle'] = implode(', ', $lnk);
        }
    }
    if ($DBInfo->man_charset and $DBInfo->man_charset != $DBInfo->charset) {
        if (function_exists('iconv')) {
            $ignore = '//IGNORE';
            // XXX
            $raw = iconv($DBInfo->man_charset, $DBInfo->charset . $ignore, $raw);
        }
    }
    if ($DBInfo->man_filter) {
        $raw = $formatter->filter_repl('simplere', $raw, array('page' => $DBInfo->man_filter));
    }
    $options['savetext'] = $raw;
    if ($options['edit']) {
        $formatter->send_header("", $options);
        $formatter->send_title("", "", $options);
        print macro_EditText($formatter, $raw, $options);
    } else {
        if ($options['raw']) {
            $formatter->send_header("content-type: text/plain", $options);
            print $raw;
            return;
        } else {
            $formatter->send_header("", $options);
            $formatter->send_title("", "", $options);
            print $formatter->processor_repl('man', $raw, $options);
            $extra = '';
            if ($options['sec']) {
                $extra = '&amp;sec=' . $options['sec'];
            }
            if ($options['lang']) {
                $extra = '&amp;lang=' . $options['lang'];
            }
            $formatter->actions[] = '?action=man_get&man=' . $options['man'] . $extra . '&amp;edit=1 ' . _("Edit man page");
        }
    }
    $formatter->send_footer('', $options);
    return;
    // vim:et:sts=4:
}
Beispiel #8
0
function do_post_rcsimport($formatter, $options)
{
    global $DBInfo;
    if (empty($DBInfo->version_class)) {
        $msg = _("Version info is not available in this wiki");
        return "<h2>{$msg}</h2>";
    }
    if (empty($options['rcsfile']) or !trim($options['rcsfile'])) {
        $formatter->send_header('', $options);
        $formatter->send_title('', '', $options);
        $COLS_MSIE = 80;
        $COLS_OTHER = 85;
        $cols = preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT']) ? $COLS_MSIE : $COLS_OTHER;
        print <<<FORM
<form method='post' action=''>
<div>
<textarea name='rcsfile' class='' cols='{$cols}' rows='20'>
</textarea></div>
<input type='hidden' name='action' value='rcsimport' />
FORM;
        if ($DBInfo->security->is_protected("rcsimport", $options)) {
            print _("Password") . ": <input type='password' name='passwd' /> ";
        }
        print <<<FORM
<input type='submit' value='Import RCS' />
</form>
FORM;
        $formatter->send_footer('', $options);
        return;
    }
    $version = $DBInfo->lazyLoad('version', $DBInfo);
    header('Content-type:text/plain');
    if (method_exists($version, 'import')) {
        $body = $options['rcsfile'];
        $meta = array();
        while (!empty($body)) {
            list($line, $body) = explode("\n", $body, 2);
            if (!trim($line)) {
                continue;
            }
            if (preg_match('/^#(.*)$/', $line, $m)) {
                $p = strpos($line, ' ');
                if ($p !== false) {
                    $tag = substr($line, 0, $p);
                    $val = substr($line, $p + 1);
                    if (in_array($tag, array('#title', '#charset', '#encrypt'))) {
                        $meta[$tag] = $val;
                    }
                }
            } else {
                $body = $line . "\n" . $body;
                break;
            }
        }
        if (isset($meta['#title']) or isset($meta['#charset'])) {
            $title = isset($meta['#title']) ? $meta['#title'] : $options['page'];
            $charset = $meta['#charset'];
            $formatter->send_header('', $options);
            $formatter->send_title('', '', $options);
            $COLS_MSIE = 80;
            $COLS_OTHER = 85;
            $cols = preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT']) ? $COLS_MSIE : $COLS_OTHER;
            $tmsg = _("Page name");
            print <<<FORM
<form method='post' action=''>
<div>
<textarea name='rcsfile' class='' cols='{$cols}' rows='20'>
{$body}
</textarea></div>
{$tmsg}: <input type='text' size='40' name='title' value='{$title}' /><br />
<input type='hidden' name='charset' value='{$charset}' />
<input type='hidden' name='action' value='rcsimport' />
FORM;
            if ($DBInfo->security->is_protected("rcsimport", $options)) {
                print _("Password") . ": <input type='password' name='passwd' /> ";
            }
            print <<<FORM
<input type='submit' value='Import RCS' />
</form>
FORM;
            $formatter->send_footer('', $options);
            return;
        }
        if (!empty($body)) {
            $body = base64_decode($body);
        }
        $read = '';
        while (!empty($body)) {
            list($line, $body) = explode("\n", $body, 2);
            if (preg_match('/^\\s+(.*):(\\d+\\.\\d+);\\s*(strict;)?$/', $line, $m)) {
                $line = "\t" . $DBInfo->rcs_user . ':' . $m[2] . ';';
                $read .= $line . "\n";
                break;
            }
            $read .= $line . "\n";
        }
        $content = $read . $body;
        if (!empty($options['title'])) {
            $options['page'] = $options['title'];
        }
        if ($options['charset'] and strcasecmp($options['charset'], $DBInfo->charset) != 0 and function_exists('iconv')) {
            $t = @iconv($options['charset'], $DBInfo->charset, $content);
            if (!empty($t)) {
                $content = $t;
            }
        }
        if (isset($content[0])) {
            $test = $version->import($options['page'], $content);
        }
        $options['value'] = $options['page'];
        do_goto($formatter, $options);
        return;
    }
}