Topic-icon Problem with object

Active Subscriptions:

None
13 years 3 months ago #31080 by kongenii
Problem with object was created by kongenii
I have created my own opengraph plugin. I got half of it working, but the last part of the function checkActionAfterRoute() does trigger, however back end i get the error (#100) At least one reference object must be specified.

When i print_r($this->object) i get an object printed that matches the object set up back-end. It has also been set-up on facebook and references double checked. Is there any input on what might trigger this error?
The topic has been locked.
Support Specialist
13 years 3 months ago #31086 by alzander
Replied by alzander on topic Problem with object
Very glad to hear you're trying to make your own plugin! We don't have documentation for doing that, but it's something we're planning to create soon. I'm hoping the comments in the content or custom plugin are helpful.

The likely issue for that error is that when you're calling:
$this->triggerAction($action, $url);
The URL you're sending in isn't correct. Try echo'ing out that URL and make sure if you go to it directly that the og:type is properly set in the HTML.

Beyond that, you can also go to the /components/com_jfbconnect/models/opengraphaction.php file and print_r some of the fields in the triggerAction function. Mainly, verify that the following lines have the data you expect for the $url, and check that URL as mentioned above.
// Always include the 'object' argument as some actions want the generic, others want the specific.
                    $args['object'] = $url;
                    $args[strtolower($object->type)] = $url;
I hope that helps get you going. Let us know how your development goes. If there's any feedback you have on the process, let us know. Also, if your plugin is something for an available extension, we'd love to hear more about it if it may help others.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
13 years 3 months ago #31103 by kongenii
Replied by kongenii on topic Problem with object
Hi Alex,

Thanks for the comments, it led me in somewhat the right direction. My problem is that in my plugin i have set up two actions and one object. The problem initially was the URL as you correctly described. What I want is to have two action for the same object, it results in both actions getting printed when i load one page the are related two. I have an action for viewing an item, and one for bying. Both actions are set to the same object so when the item is loaded for viewing on facebook it will both say that i viewed and bought the item. I looked at how it is done in the jomsocial component. And tried if i could put in $this->triggerAction($action, $url); in a function, and then when i view the item i call the trigger function, and do the same when i buy. However even when i put it in functions, the actions are still triggered even though i am not actually calling the method?

How can i make it so that i can define two different triggers for the same object but that is fired on different places on the webpage? I would suspect, that you would have to do it in a function as both when buying and viewing it all goes down from the same URL to the items page..
The topic has been locked.
Active Subscriptions:

None
13 years 3 months ago #31151 by kongenii
Replied by kongenii on topic Problem with object
Hi Alex,

I think I am quite close now, however i still get the (#100) At least one reference object must be specified. error.

I have tested the $url, it works and when printing it is correct. When I visite the url manualy and view the source the og:type is now correct. I tried using the same object for two actions. That did work however it printet both actions on viewing a garmin which was not correct as viewing is not buying. And i could not seperate the two, so i decided to make two actions and two objects. One for viewing and one for buying. The objects are now defined as garment and outfit. Both are loaded on the same page. A parameter in the url defines what object is loaded. I checked and it works correctly. When viewing source the og:type is set to garment when viewing and outfit when buying.

Viewing a garment works correctly it is posted to facebook, however buying does not for some reason. Another odd thing is also, that i did go into the opengraphaction.php file and print out the args you mentioned. In the case where it is working, viewing it does not print anything. In the case of buying that does not work it prints an array that consists of object = URL and outfit = URL.. both urls are the same, and works fine in the browser.

What am i missing?
The topic has been locked.
Support Specialist
13 years 3 months ago #31223 by alzander
Replied by alzander on topic Problem with object
You can definitely use the same object for multiple actions. We already do that in the EasyBlog plugin, for instance. You may want to look at our checkActionAfterRoute($action) call in that function to see how we handle multiple possible actions on the same object. You basically need to look at different parameters from the URL to see if the user is actually buying or viewing and then decide when to call the triggerAction function based off that.

When viewing source the og:type is set to garment when viewing and outfit when buying.

If the URL is staying the exact same, you shouldn't change the og:type as that will confuse Facebook. The type shouldn't change for the same URL.

I hope that helps, but if not, can you post the plugin code you've created for the checkActionAfterRoute, or whatever function you're editing to trigger the action? That will help us understand better what's going on.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
13 years 3 months ago #31263 by kongenii
Replied by kongenii on topic Problem with object
Hi Alex,

I still have not solved my issue. I have gotten really far, so far i have set up two objects, as it seamed like it worked the best. When trying with one object i did get it to work however both actions were triggered when loading the same URL when infact the should be triggered at two different times on the URL.. with the items everything loads correct both url works and the right OG parameters are loaded in the header. But for some reason i get the object error. Below is the code of my plugin.


defined('_JEXEC') or die('Restricted access');

jimport('sourcecoast.articleContent');
jimport('sourcecoast.openGraphPlugin');

class plgOpenGraphDjclassifieds extends OpenGraphPlugin {
protected function init() {
$this->extensionName = "Djclassifieds";
$this->supportedComponents[] = 'com_djclassifieds';
$this->setsDefaultTags = true;

// Define all types of pages this component can create and would be 'objects'
$this->addSupportedObject("Item", "item");
$this->addSupportedObject("Swapitem", "swaps");

// Add actions that aren't passive (commenting, voting, etc).
// Things that trigger just by loading the page should not be defined here unless extra logic is required
// ie. Don't define reading an article

$this->addSupportedAction("Swap", "swap");
$this->addSupportedAction("Want", "want");
$this->addSupportedAction("View item", "View");
}

protected function findObjectType($queryVars) {
// Setup Object type for page

$view = array_key_exists('view', $queryVars) ? $queryVars : '';
$object = null;
$isswaps = 0;
$isswapid = JRequest::getVar('swap_id', '');

if($isswapid != '' && $view == 'item') {
$objectTypes = $this->getObjects('swaps');
$isswaps = 1;
} else {
$objectTypes = $this->getObjects($view);
}

if ($view == 'swaps' || $view == 'item') {
if(count($objectTypes) > 0) {
$object = $objectTypes[0];
return $object;
} else {
return NULL;
}
} else {
return NULL;
}
}

//TODO - clean up when we remove J1.5 support
protected function setOpenGraphTags() {
$desc = ''; //Note: meta is same as blank value, since system plugin attempts to generate from metadescription if no value is found
$image = '';
$view = JRequest::getVar('view');
$task = JRequest::getVar('swap_id', '');

if($this->object) {
$desc_type = $this->object->getParameter('custom_desc_type');
$desc_length = $this->object->getParameter('custom_desc_length');
$image_type = $this->object->getParameter('custom_image_type');
$image_path = $this->object->getParameter('custom_image_path');
}
else {
$desc_type = 'custom_desc_introwords';
$desc_length = '10';
$image_type = 'custom_image_item';
$image_path = '';
}

//Get Description
$itemModel = JModel::getInstance('Item', 'DjclassifiedsModel');
$item = $itemModel->getItem();

$desc = $item->intro_desc;
$this->addOpenGraphTag('description', $desc, false);

//Get image
$imageName = 'components/com_djclassifieds/images/'.str_replace(";","",$item->image_url).'.thb.jpg';

if(JFile::exists(JPATH_SITE.'/'. $imageName))
$image_path = JURI::base() . $imageName;
else
$image_path = '';

$image = $image_path;

$this->addOpenGraphTag('image', $image, false);
}

/************* DEFINED ACTIONS CALLS *******************/

protected function checkActionAfterRoute($action) {

if (JRequest::getVar('view') == 'item' && $action->system_name == 'item') {

//Get item
$theswapid = JRequest::getVar('id', 0, '', 'int');

if($theswapid != 0) {
$db = JFactory::getDBO();
$query = "SELECT i.* FROM #__djcf_items i WHERE i.id=".$theswapid;
$db->setQuery($query, 0, 1);
$theitem = $db->loadObject();
}

//Get Item URL
$url = $this->getItemURL($theitem);
$queryVars = $this->jfbcOgActionModel->getUrlVars($url);

$this->triggerAction($action, $url);
}

if ($action->system_name == 'swap') {
$theswapid = JRequest::getVar('swap_id', '');

$db = JFactory::getDBO();
$query = "SELECT i.* FROM #__djcf_items i, #__djcf_itemsask j WHERE j.swap_id = '".$theswapid."' AND i.id = j.item_id";
$db->setQuery($query, 0, 1);
$theswap = $db->loadObject();


//Get Item URL
$url = $this->getItemURL($theswap);
$url = $url.'&swap_id='.$theswapid;
$queryVars = $this->jfbcOgActionModel->getUrlVars($url);

$this->triggerAction($action, $url);
}
}

private function getItemURL($item) {
$menus = JSite::getMenu();
$menu_item = $menus->getItems('link','index.php?option=com_djclassifieds&view=items&cid=0',1);
$Itemid = $menu_item->id;
//$anch = '#dj-classifieds';

$url = '/index.php?option=com_djclassifieds&view=item&cid='.$item->cat_id.'&id='.$item->id.'&Itemid='.$Itemid.$anch;
$url = JRoute::_($url, true);
$jUri = JURI::getInstance();
$url = rtrim($jUri->toString(array('scheme', 'host', 'port')), '/') . $url;

return $url;
}
}
The topic has been locked.
Support Specialist
13 years 3 months ago #31450 by alzander
Replied by alzander on topic Problem with object
What are the URLs for your different objects? I see how you're setting 2 different object types, but just want to make sure they are different unique URLs.

As for the action triggering twice, you have the following checks:
if (JRequest::getVar('view') == 'item' && $action->system_name == 'item') {
This one will trigger every time that view=item is in your URL. You don't do any further checks to make sure that the action should trigger, though you do gather some data. So, I would expect this to trigger on every page load of your extension (with view=item at least)
if ($action->system_name == 'swap') {
This action will trigger on every page load of your extension, regardless of other query variables, because you aren't testing to see if it's a specific type of page from your component.

So, I'd actually expect you'd see both actions triggering a lot. I think you just need to filter out the actions a little more to make sure the current page is really the type of page you want the action to trigger on.

Hope that makes sense, but if not, let us know,
Alex
The topic has been locked.
Active Subscriptions:

None
13 years 3 months ago #31474 by kongenii
Replied by kongenii on topic Problem with object
Hi Alex,

The url for the two object types won't be unique.. as the both refer to a page where the item is showed.. so in that case both actions will have a url leading two /index.php/markedsplads/klaedeskabe/ad/bluser,13/vero-moda-bluse,16

The only difference I can do is to pass a parameter along when bying like /index.php/markedsplads/klaedeskabe/ad/bluser,13/vero-moda-bluse,16&buy=yes.
That parameter should then decide whether to trigger one action on another.. So far though, when i attach the two actions to the same object Garmen, they both trigger when just viewing, and nothing happens when i am buying..

If i create a new object Outfit and attach it the the action buy. It triggers at the right place and so does view. however when buying i get an error that object should be attached to the url. when i check the error url and view source i can see all tags are set correctly..

So it seams like i have to give up unless you have a brilliant idea. I have spent 5 days on this without a solution.
The topic has been locked.
Active Subscriptions:

None
13 years 3 months ago #31475 by kongenii
Replied by kongenii on topic Problem with object
I must admit, that i do not understand how your module is built up.

If I leave out this section protected function checkActionAfterRoute($action) {
Its still triggers anyway, posting stuff on my timeline that it is not supposed to, how can this be.. I thought that it was only triggering anything if the had that piece of code in your plugin and when you where calling, $this->triggerAction($action, $url); but i guess this is not the case..

I am a bit lost here.. what can i do..
The topic has been locked.
Support Specialist
13 years 3 months ago #31664 by alzander
Replied by alzander on topic Problem with object
Sorry for the delay in getting back to this.

If you're passing a different parameter, the URLs are then unique, so that should be ok as long as the Open Graph plugin is configured to make sure it recognizes the different query parameter and returns a different object from the findObjectType function.

As for the checkActionAfterRoute, that function is called on every page load. It's up to your plugin to differentiate whether the URL that is being loaded/called is the right URL to trigger the action on.

Additionally, in the "Automatic Actions" tab of the action parameters, you should set the "Action Type" to "Manual". That will mean that the user has to 'do' something for the action to trigger, like 'buying' something. If you've set it to 'automatic', that means that JFBConnect will trigger the action *always* on every page load. It does so in a separate way from using the checkActionAfterRoute function, which would likely explain why you're seeing multiple triggers. That sounds like what you're issue is.. you have that value set to 'automatic'. Please try changing that to Manual and then make sure the proper checks and triggerAction calls are in your checkActionAfterRoute function.

Hope that helps, but if not, let us know.

Thanks,
Alex
The topic has been locked.