prefix."attributor"; $structure = "CREATE TABLE IF NOT EXISTS ". $table." ( id INT(9) NOT NULL AUTO_INCREMENT, post_id VARCHAR(255) NOT NULL, UNIQUE KEY id (id) );"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($structure); delete_option('fairshare_position'); add_option('fairshare_position','top-left'); $insert_structure = "INSERT INTO ".$table."(post_id) SELECT ID FROM wp_posts WHERE post_status='publish' or post_status = 'draft'"; $wpdb->query($insert_structure); } catch(Exception $e){ $myFile = WP_CONTENT_DIR."/plugins/attributor-fairshare-plugin/fairshare-widget.log"; $fh = fopen($myFile, 'a'); fwrite($fh, "Error while installing the plugin"); fwrite($fh, $e->getMessage()."\n"); fclose($fh); } } function page_field() { if( function_exists( 'add_meta_box' )) { add_meta_box('attributor', __('Attributor FairShare'), 'post_attributor', 'page', 'advanced', 'core'); add_meta_box('attributor', __('Attributor FairShare'), 'post_attributor', 'post', 'advanced', 'core'); } } /* BACK-END attributor DISPLAY */ function post_attributor($post) { global $wpdb; $page_id=$post->ID; $table=$wpdb->prefix."attributor"; $structure = "SELECT * FROM ". $table." WHERE post_id=".$post->ID; $myrows = $wpdb->get_results($structure); $pageName = basename($_SERVER['SCRIPT_FILENAME']); ?> 0 || $pageName == "post-new.php") echo 'checked'; ?>/> prefix."attributor"; $delete_structure = "DELETE FROM ". $table." WHERE post_id=".$post_id; $wpdb->query($delete_structure); $status = $wpdb->get_results('SELECT post_status FROM wp_posts WHERE ID='.$post_id); //IF WE SET THAT THE POST WILL INCLUDE THE attributor WIDGET // if(($status[0]->post_status=='publish')) // { $myFile = WP_CONTENT_DIR."/plugins/attributor-fairshare-plugin/fairshare-widget.log"; $fh = fopen($myFile, 'a'); $postAction = $_POST['action']; if(isset($_POST["is_checked"]) || $postAction === "post-quickpress-publish" || $postAction === "post-quickpress-save"){ $text = "Saved checked box for post ".$post_id."\n"; fwrite($fh, $text); $insert_structure = "INSERT INTO ".$table."(post_id) VALUES (".$post_id.")"; $wpdb->query($insert_structure); } else{ $text = "Saved unchecked box for post ".$post_id."\n"; fwrite($fh, $text); } fclose($fh); // } } /* attributor UNINSTALL */ function attributor_uninstall(){ global $wpdb; $table=$wpdb->prefix."attributor"; $structure = "DROP TABLE ". $table.";"; $wpdb->query($structure); delete_option('fairshare_position'); } //FUNCTION FOR INSERTING attributor WIDGET INTO SELECTED POSTS function protect($content ) { global $wpdb; global $post; $table = $wpdb->prefix."attributor"; //VERIFY IF THE POST IS SET TO HAVE attributor WIDGET IN IT $is_attributor = $wpdb->get_results('SELECT * FROM '.$table.' WHERE post_id='.$post->ID); if(count($is_attributor)>0){ $pos = get_option('fairshare_position'); $result = ''; switch($pos){ case 'top-left': $result .= '
'.$content; break; case 'top-right': $result .= '
'.$content; break; case 'top-center': $result .= '
'.$content; break; case 'bottom-left': $result .= $content.'
'; break; case 'bottom-right': $result .= $content.'
'; break; case 'bottom-center': $result .= $content.'
'; break; } } else{ $result = $content; } return $result; } function attributor_custom(){ add_menu_page('Attributor FairShare Widget', 'FairShare', 7, 'attributor-page.php', 'attributor_custom_fct', WP_CONTENT_URL.'/plugins/attributor-fairshare-plugin/fs-rings_16x16.png'); } function attributor_custom_fct(){ global $wpdb; if((isset($_POST['save']))&&($_POST['save']=='Save')) { $myFile = WP_CONTENT_DIR."/plugins/attributor-fairshare-plugin/fairshare-widget.log"; $fh = fopen($myFile, 'a'); $text = "Saved setting into database \n"; fwrite($fh, $text); fclose($fh); ?>
FairShare widget setting has been updated.
FairShare widget'; $pos = get_option('fairshare_position'); ?>
style="float:left;">Top-Left
style="float:left;">Top-Center
style="float:left;">Top-Right
Page Content
style="float:left;">Bottom-Left
style="float:left;" >Bottom-Center
style="float:left;" >Bottom-Right
prefix."attributor"; $select_pages = $wpdb->get_results('SELECT * FROM wp_posts WHERE post_status="publish"'); $attributor_pages = $wpdb->get_results('SELECT t1.* FROM wp_posts AS t1 join '.$table.' AS t2 ON t1.ID=t2.post_id WHERE t1.post_status="publish"'); if(count($attributor_pages)==0) { $checked='unchecked'; } else if(count($select_pages)>count($attributor_pages)) { $checked='partial_checked'; } else if (count($select_pages)==count($attributor_pages)) { $checked='all_checked'; } */ ?>