Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Facebook Titles: mod #454

Closed
ghostofzigz opened this issue Jan 10, 2017 · 3 comments
Closed

Better Facebook Titles: mod #454

ghostofzigz opened this issue Jan 10, 2017 · 3 comments
Labels
Code-Inclusion-Request Author requests including code Code-Refactoring Code refactoring

Comments

@ghostofzigz
Copy link

ghostofzigz commented Jan 10, 2017

UPDATED Jan 12, 2017 (working well)

My News Aggrigation application filters by title. The titles coming from the FacebookBridge are mostly NON-unique. Here is an update to the FacebookBridge title section which gives a far more descriptive title and attempts to make it unique if there is not enough data:

On or near line 150 find the following
AFTER THIS, add:

			// remove these items from title
			$_d1 = html_entity_decode("·", ENT_COMPAT, "UTF-8");
			$_d2 = html_entity_decode("Â", ENT_COMPAT, "UTF-8");
			$rp = array(
				"/$_d1/",
				"/$_d2/",
				"/^PostsSee All/",
				"/^NotesSee All/",
				"/$author shared/",
				"/^$author/",
				"/^shared/",
				"/^\&quot\;/",
				"/^Posts/",
				"/^Notes/",
				"/^Continue Reading/",
				"/^(\d*) hrs/",
				"/^Reviews/",
				"/^See All/",
				"/^(\d*) Reviews/",
				"/(.*?)See More/",
				"/^Click for more/",
			);

On or near Line 210 change:

					//Build title from username and content
					$title = $author;
					if (strlen($title) > 24)
						$title = substr($title, 0, strpos(wordwrap($title, 24), "\n")).'...';
					$title = $title.' | '.strip_tags($content);
					if (strlen($title) > 64)
						$title = substr($title, 0, strpos(wordwrap($title, 64), "\n")).'...';

To:

					//Build title from username and content
					/*
					$title = $author;
					if (strlen($title) > 24)
						$title = substr($title, 0, strpos(wordwrap($title, 24), "\n")).'...';
					$title = $title.' | '.strip_tags($content);
					if (strlen($title) > 64)
						$title = substr($title, 0, strpos(wordwrap($title, 64), "\n")).'...';

					*/
					
					// Build title from content, date, and username
					$p = "/.*?".$_d1."\s/";
					$title = strip_tags(preg_replace($p, '', $content));
					$_f = 1; $_c = 0;
					while ($_f) {
						$_f = 0;
						foreach ($rp as $p) {
							$title = trim(preg_replace($p, '', $title, $_c));
							if (($_c) && ($_c > 0)) $_f++;
						}
					}
					if (strlen($title) < 4) {
						$title = $author;
						if ($date) $_d = date("M j, Y", $date);
						$_l = (($date) ? 62 - strlen($_d) : 64);
						if (strlen($title) > $_l)
							$title = substr($title, 0, strpos(wordwrap($title, $_l), "\n"))."&hellip;";
						if ($date) $title = $title." ".$_d;
					} else {
						$_l = 64;
						if (strlen($title) > $_l)
							$title = substr($title, 0, strpos(wordwrap($title, $_l), "\n"))."&hellip;";
					}	

I also have a shell script to automate this update for whenever the RSS-Bridge code is updated from here... if anyone would like that, get at me.
-- ghostofzigz

@logmanoriginal logmanoriginal added Code-Inclusion-Request Author requests including code Code-Refactoring Code refactoring labels Jan 12, 2017
@logmanoriginal
Copy link
Contributor

Nice work @ghostofzigz 👍
Can you open a PR for this?

I haven't tested it on my machine yet, but can this be made compatible to all languages (I assume this will only work for English Facebook)?

Also, is there any particular reason to wrap lines at 24/64 characters or is it made to your specific needs?

@ghostofzigz
Copy link
Author

ghostofzigz commented Jan 16, 2017

I will take another look at simplifying the regex to eliminate language specific patterns... unfortunately at this time it looks like Facebook is blocking ALL requests via the RSS Bridge, so I will need to hack the request URL for this module to continue automated testing.

The reason for the 24 and 64 length limits was for compatibility with the code I was replacing (wasn't sure the reason for that either, figured it may come into play in other parts of the application adding to the title, and twitter length limits).

logmanoriginal pushed a commit that referenced this issue Nov 16, 2018
A slightly improved version of #454 and #468 . Build titles from content rather than author + pre-content (which doesn't reflect anything useful).
@logmanoriginal
Copy link
Contributor

Closing because Facebook titles were fixed a long time ago.

infominer33 pushed a commit to web-work-tools/rss-bridge that referenced this issue Apr 17, 2020
A slightly improved version of RSS-Bridge#454 and RSS-Bridge#468 . Build titles from content rather than author + pre-content (which doesn't reflect anything useful).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code-Inclusion-Request Author requests including code Code-Refactoring Code refactoring
Projects
None yet
Development

No branches or pull requests

2 participants