diff options
-rwxr-xr-x | boot.php | 3 | ||||
-rw-r--r-- | include/ItemObject.php | 20 | ||||
-rw-r--r-- | include/conversation.php | 30 | ||||
-rwxr-xr-x | include/dba/dba_driver.php | 8 | ||||
-rw-r--r-- | include/externals.php | 2 | ||||
-rw-r--r-- | include/poller.php | 55 | ||||
-rw-r--r-- | install/migrate-mypg.php | 306 | ||||
-rw-r--r-- | install/migrate_mypg_fixseq.sql | 55 | ||||
-rw-r--r-- | mod/channel.php | 8 | ||||
-rw-r--r-- | mod/home.php | 48 | ||||
-rw-r--r-- | mod/network.php | 222 | ||||
-rw-r--r-- | mod/settings.php | 10 | ||||
-rw-r--r-- | version.inc | 2 | ||||
-rw-r--r-- | view/js/main.js | 33 | ||||
-rwxr-xr-x | view/tpl/conv_list.tpl | 175 | ||||
-rwxr-xr-x | view/tpl/settings_display.tpl | 2 |
16 files changed, 774 insertions, 205 deletions
@@ -567,7 +567,8 @@ define ( 'ITEM_VERIFIED', 0x2000); // Signature verification was success define ( 'ITEM_RETAINED', 0x4000); // We looked at this item once to decide whether or not to expire it, and decided not to. define ( 'ITEM_RSS', 0x8000); // Item comes from a feed. Use this to decide whether to link the title // Don't make us evaluate this same item again. -define ( 'DBTYPE_MYSQL', 0 ); + +define ( 'DBTYPE_MYSQL', 0 ); define ( 'DBTYPE_POSTGRES', 1 ); /** diff --git a/include/ItemObject.php b/include/ItemObject.php index 9e694b8ac..4aa6857c1 100644 --- a/include/ItemObject.php +++ b/include/ItemObject.php @@ -28,6 +28,7 @@ class Item extends BaseObject { private $threaded = false; private $visiting = false; private $channel = null; + private $display_mode = 'normal'; public function __construct($data) { @@ -226,9 +227,10 @@ class Item extends BaseObject { if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0) $indent .= ' shiny'; - localize_item($item); + localize_item($item); $body = prepare_body($item,true); + $comment_count_txt = sprintf( tt('%d comment','%d comments',$total_children),$total_children ); $children = $this->get_children(); @@ -243,6 +245,7 @@ class Item extends BaseObject { 'id' => $this->get_id(), 'linktitle' => sprintf( t('View %s\'s profile - %s'), $profile_name, $item['author']['xchan_addr']), 'olinktitle' => sprintf( t('View %s\'s profile - %s'), $this->get_owner_name(), $item['owner']['xchan_addr']), + 'llink' => $item['llink'], 'to' => t('to'), 'via' => t('via'), 'wall' => t('Wall-to-Wall'), @@ -315,7 +318,8 @@ class Item extends BaseObject { $result['children'] = array(); $nb_children = count($children); - if($nb_children > 0) { + + if(($this->get_display_mode() === 'normal') && ($nb_children > 0)) { foreach($children as $child) { $result['children'][] = $child->get_template_data($alike, $dlike, $thread_level + 1); } @@ -352,6 +356,14 @@ class Item extends BaseObject { return $this->get_data_value('id'); } + public function get_display_mode() { + return $this->display_mode; + } + + public function set_display_mode($mode) { + $this->display_mode = $mode; + } + public function is_threaded() { return $this->threaded; } @@ -503,12 +515,12 @@ class Item extends BaseObject { /** * Get template */ - private function get_template() { + public function get_template() { return $this->template; } - private function set_template($t) { + public function set_template($t) { $this->template = $t; } diff --git a/include/conversation.php b/include/conversation.php index af8780549..96864c29a 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -419,8 +419,6 @@ function visible_activity($item) { function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $prepared_item = '') { - $tstart = dba_timer(); - $t0 = $t1 = $t2 = $t3 = $t4 = $t5 = $t6 = null; $content_html = ''; $o = ''; @@ -452,8 +450,6 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ if($mode === 'network') { - $t1 = dba_timer(); - $profile_owner = local_user(); $page_writeable = true; @@ -790,29 +786,21 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ $item['pagedrop'] = $page_dropping; if($item['id'] == $item['parent']) { -// $tx1 = dba_timer(); + $item_object = new Item($item); $conv->add_thread($item_object); - if($page_mode === 'list') + if($page_mode === 'list') { $item_object->set_template('conv_list.tpl'); - -// $tx2 = dba_timer(); -// if($mode === 'network') -// profiler($tx1,$tx2,'add thread ' . $item['id']); + $item_object->set_display_mode('list'); + } } } - $t2 = dba_timer(); + $threads = $conv->get_template_data($alike, $dlike); if(!$threads) { logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG); $threads = array(); } - $t3 = dba_timer(); - if($mode === 'network') { - profiler($t1,$t2,'Conversation prepare'); - profiler($t2,$t3,'Conversation get_template'); - } - } } @@ -848,14 +836,6 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ '$dropping' => ($page_dropping?t('Delete Selected Items'):False), )); - if($mode === 'network') { - $t4 = dba_timer(); - profiler($t3,$t4,'conversation template'); - } - -// if($page_mode === 'preview') -// logger('preview: ' . $o, LOGGER_DATA); - return $o; } diff --git a/include/dba/dba_driver.php b/include/dba/dba_driver.php index 103dc8fcc..1bb45b06d 100755 --- a/include/dba/dba_driver.php +++ b/include/dba/dba_driver.php @@ -24,7 +24,10 @@ function dba_factory($server, $port,$user,$pass,$db,$dbtype,$install = false) { $dba = null; - if($dbtype == 1) { + + $dbtype = intval($dbtype); + + if($dbtype == DBTYPE_POSTGRES) { require_once('include/dba/dba_postgres.php'); if(is_null($port)) $port = 5432; $dba = new dba_postgres($server, $port, $user, $pass, $db, $install); @@ -39,6 +42,7 @@ function dba_factory($server, $port,$user,$pass,$db,$dbtype,$install = false) { $dba = new dba_mysql($server, $port,$user,$pass,$db,$install); } } + define('NULL_DATE', $dba->get_null_date()); define('ACTIVE_DBTYPE', $dbtype); return $dba; @@ -371,7 +375,7 @@ function db_getfunc($f) { if(isset($lookup[$f]) && isset($lookup[$f][ACTIVE_DBTYPE])) return $lookup[$f][ACTIVE_DBTYPE]; - logger('Unable to abstract DB function "'. $f . '"', LOG_DEBUG); + logger('Unable to abstract DB function "'. $f . '" for dbtype ' . ACTIVE_DBTYPE, LOGGER_DEBUG); return $f; } diff --git a/include/externals.php b/include/externals.php index 0be5d0fde..b0f853dc6 100644 --- a/include/externals.php +++ b/include/externals.php @@ -14,6 +14,8 @@ function externals_run($argv, $argc){ $total = 0; $attempts = 0; + logger('externals: startup', LOGGER_DEBUG); + // pull in some public posts diff --git a/include/poller.php b/include/poller.php index 952431926..e13c6829d 100644 --- a/include/poller.php +++ b/include/poller.php @@ -27,10 +27,11 @@ function poller_run($argv, $argc){ // Check for a lockfile. If it exists, but is over an hour old, it's stale. Ignore it. $lockfile = 'store/[data]/poller'; - if ((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 3600))) { - logger("poller: Already running"); + if((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 3600)) + && (! get_config('system','override_poll_lockfile'))) { + logger("poller: Already running"); return; - } + } // Create a lockfile. Needs two vars, but $x doesn't need to contain anything. file_put_contents($lockfile, $x); @@ -52,7 +53,7 @@ function poller_run($argv, $argc){ // expire any expired items $r = q("select id from item where expires != '%s' and expires < %s - and not ( item_restrict & %d )>0 ", + and ( item_restrict & %d ) = 0 ", dbesc(NULL_DATE), db_utcnow(), intval(ITEM_DELETED) @@ -69,7 +70,8 @@ function poller_run($argv, $argc){ // or dead entries. $r = q("select channel_id from channel where channel_dirdate < %s - INTERVAL %s", - db_utcnow(), db_quoteinterval('30 DAY') + db_utcnow(), + db_quoteinterval('30 DAY') ); if($r) { foreach($r as $rr) { @@ -82,7 +84,7 @@ function poller_run($argv, $argc){ // publish any applicable items that were set to be published in the future // (time travel posts) - $r = q("select id from item where ( item_restrict & %d )>0 and created <= %s ", + $r = q("select id from item where ( item_restrict & %d ) > 0 and created <= %s ", intval(ITEM_DELAYED_PUBLISH), db_utcnow() ); @@ -207,7 +209,8 @@ function poller_run($argv, $argc){ $r = q("select xchan_photo_l, xchan_hash from xchan where xchan_photo_l != '' and xchan_photo_m = '' and xchan_photo_date < %s - INTERVAL %s", - db_utcnow(), db_quoteinterval('1 DAY') + db_utcnow(), + db_quoteinterval('1 DAY') ); if($r) { require_once('include/photo/photo_driver.php'); @@ -253,13 +256,13 @@ function poller_run($argv, $argc){ } - $sql_extra = (($manual_id) ? " AND abook_id = $manual_id " : ""); + $sql_extra = (($manual_id) ? " AND abook_id = " . intval($manual_id) . " " : ""); reload_plugins(); $d = datetime_convert(); - //TODO check to see if there are any cronhooks before wasting a process + // TODO check to see if there are any cronhooks before wasting a process if(! $restart) proc_run('php','include/cronhooks.php'); @@ -271,12 +274,12 @@ function poller_run($argv, $argc){ : '' ); - $randfunc = (ACTIVE_DBTYPE == DBTYPE_POSTGRES) ? 'RANDOM()' : 'RAND()'; + $randfunc = db_getfunc('RAND'); - $contacts = q("SELECT abook_id, abook_flags, abook_updated, abook_connected, abook_closeness, abook_xchan, abook_channel - FROM abook LEFT JOIN account on abook_account = account_id + $contacts = q("SELECT abook_id, abook_flags, abook_updated, abook_connected, abook_closeness, abook_xchan, abook_channel, xchan_network + FROM abook LEFT JOIN xchan on abook_xchan = xchan_hash LEFT JOIN account on abook_account = account_id $sql_extra - AND (( abook_flags & %d )>0 OR ( abook_flags = %d )) + AND (( abook_flags & %d ) > 0 OR ( abook_flags = %d )) AND (( account_flags = %d ) OR ( account_flags = %d )) $abandon_sql ORDER BY $randfunc", intval(ABOOK_FLAG_HIDDEN|ABOOK_FLAG_PENDING|ABOOK_FLAG_UNCONNECTED|ABOOK_FLAG_FEED), intval(0), @@ -289,6 +292,9 @@ function poller_run($argv, $argc){ foreach($contacts as $contact) { + if($contact['abook_flags'] & ABOOK_FLAG_SELF) + continue; + $update = false; $t = $contact['abook_updated']; @@ -310,6 +316,9 @@ function poller_run($argv, $argc){ } + if($contact['xchan_network'] !== 'zot') + continue; + if($c == $t) { if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day")) $update = true; @@ -330,17 +339,12 @@ function poller_run($argv, $argc){ // He's dead, Jim if(strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $c . " + 30 day")) > 0) { - $n = q("select xchan_network from xchan where xchan_hash = '%s' limit 1", - dbesc($contact['abook_xchan']) + $r = q("update abook set abook_flags = (abook_flags | %d) where abook_id = %d", + intval(ABOOK_FLAG_ARCHIVED), + intval($contact['abook_id']) ); - if($n && $n[0]['xchan_network'] == 'zot') { - $r = q("update abook set abook_flags = (abook_flags | %d) where abook_id = %d", - intval(ABOOK_FLAG_ARCHIVED), - intval($contact['abook_id']) - ); - $update = false; - continue; - } + $update = false; + continue; } if($contact['abook_flags'] & ABOOK_FLAG_ARCHIVED) { @@ -364,6 +368,9 @@ function poller_run($argv, $argc){ } + if($contact['abook_flags'] & (ABOOK_FLAG_PENDING|ABOOK_FLAG_ARCHIVED|ABOOK_FLAG_IGNORED)) + continue; + if((! $update) && (! $force)) continue; @@ -375,7 +382,7 @@ function poller_run($argv, $argc){ } if($dirmode == DIRECTORY_MODE_SECONDARY || $dirmode == DIRECTORY_MODE_PRIMARY) { - $r = q("select distinct ud_addr, updates.* from updates where not ( ud_flags & %d )>0 and ud_addr != '' and ( ud_last = '%s' OR ud_last > %s - INTERVAL %s ) group by ud_addr ", + $r = q("select distinct ud_addr, updates.* from updates where ( ud_flags & %d ) = 0 and ud_addr != '' and ( ud_last = '%s' OR ud_last > %s - INTERVAL %s ) group by ud_addr ", intval(UPDATE_FLAGS_UPDATED), dbesc(NULL_DATE), db_utcnow(), db_quoteinterval('7 DAY') diff --git a/install/migrate-mypg.php b/install/migrate-mypg.php new file mode 100644 index 000000000..b7a7ced1b --- /dev/null +++ b/install/migrate-mypg.php @@ -0,0 +1,306 @@ +<?php +function ask_question($menu, $options, $default) { + $r=null; + while(!$r) { + echo $menu; + $str = substr(strtolower(fgets(STDIN)),0,-1); + if($str == '') + $r = $default; + else if(in_array($str, $options)) + $r = $str; + } + return $r; +} + +function get_data($prompt, $regex) { + do { + echo $prompt; + $r = substr(fgets(STDIN), 0, -1); + if(!preg_match($regex, $prompt)) + $r = ''; + } while($r === ''); + return $r; +} + +function parse_htconfig($file) { + if(!file_exists($file)) + return array(); + $conf = file_get_contents($file); + preg_match_all('/\$db\_(host|port|user|pass|data|type)\s*=\s*\'([[:print:]]+)\'/', $conf, $matches); + return array_combine($matches[1], $matches[2]); +} + +function get_configtype(array $data) { + if(!isset($data['host'], $data['user'], $data['pass'], $data['data'])) + return 'none'; + if($data['type'] == 1) + return 'pgsql'; + return 'mysql'; +} + +function phpquote($str) { + for($r = '', $x=0, $l=strlen($str); $x < $l; $x++) + if($str{$x} == '\'' || $str{$x} == '\\') + $r .= '\\' . $str{$x}; + else + $r .= $str{$x}; + return $r; +} + +function run_sql($file, $db, &$err, &$n) { + $sql = file_get_contents($file); + $sql = explode(';', $sql); + $err = 0; $n = 0; + $c = count($sql); + if(!$c) { + echo "Unknown error.\n"; + exit(); + } + foreach($sql as $stmt) { + if($stmt == '' || $stmt == "\n" || $stmt == "\n\n") + continue; + $r = $db->exec($stmt); + if($r===false) { + echo "\nError executing $stmt: ".var_export($db->errorInfo(), true)."\n"; + $err++; + } else { + $n++; + } + if($n % 5 == 0) + echo "\033[255DExecuting: $file, $n/$c\033[K"; + } + echo "\n"; +} + +$drivers=true; +if(!class_exists('PDO')) + $drivers=false; +if($drivers) { + $drivers = PDO::getAvailableDrivers(); + if(!in_array('pgsql', $drivers) || !in_array('mysql', $drivers)) + $drivers = false; +} +if(!$drivers) { + echo "Sorry. This migration tool requires both mysql and pgsql PDO drivers.\n"; + $r = ask_question("If you are on dreamhost you can enable them. This might work on other shared hosts too. Type 'n' to do it yourself.\nWould you like to try (Y/n)? ", array('y', 'n'), 'y'); + if($r=='y') { + $path = $_SERVER['HOME'] . '/.php/5.4'; + if(!file_exists($path)) + mkdir($path, 0770, true); + + $rcfile = $path . '/phprc'; + + $str = ''; + $mods = get_loaded_extensions(); + foreach(array('pdo_mysql','pdo_pgsql','pgsql') as $ext) + if(!in_array($ext, $mods)) + $str .= 'extension=' . $ext . ".so\n"; + + file_put_contents($rcfile, $str, FILE_APPEND ); + echo "drivers enabled.\nNow type: \033[1m/usr/local/bin/php-5.4 install/".basename($argv[0])."\033[0m\n"; + } + exit(); +} + +foreach(array('install','include','mod','view') as $dir) { + if(!file_exists($dir)) { + echo "You must execute from inside the webroot like the cron\n"; + exit(); + } +} + +$cfg = parse_htconfig('.htconfig.php'); +$type = get_configtype($cfg); +if($type != 'mysql') { + echo "Error. Must start with standard mysql installation in .htconfig.php.\n"; + exit(); +} + +if(!$cfg['port']) + $cfg['port'] = 3306; +try { + $mydb = new PDO("mysql:host={$cfg['host']};dbname={$cfg['data']};port={$cfg['port']}", $cfg['user'], $cfg['pass']); +} catch (PDOException $e) { + echo "Error connecting to mysql DB: " . $e->getMessage() . "\n"; + exit(); +} + +if(!file_exists('.htconfig.php-pgsql')) { + echo "Enter postgres server info:\n"; + $p['host'] = get_data("Hostname: ", '/[\w.]+/'); + $p['port'] = get_data("Enter port (0 for default): ", '/\d+/'); + $p['user'] = get_data("Username: ", '/\w+/'); + $p['pass'] = get_data("Password: ", '/[[:print:]]+/'); + $p['data'] = get_data("Database name: ", '/\w+/'); + $old = file_get_contents('.htconfig.php'); + $new = preg_replace( + array( + '/^(\$db_host\s*=\s*\')([\w.]+)(\';)$/m', + '/^(\$db_port\s*=\s*\')(\d+)(\';)$/m', + '/^(\$db_user\s*=\s*\')(\w+)(\';)$/m', + '/^(\$db_pass\s*=\s*\')([[:print:]]+)(\';)/m', + '/^(\$db_data\s*=\s*\')(\w+)(\';)$/m', + '/^(\$db_type\s*=\s*\')(\d)(\';)$/m' // in case they already have it + ), array( + "$1{$p['host']}$3", + "\${1}{$p['port']}$3", + "$1{$p['user']}$3", + "$1{$p['pass']}$3", + "$1{$p['data']}$3\n\$db_type = '1';\n", // they probably don't + "\${1}1$3" + ), + $old, + 1, + $repl + ); + if($new === false || $repl < 5) { + echo "Failed. Please make a postgres config file named .htconfig.php-pgsql - Be sure to add \"\$db_type = '1';\" to your config.\n"; + exit(); + } + file_put_contents('.htconfig.php-pgsql', $new); +} + +$pcfg = parse_htconfig('.htconfig.php-pgsql'); +$ptype = get_configtype($pcfg); +if($ptype != 'pgsql') { + echo "Error. Must have a valid pgsql config named .htconfig.php-pgsql. Be sure to add \"\$db_type = '1';\" to your config.\n"; + exit(); +} + +if(!$pcfg['port']) + $pcfg['port'] = 5432; +try { + $pgdb = new PDO("pgsql:host={$pcfg['host']};dbname={$pcfg['data']};port={$pcfg['port']}", $pcfg['user'], $pcfg['pass']); +} catch (PDOException $e) { + echo "Error connecting to pgsql DB: " . $e->getMessage() . "\n"; + echo "cfg string: " . "pgsql:host={$pcfg['host']};dbname={$pcfg['data']};port={$pcfg['port']}\n"; + exit(); +} +$B = "\033[0;34m"; +$H = "\033[0;35m"; +$W = "\033[1;37m"; +$M = "\033[1;31m"; +$N = "\033[0m"; +$r = ask_question("Ready to migrate {$W}Red{$M}(#){$W}Matrix$N from mysql db @$B{$cfg['host']}$N/$B{$cfg['data']}$N to postgres db @$B{$pcfg['host']}$N/$B{$pcfg['data']}$N. +The site will be disabled during the migration by moving the $H.htconfig.php$N file to $H.htconfig.php-mysql$N. +If for any reason the migration fails, you will need to move the config file back into place manually before trying again. + +Are you ready to begin (N/y)? ", array('y','n'), 'n' +); + +if($r == 'n') + exit(); + +rename('.htconfig.php', '.htconfig.php-mysql'); + +run_sql('install/schema_postgres.sql', $pgdb, $err, $n); +if($err) { + echo "There were $err errors creating the pgsql schema. Unable to continue.\n"; +/* $r = ask_question("There were $err errors (and $n ok) creating the schema. This shouldn't happen and continuing will probably fail. +Do you want to continue migration anyway (N/y)? ", array('y','n'), 'n' + ); + if($r == 'n')*/ + exit(); +} + +echo "pgsql schema created. $n queries executed successfully.\n"; + +$res = $pgdb->query("select relname, attname, pg_type.typname from ((pg_attribute inner join pg_class on attrelid=pg_class.oid) inner join pg_type on atttypid=pg_type.oid) inner join pg_namespace on relnamespace=pg_namespace.oid where nspname='public' and atttypid not in (26,27,28,29) and relkind='r' and attname <> 'item_search_vector';"); +if($res === false) { + echo "Error reading back schema. Unable to continue.\n"; + var_export($pgdb->errorInfo()); + exit(); +} +$schema = array(); +while(($row = $res->fetch()) !== false) + $schema[$row[0]][$row[1]] = $row[2]; + +$err = 0; $n = 0; +$reserved = array('ignore','key','with'); +foreach($schema as $table=>$fields) { + $fnames = array_keys($fields); + $pfnames = array_keys($fields); + + foreach($fnames as &$fname) + if(in_array($fname, $reserved)) + $fname = '`' . $fname . '`'; + $fstr = implode(',', $fnames); + + foreach($pfnames as &$pfname) + if(in_array($pfname, $reserved)) + $pfname = '"' . $pfname . '"'; + $pfstr = implode(',', $pfnames); + + $res = $mydb->query("SELECT count(*) FROM $table;"); + if($res === false) { + echo "Fatal error counting table $table: ".var_export($mydb->errorInfo(), true)."\n"; + exit(); + } + $nrows = $res->fetchColumn(0); + if(!$nrows) { + echo "\nTABLE $table has 0 rows in mysql db.\n"; + continue; + } + + $pstr = ''; + for($x=0, $c=count($fields); $x < $c; $x++) + $pstr .= ($x ? ',?' : '?'); + + $crow = 0; + echo "\033[255DTABLE: $table [$c fields] $crow/$nrows (".number_format(($crow/$nrows)*100,2)."%)\033[K"; + + $res = $mydb->query("SELECT $fstr FROM $table;"); + if($res === false) { + echo "Fatal Error importing table $table: ".var_export($mydb->errorInfo(), true)."\n"; + exit(); + } + + $istmt = $pgdb->prepare("INSERT INTO $table ($pfstr) VALUES ($pstr);"); + if($istmt === false) { + echo "Fatal error preparing query. Aborting.\n"; + var_export($pgdb->errorInfo()); + exit(); + } + + while(($row = $res->fetch(PDO::FETCH_NUM)) !== false) { + foreach($row as $idx => &$val) + if(array_slice(array_values($fields),$idx,1)[0] == 'timestamp' && $val == '0000-00-00 00:00:00') + $istmt->bindParam($idx+1, ($nulldate='0001-01-01 00:00:00')); + else if(array_slice(array_values($fields),$idx,1)[0] == 'bytea') + $istmt->bindParam($idx+1, $val, PDO::PARAM_LOB); + else + $istmt->bindParam($idx+1, $val); + $r = $istmt->execute(); + if($r === false) { + $err++; + echo "\nInsert error: ".var_export(array($pgdb->errorInfo(), $table, $fields, $row), true)."\n"; + //exit(); + } else + $n++; + $crow++; + if(($crow % 10) == 0 || $crow == $nrows) + echo "\033[255DTABLE: $table [$c fields] $crow/$nrows (".number_format(($crow/$nrows)*100,2)."%)\033[K"; + } +} + +echo "Done with $err errors and $n inserts.\n"; +if($err) { + echo "Migration had errors. Aborting.\n"; + exit(); +} + +run_sql('install/migrate_mypg_fixseq.sql', $pgdb, $err, $n); +echo "Sequences updated with $err errors and $n inserts.\n"; +if($err) + exit(); + +$r = ask_question("Everything successful. Once you connect up the pg database there is no going back. Do you want to make it live (N,y)?", array('y', 'n'), 'n'); +if($r == 'n') { + echo "You can make active by renaming .htconfig.php-pgsql to .htconfig.php, or start over by renaming .htconfig.php-mysql to .htconfig.php\n"; + exit(); +} + +rename('.htconfig.php-pgsql', '.htconfig.php'); +echo "Done. {$W}Red{$M}(#){$W}Matrix$N now running on postgres.\n"; + + diff --git a/install/migrate_mypg_fixseq.sql b/install/migrate_mypg_fixseq.sql new file mode 100644 index 000000000..806c5cf31 --- /dev/null +++ b/install/migrate_mypg_fixseq.sql @@ -0,0 +1,55 @@ + SELECT SETVAL('public.abook_abook_id_seq', COALESCE(MAX(abook_id), 1) ) FROM public.abook; + SELECT SETVAL('public.account_account_id_seq', COALESCE(MAX(account_id), 1) ) FROM public.account; + SELECT SETVAL('public.addon_id_seq', COALESCE(MAX(id), 1) ) FROM public.addon; + SELECT SETVAL('public.app_id_seq', COALESCE(MAX(id), 1) ) FROM public.app; + SELECT SETVAL('public.attach_id_seq', COALESCE(MAX(id), 1) ) FROM public.attach; + SELECT SETVAL('public.channel_channel_id_seq', COALESCE(MAX(channel_id), 1) ) FROM public.channel; + SELECT SETVAL('public.chat_chat_id_seq', COALESCE(MAX(chat_id), 1) ) FROM public.chat; + SELECT SETVAL('public.chatpresence_cp_id_seq', COALESCE(MAX(cp_id), 1) ) FROM public.chatpresence; + SELECT SETVAL('public.chatroom_cr_id_seq', COALESCE(MAX(cr_id), 1) ) FROM public.chatroom; + SELECT SETVAL('public.config_id_seq', COALESCE(MAX(id), 1) ) FROM public.config; + SELECT SETVAL('public.conv_id_seq', COALESCE(MAX(id), 1) ) FROM public.conv; + SELECT SETVAL('public.event_id_seq', COALESCE(MAX(id), 1) ) FROM public.event; + SELECT SETVAL('public.fcontact_id_seq', COALESCE(MAX(id), 1) ) FROM public.fcontact; + SELECT SETVAL('public.ffinder_id_seq', COALESCE(MAX(id), 1) ) FROM public.ffinder; + SELECT SETVAL('public.fserver_id_seq', COALESCE(MAX(id), 1) ) FROM public.fserver; + SELECT SETVAL('public.fsuggest_id_seq', COALESCE(MAX(id), 1) ) FROM public.fsuggest; + SELECT SETVAL('public.group_member_id_seq', COALESCE(MAX(id), 1) ) FROM public.group_member; + SELECT SETVAL('public.groups_id_seq', COALESCE(MAX(id), 1) ) FROM public.groups; + SELECT SETVAL('public.hook_id_seq', COALESCE(MAX(id), 1) ) FROM public.hook; + SELECT SETVAL('public.hubloc_hubloc_id_seq', COALESCE(MAX(hubloc_id), 1) ) FROM public.hubloc; + SELECT SETVAL('public.issue_issue_id_seq', COALESCE(MAX(issue_id), 1) ) FROM public.issue; + SELECT SETVAL('public.item_id_id_seq', COALESCE(MAX(id), 1) ) FROM public.item_id; + SELECT SETVAL('public.item_id_seq', COALESCE(MAX(id), 1) ) FROM public.item; + SELECT SETVAL('public.likes_id_seq', COALESCE(MAX(id), 1) ) FROM public.likes; + SELECT SETVAL('public.mail_id_seq', COALESCE(MAX(id), 1) ) FROM public.mail; + SELECT SETVAL('public.manage_id_seq', COALESCE(MAX(id), 1) ) FROM public.manage; + SELECT SETVAL('public.menu_item_mitem_id_seq', COALESCE(MAX(mitem_id), 1) ) FROM public.menu_item; + SELECT SETVAL('public.menu_menu_id_seq', COALESCE(MAX(menu_id), 1) ) FROM public.menu; + SELECT SETVAL('public.notify_id_seq', COALESCE(MAX(id), 1) ) FROM public.notify; + SELECT SETVAL('public.obj_obj_id_seq', COALESCE(MAX(obj_id), 1) ) FROM public.obj; + SELECT SETVAL('public.pconfig_id_seq', COALESCE(MAX(id), 1) ) FROM public.pconfig; + SELECT SETVAL('public.photo_id_seq', COALESCE(MAX(id), 1) ) FROM public.photo; + SELECT SETVAL('public.poll_elm_pelm_id_seq', COALESCE(MAX(pelm_id), 1) ) FROM public.poll_elm; + SELECT SETVAL('public.poll_poll_id_seq', COALESCE(MAX(poll_id), 1) ) FROM public.poll; + SELECT SETVAL('public.profdef_id_seq', COALESCE(MAX(id), 1) ) FROM public.profdef; + SELECT SETVAL('public.profext_id_seq', COALESCE(MAX(id), 1) ) FROM public.profext; + SELECT SETVAL('public.profile_check_id_seq', COALESCE(MAX(id), 1) ) FROM public.profile_check; + SELECT SETVAL('public.profile_id_seq', COALESCE(MAX(id), 1) ) FROM public.profile; + SELECT SETVAL('public.register_id_seq', COALESCE(MAX(id), 1) ) FROM public.register; + SELECT SETVAL('public.session_id_seq', COALESCE(MAX(id), 1) ) FROM public.session; + SELECT SETVAL('public.shares_share_id_seq', COALESCE(MAX(share_id), 1) ) FROM public.shares; + SELECT SETVAL('public.sign_id_seq', COALESCE(MAX(id), 1) ) FROM public.sign; + SELECT SETVAL('public.source_src_id_seq', COALESCE(MAX(src_id), 1) ) FROM public.source; + SELECT SETVAL('public.spam_id_seq', COALESCE(MAX(id), 1) ) FROM public.spam; + SELECT SETVAL('public.sys_perms_id_seq', COALESCE(MAX(id), 1) ) FROM public.sys_perms; + SELECT SETVAL('public.term_tid_seq', COALESCE(MAX(tid), 1) ) FROM public.term; + SELECT SETVAL('public.updates_ud_id_seq', COALESCE(MAX(ud_id), 1) ) FROM public.updates; + SELECT SETVAL('public.verify_id_seq', COALESCE(MAX(id), 1) ) FROM public.verify; + SELECT SETVAL('public.vote_vote_id_seq', COALESCE(MAX(vote_id), 1) ) FROM public.vote; + SELECT SETVAL('public.xchat_xchat_id_seq', COALESCE(MAX(xchat_id), 1) ) FROM public.xchat; + SELECT SETVAL('public.xconfig_id_seq', COALESCE(MAX(id), 1) ) FROM public.xconfig; + SELECT SETVAL('public.xign_id_seq', COALESCE(MAX(id), 1) ) FROM public.xign; + SELECT SETVAL('public.xlink_xlink_id_seq', COALESCE(MAX(xlink_id), 1) ) FROM public.xlink; + SELECT SETVAL('public.xtag_xtag_id_seq', COALESCE(MAX(xtag_id), 1) ) FROM public.xtag; + diff --git a/mod/channel.php b/mod/channel.php index 8d6b2a169..1cc2dc02c 100644 --- a/mod/channel.php +++ b/mod/channel.php @@ -293,8 +293,14 @@ function channel_content(&$a, $update = 0, $load = false) { } + if(get_pconfig($a->profile['profile_uid'],'system','channel_list_mode')) + $page_mode = 'list'; + else + $page_mode = 'client'; + + if($_COOKIE['jsAvailable'] == 1) { - $o .= conversation($a,$items,'channel',$update,'client'); + $o .= conversation($a,$items,'channel',$update,$page_mode); } else { $o .= conversation($a,$items,'channel',$update,'traditional'); } diff --git a/mod/home.php b/mod/home.php index 576213e06..a1a68710f 100644 --- a/mod/home.php +++ b/mod/home.php @@ -9,9 +9,10 @@ function home_init(&$a) { $ret = array(); call_hooks('home_init',$ret); - $channel = $a->get_channel(); + $splash = ((argc() > 1 && argv(1) === 'splash') ? true : false); - if(local_user() && $channel && $channel['xchan_url']) { + $channel = $a->get_channel(); + if(local_user() && $channel && $channel['xchan_url'] && ! $splash) { $dest = $channel['channel_startpage']; if(! $dest) $dest = get_pconfig(local_user(),'system','startpage'); @@ -23,7 +24,7 @@ function home_init(&$a) { goaway($dest); } - if(get_account_id()) { + if(get_account_id() && ! $splash) { goaway(z_root() . '/new_channel'); } @@ -39,6 +40,7 @@ function home_content(&$a) { if(x($_SESSION,'mobile_theme')) unset($_SESSION['mobile_theme']); + $splash = ((argc() > 1 && argv(1) === 'splash') ? true : false); if(get_config('system','projecthome')) { $o .= file_get_contents('assets/home.html'); @@ -48,20 +50,20 @@ function home_content(&$a) { } -// Deprecated - $channel_address = get_config("system", "site_channel" ); - -// See if the sys channel set a homepage - if (! $channel_address) { - $u = get_sys_channel(); - if ($u) { - $u = array($u); - // change to channel_id when below deprecated and skip the $u=... - $channel_address = $u[0]['channel_address']; - } - } + // Deprecated + $channel_address = get_config("system", "site_channel" ); + + // See if the sys channel set a homepage + if (! $channel_address) { + $u = get_sys_channel(); + if ($u) { + $u = array($u); + // change to channel_id when below deprecated and skip the $u=... + $channel_address = $u[0]['channel_address']; + } + } - if ($channel_address){ + if($channel_address) { $page_id = 'home'; @@ -78,16 +80,16 @@ function home_content(&$a) { ); if($r) { - xchan_query($r); - $r = fetch_post_tags($r,true); - $a->profile = array('profile_uid' => $u[0]['channel_id']); - $o .= prepare_page($r[0]); - return $o; + xchan_query($r); + $r = fetch_post_tags($r,true); + $a->profile = array('profile_uid' => $u[0]['channel_id']); + $a->profile_uid = $u[0]['channel_id']; + $o .= prepare_page($r[0]); + return $o; } - } -// Nope, we didn't find an item. Let's see if there's any html + // Nope, we didn't find an item. Let's see if there's any html if(file_exists('home.html')) { $o .= file_get_contents('home.html'); diff --git a/mod/network.php b/mod/network.php index da020c389..d6c19eca7 100644 --- a/mod/network.php +++ b/mod/network.php @@ -24,7 +24,7 @@ function network_content(&$a, $update = 0, $load = false) { if(! local_user()) { $_SESSION['return_url'] = $a->query_string; - return login(false); + return login(false); } @@ -52,28 +52,30 @@ function network_content(&$a, $update = 0, $load = false) { } - $datequery = $datequery2 = ''; $group = 0; - $nouveau = false; + $nouveau = false; - $datequery = ((x($_GET,'dend') && is_a_date_arg($_GET['dend'])) ? notags($_GET['dend']) : ''); + $datequery = ((x($_GET,'dend') && is_a_date_arg($_GET['dend'])) ? notags($_GET['dend']) : ''); $datequery2 = ((x($_GET,'dbegin') && is_a_date_arg($_GET['dbegin'])) ? notags($_GET['dbegin']) : ''); - $nouveau = ((x($_GET,'new')) ? intval($_GET['new']) : 0); - $gid = ((x($_GET,'gid')) ? intval($_GET['gid']) : 0); + $nouveau = ((x($_GET,'new')) ? intval($_GET['new']) : 0); + $gid = ((x($_GET,'gid')) ? intval($_GET['gid']) : 0); if($datequery) $_GET['order'] = 'post'; + + // filter by collection (e.g. group) + if($gid) { - $r = q("SELECT * FROM `groups` WHERE id = %d AND uid = %d LIMIT 1", - intval($gid), - intval(local_user()) - ); - if(! $r) { + $r = q("SELECT * FROM groups WHERE id = %d AND uid = %d LIMIT 1", + intval($gid), + intval(local_user()) + ); + if(! $r) { if($update) killme(); notice( t('No such group') . EOL ); @@ -81,27 +83,26 @@ function network_content(&$a, $update = 0, $load = false) { // NOTREACHED } - $group = $gid; + $group = $gid; $group_hash = $r[0]['hash']; - $def_acl = array('allow_gid' => '<' . $r[0]['hash'] . '>'); + $def_acl = array('allow_gid' => '<' . $r[0]['hash'] . '>'); } $o = ''; - // if no tabs are selected, defaults to comments - $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0); - $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0); - $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment'); - $liked = ((x($_GET,'liked')) ? intval($_GET['liked']) : 0); - $conv = ((x($_GET,'conv')) ? intval($_GET['conv']) : 0); - $spam = ((x($_GET,'spam')) ? intval($_GET['spam']) : 0); - $cmin = ((x($_GET,'cmin')) ? intval($_GET['cmin']) : 0); - $cmax = ((x($_GET,'cmax')) ? intval($_GET['cmax']) : 99); - $firehose = ((x($_GET,'fh')) ? intval($_GET['fh']) : 0); - $file = ((x($_GET,'file')) ? $_GET['file'] : ''); + $cid = ((x($_GET,'cid')) ? intval($_GET['cid']) : 0); + $star = ((x($_GET,'star')) ? intval($_GET['star']) : 0); + $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment'); + $liked = ((x($_GET,'liked')) ? intval($_GET['liked']) : 0); + $conv = ((x($_GET,'conv')) ? intval($_GET['conv']) : 0); + $spam = ((x($_GET,'spam')) ? intval($_GET['spam']) : 0); + $cmin = ((x($_GET,'cmin')) ? intval($_GET['cmin']) : 0); + $cmax = ((x($_GET,'cmax')) ? intval($_GET['cmax']) : 99); + $firehose = ((x($_GET,'fh')) ? intval($_GET['fh']) : 0); + $file = ((x($_GET,'file')) ? $_GET['file'] : ''); if(x($_GET,'search') || x($_GET,'file')) @@ -122,21 +123,21 @@ function network_content(&$a, $update = 0, $load = false) { $channel_acl = array( 'allow_cid' => $channel['channel_allow_cid'], 'allow_gid' => $channel['channel_allow_gid'], - 'deny_cid' => $channel['channel_deny_cid'], - 'deny_gid' => $channel['channel_deny_gid'] + 'deny_cid' => $channel['channel_deny_cid'], + 'deny_gid' => $channel['channel_deny_gid'] ); $x = array( - 'is_owner' => true, - 'allow_location' => ((intval(get_pconfig($channel['channel_id'],'system','use_browser_location'))) ? '1' : ''), + 'is_owner' => true, + 'allow_location' => ((intval(get_pconfig($channel['channel_id'],'system','use_browser_location'))) ? '1' : ''), 'default_location' => $channel['channel_location'], - 'nickname' => $channel['channel_address'], - 'lockstate' => (($group || $cid || $channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'), - 'acl' => populate_acl((($group || $cid) ? $def_acl : $channel_acl)), - 'bang' => (($group || $cid) ? '!' : ''), - 'visitor' => true, - 'profile_uid' => local_user() + 'nickname' => $channel['channel_address'], + 'lockstate' => (($group || $cid || $channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'), + 'acl' => populate_acl((($group || $cid) ? $def_acl : $channel_acl)), + 'bang' => (($group || $cid) ? '!' : ''), + 'visitor' => true, + 'profile_uid' => local_user() ); $o .= status_editor($a,$x); @@ -146,11 +147,11 @@ function network_content(&$a, $update = 0, $load = false) { // We don't have to deal with ACL's on this page. You're looking at everything // that belongs to you, hence you can see all of it. We will filter by group if - // desired. + // desired. + - - $sql_options = (($star) - ? " and (item_flags & " . intval(ITEM_STARRED) . ")>0" + $sql_options = (($star) + ? " and (item_flags & " . intval(ITEM_STARRED) . ") > 0" : ''); $sql_nets = ''; @@ -159,20 +160,20 @@ function network_content(&$a, $update = 0, $load = false) { if($group) { $contact_str = ''; - $contacts = group_get_members($group); - if($contacts) { + $contacts = group_get_members($group); + if($contacts) { foreach($contacts as $c) { if($contact_str) $contact_str .= ','; - $contact_str .= "'" . $c['xchan'] . "'"; + $contact_str .= "'" . $c['xchan'] . "'"; } - } - else { - $contact_str = ' 0 '; + } + else { + $contact_str = ' 0 '; info( t('Collection is empty')); - } + } - $sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true $sql_options AND (( author_xchan IN ( $contact_str ) OR owner_xchan in ( $contact_str )) or allow_gid like '" . protect_sprintf('%<' . dbesc($group_hash) . '>%') . "' ) and id = parent and item_restrict = 0 ) "; + $sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true $sql_options AND (( author_xchan IN ( $contact_str ) OR owner_xchan in ( $contact_str )) or allow_gid like '" . protect_sprintf('%<' . dbesc($group_hash) . '>%') . "' ) and id = parent and item_restrict = 0 ) "; $x = group_rec_byhash(local_user(), $group_hash); @@ -180,60 +181,60 @@ function network_content(&$a, $update = 0, $load = false) { $o = '<h2>' . t('Collection: ') . $x['name'] . '</h2>' . $o; - } + } elseif($cid) { - $r = q("SELECT abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d and abook_channel = %d and not ( abook_flags & " . intval(ABOOK_FLAG_BLOCKED) . ")>0 limit 1", + $r = q("SELECT abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash where abook_id = %d and abook_channel = %d and not ( abook_flags & " . intval(ABOOK_FLAG_BLOCKED) . ") > 0 limit 1", intval($cid), intval(local_user()) - ); - if($r) { - $sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true $sql_options AND uid = " . intval(local_user()) . " AND ( author_xchan = '" . dbesc($r[0]['abook_xchan']) . "' or owner_xchan = '" . dbesc($r[0]['abook_xchan']) . "' ) and item_restrict = 0 ) "; + ); + if($r) { + $sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true $sql_options AND uid = " . intval(local_user()) . " AND ( author_xchan = '" . dbesc($r[0]['abook_xchan']) . "' or owner_xchan = '" . dbesc($r[0]['abook_xchan']) . "' ) and item_restrict = 0 ) "; $o = '<h2>' . t('Connection: ') . $r[0]['xchan_name'] . '</h2>' . $o; - } - else { + } + else { notice( t('Invalid connection.') . EOL); goaway($a->get_baseurl(true) . '/network'); - } + } } if(! $update) { // The special div is needed for liveUpdate to kick in for this page. - // We only launch liveUpdate if you aren't filtering in some incompatible + // We only launch liveUpdate if you aren't filtering in some incompatible // way and also you aren't writing a comment (discovered in javascript). if($gid || $cid || $cmin || ($cmax != 99) || $star || $liked || $conv || $spam || $nouveau || $list) - $firehose = 0; + $firehose = 0; $o .= '<div id="live-network"></div>' . "\r\n"; - $o .= "<script> var profile_uid = " . $_SESSION['uid'] . "; var profile_page = " . $a->pager['page'] . ";</script>"; + $o .= "<script> var profile_uid = " . local_user() . "; var profile_page = " . $a->pager['page'] . ";</script>"; $a->page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"),array( '$baseurl' => z_root(), - '$pgtype' => 'network', - '$uid' => ((local_user()) ? local_user() : '0'), - '$gid' => (($gid) ? $gid : '0'), - '$cid' => (($cid) ? $cid : '0'), - '$cmin' => (($cmin) ? $cmin : '0'), - '$cmax' => (($cmax) ? $cmax : '0'), - '$star' => (($star) ? $star : '0'), - '$liked' => (($liked) ? $liked : '0'), - '$conv' => (($conv) ? $conv : '0'), - '$spam' => (($spam) ? $spam : '0'), - '$fh' => (($firehose) ? $firehose : '0'), + '$pgtype' => 'network', + '$uid' => ((local_user()) ? local_user() : '0'), + '$gid' => (($gid) ? $gid : '0'), + '$cid' => (($cid) ? $cid : '0'), + '$cmin' => (($cmin) ? $cmin : '0'), + '$cmax' => (($cmax) ? $cmax : '0'), + '$star' => (($star) ? $star : '0'), + '$liked' => (($liked) ? $liked : '0'), + '$conv' => (($conv) ? $conv : '0'), + '$spam' => (($spam) ? $spam : '0'), + '$fh' => (($firehose) ? $firehose : '0'), '$nouveau' => (($nouveau) ? $nouveau : '0'), - '$wall' => '0', - '$list' => ((x($_REQUEST,'list')) ? intval($_REQUEST['list']) : 0), - '$page' => (($a->pager['page'] != 1) ? $a->pager['page'] : 1), - '$search' => (($search) ? $search : ''), - '$order' => $order, - '$file' => $file, - '$cats' => '', - '$dend' => $datequery, - '$mid' => '', - '$dbegin' => $datequery2 + '$wall' => '0', + '$list' => ((x($_REQUEST,'list')) ? intval($_REQUEST['list']) : 0), + '$page' => (($a->pager['page'] != 1) ? $a->pager['page'] : 1), + '$search' => (($search) ? $search : ''), + '$order' => $order, + '$file' => $file, + '$cats' => '', + '$dend' => $datequery, + '$mid' => '', + '$dbegin' => $datequery2 )); } @@ -246,17 +247,19 @@ function network_content(&$a, $update = 0, $load = false) { $sql_extra3 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2)))); } - $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` "); + $sql_extra2 = (($nouveau) ? '' : " AND item.parent = item.id "); $sql_extra3 = (($nouveau) ? '' : $sql_extra3); if(x($_GET,'search')) { $search = escape_tags($_GET['search']); - if(strpos($search,'#') === 0) + if(strpos($search,'#') === 0) { $sql_extra .= term_query('item',substr($search,1),TERM_HASHTAG); - else - $sql_extra .= sprintf(" AND `item`.`body` like '%s' ", + } + else { + $sql_extra .= sprintf(" AND item.body like '%s' ", dbesc(protect_sprintf('%' . $search . '%')) ); + } } if(strlen($file)) { @@ -264,7 +267,7 @@ function network_content(&$a, $update = 0, $load = false) { } if($conv) { - $sql_extra .= sprintf(" AND parent IN (SELECT distinct(parent) from item where ( author_xchan like '%s' or ( item_flags & %d )>0)) ", + $sql_extra .= sprintf(" AND parent IN (SELECT distinct(parent) from item where ( author_xchan like '%s' or ( item_flags & %d ) > 0)) ", dbesc(protect_sprintf($channel['channel_hash'])), intval(ITEM_MENTIONSME) ); @@ -287,7 +290,7 @@ function network_content(&$a, $update = 0, $load = false) { // Not everybody who shows up in the network stream will be in your address book. // By default those that aren't are assumed to have closeness = 99; but this isn't - // recorded anywhere. So if cmax is 99, we'll open the search up to anybody in + // recorded anywhere. So if cmax is 99, we'll open the search up to anybody in // the stream with a NULL address book entry. $sql_nets .= " AND "; @@ -314,33 +317,33 @@ function network_content(&$a, $update = 0, $load = false) { $uids = " and item.uid = " . local_user() . " "; } - $simple_update = (($update) ? " and ( item.item_flags & " . intval(ITEM_UNSEEN) . " )>0 " : ''); + $simple_update = (($update) ? " and ( item.item_flags & " . intval(ITEM_UNSEEN) . " ) > 0 " : ''); // This fixes a very subtle bug so I'd better explain it. You wake up in the morning or return after a day - // or three and look at your matrix page - after opening up your browser. The first page loads just as it - // should. All of a sudden a few seconds later, page 2 will get inserted at the beginning of the page + // or three and look at your matrix page - after opening up your browser. The first page loads just as it + // should. All of a sudden a few seconds later, page 2 will get inserted at the beginning of the page // (before the page 1 content). The update code is actually doing just what it's supposed // to, it's fetching posts that have the ITEM_UNSEEN bit set. But the reason that page 2 content is being - // returned in an UPDATE is because you hadn't gotten that far yet - you're still on page 1 and everything + // returned in an UPDATE is because you hadn't gotten that far yet - you're still on page 1 and everything // that we loaded for page 1 is now marked as seen. But the stuff on page 2 hasn't been. So... it's being - // treated as "new fresh" content because it is unseen. We need to distinguish it somehow from content + // treated as "new fresh" content because it is unseen. We need to distinguish it somehow from content // which "arrived as you were reading page 1". We're going to do this // by storing in your session the current UTC time whenever you LOAD a network page, and only UPDATE items // which are both ITEM_UNSEEN and have "changed" since that time. Cross fingers... - if($update && $_SESSION['loadtime']) - $simple_update .= " and item.changed > '" . datetime_convert('UTC','UTC',$_SESSION['loadtime']) . "' "; + if($update && $_SESSION['loadtime']) + $simple_update .= " and item.changed > '" . datetime_convert('UTC','UTC',$_SESSION['loadtime']) . "' "; if($load) $simple_update = ''; if($nouveau && $load) { // "New Item View" - show all items unthreaded in reverse created date order - $items = q("SELECT `item`.*, `item`.`id` AS `item_id`, received FROM `item` - WHERE true $uids AND item_restrict = 0 + $items = q("SELECT item.*, item.id AS item_id, received FROM item + WHERE true $uids AND item_restrict = 0 $simple_update $sql_extra $sql_nets - ORDER BY `item`.`received` DESC $pager_sql " + ORDER BY item.received DESC $pager_sql " ); require_once('include/items.php'); @@ -354,9 +357,9 @@ function network_content(&$a, $update = 0, $load = false) { // Normal conversation view if($order === 'post') - $ordering = "`created`"; + $ordering = "created"; else - $ordering = "`commented`"; + $ordering = "commented"; if($load) { @@ -364,7 +367,7 @@ function network_content(&$a, $update = 0, $load = false) { // Fetch a page full of parent items for this page - $r = q("SELECT distinct item.id AS item_id, $ordering FROM item + $r = q("SELECT distinct item.id AS item_id, $ordering FROM item left join abook on item.author_xchan = abook.abook_xchan WHERE true $uids AND item.item_restrict = 0 AND item.parent = item.id @@ -376,7 +379,7 @@ function network_content(&$a, $update = 0, $load = false) { } else { - if(! $firehose) { + if(! $firehose) { // update $r = q("SELECT item.parent AS item_id FROM item left join abook on item.author_xchan = abook.abook_xchan @@ -396,9 +399,9 @@ function network_content(&$a, $update = 0, $load = false) { $parents_str = ids_to_querystr($r,'item_id'); - $items = q("SELECT `item`.*, `item`.`id` AS `item_id` FROM `item` - WHERE true $uids AND `item`.`item_restrict` = 0 - AND `item`.`parent` IN ( %s ) + $items = q("SELECT item.*, item.id AS item_id FROM item + WHERE true $uids AND item.item_restrict = 0 + AND item.parent IN ( %s ) $sql_extra ", dbesc($parents_str) ); @@ -406,7 +409,7 @@ function network_content(&$a, $update = 0, $load = false) { xchan_query($items,true,(($firehose) ? local_user() : 0)); $items = fetch_post_tags($items,true); $items = conv_sort($items,$ordering); - } + } else { $items = array(); } @@ -417,8 +420,8 @@ function network_content(&$a, $update = 0, $load = false) { } if(($update_unseen) && (! $firehose)) - $r = q("UPDATE `item` SET item_flags = ( item_flags & ~%d) - WHERE (item_flags & %d)>0 AND `uid` = %d $update_unseen ", + $r = q("UPDATE item SET item_flags = ( item_flags & ~%d) + WHERE (item_flags & %d) > 0 AND uid = %d $update_unseen ", intval(ITEM_UNSEEN), intval(ITEM_UNSEEN), intval(local_user()) @@ -426,10 +429,15 @@ function network_content(&$a, $update = 0, $load = false) { $mode = (($nouveau) ? 'network-new' : 'network'); - $o .= conversation($a,$items,$mode,$update,'client'); + if(get_pconfig(local_user(),'system','network_list_mode')) + $page_mode = 'list'; + else + $page_mode = 'client'; + + $o .= conversation($a,$items,$mode,$update,$page_mode); - if(($items) && (! $update)) - $o .= alt_pager($a,count($items)); + if(($items) && (! $update)) + $o .= alt_pager($a,count($items)); return $o; } diff --git a/mod/settings.php b/mod/settings.php index 396bb2972..725825b34 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -140,6 +140,10 @@ function settings_post(&$a) { $user_scalable = ((x($_POST,'user_scalable')) ? intval($_POST['user_scalable']) : 0); $nosmile = ((x($_POST,'nosmile')) ? intval($_POST['nosmile']) : 0); $title_tosource = ((x($_POST,'title_tosource')) ? intval($_POST['title_tosource']) : 0); + $channel_list_mode = ((x($_POST,'channel_list_mode')) ? intval($_POST['channel_list_mode']) : 0); + $network_list_mode = ((x($_POST,'network_list_mode')) ? intval($_POST['network_list_mode']) : 0); + + $browser_update = ((x($_POST,'browser_update')) ? intval($_POST['browser_update']) : 0); $browser_update = $browser_update * 1000; if($browser_update < 10000) @@ -159,6 +163,8 @@ function settings_post(&$a) { set_pconfig(local_user(),'system','itemspage', $itemspage); set_pconfig(local_user(),'system','no_smilies',$nosmile); set_pconfig(local_user(),'system','title_tosource',$title_tosource); + set_pconfig(local_user(),'system','channel_list_mode', $channel_list_mode); + set_pconfig(local_user(),'system','network_list_mode', $network_list_mode); if ($theme == $a->channel['channel_theme']){ // call theme_post only if theme has not been changed @@ -722,6 +728,7 @@ function settings_content(&$a) { /* * DISPLAY SETTINGS */ + if((argc() > 1) && (argv(1) === 'display')) { $default_theme = get_config('system','theme'); if(! $default_theme) @@ -801,6 +808,9 @@ function settings_content(&$a) { '$layout_editor' => t('System Page Layout Editor - (advanced)'), '$theme_config' => $theme_config, '$expert' => feature_enabled(local_user(),'expert'), + '$channel_list_mode' => array('channel_list_mode', t('Use blog/list mode on channel page'), get_pconfig(local_user(),'system','channel_list_mode'), t('(comments displayed separately)')), + '$network_list_mode' => array('network_list_mode', t('Use blog/list mode on matrix page'), get_pconfig(local_user(),'system','network_list_mode'), t('(comments displayed separately)')), + )); return $o; diff --git a/version.inc b/version.inc index 0ea73e309..664554361 100644 --- a/version.inc +++ b/version.inc @@ -1 +1 @@ -2014-11-15.860 +2014-11-16.861 diff --git a/view/js/main.js b/view/js/main.js index a55b8fbb1..bec35ba72 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -458,25 +458,17 @@ function updateConvItems(mode,data) { if(isVisible) showHideComments(itmId); $(".autotime").timeago(); - // divgrow doesn't prevent itself from attaching a second (or 500th) - // "show more" div to a content region - it also has a few other - // issues related to how we're trying to use it. - // disable for now. - // $("div.wall-item-body").divgrow({ initialHeight: 400 }); } else { $('img',this).each(function() { $(this).attr('src',$(this).attr('dst')); }); - // more FIXME related to expanded comments if($('#collapsed-comments-'+itmId).is(':visible')) isVisible = true; $('#' + ident).replaceWith($(this)); if(isVisible) showHideComments(itmId); $(".autotime").timeago(); - // $("div.wall-item-body").divgrow({ initialHeight: 400 }); - } prev = ident; }); @@ -508,8 +500,6 @@ function updateConvItems(mode,data) { if(isVisible) showHideComments(itmId); $(".autotime").timeago(); - // $("div.wall-item-body").divgrow({ initialHeight: 400 }); - } else { $('img',this).each(function() { @@ -521,7 +511,6 @@ function updateConvItems(mode,data) { if(isVisible) showHideComments(itmId); $(".autotime").timeago(); - // $("div.wall-item-body").divgrow({ initialHeight: 400 }); } }); @@ -557,7 +546,6 @@ function updateConvItems(mode,data) { showHideComments(itmId); $(".autotime").timeago(); - // $("div.wall-item-body").divgrow({ initialHeight: 400 }); } prev = ident; }); @@ -596,17 +584,28 @@ function updateConvItems(mode,data) { function collapseHeight() { - $(".wall-item-body").each(function() { - if($(this).height() > 410) { + var isListMode = false; + $(".wall-item-listbody").each(function() { + isListMode = true; + if($(this).height() > 210) { if(! $(this).hasClass('divmore')) { - $(this).divgrow({ initialHeight: 400, moreText: aStr['divgrowmore'], lessText: aStr['divgrowless'], showBrackets: false }); + $(this).divgrow({ initialHeight: 200, moreText: aStr['divgrowmore'], lessText: aStr['divgrowless'], showBrackets: false }); $(this).addClass('divmore'); } } }); - } - + $(".wall-item-body").each(function() { + if(! isListMode) { + if($(this).height() > 410) { + if(! $(this).hasClass('divmore')) { + $(this).divgrow({ initialHeight: 400, moreText: aStr['divgrowmore'], lessText: aStr['divgrowless'], showBrackets: false }); + $(this).addClass('divmore'); + } + } + } + }); + } function liveUpdate() { if((src == null) || (stopped) || (! profile_uid)) { $('.like-rotator').spin(false); return; } diff --git a/view/tpl/conv_list.tpl b/view/tpl/conv_list.tpl new file mode 100755 index 000000000..71554a9b3 --- /dev/null +++ b/view/tpl/conv_list.tpl @@ -0,0 +1,175 @@ +{{if $item.comment_firstcollapsed}} +<div class="hide-comments-outer fakelink" onclick="showHideComments({{$item.id}});"> + <span id="hide-comments-{{$item.id}}" class="hide-comments">{{$item.hide_text}}</span> <span id="hide-comments-total-{{$item.id}}" class="hide-comments-total">{{$item.num_comments}}</span> +</div> +<div id="collapsed-comments-{{$item.id}}" class="collapsed-comments" style="display: none;"> +{{/if}} + <div id="thread-wrapper-{{$item.id}}" class="thread-wrapper {{$item.toplevel}}"> + <a name="{{$item.id}}" ></a> + <div class="wall-item-outside-wrapper {{$item.indent}}{{$item.previewing}}" id="wall-item-outside-wrapper-{{$item.id}}" > + <div class="wall-item-content-wrapper {{$item.indent}}" id="wall-item-content-wrapper-{{$item.id}}" style="clear:both;"> + <div class="wall-item-info" id="wall-item-info-{{$item.id}}" > + <div class="wall-item-photo-wrapper{{if $item.owner_url}} wwfrom{{/if}}" id="wall-item-photo-wrapper-{{$item.id}}"> + <a href="{{$item.profile_url}}" title="{{$item.linktitle}}" class="wall-item-photo-link" id="wall-item-photo-link-{{$item.id}}"><img src="{{$item.thumb}}" class="wall-item-photo{{$item.sparkle}}" id="wall-item-photo-{{$item.id}}" alt="{{$item.name}}" /></a> + </div> + <div class="wall-item-photo-end" style="clear:both"></div> + </div> + {{if $item.title}} + <div class="wall-item-title" id="wall-item-title-{{$item.id}}"> + <h3>{{if $item.title_tosource}}{{if $item.plink}}<a href="{{$item.plink.href}}" title="{{$item.title}} ({{$item.plink.title}})">{{/if}}{{/if}}{{$item.title}}{{if $item.title_tosource}}{{if $item.plink}}</a>{{/if}}{{/if}}</h3> + </div> + {{/if}} + {{if $item.lock}} + <div class="wall-item-lock dropdown"> + <i class="icon-lock lockview dropdown-toggle" data-toggle="dropdown" title="{{$item.lock}}" onclick="lockview(event,{{$item.id}});" ></i><ul id="panel-{{$item.id}}" class="lockview-panel dropdown-menu"></ul> + </div> + {{/if}} + <div class="wall-item-author"> + <a href="{{$item.profile_url}}" title="{{$item.linktitle}}" class="wall-item-name-link"><span class="wall-item-name{{$item.sparkle}}" id="wall-item-name-{{$item.id}}" >{{$item.name}}</span></a>{{if $item.owner_url}} {{$item.via}} <a href="{{$item.owner_url}}" title="{{$item.olinktitle}}" class="wall-item-name-link"><span class="wall-item-name{{$item.osparkle}}" id="wall-item-ownername-{{$item.id}}">{{$item.owner_name}}</span></a>{{/if}} + </div> + <div class="wall-item-ago" id="wall-item-ago-{{$item.id}}"> + {{if $item.verified}}<i class="icon-ok" title="{{$item.verified}}"></i> {{elseif $item.forged}}<i class="icon-remove item-forged" title="{{$item.forged}}"></i> {{/if}}{{if $item.location}}<span class="wall-item-location" id="wall-item-location-{{$item.id}}">{{$item.location}}, </span>{{/if}}<span class="autotime" title="{{$item.isotime}}">{{$item.localtime}}{{if $item.editedtime}} {{$item.editedtime}}{{/if}}{{if $item.expiretime}} {{$item.expiretime}}{{/if}}</span>{{if $item.editedtime}} <i class="icon-pencil"></i>{{/if}} {{if $item.app}}<span class="item.app">{{$item.str_app}}</span>{{/if}} + </div> + <div class="wall-item-content" id="wall-item-content-{{$item.id}}"> + <div class="wall-item-title-end"></div> + <div class="wall-item-body wall-item-listbody" id="wall-item-body-{{$item.id}}" > + {{$item.body}} + {{if $item.tags}} + <div class="body-tag"> + {{foreach $item.tags as $tag}} + <span class='tag'>{{$tag}}</span> + {{/foreach}} + </div> + {{/if}} + {{if $item.has_cats}} + <div class="categorytags"> + <span>{{$item.txt_cats}} {{foreach $item.categories as $cat}}{{$cat.name}} <a href="{{$cat.removeurl}}" title="{{$remove}}">[{{$remove}}]</a> {{if $cat.last}}{{else}}, {{/if}}{{/foreach}} + </div> + {{/if}} + {{if $item.has_folders}} + <div class="filesavetags"> + <span>{{$item.txt_folders}} {{foreach $item.folders as $cat}}{{$cat.name}} <a href="{{$cat.removeurl}}" title="{{$remove}}">[{{$remove}}]</a> {{if $cat.last}}{{else}}, {{/if}}{{/foreach}} + </div> + {{/if}} + </div> + </div> + <div class="wall-item-tools"> + <div class="wall-item-tools-right btn-group pull-right"> + {{if $item.like}} + <button type="button" class="btn btn-default btn-sm" onclick="dolike({{$item.id}},'like'); return false"> + <i class="icon-thumbs-up-alt" title="{{$item.like.0}}"></i> + </button> + {{/if}} + {{if $item.dislike}} + <button type="button" class="btn btn-default btn-sm" onclick="dolike({{$item.id}},'dislike'); return false"> + <i class="icon-thumbs-down-alt" title="{{$item.dislike.0}}"></i> + </button> + {{/if}} + <button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" id="wall-item-menu-{{$item.id}}"> + <i class="icon-caret-down"></i> + </button> + <ul class="dropdown-menu" role="menu" aria-labelledby="wall-item-menu-{{$item.id}}"> + {{if $item.share}} + <li role="presentation"><a role="menuitem" href="#" onclick="jotShare({{$item.id}}); return false"><i class="icon-retweet" title="{{$item.share.0}}"></i> {{$item.share.0}}</a></li> + {{/if}} + {{if $item.plink}} + <li role="presentation"><a role="menuitem" href="{{$item.plink.href}}" title="{{$item.plink.title}}" ><i class="icon-external-link"></i> {{$item.plink.title}}</a></li> + {{/if}} + {{if $item.edpost}} + <li role="presentation"><a role="menuitem" href="{{$item.edpost.0}}" title="{{$item.edpost.1}}"><i class="editpost icon-pencil"></i> {{$item.edpost.1}}</a></li> + {{/if}} + {{if $item.tagger}} + <li role="presentation"><a role="menuitem" href="#" onclick="itemTag({{$item.id}}); return false;"><i id="tagger-{{$item.id}}" class="icon-tag" title="{{$item.tagger.tagit}}"></i> {{$item.tagger.tagit}}</a></li> + {{/if}} + {{if $item.filer}} + <li role="presentation"><a role="menuitem" href="#" onclick="itemFiler({{$item.id}}); return false;"><i id="filer-{{$item.id}}" class="icon-folder-open" title="{{$item.filer}}"></i> {{$item.filer}}</a></li> + {{/if}} + {{if $item.bookmark}} + <li role="presentation"><a role="menuitem" href="#" onclick="itemBookmark({{$item.id}}); return false;"><i id="bookmarker-{{$item.id}}" class="icon-bookmark" title="{{$item.bookmark}}"></i> {{$item.bookmark}}</a></li> + {{/if}} + {{if $item.addtocal}} + <li role="presentation"><a role="menuitem" href="#" onclick="itemAddToCal({{$item.id}}); return false;"><i id="addtocal-{{$item.id}}" class="icon-calendar" title="{{$item.addtocal}}"></i> {{$item.addtocal}}</a></li> + {{/if}} + {{if $item.star}} + <li role="presentation"><a role="menuitem" href="#" onclick="dostar({{$item.id}}); return false;"><i id="starred-{{$item.id}}" class="icon-star {{$item.star.isstarred}}" title="{{$item.star.toggle}}"></i> {{$item.star.toggle}}</a></li> + {{/if}} + {{if $item.item_photo_menu}} + <li role="presentation" class="divider"></li> + {{$item.item_photo_menu}} + {{/if}} + {{if $item.drop.dropping}} + <li role="presentation" class="divider"></li> + <li role="presentation"><a role="menuitem" href="item/drop/{{$item.id}}" onclick="return confirmDelete();" title="{{$item.drop.delete}}" ><i class="icon-remove"></i> {{$item.drop.delete}}</a></li> + {{/if}} + </ul> + </div> + <div id="like-rotator-{{$item.id}}" class="like-rotator"></div> + <div class="wall-item-tools-left{{if $item.like_count && $item.dislike_count}} btn-group{{/if}}"> + {{if $item.like_count}} + <div class="btn-group"> + <button type="button" class="btn btn-default btn-sm wall-item-like dropdown-toggle" data-toggle="dropdown" id="wall-item-like-{{$item.id}}">{{$item.like_count}} {{$item.like_button_label}}</button> + {{if $item.like_list_part}} + <ul class="dropdown-menu" role="menu" aria-labelledby="wall-item-like-{{$item.id}}">{{foreach $item.like_list_part as $liker}}<li role="presentation">{{$liker}}</li>{{/foreach}}</ul> + {{else}} + <ul class="dropdown-menu" role="menu" aria-labelledby="wall-item-like-{{$item.id}}">{{foreach $item.like_list as $liker}}<li role="presentation">{{$liker}}</li>{{/foreach}}</ul> + {{/if}} + </div> + {{/if}} + {{if $item.dislike_count}} + <div class="btn-group"> + <button type="button" class="btn btn-default btn-sm wall-item-dislike dropdown-toggle" data-toggle="dropdown" id="wall-item-dislike-{{$item.id}}">{{$item.dislike_count}} {{$item.dislike_button_label}}</button> + {{if $item.dislike_list_part}} + <ul class="dropdown-menu" role="menu" aria-labelledby="wall-item-dislike-{{$item.id}}">{{foreach $item.dislike_list_part as $disliker}}<li role="presentation">{{$disliker}}</li>{{/foreach}}</ul> + {{else}} + <ul class="dropdown-menu" role="menu" aria-labelledby="wall-item-dislike-{{$item.id}}">{{foreach $item.dislike_list as $disliker}}<li role="presentation">{{$disliker}}</li>{{/foreach}}</ul> + {{/if}} + </div> + {{/if}} + </div> + {{if $item.like_list_part}} + <div class="modal" id="likeModal-{{$item.id}}"> + <div class="modal-dialog"> + <div class="modal-content"> + <div class="modal-header"> + <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> + <h4 class="modal-title">{{$item.like_modal_title}}</h4> + </div> + <div class="modal-body"> + <ul>{{foreach $item.like_list as $liker}}<li role="presentation">{{$liker}}</li>{{/foreach}}</ul> + </div> + <div class="modal-footer clear"> + <button type="button" class="btn btn-default" data-dismiss="modal">{{$item.modal_dismiss}}</button> + </div> + </div><!-- /.modal-content --> + </div><!-- /.modal-dialog --> + </div><!-- /.modal --> + {{/if}} + {{if $item.dislike_list_part}} + <div class="modal" id="dislikeModal-{{$item.id}}"> + <div class="modal-dialog"> + <div class="modal-content"> + <div class="modal-header"> + <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> + <h4 class="modal-title">{{$item.dislike_modal_title}}</h4> + </div> + <div class="modal-body"> + <ul>{{foreach $item.dislike_list as $disliker}}<li role="presentation">{{$disliker}}</li>{{/foreach}}</ul> + </div> + <div class="modal-footer clear"> + <button type="button" class="btn btn-default" data-dismiss="modal">{{$item.modal_dismiss}}</button> + </div> + </div><!-- /.modal-content --> + </div><!-- /.modal-dialog --> + </div><!-- /.modal --> + {{/if}} + </div> + <div class="clear"></div> + <div class="wall-item-list-comments"><a href="{{$item.llink}}">{{$item.comment_count_txt}}</a></div> + </div> + <div class="wall-item-wrapper-end"></div> + <div class="wall-item-outside-wrapper-end {{$item.indent}}" ></div> + </div> + </div> +{{if $item.comment_lastcollapsed}} +</div> +{{/if}} diff --git a/view/tpl/settings_display.tpl b/view/tpl/settings_display.tpl index d3134ea88..8e870ba0e 100755 --- a/view/tpl/settings_display.tpl +++ b/view/tpl/settings_display.tpl @@ -13,6 +13,8 @@ {{include file="field_input.tpl" field=$itemspage}} {{include file="field_checkbox.tpl" field=$nosmile}} {{include file="field_checkbox.tpl" field=$title_tosource}} +{{include file="field_checkbox.tpl" field=$channel_list_mode}} +{{include file="field_checkbox.tpl" field=$network_list_mode}} <div class="settings-submit-wrapper" > <input type="submit" name="submit" class="settings-submit" value="{{$submit}}" /> |