forum_id ); $forum_name = sprintf( '%2$s', $forum_link, $forum->forum_name ); $checked = ''; $class = ''; if ( $support_forums_settings->isEnabled() && in_array( $forum->forum_id, $support_forums_settings->forums ) ) { // Plugin is enabled and forum is a support forum $checked = ' checked="checked"'; $class = ' class="alt"'; } $checkbox = sprintf( '', 'support-forum-' . $forum->forum_id, 'support_forum_' . $forum->forum_id, $forum->forum_id, $checked, __( 'Turn into support forum', SUPPORT_FORUMS_ID ) ); ?> >
forum_id; ?>
 
forum_desc; ?>
__( 'Default support status', SUPPORT_FORUMS_ID ), 'type' => 'radio', 'options' => $support_forums_settings->statuses ) ); bb_option_form_element( 'support_forums_settings[poster_setable]', array( 'title' => __( 'Poster setable', SUPPORT_FORUMS_ID ), 'type' => 'checkbox', 'options' => array( 1 => __( 'Users can set topic support status on creation.', SUPPORT_FORUMS_ID ) ) ) ); bb_option_form_element( 'support_forums_settings[poster_changeable]', array( 'title' => __( 'Poster changeable', SUPPORT_FORUMS_ID ), 'type' => 'checkbox', 'options' => array( 1 => __( 'Support topic poster can change its status at anytime.', SUPPORT_FORUMS_ID ) ) ) ); ?>

areViewsEnabled(); foreach ( $support_forums_settings->statuses as $status => $display ) { $checked = ( $views_enabled && in_array( $status, $support_forums_settings->views ) ) ? ' checked="checked"' : ''; printf( '
%2$s', str_replace( '_', '-', $status ), "\n" ); printf( '
%1$s
%2$s', ucfirst( $display ), // ucfirst() capitalizes string first char "\n" ); echo '
' . "\n"; echo '' . "\n"; echo '
' . "\n"; echo '
' . "\n"; } ?>

areIconsEnabled(); printf( '%2$s', ( $icons_enabled && array_key_exists( 'dir', $support_forums_settings->icons ) ) ? $support_forums_settings->icons['dir'] : '', "\n" ); ?>

%s.', 'my-support-icons/' ); ?>

images/ directory.' ); ?>

icons ) ) ? SUPPORT_FORUMS_ACTIVE_TEMPLATE_IMAGES_URI . $support_forums_settings->icons['dir'] : SUPPORT_FORUMS_ICONS_URI; foreach ( $support_forums_settings->statuses as $status => $display ) printf( '

- %3$s

', $icons_uri . SUPPORT_FORUMS_ID, str_replace( '_', '-', $status ), $display ); ?>
__( 'closed', SUPPORT_FORUMS_ID ), 'sticky' => __( 'sticky', SUPPORT_FORUMS_ID ) ) as $status => $display ) : printf( '
%2$s', $status, "\n" ); $label = sprintf( __( '%s topics icon', SUPPORT_FORUMS_ID ), $display ); printf( '
%1$s
%2$s', ucfirst( $label ), // ucfirst() capitalizes string first char "\n" ); echo '
' . "\n"; echo '', $status, ( $icons_enabled && in_array( $status, $support_forums_settings->icons ) ) ? ' checked="checked"' : '', $label ); printf( '

%3$s - %3$s

', $icons_uri . SUPPORT_FORUMS_ID, $status, $display ); ?>
$entry * - - - - - - - - - - - - - - - - - - - - - - - - - - - - * support_forum_N N * support_forums_settings array() * * $key $entry as $_key => $_entry * - - - - - - - - - - - - - - - - - - - - - - - - - - - - * default_status 'not_support' * poster_setable 1 * poster_changeable 1 * views array() * icons array() * * $_key $_entry * - - - - - - - - - - - - - - - - - - - - - - - - - - - - * not_resolved 1 * ... * dir 'my-support-icons/' * sticky 1 * ... * * = = = = = = = = = = = = = = = = = = = = = = = = = = = = * * * @global $bb_admin_body_class * @global $bbdb * * @uses bb_check_admin_referer() * @uses wp_get_referer() * @uses remove_query_arg() * @uses bb_delete_option() * @uses add_query_arg() * @uses bb_safe_redirect() * @uses import_support_forum_settings() * @uses bb_get_active_theme_directory() * @uses bb_update_option() * @uses bb_admin_notice() * * @return void */ function support_forums_configuration_page_process() { if ( 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && !empty( $_POST['action'] ) && 'update-support-forums-settings' == $_POST['action'] ) { bb_check_admin_referer( 'options-support-forums-update' ); $goback = remove_query_arg( array( 'support-forums-updated', 'icons-directory-invalid', 'support-forums-uninstalled', 'support-forum-settings-imported', 'support-forum-settings-import-error' ), wp_get_referer() ); if ( empty( $_POST['support_forums_uninstall'] ) ) $_POST['support_forums_uninstall'] = false; if ( (bool) $_POST['support_forums_uninstall'] ) { // Remove plugin data from database global $bbdb; bb_delete_option( 'support_forums_settings' ); $bbdb->query( $bbdb->prepare( "DELETE FROM $bbdb->meta WHERE meta_key = %s", 'topic_support_status' ) ); // Remove plugin inserted topic meta (there could be none) $goback = add_query_arg( 'support-forums-uninstalled', 'true', $goback ); bb_safe_redirect( $goback ); exit; } if ( empty( $_POST['support_forums_import_settings'] ) ) $_POST['support_forums_import_settings'] = false; if ( (bool) $_POST['support_forums_import_settings'] ) { // Import Support Forum settings if ( empty( $_POST['support_forums_remove_settings'] ) ) $_POST['support_forums_remove_settings'] = false; $goback = ( import_support_forum_settings( (bool) $_POST['support_forums_remove_settings'] ) ) ? add_query_arg( 'support-forum-settings-imported', 'true', $goback ) : add_query_arg( 'support-forum-settings-import-error', 'true', $goback ); bb_safe_redirect( $goback ); exit; } // Temporary var for options $requested_settings = array(); foreach ( (array) $_POST as $option => $value ) // $option = ( support_forums_settings | support_forum_#id ) if ( !in_array( $option, array( '_wpnonce', '_wp_http_referer', 'action', 'submit' ) ) ) { $option = trim( $option ); $value = ( is_array( $value ) ) ? $value : trim( $value ); if ( empty( $value ) ) $value = false; if ( $value ) { if ( is_array( $value ) ) { // $value = ( support_forums_settings ) foreach ( $value as $key => &$entry ) { // Prepend '&' to modify var value $key = trim( $key ); $entry = ( is_array( $entry ) ) ? $entry : trim( $entry ); if ( empty( $entry ) ) $entry = false; if ( $entry ) { if ( is_array( $entry ) ) // $entry = ( views | icons ) foreach ( $entry as $_key => &$_entry ) { // Prepend '&' to modify var value $_key = trim( $_key ); $_entry = ( is_array( $_entry ) ) ? $_entry : trim( $_entry ); if ( empty( $_entry ) ) $_entry = false; if ( $_entry ) { // $_entry could be empty only if ( dir ) was empty if ( 'dir' == $_key ) { // First remove ALL shashes $_entry = str_replace( '/', '', $_entry ); // Do the trim again since $_entry might have changed $_entry = trim( $_entry ); // Tail a slash. Mandatory! $_entry .= '/'; if ( !is_dir( bb_get_active_theme_directory() . 'images/' . $_entry ) ) { $goback = add_query_arg( 'icons-directory-invalid', 'true', $goback ); bb_safe_redirect( $goback ); exit; } $requested_settings[$key][$_key] = $_entry; } else { // status, closed and sticky are elements of icons[]. views[] follows the same rule $requested_settings[$key][] = $_key; } } } else // $entry = ( default_status | poster_setable | poster_changeable ) $requested_settings[$key] = $entry; } } } else { // $value = ( #id ) // Forums ids are elements of forums[] $requested_settings['forums'][] = $value; } } } bb_update_option( 'support_forums_settings', $requested_settings ); $goback = add_query_arg( 'support-forums-updated', 'true', $goback ); bb_safe_redirect( $goback ); exit; } if ( !empty( $_GET['support-forums-updated'] ) ) bb_admin_notice( __( 'Settings saved.', SUPPORT_FORUMS_ID ) ); if ( !empty( $_GET['support-forums-uninstalled'] ) ) bb_admin_notice( sprintf( __( '%s data removed.', SUPPORT_FORUMS_ID ), SUPPORT_FORUMS_NAME ) ); if ( !empty( $_GET['icons-directory-invalid'] ) ) bb_admin_notice( __( 'The icons directory you entered is not valid.', SUPPORT_FORUMS_ID ), 'error' ); if ( !empty( $_GET['support-forum-settings-imported'] ) ) bb_admin_notice( __( 'Support Forum settings imported.', SUPPORT_FORUMS_ID ) ); if ( !empty( $_GET['support-forum-settings-import-error'] ) ) bb_admin_notice( __( 'No Support Forum settings found.', SUPPORT_FORUMS_ID ), 'error' ); global $bb_admin_body_class; $bb_admin_body_class = ' bb-admin-settings'; } /** * Whether or not Support Forum settings import was successful * * @access private * * @param boolean $remove_sf_settings Whether or not remove Support Forum settings after import * * @global $bbdb * * @uses bb_get_option() * @uses support_forums_map_status() * @uses bb_update_option() * @uses support_forums_remove_sf_settings() * * @return boolean */ function import_support_forum_settings( $remove_sf_settings = false ) { $sf_forums = (array) bb_get_option( 'support_forum_enabled' ); if ( empty( $sf_forums ) ) { // Support Forum is not installed return false; } // Get all other settings global $bbdb; $sf_default_status = (string) bb_get_option( 'support_forum_default_status' ); $sf_poster_setable = (string) bb_get_option( 'support_forum_poster_setable' ); $sf_poster_changeable = (string) bb_get_option( 'support_forum_poster_changeable' ); $sf_views = (array) bb_get_option( 'support_forum_views' ); $sf_icons = array( 'status' => (string) bb_get_option( 'support_forum_icons_status' ), 'closed' => (string) bb_get_option( 'support_forum_icons_closed' ), 'sticky' => (string) bb_get_option( 'support_forum_icons_sticky' ) ); // Temporary var for imported settings $imported_settings = array(); // Get support forums foreach ( $sf_forums as $sf_forum ) $imported_settings['forums'][] = $sf_forum; // Get support topics $sf_topics = $bbdb->get_results( $bbdb->prepare( "SELECT object_id, meta_value FROM $bbdb->meta WHERE meta_key = %s", 'topic_resolved' ) ); foreach ( $sf_topics as $sf_topic ) $bbdb->query( $bbdb->prepare( "INSERT IGNORE INTO $bbdb->meta ( object_type, object_id, meta_key, meta_value ) VALUES ( %s, %d, %s, %s )", // Prevent duplication of content using IGNORE 'bb_topic', (int) $sf_topic->object_id, 'topic_support_status', support_forums_map_status( $sf_topic->meta_value ) ) ); // Get default support status $imported_settings['default_status'] = ( !empty( $sf_default_status ) ) ? support_forums_map_status( $sf_default_status ) : 'not_support'; // Get poster setable $imported_settings['poster_setable'] = ( !empty( $sf_poster_setable ) ) ? $sf_poster_setable : '0'; // Get poster changeable $imported_settings['poster_changeable'] = ( !empty( $sf_poster_changeable ) ) ? $sf_poster_changeable : '0'; // Get support views if ( !empty( $sf_views ) ) foreach ( array_keys( $sf_views ) as $sf_view ) $imported_settings['views'][] = support_forums_map_status( $sf_view ); // Get support, closed and sticky icons foreach ( $sf_icons as $option => $value ) if ( !empty( $value ) ) $imported_settings['icons'][] = $option; bb_update_option( 'support_forums_settings', $imported_settings ); if ( (bool) $remove_sf_settings ) // Remove Support Forum settings support_forums_remove_sf_settings(); return true; } /** * Map Support Forum statuses into Support Forums ones * * @access private * * @param string $sf_status Support Forum status * * @return string */ function support_forums_map_status( $sf_status ) { switch ( $sf_status ) { case 'yes': $sf_status = 'resolved'; break; case 'no': $sf_status = 'not_resolved'; break; case 'mu': $sf_status = 'not_support'; break; } return $sf_status; } /** * Remove Support Forum settings * * @access private * * @return void */ function support_forums_remove_sf_settings() { bb_delete_option( 'support_forum_enabled' ); bb_delete_option( 'support_forum_default_status' ); bb_delete_option( 'support_forum_poster_setable' ); bb_delete_option( 'support_forum_poster_changeable' ); bb_delete_option( 'support_forum_views' ); bb_delete_option( 'support_forum_icons_status' ); bb_delete_option( 'support_forum_icons_closed' ); bb_delete_option( 'support_forum_icons_sticky' ); $bbdb->query( $bbdb->prepare( "DELETE FROM $bbdb->meta WHERE meta_key = %s", 'topic_resolved' ) ); // Remove Support Forum inserted topic meta (there could be none) } ?>