2011-03-02 04:36:24 +00:00
< ? php
function manage_content ( & $a ) {
2012-08-31 05:42:51 +00:00
if ( ! get_account_id ()) {
2011-03-02 04:36:24 +00:00
notice ( t ( 'Permission denied.' ) . EOL );
return ;
}
2012-10-02 02:04:21 +00:00
require_once ( 'include/security.php' );
2012-09-03 03:57:44 +00:00
$change_channel = (( argc () > 1 ) ? intval ( argv ( 1 )) : 0 );
2012-10-02 02:04:21 +00:00
2012-11-02 07:55:40 +00:00
if (( argc () > 2 ) && ( argv ( 2 ) === 'default' )) {
$r = q ( " select channel_id from channel where channel_id = %d and channel_account_id = %d limit 1 " ,
2012-11-01 22:45:02 +00:00
intval ( $change_channel ),
intval ( get_account_id ())
);
2012-11-02 07:55:40 +00:00
if ( $r ) {
q ( " update account set account_default_channel = %d where account_id = %d limit 1 " ,
intval ( $change_channel ),
intval ( get_account_id ())
);
}
2012-11-01 22:45:02 +00:00
goaway ( z_root () . '/manage' );
}
2012-09-03 03:30:47 +00:00
if ( $change_channel ) {
2012-10-02 02:04:21 +00:00
$r = change_channel ( $change_channel );
2012-10-04 05:28:19 +00:00
if ( $r && $r [ 'channel_startpage' ])
goaway ( z_root () . '/' . $r [ 'channel_startpage' ]);
2012-09-03 03:57:44 +00:00
goaway ( z_root ());
2012-09-03 03:30:47 +00:00
}
$channels = null ;
2011-03-02 04:36:24 +00:00
2012-08-31 05:42:51 +00:00
if ( local_user ()) {
2013-11-13 02:27:36 +00:00
$r = q ( " select channel.*, xchan.* from channel left join xchan on channel.channel_hash = xchan.xchan_hash where channel.channel_account_id = %d and not ( channel_pageflags & %d ) order by channel_name " ,
intval ( get_account_id ()),
intval ( PAGE_REMOVED )
2012-08-31 05:42:51 +00:00
);
2011-03-02 04:36:24 +00:00
2012-11-02 00:06:34 +00:00
$selected_channel = null ;
2012-11-02 07:55:40 +00:00
$account = get_app () -> get_account ();
2012-11-02 00:06:34 +00:00
2012-09-03 03:30:47 +00:00
if ( $r && count ( $r )) {
$channels = $r ;
2012-11-02 00:06:34 +00:00
for ( $x = 0 ; $x < count ( $channels ); $x ++ ) {
2012-09-26 00:57:20 +00:00
$channels [ $x ][ 'link' ] = 'manage/' . intval ( $channels [ $x ][ 'channel_id' ]);
2012-11-02 00:06:34 +00:00
if ( $channels [ $x ][ 'channel_id' ] == local_user ())
$selected_channel = $channels [ $x ];
2012-11-02 07:55:40 +00:00
$channels [ $x ][ 'default' ] = (( $channels [ $x ][ 'channel_id' ] == $account [ 'account_default_channel' ]) ? " 1 " : '' );
$channels [ $x ][ 'default_links' ] = '1' ;
2012-11-02 00:06:34 +00:00
}
2012-09-03 03:30:47 +00:00
}
2013-09-07 22:21:42 +00:00
$r = q ( " select count(channel_id) as total from channel where channel_account_id = %d " ,
2013-09-09 20:00:39 +00:00
intval ( get_account_id ())
2013-09-07 22:21:42 +00:00
);
$limit = service_class_fetch ( local_user (), 'total_identities' );
if ( $limit !== false ) {
$channel_usage_message = sprintf ( t ( " You have created %1 $ .0f of %2 $ .0f allowed channels. " ), $r [ 0 ][ 'total' ], $limit );
}
else {
$channel_usage_message = '' ;
}
2011-03-02 04:36:24 +00:00
}
2012-09-03 03:30:47 +00:00
$links = array (
2012-11-02 00:06:34 +00:00
array ( 'new_channel' , t ( 'Create a new channel' ), t ( 'Create a new channel' ))
2012-09-03 03:30:47 +00:00
);
2011-03-02 04:36:24 +00:00
2012-08-31 05:42:51 +00:00
$o = replace_macros ( get_markup_template ( 'channels.tpl' ), array (
2012-11-01 22:45:02 +00:00
'$header' => t ( 'Channel Manager' ),
2012-11-02 00:06:34 +00:00
'$msg_selected' => t ( 'Current Channel' ),
'$selected' => $selected_channel ,
2012-11-01 22:45:02 +00:00
'$desc' => t ( 'Attach to one of your channels by selecting it.' ),
2012-11-02 07:55:40 +00:00
'$msg_default' => t ( 'Default Channel' ),
'$msg_make_default' => t ( 'Make Default' ),
2012-11-01 22:45:02 +00:00
'$links' => $links ,
'$all_channels' => $channels ,
2013-09-07 22:21:42 +00:00
'$channel_usage_message' => $channel_usage_message ,
2012-08-31 05:42:51 +00:00
));
2011-03-02 04:36:24 +00:00
return $o ;
2011-05-23 09:39:57 +00:00
}