aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2013-09-29 18:18:05 -0700
committerfriendica <info@friendica.com>2013-09-29 18:18:05 -0700
commita26e48b013f6674e0cb96c143739b0d5c3f71f63 (patch)
tree54a6ed491a5523b8d17bdeac386eb05c78d35257
parent046ddea9e80523f426f7875674a62ab5a494ad64 (diff)
downloadvolse-hubzilla-a26e48b013f6674e0cb96c143739b0d5c3f71f63.tar.gz
volse-hubzilla-a26e48b013f6674e0cb96c143739b0d5c3f71f63.tar.bz2
volse-hubzilla-a26e48b013f6674e0cb96c143739b0d5c3f71f63.zip
sources management page
-rw-r--r--include/features.php1
-rw-r--r--mod/sources.php140
-rw-r--r--view/js/mod_sources.js12
-rw-r--r--view/tpl/sources_edit.tpl22
-rw-r--r--view/tpl/sources_list.tpl15
-rw-r--r--view/tpl/sources_new.tpl15
6 files changed, 205 insertions, 0 deletions
diff --git a/include/features.php b/include/features.php
index 6272b33ea..9950039c0 100644
--- a/include/features.php
+++ b/include/features.php
@@ -35,6 +35,7 @@ function get_features() {
t('Post Composition Features'),
array('richtext', t('Richtext Editor'), t('Enable richtext editor')),
array('preview', t('Post Preview'), t('Allow previewing posts and comments before publishing them')),
+ array('channel_sources', t('Channel Sources'), t('Automatically import channel content from other channels or feeds')),
),
// Network Tools
diff --git a/mod/sources.php b/mod/sources.php
new file mode 100644
index 000000000..200a0cddf
--- /dev/null
+++ b/mod/sources.php
@@ -0,0 +1,140 @@
+<?php /** @file */
+
+function sources_post(&$a) {
+ if(! local_user())
+ return;
+
+ if(! feature_enabled(local_user(),'channel_sources'))
+ return '';
+
+ $source = intval($_REQUEST['source']);
+ $xchan = $_REQUEST['xchan'];
+ $words = $_REQUEST['words'];
+ $frequency = $_REQUEST['frequency'];
+
+ $channel = $a->get_channel();
+
+
+ if(! $source) {
+ $r = q("insert into source ( src_channel_id, src_channel_xchan, src_xchan, src_patt )
+ values ( %d, '%s', '%s', '%s' ) ",
+ intval(local_user()),
+ dbesc($channel['channel_hash']),
+ dbesc($xchan),
+ dbesc($words)
+ );
+ if($r) {
+ info( t('Source created.') . EOL);
+ }
+ goaway(z_root() . '/sources');
+ }
+ else {
+ $r = q("update source set src_xchan = '%s', src_patt = '%s' where src_channel_id = %d and src_id = %d limit 1",
+ dbesc($xchan),
+ dbesc($words),
+ intval(local_user()),
+ intval($source)
+ );
+ if($r) {
+ info( t('Source updated.') . EOL);
+ }
+
+ }
+}
+
+
+function sources_content(&$a) {
+ if(! local_user()) {
+ notice( t('Permission denied.') . EOL);
+ return '';
+ }
+
+ if(! feature_enabled(local_user(),'channel_sources')) {
+ return '';
+ }
+
+ // list sources
+ if(argc() == 1) {
+ $r = q("select source.*, xchan.* from source left join xchan on src_xchan = xchan_hash where src_channel_id = %d",
+ intval(local_user())
+ );
+ if($r) {
+ for($x = 0; $x < count($r); $x ++) {
+ $r[$x]['src_patt'] = htmlspecialchars($r[$x]['src_patt']);
+ }
+ }
+ $o = replace_macros(get_markup_template('sources_list.tpl'), array(
+ '$title' => t('Channel Sources'),
+ '$desc' => t('Manage remote sources of content for your channel.'),
+ '$new' => t('New Source'),
+ '$sources' => $r
+ ));
+ return $o;
+ }
+
+ if(argc() == 2 && argv(1) === 'new') {
+ // TODO add the words 'or RSS feed' and corresponding code to manage feeds and frequency
+
+ $o = replace_macros(get_markup_template('sources_new.tpl'), array(
+ '$title' => t('New Source'),
+ '$desc' => t('Import all or selected content from the following channel into this channel and distribute it according to your channel settings.'),
+ '$words' => array( 'words', t('Only import content with these words (one per line)'),'',t('Leave blank to import all public content')),
+ '$name' => array( 'name', t('Channel Name'), '', ''),
+ '$submit' => t('Submit')
+ ));
+ return $o;
+
+ }
+
+ if(argc() == 2 && intval(argv(1))) {
+ // edit source
+ $r = q("select source.*, xchan.* from source left join xchan on src_xchan = xchan_hash where src_id = %d and src_channel_id = %d limit 1",
+ intval(argv(1)),
+ intval(local_user())
+ );
+ if(! $r) {
+ notice( t('Source not found.') . EOL);
+ return '';
+ }
+
+ $r[0]['src_patt'] = htmlspecialchars($r[0]['src_patt']);
+
+ $o = replace_macros(get_markup_template('sources_edit.tpl'), array(
+ '$title' => t('Edit Source'),
+ '$drop' => t('Delete Source'),
+ '$id' => $r[0]['src_id'],
+ '$desc' => t('Import all or selected content from the following channel into this channel and distribute it according to your channel settings.'),
+ '$words' => array( 'words', t('Only import content with these words (one per line)'),$r[0]['src_patt'],t('Leave blank to import all public content')),
+ '$xchan' => $r[0]['src_xchan'],
+ '$name' => array( 'name', t('Channel Name'), $r[0]['xchan_name'], ''),
+ '$submit' => t('Submit')
+ ));
+ return $o;
+
+ }
+
+ if(argc() == 3 && intval(argv(1)) && argv(2) === 'drop') {
+ $r = q("select * from source where src_id = %d and src_channel_id = %d limit 1",
+ intval(argv(1)),
+ intval(local_user())
+ );
+ if(! $r) {
+ notice( t('Source not found.') . EOL);
+ return '';
+ }
+ $r = q("delete from source where src_id = %d and src_channel_id = %d limit 1",
+ intval(argv(1)),
+ intval(local_user())
+ );
+ if($r)
+ info( t('Source removed') . EOL);
+ else
+ notice( t('Unable to remove source.') . EOL);
+
+ goaway(z_root() . '/sources');
+
+ }
+
+ // shouldn't get here.
+
+} \ No newline at end of file
diff --git a/view/js/mod_sources.js b/view/js/mod_sources.js
new file mode 100644
index 000000000..140f13843
--- /dev/null
+++ b/view/js/mod_sources.js
@@ -0,0 +1,12 @@
+$(document).ready(function() {
+ var a;
+ a = $("#id_name").autocomplete({
+ serviceUrl: baseurl + '/acl',
+ minChars: 2,
+ width: 350,
+ onSelect: function(value,data) {
+ $("#id_xchan").val(data);
+ }
+ });
+
+});
diff --git a/view/tpl/sources_edit.tpl b/view/tpl/sources_edit.tpl
new file mode 100644
index 000000000..6e9cee32b
--- /dev/null
+++ b/view/tpl/sources_edit.tpl
@@ -0,0 +1,22 @@
+<h1>{{$title}}</h1>
+
+<div class="descriptive-text">{{$desc}}</div>
+
+<form action="sources" method="post">
+<input type="hidden" name="source" value="{{$id}}" />
+<input type="hidden" id="id_xchan" name="xchan" value="{{$xchan}}" />
+{{include file="field_input.tpl" field=$name}}
+{{include file="field_textarea.tpl" field=$words}}
+
+<div class="sources-submit-wrapper" >
+<input type="submit" name="submit" class="sources-submit" value="{{$submit}}" />
+</div>
+</form>
+<br />
+<br />
+<a href="sources/{{$id}}/drop">{{$drop}}</a>
+
+
+
+
+
diff --git a/view/tpl/sources_list.tpl b/view/tpl/sources_list.tpl
new file mode 100644
index 000000000..5fe50ba98
--- /dev/null
+++ b/view/tpl/sources_list.tpl
@@ -0,0 +1,15 @@
+<h1>{{$title}}</h1>
+
+<div class="descriptive-text">{{$desc}}</div>
+
+<div class="sources-links">
+<a href="sources/new">{{$new}}</a>
+</div>
+
+{{if $sources}}
+<ul class="sources-list">
+{{foreach $sources as $source}}
+<li><a href="sources/{{$source.src_id}}">{{$source.xchan_name}}</a></li>
+{{/foreach}}
+</ul>
+{{/if}} \ No newline at end of file
diff --git a/view/tpl/sources_new.tpl b/view/tpl/sources_new.tpl
new file mode 100644
index 000000000..267245ae4
--- /dev/null
+++ b/view/tpl/sources_new.tpl
@@ -0,0 +1,15 @@
+<h1>{{$title}}</h1>
+
+<div class="descriptive-text">{{$desc}}</div>
+
+<form action="sources" method="post">
+<input type="hidden" id="id_xchan" name="xchan" value="{{$xchan}}" />
+{{include file="field_input.tpl" field=$name}}
+{{include file="field_textarea.tpl" field=$words}}
+
+<div class="sources-submit-wrapper" >
+<input type="submit" name="submit" class="sources-submit" value="{{$submit}}" />
+</div>
+</form>
+
+