php if defined BASEPATH exit No direct script access allowed Comment t

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');//Comment this string for use outside codeigniter:
/**
* CodeIgniter Ninja Editor Helper
*
* @package CodeIgniter
* @subpackage Helpers
* @category Helpers
* @author recoilme
* @link http://recoilme.ru/ninja
*/
// ------------------------------------------------------------------------
/**
* JS Insert Ninja
*
* Generates the javascript function needed to insert ninja editor tags
*
* @access public
* @return string
*/
if ( ! function_exists('js_insert_ninja'))
{
function js_insert_ninja()
{
return <<<EOF
<script type="text/javascript">
function voidPutATag(Tag,Tag2,AreaName)
{
if (window.attachEvent && navigator.userAgent.indexOf('Opera') === -1) {
allAreas = document.getElementsByName(AreaName);
var doc = allAreas[0];
doc.focus();
sel = document.selection.createRange();
sel.text = Tag+sel.text+Tag2;
doc.focus();
}
else {
allAreas = document.getElementsByName(AreaName);
var doc = allAreas[0];
var ss = doc.scrollTop;
sel1 = doc.value.substr(0, doc.selectionStart);
sel2 = doc.value.substr(doc.selectionEnd);
sel = doc.value.substr(doc.selectionStart,
doc.selectionEnd - doc.selectionStart);
var text = doc.firstChild;
doc.value = sel1 + Tag + sel + Tag2 + sel2;
selPos = Tag.length + sel1.length + sel.length + Tag2.length;
doc.setSelectionRange(sel1.length, selPos);
doc.scrollTop = ss;
}
}
</script>
EOF;
}
}
// ------------------------------------------------------------------------
/**
* CSS Insert Ninja
*
* Generates the CSS style needed for editor panel
*
* @access public
* @param string width of toolbar, '100%'
* @param string path to toolbar.gif, '/themes/img/toolbar.gif'
* @return string
*/
if ( ! function_exists('css_insert_ninja'))
{
function css_insert_ninja($width='100%',$toolbar='/themes/img/toolbar.gif')
{
return <<<EOF
<style type="text/css">
/*Ninja Editor*/
/* Toolbar */
#toolbar {
position: relative;
list-style-type: none;
list-style-position: inside;
background-color: #f3f3f3;
border: 1px solid #c7c7c7;
margin: 0;
padding: 0 2px 0 2px;
height: 24px;
margin-bottom: 6px;
width: {$width};
}
#toolbar li {
list-style:none;
margin: 2px 0 2px 0;
padding: 0;
float:left;
}
#toolbar li a {
width:18px;
height:18px;
float:left;
display:block;
background-color: transparent;
background-repeat: no-repeat;
background-image:url("{$toolbar}");
border: 1px solid #f3f3f3;
}
#toolbar li a:hover {
border: 1px solid #707070;
background-color: #e0e0e0;
}
#toolbar li span {
display: none;
}
#bold_button {
background-position: -36px 0;
}
#italic_button {
background-position: -108px 0;
}
#underline_button {
background-position: -306px 0;
}
#strike_button {
background-position: -234px 0;
}
#link_button {
background-position: -342px 0;
}
#img_button {
background-position: -324px 0;
}
</style>
EOF;
}
}
// ------------------------------------------------------------------------
/**
* HTML Insert Ninja panel
*
* Generates the html needed for ninja editor panel
*
* @access public
* @param string name for textarea field, 'msg_body'
* @return string
*/
if ( ! function_exists('html_insert_ninja'))
{
function html_insert_ninja($textarea_name='msg_body')
{
return <<<EOF
<div style = "width:500px;">
<ul id=toolbar>
<li><a id=bold_button href="javascript: voidPutATag('[b]', '[/b]','{$textarea_name}')"><span>Bold</span></a></li>
<li><a id=italic_button href="javascript: voidPutATag( '[i]','[/i]','{$textarea_name}')"><span>Italic</span></a></li>
<li><a id=strike_button href="javascript: voidPutATag( '[я идиот]','[/я идиот]','{$textarea_name}')"><span>Strike</span></a></li>
<li><a id=link_button href="javascript: voidPutATag('[url=\'сцылко\']','[/url]','{$textarea_name}')"><span>Link</span></a></li>
<li><a id=php_button href="javascript: voidPutATag('[php]','[/php]','{$textarea_name}')"><div style = "font-size:9px;color:#818D8F;">php</div></a></li>
<li><a id=img_button href="javascript: voidPutATag('[img]','[/img]','{$textarea_name}')"><span>img</span></a></li>
</ul>
</div>
EOF;
}
}
// ------------------------------------------------------------------------
/**
* BBcode Parse
*
* Takes a string as input and swaps any contained code for the actual html code
*
* @access public
* @param string the text to be parsed
* @param string the URL to the folder containing the smiley images
* @return string
*/
if ( ! function_exists('bb_parse'))
{
function bb_parse($str="")
{
//url
$str = preg_replace('#(\[URL=\')(.*?)(\'\])(.*?)(\[/URL\])#si', '<noindex><a href="\\2" rel=\"nofollow\" target=_blank>\\4</a></noindex>', $str);
//img
$str = preg_replace('#(\[IMG\])(.*?)(\[/IMG\])#si', '<img src="\\2" />', $str);
//i
$str = preg_replace('#(\[I\])(.*?)(\[/I\])#si', '<em>\\2</em>', $str);
//strike
$str = preg_replace('#(\[я идиот\])(.*?)(\[/я идиот\])#si', '<strike>\\2</strike>', $str);
//b
$str = preg_replace('#(\[B\])(.*?)(\[/B\])#si', '<strong>\\2</strong>', $str);
//php
$str = preg_replace_callback(
'#(\[php\]|<\?)(.*?)(\[/php\]|\?>)#si',
create_function('$matches',
'$s = str_replace("[php]","<?php",$matches[0]);'.
'$s = str_replace("[/php]","?>",$s);'.
'$s = str_replace("\r","",$s);'.
'$s = str_replace(array("&amp;lt;", "&amp;gt;","&quot;","&gt;","&lt;"
), array("<", ">","\"",">","<"), $s);'.//un_htmlspecialchars
'ob_start();highlight_string($s);$s = ob_get_contents();ob_end_clean();'.
'return $s;'),$str);
//echo $str;exit();
return $str;
}
}
// ------------------------------------------------------------------------
/**
* Parse text Ninja
*
* Takes a string as input and swaps any contained code and urls in html
*
* @access public
* @param string the text to be parsed
* @param bool use htmlspecialchars for safe insert
* @return string
*/
if ( ! function_exists('text_process'))
{
function text_process($text="",$removehakers=true)
{
if ($removehakers) $text = htmlspecialchars($text);//идите в жопу хакеры малолетки
$text = bb_parse($text);
$text = str_replace(' ninja ',' <a href="http://recoilme.ru" title="Recoilme\'s Ninja editor"><img src="http://recoilme.ru/favicon.gif"></a> ',$text);//just_for_fun
if (strpos(strtolower("1".$text),"<a")>0 or strpos(strtolower("1".$text),"<img")>0){
return $text;// for unsafe insert links by editor
} else {
//преобразуем http:// в ссылки, http://..gif - в картинки
$processedtxt = preg_replace_callback(
"#[^(\"')]?[hHtTpP]{4}[:]\/\/[a-zA-z.\/0-9-+?=&%\#;]*#",
create_function('$matches',
'$pos = strpos(strtolower($matches[0]),"http");$first=\'\';'.
'if ($pos == 1) {$first=substr($matches[0],0,1); $matches[0] = substr($matches[0],1);}'.
'$ext= substr(strtolower($matches[0]),strlen($matches[0])-3);'.
'if ($ext == "gif" or $ext == "jpg" or $ext == "png") return "<img src=\"$matches[0]\">";'.
'else return "$first<noindex><a rel=\"nofollow\" target=_blank href=\"$matches[0]\">$matches[0]</a></noindex>";'),$text);
return $processedtxt;
}
}
}
// ------------------------------------------------------------------------
/* End of file ninja_helper.php */
/* Location: ./system/helpers/ninja_helper.php */