Syndicate

Feed

Adding 'Last edited by name some time ago' information

Administrators are presented with a special marker when content is new or has been updated in the Administration section of their site at webSite.com/admin/content/node. Additionally, in node lists, the module tracker informs any logged-in user if he or she hasn't read a particular (recently created) node (using the marker new), or if a node he/she's read already was modified (using the marker updated). You, the themer, may want everyone, including “anonymous users”, to be informed of updates to nodes right inside their content. This information may specify who last edited the node and when. Note that the last editor of a content may not be the creator of that content, and I'll take this into account in my “solution”. In the following theming tweak, you'll add Last edited by name some time ago information to your nodes' content.

Here is what you'll try to achieve:

Last edited by name some time ago.

Solution

  1. Edit the file template.php to pass an additional variable to the node template, a variable we'll call $last_edit...

  2. print that variable in our node.tpl.php file, and...

  3. style this added markup as needed in style.css.

Before you apply this solution to your theme, we will review how Drupal deals with node editing and node revisions. Read carefully.

When a node is simply edited, with no new revision created

If the editor of the node doesn't edit the Authored by field under Authoring information, the recorded author of the node remains unchanged. What that means is that the variables $name and $uid in node.tpl.php will output the same HTML. However, if the editor is not the person who authored the node, the revision_uid (user ID) of the current revision does change to show who edited the node. In node.tpl.php, the variable $revision_uid always tells us who was the last person to edit the current version of a node.

If the editor changes the Authored by field under Authoring information, the variables $name and $uid in node.tpl.php will change to reflect whatever user the editor has picked as new author. However, still in node.tpl.php, the variable $revision_uid will provide us with the user ID of the editor.

No one with permission to edit a node can effectively edit it without a record of his action being saved to the Drupal database, a record of his action under his name. The info about any node version in the table {node_revision} will tell us when and by whom that version was last edited.

When a new revision of a node is created

What has been said previously still applies. If the Authored by field isn't edited, the author of the new revision and the author of the old revision will be the same person, regardless of who created the new revision. The variable $revision_uid will provide us with the user ID of the creator of the new revision.

If the editor changes the Authored by field under Authoring information when creating a new revision, the info about the author of the node will reflect that change.

Variables available to node.tpl.php — that you will use

What follows is a partial list of the variables available to node.tpl.php.

Available variables:
* - $page: Flag for the full page state.
* - $name: Themed username of node author output from theme_username().
* - $uid: User ID of the node author.
* - $vid: Current version ID of the node, e.g. the version to output.
* - $revision_uid: User ID of the last editor of the node version with $vid.
* - $created: Time the node was published formatted in Unix timestamp.
* - $changed: Time the node was last edited formatted in Unix timestamp.

For a given revision row in the {node_revisions} table of your Drupal database, the variable $revision_uid corresponds to the uid column. Whereas the $uid variable is read from the uid column in the table {node}.

You can find an exhaustive list of the variables available to node.tpl.php if you inspect a node's content using the Themer Info widget that comes with the Devel module. Look under Template Variables:

Complete list of variables available in node.tpl.php

Passing a new variable to print in the node template

You will use a prepocess function to pass a new, e.g. additional, variable to your node template, ie: $last_edit. Hence, you will need to add a phptemplate_preprocess_node() function if it has not already been defined to your template.php file. Open your theme template.php file in a text editor, and add the following code (please do read the comments):

/**
* Override or insert PHPTemplate variables into the node template.
*/
function phptemplate_preprocess_node(&$vars) {
  /*
   * If the node is shown on its dedicated page and
   * the node was edited after its creation. 
   */
  if ($vars['page'] && $vars['created'] != $vars['changed']) {
    $time_ago = format_interval(time() - $vars['changed'], 1);
    /* 
     * If the last person who edited the node 
     * is NOT the author who created the node.
     */
    if ($vars['uid'] != $vars['revision_uid']) {
      // Let's get the THEMED name of the last editor.
      $user = user_load(array('uid' => $vars['revision_uid']));
      $edited_by = theme('username', $user);
    }
    /* 
     * If the last person who edited the node 
     * is also the author who created the node,
     * we already have the THEMED name of that person.
     */
    else {
      $edited_by = $vars['name'];
    }
    /* Adding the variable. */
    $vars['last_edit'] = t('Last edited by !name about @time ago.', 
      array('!name' => $edited_by, '@time' => $time_ago));
  }
 
}

After that, you edit your node.tpl.php file to print your new variable. Take note that the variable will be undefined if we're on a node list page, or if the node wasn't edited since its creation. So we won't add a div unless our variable is defined.

<?php if ($last_edit): ?>  
  <div class="last-edit clear-block">
    <small><?php print $last_edit; ?></small>
  </div>
<?php endif; ?>

A bit of styling

You can pick a special color for that added text, and increase the white space above and below it, with this CSS rule, added to the style.css stylesheet of your theme:

/**
 * Last edit rules
 */
 
.last-edit {
  color: #ca481c;
  margin: 1em 0pt; 
}

Because it makes use of a preprocess function, this solution will work in Drupal 6 only. There's an equivalent method for Drupal 5 themes, and if someone asks for it I will provide it.

A few questions and their answer

Question 1. Why use the function theme('username', ...)? Why aren't we just outputing the name of the editor as is?

You could. When using the function theme('username', $user), the name of the user becomes a link to his profile page under certain conditions. It's very likely you may not like that. If you don't, just output the name like so (this is a snippet only):

/* 
 * If the last person who edited the node 
 * is NOT the author who created the node.
 */
if ($vars['uid'] != $vars['revision_uid']) {
  $user = user_load(array('uid' => $vars['revision_uid']));
}
/* 
 * If the last person who edited the node 
 * is also the author who created the node,
 * we already have the THEMED name of that person.
 */
else {
  $user = user_load(array('uid' => $vars['uid'])); 
}
 
/* Reading the name property of the user object */
$edited_by = $user->name;
 
/* Adding the variable. */
$vars['last_edit'] = t('Last edited by @name about @time ago.', 
  array('@name' => $edited_by, '@time' => $time_ago));

Note that I am using @name instead of !name in the translation function now. That's because I want the user name to be escaped properly and sanitized before being output to screen. Always do this for user names. The ! prefix used for a placeholder means that the variable it stands for should be used as is.

Question 2. Are variables publicized as being available in a template are the same ones we can read in the parameter $vars passed to a preprocess function, right?

Riiight.

Question 3. Some of these variables we're using don't seem to be listed at the beginning of the file modules/node/node.tpl.php...

True. They are missing from the comment area, because they are less commonly used. That's why the Devel module is tremendously useful to themers in Drupal 6: as a themer, you can use the Themer info widget to get an exhaustive list of the available variables for any template.

Question 4. You say that the variable $last_edit is undefined if we're on a page with a list of nodes, or if the node wasn't edited after its creation. Why is that?

Because of this condition in the preprocess function:

if ($vars['page'] && $vars['created'] != $vars['changed']) {

We are defining the new variable only when we pass through this condition.

$vars['page'] becomes $page in the node template and it's a TRUE/FALSE flag. It is TRUE when the node is shown on its dedicated page at webSite.com/node/x, and FALSE otherwise. You could change this to say if we're not showing the node in teaser view, and in most cases this would have the same effect, but take note that it is possible to show a list of nodes in full view, with the module Views for example.

Changing $vars['page'] to !$vars['teaser'] — and changing the != sign to a 'greater than' sign — will give your script the same behavior in most situations:

if (!$vars['teaser'] && $vars['created'] < $vars['changed']) {
Last edited by Caroline Schnapp about 13 years ago.

Comments

Corals at Keppel Bay

366 units in one of the rare true waterfront living condominiums in Singapore, ie Corals at Keppel Bay. Visit www.keppelbay-corals.com for more details.

This information may specify

This information may specify who last edited the node and when. Note that the last editor of a content may not be the creator of that content. http://www.youtube.com/watch?v=rMJn9Uiml_8

The condo’s facilities

The condo’s facilities provide full family entertainment needs for your family and loved ones. Indulge in a serene and tranquil lifestyle right in the heart of Punggol. http://www.youtube.com/watch?v=rMJn9Uiml_8

hai

good.. Thanks you, this is one of the most interesting blogs that I have ever seen. Interesting article, Funny comment. Keep it up!

Jewel at Buangkok will be

Jewel at Buangkok will be accessible via Buangkok MRT Station, which is just next to it. Commuting to the city area as well as the Serangoon area is therefore very convenient.

well done

future residents of lush acres ec will be able to walk to seletar mall and fernvale point in just 5 mins.

Skypark Residences is a

Skypark Residences is a 99-years leasehold Sembawang EC development located at Sembawang Crescent / Sembawang Drive in District 26. With expected completion in mid 2016, it comprises of 9 towers with 502 units and stands 15 storeys tall. It is a short walk away from Sembawang MRT Station.
Sky Park Residences

Understanding Rapid Methods In Guaranteed Car Loan

Insights Into Uncomplicated Guaranteed Car Finance Advice

http://gtdcarfinance.co.uk/ - Guaranteed car loans

Examining Significant Aspects Of Guaranteed Car Loan

http://gtdcarfinance.co.uk/

Sensible Plans Of Guaranteed Car Finance - A Closer Look

Speedy Products In Guaranteed Car Finance Explained

http://gtdcarfinance.co.uk/ - Guaranteed car loans

An Analysis Of Speedy Systems Of Guaranteed Car Loan

http://gtdcarfinance.co.uk/

The Doctor showcase her

The Doctor showcase her archives though she she felt a little bit nervous but still she delivered her discussion well. I learned a lot from her experience.

Poor Credit Car Loan Programs - For Adults

You could end up making payments for 25 years without ever actually paying one cent from the principal. One will not fall short if applied for this loan. You will quickly realize tourist from all the continents visiting this country. A good car lease on credit consultant must also manage to clarify the comparison fee (if applicable) of your respective respective recommended auto car lease on credit along using the whole cost of the respective car lease on credit package deal, including any hidden charges or costs. If you possess an imperfect credit rating, submitting the application form to wrong lender may result in rejection.

When looking for car loan and you are trying to determine an IFA opt for one who has a good reputation. How would you're making certain in that will find an inexpensive car finance deal to save cash. A cosigner can also be totally knowledgeable about the monetary incapability from the borrower and still go ahead with the deal. A bank may also give you a realistic base for thinking about what kind of interest rate you'll have to cover for your auto loan. This could only signify if you fail to spend your timely repayments, financing companies and banks hold the rights to adopt back the vehicle you loaned for anytime.

A Background In Quick Methods In Poor Credit Car Finance

http://badcredcarfinance.co.uk/ - poor credit car finance

Inside No-Fuss Bad Credit Car Loan Programs

http://badcredcarfinance.co.uk/

Several buses are available

Several buses are available near The Inflora Condo along with shopping centers and restaurants. The Inflora Condo is also near to Tanah Merah Golf & Country Club and Safra Golf & Country Club. Inflora condo

For vehicle owners, Sky Vue

For vehicle owners, Sky Vue Condo takes less than 15 minutes to drive to the business hub and vibrant Orchard Road shopping district, via Central Expressway (CTE). Skyvue

Sengkang West Way Condo is a

Sengkang West Way Condo is a 99-years leasehold private condominium development located atSengkang West Way / Fernvale Link in District 19. With expected completion in mid 2017, it comprises of TBA towers with estimated 590 units and stands TBA storeys tall. Sengkang West Way Condo

I genuinely enjoyed reading

I genuinely enjoyed reading it, you're a great author.The great information is here. I love such post bcz we can get a few useful information from this particular blog. I be expecting more post from you.
MCI Screening test after MBBS
MCI Screening test

I wish to show my thanks to

I wish to show my thanks to the writer for bailing me out of this instance. Just after surfing around through your site and coming across opinions which were pleasant.

Online Supplement

Does ones creating imagination influenced everyone, and today My partner and i produce the blog. The genuine web site will be distributing their wings rapidly. Online Supplement Is a great case. Thank you all over again for your totally free dialogue in this look about the multilevel.

Boardwalk Residences in Sengkang Fernvale Close

Boardwalk Residences will be accessible with Layar LRT Station as well as Sengkang Bus Interchange. It is also right beside Tampines Expressway(TPE). Boardwalk Residences is also near to Greenwich V and the Upcoming Seletar Mall. sengkang boardwalk residences

Boardwalk Residences in Sengkang Fernvale Close

For vehicle owners, it takes less than 30 minutes to drive to the business hub and vibrant Orchard Road shopping district, via Tampines Expressway (TPE), Central Expressway (CTE) and Kallang-Paya Lebar Expressway (KPE). Boardwalk

incubator

Feed wastage is virtually eliminated and a good feed conversion ratio is achieved due to innovative design of feeder 2001. chicken drinkersIt has a capacity to hold approximately 7. 5 kg of feed which helps in reducing labour and saves on time.

supplier

Breakers are usually arranged in two columns. In a US-style board, breaker positions are numbered left-to-right, along each rownon sparking tools supplier from top to bottom. This numbering system is universal across various competing manufacturers of breaker panels.

transplant surgeon

At KIMS advanced Hair transplant Hyderabad, we understand the importance of a proper hair transplantation. Each baldness case is best hair transplant surgeon in Hyderabadtreated uniquely, since baldness patterns are not the same for any two individuals.

incubator

Feed wastage is virtually eliminated and a good feed conversion ratio is achieved due to innovative design of feeder 2001. It has a capacity to hold approximately 7. 5 kg of feed which helps in reducing labour and saves on time. chicken incubator

Still useful.

This post might be old, but your tips are still useful for us.
This snippet ist really helpful for readers to see if a post ist still up to date and worth spensing time to read.
Kind regards.

Pet Grooming Centres in Singapore

Humans and dogs have natural connections that make it a happy relationship. The dog culture and the human culture are very different from each other but through puppy training we can teach your culture to them. 4 Puppy Training Techniques

usefull information

Wow amazing, Nice content I found so many interesting stuff in your blog especially its discussion Thanks to sharing thanks!

bollywood film news

I genuinely enjoyed reading it, you're a great author.The great information is here. I love such post bcz we can get a few useful information from this particular blog. I be expecting more post from you.

It was recently confirmed

It was recently confirmed that Pawan Kalyan will be playing Lord Krishna in Venkatesh’s Oh My God remake which will be produced by Bellamkonda Suresh and Pawan’s close buddy Sharath Marar. Pawan’s entry to OMG has…
Latest tollywood news online
Latest tollywood news updates
Regional news

Lakeville is a new and

Lakeville is a new and upcoming condominium located in Boon Lay Way, Jurong East area. It is located right beside JCube, and the upcoming Westgate and Jem. With expected completion in mid 2016, it comprises of 4 towers with TBA units and stands TBA storeys tall. new executive condo

Highline Residences is also

Highline Residences is also near elite schools such as Zhangde Primary School and Henderson Secondary School. Gan Eng Seng Secondary School as well as Alexandra Primary School are also around in the area. highlineresidence.net

Different promotion for Baahubali on ValentineDay : Rajmouli

Different promotion for Baahubali on ValentineDay : Rajmouli
South Indian most well-known movie director SS.Rajamouli is very active in the capturing of his upcoming film Baahubali starrer Prabhas, Anushka and Rana in the cause tasks

Rajamouli not leaving a single chance to promote his movie .First he comes up with first look feelers on the birthdays of star cast , later he adopted technique of light hearted videos which goes well among movie buffs
Latest tollywood news
Latest tollywood news online
Latest tollywood news updates
Regional news

Preity Zinta to contest elections against Priya Dutt?

She has never confessed to harbouring political ambitions and we are kind of amused at the prospect of Preity Zinta contesting the electionson a BJP ticket. Buzz is, the party is on the…
Latest bollywood entertainment news
Latest bollywood news

First tremors of Big Bang detected

Scientists have heralded a “whole new era” in physics with the detection of “primordial gravitational waves” — the first tremors of the big bang. The minuscule ripples in space-time are…
Science technology news