Changeset 818923
- Timestamp:
- 12/11/2013 02:14:50 PM (12 years ago)
- Location:
- pubmed-posts/trunk
- Files:
-
- 8 added
- 5 edited
-
admin.css (modified) (2 diffs)
-
class-article.php (modified) (6 diffs)
-
class-search.php (added)
-
images/cross_white.png (added)
-
images/minus.png (added)
-
images/plus.png (added)
-
images/question_white.png (added)
-
images/tick_white.png (added)
-
languages/pubmed-posts.pot (modified) (3 diffs)
-
pubmed-posts.php (modified) (25 diffs)
-
readme.txt (modified) (3 diffs)
-
script.js (added)
-
style.css (added)
Legend:
- Unmodified
- Added
- Removed
-
pubmed-posts/trunk/admin.css
r812902 r818923 1 1 /** 2 * Stylesheet for "PubMed Posts" Wordpress plugin2 * Admin stylesheet for "PubMed Posts" Wordpress plugin 3 3 */ 4 4 … … 32 32 #pubmed-dashboard .pubmed-buttons { 33 33 margin: 10px 0 0 0; 34 overflow: hidden;35 34 } 36 35 -
pubmed-posts/trunk/class-article.php
r812902 r818923 10 10 } 11 11 12 class PubMed Article {12 class PubMedPostsArticle { 13 13 14 14 const PUBMED_URL = 'http://www.ncbi.nlm.nih.gov/pubmed/'; … … 317 317 $year = $this->getJournalYear(); 318 318 $month = $this->getJournalMonth(); 319 $ date = $this->getJournalDate();319 $medline = $this->getJournalMedlineDate(); 320 320 $volume = $this->getJournalVolume(); 321 321 $issue = $this->getJournalIssue(); … … 328 328 } 329 329 } else { 330 if (!empty($ date)) {331 $citation .= ' ' . $ date;330 if (!empty($medline)) { 331 $citation .= ' ' . $medline; 332 332 } 333 333 } … … 347 347 */ 348 348 public function getJournalDate() { 349 $date = ''; 349 350 $year = $this->getJournalYear(); 350 351 $month = $this->getJournalMonth(); 351 $day = $this->getJournalDay(); 352 if (!empty($year) && !empty($month) && !empty($day)) { 352 $day = $this->getJournalDay(); 353 if (empty($year)) { 354 // Try to parse MEDLINE date 355 $medline_date = $this->getJournalMedlineDate(); 356 if (!empty($medline_date)) { 357 $components = $this->getMedlineDateComponents($medline_date); 358 $year = empty($components['year']) ? '' : $components['year']; 359 $month = empty($components['month']) ? '' : $components['month']; 360 $day = empty($components['day']) ? '' : $components['day']; 361 } 362 } 363 if (!empty($year)) { 364 $month = empty($month) ? '1' : $month; 365 $day = empty($day) ? '1' : $day; 353 366 $time = strtotime($year . '-' . $month . '-' . $day); 354 $date = date('Y-m-d', $time); 355 } else { 356 // Try Medline date 357 $date = $this->getJournalMedlineDate(); 367 if ($time) { 368 $date = date('Y-m-d', $time); 369 } 358 370 } 359 371 return $date; … … 385 397 386 398 /** 387 * Get journal M edlinedate399 * Get journal MEDLINE date 388 400 * @return string 389 401 */ … … 422 434 public function getJournalYear() { 423 435 return (string) $this->xml->MedlineCitation->Article->Journal->JournalIssue->PubDate->Year; 436 } 437 438 /** 439 * Get MEDLINE date components 440 * 441 * MEDLINE is compiled by the United States National Library of Medicine. 442 * It is assumed that seasons are for the northern hemishpere. 443 * Only gets the first date of a range. Typos are converted as follows: 444 * "2rd Semest" to "2nd Semest" 445 * "4th Trimest" to "4th Quart" 446 * 447 * @param string $date 448 * @return string 449 */ 450 public function getMedlineDateComponents($date) { 451 $year = $month = $day = ''; 452 $ordinals = array('1st', '2nd', '2rd', '2d', '3rd', '3rd', '3d', '4th'); 453 $pattern = '/^(\d{4})([ \-])?([A-Za-z0-9]+)?([ \-])?([A-Za-z0-9]+)?([ \-])?([A-Za-z0-9]+)?([ \-])?([A-Za-z0-9]+)?([ \-])?([A-Za-z0-9]+)?([ \-])?/'; 454 preg_match($pattern, $date, $matches); 455 // Get year 456 $year = empty($matches[1]) ? '' : $matches[1]; 457 // Get month and day 458 $separator = empty($matches[2]) ? '' : $matches[2]; 459 if (' ' == $separator) { 460 $str1 = empty($matches[3]) ? '' : $matches[3]; 461 $separator = empty($matches[4]) ? '' : $matches[4]; 462 // Get academic term or day 463 if ($str1 && ' ' == $separator) { 464 $str2 = empty($matches[5]) ? '' : $matches[5]; 465 if ($str2) { 466 if (in_array($str1, $ordinals)) { 467 $str1 .= ' ' . $str2; 468 } else { 469 $day = $str2; 470 } 471 } 472 } 473 $month = $this->getMedlineDateMonth($str1); 474 } 475 // Output date 476 $month = empty($month) ? '1' : $month; 477 $day = empty($day) ? '1' : $day; 478 $time = strtotime($year . '-' . $month . '-' . $day); 479 if ($time) { 480 return array( 481 'year' => $year, 482 'month' => $month, 483 'day' => $day, 484 ); 485 } else { 486 return array(); 487 } 488 } 489 490 /** 491 * Get month from Medline date 492 * @param $str string 493 * @result string 494 */ 495 public function getMedlineDateMonth($str) { 496 $str = strtolower($str); 497 switch ($str) { 498 case '1st semester' : 499 case '1st semest' : 500 case '1st trimest' : 501 case '1st quart' : 502 return '01'; 503 504 case 'spring' : 505 return '03'; 506 507 case '2nd quart' : 508 case '2d quart' : 509 return '04'; 510 511 case '2nd trimest' : 512 case '2d trimest' : 513 return '05'; 514 515 case 'summer' : 516 return '06'; 517 518 case '2nd semester' : 519 case '2d semester' : 520 case '2nd semest' : 521 case '2rd semest' : // typo found 522 case '2d semest' : 523 case '3rd quart' : 524 case '3d quart' : 525 return '07'; 526 527 case 'autumn' : 528 case '3rd trimest' : 529 case '3d trimest' : 530 return '09'; 531 532 case '4th quart' : 533 case '4th trimest' : // typo found 534 return '10'; 535 536 case 'winter' : 537 case 'christmas' : 538 return '12'; 539 540 default : 541 $date = date_parse($str); 542 return (string) $date['month']; 543 } 424 544 } 425 545 -
pubmed-posts/trunk/languages/pubmed-posts.pot
r812902 r818923 2 2 msgstr "" 3 3 "Project-Id-Version: PubMed\n" 4 "POT-Creation-Date: 2013-12- 01 01:58+1000\n"5 "PO-Revision-Date: 2013-12- 01 01:58+1000\n"4 "POT-Creation-Date: 2013-12-11 13:42+1000\n" 5 "PO-Revision-Date: 2013-12-11 13:42+1000\n" 6 6 "Last-Translator: \n" 7 7 "Language-Team: \n" … … 14 14 "X-Poedit-SearchPath-0: ..\n" 15 15 16 #: ../pubmed-posts.php:155 ../template-dashboard.php:15 16 #: ../class-search.php:14 17 msgid "A search form for PubMed posts" 18 msgstr "" 19 20 #: ../class-search.php:15 21 msgid "PubMed Posts Search" 22 msgstr "" 23 24 #: ../class-search.php:79 25 msgid "Article Abstract" 26 msgstr "" 27 28 #: ../class-search.php:83 29 msgid "Article Affiliation" 30 msgstr "" 31 32 #: ../class-search.php:87 33 msgid "Article Authors" 34 msgstr "" 35 36 #: ../class-search.php:91 37 msgid "Article Title" 38 msgstr "" 39 40 #: ../class-search.php:95 41 msgid "Journal Title" 42 msgstr "" 43 44 #: ../class-search.php:99 45 msgid "Journal Volume" 46 msgstr "" 47 48 #: ../class-search.php:103 49 msgid "Journal Year" 50 msgstr "" 51 52 #: ../class-search.php:107 53 msgid "PMID" 54 msgstr "" 55 56 #: ../class-search.php:112 ../class-search.php:117 ../class-search.php:122 57 msgid "Tags" 58 msgstr "" 59 60 #: ../class-search.php:113 61 msgid "OR" 62 msgstr "" 63 64 #: ../class-search.php:118 65 msgid "AND" 66 msgstr "" 67 68 #: ../class-search.php:123 69 msgid "NOT" 70 msgstr "" 71 72 #: ../class-search.php:130 73 msgid "Advanced" 74 msgstr "" 75 76 #: ../class-search.php:131 77 msgid "Hide" 78 msgstr "" 79 80 #: ../class-search.php:134 ../template-dashboard.php:27 81 msgid "Reset" 82 msgstr "" 83 84 #: ../class-search.php:136 85 msgid "Search" 86 msgstr "" 87 88 #: ../class-search.php:151 89 msgid "Title" 90 msgstr "" 91 92 #: ../class-search.php:157 93 msgid "Show advanced search" 94 msgstr "" 95 96 #: ../class-search.php:162 97 msgid "Hide reset button" 98 msgstr "" 99 100 #: ../pubmed-posts.php:138 ../pubmed-posts.php:216 101 msgid "Tags (press enter to select)" 102 msgstr "" 103 104 #: ../pubmed-posts.php:213 ../template-dashboard.php:15 17 105 msgid "PMIDs (separate with commas)" 18 106 msgstr "" 19 107 20 #: ../pubmed-posts.php: 156108 #: ../pubmed-posts.php:214 21 109 msgid "Categories (# of # selected)" 22 110 msgstr "" 23 111 24 #: ../pubmed-posts.php: 157112 #: ../pubmed-posts.php:215 25 113 msgid "Categories" 26 114 msgstr "" 27 115 28 #: ../pubmed-posts.php:158 29 msgid "Tags (press enter to select)" 30 msgstr "" 31 32 #: ../pubmed-posts.php:167 ../pubmed-posts.php:428 116 #: ../pubmed-posts.php:260 ../pubmed-posts.php:666 33 117 msgid "PubMed Posts" 34 118 msgstr "" 35 119 36 #: ../pubmed-posts.php: 195120 #: ../pubmed-posts.php:298 37 121 msgid "Security check failed" 38 122 msgstr "" 39 123 40 #: ../pubmed-posts.php:215 124 #: ../pubmed-posts.php:318 125 msgid "Invalid identifier" 126 msgstr "" 127 128 #: ../pubmed-posts.php:420 41 129 msgid "Post already exists" 42 130 msgstr "" 43 131 44 #: ../pubmed-posts.php:220 45 msgid "Invalid identifier" 46 msgstr "" 47 48 #: ../pubmed-posts.php:242 132 #: ../pubmed-posts.php:427 49 133 msgid "Article not found" 50 134 msgstr "" 51 135 52 #: ../pubmed-posts.php:296 136 #: ../pubmed-posts.php:480 137 msgid "Failed to update post" 138 msgstr "" 139 140 #: ../pubmed-posts.php:497 53 141 msgid "View post" 54 142 msgstr "" 55 143 56 #: ../pubmed-posts.php: 297144 #: ../pubmed-posts.php:498 57 145 msgid "Edit post" 58 146 msgstr "" 59 147 60 #: ../pubmed-posts.php:299 61 msgid "Post created" 62 msgstr "" 63 64 #: ../pubmed-posts.php:301 148 #: ../pubmed-posts.php:501 149 msgid "Post draft created" 150 msgstr "" 151 152 #: ../pubmed-posts.php:503 153 msgid "Post draft updated" 154 msgstr "" 155 156 #: ../pubmed-posts.php:507 65 157 msgid "Post published" 66 158 msgstr "" 67 159 68 #: ../pubmed-posts.php:427 ../template-settings.php:14 160 #: ../pubmed-posts.php:509 161 msgid "Post updated" 162 msgstr "" 163 164 #: ../pubmed-posts.php:665 ../template-settings.php:14 69 165 msgid "PubMed Posts Settings" 70 166 msgstr "" 71 167 72 #: ../pubmed-posts.php: 441168 #: ../pubmed-posts.php:679 73 169 msgid "You do not have sufficient permissions to access this page" 74 170 msgstr "" 75 171 76 #: ../pubmed-posts.php:453 172 #: ../pubmed-posts.php:691 173 msgid "Update Post" 174 msgstr "" 175 176 #: ../pubmed-posts.php:698 177 msgid "Replace Taxonomy" 178 msgstr "" 179 180 #: ../pubmed-posts.php:705 77 181 msgid "Post Author" 78 182 msgstr "" 79 183 80 #: ../pubmed-posts.php: 460184 #: ../pubmed-posts.php:712 81 185 msgid "Post Date" 82 186 msgstr "" 83 187 84 #: ../pubmed-posts.php: 467188 #: ../pubmed-posts.php:719 85 189 msgid "Post Template" 86 190 msgstr "" 87 191 88 #: ../pubmed-posts.php:483 89 msgid "Check to show article authors" 90 msgstr "" 91 92 #: ../pubmed-posts.php:484 192 #: ../pubmed-posts.php:735 193 msgid "Update existing post" 194 msgstr "" 195 196 #: ../pubmed-posts.php:736 197 msgid "Content and custom fields will be updated if post exists" 198 msgstr "" 199 200 #: ../pubmed-posts.php:749 201 msgid "Replace post taxonomy" 202 msgstr "" 203 204 #: ../pubmed-posts.php:750 205 msgid "New categories and tags will replace existing ones for post" 206 msgstr "" 207 208 #: ../pubmed-posts.php:763 209 msgid "Show article authors" 210 msgstr "" 211 212 #: ../pubmed-posts.php:764 93 213 msgid "All posts will show the article authors instead of post author" 94 214 msgstr "" 95 215 96 #: ../pubmed-posts.php:497 97 msgid "Check to show article dates" 98 msgstr "" 99 100 #: ../pubmed-posts.php:498 101 msgid "New posts will be backdated to the article date" 102 msgstr "" 103 104 #: ../pubmed-posts.php:511 216 #: ../pubmed-posts.php:777 217 msgid "Today" 218 msgstr "" 219 220 #: ../pubmed-posts.php:778 221 msgid "Article Published" 222 msgstr "" 223 224 #: ../pubmed-posts.php:779 225 msgid "Journal Published" 226 msgstr "" 227 228 #: ../pubmed-posts.php:780 229 msgid "PubMed Record Created" 230 msgstr "" 231 232 #: ../pubmed-posts.php:781 233 msgid "PubMed Record Completed" 234 msgstr "" 235 236 #: ../pubmed-posts.php:782 237 msgid "PubMed Record Revised" 238 msgstr "" 239 240 #: ../pubmed-posts.php:784 241 msgid "New posts will be set to this date" 242 msgstr "" 243 244 #: ../pubmed-posts.php:797 105 245 msgid "Create a template for new posts using HTML and the following tags" 106 246 msgstr "" … … 110 250 msgstr "" 111 251 112 #: ../template-dashboard.php:27113 msgid "Reset"114 msgstr ""115 116 252 #: ../template-dashboard.php:28 117 253 msgid "Publish" -
pubmed-posts/trunk/pubmed-posts.php
r812902 r818923 3 3 Plugin Name: PubMed Posts 4 4 Plugin URI: http://wordpress.org/plugins/pubmed-posts/ 5 Description: This plugin adds a dashboard widget that creates posts from <a href='http://www.ncbi.nlm.nih.gov/pubmed/'>PubMed</a> articles .6 Version: 1. 0.05 Description: This plugin adds a dashboard widget that creates posts from <a href='http://www.ncbi.nlm.nih.gov/pubmed/'>PubMed</a> articles, plus a search widget that finds posts with specific article data. 6 Version: 1.1.0 7 7 Author: sydcode 8 8 Author URI: http://profiles.wordpress.org/sydcode … … 25 25 26 26 // Load PubMed article class 27 if ( !class_exists('PubMed Article') ) {27 if ( !class_exists('PubMedPostsArticle') ) { 28 28 require(dirname(__FILE__) . '/class-article.php'); 29 } 30 31 // Load search widget class 32 if ( !class_exists('PubMedPostsSearch') ) { 33 require(dirname(__FILE__) . '/class-search.php'); 29 34 } 30 35 … … 38 43 protected static $instance = null; 39 44 const PLUGIN_SLUG = 'pubmed-posts'; 40 const PLUGIN_VERSION = '1. 0.0';45 const PLUGIN_VERSION = '1.1.0'; 41 46 const DEFAULT_TEMPLATE = <<<HTML 42 47 <p>[article_authors]</p> 43 48 <p>[journal_citation]</p> 44 <p>PMID: [pmid ]</p>49 <p>PMID: [pmid_link]</a></p> 45 50 <h2>Abstract</h2> 46 51 <p>[article_abstract]</p> … … 67 72 // Actions 68 73 add_action('admin_init', array($this, 'admin_init')); 74 add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); 69 75 add_action('admin_menu', array($this, 'settings_menu')); 70 add_action('admin_enqueue_scripts', array($this, 'admin_scripts')); 76 add_action('pre_get_posts', array($this, 'search_posts'), 99); 77 add_action('widgets_init', array($this, 'register_search_widget')); 71 78 add_action('wp_dashboard_setup', array($this, 'dashboard_add_widget')); 72 add_action('wp_ajax_pubmed-posts', array($this, 'ajax_callback')); 79 add_action('wp_ajax_pubmed-posts', array($this, 'posts_callback')); 80 add_action('wp_enqueue_scripts', array($this, 'frontend_scripts')); 81 73 82 // Filters 83 add_filter('author_link', array($this, 'author_link'), 10, 3); 84 add_filter('get_the_author_display_name', array($this, 'show_authors')); 85 add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); 74 86 add_filter('the_author', array($this, 'show_authors')); 75 add_filter('get_the_author_display_name', array($this, 'show_authors'));76 add_filter('author_link', array($this, 'author_link'), 10, 3);77 add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links'));78 87 } 79 80 /** 81 * Register settings , stylesheet and script88 89 /** 90 * Register settings 82 91 */ 83 92 public function admin_init() { 84 93 register_setting('pmp_settings_group', 'pmp_settings'); 85 94 add_settings_section('pmp_settings_section', '', array($this, 'settings_section'), 'pmp_settings_page'); 95 } 96 97 /** 98 * Load front script and stylesheet 99 */ 100 public function frontend_scripts() { 101 // jQuery TextExt plugin 102 $this->load_textext_plugin(); 103 104 // PubMed Posts stylesheet 105 $deps = array( 106 'textext-core', 107 'textext-tags', 108 'textext-arrow', 109 'textext-prompt', 110 'textext-autocomplete', 111 ); 112 $url = plugins_url('style.css', __FILE__); 113 wp_enqueue_style('pubmed-front', $url, $deps, self::PLUGIN_VERSION); 114 115 // PubMed posts script 116 $deps = array( 117 'jquery', 118 'textext-core', 119 'textext-tags', 120 'textext-arrow', 121 'textext-prompt', 122 'textext-autocomplete', 123 ); 124 $url = plugins_url('script.js', __FILE__); 125 wp_enqueue_script('pubmed-front', $url, $deps, self::PLUGIN_VERSION); 126 127 // Get current tags for autocomplete 128 $args = array( 129 'hide_empty' => false, 130 'fields' => 'names' 131 ); 132 $tags = get_tags($args); 133 $tags = json_encode($tags); 134 135 // Output data 136 $variables = array( 137 'tags' => $tags, 138 'tagsText' => __('Tags (press enter to select)', 'pubmed-posts') 139 ); 140 wp_localize_script('pubmed-front', 'pubMedPosts', $variables); 141 } 142 143 /** 144 * Load admin scripts and stylesheets 145 */ 146 public function admin_scripts() { 86 147 // jQuery MultiSelect plugin 87 wp_enqueue_style('jquery-smoothness', plugins_url('smoothness/jquery-ui-1.10.3.custom.min.css', __FILE__), array(), '1.10.3'); 88 wp_enqueue_style('jquery-multiselect', plugins_url('multiselect/jquery.multiselect.css', __FILE__), array(), '1.13'); 89 wp_enqueue_script('jquery-multiselect', plugins_url('multiselect/jquery.multiselect.min.js', __FILE__), array('jquery', 'jquery-ui-core', 'jquery-ui-widget'), '1.13'); 148 $url = plugins_url('smoothness/jquery-ui-1.10.3.custom.min.css', __FILE__); 149 wp_enqueue_style('jquery-smoothness', $url, array(), '1.10.3'); 150 151 $url = plugins_url('multiselect/jquery.multiselect.css', __FILE__); 152 wp_enqueue_style('jquery-multiselect', $url, array(), '1.13'); 153 154 $url = plugins_url('multiselect/jquery.multiselect.min.js', __FILE__); 155 wp_enqueue_script('jquery-multiselect', $url, array('jquery', 'jquery-ui-core', 'jquery-ui-widget'), '1.13'); 156 90 157 // jQuery TextExt plugin 91 wp_register_style('textext-core', plugins_url('textext/css/textext.core.css', __FILE__), array(), '1.3.1'); 92 wp_register_style('textext-tags', plugins_url('textext/css/textext.plugin.tags.css', __FILE__), array(), '1.3.1'); 93 wp_register_style('textext-arrow', plugins_url('textext/css/textext.plugin.arrow.css', __FILE__), array(), '1.3.1'); 94 wp_register_style('textext-prompt', plugins_url('textext/css/textext.plugin.prompt.css', __FILE__), array(), '1.3.1'); 95 wp_register_style('textext-autocomplete', plugins_url('textext/css/textext.plugin.autocomplete.css', __FILE__), array(), '1.3.1'); 96 wp_register_script('textext-core', plugins_url('textext/js/textext.core.js', __FILE__), array('jquery'), '1.3.1'); 97 wp_register_script('textext-tags', plugins_url('textext/js/textext.plugin.tags.js', __FILE__), array('jquery'), '1.3.1'); 98 wp_register_script('textext-arrow', plugins_url('textext/js/textext.plugin.arrow.js', __FILE__), array('jquery'), '1.3.1'); 99 wp_register_script('textext-prompt', plugins_url('textext/js/textext.plugin.prompt.js', __FILE__), array('jquery'), '1.3.1'); 100 wp_register_script('textext-autocomplete', plugins_url('textext/js/textext.plugin.autocomplete.js', __FILE__), array('jquery'), '1.3.1'); 101 // PubMed Posts 158 $this->load_textext_plugin(); 159 160 // PubMed Posts stylesheet 102 161 $deps = array( 103 162 'jquery-smoothness', … … 107 166 'textext-arrow', 108 167 'textext-prompt', 109 'textext-autocomplete' 168 'textext-autocomplete', 110 169 ); 111 wp_register_style('pubmed-admin', plugins_url('admin.css', __FILE__),$deps, self::PLUGIN_VERSION); 170 $url = plugins_url('admin.css', __FILE__); 171 wp_enqueue_style('pubmed-admin', $url, $deps, self::PLUGIN_VERSION); 172 173 // PubMed Posts script 112 174 $deps = array( 113 175 'jquery', … … 117 179 'textext-arrow', 118 180 'textext-prompt', 119 'textext-autocomplete' 181 'textext-autocomplete', 120 182 ); 121 wp_register_script('pubmed-admin', plugins_url('admin.js', __FILE__), $deps, self::PLUGIN_VERSION); 122 } 123 124 /** 125 * Enqueue script and stylesheet 126 */ 127 public function admin_scripts() { 128 wp_enqueue_style('pubmed-admin'); 129 wp_enqueue_script('pubmed-admin'); 183 $url = plugins_url('admin.js', __FILE__); 184 wp_enqueue_script('pubmed-admin', $url, $deps, self::PLUGIN_VERSION); 185 130 186 // Get categories for autocomplete list 131 187 $categories = array(); … … 142 198 } 143 199 $categories = json_encode($categories); 200 144 201 // Get current tags for autocomplete 145 202 $args = array( … … 149 206 $tags = get_tags($args); 150 207 $tags = json_encode($tags); 208 151 209 // Output data 152 210 $variables = array( … … 160 218 wp_localize_script('pubmed-admin', 'pubMedPosts', $variables); 161 219 } 220 221 /** 222 * Load stylesheets and scripts for jQuery TextExt plugin 223 */ 224 public function load_textext_plugin() { 225 $url = plugins_url('textext/css/textext.core.css', __FILE__); 226 wp_enqueue_style('textext-core', $url, array(), '1.3.1'); 227 228 $url = plugins_url('textext/css/textext.plugin.tags.css', __FILE__); 229 wp_enqueue_style('textext-tags', $url, array(), '1.3.1'); 230 231 $url = plugins_url('textext/css/textext.plugin.arrow.css', __FILE__); 232 wp_enqueue_style('textext-arrow', $url, array(), '1.3.1'); 233 234 $url = plugins_url('textext/css/textext.plugin.prompt.css', __FILE__); 235 wp_enqueue_style('textext-prompt', $url, array(), '1.3.1'); 236 237 $url = plugins_url('textext/css/textext.plugin.autocomplete.css', __FILE__); 238 wp_enqueue_style('textext-autocomplete', $url, array(), '1.3.1'); 239 240 $url = plugins_url('textext/js/textext.core.js', __FILE__); 241 wp_enqueue_script('textext-core', $url, array('jquery'), '1.3.1'); 242 243 $url = plugins_url('textext/js/textext.plugin.tags.js', __FILE__); 244 wp_enqueue_script('textext-tags', $url, array('jquery'), '1.3.1'); 245 246 $url = plugins_url('textext/js/textext.plugin.arrow.js', __FILE__); 247 wp_enqueue_script('textext-arrow', $url, array('jquery'), '1.3.1'); 248 249 $url = plugins_url('textext/js/textext.plugin.prompt.js', __FILE__); 250 wp_enqueue_script('textext-prompt', $url, array('jquery'), '1.3.1'); 251 252 $url = plugins_url('textext/js/textext.plugin.autocomplete.js', __FILE__); 253 wp_enqueue_script('textext-autocomplete', $url, array('jquery'), '1.3.1'); 254 } 162 255 163 256 /** … … 185 278 ob_end_flush(); 186 279 } 187 188 /** 189 * Handle AJAX callback280 281 /** 282 * Create markup for dashboard widget 190 283 * @return string 191 284 */ 192 public function ajax_callback() { 285 public function register_search_widget() { 286 if (class_exists('PubMedPostsSearch')) { 287 register_widget('PubMedPostsSearch'); 288 } 289 } 290 291 /** 292 * Handle AJAX callback for posts 293 * @return string 294 */ 295 public function posts_callback() { 193 296 // Security check 194 297 if (!wp_verify_nonce($_POST['nonce'], 'pubmed-submit')) { … … 211 314 $id = trim($id); 212 315 if (is_numeric($id)) { 213 $exists = $this->article_exists($id); 214 if ($exists) { 215 $messages[] = '<p>' . $id . ' - ' . __('Post already exists', 'pubmed-posts') . '.</p>'; 216 } else { 217 $messages[] = '<p>' . $this->create_post($id, $status, $categories, $tags) . '</p>'; 218 } 316 $messages[] = '<p>' . $this->create_post($id, $status, $categories, $tags) . '</p>'; 219 317 } else { 220 318 $messages[] = '<p>' . $id . ' - ' . __('Invalid identifier', 'pubmed-posts') . '.</p>'; … … 227 325 die(); 228 326 } 229 327 328 /** 329 * Search for PubMed posts 330 * @param object $query 331 * @return object 332 */ 333 public function search_posts($query) { 334 // Check for PubMed search 335 if (!isset($_POST['pubmed-search'])) { 336 return $query; 337 } 338 if ('simple' == $_POST['pubmed-search']) { 339 // Simple Search 340 if (!empty($_POST['pubmed-keyword'])) { 341 $query->set('s', $_POST['pubmed-keyword']); 342 } 343 } else { 344 // Advanced search 345 346 // Meta query 347 $meta_query = array(); 348 $meta_fields = array( 349 'pubmed-pmid' => 'PMID', 350 'article-abstract' => 'Article Abstract', 351 'article-affiliation' => 'Article Affiliation', 352 'article-authors' => 'Article Authors', 353 'article-title' => 'Article Title', 354 'journal-title' => 'Journal Title', 355 'journal-volume' => 'Journal Volume', 356 'journal-year' => 'Journal Year', 357 ); 358 $like_fields = array( 359 'article-abstract', 360 'article-affiliation', 361 'article-authors', 362 'article-title', 363 'journal-title', 364 ); 365 foreach ($meta_fields as $name => $key) { 366 if (!empty($_POST[$name])) { 367 $element = array( 368 'key' => $key, 369 'value' => $_POST[$name], 370 ); 371 if (in_array($name, $like_fields)) { 372 $element['compare'] = 'LIKE'; 373 } 374 $meta_query[] = $element; 375 } 376 } 377 $query->set('meta_query', $meta_query); 378 379 // Tags query 380 $tax_query = array(); 381 $tax_fields = array( 382 'post-tags-or' => 'IN', 383 'post-tags-and' => 'AND', 384 'post-tags-not' => 'NOT IN', 385 ); 386 foreach ($tax_fields as $name => $operator) { 387 if (isset($_POST[$name])) { 388 $tags = json_decode(stripslashes($_POST[$name])); 389 if (!empty($tags)) { 390 $tags = array_map('trim', $tags); 391 $element = array( 392 'taxonomy' => 'post_tag', 393 'field' => 'slug', 394 'terms' => $tags, 395 'operator' => $operator, 396 ); 397 $tax_query[] = $element; 398 } 399 } 400 } 401 $query->set('tax_query', $tax_query); 402 } 403 return $query; 404 } 405 230 406 /** 231 407 * Create post from PubMed article … … 236 412 */ 237 413 public function create_post($pmid, $status, $categories, $tags) { 414 // Check if post must be updated 415 $settings = get_option('pmp_settings'); 416 $post_update = empty($settings['update']) ? false : true; 417 $post_ID = $this->get_article_post($pmid); 418 if (!$post_update && $post_ID) { 419 // Exit if update is off and post exists 420 return $pmid . ' - ' . __('Post already exists', 'pubmed-posts') . '.'; 421 } 422 238 423 // Get PubMed article 239 424 try { 240 $article = new PubMed Article($pmid);425 $article = new PubMedPostsArticle($pmid); 241 426 } catch (Exception $e) { 242 427 return $pmid . ' - ' . __('Article not found', 'pubmed-posts') . '.'; … … 259 444 260 445 // Build post content by parsing template tags 261 $settings = get_option('pmp_settings');262 446 $content = empty($settings['template']) ? self::DEFAULT_TEMPLATE : $settings['template']; 263 447 foreach ($data as $key => $value) { … … 270 454 $content = str_replace($key, $value, $content); 271 455 } 272 273 // Create post (change date if required) 456 if ( empty($data['pmid']) || empty($data['article_url']) ) { 457 $content = str_replace('[pmid_link]', '', $content); 458 } else { 459 $pmid_link = sprintf("<a href='%s' title=''>%s</a>", $data['article_url'], $data['pmid']); 460 $content = str_replace('[pmid_link]', $pmid_link, $content); 461 } 462 463 // Create post data 274 464 $post_data = array( 275 465 'post_title' => $data['article_title'], … … 277 467 'post_status' => $status 278 468 ); 279 if (!empty($settings['dates'])) { 280 if (!empty($data['article_date'])) { 281 $post_data['post_date'] = $data['article_date']; 282 } else if (!empty($data['date_created'])) { 283 $post_data['post_date'] = $data['date_created']; 284 } 285 } 286 $post_ID = wp_insert_post($post_data); 287 469 $date = $this->post_date($data); 470 if (!empty($date)) { 471 $post_data['post_date'] = $date; 472 } 473 474 // Update post or create new post 475 $append_taxonomy = empty($settings['replace']) ? true : false; 476 if ($post_ID) { 477 $new_post = false; 478 $post_data['ID'] = $post_ID; 479 $post_ID = wp_update_post($post_data); 480 if (empty($post_ID)) { 481 return $pmid . ' - ' . __('Failed to update post', 'pubmed-posts') . '.'; 482 } 483 if ($append_taxonomy) { 484 // Append current categories 485 $post_categories = wp_get_post_categories($post_ID); 486 $categories = array_unique( array_merge($categories, $post_categories) ); 487 } 488 } else { 489 $new_post = true; 490 $post_ID = wp_insert_post($post_data); 491 } 492 288 493 // Set metadata, categories and tags 289 494 $this->save_metadata($post_ID, $data); 290 495 wp_set_post_categories($post_ID, $categories); 291 wp_set_post_tags($post_ID, $tags, false);496 wp_set_post_tags($post_ID, $tags, $append_taxonomy); 292 497 293 498 // Create status messsage … … 297 502 $post_links .= "<a href='" . $post_edit_url . "'>" . __('Edit post', 'pubmed-posts') . "</a>"; 298 503 if ($status == 'draft') { 299 $message = $pmid . ' - ' . __('Post created', 'pubmed-posts') . '. ' . $post_links; 504 if ($new_post) { 505 $message = __('Post draft created', 'pubmed-posts'); 506 } else { 507 $message = __('Post draft updated', 'pubmed-posts'); 508 } 300 509 } else { 301 $message = $pmid . ' - ' . __('Post published', 'pubmed-posts') . '. ' . $post_links; 302 } 303 return $message; 510 if ($new_post) { 511 $message = __('Post published', 'pubmed-posts'); 512 } else { 513 $message = __('Post updated', 'pubmed-posts'); 514 } 515 } 516 return $pmid . ' - ' . $message . '. ' . $post_links; 517 } 518 519 /** 520 * Get date to use for post date 521 * @param array $data 522 * @return string 523 */ 524 public function post_date($data) { 525 $settings = get_option('pmp_settings'); 526 $selected = empty($settings['dates']) ? '' : $settings['dates']; 527 if ('1' == $selected) { 528 // Support for old date setting 529 $selected = 'article_date'; 530 } 531 $date = empty($data[$selected]) ? '' : $data[$selected]; 532 if (!empty($date)) { 533 // Validate date 534 $time = strtotime($date); 535 if ($time === false) { 536 return ''; 537 } 538 } 539 return $date; 304 540 } 305 541 … … 310 546 */ 311 547 public function save_metadata($post_ID, $data) { 548 delete_post_meta($post_ID, 'Article Abstract'); 312 549 foreach ( (array) $data['article_abstract'] as $abstract) { 313 550 add_post_meta($post_ID, 'Article Abstract', $abstract, false); 314 551 } 315 add_post_meta($post_ID, 'Article Affiliation', $data['article_affiliation'], true); 316 add_post_meta($post_ID, 'Article Authors', $data['article_authors'], true); 317 add_post_meta($post_ID, 'Article Date', $data['article_date'], true); 318 add_post_meta($post_ID, 'Article Pagination', $data['article_pagination'], true); 319 add_post_meta($post_ID, 'Article URL', $data['article_url'], true); 320 add_post_meta($post_ID, 'Date Completed', $data['date_completed'], true); 321 add_post_meta($post_ID, 'Date Created', $data['date_created'], true); 322 add_post_meta($post_ID, 'Date Revised', $data['date_revised'], true); 323 add_post_meta($post_ID, 'Journal Abbreviation', $data['journal_abbreviation'], true); 324 add_post_meta($post_ID, 'Journal Citation', $data['journal_citation'], true); 325 add_post_meta($post_ID, 'Journal Date', $data['journal_date'], true); 326 add_post_meta($post_ID, 'Journal Day', $data['journal_day'], true); 327 add_post_meta($post_ID, 'Journal Issue', $data['journal_issue'], true); 328 add_post_meta($post_ID, 'Journal Month', $data['journal_month'], true); 329 add_post_meta($post_ID, 'Journal Title', $data['journal_title'], true); 330 add_post_meta($post_ID, 'Journal Volume', $data['journal_volume'], true); 331 add_post_meta($post_ID, 'Journal Year', $data['journal_year'], true); 332 add_post_meta($post_ID, 'PMID', $data['pmid'], true); 333 } 334 335 /** 336 * Check if a post exists for a PubMed article 552 update_post_meta($post_ID, 'Article Affiliation', $data['article_affiliation']); 553 update_post_meta($post_ID, 'Article Authors', $data['article_authors']); 554 update_post_meta($post_ID, 'Article Date', $data['article_date']); 555 update_post_meta($post_ID, 'Article Pagination', $data['article_pagination']); 556 update_post_meta($post_ID, 'Article Title', $data['article_title']); 557 update_post_meta($post_ID, 'Article URL', $data['article_url']); 558 update_post_meta($post_ID, 'Date Completed', $data['date_completed']); 559 update_post_meta($post_ID, 'Date Created', $data['date_created']); 560 update_post_meta($post_ID, 'Date Revised', $data['date_revised']); 561 update_post_meta($post_ID, 'Journal Abbreviation', $data['journal_abbreviation']); 562 update_post_meta($post_ID, 'Journal Citation', $data['journal_citation']); 563 update_post_meta($post_ID, 'Journal Date', $data['journal_date']); 564 update_post_meta($post_ID, 'Journal Day', $data['journal_day']); 565 update_post_meta($post_ID, 'Journal Issue', $data['journal_issue']); 566 update_post_meta($post_ID, 'Journal Month', $data['journal_month']); 567 update_post_meta($post_ID, 'Journal Title', $data['journal_title']); 568 update_post_meta($post_ID, 'Journal Volume', $data['journal_volume']); 569 update_post_meta($post_ID, 'Journal Year', $data['journal_year']); 570 update_post_meta($post_ID, 'PMID', $data['pmid']); 571 } 572 573 /** 574 * Get ID of post for a PubMed article 337 575 * @param string $pmid 338 * @return boolean 339 */ 340 public function article_exists($pmid) { 576 * @return integer 577 */ 578 public function get_article_post($pmid) { 579 $pmid = trim($pmid); 341 580 $args = array( 342 581 'posts_per_page' => -1 … … 344 583 $posts = get_posts($args); 345 584 foreach($posts as $post) { 346 $data = get_post_meta($post->ID, ' pubmed-pmid', true);347 if ( $data == $pmid) {348 return true;349 } 350 } 351 return false;585 $data = get_post_meta($post->ID, 'PMID', true); 586 if (strtolower($data) == strtolower($pmid)) { 587 return $post->ID; 588 } 589 } 590 return 0; 352 591 } 353 592 … … 380 619 $settings = get_option('pmp_settings'); 381 620 if (!empty($settings['authors'])) { 621 $authors = get_post_meta($post->ID, 'Article Authors', true); 622 if (!empty($authors)) { 623 return $authors; 624 } 625 // Support for version 1.0 382 626 $authors = get_post_meta($post->ID, 'pubmed-article-authors', true); 383 if ($authors) { 384 $name = $authors; 385 } else { 386 // Support for old plugin 387 $old_authors = get_post_meta($post->ID, 'authors', true); 388 if ($old_authors) { 389 $name = $old_authors; 390 } 391 } 627 if (!empty($authors)) { 628 return $authors; 629 } 630 // Support for beta version 631 $authors = get_post_meta($post->ID, 'authors', true); 632 if (!empty($authors)) { 633 return $authors; 634 } 392 635 } 393 636 return $name; … … 449 692 */ 450 693 public function settings_section() { 694 add_settings_field( 695 'pmp_settings_update', 696 __('Update Post', 'pubmed-posts'), 697 array($this, 'settings_update'), 698 'pmp_settings_page', 699 'pmp_settings_section' 700 ); 701 add_settings_field( 702 'pmp_settings_replace', 703 __('Replace Taxonomy', 'pubmed-posts'), 704 array($this, 'settings_replace'), 705 'pmp_settings_page', 706 'pmp_settings_section' 707 ); 451 708 add_settings_field( 452 709 'pmp_settings_authors', … … 471 728 ); 472 729 } 730 731 /** 732 * Settings field for update post 733 * @return string 734 */ 735 public function settings_update() { 736 $settings = get_option('pmp_settings'); 737 $checked = empty($settings['update']) ? '' : "checked='checked'"; 738 ?> 739 <input id='pubmed-update' type='checkbox' name='pmp_settings[update]' value='1' <?php echo $checked; ?> /> 740 <label for='pubmed-update'><?php _e('Update existing post', 'pubmed-posts'); ?></label> 741 <p class='description'><?php _e('Content and custom fields will be updated if post exists', 'pubmed-posts'); ?>.</p> 742 <?php 743 } 744 745 /** 746 * Settings field for replace taxonomy 747 * @return string 748 */ 749 public function settings_replace() { 750 $settings = get_option('pmp_settings'); 751 $checked = empty($settings['replace']) ? '' : "checked='checked'"; 752 ?> 753 <input id='pubmed-replace' type='checkbox' name='pmp_settings[replace]' value='1' <?php echo $checked; ?> /> 754 <label for='pubmed-replace'><?php _e('Replace post taxonomy', 'pubmed-posts'); ?></label> 755 <p class='description'><?php _e('New categories and tags will replace existing ones for post', 'pubmed-posts'); ?>.</p> 756 <?php 757 } 473 758 474 759 /** … … 481 766 ?> 482 767 <input id='pubmed-authors' type='checkbox' name='pmp_settings[authors]' value='1' <?php echo $checked; ?> /> 483 <label for='pubmed-authors'><?php _e(' Check to show article authors', 'pubmed-posts'); ?></label>484 <p class='description'><?php _e('All posts will show the article authors instead of post author', 'pubmed-posts'); ?> </p>768 <label for='pubmed-authors'><?php _e('Show article authors', 'pubmed-posts'); ?></label> 769 <p class='description'><?php _e('All posts will show the article authors instead of post author', 'pubmed-posts'); ?>.</p> 485 770 <?php 486 771 } … … 492 777 public function settings_dates() { 493 778 $settings = get_option('pmp_settings'); 494 $ checked = empty($settings['dates']) ? '' : "checked='checked'";779 $selected = empty($settings['dates']) ? '' : $settings['dates']; 495 780 ?> 496 <input id='pubmed-dates' type='checkbox' name='pmp_settings[dates]' value='1' <?php echo $checked; ?> /> 497 <label for='pubmed-dates'><?php _e('Check to show article dates', 'pubmed-posts'); ?></label> 498 <p class='description'><?php _e('New posts will be backdated to the article date', 'pubmed-posts'); ?></p> 781 <select id='pubmed-dates' name='pmp_settings[dates]'> 782 <option value=''><?php _e('Today', 'pubmed-posts'); ?></option> 783 <option value='article_date' <?php selected($selected, 'article_date');?>><?php _e('Article Published', 'pubmed-posts'); ?></option> 784 <option value='journal_date' <?php selected($selected, 'journal_date');?>><?php _e('Journal Published', 'pubmed-posts'); ?></option> 785 <option value='date_created' <?php selected($selected, 'date_created');?>><?php _e('PubMed Record Created', 'pubmed-posts'); ?></option> 786 <option value='date_completed' <?php selected($selected, 'date_completed');?>><?php _e('PubMed Record Completed', 'pubmed-posts'); ?></option> 787 <option value='date_revised' <?php selected($selected, 'date_revised');?>><?php _e('PubMed Record Revised', 'pubmed-posts'); ?></option> 788 </select> 789 <p class='description'><?php _e('New posts will be set to this date', 'pubmed-posts'); ?>.</p> 499 790 <?php 500 791 } … … 509 800 ?> 510 801 <textarea id='pubmed-template' type='checkbox' name='pmp_settings[template]'><?php echo $template; ?></textarea> 511 <p class='description'><?php _e('Create a template for new posts using HTML and the following tags', 'pubmed-posts'); ?> </p>802 <p class='description'><?php _e('Create a template for new posts using HTML and the following tags', 'pubmed-posts'); ?>.</p> 512 803 <p> 513 <code>[pmid], [ date_created], [date_completed], [date_revised], [article_url], [article_title], [article_date], [article_authors],514 [article_a bstract], [article_pagination], [article_affiliation], [journal_title], [journal_abbreviation], [journal_volume],515 [journal_ issue], [journal_date], [journal_citation]</code>804 <code>[pmid], [pmid_link], [date_created], [date_completed], [date_revised], [article_url], [article_title], [article_date], 805 [article_authors], [article_abstract], [article_pagination], [article_affiliation], [journal_title], [journal_abbreviation], 806 [journal_volume], [journal_issue], [journal_date], [journal_citation]</code> 516 807 </p> 517 808 <?php 518 } 809 } 519 810 520 811 } // End Class -
pubmed-posts/trunk/readme.txt
r812902 r818923 5 5 Requires at least: 3.3 6 6 Tested up to: 3.7.1 7 Stable tag: 1. 0.07 Stable tag: 1.1.0 8 8 License: GPLv3 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-3.0.html 10 10 11 This plugin adds a dashboard widget that creates posts from PubMed articles .11 This plugin adds a dashboard widget that creates posts from PubMed articles, plus a search widget that finds posts with specific article data. 12 12 13 13 == Description == 14 14 15 This plugin adds a dashboard widget that creates posts from [PubMed](http://www.ncbi.nlm.nih.gov/pubmed/) articles . A basic editor is included for changingthe layout of data in the post content.15 This plugin adds a dashboard widget that creates posts from [PubMed](http://www.ncbi.nlm.nih.gov/pubmed/) articles, plus a search widget that finds posts with specific article data. A basic editor is also included that changes the layout of data in the post content. 16 16 17 17 This is not an official [PubMed](http://www.ncbi.nlm.nih.gov/pubmed/) plugin. All questions and suggestions should be posted in the plugin forum. … … 33 33 3. Settings Page 34 34 35 4. Sidebar Widget 36 35 37 == Frequently Asked Questions == 36 38 … … 39 41 == Upgrade Notice == 40 42 41 No upgrade notices .43 No upgrade notices 42 44 43 45 == Changelog == 44 46 47 = 1.1.0 = 48 * Added search widget 49 * Added new settings (update posts, replace taxonomy) 50 * Added more options to post date settings 51 * Improved parsing of MEDLINE dates 52 45 53 = 1.0.0 = 46 54 * First release
Note: See TracChangeset
for help on using the changeset viewer.