| 1 |
<?php |
<?php |
| 2 |
// $Id: contaxe.module,v 1.8 2008/02/26 09:42:00 salgar Exp $ |
// $Id: contaxe.module,v 1.9 2008/02/26 14:27:17 salgar Exp $ |
| 3 |
|
|
| 4 |
/* |
/* |
| 5 |
http://drupal.org/project/jquery_update |
http://drupal.org/project/jquery_update |
| 1485 |
*/ |
*/ |
| 1486 |
function contaxe_nodeapi(&$node, $op, $teaser, $page) { |
function contaxe_nodeapi(&$node, $op, $teaser, $page) { |
| 1487 |
if ($op != 'view') return; |
if ($op != 'view') return; |
| 1488 |
// TODO check if page matches |
if (variable_get(CONTAXE_INJECTOR_NODETYPE . $node->type, FALSE)) return; |
| 1489 |
// TODO check if the current |
// TODO PAGELIST check if page matches |
|
// TODO check if $node->type is valid for injection |
|
| 1490 |
if (isset($page)) { // normal view |
if (isset($page)) { // normal view |
| 1491 |
|
if (!variable_get('contaxe_injector_body_enable', FALSE)) return; |
| 1492 |
|
$minwords = variable_get('contaxe_injector_minwords', 75); |
| 1493 |
|
$cntwords = contaxe_count_words($node->content['body']['#value'], $minwords); |
| 1494 |
|
if ($cntwords < $minwords) return; |
| 1495 |
|
$template = variable_get('contaxe_injector_body_template', CONTAXE_INJECTOR_DEFAULT_BODY_TEMPLATE); |
| 1496 |
|
$template = contaxe_process_tags($template); |
| 1497 |
|
$node->body = $node->content['body']['#value'] = strtr($template, array('%body' => $node->content['body']['#value'])); |
| 1498 |
|
return; |
| 1499 |
|
} |
| 1500 |
|
if (isset($teaser)) { // list |
| 1501 |
|
if (!variable_get('contaxe_injector_list_enable', FALSE)) return; |
| 1502 |
|
$template = variable_get('contaxe_injector_list_template', CONTAXE_INJECTOR_DEFAULT_LIST_TEMPLATE); |
| 1503 |
|
$template = contaxe_process_tags($template); |
| 1504 |
|
$node->content['body']['#value'] = strtr($template, array('%teaser' => $node->teaser)); |
| 1505 |
|
return; |
| 1506 |
} |
} |
|
else if (isset($teaser)) { // list |
|
|
} |
|
| 1507 |
} |
} |
| 1508 |
|
|
| 1509 |
|
/** |
| 1510 |
|
* Count words in a string. |
| 1511 |
|
* @param $str ref to a string (ref so no copy) |
| 1512 |
|
* @param $max max # of words we care about. Return value will never exceed this. |
| 1513 |
|
* @return the count of words, where delimiter is one or more spaces |
| 1514 |
|
* @todo Efficiency, find better way to do this |
| 1515 |
|
*/ |
| 1516 |
|
function contaxe_count_words(&$str, $max) { |
| 1517 |
|
return count(explode(' ', $str, $max)); // lifted from node.module node_validate() function. |
| 1518 |
|
} |
| 1519 |
|
|
| 1520 |
|
|
| 1521 |
function contaxe_display($id) { |
function contaxe_display($id) { |
| 1522 |
list ($ret, $output) = contaxe_show_banner($id); |
list ($ret, $output) = contaxe_show_banner($id); |
| 1523 |
return $output; |
return $output; |