streams/Code/Module/Wall_upload.php

63 lines
1.3 KiB
PHP
Raw Normal View History

2016-04-19 03:38:38 +00:00
<?php
2021-12-03 03:01:39 +00:00
2022-02-16 04:08:28 +00:00
namespace Code\Module;
2016-04-19 03:38:38 +00:00
2021-12-02 22:33:36 +00:00
use App;
2022-02-16 04:08:28 +00:00
use Code\Web\Controller;
use Code\Lib\Channel;
2021-12-02 22:33:36 +00:00
2019-04-16 06:43:06 +00:00
require_once('include/photo_factory.php');
2016-04-19 03:38:38 +00:00
require_once('include/photos.php');
2021-12-02 23:02:31 +00:00
class Wall_upload extends Controller
{
2016-04-19 03:38:38 +00:00
2021-12-02 23:02:31 +00:00
public function post()
{
$using_api = ((x($_FILES, 'media')) ? true : false);
if ($using_api) {
require_once('include/api.php');
2021-12-03 03:01:39 +00:00
if (api_user()) {
2022-01-25 01:26:12 +00:00
$channel = Channel::from_id(api_user());
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
} else {
2021-12-03 03:01:39 +00:00
if (argc() > 1) {
2022-01-25 01:26:12 +00:00
$channel = Channel::from_username(argv(1));
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
}
if (!$channel) {
2021-12-03 03:01:39 +00:00
if ($using_api) {
2021-12-02 23:02:31 +00:00
return;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
notice(t('Channel not found.') . EOL);
killme();
}
$observer = App::get_observer();
$args = array('source' => 'editor', 'visible' => 0, 'contact_allow' => array($channel['channel_hash']));
$ret = photo_upload($channel, $observer, $args);
if (!$ret['success']) {
2021-12-03 03:01:39 +00:00
if ($using_api) {
2021-12-02 23:02:31 +00:00
return;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
notice($ret['message']);
killme();
}
2021-12-03 03:01:39 +00:00
if ($using_api) {
2021-12-02 23:02:31 +00:00
return ("\n\n" . $ret['body'] . "\n\n");
2021-12-03 03:01:39 +00:00
} else {
2021-12-02 23:02:31 +00:00
echo "\n\n" . $ret['body'] . "\n\n";
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
killme();
}
2016-04-19 03:38:38 +00:00
}