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() { ?>
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 "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 .= "You must be logged in to post.
" ); } $out .= "