Annotation of /mambo/branches/4.7/administrator/components/com_newsfeeds/admin.newsfeeds.php
Parent Directory
|
Revision Log
Revision 917 - (view) (download)
| 1 : | cauld | 917 | <?php |
| 2 : | /** | ||
| 3 : | * @package Mambo Open Source | ||
| 4 : | * @subpackage Newsfeeds | ||
| 5 : | * @copyright (C) 2005 - 2006 Mambo Foundation Inc. | ||
| 6 : | * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL | ||
| 7 : | * | ||
| 8 : | * Mambo was originally developed by Miro (www.miro.com.au) in 2000. Miro assigned the copyright in Mambo to The Mambo Foundation in 2005 to ensure | ||
| 9 : | * that Mambo remained free Open Source software owned and managed by the community. | ||
| 10 : | * Mambo is Free Software | ||
| 11 : | */ | ||
| 12 : | |||
| 13 : | /** ensure this file is being included by a parent file */ | ||
| 14 : | defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); | ||
| 15 : | |||
| 16 : | // ensure user has access to this function | ||
| 17 : | if (!($acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'all' ) | ||
| 18 : | | $acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'com_newsfeeds' ))) { | ||
| 19 : | mosRedirect( 'index2.php', T_('You are not authorized to view this resource.') ); | ||
| 20 : | } | ||
| 21 : | |||
| 22 : | require_once( $mainframe->getPath( 'admin_html' ) ); | ||
| 23 : | require_once( $mainframe->getPath( 'class' ) ); | ||
| 24 : | |||
| 25 : | $task = mosGetParam( $_REQUEST, 'task', array(0) ); | ||
| 26 : | $cid = mosGetParam( $_POST, 'cid', array(0) ); | ||
| 27 : | $id = mosGetParam( $_GET, 'id', 0 ); | ||
| 28 : | if (!is_array( $cid )) { | ||
| 29 : | $cid = array(0); | ||
| 30 : | } | ||
| 31 : | |||
| 32 : | switch ($task) { | ||
| 33 : | |||
| 34 : | case 'new': | ||
| 35 : | editNewsFeed( 0, $option ); | ||
| 36 : | break; | ||
| 37 : | |||
| 38 : | case 'edit': | ||
| 39 : | editNewsFeed( $cid[0], $option ); | ||
| 40 : | break; | ||
| 41 : | |||
| 42 : | case 'editA': | ||
| 43 : | editNewsFeed( $id, $option ); | ||
| 44 : | break; | ||
| 45 : | |||
| 46 : | case 'save': | ||
| 47 : | saveNewsFeed( $option ); | ||
| 48 : | break; | ||
| 49 : | |||
| 50 : | case 'publish': | ||
| 51 : | publishNewsFeeds( $cid, 1, $option ); | ||
| 52 : | break; | ||
| 53 : | |||
| 54 : | case 'unpublish': | ||
| 55 : | publishNewsFeeds( $cid, 0, $option ); | ||
| 56 : | break; | ||
| 57 : | |||
| 58 : | case 'remove': | ||
| 59 : | removeNewsFeeds( $cid, $option ); | ||
| 60 : | break; | ||
| 61 : | |||
| 62 : | case 'cancel': | ||
| 63 : | cancelNewsFeed( $option ); | ||
| 64 : | break; | ||
| 65 : | |||
| 66 : | case 'orderup': | ||
| 67 : | orderNewsFeed( $cid[0], -1, $option ); | ||
| 68 : | break; | ||
| 69 : | |||
| 70 : | case 'orderdown': | ||
| 71 : | orderNewsFeed( $cid[0], 1, $option ); | ||
| 72 : | break; | ||
| 73 : | |||
| 74 : | default: | ||
| 75 : | showNewsFeeds( $option ); | ||
| 76 : | break; | ||
| 77 : | } | ||
| 78 : | |||
| 79 : | /** | ||
| 80 : | * List the records | ||
| 81 : | * @param string The current GET/POST option | ||
| 82 : | */ | ||
| 83 : | function showNewsFeeds( $option ) { | ||
| 84 : | global $database, $mainframe, $mosConfig_list_limit; | ||
| 85 : | |||
| 86 : | $catid = $mainframe->getUserStateFromRequest( "catid{$option}", 'catid', 0 ); | ||
| 87 : | $limit = $mainframe->getUserStateFromRequest( "viewlistlimit", 'limit', $mosConfig_list_limit ); | ||
| 88 : | $limitstart = $mainframe->getUserStateFromRequest( "view{$option}limitstart", 'limitstart', 0 ); | ||
| 89 : | |||
| 90 : | // get the total number of records | ||
| 91 : | $query = "SELECT count(*) FROM #__newsfeeds" | ||
| 92 : | . ( $catid ? "\n WHERE catid='$catid'" : '' ) | ||
| 93 : | ; | ||
| 94 : | $database->setQuery( $query ); | ||
| 95 : | $total = $database->loadResult(); | ||
| 96 : | |||
| 97 : | require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' ); | ||
| 98 : | $pageNav = new mosPageNav( $total, $limitstart, $limit ); | ||
| 99 : | |||
| 100 : | // get the subset (based on limits) of required records | ||
| 101 : | $query = "SELECT a.*, c.name AS catname, u.name AS editor" | ||
| 102 : | . "\n FROM #__newsfeeds AS a" | ||
| 103 : | . "\n LEFT JOIN #__categories AS c ON c.id = a.catid" | ||
| 104 : | . "\n LEFT JOIN #__users AS u ON u.id = a.checked_out" | ||
| 105 : | . ( $catid ? "\n WHERE a.catid='$catid'" : '' ) | ||
| 106 : | . "\n ORDER BY a.ordering" | ||
| 107 : | . "\n LIMIT $pageNav->limitstart,$pageNav->limit" | ||
| 108 : | ; | ||
| 109 : | $database->setQuery( $query ); | ||
| 110 : | |||
| 111 : | $rows = $database->loadObjectList(); | ||
| 112 : | if ($database->getErrorNum()) { | ||
| 113 : | echo $database->stderr(); | ||
| 114 : | return false; | ||
| 115 : | } | ||
| 116 : | |||
| 117 : | // build list of categories | ||
| 118 : | $javascript = 'onchange="document.adminForm.submit();"'; | ||
| 119 : | $lists['category'] = mosAdminMenus::ComponentCategory( 'catid', $option, $catid, $javascript ); | ||
| 120 : | |||
| 121 : | HTML_newsfeeds::showNewsFeeds( $rows, $lists, $pageNav, $option ); | ||
| 122 : | } | ||
| 123 : | |||
| 124 : | /** | ||
| 125 : | * Creates a new or edits and existing user record | ||
| 126 : | * @param int The id of the user, 0 if a new entry | ||
| 127 : | * @param string The current GET/POST option | ||
| 128 : | */ | ||
| 129 : | function editNewsFeed( $id, $option ) { | ||
| 130 : | global $database, $my; | ||
| 131 : | |||
| 132 : | $catid = intval( mosGetParam( $_REQUEST, 'catid', 0 ) ); | ||
| 133 : | |||
| 134 : | $row = new mosNewsFeed( $database ); | ||
| 135 : | // load the row from the db table | ||
| 136 : | $row->load( $id ); | ||
| 137 : | |||
| 138 : | if ($id) { | ||
| 139 : | // do stuff for existing records | ||
| 140 : | $row->checkout( $my->id ); | ||
| 141 : | } else { | ||
| 142 : | // do stuff for new records | ||
| 143 : | $row->ordering = 0; | ||
| 144 : | $row->numarticles = 5; | ||
| 145 : | $row->cache_time = 3600; | ||
| 146 : | $row->published = 1; | ||
| 147 : | } | ||
| 148 : | |||
| 149 : | // build the html select list for ordering | ||
| 150 : | $query = "SELECT a.ordering AS value, a.name AS text" | ||
| 151 : | . "\n FROM #__newsfeeds AS a" | ||
| 152 : | . "\n ORDER BY a.ordering" | ||
| 153 : | ; | ||
| 154 : | $lists['ordering'] = mosAdminMenus::SpecificOrdering( $row, $id, $query, 1 ); | ||
| 155 : | |||
| 156 : | // build list of categories | ||
| 157 : | $lists['category'] = mosAdminMenus::ComponentCategory( 'catid', $option, intval( $row->catid ) ); | ||
| 158 : | // build the html select list | ||
| 159 : | $lists['published'] = mosHTML::yesnoRadioList( 'published', 'class="inputbox"', $row->published ); | ||
| 160 : | |||
| 161 : | HTML_newsfeeds::editNewsFeed( $row, $lists, $option ); | ||
| 162 : | } | ||
| 163 : | |||
| 164 : | /** | ||
| 165 : | * Saves the record from an edit form submit | ||
| 166 : | * @param string The current GET/POST option | ||
| 167 : | */ | ||
| 168 : | function saveNewsFeed( $option ) { | ||
| 169 : | global $database, $my; | ||
| 170 : | |||
| 171 : | $row = new mosNewsFeed( $database ); | ||
| 172 : | if (!$row->bind( $_POST )) { | ||
| 173 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 174 : | exit(); | ||
| 175 : | } | ||
| 176 : | |||
| 177 : | // pre-save checks | ||
| 178 : | if (!$row->check()) { | ||
| 179 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 180 : | exit(); | ||
| 181 : | } | ||
| 182 : | |||
| 183 : | // save the changes | ||
| 184 : | if (!$row->store()) { | ||
| 185 : | echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n"; | ||
| 186 : | exit(); | ||
| 187 : | } | ||
| 188 : | $row->checkin(); | ||
| 189 : | $row->updateOrder(); | ||
| 190 : | |||
| 191 : | mosRedirect( 'index2.php?option='. $option ); | ||
| 192 : | } | ||
| 193 : | |||
| 194 : | /** | ||
| 195 : | * Publishes or Unpublishes one or more modules | ||
| 196 : | * @param array An array of unique category id numbers | ||
| 197 : | * @param integer 0 if unpublishing, 1 if publishing | ||
| 198 : | * @param string The current GET/POST option | ||
| 199 : | */ | ||
| 200 : | function publishNewsFeeds( $cid, $publish, $option ) { | ||
| 201 : | global $database; | ||
| 202 : | |||
| 203 : | if (count( $cid ) < 1) { | ||
| 204 : | $action = $publish ? T_('publish') : T_('unpublish'); | ||
| 205 : | echo "<script> alert('".sprintf(T_('Select a module to %s'), $action)."'); window.history.go(-1);</script>\n"; | ||
| 206 : | exit; | ||
| 207 : | } | ||
| 208 : | |||
| 209 : | $cids = implode( ',', $cid ); | ||
| 210 : | |||
| 211 : | $query = "UPDATE #__newsfeeds SET published='$publish'" | ||
| 212 : | . "\n WHERE id IN ($cids)" | ||
| 213 : | . "\n AND ( checked_out=0 OR (checked_out='$my->id') )" | ||
| 214 : | ; | ||
| 215 : | $database->setQuery( $query ); | ||
| 216 : | if (!$database->query()) { | ||
| 217 : | echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; | ||
| 218 : | exit(); | ||
| 219 : | } | ||
| 220 : | |||
| 221 : | if (count( $cid ) == 1) { | ||
| 222 : | $row = new mosNewsFeed( $database ); | ||
| 223 : | $row->checkin( $cid[0] ); | ||
| 224 : | } | ||
| 225 : | |||
| 226 : | mosRedirect( 'index2.php?option='. $option ); | ||
| 227 : | } | ||
| 228 : | |||
| 229 : | /** | ||
| 230 : | * Removes records | ||
| 231 : | * @param array An array of id keys to remove | ||
| 232 : | * @param string The current GET/POST option | ||
| 233 : | */ | ||
| 234 : | function removeNewsFeeds( &$cid, $option ) { | ||
| 235 : | global $database; | ||
| 236 : | |||
| 237 : | if (!is_array( $cid ) || count( $cid ) < 1) { | ||
| 238 : | echo "<script> alert('".T_('Select an item to delete')."'); window.history.go(-1);</script>\n"; | ||
| 239 : | exit; | ||
| 240 : | } | ||
| 241 : | if (count( $cid )) { | ||
| 242 : | $cids = implode( ',', $cid ); | ||
| 243 : | $query = "DELETE FROM #__newsfeeds" | ||
| 244 : | . "\n WHERE id IN ($cids)" | ||
| 245 : | . "\n AND checked_out='0'" | ||
| 246 : | ; | ||
| 247 : | $database->setQuery( $query ); | ||
| 248 : | if (!$database->query()) { | ||
| 249 : | echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n"; | ||
| 250 : | } | ||
| 251 : | } | ||
| 252 : | |||
| 253 : | mosRedirect( 'index2.php?option='. $option ); | ||
| 254 : | } | ||
| 255 : | |||
| 256 : | /** | ||
| 257 : | * Cancels an edit operation | ||
| 258 : | * @param string The current GET/POST option | ||
| 259 : | */ | ||
| 260 : | function cancelNewsFeed( $option ) { | ||
| 261 : | global $database; | ||
| 262 : | |||
| 263 : | $row = new mosNewsFeed( $database ); | ||
| 264 : | $row->bind( $_POST ); | ||
| 265 : | // sanitize | ||
| 266 : | $row->id = intval($row->id); | ||
| 267 : | $row->checkin(); | ||
| 268 : | mosRedirect( 'index2.php?option='. $option ); | ||
| 269 : | } | ||
| 270 : | |||
| 271 : | /** | ||
| 272 : | * Moves the order of a record | ||
| 273 : | * @param integer The id of the record to move | ||
| 274 : | * @param integer The direction to reorder, +1 down, -1 up | ||
| 275 : | * @param string The current GET/POST option | ||
| 276 : | */ | ||
| 277 : | function orderNewsFeed( $id, $inc, $option ) { | ||
| 278 : | global $database; | ||
| 279 : | |||
| 280 : | $limit = mosGetParam( $_REQUEST, 'limit', 0 ); | ||
| 281 : | $limitstart = mosGetParam( $_REQUEST, 'limitstart', 0 ); | ||
| 282 : | $catid = intval( mosGetParam( $_REQUEST, 'catid', 0 ) ); | ||
| 283 : | |||
| 284 : | $row = new mosNewsFeed( $database ); | ||
| 285 : | $row->load( $id ); | ||
| 286 : | $row->move( $inc ); | ||
| 287 : | |||
| 288 : | mosRedirect( 'index2.php?option='. $option ); | ||
| 289 : | } | ||
| 290 : | root | 1 | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

