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

Contents of /contributions/modules/easylink/easylink.module

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


Revision 1.5 - (show annotations) (download) (as text)
Wed Aug 29 21:20:43 2007 UTC (2 years, 2 months ago) by linuxbox
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +92 -29 lines
File MIME type: text/x-php
Added a new permission to allow using easylink without administer permission.  Added a default view and fixed views filters.
1 <?php
2 // $Id: easylink.module,v 1.3.2.1 2007/05/25 15:22:47 linuxbox Exp $
3
4 /**
5 * Implementation of hook_help().
6 */
7 function easylink_help($section) {
8 switch ($section) {
9 case 'admin/modules#description':
10 return t('Enables users easily add links within TinyMCE.');
11 case 'admin/settings/easylink':
12 return t('Here you can configure the view easylink uses to provide the list of nodes within TinyMCE. You may also
13 change the number of nodes displayed per page.');
14 }
15 }
16
17 function easylink_menu($may_cache) {
18 $items = array();
19 if ($may_cache) {
20 $items[] = array(
21 'path' => 'easylink/load',
22 'title' => t('EasyLink'),
23 'callback' => 'easylink_loader',
24 'access' => user_access('use easylink'),
25 'type' => MENU_CALLBACK);
26
27 $items[] = array(
28 'path' => 'admin/settings/easylink',
29 'title' => t('EasyLink'),
30 'callback' => 'drupal_get_form',
31 'callback arguments' => array('easylink_admin_settings'),
32 'access' => user_access('administer easylink'),
33 'type' => MENU_NORMAL_ITEM);
34 } else {
35 $path = drupal_get_path('module', 'easylink');
36
37 // the base url here is used for popup windows
38 $js_base_url = "\n<script type=\"text/javascript\"><!--\n";
39 $js_base_url .= " var BASE_URL = \"" . base_path() . "\";\n";
40 $js_base_url .= "--></script>\n";
41 drupal_set_html_head($js_base_url);
42
43 }
44 return $items;
45 }
46
47 /**
48 * Implementation of hook_perm().
49 */
50 function easylink_perm() {
51 $array = array('administer easylink', 'use easylink');
52
53 return $array;
54 }
55
56
57 /**
58 * Print the main easylink interface
59 */
60 function easylink_loader() {
61
62 $editor = arg(2) ? arg(2) : 'textarea';
63
64 $title = t('EasyLink');
65 $bp = base_path();
66 $output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN">' . "\n";
67 $output .= "<html>\n";
68 $output .= "<head>\n";
69 $output .= "<title>EasyLink</title>\n";
70 $output .= '<style type="text/css" media="all">@import "'.$bp.'misc/drupal.css";</style>';
71 $output .= '<style type="text/css" media="all">@import "'.$bp.path_to_theme().'/style.css";</style>';
72 $output .= '<style type="text/css">#pager {text-align: left; }</style>';
73 $output .= "\n<script type=\"text/javascript\"><!--\n";
74 $output .= " var BASE_URL = \"" . base_path() . "\";\n";
75 $output .= "--></script>\n";
76
77 $path = drupal_get_path('module', 'easylink');
78 $tinymce_path = drupal_get_path('module', 'tinymce');
79 $tinymce_js = base_path() . $tinymce_path . '/tinymce/jscripts/tiny_mce/tiny_mce_popup.js';
80 $easylink_js = base_path() . $tinymce_path . '/tinymce/jscripts/tiny_mce/plugins/easylink/jscripts/easylink.js';
81
82 $output .= "<script type=\"text/javascript\" src=\"$tinymce_js\"></script>\n"; // splitting the tag helps Dreamweaver color coding
83 $output .= "<script type=\"text/javascript\" src=\"$easylink_js\"></script>\n";
84
85 $output .= "</head>\n\n";
86 $output .= '<html><div id="content"><div id="main"><div class="mw1">';
87
88 // Load view
89 $myview = views_get_view(variable_get('easylink_view', 'easylink'));
90 // Override url to support views filters
91 $myview->url = "easylink/load";
92 // Build view
93 $output .= views_build_view('embed', $myview, FALSE, TRUE, 15);
94
95 // Add javascript onClick action to insert link except on pager links
96 $output = preg_replace_callback('/<a href=".*">/i', "check_pager", $output);
97 $output .= "</div></div></div></html>\n";
98
99 print $output;
100 }
101
102 // Check if link is a pager link or not. Only replace non-pager links
103 function check_pager($matches){
104 foreach ($matches as $match){
105 if (preg_match('/.*\?page=/', $match)||preg_match('/.*\?sort=/', $match)){
106 return $match;
107 } else {
108 // Reg-ex fix from Jose San Martin
109 $search = '/<a href="(.*?)"[^>]*>/i';
110 $replace = '<a href="javascript:void(0);" onClick="addLink(\'$1\')">';
111 return preg_replace($search, $replace, $match);
112 }
113 }
114 }
115
116 // Implementation of hook_settings()
117 function easylink_admin_settings() {
118
119 $form['easylink_view'] = array(
120 '#type' => 'textfield',
121 '#title' => t('View to use for easylink plugin'),
122 '#size' => 50,
123 '#maxlength' => 100,
124 '#description' => t("The path to the view that will give a list of pages that can be linked to."),
125 '#default_value' => variable_get('easylink_view', 'easylink'),
126 );
127
128 return system_settings_form($form);
129 }
130
131 function easylink_views_default_views(){
132 $view = new stdClass();
133 $view->name = 'easylink';
134 $view->url = 'easylink';
135 $view->description = 'The basic easylink view shows all pages belonging to the current user';
136 $view->access = array (
137 0 => '2',
138 );
139 $view->view_args_php = '';
140 $view->page = TRUE;
141 $view->page_title = 'EasyLink';
142 $view->page_header = '';
143 $view->page_header_format = '3'; $view->page_footer = '';
144 $view->page_footer_format = '3';
145 $view->page_empty = '';
146 $view->page_empty_format = '3';
147 $view->page_type = 'table';
148 $view->url = 'easylink';
149 $view->use_pager = TRUE;
150 $view->nodes_per_page = '50';
151 $view->sort = array (
152 );
153 $view->argument = array (
154 );
155 $view->field = array (
156 array (
157 'tablename' => 'node',
158 'field' => 'title',
159 'label' => 'Page Title',
160 'handler' => 'views_handler_field_nodelink_with_mark',
161 'sortable' => '1',
162 'defaultsort' => 'ASC',
163 'options' => 'link',
164 ),
165 );
166 $view->filter = array (
167 array (
168 'tablename' => 'node',
169 'field' => 'type',
170 'operator' => 'OR',
171 'options' => '',
172 'value' => array (
173 0 => 'page',
174 ),
175 ),
176 array (
177 'tablename' => 'node',
178 'field' => 'currentuid',
179 'operator' => '=',
180 'options' => '',
181 'value' => '***CURRENT_USER***',
182 ),
183 );
184 $view->exposed_filter = array (
185 );
186 $view->requires = array(node);
187 $views[$view->name] = $view;
188 return $views;
189 }

  ViewVC Help
Powered by ViewVC 1.1.2