diff options
-rwxr-xr-x | boot.php | 3 | ||||
-rw-r--r-- | doc/Widgets.md | 6 | ||||
-rw-r--r-- | include/ItemObject.php | 44 | ||||
-rw-r--r-- | include/conversation.php | 30 | ||||
-rwxr-xr-x | include/dba/dba_driver.php | 8 | ||||
-rw-r--r-- | include/externals.php | 2 | ||||
-rwxr-xr-x | include/items.php | 5 | ||||
-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 | 37 | ||||
-rw-r--r-- | mod/home.php | 48 | ||||
-rw-r--r-- | mod/network.php | 250 | ||||
-rw-r--r-- | mod/photos.php | 4 | ||||
-rw-r--r-- | mod/ping.php | 28 | ||||
-rw-r--r-- | mod/poco.php | 4 | ||||
-rw-r--r-- | mod/settings.php | 21 | ||||
-rw-r--r-- | version.inc | 2 | ||||
-rw-r--r-- | view/js/acl.js | 1 | ||||
-rw-r--r-- | view/js/main.js | 26 | ||||
-rw-r--r-- | view/tpl/attach_edit.tpl | 4 | ||||
-rw-r--r-- | view/tpl/chatroom_new.tpl | 4 | ||||
-rwxr-xr-x | view/tpl/conv_list.tpl | 176 | ||||
-rwxr-xr-x | view/tpl/jot.tpl | 4 | ||||
-rw-r--r-- | view/tpl/mitemedit.tpl | 2 | ||||
-rwxr-xr-x | view/tpl/photo_view.tpl | 4 | ||||
-rwxr-xr-x | view/tpl/photos_upload.tpl | 4 | ||||
-rwxr-xr-x | view/tpl/settings_display.tpl | 4 |
28 files changed, 902 insertions, 235 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/doc/Widgets.md b/doc/Widgets.md index 48006adcd..dcf8dfb48 100644 --- a/doc/Widgets.md +++ b/doc/Widgets.md @@ -39,6 +39,12 @@ Some/many of these widgets have restrictions which may restrict the type of page * categories - categories filter (channel page) * tagcloud_wall - tagcloud for channel page only + * args: 'limit' - number of tags to return (default 50) +<br /> <br /> + +* catcloud_wall - tagcloud for channel page categories + * args: 'limit' - number of categories to return (default 50) +<br /> <br /> * affinity - affinity slider for network page - must be logged in diff --git a/include/ItemObject.php b/include/ItemObject.php index 9e694b8ac..6f1c76fa1 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) { @@ -78,6 +79,7 @@ class Item extends BaseObject { $indent = ''; $osparkle = ''; $total_children = $this->count_descendants(); + $unseen_comments = (($item->real_uid) ? 0 : $this->count_unseen_descendants()); $conv = $this->get_conversation(); $observer = $conv->get_observer(); @@ -226,11 +228,14 @@ 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 ); + $list_unseen_txt = (($unseen_comments) ? sprintf('%d unseen',$unseen_comments) : ''); + $children = $this->get_children(); $tmp_item = array( @@ -243,6 +248,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'), @@ -287,8 +293,12 @@ class Item extends BaseObject { 'drop' => $drop, 'multidrop' => ((feature_enabled($conv->get_profile_owner(),'multi_delete')) ? $multidrop : ''), // end toolbar buttons + + 'unseen_comments' => $unseen_comments, 'comment_count' => $total_children, 'comment_count_txt' => $comment_count_txt, + 'list_unseen_txt' => $list_unseen_txt, + 'markseen' => t('Mark all seen'), 'like_count' => $like_count, 'like_list' => $like_list, 'like_list_part' => $like_list_part, @@ -315,7 +325,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 +363,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 +522,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; } @@ -533,6 +552,23 @@ class Item extends BaseObject { return $total; } + private function count_unseen_descendants() { + $children = $this->get_children(); + $total = count($children); + if($total > 0) { + $total = 0; + foreach($children as $child) { + if((! visible_activity($child->data)) || array_key_exists('author_blocked',$child->data)) { + continue; + } + if($child->data['item_flags'] & ITEM_UNSEEN) + $total ++; + } + } + return $total; + } + + /** * Get the template for the comment box */ 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/items.php b/include/items.php index 6447de4e7..19de52e92 100755 --- a/include/items.php +++ b/include/items.php @@ -66,6 +66,8 @@ function collect_recipients($item,&$private_envelope) { // by the directives in $item['public_policy']. $private_envelope = false; + require_once('include/identity.php'); + $sys = get_sys_channel(); if(array_key_exists('public_policy',$item) && $item['public_policy'] !== 'self') { $r = q("select abook_xchan, xchan_network from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d and not (abook_flags & %d)>0 ", @@ -95,6 +97,9 @@ function collect_recipients($item,&$private_envelope) { } } } +// we probably want to check that discovery channel delivery is allowed before uncommenting this. +// if($policy === 'pub') +// $recipients[] = $sys['xchan_hash']; } } 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..54b25ad8b 100644 --- a/mod/channel.php +++ b/mod/channel.php @@ -137,6 +137,11 @@ function channel_content(&$a, $update = 0, $load = false) { $sql_extra = item_permissions_sql($a->profile['profile_uid'],$remote_contact,$groups); + if(get_pconfig($a->profile['profile_uid'],'system','channel_list_mode')) + $page_mode = 'list'; + else + $page_mode = 'client'; + if(($update) && (! $load)) { if ($mid) { @@ -246,9 +251,14 @@ function channel_content(&$a, $update = 0, $load = false) { // This is ugly, but we can't pass the profile_uid through the session to the ajax updater, // because browser prefetching might change it on us. We have to deliver it with the page. + $maxheight = get_pconfig($a->profile['profile_uid'],'system','channel_divmore_height'); + if(! $maxheight) + $maxheight = 400; + $o .= '<div id="live-channel"></div>' . "\r\n"; $o .= "<script> var profile_uid = " . $a->profile['profile_uid'] - . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n"; + . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] + . "; divmore_height = " . intval($maxheight) . "; </script>\r\n"; $a->page['htmlhead'] .= replace_macros(get_markup_template("build_query.tpl"),array( '$baseurl' => z_root(), @@ -279,12 +289,31 @@ function channel_content(&$a, $update = 0, $load = false) { } + $update_unseen = ''; + if($page_mode === 'list') { - if($is_owner) { + /** + * in "list mode", only mark the parent item and any like activities as "seen". + * We won't distinguish between comment likes and post likes. The important thing + * is that the number of unseen comments will be accurate. The SQL to separate the + * comment likes could also get somewhat hairy. + */ + + if($parents_str) { + $update_unseen = " AND ( id IN ( " . dbesc($parents_str) . " )"; + $update_unseen .= " OR ( parent IN ( " . dbesc($parents_str) . " ) AND verb in ( '" . dbesc(ACTIVITY_LIKE) . "','" . dbesc(ACTIVITY_DISLIKE) . "' ))) "; + } + } + else { + if($parents_str) { + $update_unseen = " AND parent IN ( " . dbesc($parents_str) . " )"; + } + } + if($is_owner && $update_unseen) { $r = q("UPDATE item SET item_flags = (item_flags & ~%d) - WHERE (item_flags & %d)>0 AND (item_flags & %d)>0 AND uid = %d ", + WHERE (item_flags & %d) > 0 AND (item_flags & %d) > 0 AND uid = %d $update_unseen", intval(ITEM_UNSEEN), intval(ITEM_UNSEEN), intval(ITEM_WALL), @@ -294,7 +323,7 @@ function channel_content(&$a, $update = 0, $load = false) { 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..522622f03 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,67 @@ 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; + + $maxheight = get_pconfig(local_user(),'system','network_divmore_height'); + if(! $maxheight) + $maxheight = 400; + $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'] + . "; divmore_height = " . intval($maxheight) . "; </script>\r\n"; $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 +254,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 +274,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 +297,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 +324,38 @@ 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 " : ''); + if(get_pconfig(local_user(),'system','network_list_mode')) + $page_mode = 'list'; + else + $page_mode = 'client'; + + $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 +369,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 +379,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 +391,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 +411,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,19 +421,35 @@ 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(); } - if($parents_str) - $update_unseen = ' AND parent IN ( ' . dbesc($parents_str) . ' )'; + if($page_mode === 'list') { + /** + * in "list mode", only mark the parent item and any like activities as "seen". + * We won't distinguish between comment likes and post likes. The important thing + * is that the number of unseen comments will be accurate. The SQL to separate the + * comment likes could also get somewhat hairy. + */ + + if($parents_str) { + $update_unseen = " AND ( id IN ( " . dbesc($parents_str) . " )"; + $update_unseen .= " OR ( parent IN ( " . dbesc($parents_str) . " ) AND verb in ( '" . dbesc(ACTIVITY_LIKE) . "','" . dbesc(ACTIVITY_DISLIKE) . "' ))) "; + } + } + else { + if($parents_str) { + $update_unseen = " AND parent IN ( " . dbesc($parents_str) . " )"; + } + } } 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 +457,11 @@ function network_content(&$a, $update = 0, $load = false) { $mode = (($nouveau) ? 'network-new' : 'network'); - $o .= conversation($a,$items,$mode,$update,'client'); - if(($items) && (! $update)) - $o .= alt_pager($a,count($items)); + $o .= conversation($a,$items,$mode,$update,$page_mode); + + if(($items) && (! $update)) + $o .= alt_pager($a,count($items)); return $o; } diff --git a/mod/photos.php b/mod/photos.php index ab1e4b48a..ab848c709 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -618,7 +618,7 @@ function photos_content(&$a) { $album = hex2bin($datum); $r = q("SELECT `resource_id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s' - AND `scale` <= 4 and ((photo_flags = %d) or (photo_flags & %d )) $sql_extra GROUP BY `resource_id`", + AND `scale` <= 4 and ((photo_flags = %d) or (photo_flags & %d ) > 0) $sql_extra GROUP BY `resource_id`", intval($owner_uid), dbesc($album), intval(PHOTO_NORMAL), @@ -1160,7 +1160,7 @@ function photos_content(&$a) { //$o = ''; $r = q("SELECT `resource_id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' - and ((photo_flags = %d) or (photo_flags & %d)) $sql_extra GROUP BY `resource_id`", + and ((photo_flags = %d) or (photo_flags & %d) > 0) $sql_extra GROUP BY `resource_id`", intval($a->data['channel']['channel_id']), dbesc('Contact Photos'), dbesc( t('Contact Photos')), diff --git a/mod/ping.php b/mod/ping.php index d7b9e3d2e..ef8afd91c 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -150,14 +150,14 @@ function ping_init(&$a) { if(x($_REQUEST, 'markRead') && local_user()) { switch($_REQUEST['markRead']) { case 'network': - $r = q("update item set item_flags = ( item_flags & ~%d ) where (item_flags & %d)>0 and uid = %d", + $r = q("update item set item_flags = ( item_flags & ~%d ) where (item_flags & %d) > 0 and uid = %d", intval(ITEM_UNSEEN), intval(ITEM_UNSEEN), intval(local_user()) ); break; case 'home': - $r = q("update item set item_flags = ( item_flags & ~%d ) where (item_flags & %d)>0 and (item_flags & %d) and uid = %d", + $r = q("update item set item_flags = ( item_flags & ~%d ) where (item_flags & %d) > 0 and (item_flags & %d) > 0 and uid = %d", intval(ITEM_UNSEEN), intval(ITEM_UNSEEN), intval(ITEM_WALL), @@ -165,7 +165,7 @@ function ping_init(&$a) { ); break; case 'messages': - $r = q("update mail set mail_flags = ( mail_flags | %d ) where channel_id = %d and not (mail_flags & %d)>0", + $r = q("update mail set mail_flags = ( mail_flags | %d ) where channel_id = %d and not (mail_flags & %d) > 0", intval(MAIL_SEEN), intval(local_user()), intval(MAIL_SEEN) @@ -186,6 +186,14 @@ function ping_init(&$a) { } } + if(x($_REQUEST, 'markItemRead') && local_user()) { + $r = q("update item set item_flags = ( item_flags & ~%d ) where parent = %d and uid = %d", + intval(ITEM_UNSEEN), + intval($_REQUEST['markItemRead']), + intval(local_user()) + ); + } + /** @@ -237,7 +245,7 @@ function ping_init(&$a) { if(argc() > 1 && argv(1) === 'messages') { $channel = $a->get_channel(); $t = q("select mail.*, xchan.* from mail left join xchan on xchan_hash = from_xchan - where channel_id = %d and not ( mail_flags & %d )>0 and not (mail_flags & %d )>0 + where channel_id = %d and not ( mail_flags & %d ) > 0 and not (mail_flags & %d ) > 0 and from_xchan != '%s' order by created desc limit 50", intval(local_user()), intval(MAIL_SEEN), @@ -267,7 +275,7 @@ function ping_init(&$a) { $result = array(); $r = q("SELECT * FROM item - WHERE item_restrict = %d and ( item_flags & %d )>0 and uid = %d", + WHERE item_restrict = %d and ( item_flags & %d ) > 0 and uid = %d", intval(ITEM_VISIBLE), intval(ITEM_UNSEEN), intval(local_user()) @@ -289,7 +297,7 @@ function ping_init(&$a) { if(argc() > 1 && (argv(1) === 'intros')) { $result = array(); - $r = q("SELECT * FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and (abook_flags & %d)>0 and not ((abook_flags & %d)>0 or (xchan_flags & %d)>0)", + $r = q("SELECT * FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and (abook_flags & %d) > 0 and not ((abook_flags & %d) > 0 or (xchan_flags & %d) > 0)", intval(local_user()), intval(ABOOK_FLAG_PENDING), intval(ABOOK_FLAG_SELF|ABOOK_FLAG_IGNORED), @@ -373,7 +381,7 @@ function ping_init(&$a) { if($vnotify & (VNOTIFY_NETWORK|VNOTIFY_CHANNEL)) { $r = q("SELECT id, item_restrict, item_flags FROM item - WHERE (item_restrict = %d) and ( item_flags & %d )>0 and uid = %d", + WHERE (item_restrict = %d) and ( item_flags & %d ) > 0 and uid = %d", intval(ITEM_VISIBLE), intval(ITEM_UNSEEN), intval(local_user()) @@ -400,7 +408,7 @@ function ping_init(&$a) { $t2 = dba_timer(); if($vnotify & VNOTIFY_INTRO) { - $intr = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and (abook_flags & %d)>0 and not ((abook_flags & %d)>0 or (xchan_flags & %d)>0)", + $intr = q("SELECT COUNT(abook.abook_id) AS total FROM abook left join xchan on abook.abook_xchan = xchan.xchan_hash where abook_channel = %d and (abook_flags & %d) > 0 and not ((abook_flags & %d) > 0 or (xchan_flags & %d) > 0)", intval(local_user()), intval(ABOOK_FLAG_PENDING), intval(ABOOK_FLAG_SELF|ABOOK_FLAG_IGNORED), @@ -418,7 +426,7 @@ function ping_init(&$a) { if($vnotify & VNOTIFY_MAIL) { $mails = q("SELECT count(id) as total from mail - WHERE channel_id = %d AND not (mail_flags & %d)>0 and from_xchan != '%s' ", + WHERE channel_id = %d AND not (mail_flags & %d) > 0 and from_xchan != '%s' ", intval(local_user()), intval(MAIL_SEEN), dbesc($channel['channel_hash']) @@ -429,7 +437,7 @@ function ping_init(&$a) { if($vnotify & VNOTIFY_REGISTER) { if ($a->config['system']['register_policy'] == REGISTER_APPROVE && is_site_admin()) { - $regs = q("SELECT count(account_id) as total from account where (account_flags & %d)>0", + $regs = q("SELECT count(account_id) as total from account where (account_flags & %d) > 0", intval(ACCOUNT_PENDING) ); if($regs) diff --git a/mod/poco.php b/mod/poco.php index fc01fc565..3f932e92f 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -69,7 +69,7 @@ function poco_init(&$a) { if($system_mode) { $r = q("SELECT count(*) as `total` from abook where ( abook_flags & " . ABOOK_FLAG_SELF . - " )>0 and abook_channel in (select uid from pconfig where cat = 'system' and k = 'suggestme' and v = 1) "); + " )>0 and abook_channel in (select uid from pconfig where cat = 'system' and k = 'suggestme' and v = '1') "); } else { $r = q("SELECT count(*) as `total` from abook where abook_channel = %d @@ -93,7 +93,7 @@ function poco_init(&$a) { if($system_mode) { $r = q("SELECT abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash where ( abook_flags & " . ABOOK_FLAG_SELF . - " )>0 and abook_channel in (select uid from pconfig where cat = 'system' and k = 'suggestme' and v = 1) limit %d offset %d ", + " )>0 and abook_channel in (select uid from pconfig where cat = 'system' and k = 'suggestme' and v = '1') limit %d offset %d ", intval($itemsPerPage), intval($startIndex) ); diff --git a/mod/settings.php b/mod/settings.php index 396bb2972..ab6638ccb 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -140,6 +140,16 @@ 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); + + $channel_divmore_height = ((x($_POST,'channel_divmore_height')) ? intval($_POST['channel_divmore_height']) : 400); + if($channel_divmore_height < 50) + $channel_divmore_height = 50; + $network_divmore_height = ((x($_POST,'network_divmore_height')) ? intval($_POST['network_divmore_height']) : 400); + if($network_divmore_height < 50) + $network_divmore_height = 50; + $browser_update = ((x($_POST,'browser_update')) ? intval($_POST['browser_update']) : 0); $browser_update = $browser_update * 1000; if($browser_update < 10000) @@ -159,6 +169,10 @@ 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); + set_pconfig(local_user(),'system','channel_divmore_height', $channel_divmore_height); + set_pconfig(local_user(),'system','network_divmore_height', $network_divmore_height); if ($theme == $a->channel['channel_theme']){ // call theme_post only if theme has not been changed @@ -722,6 +736,7 @@ function settings_content(&$a) { /* * DISPLAY SETTINGS */ + if((argc() > 1) && (argv(1) === 'display')) { $default_theme = get_config('system','theme'); if(! $default_theme) @@ -801,6 +816,12 @@ 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)')), + '$channel_divmore_height' => array('channel_divmore_height', t('Channel page max height of content (in pixels)'), ((get_pconfig(local_user(),'system','channel_divmore_height')) ? get_pconfig(local_user(),'system','channel_divmore_height') : 400), t('click to expand content exceeding this height')), + '$network_divmore_height' => array('network_divmore_height', t('Matrix page max height of content (in pixels)'), ((get_pconfig(local_user(),'system','network_divmore_height')) ? get_pconfig(local_user(),'system','network_divmore_height') : 400) , t('click to expand content exceeding this height')), + + )); return $o; diff --git a/version.inc b/version.inc index 0ea73e309..2679ebdf3 100644 --- a/version.inc +++ b/version.inc @@ -1 +1 @@ -2014-11-15.860 +2014-11-18.863 diff --git a/view/js/acl.js b/view/js/acl.js index f9fd66bab..f9428e1c5 100644 --- a/view/js/acl.js +++ b/view/js/acl.js @@ -273,6 +273,5 @@ ACL.prototype.populate = function(data){ $(el).removeAttr("data-src"); }); that.update_view(); - $('#dbtn-submit, #dbtn-acl').prop('disabled', false); } diff --git a/view/js/main.js b/view/js/main.js index a55b8fbb1..8939f4a09 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -180,6 +180,13 @@ timer = setTimeout(NavUpdate,2000); } + function markItemRead(itemId) { + $.get('ping?f=&markItemRead='+itemId); + $('.unseen-wall-indicator-'+itemId).hide(); + } + + + var src = null; var prev = null; var livetime = null; @@ -200,6 +207,7 @@ var loadingPage = true; var pageHasMoreContent = true; var updateCountsOnly = false; + var divmore_height = 400; $(function() { $.ajaxSetup({cache: false}); @@ -458,25 +466,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 +508,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 +519,6 @@ function updateConvItems(mode,data) { if(isVisible) showHideComments(itmId); $(".autotime").timeago(); - // $("div.wall-item-body").divgrow({ initialHeight: 400 }); } }); @@ -557,7 +554,6 @@ function updateConvItems(mode,data) { showHideComments(itmId); $(".autotime").timeago(); - // $("div.wall-item-body").divgrow({ initialHeight: 400 }); } prev = ident; }); @@ -597,17 +593,15 @@ function updateConvItems(mode,data) { function collapseHeight() { $(".wall-item-body").each(function() { - if($(this).height() > 410) { + if($(this).height() > divmore_height + 10) { if(! $(this).hasClass('divmore')) { - $(this).divgrow({ initialHeight: 400, moreText: aStr['divgrowmore'], lessText: aStr['divgrowless'], showBrackets: false }); + $(this).divgrow({ initialHeight: divmore_height, moreText: aStr['divgrowmore'], lessText: aStr['divgrowless'], showBrackets: false }); $(this).addClass('divmore'); } } }); } - - function liveUpdate() { if((src == null) || (stopped) || (! profile_uid)) { $('.like-rotator').spin(false); return; } if(($('.comment-edit-text-full').length) || (in_progress)) { diff --git a/view/tpl/attach_edit.tpl b/view/tpl/attach_edit.tpl index 1254c713b..a2a4af16b 100644 --- a/view/tpl/attach_edit.tpl +++ b/view/tpl/attach_edit.tpl @@ -5,7 +5,7 @@ <form action="filestorage/{{$channelnick}}/{{$file.id}}/edit" method="post" > <div id="attach-edit-perms" > -<button id="dbtn-acl" class="btn btn-default btn-sm" data-toggle="modal" data-target="#aclModal" title="{{$permset}}" disabled="disabled" onclick="return false;"> +<button id="dbtn-acl" class="btn btn-default btn-sm" data-toggle="modal" data-target="#aclModal" title="{{$permset}}" onclick="return false;"> <i id="jot-perms-icon" class="icon-{{$lockstate}} jot-icons"></i> </button> {{$aclselect}} {{$file.filename}} @@ -30,7 +30,7 @@ <input type="text" id="linkpasteinput" name="cutpasteextlink" value="{{$cloudpath}}" onclick="this.select();"/><br /> <div class="clear"></div> -<input id="dbtn-submit" type="submit" name="submit" value="{{$submit}}" disabled="disabled"/> +<input id="dbtn-submit" type="submit" name="submit" value="{{$submit}}" /> </form> diff --git a/view/tpl/chatroom_new.tpl b/view/tpl/chatroom_new.tpl index bb1121924..a559dba54 100644 --- a/view/tpl/chatroom_new.tpl +++ b/view/tpl/chatroom_new.tpl @@ -2,12 +2,12 @@ <form action="chat" method="post" > {{include file="field_input.tpl" field=$name}} -<button id="dbtn-acl" class="btn btn-default btn-xs" data-toggle="modal" data-target="#aclModal" onclick="return false;" disabled="disabled">{{$permissions}}</button> +<button id="dbtn-acl" class="btn btn-default btn-xs" data-toggle="modal" data-target="#aclModal" onclick="return false;" >{{$permissions}}</button> {{$acl}} <div class="clear"></div> <br /> <br /> -<input id="dbtn-submit" type="submit" name="submit" value="{{$submit}}" disabled="disabled"/> +<input id="dbtn-submit" type="submit" name="submit" value="{{$submit}}" /> </form> diff --git a/view/tpl/conv_list.tpl b/view/tpl/conv_list.tpl new file mode 100755 index 000000000..b9a966e93 --- /dev/null +++ b/view/tpl/conv_list.tpl @@ -0,0 +1,176 @@ +{{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}}{{if $item.unseen_comments}} +<span class="unseen-wall-indicator-{{$item.id}}">, {{$item.list_unseen_txt}}{{/if}}</span></a>{{if $item.unseen_comments}}<span class="unseen-wall-indicator-{{$item.id}}"> <button class="btn btn-default" title="{{$item.markseen}}" onclick="markItemRead({{$item.id}}); return false;"><i class="icon-check"></i></span>{{/if}}</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/jot.tpl b/view/tpl/jot.tpl index c77d49a74..f172a6dfa 100755 --- a/view/tpl/jot.tpl +++ b/view/tpl/jot.tpl @@ -76,7 +76,7 @@ </div> <div id="profile-jot-submit-right" class="btn-group pull-right"> {{if $showacl}} - <button id="dbtn-acl" class="btn btn-default btn-sm" data-toggle="modal" data-target="#aclModal" title="{{$permset}}" disabled="disabled" onclick="return false;"> + <button id="dbtn-acl" class="btn btn-default btn-sm" data-toggle="modal" data-target="#aclModal" title="{{$permset}}" onclick="return false;"> <i id="jot-perms-icon" class="icon-{{$lockstate}} jot-icons">{{$bang}}</i> </button> {{/if}} @@ -85,7 +85,7 @@ <i class="icon-eye-open jot-icons" ></i> </button> {{/if}} - <button id="dbtn-submit" class="btn btn-primary btn-sm" type="submit" name="button-submit"{{if $showacl}} disabled="disabled"{{/if}}>{{$share}}</button> + <button id="dbtn-submit" class="btn btn-primary btn-sm" type="submit" name="button-submit" >{{$share}}</button> </div> <div id="profile-jot-perms-end"></div> <div id="profile-jot-plugin-wrapper"> diff --git a/view/tpl/mitemedit.tpl b/view/tpl/mitemedit.tpl index f398cf02c..a18fbb0ef 100644 --- a/view/tpl/mitemedit.tpl +++ b/view/tpl/mitemedit.tpl @@ -26,7 +26,7 @@ <div class="mitemedit-submit-wrapper" > -<input id="dbtn-submit" type="submit" name="submit" class="mitemedit-submit" value="{{$submit}}" disabled="disabled" /> +<input id="dbtn-submit" type="submit" name="submit" class="mitemedit-submit" value="{{$submit}}" /> </div> </form> diff --git a/view/tpl/photo_view.tpl b/view/tpl/photo_view.tpl index 4652f33c6..a741a5ce7 100755 --- a/view/tpl/photo_view.tpl +++ b/view/tpl/photo_view.tpl @@ -68,10 +68,10 @@ <button class="btn btn-danger btn-sm" id="photo-edit-delete-button" type="submit" name="delete" value="{{$edit.delete}}" onclick="return confirmDelete();" />{{$edit.delete}}</button> </div> <div class="form-group btn-group pull-right"> - <button id="dbtn-acl" class="btn btn-default btn-sm" data-toggle="modal" data-target="#aclModal" disabled="disabled" onclick="return false;"> + <button id="dbtn-acl" class="btn btn-default btn-sm" data-toggle="modal" data-target="#aclModal" onclick="return false;"> <i id="jot-perms-icon" class="icon-{{$edit.lockstate}}"></i> </button> - <button id="dbtn-submit" class="btn btn-primary btn-sm" type="submit" name="submit" disabled="disabled">{{$edit.submit}}</button> + <button id="dbtn-submit" class="btn btn-primary btn-sm" type="submit" name="submit" >{{$edit.submit}}</button> </div> </form> <div id="photo-edit-end" class="clear"></div> diff --git a/view/tpl/photos_upload.tpl b/view/tpl/photos_upload.tpl index 2dd7de9b2..a04038aa2 100755 --- a/view/tpl/photos_upload.tpl +++ b/view/tpl/photos_upload.tpl @@ -22,10 +22,10 @@ <input id="photos-upload-choose" type="file" name="userfile" /> </div> <div class="btn-group pull-right"> - <button id="dbtn-acl" class="btn btn-default btn-sm" data-toggle="modal" data-target="#aclModal" disabled="disabled" onclick="return false;"> + <button id="dbtn-acl" class="btn btn-default btn-sm" data-toggle="modal" data-target="#aclModal" onclick="return false;"> <i id="jot-perms-icon" class="icon-{{$lockstate}}"></i> </button> - <button id="dbtn-submit" class="btn btn-primary btn-sm" type="submit" name="submit" disabled="disabled">{{$submit}}</button> + <button id="dbtn-submit" class="btn btn-primary btn-sm" type="submit" name="submit" >{{$submit}}</button> </div> {{/if}} diff --git a/view/tpl/settings_display.tpl b/view/tpl/settings_display.tpl index d3134ea88..8bf4dc0cc 100755 --- a/view/tpl/settings_display.tpl +++ b/view/tpl/settings_display.tpl @@ -11,8 +11,12 @@ {{/if}} {{include file="field_input.tpl" field=$ajaxint}} {{include file="field_input.tpl" field=$itemspage}} +{{include file="field_input.tpl" field=$channel_divmore_height}} +{{include file="field_input.tpl" field=$network_divmore_height}} {{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}}" /> |