/[drupal]/contributions/modules/linodef/linodef.module
ViewVC logotype

Contents of /contributions/modules/linodef/linodef.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Sat Nov 1 15:43:19 2008 UTC (12 months, 3 weeks ago) by roidanton
Branch: MAIN
CVS Tags: DRUPAL-6--1-0-RC1, HEAD
Branch point for: DRUPAL-6--1
File MIME type: text/x-php
Initial Release of Linodef for Drupal 6.x
1 <?php
2 // $Id$
3
4 /**
5 * @defgroup linodef Linodef: Link nodes and embed fields, link and embed terms
6 *
7 * This module contains several include files. There is an api for submodules which implements buttons in various editors to facilitate the creation of buttons which supports Linodef filter.
8 */
9
10 /**
11 * @file
12 * The main Linodef filter module with filter hooks.
13 *
14 * Linodef is a filter which filters ID tags, add links to nodes and embeds field values.
15 *
16 * @package Linodef
17 * @author Roi Danton
18 */
19
20 /**
21 * Implementation of hook_filter.
22 */
23 function linodef_filter($op, $delta = 0, $format = -1, $text = '') {
24 if ($op == 'list') {
25 return array(
26 0 => t('Linodef - Link nodes & taxonomy terms and embed field values & term names.')
27 );
28 }
29
30 // Provides extensibility.
31 switch ($delta) {
32
33 case 0:
34
35 switch ($op) {
36 case 'description':
37 return t('Substitutes the Node ID for the node title or field value & links to this node. Furthermore Linodef substitutes the term ID for the term name & links to the term.');
38
39 // Since lineodef will return a different result on each page load, we
40 // need to return TRUE for "no cache" to ensure that the filter is run
41 // every time the text is requested.
42 case 'no cache':
43 return TRUE;
44
45 // I tried to use the bytes 0xFE and 0xFF to replace < and > here. These bytes
46 // are not valid in UTF-8 data and thus unlikely to cause problems.
47 // This doesnt work with double quotes "", but we need this in order to execute
48 // the second preg_replace in filter.inc, so valid bytes U+10004C & U+1003CD
49 // have been used.
50 case 'prepare':
51 return preg_replace('@<#([0-9]+)>(.*?)</#>@s', "\xf4\x80\x81\x8c#$1\xf4\x80\x8f\x8d$2\xf4\x80\x81\x8c/#\xf4\x80\x8f\x8d", $text);
52
53 case 'process':
54 include_once(drupal_get_path('module', 'linodef') .'/includes/linodef-filter.inc');
55 return _linodef_filter_process($text, $format);
56 }
57 break;
58 }
59 }
60
61 /**
62 * Implementation of hook_filter_tips.
63 */
64 function linodef_filter_tips($delta, $format, $long = FALSE) {
65 switch ($delta) {
66 case 0:
67 if ($long) {
68 include_once(drupal_get_path('module', 'linodef') .'/includes/linodef-filter-tips.inc');
69 return _linodef_filter_tips();
70 }
71 else {
72 return t('Embeds node title or field values by node ID and terms by term ID (<a href="@format-tips-page">[#8], [#8:field_name], [#8:field_name:2], &lt;#8&gt;Your Text&lt;/#8&gt;, [#t8]</a>).', array('@format-tips-page' => url('filter/tips/'. $format, array('fragment' => 'linodef'))));
73 }
74 break;
75 }
76 }
77
78 /**
79 * Returns default messages that are needed several times and thus should be identical.
80 *
81 * @param array $type
82 * - keys: nid, field or tid etc
83 * - values: the associated value ($nid, $fieldname, $tid)
84 *
85 * @return string
86 * Returns a message.
87 */
88 function linodef_message($type, $message = FALSE) {
89 if ($type['nid']) {
90 $context = t('Node') .' '. $type['nid'];
91 }
92 elseif ($type['field']) {
93 $context = t('Field') .' '. $type['field'];
94 }
95 elseif ($type['tid']) {
96 $context = t('Term') .' '. $type['tid'];
97 }
98 elseif ($type['ctype']) {
99 $context = t('Content type') .' '. $type['ctype'];
100 }
101 elseif ($type['vid']) {
102 $context = t('Vocabulary') .' '. $type['vid'];
103 }
104 elseif ($type['checkinputvar']) {
105 $output = t('Check value for %inputvariable or ask your site administrator.', array('%inputvariable' => $type['checkinputvar']));
106 }
107 elseif ($type['elementtypes']) {
108 $output = t('Supported fields must store a (single or multiple) value such as textfields & datefield (from date).');
109 }
110 else {
111 $output = t('Unknown key for $type in linodef_message().');
112 }
113 if ($context && $message) {
114 switch ($message) {
115 case "access denied":
116 // drupal_access_denied() doesn't fit here because no page should be returned and the pagetitle should not show "Access denied"
117 $output = t('Access to !context denied.', array('!context' => $context));
118 break;
119 case "not found":
120 $output = t('!context not found', array('!context' => $context));
121 break;
122 }
123 }
124 return $output;
125 }

  ViewVC Help
Powered by ViewVC 1.1.2