PageRenderTime 63ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/df_home/static/test/portalbkd/wp-admin/includes/class-wp-press-this.php

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