editpost.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php /** @file */
  2. require_once('include/acl_selectors.php');
  3. require_once('include/crypto.php');
  4. require_once('include/items.php');
  5. require_once('include/taxonomy.php');
  6. function editpost_content(&$a) {
  7. $o = '';
  8. if(! local_channel()) {
  9. notice( t('Permission denied.') . EOL);
  10. return;
  11. }
  12. $post_id = ((argc() > 1) ? intval(argv(1)) : 0);
  13. if(! $post_id) {
  14. notice( t('Item not found') . EOL);
  15. return;
  16. }
  17. $itm = q("SELECT * FROM `item` WHERE `id` = %d AND ( owner_xchan = '%s' OR author_xchan = '%s' ) LIMIT 1",
  18. intval($post_id),
  19. dbesc(get_observer_hash()),
  20. dbesc(get_observer_hash())
  21. );
  22. if(! count($itm)) {
  23. notice( t('Item is not editable') . EOL);
  24. return;
  25. }
  26. if($itm[0]['resource_type'] === 'event' && $itm[0]['resource_id']) {
  27. goaway(z_root() . '/events/' . $itm[0]['resource_id'] . '?expandform=1');
  28. }
  29. $owner_uid = $itm[0]['uid'];
  30. $plaintext = true;
  31. // if(feature_enabled(local_channel(),'richtext'))
  32. // $plaintext = false;
  33. $channel = App::get_channel();
  34. App::$page['htmlhead'] .= replace_macros(get_markup_template('jot-header.tpl'), array(
  35. '$baseurl' => z_root(),
  36. '$editselect' => (($plaintext) ? 'none' : '/(profile-jot-text|prvmail-text)/'),
  37. '$pretext' => '',
  38. '$ispublic' => '&nbsp;', // t('Visible to <strong>everybody</strong>'),
  39. '$geotag' => $geotag,
  40. '$nickname' => $channel['channel_address'],
  41. '$expireswhen' => t('Expires YYYY-MM-DD HH:MM'),
  42. '$confirmdelete' => t('Delete item?'),
  43. '$editor_autocomplete'=> true,
  44. '$bbco_autocomplete'=> 'bbcode'
  45. ));
  46. if(intval($itm[0]['item_obscured'])) {
  47. $key = get_config('system','prvkey');
  48. if($itm[0]['title'])
  49. $itm[0]['title'] = crypto_unencapsulate(json_decode_plus($itm[0]['title']),$key);
  50. if($itm[0]['body'])
  51. $itm[0]['body'] = crypto_unencapsulate(json_decode_plus($itm[0]['body']),$key);
  52. }
  53. $tpl = get_markup_template("jot.tpl");
  54. $jotplugins = '';
  55. $jotnets = '';
  56. call_hooks('jot_tool', $jotplugins);
  57. call_hooks('jot_networks', $jotnets);
  58. //$tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
  59. $voting = feature_enabled($owner_uid,'consensus_tools');
  60. $category = '';
  61. $catsenabled = ((feature_enabled($owner_uid,'categories')) ? 'categories' : '');
  62. if ($catsenabled){
  63. $itm = fetch_post_tags($itm);
  64. $cats = get_terms_oftype($itm[0]['term'], TERM_CATEGORY);
  65. foreach ($cats as $cat) {
  66. if (strlen($category))
  67. $category .= ', ';
  68. $category .= $cat['term'];
  69. }
  70. }
  71. if($itm[0]['attach']) {
  72. $j = json_decode($itm[0]['attach'],true);
  73. if($j) {
  74. foreach($j as $jj) {
  75. $itm[0]['body'] .= "\n" . '[attachment]' . basename($jj['href']) . ',' . $jj['revision'] . '[/attachment]' . "\n";
  76. }
  77. }
  78. }
  79. $cipher = get_pconfig(App::$profile['profile_uid'],'system','default_cipher');
  80. if(! $cipher)
  81. $cipher = 'aes256';
  82. $editor = replace_macros($tpl,array(
  83. '$return_path' => $_SESSION['return_url'],
  84. '$action' => 'item',
  85. '$share' => t('Edit'),
  86. '$bold' => t('Bold'),
  87. '$italic' => t('Italic'),
  88. '$underline' => t('Underline'),
  89. '$quote' => t('Quote'),
  90. '$code' => t('Code'),
  91. '$upload' => t('Upload photo'),
  92. '$attach' => t('Attach file'),
  93. '$weblink' => t('Insert web link'),
  94. '$youtube' => t('Insert YouTube video'),
  95. '$video' => t('Insert Vorbis [.ogg] video'),
  96. '$audio' => t('Insert Vorbis [.ogg] audio'),
  97. '$setloc' => t('Set your location'),
  98. '$noloc' => t('Clear browser location'),
  99. '$voting' => t('Toggle voting'),
  100. '$feature_voting' => $voting,
  101. '$consensus' => intval($itm[0]['item_consensus']),
  102. '$wait' => t('Please wait'),
  103. '$permset' => t('Permission settings'),
  104. '$ptyp' => $itm[0]['obj_type'],
  105. '$content' => undo_post_tagging($itm[0]['body']),
  106. '$post_id' => $post_id,
  107. '$parent' => (($itm[0]['parent'] != $itm[0]['id']) ? $itm[0]['parent'] : ''),
  108. '$baseurl' => z_root(),
  109. '$defloc' => $channel['channel_location'],
  110. '$visitor' => false,
  111. '$public' => t('Public post'),
  112. '$jotnets' => $jotnets,
  113. '$title' => htmlspecialchars($itm[0]['title'],ENT_COMPAT,'UTF-8'),
  114. '$placeholdertitle' => t('Title (optional)'),
  115. '$category' => $category,
  116. '$placeholdercategory' => t('Categories (optional, comma-separated list)'),
  117. '$emtitle' => t('Example: bob@example.com, mary@example.com'),
  118. '$lockstate' => $lockstate,
  119. '$acl' => '',
  120. '$bang' => '',
  121. '$profile_uid' => $owner_uid,
  122. '$preview' => t('Preview'),
  123. '$jotplugins' => $jotplugins,
  124. '$sourceapp' => t(App::$sourcename),
  125. '$catsenabled' => $catsenabled,
  126. '$defexpire' => datetime_convert('UTC', date_default_timezone_get(),$itm[0]['expires']),
  127. '$feature_expire' => ((feature_enabled(App::$profile['profile_uid'],'content_expire') && (! $webpage)) ? true : false),
  128. '$expires' => t('Set expiration date'),
  129. '$feature_encrypt' => ((feature_enabled(App::$profile['profile_uid'],'content_encrypt') && (! $webpage)) ? true : false),
  130. '$encrypt' => t('Encrypt text'),
  131. '$cipher' => $cipher,
  132. '$expiryModalOK' => t('OK'),
  133. '$expiryModalCANCEL' => t('Cancel'),
  134. '$bbcode' => true
  135. ));
  136. $o .= replace_macros(get_markup_template('edpost_head.tpl'), array(
  137. '$title' => t('Edit post'),
  138. '$editor' => $editor
  139. ));
  140. return $o;
  141. }