| 1 |
<?php
|
| 2 |
// Modeline for drupal
|
| 3 |
// vim: set expandtab tabstop=2 shiftwidth=2 autoindent smartindent filetype=php:
|
| 4 |
|
| 5 |
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
| 6 |
* ZINA (Zina is not Andromeda)
|
| 7 |
*
|
| 8 |
* Zina is a graphical interface to your MP3 collection, a personal
|
| 9 |
* jukebox, an MP3 streamer. It can run on its own, embeded into an
|
| 10 |
* existing website, or as a Drupal/Joomla/Wordpress/etc. module.
|
| 11 |
*
|
| 12 |
* http://www.pancake.org/zina
|
| 13 |
* Author: Ryan Lathouwers <ryanlath@pacbell.net>
|
| 14 |
* Support: http://sourceforge.net/projects/zina/
|
| 15 |
* License: GNU GPL2 <http://www.gnu.org/copyleft/gpl.html>
|
| 16 |
*
|
| 17 |
* Drupal Module:
|
| 18 |
* - Zina testbed module...should be most complete.
|
| 19 |
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
| 20 |
define('__ZINA__', 'music');
|
| 21 |
|
| 22 |
/**
|
| 23 |
* Implementation of hook_help().
|
| 24 |
*/
|
| 25 |
function zina_help($section) {
|
| 26 |
switch ($section) {
|
| 27 |
case 'admin/help#zina':
|
| 28 |
return t("XXX");
|
| 29 |
}
|
| 30 |
}
|
| 31 |
|
| 32 |
/**
|
| 33 |
* Implementation of hook_perm().
|
| 34 |
*/
|
| 35 |
function zina_perm() {
|
| 36 |
return array('administer zina', 'access zina');
|
| 37 |
}
|
| 38 |
|
| 39 |
/**
|
| 40 |
* Implementation of hook_menu().
|
| 41 |
*/
|
| 42 |
function zina_menu() {
|
| 43 |
$items['admin/settings/zina'] = array(
|
| 44 |
'title' => t('Zina'),
|
| 45 |
'description' => t('Zina module settings.'),
|
| 46 |
'page callback' => 'zina_admin_settings',
|
| 47 |
'access arguments' => array('administer zina'),
|
| 48 |
'type' => MENU_NORMAL_ITEM,
|
| 49 |
);
|
| 50 |
|
| 51 |
$items[__ZINA__] = array(
|
| 52 |
'title' => t('Music'),
|
| 53 |
'description' => t('Zina is a graphical interface to your MP3 collection, a personal jukebox, an MP3 streamer'),
|
| 54 |
'page callback' => 'zina_main',
|
| 55 |
'access arguments' => array('access content'),
|
| 56 |
'type' => MENU_NORMAL_ITEM,
|
| 57 |
);
|
| 58 |
|
| 59 |
return $items;
|
| 60 |
}
|
| 61 |
|
| 62 |
function zina_get_active_db(&$opts) {
|
| 63 |
global $active_db, $db_type, $db_prefix;
|
| 64 |
$opts['prefix'] = $db_prefix;
|
| 65 |
$opts['type'] = $db_type;
|
| 66 |
return $active_db;
|
| 67 |
}
|
| 68 |
|
| 69 |
function zina_main() {
|
| 70 |
global $user;
|
| 71 |
require_once('zina/index.php');
|
| 72 |
$conf['time'] = microtime(true);
|
| 73 |
|
| 74 |
if (isset($_GET['zid']) && isset($_GET['l']) && ($_GET['l'] == '6' || $_GET['l'] == '10')) {
|
| 75 |
$access = false;
|
| 76 |
if ($uid = zina_token('verify',$_GET['zid'])) {
|
| 77 |
$user = db_fetch_object(db_query("SELECT u.*, s.* FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE u.uid = '%s'", $uid));
|
| 78 |
|
| 79 |
// We found the client's session record and they are an authenticated user
|
| 80 |
if ($user && $user->uid > 0 && user_access('access zina', $user)) {
|
| 81 |
$access = true;
|
| 82 |
$user = drupal_unpack($user);
|
| 83 |
}
|
| 84 |
}
|
| 85 |
if (!$access) {
|
| 86 |
drupal_access_denied();
|
| 87 |
return;
|
| 88 |
}
|
| 89 |
} elseif (!user_access('access zina')) {
|
| 90 |
drupal_access_denied();
|
| 91 |
return;
|
| 92 |
}
|
| 93 |
|
| 94 |
$conf['embed'] = 'drupal';
|
| 95 |
$conf['is_admin'] = user_access('administer zina');
|
| 96 |
$conf['index_abs'] = dirname(__FILE__);
|
| 97 |
|
| 98 |
if ($clean_urls = (bool)variable_get('clean_url', '0')) {
|
| 99 |
$conf['clean_urls_hack'] = false;
|
| 100 |
$conf['index_rel'] = __ZINA__;
|
| 101 |
$conf['clean_urls'] = true;
|
| 102 |
} else {
|
| 103 |
$conf['url_query'][] = 'q='.__ZINA__;
|
| 104 |
$conf['clean_urls'] = false;
|
| 105 |
}
|
| 106 |
|
| 107 |
$conf['user_id'] = $user->uid;
|
| 108 |
|
| 109 |
if ($user->uid > 0) {
|
| 110 |
if ($user->lastfm) {
|
| 111 |
$conf['lastfm'] = true;
|
| 112 |
$conf['lastfm_username'] = $user->lastfm_username;
|
| 113 |
$conf['lastfm_password'] = $user->lastfm_password;
|
| 114 |
}
|
| 115 |
if ($user->twitter) {
|
| 116 |
$conf['twitter'] = true;
|
| 117 |
$conf['twitter_username'] = $user->twitter_username;
|
| 118 |
$conf['twitter_password'] = $user->twitter_password;
|
| 119 |
}
|
| 120 |
}
|
| 121 |
|
| 122 |
if (!isset($_GET['p'])) {
|
| 123 |
$_GET['p'] = substr($_GET['q'],strlen(__ZINA__)+1);
|
| 124 |
}
|
| 125 |
|
| 126 |
$conf['site_name'] = variable_get('site_name', '');
|
| 127 |
|
| 128 |
$zina = zina($conf);
|
| 129 |
|
| 130 |
global $zina_cms_teaser;
|
| 131 |
if (!$zina_cms_teaser) {
|
| 132 |
$bc = drupal_get_breadcrumb();
|
| 133 |
if (is_array($zina['breadcrumb'])) $bc = array_merge($bc, $zina['breadcrumb']);
|
| 134 |
drupal_set_breadcrumb($bc);
|
| 135 |
|
| 136 |
# todo potentially overirde _ZARTIST? w/ drupal_get_title()?
|
| 137 |
#drupal_set_title( drupal_get_title(). ': ' . $zina['title'] );
|
| 138 |
drupal_set_title($zina['title']);
|
| 139 |
}
|
| 140 |
drupal_set_html_head($zina['head_html'].$zina['head_css']);
|
| 141 |
$js = zina_set_js();
|
| 142 |
foreach($js['file'] as $file=>$nothing) {
|
| 143 |
if ($file == 'extras/jquery.js' || $file == 'extras/drupal.js') continue;
|
| 144 |
drupal_add_js(drupal_get_path('module', 'zina').'/zina/'.$file, 'module');
|
| 145 |
}
|
| 146 |
if (!empty($js['vars'])) drupal_add_js(implode('',$js['vars']), 'inline');
|
| 147 |
if (!empty($js['jquery'])) drupal_add_js('jQuery().ready(function(){'.implode('', $js['jquery']).'});', 'inline');
|
| 148 |
if (!empty($js['inline'])) drupal_add_js(implode('',$js['inline']), 'inline');
|
| 149 |
|
| 150 |
if ($zina) {
|
| 151 |
global $zina_nid;
|
| 152 |
if (!empty($zina_nid)) {
|
| 153 |
# drupal paths
|
| 154 |
return $zina;
|
| 155 |
} elseif (isset($zina['page_type']) && $zina['page_type'] == 'main') {
|
| 156 |
# zina paths
|
| 157 |
$node_id = zdbq_single("SELECT cms_id FROM {dirs} WHERE path = '%s'", array($zina['path']));
|
| 158 |
if (!empty($node_id)) {
|
| 159 |
$_GET['q'] = 'node/'.$node_id;
|
| 160 |
$node = node_load($node_id);
|
| 161 |
$node->zina['complete'] = ztheme('page_complete', $zina);
|
| 162 |
return node_show($node, null);
|
| 163 |
#return node_view($node, false, true);
|
| 164 |
}
|
| 165 |
}
|
| 166 |
return ztheme('page_complete', $zina);
|
| 167 |
}
|
| 168 |
}
|
| 169 |
|
| 170 |
function zina_admin_settings() {
|
| 171 |
drupal_goto(__ZINA__.'/','l=20');
|
| 172 |
return;
|
| 173 |
}
|
| 174 |
|
| 175 |
/**
|
| 176 |
* Implementation of hook_node_info
|
| 177 |
*/
|
| 178 |
function zina_node_info() {
|
| 179 |
return array(
|
| 180 |
'zina' => array(
|
| 181 |
'name' => t('Zina'),
|
| 182 |
'module' => 'zina',
|
| 183 |
'description' => t('Zina internal node.'),
|
| 184 |
'has_body' => 0,
|
| 185 |
'has_title' => 0,
|
| 186 |
)
|
| 187 |
);
|
| 188 |
}
|
| 189 |
|
| 190 |
# needed
|
| 191 |
function zina_form(&$node) {
|
| 192 |
/*
|
| 193 |
$form = array();
|
| 194 |
$type = node_get_types('type', $node);
|
| 195 |
if ($type->has_title) {
|
| 196 |
$form['title'] = array(
|
| 197 |
'#type' => 'textfield',
|
| 198 |
'#title' => check_plain($type->title_label),
|
| 199 |
'#required' => TRUE,
|
| 200 |
'#default_value' => $node->title,
|
| 201 |
'#weight' => -5
|
| 202 |
);
|
| 203 |
}
|
| 204 |
|
| 205 |
return $form;
|
| 206 |
*/
|
| 207 |
}
|
| 208 |
|
| 209 |
function zina_cms_insert($path) {
|
| 210 |
$crumbs = explode('/',$path);
|
| 211 |
foreach($crumbs as $crumb) {
|
| 212 |
$titles[] = ztheme('title',zcheck_utf8($crumb));
|
| 213 |
}
|
| 214 |
|
| 215 |
$node->type = 'zina';
|
| 216 |
$node->title = implode('', $titles);
|
| 217 |
$node->uid = variable_get('zina_drupal_uid', 1);
|
| 218 |
$node->promote = 0;
|
| 219 |
node_save($node);
|
| 220 |
return $node->nid;
|
| 221 |
}
|
| 222 |
|
| 223 |
function zina_cms_select($cms_id) {
|
| 224 |
return node_load($cms_id);
|
| 225 |
}
|
| 226 |
|
| 227 |
function zina_cms_alias($cms_id, $path) {
|
| 228 |
static $account = array();
|
| 229 |
if (empty($account)) {
|
| 230 |
$uid = variable_get('zina_drupal_uid', 1);
|
| 231 |
$account = user_load($uid);
|
| 232 |
}
|
| 233 |
if (!user_access('create url aliases', $account)) return false;
|
| 234 |
|
| 235 |
$parts = explode('/', $path);
|
| 236 |
foreach($parts as $part) {
|
| 237 |
$paths[] = zcheck_plain($part);
|
| 238 |
}
|
| 239 |
if (!isset($paths)) {
|
| 240 |
$safe_path = zt('Artists');
|
| 241 |
} else {
|
| 242 |
$safe_path = implode('/',$paths);
|
| 243 |
}
|
| 244 |
|
| 245 |
# GOOD: /music/Bj%F6rk
|
| 246 |
# BAD: /music/Bj%C3%B6rk
|
| 247 |
return path_set_alias('node/'. $cms_id, __ZINA__.'/'.$safe_path);
|
| 248 |
}
|
| 249 |
|
| 250 |
function zina_cms_tags($cms_id, $genre) {
|
| 251 |
$node->nid = $cms_id;
|
| 252 |
$node->vid = $cms_id;
|
| 253 |
$node->type = 'zina';
|
| 254 |
$node->uid = variable_get('zina_drupal_uid', 1);
|
| 255 |
$node->taxonomy['tags'][] = $genre;
|
| 256 |
$terms = taxonomy_node_get_terms($node);
|
| 257 |
|
| 258 |
if (empty($terms)) {
|
| 259 |
$vid = variable_get('zina_genre_vocabulary', 0);
|
| 260 |
$term = array(
|
| 261 |
'tags' => array($vid => $genre),
|
| 262 |
);
|
| 263 |
taxonomy_node_save($node, $term);
|
| 264 |
}
|
| 265 |
}
|
| 266 |
|
| 267 |
function zina_delete(&$node) {
|
| 268 |
db_query('UPDATE {zina_dirs} SET cms_id = 0 WHERE cms_id = %d', $node->nid);
|
| 269 |
}
|
| 270 |
|
| 271 |
function zina_load(&$node) {
|
| 272 |
global $zina_nid;
|
| 273 |
$zina_nid = $node->nid;
|
| 274 |
#return $additions;
|
| 275 |
}
|
| 276 |
|
| 277 |
function zina_view($node, $teaser = FALSE, $page = FALSE) {
|
| 278 |
if (isset($node->zina['complete'])) {
|
| 279 |
# zina paths
|
| 280 |
$node->content['zina'] = array(
|
| 281 |
'#value' => $node->zina['complete'],
|
| 282 |
'#weight' => 0, #variable_get('zina
|
| 283 |
);
|
| 284 |
} else {
|
| 285 |
# drupal paths
|
| 286 |
$zina_path = db_result(db_query("SELECT path FROM {zina_dirs} WHERE cms_id = %d", array($node->nid)));
|
| 287 |
if (!empty($zina_path)) {
|
| 288 |
global $zina_cms_teaser;
|
| 289 |
$zina_cms_teaser = $teaser;
|
| 290 |
#XXX
|
| 291 |
$_GET['p'] = utf8_decode($zina_path);
|
| 292 |
|
| 293 |
$zina = zina_main();
|
| 294 |
$node->zina = &$zina;
|
| 295 |
$node->title = theme('zina_title', $zina['title']);
|
| 296 |
if ($teaser) {
|
| 297 |
$node->readmore = true;
|
| 298 |
$node->teaser = $content = theme('zina_teaser', $zina);
|
| 299 |
} else {
|
| 300 |
$content = ztheme('page_complete', $zina);
|
| 301 |
}
|
| 302 |
} else {
|
| 303 |
$content = t('Error');
|
| 304 |
}
|
| 305 |
|
| 306 |
$node->content['zina'] = array(
|
| 307 |
'#value' => $content,
|
| 308 |
'#weight' => 0, #variable_get('zina
|
| 309 |
);
|
| 310 |
}
|
| 311 |
return $node;
|
| 312 |
}
|
| 313 |
|
| 314 |
#function zina_insert($node) { }
|
| 315 |
|
| 316 |
/**
|
| 317 |
* Implementation of hook_nodeapi().
|
| 318 |
*/
|
| 319 |
function zina_nodeapi(&$node, $op, $teaser, $page) {
|
| 320 |
switch ($op) {
|
| 321 |
case 'delete':
|
| 322 |
break;
|
| 323 |
|
| 324 |
case 'load':
|
| 325 |
break;
|
| 326 |
|
| 327 |
case 'update':
|
| 328 |
break;
|
| 329 |
|
| 330 |
case 'insert':
|
| 331 |
break;
|
| 332 |
|
| 333 |
case 'presave':
|
| 334 |
break;
|
| 335 |
|
| 336 |
case 'view':
|
| 337 |
break;
|
| 338 |
|
| 339 |
case 'search result':
|
| 340 |
break;
|
| 341 |
|
| 342 |
case 'update index':
|
| 343 |
break;
|
| 344 |
}
|
| 345 |
}
|
| 346 |
|
| 347 |
/**
|
| 348 |
* Implementation of hook_block().
|
| 349 |
*/
|
| 350 |
function zina_block($op = 'list', $delta = null, $edit = array()) {
|
| 351 |
if (!function_exists('zina_init')) {
|
| 352 |
$conf['time'] = microtime(true);
|
| 353 |
$conf['embed'] = 'drupal';
|
| 354 |
$conf['index_abs'] = dirname(__FILE__);
|
| 355 |
if ($clean_urls = (bool)variable_get('clean_url', '0')) {
|
| 356 |
$conf['clean_urls_hack'] = false;
|
| 357 |
$conf['index_rel'] = __ZINA__;
|
| 358 |
$conf['clean_urls'] = true;
|
| 359 |
} else {
|
| 360 |
$conf['url_query'][] = 'q='.__ZINA__;
|
| 361 |
$conf['clean_urls'] = false;
|
| 362 |
}
|
| 363 |
|
| 364 |
require_once('zina/index.php');
|
| 365 |
zina_init($conf);
|
| 366 |
}
|
| 367 |
|
| 368 |
if (!zina_get_setting('database')) return;
|
| 369 |
|
| 370 |
if ($op == 'list') {
|
| 371 |
#todo: make 5 configable
|
| 372 |
for ($i=1; $i<=5; $i++) {
|
| 373 |
$blocks['zina_block_'.$i]['info'] = t('Zina Block @num', array('@num'=>$i));
|
| 374 |
}
|
| 375 |
$blocks['zina_block_zinamp']['info'] = t('Zina Flash Player');
|
| 376 |
return $blocks;
|
| 377 |
|
| 378 |
} elseif ($op == 'view') {
|
| 379 |
if ($delta == 'zina_block_zinamp') {
|
| 380 |
if ($_GET['q'] != __ZINA__) {
|
| 381 |
$block['subject'] = $blocks[$delta]['info'];
|
| 382 |
$block['content'] = ztheme('zinamp_embed');
|
| 383 |
#TODO: XXX redudant
|
| 384 |
$js = zina_set_js();
|
| 385 |
foreach($js['file'] as $file=>$nothing) {
|
| 386 |
if ($file == 'extras/jquery.js' || $file == 'extras/drupal.js') continue;
|
| 387 |
drupal_add_js(drupal_get_path('module', 'zina').'/zina/'.$file, 'module');
|
| 388 |
}
|
| 389 |
if (!empty($js['vars'])) drupal_add_js(implode('',$js['vars']), 'inline');
|
| 390 |
if (!empty($js['jquery'])) drupal_add_js('jQuery().ready(function(){'.implode('', $js['jquery']).'});', 'inline');
|
| 391 |
if (!empty($js['inline'])) drupal_add_js(implode('',$js['inline']), 'inline');
|
| 392 |
|
| 393 |
return $block;
|
| 394 |
}
|
| 395 |
} else {
|
| 396 |
$number = (int) variable_get($delta.'_items', 5);
|
| 397 |
$type = variable_get($delta.'_type', 'f');
|
| 398 |
$page = variable_get($delta.'_page', 'rating');
|
| 399 |
$period = variable_get($delta.'_period', 'all');
|
| 400 |
$id3 = variable_get($delta.'_id3', 0);
|
| 401 |
$images = variable_get($delta.'_images', 1);
|
| 402 |
$results = zina_get_block_stat($type, $page, $period, $number, $id3, $images);
|
| 403 |
if (sizeof($results) > $number) $results = array_slice($results,0, $number);
|
| 404 |
$block['subject'] = $blocks[$delta]['info'];
|
| 405 |
$block['content'] = theme('zina_block', $results, array('type'=>$type, 'page'=>$page, 'period'=>$period, 'images'=>$images));
|
| 406 |
return $block;
|
| 407 |
}
|
| 408 |
} elseif ($op == 'configure') {
|
| 409 |
if ($delta == 'zina_block_zinamp') {
|
| 410 |
|
| 411 |
#return $form;
|
| 412 |
} else {
|
| 413 |
$types = zina_get_stats_types();
|
| 414 |
$form[$delta.'_type'] = array(
|
| 415 |
'#type' => 'select',
|
| 416 |
'#title' => t('Type of Item'),
|
| 417 |
'#options' => $types,
|
| 418 |
'#default_value' => variable_get($delta.'_type', 'song'),
|
| 419 |
'#required' => true,
|
| 420 |
);
|
| 421 |
|
| 422 |
#$pages = zina_get_stats_pages();
|
| 423 |
$pages = zina_get_stats_blocks();
|
| 424 |
$form[$delta.'_page'] = array(
|
| 425 |
'#type' => 'select',
|
| 426 |
'#title' => t('Type of statistic'),
|
| 427 |
'#options' => $pages,
|
| 428 |
'#default_value' => variable_get($delta.'_page', 'rating'),
|
| 429 |
'#required' => true,
|
| 430 |
);
|
| 431 |
|
| 432 |
$periods = zina_get_stats_periods();
|
| 433 |
$form[$delta.'_period'] = array(
|
| 434 |
'#type' => 'select',
|
| 435 |
'#title' => t('Period of statistic'),
|
| 436 |
'#description' => t('Will not be relevant for all stats'),
|
| 437 |
'#options' => $periods,
|
| 438 |
'#default_value' => variable_get($delta.'_period', 'all'),
|
| 439 |
'#required' => true,
|
| 440 |
);
|
| 441 |
|
| 442 |
$form[$delta.'_items'] = array(
|
| 443 |
'#type' => 'textfield',
|
| 444 |
'#title' => t('Number of items'),
|
| 445 |
'#description' => t('This needs to be a number.'),
|
| 446 |
'#default_value' => variable_get($delta.'_items', 10),
|
| 447 |
'#required' => true,
|
| 448 |
);
|
| 449 |
$form[$delta.'_id3'] = array(
|
| 450 |
'#type' => 'radios',
|
| 451 |
'#title' => t('Use id3 tags (if applicable)'),
|
| 452 |
'#options' => array(1=> t('True'), 0=>t('False')),
|
| 453 |
'#default_value' => variable_get($delta.'_id3', 0),
|
| 454 |
'#required' => true,
|
| 455 |
);
|
| 456 |
$form[$delta.'_images'] = array(
|
| 457 |
'#type' => 'radios',
|
| 458 |
'#title' => t('Show images'),
|
| 459 |
'#options' => array(1=> t('True'), 0=>t('False')),
|
| 460 |
'#default_value' => variable_get($delta.'_images', 1),
|
| 461 |
'#required' => true,
|
| 462 |
);
|
| 463 |
return $form;
|
| 464 |
}
|
| 465 |
} elseif ($op == 'save') {
|
| 466 |
if ($delta == 'zina_block_zinamp') {
|
| 467 |
|
| 468 |
} else {
|
| 469 |
$options = array('items','type', 'page', 'period', 'id3', 'images');
|
| 470 |
foreach ($options as $opt) {
|
| 471 |
variable_set($delta.'_'.$opt, $edit[$delta.'_'.$opt]);
|
| 472 |
}
|
| 473 |
}
|
| 474 |
}
|
| 475 |
}
|
| 476 |
|
| 477 |
/*function zina_link($type, $object, $teaser = false) {
|
| 478 |
$links = array();
|
| 479 |
if ($type == 'node' && $object->type == 'zina') {
|
| 480 |
if ($teaser) {
|
| 481 |
$links['zina_read_more'] = array(
|
| 482 |
'title' => t('Read More'),
|
| 483 |
'href' => 'asdf',
|
| 484 |
'attributes' => array('title' => t('Read the rest of !title.', array('!title' => $node->title)))
|
| 485 |
);
|
| 486 |
}
|
| 487 |
}
|
| 488 |
return $links;
|
| 489 |
}
|
| 490 |
*/
|
| 491 |
/**
|
| 492 |
* Implementation of hook_theme().
|
| 493 |
*/
|
| 494 |
function zina_theme() {
|
| 495 |
return array(
|
| 496 |
'zina_admin_view' => array(
|
| 497 |
'arguments' => array('form'),
|
| 498 |
),
|
| 499 |
'zina_block' => array(
|
| 500 |
'arguments' => array('items','opts'),
|
| 501 |
),
|
| 502 |
'zina_teaser' => array(
|
| 503 |
'arguments' => array('zina'),
|
| 504 |
),
|
| 505 |
'zina_title' => array(
|
| 506 |
'arguments' => array('path'),
|
| 507 |
),
|
| 508 |
);
|
| 509 |
}
|
| 510 |
|
| 511 |
function theme_zina_title($title) {
|
| 512 |
return decode_entities($title);
|
| 513 |
}
|
| 514 |
|
| 515 |
function theme_zina_teaser($zina) {
|
| 516 |
$output = '<div class="node-content clear-block"><div class="zina-directory-image">'.zl($zina['dir_image_sub'], $zina['path']).'</div>';
|
| 517 |
if (!empty($zina['description'])) {
|
| 518 |
$output .= '<p>'.$zina['description'].'</p>';
|
| 519 |
}
|
| 520 |
$output .= '</div>';
|
| 521 |
return $output;
|
| 522 |
}
|
| 523 |
|
| 524 |
function zina_cron() {
|
| 525 |
$conf['time'] = microtime(true);
|
| 526 |
$conf['embed'] = 'drupal';
|
| 527 |
$conf['index_abs'] = dirname(__FILE__);
|
| 528 |
require_once('zina/index.php');
|
| 529 |
zina_init($conf);
|
| 530 |
zina_cron_run();
|
| 531 |
}
|
| 532 |
|
| 533 |
|
| 534 |
function theme_zina_block($items, $opts) {
|
| 535 |
if (!empty($items)) {
|
| 536 |
|
| 537 |
if ($opts['images']) {
|
| 538 |
if ($_GET['q'] != __ZINA__) {
|
| 539 |
drupal_set_html_head('<style>div.zina-stats-block{float:left;width:100%;}'.
|
| 540 |
'.zina-stats-block p{margin:0;padding:0;}'.
|
| 541 |
'.zina-stats-block img{float:left;padding-right:5px;padding-bottom:5px;}'.
|
| 542 |
'</style>');
|
| 543 |
}
|
| 544 |
foreach($items as $item) {
|
| 545 |
$output .= '<div class="zina-stats-block">';
|
| 546 |
if ($opts['type'] == 'f' || $opts['type'] == 'song') {
|
| 547 |
if (isset($item['url'])) {
|
| 548 |
$output .= zl($item['image'], dirname($item['path'])).
|
| 549 |
'<p><a href="'.$item['url'].'" class="zinamp">'.$item['title'].'</a></p>';
|
| 550 |
} else {
|
| 551 |
$output .= zl($item['image'], dirname($item['path'])).
|
| 552 |
'<p>'.zl($item['title'], dirname($item['path'])).'</p>';
|
| 553 |
}
|
| 554 |
} else {
|
| 555 |
$output .= zl($item['image'], $item['path']).'<p>'.$item['display'].'</p>';
|
| 556 |
}
|
| 557 |
$output .= '</div>';
|
| 558 |
}
|
| 559 |
} else {
|
| 560 |
|
| 561 |
$output = '<ul class="item-list">';
|
| 562 |
foreach($items as $item) {
|
| 563 |
$output .= '<li>';
|
| 564 |
if ($opts['type'] == 'f' || $opts['type'] == 'song') {
|
| 565 |
$output .= (isset($item['url'])) ? '<a href="'.$item['url'].'" class="zinamp">'.$item['title'].'</a>' : $item['title'];
|
| 566 |
} else {
|
| 567 |
$output .= $item['display'];
|
| 568 |
}
|
| 569 |
$output .= '</li>';
|
| 570 |
}
|
| 571 |
$output .= '</ul>';
|
| 572 |
}
|
| 573 |
} else {
|
| 574 |
$output = t('No results');
|
| 575 |
}
|
| 576 |
return $output;
|
| 577 |
}
|
| 578 |
|
| 579 |
function zina_user($op, &$edit, &$account, $category = NULL) {
|
| 580 |
if ($op == 'form' && $category == 'account') {
|
| 581 |
$form['zina'] = array(
|
| 582 |
'#type' => 'fieldset',
|
| 583 |
'#title' => t('Last.fm and/or Twitter Integration'),
|
| 584 |
'#description' => t('If you want to send your listening information to last.fm or twitter.com enable this and enter your login credentials.'),
|
| 585 |
'#collapsible' => TRUE,
|
| 586 |
'#weight' => 4);
|
| 587 |
$form['zina']['lastfm'] = array(
|
| 588 |
'#type' => 'checkbox',
|
| 589 |
'#title' => t('Enable last.fm integration'),
|
| 590 |
'#default_value' => $edit['lastfm'],
|
| 591 |
);
|
| 592 |
$form['zina']['lastfm_username'] = array(
|
| 593 |
'#type' => 'textfield',
|
| 594 |
'#title' => t('Username'),
|
| 595 |
'#default_value' => $edit['lastfm_username'],
|
| 596 |
'#size' => 20,
|
| 597 |
);
|
| 598 |
$form['zina']['lastfm_password'] = array(
|
| 599 |
'#type' => 'textfield',
|
| 600 |
'#title' => t('Password'),
|
| 601 |
'#default_value' => $edit['lastfm_password'],
|
| 602 |
'#size' => 20,
|
| 603 |
);
|
| 604 |
$form['zina']['twitter'] = array(
|
| 605 |
'#type' => 'checkbox',
|
| 606 |
'#title' => t('Enable twitter integration'),
|
| 607 |
'#default_value' => $edit['twitter'],
|
| 608 |
);
|
| 609 |
$form['zina']['twitter_username'] = array(
|
| 610 |
'#type' => 'textfield',
|
| 611 |
'#title' => t('Username'),
|
| 612 |
'#default_value' => $edit['twitter_username'],
|
| 613 |
'#size' => 20,
|
| 614 |
);
|
| 615 |
$form['zina']['twitter_password'] = array(
|
| 616 |
'#type' => 'textfield',
|
| 617 |
'#title' => t('Password'),
|
| 618 |
'#default_value' => $edit['twitter_password'],
|
| 619 |
'#size' => 20,
|
| 620 |
);
|
| 621 |
return $form;
|
| 622 |
}
|
| 623 |
}
|
| 624 |
|
| 625 |
function zina_access_denied() {
|
| 626 |
drupal_access_denied();
|
| 627 |
return false;
|
| 628 |
}
|
| 629 |
|
| 630 |
function zina_not_found() {
|
| 631 |
drupal_not_found();
|
| 632 |
return false;
|
| 633 |
}
|
| 634 |
|
| 635 |
function zina_cms_info() {
|
| 636 |
return array(
|
| 637 |
'version' => VERSION,
|
| 638 |
'modules' => module_list(false, false),
|
| 639 |
);
|
| 640 |
}
|
| 641 |
|
| 642 |
function zina_token($type, $value) {
|
| 643 |
$sitekey = drupal_get_private_key();
|
| 644 |
|
| 645 |
$sep = '|';
|
| 646 |
if ($type == 'get') {
|
| 647 |
return $value.$sep.md5($value.$sitekey);
|
| 648 |
} elseif ($type == 'verify') {
|
| 649 |
$x = explode($sep, $value);
|
| 650 |
if (md5($x[0].$sitekey) === $x[1]) {
|
| 651 |
return $x[0];
|
| 652 |
} else {
|
| 653 |
return false;
|
| 654 |
}
|
| 655 |
}
|
| 656 |
|
| 657 |
return false;
|
| 658 |
}
|
| 659 |
|
| 660 |
function zina_xmlsitemap_links($type = null, $excludes = array()) {
|
| 661 |
if ($type == 'xml') {
|
| 662 |
$conf['time'] = microtime(true);
|
| 663 |
$conf['embed'] = 'drupal';
|
| 664 |
$conf['index_abs'] = dirname(__FILE__);
|
| 665 |
if ($clean_urls = (bool)variable_get('clean_url', '0')) {
|
| 666 |
$conf['clean_urls_hack'] = false;
|
| 667 |
$conf['index_rel'] = __ZINA__;
|
| 668 |
$conf['clean_urls'] = true;
|
| 669 |
} else {
|
| 670 |
$conf['url_query'][] = 'q='.__ZINA__;
|
| 671 |
$conf['clean_urls'] = false;
|
| 672 |
}
|
| 673 |
|
| 674 |
require_once('zina/index.php');
|
| 675 |
zina_init($conf);
|
| 676 |
return zina_content_sitemap();
|
| 677 |
}
|
| 678 |
}
|
| 679 |
|
| 680 |
/*
|
| 681 |
function zina_search_page($results) {
|
| 682 |
#TODO: theme zina info
|
| 683 |
return theme('search_results', $results, 'zina');
|
| 684 |
}
|
| 685 |
*/
|
| 686 |
|
| 687 |
#TODO: test out on big search (limit? make opt?)
|
| 688 |
function zina_search($op = 'search', $keys = null) {
|
| 689 |
if ($op == 'name') {
|
| 690 |
return t('Music');
|
| 691 |
} elseif ($op == 'search') {
|
| 692 |
$count = variable_get('minimum_word_size', 3);
|
| 693 |
if (empty($keys) || strlen($keys) < $count) {
|
| 694 |
form_set_error('keys', t('You must include at least one keyword with @count characters or more.', array('@count' => $count)));
|
| 695 |
return;
|
| 696 |
}
|
| 697 |
|
| 698 |
global $user;
|
| 699 |
if (!user_access('access zina', $user)) return;
|
| 700 |
|
| 701 |
if (!function_exists('zina_init')) {
|
| 702 |
$conf['time'] = microtime(true);
|
| 703 |
$conf['embed'] = 'drupal';
|
| 704 |
$conf['index_abs'] = dirname(__FILE__);
|
| 705 |
if ($clean_urls = (bool)variable_get('clean_url', '0')) {
|
| 706 |
$conf['clean_urls_hack'] = false;
|
| 707 |
$conf['index_rel'] = __ZINA__;
|
| 708 |
$conf['clean_urls'] = true;
|
| 709 |
} else {
|
| 710 |
$conf['url_query'][] = 'q='.__ZINA__;
|
| 711 |
$conf['clean_urls'] = false;
|
| 712 |
}
|
| 713 |
|
| 714 |
require_once('zina/index.php');
|
| 715 |
zina_init($conf);
|
| 716 |
}
|
| 717 |
|
| 718 |
$results = zina_search_embed($keys);
|
| 719 |
|
| 720 |
foreach($results as $item) {
|
| 721 |
$drupal_results[] = array(
|
| 722 |
'link' => zurl($item['title_link']['path'],str_replace('&','&',$item['title_link']['query'])),
|
| 723 |
#'type' => ucfirst($item['type']),
|
| 724 |
'title' => $item['title'],
|
| 725 |
'snippet' => $item['description'],
|
| 726 |
);
|
| 727 |
}
|
| 728 |
return $drupal_results;
|
| 729 |
|
| 730 |
/*
|
| 731 |
$results[] = array(
|
| 732 |
'link' => url('node/'. $item->sid, array('absolute' => TRUE)),
|
| 733 |
'type' => check_plain(node_get_types('name', $node)),
|
| 734 |
'title' => $node->title,
|
| 735 |
'user' => theme('username', $node),
|
| 736 |
'date' => $node->changed,
|
| 737 |
'node' => $node,
|
| 738 |
'extra' => $extra,
|
| 739 |
'score' => $item->score / $total,
|
| 740 |
'snippet' => search_excerpt($keys, $node->body),
|
| 741 |
);
|
| 742 |
*/
|
| 743 |
}
|
| 744 |
}
|
| 745 |
|
| 746 |
function zina_update_index() {
|
| 747 |
$limit = (int)variable_get('search_cron_limit', 100);
|
| 748 |
$result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'zina' AND d.sid = n.nid ".
|
| 749 |
"WHERE d.sid IS NULL OR d.reindex <> 0 ORDER BY d.reindex ASC, n.nid ASC", 0, $limit);
|
| 750 |
|
| 751 |
while ($node = db_fetch_object($result)) {
|
| 752 |
$node = node_load($node->nid);
|
| 753 |
|
| 754 |
if (node_hook($node, 'view')) {
|
| 755 |
node_invoke($node, 'view', false, false);
|
| 756 |
} else {
|
| 757 |
$node = node_prepare($node, false);
|
| 758 |
}
|
| 759 |
|
| 760 |
// Allow modules to change $node->body before viewing.
|
| 761 |
node_invoke_nodeapi($node, 'view', false, false);
|
| 762 |
|
| 763 |
$text = '<h1>'. check_plain($node->title) .'</h1>'. $node->body;
|
| 764 |
|
| 765 |
// Fetch extra data normally not visible
|
| 766 |
$extra = node_invoke_nodeapi($node, 'update index');
|
| 767 |
foreach ($extra as $t) {
|
| 768 |
$text .= $t;
|
| 769 |
}
|
| 770 |
|
| 771 |
// Update index
|
| 772 |
search_index($node->nid, 'node', $text);
|
| 773 |
}
|
| 774 |
}
|
| 775 |
?>
|