installer changes, pe sync

This commit is contained in:
Mike Macgirvin 2010-08-15 21:49:29 -07:00
parent 7294a3aab1
commit 35e29e10e6
15 changed files with 345 additions and 77 deletions

View File

@ -43,10 +43,10 @@ class App {
public $module;
public $pager;
public $strings;
public $path;
private $scheme;
private $hostname;
private $path;
private $baseurl;
private $db;

View File

@ -10,7 +10,7 @@ if((x($_SESSION,'authenticated')) && (! ($_POST['auth-params'] == 'login'))) {
unset($_SESSION['is_visitor']);
unset($_SESSION['administrator']);
unset($_SESSION['cid']);
$_SESSION['sysmsg'] = t("Logged out.") . EOL;
notice( t('Logged out.') . EOL);
goaway($a->get_baseurl());
}
if(x($_SESSION,'uid')) {
@ -50,7 +50,7 @@ else {
dbesc(trim($_POST['login-name'])),
dbesc($encrypted));
if(($r === false) || (! count($r))) {
$_SESSION['sysmsg'] = t('Login failed.') . EOL ;
notice( t('Login failed.') . EOL );
goaway($a->get_baseurl());
}
$_SESSION['uid'] = $r[0]['uid'];
@ -58,7 +58,7 @@ else {
$_SESSION['authenticated'] = 1;
$_SESSION['my_url'] = $a->get_baseurl() . '/profile/' . $r[0]['nickname'];
$_SESSION['sysmsg'] = t("Welcome back ") . $r[0]['username'] . EOL;
notice( t("Welcome back ") . $r[0]['username'] . EOL);
$a->user = $r[0];
if(strlen($a->user['timezone']))
date_default_timezone_set($a->user['timezone']);

View File

@ -8,8 +8,8 @@ function timezone_cmp($a, $b) {
}
if(strstr($a,'/')) return -1;
if(strstr($b,'/')) return 1;
if ($a == $b) return 0;
return ($a < $b) ? -1 : 1;
if ( t($a) == t($b)) return 0;
return ( t($a) < t($b)) ? -1 : 1;
}}
@ -29,7 +29,7 @@ function select_timezone($current = 'America/Los_Angeles') {
if($continent != '')
$o .= '</optgroup>';
$continent = $ex[0];
$o .= "<optgroup label=\"$continent\">";
$o .= '<optgroup label="' . t($continent) . '">';
}
if(count($ex) > 2)
$city = substr($value,strpos($value,'/')+1);
@ -41,10 +41,10 @@ function select_timezone($current = 'America/Los_Angeles') {
if($continent != 'Miscellaneous') {
$o .= '</optgroup>';
$continent = 'Miscellaneous';
$o .= "<optgroup label=\"$continent\">";
$o .= '<optgroup label="' . t($continent) . '">';
}
}
$city = str_replace('_', ' ', $city);
$city = str_replace('_', ' ', t($city));
$selected = (($value == $current) ? " selected=\"selected\" " : "");
$o .= "<option value=\"$value\" $selected >$city</option>";
}
@ -101,56 +101,36 @@ function datesel($pre,$ymin,$ymax,$allow_blank,$y,$m,$d) {
}}
// TODO rewrite this buggy sucker
if(! function_exists('relative_date')) {
function relative_date($posted_date) {
$localtime = datetime_convert('UTC',date_default_timezone_get(),$posted_date);
$abs = strtotime($localtime);
$etime = time() - $abs;
$in_seconds = strtotime($localtime);
$diff = time() - $in_seconds;
if ($etime < 1) {
return t('less than a second ago');
}
$months = floor($diff/2592000);
$diff -= $months*2419200;
$weeks = floor($diff/604800);
$diff -= $weeks*604800;
$days = floor($diff/86400);
$diff -= $days*86400;
$hours = floor($diff/3600);
$diff -= $hours*3600;
$minutes = floor($diff/60);
$diff -= $minutes*60;
$seconds = $diff;
if($months > 2)
return(datetime_convert('UTC',date_default_timezone_get(),$posted_date,'\o\n Y-m-d \a\t H:i:s'));
if ($months>0) {
// over a month old,
return 'over a month ago';
} else {
if ($weeks>0) {
// weeks and days
$relative_date .= ($relative_date?', ':'').$weeks.' week'.($weeks!=1 ?'s':'');
} elseif ($days>0) {
// days and hours
$relative_date .= ($relative_date?', ':'').$days.' day'.($days!=1?'s':'');
} elseif ($hours>0) {
// hours and minutes
$relative_date .= ($relative_date?', ':'').$hours.' hour'.($hours!=1?'s':'');
} elseif ($minutes>0) {
// minutes only
$relative_date .= ($relative_date?', ':'').$minutes.' minute'.($minutes!=1?'s':'');
} else {
// seconds only
$relative_date .= ($relative_date?', ':'').$seconds.' second'.($seconds!=1?'s':'');
$a = array( 12 * 30 * 24 * 60 * 60 => array( t('year'), t('years')),
30 * 24 * 60 * 60 => array( t('month'), t('months')),
7 * 24 * 60 * 60 => array( t('week'), t('weeks')),
24 * 60 * 60 => array( t('day'), t('days')),
60 * 60 => array( t('hour'), t('hours')),
60 => array( t('minute'), t('minutes')),
1 => array( t('second'), t('seconds'))
);
foreach ($a as $secs => $str) {
$d = $etime / $secs;
if ($d >= 1) {
$r = round($d);
return $r . ' ' . (($r == 1) ? $str[0] : $str[1]) . t(' ago');
}
}
// show relative date and add proper verbiage
return $relative_date.' ago';
}
}}
function age($dob,$owner_tz = '',$viewer_tz = '') {
if(! intval($dob))

View File

@ -20,6 +20,10 @@ class dba {
system_unavailable();
}
public function getdb() {
return $this->db;
}
public function q($sql) {
global $debug_text;

View File

@ -15,7 +15,9 @@ require_once("dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data, $install);
unset($db_host, $db_user, $db_pass, $db_data);
require_once("session.php");
if(! $install)
require_once("session.php");
require_once("datetime.php");
date_default_timezone_set(($default_timezone) ? $default_timezone : 'UTC');
@ -101,7 +103,8 @@ $a->page['content'] .= $debug_text;
// build page
// Navigation (menu) template
require_once("nav.php");
if($a->module != 'install')
require_once("nav.php");
$page = $a->page;
$profile = $a->profile;

View File

@ -170,8 +170,9 @@ function dfrn_notify_post(&$a) {
);
$url = $a->get_baseurl();
$php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
proc_close(proc_open("php include/notifier.php $url comment-import $posted_id > remote-notify.log &",
proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"$url\" \"comment-import\" \"$posted_id\" &",
array(),$foo));
if(($importer['notify-flags'] & NOTIFY_COMMENT) && (! $importer['self'])) {

View File

@ -34,7 +34,7 @@ function dfrn_poll_init(&$a) {
if((int) $xml->status == 1) {
$_SESSION['authenticated'] = 1;
$_SESSION['visitor_id'] = $r[0]['id'];
$_SESSION['sysmsg'] .= "Hi {$r[0]['name']}" . EOL;
notice( t('Hi ') . $r[0]['name'] . EOL);
// Visitors get 1 day session.
$session_id = session_id();
$expire = time() + 86400;

153
mod/install.php Normal file
View File

@ -0,0 +1,153 @@
<?php
function install_post(&$a) {
global $db;
$dbhost = notags(trim($_POST['dbhost']));
$dbuser = notags(trim($_POST['dbuser']));
$dbpass = notags(trim($_POST['dbpass']));
$dbdata = notags(trim($_POST['dbdata']));
$timezone = notags(trim($_POST['timezone']));
$phpath = notags(trim($_POST['phpath']));
require_once("dba.php");
$db = new dba($dbhost, $dbuser, $dbpass, $dbdata, $true);
if(! $db->getdb()) {
notice( t('Could not connect to database.') . EOL);
return;
}
else
notice( t('Connected to database.') . EOL);
$tpl = file_get_contents('view/htconfig.tpl');
$txt = replace_macros($tpl,array(
'$dbhost' => $dbhost,
'$dbuser' => $dbuser,
'$dbpass' => $dbpass,
'$dbdata' => $dbdata,
'$timezone' => $timezone,
'$phpath' => $phpath
));
$result = file_put_contents('.htconfig.php', $txt);
if(! $result) {
$a->data = $txt;
}
$errors = load_database($db);
if(! $errors) {
// Our sessions normally are stored in the database. But as we have only managed
// to get it bootstrapped milliseconds ago, we have to apply a bit of trickery so
// that you'll see the following important notice (which is stored in the session).
session_write_close();
require_once('session.php');
session_start();
$_SESSION['sysmsg'] = '';
notice( t('Database import succeeded.') . EOL
. t('IMPORTANT: You will need to (manually) setup a scheduled task for the poller.') . EOL
. t('Please see the file INSTALL.') . EOL );
goaway($a->get_baseurl());
}
else {
$db = null; // start fresh
notice( t('Database import failed.') . EOL
. t('You may need to import the file "database.sql" manually using phpmyadmin or mysql.') . EOL
. t('Please see the file INSTALL.') . EOL );
}
}
function install_content(&$a) {
notice( t('Welcome to the Mistpark Social Network.') . EOL);
$o .= check_htconfig();
if(strlen($o))
return $o;
if(strlen($a->data)) {
$o .= manual_config($a);
return;
}
$o .= check_php($phpath);
require_once('datetime.php');
$tpl = file_get_contents('view/install_db.tpl');
$o .= replace_macros($tpl, array(
'$tzselect' => ((x($_POST,'timezone')) ? select_timezone($_POST['timezone']) : select_timezone()),
'$submit' => t('Submit'),
'$dbhost' => ((x($_POST,'dbhost')) ? notags(trim($_POST['dbhost'])) : 'localhost'),
'$dbuser' => notags(trim($_POST['dbuser'])),
'$dbpass' => notags(trim($_POST['dbpass'])),
'$dbdata' => notags(trim($_POST['dbdata'])),
'$phpath' => $phpath
));
return $o;
}
function check_php(&$phpath) {
$phpath = trim(shell_exec('which php'));
if(! strlen($phpath)) {
$o .= <<< EOT
Could not find a command line version of PHP in the web server PATH. This is required. Please adjust the configuration file .htconfig.php accordingly.
EOT;
}
return $o;
}
function check_htconfig() {
if(((file_exists('.htconfig.php')) && (! is_writable('.htconfig.php')))
|| (! is_writable('.'))) {
$o .= <<< EOT
The web installer needs to be able to create a file called ".htconfig.php" in the top folder of
your web server. It is unable to do so. This is most often a permission setting, as the web server
may not be able to write files in your folder (even if you can).
Please check with your site documentation or support people to see if this situation can be corrected.
If not, you may be required to perform a manual installation. Please see the file "INSTALL" for instructions.
EOT;
}
return $o;
}
function manual_config(&$a) {
$o .= <<< EOT
The database configuration file ".htconfig.php" could not be written. Please use the enclosed text to create a configuration file in your web server root.
<textarea rows="24" cols="80" >{$a->data}</textarea>
EOT;
return $o;
}
function load_database($db) {
$str = file_get_contents('database.sql');
$arr = explode(';',$str);
$errors = 0;
foreach($arr as $a) {
if(strlen(trim($a))) {
$r = @$db->q(trim($a));
if(! $r) {
notice( t('Errors encountered creating database tables.') . $a . EOL);
$errors ++;
}
}
}
return $errors;
}

View File

@ -239,8 +239,9 @@ function item_post(&$a) {
}
}
$url = $a->get_baseurl();
$php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
proc_close(proc_open("php include/notifier.php \"$url\" \"$notify_type\" \"$post_id\" > notify.log &",
proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"$url\" \"$notify_type\" \"$post_id\" &",
array(),$foo));
goaway($a->get_baseurl() . "/" . $_POST['return'] );
@ -308,10 +309,11 @@ function item_content(&$a) {
$url = $a->get_baseurl();
$drop_id = intval($item['id']);
$php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
// send the notification upstream/downstream as the case may be
proc_close(proc_open("php include/notifier.php \"$url\" \"drop\" \"$drop_id\" > notify.log &",
proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"$url\" \"drop\" \"$drop_id\" &",
array(),$foo));
goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);

View File

@ -68,9 +68,10 @@ function message_post(&$a) {
$post_id = $r[0]['id'];
$url = $a->get_baseurl();
$php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
if($post_id) {
proc_close(proc_open("php include/notifier.php \"$url\" \"mail\" \"$post_id\" > mail.log &",
proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"$url\" \"mail\" \"$post_id\" &",
array(),$foo));
notice( t('Message sent.') . EOL );
}
@ -135,7 +136,9 @@ function message_content(&$a) {
if(($a->argc > 2) && ($a->argv[1] == 'redeliver') && intval($a->argv[2])) {
$url = $a->get_baseurl();
$post_id = intval($a->argv[2]);
proc_close(proc_open("php include/notifier.php \"$url\" \"mail\" \"$post_id\" > mail.log &",
$php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"$url\" \"mail\" \"$post_id\" &",
array(),$foo));
goaway($a->get_baseurl() . '/message' );
}

View File

@ -2,11 +2,11 @@
function notifications_post(&$a) {
if((! x($_SESSION,'authenticated')) || (! (x($_SESSION,'uid')))) {
if(! local_user()) {
goaway($a->get_baseurl());
}
$request_id = (($a->argc > 1) ? $a->argv[0] : 0);
$request_id = (($a->argc > 1) ? $a->argv[1] : 0);
if($request_id == "all")
return;
@ -24,17 +24,17 @@ function notifications_post(&$a) {
$intro_id = $r[0]['id'];
}
else {
$_SESSION['sysmsg'] .= "Invalid request identifier." . EOL;
notice( t('Invalid request identifier.') . EOL);
return;
}
if($_POST['submit'] == 'Discard') {
if($_POST['submit'] == t('Discard'() {
$r = q("DELETE FROM `intro` WHERE `id` = %d LIMIT 1", intval($intro_id));
$r = q("DELETE `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($request_id),
intval($_SESSION['uid']));
return;
}
if($_POST['submit'] == 'Ignore') {
if($_POST['submit'] == t('Ignore')) {
$r = q("UPDATE `intro` SET `ignore` = 1 WHERE `id` = %d LIMIT 1",
intval($intro_id));
return;
@ -48,12 +48,13 @@ function notifications_post(&$a) {
function notifications_content(&$a) {
$o = '';
if((! x($_SESSION,'authenticated')) || (! (x($_SESSION,'uid')))) {
if(! local_user()) {
notice( t('Permission denied.') . EOL);
goaway($a->get_baseurl());
}
$o = '';
if(($a->argc > 1) && ($a->argv[1] == 'all'))
$sql_extra = '';
else
@ -63,7 +64,7 @@ function notifications_content(&$a) {
$tpl = file_get_contents('view/intros-top.tpl');
$o .= replace_macros($tpl,array(
'$hide_url' => ((strlen($sql_extra)) ? 'notifications/all' : 'notifications' ),
'$hide_text' => ((strlen($sql_extra)) ? 'Show Ignored Requests' : 'Hide Ignored Requests')
'$hide_text' => ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests'))
));
$r = q("SELECT `intro`.`id` AS `intro-id`, `intro`.*, `contact`.*
@ -85,14 +86,14 @@ function notifications_content(&$a) {
'$contact-id' => $rr['contact-id'],
'$photo' => ((x($rr,'photo')) ? $rr['photo'] : "images/default-profile.jpg"),
'$fullname' => $rr['name'],
'$knowyou' => (($rr['knowyou']) ? 'yes' : 'no'),
'$knowyou' => (($rr['knowyou']) ? t('yes') : t('no')),
'$url' => $rr['url'],
'$note' => $rr['note']
));
}
}
else
$_SESSION['sysmsg'] .= "No notifications." . EOL;
notice( t('No notifications.') . EOL);
return $o;
}

View File

@ -124,11 +124,12 @@ function photos_post(&$a) {
$url = $a->get_baseurl();
$drop_id = intval($rr['id']);
$php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
// send the notification upstream/downstream as the case may be
if($rr['visible'])
proc_close(proc_open("php include/notifier.php \"$url\" \"drop\" \"$drop_id\" & ",
proc_close(proc_open("\"php_path\" \"include/notifier.php\" \"$url\" \"drop\" \"$drop_id\" & ",
array(),$foo));
}
@ -160,11 +161,12 @@ function photos_post(&$a) {
$url = $a->get_baseurl();
$drop_id = intval($i[0]['id']);
$php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
// send the notification upstream/downstream as the case may be
if($i[0]['visible'])
proc_close(proc_open("php include/notifier.php \"$url\" \"drop\" \"$drop_id\" & ",
proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"$url\" \"drop\" \"$drop_id\" & ",
array(),$foo));
}
}

44
view/htconfig.tpl Normal file
View File

@ -0,0 +1,44 @@
<?php
// Set the following for your MySQL installation
// Copy or rename this file to .htconfig.php
$db_host = '$dbhost';
$db_user = '$dbuser';
$db_pass = '$dbpass';
$db_data = '$dbdata';
// If you are using a subdirectory of your domain you will need to put the
// relative path (from the root of your domain) here.
// For instance if your URL is 'http://example.com/directory/subdirectory',
// set $a->path to 'directory/subdirectory'.
$a->path = '';
// Choose a legal default timezone. If you are unsure, use "America/Los_Angeles".
// It can be changed later and only applies to timestamps for anonymous viewers.
$default_timezone = '$timezone';
// What is your site name?
$a->config['sitename'] = "My Friend Network";
// Your choices are REGISTER_OPEN, REGISTER_APPROVE, or REGISTER_CLOSED.
// Be certain to create your own personal account before setting
// REGISTER_CLOSED. 'register_text' (if set) will be displayed prominently on
// the registration page. REGISTER_APPROVE requires you set 'admin_email'
// to the email address of an already registered person who can authorise
// and/or approve/deny the request.
$a->config['register_policy'] = REGISTER_OPEN;
$a->config['register_text'] = '';
$a->config['admin_email'] = '';
// Maximum size of an imported message, 0 is unlimited (but our database 'text' element is limited to 65535).
$a->config['max_import_size'] = 65535;
// Location of PHP command line processor
$a->config['php_path'] = '$phpath';

40
view/install_db.tpl Normal file
View File

@ -0,0 +1,40 @@
<h3>Mistpark Personal Edition</h3>
<h3>Installation</h3>
<p>
In order to install Mistpark we need to know how to contact your database. Please contact your hosting provider or site administrator if you have questions about these settings. The database you specify below must already exist. If it does not, please create it before continuing.
</p>
<form id="install-form" action="install" method="post">
<input type="hidden" name="phpath" value="$phpath" />
<label for="install-dbhost" id="install-dbhost-label">Database Server Name</label>
<input type="text" name="dbhost" id="install-dbhost" value="$dbhost" />
<div id="install-dbhost-end"></div>
<label for="install-dbuser" id="install-dbuser-label">Database Login Name</label>
<input type="text" name="dbuser" id="install-dbuser" value="$dbuser" />
<div id="install-dbuser-end"></div>
<label for="install-dbpass" id="install-dbpass-label">Database Login Password</label>
<input type="password" name="dbpass" id="install-dbpass" value="$dbpass" />
<div id="install-dbpass-end"></div>
<label for="install-dbdata" id="install-dbdata-label">Database Name</label>
<input type="text" name="dbdata" id="install-dbdata" value="$dbdata" />
<div id="install-dbdata-end"></div>
<div id="install-tz-desc">
Please select a default timezone for your website
</div>
$tzselect
<div id="install-tz-end" ></div>
<input id="install-submit" type="submit" name="submit" value="$submit" />
</form>
<div id="install-end" ></div>

View File

@ -1457,4 +1457,39 @@ input#dfrn-url {
.group-delete-wrapper {
float: right;
margin-right: 50px;
}
}
#install-dbhost-label,
#install-dbuser-label,
#install-dbpass-label,
#install-dbdata-label,
#install-tz-desc {
float: left;
width: 250px;
margin-top: 10px;
margin-bottom: 10px;
}
#install-dbhost,
#install-dbuser,
#install-dbpass,
#install-dbdata {
float: left;
width: 200px;
margin-left: 20px;
}
#install-dbhost-end,
#install-dbuser-end,
#install-dbpass-end,
#install-dbdata-end,
#install-tz-end {
clear: both;
}
#install-form select#timezone_select {
float: left;
margin-top: 18px;
margin-left: 20px;
}