We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

Blogs plugin newsfeed item bug | Forum

Omari
Omari Dec 8 '13
If multiple lines spaces are used in blogs the resultant newsfeed item refelcts these spaces, For example any user can  produce a blog and place 20 line spaces in the top part of his/her article and it will appear like this in the newfeed. The same holds true for if full sized images are inserted into posts. A large black space will appear in the associated newsfeed item.
The Forum post is edited by Omari Dec 8 '13
Alia Team
Alia Dec 10 '13
Omari,

1. multiple line spaces

You can modify this using preg_replace or any other method that you know, within init.php of the "Blogs" plugin:

 $content = nl2br( UTIL_String::truncate(strip_tags($post->post), 150, '...') );
 $title = UTIL_String::truncate(strip_tags($post->title), 100, '...');


2. Black spaces instead of full size images.

Can't reproduce this.

 a) here is my full size image



b) here is the newsfeed item


Omari
Omari Dec 10 '13
yes u are not supposed to have that large space in between. You have just reproduced the issue. 


Can u explain ur method of preg replace a bit clearer im no coder

Alia Team
Alia Dec 12 '13
Omari, there are several approaches to this issue. And it is up to you to choose needed one.
Here is one of the solutions:

We are editing init.php file of "Blogs" plugin.

Original code:

$content = nl2br( UTIL_String::truncate(strip_tags($post->post), 150, '...') );

1. SHOW IMAGES UPLOADED TO BLOG'S BODY IN NEWSFEED

Modified code:

$content = nl2br( UTIL_String::truncate(strip_tags($post->post,'<img>'), 150, '...') );

Where '<img>' part tells the script to strip ALL tags except <img> ones.
As a result images added to blog posts will be displayed in newsfeed.

2. REMOVE EMPTY LINES

Modified FINAL code:

$content = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n",( UTIL_String::truncate(strip_tags($post->post, '<img>'), 500, '...')));

Where:

preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n" tells the script to completely remove 
empty lines and give out $post as one string.

500- is increased number of allowed symbols. You need to increase it because now script will be counting symbols within the <img> tag.
Example: <img style="padding:5px;" src="http://sitename.com/...-macro_sharon_14.jpg" /> . This string already contains 100 symbols. So original 150 limit to the $post itself is definitely not enough.

RESULT:




IMPORTANT NOTES.

1. Any custom code modifications  done in .php files will be erased if you update the plugin. Always keep track of what and where you are changing.

2. If image string contains for example 100 symbols, and user adds the image after the text which already contains 450 symbols, script will cut the image giving that the overall  $post limit is 500 symbols.

3. You are doing any custom work at your own risk. Always back up the file you are going to edit.
 
WHY OXWALL WORKS THE WAY It CURRENTLY DOES.

1. Showing additional images  in newsfeed effect site performance.
2. Increasing $post limit in newsfeed will result in longer newsfeed, which is not what majority user want to.
3. With regards to empty spaces, images are being replaced with optimal ( 4-5) empty lines, which doesn't influence the perception of the site and saves server resources.
    Likelihood of user entering 20 empty lines at the beginning of the blog is small. Your report is the first one we received. If we get similar reports in future we will surely try to find a better solution to displaying blogs in newsfeed.


Alia Team
Alia Dec 12 '13
Topic was moved from Bug reports and troubleshooting.
Omari
Omari Dec 12 '13
thanks for this detailed feedback i really appreciate it. will have to analyze
Omari
Omari Dec 12 '13
p.s. i thought u said u weren't a coder lol or is this someone else's solution?
Alia Team
Alia Dec 12 '13
Omari, I got interested in your question and did some googling to find out how strip_tag and preg_replace work :D

You are welcome
Omari
Omari Dec 13 '13
much appreciated
matt
matt Jan 20 '15
Hi,

Can you let us know how the solution for blog newsfeed images will work with current 1.7x version?

Thanks,

Matt
=========================================
Original code:

$content = nl2br( UTIL_String::truncate(strip_tags($post->post), 150, '...') );

1. SHOW IMAGES UPLOADED TO BLOG'S BODY IN NEWSFEED

Modified code:

$content = nl2br( UTIL_String::truncate(strip_tags($post->post,'<img>'), 150, '...') );

Where '<img>' part tells the script to strip ALL tags except <img> ones.
As a result images added to blog posts will be displayed in newsfeed.
matt
matt Jan 21 '15
Anyone?