How do I get a user's profile path in Drupal? - php

How do I get a user's profile path in Drupal based on the author of the current node?
<?php print t('Posted on !date by !username', array('!username' => theme('username', $node), '!date' => format_date($node->created,'custom','m.d.y'))); ?>
The above gets me the right url, but that's all i want... the url.

$link = drupal_get_path_alias('user/' . $node->uid);
At least I think that's the most direct. I'm sure there's a more correct answer though.

Related

Moodle Course ID always equals to 1

I am trying to get a Moodle Course ID in a php script shown below.
I have tested it in different courses and different accounts and it always gives me the ID of 1. Why is that and how to get the correct ID?
<?php
require('./config.php');
global $PAGE;
echo $PAGE->course->id;
?>
Moodle only knows which course your page is meant to be part of if you tell it (you could have arrived on your page by following a link from any course on the site). When you create a link to your page you need to include a parameter of some kind that will tell your page what course it should be considered part of, e.g. $url = new moodle_url('/blocks/myblock/mypage.php', ['id' => $PAGE->course->id]); echo html_writer($url, 'Look at my page');
Then, once you follow the link, gather the param using required_param() and use require_login() to set up the page. E.g
$courseid = required_param('id', PARAM_INT);
$course = $DB->get_record('course', ['id' => $courseid], '*', MUST_EXIST);
require_login($course);
After that, $PAGE->course will be configured.

Wordpress - Get User's image ID from Pods field

I am currently working with the Pods plugin.
I extended the user pod and I added a corporate image field.
On the administration everything is fine, I can change the image of each user.
AND :
My problem is that I can not display this image on a front office page..
If i do this : var_dump($pod->field('image_societe'));
It return false, while the field name is correct, and for plain text fields, it works.
But i can do this :
var_dump($pod->fields('image_societe'));
This will return me full of information, but I do not have access to the id of the image, it is not present in the information.
I would like to finally be able to do this:
the_attachment_link( 11923 );
Where 11923 is the image's ID.
To be dynamic according to the user, the documentation says that it must be done like this:
the_attachment_link($pod->field('image_societe.ID'));
But as pods return me false, it does not work.
Does someone have an idea ?
Thank you !
Usually you can get the image url by querying $pod->field('image_societe.guid'). E.g. :
$items = pods('your_pod', array("limit" => -1));
while($items->fetch()) {
echo $items->field('image_societe.guid');
}
If $pod->field('image_societe'); doesn't return anything, then something might be wrong with your pod query, or caching kicking in. So more code would be needed to review this.

Buddypress overriding author url

I am getting author's url on Wordpress from outside the loop using this:
<?php
get_author_posts_url( $author_id, $author_nicename );
?>
Which works fine by delivering the author URL in this format -
mysitename.com/author/john-james.
However when Buddypress is enabled, this same URL changes to
mysitename.com/members/john-james
Is there a way to prevent this from happening?
get_author_posts_url() calls $wp_rewrite->get_author_permastruct() which by default returns:
$this->author_structure = $this->front . $this->author_base . '/%author%';
The WP_Rewrite class has this filter which may let you change the values:
apply_filters( 'author_rewrite_rules', array $author_rewrite )
All this is info is from the WP Codex.
I eventually have to use this code - <?php echo get_site_url(); ?>/author/<?php echo($user_name); ?> where $user_name = $user_info->user_nicename;
This also gets me - mysitename.com/author/john-james
There may be other ways, but this allows me to use the two URLs together for different purposes, one to check the author's profile (through buddypress) and the other to view all author's articles.

Getting the URL of a node in Drupal 7

Goal: To send an email with a list of URLs generated from nodes.
In my custom module I have managed to get the node id which the user wants and I now want to get the URL of each node to put into my email.
I searched the db and used google but I can't seem to find the right solution.
It seems we need to construct the URL something like this:
<?php
global $base_url;
$link=$base_url."// few more parameters
You can use the url() function:
$options = array('absolute' => TRUE);
$nid = 1; // Node ID
$url = url('node/' . $nid, $options);
That will give you the absolute path (i.e. with http://example.com/ in front of it), with the URL aliased path to the node page.
You can also try drupal_lookup_path('alias',"node/".$node->nid).
Also you can get it by
$path=drupal_get_path_alias('node/'.$nid);
absolute path for nid
url('node/' . $node->id(), ["absolute" => TRUE]);
You can also use the l() function.
l(t('Link text'), 'node/123', array('options' => array('absolute' => TRUE)));
use
$node_url;
it will give you the current node url

Facebook; posting a link to a fanpage

I have a web application that allows a user to publish a small blurb when one of their articles goes live on their site. Right now I am able to post to the user's wall using a session_key I saved in a table but I can't publish the same link on a fan page (I have the rights and IDs of the pages I need).
Essentially I want the functionality of: http://wiki.developers.facebook.com/index.php/Links.post but for a page instead. So far all I can find utilizes the steam.publish function which isn't quite the same thing.
I'm hoping that there's a hidden parameter (like a target_id) in the link.post function that I've missed (since the facebook wiki is horrible).
Any help is appreciated :) If there isn't a function maybe someone could help me use the parameters of stream.publish to have the content of a post look the same?
Well I couldn't find a way to use the link_post() function to post to a fanpage so I decided to shape the stream.publish result in a way that it would look the same. I had to do a lot of dancing around the variables to get the same effect but it worked. In this case I had to grab the "description" metatag, the first image in the page's content, and the page's title.
I hope this can help someone out:
$title = 'Title of the article, or the title of your webpage';
$message = 'Caption that will go with the link, from the user';
$description = 'I put what would have been in the description metatag, which is what the post link seems to grab';
$fb_thumbnail = ''; // a link to the first image in your article
$target_id = 'XXXXXX'; // the id of the fan page you want to post to
$attachment = array( 'name' => $title,
'href' => 'http://'.$url,
'description' => $description,
'media' => array(array('type' => 'image',
'src' => $fb_thumbnail,
'href' => 'http://'.$url))); // I would get an error with the HREF but that's because I wasn't including the "http://" bit in the link
$attachment = json_encode($attachment);
$facebook->api_client->stream_publish($message, $attachment,"",$target_id);

Categories