Add category slug in post page - content-management-system

I am beginner in october cms and using rainlab blog plugin for my personal blog.
I want to display category slug in the url of blog post page, how can i achieve that?
i.e example.com/{category_slug}/{blog_post_slug}

Should just be example.com/:category?/:slug?
Unless you skip the component all together there is no way around that. The Blog component for a post is just looking for the slug: :slug. I don't think you really have to worry about people changing the category in my opinion. Your post list page should have the url example.com/category/post for its link. Why would a user change the category?
If you really care here is a way around that. Don't use the blog post component. Make your own plugin or use CMS Pages. The code will vary slightly and in this example I will use CMS Page code cause it is 'ad hoc' and quicker.
use Rainlab\Blog\Models\Post;
function onStart() {
$category = $this->param('category');
$slug = $this->param('slug');
$posts = Post::whereHas('categories', function ($query) use ($category) {
$query->where('slug', $category);
})->get();
$this['post'] = $posts->where('slug', $slug)->first();
}

Related

How can we dynamically populate quick replies of facebook messenger from a JSON object?

I really liked the Facebook quick replies feature which helps us guide the conversation with the user.
My context is I am building a form fill bot. There are a few questions a user is asked before he is redirected to the appropriate page. The questions and their options come as a JSON object.
I would like to make the question as a text message and the options as quick replies. This would greatly help the user quickly answer the few questions and get the form filled.
I am stuck at the point where I need to populate the quick replies options with the questions' options.
I am using Microsoft Bot builder framework to build the bot
Channel's specific features (such as the Quick Replies from Facebook) are supported through the ChannelData (C#) / sourceEvent (Node) fields. So you need to send the specific info through it so Facebook can understand it and react accordingly.
Here is a quick example showing how to send Facebook's Quick Replies.
var channelData = JObject.FromObject(new
{
quick_replies = new dynamic[]
{
new
{
content_type = "text",
title = "Blue",
payload = "DEFINED_PAYLOAD_FOR_PICKING_BLUE",
image_url = "https://cdn3.iconfinder.com/data/icons/developperss/PNG/Blue%20Ball.png"
},
new
{
content_type = "text",
title = "Green",
payload = "DEFINED_PAYLOAD_FOR_PICKING_GREEN",
image_url = "https://cdn3.iconfinder.com/data/icons/developperss/PNG/Green%20Ball.png"
},
new
{
content_type = "text",
title = "Red",
payload = "DEFINED_PAYLOAD_FOR_PICKING_RED",
}
}
});
reply.ChannelData = channelData;
You can also find more details about how to use new Facebook's features with BotFramework in this blog post.
Please note that in the particular case of Quick Replies, the BotFramework team is adding support to them in the library. The commit is still in the develop branch; so it's not yet public (you can still build the library and reference to that instead of the public NuGet)

How to comment on embedded facebook post on a website without leaving it

I recently made a fanpage and i have used embedded code from one of the post of my fanpage to my website.
So now It shows the post on my website and number of likes but i would like to show current existing comments which that particular post had got. Right now it is just displays the comment button and if i will click that then it will take me to the fanpage just for the sake of comment.
So heres what i need
1 - Comment on the embedded post without leaving the website to facebook.
2 - Displaying all the current existed comments ..
the image right now look like this
Thats very simple. First, you need to login user and ask for publish_stream permission. After the user is logged in, you just to display a button that triggers the function named comment, passing the ID (corresponding to the object user is going to comment to) .
You will also need an input field for inserting the comment (of course), and using jquery .value we will get the value of the input field .
PS: Specify NAME and ID on the message input field. I dont remember wich one is, put both of them .
After getting the variables, we will call FB.api, specifing the variables id and comentario than get the response for handling the result (if you want), you can try to reload the comment plugin, or refreshing the page .
function comment(id) {
var id = id;
var comentario = document.getElementById("message").value;
FB.api("/"+id+"/comments","POST",
{
"message": comentario
},
function (response) {
if (response && !response.error) {
alert('Comentado !');
} else {
alert('Erro !');
}
});
$("#atividade").html('COMENTADO');
}
That is very simple and fun, but you will need to get authorization from facebook platform to ask users for publish_stream permissions before production .
I think David's answer will just post a new comment, not show all post's comments.
Unfortunately there is not a option to show the comments on embed posts.
You need to get the post id, call a api to load all comments and so embed each one of them. Yeah, that's terrible...
Open the graph api explorer:
https://developers.facebook.com/tools/explorer/
Type {post-id}/comments on GET input and send it to see a response example.
And that's how you embed comments:
https://developers.facebook.com/docs/plugins/embedded-comments
I don't think loading all comments from all posts will have a good performance. I suggest you to create a button "see comments" which call the api. After that you can create the input text for new comments, like David said.

How to filter posts, pages, archives and others page?

I am developing a new plugin. In this plugin user can choose where the plugin will display.
If user choose only in post or archives pages then how can i find it?
if I use add_filter('the_content','function');
then my plugin will show all pages but how to do that in single category or archive page?
You can check if a specific page is being displayer with these conditonals
is_page() //For pages
is_single //for posts
is_singular //for posts AND pages
is_category //for categories
is_tag() //for tags
is_404() //for 404 page
Also, don't use anonymous functions when you add filters. always use defined functions
add_filter ('the_content','my_magic_function');
For a more complete list of template tags check visit:
http://codex.wordpress.org/Function_Reference/is_page
We use Conditional Tags:
add_filter( 'the_content', function( $content )
{
is( !is_single() )
return $content;
return '<p>This is a single post.</p>' . $content;
});
sample code requires PHP 5.3+

How to detect if is the user the fan of my page

I have a little problem, I don't know how to create the script (with PHP SDK) which check if is the user a fan of my page.
I successfly get the permission for user_likes, but I cant post data to array and after check it.
When I dump this code: $user_likes = $facebook->api('/me/likes'); I'll got all data, but I cant post them to array.
It's amazing what one can find on the internet these days if only he tries to Google his questions...
Here's the first result I got for "facebook is the user a fan":
http://www.masteringapi.com/tutorials/facebook-api-check-if-a-user-is-fan-of-a-facebook-page/20/
It discuss a few options, PHP and JavaScript, Graph API and REST API, just pick your favorite.
FB.api("me/likes/270801249647033", function(response) {
if ( response.data.length == 1 ) {
// Has liked
} else {
// Not liked
}});
Source and download script
From: http://developers.facebook.com/docs/reference/rest/pages.isFan/ (yes, this is deprecated, but it includes the new Graph API way to do things at the top of it. :) )
You can now issue a HTTP GET request to /USER_ID/likes/PAGE_ID (aka /me/likes/PAGE_ID ) to check if a user is a page of a fan.

Is there a way to insert an #mention into a Facebook status update posted with pyfacebook?

I have some code like the following in my application:
message = "Hi, #John Doe!"
postID = fb.stream.publish(
message = loader.render_to_string('wall_post.phtml', {'message':message}),
action_links = simplejson.dumps([{'text': "Check out blah", 'href': "http://blah.dev"}]),
target_id = 'nf'
)
Is there any way to represent a facebook #mention in the message string so that facebook converts it to a profile link for the mentioned user?
I've also been looking for an answer to this. The facebook website uses the format:
#[139730900025:PhotoGrabber] is awesome
to represent the links but I haven't been able to make that work. I re-posted a thread on the facebook forum under the "Stream" category since your post wasn't getting any attention:
http://forum.developers.facebook.com/viewtopic.php?id=47885
Mention it's partially available by open graph now. You can use only when posting an open graph ACTION
Check:
https://developers.facebook.com/docs/opengraph/mention_tagging/
It seems still impossible to use #mention tagging in classic feed posting via API
I'm pretty sure this is impossible at the moment. If it were posible by using the format that tam7t suggested it should work... Your best bet is asking them to add that to their api stream parser.
This is not possible at the moment, sorry.
AFAIK facebook's API does not allow this. The only approach that I know of at the moment would be to write a screen scraper to do these posts using the format described by tam7t's answer. If you use the mobile version of facebook's site (m.facebook.com) it makes it much easier.
NOTE: This might be a violation of Facebook's Application TOS.
Edit:
Here is some ruby code that will do the trick, using the Mechanize Gem
require 'mechanize'
agent = Mechanize.new
agent.user_agent_alias = 'Mac Safari'
page = agent.get('http://m.facebook.com')
form = page.forms.first
# enter credentials
form.pass = 'user password'
form.email = 'user#example.com'
page = agent.submit form
# go straight to page to post on
page = agent.get("http://m.facebook.com/wall.php?id=PAGE_ID_NUM")
form = page.forms.first
form.message = "#[139730900025:PhotoGrabber] is awesome"
page = agent.submit form
NOTE: Obviously (as tiagoboldt kindly pointed out) it would be wrong to store / utilise the credentials of other people in your application. This approach would only be appropriate for making posts from a facebook account that you controlled.
That said, back to the original question of putting an #mention in a wall post, I have noticed that whilst the post and #mention go up on the wall fine, this method does not propagate the post to the mentioned user/page's wall. Not sure if that is important to you.