By Christopher Ambler on Friday, 13 November 2020
Replies 17
Likes 0
Views 1.7K
Votes 0
It seems if I have autoposting to Facebook turned on, all posts go to the same pages and/or groups I specify in the autoposting configuration.

I run multiple Facebook pages and groups, though, and my blog has many categories. Each category is appropriate to a different Facebook group.

Would it be possible to have an override for categories such that one could pick the page and/or group to autopost to based on the category of the post?

I could code this myself, of course, as your code to do the posting is pretty clear, but it would totally be a core code change and, thus, overwritten every time you update.
Do you mean that you would like to autopost to the specific Facebook page or group base on the specific category?

If yes, currently it is not possible, it required to modify the core code.
·
Friday, 13 November 2020 13:16
·
0 Likes
·
0 Votes
·
0 Comments
·
Okay, well, count this as a voice for such a feature

Now, in the meantime, it seems to me that I can do this myself, perhaps. If I create a plugin that responds to onAfterEasyBlogSave and calls into the autopost code, perhaps I can do this.

Looking at the path things take, the group chosen to receive the autopost is determined with this line in includes/oauth/adapters/facebook/client.php:

$groups = $this->config->get('integrations_facebook_group_id');


So... if, in my plugin, I grab this value, set a NEW value, call into the autopost code, and then put the original value back, I might just have hacked a solution ... I'll just have to create a mapping of category to group for the plugin to use.

I might just do this
·
Saturday, 14 November 2020 04:00
·
0 Likes
·
0 Votes
·
0 Comments
·
Of course, making this a FEATURE would be easier.

Put a field in the category for the group, and modify the code, above, in client.php to say, "If the category has a group, use that one. If not, use the one as already coded."

I could code that up in a couple hours (most of it is putting in the new field in the DB table for category and the editor field in the administrator interface).

But that's a change to core code, and I like updates

(NOTE: this could be done just for groups, or more realistically, for pages and groups. Just two config fields. And they're exactly the same as the ones in the autopost config, so that code already exists)
·
Saturday, 14 November 2020 04:03
·
0 Likes
·
0 Votes
·
0 Comments
·
Thanks for your input, currently we did not plan to add this yet because not many users request this feature before.

I would suggest you request this feature on our voice page here https://stackideas.com/voices/easyblog so our developer will usually prioritize features that are in popular demand during the development process of the next major release.
·
Monday, 16 November 2020 13:04
·
0 Likes
·
0 Votes
·
0 Comments
·
+1
·
Monday, 07 December 2020 20:46
·
0 Likes
·
0 Votes
·
0 Comments
·
+1
·
Monday, 07 December 2020 21:02
·
0 Likes
·
0 Votes
·
0 Comments
·
You guys should add a vote from his feature request post instead of this thread.
·
Wednesday, 09 December 2020 10:09
·
0 Likes
·
0 Votes
·
0 Comments
·
If you +1 here, PLEASE go upvote:

https://stackideas.com/voices/easyblog/item/375-specify-facebook-page-group-on-a-categor

StackIdeas won't consider this if there isn't demand. I was able to do it, myself, in about 4 hours of coding, but it modifies core code, of course, so I'd MUCH rather see this a feature!
·
Saturday, 26 December 2020 09:11
·
0 Likes
·
0 Votes
·
0 Comments
·
Christopher good idea and if you consider to share your code to Stackideas It maybe go faster too
·
Saturday, 26 December 2020 17:59
·
0 Likes
·
0 Votes
·
0 Comments
·
Here is my code. I tried to limit it to the share() function and didn't want to modify existing tables, so I created a new table.

I didn't do any UI. If StackIdeas wants to take this, adding the UI in the category view should be trivial and to their style.

If StackIdeas doesn't take this, I'm going to make a plugin that does it outside of core code. But it sure would be great to have this in core code.

LOGIC: If there's an override here in the table, use it. If not, use the global in the autopost configuration. If an override is used, there's an option to include the default as well. Simple as that!

CREATE TABLE `chip_easyblog_facebookcat` (
`id` bigint(20) NOT NULL,
`category` bigint(20) NOT NULL,
`pages` varchar(2048) DEFAULT NULL,
`groups` varchar(2048) DEFAULT NULL,
`include_default_pages` tinyint(4) NOT NULL DEFAULT '0',
`include_default_groups` tinyint(4) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Code:


/**
* Shares the post to facebook, either personal timeline, page(s) and/or group(s)
*
* @param EasyBlogPost $post
* @param EasyBlogTableOAuth $oauth
* @param bool $system
* @param false $reposting
*
* @return bool
*
* @since 5.0
*
* NOTES:
*
* parent::api changed to $this->api as this class derives from the parent without overriding api()
* order of execution changed to note if post goes to a group or page, and if not, then goes to user's timeline
*/
public function share(EasyBlogPost $post, EasyBlogTableOAuth $oauth, $system = true, $reposting = false): bool
{
echo "share called<br />";
$oa = EB::oauth();

if (!$oa) {
return false;
}

// Get the post data

$data = $this->extractPostData($post);
$state = false;

// Construct the params that should be sent to facebook

$params = array(
'link' => $data->url,
'access_token' => $this->token
);

$isNew = $post->isNew();

$do_fb_intro = $this->config->get('integrations_facebook_introtext_message');
$do_fb_group = $this->config->get('integrations_facebook_impersonate_group');
$do_fb_page = $this->config->get('integrations_facebook_impersonate_page');

// If we have content and we want to use it for the Facebook message, set the parameter accordingly

if ($do_fb_intro && $data->content) {
$params['message'] = $data->content;
}

// if detected that this is a post update, we need to send a POST request to the Facebook crawler for
// a re-scrape in order to get the latest post content during autopost.

if (!$isNew || $reposting) {

$scrapeObj = array(
'id' => $data->url,
'access_token' => $this->token,
'scrape' => true
);

$this->api('/', 'POST', $scrapeObj);
}

$hasPostedToGroupOrPage = false;

// See if we want to post this to a particular set of facebook page(s) and/or group(s) based on the
// primary category

$db = \Joomla\CMS\Factory::getDbo();

$groupsOverride = null;

if ($db) {

$inCats = "(" . implode(",", $post->categories) . ")";

$query = 'SELECT ' . $db->quoteName('groups') . ',' . $db->quoteName('include_default_groups');
$query .= ' FROM ' . $db->quoteName('#__easyblog_facebookcat');
$query .= ' WHERE ' . $db->quoteName('category') . ' IN ' . $inCats;

$db->setQuery($query);

$groupsOverride = $db->loadObjectList();

if (!empty($groupsOverride)) {

$do_fb_group = true;
}
}

// Determines if we should auto post to facebook group(s)

if ($do_fb_group && $system) {

if (empty($groupsOverride)) {

$groups = explode(',', $this->config->get('integrations_facebook_group_id'));

} else {

$includeDefault = false;

foreach ($groupsOverride as $p) {
if ($p->include_default_groups) {
$includeDefault = true;
}
}

if ($includeDefault) {

$groups = explode(',', $this->config->get('integrations_facebook_group_id'));

} else {

$groups = array();
}

foreach ($groupsOverride as $g) {

$addGroups = explode(',', $g->groups);

foreach ($addGroups as $a) {
$groups[] = $a;
}
}
}

// Get a list of groups the user can access

$groupAccess = $this->api('/me/groups', 'GET', array('access_token' => $this->token, 'limit' => 500));

// Now we need to find the access for the particular group(s) that they want to share

if (isset($groupAccess['data']) && $groupAccess) {

// We need to ensure that the user really has access to the group

foreach ($groups as $group) {

foreach ($groupAccess['data'] as $access) {

if ($access['id'] == $group) {

$hasPostedToGroupOrPage = true;

$response = $this->api('/' . $group . '/feed', 'post', $params);

$state = isset($response['id']);

$oa->log($oauth, $post, $state, $response);
}
}
}
}
}

// Determines if we should auto post to facebook page(s)

$pagesOverride = null;

if ($db) {

$inCats = "(" . implode(",", $post->categories) . ")";

$query = 'SELECT ' . $db->quoteName('pages') . ',' . $db->quoteName('include_default_pages');
$query .= ' FROM ' . $db->quoteName('#__easyblog_facebookcat');
$query .= ' WHERE ' . $db->quoteName('category') . ' IN ' . $inCats;

$db->setQuery($query);

$pagesOverride = $db->loadObjectList();

if (!empty($pagesOverride)) {

$do_fb_page = true;
}
}

if ($do_fb_page && $system) {

if (empty($pagesOverride)) {

$pages = explode(',', $this->config->get('integrations_facebook_page_id'));

} else {

$includeDefault = false;

foreach ($pagesOverride as $p) {
if ($p->include_default_pages) {
$includeDefault = true;
}
}

if ($includeDefault) {

$pages = explode(',', $this->config->get('integrations_facebook_page_id'));

} else {

$pages = array();
}

foreach ($pagesOverride as $p) {

$addPages = explode(',', $p->pages);

foreach ($addPages as $a) {
$pages[] = $a;
}
}
}

// Get a list of pages the user can access

$pageAccess = $this->api('/me/accounts', array('access_token' => $this->token, 'limit' => 500));

foreach ($pages as $page) {

if (isset($pageAccess['data'])) {

foreach ($pageAccess['data'] as $access) {

if ($access['id'] == $page) {

// We need to set the access now to the page's access

$params['access_token'] = $access['access_token'];

$hasPostedToGroupOrPage = true;

$response = $this->api('/' . $page . '/feed', 'post', $params);

$state = isset($response['id']);

$oa->log($oauth, $post, $state, $response);
}
}
}
}
}

// If this is not a system auto posting or it wasn't posted to a group or page,
// post it to the user's own timeline

if (!$hasPostedToGroupOrPage || !$system) {

$response = $this->api('/me/feed', 'post', $params);
$state = isset($response['id']);
$oa->log($oauth, $post, $state, $response);
}

return $state;
}
·
Thursday, 31 December 2020 08:13
·
0 Likes
·
0 Votes
·
0 Comments
·
wow iwant this!

too advanced for me but I may try to offer Chris money after I move hosts to set it up.

Chris will it mess with updates or anything?
·
Monday, 04 January 2021 14:07
·
0 Likes
·
0 Votes
·
0 Comments
·
My code, above, would not be something you'd want to use as it would be overwritten with updates. I provided it as a way to give StackIdeas a view of how I've solved the issue. It also needs UI, obviously.

Now, if they don't want to implement it, I could make it a plugin. I'd hook on a post and then do the sharing work in the plugin, and I'd have to write my own UI for it, of course.

I could likely do it in a few days if I had to.
·
Tuesday, 05 January 2021 02:38
·
0 Likes
·
0 Votes
·
0 Comments
·
WOW I am impressed
·
Tuesday, 05 January 2021 06:48
·
0 Likes
·
0 Votes
·
0 Comments
·
There had been a note that this feature was going to be added. It's been about half a year now.

Any progress?

I hate having to re-patch every time I upgrade
·
Saturday, 21 August 2021 07:43
·
0 Likes
·
0 Votes
·
0 Comments
·
I can't expose any feature we add in the next major Easyblog version but it will be pretty soon Do check on our blog regularly!
·
Saturday, 21 August 2021 09:41
·
0 Likes
·
0 Votes
·
0 Comments
·
·
Saturday, 21 August 2021 11:41
·
0 Likes
·
0 Votes
·
0 Comments
·
There had been a note that this feature was going to be added. It's been about half a year now.

Any progress?

Have a look on Perfect Publisher pro from extly:
https://www.extly.com/perfect-publisher.html
with this tool you can define different automation profiles with rules for EB categories.
·
Saturday, 21 August 2021 17:40
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post