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