| 1 |
<?php
|
| 2 |
// $Id: interview.module,v 1.4 2006/05/26 11:08:56 trunks Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Interview module
|
| 7 |
*
|
| 8 |
* Developed by Jose A. Reyero for Alquimia Proyectos Digitales
|
| 9 |
* http://www.reyero.net, 2006
|
| 10 |
*/
|
| 11 |
|
| 12 |
/*******************************
|
| 13 |
* module hooks
|
| 14 |
*******************************/
|
| 15 |
|
| 16 |
/**
|
| 17 |
* Implementation of hook_block().
|
| 18 |
*
|
| 19 |
* Displays the latest interview.
|
| 20 |
*/
|
| 21 |
function interview_block($op = 'list', $delta = 0) {
|
| 22 |
global $user;
|
| 23 |
if ($op == 'list') {
|
| 24 |
$block[0]['info'] = t('Latest interview');
|
| 25 |
return $block;
|
| 26 |
}
|
| 27 |
else if ($op == 'view') {
|
| 28 |
$latest = db_fetch_object(db_query_range(db_rewrite_sql("SELECT n.nid, n.title, i.subtitle FROM {node} n INNER JOIN {interview} i ON n.nid = i.nid WHERE n.type = 'interview' AND n.status = 1 ORDER BY n.created DESC"), 0, 1));
|
| 29 |
if($latest) {
|
| 30 |
$block['content'] = $latest->subtitle;
|
| 31 |
$block['content'] .= '<div class="more-link">'. l(t('more'), "node/$latest->nid" ) .'</div>';
|
| 32 |
$block['subject'] = $latest->title;
|
| 33 |
return $block;
|
| 34 |
}
|
| 35 |
}
|
| 36 |
}
|
| 37 |
|
| 38 |
/**
|
| 39 |
* Implementation of hook filter
|
| 40 |
*/
|
| 41 |
function interview_filter($op, $delta = 0, $format = -1, $text = '') {
|
| 42 |
|
| 43 |
switch ($op) {
|
| 44 |
case 'list':
|
| 45 |
return array(0 => t('Interview filter'));
|
| 46 |
|
| 47 |
case 'description':
|
| 48 |
return t('Allows users to format interview questions using <question> tag.');
|
| 49 |
|
| 50 |
case 'prepare':
|
| 51 |
// Note: we use the bytes 0xFE and 0xFF to replace < > during the filtering process.
|
| 52 |
// These bytes are not valid in UTF-8 data and thus least likely to cause problems.
|
| 53 |
$text = preg_replace('@<question>(.+?)</question>@se', "'\xFEquestion\xFF\\1\xFE/question\xFF'", $text);
|
| 54 |
return $text;
|
| 55 |
|
| 56 |
case "process":
|
| 57 |
$text = preg_replace('@\xFEquestion\xFF(.+?)\xFE/question\xFF@se', "'<span class=\"question\">$1</span>'", $text);
|
| 58 |
return $text;
|
| 59 |
|
| 60 |
default:
|
| 61 |
return $text;
|
| 62 |
}
|
| 63 |
}
|
| 64 |
|
| 65 |
/**
|
| 66 |
* Implementation of hook_filter_tips()
|
| 67 |
*/
|
| 68 |
function interview_filter_tips($delta, $format, $long = false) {
|
| 69 |
if ($long) {
|
| 70 |
return t('To post interview questions, surround them with <question>...</question> tags.');
|
| 71 |
}
|
| 72 |
else {
|
| 73 |
return t('You may post code using <question>...</question>.');
|
| 74 |
}
|
| 75 |
}
|
| 76 |
|
| 77 |
/**
|
| 78 |
* Implementation of hook_help().
|
| 79 |
*/
|
| 80 |
function interview_help($section) {
|
| 81 |
switch ($section) {
|
| 82 |
case 'admin/modules#description':
|
| 83 |
return t('Allows users to submit interviews.');
|
| 84 |
case 'node/add#interview':
|
| 85 |
return t('Interviews are articles with some additional fields and some special formatting.');
|
| 86 |
}
|
| 87 |
}
|
| 88 |
|
| 89 |
/**
|
| 90 |
* Implementation of hook_settings().
|
| 91 |
*/
|
| 92 |
function interview_settings() {
|
| 93 |
$group .= form_select(t('Limit latest interviews'), 'limit_latest_interviews', variable_get('limit_latest_interviews', '3'), array(0 => 0, 1 => 1, 2 => 2, 3=> 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10), t('Amount of latest interviews listed above the interview in view mode.'));
|
| 94 |
$output .= form_group(t('Interviews list settings'), $group);
|
| 95 |
|
| 96 |
return $output;
|
| 97 |
}
|
| 98 |
|
| 99 |
/**
|
| 100 |
* Implementation of hook_menu().
|
| 101 |
*/
|
| 102 |
function interview_menu($may_cache) {
|
| 103 |
$items = array();
|
| 104 |
|
| 105 |
if ($may_cache) {
|
| 106 |
$items[] = array('path' => 'node/add/interview', 'title' => t('interview'),
|
| 107 |
'access' => user_access('create interviews'));
|
| 108 |
$items[] = array('path' => 'interview', 'title' => t('interviews'),
|
| 109 |
'callback' => 'interview_page', 'access' => user_access('access content'));
|
| 110 |
} else {
|
| 111 |
// Set stylesheet
|
| 112 |
drupal_set_html_head(theme('stylesheet_import', drupal_get_path('module', 'interview') . '/interview.css'));
|
| 113 |
}
|
| 114 |
|
| 115 |
return $items;
|
| 116 |
}
|
| 117 |
|
| 118 |
/**
|
| 119 |
* Implementation of hook_perm().
|
| 120 |
*/
|
| 121 |
function interview_perm() {
|
| 122 |
return array('create interviews', 'edit own interviews');
|
| 123 |
}
|
| 124 |
|
| 125 |
/**
|
| 126 |
* Callback for interviews page
|
| 127 |
*/
|
| 128 |
function interview_page(){
|
| 129 |
$result = pager_query(db_rewrite_sql("SELECT n.nid, n.sticky, n.created FROM {node} n WHERE n.type = 'interview' AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC"), variable_get('default_nodes_main', 10));
|
| 130 |
|
| 131 |
if ($num_rows = db_num_rows($result)) {
|
| 132 |
drupal_add_link(array('rel' => 'alternate',
|
| 133 |
'type' => 'application/rss+xml',
|
| 134 |
'title' => 'RSS',
|
| 135 |
'href' => url('node/feed', NULL, NULL, TRUE)));
|
| 136 |
|
| 137 |
$node->teaser = t('Listed') . ' ' . $num_rows . ' ' . t('interviews');
|
| 138 |
$output = theme('node', $node, 1);
|
| 139 |
while ($node = db_fetch_object($result)) {
|
| 140 |
$output .= node_view(node_load(array('nid' => $node->nid)), 1);
|
| 141 |
}
|
| 142 |
$output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
|
| 143 |
}
|
| 144 |
else {
|
| 145 |
$output = t("No interviews");
|
| 146 |
}
|
| 147 |
|
| 148 |
print theme('page', $output);
|
| 149 |
}
|
| 150 |
|
| 151 |
/**********************
|
| 152 |
* interview node type
|
| 153 |
**********************/
|
| 154 |
|
| 155 |
/**
|
| 156 |
* Implementation of hook_access().
|
| 157 |
*/
|
| 158 |
function interview_access($op, $node) {
|
| 159 |
global $user;
|
| 160 |
|
| 161 |
if ($op == 'create') {
|
| 162 |
return user_access('create interviews');
|
| 163 |
}
|
| 164 |
|
| 165 |
if ($op == 'update' || $op == 'delete') {
|
| 166 |
if (user_access('edit own interviews') && ($user->uid == $node->uid)) {
|
| 167 |
return TRUE;
|
| 168 |
}
|
| 169 |
}
|
| 170 |
}
|
| 171 |
|
| 172 |
/**
|
| 173 |
* Implementation of hook_node_name().
|
| 174 |
*/
|
| 175 |
function interview_node_name($node) {
|
| 176 |
return t('interview');
|
| 177 |
}
|
| 178 |
|
| 179 |
/**
|
| 180 |
* Implementation of hook_form().
|
| 181 |
*/
|
| 182 |
function interview_form(&$node) {
|
| 183 |
$output = '';
|
| 184 |
|
| 185 |
if (function_exists('taxonomy_node_form')) {
|
| 186 |
$output .= implode('', taxonomy_node_form('interview', $node));
|
| 187 |
}
|
| 188 |
$output .= form_textarea(t('Subtitle'), 'subtitle', $node->subtitle, 60, 4, '', NULL, FALSE);
|
| 189 |
$output .= form_textarea(t('Lead'), 'lead', $node->lead, 60, 4, '', NULL, FALSE);
|
| 190 |
$output .= form_textarea(t('Highlight'), 'highlight', $node->highlight, 60, 4, '', NULL, FALSE);
|
| 191 |
|
| 192 |
$output .= form_textarea(t('Body'), 'body', $node->body, 60, 20, '', NULL, TRUE);
|
| 193 |
$output .= filter_form('format', $node->format);
|
| 194 |
$output .= form_textarea(t('Image footer'), 'imagefooter', $node->imagefooter, 60, 2, '', NULL, FALSE);
|
| 195 |
|
| 196 |
return $output;
|
| 197 |
}
|
| 198 |
|
| 199 |
/**
|
| 200 |
* Implementation of hook_view().
|
| 201 |
*/
|
| 202 |
|
| 203 |
function interview_view(&$node, $teaser = FALSE, $page = FALSE) {
|
| 204 |
$node = node_prepare($node, $teaser);
|
| 205 |
if($page){
|
| 206 |
$content = '';
|
| 207 |
$imagefull = variable_get('image_full_size', 'preview');
|
| 208 |
$limit = variable_get('limit_latest_interviews', '3');
|
| 209 |
if( function_exists('image_display') && $image = image_display($node, $imagefull) ) {
|
| 210 |
$info = image_get_info(file_create_path($node->images[$imagefull]));
|
| 211 |
// Calculate size of image for block width
|
| 212 |
$width = $info ? $info['width'] : 200;
|
| 213 |
$content = "<div class=\"image-box\" style=\"width:${width}px;\">".$image.
|
| 214 |
"<div class=\"footer\">".$node->imagefooter."</div>\n</div>\n";
|
| 215 |
}
|
| 216 |
$node->title .= "<br /><span class='subtitle'>" . $node->subtitle . "</span>";
|
| 217 |
$body = $node->body;
|
| 218 |
// Possibly cleaner with CSS but I don't know how
|
| 219 |
$body_header = node_teaser($body, 0);
|
| 220 |
$count = strlen($body_header);
|
| 221 |
$node->body = $content . '<p class="lead-full">'.nl2br($node->lead).'</p>';
|
| 222 |
$node->body .= $body_header;
|
| 223 |
$node->body .= "<div class=\"highlight\" style=\"width: 200px;\">".$node->highlight."</div>\n";
|
| 224 |
$node->body .= substr($body, $count);
|
| 225 |
$node->body .= interview_latest($node, $limit);
|
| 226 |
} else {
|
| 227 |
$node->teaser = '<p>'.nl2br($node->lead).'</p>';
|
| 228 |
}
|
| 229 |
}
|
| 230 |
|
| 231 |
function interview_latest($node, $limit) {
|
| 232 |
$sql = db_query("SELECT i.nid, n.title FROM {interview} i JOIN {node} n ON i.nid = n.nid WHERE i.nid < %d ORDER BY i.nid DESC LIMIT 0,%d", $node->nid, $limit);
|
| 233 |
|
| 234 |
$num_results = db_num_rows($sql);
|
| 235 |
|
| 236 |
while ($result = db_fetch_object($sql)) {
|
| 237 |
$output .= '<li>' . l($result->title, 'node/' . $result->nid) . '</li>' . "\n";
|
| 238 |
}
|
| 239 |
|
| 240 |
if ( $num_results > 0 )
|
| 241 |
$output = '<br /><p class="latest-interviews"><span>' . t('View more interviews:') . '</span><ul>' . $output . "</ul></p><br />";
|
| 242 |
|
| 243 |
return $output;
|
| 244 |
}
|
| 245 |
|
| 246 |
/**
|
| 247 |
* Implementation of hook_insert().
|
| 248 |
*/
|
| 249 |
function interview_insert($node) {
|
| 250 |
db_query("INSERT INTO {interview} (nid, subtitle, lead, highlight, imagefooter) VALUES (%d, '%s', '%s', '%s', '%s')", $node->nid, $node->subtitle, $node->lead, $node->highlight, $node->imagefooter);
|
| 251 |
}
|
| 252 |
|
| 253 |
/**
|
| 254 |
* Implementation of hook load
|
| 255 |
*/
|
| 256 |
function interview_load($node) {
|
| 257 |
return db_fetch_object(db_query("SELECT * FROM {interview} WHERE nid = %d", $node->nid));
|
| 258 |
}
|
| 259 |
|
| 260 |
/**
|
| 261 |
* Implementation of hook_update().
|
| 262 |
*/
|
| 263 |
function interview_update($node) {
|
| 264 |
db_query("UPDATE {interview} SET subtitle = '%s', lead = '%s', highlight = '%s', imagefooter = '%s' WHERE nid = %d", $node->subtitle, $node->lead, $node->highlight, $node->imagefooter, $node->nid);
|
| 265 |
}
|
| 266 |
|
| 267 |
?>
|