From af92c0deac162cba11dba2e13d2d8e4801af00b2 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Wed, 6 Apr 2016 11:21:23 -0700 Subject: [PATCH] add tweet text length countdown on note interface --- controllers/controllers.php | 1 + public/images/twitter.ico | Bin 0 -> 1150 bytes public/js/cassis.js | 1584 +++++++++++++++++++++++++++++++++++ views/layout.php | 1 + views/new-post.php | 26 + 5 files changed, 1612 insertions(+) create mode 100644 public/images/twitter.ico create mode 100644 public/js/cassis.js diff --git a/controllers/controllers.php b/controllers/controllers.php index 475e620..95d3aa5 100644 --- a/controllers/controllers.php +++ b/controllers/controllers.php @@ -83,6 +83,7 @@ $app->get('/new', function() use($app) { 'syndication_targets' => json_decode($user->syndication_targets, true), 'test_response' => $test_response, 'location_enabled' => $user->location_enabled, + 'user' => $user, 'authorizing' => false )); $app->response()->body($html); diff --git a/public/images/twitter.ico b/public/images/twitter.ico new file mode 100644 index 0000000000000000000000000000000000000000..b4a71699a727c7642612dfa116c748df3c530fe1 GIT binary patch literal 1150 zcmd5)O-lk%6un{KMi>_n?QH2z|AEpUs8vFnq*c3Gwi4VWK~P9g#F)@V5VDO#m`Wj1 zi6iuZF_nfwAvhW{l=i{vUUYJrrd$QR;mo~r?>*-o-Wz}ce5_W$_bAK`0t^Fy9f2jR zbm|xYu%};)G5ANYpck74Bbb{J{XCj*#{Sw6yiXUtu!>fR54lA4 zHxysAN(TX8VhETN?Lj%6j=#4XuHQ7e+FZMypOP~Zhgv@6j|r#P)iCrxe7TzR)b|{s zo~wS72F}r$7-?9PGhaxGak4sZ6qRee>dpf4>0kNuQHi@wj#q#YkM5It&HKEw zvi;RVDGcl(%E?Mi7}N4|k@4L-f%j@_lpk$43b`P#!WuBr&uqC<$yHmqQs8H_v+ADO z8s${K$u7?qQ$D|{Pqm-s_58p820X(Kni$hAfR+uQ$pMtj9i+Q4YXT@CSgFVP0GFBa AX8-^I literal 0 HcmV?d00001 diff --git a/public/js/cassis.js b/public/js/cassis.js new file mode 100644 index 0000000..aee3b62 --- /dev/null +++ b/public/js/cassis.js @@ -0,0 +1,1584 @@ +/* +if you see this in the browser, you need to wrap your PHP include of cassis.js and use thereof with calls to ob_start and ob_end_clean, e.g.: +ob_start(); +include 'cassis.js'; +// your code that calls CASSIS functions goes here +ob_end_clean(); +/* +// =================================================================== +// PHP-only block. Processed only by PHP. Use only // comments here. +// ------------------------------------------------------------------- +function js() { + return false; +} + +// global configuration + +if (php_min_version("5.1.0")) { + date_default_timezone_set("UTC"); +} + +function php_min_version($s) { + $s = explode(".", $s); + $phpv = explode(".", phpversion()); + for ($i=0; $i < count($s); $i+=1) { + if ($s[$i] > $phpv[$i]) { + return false; + } + } + return true; +} + +// ------------------------------------------------------------------- +// date time functions + +function date_get_full_year($d = "") { + if ($d == "") { + $d = new DateTime(); + } + return $d->format('Y'); +} + +function date_get_timestamp($d) { + return $d->format('U'); // $d->getTimestamp(); // in PHP 5.3+ +} + +// mixed-case function names are bad for PHP vs JS. Don't do it. +//function Number($n) { +// return $n-0; +//} + + +// ------------------------------------------------------------------- +// old wrappers. transition code away from these +// ** do not use these in new code. ** + +function getFullYear($d = "") { + // 2010-020 obsoleted. Use date_get_full_year instead + return date_get_full_year($d); +} + +// =================================================================== +/*/ // This comment inverter switches from PHP only to JS only. +// JS-only block. Processed only by JS. Use only // comments here. +// ------------------------------------------------------------------- +function js() { + return true; +} + +// array functions + +function array() { // makes an array from arbitrary parameter list. + return Array.prototype.slice.call(arguments); +} + +function is_array(a) { + return (typeof(a) === "object") && (a instanceof Array); +} + +function count(a) { + return a.length; +} + +function array_slice(a, b, e) { // slice an array, begin, optional end + if (a === undefined) { return array(); } + if (b === undefined) { return a; } + if (e === undefined) { return a.slice(b); } + return a.slice(b, e); +} + +// ------------------------------------------------------------------- +// math and numerical functions + +function floor(n) { + return Math.floor(n); +} + +function intval(n) { + return parseInt(n, 10); +} + +Array.min = function(a) { +// from http://ejohn.org/blog/fast-javascript-maxmin/ + return Math.min.apply(Math, a); +}; + +function min() { + var m = arguments; + if (m.length < 1) { + return false; + } + if (m.length === 1) { + m = m[0]; + if (!is_array(m)) { + return m; + } + } + return Array.min(m); +} + +function ctype_digit(s) { + return (/^[0-9]+$/).test(s); +} + +function ctype_space(s) { + return /\s/.test(s); +} + +// ------------------------------------------------------------------- +// date time functions + +function date_create(s) { + var d = new Date(); + d.parse(s); + return d; +} + +function date_get_full_year(d) { + if (arguments.length < 1) { + d = new Date(); + } + return d.getFullYear(); +} + +function date_get_timestamp(d) { + return floor(d.getTime() / 1000); +} + + +// ------------------------------------------------------------------- +// character and string functions + +function ord(s) { + return s.charCodeAt(0); +} + +function strlen(s) { + return s.length; +} + +function substr(s, o, n) { + var m = strlen(s); + if ((o < 0 ? -1-o : o) >= m) { return false; } + if (o < 0) { o = m + o; } + if (n < 0) { n = m - o + n; } + if (n === undefined) { n = m - o; } + return s.substring(o, o + n); +} + +function substr_count(s, n) { + return s.split(n).length - 1; +} + +function strpos(h, n, o) { + // clients must triple-equal test return for === false for no match! + // or use offset(n, h) instead (0 = not found, else 1-based index) + if (arguments.length === 2) { + o = 0; + } + o = h.indexOf(n, o); + if (o === -1) { return false; } + else { return o; } +} + +function strncmp(s1, s2, n) { + s1 = substr(String(s1), 0, n); + s2 = substr(String(s2), 0, n); + return (s1 === s2) ? 0 : + ((s1 < s2) ? -1 : 1); +} + +function explode(d, s, n) { + if (arguments.length === 2) { + return s.split(d); + } + return s.split(d, n); +} + +function implode(d, a) { + return a.join(d); +} + +function rawurlencode(s) { + return encodeURIComponent(s); +} + +function htmlspecialchars(s) { + var c, i; + c = [["&","&"], ["<","<"], [">",">"], + ["'","'"], ['"',"""]]; + for (i = 0; i < c.length; i+=1) { + s = s.replace(new RegExp(c[i][0], "g"), c[i][1]); + } + return s; +} + +function str_ireplace(a, b, s) { + var i; + if (!is_array(a)) { + return s.replace(new RegExp(a, "gi"), is_array(b) ? b[0] : b); + } + else { + for (i=0; i 1 ? m[1] : " \t\n\r\f\x00\x0b\xa0"; + i = 0; + j = strlen(s); + + while (strpos(c,s[i])!==false && ii && strpos(c,s[j])!==false) { + j-=1; + } + j+=1; + if (j>i) { + return substr(s,i,j-i); + } + else { + return ''; + } +} + +function rtrim() { + var c,j,m,s; + m = arguments; + s = m[0]; + c = count(m)>1 ? m[1] : " \t\n\r\f\x00\x0b\xa0"; + j = strlen(s)-1; + while (j>=0 && strpos(c,s[j])!==false) { + j-=1; + } + if (j>=0) { + return substr(s,0,j+1); + } + else { + return ''; + } +} + +function strtolower(s) { + return s.toLowerCase(); +} + +function ucfirst(s) { + return s.charAt(0).toUpperCase() + substr(s, 1); +} + +// ------------------------------------------------------------------- +// more javascript-only php-equivalent functions here + + +// ------------------------------------------------------------------- +// pacify jslint/jshint +// -- define functions and variables only used in PHP flow. +function func_get_args() { } +var FALSE = false; +var PREG_PATTERN_ORDER; +var STR_PAD_LEFT; +// -- may eventually define these for JS. +function date_format() { } +function preg_match_all() { } +function str_pad() { } +function DateTime() { } + +// =================================================================== +/**/ // unconditional comment closer exits PHP comment block. +// JS+PHP block. Processed by both JS and PHP. /*...*/ comments ok. +// ------------------------------------------------------------------- +/* original js/php test - doesn't pass jslint/jshint. +function js() { + return "00"==false; +} +*/ + +/*global document: false, window: false */ +/// ?> =0; $i-=1) { + $r = $isjs ? $args[$i] + $r : $args[$i] . $r; + } + return $r; +} + +function number($s) { + return $s - 0; +} + +function string($n) { + if (js()) { + if (typeof($n)==="number") { + return Number($n).toString(); + } else if (typeof($n)==="undefined") { + return ""; + } else { + return $n.toString(); + } + } + else { + return "" . $n; + } +} + +function str_pad_left($s1, $n, $s2) { + $s1 = string($s1); + $s2 = string($s2); + if (js()) { + $n -= strlen($s1); + while ($n >= strlen($s2)) { + $s1 = strcat($s2, $s1); + $n -= strlen($s2); + } + if ($n > 0) { + $s1 = strcat(substr($s2, 0, $n), $s1); + } + return $s1; + } else { + return str_pad($s1, $n, $s2, STR_PAD_LEFT); + } +} + +function trim_slashes($s) { + if ($s[0]==="/") { // strip unnecessary / delim PHP regex funcs want + return substr($s, 1, strlen($s)-2); + } + return $s; +} + +// define a few JS functions that PHP already has, using CASSIS funcs +/// ?> 0) { + if(!js() && function_exists('bcmod')) { + $d = bcmod($n, 60); + $s = $m[$d] . $s; + $n = bcdiv(bcsub($n, $d), 60); + } else { + $d = $n % 60; + $s = strcat($m[$d], $s); + $n = ($n-$d)/60; + } + } + return strcat($p, $s); +} + +function num_to_sxgf($n, $f) { + if (!$f) { $f=1; } + return str_pad_left(num_to_sxg($n), $f, "0"); +} + +function sxg_to_num($s) { /// ?> =48 && $c<=57) { $c=$c-48; } + else if ($c>=65 && $c<=72) { $c-=55; } + else if ($c===73 || $c===108) { $c=1; } // typo cap I lower l to 1 + else if ($c>=74 && $c<=78) { $c-=56; } + else if ($c===79) { $c=0; } // error correct typo capital O to 0 + else if ($c>=80 && $c<=90) { $c-=57; } + else if ($c===95 || $c===45) { $c=34; } // _ and dash - to _ + else if ($c>=97 && $c<=107) { $c-=62; } + else if ($c>=109 && $c<=122) { $c-=63; } + else { break; } // treat all other noise as end of number + if(!js() && function_exists('bcadd')) { + $n = bcadd(bcmul(60, $n), $c); + } else { + $n = 60*$n + $c; + } + } + return $n*$m; +} + +function sxg_to_numf($s, $f) { + if ($f===undefined) { $f=1; } + return str_pad_left(sxg_to_num($s), $f, "0"); +} + +// ------------------------------------------------------------------- +// == newbase60 compat functions only == (before 2011-149) +function numtosxg($n) { + return num_to_sxg($n); +} + +function numtosxgf($n, $f) { + return num_to_sxgf($n, $f); +} + +function sxgtonum($s) { + return sxg_to_num($s); +} + +function sxgtonumf($s, $f) { + return sxg_to_numf($s, $f); +} + +// ------------------------------------------------------------------- +// date and time + +function date_create_ymd($s) { /// ?> 1) ? $dt[1] : "0:00"; +} + +function dt_to_date($dt) { + $dt = explode("T", $dt); + if (count($dt)==1) { + $dt = explode(" ", $dt); + } + return $dt[0]; +} + +function dt_to_ordinal_date($dt) { + return ymd_to_yd(dt_to_date($dt)); +} + +// ------------------------------------------------------------------- +// newcal + +function isleap($y) { + return ($y % 4 === 0 && ($y % 100 !== 0 || $y % 400 === 0)); +} + +function ymdp_to_d($y, $m, $d) { /// ?> 0) ? $args[0] : 0))); +} + +function get_nm_str($m) { /// ?> 29) ? 2+2*(bim_from_od($d)-1) : 1+2*(bim_from_od($d)-1); +} + +// date_get_ordinal_date: optional date argument +function date_get_ordinal_date() { /// ?> 0) ? $args[0] : 0); + return strcat(date_get_full_year($d), '-', + str_pad_left(date_get_ordinal_days($d), 3, "0")); +} + +// ------------------------------------------------------------------- +// begin epochdays + +function y_to_days($y) { + // convert y-01-01 to epoch days + return floor( + (date_get_timestamp(date_create_ymd(strcat($y, "-01-01"))) - + date_get_timestamp(date_create_ymd("1970-01-01")))/86400); +} + +// convert ymd to epoch days and sexagesimal epoch days (sd) + +function ymd_to_days($d) { + return yd_to_days(ymd_to_yd($d)); +} + +/* old: +function ymd_to_days($d) { + // fails in JS, "2013-03-10" and "2013-03-11" both return 15774 + return floor( + (date_get_timestamp(date_create_ymd($d)) - + date_get_timestamp(date_create_ymd("1970-01-01")))/86400); +} +*/ + +function ymd_to_sd($d) { + return num_to_sxg(ymd_to_days($d)); +} + +function ymd_to_sdf($d, $f) { + return num_to_sxgf(ymd_to_days($d), $f); +} + +// ordinal date (YYYY-DDD) to ymd, epoch days, sexagesimal epoch days + +function ydp_to_ymd($y, $d) { /// ?> $d) $m -= 1; + $d = $d - $md[isleap($y)-0][$m] + 1; + $m += 1; + return strcat($y, '-', str_pad_left($m, 2, '0'), + '-', str_pad_left($d, 2, '0')); +} + +function yd_to_ymd($d) { + return ydp_to_ymd(substr($d, 0, 4), substr($d, 5, 3)); +} + +function yd_to_days($d) { + return y_to_days(substr($d, 0, 4)) - 1 + number(substr($d, 5, 3)); +} + +function yd_to_sd($d) { + return num_to_sxg(yd_to_days($d)); +} + +function yd_to_sdf($d, $f) { + return num_to_sxgf(yd_to_days($d), $f); +} + +// convert epoch days or sexagesimal epoch days (sd) to ordinal date +function days_to_yd($d) { /// ?> 2) { + $uri = $uri[2]; + if (offset(':', $uri) !== 0) { + $uri = explode(':', $uri, 2); + $uri = $uri[0]; + } + return $uri; + } + return ''; +} + +function sld_of_uri($uri) { + $uri = hostname_of_uri($uri); + $uri = explode('.', $uri); + if (count($uri) > 1) { + return $uri[count($uri) - 2]; + } + return ""; +} + +function path_of_uri($uri) { + $uri = explode('/', $uri, 4); + if (count($uri) > 3) { + $uri = array_slice($uri, 3); + $uri = strcat('/', implode('/', $uri)); + if (offset('?', $uri) !== 0) { + $uri = explode('?', $uri, 2); + $uri = $uri[0]; + } + if (offset('#', $uri) !== 0) { + $uri = explode('#', $uri, 2); + $uri = $uri[0]; + } + return $uri; + } + return '/'; +} + +function is_http_uri($uri) { + $uri = explode(":", $uri, 2); + return !!strncmp($uri[0], "http", 4); +} + +// ------------------------------------------------------------------- +// compat as of 2011-149 +function webaddresstouri($wa, $addhttp) { + return web_address_to_uri($wa, $addhttp); +} +function uriclean($uri) { return uri_clean($uri); } + + +// ------------------------------------------------------------------- +// hexatridecimal + +function num_to_hxt($n) { /// ?> 0) { + $d = $n % 36; + $s = strcat($m[$d], $s); + $n = ($n-$d)/36; + } + return $s; +} + +function num_to_hxtf($n, $f) { + if ($f === undefined) { $f=1; } + return str_pad_left(num_to_hxt($n), $f, "0"); +} + +function hxt_to_num($h) { /// ?> =48 && $c<=57) { $c=$c-48; } // 0-9 + else if ($c>=65 && $c<=90) { $c-=55; } // A-Z + else if ($c>=97 && $c<=122) { $c-=87; } // a-z treat as A-Z + else { $c = 0; } // treat all other noise as 0 + $n = 36*$n + $c; + } + return $n; +} + +// ------------------------------------------------------------------- +// compat as of 2011-149 +function numtohxt($n) { return num_to_hxt($n); } +function numtohxtf($n,$f) { return num_to_hxtf($n, $f); } +function hxttonum($h) { return hxt_to_num($h); } + + +// ------------------------------------------------------------------- +// ISBN-10 + +function num_to_isbn10($n) { /// ?> =0; $i-=1) { + $d += $n[$i]*$f; + $f += 1; + } + $d = 11-($d % 11); + if ($d===10) {$d="X";} + else if ($d===11) {$d="0";} + else {$d=string($d);} + return strcat(str_pad_left($n, 9, "0"), $d); +} + +// ------------------------------------------------------------------- +// compat as of 2011-149 +function numtoisbn10($n) { return num_to_isbn10($n); } + + +// ------------------------------------------------------------------- +// HyperTalk + +function trunc($n) { // just an alias from BASIC days + return floor($n); +} + +function offset($n, $h) { + $n = strpos($h, $n); + if ($n === false) { + return 0; + } else { + return $n+1; + } +} + +function contains($h, $n) { +// HyperTalk syntax haystack contains needle: if ("abc" contains "b") + return strpos($h, $n)!==false; +} + +function last_character_of($s) { + return (strlen($s) > 0) ? $s[strlen($s)-1] : ''; +} + +function line_1_of($s) { /// ?> 1) { + $r = explode("-", $d[1]); + if (count($d)==1) { + $r = explode("+", $d[1]); + } + if (count($d)>1) { + $r = strcat(' on '); + } + else { + $r = strcat(' on '); + } + } + return strcat($r, ''); +} + + +// ------------------------------------------------------------------- +// compat as of 2011-149 +function xphasclass($s) { return xp_has_class($s); } +function xprhasclass($s) { return xpr_has_class($s); } +function xphasid($s) { return xp_has_id($s); } +function xpattrstartswith($a, $s) { + return xp_attr_starts_with($a, $s); +} +function xphasrel($s) { return xp_has_rel($s); } +function xprhasrel($s) { return xpr_has_rel($s); } +function xprattrstartswithhasrel($a, $s, $r) { + return xpr_attr_starts_with_has_rel($a, $s, $r); +} +function vcpdtreadable($d) { return vcp_dt_readable($d); } + + +// ------------------------------------------------------------------- +// whistle +// algorithmic URL shortener core +// YYYY/DDD/tnnn to tdddss +// ordinal date, type, decimal #, to sexagesimal epoch days, sexagesimal # +function whistle_short_path($p) { + return strcat(substr($p, 9, 1), + ((substr($p, 9, 1)!=='t') ? "/" : ""), + yd_to_sdf(substr($p, 0, 8), 3), + num_to_sxg(substr($p, 10, 3))); +} + +// ------------------------------------------------------------------- +// falcon + +function html_unesc_amp_only($s) { + return str_ireplace('&', '&', $s); +} + +function html_esc_amper_once($s) { + return str_ireplace('&', '&', html_unesc_amp_only($s)); +} + +function html_esc_amp_ang($s) { + return str_ireplace('<', '<', + str_ireplace('>', '>', html_esc_amper_once($s))); +} + +function ellipsize_to_word($s, $max, $e, $min) { /// ?> $min && + !contains('@$ -~*()_+[]{}|;,<>', $s[$slen-1])) { + $slen-=1; + } + } + // at this point we've got a min length string, + // only do minimum trimming necessary to avoid a punctuation error. + + // trim slash after colon or slash + if ($s[$slen-1]==='/' && $slen > 2) { + if ($s[$slen-2]===':') { + $slen-=1; + } + if ($s[$slen-2]==='/') { + $slen-=2; + } + } + + //if trimmed at a ":" in a URL, trim the whole thing + //or trimmed at "http", trim the whole URL + if ($s[$slen-1]===':' && $slen > 5 && + substr($s, $slen-5, 5)==='http:') { + $slen -= 5; + } else if ($s[$slen-1]==='p' && $slen > 4 && + substr($s, $slen-4, 4)==='http') { + $slen -= 4; + } else if ($s[$slen-1]==='t' && $slen > 4 && + (substr($s, $slen-3, 4)==='http' || + substr($s, $slen-3, 4)===' htt')) { + $slen -= 3; + } else if ($s[$slen-1]==='h' && $slen > 4 && + substr($s, $slen-1, 4)==='http') { + $slen -= 1; + } + + //if char immediately before ellipsis would be @$ then trim it + if ($slen > 0 && contains('@$', $s[$slen-1])) { + $slen-=1; + } + + //if char before ellipsis would be sentence terminator, trim 2 more + while ($slen > 1 && contains('.!?', $s[$slen-1])) { + $slen-=2; + } + + // trim extra whitespace before ellipsis down to one space + if ($slen > 2 && contains("\n\r ", $s[$slen-1])) { + while (contains("\n\r ", $s[$slen-2]) && $slen > 2) { + --$slen; + } + } + + if ($slen < 1) { // somehow shortened too much + return $e; // or ellipsis by itself exceeded max, return ellipsis. + } + + // if last two chars are ': ', omit ellipsis. + if ($e==='...' && substr($s, $slen-2, 2)===': ') { + return substr($s, 0, $slen); + } + + return strcat(substr($s, 0, $slen), $e); +} + +function trim_leading_urls($s) { + // deliberately trim URLs with explicit http: / https: from start + // keep schemeless URLs, @-names as expected user-visible text + // if empty or just space after trimming, just return original + $r = trim($s); + while (substr($r, 0, 5) == 'http:' || substr($r, 0, 6) == 'https:') + { + $ws = offset(' ', $r); + $rs = offset("\r", $r); + if ($rs == 0) { $rs = offset("\n", $r); } + if ($rs != 0 && $rs < $ws) { $ws = $rs; } + if ($ws == 0) { return $s; } + $r = substr($r, $ws, strlen($r)-$ws); + } + $r = trim($r); + return ((strlen($r) > 0) ? $r : $s); +} + +function auto_space($s) { +// replace linebreaks with
+// and one leading space with   +// replace " " with "  " +// replace leading spaces (on a line or before spaces) with nbsp; + if ($s[0] === ' ') { + $s = strcat(' ', substr($s, 1, strlen($s)-1)); + } + return str_ireplace(array("\r\n", "\r", "\n ", "\n", " "), + array("\n", "\n", '
 ', + '
', + '  '), + $s); +} + +function auto_link_re() { + return '/(?:\\@[_a-zA-Z0-9]{1,17})|(?:(?:(?:(?:http|https|irc)?:\\/\\/(?:(?:[!$&-.0-9;=?A-Z_a-z]|(?:\\%[a-fA-F0-9]{2}))+(?:\\:(?:[!$&-.0-9;=?A-Z_a-z]|(?:\\%[a-fA-F0-9]{2}))+)?\\@)?)?(?:(?:(?:[a-zA-Z0-9][-a-zA-Z0-9]*\\.)+(?:(?:aero|arpa|asia|a[cdefgilmnoqrstuwxz])|(?:biz|b[abdefghijmnorstvwyz])|(?:cat|com|coop|c[acdfghiklmnoruvxyz])|d[ejkmoz]|(?:edu|e[cegrstu])|f[ijkmor]|(?:gov|g[abdefghilmnpqrstuwy])|h[kmnrtu]|(?:info|int|i[delmnoqrst])|j[emop]|k[eghimnrwyz]|l[abcikrstuvy]|(?:mil|museum|m[acdeghklmnopqrstuvwxyz])|(?:name|net|n[acefgilopruz])|(?:org|om)|(?:pro|p[aefghklmnrstwy])|qa|r[eouw]|(?:space|s[abcdeghijklmnortuvyz])|(?:tel|travel|t[cdfghjklmnoprtvwz])|u[agkmsyz]|v[aceginu]|(?:wtf|w[fs])|xyz|y[etu]|z[amw]))|(?:(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[0-9])\\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[0-9])\\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[0-9])))(?:\\:\\d{1,5})?)(?:\\/(?:(?:[!#&-;=?-Z_a-z~])|(?:\\%[a-fA-F0-9]{2}))*)?)(?=\\b|\\s|$)/'; + // ccTLD compressed regular expression clauses (re)created. + // .mobi .jobs deliberately excluded to discourage layer violations. + // see http://flic.kr/p/2kmuSL for more on the problematic new gTLDs + // part of $re derived from Android Open Source Project, Apache 2.0 + // with a bunch of subsequent fixes/improvements (e.g. ttk.me/t44H2) + // thus auto_link_re is also Apache 2.0 licensed + // http://www.apache.org/licenses/LICENSE-2.0 + // - Tantek 2010-046 (moved to auto_link_re 2012-062) +} + +// auto_link: param 1: text; +// optional: param 2: do embeds or not (false), +// param 3: do auto_links or not (true) +// auto_link is idempotent, works on plain text or typical markup. +function auto_link() { + /// ?> 1) && ($args[1]!==false); + $do_link = (count($args) < 3) || ($args[2]!==false); + + $re = auto_link_re(); + $ms = preg_matches($re, $t); + if (!$ms) { + return $t; + } + + $mlen = count($ms); + $sp = preg_split($re, $t); + $t = ""; + $sp[0] = string($sp[0]); // force undefined to "" + for ($i=0; $i<$mlen; $i+=1) { + $mi = $ms[$i]; + $spliti = $sp[$i]; + $t = strcat($t, $spliti); + $sp[$i+1] = string($sp[$i+1]); // force undefined to "" + if (substr($sp[$i+1], 0, 1)==='/') { //regex omits end/ before '); + $enda = ''; + } + + if ($fe && + ($fe === '.jpeg' || $fe === '.jpg' || $fe === '.png' || + $fe === '.gif' || $fe === '.svg')) { + $alt = strcat('a ', + (offset('photo', $mi) != 0) ? 'photo' + : substr($fe, 1)); + $t = strcat($t, $ahref, '', 
+                    $alt, '', $enda, $afterlink); + } else if ($fe && + ($fe === '.mp4' || $fe === '.mov' || + $fe === '.ogv' || $fe === '.webm')) + { + $t = strcat($t, $ahref, '', + $enda, $afterlink); + } else if ($hn === 'vimeo.com' + && ctype_digit(substr($pa, 1))) { + if ($do_link) { + $t = strcat($t, '', $mi, ' '); + } + + $t = strcat($t, '', + $afterlink); + } else if ($hn === 'youtu.be' || + (($hn === 'youtube.com' || $hn === 'www.youtube.com') + && ($yvid = offset('watch?v=', $mi)) !== 0)) { + if ($hn === 'youtu.be') { + $yvid = substr($pa, 1); + } else { + $yvid = explode('&', substr($mi, $yvid+7)); + $yvid = $yvid[0]; + } + if ($do_link) { + $t = strcat($t, '', $mi, ' '); + } + $t = strcat($t, '', + $afterlink); + } else if ($mi[0] === '@' && $do_link) { + if ($sp[$i+1][0] === '.' && + $spliti != '' && + ctype_email_local(substr($spliti, -1, 1))) { + // if email address, simply append info, no linking + $t = strcat($t, $mi, $afterlink); + } + else { + // treat it as a Twitter @-username reference and link it + $t = strcat($t, '', $mi, '', + $afterlink); + } + } else if ($do_link) { + $t = strcat($t, '', $mi, '', + $afterlink); + } else { + $t = strcat($t, $mi, $afterlink); + } + } else { + $t = strcat($t, $mi); + } + } + return strcat($t, $sp[$mlen]); +} + + +// returns array of URLs after literal "in-reply-to:" in text +function get_in_reply_to_urls($s) { + /// ?> 1)) { + $afterlink = ''; + $afterchar = substr($mi, -1, 1); + while (contains('.!?,;"\')]}', $afterchar) && // trim punc @ end + ($afterchar !== ')' || !contains($mi, '('))) { + // allow one paren pair + // *** not sure twitter is this smart + $afterlink = strcat($afterchar, $afterlink); + $mi = substr($mi, 0, -1); + $afterchar = substr($mi, -1, 1); + } + + $prot = protocol_of_uri($mi); + $proxy_url = ''; + if ($prot === 'irc:') { + $proxy_url = $mi; // Twitter doesn't tco irc: URLs + } else { /* 'https:', 'http:' or presumed for schemeless URLs */ + $proxy_url = 'https://j.mp/0011235813'; + } + $t = strcat($t, $proxy_url, $afterlink); + } + else { + $t = strcat($t, $mi); + } + } + return strcat($t, $sp[$mlen]); +} + + +// note_length_check: +// checks if $note fits in $maxlen characters. +// if $username is non-empty, checks if RT'd $note fits in $maxlen +// 0 - bad params or other precondition failure error +// 200 - exactly fits max characters with RT if username provided +// 206 - less than max chars with RT if username provided +// 207 - more than RT safe length, but less than tweet max +// 208 - tweet max length but with RT would be over +// 413 - (entity too large) over max tweet length +// strlen('RT @: ') === 6. +function note_length_check($note, $maxlen, $username) { + /// ?> --> \ No newline at end of file diff --git a/views/layout.php b/views/layout.php index f783406..f853edd 100644 --- a/views/layout.php +++ b/views/layout.php @@ -30,6 +30,7 @@ + diff --git a/views/new-post.php b/views/new-post.php index 4453e15..532a5ca 100644 --- a/views/new-post.php +++ b/views/new-post.php @@ -4,6 +4,7 @@
+
140
@@ -103,9 +104,34 @@ + +