summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.txt7
-rw-r--r--achievement-notification.tpl.php16
-rw-r--r--achievement.tpl.php19
-rw-r--r--achievements.module47
-rw-r--r--achievements.pages.inc2
5 files changed, 63 insertions, 28 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index f750637..c013086 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -4,6 +4,12 @@ Achievements 7.x-1.4, 2011-XX-XX
* (todo) Write up a "Getting started" part of the README?
* (todo) Add some links for good achievement design?
+ * Most .tpl.php $variables are now render arrays instead of strings.
+ * This allows for easier modifications in preprocess hooks.
+ * You WILL need to modify any overridden themes to support this.
+ * You should be able to just replace "print $a" with "print render($a)";
+ * "image_path" added to achievement themes for the context-aware image path.
+ * "achievement_title" added to achievement themes for easier link display.
* Fixed double-encoding bug in titles of achievements/leaderboard/$AID.
* achievements_locked() added for programmatic taking away of an unlock.
* achievements_storage_del() added to complement the _set and _get ones.
@@ -11,7 +17,6 @@ Achievements 7.x-1.4, 2011-XX-XX
* #theme => 'achievement' usage has gained contextual theme suggestions.
* Admins can no longer take away an achievement the user hasn't unlocked.
* An empty relative leaderboard table is no longer displayed in the HTML.
- * "image_raw" added to achievement themes for the context-aware image path.
* "achievement-leaderboard-top-rank" CSS class added to top 3 rank rows.
* "achievement-leaderboard-top-rank-[123]" CSS class added to top 3 rank rows.
* theme_achievements_group_wrapper() added (wraps around user/#/achievements).
diff --git a/achievement-notification.tpl.php b/achievement-notification.tpl.php
index 5809e3c..4b8bdbd 100644
--- a/achievement-notification.tpl.php
+++ b/achievement-notification.tpl.php
@@ -7,26 +7,28 @@
* Available variables:
* - $achievement: The achievement being displayed, as an array.
* - $unlock: An array of unlocked 'rank' and 'timestamp', if applicable.
- * - $unlocked_date: A formatted date of the user's unlock timestamp.
- * - $unlocked_rank: A formatted string of the user's unlock ranking.
- * - $image: The achievement's image (default or otherwise), linked.
- * - $image_raw: The raw path to the context-aware achievement image.
+ * - $unlocked_date: A renderable string of the user's unlock timestamp.
+ * - $unlocked_rank: A renderable string of the user's unlock ranking.
+ * - $image: The renderable achievement's linked image (default or otherwise).
+ * - $image_path: The raw path to the context-aware achievement image.
* - $achievement_url: Direct URL of the current achievement.
+ * - $achievement_title: The renderable and linked achievement title.
+ * - $state: The 'unlocked', 'locked', or 'hidden' achievement state.
* - $classes: String of classes for this achievement.
*/
?>
<div class="<?php print $classes; ?>">
- <div class="achievement-image"><?php print $image; ?></div>
+ <div class="achievement-image"><?php print render($image); ?></div>
<div class="achievement-points-box">
<div class="achievement-points"><?php print $achievement['points']; ?></div>
<div class="achievement-unlocked-stats">
- <div class="achievement-unlocked-rank"><?php print $unlocked_rank; ?></div>
+ <div class="achievement-unlocked-rank"><?php print render($unlocked_rank); ?></div>
</div>
</div>
<div class="achievement-body">
<div class="achievement-header">Achievement Unlocked</div>
- <div class="achievement-title"><a href="<?php print $achievement_url; ?>"><?php print $achievement['title']; ?></a></div>
+ <div class="achievement-title"><?php print render($achievement_title); ?></div>
</div>
</div>
diff --git a/achievement.tpl.php b/achievement.tpl.php
index 8467bfa..ed00386 100644
--- a/achievement.tpl.php
+++ b/achievement.tpl.php
@@ -7,28 +7,29 @@
* Available variables:
* - $achievement: The achievement being displayed, as an array.
* - $unlock: An array of unlocked 'rank' and 'timestamp', if applicable.
- * - $unlocked_date: A formatted date of the user's unlock timestamp.
- * - $unlocked_rank: A formatted string of the user's unlock ranking.
- * - $image: The achievement's image (default or otherwise), linked.
- * - $image_raw: The raw path to the context-aware achievement image.
- * - $classes: String of classes for this achievement.
+ * - $unlocked_date: A renderable string of the user's unlock timestamp.
+ * - $unlocked_rank: A renderable string of the user's unlock ranking.
+ * - $image: The renderable achievement's linked image (default or otherwise).
+ * - $image_path: The raw path to the context-aware achievement image.
* - $achievement_url: Direct URL of the current achievement.
+ * - $achievement_title: The renderable and linked achievement title.
* - $state: The 'unlocked', 'locked', or 'hidden' achievement state.
+ * - $classes: String of classes for this achievement.
*/
?>
<div class="<?php print $classes; ?>">
- <div class="achievement-image"><?php print $image; ?></div>
+ <div class="achievement-image"><?php print render($image); ?></div>
<div class="achievement-points-box">
<div class="achievement-points"><?php print $achievement['points']; ?></div>
<div class="achievement-unlocked-stats">
- <div class="achievement-unlocked-timestamp"><?php print $unlocked_date; ?></div>
- <div class="achievement-unlocked-rank"><?php print $unlocked_rank; ?></div>
+ <div class="achievement-unlocked-timestamp"><?php print render($unlocked_date); ?></div>
+ <div class="achievement-unlocked-rank"><?php print render($unlocked_rank); ?></div>
</div>
</div>
<div class="achievement-body">
- <div class="achievement-title"><a href="<?php print $achievement_url; ?>"><?php print $achievement['title']; ?></a></div>
+ <div class="achievement-title"><?php print render($achievement_title); ?></div>
<div class="achievement-description"><?php print $achievement['description']; ?></div>
</div>
</div>
diff --git a/achievements.module b/achievements.module
index 6fc63dd..af1b3c3 100644
--- a/achievements.module
+++ b/achievements.module
@@ -119,6 +119,9 @@ function template_preprocess_achievement_notification(&$variables) {
*/
function achievements_template_shared_variables(&$variables) {
$variables['state'] = isset($variables['unlock']) ? 'unlocked' : 'locked';
+ $variables['classes_array'][] = 'achievement-' . $variables['state'];
+ $variables['classes_array'][] = 'ui-corner-all'; // add rounded rects for tabs.
+ $variables['achievement_url'] = url('achievements/leaderboard/' . $variables['achievement']['id']);
if (isset($variables['achievement']['hidden']) && !achievements_unlocked_already($variables['achievement']['id'])) {
$variables['achievement']['points'] = t('???'); // IIiII haveEeeA aa seecFRrit and I'll NEEVvaaha hTellLL..
@@ -127,17 +130,41 @@ function achievements_template_shared_variables(&$variables) {
$variables['state'] = 'hidden';
}
- $variables['classes_array'][] = 'achievement-' . $variables['state'];
- $variables['classes_array'][] = 'ui-corner-all'; // if jquery UI is enabled, adds rounded rects.
- $variables['achievement_url'] = url('achievements/leaderboard/' . $variables['achievement']['id']);
- $variables['unlocked_date'] = isset($variables['unlock']['timestamp']) ? format_date($variables['unlock']['timestamp'], 'custom', 'Y/m/d') : '';
- $variables['unlocked_rank'] = isset($variables['unlock']['rank']) ? t('Rank #@rank', array('@rank' => $variables['unlock']['rank'])) : '';
-
- // set the per-achievement image or admin default.
+ // set the displayed image to a hidden-or-not default-or-not determined value. sheesh.
$default = drupal_get_path('module', 'achievements') . '/images/default-' . $variables['state'] . '-70.jpg';
- $variables['image_raw'] = isset($variables['achievement']['images'][$variables['state']]) ? $variables['achievement']['images'][$variables['state']] : variable_get('achievements_image_' . $variables['state'], $default);
- $variables['image'] = theme('image', array('path' => $variables['image_raw'])); // store the selected image path separately so that folks can send it to an image_style or otherwise fiddle with the path not URL.
- $variables['image'] = l($variables['image'], 'achievements/leaderboard/' . $variables['achievement']['id'], array('html' => TRUE));
+ $variables['image_path'] = isset($variables['achievement']['images'][$variables['state']])
+ ? $variables['achievement']['images'][$variables['state']] // user-defined image, yay!
+ : variable_get('achievements_image_' . $variables['state'], $default);
+
+ $variables['image'] = array(
+ '#theme' => 'image_formatter',
+ '#item' => array(
+ 'uri' => $variables['image_path'],
+ 'alt' => $variables['achievement']['title'],
+ 'title' => $variables['achievement']['title'],
+ ),
+ '#path' => array(
+ 'path' => 'achievements/leaderboard/' . $variables['achievement']['id'],
+ 'options' => array('html' => TRUE),
+ ),
+ );
+
+ $variables['achievement_title'] = array(
+ '#theme' => 'link',
+ '#text' => $variables['achievement']['title'],
+ '#path' => 'achievements/leaderboard/' . $variables['achievement']['id'],
+ '#options' => array('html' => FALSE, 'attributes' => array()),
+ );
+ $variables['unlocked_date'] = array(
+ '#markup' => isset($variables['unlock']['timestamp'])
+ ? format_date($variables['unlock']['timestamp'], 'custom', 'Y/m/d')
+ : '',
+ );
+ $variables['unlocked_rank'] = array(
+ '#markup' => isset($variables['unlock']['rank'])
+ ? t('Rank #@rank', array('@rank' => $variables['unlock']['rank']))
+ : '',
+ );
}
/**
diff --git a/achievements.pages.inc b/achievements.pages.inc
index 41bbbac..3cf3395 100644
--- a/achievements.pages.inc
+++ b/achievements.pages.inc
@@ -75,7 +75,7 @@ function achievements_leaderboard_totals() {
),
array(
'data' =>
- '<div class="achievement-latest-image">' . $achievers[$type][$achiever->uid]->latest['image'] . '</div>' .
+ '<div class="achievement-latest-image">' . render($achievers[$type][$achiever->uid]->latest['image']) . '</div>' .
'<div class="achievement-latest-title">' . $achievers[$type][$achiever->uid]->latest['achievement']['title'] . '</div>' .
'<div class="achievement-latest-when">' . format_date($achiever->timestamp, 'small') . '</div>',
'class' => array('achievement-leaderboard-latest')