/** * Send a multipart/alternative message with Text and HTML versions * * @param fromName name of the sender * @param fromEmail email fo the sender * @param replyTo replyTo address to direct responses * @param toEmail destination email address * @param messageSubject subject of the message * @param htmlVersion html version of the message * @param textVersion text only version of the message * @param additionalMailHeader additions to the smtp mail header * @param optional uid user id of the destination user */ public static function send($params) { call_hooks('emailer_send_prepare', $params); $email_textonly = False; if (x($params, "uid")) { $email_textonly = get_pconfig($params['uid'], "system", "email_textonly"); } $fromName = email_header_encode(html_entity_decode($params['fromName'], ENT_QUOTES, 'UTF-8'), 'UTF-8'); $messageSubject = email_header_encode(html_entity_decode($params['messageSubject'], ENT_QUOTES, 'UTF-8'), 'UTF-8'); // generate a mime boundary $mimeBoundary = rand(0, 9) . "-" . rand(10000000000, 99999999999) . "-" . rand(10000000000, 99999999999) . "=:" . rand(10000, 99999); // generate a multipart/alternative message header $messageHeader = $params['additionalMailHeader'] . "From: {$fromName} <{$params['fromEmail']}>\n" . "Reply-To: {$fromName} <{$params['replyTo']}>\n" . "MIME-Version: 1.0\n" . "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\""; // assemble the final multipart message body with the text and html types included $textBody = chunk_split(base64_encode($params['textVersion'])); $htmlBody = chunk_split(base64_encode($params['htmlVersion'])); $multipartMessageBody = "--" . $mimeBoundary . "\n" . "Content-Type: text/plain; charset=UTF-8\n" . "Content-Transfer-Encoding: base64\n\n" . $textBody . "\n"; if (!$email_textonly && !is_null($params['htmlVersion'])) { $multipartMessageBody .= "--" . $mimeBoundary . "\n" . "Content-Type: text/html; charset=UTF-8\n" . "Content-Transfer-Encoding: base64\n\n" . $htmlBody . "\n"; } $multipartMessageBody .= "--" . $mimeBoundary . "--\n"; // message ending // send the message $hookdata = array('to' => $params['toEmail'], 'subject' => $messageSubject, 'body' => $multipartMessageBody, 'headers' => $messageHeader); //echo "<pre>"; var_dump($hookdata); killme(); call_hooks("emailer_send", $hookdata); $res = mail($hookdata['to'], $hookdata['subject'], $hookdata['body'], $hookdata['headers']); logger("header " . 'To: ' . $params['toEmail'] . "\n" . $messageHeader, LOGGER_DEBUG); logger("return value " . ($res ? "true" : "false"), LOGGER_DEBUG); return $res; }
function search_ac_init(&$a) { if (!local_channel()) { killme(); } $start = x($_REQUEST, 'start') ? $_REQUEST['start'] : 0; $count = x($_REQUEST, 'count') ? $_REQUEST['count'] : 100; $search = x($_REQUEST, 'search') ? $_REQUEST['search'] : ""; if (x($_REQUEST, 'query') && strlen($_REQUEST['query'])) { $search = $_REQUEST['query']; } // Priority to people searches if ($search) { $people_sql_extra = protect_sprintf(" AND `xchan_name` LIKE '%" . dbesc($search) . "%' "); $tag_sql_extra = protect_sprintf(" AND term LIKE '%" . dbesc($search) . "%' "); } $r = q("SELECT `abook_id`, `xchan_name`, `xchan_photo_s`, `xchan_url`, `xchan_addr` FROM `abook` left join xchan on abook_xchan = xchan_hash WHERE abook_channel = %d \n\t\t{$people_sql_extra}\n\t\tORDER BY `xchan_name` ASC ", intval(local_channel())); $results = array(); if ($r) { foreach ($r as $g) { $results[] = array("photo" => $g['xchan_photo_s'], "name" => '@' . $g['xchan_name'], "id" => $g['abook_id'], "link" => $g['xchan_url'], "label" => '', "nick" => ''); } } $r = q("select distinct term, tid, url from term where type in ( %d, %d ) {$tag_sql_extra} group by term order by term asc", intval(TERM_HASHTAG), intval(TERM_COMMUNITYTAG)); if (count($r)) { foreach ($r as $g) { $results[] = array("photo" => $a->get_baseurl() . '/images/hashtag.png', "name" => '#' . $g['term'], "id" => $g['tid'], "link" => $g['url'], "label" => '', "nick" => ''); } } header("content-type: application/json"); $o = array('start' => $start, 'count' => $count, 'items' => $results); echo json_encode($o); logger('search_ac: ' . print_r($x, true)); killme(); }
public function read_json($data) { if (!is_array($data)) { logger(' source data is not a array.'); return; } foreach ($data as $value) { if ($value['audio']) { $audio = $value['audio']; if ($audio['title_photo']) { $this->picArray[] = $audio['title_photo']; } if ($audio['content_photo']) { $this->picArray[] = $audio['content_photo']; } if ($audio['wetsound_path']) { $this->mp3Array[] = $audio['wetsound_path']; } if (isset($audio['addPicList'])) { $addPicList = $audio['addPicList']; if (!is_array($addPicList)) { return; } foreach ($addPicList as $value) { $this->picArray[] = $value['content_pic']; } } } } }
public function __construct($dsn, $user, $password) { parent::__construct($dsn, $user, $password); $this->query("SET NAMES ´utf8´"); $this->query("SET CHARACTER SET utf8"); logger("INFO", "Database Class Initialized"); }
public static function getFromRouter(Router $router) { $mode = $router->getMode(); $parameters = []; $path = preg_replace_callback('/\\/\\${.*}/U', function ($matches) use(&$parameters) { $parameters[] = preg_replace('/\\/|\\$|\\{|\\}/', '', $matches[0]); return ''; }, $router->getPath()); $patharr = array_merge(explode('/', $router->getBase()), explode('/', $path)); $path = array_filter(array_map(function ($p) { return \camelCase($p, true, '-'); }, $patharr)); if ($mode === Router::MOD_RESTFUL) { $request = $router->getRequest(); $method = strtoupper($_POST['_method'] ?? $request->getMethod()); $action = $router->getActionOfRestful($method); if ($action === null) { throw new \Leno\Http\Exception(501); } } else { $action = preg_replace_callback('/^[A-Z]/', function ($matches) { if (isset($matches[0])) { return strtolower($matches[0]); } }, preg_replace('/\\..*$/', '', array_pop($path))); } try { return (new self(implode('\\', $path) . 'Controller'))->setMethod($action)->setParameters($parameters); } catch (\Exception $ex) { logger()->err((string) $ex); throw new \Leno\Http\Exception(404); } }
function bookmarks_init(&$a) { if (!local_user()) { return; } $item_id = intval($_REQUEST['item']); if (!$item_id) { return; } $u = $a->get_channel(); $i = q("select * from item where id = %d and uid = %d limit 1", intval($item_id), intval(local_user())); if (!$i) { return; } $i = fetch_post_tags($i); $item = $i[0]; $terms = get_terms_oftype($item['term'], TERM_BOOKMARK); if ($terms && !$item['item_restrict']) { require_once 'include/bookmarks.php'; $s = q("select * from xchan where xchan_hash = '%s' limit 1", dbesc($item['author_xchan'])); if (!$s) { logger('mod_bookmarks: author lookup failed.'); killme(); } foreach ($terms as $t) { bookmark_add($u, $s[0], $t, $item['item_private']); info(t('Bookmark added') . EOL); } } killme(); }
function servePostRequest($params) { //logger("POST Params : ".print_r($params, true) ); switch ($params['task']) { case 'UPDATE_MODULE': $ret = updateLineItem($params); break; // Handles the case when a module/project/item has to be marked complete. Identifiers in $params['identifier'] // Handles the case when a module/project/item has to be marked complete. Identifiers in $params['identifier'] case 'MARK_COMPLETE': $tmp = $params['identifier']['project_name']; $tmp_proj = new ProjectController(); $tmp_proj->markAsComplete($params); logger("{$tmp} is COMPLETE"); break; // Handles the case when a module/project/item is to be marked invalid. Identifiers in $params['identifier'] // Handles the case when a module/project/item is to be marked invalid. Identifiers in $params['identifier'] case 'MARK_DISABLED': $tmp = $params['identifier']['project_name']; $tmp_proj = new ProjectController(); $tmp_proj->markAsInactive($params); logger("{$tmp} is INVALID"); break; case 'NEW_PROJECT': $ret = addNewProject($params); //$ret = "New project initiated"; break; default: # code... break; } return $ret; }
function init() { $result = array('success' => false); $mindate = $_REQUEST['mindate'] ? datetime_convert('UTC', 'UTC', $_REQUEST['mindate']) : ''; if (!$mindate) { $mindate = datetime_convert('UTC', 'UTC', 'now - 14 days'); } if (observer_prohibited()) { $result['message'] = 'Public access denied'; json_return_and_die($result); } $observer = \App::get_observer(); $channel_address = argc() > 1 ? argv(1) : ''; if ($channel_address) { $r = q("select channel_id, channel_name from channel where channel_address = '%s' and channel_removed = 0 limit 1", dbesc(argv(1))); } else { $x = get_sys_channel(); if ($x) { $r = array($x); } $mindate = datetime_convert('UTC', 'UTC', 'now - 14 days'); } if (!$r) { $result['message'] = 'Channel not found.'; json_return_and_die($result); } logger('zotfeed request: ' . $r[0]['channel_name'], LOGGER_DEBUG); $result['messages'] = zot_feed($r[0]['channel_id'], $observer['xchan_hash'], array('mindate' => $mindate)); $result['success'] = true; json_return_and_die($result); }
public function testHelpersFacade() { $this->assertInstanceOf(\Clarity\Support\Auth\Auth::class, auth()); $this->assertInstanceOf(\Phalcon\Config::class, config()); $this->assertInstanceOf(\Phalcon\Mvc\Dispatcher::class, dispatcher()); $this->assertInstanceOf(\Phalcon\Filter::class, filter()); $this->assertInstanceOf(\Phalcon\Flash\Direct::class, flash()->direct()); $this->assertInstanceOf(\Phalcon\Flash\Session::class, flash()->session()); $this->assertInstanceOf(\League\Flysystem\Filesystem::class, flysystem()); $this->assertInstanceOf(\League\Flysystem\MountManager::class, flysystem_manager()); $this->assertInstanceOf(\Clarity\Support\Redirect\Redirect::class, redirect()); $this->assertInstanceOf(\Clarity\Support\Phalcon\Http\Request::class, request()); $this->assertInstanceOf(\Phalcon\Http\Response::class, response()); $this->assertInstanceOf(\Phalcon\Mvc\Router::class, route()); $this->assertInstanceOf(\Phalcon\Security::class, security()); $this->assertInstanceOf(\Phalcon\Tag::class, tag()); $this->assertInstanceOf(\Phalcon\Mvc\Url::class, url()); $this->assertInstanceOf(\Phalcon\Mvc\View::class, view()); # getting an error, will check later on $this->assertInstanceOf(\Monolog\Logger::class, logger()); # adapter base functions // $this->assertInstanceOf(, cache()); // $this->assertInstanceOf(, db()); // $this->assertInstanceOf(, queue()); // $this->assertInstanceOf(, session()); $this->assertContains(url()->getBaseUri() . 'auth/login', route('showLoginForm')); $this->assertInstanceOf(\Phalcon\Mvc\View::class, view('welcome')); }
/** @file */ function notes_init(&$a) { if (!local_channel()) { return; } $ret = array('success' => true); if (array_key_exists('note_text', $_REQUEST)) { $body = escape_tags($_REQUEST['note_text']); // I've had my notes vanish into thin air twice in four years. // Provide a backup copy if there were contents previously // and there are none being saved now. if (!$body) { $old_text = get_pconfig(local_channel(), 'notes', 'text'); if ($old_text) { set_pconfig(local_channel(), 'notes', 'text.bak', $old_text); } } set_pconfig(local_channel(), 'notes', 'text', $body); } // push updates to channel clones if (argc() > 1 && argv(1) === 'sync') { require_once 'include/zot.php'; build_sync_packet(); } logger('notes saved.', LOGGER_DEBUG); json_return_and_die($ret); }
function pubsub_post(&$a) { $xml = file_get_contents('php://input'); logger('pubsub: feed arrived from ' . $_SERVER['REMOTE_ADDR'] . ' for ' . $a->cmd); logger('pubsub: user-agent: ' . $_SERVER['HTTP_USER_AGENT']); logger('pubsub: data: ' . $xml, LOGGER_DATA); // if(! stristr($xml,'<?xml')) { // logger('pubsub_post: bad xml'); // hub_post_return(); // } $nick = $a->argc > 1 ? notags(trim($a->argv[1])) : ''; $contact_id = $a->argc > 2 ? intval($a->argv[2]) : 0; $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1", dbesc($nick)); if (!count($r)) { hub_post_return(); } $importer = $r[0]; $r = q("SELECT * FROM `contact` WHERE `subhub` = 1 AND `id` = %d AND `uid` = %d \n\t\tAND ( `rel` = %d OR `rel` = %d OR network = '%s' ) AND `blocked` = 0 AND `readonly` = 0 LIMIT 1", intval($contact_id), intval($importer['uid']), intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND), dbesc(NETWORK_FEED)); if (!count($r)) { logger('pubsub: no contact record for "' . $nick . ' (' . $contact_id . ')" - ignored. ' . $xml); hub_post_return(); } $contact = $r[0]; // we have no way to match Diaspora guid's with atom post id's and could get duplicates. // we'll assume that direct delivery is robust (and this is a bad assumption, but the duplicates are messy). if ($r[0]['network'] === NETWORK_DIASPORA) { hub_post_return(); } $feedhub = ''; require_once 'include/items.php'; consume_feed($xml, $importer, $contact, $feedhub, 1, 1); // do it a second time so that any children find their parents. consume_feed($xml, $importer, $contact, $feedhub, 1, 2); hub_post_return(); }
function query($query) { if ($this->debug) { logger("DB:" . $this->name, "Query: " . substr($query, 0, $this->traceLength)); } return parent::query($query); }
private function generateForm() { $fieldTemplate = $this->getTemplate($this->templatePath . 'form_field.blade'); $fields = []; logger($this->fillableColumns); foreach ($this->fillableColumns as $column) { switch ($column['type']) { case 'integer': $inputType = 'number'; break; case 'text': $inputType = 'textarea'; break; case 'date': $inputType = $column['type']; break; case 'boolean': $inputType = 'checkbox'; break; default: $inputType = 'text'; break; } $fields[] = $this->compile($fieldTemplate, ['FIELD_NAME' => $column['field'], 'LABEL' => title_case(str_replace('_', ' ', $column['field'])), 'INPUT_TYPE' => $inputType]); } $templateData = $this->templateData; $templateData['FIELDS'] = implode("\n\n", $fields); $filename = 'form.blade.php'; $this->generateFile($filename, $templateData, $this->templatePath . 'form.blade'); }
public static function run($argc, $argv) { /** * Cron Weekly * * Actions in the following block are executed once per day only on Sunday (once per week). * */ call_hooks('cron_weekly', datetime_convert()); z_check_cert(); require_once 'include/hubloc.php'; prune_hub_reinstalls(); mark_orphan_hubsxchans(); // get rid of really old poco records q("delete from xlink where xlink_updated < %s - INTERVAL %s and xlink_static = 0 ", db_utcnow(), db_quoteinterval('14 DAY')); $dirmode = intval(get_config('system', 'directory_mode')); if ($dirmode === DIRECTORY_MODE_SECONDARY || $dirmode === DIRECTORY_MODE_PRIMARY) { logger('regdir: ' . print_r(z_fetch_url(get_directory_primary() . '/regdir?f=&url=' . urlencode(z_root()) . '&realm=' . urlencode(get_directory_realm())), true)); } // Check for dead sites Master::Summon(array('Checksites')); // update searchable doc indexes Master::Summon(array('Importdoc')); /** * End Cron Weekly */ }
function fromapp_uninstall() { unregister_hook('post_local', 'addon/fromapp/fromapp.php', 'fromapp_post_hook'); unregister_hook('plugin_settings', 'addon/fromapp/fromapp.php', 'fromapp_settings'); unregister_hook('plugin_settings_post', 'addon/fromapp/fromapp.php', 'fromapp_settings_post'); logger("removed fromapp"); }
/** * Update the business service types. * * @param Business $business * @param Request $request * * @return Response */ public function update(Business $business, Request $request) { logger()->info(__METHOD__); logger()->info(sprintf('businessId:%s', $business->id)); $this->authorize('manageServices', $business); // BEGIN $servicetypeSheet = $request->input('servicetypes'); $regex = '/(?P<name>[a-zA-Z\\d\\-\\ ]+)\\:(?P<description>[a-zA-Z\\d\\ ]+)/im'; preg_match_all($regex, $servicetypeSheet, $matches, PREG_SET_ORDER); $publishing = collect($matches)->map(function ($item) { $data = array_only($item, ['name', 'description']); $data['slug'] = str_slug($data['name']); return $data; }); foreach ($business->servicetypes as $servicetype) { if (!$this->isPublished($servicetype, $publishing)) { $servicetype->delete(); } } foreach ($publishing as $servicetypeData) { $servicetype = ServiceType::firstOrNew($servicetypeData); $business->servicetypes()->save($servicetype); } flash()->success(trans('servicetype.msg.update.success')); return redirect()->route('manager.business.service.index', [$business]); }
function chat_post(&$a) { if ($_POST['room_name']) { $room = strip_tags(trim($_POST['room_name'])); } if (!$room || !local_channel()) { return; } $channel = $a->get_channel(); if ($_POST['action'] === 'drop') { logger('delete chatroom'); chatroom_destroy($channel, array('cr_name' => $room)); goaway(z_root() . '/chat/' . $channel['channel_address']); } $acl = new AccessList($channel); $acl->set_from_array($_REQUEST); $arr = $acl->get(); $arr['name'] = $room; $arr['expire'] = intval($_POST['chat_expire']); if (intval($arr['expire']) < 0) { $arr['expire'] = 0; } chatroom_create($channel, $arr); $x = q("select * from chatroom where cr_name = '%s' and cr_uid = %d limit 1", dbesc($room), intval(local_channel())); build_sync_packet(0, array('chatroom' => $x)); if ($x) { goaway(z_root() . '/chat/' . $channel['channel_address'] . '/' . $x[0]['cr_id']); } // that failed. Try again perhaps? goaway(z_root() . '/chat/' . $channel['channel_address'] . '/new'); }
function chat_post(&$a) { if ($_POST['room_name']) { $room = strip_tags(trim($_POST['room_name'])); } if (!$room || !local_channel()) { return; } $channel = $a->get_channel(); if ($_POST['action'] === 'drop') { logger('delete chatroom'); chatroom_destroy($channel, array('cr_name' => $room)); goaway(z_root() . '/chat/' . $channel['channel_address']); } $arr = array('name' => $room); $arr['allow_gid'] = perms2str($_REQUEST['group_allow']); $arr['allow_cid'] = perms2str($_REQUEST['contact_allow']); $arr['deny_gid'] = perms2str($_REQUEST['group_deny']); $arr['deny_cid'] = perms2str($_REQUEST['contact_deny']); chatroom_create($channel, $arr); $x = q("select cr_id from chatroom where cr_name = '%s' and cr_uid = %d limit 1", dbesc($room), intval(local_channel())); if ($x) { goaway(z_root() . '/chat/' . $channel['channel_address'] . '/' . $x[0]['cr_id']); } // that failed. Try again perhaps? goaway(z_root() . '/chat/' . $channel['channel_address'] . '/new'); }
/** * Sends the instructions to a user's email address. * * @return bool */ private static function _send_instructions($name, Model_User $user) { $config_key = null; switch ($name) { case 'confirmation': $config_key = 'confirmable'; break; case 'reset_password': $config_key = 'recoverable'; break; case 'unlock': $config_key = 'lockable'; break; default: throw new \InvalidArgumentException("Invalid instruction: {$name}"); } $mail = \Email::forge(); $mail->from(\Config::get('email.defaults.from.email'), \Config::get('email.defaults.from.name')); $mail->to($user->email); $mail->subject(__("warden.mailer.subject.{$name}")); $token_name = "{$name}_token"; $mail->html_body(\View::forge("warden/mailer/{$name}_instructions", array('username' => $user->username, 'uri' => \Uri::create(':url/:token', array('url' => rtrim(\Config::get("warden.{$config_key}.url"), '/'), 'token' => $user->{$token_name}))))); $mail->priority(\Email::P_HIGH); try { return $mail->send(); } catch (\EmailSendingFailedException $ex) { logger(\Fuel::L_ERROR, "Warden\\Mailer failed to send {$name} instructions."); return false; } }
/** * Extends parent constructor to detect availability of cURL * * @param string $resource * @param array $options * @throws \RuntimeException */ public function __construct($resource, array $options) { // check if we have libcurl available if (!class_exists('SoapClient')) { throw new \RuntimeException('Your PHP installation doesn\'t have Soap enabled. Rebuild PHP with --enable-soap'); } logger(\Fuel::L_INFO, 'Creating a new SOAP Request with URI = "' . $resource . '"', __METHOD__); // If authentication is enabled use it if (!empty($options['user']) and !empty($options['pass'])) { $this->set_option('login', $options['user']); $this->set_option('password', $options['pass']); } // WSDL-mode only options if (!empty($resource)) { foreach (static::$wsdl_settings as $setting) { isset($options[$setting]) and $this->set_option($setting, $options[$setting]); } } else { $resource = null; if (!isset($options['location']) or !isset($options['uri'])) { throw new \RequestException('The keys "location" and "uri" are required in non-WSDL mode.'); } foreach (static::$non_wsdl_settings as $setting) { isset($options[$setting]) and $this->set_option($setting, $options[$setting]); } } foreach (static::$generic_settings as $setting) { isset($options[$setting]) and $this->set_option($setting, $options[$setting]); } // make it always throw exceptions $this->set_option('exceptions', true); parent::__construct($resource, $options); }
/** * read the session * * @access public * @param boolean, set to true if we want to force a new session to be created * @return Fuel\Core\Session_Driver */ public function read($force = false) { // initialize the session $this->data = array(); $this->keys = array(); $this->flash = array(); // get the session cookie $payload = $this->_get_cookie(); // validate it if ($force) { // a forced session reset } elseif ($payload === false) { // no cookie found } elseif (!isset($payload[0]) or !is_array($payload[0])) { logger('DEBUG', 'Error: not a valid cookie payload!'); } elseif ($payload[0]['updated'] + $this->config['expiration_time'] <= $this->time->get_timestamp()) { logger('DEBUG', 'Error: session id has expired!'); } elseif ($this->config['match_ip'] and $payload[0]['ip_hash'] !== md5(\Input::ip() . \Input::real_ip())) { logger('DEBUG', 'Error: IP address in the session doesn\'t match this requests source IP!'); } elseif ($this->config['match_ua'] and $payload[0]['user_agent'] !== \Input::user_agent()) { logger('DEBUG', 'Error: User agent in the session doesn\'t match the browsers user agent string!'); } else { // session is valid, retrieve the payload if (isset($payload[0]) and is_array($payload[0])) { $this->keys = $payload[0]; } if (isset($payload[1]) and is_array($payload[1])) { $this->data = $payload[1]; } if (isset($payload[2]) and is_array($payload[2])) { $this->flash = $payload[2]; } } return parent::read(); }
function dsprphotoq_run($argv, $argc) { global $a, $db; if (is_null($a)) { $a = new App(); } if (is_null($db)) { @(include ".htconfig.php"); require_once "include/dba.php"; $db = new dba($db_host, $db_user, $db_pass, $db_data); unset($db_host, $db_user, $db_pass, $db_data); } logger("diaspora photo queue: running", LOGGER_DEBUG); $r = q("SELECT * FROM dsprphotoq"); if (!$r) { return; } $dphotos = $r; logger("diaspora photo queue: processing " . count($dphotos) . " photos"); foreach ($dphotos as $dphoto) { $r = q("SELECT * FROM user WHERE uid = %d", intval($dphoto['uid'])); if (!$r) { logger("diaspora photo queue: user " . $dphoto['uid'] . " not found"); return; } $ret = diaspora_dispatch($r[0], unserialize($dphoto['msg']), $dphoto['attempt']); q("DELETE FROM dsprphotoq WHERE id = %d", intval($dphoto['id'])); } }
function blackout_redirect($a, $b) { // if we have a logged in user, don't throw her out if (local_user()) { return true; } if (!(version_compare(PHP_VERSION, '5.3.0') >= 0)) { return true; } // else... $mystart = get_config('blackout', 'begindate'); $myend = get_config('blackout', 'enddate'); $myurl = get_config('blackout', 'url'); $now = time(); $date1 = DateTime::createFromFormat('Y-m-d G:i', $mystart); $date2 = DateTime::createFromFormat('Y-m-d G:i', $myend); if ($date1 && $date2) { $date1 = DateTime::createFromFormat('Y-m-d G:i', $mystart)->format('U'); $date2 = DateTime::createFromFormat('Y-m-d G:i', $myend)->format('U'); } else { $date1 = 0; $date2 = 0; } if ($date1 <= $now && $now <= $date2) { logger('redirecting user to blackout page'); goaway($myurl); } }
function checksites_run($argv, $argc) { cli_startup(); $a = get_app(); logger('checksites: start'); if ($argc > 1 && $argv[1]) { $site_id = $argv[1]; } if ($site_id) { $sql_options = " and site_url = '" . dbesc($argv[1]) . "' "; } $days = intval(get_config('system', 'sitecheckdays')); if ($days < 1) { $days = 30; } $r = q("select * from site where site_dead = 0 and site_update < %s - INTERVAL %s and site_type = %d {$sql_options} ", db_utcnow(), db_quoteinterval($days . ' DAY'), intval(SITE_TYPE_ZOT)); if (!$r) { return; } foreach ($r as $rr) { if (!strcasecmp($rr['site_url'], z_root())) { continue; } $x = ping_site($rr['site_url']); if ($x['success']) { logger('checksites: ' . $rr['site_url']); q("update site set site_update = '%s' where site_url = '%s' ", dbesc(datetime_convert()), dbesc($rr['site_url'])); } else { logger('marking dead site: ' . $x['message']); q("update site set site_dead = 1 where site_url = '%s' ", dbesc($rr['site_url'])); } } return; }
function filer_content(&$a) { if (!local_channel()) { killme(); } $term = unxmlify(trim($_GET['term'])); $item_id = $a->argc > 1 ? intval($a->argv[1]) : 0; logger('filer: tag ' . $term . ' item ' . $item_id); if ($item_id && strlen($term)) { // file item store_item_tag(local_channel(), $item_id, TERM_OBJ_POST, TERM_FILE, $term, ''); // protect the entire conversation from periodic expiration $r = q("select parent from item where id = %d and uid = %d limit 1", intval($item_id), intval(local_channel())); if ($r) { $x = q("update item set item_retained = 1 where id = %d and uid = %d", intval($r[0]['parent']), intval(local_channel())); } } else { $filetags = array(); $r = q("select distinct(term) from term where uid = %d and type = %d order by term asc", intval(local_channel()), intval(TERM_FILE)); if (count($r)) { foreach ($r as $rr) { $filetags[] = $rr['term']; } } $tpl = get_markup_template("filer_dialog.tpl"); $o = replace_macros($tpl, array('$field' => array('term', t("Save to Folder:"), '', '', $filetags, t('- select -')), '$submit' => t('Save'))); echo $o; } killme(); }
function zotfeed_init(&$a) { $result = array('success' => false); $mindate = $_REQUEST['mindate'] ? datetime_convert('UTC', 'UTC', $_REQUEST['mindate']) : ''; if (!$mindate) { $mindate = datetime_convert('UTC', 'UTC', 'now - 1 month'); } if (get_config('system', 'block_public') && !get_account_id() && !remote_user()) { $result['message'] = 'Public access denied'; json_return_and_die($result); } $observer = $a->get_observer(); $channel_address = argc() > 1 ? argv(1) : ''; if ($channel_address) { $r = q("select channel_id, channel_name from channel where channel_address = '%s' and not (channel_pageflags & %d) limit 1", dbesc(argv(1)), intval(PAGE_REMOVED)); } else { $x = get_sys_channel(); if ($x) { $r = array($x); } } if (!$r) { $result['message'] = 'Channel not found.'; json_return_and_die($result); } logger('zotfeed request: ' . $r[0]['channel_name'], LOGGER_DEBUG); $result['messages'] = zot_feed($r[0]['channel_id'], $observer['xchan_hash'], $mindate); $result['success'] = true; json_return_and_die($result); }
function profile_photo_set_profile_perms($profileid = '') { $allowcid = ''; if (x($profileid)) { $r = q("SELECT photo, profile_guid, id, is_default, uid FROM profile WHERE profile.id = %d OR profile.profile_guid = '%s' LIMIT 1", intval($profileid), dbesc($profileid)); } else { logger('Resetting permissions on default-profile-photo for user' . local_channel()); $r = q("SELECT photo, profile_guid, id, is_default, uid FROM profile WHERE profile.uid = %d AND is_default = 1 LIMIT 1", intval(local_channel())); //If no profile is given, we update the default profile } $profile = $r[0]; if (x($profile['id']) && x($profile['photo'])) { preg_match("@\\w*(?=-\\d*\$)@i", $profile['photo'], $resource_id); $resource_id = $resource_id[0]; if (intval($profile['is_default']) != 1) { $r0 = q("SELECT channel_hash FROM channel WHERE channel_id = %d LIMIT 1", intval(local_channel())); $r1 = q("SELECT abook.abook_xchan FROM abook WHERE abook_profile = '%d' ", intval($profile['id'])); //Should not be needed in future. Catches old int-profile-ids. $r2 = q("SELECT abook.abook_xchan FROM abook WHERE abook_profile = '%s'", dbesc($profile['profile_guid'])); $allowcid = "<" . $r0[0]['channel_hash'] . ">"; foreach ($r1 as $entry) { $allowcid .= "<" . $entry['abook_xchan'] . ">"; } foreach ($r2 as $entry) { $allowcid .= "<" . $entry['abook_xchan'] . ">"; } q("UPDATE `photo` SET allow_cid = '%s' WHERE resource_id = '%s' AND uid = %d", dbesc($allowcid), dbesc($resource_id), intval($profile['uid'])); } else { q("UPDATE `photo` SET allow_cid = '' WHERE profile = 1 AND uid = %d", intval($profile['uid'])); //Reset permissions on default profile picture to public } } return; }
function onedirsync_run($argv, $argc) { cli_startup(); $a = get_app(); logger('onedirsync: start ' . intval($argv[1])); if ($argc > 1 && intval($argv[1])) { $update_id = intval($argv[1]); } if (!$update_id) { logger('onedirsync: no update'); return; } $r = q("select * from updates where ud_id = %d limit 1", intval($update_id)); if (!$r) { return; } if ($r[0]['ud_flags'] & UPDATE_FLAGS_UPDATED || !$r[0]['ud_addr']) { return; } // Have we probed this channel more recently than the other directory server // (where we received this update from) ? // If we have, we don't need to do anything except mark any older entries updated $x = q("select * from updates where ud_addr = '%s' and ud_date > '%s' and ( ud_flags & %d ) order by ud_date desc limit 1", dbesc($r[0]['ud_addr']), dbesc($r[0]['ud_date']), intval(UPDATE_FLAGS_UPDATED)); if ($x) { $y = q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and not ( ud_flags & %d ) and ud_date < '%s' ", intval(UPDATE_FLAGS_UPDATED), dbesc($r[0]['ud_addr']), intval(UPDATE_FLAGS_UPDATED), dbesc($x[0]['ud_date'])); return; } update_directory_entry($r[0]); return; }
function init() { $uri = urldecode(notags(trim($_GET['uri']))); logger('xrd: ' . $uri, LOGGER_DEBUG); $resource = $uri; if (substr($uri, 0, 4) === 'http') { $uri = str_replace('~', '', $uri); $name = basename($uri); } else { $local = str_replace('acct:', '', $uri); if (substr($local, 0, 2) == '//') { $local = substr($local, 2); } $name = substr($local, 0, strpos($local, '@')); } $r = q("SELECT * FROM channel WHERE channel_address = '%s' LIMIT 1", dbesc($name)); if (!$r) { killme(); } $dspr = replace_macros(get_markup_template('xrd_diaspora.tpl'), array('$baseurl' => z_root(), '$dspr_guid' => $r[0]['channel_guid'] . str_replace('.', '', \App::get_hostname()), '$dspr_key' => base64_encode(pemtorsa($r[0]['channel_pubkey'])))); $salmon_key = salmon_key($r[0]['channel_pubkey']); header('Access-Control-Allow-Origin: *'); header("Content-type: application/xrd+xml"); $aliases = array('acct:' . channel_reddress($r[0]), z_root() . '/channel/' . $r[0]['channel_address'], z_root() . '/~' . $r[0]['channel_address']); for ($x = 0; $x < count($aliases); $x++) { if ($aliases[$x] === $resource) { unset($aliases[$x]); } } $o = replace_macros(get_markup_template('xrd_person.tpl'), array('$nick' => $r[0]['channel_address'], '$accturi' => $resource, '$aliases' => $aliases, '$profile_url' => z_root() . '/channel/' . $r[0]['channel_address'], '$hcard_url' => z_root() . '/hcard/' . $r[0]['channel_address'], '$atom' => z_root() . '/feed/' . $r[0]['channel_address'], '$zot_post' => z_root() . '/post/' . $r[0]['channel_address'], '$poco_url' => z_root() . '/poco/' . $r[0]['channel_address'], '$photo' => z_root() . '/photo/profile/l/' . $r[0]['channel_id'], '$dspr' => $dspr, '$modexp' => 'data:application/magic-public-key,' . $salmon_key, '$subscribe' => z_root() . '/follow?url={uri}', '$bigkey' => salmon_key($r[0]['channel_pubkey']))); $arr = array('user' => $r[0], 'xml' => $o); call_hooks('personal_xrd', $arr); echo $arr['xml']; killme(); }
function post_post(&$a) { $bulk_delivery = false; if ($a->argc == 1) { $bulk_delivery = true; } else { $nickname = $a->argv[2]; $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' \n\t\t\t\tAND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1", dbesc($nickname)); if (!count($r)) { http_status_exit(500); } $importer = $r[0]; } $xml = file_get_contents('php://input'); logger('mod-post: new zot: ' . $xml, LOGGER_DATA); if (!$xml) { http_status_exit(500); } $msg = zot_decode($importer, $xml); logger('mod-post: decoded msg: ' . print_r($msg, true), LOGGER_DATA); if (!is_array($msg)) { http_status_exit(500); } $ret = 0; $ret = zot_incoming($bulk_delivery, $importer, $msg); http_status_exit($ret ? $ret : 200); // NOTREACHED }