From 69b883829af30d314898623804dfda2b5c46eb35 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 25 Jul 2012 21:28:06 +0200 Subject: [PATCH 1/8] Speed improvements in the database --- database.sql | 2 ++ update.php | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/database.sql b/database.sql index 1d0a3217..13722d3c 100644 --- a/database.sql +++ b/database.sql @@ -569,6 +569,8 @@ CREATE TABLE IF NOT EXISTS `item` ( KEY `moderated` (`moderated`), KEY `spam` (`spam`), KEY `author-name` (`author-name`), + KEY `uid_commented` (`uid`, `commented`), + KEY `uid_created` (`uid`, `created`), FULLTEXT KEY `title` (`title`), FULLTEXT KEY `body` (`body`), FULLTEXT KEY `allow_cid` (`allow_cid`), diff --git a/update.php b/update.php index d752eaa6..879d7017 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@ Date: Wed, 25 Jul 2012 22:50:06 +0200 Subject: [PATCH 2/8] Further performance improvements --- database.sql | 1 + update.php | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/database.sql b/database.sql index 13722d3c..68449168 100644 --- a/database.sql +++ b/database.sql @@ -571,6 +571,7 @@ CREATE TABLE IF NOT EXISTS `item` ( KEY `author-name` (`author-name`), KEY `uid_commented` (`uid`, `commented`), KEY `uid_created` (`uid`, `created`), + KEY `uid_unseen` (`uid`, `unseen`), FULLTEXT KEY `title` (`title`), FULLTEXT KEY `body` (`body`), FULLTEXT KEY `allow_cid` (`allow_cid`), diff --git a/update.php b/update.php index 879d7017..2d80ee36 100644 --- a/update.php +++ b/update.php @@ -1338,7 +1338,13 @@ function update_1152() { } function update_1153() { - $r = q("CREATE INDEX `uid_commented` ON `item` (`uid`, `commented`); CREATE INDEX `uid_created` ON `item` (`uid`, `created`)"); + $r = q("CREATE INDEX `uid_commented` ON `item` (`uid`, `commented`)"); + if(! $r) + return UPDATE_FAILED; + $r = q("CREATE INDEX `uid_created` ON `item` (`uid`, `created`)"); + if(! $r) + return UPDATE_FAILED; + $r = q("CREATE INDEX `uid_unseen` ON `item` (`uid`, `unseen`)"); if(! $r) return UPDATE_FAILED; return UPDATE_SUCCESS; From 6456c2484ece64dc3fa02a8984b04854aee66b38 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Wed, 25 Jul 2012 23:40:23 +0200 Subject: [PATCH 3/8] scale_external_images: Fix: Hadn't looked for pictures in the format [img=XxY] --- include/network.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/network.php b/include/network.php index a95dde53..fd9999b5 100644 --- a/include/network.php +++ b/include/network.php @@ -802,7 +802,7 @@ function scale_external_images($s, $include_link = true, $scale_replace = false) $s = htmlspecialchars_decode($s); $matches = null; - $c = preg_match_all('/\[img\](.*?)\[\/img\]/ism',$s,$matches,PREG_SET_ORDER); + $c = preg_match_all('/\[img.*?\](.*?)\[\/img\]/ism',$s,$matches,PREG_SET_ORDER); if($c) { require_once('include/Photo.php'); foreach($matches as $mtch) { From fc27edb6d76765cd9b85d29a3c41f23f17c6ca41 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 26 Jul 2012 00:23:25 +0200 Subject: [PATCH 4/8] network: Caching of images --- include/network.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/network.php b/include/network.php index fd9999b5..0fff5c7c 100644 --- a/include/network.php +++ b/include/network.php @@ -823,6 +823,12 @@ function scale_external_images($s, $include_link = true, $scale_replace = false) $scaled = $mtch[1]; $i = fetch_url($scaled); + $cache = get_config('system','itemcache'); + if (($cache != '') and is_dir($cache)) { + $cachefile = $cache."/".hash("md5", $scaled); + file_put_contents($cachefile, $i); + } + // guess mimetype from headers or filename $type = guess_image_type($mtch[1],true); From dc416e58871ff817aca6b51dde176c7eae80ddaa Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 26 Jul 2012 07:38:51 +0200 Subject: [PATCH 5/8] Moving the index creation commands into a readme file due to the fact that creating of these indexes is really slow. --- mods/readme.txt | 5 +++++ update.php | 15 +-------------- 2 files changed, 6 insertions(+), 14 deletions(-) create mode 100644 mods/readme.txt diff --git a/mods/readme.txt b/mods/readme.txt new file mode 100644 index 00000000..9e79f843 --- /dev/null +++ b/mods/readme.txt @@ -0,0 +1,5 @@ +Site speed can be improved when the following indexes are set. They cannot be set through the update script because on large sites they will block the site for several minutes. + +CREATE INDEX `uid_commented` ON `item` (`uid`, `commented`); +CREATE INDEX `uid_created` ON `item` (`uid`, `created`); +CREATE INDEX `uid_unseen` ON `item` (`uid`, `unseen`); diff --git a/update.php b/update.php index 2d80ee36..f98fb3ae 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@ Date: Thu, 2 Aug 2012 00:13:37 +0200 Subject: [PATCH 6/8] bbcode: two new bbcode elements (style, class) for CSS --- include/bbcode.php | 6 ++++++ view/theme/diabook/style-profile.css | 7 ++++++- view/theme/diabook/style.css | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index 9ece3c3d..d83cd358 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -224,6 +224,12 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { // Check for list text $Text = str_replace("[*]", "
  • ", $Text); + // Check for style sheet commands + $Text = preg_replace("(\[style=(.*?)\](.*?)\[\/style\])ism","$2",$Text); + + // Check for CSS classes + $Text = preg_replace("(\[class=(.*?)\](.*?)\[\/class\])ism","$2",$Text); + // handle nested lists $endlessloop = 0; diff --git a/view/theme/diabook/style-profile.css b/view/theme/diabook/style-profile.css index 63b2eb54..927549fa 100644 --- a/view/theme/diabook/style-profile.css +++ b/view/theme/diabook/style-profile.css @@ -2549,4 +2549,9 @@ list-style-type: disc; #photos-upload-newalbum-div { float: left; width: 175px; -} \ No newline at end of file +} + +.item-image-preview { + float: left; + margin-right: 10px; +} diff --git a/view/theme/diabook/style.css b/view/theme/diabook/style.css index 68bfd5d3..286559b8 100644 --- a/view/theme/diabook/style.css +++ b/view/theme/diabook/style.css @@ -2906,4 +2906,4 @@ list-style-type: disc; #photos-upload-newalbum-div { float: left; width: 175px; -} \ No newline at end of file +} From 2aa67d67f508067fcb821ec9f816cdc921c18d8a Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 2 Aug 2012 01:46:28 +0200 Subject: [PATCH 7/8] Changed markdown to enable diaspora postings with images that contain links --- include/bb2diaspora.php | 6 +++--- include/markdownify/markdownify.php | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index b95dee8f..9ede42f6 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -202,9 +202,9 @@ function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) { // the following was added on 10-January-2012 due to an inability of Diaspora's // new javascript markdown processor to handle links with images as the link "text" // It is not optimal and may be removed if this ability is restored in the future - if ($fordiaspora) - $Text = preg_replace("/\[url\=([^\[\]]*)\]\s*\[img\](.*?)\[\/img\]\s*\[\/url\]/ism", - "[url]$1[/url]\n[img]$2[/img]", $Text); + //if ($fordiaspora) + // $Text = preg_replace("/\[url\=([^\[\]]*)\]\s*\[img\](.*?)\[\/img\]\s*\[\/url\]/ism", + // "[url]$1[/url]\n[img]$2[/img]", $Text); // Convert it to HTML - don't try oembed $Text = bbcode($Text, $preserve_nl, false); diff --git a/include/markdownify/markdownify.php b/include/markdownify/markdownify.php index 7bbf1cbb..0d4429a0 100644 --- a/include/markdownify/markdownify.php +++ b/include/markdownify/markdownify.php @@ -686,6 +686,10 @@ class Markdownify { # [1]: mailto:mail@example.com Title $tag['href'] = 'mailto:'.$bufferDecoded; } + + $this->out('['.$buffer.']('.$tag['href'].' "'.$tag['title'].'")', true); + +/* # [This link][id] foreach ($this->stack['a'] as $tag2) { if ($tag2['href'] == $tag['href'] && $tag2['title'] === $tag['title']) { @@ -699,6 +703,7 @@ class Markdownify { } $this->out('['.$buffer.']['.$tag['linkID'].']', true); +*/ } } /** @@ -737,7 +742,7 @@ class Markdownify { // ![Alt text](/path/to/img.jpg "Optional title") if ($this->parser->tagAttributes['title'] != "") - $this->out('!['.$this->parser->tagAttributes['alt'].']('.$this->parser->tagAttributes['src'].'"'.$this->parser->tagAttributes['title'].'")', true); + $this->out('!['.$this->parser->tagAttributes['alt'].']('.$this->parser->tagAttributes['src'].' "'.$this->parser->tagAttributes['title'].'")', true); else $this->out('!['.$this->parser->tagAttributes['alt'].']('.$this->parser->tagAttributes['src'].')', true); From 6d0f0e62733d4e2088631c8e4ab44631d9e60548 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 2 Aug 2012 10:25:08 +0200 Subject: [PATCH 8/8] parse_url: Fixed a problem in the detection if there was an image or not. Additionally removed some test content. --- mod/parse_url.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mod/parse_url.php b/mod/parse_url.php index 5dd7de75..ea05055f 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -176,6 +176,9 @@ function parseurl_getsiteinfo($url) { } } else { $src = completeurl($siteinfo["image"], $url); + + unset($siteinfo["image"]); + $photodata = getimagesize($src); if (($photodata[0] > 10) and ($photodata[1] > 10)) @@ -292,8 +295,7 @@ function parse_url_content(&$a) { $siteinfo = parseurl_getsiteinfo($url); if($siteinfo["title"] == "") { - echo print_r($siteinfo, true); - //echo sprintf($template,$url,$url,'') . $str_tags; + echo sprintf($template,$url,$url,'') . $str_tags; killme(); } else { $text = $siteinfo["text"]; @@ -302,7 +304,7 @@ function parse_url_content(&$a) { $image = ""; - if($siteinfo["image"] != ""){ + if(sizeof($siteinfo["images"]) > 0){ /* Execute below code only if image is present in siteinfo */