Ejemplo n.º 1
0
function txDownloadThumb()
{
    global $json, $C;
    $out = array('status' => JSON_FAILURE);
    $id = md5($_REQUEST['thumb']);
    $cachefile = SafeFilename("_{$_REQUEST['gallery_id']}_" . $id . ".jpg", FALSE);
    if (!is_file("{$GLOBALS['BASE_DIR']}/cache/{$cachefile}")) {
        $http = new Http();
        if ($http->Get($_REQUEST['thumb'], TRUE, $_REQUEST['gallery_url'])) {
            FileWrite("{$GLOBALS['BASE_DIR']}/cache/{$cachefile}", $http->body);
        }
    }
    $out['size'] = @getimagesize("{$GLOBALS['BASE_DIR']}/cache/{$cachefile}");
    if ($out['size'] !== FALSE) {
        $out['src'] = "{$C['install_url']}/cache/{$cachefile}";
        $out['status'] = JSON_SUCCESS;
    } else {
        unlink("{$GLOBALS['BASE_DIR']}/cache/{$cachefile}");
    }
    echo $json->encode($out);
}
Ejemplo n.º 2
0
function &ScanGallery(&$gallery, &$category, &$whitelisted, $all_images = FALSE)
{
    require_once "{$GLOBALS['BASE_DIR']}/includes/http.class.php";
    require_once "{$GLOBALS['BASE_DIR']}/includes/htmlparser.class.php";
    // Setup default values
    $results = array('thumbnails' => 0, 'links' => 0, 'format' => FMT_PICTURES, 'has_recip' => FALSE, 'has_2257' => FALSE, 'thumbs' => array(), 'server_match' => TRUE);
    // Download the gallery page
    $http = new Http();
    $http_result = $http->Get($gallery['gallery_url'], $whitelisted['allow_redirect']);
    // Record the request results
    $results = array_merge($results, $http->request_info);
    $results['page_hash'] = md5($http->body);
    $results['gallery_ip'] = GetIpFromUrl($http->end_url);
    $results['bytes'] = intval($results['size_download']);
    $results['html'] = $http->body;
    $results['headers'] = trim($http->raw_response_headers);
    $results['status'] = $http->response_headers['status'];
    $results['success'] = $http_result;
    $results['errstr'] = $http->errstr;
    $results['end_url'] = $http->end_url;
    if (!$http_result) {
        $http_result = null;
        return $results;
    }
    // Check if reciprocal link and 2257 code are present
    $results['has_recip'] = CheckReciprocal($http->body);
    $results['has_2257'] = Check2257($http->body);
    // Extract information from the gallery HTML
    $parser = new PageParser($http->end_url, $category['pics_extensions'], $category['movies_extensions']);
    $parser->parse($http->body);
    $results['links'] = $parser->num_links;
    if ($parser->num_content_links > 0) {
        if ($parser->num_picture_links > $parser->num_movie_links) {
            $results['format'] = FMT_PICTURES;
            $results['thumbnails'] = $parser->num_picture_links;
            $results['preview'] = $parser->thumbs['pictures'][array_rand($parser->thumbs['pictures'])]['full'];
            $results['thumbs'] = array_values($parser->thumbs['pictures']);
        } else {
            $results['format'] = FMT_MOVIES;
            $results['thumbnails'] = $parser->num_movie_links;
            $results['preview'] = $parser->thumbs['movies'][array_rand($parser->thumbs['movies'])]['full'];
            $results['thumbs'] = array_values($parser->thumbs['movies']);
        }
    } else {
        if ($all_images) {
            $results['thumbnails'] = count($parser->images);
            $results['preview'] = $parser->images[array_rand($parser->images)]['full'];
            $results['thumbs'] = array_values($parser->images);
        }
    }
    // Check that gallery content is hosted on same server as the gallery itself
    $parsed_gallery_url = parse_url($results['end_url']);
    $parsed_gallery_url['host'] = preg_quote(preg_replace('~^www\\.~', '', $parsed_gallery_url['host']));
    foreach ($results['thumbs'] as $thumb) {
        $parsed_content_url = parse_url($thumb['content']);
        if (!preg_match("~{$parsed_gallery_url['host']}~", $parsed_content_url['host'])) {
            $results['server_match'] = FALSE;
            break;
        }
    }
    $parser->Cleanup();
    unset($parser);
    $http->Cleanup();
    unset($http);
    return $results;
}
Ejemplo n.º 3
0
function tlxAccountAdd()
{
    global $C, $DB, $L, $IMAGE_EXTENSIONS, $t;
    unset($_REQUEST['banner_url_local']);
    // Get domain
    $parsed_url = parse_url($_REQUEST['site_url']);
    $_REQUEST['domain'] = preg_replace('~^www\\.~', '', $parsed_url['host']);
    $v = new Validator();
    // Get selected category (if any) and set variables
    if (isset($_REQUEST['category_id'])) {
        $category = $DB->Row('SELECT * FROM `tlx_categories` WHERE `category_id`=? AND `hidden`=0', array($_REQUEST['category_id']));
        if ($category) {
            $C['min_desc_length'] = $category['desc_min_length'];
            $C['max_desc_length'] = $category['desc_max_length'];
            $C['min_title_length'] = $category['title_min_length'];
            $C['max_title_length'] = $category['title_max_length'];
            $C['banner_max_width'] = $category['banner_max_width'];
            $C['banner_max_height'] = $category['banner_max_height'];
            $C['banner_max_bytes'] = $category['banner_max_bytes'];
            $C['allow_redirect'] = $category['allow_redirect'];
        } else {
            $v->SetError($L['INVALID_CATEGORY']);
        }
    }
    // See if username is taken
    if ($DB->Count('SELECT COUNT(*) FROM `tlx_accounts` WHERE `username`=?', array($_REQUEST['username'])) > 0) {
        $v->SetError($L['USERNAME_TAKEN']);
    }
    // Check for duplicate account information
    if ($DB->Count('SELECT COUNT(*) FROM `tlx_accounts` WHERE `site_url`=? OR `email`=? OR `domain`=?', array($_REQUEST['site_url'], $_REQUEST['email'], $_REQUEST['domain'])) > 0) {
        $v->SetError($L['EXISTING_ACCOUNT']);
    }
    $v->Register($_REQUEST['username'], V_LENGTH, $L['USERNAME_LENGTH'], '4,32');
    $v->Register($_REQUEST['username'], V_ALPHANUM, $L['INVALID_USERNAME']);
    $v->Register($_REQUEST['password'], V_LENGTH, $L['PASSWORD_LENGTH'], '4,9999');
    $v->Register($_REQUEST['email'], V_EMAIL, $L['INVALID_EMAIL']);
    $v->Register($_REQUEST['site_url'], V_URL, sprintf($L['INVALID_URL'], $L['SITE_URL']));
    $v->Register($_REQUEST['password'], V_NOT_EQUALS, $L['USERNAME_IS_PASSWORD'], $_REQUEST['username']);
    $v->Register($_REQUEST['password'], V_EQUALS, $L['PASSWORDS_DONT_MATCH'], $_REQUEST['confirm_password']);
    if (!IsEmptyString($_REQUEST['banner_url'])) {
        $v->Register($_REQUEST['banner_url'], V_URL, sprintf($L['INVALID_URL'], $L['BANNER_URL']));
    }
    // Format keywords and check number
    if ($C['allow_keywords']) {
        $_REQUEST['keywords'] = FormatSpaceSeparated($_REQUEST['keywords']);
        $keywords = explode(' ', $_REQUEST['keywords']);
        $v->Register(count($keywords), V_LESS_EQ, sprintf($L['MAXIMUM_KEYWORDS'], $C['max_keywords']), $C['max_keywords']);
    } else {
        $_REQUEST['keywords'] = null;
    }
    // Verify captcha code
    if ($C['account_add_captcha']) {
        VerifyCaptcha($v);
    }
    // Initial validation
    if (!$v->Validate()) {
        return $v->ValidationError('tlxShAccountAdd', TRUE);
    }
    // Check if the site URL is working
    $http = new Http();
    if ($http->Get($_REQUEST['site_url'], $C['allow_redirect'])) {
        $_REQUEST['html'] = $http->body;
        $_REQUEST['headers'] = $http->raw_response_headers;
    } else {
        $v->SetError(sprintf($L['BROKEN_URL'], $_REQUEST['site_url'], $http->errstr));
    }
    // Check the blacklist
    $blacklisted = CheckBlacklistAccount($_REQUEST);
    if ($blacklisted !== FALSE) {
        $v->SetError(sprintf($blacklisted[0]['reason'] ? $L['BLACKLISTED_REASON'] : $L['BLACKLISTED'], $blacklisted[0]['match'], $blacklisted[0]['reason']));
    }
    // Check site title and description length
    $v->Register($_REQUEST['title'], V_LENGTH, sprintf($L['TITLE_LENGTH'], $C['min_title_length'], $C['max_title_length']), "{$C['min_title_length']},{$C['max_title_length']}");
    $v->Register($_REQUEST['description'], V_LENGTH, sprintf($L['DESCRIPTION_LENGTH'], $C['min_desc_length'], $C['max_desc_length']), "{$C['min_desc_length']},{$C['max_desc_length']}");
    // Validation of user defined fields
    $fields =& GetUserAccountFields();
    foreach ($fields as $field) {
        if ($field['on_create']) {
            if ($field['required_create']) {
                $v->Register($_REQUEST[$field['name']], V_EMPTY, sprintf($L['REQUIRED_FIELD'], $field['label']));
            }
            if (!IsEmptyString($_REQUEST[$field['name']]) && $field['validation']) {
                $v->Register($_REQUEST[$field['name']], $field['validation'], $field['validation_message'], $field['validation_extras']);
            }
        }
    }
    // Download banner to check size
    $banner_file = null;
    if (!IsEmptyString($_REQUEST['banner_url']) && ($C['download_banners'] || $C['host_banners'])) {
        $http = new Http();
        if ($http->Get($_REQUEST['banner_url'], TRUE, $_REQUEST['site_url'])) {
            $banner_file = SafeFilename("{$C['banner_dir']}/{$_REQUEST['username']}.jpg", FALSE);
            FileWrite($banner_file, $http->body);
            $banner_info = @getimagesize($banner_file);
            if ($banner_info !== FALSE) {
                $_REQUEST['banner_width'] = $banner_info[0];
                $_REQUEST['banner_height'] = $banner_info[1];
                if (filesize($banner_file) > $C['banner_max_bytes']) {
                    $v->SetError(sprintf($L['BAD_BANNER_BYTES'], $C['banner_max_bytes']));
                }
                if ($C['host_banners']) {
                    if (isset($IMAGE_EXTENSIONS[$banner_info[2]])) {
                        $banner_ext = strtolower($IMAGE_EXTENSIONS[$banner_info[2]]);
                        if ($banner_ext != 'jpg') {
                            $new_file = preg_replace('~\\.jpg$~', ".{$banner_ext}", $banner_file);
                            rename($banner_file, $new_file);
                            $banner_file = $new_file;
                        }
                        $_REQUEST['banner_url_local'] = "{$C['banner_url']}/{$_REQUEST['username']}.{$banner_ext}";
                    } else {
                        $v->SetError($L['BAD_BANNER_IMAGE']);
                    }
                } else {
                    @unlink($banner_file);
                    $banner_file = null;
                }
            } else {
                $v->SetError($L['BAD_BANNER_IMAGE']);
            }
        } else {
            $v->SetError(sprintf($L['BROKEN_URL'], $_REQUEST['banner_url'], $http->errstr));
        }
    }
    // Check banner dimensions
    if ($_REQUEST['banner_width'] > $C['banner_max_width'] || $_REQUEST['banner_height'] > $C['banner_max_height']) {
        $v->SetError(sprintf($L['BAD_BANNER_SIZE'], $C['banner_max_width'], $C['banner_max_height']));
    }
    // Force banner dimensions
    if ($C['banner_force_size']) {
        $_REQUEST['banner_width'] = $C['banner_max_width'];
        $_REQUEST['banner_height'] = $C['banner_max_height'];
    }
    if (!$v->Validate()) {
        if (!empty($banner_file)) {
            @unlink($banner_file);
        }
        return $v->ValidationError('tlxShAccountAdd', TRUE);
    }
    $_REQUEST['status'] = STATUS_ACTIVE;
    $email_template = 'email-account-added.tpl';
    if ($C['confirm_accounts']) {
        $_REQUEST['status'] = STATUS_UNCONFIRMED;
        $email_template = 'email-account-confirm.tpl';
        $confirm_id = md5(uniqid(rand(), true));
        $t->assign('confirm_url', "{$C['install_url']}/accounts.php?r=confirm&id={$confirm_id}");
        $DB->Update('INSERT INTO `tlx_account_confirms` VALUES (?,?,?)', array($_REQUEST['username'], $confirm_id, MYSQL_NOW));
    } else {
        if ($C['review_new_accounts']) {
            $_REQUEST['status'] = STATUS_PENDING;
            $email_template = 'email-account-pending.tpl';
        }
    }
    // Add account information
    $DB->Update('INSERT INTO `tlx_accounts` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array($_REQUEST['username'], $_REQUEST['email'], $_REQUEST['site_url'], $_REQUEST['domain'], $_REQUEST['banner_url'], $_REQUEST['banner_url_local'], $_REQUEST['banner_height'], $_REQUEST['banner_width'], $_REQUEST['title'], $_REQUEST['description'], $_REQUEST['keywords'], MYSQL_NOW, $_REQUEST['status'] == STATUS_ACTIVE ? MYSQL_NOW : null, MYSQL_NOW, sha1($_REQUEST['password']), $C['return_percent'], $_REQUEST['status'], 0, 0, 0, $_REQUEST['category_id'], null, null, 0, 0, 0, null, null));
    // Create stats tracking data
    $stats_data = array_merge(array($_REQUEST['username']), array_fill(0, 127, 0));
    $DB->Update('INSERT INTO `tlx_account_hourly_stats` VALUES (' . CreateBindList($stats_data) . ')', $stats_data);
    // Insert user defined database fields
    $query_data = CreateUserInsert('tlx_account_fields', $_REQUEST);
    $DB->Update('INSERT INTO `tlx_account_fields` VALUES (' . $query_data['bind_list'] . ')', $query_data['binds']);
    // Assign template values
    $_REQUEST['category'] = $category['name'];
    $t->assign_by_ref('account', $_REQUEST);
    $t->assign_by_ref('user_fields', $fields);
    $t->assign('tracking_url', $C['tracking_mode'] == 'unique_link' ? "{$C['in_url']}?id={$_REQUEST['username']}" : $C['in_url']);
    // Send e-mail to account submitter
    if ($C['confirm_accounts'] || $C['email_new_accounts']) {
        SendMail($_REQUEST['email'], $email_template, $t);
    }
    // Send e-mail to administrators
    $administrators =& $DB->FetchAll('SELECT * FROM `tlx_administrators`');
    foreach ($administrators as $administrator) {
        if ($administrator['notifications'] & E_ACCOUNT_ADDED) {
            SendMail($administrator['email'], 'email-admin-account-added.tpl', $t);
        }
    }
    // Display confirmation page
    $t->display('accounts-added.tpl');
}
Ejemplo n.º 4
0
function HandlePreviewThumb(&$v, &$format, &$annotation)
{
    global $L, $C, $domain;
    list($width, $height) = explode('x', $format['preview_size']);
    $imagefile = "{$GLOBALS['BASE_DIR']}/cache/" . md5(uniqid(rand(), true)) . ".jpg";
    $i = GetImager();
    switch ($_REQUEST['preview']) {
        // Automatically crop and resize
        case 'automatic':
            $referrer_url = $_REQUEST['scan']['end_url'];
            $preview_url = $_REQUEST['scan']['preview'];
            if (!IsEmptyString($preview_url)) {
                $http = new Http();
                if ($http->Get($preview_url, TRUE, $referrer_url)) {
                    FileWrite($imagefile, $http->body);
                    $i->ResizeAuto($imagefile, $format['preview_size'], $annotation, $C['landscape_bias'], $C['portrait_bias']);
                } else {
                    $v->SetError(sprintf($L['PREVIEW_DOWNLOAD_FAILED'], $http->errstr));
                }
            } else {
                $v->SetError($L['NO_THUMBS_FOR_PREVIEW']);
            }
            break;
            // Handle uploaded image
        // Handle uploaded image
        case 'upload':
            if (is_uploaded_file($_FILES['upload']['tmp_name'])) {
                move_uploaded_file($_FILES['upload']['tmp_name'], $imagefile);
                @chmod($imagefile, 0666);
                $image = @getimagesize($imagefile);
                if ($image !== FALSE && $image[2] == IMAGETYPE_JPEG) {
                    // Image is properly sized
                    if ($image[0] == $width && $image[1] == $height) {
                        if ($C['have_imager']) {
                            $i->Annotate($imagefile, $annotation);
                        }
                    } else {
                        if ($C['have_imager'] && $C['handle_bad_size'] == 'crop') {
                            $i->ResizeAuto($imagefile, $format['preview_size'], $annotation, $C['landscape_bias'], $C['portrait_bias']);
                        } else {
                            @unlink($imagefile);
                            $v->SetError(sprintf($L['INVALID_IMAGE_SIZE'], $width, $height));
                        }
                    }
                } else {
                    @unlink($imagefile);
                    $v->SetError($L['INVALID_IMAGE']);
                }
            } else {
                $v->SetError($L['INVALID_UPLOAD']);
            }
            break;
            // Cropping an image
        // Cropping an image
        case 'crop':
            if (IsEmptyString($_REQUEST['scan']['preview'])) {
                $v->SetError($L['NO_THUMBS_FOR_PREVIEW']);
            }
            $imagefile = null;
            break;
            // Cropping or no image provided
        // Cropping or no image provided
        default:
            $imagefile = null;
            break;
    }
    return $imagefile;
}
Ejemplo n.º 5
0
 function SimpleRss($sUrl, $vCacheTime = 300, $iNumItems = -1, $sInputEncoding = '', $sOutputEncoding = 'UTF-8')
 {
     $this->oRssObject = new RssObject();
     // this object holds the returned data
     $this->iNumItems = $iNumItems;
     $this->sInputEncoding = $sInputEncoding;
     $this->sOutputEncoding = $sOutputEncoding;
     // make sure caching hasn't been disabled
     if ($vCacheTime) {
         $oCache = new PhpCache($sUrl . '_' . $this->iNumItems, $vCacheTime);
     }
     // is caching disabled or if not has the cache expired
     if (!$vCacheTime || !$oCache->Check()) {
         $oHttp = new Http();
         // request feed
         if ($sData = $oHttp->Get($sUrl)) {
             $this->bSuccessful = $this->Parse($sData);
             // do we want to cache result
             if ($vCacheTime) {
                 $oCache->Set($this->oRssObject);
             }
         }
     } else {
         // get data from cache
         $this->oRssObject = $oCache->Get();
         $this->bSuccessful = true;
         $this->bCached = true;
     }
     // check to see if request was successful, if not try and retrieve stale cache
     if (!$this->bSuccessful && $vCacheTime && $oCache->Exists()) {
         // make cache fresh
         $oCache->ReValidate();
         // get data from cache
         $this->oRssObject = $oCache->Get();
         $this->bSuccessful = true;
         $this->bCached = true;
         // mark as stale request
         $this->bStaleCache = true;
     }
 }
Ejemplo n.º 6
0
function txDownloadThumb()
{
    global $DB, $json, $C;
    $out = array('status' => JSON_FAILURE);
    $id = md5($_REQUEST['thumb']);
    $cachefile = SafeFilename("_{$_REQUEST['gallery_id']}_" . $id . ".jpg", FALSE);
    if (!is_file("{$GLOBALS['BASE_DIR']}/cache/{$cachefile}")) {
        $http = new Http();
        if ($http->Get($_REQUEST['thumb'], TRUE, $_REQUEST['gallery_url'])) {
            FileWrite("{$GLOBALS['BASE_DIR']}/cache/{$cachefile}", $http->body);
        }
    }
    $out['size'] = @getimagesize("{$GLOBALS['BASE_DIR']}/cache/{$cachefile}");
    if ($out['size'] !== FALSE) {
        if ($out['size'][0] >= $C['min_thumb_width'] && $out['size'][1] >= $C['min_thumb_height'] && $out['size'][0] <= $C['max_thumb_width'] && $out['size'][1] <= $C['max_thumb_height']) {
            $out['src'] = "{$C['install_url']}/cache/{$cachefile}";
            $out['status'] = JSON_SUCCESS;
            $out['id'] = $id;
        } else {
            $out['message'] = "Downloading " . htmlspecialchars($_REQUEST['thumb']) . " failed: image size of {$out['size'][0]}x{$out['size'][1]} is " . "not within the range of {$C['min_thumb_width']}x{$C['min_thumb_height']} to {$C['max_thumb_width']}x{$C['max_thumb_height']}";
        }
    } else {
        $out['message'] = "Downloading " . htmlspecialchars($_REQUEST['thumb']) . " failed: not a valid image file";
    }
    echo $json->encode($out);
}
Ejemplo n.º 7
0
}
while ($account = $DB->NextRow($result)) {
    $exception = 0x0;
    $current_account++;
    // Exit if stopped (pid set to 0)
    $pid = $DB->Count('SELECT `pid` FROM `tlx_scanner_configs` WHERE `config_id`=?', array($config_id));
    if ($pid == 0) {
        break;
    }
    // Update scanner status
    $DB->Update('UPDATE `tlx_scanner_configs` SET `current_status`=?,`status_updated`=? WHERE `config_id`=?', array("Scanning account {$current_account} of {$total_accounts}", time(), $config_id));
    // Update history
    $DB->Update('UPDATE `tlx_scanner_history` SET `scanned`=? WHERE `history_id`=?', array($current_account, $history_id));
    // Check if the site URL is working
    $http = new Http();
    if ($http->Get($account['site_url'], $C['allow_redirect'])) {
        $account['html'] = $http->body;
        $account['headers'] = $http->raw_response_headers;
    } else {
        // Bad status code
        if (!empty($http->response_headers['status'])) {
            if (preg_match('~^3\\d\\d~', $http->response_headers['status'])) {
                $exception = $exceptions['forward'];
            } else {
                $exception = $exceptions['broken'];
            }
        } else {
            $exception = $exceptions['connect'];
        }
    }
    $account['http'] =& $http;
Ejemplo n.º 8
0
 /**
  * 取接口数据
  *
  * @param string $this_api        	
  */
 protected function apiData($this_api)
 {
     // 解析接口路径
     $api = self::getApiInfo($this_api);
     debugLog(__METHOD__ . '|api|' . $this_api, $api);
     // 获取接口数据
     $source_data = Http::Get($api['host'], $api['script'], $api['port']);
     $source_data = empty($source_data) ? array() : json_decode($source_data, true);
     debugLog(__METHOD__ . '|source data', $source_data);
     return $source_data;
 }
Ejemplo n.º 9
0
 function TestUrl($url, $redirection)
 {
     if (!class_exists('http')) {
         require_once "{$GLOBALS['BASE_DIR']}/includes/http.class.php";
     }
     $http = new Http();
     $result = $http->Get($url, $redirection);
     return array($result, $http->errstr);
 }
Ejemplo n.º 10
0
                         } else {
                             @unlink($imagefile);
                         }
                     }
                 }
             }
         }
     }
 }
 // Download thumbnail(s) from remote server
 if ($configuration['process_downloadpreview']) {
     foreach ($previews as $preview) {
         if (!preg_match('~^' . $C['preview_url'] . '~', $preview['preview_url'])) {
             $http = new Http();
             // Download the image
             if ($http->Get($preview['preview_url'], TRUE, $gallery['gallery_url'])) {
                 $imagefile = "{$GLOBALS['BASE_DIR']}/cache/" . md5(uniqid(rand(), true)) . ".jpg";
                 FileWrite($imagefile, $http->body);
                 $imagesize = @getimagesize($imagefile);
                 if ($imagesize !== FALSE && ($imagesize[2] = IMAGETYPE_JPEG)) {
                     $width = $imagesize[0];
                     $height = $imagesize[1];
                     $resized = FALSE;
                     // Resize thumb to specific size
                     if ($configuration['process_downloadresize'] && ($width != $preview_width || $height != $preview_height)) {
                         $imager->ResizeAuto($imagefile, $preview_width . 'x' . $preview_height, $annotation, $C['landscape_bias'], $C['portrait_bias']);
                         $width = $preview_width;
                         $height = $preview_height;
                         $resized = TRUE;
                     }
                     // Annotate the image
Ejemplo n.º 11
0
function ImportFromRss($feed)
{
    global $DB, $C;
    $settings = unserialize($feed['settings']);
    $category = $DB->Row('SELECT * FROM `tx_categories` WHERE `category_id`=?', array($settings['category']));
    $columns = $DB->GetColumns('tx_gallery_fields');
    $imported = 0;
    $defaults = array('gallery_url' => null, 'description' => null, 'keywords' => null, 'thumbnails' => 0, 'email' => $C['from_email'], 'nickname' => null, 'weight' => $C['gallery_weight'], 'clicks' => 0, 'submit_ip' => GetIpFromUrl($feed['feed_url']), 'gallery_ip' => '', 'sponsor_id' => !empty($feed['sponsor_id']) ? $feed['sponsor_id'] : null, 'type' => $settings['type'], 'format' => $settings['format'], 'status' => $settings['status'], 'previous_status' => null, 'date_scanned' => null, 'date_added' => MYSQL_NOW, 'date_approved' => null, 'date_scheduled' => null, 'date_displayed' => null, 'date_deletion' => null, 'partner' => null, 'administrator' => $_SERVER['REMOTE_USER'], 'admin_comments' => null, 'page_hash' => null, 'has_recip' => 0, 'has_preview' => 0, 'allow_scan' => 1, 'allow_preview' => 1, 'times_selected' => 0, 'used_counter' => 0, 'build_counter' => 0, 'tags' => null, 'categories' => MIXED_CATEGORY . " " . $category['tag'], 'preview_url' => null, 'dimensions' => null);
    require_once "{$GLOBALS['BASE_DIR']}/includes/rssparser.class.php";
    $http = new Http();
    if ($http->Get($feed['feed_url'], TRUE, $C['install_url'])) {
        $parser = new RSSParser();
        if (($rss = $parser->Parse($http->body)) !== FALSE) {
            foreach ($rss['items'] as $item) {
                $gallery = array();
                $gallery['gallery_url'] = html_entity_decode($item[$settings['gallery_url_from']]);
                $gallery['description'] = html_entity_decode($item[$settings['description_from']]);
                if (!empty($settings['date_added_from'])) {
                    if (($timestamp = strtotime($item[$settings['date_added_from']])) !== FALSE) {
                        $gallery['date_added'] = date(DF_DATETIME, $timestamp);
                    }
                }
                if (!empty($settings['preview_from'])) {
                    if (!is_array($item[$settings['preview_from']])) {
                        $item[$settings['preview_from']] = array($item[$settings['preview_from']]);
                    }
                    foreach ($item[$settings['preview_from']] as $item_value) {
                        if (preg_match('~(http://[^>< ]+\\.(jpg|png))~i', $item_value, $matches)) {
                            $gallery['preview_url'] = $matches[1];
                            break;
                        }
                    }
                }
                // Remove HTML tags and trim the description
                $gallery['description'] = trim(strip_tags($gallery['description']));
                // Merge with the defaults
                $gallery = array_merge($defaults, $gallery);
                // Skip over duplicate or empty URLs
                if ($DB->Count('SELECT COUNT(*) FROM `tx_galleries` WHERE `gallery_url`=?', array($gallery['gallery_url'])) || IsEmptyString($gallery['gallery_url'])) {
                    continue;
                }
                $imported++;
                // Has a preview thumbnail
                if (!empty($gallery['preview_url'])) {
                    $gallery['has_preview'] = 1;
                }
                // Add regular fields
                $DB->Update('INSERT INTO `tx_galleries` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array(null, $gallery['gallery_url'], $gallery['description'], $gallery['keywords'], $gallery['thumbnails'], $gallery['email'], $gallery['nickname'], $gallery['weight'], $gallery['clicks'], $gallery['submit_ip'], $gallery['gallery_ip'], $gallery['sponsor_id'], $gallery['type'], $gallery['format'], $gallery['status'], $gallery['previous_status'], $gallery['date_scanned'], $gallery['date_added'], $gallery['date_approved'], $gallery['date_scheduled'], $gallery['date_displayed'], $gallery['date_deletion'], $gallery['partner'], $gallery['administrator'], $gallery['admin_comments'], $gallery['page_hash'], $gallery['has_recip'], $gallery['has_preview'], $gallery['allow_scan'], $gallery['allow_preview'], $gallery['times_selected'], $gallery['used_counter'], $gallery['build_counter'], $gallery['tags'], $gallery['categories']));
                $gallery['gallery_id'] = $DB->InsertID();
                // Add user defined fields
                $query_data = CreateUserInsert('tx_gallery_fields', $gallery, $columns);
                $DB->Update('INSERT INTO `tx_gallery_fields` VALUES (' . $query_data['bind_list'] . ')', $query_data['binds']);
                // Has a preview thumbnail
                if (!empty($gallery['preview_url'])) {
                    $DB->Update('INSERT INTO `tx_gallery_previews` VALUES (?,?,?,?)', array(null, $gallery['gallery_id'], $gallery['preview_url'], $gallery['dimensions']));
                }
            }
        }
        $DB->Update('UPDATE `tx_rss_feeds` SET `date_last_import`=? WHERE `feed_id`=?', array(MYSQL_NOW, $feed['feed_id']));
    } else {
        return "Could not access the RSS feed: " . $http->errstr;
    }
    return $imported;
}
Ejemplo n.º 12
0
 /**
  * 发站内消息接口
  * @param string $toid
  * @param string $content
  * @param string $from
  */
 public static function sysMsg($toid, $content, $from = false)
 {
     if (!$toid) {
         return null;
     }
     if (!$from) {
         $from = 'cs';
     }
     $key = md5('msg_no_ip_ban');
     $page = "api/sendsys.php?from={$from}&to={$toid}&content=" . urlencode("{$content}") . ($key ? '&key=' . $key : '');
     $return = Http::Get('msg.56.com', $page);
     return $return;
 }
Ejemplo n.º 13
0
function &ScanLink(&$link)
{
    global $DB, $C, $L;
    $result = array('has_recip' => 0, 'site_url' => array(), 'recip_url' => null);
    if (!class_exists('http')) {
        require_once "{$GLOBALS['BASE_DIR']}/includes/http.class.php";
    }
    $http = new Http();
    // Check site URL
    $result['site_url']['working'] = $http->Get($link['site_url'], $link['allow_redirect']);
    $result['site_url']['error'] = $http->errstr;
    $result['site_url']['status'] = $http->response_headers['status'];
    $result['site_url']['ip_address'] = IPFromUrl($link['site_url']);
    $result['site_url']['html'] = $http->body;
    $result['site_url']['has_recip'] = HasReciprocal($http->body);
    // Check recip URL, if provided
    if ($link['recip_url']) {
        $http = new Http();
        $result['recip_url'] = array();
        $result['recip_url']['working'] = $http->Get($link['recip_url'], $link['allow_redirect']);
        $result['recip_url']['error'] = $http->errstr;
        $result['recip_url']['status'] = $http->response_headers['status'];
        $result['recip_url']['ip_address'] = IPFromUrl($link['recip_url']);
        $result['recip_url']['html'] = $http->body;
        $result['recip_url']['has_recip'] = HasReciprocal($http->body);
    }
    $result['has_recip'] = $result['site_url']['has_recip'] || $result['recip_url']['has_recip'];
    return $result;
}
Ejemplo n.º 14
0
 /**
 * @name GetProfile
 * @author zhys9
 * @desc ȡû
 * @param string $user_id
 * @param bool $big_photo
 * @param int $short 0|1  1ֻҪϢ0ȫϢ
 * @return array
 *
 * @ijֶ֧û
 * @modify Melon`` 2010
 	   一个或者多个用户名取得用户信息,请求一次用户接口
 */
 public static function GetProfile2011($user_id, $big_photo = true, $short = 0)
 {
     $root_uri = self::API_ROOT . '?short=' . $short . '&charset=' . self::$charset . '&user_id=';
     $uri = $root_uri . $user_id;
     //if(DEBUG) _debug("CallUserApi: $uri");
     //send request
     $rs = Http::Get(self::API_HOST, $uri, self::API_PORT);
     if ($rs) {
         $info = array();
         if (strpos($user_id, ',') == TRUE) {
             $rs = unserialize($rs);
             if (is_array($rs)) {
                 foreach ($rs as $k => &$v) {
                     $v['nickname'] = $v['LastName'] ? $v['LastName'] : $v['Account'];
                     unset($rs[$k]['LastName']);
                     $v['photo'] = self::GetPhotoUrl($v['Account'], $big_photo, $v['head']);
                 }
             }
             $info = $rs;
         } else {
             @parse_str($rs, $info);
             $nickname = $info['LastName'];
             unset($info['LastName']);
             $info['nickname'] = $nickname ? $nickname : $info['Account'];
             $info['photo'] = self::GetPhotoUrl($user_id, $big_photo, $info['head']);
         }
         return $info;
     } else {
         return array();
     }
 }
Ejemplo n.º 15
0
function txCropWithBias()
{
    global $DB, $C;
    require_once "{$GLOBALS['BASE_DIR']}/includes/imager.class.php";
    $gallery = $DB->Row('SELECT * FROM `tx_galleries` WHERE `gallery_id`=?', array($_REQUEST['gallery_id']));
    $categories =& CategoriesFromTags($gallery['categories']);
    $format = GetCategoryFormat($gallery['format'], $categories[0]);
    $annotation =& LoadAnnotation($format['annotation'], $categories[0]['name']);
    $tempfile = md5(uniqid(rand(), true)) . ".jpg";
    $http = new Http();
    if ($http->Get($_REQUEST['imagefile'], TRUE, $gallery['gallery_url'])) {
        FileWrite("{$GLOBALS['BASE_DIR']}/cache/{$tempfile}", $http->body);
        $i = GetImager();
        $i->ResizeAuto("{$GLOBALS['BASE_DIR']}/cache/{$tempfile}", $_REQUEST['dimensions'], $annotation, $_REQUEST['bias_land'], $_REQUEST['bias_port']);
        $preview = AddPreview($gallery['gallery_id'], $_REQUEST['dimensions'], "{$GLOBALS['BASE_DIR']}/cache/{$tempfile}");
        UpdateThumbSizes($_REQUEST['dimensions']);
        include_once 'includes/crop-complete.php';
    } else {
        $error = 'Could not download image file: ' . $http->errstr;
        include_once 'includes/error.php';
    }
}
Ejemplo n.º 16
0
function tlxAccountEdit()
{
    global $DB, $C, $IMAGE_EXTENSIONS;
    VerifyPrivileges(P_ACCOUNT_MODIFY);
    $_REQUEST['return_percent'] /= 100;
    // Get domain
    $parsed_url = parse_url($_REQUEST['site_url']);
    $_REQUEST['domain'] = preg_replace('~^www\\.~', '', $parsed_url['host']);
    $v = new Validator();
    $v->Register($_REQUEST['email'], V_EMAIL, 'The E-mail Address is not properly formatted');
    $v->Register($_REQUEST['site_url'], V_URL, 'The Site URL is not properly formatted');
    $v->Register($_REQUEST['date_added'], V_DATETIME, 'The Date Added value is not properly formatted');
    if (!IsEmptyString($_REQUEST['password'])) {
        $v->Register($_REQUEST['password'], V_LENGTH, 'The account password must be at least 4 characters', '4,9999');
    }
    if (!IsEmptyString($_REQUEST['banner_url'])) {
        $v->Register($_REQUEST['banner_url'], V_URL, sprintf($L['INVALID_URL'], $L['BANNER_URL']));
    }
    if (!$v->Validate()) {
        return $v->ValidationError('tlxShAccountEdit');
    }
    // Setup account password, if changed
    $account = $DB->Row('SELECT * FROM `tlx_accounts` WHERE `username`=?', array($_REQUEST['username']));
    $_REQUEST['password'] = IsEmptyString($_REQUEST['password']) ? $account['password'] : sha1($_REQUEST['password']);
    // Handling of banner_url_local
    if ($_REQUEST['download_banner']) {
        $http = new Http();
        if ($http->Get($_REQUEST['banner_url'], TRUE, $_REQUEST['site_url'])) {
            $banner_file = SafeFilename("{$C['banner_dir']}/{$_REQUEST['username']}.jpg", FALSE);
            FileWrite($banner_file, $http->body);
            $banner_info = @getimagesize($banner_file);
            if ($banner_info !== FALSE) {
                $_REQUEST['banner_width'] = $banner_info[0];
                $_REQUEST['banner_height'] = $banner_info[1];
                $banner_ext = strtolower($IMAGE_EXTENSIONS[$banner_info[2]]);
                if ($banner_ext != 'jpg') {
                    $new_file = preg_replace('~\\.jpg$~', ".{$banner_ext}", $banner_file);
                    rename($banner_file, $new_file);
                    $banner_file = $new_file;
                }
                $_REQUEST['banner_url_local'] = "{$C['banner_url']}/{$_REQUEST['username']}.{$banner_ext}";
            } else {
                @unlink($banner_file);
                $banner_file = null;
            }
        }
    } else {
        $_REQUEST['banner_url_local'] = $account['banner_url_local'];
    }
    if ($account['status'] != STATUS_ACTIVE && $_REQUEST['status'] == STATUS_ACTIVE) {
        $account['date_activated'] = MYSQL_NOW;
    }
    // Update account data
    $DB->Update('UPDATE `tlx_accounts` SET ' . '`email`=?, ' . '`site_url`=?, ' . '`domain`=?, ' . '`banner_url`=?, ' . '`banner_url_local`=?, ' . '`banner_height`=?, ' . '`banner_width`=?, ' . '`title`=?, ' . '`description`=?, ' . '`keywords`=?, ' . '`date_added`=?, ' . '`date_activated`=?, ' . '`password`=?, ' . '`return_percent`=?, ' . '`status`=?, ' . '`locked`=?, ' . '`disabled`=?, ' . '`category_id`=?, ' . '`ratings`=?, ' . '`ratings_total`=?, ' . '`admin_comments`=? ' . 'WHERE `username`=?', array($_REQUEST['email'], $_REQUEST['site_url'], $_REQUEST['domain'], $_REQUEST['banner_url'], $_REQUEST['banner_url_local'], $_REQUEST['banner_height'], $_REQUEST['banner_width'], $_REQUEST['title'], $_REQUEST['description'], $_REQUEST['keywords'], $_REQUEST['date_added'], $account['date_activated'], $_REQUEST['password'], $_REQUEST['return_percent'], $_REQUEST['status'], intval($_REQUEST['locked']), intval($_REQUEST['disabled']), $_REQUEST['category_id'], intval($_REQUEST['ratings']), intval($_REQUEST['ratings_total']), $_REQUEST['admin_comments'], $_REQUEST['username']));
    // Update stats
    $stats = array();
    $totals = array('raw_in_total' => 0, 'unique_in_total' => 0, 'raw_out_total' => 0, 'unique_out_total' => 0, 'clicks_total' => 0);
    foreach (range(0, 23) as $hour) {
        $stats[] = "`raw_in_{$hour}`=" . intval($_REQUEST["raw_in_{$hour}"]);
        $stats[] = "`unique_in_{$hour}`=" . intval($_REQUEST["unique_in_{$hour}"]);
        $stats[] = "`raw_out_{$hour}`=" . intval($_REQUEST["raw_out_{$hour}"]);
        $stats[] = "`unique_out_{$hour}`=" . intval($_REQUEST["unique_out_{$hour}"]);
        $stats[] = "`clicks_{$hour}`=" . intval($_REQUEST["clicks_{$hour}"]);
        $totals['raw_in_total'] += $_REQUEST["raw_in_{$hour}"];
        $totals['unique_in_total'] += $_REQUEST["unique_in_{$hour}"];
        $totals['raw_out_total'] += $_REQUEST["raw_out_{$hour}"];
        $totals['unique_out_total'] += $_REQUEST["unique_out_{$hour}"];
        $totals['clicks_total'] += $_REQUEST["clicks_{$hour}"];
    }
    $DB->Update('UPDATE `tlx_account_hourly_stats` SET ' . join(', ', $stats) . ', ' . '`raw_in_total`=?, ' . '`unique_in_total`=?, ' . '`raw_out_total`=?, ' . '`unique_out_total`=?, ' . '`clicks_total`=? ' . ' WHERE `username`=?', array($totals['raw_in_total'], $totals['unique_in_total'], $totals['raw_out_total'], $totals['unique_out_total'], $totals['clicks_total'], $_REQUEST['username']));
    // Update user defined fields
    UserDefinedUpdate('tlx_account_fields', 'tlx_account_field_defs', 'username', $_REQUEST['username'], $_REQUEST);
    // Update icons
    $DB->Update('DELETE FROM `tlx_account_icons` WHERE `username`=?', array($_REQUEST['username']));
    if (is_array($_REQUEST['icons'])) {
        foreach ($_REQUEST['icons'] as $icon_id) {
            $DB->Update('INSERT INTO `tlx_account_icons` VALUES (?,?)', array($_REQUEST['username'], $icon_id));
        }
    }
    $GLOBALS['message'] = 'Account successfully updated';
    $GLOBALS['added'] = true;
    tlxShAccountEdit();
}