<?php
/* This is an untested re-scripting of Luis' posted snippet.
* I am mostly avoiding single-use variables and separating "processing" from "displaying" portions of code
* I am have added spaces when concatenating with dots, and between function parameters.
* The addition of the head tags is only done if the option and view parameters are satisfactory.
* Finally, it may be a good idea to call addcslashes($string, '"') on your variables for stability
*/
if (JRequest::getCmd('option') === "com_content" && JRequest::getCmd('view') === "article") {
$doc =& JFactory::getDocument();
$article =& JTable::getInstance("content");
$article->load(strstr(JRequest::getString('id'), ':', true));
$twitterTitle = mb_strimwidth(strip_tags($article->get("title")), 0, 225, " ...");
$twitterDescription = mb_strimwidth(strip_tags($doc->getMetaData('description')), 0, 225, " ...");
$introImage = 'http://yourdomain.com/' . json_decode($article->get("images"))->image_intro;
$doc->addCustomTag('
<meta name="twitter:title" content="{$twitterTitle}"/>
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:site" content="yoursite"/>
<meta name="twitter:creator" content="yourcreator"/>
<meta name="twitter:url" content="' . JURI::current() . '"/>
<meta name="twitter:description" content="{$twitterDescription}"/>
<meta name="twitter:image" content="{$introImage}"/>
');
}