Browse Source

urlmetadata: support og:description, limit maximum content sizes, properly cache result

Andrew Dolgov 2 years ago
parent
commit
2f17696a65
1 changed files with 11 additions and 2 deletions
  1. 11 2
      backend.php

+ 11 - 2
backend.php

@@ -825,6 +825,7 @@
 
 						$m_title = $xpath->query("//meta[@property='og:title']")->item(0);
 						$m_image = $xpath->query("//meta[@property='og:image']")->item(0);
+						$m_descr = $xpath->query("//meta[@property='og:description']")->item(0);
 
 						if ($m_title) {
 							$rv['title'] = $m_title->getAttribute('content');
@@ -834,14 +835,22 @@
 
 							if ($node) {
 								$rv['title'] = preg_replace("/[\r\n\t]/", "", trim($node->nodeValue));
-
-								$cache->set($key, $rv, 86400 * 12);
 							}
 						}
 
 						if ($m_image)
 							$rv['image'] = $m_image->getAttribute('content');
 
+						if ($m_descr)
+							$rv['descr'] = $m_descr->getAttribute('content');
+
+						foreach ($rv as $k => $v) {
+							$rv[$k] = mb_substr($v, 0, 1024);
+						}
+
+						if ($rv['title'])
+							$cache->set($key, $rv, 86400 * 12);
+
 					}
 				}
 			}