[ Index ] |
PHP Cross Reference of Textpattern 4.0.8 |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 This is Textpattern 5 6 Copyright 2005 by Dean Allen 7 www.textpattern.com 8 All rights reserved 9 10 Use of this software indicates acceptance of the Textpattern license agreement 11 12 $HeadURL: https://textpattern.googlecode.com/svn/releases/4.0.8/source/textpattern/include/txp_link.php $ 13 $LastChangedRevision: 3069 $ 14 15 */ 16 17 if (!defined('txpinterface')) 18 { 19 die('txpinterface is undefined.'); 20 } 21 22 global $vars; 23 24 if ($event == 'link') 25 { 26 require_privs('link'); 27 28 $vars = array('category', 'url', 'linkname', 'linksort', 'description', 'id'); 29 30 $available_steps = array( 31 'link_list', 32 'link_edit', 33 'link_post', 34 'link_save', 35 'link_delete', 36 'link_change_pageby', 37 'link_multi_edit' 38 ); 39 40 if (!$step or !function_exists($step) or !in_array($step, $available_steps)) 41 { 42 link_edit(); 43 } 44 45 else 46 { 47 $step(); 48 } 49 } 50 51 // ------------------------------------------------------------- 52 53 function link_list($message = '') 54 { 55 global $step, $link_list_pageby; 56 57 extract(gpsa(array('page', 'sort', 'dir', 'crit', 'search_method'))); 58 59 $dir = ($dir == 'desc') ? 'desc' : 'asc'; 60 61 switch ($sort) 62 { 63 case 'id': 64 $sort_sql = 'id '.$dir; 65 break; 66 67 case 'description': 68 $sort_sql = 'description '.$dir.', id asc'; 69 break; 70 71 case 'category': 72 $sort_sql = 'category '.$dir.', id asc'; 73 break; 74 75 case 'date': 76 $sort_sql = 'date '.$dir.', id asc'; 77 break; 78 79 default: 80 $sort = 'name'; 81 $sort_sql = 'linksort '.$dir.', id asc'; 82 break; 83 } 84 85 $switch_dir = ($dir == 'desc') ? 'asc' : 'desc'; 86 87 $criteria = 1; 88 89 if ($search_method and $crit) 90 { 91 $crit_escaped = doSlash($crit); 92 93 $critsql = array( 94 'id' => "ID in ('" .join("','", do_list($crit_escaped)). "')", 95 'name' => "linkname like '%$crit_escaped%'", 96 'description' => "description like '%$crit_escaped%'", 97 'category' => "category like '%$crit_escaped%'" 98 ); 99 100 if (array_key_exists($search_method, $critsql)) 101 { 102 $criteria = $critsql[$search_method]; 103 $limit = 500; 104 } 105 106 else 107 { 108 $search_method = ''; 109 $crit = ''; 110 } 111 } 112 113 else 114 { 115 $search_method = ''; 116 $crit = ''; 117 } 118 119 $total = getCount('txp_link', $criteria); 120 121 if ($total < 1) 122 { 123 if ($criteria != 1) 124 { 125 echo n.link_search_form($crit, $search_method). 126 n.graf(gTxt('no_results_found'), ' class="indicator"'); 127 } 128 129 else 130 { 131 echo n.graf(gTxt('no_links_recorded'), ' class="indicator"'); 132 } 133 134 return; 135 } 136 137 $limit = max($link_list_pageby, 15); 138 139 list($page, $offset, $numPages) = pager($total, $limit, $page); 140 141 echo link_search_form($crit, $search_method); 142 143 $rs = safe_rows_start('*, unix_timestamp(date) as uDate', 'txp_link', "$criteria order by $sort_sql limit $offset, $limit"); 144 145 if ($rs) 146 { 147 echo n.n.'<form action="index.php" method="post" name="longform" onsubmit="return verify(\''.gTxt('are_you_sure').'\')">', 148 149 startTable('list'). 150 151 n.tr( 152 column_head('ID', 'id', 'link', true, $switch_dir, $crit, $search_method, ('id' == $sort) ? $dir : ''). 153 hCell(). 154 column_head('link_name', 'name', 'link', true, $switch_dir, $crit, $search_method, ('name' == $sort) ? $dir : ''). 155 column_head('description', 'description', 'link', true, $switch_dir, $crit, $search_method, ('description' == $sort) ? $dir : ''). 156 column_head('link_category', 'category', 'link', true, $switch_dir, $crit, $search_method, ('category' == $sort) ? $dir : ''). 157 column_head('date', 'date', 'link', true, $switch_dir, $crit, $search_method, ('date' == $sort) ? $dir : ''). 158 hCell() 159 ); 160 161 while ($a = nextRow($rs)) 162 { 163 extract($a); 164 165 $edit_url = '?event=link'.a.'step=link_edit'.a.'id='.$id.a.'sort='.$sort. 166 a.'dir='.$dir.a.'page='.$page.a.'search_method='.$search_method.a.'crit='.$crit; 167 168 echo tr( 169 170 n.td($id, 20). 171 172 td( 173 n.'<ul>'. 174 n.t.'<li>'.href(gTxt('edit'), $edit_url).'</li>'. 175 n.t.'<li>'.href(gTxt('view'), $url).'</li>'. 176 n.'</ul>' 177 , 35). 178 179 td( 180 href(htmlspecialchars($linkname), $edit_url) 181 , 125). 182 183 td( 184 htmlspecialchars($description) 185 , 150). 186 187 td( 188 '<span title="'.htmlspecialchars(fetch_category_title($category, 'link')).'">'.$category.'</span>' 189 , 125). 190 191 td( 192 gTime($uDate) 193 , 75). 194 195 td( 196 fInput('checkbox', 'selected[]', $id) 197 ) 198 ); 199 } 200 201 echo n.n.tr( 202 tda( 203 select_buttons(). 204 link_multiedit_form($page, $sort, $dir, $crit, $search_method) 205 , ' colspan="7" style="text-align: right; border: none;"') 206 ). 207 208 endTable(). 209 '</form>'. 210 211 n.nav_form('link', $page, $numPages, $sort, $dir, $crit, $search_method). 212 213 pageby_form('link', $link_list_pageby); 214 } 215 } 216 217 // ------------------------------------------------------------- 218 219 function link_search_form($crit, $method) 220 { 221 $methods = array( 222 'id' => gTxt('ID'), 223 'name' => gTxt('link_name'), 224 'description' => gTxt('description'), 225 'category' => gTxt('link_category') 226 ); 227 228 return search_form('link', 'link_edit', $crit, $methods, $method, 'name'); 229 } 230 231 // ------------------------------------------------------------- 232 233 function link_edit($message = '') 234 { 235 global $vars, $step; 236 237 pagetop(gTxt('edit_links'), $message); 238 239 extract(gpsa($vars)); 240 241 if ($id && $step == 'link_edit') 242 { 243 $id = assert_int($id); 244 extract(safe_row('*', 'txp_link', "id = $id")); 245 } 246 247 if ($step == 'link_save' or $step == 'link_post') 248 { 249 foreach ($vars as $var) 250 { 251 $$var = ''; 252 } 253 } 254 255 echo form( 256 257 startTable('edit') . 258 259 tr( 260 fLabelCell('title', '', 'link-title'). 261 fInputCell('linkname', $linkname, 1, 30, '', 'link-title') 262 ). 263 264 tr( 265 fLabelCell('sort_value', '', 'link-sort'). 266 fInputCell('linksort', $linksort, 2, 15, '', 'link-sort') 267 ). 268 269 tr( 270 fLabelCell('url', 'link_url', 'link-url'). 271 fInputCell('url', $url, 3, 30, '', 'link-url') 272 ). 273 274 tr( 275 fLabelCell('link_category', 'link_category', 'link-category'). 276 277 td( 278 linkcategory_popup($category).' ['.eLink('category', 'list', '', '', gTxt('edit')).']' 279 ) 280 ) . 281 282 tr( 283 tda( 284 '<label for="link-description">'.gTxt('description').'</label>'.sp.popHelp('link_description') 285 ,' style="text-align: right; vertical-align: top;"'). 286 287 td( 288 '<textarea id="link-description" name="description" cols="40" rows="7" tabindex="4">'.htmlspecialchars($description).'</textarea>' 289 ) 290 ). 291 292 tr( 293 td(). 294 td( 295 fInput('submit', '', gTxt('save'), 'publish') 296 ) 297 ). 298 299 endTable(). 300 301 eInput('link'). 302 303 ($id ? sInput('link_save').hInput('id', $id) : sInput('link_post')). 304 305 hInput('search_method', gps('search_method')). 306 hInput('crit', gps('crit')) 307 , 'margin-bottom: 25px;'); 308 309 echo link_list(); 310 } 311 312 //-------------------------------------------------------------- 313 314 function linkcategory_popup($cat = '') 315 { 316 return event_category_popup('link', $cat, 'link-category'); 317 } 318 319 // ------------------------------------------------------------- 320 function link_post() 321 { 322 global $txpcfg,$vars; 323 $varray = gpsa($vars); 324 325 extract(doSlash($varray)); 326 327 if (!$linksort) $linksort = $linkname; 328 329 $q = safe_insert("txp_link", 330 "category = '$category', 331 date = now(), 332 url = '".trim($url)."', 333 linkname = '$linkname', 334 linksort = '$linksort', 335 description = '$description'" 336 ); 337 338 $GLOBALS['ID'] = mysql_insert_id( ); 339 340 if ($q) 341 { 342 //update lastmod due to link feeds 343 update_lastmod(); 344 345 $message = gTxt('link_created', array('{name}' => $linkname)); 346 347 link_edit($message); 348 } 349 } 350 351 // ------------------------------------------------------------- 352 function link_save() 353 { 354 global $txpcfg,$vars; 355 $varray = gpsa($vars); 356 357 extract(doSlash($varray)); 358 359 if (!$linksort) $linksort = $linkname; 360 $id = assert_int($id); 361 362 $rs = safe_update("txp_link", 363 "category = '$category', 364 url = '".trim($url)."', 365 linkname = '$linkname', 366 linksort = '$linksort', 367 description = '$description'", 368 "id = $id" 369 ); 370 371 if ($rs) 372 { 373 update_lastmod(); 374 375 $message = gTxt('link_updated', array('{name}' => doStrip($linkname))); 376 377 link_edit($message); 378 } 379 } 380 381 // ------------------------------------------------------------- 382 function link_change_pageby() 383 { 384 event_change_pageby('link'); 385 link_edit(); 386 } 387 388 // ------------------------------------------------------------- 389 390 function link_multiedit_form($page, $sort, $dir, $crit, $search_method) 391 { 392 $methods = array( 393 'changecategory' => gTxt('changecategory'), 394 'delete' => gTxt('delete') 395 ); 396 397 return event_multiedit_form('link', $methods, $page, $sort, $dir, $crit, $search_method); 398 } 399 400 // ------------------------------------------------------------- 401 402 function link_multi_edit() 403 { 404 $selected = ps('selected'); 405 406 if (!$selected or !is_array($selected)) 407 { 408 return link_edit(); 409 } 410 411 $selected = array_map('assert_int', $selected); 412 $method = ps('edit_method'); 413 $changed = array(); 414 415 if ($method == 'delete') 416 { 417 foreach ($selected as $id) 418 { 419 if (safe_delete('txp_link', 'id = '.$id)) 420 { 421 $changed[] = $id; 422 } 423 } 424 } 425 elseif ($method == 'changecategory') 426 { 427 foreach ($selected as $id) 428 { 429 if (safe_update('txp_link', "category = '".doSlash(ps('category'))."'", "id = $id")) 430 { 431 $changed[] = $id; 432 } 433 } 434 } 435 436 if ($changed) 437 { 438 return link_edit(gTxt( 439 ($method == 'delete' ? 'links_deleted' : 'link_updated'), 440 array(($method == 'delete' ? '{list}' : '{name}') => join(', ', $changed)))); 441 } 442 443 return link_edit(); 444 } 445 446 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu May 21 23:03:01 2009 | Cross-referenced by PHPXref 0.7 |