コード例 #1
0
ファイル: admin.php プロジェクト: strk/friendica
/**
 * @param  App $a
 * @return string
 */
function admin_page_site(&$a)
{
    /* Installed langs */
    $lang_choices = array();
    $langs = glob('view/*/strings.php');
    if (is_array($langs) && count($langs)) {
        if (!in_array('view/en/strings.php', $langs)) {
            $langs[] = 'view/en/';
        }
        asort($langs);
        foreach ($langs as $l) {
            $t = explode("/", $l);
            $lang_choices[$t[1]] = $t[1];
        }
    }
    /* Installed themes */
    $theme_choices = array();
    $theme_choices_mobile = array();
    $theme_choices_mobile["---"] = t("No special theme for mobile devices");
    $files = glob('view/theme/*');
    if ($files) {
        foreach ($files as $file) {
            $f = basename($file);
            $theme_name = file_exists($file . '/experimental') ? sprintf("%s - (Experimental)", $f) : $f;
            if (file_exists($file . '/mobile')) {
                $theme_choices_mobile[$f] = $theme_name;
            } else {
                $theme_choices[$f] = $theme_name;
            }
        }
    }
    /* Community page style */
    $community_page_style_choices = array(CP_NO_COMMUNITY_PAGE => t("No community page"), CP_USERS_ON_SERVER => t("Public postings from users of this site"), CP_GLOBAL_COMMUNITY => t("Global community page"));
    /* OStatus conversation poll choices */
    $ostatus_poll_choices = array("-2" => t("Never"), "-1" => t("At post arrival"), "0" => t("Frequently"), "60" => t("Hourly"), "720" => t("Twice daily"), "1440" => t("Daily"));
    /* get user names to make the install a personal install of X */
    $user_names = array();
    $user_names['---'] = t('Multi user instance');
    $users = q("SELECT username, nickname FROM `user`");
    foreach ($users as $user) {
        $user_names[$user['nickname']] = $user['username'];
    }
    /* Banner */
    $banner = get_config('system', 'banner');
    if ($banner == false) {
        $banner = '<a href="http://friendica.com"><img id="logo-img" src="images/friendica-32.png" alt="logo" /></a><span id="logo-text"><a href="http://friendica.com">Friendica</a></span>';
    }
    $banner = htmlspecialchars($banner);
    $info = get_config('config', 'info');
    $info = htmlspecialchars($info);
    // Automatically create temporary paths
    get_temppath();
    get_lockpath();
    get_itemcachepath();
    //echo "<pre>"; var_dump($lang_choices); die("</pre>");
    /* Register policy */
    $register_choices = array(REGISTER_CLOSED => t("Closed"), REGISTER_APPROVE => t("Requires approval"), REGISTER_OPEN => t("Open"));
    $ssl_choices = array(SSL_POLICY_NONE => t("No SSL policy, links will track page SSL state"), SSL_POLICY_FULL => t("Force all links to use SSL"), SSL_POLICY_SELFSIGN => t("Self-signed certificate, use SSL for local links only (discouraged)"));
    if ($a->config['hostname'] == "") {
        $a->config['hostname'] = $a->get_hostname();
    }
    $t = get_markup_template("admin_site.tpl");
    return replace_macros($t, array('$title' => t('Administration'), '$page' => t('Site'), '$submit' => t('Save Settings'), '$registration' => t('Registration'), '$upload' => t('File upload'), '$corporate' => t('Policies'), '$advanced' => t('Advanced'), '$performance' => t('Performance'), '$relocate' => t('Relocate - WARNING: advanced function. Could make this server unreachable.'), '$baseurl' => $a->get_baseurl(true), '$sitename' => array('sitename', t("Site name"), htmlentities($a->config['sitename'], ENT_QUOTES), 'UTF-8'), '$hostname' => array('hostname', t("Host name"), $a->config['hostname'], ""), '$sender_email' => array('sender_email', t("Sender Email"), $a->config['sender_email'], "The email address your server shall use to send notification emails from.", "", "", "email"), '$banner' => array('banner', t("Banner/Logo"), $banner, ""), '$shortcut_icon' => array('shortcut_icon', t("Shortcut icon"), get_config('system', 'shortcut_icon'), "Link to an icon that will be used for browsers."), '$touch_icon' => array('touch_icon', t("Touch icon"), get_config('system', 'touch_icon'), "Link to an icon that will be used for tablets and mobiles."), '$info' => array('info', t('Additional Info'), $info, t('For public servers: you can add additional information here that will be listed at dir.friendica.com/siteinfo.')), '$language' => array('language', t("System language"), get_config('system', 'language'), "", $lang_choices), '$theme' => array('theme', t("System theme"), get_config('system', 'theme'), t("Default system theme - may be over-ridden by user profiles - <a href='#' id='cnftheme'>change theme settings</a>"), $theme_choices), '$theme_mobile' => array('theme_mobile', t("Mobile system theme"), get_config('system', 'mobile-theme'), t("Theme for mobile devices"), $theme_choices_mobile), '$ssl_policy' => array('ssl_policy', t("SSL link policy"), (string) intval(get_config('system', 'ssl_policy')), t("Determines whether generated links should be forced to use SSL"), $ssl_choices), '$force_ssl' => array('force_ssl', t("Force SSL"), get_config('system', 'force_ssl'), t("Force all Non-SSL requests to SSL - Attention: on some systems it could lead to endless loops.")), '$old_share' => array('old_share', t("Old style 'Share'"), get_config('system', 'old_share'), t("Deactivates the bbcode element 'share' for repeating items.")), '$hide_help' => array('hide_help', t("Hide help entry from navigation menu"), get_config('system', 'hide_help'), t("Hides the menu entry for the Help pages from the navigation menu. You can still access it calling /help directly.")), '$singleuser' => array('singleuser', t("Single user instance"), get_config('system', 'singleuser'), t("Make this instance multi-user or single-user for the named user"), $user_names), '$maximagesize' => array('maximagesize', t("Maximum image size"), get_config('system', 'maximagesize'), t("Maximum size in bytes of uploaded images. Default is 0, which means no limits.")), '$maximagelength' => array('maximagelength', t("Maximum image length"), get_config('system', 'max_image_length'), t("Maximum length in pixels of the longest side of uploaded images. Default is -1, which means no limits.")), '$jpegimagequality' => array('jpegimagequality', t("JPEG image quality"), get_config('system', 'jpeg_quality'), t("Uploaded JPEGS will be saved at this quality setting [0-100]. Default is 100, which is full quality.")), '$register_policy' => array('register_policy', t("Register policy"), $a->config['register_policy'], "", $register_choices), '$daily_registrations' => array('max_daily_registrations', t("Maximum Daily Registrations"), get_config('system', 'max_daily_registrations'), t("If registration is permitted above, this sets the maximum number of new user registrations to accept per day.  If register is set to closed, this setting has no effect.")), '$register_text' => array('register_text', t("Register text"), htmlentities($a->config['register_text'], ENT_QUOTES, 'UTF-8'), t("Will be displayed prominently on the registration page.")), '$abandon_days' => array('abandon_days', t('Accounts abandoned after x days'), get_config('system', 'account_abandon_days'), t('Will not waste system resources polling external sites for abandonded accounts. Enter 0 for no time limit.')), '$allowed_sites' => array('allowed_sites', t("Allowed friend domains"), get_config('system', 'allowed_sites'), t("Comma separated list of domains which are allowed to establish friendships with this site. Wildcards are accepted. Empty to allow any domains")), '$allowed_email' => array('allowed_email', t("Allowed email domains"), get_config('system', 'allowed_email'), t("Comma separated list of domains which are allowed in email addresses for registrations to this site. Wildcards are accepted. Empty to allow any domains")), '$block_public' => array('block_public', t("Block public"), get_config('system', 'block_public'), t("Check to block public access to all otherwise public personal pages on this site unless you are currently logged in.")), '$force_publish' => array('publish_all', t("Force publish"), get_config('system', 'publish_all'), t("Check to force all profiles on this site to be listed in the site directory.")), '$global_directory' => array('directory_submit_url', t("Global directory update URL"), get_config('system', 'directory_submit_url'), t("URL to update the global directory. If this is not set, the global directory is completely unavailable to the application.")), '$thread_allow' => array('thread_allow', t("Allow threaded items"), get_config('system', 'thread_allow'), t("Allow infinite level threading for items on this site.")), '$newuser_private' => array('newuser_private', t("Private posts by default for new users"), get_config('system', 'newuser_private'), t("Set default post permissions for all new members to the default privacy group rather than public.")), '$enotify_no_content' => array('enotify_no_content', t("Don't include post content in email notifications"), get_config('system', 'enotify_no_content'), t("Don't include the content of a post/comment/private message/etc. in the email notifications that are sent out from this site, as a privacy measure.")), '$private_addons' => array('private_addons', t("Disallow public access to addons listed in the apps menu."), get_config('config', 'private_addons'), t("Checking this box will restrict addons listed in the apps menu to members only.")), '$disable_embedded' => array('disable_embedded', t("Don't embed private images in posts"), get_config('system', 'disable_embedded'), t("Don't replace locally-hosted private photos in posts with an embedded copy of the image. This means that contacts who receive posts containing private photos will have to authenticate and load each image, which may take a while.")), '$allow_users_remote_self' => array('allow_users_remote_self', t('Allow Users to set remote_self'), get_config('system', 'allow_users_remote_self'), t('With checking this, every user is allowed to mark every contact as a remote_self in the repair contact dialog. Setting this flag on a contact causes mirroring every posting of that contact in the users stream.')), '$no_multi_reg' => array('no_multi_reg', t("Block multiple registrations"), get_config('system', 'block_extended_register'), t("Disallow users to register additional accounts for use as pages.")), '$no_openid' => array('no_openid', t("OpenID support"), !get_config('system', 'no_openid'), t("OpenID support for registration and logins.")), '$no_regfullname' => array('no_regfullname', t("Fullname check"), !get_config('system', 'no_regfullname'), t("Force users to register with a space between firstname and lastname in Full name, as an antispam measure")), '$no_utf' => array('no_utf', t("UTF-8 Regular expressions"), !get_config('system', 'no_utf'), t("Use PHP UTF8 regular expressions")), '$community_page_style' => array('community_page_style', t("Community Page Style"), get_config('system', 'community_page_style'), t("Type of community page to show. 'Global community' shows every public posting from an open distributed network that arrived on this server."), $community_page_style_choices), '$max_author_posts_community_page' => array('max_author_posts_community_page', t("Posts per user on community page"), get_config('system', 'max_author_posts_community_page'), t("The maximum number of posts per user on the community page. (Not valid for 'Global Community')")), '$ostatus_disabled' => array('ostatus_disabled', t("Enable OStatus support"), !get_config('system', 'ostatus_disabled'), t("Provide built-in OStatus (StatusNet, GNU Social etc.) compatibility. All communications in OStatus are public, so privacy warnings will be occasionally displayed.")), '$ostatus_poll_interval' => array('ostatus_poll_interval', t("OStatus conversation completion interval"), (string) intval(get_config('system', 'ostatus_poll_interval')), t("How often shall the poller check for new entries in OStatus conversations? This can be a very ressource task."), $ostatus_poll_choices), '$diaspora_enabled' => array('diaspora_enabled', t("Enable Diaspora support"), get_config('system', 'diaspora_enabled'), t("Provide built-in Diaspora network compatibility.")), '$dfrn_only' => array('dfrn_only', t('Only allow Friendica contacts'), get_config('system', 'dfrn_only'), t("All contacts must use Friendica protocols. All other built-in communication protocols disabled.")), '$verifyssl' => array('verifyssl', t("Verify SSL"), get_config('system', 'verifyssl'), t("If you wish, you can turn on strict certificate checking. This will mean you cannot connect (at all) to self-signed SSL sites.")), '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system', 'proxyuser'), ""), '$proxy' => array('proxy', t("Proxy URL"), get_config('system', 'proxy'), ""), '$timeout' => array('timeout', t("Network timeout"), x(get_config('system', 'curl_timeout')) ? get_config('system', 'curl_timeout') : 60, t("Value is in seconds. Set to 0 for unlimited (not recommended).")), '$delivery_interval' => array('delivery_interval', t("Delivery interval"), x(get_config('system', 'delivery_interval')) ? get_config('system', 'delivery_interval') : 2, t("Delay background delivery processes by this many seconds to reduce system load. Recommend: 4-5 for shared hosts, 2-3 for virtual private servers. 0-1 for large dedicated servers.")), '$poll_interval' => array('poll_interval', t("Poll interval"), x(get_config('system', 'poll_interval')) ? get_config('system', 'poll_interval') : 2, t("Delay background polling processes by this many seconds to reduce system load. If 0, use delivery interval.")), '$maxloadavg' => array('maxloadavg', t("Maximum Load Average"), intval(get_config('system', 'maxloadavg')) > 0 ? get_config('system', 'maxloadavg') : 50, t("Maximum system load before delivery and poll processes are deferred - default 50.")), '$use_fulltext_engine' => array('use_fulltext_engine', t("Use MySQL full text engine"), get_config('system', 'use_fulltext_engine'), t("Activates the full text engine. Speeds up search - but can only search for four and more characters.")), '$suppress_language' => array('suppress_language', t("Suppress Language"), get_config('system', 'suppress_language'), t("Suppress language information in meta information about a posting.")), '$suppress_tags' => array('suppress_tags', t("Suppress Tags"), get_config('system', 'suppress_tags'), t("Suppress showing a list of hashtags at the end of the posting.")), '$itemcache' => array('itemcache', t("Path to item cache"), get_config('system', 'itemcache'), "The item caches buffers generated bbcode and external images."), '$itemcache_duration' => array('itemcache_duration', t("Cache duration in seconds"), get_config('system', 'itemcache_duration'), t("How long should the cache files be hold? Default value is 86400 seconds (One day). To disable the item cache, set the value to -1.")), '$max_comments' => array('max_comments', t("Maximum numbers of comments per post"), get_config('system', 'max_comments'), t("How much comments should be shown for each post? Default value is 100.")), '$lockpath' => array('lockpath', t("Path for lock file"), get_config('system', 'lockpath'), "The lock file is used to avoid multiple pollers at one time. Only define a folder here."), '$temppath' => array('temppath', t("Temp path"), get_config('system', 'temppath'), "If you have a restricted system where the webserver can't access the system temp path, enter another path here."), '$basepath' => array('basepath', t("Base path to installation"), get_config('system', 'basepath'), "If the system cannot detect the correct path to your installation, enter the correct path here. This setting should only be set if you are using a restricted system and symbolic links to your webroot."), '$proxy_disabled' => array('proxy_disabled', t("Disable picture proxy"), get_config('system', 'proxy_disabled'), t("The picture proxy increases performance and privacy. It shouldn't be used on systems with very low bandwith.")), '$old_pager' => array('old_pager', t("Enable old style pager"), get_config('system', 'old_pager'), t("The old style pager has page numbers but slows down massively the page speed.")), '$only_tag_search' => array('only_tag_search', t("Only search in tags"), get_config('system', 'only_tag_search'), t("On large systems the text search can slow down the system extremely.")), '$relocate_url' => array('relocate_url', t("New base url"), $a->get_baseurl(), "Change base url for this server. Sends relocate message to all DFRN contacts of all users."), '$form_security_token' => get_form_security_token("admin_site")));
}
コード例 #2
0
ファイル: boot.php プロジェクト: jzacman/friendica
function get_lockpath()
{
    $lockpath = get_config('system', 'lockpath');
    if ($lockpath != "" and is_dir($lockpath) and is_writable($lockpath)) {
        return $lockpath;
    }
    $temppath = get_temppath();
    if ($temppath != "") {
        $lockpath = $temppath . "/lock";
        mkdir($lockpath);
        if (is_dir($lockpath) and is_writable($lockpath)) {
            set_config("system", "lockpath", $lockpath);
            return $lockpath;
        }
    }
    return "";
}
コード例 #3
0
ファイル: Photo.php プロジェクト: jzacman/friendica
function store_photo($a, $uid, $imagedata = "", $url = "")
{
    $r = q("SELECT `user`.`nickname`, `user`.`page-flags`, `contact`.`id` FROM `user` INNER JOIN `contact` on `user`.`uid` = `contact`.`uid`\n\t\tWHERE `user`.`uid` = %d AND `user`.`blocked` = 0 and `contact`.`self` = 1 LIMIT 1", intval($uid));
    if (!count($r)) {
        logger("Can't detect user data for uid " . $uid, LOGGER_DEBUG);
        return array();
    }
    $page_owner_nick = $r[0]['nickname'];
    //	To-Do:
    //	$default_cid      = $r[0]['id'];
    //	$community_page   = (($r[0]['page-flags'] == PAGE_COMMUNITY) ? true : false);
    if (strlen($imagedata) == 0 and $url == "") {
        logger("No image data and no url provided", LOGGER_DEBUG);
        return array();
    } elseif (strlen($imagedata) == 0) {
        logger("Uploading picture from " . $url, LOGGER_DEBUG);
        $imagedata = @file_get_contents($url);
    }
    $maximagesize = get_config('system', 'maximagesize');
    if ($maximagesize && strlen($imagedata) > $maximagesize) {
        logger("Image exceeds size limit of " . $maximagesize, LOGGER_DEBUG);
        return array();
    }
    /*
            $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
                    intval($uid)
            );
    
            $limit = service_class_fetch($uid,'photo_upload_limit');
    
            if(($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
    		logger("Image exceeds personal limit of uid ".$uid, LOGGER_DEBUG);
    		return(array());
            }
    */
    $tempfile = tempnam(get_temppath(), "cache");
    file_put_contents($tempfile, $imagedata);
    $data = getimagesize($tempfile);
    if (!isset($data["mime"])) {
        unlink($tempfile);
        logger("File is no picture", LOGGER_DEBUG);
        return array();
    }
    $ph = new Photo($imagedata, $data["mime"]);
    if (!$ph->is_valid()) {
        unlink($tempfile);
        logger("Picture is no valid picture", LOGGER_DEBUG);
        return array();
    }
    $ph->orient($tempfile);
    unlink($tempfile);
    $max_length = get_config('system', 'max_image_length');
    if (!$max_length) {
        $max_length = MAX_IMAGE_LENGTH;
    }
    if ($max_length > 0) {
        $ph->scaleImage($max_length);
    }
    $width = $ph->getWidth();
    $height = $ph->getHeight();
    $hash = photo_new_resource();
    $smallest = 0;
    // Pictures are always public by now
    //$defperm = '<'.$default_cid.'>';
    $defperm = "";
    $visitor = 0;
    $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 0, 0, $defperm);
    if (!$r) {
        logger("Picture couldn't be stored", LOGGER_DEBUG);
        return array();
    }
    $image = array("page" => $a->get_baseurl() . '/photos/' . $page_owner_nick . '/image/' . $hash, "full" => $a->get_baseurl() . "/photo/{$hash}-0." . $ph->getExt());
    if ($width > 800 || $height > 800) {
        $image["large"] = $a->get_baseurl() . "/photo/{$hash}-0." . $ph->getExt();
    }
    if ($width > 640 || $height > 640) {
        $ph->scaleImage(640);
        $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 1, 0, $defperm);
        if ($r) {
            $image["medium"] = $a->get_baseurl() . "/photo/{$hash}-1." . $ph->getExt();
        }
    }
    if ($width > 320 || $height > 320) {
        $ph->scaleImage(320);
        $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 2, 0, $defperm);
        if ($r) {
            $image["small"] = $a->get_baseurl() . "/photo/{$hash}-2." . $ph->getExt();
        }
    }
    if ($width > 160 and $height > 160) {
        $x = 0;
        $y = 0;
        $min = $ph->getWidth();
        if ($min > 160) {
            $x = ($min - 160) / 2;
        }
        if ($ph->getHeight() < $min) {
            $min = $ph->getHeight();
            if ($min > 160) {
                $y = ($min - 160) / 2;
            }
        }
        $min = 160;
        $ph->cropImage(160, $x, $y, $min, $min);
        $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 3, 0, $defperm);
        if ($r) {
            $image["thumb"] = $a->get_baseurl() . "/photo/{$hash}-3." . $ph->getExt();
        }
    }
    // Set the full image as preview image. This will be overwritten, if the picture is larger than 640.
    $image["preview"] = $image["full"];
    // Deactivated, since that would result in a cropped preview, if the picture wasn't larger than 320
    //if (isset($image["thumb"]))
    //	$image["preview"] = $image["thumb"];
    // Unsure, if this should be activated or deactivated
    //if (isset($image["small"]))
    //	$image["preview"] = $image["small"];
    if (isset($image["medium"])) {
        $image["preview"] = $image["medium"];
    }
    return $image;
}
コード例 #4
0
function twitter_expand_entities($a, $body, $item, $no_tags = false, $picture)
{
    require_once "include/oembed.php";
    require_once "include/network.php";
    $tags = "";
    if (isset($item->entities->urls)) {
        $type = "";
        $footerurl = "";
        $footerlink = "";
        $footer = "";
        foreach ($item->entities->urls as $url) {
            if ($url->url and $url->expanded_url and $url->display_url) {
                $expanded_url = original_url($url->expanded_url);
                $oembed_data = oembed_fetch_url($expanded_url);
                // Quickfix: Workaround for URL with "[" and "]" in it
                if (strpos($expanded_url, "[") or strpos($expanded_url, "]")) {
                    $expanded_url = $url->url;
                }
                if ($type == "") {
                    $type = $oembed_data->type;
                }
                if ($oembed_data->type == "video") {
                    //$body = str_replace($url->url,
                    //		"[video]".$expanded_url."[/video]", $body);
                    //$dontincludemedia = true;
                    $type = $oembed_data->type;
                    $footerurl = $expanded_url;
                    $footerlink = "[url=" . $expanded_url . "]" . $expanded_url . "[/url]";
                    $body = str_replace($url->url, $footerlink, $body);
                    //} elseif (($oembed_data->type == "photo") AND isset($oembed_data->url) AND !$dontincludemedia) {
                } elseif ($oembed_data->type == "photo" and isset($oembed_data->url)) {
                    $body = str_replace($url->url, "[url=" . $expanded_url . "][img]" . $oembed_data->url . "[/img][/url]", $body);
                    //$dontincludemedia = true;
                } elseif ($oembed_data->type != "link") {
                    $body = str_replace($url->url, "[url=" . $expanded_url . "]" . $expanded_url . "[/url]", $body);
                } else {
                    $img_str = fetch_url($expanded_url, true, $redirects, 4);
                    $tempfile = tempnam(get_temppath(), "cache");
                    file_put_contents($tempfile, $img_str);
                    $mime = image_type_to_mime_type(exif_imagetype($tempfile));
                    unlink($tempfile);
                    if (substr($mime, 0, 6) == "image/") {
                        $type = "photo";
                        $body = str_replace($url->url, "[img]" . $expanded_url . "[/img]", $body);
                        //$dontincludemedia = true;
                    } else {
                        $type = $oembed_data->type;
                        $footerurl = $expanded_url;
                        $footerlink = "[url=" . $expanded_url . "]" . $expanded_url . "[/url]";
                        $body = str_replace($url->url, $footerlink, $body);
                    }
                }
            }
        }
        if ($footerurl != "") {
            $footer = add_page_info($footerurl, false, $picture);
        }
        if ($footerlink != "" and trim($footer) != "") {
            $removedlink = trim(str_replace($footerlink, "", $body));
            if ($removedlink == "" or strstr($body, $removedlink)) {
                $body = $removedlink;
            }
            $body .= $footer;
        }
        if ($footer == "" and $picture != "") {
            $body .= "\n\n[img]" . $picture . "[/img]\n";
        } elseif ($footer == "" and $picture == "") {
            $body = add_page_info_to_body($body);
        }
        if ($no_tags) {
            return array("body" => $body, "tags" => "");
        }
        $tags_arr = array();
        foreach ($item->entities->hashtags as $hashtag) {
            $url = "#[url=" . $a->get_baseurl() . "/search?tag=" . rawurlencode($hashtag->text) . "]" . $hashtag->text . "[/url]";
            $tags_arr["#" . $hashtag->text] = $url;
            $body = str_replace("#" . $hashtag->text, $url, $body);
        }
        foreach ($item->entities->user_mentions as $mention) {
            $url = "@[url=https://twitter.com/" . rawurlencode($mention->screen_name) . "]" . $mention->screen_name . "[/url]";
            $tags_arr["@" . $mention->screen_name] = $url;
            $body = str_replace("@" . $mention->screen_name, $url, $body);
        }
        // it seems as if the entities aren't always covering all mentions. So the rest will be checked here
        $tags = get_tags($body);
        if (count($tags)) {
            foreach ($tags as $tag) {
                if (strstr(trim($tag), " ")) {
                    continue;
                }
                if (strpos($tag, '#') === 0) {
                    if (strpos($tag, '[url=')) {
                        continue;
                    }
                    // don't link tags that are already embedded in links
                    if (preg_match('/\\[(.*?)' . preg_quote($tag, '/') . '(.*?)\\]/', $body)) {
                        continue;
                    }
                    if (preg_match('/\\[(.*?)\\]\\((.*?)' . preg_quote($tag, '/') . '(.*?)\\)/', $body)) {
                        continue;
                    }
                    $basetag = str_replace('_', ' ', substr($tag, 1));
                    $url = '#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
                    $body = str_replace($tag, $url, $body);
                    $tags_arr["#" . $basetag] = $url;
                    continue;
                } elseif (strpos($tag, '@') === 0) {
                    if (strpos($tag, '[url=')) {
                        continue;
                    }
                    $basetag = substr($tag, 1);
                    $url = '@[url=https://twitter.com/' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
                    $body = str_replace($tag, $url, $body);
                    $tags_arr["@" . $basetag] = $url;
                }
            }
        }
        $tags = implode($tags_arr, ",");
    }
    return array("body" => $body, "tags" => $tags);
}
コード例 #5
0
ファイル: appnet.php プロジェクト: rabuzarus/friendica-addons
function appnet_send(&$a, &$b)
{
    logger('appnet_send: invoked for post ' . $b['id'] . " " . $b['app']);
    if (!get_pconfig($b["uid"], 'appnet', 'import')) {
        if ($b['deleted'] || $b['private'] || $b['created'] !== $b['edited']) {
            return;
        }
    }
    if ($b['parent'] != $b['id']) {
        logger("appnet_send: parameter " . print_r($b, true), LOGGER_DATA);
        // Looking if its a reply to an app.net post
        if (substr($b["parent-uri"], 0, 5) != "adn::" and substr($b["extid"], 0, 5) != "adn::" and substr($b["thr-parent"], 0, 5) != "adn::") {
            logger("appnet_send: no app.net post " . $b["parent"]);
            return;
        }
        $r = q("SELECT * FROM item WHERE item.uri = '%s' AND item.uid = %d LIMIT 1", dbesc($b["thr-parent"]), intval($b["uid"]));
        if (!count($r)) {
            logger("appnet_send: no parent found " . $b["thr-parent"]);
            return;
        } else {
            $iscomment = true;
            $orig_post = $r[0];
        }
        $nicknameplain = preg_replace("=https?://alpha.app.net/(.*)=ism", "\$1", $orig_post["author-link"]);
        $nickname = "@[url=" . $orig_post["author-link"] . "]" . $nicknameplain . "[/url]";
        $nicknameplain = "@" . $nicknameplain;
        logger("appnet_send: comparing " . $nickname . " and " . $nicknameplain . " with " . $b["body"], LOGGER_DEBUG);
        if (strpos($b["body"], $nickname) === false and strpos($b["body"], $nicknameplain) === false) {
            $b["body"] = $nickname . " " . $b["body"];
        }
        logger("appnet_send: parent found " . print_r($orig_post, true), LOGGER_DATA);
    } else {
        $iscomment = false;
        if ($b['private'] or !strstr($b['postopts'], 'appnet')) {
            return;
        }
    }
    if ($b['verb'] == ACTIVITY_POST and $b['deleted']) {
        appnet_action($a, $b["uid"], substr($orig_post["uri"], 5), "delete");
    }
    if ($b['verb'] == ACTIVITY_LIKE) {
        logger("appnet_send: " . print_r($b, true), LOGGER_DEBUG);
        logger("appnet_send: parameter 2 " . substr($b["thr-parent"], 5), LOGGER_DEBUG);
        if ($b['deleted']) {
            appnet_action($a, $b["uid"], substr($b["thr-parent"], 5), "unlike");
        } else {
            appnet_action($a, $b["uid"], substr($b["thr-parent"], 5), "like");
        }
        return;
    }
    if ($b['deleted'] || $b['created'] !== $b['edited']) {
        return;
    }
    $token = get_pconfig($b['uid'], 'appnet', 'token');
    if ($token) {
        // If it's a repeated message from app.net then do a native repost and exit
        if (appnet_is_repost($a, $b['uid'], $b['body'])) {
            return;
        }
        require_once 'addon/appnet/AppDotNet.php';
        $clientId = get_pconfig($b["uid"], 'appnet', 'clientid');
        $clientSecret = get_pconfig($b["uid"], 'appnet', 'clientsecret');
        $app = new AppDotNet($clientId, $clientSecret);
        $app->setAccessToken($token);
        $data = array();
        require_once "include/plaintext.php";
        require_once "include/network.php";
        $post = plaintext($a, $b, 256, false, 6);
        logger("appnet_send: converted message " . $b["id"] . " result: " . print_r($post, true), LOGGER_DEBUG);
        if (isset($post["image"])) {
            $img_str = fetch_url($post['image'], true, $redirects, 10);
            $tempfile = tempnam(get_temppath(), "cache");
            file_put_contents($tempfile, $img_str);
            try {
                $photoFile = $app->createFile($tempfile, array(type => "com.github.jdolitsky.appdotnetphp.photo"));
                $data["annotations"][] = array("type" => "net.app.core.oembed", "value" => array("+net.app.core.file" => array("file_id" => $photoFile["id"], "file_token" => $photoFile["file_token"], "format" => "oembed")));
            } catch (AppDotNetException $e) {
                logger("appnet_send: Error creating file " . appnet_error($e->getMessage()));
            }
            unlink($tempfile);
        }
        // Adding a link to the original post, if it is a root post
        if ($b['parent'] == $b['id']) {
            $data["annotations"][] = array("type" => "net.app.core.crosspost", "value" => array("canonical_url" => $b["plink"]));
        }
        // Adding the original post
        $attached_data = get_attached_data($b["body"]);
        $attached_data["post-uri"] = $b["uri"];
        $attached_data["post-title"] = $b["title"];
        $attached_data["post-body"] = substr($b["body"], 0, 4000);
        // To-Do: Better shortening
        $attached_data["post-tag"] = $b["tag"];
        $attached_data["author-name"] = $b["author-name"];
        $attached_data["author-link"] = $b["author-link"];
        $attached_data["author-avatar"] = $b["author-avatar"];
        $data["annotations"][] = array("type" => "com.friendica.post", "value" => $attached_data);
        if (isset($post["url"]) and !isset($post["title"]) and $post["type"] != "photo") {
            $display_url = str_replace(array("http://www.", "https://www."), array("", ""), $post["url"]);
            $display_url = str_replace(array("http://", "https://"), array("", ""), $display_url);
            if (strlen($display_url) > 26) {
                $display_url = substr($display_url, 0, 25) . "…";
            }
            $post["title"] = $display_url;
        }
        $text = appnet_create_entities($a, $b, $post);
        $data["entities"]["parse_markdown_links"] = true;
        if ($iscomment) {
            $data["reply_to"] = substr($orig_post["uri"], 5);
        }
        try {
            logger("appnet_send: sending message " . $b["id"] . " " . $text . " " . print_r($data, true), LOGGER_DEBUG);
            $ret = $app->createPost($text, $data);
            logger("appnet_send: send message " . $b["id"] . " result: " . print_r($ret, true), LOGGER_DEBUG);
            if ($iscomment) {
                logger('appnet_send: Update extid ' . $ret["id"] . " for post id " . $b['id']);
                q("UPDATE `item` SET `extid` = '%s' WHERE `id` = %d", dbesc("adn::" . $ret["id"]), intval($b['id']));
            }
        } catch (AppDotNetException $e) {
            logger("appnet_send: Error sending message " . $b["id"] . " " . appnet_error($e->getMessage()));
        }
    }
}
コード例 #6
0
function statusnet_convertmsg($a, $body, $no_tags = false)
{
    require_once "include/oembed.php";
    require_once "include/items.php";
    require_once "include/network.php";
    $body = preg_replace("=\\[url\\=https?://([0-9]*).([0-9]*).([0-9]*).([0-9]*)/([0-9]*)\\](.*?)\\[\\/url\\]=ism", "\$1.\$2.\$3.\$4/\$5", $body);
    $URLSearchString = "^\\[\\]";
    $links = preg_match_all("/[^!#@]\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", $body, $matches, PREG_SET_ORDER);
    $footer = "";
    $footerurl = "";
    $footerlink = "";
    $type = "";
    if ($links) {
        foreach ($matches as $match) {
            $search = "[url=" . $match[1] . "]" . $match[2] . "[/url]";
            logger("statusnet_convertmsg: expanding url " . $match[1], LOGGER_DEBUG);
            $expanded_url = original_url($match[1]);
            logger("statusnet_convertmsg: fetching data for " . $expanded_url, LOGGER_DEBUG);
            $oembed_data = oembed_fetch_url($expanded_url, true);
            logger("statusnet_convertmsg: fetching data: done", LOGGER_DEBUG);
            if ($type == "") {
                $type = $oembed_data->type;
            }
            if ($oembed_data->type == "video") {
                //$body = str_replace($search, "[video]".$expanded_url."[/video]", $body);
                $type = $oembed_data->type;
                $footerurl = $expanded_url;
                $footerlink = "[url=" . $expanded_url . "]" . $expanded_url . "[/url]";
                $body = str_replace($search, $footerlink, $body);
            } elseif ($oembed_data->type == "photo" and isset($oembed_data->url) and !$dontincludemedia) {
                $body = str_replace($search, "[url=" . $expanded_url . "][img]" . $oembed_data->url . "[/img][/url]", $body);
            } elseif ($oembed_data->type != "link") {
                $body = str_replace($search, "[url=" . $expanded_url . "]" . $expanded_url . "[/url]", $body);
            } else {
                $img_str = fetch_url($expanded_url, true, $redirects, 4);
                $tempfile = tempnam(get_temppath(), "cache");
                file_put_contents($tempfile, $img_str);
                $mime = image_type_to_mime_type(exif_imagetype($tempfile));
                unlink($tempfile);
                if (substr($mime, 0, 6) == "image/") {
                    $type = "photo";
                    $body = str_replace($search, "[img]" . $expanded_url . "[/img]", $body);
                } else {
                    $type = $oembed_data->type;
                    $footerurl = $expanded_url;
                    $footerlink = "[url=" . $expanded_url . "]" . $expanded_url . "[/url]";
                    $body = str_replace($search, $footerlink, $body);
                }
            }
        }
        if ($footerurl != "") {
            $footer = add_page_info($footerurl);
        }
        if ($footerlink != "" and trim($footer) != "") {
            $removedlink = trim(str_replace($footerlink, "", $body));
            if ($removedlink == "" or strstr($body, $removedlink)) {
                $body = $removedlink;
            }
            $body .= $footer;
        }
    }
    if ($no_tags) {
        return array("body" => $body, "tags" => "");
    }
    $str_tags = '';
    $cnt = preg_match_all("/([!#@])\\[url\\=([{$URLSearchString}]*)\\](.*?)\\[\\/url\\]/ism", $body, $matches, PREG_SET_ORDER);
    if ($cnt) {
        foreach ($matches as $mtch) {
            if (strlen($str_tags)) {
                $str_tags .= ',';
            }
            if ($mtch[1] == "#") {
                // Replacing the hash tags that are directed to the GNU Social server with internal links
                $snhash = "#[url=" . $mtch[2] . "]" . $mtch[3] . "[/url]";
                $frdchash = '#[url=' . $a->get_baseurl() . '/search?tag=' . rawurlencode($mtch[3]) . ']' . $mtch[3] . '[/url]';
                $body = str_replace($snhash, $frdchash, $body);
                $str_tags .= $frdchash;
            } else {
                $str_tags .= "@[url=" . $mtch[2] . "]" . $mtch[3] . "[/url]";
            }
            // To-Do:
            // There is a problem with links with to GNU Social groups, so these links are stored with "@" like friendica groups
            //$str_tags .= $mtch[1]."[url=".$mtch[2]."]".$mtch[3]."[/url]";
        }
    }
    return array("body" => $body, "tags" => $str_tags);
}
コード例 #7
0
function mailstream_do_images($a, &$item, &$attachments)
{
    if (!get_pconfig($item['uid'], 'mailstream', 'attachimg')) {
        return;
    }
    $attachments = array();
    $baseurl = $a->get_baseurl();
    preg_match_all("/\\[img\\=([0-9]*)x([0-9]*)\\](.*?)\\[\\/img\\]/ism", $item["body"], $matches1);
    preg_match_all("/\\[img\\](.*?)\\[\\/img\\]/ism", $item["body"], $matches2);
    foreach (array_merge($matches1[3], $matches2[1]) as $url) {
        $redirects;
        $cookiejar = tempnam(get_temppath(), 'cookiejar-mailstream-');
        $attachments[$url] = array('data' => fetch_url($url, true, $redirects, 0, Null, $cookiejar), 'guid' => hash("crc32", $url), 'filename' => basename($url), 'type' => $a->get_curl_content_type());
        if (strlen($attachments[$url]['data'])) {
            $item['body'] = str_replace($url, 'cid:' . $attachments[$url]['guid'], $item['body']);
            continue;
        }
    }
    return $attachments;
}
コード例 #8
0
ファイル: proxy.php プロジェクト: ZerGabriel/friendica
function proxy_init()
{
    global $a, $_SERVER;
    // Pictures are stored in one of the following ways:
    // 1. If a folder "proxy" exists and is writeable, then use this for caching
    // 2. If a cache path is defined, use this
    // 3. If everything else failed, cache into the database
    //
    // Question: Do we really need these three methods?
    if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
        header('HTTP/1.1 304 Not Modified');
        header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
        header('Etag: ' . $_SERVER['HTTP_IF_NONE_MATCH']);
        header("Expires: " . gmdate("D, d M Y H:i:s", time() + 31536000) . " GMT");
        header("Cache-Control: max-age=31536000");
        if (function_exists('header_remove')) {
            header_remove('Last-Modified');
            header_remove('Expires');
            header_remove('Cache-Control');
        }
        exit;
    }
    if (function_exists('header_remove')) {
        header_remove('Pragma');
        header_remove('pragma');
    }
    $thumb = false;
    $size = 1024;
    // If the cache path isn't there, try to create it
    if (!is_dir($_SERVER["DOCUMENT_ROOT"] . "/proxy")) {
        if (is_writable($_SERVER["DOCUMENT_ROOT"])) {
            mkdir($_SERVER["DOCUMENT_ROOT"] . "/proxy");
        }
    }
    // Checking if caching into a folder in the webroot is activated and working
    $direct_cache = (is_dir($_SERVER["DOCUMENT_ROOT"] . "/proxy") and is_writable($_SERVER["DOCUMENT_ROOT"] . "/proxy"));
    // Look for filename in the arguments
    if ((isset($a->argv[1]) or isset($a->argv[2]) or isset($a->argv[3])) and !isset($_REQUEST["url"])) {
        if (isset($a->argv[3])) {
            $url = $a->argv[3];
        } elseif (isset($a->argv[2])) {
            $url = $a->argv[2];
        } else {
            $url = $a->argv[1];
        }
        if (isset($a->argv[3]) and $a->argv[3] == "thumb") {
            $size = 200;
        }
        // thumb, small, medium and large.
        if (substr($url, -6) == ":thumb") {
            $size = 150;
        }
        if (substr($url, -6) == ":small") {
            $size = 340;
        }
        if (substr($url, -7) == ":medium") {
            $size = 600;
        }
        if (substr($url, -6) == ":large") {
            $size = 1024;
        }
        $pos = strrpos($url, "=.");
        if ($pos) {
            $url = substr($url, 0, $pos + 1);
        }
        $url = str_replace(array(".jpg", ".jpeg", ".gif", ".png"), array("", "", "", ""), $url);
        $url = base64_decode(strtr($url, '-_', '+/'), true);
        if ($url) {
            $_REQUEST['url'] = $url;
        }
    } else {
        $direct_cache = false;
    }
    if (!$direct_cache) {
        $urlhash = 'pic:' . sha1($_REQUEST['url']);
        $cachefile = get_cachefile(hash("md5", $_REQUEST['url']));
        if ($cachefile != '') {
            if (file_exists($cachefile)) {
                $img_str = file_get_contents($cachefile);
                $mime = image_type_to_mime_type(exif_imagetype($cachefile));
                header("Content-type: {$mime}");
                header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
                header('Etag: "' . md5($img_str) . '"');
                header("Expires: " . gmdate("D, d M Y H:i:s", time() + 31536000) . " GMT");
                header("Cache-Control: max-age=31536000");
                // reduce quality - if it isn't a GIF
                if ($mime != "image/gif") {
                    $img = new Photo($img_str, $mime);
                    if ($img->is_valid()) {
                        $img_str = $img->imageString();
                    }
                }
                echo $img_str;
                killme();
            }
        }
    } else {
        $cachefile = "";
    }
    $valid = true;
    if (!$direct_cache and $cachefile == "") {
        $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' LIMIT 1", $urlhash);
        if (count($r)) {
            $img_str = $r[0]['data'];
            $mime = $r[0]["desc"];
            if ($mime == "") {
                $mime = "image/jpeg";
            }
        }
    } else {
        $r = array();
    }
    if (!count($r)) {
        // It shouldn't happen but it does - spaces in URL
        $_REQUEST['url'] = str_replace(" ", "+", $_REQUEST['url']);
        $redirects = 0;
        $img_str = fetch_url($_REQUEST['url'], true, $redirects, 10);
        $tempfile = tempnam(get_temppath(), "cache");
        file_put_contents($tempfile, $img_str);
        $mime = image_type_to_mime_type(exif_imagetype($tempfile));
        unlink($tempfile);
        // If there is an error then return a blank image
        if (substr($a->get_curl_code(), 0, 1) == "4" or !$img_str) {
            $img_str = file_get_contents("images/blank.png");
            $mime = "image/png";
            $cachefile = "";
            // Clear the cachefile so that the dummy isn't stored
            $valid = false;
            $img = new Photo($img_str, "image/png");
            if ($img->is_valid()) {
                $img->scaleImage(10);
                $img_str = $img->imageString();
            }
        } else {
            if ($mime != "image/jpeg" and !$direct_cache and $cachefile == "") {
                $image = @imagecreatefromstring($img_str);
                if ($image === FALSE) {
                    die;
                }
                q("INSERT INTO `photo`\n\t\t\t( `uid`, `contact-id`, `guid`, `resource-id`, `created`, `edited`, `filename`, `album`, `height`, `width`, `desc`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` )\n\t\t\tVALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', %d, %d, '%s', '%s', '%s', '%s' )", 0, 0, get_guid(), dbesc($urlhash), dbesc(datetime_convert()), dbesc(datetime_convert()), dbesc(basename(dbesc($_REQUEST["url"]))), dbesc(''), intval(imagesy($image)), intval(imagesx($image)), $mime, dbesc($img_str), 100, intval(0), dbesc(''), dbesc(''), dbesc(''), dbesc(''));
            } else {
                $img = new Photo($img_str, $mime);
                if ($img->is_valid()) {
                    if (!$direct_cache and $cachefile == "") {
                        $img->store(0, 0, $urlhash, $_REQUEST['url'], '', 100);
                    }
                }
            }
        }
    }
    // reduce quality - if it isn't a GIF
    if ($mime != "image/gif") {
        $img = new Photo($img_str, $mime);
        if ($img->is_valid()) {
            $img->scaleImage($size);
            $img_str = $img->imageString();
        }
    }
    // If there is a real existing directory then put the cache file there
    // advantage: real file access is really fast
    // Otherwise write in cachefile
    if ($valid and $direct_cache) {
        file_put_contents($_SERVER["DOCUMENT_ROOT"] . "/proxy/" . proxy_url($_REQUEST['url'], true), $img_str);
    } elseif ($cachefile != '') {
        file_put_contents($cachefile, $img_str);
    }
    header("Content-type: {$mime}");
    // Only output the cache headers when the file is valid
    if ($valid) {
        header("Last-Modified: " . gmdate("D, d M Y H:i:s", time()) . " GMT");
        header('Etag: "' . md5($img_str) . '"');
        header("Expires: " . gmdate("D, d M Y H:i:s", time() + 31536000) . " GMT");
        header("Cache-Control: max-age=31536000");
    }
    echo $img_str;
    killme();
}
コード例 #9
0
 /**
  * Detect filenames in upload parameters,
  * build multipart request from upload params
  *
  * @param string $method  The API method to call
  * @param array  $params  The parameters to send along
  *
  * @return void
  */
 protected function _buildMultipart($method, $params)
 {
     // well, files will only work in multipart methods
     if (!$this->_detectMultipart($method)) {
         return;
     }
     // only check specific parameters
     $possible_files = array('statuses/update' => 'media[]', 'statuses/update_with_media' => 'media[]', 'account/update_profile_background_image' => 'image', 'account/update_profile_image' => 'image', 'account/update_profile_banner' => 'banner');
     // method might have files?
     if (!in_array($method, array_keys($possible_files))) {
         return;
     }
     $possible_files = explode(' ', $possible_files[$method]);
     $multipart_border = '--------------------' . $this->_nonce();
     $multipart_request = '';
     foreach ($params as $key => $value) {
         // is it an array?
         if (is_array($value)) {
             throw new \Exception('Using URL-encoded parameters is not supported for uploading media.');
             continue;
         }
         // check for filenames
         if (in_array($key, $possible_files)) {
             if (@file_exists($value) && @is_readable($value) && ($data = @getimagesize($value))) {
                 if (in_array($data[2], $this->_supported_media_files)) {
                     // try to read the file
                     ob_start();
                     readfile($value);
                     $data = ob_get_contents();
                     ob_end_clean();
                     if (strlen($data) == 0) {
                         continue;
                     }
                     $value = $data;
                 }
             }
             // To-Do
             $tempfile = tempnam(get_temppath(), "mimecheck");
             file_put_contents($tempfile, $data);
             $mime = image_type_to_mime_type(exif_imagetype($tempfile));
             unlink($tempfile);
             $filename = "upload";
             $parametername = str_replace("[]", "", $key);
             $multipart_request .= "--" . $multipart_border . "\n";
             $multipart_request .= "Content-Disposition: form-data; name=\"{$parametername}\"; filename=\"{$filename}\"\n";
             $multipart_request .= "Content-Type: " . $mime . "\n";
             $multipart_request .= "Content-Transfer-Encoding: binary\n\n";
             $multipart_request .= $data . "\n";
         } else {
             $multipart_request .= '--' . $multipart_border . "\r\n" . 'Content-Disposition: form-data; name="' . $key . '"';
             $multipart_request .= "\r\n\r\n" . $value . "\r\n";
         }
     }
     $multipart_request .= '--' . $multipart_border . '--';
     return $multipart_request;
 }
コード例 #10
0
function retrieve_resource($resource)
{
    $a = get_app();
    logger('retrieve_resource: ' . ($resource['num-tries'] + 1) . ' attempt at resource ' . $resource['id'] . ' ' . $resource['url'], LOGGER_DEBUG);
    $redirects;
    $cookiejar = tempnam(get_temppath(), 'cookiejar-retriever-');
    $fetch_result = z_fetch_url($resource['url'], $resource['binary'], $redirects, array('cookiejar' => $cookiejar));
    unlink($cookiejar);
    $resource['data'] = $fetch_result['body'];
    $resource['http-code'] = $a->get_curl_code();
    $resource['type'] = $a->get_curl_content_type();
    $resource['redirect-url'] = $fetch_result['redirect_url'];
    logger('retrieve_resource: got code ' . $resource['http-code'] . ' retrieving resource ' . $resource['id'] . ' final url ' . $resource['redirect-url'], LOGGER_DEBUG);
    q("UPDATE `retriever_resource` SET `last-try` = now(), `num-tries` = `num-tries` + 1, `http-code` = %d, `redirect-url` = '%s' WHERE id = %d", intval($resource['http-code']), dbesc($resource['redirect-url']), intval($resource['id']));
    if ($resource['data']) {
        q("UPDATE `retriever_resource` SET `completed` = now(), `data` = '%s', `type` = '%s' WHERE id = %d", dbesc($resource['data']), dbesc($resource['type']), intval($resource['id']));
        retriever_resource_completed($resource);
    }
}