| 1 |
<?php
|
| 2 |
// $Id: coolfilter.module,v 1.8 2007/02/22 04:28:29 lllkkk Exp $
|
| 3 |
/*
|
| 4 |
Modules Name: Coolfilter
|
| 5 |
Modules URI: http://drupal.org/node/61357
|
| 6 |
Description: display all kinds of media in drupal.Adds syntax highlighting and line number to your code, base on Text_Highlighter.
|
| 7 |
Version: 0.5
|
| 8 |
Author: liukan
|
| 9 |
Author URI: http://www.kylinx.net/
|
| 10 |
*/
|
| 11 |
function coolfilter_help($section) {
|
| 12 |
if ($section == "admin/modules#description") {
|
| 13 |
return t("Allow the use of coolfilter in your posts.");
|
| 14 |
}
|
| 15 |
}
|
| 16 |
|
| 17 |
function coolfilter_link($type, $node = 0, $main = 0) {
|
| 18 |
|
| 19 |
if (!$main && $type == 'node')
|
| 20 |
{
|
| 21 |
|
| 22 |
$cool_downloadlink = db_fetch_array(db_query('SELECT format,body FROM {node_revisions} WHERE nid = %d', $node->nid));
|
| 23 |
if(db_fetch_array(db_query('SELECT format FROM {filters} WHERE format = %d AND module = "%s"', $cool_downloadlink["format"],"coolfilter")))
|
| 24 |
{
|
| 25 |
if(FALSE!=strstr($cool_downloadlink["body"],"</coolcode>")||FALSE!=strstr($cool_downloadlink["body"],"[/coolcode]"))
|
| 26 |
if(FALSE!=strstr($cool_downloadlink["body"],"download=\""))
|
| 27 |
{
|
| 28 |
$links = array();
|
| 29 |
global $base_url;
|
| 30 |
$cool_downname=$cool_downloadlink["body"];
|
| 31 |
$ii=1;
|
| 32 |
$havedown=0;
|
| 33 |
while($ii)
|
| 34 |
{
|
| 35 |
if(preg_match('#(.*?)\<coolcode(.*?)download="(.*?)\"(.*?)\>(.*?)\</coolcode(?::\w+)?\>(.*?)#sie',$cool_downname,$match_down)){
|
| 36 |
if($havedown==0){
|
| 37 |
$links['coolcode_download_links_name'] = array('title' => t('<br/>Download source code here:<a name="coolcode_download"></a> '),
|
| 38 |
'href'=>NULL,
|
| 39 |
'html'=>TRUE
|
| 40 |
);
|
| 41 |
$havedown=1;
|
| 42 |
}
|
| 43 |
$links[] = array(
|
| 44 |
'title' =>$match_down[3],
|
| 45 |
'href'=>$base_url."/"/*.base_path()*/.drupal_get_path('module', 'coolfilter')."/downcode.php?p=".$node->nid."&download=".$match_down[3]."&multi=".variable_get("coolfilter_variable_multisite", 0),
|
| 46 |
|
| 47 |
);
|
| 48 |
}
|
| 49 |
$cool_downname=strstr($cool_downname,"</coolcode>");
|
| 50 |
if($cool_downname==FALSE)
|
| 51 |
$ii=0;
|
| 52 |
$cool_downname=strstr($cool_downname,"oo");
|
| 53 |
}
|
| 54 |
$cool_downname=$cool_downloadlink["body"];
|
| 55 |
$ii=1;
|
| 56 |
while($ii)
|
| 57 |
{
|
| 58 |
if(preg_match('#(.*?)\[coolcode(.*?)download="(.*?)\"(.*?)\](.*?)\[/coolcode(?::\w+)?\](.*?)#sie',$cool_downname,$match_down))
|
| 59 |
{
|
| 60 |
if($havedown==0){
|
| 61 |
$links['coolcode_download_links_name'] = array('title' => t('<br/>Download source code here:<a name="coolcode_download"></a> '),
|
| 62 |
'href'=>NULL,
|
| 63 |
'html'=>TRUE
|
| 64 |
);
|
| 65 |
$havedown=1;
|
| 66 |
}
|
| 67 |
$links[] = array(
|
| 68 |
'title' =>$match_down[3],
|
| 69 |
'href'=>$base_url."/"/*.base_path()*/.drupal_get_path('module', 'coolfilter')."/downcode.php?p=".$node->nid."&download=".$match_down[3]."&multi=".variable_get("coolfilter_variable_multisite", 0),
|
| 70 |
|
| 71 |
);
|
| 72 |
}
|
| 73 |
$cool_downname=strstr($cool_downname,"[/coolcode]");
|
| 74 |
if($cool_downname==FALSE)
|
| 75 |
$ii=0;
|
| 76 |
$cool_downname=strstr($cool_downname,"oo");
|
| 77 |
}
|
| 78 |
if($havedown==1){
|
| 79 |
$links[] = array('title' => t('.<br/>'),
|
| 80 |
'href'=>NULL,
|
| 81 |
'html'=>TRUE
|
| 82 |
);
|
| 83 |
return $links;
|
| 84 |
}
|
| 85 |
}
|
| 86 |
|
| 87 |
}
|
| 88 |
}
|
| 89 |
|
| 90 |
}
|
| 91 |
|
| 92 |
function coolfilter_menu($may_cache) {
|
| 93 |
$items = array();
|
| 94 |
$path = drupal_get_path('module', 'coolfilter');
|
| 95 |
drupal_add_css($path . '/coolcode.css');
|
| 96 |
drupal_add_js($path . '/coolcode.js');
|
| 97 |
if ((!defined('PHPRPC_JS_CLIENT_LOADED')) || (PHPRPC_JS_CLIENT_LOADED == false)) {
|
| 98 |
drupal_add_js($path . '/phprpc_client.js');
|
| 99 |
define('PHPRPC_JS_CLIENT_LOADED', true);
|
| 100 |
}
|
| 101 |
include("coolplayer_config.php");
|
| 102 |
drupal_set_html_head("<script type=\"text/javascript\"><!--\n" .
|
| 103 |
"coolplayer_plugin_path = \"{$coolplayer_pluginpath}\";\n" .
|
| 104 |
"coolplayer_rpcurl = \"{$coolplayer_rpcurl }\";\n" .
|
| 105 |
"//--></script>\n");
|
| 106 |
drupal_add_js($path . '/coolplayer.js');
|
| 107 |
drupal_set_html_head('<link rel="stylesheet" href="'.$path.'/coolplayer.css" /><!--[if IE]><link rel="stylesheet" href="'. base_path() .'modules/coolfilter/coolplayer_ie.css" /><![endif]-->');
|
| 108 |
$items[] = array(
|
| 109 |
'path' => 'admin/settings/coolfilter',
|
| 110 |
'title' => t('Coolfilter'),
|
| 111 |
'callback' => 'drupal_get_form',
|
| 112 |
'callback arguments' => array('coolfilter_admin_settings'),
|
| 113 |
'access' => user_access('administer site configuration'),
|
| 114 |
'type' => MENU_NORMAL_ITEM
|
| 115 |
);
|
| 116 |
return $items;
|
| 117 |
}
|
| 118 |
function coolfilter_filter_tips($delta, $format, $long = false) {
|
| 119 |
if ($long) {
|
| 120 |
global $base_url;
|
| 121 |
include_once 'coolfilter-help.inc';
|
| 122 |
return _coolfilter_filter_tip($base_url);
|
| 123 |
}
|
| 124 |
else {
|
| 125 |
return t("You can use <a href=\"%coolfilter_help\">coolfilter tags</a> in the text, to include code and media", array("%coolfilter_help" => url("filter/tips/$format", NULL, 'filter-coolfilter')));
|
| 126 |
}
|
| 127 |
}
|
| 128 |
|
| 129 |
function coolfilter_filter($op, $delta = 0, $format = -1, $text = '') {
|
| 130 |
switch ($op) {
|
| 131 |
case 'list':
|
| 132 |
return array(0 => t('CoolFilter'));
|
| 133 |
|
| 134 |
case 'description':
|
| 135 |
return t('Converts coolfilter to html.');
|
| 136 |
|
| 137 |
case 'process':
|
| 138 |
if(FALSE!=strstr($text,"</coolplayer>")||FALSE!=strstr($text,"[/coolplayer]")){
|
| 139 |
include_once 'coolplayer.php';
|
| 140 |
$CoolPlayer = new CoolPlayer();
|
| 141 |
$text1=$CoolPlayer->part_one($text);
|
| 142 |
$text=$CoolPlayer->part_two($text1);
|
| 143 |
unset($CoolPlayer);
|
| 144 |
}
|
| 145 |
if(FALSE!=strstr($text,"</coolcode>")||FALSE!=strstr($text,"[/coolcode]")){
|
| 146 |
include_once 'coolcode.php';
|
| 147 |
$CoolCode = new CoolCode();
|
| 148 |
$text1=$CoolCode->part_one($text);
|
| 149 |
$text=$CoolCode->part_two($text1);
|
| 150 |
unset($CoolCode);
|
| 151 |
}
|
| 152 |
return $text;
|
| 153 |
|
| 154 |
|
| 155 |
case 'settings':
|
| 156 |
global $base_url;
|
| 157 |
|
| 158 |
$form = array();
|
| 159 |
return $form;
|
| 160 |
|
| 161 |
default:
|
| 162 |
return $text;
|
| 163 |
}
|
| 164 |
}
|
| 165 |
|
| 166 |
|
| 167 |
function coolfilter_admin_settings() {
|
| 168 |
global $base_url;
|
| 169 |
|
| 170 |
|
| 171 |
$form = array();
|
| 172 |
$form['coolfilter_filter'] = array(
|
| 173 |
'#type' => 'fieldset',
|
| 174 |
'#title' => t('CoolFilter filter'),
|
| 175 |
'#collapsible' => TRUE,
|
| 176 |
'#collapsed' => FALSE);
|
| 177 |
if(strlen($base_url)<8){
|
| 178 |
$form['coolfilter_filter']["coolfilter_global_base_url"] = array(
|
| 179 |
'#type' => 'textfield',
|
| 180 |
'#disabled' => TRUE,
|
| 181 |
'#title' => t('Notice:in order to use [coolcode] download fuction'),
|
| 182 |
'#default_value' => 'You need configure $base_url at sites/default/settings.php',
|
| 183 |
'#size' => 60,
|
| 184 |
);
|
| 185 |
}
|
| 186 |
$form['coolfilter_filter']["coolfilter_variable_multisite"] = array(
|
| 187 |
'#type' => 'checkbox',
|
| 188 |
'#title' => t('Install coolfilter on drupal multisite'),
|
| 189 |
'#default_value' => variable_get("coolfilter_variable_multisite", 0),
|
| 190 |
'#description' => t('If you install CoolFilter for mutisite, that to say you place it at sites/all/modules/coolfilter, choose this.'));
|
| 191 |
|
| 192 |
$form['coolfilter_filter']["coolfilter_variable_reinstall"] = array(
|
| 193 |
'#type' => 'checkbox',
|
| 194 |
'#title' => t('Reinstall coolfilter'),
|
| 195 |
'#default_value' => variable_get("coolfilter_variable_reinstall", 0),
|
| 196 |
'#description' => t('If the absolute path, where drupal installed, on the server filesystem has been changed, you need check this box. Then you goto <a href="').$base_url.t('/update.php?op=selection">') .$base_url.t('/update.php?op=selection</a> Press"Select versions", choose "coolfilter module" update version 1 and click "update" button to reinstall coolfilter.'));
|
| 197 |
return system_settings_form($form);
|
| 198 |
}
|
| 199 |
|