| [ Index ] | PHP Cross Reference of Mambo 4.6.5 |
|
| [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Mambo 4 * @subpackage Content 5 * @author Mambo Foundation Inc see README.php 6 * @copyright (C) 2000 - 2009 Mambo Foundation Inc. 7 * See COPYRIGHT.php for copyright notices and details. 8 * @license GNU/GPL Version 2, see LICENSE.php 9 * 10 * Redistributions of files must retain the above copyright notice. 11 * 12 * Mambo is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU General Public License 14 * as published by the Free Software Foundation; version 2 of the License. 15 */ 16 17 /** ensure this file is being included by a parent file */ 18 defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); 19 require_once ($mosConfig_absolute_path.'/components/com_content/content.class.php'); 20 21 // ensure user has access to this function 22 if (!($acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'all' ) 23 | $acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'com_frontpage' ))) { 24 mosRedirect( 'index2.php', T_('You are not authorized to view this resource.') ); 25 } 26 27 // call 28 require_once( $mainframe->getPath( 'admin_html' ) ); 29 require_once( $mainframe->getPath( 'class' ) ); 30 31 $task = mosGetParam( $_REQUEST, 'task', array(0) ); 32 $cid = mosGetParam( $_POST, 'cid', array(0) ); 33 if (!is_array( $cid )) { 34 $cid = array(0); 35 } 36 37 switch ($task) { 38 case 'publish': 39 changeFrontPage( $cid, 1, $option ); 40 break; 41 42 case 'unpublish': 43 changeFrontPage( $cid, 0, $option ); 44 break; 45 46 case 'archive': 47 changeFrontPage( $cid, -1, $option ); 48 break; 49 50 case 'remove': 51 removeFrontPage( $cid, $option ); 52 break; 53 54 case 'orderup': 55 orderFrontPage( $cid[0], -1, $option ); 56 break; 57 58 case 'orderdown': 59 orderFrontPage( $cid[0], 1, $option ); 60 break; 61 62 case 'saveorder': 63 saveOrder( $cid ); 64 break; 65 66 case 'accesspublic': 67 accessMenu( $cid[0], 0 ); 68 break; 69 70 case 'accessregistered': 71 accessMenu( $cid[0], 1 ); 72 break; 73 74 case 'accessspecial': 75 accessMenu( $cid[0], 2 ); 76 break; 77 78 default: 79 viewFrontPage( $option ); 80 break; 81 } 82 83 84 /** 85 * Compiles a list of frontpage items 86 */ 87 function viewFrontPage( $option ) { 88 global $database, $mainframe, $mosConfig_list_limit; 89 90 $catid = $mainframe->getUserStateFromRequest( "catid{$option}", 'catid', 0 ); 91 $filter_authorid = $mainframe->getUserStateFromRequest( "filter_authorid{$option}", 'filter_authorid', 0 ); 92 $filter_sectionid = $mainframe->getUserStateFromRequest( "filter_sectionid{$option}", 'filter_sectionid', 0 ); 93 94 $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ); 95 $limitstart = $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 ); 96 $search = $mainframe->getUserStateFromRequest( "search{$option}", 'search', '' ); 97 $search = $database->getEscaped( trim( strtolower( $search ) ) ); 98 99 $where = array( 100 "c.state >= 0" 101 ); 102 103 // used by filter 104 if ( $filter_sectionid > 0 ) { 105 $where[] = "c.sectionid = '$filter_sectionid'"; 106 } 107 if ( $catid > 0 ) { 108 $where[] = "c.catid = '$catid'"; 109 } 110 if ( $filter_authorid > 0 ) { 111 $where[] = "c.created_by = '$filter_authorid'"; 112 } 113 114 if ($search) { 115 $where[] = "LOWER(c.title) LIKE '%$search%'"; 116 } 117 118 // get the total number of records 119 $query = "SELECT count(*)" 120 . "\n FROM #__content AS c" 121 . "\n LEFT JOIN #__categories AS cc ON cc.id = c.catid" 122 . "\n LEFT JOIN #__sections AS s ON s.id = cc.section AND s.scope='content'" 123 . "\n INNER JOIN #__content_frontpage AS f ON f.content_id = c.id" 124 . (count( $where ) ? "\n WHERE " . implode( ' AND ', $where ) : '' ) 125 ; 126 $database->setQuery( $query ); 127 $total = $database->loadResult(); 128 129 require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' ); 130 $pageNav = new mosPageNav( $total, $limitstart, $limit ); 131 132 $query = "SELECT c.*, g.name AS groupname, cc.name, s.name AS sect_name, u.name AS editor, f.ordering AS fpordering, v.name AS author" 133 . "\n FROM #__content AS c" 134 . "\n LEFT JOIN #__categories AS cc ON cc.id = c.catid" 135 . "\n LEFT JOIN #__sections AS s ON s.id = cc.section AND s.scope='content'" 136 . "\n INNER JOIN #__content_frontpage AS f ON f.content_id = c.id" 137 . "\n INNER JOIN #__groups AS g ON g.id = c.access" 138 . "\n LEFT JOIN #__users AS u ON u.id = c.checked_out" 139 . "\n LEFT JOIN #__users AS v ON v.id = c.created_by" 140 . (count( $where ) ? "\nWHERE " . implode( ' AND ', $where ) : "") 141 . "\n ORDER BY f.ordering" 142 . "\n LIMIT $pageNav->limitstart,$pageNav->limit" 143 ; 144 $database->setQuery( $query ); 145 146 $rows = $database->loadObjectList(); 147 if ($database->getErrorNum()) { 148 echo $database->stderr(); 149 return false; 150 } 151 152 // get list of categories for dropdown filter 153 $query = "SELECT cc.id AS value, cc.title AS text, section" 154 . "\n FROM #__categories AS cc" 155 . "\n INNER JOIN #__sections AS s ON s.id=cc.section " 156 . "\n ORDER BY s.ordering, cc.ordering" 157 ; 158 $categories[] = mosHTML::makeOption( '0', T_('- All Categories -')); 159 $database->setQuery( $query ); 160 $categories = array_merge( $categories, (array)$database->loadObjectList() ); 161 $lists['catid'] = mosHTML::selectList( $categories, 'catid', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', $catid ); 162 163 // get list of sections for dropdown filter 164 $javascript = 'onchange="document.adminForm.submit();"'; 165 $lists['sectionid'] = mosAdminMenus::SelectSection( 'filter_sectionid', $filter_sectionid, $javascript ); 166 167 // get list of Authors for dropdown filter 168 $query = "SELECT c.created_by AS value, u.name AS text" 169 . "\n FROM #__content AS c" 170 . "\n INNER JOIN #__sections AS s ON s.id = c.sectionid" 171 . "\n LEFT JOIN #__users AS u ON u.id = c.created_by" 172 . "\n WHERE c.state <> '-1'" 173 . "\n AND c.state <> '-2'" 174 . "\n GROUP BY u.name" 175 . "\n ORDER BY u.name" 176 ; 177 $authors[] = mosHTML::makeOption( '0', T_('- All Authors -') ); 178 $database->setQuery( $query ); 179 $authors = array_merge( $authors, (array)$database->loadObjectList() ); 180 $lists['authorid'] = mosHTML::selectList( $authors, 'filter_authorid', 'class="inputbox" size="1" onchange="document.adminForm.submit( );"', 'value', 'text', $filter_authorid ); 181 182 HTML_content::showList( $rows, $search, $pageNav, $option, $lists ); 183 } 184 185 /** 186 * Changes the state of one or more content pages 187 * @param array An array of unique category id numbers 188 * @param integer 0 if unpublishing, 1 if publishing 189 */ 190 function changeFrontPage( $cid=null, $state=0, $option ) { 191 global $database, $my; 192 193 if (count( $cid ) < 1) { 194 $action = $publish == 1 ? T_('publish') : ($publish == -1 ? T_('archive') : T_('unpublish')); 195 echo "<script> alert('".sprintf(T_('Select an item to %a'),$action)."'); window.history.go(-1);</script>\n"; 196 exit; 197 } 198 199 $cids = implode( ',', $cid ); 200 201 $query = "UPDATE #__content SET state='$state'" 202 . "\n WHERE id IN ($cids) AND (checked_out=0 OR (checked_out='$my->id'))" 203 ; 204 $database->setQuery( $query ); 205 if (!$database->query()) { 206 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 207 exit(); 208 } 209 210 if (count( $cid ) == 1) { 211 $row = new mosContent( $database ); 212 $row->checkin( $cid[0] ); 213 } 214 215 mosRedirect( "index2.php?option=$option" ); 216 } 217 218 function removeFrontPage( &$cid, $option ) { 219 global $database; 220 221 if (!is_array( $cid ) || count( $cid ) < 1) { 222 echo "<script> alert('".T_('Select an item to delete')."'); window.history.go(-1);</script>\n"; 223 exit; 224 } 225 $fp = new mosFrontPage( $database ); 226 foreach ($cid as $id) { 227 if (!$fp->delete( $id )) { 228 echo "<script> alert('".$fp->getError()."'); </script>\n"; 229 exit(); 230 } 231 $obj = new mosContent( $database ); 232 $obj->load( $id ); 233 $obj->mask = 0; 234 if (!$obj->store()) { 235 echo "<script> alert('".$fp->getError()."'); </script>\n"; 236 exit(); 237 } 238 } 239 $fp->updateOrder(); 240 241 mosRedirect( "index2.php?option=$option" ); 242 } 243 244 /** 245 * Moves the order of a record 246 * @param integer The increment to reorder by 247 */ 248 function orderFrontPage( $uid, $inc, $option ) { 249 global $database; 250 251 $fp = new mosFrontPage( $database ); 252 $fp->load( $uid ); 253 $fp->move( $inc ); 254 255 mosRedirect( "index2.php?option=$option" ); 256 } 257 258 /** 259 * @param integer The id of the content item 260 * @param integer The new access level 261 * @param string The URL option 262 */ 263 function accessMenu( $uid, $access ) { 264 global $database; 265 266 $row = new mosContent( $database ); 267 $row->load( $uid ); 268 $row->access = $access; 269 270 if ( !$row->check() ) { 271 return $row->getError(); 272 } 273 if ( !$row->store() ) { 274 return $row->getError(); 275 } 276 277 mosRedirect( 'index2.php?option=com_frontpage' ); 278 } 279 280 function saveOrder( &$cid ) { 281 global $database; 282 283 $total = count( $cid ); 284 $order = mosGetParam( $_POST, 'order', array(0) ); 285 286 for( $i=0; $i < $total; $i++ ) { 287 // @RawSQLUse, trivial_implementation, UPDATE 288 $query = "UPDATE #__content_frontpage SET ordering='$order[$i]' WHERE content_id = $cid[$i]"; 289 $database->setQuery( $query ); 290 if (!$database->query()) { 291 echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; 292 exit(); 293 } 294 295 // update ordering 296 $row = new mosFrontPage( $database ); 297 $row->load( $cid[$i] ); 298 $row->updateOrder(); 299 } 300 301 $msg = T_('New ordering saved'); 302 mosRedirect( 'index2.php?option=com_frontpage', $msg ); 303 } 304 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed May 23 00:05:01 2012 | Cross-referenced by PHPXref 0.7 |
| Mambo API: Mambo is Free software released under the GNU/General Public License, Version 2 |