// INIT DEFAULT/EMPTY VARS
// You can add any other url parameters you require here
$myComponentID = 0; //This is the unique ID from whichever component you're using
$myComponentView = ""; // This is the view that you want to target within your component, e.g. "list", "article", "file" etc...
// AS A SAFETY MEASURE, CHECK THAT YOUR 'IN' YOUR CHOSEN COMPONENT
if(isset($_GET['option']) && $_GET['option'] == "com_mycomponent"){ // Replace with the string for your chosen component
// grab the url params
$myComponentID = $_GET['id']; // set id to query image filename & any other data
$myComponentView = $_GET['view']; // check view/database table to look up
if (!is_numeric($myComponentID) || $myComponentID == 0 || $myComponentID == ""){ // the view or artist id are missing - DON'T OUTPUT TAGS!
$htmlToRender ="";
}else{ //get image filename from the db
// Joomla DB Object - needed to make calls to the DB
$db =& JFactory::getDBO();
// Check which view we're in if not empty view
switch ($myComponentView) {
// DEFAULT VARS
case "client":
//query
$db->setQuery("
SELECT
t1.name AS Name, t1.dept AS Dept, t1.pic AS Pic
FROM jos_my_component_table t1 /* ref to table t1 */
WHERE t1.id = $myComponentID
LIMIT 1
");
// DEBUG THE VARS
print_r($_ogData); // COMMENT THIS OUT TO REMOVE
$_ogData = $db->loadAssoc(); // An associative array of results
// Now get all of the individual elements from the array
$_ogTitle = $_ogData[Name] . " - " . $_ogData[Dept]; // Here I'm concatenating a fiew fields to create a more descriptive title
// Check that there is an image in the db
if(is_null($_ogData[Pic]) || $_ogData[Pic] == ""){ // if it's empty or null set a default
$_ogImage = "http://www.mydomain.com/images/stories/default-component-image.png";
}else{ // Concat the url to the artist pic directory and add the aPic
$_ogImage = "https://www.learnthrusong.co.uk/images/stories/" . $_ogData[Pic];
}
// ADD ANY OTHER FIELDS/EVAL HERE AS YOU LIKE
break;
case "others":
// add your other cases as with "client", changing DB tables/fields to suit
// This allows you to totally customise your output per view
break;
default: // IN MY CASE - DO NOTHING!!! //
// This is your safety net!!! Anything not covered in the cases defined above will run DEFAULT
// Therefore, you could specify some default values OR LEAVE BLANK
break;
} //END SWITCH
// Output HTML - {JFBC Tags} // AGAIN, ADD WHICHEVER ONES YOU WANT WITH YOUR NEW CUSTOM VARS
$currenturl = JURI::current(); // The current page URL
$htmlToRender ="
Yes it worked!
{JFBCGraph title=$_ogTitle}
{JFBCGraph url=$currenturl}
{JFBCGraph type=your_app_name:your_fb_object_name}
{JFBCGraph image=$_ogImage}
";
}
echo "$htmlToRender";
}
}else{ // the option (component) you specified in the first IF wasn't detected in the URL
$htmlToRender ="Didn't get the option out of the URL";
echo "$htmlToRender";
}
$myComponentID = JRequest::getInt('id', null); // set id to query image filename & any other data - Use JRequest to filter by int
$myComponentView = JRequest::getCmd('view', 'default')// check view/database table to look up - Use JRequest to filter the variable (not necessary in your case, but always good anyways) and set a default value of 'default'.
if (!$myComponentID){ // the view or artist id are missing - DON'T OUTPUT TAGS! - JRequest already filtered, or set this to null. Just check the value
$htmlToRender ="";
Join our newsletter to get alerts for Joomla releases, tips and tricks and extension updates.