示例#1
0
/**
 * Compresses a file (creates a gzipped file)
 *
 * @param string $srcName the source file
 * @param string $dstName the destination file name (the compressed one)
 *
 * @return bool returns true on success, false else
 **/
function gzip_compress_file($srcName, $dstName)
{
    $success = false;
    $data = getFileContents($srcName);
    if ($data != "") {
        $success = gzip_writeToFile($dstName, $data);
    }
    return $success;
}
示例#2
0
文件: import.php 项目: eou/Magic
function importTangram($files, $returnFile = true)
{
    global $MATCHED, $DEBUG, $IMPORTED;
    $output = "";
    if (is_string($files)) {
        $files = array($files);
    } else {
        if (!is_array($files)) {
            return $output;
        }
    }
    if ($DEBUG) {
        var_dump($files);
    }
    foreach ($files as $file) {
        if (strrpos($file, '*')) {
            $output .= importTangram(getPackage(str_replace(array(".", '*'), array('/', ''), $file)));
        } elseif (in_array($file, $IMPORTED)) {
            continue;
        } else {
            $IMPORTED[] = $file;
            $file = str_replace(".", '/', $file) . ".js";
            if ($DEBUG) {
                echo "Importing: " . $file . ", returnFile {$returnFile}\n";
            }
            if (!in_array($file, $MATCHED)) {
                $content = getFileContents($file);
                if (!$content) {
                    if ($DEBUG) {
                        echo "no content... \n;";
                    }
                    continue;
                }
                $MATCHED[] = $file;
                $matches = array();
                //去掉注释
                $content = trim(preg_replace("/\\/\\*(.*?)\\*\\//ies", "", $content)) . "\n";
                $output .= preg_replace("/\\/\\/\\/import\\s+([\\w\\-\$]+(\\.[\\w\\-\$]+)*);?/ies", "importTangram('\\1')", $content);
            }
        }
    }
    return $output;
}
function getAvailableFiles($sModule, $sFolder = "langs")
{
    global $sIncPath;
    global $sModulesUrl;
    //--- Get info which was set by admin in the Ray Base ---//
    $aFileContents = getFileContents($sModule, "/xml/" . $sFolder . ".xml", true);
    $aFiles = $aFileContents['contents'];
    //--- Get info from file system ---//
    $aRealFiles = getExtraFiles($sModule, $sFolder, false, true);
    //--- Merge info from these arrays ---//
    $aResult = array();
    foreach ($aFiles as $sFile => $bEnabled) {
        if ($bEnabled == TRUE_VAL && ($sKey = array_search($sFile, $aRealFiles['files'])) !== false) {
            $aResult['files'][] = $sFile;
            $aResult['dates'][] = $aRealFiles['dates'][$sKey];
        }
    }
    $aResult['default'] = $aFiles['_default_'];
    return $aResult;
}
示例#4
0
/**
 * Deploys commits to the file-system
 */
function deployChangeSet($postData)
{
    global $CONFIG, $DEPLOY, $DEPLOY_BRANCH;
    global $processed;
    global $rmdirs;
    $o = json_decode($postData);
    if (!$o) {
        // could not parse ?
        echo "    ! Invalid JSON file\n";
        return false;
    }
    // determine the destination of the deployment
    if (array_key_exists($o->repository->slug, $DEPLOY)) {
        $deployLocation = $DEPLOY[$o->repository->slug] . (substr($DEPLOY[$o->repository->slug], -1) == DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR);
    } else {
        // unknown repository ?
        echo "    ! Repository not configured for sync: {$o->repository->slug}\n";
        return false;
    }
    // determine from which branch to get the data
    if (isset($DEPLOY_BRANCH) && array_key_exists($o->repository->slug, $DEPLOY_BRANCH)) {
        $deployBranch = $DEPLOY_BRANCH[$o->repository->slug];
    } else {
        // use the default branch
        $deployBranch = $CONFIG['deployBranch'];
    }
    // build URL to get the updated files
    $baseUrl = $o->canon_url;
    # https://bitbucket.org
    $apiUrl = '/api/1.0/repositories';
    # /api/1.0/repositories
    $repoUrl = $o->repository->absolute_url;
    # /user/repo/
    $rawUrl = 'raw/';
    # raw/
    $branchUrl = $deployBranch . '/';
    # branch/
    // prepare to get the files
    $pending = array();
    // loop through commits
    foreach ($o->commits as $commit) {
        // check if the branch is known at this step
        loginfo("    > Change-set: " . trim($commit->message) . "\n");
        if (!empty($commit->branch) || !empty($commit->branches)) {
            // if commit was on the branch we're watching, deploy changes
            if ($commit->branch == $deployBranch || !empty($commit->branches) && array_search($deployBranch, $commit->branches) !== false) {
                // if there are any pending files, merge them in
                $files = array_merge($pending, $commit->files);
                // get a list of files
                foreach ($files as $file) {
                    if ($file->type == 'modified' || $file->type == 'added') {
                        if (empty($processed[$file->file])) {
                            $processed[$file->file] = 1;
                            // mark as processed
                            $contents = getFileContents($baseUrl . $apiUrl . $repoUrl . $rawUrl . $branchUrl . $file->file);
                            if ($contents == 'Not Found') {
                                // try one more time, BitBucket gets weirdo sometimes
                                $contents = getFileContents($baseUrl . $apiUrl . $repoUrl . $rawUrl . $branchUrl . $file->file);
                            }
                            if ($contents != 'Not Found' && $contents !== false) {
                                if (!is_dir(dirname($deployLocation . $file->file))) {
                                    // attempt to create the directory structure first
                                    mkdir(dirname($deployLocation . $file->file), 0755, true);
                                }
                                file_put_contents($deployLocation . $file->file, $contents);
                                loginfo("      - Synchronized {$file->file}\n");
                            } else {
                                echo "      ! Could not get file contents for {$file->file}\n";
                                flush();
                            }
                        }
                    } else {
                        if ($file->type == 'removed') {
                            unlink($deployLocation . $file->file);
                            $processed[$file->file] = 0;
                            // to allow for subsequent re-creating of this file
                            $rmdirs[dirname($deployLocation . $file->file)] = dirname($file->file);
                            loginfo("      - Removed {$file->file}\n");
                        }
                    }
                }
            }
            // clean pending files, if any
            $pending = array();
        } else {
            // unknown branch for now, keep these files
            $pending = array_merge($pending, $commit->files);
        }
    }
    return true;
}
示例#5
0
/**
 * This function takes a (set of) temporary file(s) of a submission,
 * validates it and puts it into the database. Additionally it
 * moves it to a backup storage.
 */
function submit_solution($team, $prob, $contest, $lang, $files, $filenames, $origsubmitid = NULL)
{
    global $DB;
    if (empty($team)) {
        error("No value for Team.");
    }
    if (empty($prob)) {
        error("No value for Problem.");
    }
    if (empty($contest)) {
        error("No value for Contest.");
    }
    if (empty($lang)) {
        error("No value for Language.");
    }
    if (!is_array($files) || count($files) == 0) {
        error("No files specified.");
    }
    if (count($files) > dbconfig_get('sourcefiles_limit', 100)) {
        error("Tried to submit more than the allowed number of source files.");
    }
    if (!is_array($filenames) || count($filenames) != count($files)) {
        error("Nonmatching (number of) filenames specified.");
    }
    if (count($filenames) != count(array_unique($filenames))) {
        error("Duplicate filenames detected.");
    }
    $sourcesize = dbconfig_get('sourcesize_limit');
    // If no contest has started yet, refuse submissions.
    $now = now();
    $contestdata = $DB->q('MAYBETUPLE SELECT starttime,endtime FROM contest WHERE cid = %i', $contest);
    if (!isset($contestdata)) {
        error("Contest c{$contest} not found.");
    }
    if (difftime($contestdata['starttime'], $now) > 0) {
        error("The contest is closed, no submissions accepted. [c{$contest}]");
    }
    // Check 2: valid parameters?
    if (!($langid = $DB->q('MAYBEVALUE SELECT langid FROM language
	                        WHERE langid = %s AND allow_submit = 1', $lang))) {
        error("Language '{$lang}' not found in database or not submittable.");
    }
    if (!($teamid = $DB->q('MAYBEVALUE SELECT teamid FROM team
	                        WHERE teamid = %i AND enabled = 1', $team))) {
        error("Team '{$team}' not found in database or not enabled.");
    }
    $probdata = $DB->q('MAYBETUPLE SELECT probid, points FROM problem
	                    INNER JOIN contestproblem USING (probid)
	                    WHERE probid = %s AND cid = %i AND allow_submit = 1', $prob, $contest);
    if (empty($probdata)) {
        error("Problem p{$prob} not found in database or not submittable [c{$contest}].");
    } else {
        $points = $probdata['points'];
        $probid = $probdata['probid'];
    }
    // Reindex arrays numerically to allow simultaneously iterating
    // over both $files and $filenames.
    $files = array_values($files);
    $filenames = array_values($filenames);
    $totalsize = 0;
    for ($i = 0; $i < count($files); $i++) {
        if (!is_readable($files[$i])) {
            error("File '" . $files[$i] . "' not found (or not readable).");
        }
        if (!preg_match(FILENAME_REGEX, $filenames[$i])) {
            error("Illegal filename '" . $filenames[$i] . "'.");
        }
        $totalsize += filesize($files[$i]);
    }
    if ($totalsize > $sourcesize * 1024) {
        error("Submission file(s) are larger than {$sourcesize} kB.");
    }
    logmsg(LOG_INFO, "input verified");
    // Insert submission into the database
    $id = $DB->q('RETURNID INSERT INTO submission
	              (cid, teamid, probid, langid, submittime, origsubmitid)
	              VALUES (%i, %i, %i, %s, %s, %i)', $contest, $teamid, $probid, $langid, $now, $origsubmitid);
    for ($rank = 0; $rank < count($files); $rank++) {
        $DB->q('INSERT INTO submission_file
		        (submitid, filename, rank, sourcecode) VALUES (%i, %s, %i, %s)', $id, $filenames[$rank], $rank, getFileContents($files[$rank], false));
    }
    // Recalculate scoreboard cache for pending submissions
    calcScoreRow($contest, $teamid, $probid);
    // Log to event table
    $DB->q('INSERT INTO event (eventtime, cid, teamid, langid, probid, submitid, description)
	        VALUES(%s, %i, %i, %s, %i, %i, "problem submitted")', now(), $contest, $teamid, $langid, $probid, $id);
    if (is_writable(SUBMITDIR)) {
        // Copy the submission to SUBMITDIR for safe-keeping
        for ($rank = 0; $rank < count($files); $rank++) {
            $fdata = array('cid' => $contest, 'submitid' => $id, 'teamid' => $teamid, 'probid' => $probid, 'langid' => $langid, 'rank' => $rank, 'filename' => $filenames[$rank]);
            $tofile = SUBMITDIR . '/' . getSourceFilename($fdata);
            if (!@copy($files[$rank], $tofile)) {
                warning("Could not copy '" . $files[$rank] . "' to '" . $tofile . "'");
            }
        }
    } else {
        logmsg(LOG_DEBUG, "SUBMITDIR not writable, skipping");
    }
    if (difftime($contestdata['endtime'], $now) <= 0) {
        logmsg(LOG_INFO, "The contest is closed, submission stored but not processed. [c{$contest}]");
    }
    return $id;
}
示例#6
0
             $aContents[] = parseXml($aXmlTemplates['widget'], $sInner, $sVersion, $sTitle, $sAuthor, $sAuthorUrl, $sImageUrl, $sStatus, $sAdminUrl);
             $aTitles[] = $sTitle;
             array_multisort($aTitles, $aContents);
             $sContent = implode("", $aContents);
         }
     }
     $sContents = makeGroup($sContent, "widgets");
     break;
     /**
      * Gets widget code.
      */
 /**
  * Gets widget code.
  */
 case 'getWidgetCode':
     $aResult = getFileContents($sWidget, "/xml/main.xml", true);
     if ($aResult['status'] == SUCCESS_VAL) {
         $aContents = $aResult['contents'];
         $sCode = $aContents['code'];
         if (empty($sCode)) {
             if (secureCheckWidgetName($sWidget)) {
                 require_once $sModulesPath . $sWidget . "/inc/constants.inc.php";
                 $sCode = $aInfo['code'];
             }
         }
         $sContents = parseXml($aXmlTemplates['result'], SUCCESS_VAL, $sCode, $aContents['license']);
     } else {
         $sContents = parseXml($aXmlTemplates['result'], $aResult['value'], FAILED_VAL);
     }
     break;
     /**
function index_site($url, $reindex, $maxlevel, $soption, $url_inc, $url_not_inc, $can_leave, $use_robot, $use_nofollow, $cl, $all, $use_pref)
{
    global $db_con, $mysql_table_prefix, $command_line, $mainurl, $tmp_urls, $domain_arr, $all_keywords, $smp, $follow_sitemap;
    global $link_check, $smap_dir, $index_media, $clear, $create_sitemap, $tmp_dir, $domaincb;
    global $max_links, $realnum, $debug, $no_log, $dba_act, $add_auth, $interrupt, $index_media, $thumb_folder;
    if (!$can_leave) {
        $can_leave = $domaincb;
    }
    $can_leave_domain = $can_leave;
    $starttime = getmicrotime();
    //  start time to index this site
    $black = '0';
    //  will become counter for hits of blacklist
    $site_id = '';
    $skip = '';
    $smp = '0';
    $omit = array();
    $url = $db_con->real_escape_string(stripslashes($url));
    if (strstr($interrupt, "-")) {
        //  if indexer should not be interrupted periodically
        $interrupt = '999999';
        //  never
    }
    $int_count = $interrupt;
    //  $int_count will be decreased by each indexed link until $int_count = 1
    printStandardReport('starting', $command_line, $no_log);
    if (!isset($all_keywords)) {
        mysqltest();
        $sql_query = "SELECT keyword_ID, keyword from " . $mysql_table_prefix . "keywords";
        $result = $db_con->query($sql_query);
        if ($debug && $db_con->errno) {
            $err_row = __LINE__ - 2;
            printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
            if (__FUNCTION__) {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
            } else {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
            }
            printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
            printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
            echo "<p> {$sql_query} </p>";
            exit;
        }
        while ($row = $result->fetch_array(MYSQLI_NUM)) {
            $all_keywords[addslashes($row[1])] = $row[0];
        }
        if ($clear == 1) {
            clean_resource($result, '06');
        }
    }
    $url = convert_url($url);
    $compurl = parse_addr($url);
    if ($compurl['path'] == '') {
        $url = $url . "/";
    }
    $t = microtime();
    $a = getenv("REMOTE_ADDR");
    $sessid = md5($t . $a);
    if ($url != '/') {
        //      ignore dummies
        $urlparts = parse_addr($url);
        $domain = $urlparts['host'];
        if (isset($urlparts['port'])) {
            $port = (int) $urlparts['port'];
        } else {
            $port = 80;
        }
        if (strpos($url, "?")) {
            $url_bas = substr($url, 0, strpos($url, "?"));
        } else {
            $url_bas = $url;
        }
        mysqltest();
        $sql_query = "SELECT * from " . $mysql_table_prefix . "sites where url like '{$url_bas}%'";
        $result = $db_con->query($sql_query);
        if ($debug && $db_con->errno) {
            $err_row = __LINE__ - 2;
            printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
            if (__FUNCTION__) {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
            } else {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
            }
            printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
            printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
            echo "<p> {$sql_query} </p>";
            exit;
        }
        $row = $result->fetch_array(MYSQLI_NUM);
        $site_id = $row[0];
        $authent = $row[2];
        if ($add_auth && $authent) {
            //  for sites with authentication we need to verify the value
            $url_status = url_status($url, $site_id, $sessid);
            $url_parts = parse_all_url($url);
            if ($url_status['state'] == 'ok' && $url_status['content'] == 'text') {
                if ($url_status['relocate']) {
                    //  if relocated,  print message and redirect to new URL
                    printRedirected($url_status['relocate'], $url_status['path'], $cl);
                    if (strstr($url_status['path'], "//")) {
                        //  if redirected to absolute URL, use this for further usage
                        $url = $url_status['path'];
                    } else {
                        $relo_url = str_replace($url_parts['query'], "", $url);
                        //  url without query
                        $relo_url = substr($url, 0, strrpos($relo_url, "/") + 1);
                        //  url without file name
                        if (strpos($url_status['path'], "./") === 0) {
                            //  if redirected relativ to same folder depth
                            $url_status['path'] = str_replace("./", "", $url_status['path']);
                            $url = "" . $relo_url . "" . $url_status['path'] . "";
                        }
                        if (strpos($url_status['path'], "../") === 0) {
                            //  if redirected relativ and one folder up
                            $url_status['path'] = str_replace("./", "", $url_status['path']);
                            $relo_url = substr($url, 0, strpos($url_parts['path']));
                            //  url without file name
                            $relo_url = substr($url, 0, strrpos($relo_url, "/") + 1);
                            //  url without last folder
                            $url = "" . $relo_url . "" . $url_status['path'] . "";
                        }
                    }
                }
                //  read file
                $contents = array();
                $file = '';
                $file = file_get_contents($url);
                if ($file === FALSE) {
                    //  we know another way to get the content
                    $get_charset = '';
                    $contents = getFileContents($url, $get_charset);
                    $file = $contents['file'];
                }
                //  parse header only
                preg_match("@<head[^>]*>(.*?)<\\/head>@si", $file, $regs);
                $headdata = $regs[1];
                //  fetch the tag value
                preg_match("/<meta +name *=[\"']?Sphider-plus[\"']? *content=[\"'](.*?)[\"']/i", $headdata, $res);
                if (isset($res)) {
                    if ($authent != $res[1]) {
                        //  invalid value in authentication tag
                        $skip = '1';
                        printHeader($omit, $url, $command_line);
                        printStandardReport('Skipped_03', $command_line, $no_log);
                    }
                } else {
                    //  no authentication tag found in header
                    $skip = '1';
                    printHeader($omit, $url, $command_line);
                    printStandardReport('Skipped_02', $command_line, $no_log);
                }
            } else {
                $skip = '1';
                printHeader($omit, $url, $command_line);
                printStandardReport('statError', $command_line, $no_log);
            }
        }
        if (!$skip) {
            if ($site_id != "" && $reindex == 1) {
                mysqltest();
                $sql_query = "INSERT into " . $mysql_table_prefix . "temp (link, level, id) values ('{$url}', 0, '{$sessid}')";
                $db_con->query($sql_query);
                if ($debug && $db_con->errno) {
                    $err_row = __LINE__ - 2;
                    printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                    if (__FUNCTION__) {
                        printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                    } else {
                        printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                    }
                    printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                    printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                    echo "<p> {$sql_query} </p>";
                    exit;
                }
                $sql_query = "SELECT url, level from " . $mysql_table_prefix . "links where site_id = {$site_id}";
                $result = $db_con->query($sql_query);
                while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
                    $site_link = $row['url'];
                    $link_level = $row['level'];
                    if ($site_link != $url) {
                        $sql_query = "INSERT into " . $mysql_table_prefix . "temp (link, level, id) values ('{$site_link}', '{$link_level}', '{$sessid}')";
                        $db_con->query($sql_query);
                    }
                }
                $sql_query = "UPDATE " . $mysql_table_prefix . "sites set indexdate=now(), spider_depth ='{$maxlevel}', required = '{$url_inc}'," . "disallowed = '{$url_not_inc}', can_leave_domain='{$can_leave}', use_prefcharset='{$use_pref}' where site_id='{$site_id}'";
                mysqltest();
                $db_con->query($sql_query);
                if ($debug && $db_con->errno) {
                    $err_row = __LINE__ - 2;
                    printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                    if (__FUNCTION__) {
                        printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                    } else {
                        printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                    }
                    printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                    printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                    echo "<p> {$sql_query} </p>";
                    exit;
                }
            } else {
                if ($site_id == '') {
                    mysqltest();
                    $sql_query = "INSERT into " . $mysql_table_prefix . "sites (url, indexdate, spider_depth, required, disallowed, can_leave_domain, use_prefcharset) " . "values ('{$url}', now(), '{$maxlevel}', '{$url_inc}', '{$url_not_inc}', '{$can_leave_domain}', '{$use_pref}')";
                    $db_con->query($sql_query);
                    if ($debug && $db_con->errno) {
                        $err_row = __LINE__ - 2;
                        printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                        if (__FUNCTION__) {
                            printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                        } else {
                            printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                        }
                        printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                        printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                        echo "<p> {$sql_query} </p>";
                        exit;
                    }
                    $sql_query = "SELECT site_ID from " . $mysql_table_prefix . "sites where url='{$url}'";
                    $result = $db_con->query($sql_query);
                    if ($debug && $db_con->errno) {
                        $err_row = __LINE__ - 2;
                        printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                        if (__FUNCTION__) {
                            printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                        } else {
                            printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                        }
                        printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                        printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                        echo "<p> {$sql_query} </p>";
                        exit;
                    }
                    $row = $result->fetch_array(MYSQLI_NUM);
                    $site_id = $row[0];
                    if ($clear == 1) {
                        clean_resource($result, '09');
                    }
                } else {
                    mysqltest();
                    $sql_query = "UPDATE " . $mysql_table_prefix . "sites set indexdate=now(), spider_depth ='{$maxlevel}', required = '{$url_inc}'," . "disallowed = '{$url_not_inc}', can_leave_domain='{$can_leave_domain}', use_prefcharset='{$use_pref}' where site_id='{$site_id}'";
                    $db_con->query($sql_query);
                    if ($debug && $db_con->errno) {
                        $err_row = __LINE__ - 2;
                        printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                        if (__FUNCTION__) {
                            printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                        } else {
                            printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                        }
                        printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                        printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                        echo "<p> {$sql_query} </p>";
                        exit;
                    }
                }
            }
            $pending = array();
            mysqltest();
            $sql_query = "SELECT site_id, temp_id, level, count, num from " . $mysql_table_prefix . "pending where site_id='{$site_id}'";
            $result = $db_con->query($sql_query);
            if ($debug && $db_con->errno) {
                $err_row = __LINE__ - 2;
                printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                if (__FUNCTION__) {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                } else {
                    printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                }
                printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                echo "<p> {$sql_query} </p>";
                exit;
            }
            $row = $result->fetch_array(MYSQLI_NUM);
            $pending = $row[0];
            $level = '0';
            $count = '0';
            if ($clear == 1) {
                clean_resource($result, '10');
            }
            $domain_arr = get_domains();
            if ($pending == '') {
                mysqltest();
                $sql_query = "INSERT into " . $mysql_table_prefix . "temp (link, level, id) values ('{$url}', 0, '{$sessid}')";
                $db_con->query($sql_query);
                if ($debug && $db_con->errno) {
                    $err_row = __LINE__ - 2;
                    printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                    if (__FUNCTION__) {
                        printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                    } else {
                        printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                    }
                    printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                    printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                    echo "<p> {$sql_query} </p>";
                    exit;
                }
            } else {
                if ($pending != '') {
                    printStandardReport('continueSuspended', $command_line, $no_log);
                    mysqltest();
                    $pend_count = '0';
                    //$result = $db_con->query("SELECT temp_id, level, count from ".$mysql_table_prefix."pending where site_id='$site_id'");
                    $sql_query = "SELECT * from " . $mysql_table_prefix . "pending where site_id='{$site_id}'";
                    $result = $db_con->query($sql_query);
                    if ($debug && $db_con->errno) {
                        $err_row = __LINE__ - 2;
                        printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                        if (__FUNCTION__) {
                            printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                        } else {
                            printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                        }
                        printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                        printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                        echo "<p> {$sql_query} </p>";
                        exit;
                    }
                    $row = $result->fetch_array(MYSQLI_NUM);
                    if ($row) {
                        $sessid = $row[1];
                        $level = $row[2];
                        $pend_count = $row[3] + 1;
                        $num = $row[4];
                        $pending = 1;
                        $tmp_urls = get_temp_urls($sessid);
                        if ($clear == 1) {
                            clean_resource($result, '11');
                        }
                    }
                }
            }
            if ($pending != 1) {
                mysqltest();
                $sql_query = "INSERT into " . $mysql_table_prefix . "pending (site_id, temp_id, level, count) values ('{$site_id}', '{$sessid}', '0', '0')";
                $db_con->query($sql_query);
                if ($debug && $db_con->errno) {
                    $err_row = __LINE__ - 2;
                    printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
                    if (__FUNCTION__) {
                        printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
                    } else {
                        printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
                    }
                    printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
                    printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
                    echo "<p> {$sql_query} </p>";
                    exit;
                }
            }
            $time = time();
            $robots = "robots.txt";
            // standardname of robots file
            if ($use_robot == '1') {
                $omit = check_robot_txt($url, $robots);
            }
            printHeader($omit, $url, $command_line);
            if ($link_check == 1) {
                printStandardReport('start_link_check', $command_line, $no_log);
            }
            if ($link_check == 0 && $reindex == 1) {
                printStandardReport('start_reindex', $command_line, $no_log);
            }
            if ($link_check == 0 && $reindex == 0) {
                printStandardReport('starting', $command_line, $no_log);
            }
            $mainurl = $url;
            $realnum = $num;
            $num = 0;
            while ($level <= $maxlevel && $soption == 'level' || $soption == 'full') {
                if ($pending == 1) {
                    $count = $pend_count;
                    $pending = 0;
                } else {
                    $count = 0;
                }
                $links = array();
                mysqltest();
                $sql_query = "SELECT distinct link from " . $mysql_table_prefix . "temp where level={$level} && id='{$sessid}' order by link";
                $result = $db_con->query($sql_query);
                $rows = $result->num_rows;
                if ($rows == 0) {
                    break;
                }
                while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
                    $links[] = $row['link'];
                }
                //  now loop through all available links(pages)
                while ($count < count($links)) {
                    $num++;
                    $realnum++;
                    if ($realnum > $max_links) {
                        //  if max. links per page reached
                        mysqltest();
                        $sql_query = "DELETE from " . $mysql_table_prefix . "temp where id = '{$sessid}'";
                        $db_con->query($sql_query);
                        $sql_query = "DELETE from " . $mysql_table_prefix . "pending where site_id = '{$site_id}'";
                        $db_con->query($sql_query);
                        printMaxLinks($max_links, $cl);
                        printStandardReport('completed', $command_line, $no_log);
                        return;
                    }
                    $thislink = $db_con->real_escape_string(stripslashes($links[$count]));
                    $urlparts = parse_addr($thislink);
                    $forbidden = 0;
                    if (is_array($omit)) {
                        //      if valid robots.txt  was found
                        reset($omit);
                        foreach ($omit as $omiturl) {
                            $omiturl = trim($omiturl);
                            $omiturl_parts = array();
                            $omiturl_parts = parse_addr($omiturl);
                            if (@$omiturl_parts['scheme'] == '') {
                                $check_omit = $urlparts['host'] . $omiturl;
                            } else {
                                $check_omit = $omiturl;
                            }
                            if (strpos($thislink, $check_omit)) {
                                printRobotsReport($num, $thislink, $command_line);
                                $realnum--;
                                check_for_removal($thislink);
                                $forbidden = 1;
                                break;
                            }
                        }
                    }
                    if (!check_include($thislink, $url_inc, $url_not_inc)) {
                        $realnum--;
                        printUrlStringReport($num, $thislink, $command_line);
                        //printUrlStringReport($realnum, $thislink, $command_line);
                        check_for_removal($thislink);
                        $forbidden = 1;
                    }
                    if ($forbidden == 0) {
                        printRetrieving($num, stripslashes(rawurldecode($thislink)), $command_line);
                        //printRetrieving($realnum, $thislink, $command_line);
                        mysqltest();
                        $sql_query = "SELECT md5sum, indexdate from " . $mysql_table_prefix . "links where url='{$thislink}'";
                        $result = $db_con->query($sql_query);
                        $rows = $result->num_rows;
                        if ($rows == 0) {
                            $url_status = index_url($thislink, $level + 1, $site_id, '', $domain, '', $sessid, $can_leave_domain, $reindex, $use_nofollow, $cl, $use_robot, $use_pref, $url_inc, $url_not_inc, $num);
                            //  check for touching the blacklist and its count against limit
                            if ($url_status['black'] == "1") {
                                $black++;
                                if ($black > 20) {
                                    //  limit until aborting the indexation of this site
                                    $url_status['aborted'] = "1";
                                    $url_status['state'] = "<br /><br />Indexation aborted for this site, as it met too often the blacklist.";
                                }
                            } else {
                                $black = 0;
                                //  reset counter, as should count only on continuous hits
                            }
                            //  check for emergency exit
                            if ($url_status['aborted'] == "1") {
                                //  delete all links from the temp table, which might be left for this site
                                mysqltest();
                                $sql_query = "DELETE from " . $mysql_table_prefix . "temp where id = '{$sessid}'";
                                $db_con->query($sql_query);
                                $sql_query = "DELETE from " . $mysql_table_prefix . "pending where site_id = '{$site_id}'";
                                $db_con->query($sql_query);
                                $sql_query = "UPDATE " . $mysql_table_prefix . "sites set indexdate=now() where url = '{$url}'";
                                $db_con->query($sql_query);
                                //  end all loops
                                $forbidden = '1';
                                $omit = '';
                                $reindex = '';
                                $count = '9999999999';
                                $pending = array();
                                if (!stristr($url_status['state'], "NOHOST") && !stristr($url_status['state'], "black")) {
                                    //  NOHOST warning will be printed separately
                                    printWarning($url_status['state'], $command_line, $no_log);
                                }
                            }
                            if (stristr($url_status['state'], "NOHOST")) {
                                //  delete all links from the temp table, which might be left for this site,  etc
                                mysqltest();
                                $sql_query = "DELETE from " . $mysql_table_prefix . "temp where id = '{$sessid}'";
                                $db_con->query($sql_query);
                                $sql_query = "DELETE from " . $mysql_table_prefix . "pending where site_id = '{$site_id}'";
                                $db_con->query($sql_query);
                                $sql_query = "UPDATE " . $mysql_table_prefix . "sites set indexdate=now() where url = '{$url}'";
                                $db_con->query($sql_query);
                                //  end all loops
                                $forbidden = '1';
                                $omit = '';
                                $reindex = '';
                                $count = '9999999999';
                                $pending = array();
                                printWarning($url_status['state'], $command_line, $no_log);
                                return;
                            }
                            //  check for UFO file or invalid suffix (by redirected URL)
                            if (stristr($url_status['state'], "ufo")) {
                                //printWarning($url_status['state'],$command_line, $no_log);
                            }
                            if ($url_status['state'] != "ok") {
                                printWarning($url_status['state'], $command_line, $no_log);
                            }
                            mysqltest();
                            $sql_query = "UPDATE " . $mysql_table_prefix . "pending set level ='{$level}', count='{$count}', num='{$realnum}' where site_id='{$site_id}'";
                            $db_con->query($sql_query);
                        } else {
                            if ($rows != 0 && $reindex == 1) {
                                $row = $result->fetch_array(MYSQLI_ASSOC);
                                $md5sum = $row['md5sum'];
                                $indexdate = $row['indexdate'];
                                if ($link_check == 1 && $reindex == 1) {
                                    link_check($thislink, $level + 1, $sessid, $can_leave_domain, $reindex, $site_id);
                                } else {
                                    $url_status = index_url($thislink, $level + 1, $site_id, $md5sum, $domain, $indexdate, $sessid, $can_leave_domain, $reindex, $use_nofollow, $cl, $use_robot, $use_pref, $url_inc, $url_not_inc, $num);
                                    //  check for emergency exit
                                    if ($url_status['aborted']) {
                                        //  delete all links from the temp table, which might be left for this site
                                        mysqltest();
                                        $sql_query = "DELETE from " . $mysql_table_prefix . "temp where id = '{$sessid}'";
                                        $db_con->query($sql_query);
                                        //  end all loops
                                        $forbidden = '1';
                                        $omit = '';
                                        $reindex = '';
                                        $count = '9999999999';
                                        $pending = array();
                                        printWarning($url_status['state'], $command_line, $no_log);
                                    }
                                }
                            } else {
                                printStandardReport('inDatabase', $command_line, $no_log);
                                $realnum--;
                                //$num--;
                            }
                        }
                        if ($rows != 0) {
                            mysqltest();
                            $sql_query = "UPDATE " . $mysql_table_prefix . "pending set level ='{$level}', count='{$count}', num='{$realnum}' where site_id='{$site_id}'";
                            $db_con->query($sql_query);
                        }
                        if ($clear == 1) {
                            clean_resource($result, '13');
                        }
                    }
                    //  check for interrupt counter
                    if ($int_count == '1') {
                        //  interrupt the index procedure until interactive resume
                        $sql_query = "UPDATE " . $mysql_table_prefix . "pending set level ='{$level}', count='{$count}', num='{$realnum}' where site_id='{$site_id}'";
                        $db_con->query($sql_query);
                        printInterrupt($interrupt, $url, $cl);
                        die;
                    }
                    $count++;
                    $int_count--;
                }
                $level++;
            }
        }
        mysqltest();
        $sql_query = "DELETE from " . $mysql_table_prefix . "temp where id = '{$sessid}'";
        $db_con->query($sql_query);
        if ($debug && $db_con->errno) {
            $err_row = __LINE__ - 2;
            printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
            if (__FUNCTION__) {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
            } else {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
            }
            printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
            printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
            echo "<p> {$sql_query} </p>";
            exit;
        }
        $sql_query = "DELETE from " . $mysql_table_prefix . "pending where site_id = '{$site_id}'";
        $db_con->query($sql_query);
        if ($debug && $db_con->errno) {
            $err_row = __LINE__ - 2;
            printf("<p><span class='red'>&nbsp;MySQL failure: %s&nbsp;\n<br /></span></p>", $db_con->error);
            if (__FUNCTION__) {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;&nbsp;in function():&nbsp;" . __FUNCTION__ . "&nbsp;<br /></span></p>");
            } else {
                printf("<p><span class='red'>&nbsp;Found in script: " . __FILE__ . "&nbsp;&nbsp;row: {$err_row}&nbsp;<br /></span></p>");
            }
            printf("<p><span class='red'>&nbsp;Script execution aborted.&nbsp;<br /></span>");
            printf("<p><strong>Invalid query string, which caused the SQL error:</strong></p>");
            echo "<p> {$sql_query} </p>";
            exit;
        }
        if ($create_sitemap == 1) {
            create_sitemap($site_id, $url);
        }
        printStandardReport('completed', $command_line, $no_log);
        $stats = get_Stats();
        printDatabase($stats, $cl);
    }
    if ($index_media) {
        //  delete all thumbnails in .../admin/tmp/thumbs/ folder
        clear_folder("." . $thumb_folder);
    }
}
function updateHexImage($hColorData, $sFilePath)
{
    $sTargetFileLocation = DIR_IMAGES . $sFilePath;
    $sFileContent = getFileContents($sFilePath);
    if (!$sFileContent) {
        return false;
    }
    // Ursprünglichen Hue-Wert durch Wert der CI-Farbe ersetzen
    $sFileContent = str_replace($hColorData['replace']['search'], $hColorData['replace']['replace'], $sFileContent);
    // Neue Dateiinhalte in Zielgrafik schreiben
    if (!file_put_contents($sTargetFileLocation, $sFileContent)) {
        say('Grafik konnte nicht ueberschrieben werden: ' . $sTargetFileLocation);
        return false;
    }
    say("Grafik eingefaerbt: " . $sTargetFileLocation);
    return true;
}
示例#9
0
/**
 * Encode file contents for POST-ing to REST API.
 * Returns contents of $file (optionally limited in size, see
 * getFileContents) as encoded string.
 */
function rest_encode_file($file, $sizelimit = TRUE)
{
    return urlencode(base64_encode(getFileContents($file, $sizelimit)));
}
示例#10
0
文件: read.php 项目: bex1/MePage
    $select .= "<option value='{$val}' {$selected}>{$val}</option>";
}
$select .= "</select>";
?>

<h1>Visa annons</h1>

<p>Välj den annons som du vill visa.</p>

<form method="post">
    <fieldset>
        <p>
            <label for="input1">Annonser:</label><br>
            <?php 
echo $select;
?>
        </p>

        <p>
        <div style="background:#eee; border:1px solid #999;padding:1em; overflow: auto; text-align: center;">
            <p><?php 
if ($filename) {
    echo getFileContents($filename);
}
?>
</p>
        </div>
        </p>

    </fieldset>
</form>
if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
    $encodings = explode(',', strtolower(preg_replace("/\\s+/", "", $_SERVER['HTTP_ACCEPT_ENCODING'])));
}
if ((in_array('gzip', $encodings) || in_array('x-gzip', $encodings) || isset($_SERVER['---------------'])) && function_exists('ob_gzhandler') && !ini_get('zlib.output_compression')) {
    $enc = in_array('x-gzip', $encodings) ? "x-gzip" : "gzip";
    $supportsGzip = true;
}
// Use cached file disk cache, if possible
if ($supportsGzip && file_exists($cacheFile)) {
    header("Content-Encoding: " . $enc);
    echo getFileContents($cacheFile);
    die;
} else {
    // Add custom files
    foreach ($custom as $file) {
        $content .= getFileContents($file . '.js');
    }
    // Generate GZIP'd content, if possible
    if ($supportsGzip) {
        header("Content-Encoding: " . $enc);
        $cacheData = gzencode($content, 9, FORCE_GZIP);
        // Write gz file
        if ($cacheKey != "") {
            putFileContents($cacheFile, $cacheData);
        }
        // Stream to client
        echo $cacheData;
    } else {
        // Stream uncompressed content
        echo $content;
    }
示例#12
0
    $stmt = $mysqli->query('SELECT id FROM user_competition WHERE user_id = ' . $userId . ' AND competition_id = ' . $competitionId);
    if ($stmt->num_rows > 0) {
        $userEntered = 1;
    }
    $mysqli->close();
    return $userEntered;
}
$competitionId = 1;
$compTag = 'beyondthewharf';
if (isset($_GET['competitionId'])) {
    $competitionId = $_GET['competitionId'];
}
if ($competitionId == 2) {
    $compTag = 'vividsydney';
}
$wharfs = getFileContents('../json/wharfs.json');
$userEntered = 0;
if (isset($_GET['step']) || isset($instagramData)) {
    if (isset($_GET['step'])) {
        $step = $_GET['step'];
    } else {
        $step = 2;
    }
} else {
    $step = 1;
}
if (isset($instagramData)) {
    $instagramUsername = $instagramData->user->username;
    $instagramId = $instagramData->user->id;
    $userDetails = getUserDetails($instagramId, $DB_SERVER, $DB_USERNAME, $DB_PASSWORD, $DB_DATABASE);
    if ($userDetails['id'] > 0) {
示例#13
0
 public function initializeFileList()
 {
     if (!file_exists($GLOBALS['tupac_directory'] . '/tupac_filelist')) {
         sendMessage('creatingFileList', array());
         $GLOBALS['pacman_file_list'] = new PacmanFilesList();
     } else {
         if (!$GLOBALS['pacman_file_list']) {
             //sendMessage('reusingFileList',array());
             $GLOBALS['pacman_file_list'] = unserialize(getFileContents($GLOBALS['tupac_directory'] . '/tupac_filelist'));
             if ($GLOBALS['pacman_file_list'] === false) {
                 unlink($GLOBALS['tupac_directory'] . '/tupac_filelist');
                 sendMessage('corruptedFileList', array());
                 $GLOBALS['pacman_file_list'] = new PacmanFilesList();
             } else {
                 $GLOBALS['pacman_file_list']->updateFileList();
             }
         }
     }
 }
示例#14
0
function index_url($url, $level, $site_id, $md5sum, $domain, $indexdate, $sessid, $can_leave_domain, $reindex)
{
    global $min_delay;
    global $command_line;
    global $min_words_per_page;
    global $supdomain, $index_vpaths;
    global $user_agent, $tmp_urls, $delay_time, $domain_arr;
    global $db;
    $deletable = 0;
    $url_status = url_status($url);
    $thislevel = $level - 1;
    if (strstr($url_status['state'], "Relocation")) {
        $url = preg_replace("/ /", "", url_purify($url_status['path'], $url, $can_leave_domain));
        if ($url != '') {
            $result = $db->query("SELECT link FROM " . TABLE_PREFIX . "temp WHERE link=" . $db->quote($url) . " AND id=" . $db->quote($sessid));
            echo sql_errorstring(__FILE__, __LINE__);
            if ($result->fetch()) {
                $result->closeCursor();
                $db->exec("INSERT INTO " . TABLE_PREFIX . "temp (link, level, id) VALUES (" . $db->quote($url) . ", " . $db->quote($level) . ", " . $db->quote($sessid) . ")");
                echo sql_errorstring(__FILE__, __LINE__);
            }
        }
        $url_status['state'] == "redirected";
    }
    if (!$index_vpaths && $url_status['state'] == 'ok') {
        $url_parts = parse_url($url);
        $base = basename($url_parts['path']);
        if (strstr($base, '.') == false) {
            $url_status['state'] = "directory listing or default redirect";
        }
    }
    ini_set("user_agent", $user_agent);
    if ($url_status['state'] == 'ok') {
        $OKtoIndex = 1;
        $file_read_error = 0;
        if (time() - $delay_time < $min_delay) {
            sleep($min_delay - (time() - $delay_time));
        }
        $delay_time = time();
        if (!fst_lt_snd(phpversion(), "4.3.0")) {
            $file = file_get_contents($url);
            if ($file === FALSE) {
                $file_read_error = 1;
            }
        } else {
            $fl = @fopen($url, "r");
            if ($fl) {
                while ($buffer = @fgets($fl, 4096)) {
                    $file .= $buffer;
                }
            } else {
                $file_read_error = 1;
            }
            fclose($fl);
        }
        if ($file_read_error) {
            $contents = getFileContents($url);
            $file = $contents['file'];
        }
        $pageSize = number_format(strlen($file) / 1024, 2, ".", "");
        printPageSizeReport($pageSize);
        if ($url_status['content'] != 'text') {
            $file = extract_text($file, $url_status['content']);
        }
        printStandardReport('starting', $command_line);
        $newmd5sum = md5($file);
        if ($reindex == 0) {
            if ($md5sum == $newmd5sum) {
                printStandardReport('md5notChanged', $command_line);
                $OKtoIndex = 0;
            } else {
                if (isDuplicateMD5($newmd5sum)) {
                    $OKtoIndex = 0;
                    printStandardReport('duplicate', $command_line);
                }
            }
        }
        if (($md5sum != $newmd5sum || $reindex == 1) && $OKtoIndex == 1) {
            $urlparts = parse_url($url);
            $newdomain = $urlparts['host'];
            $type = 0;
            // remove link to css file
            //get all links from file
            $data = clean_file($file, $url, $url_status['content']);
            if ($data['noindex'] == 1) {
                $OKtoIndex = 0;
                $deletable = 1;
                printStandardReport('metaNoindex', $command_line);
            }
            $wordarray = unique_array(explode(" ", $data['content']));
            if ($data['nofollow'] != 1) {
                $links = get_links($file, $url, $can_leave_domain, $data['base']);
                $links = distinct_array($links);
                $all_links = count($links);
                $numoflinks = 0;
                //if there are any, add to the temp table, but only if there isnt such url already
                if (is_array($links)) {
                    reset($links);
                    while ($thislink = each($links)) {
                        if (!isset($tmp_urls[$thislink[1]]) || $tmp_urls[$thislink[1]] != 1) {
                            $tmp_urls[$thislink[1]] = 1;
                            $numoflinks++;
                            $db->exec("INSERT INTO " . TABLE_PREFIX . "temp (link, level, id) VALUES (" . $db->quote($thislink[1]) . ", " . $db->quote($level) . ", " . $db->quote($sessid) . ")");
                            echo sql_errorstring(__FILE__, __LINE__);
                        }
                    }
                }
            } else {
                printStandardReport('noFollow', $command_line);
            }
            if ($OKtoIndex == 1) {
                $title = $data['title'];
                $host = $data['host'];
                $path = $data['path'];
                $fulltxt = str_replace("\\'", "&quot;", $data['fulltext']);
                $desc = substr($data['description'], 0, 254);
                $language = substr($data['language'], 0, 2);
                $url_parts = parse_url($url);
                $domain_for_db = $url_parts['host'];
                if (isset($domain_arr[$domain_for_db])) {
                    $dom_id = $domain_arr[$domain_for_db];
                } else {
                    $db->exec("INSERT INTO " . TABLE_PREFIX . "domains (domain) VALUES (" . $db->quote($domain_for_db) . ")");
                    $dom_id = $db->lastInsertId();
                    $domain_arr[$domain_for_db] = $dom_id;
                }
                $wordarray = calc_weights($wordarray, $title, $host, $path, $data['keywords']);
                $tstamp = "'" . date("Y-m-d") . "'";
                //if there are words to index, add the link to the database, get its id, and add the word + their relation
                if (is_array($wordarray) && count($wordarray) > $min_words_per_page) {
                    $site_id = $db->quote($site_id);
                    $url = $db->quote($url);
                    $title = $db->quote($title);
                    $desc = $db->quote($desc);
                    $language = $db->quote($language);
                    $fulltxt = $db->quote($fulltxt);
                    $pageSize = $db->quote($pageSize);
                    $Qmd5sum = $db->quote($newmd5sum);
                    if ($md5sum == '') {
                        $db->exec("INSERT INTO " . TABLE_PREFIX . "links (site_id, url, title, description, language, fulltxt, indexdate, size, md5sum, level) VALUES ({$site_id}, {$url}, {$title}, {$desc}, {$language}, {$fulltxt}, {$tstamp}, {$pageSize}, {$Qmd5sum}, {$thislevel})");
                        $error = sql_errorstring(__FILE__, __LINE__);
                        if ($error) {
                            echo $error;
                            printStandardReport('skipped', $command_line);
                        } else {
                            $result = $db->query("SELECT link_id FROM " . TABLE_PREFIX . "links WHERE url={$url}");
                            echo sql_errorstring(__FILE__, __LINE__);
                            $row = $result->fetch();
                            $link_id = $row[0];
                            $result->closeCursor();
                            save_keywords($wordarray, $link_id, $dom_id);
                            printStandardReport('indexed', $command_line);
                        }
                    } else {
                        if ($md5sum != '' && $md5sum != $newmd5sum) {
                            //if page has changed, start updating
                            $result = $db->query("SELECT link_id FROM " . TABLE_PREFIX . "links WHERE url={$url}");
                            echo sql_errorstring(__FILE__, __LINE__);
                            $row = $result->fetch();
                            $link_id = $row[0];
                            $result->closeCursor();
                            for ($i = 0; $i <= 15; $i++) {
                                $char = dechex($i);
                                $db->exec("DELETE FROM " . TABLE_PREFIX . "link_keyword{$char} WHERE link_id={$link_id}");
                                echo sql_errorstring(__FILE__, __LINE__);
                            }
                            save_keywords($wordarray, $link_id, $dom_id);
                            $db->exec("UPDATE " . TABLE_PREFIX . "links SET title={$title}, description={$desc}, language={$language}, fulltxt={$fulltxt}, indexdate={$tstamp}, size={$pageSize}, md5sum={$Qmd5sum}, level={$thislevel} WHERE link_id={$link_id}");
                            echo sql_errorstring(__FILE__, __LINE__);
                            printStandardReport('re-indexed', $command_line);
                        }
                    }
                } else {
                    printStandardReport('minWords', $command_line);
                }
            }
        }
    } else {
        $deletable = 1;
        printUrlStatus($url_status['state'], $command_line);
    }
    if ($reindex == 1 && $deletable == 1) {
        check_for_removal($url);
    } else {
        if ($reindex == 1) {
            //???
        }
    }
    if (!isset($all_links)) {
        $all_links = 0;
    }
    if (!isset($numoflinks)) {
        $numoflinks = 0;
    }
    printLinksReport($numoflinks, $all_links, $command_line);
}
示例#15
0
function get_url_content($url)
{
    $data = getFileContents($url);
    if ($data["state"] == "ok") {
        return $data["file"];
    } else {
        return getfile($url);
    }
}
示例#16
0
文件: tupac.inc.php 项目: Kett/tupac
function checkCache()
{
    // Check if we hgave cache
    if (!file_exists($GLOBALS['tupac_directory'] . '/tupac_data')) {
        // If any of the main files is missing, regenerate cache
        Std::rm($GLOBALS['tupac_directory'] . '/tupac_data');
        Std::rm($GLOBALS['tupac_directory'] . '/tupac_filelist');
        sendMessage('generatingCache', array());
        // Gather information
        $GLOBALS['data'] = new PacmanData();
        $GLOBALS['data']->updateList();
    } else {
        // Read Cache
        $GLOBALS['data'] = unserialize(getFileContents($GLOBALS['tupac_directory'] . '/tupac_data'));
        if ($GLOBALS['data'] === false) {
            // Unserialized failed
            sendMessage('generatingCacheCorrupted', array());
            Std::rm($GLOBALS['tupac_directory'] . '/tupac_data');
            Std::rm($GLOBALS['tupac_directory'] . '/tupac_filelist');
            $GLOBALS['data'] = new PacmanData();
            $GLOBALS['data']->updateList();
        } else {
            switch ($GLOBALS['data']->verifyIntegrity()) {
                case 'cache_updated':
                    sendMessage('generatingCacheTupacUpdated', array());
                    Std::rm($GLOBALS['tupac_directory'] . '/tupac_data');
                    Std::rm($GLOBALS['tupac_directory'] . '/tupac_filelist');
                    $GLOBALS['data'] = new PacmanData();
                    $GLOBALS['data']->updateList();
                    break;
                case 'database_outdated':
                    //sendMessage('generatingCacheDatabaseUpdated',array());
                    $anyChanges = false;
                    // Get currently available repos
                    $available_repos = array();
                    $dh = getRepoDirList();
                    foreach ($dh as $repo) {
                        if (!substr($repo, 0, 1) == '.' && is_dir(getRepoDir($repo))) {
                            $available_repos[$repo] = false;
                        }
                    }
                    // The database needs to be updated
                    $mustRecheckLocal = false;
                    $repo_list = $GLOBALS['data']->repo_list;
                    foreach ($repo_list as $repo => $repoData) {
                        unset($available_repos[$repo]);
                        if ($repo == 'local' && $GLOBALS['data']->verification[$repo] != PacmanData::verifyRepo($repo)) {
                            // We check local separately, since it is not a repo.
                            sendMessage('repoIsUpdated', array('%r' => $repo));
                            $anyChanges = true;
                            $installed = true;
                            $available_packages = array();
                            // get current packages
                            $dh = opendir(getRepoDir($repo));
                            while (FALSE !== ($package = readdir($dh))) {
                                if (substr($package, 0, 1) != '.' && is_dir(getRepoDir($repo) . $package)) {
                                    $packageName = preg_replace('/\\-[0-9a-z\\._A-Z]*\\-[0-9a-z\\._A-Z]*$/', '', $package);
                                    $available_packages[$packageName] = $package;
                                }
                            }
                            closedir($dh);
                            $installed_packages = $GLOBALS['data']->installed_packages;
                            // Walk packages of the current repo
                            foreach ($installed_packages as $packageName => $packageData) {
                                if (!$available_packages[$packageName]) {
                                    // The package is not installed anymore
                                    sendMessage('removePackage', array('%p' => $packageName));
                                    unset($repo_list['local'][$packageName]);
                                    foreach ($repo_list as $tmpRepo => $tmpRepoData) {
                                        if ($tmpRepoData[$packageName]) {
                                            $repo_list[$tmpRepo][$packageName]['installed'] = 'false';
                                        }
                                    }
                                    unset($installed_packages[$packageName]);
                                } elseif ($packageData['dir'] != $available_packages[$packageName]) {
                                    // Package updated. Since it is the list of installed packages, set its version to installed version
                                    sendMessage('updatePackage', array('%p' => $packageName));
                                    $installed_packages[$packageName] = PacmanData::getPackageData($repo, $available_packages[$packageName], 'true');
                                    $installed_info = $installed_packages[$packageName]['version'];
                                    $installed_packages[$packageName]['installed'] = $installed_info;
                                    foreach ($repo_list as $tmpRepo => $tmpRepoData) {
                                        if ($tmpRepoData[$packageName]) {
                                            $repo_list[$tmpRepo][$packageName]['installed'] = $installed_info;
                                            // in local installed version equals to avaiable version
                                            if ($repo == 'local') {
                                                $repo_list[$tmpRepo][$packageName]['version'] = $installed_info;
                                            }
                                        }
                                    }
                                }
                                unset($available_packages[$packageName]);
                            }
                            // Add new packages. This is, packages that are listed in the repo directory but that aren't marked as installed.
                            foreach ($available_packages as $packageName => $package) {
                                if ($package) {
                                    $packageFound = false;
                                    sendMessage('addPackage', array('%p' => $packageName));
                                    $installed_packages[$packageName] = PacmanData::getPackageData($repo, $available_packages[$packageName], 'true');
                                    $installed_info = $installed_packages[$packageName]['version'];
                                    $installed_packages[$packageName]['installed'] = $installed_info;
                                    foreach ($repo_list as $tmpRepo => $tmpRepoData) {
                                        if ($tmpRepo != 'local' && $tmpRepoData[$packageName]) {
                                            $repo_list[$tmpRepo][$packageName]['installed'] = $installed_info;
                                            $packageFound = true;
                                        }
                                    }
                                    // It wasn't in any repo. Let's add it to the pseudorepo local
                                    if (!$packageFound) {
                                        $repo_list['local'][$packageName] = $installed_packages[$packageName];
                                    }
                                }
                            }
                            $GLOBALS['data']->installed_packages = $installed_packages;
                            $GLOBALS['data']->verification[$repo] = PacmanData::verifyRepo($repo);
                            continue;
                        }
                        if (!is_dir(getRepoDir($repo))) {
                            sendMessage('repoIsGone', array('%r' => $repo));
                            unset($repo_list[$repo]);
                            foreach ($repoData as $packageName => $packageData) {
                                if ($GLOBALS['data']->installed_packages[$packageName]) {
                                    $packageFound = false;
                                    foreach ($repo_list as $tmpRepo => $tmpRepoData) {
                                        if ($tmpRepo != 'local' && $tmpRepoData[$packageName]) {
                                            $packageFound = true;
                                            break;
                                        }
                                    }
                                    if (!$packageFound) {
                                        $repo_list['local'][$packageName] = $packageData;
                                    }
                                }
                            }
                            $anyChanges = true;
                        } else {
                            if ($GLOBALS['data']->verification[$repo] != PacmanData::verifyRepo($repo)) {
                                sendMessage('repoIsUpdated', array('%r' => $repo));
                                $anyChanges = true;
                                $available_packages = array();
                                // get current packages
                                $dh = opendir(getRepoDir($repo));
                                while (FALSE !== ($package = readdir($dh))) {
                                    if (substr($package, 0, 1) != '.' && is_dir(getRepoDir($repo) . $package)) {
                                        $packageName = preg_replace('/\\-[0-9a-z\\._A-Z]*\\-[0-9a-z\\._A-Z]*$/', '', $package);
                                        $available_packages[$packageName] = $package;
                                    }
                                }
                                closedir($dh);
                                // Walk packages of the current repo
                                foreach ($repoData as $packageName => $packageData) {
                                    if (!$available_packages[$packageName]) {
                                        // The package doesn't exist anymore in the directory of the repo
                                        sendMessage('removePackage', array('%p' => $packageName));
                                        if ($packageData['installed'] != 'false') {
                                            // since it is installed, we have to move it to the pseudorepo local
                                            $repo_list['local'][$packageName] = $repo_list[$repo][$packageName];
                                            $packageFound = false;
                                            foreach ($repo_list as $tmpRepo => $tmpRepoData) {
                                                if ($tmpRepo != 'local' && $tmpRepoData[$packageName]) {
                                                    $packageFound = true;
                                                }
                                            }
                                            if (!$packageFound) {
                                                $repo_list['local'][$packageName] = $packageData;
                                            }
                                        }
                                        unset($repo_list[$repo][$packageName]);
                                    } elseif ($packageData['dir'] != $available_packages[$packageName]) {
                                        // Package updated
                                        sendMessage('updatePackage', array('%p' => $packageName));
                                        $installed_info = $packageData['installed'];
                                        $repo_list[$repo][$packageName] = PacmanData::getPackageData($repo, $available_packages[$packageName], $installed_info);
                                    }
                                    unset($available_packages[$packageName]);
                                }
                                // Add new packages. This is, packages that are listed in the repo directory but that aren't available in the repo.
                                foreach ($available_packages as $packageName => $package) {
                                    if ($package) {
                                        sendMessage('addPackage', array('%p' => $packageName));
                                        $repo_list[$repo][$packageName] = PacmanData::getPackageData($repo, $package, $installed);
                                        // Add install information
                                        if ($repo_list['local'][$packageName]) {
                                            $GLOBALS['data']->installed_packages[$packageName] = $repo_list['local'][$packageName];
                                        }
                                        if ($GLOBALS['data']->installed_packages[$packageName]) {
                                            unset($repo_list['local'][$packageName]);
                                            $repo_list[$repo][$packageName]['installed'] = $GLOBALS['data']->installed_packages[$packageName]['version'];
                                            // remove it from the pseudo repo local
                                            if ($repo_list['local'][$packageName]) {
                                                unset($repo_list['local'][$packageName]);
                                            }
                                        } else {
                                            $repo_list[$repo][$packageName]['installed'] = 'false';
                                        }
                                    }
                                }
                                $GLOBALS['data']->verification[$repo] = PacmanData::verifyRepo($repo);
                            }
                        }
                    }
                    $GLOBALS['data']->repo_list = $repo_list;
                    foreach ($available_repos as $repo => $dummy) {
                        sendMessage('repoIsNew', array('%r' => $repo));
                        $GLOBALS['data']->getRepoData($repo);
                        $mustRecheckLocal = true;
                    }
                    if ($mustRecheckLocal) {
                        $anyChanges = true;
                        sendMessage('recheckingLocal', array());
                        // we copy installed packages to pseudorepo local
                        $GLOBALS['data']->repo_list['local'] = array_merge($GLOBALS['data']->installed_packages, $GLOBALS['data']->repo_list['local']);
                        $GLOBALS['data']->recheckLocal();
                    }
                    if ($anyChanges) {
                        sendMessage('saving', array());
                        $GLOBALS['data']->saveData();
                    }
                    break;
                default:
                    // We never get here
                    //sendMessage('reusingCache',array());
                    break;
            }
        }
    }
}
示例#17
0
文件: ajax.php 项目: Kheros/Plexis
            $data['next_step'] = 1;
            $Cache->save('debugger', $data, 2);
            usleep(1500000);
            $contents = $Cache->get('debugger');
            if ($contents['next_step'] == 0) {
                if ($contents['flags'] == 2) {
                    $output['finished'] = true;
                } else {
                    $output['data'] = array('script' => basename($contents['file']), 'file' => SYSTEM_PATH . DS . $contents['file'], 'line' => $contents['line'], 'file_contents' => getFileContents($contents['file'], $contents['line']));
                }
            }
            break;
        case 'finish':
            $data['flags'] = 1;
            $Cache->save('debugger', $data, 2);
            break;
        case 'status':
            $output['data'] = $data;
            $out = $data['output'];
            if ($out != null) {
                $data['output'] = null;
                $Cache->save('debugger', $data, 2);
                $output['data']['output'] = highlight($out);
            }
            break;
        case 'getFile':
            $output['data'] = getFileContents($data['file'], $data['line']);
            break;
    }
}
echo output($output);
// Add core
$content .= getFileContents( 'tiny_mce.js' );

// Patch loading functions
$content .= 'tinyMCEPreInit.start();';

// Add all languages (WP)
include_once( dirname(__FILE__).'/langs/wp-langs.php' );
$content .= $strings;

// Add themes
$content .= getFileContents( 'themes/' . $theme . '/editor_template.js' );

// Add plugins
foreach ( $plugins as $plugin ) 
	$content .= getFileContents( 'plugins/' . $plugin . '/editor_plugin.js' );

// Add external plugins and init 
$content .= $ext_plugins . 'tinyMCE.init({' . $mce_options . '});';

// Generate GZIP'd content
if ( '.gz' == $cache_ext ) {
	header('Content-Encoding: gzip');
	$content = gzencode( $content, 9, FORCE_GZIP );
}

// Stream to client
echo $content;

// Write file
if ( '' != $cacheKey && is_dir($cache_path) && is_readable($cache_path) ) {	
 /**
  * Gets the contents of the attachment given by it's database identifier from the filesystem 
  * 
  * @param $id integer the database identifier of the attachment
  * @return string the contents of the attachment or null on error
  */
 protected function getAttachmentContentFromFS($id)
 {
     $query = "SELECT file_size,compression_type,file_path " . " FROM {$this->tables['attachments']} WHERE id = {$id}";
     $row = $this->db->fetchFirstRow($query);
     $content = null;
     if ($row) {
         $filePath = $row['file_path'];
         $fileSize = $row['file_size'];
         $destFPath = $this->repositoryPath . DIRECTORY_SEPARATOR . $filePath;
         switch ($row['compression_type']) {
             case TL_REPOSITORY_COMPRESSIONTYPE_NONE:
                 $content = getFileContents($destFPath);
                 break;
             case TL_REPOSITORY_COMPRESSIONTYPE_GZIP:
                 $content = gzip_readFileContent($destFPath, $fileSize);
                 break;
         }
     }
     return $content;
 }
示例#20
0
/**
 * Downloads all user files per user
 * @param int $userId
 * @param array $courseInfo
 * @return bool
 */
function downloadAllFilesPerUser($userId, $courseInfo)
{
    $userInfo = api_get_user_info($userId);

    if (empty($userInfo) || empty($courseInfo)) {
        return false;
    }

    require_once api_get_path(LIBRARY_PATH).'pclzip/pclzip.lib.php';
    $tempZipFile = api_get_path(SYS_ARCHIVE_PATH).api_get_unique_id().".zip";
    $coursePath = api_get_path(SYS_COURSE_PATH).$courseInfo['path'].'/work/';

    $zip  = new PclZip($tempZipFile);

    $workPerUser = getWorkPerUser($userId);

    if (!empty($workPerUser)) {
        $files = array();
        foreach ($workPerUser as $work) {
            $work = $work['work'];
            foreach ($work->user_results as $userResult) {
                if (empty($userResult['url']) || empty($userResult['contains_file'])) {
                    continue;
                }
                $data = getFileContents($userResult['id'], $courseInfo);
                if (!empty($data) && isset($data['path'])) {
                    $files[basename($data['path'])] = array(
                        'title' => $data['title'],
                        'path' => $data['path']
                    );
                }
            }
        }

        if (!empty($files)) {
            Session::write('files', $files);
            foreach ($files as $data) {
                $zip->add(
                    $data['path'],
                    PCLZIP_OPT_REMOVE_PATH,
                    $coursePath,
                    PCLZIP_CB_PRE_ADD,
                    'preAddAllWorkStudentCallback'
                );
            }
        }

        // Start download of created file
        $name = basename(replace_dangerous_char($userInfo['complete_name'])).'.zip';
        event_download($name.'.zip (folder)');
        if (Security::check_abs_path($tempZipFile, api_get_path(SYS_ARCHIVE_PATH))) {
            DocumentManager::file_send_for_download($tempZipFile, true, $name);
            @unlink($tempZipFile);
            exit;
        }
    }
    exit;
}
示例#21
0
foreach ($themes as $theme) {
    $content .= getFileContents("themes/" . $theme . "/editor_template" . $suffix . ".js");
    foreach ($languages as $lang) {
        $content .= getFileContents("themes/" . $theme . "/langs/" . $lang . ".js");
    }
}
// Add plugins
foreach ($plugins as $plugin) {
    $content .= getFileContents("plugins/" . $plugin . "/editor_plugin" . $suffix . ".js");
    foreach ($languages as $lang) {
        $content .= getFileContents("plugins/" . $plugin . "/langs/" . $lang . ".js");
    }
}
// Add custom files
foreach ($custom as $file) {
    $content .= getFileContents($file);
}
// Restore loading functions
if ($core == "true") {
    $content .= "tinyMCE_GZ.end();";
}
// Generate GZIP'd content
if ($supportsGzip && is_writable(dirname($cacheFile))) {
    if ($compress) {
        header("Content-Encoding: " . $enc);
        $cacheData = gzencode($content, 9, FORCE_GZIP);
    } else {
        $cacheData = $content;
    }
    // Write gz file
    if ($diskCache && $cacheKey != "") {
示例#22
0
文件: EPub.php 项目: phpHaxx/PHPePub
 /**
  * Process link tags in a DOMDocument. Linked files will be loaded into the archive, and the link src will be rewritten to point to that location.
  * Link types text/css will be passed as CSS files.
  *
  * @param DOMDocument &$xmlDoc (referenced)
  * @param int    $externalReferences How to handle external references, EPub::EXTERNAL_REF_IGNORE, EPub::EXTERNAL_REF_ADD or EPub::EXTERNAL_REF_REMOVE_IMAGES? Default is EPub::EXTERNAL_REF_ADD.
  * @param string $baseDir  Default is "", meaning it is pointing to the document root.
  * @param string $htmlDir  The path to the parent HTML file's directory from the root of the archive.
  * @param string $backPath The path to get back to the root of the archive from $htmlDir.
  *
  * @return bool  FALSE if uncuccessful (book is finalized or $externalReferences == EXTERNAL_REF_IGNORE).
  */
 protected function processChapterLinks(&$xmlDoc, $externalReferences = EPub::EXTERNAL_REF_ADD, $baseDir = "", $htmlDir = "", $backPath = "")
 {
     if ($this->isFinalized || $externalReferences === EPub::EXTERNAL_REF_IGNORE) {
         return FALSE;
     }
     // process link tags.
     $links = $xmlDoc->getElementsByTagName("link");
     $linkCount = $links->length;
     for ($linkIdx = 0; $linkIdx < $linkCount; $linkIdx++) {
         $link = $links->item($linkIdx);
         $source = $link->attributes->getNamedItem("href")->nodeValue;
         $sourceData = NULL;
         $pathData = pathinfo($source);
         $internalSrc = $pathData['basename'];
         if (preg_match('#^(http|ftp)s?://#i', $source) == 1) {
             $urlinfo = parse_url($source);
             if (strpos($urlinfo['path'], $baseDir . "/") !== FALSE) {
                 $internalSrc = substr($urlinfo['path'], strpos($urlinfo['path'], $baseDir . "/") + strlen($baseDir) + 1);
             }
             @($sourceData = getFileContents($source));
         } else {
             if (strpos($source, "/") === 0) {
                 @($sourceData = file_get_contents($this->docRoot . $source));
             } else {
                 @($sourceData = file_get_contents($this->docRoot . $baseDir . "/" . $source));
             }
         }
         if (!empty($sourceData)) {
             if (!array_key_exists($internalSrc, $this->fileList)) {
                 $mime = $link->attributes->getNamedItem("type")->nodeValue;
                 if (empty($mime)) {
                     $mime = "text/plain";
                 }
                 if ($mime == "text/css") {
                     $this->processCSSExternalReferences($sourceData, $externalReferences, $baseDir, $htmlDir);
                     $this->addCSSFile($internalSrc, $internalSrc, $sourceData, EPub::EXTERNAL_REF_IGNORE, $baseDir);
                     $link->setAttribute("href", $backPath . $internalSrc);
                 } else {
                     $this->addFile($internalSrc, $internalSrc, $sourceData, $mime);
                 }
                 $this->fileList[$internalSrc] = $source;
             } else {
                 $link->setAttribute("href", $backPath . $internalSrc);
             }
         }
         // else do nothing, if the link is local, and missing, assume it's been generated.
     }
     return TRUE;
 }
示例#23
0
// handle proxies..
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
    // Check if it supports gzip
    $encodings = explode(',', strtolower(preg_replace("/\\s+/", '', $_SERVER['HTTP_ACCEPT_ENCODING'])));
}
if (in_array('gzip', $encodings) || in_array('x-gzip', $encodings) || isset($_SERVER['---------------'])) {
    $enc = in_array('x-gzip', $encodings) ? 'x-gzip' : 'gzip';
}
if ($enc && file_exists($filePath) . '.js.gz') {
    header('Content-Encoding: ' . $enc);
    echo getFileContents($filePath . '.js.gz');
    exit;
} else {
    if (file_exists($filePath) . '.js') {
        echo getFileContents($filePath . '.js');
        exit;
    }
}
exit;
//
// private functions
//
function getParam($name, $def = false)
{
    if (!isset($_GET[$name])) {
        return $def;
    }
    return preg_replace("/[^0-9a-z\\-_,\\/]+/i", '', $_GET[$name]);
    // Remove anything but 0-9,a-z,-_
}
示例#24
0
/**
 * Get text from a configured item template for editor objects
 * 
 * @param $itemTemplate identifies a TestLink item that can have
 *        templates that can be loaded when creating an item to semplify
 *        or guide user's work.
 *        $itemTemplate is a property (of type stdClass) of $tlCfg configuration object.
 *
 *        supported values:
 *        testcase_template
 *
 * @param $webEditorName webeditor name, that identifies a propety of $tlCfg->$itemTemplate
 *        that holds input tenmplate configuration
 * 
 * @param $defaultText text to use if:
 *        $tlCfg->itemTemplate OR $tlCfg->itemTemplate->$webEditorName 
 *        does not exists.
 *
 */
function getItemTemplateContents($itemTemplate, $webEditorName, $defaultText = '')
{
    $editorTemplate = config_get($itemTemplate);
    $value = $defaultText;
    if (!is_null($editorTemplate)) {
        if (property_exists($editorTemplate, $webEditorName)) {
            switch ($editorTemplate->{$webEditorName}->type) {
                case 'string':
                    $value = $editorTemplate->{$webEditorName}->value;
                    break;
                case 'string_id':
                    $value = lang_get($editorTemplate->{$webEditorName}->value);
                    break;
                case 'file':
                    $value = getFileContents($editorTemplate->{$webEditorName}->value);
                    if (is_null($value)) {
                        $value = lang_get('problems_trying_to_access_template') . " {$editorTemplate->{$webEditorName}->value} ";
                    }
                    break;
                default:
                    $value = '';
                    break;
            }
        }
    }
    return $value;
}
示例#25
0
function index_url($url, $level, $site_id, $md5sum, $domain, $indexdate, $sessid, $can_leave_domain, $reindex)
{
    global $entities, $min_delay;
    global $command_line;
    global $min_words_per_page;
    global $supdomain;
    global $mysql_table_prefix, $user_agent, $tmp_urls, $delay_time, $domain_arr;
    $needsReindex = 1;
    $deletable = 0;
    $url_status = url_status($url);
    $thislevel = $level - 1;
    if (strstr($url_status['state'], "Relocation")) {
        $url = preg_replace("/ /", "", url_purify($url_status['path'], $url, $can_leave_domain));
        if ($url != '') {
            $result = mysql_query("select link from " . $mysql_table_prefix . "temp where link='{$url}' && id = '{$sessid}'");
            echo mysql_error();
            $rows = mysql_numrows($result);
            if ($rows == 0) {
                mysql_query("insert into " . $mysql_table_prefix . "temp (link, level, id) values ('{$url}', '{$level}', '{$sessid}')");
                echo mysql_error();
            }
        }
        $url_status['state'] == "redirected";
    }
    /*
    		if ($indexdate <> '' && $url_status['date'] <> '') {
    			if ($indexdate > $url_status['date']) {
    				$url_status['state'] = "Date checked. Page contents not changed";
    				$needsReindex = 0;
    			}
    		}*/
    ini_set("user_agent", $user_agent);
    if ($url_status['state'] == 'ok') {
        $OKtoIndex = 1;
        $file_read_error = 0;
        if (time() - $delay_time < $min_delay) {
            sleep($min_delay - (time() - $delay_time));
        }
        $delay_time = time();
        if (!fst_lt_snd(phpversion(), "4.3.0")) {
            $file = file_get_contents($url);
            if ($file === FALSE) {
                $file_read_error = 1;
            }
        } else {
            $fl = @fopen($url, "r");
            if ($fl) {
                while ($buffer = @fgets($fl, 4096)) {
                    $file .= $buffer;
                }
            } else {
                $file_read_error = 1;
            }
            fclose($fl);
        }
        if ($file_read_error) {
            $contents = getFileContents($url);
            $file = $contents['file'];
        }
        $pageSize = number_format(strlen($file) / 1024, 2, ".", "");
        printPageSizeReport($pageSize);
        if ($url_status['content'] != 'text') {
            $file = extract_text($file, $url_status['content']);
        }
        printStandardReport('starting', $command_line);
        $newmd5sum = md5($file);
        if ($md5sum == $newmd5sum) {
            printStandardReport('md5notChanged', $command_line);
            $OKtoIndex = 0;
        } else {
            if (isDuplicateMD5($newmd5sum)) {
                $OKtoIndex = 0;
                printStandardReport('duplicate', $command_line);
            }
        }
        if (($md5sum != $newmd5sum || $reindex == 1) && $OKtoIndex == 1) {
            $urlparts = parse_url($url);
            $newdomain = $urlparts['host'];
            $type = 0;
            /*		if ($newdomain <> $domain)
            					$domainChanged = 1;
            
            				if ($domaincb==1) {
            					$start = strlen($newdomain) - strlen($supdomain);
            					if (substr($newdomain, $start) == $supdomain) {
            						$domainChanged = 0;
            					}
            				}*/
            // remove link to css file
            //get all links from file
            $data = clean_file($file, $url, $url_status['content']);
            if ($data['noindex'] == 1) {
                $OKtoIndex = 0;
                $deletable = 1;
                printStandardReport('metaNoindex', $command_line);
            }
            $wordarray = unique_array(explode(" ", $data['content']));
            if ($data['nofollow'] != 1) {
                $links = get_links($file, $url, $can_leave_domain, $data['base']);
                $links = distinct_array($links);
                $all_links = count($links);
                $numoflinks = 0;
                //if there are any, add to the temp table, but only if there isnt such url already
                if (is_array($links)) {
                    reset($links);
                    while ($thislink = each($links)) {
                        if ($tmp_urls[$thislink[1]] != 1) {
                            $tmp_urls[$thislink[1]] = 1;
                            $numoflinks++;
                            mysql_query("insert into " . $mysql_table_prefix . "temp (link, level, id) values ('{$thislink['1']}', '{$level}', '{$sessid}')");
                            echo mysql_error();
                        }
                    }
                }
            } else {
                printStandardReport('noFollow', $command_line);
            }
            if ($OKtoIndex == 1) {
                $title = $data['title'];
                $host = $data['host'];
                $path = $data['path'];
                $fulltxt = $data['fulltext'];
                $desc = substr($data['description'], 0, 254);
                $url_parts = parse_url($url);
                $domain_for_db = $url_parts['host'];
                if (isset($domain_arr[$domain_for_db])) {
                    $dom_id = $domain_arr[$domain_for_db];
                } else {
                    mysql_query("insert into " . $mysql_table_prefix . "domains (domain) values ('{$domain_for_db}')");
                    $dom_id = mysql_insert_id();
                    $domain_arr[$domain_for_db] = $dom_id;
                }
                $wordarray = calc_weights($wordarray, $title, $host, $path, $data['keywords']);
                //if there are words to index, add the link to the database, get its id, and add the word + their relation
                if (is_array($wordarray) && count($wordarray) > $min_words_per_page) {
                    if ($md5sum == '') {
                        mysql_query("insert into " . $mysql_table_prefix . "links (site_id, url, title, description, fulltxt, indexdate, size, md5sum, level) values ('{$site_id}', '{$url}', '{$title}', '{$desc}', '{$fulltxt}', curdate(), '{$pageSize}', '{$newmd5sum}', {$thislevel})");
                        echo mysql_error();
                        $result = mysql_query("select link_id from " . $mysql_table_prefix . "links where url='{$url}'");
                        echo mysql_error();
                        $row = mysql_fetch_row($result);
                        $link_id = $row[0];
                        save_keywords($wordarray, $link_id, $dom_id);
                        printStandardReport('indexed', $command_line);
                    } else {
                        if ($md5sum != '' && $md5sum != $newmd5sum) {
                            //if page has changed, start updating
                            $result = mysql_query("select link_id from " . $mysql_table_prefix . "links where url='{$url}'");
                            echo mysql_error();
                            $row = mysql_fetch_row($result);
                            $link_id = $row[0];
                            for ($i = 0; $i <= 15; $i++) {
                                $char = dechex($i);
                                mysql_query("delete from " . $mysql_table_prefix . "link_keyword{$char} where link_id={$link_id}");
                                echo mysql_error();
                            }
                            save_keywords($wordarray, $link_id, $dom_id);
                            $query = "update " . $mysql_table_prefix . "links set title='{$title}', description ='{$desc}', fulltxt = '{$fulltxt}', indexdate=now(), size = '{$pageSize}', md5sum='{$newmd5sum}', level={$thislevel} where link_id={$link_id}";
                            mysql_query($query);
                            echo mysql_error();
                            printStandardReport('re-indexed', $command_line);
                        }
                    }
                } else {
                    printStandardReport('minWords', $command_line);
                }
            }
        }
    } else {
        $deletable = 1;
        printUrlStatus($url_status['state'], $command_line);
    }
    if ($reindex == 1 && $deletable == 1) {
        check_for_removal($url);
    } else {
        if ($reindex == 1) {
        }
    }
    if (!isset($all_links)) {
        $all_links = 0;
    }
    if (!isset($numoflinks)) {
        $numoflinks = 0;
    }
    printLinksReport($numoflinks, $all_links, $command_line);
}
示例#26
0
         $APIversion = ZuoraAPIHelper::getAPIVersion($_SESSION['wsdl']);
         $keys = array_keys($SUBSCRIBE_TEMPLATE);
         sort($keys);
         $version = 0.0;
         foreach ($keys as $key) {
            if ($key <= $APIversion) {
                $version = $key;
            } else {
                break;
            }
         }

         #Get template.
         $_SESSION['body'] = "version: " . $version . " call: " . $call . " done.\n";
         if (file_exists($SUBSCRIBE_TEMPLATE[$version][$call])) {
             $_SESSION['body'] = getFileContents($SUBSCRIBE_TEMPLATE[$version][$call]);
         } else {
             $_SESSION['body'] = "<!-- Template is not available for this API version. -->";
         }
      }
   } catch (Exception $e) {
      $_SESSION['body'] = "<!-- Template not available: " . $e->getMessage() . " -->";
   }
}
}
?>

                <table width="99%" border="0" cellpadding="0" cellspacing="0" align="center">
                        <tr>
                                <td>
                                        <table>
示例#27
0
/**
 * refresh extra file (skins.xml/langs.xml)
 * @param sWidget - the name of the widget.
 * @param sCase - skins/langs
 */
function refreshExtraFile($sWidget, $sCase, $bReset = false, $sDefaultFile = "", $aEnabledFiles = array())
{
    global $sModulesPath;
    global $aXmlTemplates;
    global $aErrorCodes;
    //--- Get folder contents ---//
    $sDir = $sWidget . "/" . $sCase;
    $sDirName = $sModulesPath . $sDir;
    if (!(file_exists($sDirName) && is_dir($sDirName))) {
        return parseXml($aXmlTemplates['result'], getError($aErrorCodes[6], $sDir), FAILED_VAL);
    }
    $aFiles = getExtraFiles($sWidget, $sCase, false);
    $iFilesCount = count($aFiles['files']);
    if ($iFilesCount == 0) {
        return array('value' => getError($aErrorCodes[7], $sDir), 'status' => FAILED_VAL, 'contents' => "");
    }
    //--- Get XML file contents ---//
    $aFileContents = getFileContents($sWidget, "/xml/" . $sCase . ".xml", true);
    if ($aFileContents['status'] == FAILED_VAL) {
        return array('value' => $aFileContents['value'], 'status' => FAILED_VAL, 'contents' => "");
    }
    $aContents = $aFileContents['contents'];
    //--- Merge folder and file contents ---//
    $sCurrent = isset($aContents[FILE_DEFAULT_KEY]) && in_array($aContents[FILE_DEFAULT_KEY], $aFiles["files"]) ? $aContents[FILE_DEFAULT_KEY] : $aFiles["current"];
    $sCurrent = $bReset && in_array($sDefaultFile, $aFiles["files"]) ? $sDefaultFile : $sCurrent;
    $aEnabledFiles[] = $sCurrent;
    $sContents = parseXml($aXmlTemplates["item"], FILE_DEFAULT_KEY, $sCurrent);
    for ($i = 0; $i < $iFilesCount; $i++) {
        $sEnabled = isset($aContents[$aFiles["files"][$i]]) ? $aContents[$aFiles["files"][$i]] : TRUE_VAL;
        if ($bReset) {
            $sEnabled = in_array($aFiles["files"][$i], $aEnabledFiles) ? TRUE_VAL : FALSE_VAL;
        }
        $sContents .= parseXml($aXmlTemplates["item"], $aFiles["files"][$i], $sEnabled);
    }
    $sContents = makeGroup($sContents, "items");
    //--- Save changes to the file---//
    $sFile = $sWidget . "/xml/" . $sCase . ".xml";
    $sFileName = $sModulesPath . $sFile;
    $bResult = false;
    if (($rHandle = @fopen($sFileName, "wt")) !== false) {
        $bResult = fwrite($rHandle, $sContents) !== false;
        fclose($rHandle);
    }
    $bResult = $bResult && $rHandle;
    $sValue = $bResult ? "" : getError($aErrorCodes[2], $sFile);
    return array('value' => $sValue, 'status' => $bResult ? SUCCESS_VAL : FAILED_VAL, 'contents' => $sContents);
}
示例#28
0
function check_robot_txt($url)
{
    global $user_agent;
    $urlparts = parse_url($url);
    $url = 'http://' . $urlparts['host'] . "/robots.txt";
    $url_status = url_status($url);
    $omit = array();
    if ($url_status['state'] == "ok") {
        $robot = file($url);
        if (!$robot) {
            $contents = getFileContents($url);
            $file = $contents['file'];
            $robot = explode("\n", $file);
        }
        $regs = array();
        $this_agent = "";
        while (list($id, $line) = each($robot)) {
            if (eregi("^user-agent: *([^#]+) *", $line, $regs)) {
                $this_agent = trim($regs[1]);
                if ($this_agent == '*' || $this_agent == $user_agent) {
                    $check = 1;
                } else {
                    $check = 0;
                }
            }
            if (eregi("disallow: *([^#]+)", $line, $regs) && $check == 1) {
                $disallow_str = eregi_replace("[\n ]+", "", $regs[1]);
                if (trim($disallow_str) != "") {
                    $omit[] = $disallow_str;
                } else {
                    if ($this_agent == '*' || $this_agent == $user_agent) {
                        return null;
                    }
                }
            }
        }
    }
    return $omit;
}
示例#29
0
/**
 * get extra files for module in XML format
 * @param $sModule - module name
 * @param $sFolder - folder name for which value is set
 * @param $bGetDate - get dates of files
 * @return $sContents - XML formatted result
 */
function printFiles($sModule, $sFolder = "langs", $bGetDate = false, $bGetNames = false)
{
    global $sIncPath;
    global $sModulesUrl;
    require_once $sIncPath . "xmlTemplates.inc.php";
    $aFileContents = getFileContents($sModule, "/xml/" . $sFolder . ".xml", true);
    $aFiles = $aFileContents['contents'];
    $aEnabledFiles = array();
    foreach ($aFiles as $sFile => $sEnabled) {
        if ($sEnabled == TRUE_VAL) {
            $aEnabledFiles[] = $sFile;
        }
    }
    $sDefault = $aFiles['_default_'];
    $aResult = getExtraFiles($sModule, $sFolder, true, $bGetDate);
    $sCurrent = $aResult['current'];
    $sCurrent = in_array($sCurrent, $aEnabledFiles) ? $sCurrent : $sDefault;
    $sCurrentFile = $sCurrent . "." . $aResult['extension'];
    $aRealFiles = array_flip($aResult['files']);
    $aFileDates = $aResult['dates'];
    $sContents = "";
    for ($i = 0; $i < count($aEnabledFiles); $i++) {
        if (isset($aRealFiles[$aEnabledFiles[$i]])) {
            $sFile = $aEnabledFiles[$i];
            if ($bGetDate) {
                $sContents .= parseXml($aXmlTemplates['file'], $sFile, $aFileDates[$aRealFiles[$sFile]]);
            } else {
                if ($bGetNames) {
                    $sName = $sFolder == "langs" ? getSettingValue($sModule, "_name_", $sFile, false, "langs") : getSettingValue($sModule, $sFile, "skinsNames");
                    if (empty($sName)) {
                        $sName = $sFile;
                    }
                    $sContents .= parseXml($aXmlTemplates['file'], $sFile, $sName, "");
                } else {
                    $sContents .= parseXml($aXmlTemplates['file'], $sFile);
                }
            }
        }
    }
    $sContents = makeGroup($sContents, "files");
    $sContents .= parseXml($aXmlTemplates['current'], $sCurrent, $sModulesUrl . $sModule . "/" . $sFolder . "/" . $sCurrentFile);
    return $sContents;
}
示例#30
-6
文件: spider.php 项目: pwh/scrutiny
function index_url($url, $level, $site_id, $md5sum, $domain, $indexdate, $sessid, $can_leave_domain, $reindex)
{
    global $tmp_urls, $delay_time, $domain_arr, $charSet, $url_status, $whitelist, $blacklist, $supdomain, $smp, $realnum, $dup_url, $entities, $command_line;
    if (DEBUG == '0') {
        error_reporting(0);
    } else {
        error_reporting(E_ERROR);
        //  otherwise  a non existing siemap.xml  would always cause a warning message
    }
    $needsReindex = 1;
    $deletable = 0;
    $url_status = url_status($url);
    $thislevel = $level - 1;
    if ($smp != 1 && Configure::read('follow_sitemap') == 1) {
        //  enter here if we don't already know a valid sitemap and if admin settings allowed us to do so
        $tmp_urls = get_temp_urls($sessid);
        //  reload previous temp
        $url2 = remove_sessid(convert_url($url));
        // get folder where sitemap should be and if exists, cut existing filename, suffix and subfolder
        //                Configure::read('local') = "http://localhost/publizieren/";   //  your base adress for your local server
        $sitemap_name = "sitemap.xml";
        //  could be individualized
        $host = parse_url($url2);
        $hostname = $host[host];
        if ($hostname == 'localhost') {
            $host1 = str_replace(Configure::read('local'), '', $url2);
        }
        $pos = strpos($host1, "/");
        //      on local server delete all behind the /
        if ($pos) {
            $host1 = substr($host1, 0, $pos);
        }
        //      build full adress again, now only until host
        if ($hostname == 'localhost') {
            $url2 = Configure::read('local') . $host1;
        } else {
            $url2 = "{$host['scheme']}://{$hostname}";
        }
        $input_file = "{$url2}/{$sitemap_name}";
        // create path to sitemap
        if ($handle = fopen($input_file, "r")) {
            // happy times, we found a new sitemap
            $links = get_sitemap($input_file, TABLE_PREFIX);
            // now extract links from sitemap.xml
            if ($links != '') {
                //  if links were extracted from sitemap.xml
                reset($links);
                while ($thislink = each($links)) {
                    //  check if we already know this link as a site url
                    $result = mysql_query("select url from " . TABLE_PREFIX . "sites where url like '{$thislink['1']}%'");
                    if (DEBUG > '0') {
                        echo mysql_error();
                    }
                    $rows = mysql_num_rows($result);
                    if ($rows == '0') {
                        // for all new links: save in temp table
                        mysql_query("insert into " . TABLE_PREFIX . "temp (link, level, id) values ('{$thislink['1']}', '{$level}', '{$sessid}')");
                        if (DEBUG > '0') {
                            echo mysql_error();
                        }
                    }
                }
                clean_resource($result);
                $smp = '1';
                //     there was a valid sitemap and we stored the new links
            }
            unset($links, $input_file);
            fclose($handle);
        }
    }
    if (strstr($url_status['state'], "Relocation")) {
        $url = eregi_replace(" ", "", url_purify($url_status['path'], $url, $can_leave_domain));
        if ($url != '') {
            $result = mysql_query("select link from " . TABLE_PREFIX . "temp where link='{$url}' && id = '{$sessid}'");
            if (DEBUG > '0') {
                echo mysql_error();
            }
            $rows = mysql_num_rows($result);
            if ($rows == 0) {
                mysql_query("insert into " . TABLE_PREFIX . "temp (link, level, id) values ('{$url}', '{$level}', '{$sessid}')");
                if (DEBUG > '0') {
                    echo mysql_error();
                }
            }
            clean_resource($result);
        }
        $url_status['state'] == "redirected";
    }
    ini_set("user_agent", Configure::read('user_agent'));
    if ($url_status['state'] == 'ok') {
        $OKtoIndex = 1;
        $file_read_error = 0;
        if (time() - $delay_time < Configure::read('min_delay')) {
            sleep(Configure::read('min_delay') - (time() - $delay_time));
        }
        $delay_time = time();
        if (!fst_lt_snd(phpversion(), "4.3.0")) {
            $file = file_get_contents($url);
            if ($file === FALSE) {
                $file_read_error = 1;
            }
        } else {
            $fl = @fopen($url, "r");
            if ($fl) {
                while ($buffer = @fgets($fl, 4096)) {
                    $file .= $buffer;
                }
                unset($buffer);
            } else {
                $file_read_error = 1;
            }
            fclose($fl);
        }
        if ($file_read_error || Configure::read('utf8') == 1) {
            unset($file);
            $contents = getFileContents($url);
            // parse_url to get charset
            $file = $contents['file'];
        }
        $pageSize = number_format(strlen($file) / 1024, 2, ".", "");
        printPageSizeReport($pageSize);
        if ($url_status['content'] != 'text') {
            $file = extract_text($file, $url_status['content']);
            //for DOCs, PDFs etc we need special converter
            if ($file == 'ERROR') {
                //      if error, suppress further indexing
                $OKtoIndex = 0;
                $file_read_error = 1;
            }
        }
        if (Configure::read('utf8') == 1) {
            //   enter here if file should be translated into utf-8
            $charSet = $contents['charset'];
            if ($charSet == '') {
                // if we did not find any charset, we will use our own
                $charSet = Configure::read('home_charset');
            }
            $charSet = strtoupper(trim($charSet));
            if (strpos($charSet, '8859')) {
                $conv_file = html_entity_decode($file);
            } else {
                $conv_file = $file;
                //  pure code
            }
            if ($charSet != "UTF-8") {
                //  enter here only, if site / file is not jet UTF-8 coded
                $iconv_file = iconv($charSet, "UTF-8", $conv_file);
                //      if installed, first try to use PHP function iconv
                if (trim($iconv_file) == "") {
                    // iconv is not installed or input charSet not available. We need to use class ConvertCharset
                    $charSet = str_ireplace('iso-', '', $charSet);
                    $charSet = str_ireplace('iso', '', $charSet);
                    $NewEncoding = new ConvertCharset($charSet, "utf-8");
                    $NewFileOutput = $NewEncoding->Convert($conv_file);
                    $file = $NewFileOutput;
                } else {
                    $file = $iconv_file;
                }
                unset($conv_file, $iconv_file, $NewEncoding, $NewFileOutput);
            }
        }
        $data = clean_file($file, $url, $url_status['content']);
        $newmd5sum = md5($data['content']);
        if ($md5sum == $newmd5sum) {
            printStandardReport('md5notChanged', $command_line);
            $OKtoIndex = 0;
            $realnum--;
        } else {
            if (Configure::read('use_white') == '1') {
                $found = '0';
                //  check if content of page matches any word in whitelist
                foreach ($whitelist as $key => $value) {
                    $met = stripos($file, $value);
                    if ($met) {
                        $found = '1';
                    }
                }
                if ($found == '0') {
                    printStandardReport('noWhitelist', $command_line);
                    $OKtoIndex = 0;
                    $realnum--;
                }
            }
            if (Configure::read('use_black') == '1') {
                $found = '0';
                //  check if content of page matches any word in blacklist
                foreach ($blacklist as $key => $value) {
                    $met = stripos($file, $value);
                    if ($met) {
                        $found = '1';
                    }
                }
                if ($found == '1') {
                    printStandardReport('matchBlacklist', $command_line);
                    $OKtoIndex = 0;
                    $realnum--;
                }
            }
            //     check for duplicate page content
            $result = mysql_query("select link_id from " . TABLE_PREFIX . "links where md5sum='{$newmd5sum}'");
            if (DEBUG > '0') {
                echo mysql_error();
            }
            if (mysql_num_rows($result) > 0) {
                //  display warning message and urls with duplicate content
                printStandardReport('duplicate', $command_line);
                $num_rows = mysql_num_rows($result);
                for ($i = 0; $i < $num_rows; $i++) {
                    $link_id = mysql_result($result, $i, "link_id");
                    $num = $i + 1;
                    $res = mysql_query("select url from " . TABLE_PREFIX . "links where link_id like '{$link_id}'");
                    if (DEBUG > '0') {
                        echo mysql_error();
                    }
                    $row = mysql_fetch_row($res);
                    $dup_url = $row[0];
                    clean_resource($res);
                    printDupReport($dup_url, $command_line);
                }
                if (Configure::read('dup_content') == '0') {
                    //  enter here, if pages with duplicate content should not be indexed/re-indexed
                    $OKtoIndex = 0;
                    $realnum--;
                } else {
                    $OKtoIndex = 1;
                }
            }
        }
        if (($md5sum != $newmd5sum || $reindex == 1) && $OKtoIndex == 1) {
            $urlparts = parse_url($url);
            $newdomain = $urlparts['host'];
            $type = 0;
            if ($data['noindex'] == 1) {
                $OKtoIndex = 0;
                $deletable = 1;
                printStandardReport('metaNoindex', $command_line);
            }
            if (Configure::read('use_white') == '1') {
                $found = '0';
                //  check if content of page matches any word in whitelist
                foreach ($whitelist as $key => $value) {
                    $met = stripos($data[fulltext], $value);
                    if ($met) {
                        $found = '1';
                    }
                }
                if ($found == '0') {
                    printStandardReport('noWhitelist', $command_line);
                    $OKtoIndex = 0;
                    $realnum--;
                }
            }
            if (Configure::read('use_black') == '1') {
                $found = '0';
                //  check if content of page matches any word in blacklist
                foreach ($blacklist as $key => $value) {
                    $met = stripos($data[fulltext], $value);
                    if ($met) {
                        $found = '1';
                    }
                }
                if ($found == '1') {
                    printStandardReport('matchBlacklist', $command_line);
                    $OKtoIndex = 0;
                    $realnum--;
                }
            }
            $wordarray = unique_array(explode(" ", $data['content']));
            if ($smp != 1) {
                if ($data['nofollow'] != 1) {
                    $links = get_links($file, $url, $can_leave_domain, $data['base']);
                    $links = distinct_array($links);
                    $all_links = count($links);
                    if ($all_links > Configure::read('max_links')) {
                        $all_links = Configure::read('max_links');
                    }
                    $links = array_slice($links, 0, Configure::read('max_links'));
                    if ($realnum < Configure::read('max_links')) {
                        $numoflinks = 0;
                        //if there are any, add to the temp table, but only if there isnt such url already
                        if (is_array($links)) {
                            reset($links);
                            if (DEBUG == '2') {
                                //  if debug mode, show details
                                printStandardReport('newLinks', $command_line);
                            }
                            while ($thislink = each($links)) {
                                if ($tmp_urls[$thislink[1]] != 1) {
                                    $tmp_urls[$thislink[1]] = 1;
                                    $numoflinks++;
                                    if (DEBUG == '2') {
                                        $act_link = $thislink[1];
                                        printNewLinks($act_link);
                                    }
                                    if ($numoflinks <= Configure::read('max_links')) {
                                        mysql_query("insert into " . TABLE_PREFIX . "temp (link, level, id) values ('{$thislink['1']}', '{$level}', '{$sessid}')");
                                    }
                                    if (DEBUG > '0') {
                                        echo mysql_error();
                                    }
                                }
                            }
                        }
                    }
                } else {
                    printStandardReport('noFollow', $command_line);
                }
                unset($file);
            }
            if ($OKtoIndex == 1) {
                if (Configure::read('link_check') == 0) {
                    $title = $data['title'];
                    $host = $data['host'];
                    $path = $data['path'];
                    $fulltxt = $data['fulltext'];
                    $desc = substr($data['description'], 0, 254);
                    $url_parts = parse_url($url);
                    $domain_for_db = $url_parts['host'];
                    if (isset($domain_arr[$domain_for_db])) {
                        $dom_id = $domain_arr[$domain_for_db];
                    } else {
                        mysql_query("insert into " . TABLE_PREFIX . "domains (domain) values ('{$domain_for_db}')");
                        $dom_id = mysql_insert_id();
                        $domain_arr[$domain_for_db] = $dom_id;
                    }
                    $wordarray = calc_weights($wordarray, $title, $host, $path, $data['keywords'], $url_parts);
                    //if there are words to index, add the link to the database, get its id, and add the word + their relation
                    if (is_array($wordarray) && count($wordarray) > Configure::read('min_words_per_page')) {
                        if ($md5sum == '') {
                            mysql_query("insert into " . TABLE_PREFIX . "links (site_id, url, title, description, fulltxt, indexdate, size, md5sum, level) values ('{$site_id}', '{$url}', '{$title}', '{$desc}', '{$fulltxt}', curdate(), '{$pageSize}', '{$newmd5sum}', {$thislevel})");
                            if (DEBUG > '0') {
                                echo mysql_error();
                            }
                            $result = mysql_query("select link_id from " . TABLE_PREFIX . "links where url='{$url}'");
                            if (DEBUG > '0') {
                                echo mysql_error();
                            }
                            $row = mysql_fetch_row($result);
                            $link_id = $row[0];
                            clean_resource($result);
                            if (DEBUG == '2') {
                                //  if debug mode, show details
                                printStandardReport('newKeywords', $command_line);
                            }
                            save_keywords($wordarray, $link_id, $dom_id);
                            if (DEBUG == '2') {
                                printStandardReport('indexed1', $command_line);
                            } else {
                                printStandardReport('indexed', $command_line);
                            }
                        } else {
                            if ($md5sum != '' && $md5sum != $newmd5sum) {
                                //if page has changed, start updating
                                $result = mysql_query("select link_id from " . TABLE_PREFIX . "links where url='{$url}'");
                                if (DEBUG > '0') {
                                    echo mysql_error();
                                }
                                $row = mysql_fetch_row($result);
                                $link_id = $row[0];
                                for ($i = 0; $i <= 15; $i++) {
                                    $char = dechex($i);
                                    mysql_query("delete from " . TABLE_PREFIX . "link_keyword{$char} where link_id={$link_id}");
                                    if (DEBUG > '0') {
                                        echo mysql_error();
                                    }
                                }
                                clean_resource($result);
                                if (DEBUG == '2') {
                                    //  if debug mode, show details
                                    printStandardReport('newKeywords', $command_line);
                                }
                                save_keywords($wordarray, $link_id, $dom_id);
                                $query = "update " . TABLE_PREFIX . "links set title='{$title}', description ='{$desc}', fulltxt = '{$fulltxt}', indexdate=now(), size = '{$pageSize}', md5sum='{$newmd5sum}', level={$thislevel} where link_id={$link_id}";
                                mysql_query($query);
                                if (DEBUG > '0') {
                                    echo mysql_error();
                                }
                                if (DEBUG == '2') {
                                    printStandardReport('re-indexed1', $command_line);
                                } else {
                                    printStandardReport('re-indexed', $command_line);
                                }
                            }
                        }
                    } else {
                        printStandardReport('minWords', $command_line);
                        $realnum--;
                    }
                } else {
                    printStandardReport('link_okay', $command_line);
                }
                unset($wordarray, $title, $fulltxt, $desc);
            }
        }
    } else {
        $deletable = 1;
        printUrlStatus($url_status['state'], $command_line);
    }
    if ($reindex == 1 && $deletable == 1) {
        check_for_removal($url);
    } else {
        if ($reindex == 1) {
        }
    }
    if (!isset($all_links)) {
        $all_links = 0;
    }
    if (!isset($numoflinks)) {
        $numoflinks = 0;
    }
    if ($smp != 1) {
        //      if valid sitemap found, no LinkReport
        printLinksReport($numoflinks, $all_links, $command_line);
    }
}