Hubzilla core code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

236 lines
6.6 KiB

  1. <?php
  2. namespace Zotlabs\Module;
  3. use App;
  4. use Zotlabs\Lib\Apps;
  5. use Zotlabs\Web\Controller;
  6. use Zotlabs\Lib\PermissionDescription;
  7. require_once('include/channel.php');
  8. require_once('include/conversation.php');
  9. require_once('include/acl_selectors.php');
  10. require_once('include/opengraph.php');
  11. class Articles extends Controller {
  12. function init() {
  13. if(argc() > 1)
  14. $which = argv(1);
  15. if(! $which) {
  16. if(local_channel()) {
  17. $channel = App::get_channel();
  18. if($channel && $channel['channel_address'])
  19. $which = $channel['channel_address'];
  20. } else {
  21. return;
  22. }
  23. }
  24. profile_load($which);
  25. }
  26. function get($update = 0, $load = false) {
  27. if(observer_prohibited(true)) {
  28. return login();
  29. }
  30. if(! App::$profile) {
  31. notice( t('Requested profile is not available.') . EOL );
  32. App::$error = 404;
  33. return;
  34. }
  35. if(! Apps::system_app_installed(App::$profile_uid, 'Articles')) {
  36. //Do not display any associated widgets at this point
  37. App::$pdl = '';
  38. $o = '<b>' . t('Articles App') . ' (' . t('Not Installed') . '):</b><br>';
  39. $o .= t('Create interactive articles');
  40. return $o;
  41. }
  42. nav_set_selected('Articles');
  43. head_add_link([
  44. 'rel' => 'alternate',
  45. 'type' => 'application/json+oembed',
  46. 'href' => z_root() . '/oep?f=&url=' . urlencode(z_root() . '/' . App::$query_string),
  47. 'title' => 'oembed'
  48. ]);
  49. $category = (($_REQUEST['cat']) ? escape_tags(trim($_REQUEST['cat'])) : '');
  50. if($category) {
  51. $sql_extra2 .= protect_sprintf(term_item_parent_query(App::$profile['profile_uid'],'item', $category, TERM_CATEGORY));
  52. }
  53. $datequery = ((x($_GET,'dend') && is_a_date_arg($_GET['dend'])) ? notags($_GET['dend']) : '');
  54. $datequery2 = ((x($_GET,'dbegin') && is_a_date_arg($_GET['dbegin'])) ? notags($_GET['dbegin']) : '');
  55. $which = argv(1);
  56. $selected_card = ((argc() > 2) ? argv(2) : '');
  57. $_SESSION['return_url'] = App::$query_string;
  58. $uid = local_channel();
  59. $owner = App::$profile_uid;
  60. $observer = App::get_observer();
  61. $ob_hash = (($observer) ? $observer['xchan_hash'] : '');
  62. if(! perm_is_allowed($owner,$ob_hash,'view_pages')) {
  63. notice( t('Permission denied.') . EOL);
  64. return;
  65. }
  66. $is_owner = ($uid && $uid == $owner);
  67. $channel = channelx_by_n($owner);
  68. if($channel) {
  69. $channel_acl = array(
  70. 'allow_cid' => $channel['channel_allow_cid'],
  71. 'allow_gid' => $channel['channel_allow_gid'],
  72. 'deny_cid' => $channel['channel_deny_cid'],
  73. 'deny_gid' => $channel['channel_deny_gid']
  74. );
  75. }
  76. else {
  77. $channel_acl = [ 'allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '' ];
  78. }
  79. if(perm_is_allowed($owner,$ob_hash,'write_pages')) {
  80. $x = [
  81. 'webpage' => ITEM_TYPE_ARTICLE,
  82. 'is_owner' => true,
  83. 'content_label' => t('Add Article'),
  84. 'button' => t('Create'),
  85. 'nickname' => $channel['channel_address'],
  86. 'lockstate' => (($channel['channel_allow_cid'] || $channel['channel_allow_gid']
  87. || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'),
  88. 'acl' => (($is_owner) ? populate_acl($channel_acl, false,
  89. PermissionDescription::fromGlobalPermission('view_pages')) : ''),
  90. 'permissions' => $channel_acl,
  91. 'showacl' => (($is_owner) ? true : false),
  92. 'visitor' => true,
  93. 'body' => '[summary][/summary]',
  94. 'hide_location' => false,
  95. 'hide_voting' => false,
  96. 'profile_uid' => intval($owner),
  97. 'mimetype' => 'text/bbcode',
  98. 'mimeselect' => false,
  99. 'layoutselect' => false,
  100. 'expanded' => false,
  101. 'novoting' => false,
  102. 'catsenabled' => feature_enabled($owner,'categories'),
  103. 'bbco_autocomplete' => 'bbcode',
  104. 'bbcode' => true
  105. ];
  106. if($_REQUEST['title'])
  107. $x['title'] = $_REQUEST['title'];
  108. if($_REQUEST['body'])
  109. $x['body'] = $_REQUEST['body'];
  110. $editor = status_editor($a,$x,false,'Articles');
  111. }
  112. else {
  113. $editor = '';
  114. }
  115. $itemspage = get_pconfig(local_channel(),'system','itemspage');
  116. App::set_pager_itemspage(((intval($itemspage)) ? $itemspage : 20));
  117. $pager_sql = sprintf(" LIMIT %d OFFSET %d ", intval(App::$pager['itemspage']), intval(App::$pager['start']));
  118. $sql_extra = item_permissions_sql($owner);
  119. $sql_item = '';
  120. if($selected_card) {
  121. $r = q("select * from iconfig where iconfig.cat = 'system' and iconfig.k = 'ARTICLE' and iconfig.v = '%s' limit 1",
  122. dbesc($selected_card)
  123. );
  124. if($r) {
  125. $sql_item = "and item.id = " . intval($r[0]['iid']) . " ";
  126. }
  127. }
  128. if($datequery) {
  129. $sql_extra2 .= protect_sprintf(sprintf(" AND item.created <= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery))));
  130. $order = 'post';
  131. }
  132. if($datequery2) {
  133. $sql_extra2 .= protect_sprintf(sprintf(" AND item.created >= '%s' ", dbesc(datetime_convert(date_default_timezone_get(),'',$datequery2))));
  134. }
  135. if($datequery || $datequery2) {
  136. $sql_extra2 .= " and item.item_thread_top != 0 ";
  137. }
  138. $r = q("select * from item
  139. where item.uid = %d and item_type = %d
  140. $sql_extra $sql_extra2 $sql_item order by item.created desc $pager_sql",
  141. intval($owner),
  142. intval(ITEM_TYPE_ARTICLE)
  143. );
  144. $item_normal = " and item.item_hidden = 0 and item.item_type in (0,7) and item.item_deleted = 0
  145. and item.item_unpublished = 0 and item.item_delayed = 0 and item.item_pending_remove = 0
  146. and item.item_blocked = 0 ";
  147. if($r) {
  148. $pager_total = count($r);
  149. $parents_str = ids_to_querystr($r,'id');
  150. $r = q("SELECT item.*, item.id AS item_id
  151. FROM item
  152. WHERE item.uid = %d $item_normal
  153. AND item.parent IN ( %s )
  154. $sql_extra $sql_extra2 ",
  155. intval(App::$profile['profile_uid']),
  156. dbesc($parents_str)
  157. );
  158. if($r) {
  159. xchan_query($r);
  160. $items = fetch_post_tags($r, true);
  161. $items = conv_sort($items,'updated');
  162. }
  163. else
  164. $items = [];
  165. }
  166. // Add Opengraph markup
  167. opengraph_add_meta((! empty($items) ? $r[0] : []), $channel);
  168. $mode = 'articles';
  169. if(get_pconfig(local_channel(),'system','articles_list_mode') && (! $selected_card))
  170. $page_mode = 'pager_list';
  171. else
  172. $page_mode = 'traditional';
  173. $content = conversation($items,$mode,false,$page_mode);
  174. $o = replace_macros(get_markup_template('cards.tpl'), [
  175. '$title' => t('Articles'),
  176. '$editor' => $editor,
  177. '$content' => $content,
  178. '$pager' => alt_pager($pager_total)
  179. ]);
  180. return $o;
  181. }
  182. }