WP_Press_This

Press This class.

Defined (1)

The class is defined in the following location(s).

/wp-admin/includes/class-wp-press-this.php  
  1. class WP_Press_This { 
  2.  
  3. // Used to trigger the bookmarklet update notice. 
  4. public $version = 8; 
  5.  
  6. private $images = array(); 
  7.  
  8. private $embeds = array(); 
  9.  
  10. private $domain = ''; 
  11.  
  12. /** 
  13. * Constructor. 
  14. * @since 4.2.0 
  15. * @access public 
  16. */ 
  17. public function __construct() {} 
  18.  
  19. /** 
  20. * App and site settings data, including i18n strings for the client-side. 
  21. * @since 4.2.0 
  22. * @access public 
  23. * @return array Site settings. 
  24. */ 
  25. public function site_settings() { 
  26. return array( 
  27. /** 
  28. * Filters whether or not Press This should redirect the user in the parent window upon save. 
  29. * @since 4.2.0 
  30. * @param bool $redirect Whether to redirect in parent window or not. Default false. 
  31. */ 
  32. 'redirInParent' => apply_filters( 'press_this_redirect_in_parent', false ),  
  33. ); 
  34.  
  35. /** 
  36. * Get the source's images and save them locally, for posterity, unless we can't. 
  37. * @since 4.2.0 
  38. * @access public 
  39. * @param int $post_id Post ID. 
  40. * @param string $content Optional. Current expected markup for Press This. Expects slashed. Default empty. 
  41. * @return string New markup with old image URLs replaced with the local attachment ones if swapped. 
  42. */ 
  43. public function side_load_images( $post_id, $content = '' ) { 
  44. $content = wp_unslash( $content ); 
  45.  
  46. if ( preg_match_all( '/<img [^>]+>/', $content, $matches ) && current_user_can( 'upload_files' ) ) { 
  47. foreach ( (array) $matches[0] as $image ) { 
  48. // This is inserted from our JS so HTML attributes should always be in double quotes. 
  49. if ( ! preg_match( '/src="([^"]+)"/', $image, $url_matches ) ) { 
  50. continue; 
  51.  
  52. $image_src = $url_matches[1]; 
  53.  
  54. // Don't try to sideload a file without a file extension, leads to WP upload error. 
  55. if ( ! preg_match( '/[^\?]+\.(?:jpe?g|jpe|gif|png)(?:\?|$)/i', $image_src ) ) { 
  56. continue; 
  57.  
  58. // Sideload image, which gives us a new image src. 
  59. $new_src = media_sideload_image( $image_src, $post_id, null, 'src' ); 
  60.  
  61. if ( ! is_wp_error( $new_src ) ) { 
  62. // Replace the POSTED content <img> with correct uploaded ones. 
  63. // Need to do it in two steps so we don't replace links to the original image if any. 
  64. $new_image = str_replace( $image_src, $new_src, $image ); 
  65. $content = str_replace( $image, $new_image, $content ); 
  66.  
  67. // Expected slashed 
  68. return wp_slash( $content ); 
  69.  
  70. /** 
  71. * Ajax handler for saving the post as draft or published. 
  72. * @since 4.2.0 
  73. * @access public 
  74. */ 
  75. public function save_post() { 
  76. if ( empty( $_POST['post_ID'] ) || ! $post_id = (int) $_POST['post_ID'] ) { 
  77. wp_send_json_error( array( 'errorMessage' => __( 'Missing post ID.' ) ) ); 
  78.  
  79. if ( empty( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'update-post_' . $post_id ) || 
  80. ! current_user_can( 'edit_post', $post_id ) ) { 
  81.  
  82. wp_send_json_error( array( 'errorMessage' => __( 'Invalid post.' ) ) ); 
  83.  
  84. $post_data = array( 
  85. 'ID' => $post_id,  
  86. 'post_title' => ( ! empty( $_POST['post_title'] ) ) ? sanitize_text_field( trim( $_POST['post_title'] ) ) : '',  
  87. 'post_content' => ( ! empty( $_POST['post_content'] ) ) ? trim( $_POST['post_content'] ) : '',  
  88. 'post_type' => 'post',  
  89. 'post_status' => 'draft',  
  90. 'post_format' => ( ! empty( $_POST['post_format'] ) ) ? sanitize_text_field( $_POST['post_format'] ) : '',  
  91. 'tax_input' => ( ! empty( $_POST['tax_input'] ) ) ? $_POST['tax_input'] : array(),  
  92. 'post_category' => ( ! empty( $_POST['post_category'] ) ) ? $_POST['post_category'] : array(),  
  93. ); 
  94.  
  95. if ( ! empty( $_POST['post_status'] ) && 'publish' === $_POST['post_status'] ) { 
  96. if ( current_user_can( 'publish_posts' ) ) { 
  97. $post_data['post_status'] = 'publish'; 
  98. } else { 
  99. $post_data['post_status'] = 'pending'; 
  100.  
  101. $post_data['post_content'] = $this->side_load_images( $post_id, $post_data['post_content'] ); 
  102.  
  103. /** 
  104. * Filters the post data of a Press This post before saving/updating. 
  105. * The {@see 'side_load_images'} action has already run at this point. 
  106. * @since 4.5.0 
  107. * @param array $post_data The post data. 
  108. */ 
  109. $post_data = apply_filters( 'press_this_save_post', $post_data ); 
  110.  
  111. $updated = wp_update_post( $post_data, true ); 
  112.  
  113. if ( is_wp_error( $updated ) ) { 
  114. wp_send_json_error( array( 'errorMessage' => $updated->get_error_message() ) ); 
  115. } else { 
  116. if ( isset( $post_data['post_format'] ) ) { 
  117. if ( current_theme_supports( 'post-formats', $post_data['post_format'] ) ) { 
  118. set_post_format( $post_id, $post_data['post_format'] ); 
  119. } elseif ( $post_data['post_format'] ) { 
  120. set_post_format( $post_id, false ); 
  121.  
  122. $forceRedirect = false; 
  123.  
  124. if ( 'publish' === get_post_status( $post_id ) ) { 
  125. $redirect = get_post_permalink( $post_id ); 
  126. } elseif ( isset( $_POST['pt-force-redirect'] ) && $_POST['pt-force-redirect'] === 'true' ) { 
  127. $forceRedirect = true; 
  128. $redirect = get_edit_post_link( $post_id, 'js' ); 
  129. } else { 
  130. $redirect = false; 
  131.  
  132. /** 
  133. * Filters the URL to redirect to when Press This saves. 
  134. * @since 4.2.0 
  135. * @param string $url Redirect URL. If `$status` is 'publish', this will be the post permalink. 
  136. * Otherwise, the default is false resulting in no redirect. 
  137. * @param int $post_id Post ID. 
  138. * @param string $status Post status. 
  139. */ 
  140. $redirect = apply_filters( 'press_this_save_redirect', $redirect, $post_id, $post_data['post_status'] ); 
  141.  
  142. if ( $redirect ) { 
  143. wp_send_json_success( array( 'redirect' => $redirect, 'force' => $forceRedirect ) ); 
  144. } else { 
  145. wp_send_json_success( array( 'postSaved' => true ) ); 
  146.  
  147. /** 
  148. * Ajax handler for adding a new category. 
  149. * @since 4.2.0 
  150. * @access public 
  151. */ 
  152. public function add_category() { 
  153. if ( false === wp_verify_nonce( $_POST['new_cat_nonce'], 'add-category' ) ) { 
  154. wp_send_json_error(); 
  155.  
  156. $taxonomy = get_taxonomy( 'category' ); 
  157.  
  158. if ( ! current_user_can( $taxonomy->cap->edit_terms ) || empty( $_POST['name'] ) ) { 
  159. wp_send_json_error(); 
  160.  
  161. $parent = isset( $_POST['parent'] ) && (int) $_POST['parent'] > 0 ? (int) $_POST['parent'] : 0; 
  162. $names = explode( ', ', $_POST['name'] ); 
  163. $added = $data = array(); 
  164.  
  165. foreach ( $names as $cat_name ) { 
  166. $cat_name = trim( $cat_name ); 
  167. $cat_nicename = sanitize_title( $cat_name ); 
  168.  
  169. if ( empty( $cat_nicename ) ) { 
  170. continue; 
  171.  
  172. // @todo Find a more performant way to check existence, maybe get_term() with a separate parent check. 
  173. if ( term_exists( $cat_name, $taxonomy->name, $parent ) ) { 
  174. if ( count( $names ) === 1 ) { 
  175. wp_send_json_error( array( 'errorMessage' => __( 'This category already exists.' ) ) ); 
  176. } else { 
  177. continue; 
  178.  
  179. $cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) ); 
  180.  
  181. if ( is_wp_error( $cat_id ) ) { 
  182. continue; 
  183. } elseif ( is_array( $cat_id ) ) { 
  184. $cat_id = $cat_id['term_id']; 
  185.  
  186. $added[] = $cat_id; 
  187.  
  188. if ( empty( $added ) ) { 
  189. wp_send_json_error( array( 'errorMessage' => __( 'This category cannot be added. Please change the name and try again.' ) ) ); 
  190.  
  191. foreach ( $added as $new_cat_id ) { 
  192. $new_cat = get_category( $new_cat_id ); 
  193.  
  194. if ( is_wp_error( $new_cat ) ) { 
  195. wp_send_json_error( array( 'errorMessage' => __( 'Error while adding the category. Please try again later.' ) ) ); 
  196.  
  197. $data[] = array( 
  198. 'term_id' => $new_cat->term_id,  
  199. 'name' => $new_cat->name,  
  200. 'parent' => $new_cat->parent,  
  201. ); 
  202. wp_send_json_success( $data ); 
  203.  
  204. /** 
  205. * Downloads the source's HTML via server-side call for the given URL. 
  206. * @since 4.2.0 
  207. * @access public 
  208. * @param string $url URL to scan. 
  209. * @return string Source's HTML sanitized markup 
  210. */ 
  211. public function fetch_source_html( $url ) { 
  212. global $wp_version; 
  213.  
  214. if ( empty( $url ) ) { 
  215. return new WP_Error( 'invalid-url', __( 'A valid URL was not provided.' ) ); 
  216.  
  217. $remote_url = wp_safe_remote_get( $url, array( 
  218. 'timeout' => 30,  
  219. // Use an explicit user-agent for Press This 
  220. 'user-agent' => 'Press This (WordPress/' . $wp_version . '); ' . get_bloginfo( 'url' ) 
  221. ) ); 
  222.  
  223. if ( is_wp_error( $remote_url ) ) { 
  224. return $remote_url; 
  225.  
  226. $allowed_elements = array( 
  227. 'img' => array( 
  228. 'src' => true,  
  229. 'width' => true,  
  230. 'height' => true,  
  231. ),  
  232. 'iframe' => array( 
  233. 'src' => true,  
  234. ),  
  235. 'link' => array( 
  236. 'rel' => true,  
  237. 'itemprop' => true,  
  238. 'href' => true,  
  239. ),  
  240. 'meta' => array( 
  241. 'property' => true,  
  242. 'name' => true,  
  243. 'content' => true,  
  244. ); 
  245.  
  246. $source_content = wp_remote_retrieve_body( $remote_url ); 
  247. $source_content = wp_kses( $source_content, $allowed_elements ); 
  248.  
  249. return $source_content; 
  250.  
  251. /** 
  252. * Utility method to limit an array to 50 values. 
  253. * @ignore 
  254. * @since 4.2.0 
  255. * @param array $value Array to limit. 
  256. * @return array Original array if fewer than 50 values, limited array, empty array otherwise. 
  257. */ 
  258. private function _limit_array( $value ) { 
  259. if ( is_array( $value ) ) { 
  260. if ( count( $value ) > 50 ) { 
  261. return array_slice( $value, 0, 50 ); 
  262.  
  263. return $value; 
  264.  
  265. return array(); 
  266.  
  267. /** 
  268. * Utility method to limit the length of a given string to 5, 000 characters. 
  269. * @ignore 
  270. * @since 4.2.0 
  271. * @param string $value String to limit. 
  272. * @return bool|int|string If boolean or integer, that value. If a string, the original value 
  273. * if fewer than 5, 000 characters, a truncated version, otherwise an 
  274. * empty string. 
  275. */ 
  276. private function _limit_string( $value ) { 
  277. $return = ''; 
  278.  
  279. if ( is_numeric( $value ) || is_bool( $value ) ) { 
  280. $return = $value; 
  281. } else if ( is_string( $value ) ) { 
  282. if ( mb_strlen( $value ) > 5000 ) { 
  283. $return = mb_substr( $value, 0, 5000 ); 
  284. } else { 
  285. $return = $value; 
  286.  
  287. $return = html_entity_decode( $return, ENT_QUOTES, 'UTF-8' ); 
  288. $return = sanitize_text_field( trim( $return ) ); 
  289.  
  290. return $return; 
  291.  
  292. /** 
  293. * Utility method to limit a given URL to 2, 048 characters. 
  294. * @ignore 
  295. * @since 4.2.0 
  296. * @param string $url URL to check for length and validity. 
  297. * @return string Escaped URL if of valid length (< 2048) and makeup. Empty string otherwise. 
  298. */ 
  299. private function _limit_url( $url ) { 
  300. if ( ! is_string( $url ) ) { 
  301. return ''; 
  302.  
  303. // HTTP 1.1 allows 8000 chars but the "de-facto" standard supported in all current browsers is 2048. 
  304. if ( strlen( $url ) > 2048 ) { 
  305. return ''; // Return empty rather than a truncated/invalid URL 
  306.  
  307. // Does not look like a URL. 
  308. if ( ! preg_match( '/^([!#$&-;=?-\[\]_a-z~]|%[0-9a-fA-F]{2})+$/', $url ) ) { 
  309. return ''; 
  310.  
  311. // If the URL is root-relative, prepend the protocol and domain name 
  312. if ( $url && $this->domain && preg_match( '%^/[^/]+%', $url ) ) { 
  313. $url = $this->domain . $url; 
  314.  
  315. // Not absolute or protocol-relative URL. 
  316. if ( ! preg_match( '%^(?:https?:)?//[^/]+%', $url ) ) { 
  317. return ''; 
  318.  
  319. return esc_url_raw( $url, array( 'http', 'https' ) ); 
  320.  
  321. /** 
  322. * Utility method to limit image source URLs. 
  323. * Excluded URLs include share-this type buttons, loaders, spinners, spacers, WordPress interface images,  
  324. * tiny buttons or thumbs, mathtag.com or quantserve.com images, or the WordPress.com stats gif. 
  325. * @ignore 
  326. * @since 4.2.0 
  327. * @param string $src Image source URL. 
  328. * @return string If not matched an excluded URL type, the original URL, empty string otherwise. 
  329. */ 
  330. private function _limit_img( $src ) { 
  331. $src = $this->_limit_url( $src ); 
  332.  
  333. if ( preg_match( '!/ad[sx]?/!i', $src ) ) { 
  334. // Ads 
  335. return ''; 
  336. } else if ( preg_match( '!(/share-?this[^.]+?\.[a-z0-9]{3, 4})(\?.*)?$!i', $src ) ) { 
  337. // Share-this type button 
  338. return ''; 
  339. } else if ( preg_match( '!/(spinner|loading|spacer|blank|rss)\.(gif|jpg|png)!i', $src ) ) { 
  340. // Loaders, spinners, spacers 
  341. return ''; 
  342. } else if ( preg_match( '!/([^./]+[-_])?(spinner|loading|spacer|blank)s?([-_][^./]+)?\.[a-z0-9]{3, 4}!i', $src ) ) { 
  343. // Fancy loaders, spinners, spacers 
  344. return ''; 
  345. } else if ( preg_match( '!([^./]+[-_])?thumb[^.]*\.(gif|jpg|png)$!i', $src ) ) { 
  346. // Thumbnails, too small, usually irrelevant to context 
  347. return ''; 
  348. } else if ( false !== stripos( $src, '/wp-includes/' ) ) { 
  349. // Classic WordPress interface images 
  350. return ''; 
  351. } else if ( preg_match( '![^\d]\d{1, 2}x\d+\.(gif|jpg|png)$!i', $src ) ) { 
  352. // Most often tiny buttons/thumbs (< 100px wide) 
  353. return ''; 
  354. } else if ( preg_match( '!/pixel\.(mathtag|quantserve)\.com!i', $src ) ) { 
  355. // See mathtag.com and https://www.quantcast.com/how-we-do-it/iab-standard-measurement/how-we-collect-data/ 
  356. return ''; 
  357. } else if ( preg_match( '!/[gb]\.gif(\?.+)?$!i', $src ) ) { 
  358. // WordPress.com stats gif 
  359. return ''; 
  360.  
  361. return $src; 
  362.  
  363. /** 
  364. * Limit embed source URLs to specific providers. 
  365. * Not all core oEmbed providers are supported. Supported providers include YouTube, Vimeo,  
  366. * Vine, Daily Motion, SoundCloud, and Twitter. 
  367. * @ignore 
  368. * @since 4.2.0 
  369. * @param string $src Embed source URL. 
  370. * @return string If not from a supported provider, an empty string. Otherwise, a reformattd embed URL. 
  371. */ 
  372. private function _limit_embed( $src ) { 
  373. $src = $this->_limit_url( $src ); 
  374.  
  375. if ( empty( $src ) ) 
  376. return ''; 
  377.  
  378. if ( preg_match( '!//(m|www)\.youtube\.com/(embed|v)/([^?]+)\?.+$!i', $src, $src_matches ) ) { 
  379. // Embedded Youtube videos (www or mobile) 
  380. $src = 'https://www.youtube.com/watch?v=' . $src_matches[3]; 
  381. } else if ( preg_match( '!//player\.vimeo\.com/video/([\d]+)([?/].*)?$!i', $src, $src_matches ) ) { 
  382. // Embedded Vimeo iframe videos 
  383. $src = 'https://vimeo.com/' . (int) $src_matches[1]; 
  384. } else if ( preg_match( '!//vimeo\.com/moogaloop\.swf\?clip_id=([\d]+)$!i', $src, $src_matches ) ) { 
  385. // Embedded Vimeo Flash videos 
  386. $src = 'https://vimeo.com/' . (int) $src_matches[1]; 
  387. } else if ( preg_match( '!//vine\.co/v/([^/]+)/embed!i', $src, $src_matches ) ) { 
  388. // Embedded Vine videos 
  389. $src = 'https://vine.co/v/' . $src_matches[1]; 
  390. } else if ( preg_match( '!//(www\.)?dailymotion\.com/embed/video/([^/?]+)([/?].+)?!i', $src, $src_matches ) ) { 
  391. // Embedded Daily Motion videos 
  392. $src = 'https://www.dailymotion.com/video/' . $src_matches[2]; 
  393. } else { 
  394. require_once( ABSPATH . WPINC . '/class-oembed.php' ); 
  395. $oembed = _wp_oembed_get_object(); 
  396.  
  397. if ( ! $oembed->get_provider( $src, array( 'discover' => false ) ) ) { 
  398. $src = ''; 
  399.  
  400. return $src; 
  401.  
  402. /** 
  403. * Process a meta data entry from the source. 
  404. * @ignore 
  405. * @since 4.2.0 
  406. * @param string $meta_name Meta key name. 
  407. * @param mixed $meta_value Meta value. 
  408. * @param array $data Associative array of source data. 
  409. * @return array Processed data array. 
  410. */ 
  411. private function _process_meta_entry( $meta_name, $meta_value, $data ) { 
  412. if ( preg_match( '/:?(title|description|keywords|site_name)$/', $meta_name ) ) { 
  413. $data['_meta'][ $meta_name ] = $meta_value; 
  414. } else { 
  415. switch ( $meta_name ) { 
  416. case 'og:url': 
  417. case 'og:video': 
  418. case 'og:video:secure_url': 
  419. $meta_value = $this->_limit_embed( $meta_value ); 
  420.  
  421. if ( ! isset( $data['_embeds'] ) ) { 
  422. $data['_embeds'] = array(); 
  423.  
  424. if ( ! empty( $meta_value ) && ! in_array( $meta_value, $data['_embeds'] ) ) { 
  425. $data['_embeds'][] = $meta_value; 
  426.  
  427. break; 
  428. case 'og:image': 
  429. case 'og:image:secure_url': 
  430. case 'twitter:image0:src': 
  431. case 'twitter:image0': 
  432. case 'twitter:image:src': 
  433. case 'twitter:image': 
  434. $meta_value = $this->_limit_img( $meta_value ); 
  435.  
  436. if ( ! isset( $data['_images'] ) ) { 
  437. $data['_images'] = array(); 
  438.  
  439. if ( ! empty( $meta_value ) && ! in_array( $meta_value, $data['_images'] ) ) { 
  440. $data['_images'][] = $meta_value; 
  441.  
  442. break; 
  443.  
  444. return $data; 
  445.  
  446. /** 
  447. * Fetches and parses _meta, _images, and _links data from the source. 
  448. * @since 4.2.0 
  449. * @access public 
  450. * @param string $url URL to scan. 
  451. * @param array $data Optional. Existing data array if you have one. Default empty array. 
  452. * @return array New data array. 
  453. */ 
  454. public function source_data_fetch_fallback( $url, $data = array() ) { 
  455. if ( empty( $url ) ) { 
  456. return array(); 
  457.  
  458. // Download source page to tmp file. 
  459. $source_content = $this->fetch_source_html( $url ); 
  460. if ( is_wp_error( $source_content ) ) { 
  461. return array( 'errors' => $source_content->get_error_messages() ); 
  462.  
  463. // Fetch and gather <meta> data first, so discovered media is offered 1st to user. 
  464. if ( empty( $data['_meta'] ) ) { 
  465. $data['_meta'] = array(); 
  466.  
  467. if ( preg_match_all( '/<meta [^>]+>/', $source_content, $matches ) ) { 
  468. $items = $this->_limit_array( $matches[0] ); 
  469.  
  470. foreach ( $items as $value ) { 
  471. if ( preg_match( '/(property|name)="([^"]+)"[^>]+content="([^"]+)"/', $value, $new_matches ) ) { 
  472. $meta_name = $this->_limit_string( $new_matches[2] ); 
  473. $meta_value = $this->_limit_string( $new_matches[3] ); 
  474.  
  475. // Sanity check. $key is usually things like 'title', 'description', 'keywords', etc. 
  476. if ( strlen( $meta_name ) > 100 ) { 
  477. continue; 
  478.  
  479. $data = $this->_process_meta_entry( $meta_name, $meta_value, $data ); 
  480.  
  481. // Fetch and gather <img> data. 
  482. if ( empty( $data['_images'] ) ) { 
  483. $data['_images'] = array(); 
  484.  
  485. if ( preg_match_all( '/<img [^>]+>/', $source_content, $matches ) ) { 
  486. $items = $this->_limit_array( $matches[0] ); 
  487.  
  488. foreach ( $items as $value ) { 
  489. if ( ( preg_match( '/width=(\'|")(\d+)\\1/i', $value, $new_matches ) && $new_matches[2] < 256 ) || 
  490. ( preg_match( '/height=(\'|")(\d+)\\1/i', $value, $new_matches ) && $new_matches[2] < 128 ) ) { 
  491.  
  492. continue; 
  493.  
  494. if ( preg_match( '/src=(\'|")([^\'"]+)\\1/i', $value, $new_matches ) ) { 
  495. $src = $this->_limit_img( $new_matches[2] ); 
  496. if ( ! empty( $src ) && ! in_array( $src, $data['_images'] ) ) { 
  497. $data['_images'][] = $src; 
  498.  
  499. // Fetch and gather <iframe> data. 
  500. if ( empty( $data['_embeds'] ) ) { 
  501. $data['_embeds'] = array(); 
  502.  
  503. if ( preg_match_all( '/<iframe [^>]+>/', $source_content, $matches ) ) { 
  504. $items = $this->_limit_array( $matches[0] ); 
  505.  
  506. foreach ( $items as $value ) { 
  507. if ( preg_match( '/src=(\'|")([^\'"]+)\\1/', $value, $new_matches ) ) { 
  508. $src = $this->_limit_embed( $new_matches[2] ); 
  509.  
  510. if ( ! empty( $src ) && ! in_array( $src, $data['_embeds'] ) ) { 
  511. $data['_embeds'][] = $src; 
  512.  
  513. // Fetch and gather <link> data. 
  514. if ( empty( $data['_links'] ) ) { 
  515. $data['_links'] = array(); 
  516.  
  517. if ( preg_match_all( '/<link [^>]+>/', $source_content, $matches ) ) { 
  518. $items = $this->_limit_array( $matches[0] ); 
  519.  
  520. foreach ( $items as $value ) { 
  521. if ( preg_match( '/rel=["\'](canonical|shortlink|icon)["\']/i', $value, $matches_rel ) && preg_match( '/href=[\'"]([^\'" ]+)[\'"]/i', $value, $matches_url ) ) { 
  522. $rel = $matches_rel[1]; 
  523. $url = $this->_limit_url( $matches_url[1] ); 
  524.  
  525. if ( ! empty( $url ) && empty( $data['_links'][ $rel ] ) ) { 
  526. $data['_links'][ $rel ] = $url; 
  527.  
  528. return $data; 
  529.  
  530. /** 
  531. * Handles backward-compat with the legacy version of Press This by supporting its query string params. 
  532. * @since 4.2.0 
  533. * @access public 
  534. * @return array 
  535. */ 
  536. public function merge_or_fetch_data() { 
  537. // Get data from $_POST and $_GET, as appropriate ($_POST > $_GET), to remain backward compatible. 
  538. $data = array(); 
  539.  
  540. // Only instantiate the keys we want. Sanity check and sanitize each one. 
  541. foreach ( array( 'u', 's', 't', 'v' ) as $key ) { 
  542. if ( ! empty( $_POST[ $key ] ) ) { 
  543. $value = wp_unslash( $_POST[ $key ] ); 
  544. } else if ( ! empty( $_GET[ $key ] ) ) { 
  545. $value = wp_unslash( $_GET[ $key ] ); 
  546. } else { 
  547. continue; 
  548.  
  549. if ( 'u' === $key ) { 
  550. $value = $this->_limit_url( $value ); 
  551.  
  552. if ( preg_match( '%^(?:https?:)?//[^/]+%i', $value, $domain_match ) ) { 
  553. $this->domain = $domain_match[0]; 
  554. } else { 
  555. $value = $this->_limit_string( $value ); 
  556.  
  557. if ( ! empty( $value ) ) { 
  558. $data[ $key ] = $value; 
  559.  
  560. /** 
  561. * Filters whether to enable in-source media discovery in Press This. 
  562. * @since 4.2.0 
  563. * @param bool $enable Whether to enable media discovery. 
  564. */ 
  565. if ( apply_filters( 'enable_press_this_media_discovery', true ) ) { 
  566. /** 
  567. * If no title, _images, _embed, and _meta was passed via $_POST, fetch data from source as fallback,  
  568. * making PT fully backward compatible with the older bookmarklet. 
  569. */ 
  570. if ( empty( $_POST ) && ! empty( $data['u'] ) ) { 
  571. $data = $this->source_data_fetch_fallback( $data['u'], $data ); 
  572. } else { 
  573. foreach ( array( '_images', '_embeds' ) as $type ) { 
  574. if ( empty( $_POST[ $type ] ) ) { 
  575. continue; 
  576.  
  577. $data[ $type ] = array(); 
  578. $items = $this->_limit_array( $_POST[ $type ] ); 
  579.  
  580. foreach ( $items as $key => $value ) { 
  581. if ( $type === '_images' ) { 
  582. $value = $this->_limit_img( wp_unslash( $value ) ); 
  583. } else { 
  584. $value = $this->_limit_embed( wp_unslash( $value ) ); 
  585.  
  586. if ( ! empty( $value ) ) { 
  587. $data[ $type ][] = $value; 
  588.  
  589. foreach ( array( '_meta', '_links' ) as $type ) { 
  590. if ( empty( $_POST[ $type ] ) ) { 
  591. continue; 
  592.  
  593. $data[ $type ] = array(); 
  594. $items = $this->_limit_array( $_POST[ $type ] ); 
  595.  
  596. foreach ( $items as $key => $value ) { 
  597. // Sanity check. These are associative arrays, $key is usually things like 'title', 'description', 'keywords', etc. 
  598. if ( empty( $key ) || strlen( $key ) > 100 ) { 
  599. continue; 
  600.  
  601. if ( $type === '_meta' ) { 
  602. $value = $this->_limit_string( wp_unslash( $value ) ); 
  603.  
  604. if ( ! empty( $value ) ) { 
  605. $data = $this->_process_meta_entry( $key, $value, $data ); 
  606. } else { 
  607. if ( in_array( $key, array( 'canonical', 'shortlink', 'icon' ), true ) ) { 
  608. $data[ $type ][ $key ] = $this->_limit_url( wp_unslash( $value ) ); 
  609.  
  610. // Support passing a single image src as `i` 
  611. if ( ! empty( $_REQUEST['i'] ) && ( $img_src = $this->_limit_img( wp_unslash( $_REQUEST['i'] ) ) ) ) { 
  612. if ( empty( $data['_images'] ) ) { 
  613. $data['_images'] = array( $img_src ); 
  614. } elseif ( ! in_array( $img_src, $data['_images'], true ) ) { 
  615. array_unshift( $data['_images'], $img_src ); 
  616.  
  617. /** 
  618. * Filters the Press This data array. 
  619. * @since 4.2.0 
  620. * @param array $data Press This Data array. 
  621. */ 
  622. return apply_filters( 'press_this_data', $data ); 
  623.  
  624. /** 
  625. * Adds another stylesheet inside TinyMCE. 
  626. * @since 4.2.0 
  627. * @access public 
  628. * @param string $styles URL to editor stylesheet. 
  629. * @return string Possibly modified stylesheets list. 
  630. */ 
  631. public function add_editor_style( $styles ) { 
  632. if ( ! empty( $styles ) ) { 
  633. $styles .= ', '; 
  634.  
  635. $press_this = admin_url( 'css/press-this-editor.css' ); 
  636. if ( is_rtl() ) { 
  637. $press_this = str_replace( '.css', '-rtl.css', $press_this ); 
  638.  
  639. return $styles . $press_this; 
  640.  
  641. /** 
  642. * Outputs the post format selection HTML. 
  643. * @since 4.2.0 
  644. * @access public 
  645. * @param WP_Post $post Post object. 
  646. */ 
  647. public function post_formats_html( $post ) { 
  648. if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) ) { 
  649. $post_formats = get_theme_support( 'post-formats' ); 
  650.  
  651. if ( is_array( $post_formats[0] ) ) { 
  652. $post_format = get_post_format( $post->ID ); 
  653.  
  654. if ( ! $post_format ) { 
  655. $post_format = '0'; 
  656.  
  657. // Add in the current one if it isn't there yet, in case the current theme doesn't support it. 
  658. if ( $post_format && ! in_array( $post_format, $post_formats[0] ) ) { 
  659. $post_formats[0][] = $post_format; 
  660.  
  661. ?> 
  662. <div id="post-formats-select"> 
  663. <fieldset><legend class="screen-reader-text"><?php _e( 'Post Formats' ); ?></legend> 
  664. <input type="radio" name="post_format" class="post-format" id="post-format-0" value="0" <?php checked( $post_format, '0' ); ?> /> 
  665. <label for="post-format-0" class="post-format-icon post-format-standard"><?php echo get_post_format_string( 'standard' ); ?></label> 
  666. <?php 
  667.  
  668. foreach ( $post_formats[0] as $format ) { 
  669. $attr_format = esc_attr( $format ); 
  670. ?> 
  671. <br /> 
  672. <input type="radio" name="post_format" class="post-format" id="post-format-<?php echo $attr_format; ?>" value="<?php echo $attr_format; ?>" <?php checked( $post_format, $format ); ?> /> 
  673. <label for="post-format-<?php echo $attr_format ?>" class="post-format-icon post-format-<?php echo $attr_format; ?>"><?php echo esc_html( get_post_format_string( $format ) ); ?></label> 
  674. <?php 
  675.  
  676. ?> 
  677. </fieldset> 
  678. </div> 
  679. <?php 
  680.  
  681. /** 
  682. * Outputs the categories HTML. 
  683. * @since 4.2.0 
  684. * @access public 
  685. * @param WP_Post $post Post object. 
  686. */ 
  687. public function categories_html( $post ) { 
  688. $taxonomy = get_taxonomy( 'category' ); 
  689.  
  690. if ( current_user_can( $taxonomy->cap->edit_terms ) ) { 
  691. ?> 
  692. <button type="button" class="add-cat-toggle button-link" aria-expanded="false"> 
  693. <span class="dashicons dashicons-plus"></span><span class="screen-reader-text"><?php _e( 'Toggle add category' ); ?></span> 
  694. </button> 
  695. <div class="add-category is-hidden"> 
  696. <label class="screen-reader-text" for="new-category"><?php echo $taxonomy->labels->add_new_item; ?></label> 
  697. <input type="text" id="new-category" class="add-category-name" placeholder="<?php echo esc_attr( $taxonomy->labels->new_item_name ); ?>" value="" aria-required="true"> 
  698. <label class="screen-reader-text" for="new-category-parent"><?php echo $taxonomy->labels->parent_item_colon; ?></label> 
  699. <div class="postform-wrapper"> 
  700. <?php 
  701. wp_dropdown_categories( array( 
  702. 'taxonomy' => 'category',  
  703. 'hide_empty' => 0,  
  704. 'name' => 'new-category-parent',  
  705. 'orderby' => 'name',  
  706. 'hierarchical' => 1,  
  707. 'show_option_none' => '— ' . $taxonomy->labels->parent_item . ' —' 
  708. ) ); 
  709. ?> 
  710. </div> 
  711. <button type="button" class="add-cat-submit"><?php _e( 'Add' ); ?></button> 
  712. </div> 
  713. <?php 
  714.  
  715. ?> 
  716. <div class="categories-search-wrapper"> 
  717. <input id="categories-search" type="search" class="categories-search" placeholder="<?php esc_attr_e( 'Search categories by name' ) ?>"> 
  718. <label for="categories-search"> 
  719. <span class="dashicons dashicons-search"></span><span class="screen-reader-text"><?php _e( 'Search categories' ); ?></span> 
  720. </label> 
  721. </div> 
  722. <div aria-label="<?php esc_attr_e( 'Categories' ); ?>"> 
  723. <ul class="categories-select"> 
  724. <?php wp_terms_checklist( $post->ID, array( 'taxonomy' => 'category', 'list_only' => true ) ); ?> 
  725. </ul> 
  726. </div> 
  727. <?php 
  728.  
  729. /** 
  730. * Outputs the tags HTML. 
  731. * @since 4.2.0 
  732. * @access public 
  733. * @param WP_Post $post Post object. 
  734. */ 
  735. public function tags_html( $post ) { 
  736. $taxonomy = get_taxonomy( 'post_tag' ); 
  737. $user_can_assign_terms = current_user_can( $taxonomy->cap->assign_terms ); 
  738. $esc_tags = get_terms_to_edit( $post->ID, 'post_tag' ); 
  739.  
  740. if ( ! $esc_tags || is_wp_error( $esc_tags ) ) { 
  741. $esc_tags = ''; 
  742.  
  743. ?> 
  744. <div class="tagsdiv" id="post_tag"> 
  745. <div class="jaxtag"> 
  746. <input type="hidden" name="tax_input[post_tag]" class="the-tags" value="<?php echo $esc_tags; // escaped in get_terms_to_edit() ?>"> 
  747. <?php 
  748.  
  749. if ( $user_can_assign_terms ) { 
  750. ?> 
  751. <div class="ajaxtag hide-if-no-js"> 
  752. <label class="screen-reader-text" for="new-tag-post_tag"><?php _e( 'Tags' ); ?></label> 
  753. <p> 
  754. <input type="text" id="new-tag-post_tag" name="newtag[post_tag]" class="newtag form-input-tip" size="16" autocomplete="off" value="" aria-describedby="new-tag-desc" /> 
  755. <button type="button" class="tagadd"><?php _e( 'Add' ); ?></button> 
  756. </p> 
  757. </div> 
  758. <p class="howto" id="new-tag-desc"> 
  759. <?php echo $taxonomy->labels->separate_items_with_commas; ?> 
  760. </p> 
  761. <?php 
  762.  
  763. ?> 
  764. </div> 
  765. <div class="tagchecklist"></div> 
  766. </div> 
  767. <?php 
  768.  
  769. if ( $user_can_assign_terms ) { 
  770. ?> 
  771. <button type="button" class="button-link tagcloud-link" id="link-post_tag"><?php echo $taxonomy->labels->choose_from_most_used; ?></button> 
  772. <?php 
  773.  
  774. /** 
  775. * Get a list of embeds with no duplicates. 
  776. * @since 4.2.0 
  777. * @access public 
  778. * @param array $data The site's data. 
  779. * @return array Embeds selected to be available. 
  780. */ 
  781. public function get_embeds( $data ) { 
  782. $selected_embeds = array(); 
  783.  
  784. // Make sure to add the Pressed page if it's a valid oembed itself 
  785. if ( ! empty ( $data['u'] ) && $this->_limit_embed( $data['u'] ) ) { 
  786. $data['_embeds'][] = $data['u']; 
  787.  
  788. if ( ! empty( $data['_embeds'] ) ) { 
  789. foreach ( $data['_embeds'] as $src ) { 
  790. $prot_relative_src = preg_replace( '/^https?:/', '', $src ); 
  791.  
  792. if ( in_array( $prot_relative_src, $this->embeds ) ) { 
  793. continue; 
  794.  
  795. $selected_embeds[] = $src; 
  796. $this->embeds[] = $prot_relative_src; 
  797.  
  798. return $selected_embeds; 
  799.  
  800. /** 
  801. * Get a list of images with no duplicates. 
  802. * @since 4.2.0 
  803. * @access public 
  804. * @param array $data The site's data. 
  805. * @return array 
  806. */ 
  807. public function get_images( $data ) { 
  808. $selected_images = array(); 
  809.  
  810. if ( ! empty( $data['_images'] ) ) { 
  811. foreach ( $data['_images'] as $src ) { 
  812. if ( false !== strpos( $src, 'gravatar.com' ) ) { 
  813. $src = preg_replace( '%http://[\d]+\.gravatar\.com/%', 'https://secure.gravatar.com/', $src ); 
  814.  
  815. $prot_relative_src = preg_replace( '/^https?:/', '', $src ); 
  816.  
  817. if ( in_array( $prot_relative_src, $this->images ) || 
  818. ( false !== strpos( $src, 'avatar' ) && count( $this->images ) > 15 ) ) { 
  819. // Skip: already selected or some type of avatar and we've already gathered more than 15 images. 
  820. continue; 
  821.  
  822. $selected_images[] = $src; 
  823. $this->images[] = $prot_relative_src; 
  824.  
  825. return $selected_images; 
  826.  
  827. /** 
  828. * Gets the source page's canonical link, based on passed location and meta data. 
  829. * @since 4.2.0 
  830. * @access public 
  831. * @param array $data The site's data. 
  832. * @return string Discovered canonical URL, or empty 
  833. */ 
  834. public function get_canonical_link( $data ) { 
  835. $link = ''; 
  836.  
  837. if ( ! empty( $data['_links']['canonical'] ) ) { 
  838. $link = $data['_links']['canonical']; 
  839. } elseif ( ! empty( $data['u'] ) ) { 
  840. $link = $data['u']; 
  841. } elseif ( ! empty( $data['_meta'] ) ) { 
  842. if ( ! empty( $data['_meta']['twitter:url'] ) ) { 
  843. $link = $data['_meta']['twitter:url']; 
  844. } else if ( ! empty( $data['_meta']['og:url'] ) ) { 
  845. $link = $data['_meta']['og:url']; 
  846.  
  847. if ( empty( $link ) && ! empty( $data['_links']['shortlink'] ) ) { 
  848. $link = $data['_links']['shortlink']; 
  849.  
  850. return $link; 
  851.  
  852. /** 
  853. * Gets the source page's site name, based on passed meta data. 
  854. * @since 4.2.0 
  855. * @access public 
  856. * @param array $data The site's data. 
  857. * @return string Discovered site name, or empty 
  858. */ 
  859. public function get_source_site_name( $data ) { 
  860. $name = ''; 
  861.  
  862. if ( ! empty( $data['_meta'] ) ) { 
  863. if ( ! empty( $data['_meta']['og:site_name'] ) ) { 
  864. $name = $data['_meta']['og:site_name']; 
  865. } else if ( ! empty( $data['_meta']['application-name'] ) ) { 
  866. $name = $data['_meta']['application-name']; 
  867.  
  868. return $name; 
  869.  
  870. /** 
  871. * Gets the source page's title, based on passed title and meta data. 
  872. * @since 4.2.0 
  873. * @access public 
  874. * @param array $data The site's data. 
  875. * @return string Discovered page title, or empty 
  876. */ 
  877. public function get_suggested_title( $data ) { 
  878. $title = ''; 
  879.  
  880. if ( ! empty( $data['t'] ) ) { 
  881. $title = $data['t']; 
  882. } elseif ( ! empty( $data['_meta'] ) ) { 
  883. if ( ! empty( $data['_meta']['twitter:title'] ) ) { 
  884. $title = $data['_meta']['twitter:title']; 
  885. } else if ( ! empty( $data['_meta']['og:title'] ) ) { 
  886. $title = $data['_meta']['og:title']; 
  887. } else if ( ! empty( $data['_meta']['title'] ) ) { 
  888. $title = $data['_meta']['title']; 
  889.  
  890. return $title; 
  891.  
  892. /** 
  893. * Gets the source page's suggested content, based on passed data (description, selection, etc). 
  894. * Features a blockquoted excerpt, as well as content attribution, if any. 
  895. * @since 4.2.0 
  896. * @access public 
  897. * @param array $data The site's data. 
  898. * @return string Discovered content, or empty 
  899. */ 
  900. public function get_suggested_content( $data ) { 
  901. $content = $text = ''; 
  902.  
  903. if ( ! empty( $data['s'] ) ) { 
  904. $text = $data['s']; 
  905. } else if ( ! empty( $data['_meta'] ) ) { 
  906. if ( ! empty( $data['_meta']['twitter:description'] ) ) { 
  907. $text = $data['_meta']['twitter:description']; 
  908. } else if ( ! empty( $data['_meta']['og:description'] ) ) { 
  909. $text = $data['_meta']['og:description']; 
  910. } else if ( ! empty( $data['_meta']['description'] ) ) { 
  911. $text = $data['_meta']['description']; 
  912.  
  913. // If there is an ellipsis at the end, the description is very likely auto-generated. Better to ignore it. 
  914. if ( $text && substr( $text, -3 ) === '...' ) { 
  915. $text = ''; 
  916.  
  917. $default_html = array( 'quote' => '', 'link' => '', 'embed' => '' ); 
  918.  
  919. if ( ! empty( $data['u'] ) && $this->_limit_embed( $data['u'] ) ) { 
  920. $default_html['embed'] = '<p>[embed]' . $data['u'] . '[/embed]</p>'; 
  921.  
  922. if ( ! empty( $data['s'] ) ) { 
  923. // If the user has selected some text, do quote it. 
  924. $default_html['quote'] = '<blockquote>%1$s</blockquote>'; 
  925. } else { 
  926. $default_html['quote'] = '<blockquote>%1$s</blockquote>'; 
  927. $default_html['link'] = '<p>' . _x( 'Source:', 'Used in Press This to indicate where the content comes from.' ) . 
  928. ' <em><a href="%1$s">%2$s</a></em></p>'; 
  929.  
  930. /** 
  931. * Filters the default HTML tags used in the suggested content for the editor. 
  932. * The HTML strings use printf format. After filtering the content is added at the specified places with `sprintf()`. 
  933. * @since 4.2.0 
  934. * @param array $default_html Associative array with three possible keys: 
  935. * - 'quote' where %1$s is replaced with the site description or the selected content. 
  936. * - 'link' where %1$s is link href, %2$s is link text, usually the source page title. 
  937. * - 'embed' which contains an [embed] shortcode when the source page offers embeddable content. 
  938. * @param array $data Associative array containing the data from the source page. 
  939. */ 
  940. $default_html = apply_filters( 'press_this_suggested_html', $default_html, $data ); 
  941.  
  942. if ( ! empty( $default_html['embed'] ) ) { 
  943. $content .= $default_html['embed']; 
  944.  
  945. // Wrap suggested content in the specified HTML. 
  946. if ( ! empty( $default_html['quote'] ) && $text ) { 
  947. $content .= sprintf( $default_html['quote'], $text ); 
  948.  
  949. // Add source attribution if there is one available. 
  950. if ( ! empty( $default_html['link'] ) ) { 
  951. $title = $this->get_suggested_title( $data ); 
  952. $url = $this->get_canonical_link( $data ); 
  953.  
  954. if ( ! $title ) { 
  955. $title = $this->get_source_site_name( $data ); 
  956.  
  957. if ( $url && $title ) { 
  958. $content .= sprintf( $default_html['link'], $url, $title ); 
  959.  
  960. return $content; 
  961.  
  962. /** 
  963. * Serves the app's base HTML, which in turns calls the load script. 
  964. * @since 4.2.0 
  965. * @access public 
  966. * @global WP_Locale $wp_locale 
  967. * @global string $wp_version 
  968. * @global bool $is_IE 
  969. */ 
  970. public function html() { 
  971. global $wp_locale, $wp_version; 
  972.  
  973. // Get data, new (POST) and old (GET). 
  974. $data = $this->merge_or_fetch_data(); 
  975.  
  976. $post_title = $this->get_suggested_title( $data ); 
  977.  
  978. $post_content = $this->get_suggested_content( $data ); 
  979.  
  980. // Get site settings array/data. 
  981. $site_settings = $this->site_settings(); 
  982.  
  983. // Pass the images and embeds 
  984. $images = $this->get_images( $data ); 
  985. $embeds = $this->get_embeds( $data ); 
  986.  
  987. $site_data = array( 
  988. 'v' => ! empty( $data['v'] ) ? $data['v'] : '',  
  989. 'u' => ! empty( $data['u'] ) ? $data['u'] : '',  
  990. 'hasData' => ! empty( $data ),  
  991. ); 
  992.  
  993. if ( ! empty( $images ) ) { 
  994. $site_data['_images'] = $images; 
  995.  
  996. if ( ! empty( $embeds ) ) { 
  997. $site_data['_embeds'] = $embeds; 
  998.  
  999. // Add press-this-editor.css and remove theme's editor-style.css, if any. 
  1000. remove_editor_styles(); 
  1001.  
  1002. add_filter( 'mce_css', array( $this, 'add_editor_style' ) ); 
  1003.  
  1004. if ( ! empty( $GLOBALS['is_IE'] ) ) { 
  1005. @header( 'X-UA-Compatible: IE=edge' ); 
  1006.  
  1007. @header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) ); 
  1008.  
  1009. ?> 
  1010. <!DOCTYPE html> 
  1011. <!--[if IE 7]> <html class="lt-ie9 lt-ie8" <?php language_attributes(); ?>> <![endif]--> 
  1012. <!--[if IE 8]> <html class="lt-ie9" <?php language_attributes(); ?>> <![endif]--> 
  1013. <!--[if gt IE 8]><!--> <html <?php language_attributes(); ?>> <!--<![endif]--> 
  1014. <head> 
  1015. <meta http-equiv="Content-Type" content="<?php echo esc_attr( get_bloginfo( 'html_type' ) ); ?>; charset=<?php echo esc_attr( get_option( 'blog_charset' ) ); ?>" /> 
  1016. <meta name="viewport" content="width=device-width"> 
  1017. <title><?php esc_html_e( 'Press This!' ) ?></title> 
  1018.  
  1019. <script> 
  1020. window.wpPressThisData = <?php echo wp_json_encode( $site_data ); ?>; 
  1021. window.wpPressThisConfig = <?php echo wp_json_encode( $site_settings ); ?>; 
  1022. </script> 
  1023.  
  1024. <script type="text/javascript"> 
  1025. var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ?>',  
  1026. pagenow = 'press-this',  
  1027. typenow = 'post',  
  1028. adminpage = 'press-this-php',  
  1029. thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',  
  1030. decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',  
  1031. isRtl = <?php echo (int) is_rtl(); ?>; 
  1032. </script> 
  1033.  
  1034. <?php 
  1035. /** 
  1036. * $post->ID is needed for the embed shortcode so we can show oEmbed previews in the editor. 
  1037. * Maybe find a way without it. 
  1038. */ 
  1039. $post = get_default_post_to_edit( 'post', true ); 
  1040. $post_ID = (int) $post->ID; 
  1041.  
  1042. wp_enqueue_media( array( 'post' => $post_ID ) ); 
  1043. wp_enqueue_style( 'press-this' ); 
  1044. wp_enqueue_script( 'press-this' ); 
  1045. wp_enqueue_script( 'json2' ); 
  1046. wp_enqueue_script( 'editor' ); 
  1047.  
  1048. $supports_formats = false; 
  1049. $post_format = 0; 
  1050.  
  1051. if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) ) { 
  1052. $supports_formats = true; 
  1053.  
  1054. if ( ! ( $post_format = get_post_format( $post_ID ) ) ) { 
  1055. $post_format = 0; 
  1056.  
  1057. /** This action is documented in wp-admin/admin-header.php */ 
  1058. do_action( 'admin_enqueue_scripts', 'press-this.php' ); 
  1059.  
  1060. /** This action is documented in wp-admin/admin-header.php */ 
  1061. do_action( 'admin_print_styles-press-this.php' ); 
  1062.  
  1063. /** This action is documented in wp-admin/admin-header.php */ 
  1064. do_action( 'admin_print_styles' ); 
  1065.  
  1066. /** This action is documented in wp-admin/admin-header.php */ 
  1067. do_action( 'admin_print_scripts-press-this.php' ); 
  1068.  
  1069. /** This action is documented in wp-admin/admin-header.php */ 
  1070. do_action( 'admin_print_scripts' ); 
  1071.  
  1072. /** This action is documented in wp-admin/admin-header.php */ 
  1073. do_action( 'admin_head-press-this.php' ); 
  1074.  
  1075. /** This action is documented in wp-admin/admin-header.php */ 
  1076. do_action( 'admin_head' ); 
  1077. ?> 
  1078. </head> 
  1079. <?php 
  1080.  
  1081. $admin_body_class = 'press-this'; 
  1082. $admin_body_class .= ( is_rtl() ) ? ' rtl' : ''; 
  1083. $admin_body_class .= ' branch-' . str_replace( array( '.', ', ' ), '-', floatval( $wp_version ) ); 
  1084. $admin_body_class .= ' version-' . str_replace( '.', '-', preg_replace( '/^([.0-9]+).*/', '$1', $wp_version ) ); 
  1085. $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); 
  1086. $admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) ); 
  1087.  
  1088. /** This filter is documented in wp-admin/admin-header.php */ 
  1089. $admin_body_classes = apply_filters( 'admin_body_class', '' ); 
  1090.  
  1091. ?> 
  1092. <body class="wp-admin wp-core-ui <?php echo $admin_body_classes . ' ' . $admin_body_class; ?>"> 
  1093. <div id="adminbar" class="adminbar"> 
  1094. <h1 id="current-site" class="current-site"> 
  1095. <a class="current-site-link" href="<?php echo esc_url( home_url( '/' ) ); ?>" target="_blank" rel="home"> 
  1096. <span class="dashicons dashicons-wordpress"></span> 
  1097. <span class="current-site-name"><?php bloginfo( 'name' ); ?></span> 
  1098. </a> 
  1099. </h1> 
  1100. <button type="button" class="options button-link closed"> 
  1101. <span class="dashicons dashicons-tag on-closed"></span> 
  1102. <span class="screen-reader-text on-closed"><?php _e( 'Show post options' ); ?></span> 
  1103. <span aria-hidden="true" class="on-open"><?php _e( 'Done' ); ?></span> 
  1104. <span class="screen-reader-text on-open"><?php _e( 'Hide post options' ); ?></span> 
  1105. </button> 
  1106. </div> 
  1107.  
  1108. <div id="scanbar" class="scan"> 
  1109. <form method="GET"> 
  1110. <label for="url-scan" class="screen-reader-text"><?php _e( 'Scan site for content' ); ?></label> 
  1111. <input type="url" name="u" id="url-scan" class="scan-url" value="" placeholder="<?php esc_attr_e( 'Enter a URL to scan' ) ?>" /> 
  1112. <input type="submit" name="url-scan-submit" id="url-scan-submit" class="scan-submit" value="<?php esc_attr_e( 'Scan' ) ?>" /> 
  1113. </form> 
  1114. </div> 
  1115.  
  1116. <form id="pressthis-form" method="post" action="post.php" autocomplete="off"> 
  1117. <input type="hidden" name="post_ID" id="post_ID" value="<?php echo $post_ID; ?>" /> 
  1118. <input type="hidden" name="action" value="press-this-save-post" /> 
  1119. <input type="hidden" name="post_status" id="post_status" value="draft" /> 
  1120. <input type="hidden" name="wp-preview" id="wp-preview" value="" /> 
  1121. <input type="hidden" name="post_title" id="post_title" value="" /> 
  1122. <input type="hidden" name="pt-force-redirect" id="pt-force-redirect" value="" /> 
  1123. <?php 
  1124.  
  1125. wp_nonce_field( 'update-post_' . $post_ID, '_wpnonce', false ); 
  1126. wp_nonce_field( 'add-category', '_ajax_nonce-add-category', false ); 
  1127.  
  1128. ?> 
  1129.  
  1130. <div class="wrapper"> 
  1131. <div class="editor-wrapper"> 
  1132. <div class="alerts" role="alert" aria-live="assertive" aria-relevant="all" aria-atomic="true"> 
  1133. <?php 
  1134.  
  1135. if ( isset( $data['v'] ) && $this->version > $data['v'] ) { 
  1136. ?> 
  1137. <p class="alert is-notice"> 
  1138. <?php printf( __( 'You should upgrade <a href="%s" target="_blank">your bookmarklet</a> to the latest version!' ), admin_url( 'tools.php' ) ); ?> 
  1139. </p> 
  1140. <?php 
  1141.  
  1142. ?> 
  1143. </div> 
  1144.  
  1145. <div id="app-container" class="editor"> 
  1146. <span id="title-container-label" class="post-title-placeholder" aria-hidden="true"><?php _e( 'Post title' ); ?></span> 
  1147. <h2 id="title-container" class="post-title" contenteditable="true" spellcheck="true" aria-label="<?php esc_attr_e( 'Post title' ); ?>" tabindex="0"><?php echo esc_html( $post_title ); ?></h2> 
  1148.  
  1149. <div class="media-list-container"> 
  1150. <div class="media-list-inner-container"> 
  1151. <h2 class="screen-reader-text"><?php _e( 'Suggested media' ); ?></h2> 
  1152. <ul class="media-list"></ul> 
  1153. </div> 
  1154. </div> 
  1155.  
  1156. <?php 
  1157. wp_editor( $post_content, 'pressthis', array( 
  1158. 'drag_drop_upload' => true,  
  1159. 'editor_height' => 600,  
  1160. 'media_buttons' => false,  
  1161. 'textarea_name' => 'post_content',  
  1162. 'teeny' => true,  
  1163. 'tinymce' => array( 
  1164. 'resize' => false,  
  1165. 'wordpress_adv_hidden' => false,  
  1166. 'add_unload_trigger' => false,  
  1167. 'statusbar' => false,  
  1168. 'autoresize_min_height' => 600,  
  1169. 'wp_autoresize_on' => true,  
  1170. 'plugins' => 'lists, media, paste, tabfocus, fullscreen, wordpress, wpautoresize, wpeditimage, wpgallery, wplink, wptextpattern, wpview',  
  1171. 'toolbar1' => 'bold, italic, bullist, numlist, blockquote, link, unlink',  
  1172. 'toolbar2' => 'undo, redo',  
  1173. ),  
  1174. 'quicktags' => array( 
  1175. 'buttons' => 'strong, em, link, block, del, ins, img, ul, ol, li, code, more',  
  1176. ),  
  1177. ) ); 
  1178.  
  1179. ?> 
  1180. </div> 
  1181. </div> 
  1182.  
  1183. <div class="options-panel-back is-hidden" tabindex="-1"></div> 
  1184. <div class="options-panel is-off-screen is-hidden" tabindex="-1"> 
  1185. <div class="post-options"> 
  1186.  
  1187. <?php if ( $supports_formats ) : ?> 
  1188. <button type="button" class="button-link post-option"> 
  1189. <span class="dashicons dashicons-admin-post"></span> 
  1190. <span class="post-option-title"><?php _ex( 'Format', 'post format' ); ?></span> 
  1191. <span class="post-option-contents" id="post-option-post-format"><?php echo esc_html( get_post_format_string( $post_format ) ); ?></span> 
  1192. <span class="dashicons post-option-forward"></span> 
  1193. </button> 
  1194. <?php endif; ?> 
  1195.  
  1196. <button type="button" class="button-link post-option"> 
  1197. <span class="dashicons dashicons-category"></span> 
  1198. <span class="post-option-title"><?php _e( 'Categories' ); ?></span> 
  1199. <span class="dashicons post-option-forward"></span> 
  1200. </button> 
  1201.  
  1202. <button type="button" class="button-link post-option"> 
  1203. <span class="dashicons dashicons-tag"></span> 
  1204. <span class="post-option-title"><?php _e( 'Tags' ); ?></span> 
  1205. <span class="dashicons post-option-forward"></span> 
  1206. </button> 
  1207. </div> 
  1208.  
  1209. <?php if ( $supports_formats ) : ?> 
  1210. <div class="setting-modal is-off-screen is-hidden"> 
  1211. <button type="button" class="button-link modal-close"> 
  1212. <span class="dashicons post-option-back"></span> 
  1213. <span class="setting-title" aria-hidden="true"><?php _ex( 'Format', 'post format' ); ?></span> 
  1214. <span class="screen-reader-text"><?php _e( 'Back to post options' ) ?></span> 
  1215. </button> 
  1216. <?php $this->post_formats_html( $post ); ?> 
  1217. </div> 
  1218. <?php endif; ?> 
  1219.  
  1220. <div class="setting-modal is-off-screen is-hidden"> 
  1221. <button type="button" class="button-link modal-close"> 
  1222. <span class="dashicons post-option-back"></span> 
  1223. <span class="setting-title" aria-hidden="true"><?php _e( 'Categories' ); ?></span> 
  1224. <span class="screen-reader-text"><?php _e( 'Back to post options' ) ?></span> 
  1225. </button> 
  1226. <?php $this->categories_html( $post ); ?> 
  1227. </div> 
  1228.  
  1229. <div class="setting-modal tags is-off-screen is-hidden"> 
  1230. <button type="button" class="button-link modal-close"> 
  1231. <span class="dashicons post-option-back"></span> 
  1232. <span class="setting-title" aria-hidden="true"><?php _e( 'Tags' ); ?></span> 
  1233. <span class="screen-reader-text"><?php _e( 'Back to post options' ) ?></span> 
  1234. </button> 
  1235. <?php $this->tags_html( $post ); ?> 
  1236. </div> 
  1237. </div><!-- .options-panel --> 
  1238. </div><!-- .wrapper --> 
  1239.  
  1240. <div class="press-this-actions"> 
  1241. <div class="pressthis-media-buttons"> 
  1242. <button type="button" class="insert-media button-link" data-editor="pressthis"> 
  1243. <span class="dashicons dashicons-admin-media"></span> 
  1244. <span class="screen-reader-text"><?php _e( 'Add Media' ); ?></span> 
  1245. </button> 
  1246. </div> 
  1247. <div class="post-actions"> 
  1248. <span class="spinner"> </span> 
  1249. <div class="split-button"> 
  1250. <div class="split-button-head"> 
  1251. <button type="button" class="publish-button split-button-primary" aria-live="polite"> 
  1252. <span class="publish"><?php echo ( current_user_can( 'publish_posts' ) ) ? __( 'Publish' ) : __( 'Submit for Review' ); ?></span> 
  1253. <span class="saving-draft"><?php _e( 'Saving…' ); ?></span> 
  1254. </button><button type="button" class="split-button-toggle" aria-haspopup="true" aria-expanded="false"> 
  1255. <i class="dashicons dashicons-arrow-down-alt2"></i> 
  1256. <span class="screen-reader-text"><?php _e('More actions'); ?></span> 
  1257. </button> 
  1258. </div> 
  1259. <ul class="split-button-body"> 
  1260. <li><button type="button" class="button-link draft-button split-button-option"><?php _e( 'Save Draft' ); ?></button></li> 
  1261. <li><button type="button" class="button-link standard-editor-button split-button-option"><?php _e( 'Standard Editor' ); ?></button></li> 
  1262. <li><button type="button" class="button-link preview-button split-button-option"><?php _e( 'Preview' ); ?></button></li> 
  1263. </ul> 
  1264. </div> 
  1265. </div> 
  1266. </div> 
  1267. </form> 
  1268.  
  1269. <?php 
  1270. /** This action is documented in wp-admin/admin-footer.php */ 
  1271. do_action( 'admin_footer' ); 
  1272.  
  1273. /** This action is documented in wp-admin/admin-footer.php */ 
  1274. do_action( 'admin_print_footer_scripts-press-this.php' ); 
  1275.  
  1276. /** This action is documented in wp-admin/admin-footer.php */ 
  1277. do_action( 'admin_print_footer_scripts' ); 
  1278.  
  1279. /** This action is documented in wp-admin/admin-footer.php */ 
  1280. do_action( 'admin_footer-press-this.php' ); 
  1281. ?> 
  1282. </body> 
  1283. </html> 
  1284. <?php 
  1285. die();