diff --git a/boot.php b/boot.php index 4a55e757..78ef7fea 100755 --- a/boot.php +++ b/boot.php @@ -2,418 +2,482 @@ set_time_limit(0); -define ( 'BUILD_ID', 1000 ); +define('BUILD_ID', 1000); -define ( 'EOL', "
\r\n"); +define('EOL', "
\r\n"); -define ( 'REGISTER_CLOSED', 0); -define ( 'REGISTER_APPROVE', 1); -define ( 'REGISTER_OPEN', 2); +define('REGISTER_CLOSED', 0); +define('REGISTER_APPROVE', 1); +define('REGISTER_OPEN', 2); -define ( 'DIRECTION_NONE', 0); -define ( 'DIRECTION_IN', 1); -define ( 'DIRECTION_OUT', 2); -define ( 'DIRECTION_BOTH', 3); +define('DIRECTION_NONE', 0); +define('DIRECTION_IN', 1); +define('DIRECTION_OUT', 2); +define('DIRECTION_BOTH', 3); -define ( 'NOTIFY_INTRO', 0x0001 ); -define ( 'NOTIFY_CONFIRM', 0x0002 ); -define ( 'NOTIFY_WALL', 0x0004 ); -define ( 'NOTIFY_COMMENT', 0x0008 ); -define ( 'NOTIFY_MAIL', 0x0010 ); +define('NOTIFY_INTRO', 0x0001); +define('NOTIFY_CONFIRM', 0x0002); +define('NOTIFY_WALL', 0x0004); +define('NOTIFY_COMMENT', 0x0008); +define('NOTIFY_MAIL', 0x0010); -define ( 'NAMESPACE_DFRN' , 'http://purl.org/macgirvin/dfrn/1.0' ); +define('NAMESPACE_DFRN', 'http://purl.org/macgirvin/dfrn/1.0'); /** * log levels */ -define ( 'LOGGER_NORMAL', 0 ); -define ( 'LOGGER_TRACE', 1 ); -define ( 'LOGGER_DEBUG', 2 ); -define ( 'LOGGER_DATA', 3 ); -define ( 'LOGGER_ALL', 4 ); +define('LOGGER_NORMAL', 0); +define('LOGGER_TRACE', 1); +define('LOGGER_DEBUG', 2); +define('LOGGER_DATA', 3); +define('LOGGER_ALL', 4); -if(! class_exists('App')) { -class App { - - public $module_loaded = false; - public $query_string; - public $config; - public $page; - public $profile; - public $user; - public $cid; - public $contact; - public $content; - public $data; - public $error = false; - public $cmd; - public $argv; - public $argc; - public $module; - public $pager; - public $strings; - public $path; +class App +{ + public $module_loaded = false; + public $query_string; + public $config; + public $page; + public $profile; + public $user; + public $cid; + public $contact; + public $content; + public $data; + public $error = false; + public $cmd; + public $argv; + public $argc; + public $module; + public $pager; + public $strings; + public $path; private $scheme; private $hostname; private $baseurl; private $db; - function __construct() { - + public function __construct() + { $this->config = array(); $this->page = array(); $this->pager= array(); $this->scheme = ((isset($_SERVER['HTTPS']) - && ($_SERVER['HTTPS'])) ? 'https' : 'http' ); - $this->hostname = str_replace('www.','', - $_SERVER['SERVER_NAME']); + && ($_SERVER['HTTPS'])) ? 'https' : 'http'); + $this->hostname = str_replace('www.', '', + $_SERVER['SERVER_NAME']); set_include_path("include/$this->hostname" - . PATH_SEPARATOR . 'include' - . PATH_SEPARATOR . '.' ); + . PATH_SEPARATOR . 'include' + . PATH_SEPARATOR . '.'); - if(substr($_SERVER['QUERY_STRING'],0,2) == "q=") - $_SERVER['QUERY_STRING'] = substr($_SERVER['QUERY_STRING'],2); + if (substr($_SERVER['QUERY_STRING'], 0, 2) == "q=") { + $_SERVER['QUERY_STRING'] = substr($_SERVER['QUERY_STRING'], 2); + } $this->query_string = $_SERVER['QUERY_STRING']; $q = isset($_GET['q']) ? $_GET['q'] : ''; $this->cmd = trim($q, '/'); - $this->argv = explode('/',$this->cmd); + $this->argv = explode('/', $this->cmd); $this->argc = count($this->argv); - if((array_key_exists('0',$this->argv)) && strlen($this->argv[0])) { + if ((array_key_exists('0', $this->argv)) && strlen($this->argv[0])) { $this->module = $this->argv[0]; - } - else { + } else { $this->module = 'directory'; } - $this->pager['page'] = ((x($_GET,'page')) ? $_GET['page'] : 1); + $this->pager['page'] = ((x($_GET, 'page')) ? $_GET['page'] : 1); $this->pager['itemspage'] = 50; $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage']; $this->pager['total'] = 0; } - function get_baseurl($ssl = false) { - if(strlen($this->baseurl)) + public function get_baseurl($ssl = false) + { + if (strlen($this->baseurl)) { return $this->baseurl; + } $this->baseurl = (($ssl) ? 'https' : $this->scheme) . "://" . $this->hostname - . ((isset($this->path) && strlen($this->path)) - ? '/' . $this->path : '' ); + . ((isset($this->path) && strlen($this->path)) + ? '/' . $this->path : ''); return $this->baseurl; } - function set_baseurl($url) { + public function set_baseurl($url) + { $this->baseurl = $url; $this->hostname = basename($url); } - function get_hostname() { + public function get_hostname() + { return $this->hostname; } - function set_hostname($h) { + public function set_hostname($h) + { $this->hostname = $h; } - function set_path($p) { - $this->path = ltrim(trim($p),'/'); + public function set_path($p) + { + $this->path = ltrim(trim($p), '/'); } - function get_path() { + public function get_path() + { return $this->path; } - function set_pager_total($n) { + public function set_pager_total($n) + { $this->pager['total'] = intval($n); } - function set_pager_itemspage($n) { + public function set_pager_itemspage($n) + { $this->pager['itemspage'] = intval($n); $this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage']; - } - function init_pagehead() { - if(file_exists("view/head.tpl")) + public function init_pagehead() + { + if (file_exists("view/head.tpl")) { $s = file_get_contents("view/head.tpl"); - $this->page['htmlhead'] = replace_macros($s,array( - '$baseurl' => $this->get_baseurl() - )); - } - -}} - - -if(! function_exists('x')) { -function x($s,$k = NULL) { - if($k != NULL) { - if((is_array($s)) && (array_key_exists($k,$s))) { - if($s[$k]) - return (int) 1; - return (int) 0; } - return false; + $this->page['htmlhead'] = replace_macros($s, array( + '$baseurl' => $this->get_baseurl() + )); } - else { - if(isset($s)) { - if($s) { - return (int) 1; +} + + +if (! function_exists('x')) { + function x($s, $k = null) + { + if ($k != null) { + if ((is_array($s)) && (array_key_exists($k, $s))) { + if ($s[$k]) { + return (int) 1; + } + return (int) 0; } - return (int) 0; + return false; + } else { + if (isset($s)) { + if ($s) { + return (int) 1; + } + return (int) 0; + } + return false; + } + } +} + +if (! function_exists('system_unavailable')) { + function system_unavailable() + { + include('system_unavailable.php'); + killme(); + } +} + +if (! function_exists('logger')) { + function logger($msg, $level = 0) + { + $debugging = 1; + $loglevel = LOGGER_ALL; + $logfile = 'logfile.out'; + + if ((! $debugging) || (! $logfile) || ($level > $loglevel)) { + return; + } + require_once('include/datetime.php'); + + @file_put_contents($logfile, datetime_convert() . ':' . ' ' . $msg . "\n", FILE_APPEND); + return; + } +} + + +if (! function_exists('replace_macros')) { + function replace_macros($s, $r) + { + $search = array(); + $replace = array(); + + if (is_array($r) && count($r)) { + foreach ($r as $k => $v) { + $search[] = $k; + $replace[] = $v; + } + } + return str_replace($search, $replace, $s); + } +} + + +if (! function_exists('load_translation_table')) { + function load_translation_table($lang) + { + global $a; + } +} + +if (! function_exists('t')) { + function t($s) + { + global $a; + + if ($a->strings[$s]) { + return $a->strings[$s]; + } + return $s; + } +} + + + + +if (! function_exists('fetch_url')) { + function fetch_url($url, $binary = false, $timeout=20) + { + $ch = curl_init($url); + if (! $ch) { + return false; + } + + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_TIMEOUT, max(intval($timeout), 1)); //Minimum of 1 second timeout. + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_MAXREDIRS, 8); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + if ($binary) { + curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); + } + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + $s = curl_exec($ch); + curl_close($ch); + return($s); + } +} + + +if (! function_exists('post_url')) { + function post_url($url, $params) + { + $ch = curl_init($url); + if (! $ch) { + return false; + } + + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_MAXREDIRS, 8); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $params); + $s = curl_exec($ch); + curl_close($ch); + return($s); + } +} + + +if (! function_exists('random_string')) { + function random_string() + { + return(hash('sha256', uniqid(rand(), true))); + } +} + +if (! function_exists('notags')) { + function notags($string) + { + // protect against :<> with high-bit set + return(str_replace(array("<", ">", "\xBA", "\xBC", "\xBE"), array('[', ']', '', '', ''), $string)); + } +} + +if (! function_exists('escape_tags')) { + function escape_tags($string) + { + return(htmlspecialchars($string)); + } +} + +if (! function_exists('login')) { + function login($register = false) + { + $o = ""; + $register_html = (($register) ? file_get_contents("view/register-link.tpl") : ""); + + + if (x($_SESSION, 'authenticated')) { + $o = file_get_contents("view/logout.tpl"); + } else { + $o = file_get_contents("view/login.tpl"); + + $o = replace_macros($o, array('$register_html' => $register_html )); + } + return $o; + } +} + + +if (! function_exists('killme')) { + function killme() + { + session_write_close(); + closedb(); + exit; + } +} + +if (! function_exists('goaway')) { + function goaway($s) + { + header("Location: $s"); + killme(); + } +} + +if (! function_exists('local_user')) { + function local_user() + { + if ((x($_SESSION, 'authenticated')) && (x($_SESSION, 'uid'))) { + return $_SESSION['uid']; } return false; } -}} +} -if(! function_exists('system_unavailable')) { -function system_unavailable() { - include('system_unavailable.php'); - killme(); -}} - -if(! function_exists('logger')) { -function logger($msg,$level = 0) { - $debugging = 1; - $loglevel = LOGGER_ALL; - $logfile = 'logfile.out'; - - if((! $debugging) || (! $logfile) || ($level > $loglevel)) - return; - require_once('include/datetime.php'); - - @file_put_contents($logfile, datetime_convert() . ':' . ' ' . $msg . "\n", FILE_APPEND); - return; -}} - - -if(! function_exists('replace_macros')) { -function replace_macros($s,$r) { - - $search = array(); - $replace = array(); - - if(is_array($r) && count($r)) { - foreach ($r as $k => $v ) { - $search[] = $k; - $replace[] = $v; +if (! function_exists('notice')) { + function notice($s) + { + if (!isset($_SESSION['sysmsg'])) { + $_SESSION['sysmsg'] = ''; } + $_SESSION['sysmsg'] .= $s; } - return str_replace($search,$replace,$s); -}} +} - -if(! function_exists('load_translation_table')) { -function load_translation_table($lang) { - global $a; - -}} - -if(! function_exists('t')) { -function t($s) { - global $a; - - if($a->strings[$s]) - return $a->strings[$s]; - return $s; -}} - - - - -if(! function_exists('fetch_url')) { -function fetch_url($url,$binary = false, $timeout=20) { - $ch = curl_init($url); - if(! $ch) return false; - - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_TIMEOUT, max(intval($timeout), 1)); //Minimum of 1 second timeout. - curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true); - curl_setopt($ch, CURLOPT_MAXREDIRS,8); - curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); - if($binary) - curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - $s = curl_exec($ch); - curl_close($ch); - return($s); -}} - - -if(! function_exists('post_url')) { -function post_url($url,$params) { - $ch = curl_init($url); - if(! $ch) return false; - - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true); - curl_setopt($ch, CURLOPT_MAXREDIRS,8); - curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); - curl_setopt($ch, CURLOPT_POST,1); - curl_setopt($ch, CURLOPT_POSTFIELDS,$params); - $s = curl_exec($ch); - curl_close($ch); - return($s); -}} - - -if(! function_exists('random_string')) { -function random_string() { - return(hash('sha256',uniqid(rand(),true))); -}} - -if(! function_exists('notags')) { -function notags($string) { - // protect against :<> with high-bit set - return(str_replace(array("<",">","\xBA","\xBC","\xBE"), array('[',']','','',''), $string)); -}} - -if(! function_exists('escape_tags')) { -function escape_tags($string) { - - return(htmlspecialchars($string)); -}} - -if(! function_exists('login')) { -function login($register = false) { - $o = ""; - $register_html = (($register) ? file_get_contents("view/register-link.tpl") : ""); - - - if(x($_SESSION,'authenticated')) { - $o = file_get_contents("view/logout.tpl"); +if (! function_exists('hex2bin')) { + function hex2bin($s) + { + return(pack("H*", $s)); } - else { - $o = file_get_contents("view/login.tpl"); - - $o = replace_macros($o,array('$register_html' => $register_html )); - } - return $o; -}} - - -if(! function_exists('killme')) { -function killme() { - session_write_close(); - closedb(); - exit; -}} - -if(! function_exists('goaway')) { -function goaway($s) { - header("Location: $s"); - killme(); -}} - -if(! function_exists('local_user')) { -function local_user() { - if((x($_SESSION,'authenticated')) && (x($_SESSION,'uid'))) - return $_SESSION['uid']; - return false; -}} - -if(! function_exists('notice')) { -function notice($s) { - - $_SESSION['sysmsg'] .= $s; - -}} - -if(! function_exists('hex2bin')) { -function hex2bin($s) { - return(pack("H*",$s)); -}} +} -if(! function_exists('paginate')) { -function paginate(&$a) { - $o = ''; - $stripped = ereg_replace("(&page=[0-9]*)","",$a->query_string); - $stripped = str_replace('q=','',$stripped); - $stripped = trim($stripped,'/'); - $pagenum = $a->pager['page']; - $url = $a->get_baseurl() . '/' . $stripped ; +if (! function_exists('paginate')) { + function paginate(&$a) + { + $o = ''; + $stripped = preg_replace("/&page=[0-9]*/", "", $a->query_string); + $stripped = str_replace('q=', '', $stripped); + $stripped = trim($stripped, '/'); + $pagenum = $a->pager['page']; + $url = $a->get_baseurl() . '/' . $stripped ; - if($a->pager['total'] > $a->pager['itemspage']) { - $o .= '
'; - if($a->pager['page'] != 1) - $o .= ''."pager['page'] - 1).'">' . t('prev') . ' '; + if ($a->pager['total'] > $a->pager['itemspage']) { + $o .= '
'; + if ($a->pager['page'] != 1) { + $o .= ''."pager['page'] - 1).'">' . t('prev') . ' '; + } - $o .= "" . t('first') . " "; + $o .= "" . t('first') . " "; - $numpages = $a->pager['total'] / $a->pager['itemspage']; + $numpages = $a->pager['total'] / $a->pager['itemspage']; $numstart = 1; - $numstop = $numpages; + $numstop = $numpages; - if($numpages > 14) { - $numstart = (($pagenum > 7) ? ($pagenum - 7) : 1); - $numstop = (($pagenum > ($numpages - 7)) ? $numpages : ($numstart + 14)); - } + if ($numpages > 14) { + $numstart = (($pagenum > 7) ? ($pagenum - 7) : 1); + $numstop = (($pagenum > ($numpages - 7)) ? $numpages : ($numstart + 14)); + } - for($i = $numstart; $i <= $numstop; $i++){ - if($i == $a->pager['page']) - $o .= ''.(($i < 10) ? ' '.$i : $i); - else - $o .= "".(($i < 10) ? ' '.$i : $i).""; - $o .= ' '; + for ($i = $numstart; $i <= $numstop; $i++) { + if ($i == $a->pager['page']) { + $o .= ''.(($i < 10) ? ' '.$i : $i); + } else { + $o .= "".(($i < 10) ? ' '.$i : $i).""; + } + $o .= ' '; + } + + if (($a->pager['total'] % $a->pager['itemspage']) != 0) { + if ($i == $a->pager['page']) { + $o .= ''.(($i < 10) ? ' '.$i : $i); + } else { + $o .= "".(($i < 10) ? ' '.$i : $i).""; + } + $o .= ' '; + } + + $lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages); + $o .= "" . t('last') . " "; + + if (($a->pager['total'] - ($a->pager['itemspage'] * $a->pager['page'])) > 0) { + $o .= ''."pager['page'] + 1).'">' . t('next') . ''; + } + $o .= '
'."\r\n"; } - - if(($a->pager['total'] % $a->pager['itemspage']) != 0) { - if($i == $a->pager['page']) - $o .= ''.(($i < 10) ? ' '.$i : $i); - else - $o .= "".(($i < 10) ? ' '.$i : $i).""; - $o .= ' '; - } - - $lastpage = (($numpages > intval($numpages)) ? intval($numpages)+1 : $numpages); - $o .= "" . t('last') . " "; - - if(($a->pager['total'] - ($a->pager['itemspage'] * $a->pager['page'])) > 0) - $o .= ''."pager['page'] + 1).'">' . t('next') . ''; - $o .= '
'."\r\n"; + return $o; } - return $o; -}} +} -function get_my_url() { - if(x($_SESSION,'my_url')) +function get_my_url() +{ + if (x($_SESSION, 'my_url')) { return $_SESSION['my_url']; + } return false; } -function zrl($s,$force = false) { - if(! strlen($s)) +function zrl($s, $force = false) +{ + if (! strlen($s)) { return $s; - if((! strpos($s,'/profile/')) && (! $force)) + } + if ((! strpos($s, '/profile/')) && (! $force)) { return $s; - $achar = strpos($s,'?') ? '&' : '?'; + } + $achar = strpos($s, '?') ? '&' : '?'; $mine = get_my_url(); - if($mine and ! link_compare($mine,$s)) + if ($mine and ! link_compare($mine, $s)) { return $s . $achar . 'zrl=' . urlencode($mine); + } return $s; } -if(! function_exists('link_compare')) { -function link_compare($a,$b) { - if(strcasecmp(normalise_link($a),normalise_link($b)) === 0) - return true; - return false; -}} +if (! function_exists('link_compare')) { + function link_compare($a, $b) + { + if (strcasecmp(normalise_link($a), normalise_link($b)) === 0) { + return true; + } + return false; + } +} -if(! function_exists('normalise_link')) { -function normalise_link($url) { - $ret = str_replace(array('https:','//www.'), array('http:','//'), $url); - return(rtrim($ret,'/')); -}} +if (! function_exists('normalise_link')) { + function normalise_link($url) + { + $ret = str_replace(array('https:', '//www.'), array('http:', '//'), $url); + return(rtrim($ret, '/')); + } +} diff --git a/include/dba.php b/include/dba.php index d6573506..877f6cd3 100755 --- a/include/dba.php +++ b/include/dba.php @@ -101,35 +101,35 @@ class dba } if (! function_exists('printable')) { - function printable($s) - { - $s = preg_replace("~([\x01-\x08\x0E-\x0F\x10-\x1F\x7F-\xFF])~", ".", $s); - $s = str_replace("\x00", '.', $s); - if (x($_SERVER, 'SERVER_NAME')) { - $s = escape_tags($s); - } - return $s; - } + function printable($s) + { + $s = preg_replace("~([\x01-\x08\x0E-\x0F\x10-\x1F\x7F-\xFF])~", ".", $s); + $s = str_replace("\x00", '.', $s); + if (x($_SERVER, 'SERVER_NAME')) { + $s = escape_tags($s); + } + return $s; + } } // Procedural functions if (! function_exists('dbg')) { - function dbg($state) - { - global $db; - $db->dbg($state); - } + function dbg($state) + { + global $db; + $db->dbg($state); + } } if (! function_exists('dbesc')) { - function dbesc($str) - { - global $db; - if ($db) { - return($db->escape($str)); - } - } + function dbesc($str) + { + global $db; + if ($db) { + return($db->escape($str)); + } + } } @@ -139,21 +139,21 @@ if (! function_exists('dbesc')) { // 'user', 1); if (! function_exists('q')) { - function q($sql) - { - global $db; - $args = func_get_args(); - unset($args[0]); - if ($db) { - $ret = $db->q(vsprintf($sql, $args)); - } - if ($db->db->errno) { - logger('dba: ' . $db->db->error); - } + function q($sql) + { + global $db; + $args = func_get_args(); + unset($args[0]); + if ($db) { + $ret = $db->q(vsprintf($sql, $args)); + } + if ($db->db->errno) { + logger('dba: ' . $db->db->error); + } - return $ret; - } + return $ret; + } } @@ -164,29 +164,29 @@ if (! function_exists('q')) { if (! function_exists('dbesc_array_cb')) { - function dbesc_array_cb(&$item, $key) - { - if (is_string($item)) { - $item = dbesc($item); - } - } + function dbesc_array_cb(&$item, $key) + { + if (is_string($item)) { + $item = dbesc($item); + } + } } if (! function_exists('dbesc_array')) { - function dbesc_array(&$arr) - { - if (is_array($arr) && count($arr)) { - array_walk($arr, 'dbesc_array_cb'); - } - } + function dbesc_array(&$arr) + { + if (is_array($arr) && count($arr)) { + array_walk($arr, 'dbesc_array_cb'); + } + } } if (! function_exists('closedb')) { - function closedb() - { - global $db; + function closedb() + { + global $db; // $db->close(); - } + } } diff --git a/index.php b/index.php index 7d371fd0..2c6086dd 100755 --- a/index.php +++ b/index.php @@ -21,14 +21,14 @@ $db = new dba($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data); $a->init_pagehead(); -$a->page['aside'] .= '
Your friends. Your web.
'; +$a->page['aside'] = '
Your friends. Your web.
'; require_once 'session.php'; session_start(); if ((x($_SESSION, 'authenticated')) || (x($_POST, 'auth-params')) || ($a->module === 'login')) { - require 'auth.php'; + require 'auth.php'; } $dreamhost_error_hack = 1; @@ -73,17 +73,19 @@ if ($a->module_loaded) { if ((! $a->error) && (function_exists($a->module . '_content'))) { $func = $a->module . '_content'; - $a->page['content'] .= $func($a); + $a->page['content'] = $func($a); } } -if (stristr($_SESSION['sysmsg'], t('Permission denied'))) { - header($_SERVER['SERVER_PROTOCOL'] . ' 403 ' . t('Permission denied.')); -} - // report anything important happening if (x($_SESSION, 'sysmsg')) { + if (stristr($_SESSION['sysmsg'], t('Permission denied'))) { + header($_SERVER['SERVER_PROTOCOL'] . ' 403 ' . t('Permission denied.')); + } + if (!isset($a->page['content'])) { + $a->page['content'] = ''; + } $a->page['content'] = '
' . $_SESSION['sysmsg'] . '
' . PHP_EOL . $a->page['content']; unset($_SESSION['sysmsg']); diff --git a/mod/directory.php b/mod/directory.php index 0d30512d..ef83e8fa 100755 --- a/mod/directory.php +++ b/mod/directory.php @@ -4,119 +4,119 @@ require_once 'include/widget.php'; function directory_init(App $a) { - $a->set_pager_itemspage(80); + $a->set_pager_itemspage(80); - $a->page['aside'] .= tags_widget(); - $a->page['aside'] .= country_widget(); + $a->page['aside'] .= tags_widget(); + $a->page['aside'] .= country_widget(); } function directory_content(App $a) { - $forums = false; - if ($a->argc == 2 && $a->argv[1] === 'forum') { - $forums = true; - } + $forums = false; + if ($a->argc == 2 && $a->argv[1] === 'forum') { + $forums = true; + } - $alpha = false; - if ($_GET['alpha'] == 1) { - $alpha = true; - } + $alpha = false; + if (isset($_GET['alpha']) && $_GET['alpha'] == 1) { + $alpha = true; + } - $search = ((x($_GET, 'search')) ? notags(trim($_GET['search'])) : ''); + $search = ((x($_GET, 'search')) ? notags(trim($_GET['search'])) : ''); - if ($_GET['submit'] === t('Clear')) { - goaway($a->get_baseurl()); - } + if (isset($_GET['submit']) && $_GET['submit'] === t('Clear')) { + goaway($a->get_baseurl()); + } - if ($search) { - $alpha = true; - } + if ($search) { + $alpha = true; + } - $tpl .= file_get_contents('view/directory_header.tpl'); + $tpl = file_get_contents('view/directory_header.tpl'); - $o .= replace_macros($tpl, array( - '$search' => $search, - '$header' => t('Global Directory'), - '$submit' => t('Find'), - '$clear' => t('Clear'), - '$forum' => $a->get_baseurl() . (($forums) ? '' : '/directory/forum'), - '$toggle' => (($forums) ? t('Show People') : t('Show Community Forums')), - '$alpha' => (($alpha) ? t('Updated order') : t('Alphabetic order')), - '$alink' => (($alpha) ? str_replace('&alpha=1', '', $a->query_string) : $a->query_string . "&alpha=1"), - '$args' => (($forums) ? '/forum' : ''), - '$finding' => (strlen($search) ? '

' . t('Search for: ') . "'" . $search . "'" . '

' : "") - )); + $o = replace_macros($tpl, array( + '$search' => $search, + '$header' => t('Global Directory'), + '$submit' => t('Find'), + '$clear' => t('Clear'), + '$forum' => $a->get_baseurl() . (($forums) ? '' : '/directory/forum'), + '$toggle' => (($forums) ? t('Show People') : t('Show Community Forums')), + '$alpha' => (($alpha) ? t('Updated order') : t('Alphabetic order')), + '$alink' => (($alpha) ? str_replace('&alpha=1', '', $a->query_string) : $a->query_string . "&alpha=1"), + '$args' => (($forums) ? '/forum' : ''), + '$finding' => (strlen($search) ? '

' . t('Search for: ') . "'" . $search . "'" . '

' : "") + )); - if ($search) { - $search = dbesc($search . '*'); - } - $sql_extra = ((strlen($search)) ? " AND MATCH (`name`, `pdesc`, `homepage`, `locality`, `region`, `country-name`, `tags` ) - AGAINST ('$search' IN BOOLEAN MODE) " : ""); + if ($search) { + $search = dbesc($search . '*'); + } + $sql_extra = ((strlen($search)) ? " AND MATCH (`name`, `pdesc`, `homepage`, `locality`, `region`, `country-name`, `tags`) + AGAINST ('$search' IN BOOLEAN MODE) " : ""); - if ($forums) { - $sql_extra .= " and comm = 1 "; - } + if ($forums) { + $sql_extra .= " AND `comm` = 1 "; + } - $sql_extra = str_replace('%', '%%', $sql_extra); + $sql_extra = str_replace('%', '%%', $sql_extra); - $r = q("SELECT COUNT(*) AS `total` FROM `profile` WHERE `censored` = 0 $sql_extra "); - if (count($r)) { - $a->set_pager_total($r[0]['total']); - } + $r = q("SELECT COUNT(*) AS `total` FROM `profile` WHERE `censored` = 0 $sql_extra "); + if (count($r)) { + $a->set_pager_total($r[0]['total']); + } - if ($alpha) { - $order = " order by name asc "; - } else { - $order = " order by updated desc, id desc "; - } + if ($alpha) { + $order = " ORDER BY `name` ASC "; + } else { + $order = " ORDER BY `updated` DESC, `id` DESC "; + } - $r = q("SELECT * FROM `profile` WHERE `censored` = 0 $sql_extra $order LIMIT %d , %d ", - intval($a->pager['start']), - intval($a->pager['itemspage']) - ); + $r = q("SELECT * FROM `profile` WHERE `censored` = 0 $sql_extra $order LIMIT %d , %d ", + intval($a->pager['start']), + intval($a->pager['itemspage']) + ); - if (count($r)) { - $tpl = file_get_contents('view/directory_item.tpl'); + if (count($r)) { + $tpl = file_get_contents('view/directory_item.tpl'); - foreach ($r as $rr) { - $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '
' : ''); + foreach ($r as $rr) { + $pdesc = (($rr['pdesc']) ? $rr['pdesc'] . '
' : ''); - $details = ''; - if (strlen($rr['locality'])) { - $details .= $rr['locality']; - } - if (strlen($rr['region'])) { - if (strlen($rr['locality'])) { - $details .= ', '; - } - $details .= $rr['region']; - } - if (strlen($rr['country-name'])) { - if (strlen($details)) { - $details .= ', '; - } - $details .= $rr['country-name']; - } + $details = ''; + if (strlen($rr['locality'])) { + $details .= $rr['locality']; + } + if (strlen($rr['region'])) { + if (strlen($rr['locality'])) { + $details .= ', '; + } + $details .= $rr['region']; + } + if (strlen($rr['country-name'])) { + if (strlen($details)) { + $details .= ', '; + } + $details .= $rr['country-name']; + } - $o .= replace_macros($tpl, array( - '$id' => $rr['id'], - '$mod' => '
' . t('Flag this entry') . '
', - '$star' => (($rr['tags']) ? '
' : ''), - '$profile-link' => zrl($rr['homepage']), - '$photo' => $a->get_baseurl() . '/photo/' . $rr['id'], - '$alt-text' => $rr['name'] . ' ' . '(' . $rr['homepage'] . ')', - '$name' => $rr['name'], - '$pclass' => (($rr['comm']) ? ' group' : ''), - '$pgroup' => (($rr['comm']) ? '
' . t('[Public Group]') . '
' : ''), - '$details' => $pdesc . $details - )); - } + $o .= replace_macros($tpl, array( + '$id' => $rr['id'], + '$mod' => '
' . t('Flag this entry') . '
', + '$star' => (($rr['tags']) ? '
' : ''), + '$profile-link' => zrl($rr['homepage']), + '$photo' => $a->get_baseurl() . '/photo/' . $rr['id'], + '$alt-text' => $rr['name'] . ' ' . '(' . $rr['homepage'] . ')', + '$name' => $rr['name'], + '$pclass' => (($rr['comm']) ? ' group' : ''), + '$pgroup' => (($rr['comm']) ? '
' . t('[Public Group]') . '
' : ''), + '$details' => $pdesc . $details + )); + } $o .= '
' . PHP_EOL; - $o .= paginate($a); - } else { - notice(t('No matching entries.') . EOL); - } + $o .= paginate($a); + } else { + notice(t('No matching entries.') . EOL); + } - return $o; + return $o; } diff --git a/view/default.php b/view/default.php index 25d8ea1d..7f86257a 100755 --- a/view/default.php +++ b/view/default.php @@ -1,15 +1,15 @@ - <?php echo $page['title'] ?> - + <?php echo isset($page['title']) ? $page['title'] : '' ?> + -
- - -
- +
+ + +
+