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