Contenido Facebook Plugin
Contenido Facebook Plugin
Hey,
ich habe mal eine kurze Frage:
Wenn ich einen Artikel meines Blogs poste wird das Bild im Beitrag nicht als Vorschaubild ausgewählt. Woran liegt das? (1. Frage) Es ist doch per IMG eingebunden. So nun habe ich über etwas von Facebook (Open Graph glaube ich) ein festes Bild festgelegt, was ich so nicht möchte. Deshalb habe ich überlegt, das im Artikel eingefügte 1. Bild dort rein zutun, so das jeder Artikel sein eigenes Bild erhält.
Hat jemand Ideen? Lösungsvorschläge? Wie ist das überhaupt in Contenido Um setzbar? Kann ich das Bild auslesen?
Danke
VG
CA
ich habe mal eine kurze Frage:
Wenn ich einen Artikel meines Blogs poste wird das Bild im Beitrag nicht als Vorschaubild ausgewählt. Woran liegt das? (1. Frage) Es ist doch per IMG eingebunden. So nun habe ich über etwas von Facebook (Open Graph glaube ich) ein festes Bild festgelegt, was ich so nicht möchte. Deshalb habe ich überlegt, das im Artikel eingefügte 1. Bild dort rein zutun, so das jeder Artikel sein eigenes Bild erhält.
Hat jemand Ideen? Lösungsvorschläge? Wie ist das überhaupt in Contenido Um setzbar? Kann ich das Bild auslesen?
Danke
VG
CA
Re: Contenido Facebook Plugin
Hallo contenidoAmateur,
du brauchts sowas wie
im head-Bereich deines Artikels, damit Facebook genau weiß, welches Bild beim Posten vorausgewählt werden soll, wenn jemand den Artikel posten möchte. Ansonsten versucht Facebook die Bilder durch das Parsen der HTML-Ausgabe der Seite zu ermitteln, was in den meisten Fällen wegen der fehlenden Semantik nicht sehr gut klappt...
Hier ein Artikel dazu:
https://developers.facebook.com/docs/op ... g-objects/
Hast du z. B. in CONTENIDO das Bild als CMS_IMG[1], dann kannst du im Layout/Modul folgendermaßen darauf zugreifen:
Ich würde dir sogar vorschlagen, dass du das in der Chain "Contenido.Content.CreateMetatags" machst, dann werden die Open-Graph Metatags beim Generieren des Codes der Seite erstellt und nicht bei jeder Ausgabe!
Gruß
xmurrix
du brauchts sowas wie
Code: Alles auswählen
<meta property="og:image" content="http://domain/cms/upload/image.jpg" />
Hier ein Artikel dazu:
https://developers.facebook.com/docs/op ... g-objects/
Hast du z. B. in CONTENIDO das Bild als CMS_IMG[1], dann kannst du im Layout/Modul folgendermaßen darauf zugreifen:
Code: Alles auswählen
$oArt = new Article($idart, $client, $lang);
$uplid = $oArt->getContent('img', 1); // CMS_IMG[1] = img u. 1
$db = new DB_Contenido();
$imageUrl = '';
$sql = "SELECT * FROM " . $cfg['tab']['upl'] . " WHERE idclient = " . (int) $client . " AND idupl = " . (int) $uplid;
if ($db->query($sql)) {
if ($db->next_record()) {
$imageUrl = $cfgClient[$client]['path']['htmlpath'] . $cfgClient[$client]['upload'] . $db->f('dirname') . $db->f('filename');
}
}
if (!empty($imageUrl)) {
echo '<meta property="og:image" content="' . $imageUrl . '" />';
}
Gruß
xmurrix
CONTENIDO Downloads: CONTENIDO 4.10.1
CONTENIDO Links: Dokumentationsportal, FAQ, API-Dokumentation
CONTENIDO @ Github: CONTENIDO 4.10 - Mit einem Entwicklungszweig (develop-branch), das viele Verbesserungen/Optimierungen erhalten hat und auf Stabilität und Kompatibilität mit PHP 8.0 bis 8.2 getrimmt wurde.
CONTENIDO Links: Dokumentationsportal, FAQ, API-Dokumentation
CONTENIDO @ Github: CONTENIDO 4.10 - Mit einem Entwicklungszweig (develop-branch), das viele Verbesserungen/Optimierungen erhalten hat und auf Stabilität und Kompatibilität mit PHP 8.0 bis 8.2 getrimmt wurde.
Re: Contenido Facebook Plugin
Hi,
danke. Ich dachte das wäre ein einfaches Skript o.O
Naja kannst du mir helfen das von dir in das zu integrieren? Weil bei mir funzt das net...
danke. Ich dachte das wäre ein einfaches Skript o.O
Naja kannst du mir helfen das von dir in das zu integrieren? Weil bei mir funzt das net...
Code: Alles auswählen
<?php
/**
* Project:
* Contenido Content Management System
*
* Description:
* Generate metatags for current article if they are not set in article properties
*
* Requirements:
* @con_php_req 5.0
*
*
* @package Contenido Backend classes
* @version 1.0
* @author Andreas Lindner, Unknown
* @copyright four for business AG <www.4fb.de>
* @license http://www.contenido.org/license/LIZENZ.txt
* @link http://www.4fb.de
* @link http://www.contenido.org
*
* {@internal
* created 2007-10-24
* modified 2008-07-04, bilal arslan, added security fix
* modified 2009-10-08, Murat Purc, bugfix in function CheckIfMetaTagExists(), see [#CON-271]
* modified 2009-12-18, Murat Purc, fixed meta tag generation, see [#CON-272]
* $Id: include.chain.content.createmetatags.php 1102 2009-12-17 23:22:20Z xmurrix $:
* }}
*
*/
if(!defined('CON_FRAMEWORK')) {
die('Illegal call');
}
cInclude("plugins", "repository/keyword_density.php");
function cecCreateMetatags ($metatags) {
global $cfg, $lang, $idart, $client, $cfgClient, $idcat, $idartlang;
//Basic settings
$cachetime = 3600; // measured in seconds
$cachedir = $cfgClient[$client]['path']['frontend'] . "cache/";
if (!is_array($metatags)) {
$metatags = array();
}
$hash = 'metatag_'.md5($idart.'/'.$lang);
$cachefilename = $cachedir.$hash.'.tmp';
#Check if rebuilding of metatags is necessary
$reload = true;
$fileexists = false;
if (file_exists($cachefilename)) {
$fileexists = true;
$diff = mktime() - filemtime($cachefilename);
if ($diff > $cachetime) {
$reload = true;
} else {
$reload = false;
}
}
if ($reload) {
//(Re)build metatags
$db = new DB_Contenido();
#Get encoding
$sql = "SELECT * FROM ".$cfg['tab']['lang']." WHERE idlang=".(int)$lang;
$db->query($sql);
if ($db->next_record()) {
$sEncoding = strtoupper($db->f('encoding'));
} else {
$sEncoding = "ISO-8859-1";
}
#Get idcat of homepage
$sql = "SELECT a.idcat
FROM
".$cfg['tab']['cat_tree']." AS a,
".$cfg['tab']['cat_lang']." AS b
WHERE
(a.idcat = b.idcat) AND
(b.visible = 1) AND
(b.idlang = ".Contenido_Security::toInteger($lang).")
ORDER BY a.idtree LIMIT 1";
$db->query($sql);
if ($db->next_record()) {
$idcat_homepage = $db->f('idcat');
}
$availableTags = conGetAvailableMetaTagTypes();
#Get first headline and first text for current article
$oArt = new Article ($idart, $client, $lang);
#Set idartlang, if not set
if ($idartlang == '') {
$idartlang = $oArt->_getIdArtLang($idart, $lang);
}
$arrHead1 = $oArt->getContent("htmlhead");
$arrHead2 = $oArt->getContent("head");
if (!is_array($arrHead1)) {
$arrHead1 = array();
}
if (!is_array($arrHead2)) {
$arrHead2 = array();
}
$arrHeadlines = array_merge($arrHead1, $arrHead2);
foreach ($arrHeadlines as $key => $value) {
if ($value != '') {
$sHeadline = $value;
break;
}
}
$sHeadline = strip_tags($sHeadline);
$sHeadline = substr(str_replace(chr(13).chr(10),' ',$sHeadline),0,100);
$arrText1 = $oArt->getContent("html");
$arrText2 = $oArt->getContent("text");
if (!is_array($arrText1)) {
$arrText1 = array();
}
if (!is_array($arrText2)) {
$arrText2 = array();
}
$arrText = array_merge($arrText1, $arrText2);
foreach ($arrText as $key => $value) {
if ($value != '') {
$sText = $value;
break;
}
}
$sText = strip_tags(urldecode($sText));
$sText = keywordDensity ('', $sText);
//Get metatags for homeapge
$arrHomepageMetaTags = array();
$sql = "SELECT startidartlang FROM ".$cfg["tab"]["cat_lang"]." WHERE (idcat=".Contenido_Security::toInteger($idcat_homepage).") AND(idlang=".Contenido_Security::toInteger($lang).")";
$db->query($sql);
if($db->next_record()){
$iIdArtLangHomepage = $db->f('startidartlang');
#get idart of homepage
$sql = "SELECT idart FROM ".$cfg["tab"]["art_lang"]." WHERE idartlang =".Contenido_Security::toInteger($iIdArtLangHomepage);
$db->query($sql);
if ($db->next_record()) {
$iIdArtHomepage = $db->f('idart');
}
$t1 = $cfg["tab"]["meta_tag"];
$t2 = $cfg["tab"]["meta_type"];
$sql = "SELECT ".$t1.".metavalue,".$t2.".metatype FROM ".$t1.
" INNER JOIN ".$t2." ON ".$t1.".idmetatype = ".$t2.".idmetatype WHERE ".
$t1.".idartlang =".$iIdArtLangHomepage.
" ORDER BY ".$t2.".metatype";
$db->query($sql);
while ($db->next_record()) {
$arrHomepageMetaTags[$db->f("metatype")] = $db->f("metavalue");
}
$oArt = new Article ($iIdArtHomepage, $client, $lang);
$arrHomepageMetaTags['pagetitle'] = $oArt->getField('title');
}
//Cycle through all metatags
foreach ($availableTags as $key => $value) {
$metavalue = conGetMetaValue($idartlang, $key);
if (strlen($metavalue) == 0){
//Add values for metatags that don't have a value in the current article
switch(strtolower($value["name"])){
case 'author':
//Build author metatag from name of last modifier
$oArt = new Article ($idart, $client, $lang);
$lastmodifier = $oArt->getField("modifiedby");
$oUser = new User();
$oUser->loadUserByUserID(md5($lastmodifier));
$lastmodifier_real = $oUser->getRealname(md5($lastmodifier));
$iCheck = CheckIfMetaTagExists($metatags, 'author');
$metatags[$iCheck]['name'] = 'author';
$metatags[$iCheck]['content'] = $lastmodifier_real;
break;
case 'date':
//Build date metatag from date of last modification
$oArt = new Article ($idart, $client, $lang);
$lastmodified = $oArt->getField("lastmodified");
$iCheck = CheckIfMetaTagExists($metatags, 'date');
$metatags[$iCheck]['name'] = 'date';
$metatags[$iCheck]['content'] = $lastmodified;
break;
case 'description':
//Build description metatag from first headline on page
$iCheck = CheckIfMetaTagExists($metatags, 'description');
$metatags[$iCheck]['name'] = 'description';
$metatags[$iCheck]['content'] = $sHeadline;
break;
case 'keywords':
$iCheck = CheckIfMetaTagExists($metatags, 'keywords');
$metatags[$iCheck]['name'] = 'keywords';
$metatags[$iCheck]['content'] = $sText;
break;
case 'revisit-after':
case 'robots':
case 'expires':
//Build these 3 metatags from entries in homepage
$sCurrentTag = strtolower($value["name"]);
$iCheck = CheckIfMetaTagExists($metatags, $sCurrentTag);
$metatags[$iCheck]['name'] = $sCurrentTag;
$metatags[$iCheck]['content'] = $arrHomepageMetaTags[$sCurrentTag];
break;
}
}
}
// save metatags in cache file
file_put_contents($cachefilename, serialize($metatags));
} else {
#Get metatags from file system cache
$metatags = unserialize(file_get_contents($cachefilename));
}
return $metatags;
}
/**
* Checks if the metatag allready exists inside the metatag list.
*
* @param array|mixed $arrMetatags List of metatags or not a list
* @param string $sCheckForMetaTag The metatag to check
* @return int Position of metatag inside the metatag list or the next
* available position
*/
function CheckIfMetaTagExists($arrMetatags, $sCheckForMetaTag) {
if (!is_array($arrMetatags) || count($arrMetatags) == 0) {
// metatag list ist not set or empty, return initial position
return 0;
}
// loop thru existing metatags and check against the listitem name
foreach ($arrMetatags as $pos => $item) {
if ($item['name'] == $sCheckForMetaTag) {
// metatag found -> return the position
return $pos;
}
}
// metatag doesn't exists, return next position
return count($arrMetatags);
}
$oArt = new Article($idart, $client, $lang);
$uplid = $oArt->getContent('img', 1); // CMS_IMG[1] = img u. 1
$db = new DB_Contenido();
$imageUrl = '';
$sql = "SELECT * FROM " . $cfg['tab']['upl'] . " WHERE idclient = " . (int) $client . " AND idupl = " . (int) $uplid;
if ($db->query($sql)) {
if ($db->next_record()) {
$imageUrl = $cfgClient[$client]['path']['htmlpath'] . $cfgClient[$client]['upload'] . $db->f('dirname') . $db->f('filename');
}
}
if (!empty($imageUrl)) {
echo '<meta property="og:image" content="' . $imageUrl . '" />';
}
?>
Re: Contenido Facebook Plugin
Übrigends bei mir ist es nicht 1 sondern 0. Würde mich über Hilfe freuen...
Danke
Danke
Re: Contenido Facebook Plugin
Auch ne Möglichkeit: http://forum.contenido.org/viewtopic.ph ... 02#p158180
seamless-design.de
"Geht nicht!" wohnt in der "Will nicht!"-Strasse.
Das Handbuch zur Version 4.10: CONTENIDO für Einsteiger (4.10)
Das Handbuch zur Version 4.9: CONTENIDO für Einsteiger (4.9)
"Geht nicht!" wohnt in der "Will nicht!"-Strasse.
Das Handbuch zur Version 4.10: CONTENIDO für Einsteiger (4.10)
Das Handbuch zur Version 4.9: CONTENIDO für Einsteiger (4.9)