form_id = $id; $this->linktext = $linktext; $this->popup = $popup; $this->cat = $cat; register_activation_hook( __FILE__, array($this,'install') ); // add pfs_domain for translation load_plugin_textdomain('pfs_domain'); // add pfs_options group & apply validation filter, add settings fields & section add_action('admin_init', array($this, 'admin_init') ); // add js & css add_action( 'get_header', array($this,'includes') ); // add admin page & options add_action( 'admin_menu', array($this, 'show_settings') ); // add shortcode support add_shortcode( 'post-from-site', array($this, 'shortcode') ); // add admin menu item. Probably not going to happen. //add_action( 'admin_bar_menu', array($this, 'add_admin_link'), 1000 ); } public function install(){ //nothing here yet, as there's really nothing to 'install' that isn't covered by __construct } /** * Add options to databases with defaults */ public function show_settings() { add_options_page('Dedication From Site', 'Dedication From Site', 'manage_options', 'pfs', array($this, 'settings') ); if (!get_option("pfs_options")) { $options= array( 0 => array() ); $options[0]['default_author'] = ''; $options[0]['allow_image'] = true; $options[0]['wp_image_size'] = 'medium'; $options[0]['post_status'] = 'publish'; $options[0]['post_type'] = 'post'; $options[0]['comment_status'] = 'open'; $options[0]['post_category'] = ''; $options[0]['taxonomy'] = array(); $options[0]['enable_captcha'] = false; $options[0]['allow_anon'] = false; $options['recaptcha_public_key'] = ''; $options['recaptcha_private_key'] = ''; add_option ("pfs_options", $options) ; } } /** * What to display in the admin menu */ public function settings() { ?>

Create new user?', array($this, 'setting_default_author'), 'pfs', 'pfs_users'); add_settings_field('pfs_enable_captcha', 'Enable Recaptcha for not logged in users? (recommended)', array($this, 'setting_enable_captcha'), 'pfs', 'pfs_users'); add_settings_field('pfs_recaptcha_public_key', 'Recaptcha API public key:', array($this, 'setting_recaptcha_public_key'), 'pfs', 'pfs_users'); add_settings_field('pfs_recaptcha_private_key', 'Recaptcha API private key:', array($this, 'setting_recaptcha_private_key'), 'pfs', 'pfs_users'); add_settings_section('pfs_post', 'Post Creation Settings', array($this, 'setting_section_post'), 'pfs'); add_settings_field('pfs_post_status', 'Post status:', array($this, 'setting_post_status'), 'pfs', 'pfs_post'); add_settings_field('pfs_post_type', 'Post type:
Custom Post Types supported!', array($this, 'setting_post_type'), 'pfs', 'pfs_post'); add_settings_field('pfs_comment_status', 'Comment status:', array($this, 'setting_comment_status'), 'pfs', 'pfs_post'); add_settings_field('pfs_taxonomy', 'Allowed taxonomies:', array($this, 'setting_taxonomy'), 'pfs', 'pfs_post'); add_settings_field('pfs_post_category', 'Post category:', array($this, 'setting_category'), 'pfs', 'pfs_post'); add_settings_section('pfs_image', 'Image Upload Settings', array($this, 'setting_section_image'), 'pfs'); add_settings_field('pfs_allow_image', 'Allow users to upload an image?', array($this, 'setting_allow_image'), 'pfs', 'pfs_image'); add_settings_field('pfs_wp_image_size', 'Image size setting to use:', array($this, 'setting_wp_image_size'), 'pfs', 'pfs_image'); } function setting_section_users() { echo '

By default, all logged-in users can use the post-from-site interface to create a post.

'; } function setting_allow_anon() { $options = get_option('pfs_options'); $options = $options[0]; echo ""; } function setting_default_author() { $options = get_option('pfs_options'); $options = $options[0]; /* listing of authors */ wp_dropdown_users( array( 'blog_id' => get_current_blog_id(), 'name' => 'pfs_options[0][default_author]', 'id' => 'pfs_default_author', 'selected' => $options['default_author'] ) ); } function setting_enable_captcha() { $options = get_option('pfs_options'); $options = $options[0]; echo ""; } function setting_recaptcha_public_key() { $options = get_option('pfs_options'); echo ""; } function setting_recaptcha_private_key() { $options = get_option('pfs_options'); echo ""; } function setting_section_post() { echo '

Settings for posts created by Post From Site. Defaults to a published Post with comments open, and no taxonomies.

'; } function setting_post_status() { $options = get_option('pfs_options'); $options = $options[0]; echo ""; } function setting_post_type() { $options = get_option('pfs_options'); $options = $options[0]; echo ""; } function setting_comment_status() { $options = get_option('pfs_options'); $options = $options[0]; echo ""; } function setting_taxonomy() { $options = get_option('pfs_options'); $options = $options[0]; $taxonomies = get_taxonomies(array( 'public' => true ),'object'); echo ""; } function setting_category() { $options = get_option('pfs_options'); $options = $options[0]; $categories = get_categories(array( 'public' => true ),'object'); echo ""; } function setting_section_image() { echo '

Main description of this section here.

'; } function setting_allow_image() { $options = get_option('pfs_options'); $options = $options[0]; echo ""; } function setting_wp_image_size() { $options = get_option('pfs_options'); $options = $options[0]; $sizes = get_intermediate_image_sizes(); echo ""; } /** * Sanitize and validate input. * @param array $input an array to sanitize * @return array a valid array. */ public function validate($input) { $ok = array('publish','pending','draft'); $users = array(); $user_objs = get_users( array( 'blog_id' => $GLOBALS['blog_id'], 'fields' => array( 'ID', 'user_login' ) ) ); foreach ( $user_objs as $u ){ $users[] = $u->ID; } foreach ($input as $i => $val) { if (is_array($val)){ $input[$i]['allow_anon'] = array_key_exists('allow_anon',$val); $input[$i]['default_author'] = (in_array($val['default_author'], $users)) ? $val['default_author'] : 'anon' ; $input[$i]['enable_captcha'] = array_key_exists('enable_captcha',$val); $input[$i]['post_status'] = (in_array($val['post_status'],$ok) ? $val['post_status'] : 'pending'); $input[$i]['post_type'] = (post_type_exists($val['post_type']) ? $val['post_type'] : 'post'); $input[$i]['comment_status'] = ($val['comment_status'] == 'open' ? 'open' : 'closed'); if ( array_key_exists('taxonomy',$val) ){ foreach ( $input[$i]['taxonomy'] as $j => $tax) { if (!taxonomy_exists($tax)) { unset($input[$i]['taxonomy'][$j]); } } } $input[$i]['allow_image'] = array_key_exists('allow_image', $val); $input[$i]['wp_image_size'] = (in_array($val['wp_image_size'],get_intermediate_image_sizes())) ? $val['wp_image_size'] : 'medium'; } } $input['recaptcha_public_key'] = urlencode($input['recaptcha_public_key']); $input['recaptcha_private_key'] = urlencode($input['recaptcha_private_key']); return $input; } /** * Add javascript and css to header files. */ public function includes(){ if (is_page(array(1054, 'new-dedication'))) { wp_enqueue_script( 'jquery-autocomplete-js', plugins_url("includes/jquery.autocomplete-min.js",__FILE__), array( 'jquery' ) ); wp_enqueue_script( 'jquery-multi-upload', plugins_url("includes/jquery.MultiFile.pack.js",__FILE__), array('jquery','jquery-form') ); wp_enqueue_script( 'pfs-script', plugins_url("includes/pfs-script.js",__FILE__) ); wp_localize_script('pfs-script', 'pfs_script_vars', array( 'source_url' => plugins_url("search.php",__FILE__) ) ); wp_enqueue_style( 'pfs-min-style', plugins_url("includes/minimal.css",__FILE__) ); $theme_css = apply_filters( 'pfs_theme_css', plugins_url("includes/twentyeleven.css",__FILE__) ); wp_enqueue_style( 'pfs-style', $theme_css ); } } /** * Add shortcode support. * @param $atts shortcode attributes, cat, link, and popup * cat is the category to post to, link is the display text of the link, * and popup decides whether it's an inline form (false) or a popup box (true). */ function shortcode($atts, $content=null, $code="") { $a = shortcode_atts( array( 'link' => 'quick post', 'popup' => false, 'cat' => '' ), $atts ); $pfs = new DedicationFromSite(0, $a['link'], $a['popup'], $a['cat']); return $pfs->get_form(); } /** * Add a link to show the form from the admin bar function add_admin_link() { global $wp_admin_bar, $wpdb; if ( !is_super_admin() || !is_admin_bar_showing() ) return; $this->popup = false; $form = "".$this->get_form(); / * Add the main siteadmin menu item * / $wp_admin_bar->add_menu( array( 'id' => 'post_from_site', 'title' => __( 'Write a Post', 'pfs_domain' ), 'href' => FALSE ) ); $wp_admin_bar->add_menu( array( 'parent' => 'post_from_site', 'title' => $form, 'href' => FALSE ) ); } */ /** * Creates link and postbox (initially hidden with display:none), calls pfs_submit on form-submission. Echos the form. * @param string $cat Category ID for posting specifically to one category. Default is '', which allows user to choose from allowed categories. * @param string $linktext Link text for post link. Default is set in admin settings, any text here will override that. * @param bool $popup Whether the box should be a 'modal-style' popup or always display */ public function form(){ echo $this->get_form(); } /** * Creates link and postbox (initially hidden with display:none), calls pfs_submit on form-submission. Returns the form. * @param string $cat Category ID for posting specifically to one category. Default is '', which allows user to choose from allowed categories. * @param string $linktext Link text for post link. Default is set in admin settings, any text here will override that. * @param bool $popup Whether the box should be a 'modal-style' popup or always display */ public function get_form(){ $linktext = $this->linktext; $cat = $this->cat; $popup = $this->popup; $id = $this->form_id; $pfs_options = get_option('pfs_options'); $options = $pfs_options[0]; /*$from_user_link = bp_get_loggedin_user_link(); $from_user_username = bp_loggedin_user_username(); bp_loggedin_user_fullname()*/ $from_flag = gp_get_the_flag(bp_loggedin_user_id()); if (''==$linktext) $linktext = apply_filters( 'pfs_default_link_text', __('Click to post.','pfs_domain') ); $idtext = $cat.sanitize_html_class($linktext); $out = ''; $out .= "
\n"; $out .= "\n"; $out .= "\n"; $out .= "\n"; $out .= apply_filters( 'pfs_form_start', '', $idtext ); // from $out .= ""; $out .= "
" . $from_flag . "" . bp_get_loggedin_user_username() . "
"; //$out .= "\n"; // to $out .= ""; $out .= "\n"; $out .= " \n"; if (!current_user_can('publish_posts') && $options['allow_anon']){ //if not logged in/able to publish posts, and anon posting allowed, show name/email $out .= " "; $out .= " \n"; } //$out .= "\n"; if ( array_key_exists('taxonomy',$options) ){ foreach ($options['taxonomy'] as $i => $tax){ //if ($tax != 'category' || empty($cat)){ $out .= $this->get_taxonomy_list($tax); //} } } if ($options['allow_image']) { $out .= ""; /*$out .= ""; $out .= "";*/ $out .= "
\n"; } $out .= "
\n"; if ($options['enable_captcha'] && !current_user_can('publish_posts') && $options['allow_anon'] ){ if ( !empty($pfs_options['recaptcha_public_key']) ) { require_once('recaptchalib.php'); $publickey = $pfs_options['recaptcha_public_key']; // you got this from the signup page $out .= recaptcha_get_html($publickey); } else { return ""; } } $out .= apply_filters( 'pfs_before_submit', '', $idtext ); $out .= "\n"; $out .= apply_filters( 'pfs_form_end', '', $idtext ); $out .= "\n
\n"; $out .= apply_filters( 'pfs_after_form', '', $idtext ); } else { $out .= apply_filters( 'pfs_alert_login', "

You must be logged in to post.

" ); } $out .= "
\n\n"; return $out; } /** * return the categories * @param string $excluded Categories which are excluded */ public function get_taxonomy_list( $taxonomy ){ $terms = get_terms($taxonomy, array( 'hide_empty' => 0 )); if (!$terms || empty($terms)) return ''; //preg_match_all('/\s*