|
@@ -0,0 +1,249 @@
|
|
|
+<?php
|
|
|
+/**
|
|
|
+ * A module to display blocks selected by terms in a taxonomy vocabulary,
|
|
|
+ * as long as they are newer than a set limit
|
|
|
+ *
|
|
|
+ * The module defines one block for each term in the vocabulary.
|
|
|
+ *
|
|
|
+ * Settings allows the administrator to choose
|
|
|
+ * - the vocabulary to be used to select nodes
|
|
|
+ * - the number of days nodes are considered for display
|
|
|
+ *
|
|
|
+ * Blocks without matching nodes do not appear.
|
|
|
+ *
|
|
|
+ * This file contains the drupal "glue"
|
|
|
+ *
|
|
|
+ * @author Frederic G. MARAND
|
|
|
+ * @version CVS: $Id: taxonews.module,v 1.10.6.9 2008/06/15 21:19:36 fgm Exp $
|
|
|
+ * @copyright 2005-2008 Ouest Systèmes Informatiques (OSI)
|
|
|
+ * @license http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
|
|
|
+ * @link http://drupal.org/project/taxonews
|
|
|
+ * @since Version 1.1
|
|
|
+ * @package taxonews
|
|
|
+ */
|
|
|
+
|
|
|
+class Links_Filter
|
|
|
+ {
|
|
|
+ const PATH_SETTINGS = 'admin/settings/links_filter';
|
|
|
+
|
|
|
+ static public function adminSettings()
|
|
|
+ {
|
|
|
+ $form =array();
|
|
|
+
|
|
|
+ return $form;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * check requirements
|
|
|
+ * PHP 6 not yet tested either
|
|
|
+ */
|
|
|
+list($major, $minor, $patch) = explode('.', PHP_VERSION);
|
|
|
+if (($major != 5) || ($minor == 0))
|
|
|
+ {
|
|
|
+ die('Links_filter requires PHP ≥ 5.1. You are using PHP ' . PHP_VERSION);
|
|
|
+ }
|
|
|
+unset($major, $minor, $patch);
|
|
|
+
|
|
|
+$_links_filterErrorReporting = error_reporting(E_ALL | E_STRICT);
|
|
|
+
|
|
|
+/**
|
|
|
+ * Until a more generic way to use class methods as callbacks is available
|
|
|
+ * or included in core
|
|
|
+ *
|
|
|
+ * @param string $method The name of the method to be invoked
|
|
|
+ * @return mixed Returns the result of the invoked method
|
|
|
+ */
|
|
|
+function _links_filter_form_rerouter($method)
|
|
|
+ {
|
|
|
+ $args = func_get_args();
|
|
|
+ $ret = call_user_func_array(array('Links_filter', $method), $args);
|
|
|
+ return $ret;
|
|
|
+ }
|
|
|
+
|
|
|
+function _links_filter_process($text)
|
|
|
+ {
|
|
|
+ $arBacktrace = debug_backtrace();
|
|
|
+ $log = NULL;
|
|
|
+ watchdog('links_filter', var_export($arBacktrace, true), WATCHDOG_NOTICE);
|
|
|
+ if (count($arBacktrace) >= 7)
|
|
|
+ {
|
|
|
+ $bt5 = $arBacktrace[5];
|
|
|
+ $bt6 = $arBacktrace[6];
|
|
|
+
|
|
|
+ if ($bt6['function'] = 'node_build_content') // viewing or indexing a node: log its nid/vid
|
|
|
+ {
|
|
|
+ //dsm("Viewing nid " . $bt6['args'][0]->nid . ' vid ' . $bt6['args'][0]->vid);
|
|
|
+ $log = array(0, 'node', $bt6['args'][0]->nid, $bt6['args'][0]->vid);
|
|
|
+ }
|
|
|
+ elseif ($bt5['function'] == 'block_block' && $bt5['args'][0] == 'view')
|
|
|
+ {
|
|
|
+ //dsm("Viewing custom block delta " . $bt5['args'][1]);
|
|
|
+ $log = array(0, 'block', $bt5['args'][1], 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!empty($log))
|
|
|
+ {
|
|
|
+ $sqCount = 'SELECT count(lfl.lfl_id) '
|
|
|
+ . 'FROM {lf_links} lfl '
|
|
|
+ . "WHERE /* id %d */ lfl.module = '%s' AND lfl.key1 = %d AND lfl.key2 = %d "
|
|
|
+ . " AND lfl.url = '%s' ";
|
|
|
+ /*
|
|
|
+ * This is an admin-only module, so we do NO access control
|
|
|
+ */
|
|
|
+ $arMatches = array();
|
|
|
+ // @todo PREG can probably be improved
|
|
|
+ $matchCount = preg_match_all('@<a\s.*href="(.*)".*>@iU', $text, $arMatches);
|
|
|
+ if ($matchCount > 0)
|
|
|
+ {
|
|
|
+ foreach ($arMatches[1] as $match)
|
|
|
+ {
|
|
|
+ $log[4] = $match;
|
|
|
+ $count = db_result(db_query($sqCount, $log));
|
|
|
+ if ($count == 0)
|
|
|
+ {
|
|
|
+ $newLid = db_next_id('link_filter_lfl_id');
|
|
|
+ $log[0] = $newLid;
|
|
|
+ $sqInsert = 'INSERT INTO {lf_links} '
|
|
|
+ . '(lfl_id, module, key1, key2, url) '
|
|
|
+ . " VALUES (%d, '%s', %d, %d, '%s') ";
|
|
|
+ db_query($sqInsert, $log);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * -----------------------------------------------------------------------------
|
|
|
+ * Drupal hooks below
|
|
|
+ * -----------------------------------------------------------------------------
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * Implement hook_help
|
|
|
+ *
|
|
|
+ * @param string $section
|
|
|
+ * @return string HTML
|
|
|
+ */
|
|
|
+function links_filter_help($section)
|
|
|
+ {
|
|
|
+ $ret = NULL;
|
|
|
+ $help = t('<p>Store a list of links present in filtered content.</p>') ;
|
|
|
+ switch ($section)
|
|
|
+ {
|
|
|
+ case 'admin/help#links_filter':
|
|
|
+ $ret = $help
|
|
|
+ . t('<p>More help later.</p>');
|
|
|
+ break;
|
|
|
+ case 'admin/modules#description':
|
|
|
+ $ret = $help;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return $ret;
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Implement hook_block
|
|
|
+ *
|
|
|
+ * @param string $op list|view|configure|save
|
|
|
+ * @param int $delta
|
|
|
+ * @param array $edit
|
|
|
+ * @return mixed either void or HTML for blocks/block list
|
|
|
+ * @see Taxonews::blockList
|
|
|
+ * @see Taxonews::blockView
|
|
|
+ */
|
|
|
+function links_filter_block($op = 'list', $delta = 0, $edit = array())
|
|
|
+ {
|
|
|
+ $ret = NULL;
|
|
|
+ switch ($op)
|
|
|
+ {
|
|
|
+ case 'list': break;
|
|
|
+ case 'view': break;
|
|
|
+ case 'configure': break;
|
|
|
+ case 'save': break;
|
|
|
+ default: break;
|
|
|
+ }
|
|
|
+ return $ret;
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
+ * Implement hook_menu
|
|
|
+ *
|
|
|
+ * @param boolean $may_cache
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+function links_filter_menu($may_cache)
|
|
|
+ {
|
|
|
+ if ($may_cache)
|
|
|
+ {
|
|
|
+ $items[] = array
|
|
|
+ (
|
|
|
+ 'title' => t('Links filter'),
|
|
|
+ 'description' => t('Define the various parameters used by the links_filter module'),
|
|
|
+ 'path' => Links_filter::PATH_SETTINGS,
|
|
|
+ 'callback' => 'drupal_get_form',
|
|
|
+ 'callback arguments' => array('_links_filter_form_rerouter', 'adminSettings'),
|
|
|
+ 'access' => user_access('administer site configuration'),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ return $items;
|
|
|
+ }
|
|
|
+
|
|
|
+function links_filter_filter_tips($delta, $format, $long = FALSE)
|
|
|
+ {
|
|
|
+ dsm(array("links_filter_filter_tips", 'delta' => $delta, 'format' => $format, 'long' => ($long ? 'True' : 'False')));
|
|
|
+ $ret = 'Links in content are logged for later analytics. Does not modifiy content display';
|
|
|
+ return $ret;
|
|
|
+ }
|
|
|
+
|
|
|
+function links_filter_filter($op, $delta = 0, $format = -1, $text = '')
|
|
|
+ {
|
|
|
+ //dsm(array('lf_filter', 'op' => $op, 'delta' => $delta, 'format' => $format, 'text' => check_plain($text)));
|
|
|
+ switch ($op)
|
|
|
+ {
|
|
|
+ case 'list': // provide a list of available filters. Returns an associative array of filter names with numerical keys. These keys are used for subsequent operations and passed back through the $delta parameter.
|
|
|
+ $ret = array
|
|
|
+ (
|
|
|
+ 'Links filter',
|
|
|
+ );
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'no cache': // Return true if caching should be disabled for this filter.
|
|
|
+ $ret = TRUE;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'description': // Return a short description of what this filter does.
|
|
|
+ $ret = 'Catch links in content for analysis';
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'prepare': // Return the prepared version of the content in $text.
|
|
|
+ $ret = $text;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'process': // Return the processed version of the content in $text.
|
|
|
+ _links_filter_process($text);
|
|
|
+ return $text;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'settings': // Return HTML form controls for the filter's settings.
|
|
|
+ // These settings are stored with variable_set() when the form is submitted.
|
|
|
+ // Remember to use the $format identifier in the variable and control names
|
|
|
+ // to store settings per input format (e.g. "mymodule_setting_$format").
|
|
|
+ $form = array();
|
|
|
+ $form['boo'] = array
|
|
|
+ (
|
|
|
+ '#type' => 'markup',
|
|
|
+ '#value' => '<p>Some markup</p>',
|
|
|
+ );
|
|
|
+ $ret = $form;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $ret;
|
|
|
+ }
|
|
|
+
|
|
|
+error_reporting($_links_filterErrorReporting);
|
|
|
+unset($_links_filterErrorReporting);
|