コード例 #1
0
ファイル: playGame.php プロジェクト: namank/Connect4
function gameOver($board)
{		
	for ($i=ord('5'); $i>=ord('3'); $i--)
	{
		// /
		for ($j=ord('0'); $j<=ord('3');$j++)
		{
			$cur = $board[getPos(chr($i),chr($j))];			
			if (($cur != '0') && ($cur == $board[getPos(chr($i-1),chr($j+1))]) && ($cur == $board[getPos(chr($i-2),chr($j+2))]) && ($cur == $board[getPos(chr($i-3),chr($j+3))]))
			{
				return $cur;
			}			
		}
		
		// \
		for ($j=ord('6'); $j>=ord('3');$j--)
		{
			$cur = $board[getPos(chr($i),chr($j))];
			if (($cur != '0') && ($cur == $board[getPos(chr($i-1),chr($j-1))]) && ($cur == $board[getPos(chr($i-2),chr($j-2))]) && ($cur == $board[getPos(chr($i-3),chr($j-3))]))
			{
				return $cur;
			}		
		}
		
		// |
		for ($j=ord('0'); $j<=ord('6');$j++)
		{
			$cur = $board[getPos(chr($i),chr($j))];
			if (($cur != '0') && ($cur == $board[getPos(chr($i-1),chr($j))]) && ($cur == $board[getPos(chr($i-2),chr($j))]) && ($cur == $board[getPos(chr($i-3),chr($j))]))
			{
				return $cur;
			}			
		}
	}
	
	// - 
	for ($i=ord('5'); $i>=ord('0'); $i--)
	{
		for ($j=ord('0'); $j<=ord('3');$j++)
		{
			$cur = $board[getPos(chr($i),chr($j))];
			if (($cur != '0') && ($cur == $board[getPos(chr($i),chr($j+1))]) && ($cur == $board[getPos(chr($i),chr($j+2))]) && ($cur == $board[getPos(chr($i),chr($j+3))]))
			{
				return $cur;
			}
		}
	}
	
	return '0';
}
コード例 #2
0
ファイル: parse_huge_rss.php プロジェクト: arh922/ain
/**
 * This function will return the first string it could find in a resource that matches the $string.
 *
 * By using a $startFrom it recurses and seeks $chunk bytes at a time to avoid reading the 
 * whole file at once.
 * 
 * @param resource $handle - typically a file handle
 * @param string $string - what string to search for
 * @param int $startFrom - strpos to start searching from
 * @param int $chunk - chunk to read before rereading again
 * @return int|bool - Will return false if there are EOL or errors
 */
function getPos($handle, $string, $startFrom = 0, $chunk = 1024, $prev = '')
{
    // Set the file cursor on the startFrom position
    fseek($handle, $startFrom, SEEK_SET);
    // Read data
    $data = fread($handle, $chunk);
    // Try to find the search $string in this chunk
    $stringPos = mb_strpos($prev . $data, $string);
    // We found the string, return the position
    if ($stringPos !== false) {
        return $stringPos + $startFrom - mb_strlen($prev);
    }
    // We reached the end of the file
    if (feof($handle)) {
        return false;
    }
    // Recurse to read more data until we find the search $string it or run out of disk
    return getPos($handle, $string, $chunk + $startFrom, $chunk, $data);
}
コード例 #3
0
ファイル: generatePayroll.php プロジェクト: rdnjm/ici
include 'needs/connString.php';
include 'func/functions.php';
?>
<!DOCTYPE html>
<html>
	<head>
		<title>Payroll Generation</title>
		<meta name="viewport" content = "width=device-width, initial-scale=1.0">
		<link rel='stylesheet' type='text/css' href='css/bootstrap.css'>
	</head>
	
	<body>
		<?php 
if (isset($_SESSION['posCode'])) {
    accessType();
    echo getPos();
    ?>
			
				<div class='container'>
					<div class='row'>						
						<div id='view'>
						</div>
					</div>
				</div>

			<?php 
}
if (isset($_GET['view'])) {
} else {
    header("LOCATION: login.php");
}
コード例 #4
0
function dbGetAndStoreMacroPattern(&$session)
{
    $session->trace(TC_Db2, 'dbGetAndStoreMacroPattern:');
    $theme = $session->fUserTheme;
    $pattern = dbGetParam($session, $theme, Th_MacroPattern);
    if (empty($pattern)) {
        $row = dbFirstRecord($session, 'select name from ' . dbTable($session, T_Macro) . ' where theme=' . Theme_All . ' or theme=' . ($theme + 0) . ' order by name');
        $last_var = null;
        $open_parenthesis = false;
        while ($row) {
            $pos = strpos($row[0], ':');
            if ($pos <= 0) {
                $val = $row[0];
                $var = null;
            } else {
                $var = substr($row[0], 0, $pos + 1);
                $val = substr($row[0], $pos + 1);
            }
            $session->trace(TC_Db3, 'dbGetAndStoreMacroPattern-2: ' . $pos . ' ' . $var . ' / ' . $val);
            if ($var != $last_var) {
                $session->trace(TC_Db2, 'dbGetAndStoreMacroPattern-3: ');
                if ($open_parenthesis) {
                    $session->trace(TC_Db2, 'dbGetAndStoreMacroPattern-4: ');
                    $pattern .= ')';
                    $open_parenthesis = false;
                }
                $last_var = $var;
                if (!empty($var)) {
                    $session->trace(TC_Db2, 'dbGetAndStoreMacroPattern-5: ' . $pattern);
                    $val = $var . '(' . $val;
                    $open_parenthesis = true;
                }
            }
            $new = '|' . $val;
            if (getPos($pattern, $new . '|') < 0) {
                $pattern .= $new;
            }
            $row = dbNextRecord($session);
        }
        if ($open_parenthesis) {
            $pattern .= ')';
        }
        $id = dbSingleValue($session, 'select id from ' . dbTable($session, T_Param) . ' where theme=' . (0 + $theme) . ' and pos=' . Th_MacroPattern);
        if ($id > 0) {
            dbUpdateRaw($session, T_Param, $id, 'text=' . dbSqlString($session, $pattern));
            $session->trace(TC_Db1, "dbGetAndStoreMacroPattern: Id: {$id} Th: {$theme} P: {$pattern}");
        }
    }
    return $pattern;
}
コード例 #5
0
function stripPhpSource(&$session, $fn_source, $fn_target)
{
    $message = null;
    if (!($file = fopen($fn_source, "r"))) {
        $message = "+++ Kann Datei nicht öffnen: {$fn_source}";
    } else {
        $lines = array();
        $line_count = $old_size = $new_size = 0;
        $comment = false;
        while ($line = fgets($file)) {
            $line_count++;
            $old_size += strlen($line);
            if ($comment) {
                if (($pos = getPos($line, '*/')) >= 0) {
                    $line = substr($line, $pos + 2);
                    $comment = false;
                } else {
                    $line = "\n";
                }
            }
            // comment
            $line = preg_replace('/^[ \\t]+/', '', $line);
            $line = preg_replace('/\\s+$/', "\n", $line);
            if (preg_match("!^([^\"']*)(//|#)!", $line, $match)) {
                $line = $match[1] . "\n";
            }
            # $session->trace (TC_X, 'Zeile: ' . $line);
            if (getPos($line, "'") < 0 && getPos($line, '"') < 0) {
                # $session->trace (TC_X, '1: ' . $line);
                $line = preg_replace('|\\s*/\\*.*?\\*/\\s*|', ' ', $line);
                # $session->trace (TC_X, '2: ' . $line);
                if (($pos = getPos($line, '/*')) >= 0) {
                    $line = ($pos > 0 ? substr($line, 0, $pos) : '') . "\n";
                    $comment = true;
                }
            }
            if (preg_match('/->trace\\b.*;\\s*$/', $line) && !preg_match('/TC_(Warning|Error)/', $line)) {
                $line = "\n";
            }
            array_push($lines, $line);
            $new_size += strlen($line);
        }
        // while
        fclose($file);
        if ($comment) {
            $message = "Kommentar offen";
        } else {
            $diff = $old_size - $new_size;
            $message = $fn_source . ': ' . $diff . " Zeichen entfernt (" . ($old_size == 0 ? 0 : round(100 * $diff / $old_size)) . '%)';
            if (!($file = fopen($fn_target, "w"))) {
                $message = "+++ Kann Datei nicht öffnen: {$fn_target}";
            } else {
                for ($ii = 0; $ii < $line_count; $ii++) {
                    fwrite($file, $lines[$ii]);
                }
                fclose($file);
            }
            // $no_comment
        }
    }
    return $message;
}
コード例 #6
0
function baseEditPageAnswerNoSave(&$session)
{
    $session->trace(TC_Gui1, 'baseEditPageAnswerNoSave');
    if (isset($_POST['edit_cancel'])) {
        if (isset($_POST['edit_pageid']) && $_POST['edit_pageid'] > 0) {
            guiShowPageById($session, $_POST['edit_pageid'], 0);
        } else {
            baseHome($session, null);
        }
    } else {
        $message = null;
        if (isset($_POST['edit_preview'])) {
        } elseif (isset($_POST['edit_appendtemplate'])) {
            $page_id = dbPageId($session, $_POST['edit_template']);
            if ($page_id > 0) {
                $id = dbGetLastText($session, $page_id);
                $_POST['edit_content'] .= dbSingleValue($session, 'select text from ' . dbTable($session, T_Text) . ' where id=' . (0 + $id));
            }
        } elseif (isset($_POST['edit_upload'])) {
            $session->trace(TC_Gui1, 'guiEditPageSaveAnswer:');
            $message = guiUploadFileAnswerUnique($session, 'edit_upload', '/pic/', $name);
            if ($message == null || getPos($message, '+++') != 0) {
                $_POST['edit_content'] .= "\n\nhttp:pic/{$name}\n\n";
            }
        }
        baseEditPage($session, C_LastMode, $message, null, $_POST['edit_mimetype']);
    }
}
コード例 #7
0
 function replaceMacrosNoHTML($text)
 {
     $this->trace(TC_Session2, 'replaceMacrosNoHTML: ' . strlen($this->fMacroPattern) . ' ' . $text);
     $count = 0;
     $again = ($pos = strpos($text, Macro_Char)) >= 0 && is_int($pos);
     // Mehrfache Durchlaeufe, da Macros selber Macros enthalten koennen:
     if (strpos($text, "<div>Titel:") > 0) {
         $this->trace(TC_Session3, "replaceMacrosNoHTML-1:" . $this->fMacroPattern);
     }
     while ($again) {
         $again = false;
         if (getPos($text, Macro_Char) >= 0) {
             $this->trace(TC_Session3, 'replaceMacrosNoHTML-2: ' . $text);
             $old_text = $text;
             $text = '';
             // $this->fMacroPattern = '/^((\s|.)*?)\[(macro1|...macroX)\]/';
             $no_found = 0;
             $time = microtime();
             while (strlen($old_text) > 2 && preg_match($this->fMacroPattern, $old_text, $match)) {
                 if (microtime() - $time > 0.2) {
                     $this->trace(TC_Session3, 'replaceMacrosNoHTML-X2: ' . $this->fMacroPattern . " OldText: " . $old_text);
                 }
                 $time = microtime();
                 $this->trace(TC_Session3, 'replaceMacrosNoHTML-3: ' . dumpArray($match, 'match', 1));
                 $again = true;
                 $text .= $match[1] . $this->getMacro($match[3]);
                 $this->trace(TC_Session3, 'replaceMacrosNoHTML-4: ' . $old_text);
                 $old_text = substr($old_text, strlen($match[1]) + strlen($match[3]) + 2);
                 if (++$no_found > 20) {
                     $this->trace(TC_WARNING, "mehr als 20 Makros");
                     $again = false;
                     break;
                 }
             }
             // while strlen() > 2...
             if (microtime() - $time > 0.2) {
                 $this->trace(TC_Session3, 'replaceMacrosNoHTML-X3: ' . $this->fMacroPattern . " OldText: " . $old_text);
             }
             $this->trace(TC_Session3, 'replaceMacrosNoHTML-5: ' . $no_found . " #: " . count($match));
             $text .= $old_text;
             if (++$count > 6) {
                 $this->trace(TC_Session3, 'replaceMacrosNoHTML-6: ');
                 $macroname = substr($text, $pos, 20);
                 $this->trace(TC_Error, 'replaceMacrosNoHTML: zu verschachtelt (6): Pos: ' . $pos . " Macro: {$macroname} Text: {$text}");
                 break;
             }
             $this->trace(TC_Session3, 'replaceMacrosNoHTML-7: ');
         }
         // getPos (MACRO_CHAR) > 0
         $this->trace(TC_Session3, 'replaceMacrosNoHTML-8: ');
     }
     // while $again
     $this->trace(TC_Session2, 'replaceMacrosNoHTML-e: ' . $text);
     return $text;
 }
コード例 #8
0
ファイル: util.php プロジェクト: BackupTheBerlios/infobasar
function writeText($body, &$status)
{
    $status->trace(TC_Util2, "writeText: {$body}");
    $count = 0;
    while (strlen($body) > 0 && preg_match(IB_REG_EXPR, $body, $match)) {
        $args = count($match);
        $count++;
        if ($match[1] != '') {
            echo htmlentities($match[1]);
        }
        #$status->trace (TC_X, "writeText-2:" . dumpArray ($match, 'match', 2));
        // Alle Ausdrücke ohne Klammern:
        if ($args == 3) {
            switch ($match[2]) {
                case '__':
                    $status->handleEmphasis('u');
                    break;
                case '\'\'':
                    $status->handleEmphasis('i');
                    break;
                case '\'\'\'':
                    $status->handleEmphasis('b');
                    break;
                case '\'\'\'\'':
                    $status->handleEmphasis('x');
                    break;
                case '%%%':
                    outNewline();
                    break;
                default:
                    if (strpos($match[2], "hex(") == 1) {
                        for ($ii = 5; $ii < strlen($match[2]) - 1; $ii++) {
                            printf("%02x ", ord(substr($match[2], $ii, 1)));
                        }
                    } elseif (getPos($match[2], '[[') == 0) {
                        if (strlen($match[2]) == 5) {
                            echo substr($match[2], 2, 1);
                        } else {
                            writeExternLink(substr($match[2], 2, strlen($match[2]) - 4), null, true, $status);
                        }
                    } else {
                        echo htmlentities($match[2]);
                    }
            }
        } else {
            if ($args == 9) {
                writeWikiName($match[7], substr($match[8], 1), $status);
            } elseif ($args == 8) {
                writeWikiName($match[7], null, $status);
            } elseif ($args == 5) {
                // Direkter Verweis (ohne [[]]:
                writeExternLink($match[2], null, false, $status);
            } elseif ($args == 4) {
                // [[Verweis]]:
                $len = strpos($match[2], '|') - 2;
                writeExternLink(substr($match[2], 2, $len > 0 ? $len : strlen($match[2])), substr($match[3], 1), true, $status);
            } elseif ($args == 6) {
                // (Nicht-)Wikiname
                writeWikiName($match[2], null, $status);
            } elseif ($args == 7) {
                switch ($match[6]) {
                    case 'newline':
                        echo '<br />';
                        break;
                    case 'big':
                    case '/big':
                    case 'small':
                    case '/small':
                    case 'sub':
                    case '/sub':
                    case 'sup':
                    case '/sup':
                    case 'tt':
                    case '/tt':
                        echo TAG_PREFIX;
                        echo $match[6];
                        echo TAG_SUFFIX;
                        break;
                    case 'subscript':
                        echo TAG_SUB;
                        break;
                    case 'superscript':
                        echo TAG_SUP;
                        break;
                    case '/subscript':
                        echo TAG_SUP_END;
                        break;
                    case '/superscript':
                        echo TAG_SUP_END;
                        break;
                    case '/teletype':
                        echo TAG_TT;
                        break;
                    case 'teletype':
                        echo TAG_TT_END;
                        break;
                    default:
                        echo $match[2];
                        break;
                }
            } elseif ($args == 11) {
                writePlugin($match[9], $match[10], $status);
            } else {
                echo $match[2];
            }
        }
        // args != 3
        $body = substr($body, strlen($match[1]) + strlen($match[2]));
    }
    if ($body != '') {
        echo $status->fSession->replaceMacrosHTML(htmlentities($status->fSession->replaceMacrosNoHTML($body)));
    }
}