Jump to content

erdem

Members
  • Posts

    33
  • Joined

  • Last visited

    Never

Everything posted by erdem

  1. <?php $sql = mysql_query("SELECT * FROM table"); while($ROW = mysql_fetch_array($sql)){ if($ROW['li_number'] == 12) $class = 'class="active"'; elseif($ROW['li_number'] >= 13) $class = 'class="no"'; else $class = ''; echo '<li id="b'.$ROW['li_number'].'" '.$class.'></li>'; } ?>
  2. Hi Guys, Happy new year to all!! I'm trying to make starcraft 2 tournament web site for me and friends. i stuck on tournament system. I have a jquery script that makes a bracket but I couldn't figure out how can I implament it with my database and php:( I would like to ask you some questions please. I have this html and jquery script. my mysql database is like this tournamenttree id - UserID - TournamentID - Round 1 - 1 - 1 - 1 2 - 15 - 1 - 1 3 - 17 - 1 - 1 4 - 25 - 1 - 1 and tournaments id - tournamentname - createdtime - players - active 1 -Sunday Cup - time() - 4 - 1 and Users table <?php $link = mysql_connect( '', ', ' ); if ( !is_resource( $link ) ) die( 'MySQL Connect Error' ); if ( !mysql_select_db( 'db6968_game', $link ) ) die( 'MySQL DB Error' ); mysql_query( "SET CHARACTER SET UTF8" ); mysql_query( "SET collation_connection = 'utf8_turkish_ci'" ); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us"> <head> <title>MyTournamentName</title> <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js' type='text/javascript'> </script> <script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js' type='text/javascript'> </script> <style type="text/css"> .tournament { background-color: #F0F0F0; border: dashed 1px solid; overflow: auto; } .tournament .bracket { background-color: #DFDFDF; min-width: 100px; vertical-align: top; float: left; } .tournament .bracket .match { background-color: #D0D0D0; border-top: 1px solid; border-right: 1px solid; border-bottom: 1px solid; } .tournament .bracket .match .p1 { height: 20px; } .tournament .bracket .match .p2 { height: 20px; } .tournament .bracket .match .spacer { background-color: #DFDFDF; height: 38px; } .tournament .bracket .spacer { height: 80px; } .tournament .bracket .half-spacer { height: 40px; } .tournament .bracket .small-spacer { height: 10px; background-color: #F1F1F1; } .tournament .bracket .winner { border-bottom: 1px solid; } .left-line { border-left: 1px solid; } .tournament .cell { min-width: 100px; height: 20px; float: left; background-color: #DFDFDF; } .tournament .l2 { background-color: #D0D0D0; } .tournament .lmax { width: 0px; clear: both; } </style> <script type="text/javascript"> var matchInfo = { "rounds" : [ { "name": "Round1", "matches" : [ { "id" : 1, "p1" : "mTwDeMuslim", "p2" : "Luffy" }, { "id" : 2, "p1" : "SeleCT", "p2" : "NEXGenius" }, { "id" : 3, "p1" : "Fenix", "p2" : "SoftBall" }, { "id" : 4, "p1" : "White-Ra", "p2" : "Ice" }, { "id" : 5, "p1" : "HuK", "p2" : "RedArchon" }, { "id" : 6, "p1" : "Capoch", "p2" : "Loner" }, { "id" : 7, "p1" : "mTwDIMAGA", "p2" : "MakaPrime" }, { "id" : 8, "p1" : "TLAF-Liquid`TLO", "p2" : "SEN" } ] }, { "name": "Round2", "matches" : [ { "id" : 9, "p1" : null, "p2" : null }, { "id" : 10, "p1" : null, "p2" : null }, { "id" : 11, "p1" : null, "p2" : null }, { "id" : 12, "p1" : null, "p2" : null } ] }, { "name": "Round3", "matches" : [ { "id" : 13, "p1" : null, "p2" : null }, { "id" : 14, "p1" : null, "p2" : null }, ] }, { "name": "Round4", "matches" : [ { "id" : 15, "p1" : null, "p2" : null }, ] } ] }; $(document).ready(function($) { var base = $('#writeHere'); var matchDivsByRound = []; for (var roundIndex=0; roundIndex<matchInfo.rounds.length; roundIndex++) { var round = matchInfo.rounds[roundIndex]; var bracket = checkedAppend('<div class="bracket"></div>', base); var matchDivs = []; matchDivsByRound.push(matchDivs); //setup the match boxes round by round for (var i=0; i<round.matches.length; i++) { var vOffset = checkedAppend('<div></div>', bracket); var match = round.matches[i]; var matchHtml = '<div class="match" id="match' + match.id + '">' + '<div class="p1">' + fmtName(match.p1) + '</div>' + '<div class="spacer"></div>' + '<div class="p2">' + fmtName(match.p2) + '</div>'; matchDiv = checkedAppend(matchHtml, bracket); matchDivs.push(matchDiv); if (roundIndex > 0) { //row 2+; line up with previous row var alignTo = matchDivsByRound[roundIndex-1][i*2]; //offset to line up tops var desiredOffset = alignTo.position().top - matchDiv.position().top; //offset by half the previous match-height desiredOffset += alignTo.height() / 2; vOffset.height(desiredOffset); } else { checkedAppend('<div class="small-spacer"></div>', bracket); } if (roundIndex > 0) { //tweak our size so we stretch to the middle of the appropriate element var stretchTo = matchDivsByRound[roundIndex-1][i*2+1]; var newH = stretchTo.position().top + stretchTo.height()/2 - matchDiv.position().top; var deltaH = newH - matchDiv.height(); matchDiv.height(newH); var spacer = matchDiv.find('.spacer'); spacer.height(spacer.height() + deltaH); } } } //setup the final winners box; just a space for a name whose bottom is centrally aligned with the last match bracket = checkedAppend('<div class="bracket"></div>', base); var vOffset = checkedAppend('<div></div>', bracket); var alignTo = matchDivsByRound[matchInfo.rounds.length - 1][0]; //only 1 match in the last round var html = '<div class="winner">?</div>'; var winnerDiv = checkedAppend(html, bracket); vOffset.height(alignTo.position().top - winnerDiv.position().top + alignTo.height() / 2 - winnerDiv.height()); }); function fmtName(name) { return null != name ? name : '?'; } function checkedAppend(rawHtml, appendTo) { var html = $(rawHtml); if (0 == html.length) { throw "Built ourselves bad html : " + rawHtml; } html.appendTo(appendTo); return html; } </script> </head> <body> <div>blah blah blah</div> <div id="writeHere" class="tournament"></div> <div>blah blah blah</div> </body> </html> I tried to do this <?php function getusername($id){ $sql = mysql_query("SELECT * FROM users WHERE UserID = '".$id."'"); $ROW = mysql_fetch_assoc($sql); $data = $ROW['Username']; return $data; } ?> var matchInfo = { "rounds" : [ { "name": "Round1", "matches" : [ <?php for ($i = 0; $i < $num_rounds; ++$i) { $matches = $teams * pow(.5, $i - 1) / 2; $ROW = mysql_fetch_array($sql); for ($j = 0; $j < $matches; ++$j) { echo '{ "id" : '.$j.', "p1" : "'.$ROW['UserID'].'", "p2" : "'.$ROW['UserID' + $j - 1].'" }'; echo $coma = ','; } echo $coma= ''; }?> but it gives me this var matchInfo = { "rounds" : [ { "name": "Round1", "matches" : [ { "id" : 0, "p1" : "1", "p2" : "" },{ "id" : 1, "p1" : "1", "p2" : "2" },{ "id" : 2, "p1" : "1", "p2" : "1" },{ "id" : 3, "p1" : "1", "p2" : "1" },{ "id" : 0, "p1" : "15", "p2" : "" },{ "id" : 1, "p1" : "15", "p2" : "3" },{ "id" : 0, "p1" : "17", "p2" : "" }, ] }, according to my database there are 4 teams but with my php script it gives me 7 matches. it should be only 2 matches. cos there are 4 teams. i just cannot figure out this. is there anyone can give me an idea or help me please? thanks
  3. <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $host = " "; $database = " "; $username = " "; $password = " "; $tbl_name = "users"; $conn = mysql_connect($host, $username, $password) or die("Could not connect: " . mysql_error()); if($conn) { mysql_select_db($database); echo "connected to database!!"; } else { echo "failed to select database"; } //include('bouncer.php'); //$currentUser = $_SESSION['myusername']; if(isset($_POST['submit'])) { $first = mysql_real_escape_string( $_POST['first']); $last = mysql_real_escape_string( $_POST['last']); $dob = mysql_real_escape_string( $_POST['dob']); //THE SEARCH FUNCTION //$sql = mysql_query ( "SELECT * FROM users WHERE firstname LIKE '%$first%' //OR lastname LIKE '%$last%' OR dob LIKE '%$dob%'") or die(mysql_error()); $result = mysql_query ("SELECT * FROM users WHERE firstname LIKE '%" . $first . "%' OR lastname LIKE '%" . $last . "%' OR dob LIKE '%" . $dob. "%' ") or die(mysql_error()); //$result = mysql_query($sql) or die( "<br>Query: $sql<br>Failed with error: " . mysql_error() ); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } while ($row = mysql_fetch_assoc($result)) { echo $row["firstname"]; echo $row["lastname"]; echo $row["dob"]; } }else{ ?> <html> <body> <form action="login_success8.php" method="post"> <p> <input type="text" name="first" size="20" /> First name<br /> <input type="text" name="last" size="20" /> Last name<br /> <input name="dob" type="text" size="20" id="dob" /> Date of Birth<br /> <input type="submit" name="submit" value="Search" /> <input type="reset" value="Reset fields" /> </p> </form> </body> </html> <?php } ?> change to this. you should use else.
  4. you can have style.css which can be #footer{ backgground:#<?php $color; ?> } } and include it include('style.css') maybe?
  5. why don't you use time() function and insert into your database? $ROW['LastAction'] = date( 'H:i:s', $ROW['LastAction'] );
  6. this is a good idea. I think you should use tableshort jquery plugin with this. http://webdesignledger.com/resources/12-useful-jquery-plugins-for-working-with-tables have look at here and make it more user friendly.
  7. Hi Im using a php theme script and I want to use jcart with this script. The thing is my theme scrip dosen't use echo. When I need to display something I have to use something like this $_PAGE = "<div id='jcart'>..." and if i use echo i recieve header error. i changed couple of thing and now i cant see cart but when i click add to cart button it says Item added but all cart is disappearing. you can see here could you help me please thanks. <THEME Name={ShopNavDivEnd}> </ul> </div> <br /><br /><br /><br /> <VAR>_JCART</VAR> </div> </THEME> this is shop.php $_JCART .= "<div id='jcart'>".$jcart->display_cart()."</div>"; i changed the jcart.php class to like this. I mean all echo to $_PAGE .= "..." // Return specified number of tabs to improve readability of HTML output function tab($n) { $tabs = null; while ($n > 0) { $tabs .= "\t"; --$n; } return $tabs; } // If there's an error message wrap it in some HTML if ($errorMessage) { $errorMessage = "<p id='jcart-error'>$errorMessage</p>"; } // Display the cart header $_JCART .= tab(1) . "$errorMessage\n"; $_JCART .= tab(1) . "<form method='post' action='$checkout'>\n"; $_JCART .= tab(2) . "<fieldset>\n"; $_JCART .= tab(3) . "<input type='hidden' name='jcartToken' value='{$_SESSION['jcartToken']}' />\n"; $_JCART .= tab(3) . "<table border='1'>\n"; $_JCART .= tab(4) . "<thead>\n"; $_JCART .= tab(5) . "<tr>\n"; $_JCART .= tab(6) . "<th colspan='3'>\n"; $_JCART .= tab(7) . "<strong id='jcart-title'>{$config['text']['cartTitle']}</strong> ($this->itemCount $itemsText)\n"; $_JCART .= tab(6) . "</th>\n"; $_JCART .= tab(5) . "</tr>". "\n"; $_JCART .= tab(4) . "</thead>\n"; // Display the cart footer $_JCART .= tab(4) . "<tfoot>\n"; $_JCART .= tab(5) . "<tr>\n"; $_JCART .= tab(6) . "<th colspan='3'>\n"; // If this is the checkout hide the cart checkout button if ($isCheckout !== true) { if ($config['button']['checkout']) { $inputType = "image"; $src = " src='{$config['button']['checkout']}' alt='{$config['text']['checkout']}' title='' "; } $_JCART .= tab(7) . "<input type='$inputType' $src id='jcart-checkout' name='jcartCheckout' class='jcart-button' value='{$config['text']['checkout']}' />\n"; } $_JCART .= tab(7) . "<span id='jcart-subtotal'>{$config['text']['subtotal']}: <strong>$currencySymbol" . number_format($this->subtotal, $priceFormat['decimals'], $priceFormat['dec_point'], $priceFormat['thousands_sep']) . "</strong></span>\n"; $_JCART .= tab(6) . "</th>\n"; $_JCART .= tab(5) . "</tr>\n"; $_JCART .= tab(4) . "</tfoot>\n"; $_JCART .= tab(4) . "<tbody>\n"; // If any items in the cart if($this->itemCount > 0) { // Display line items foreach($this->get_contents() as $item) { $_JCART .= tab(5) . "<tr>\n"; $_JCART .= tab(6) . "<td class='jcart-item-qty'>\n"; $_JCART .= tab(7) . "<input name='jcartItemId[]' type='hidden' value='{$item['id']}' />\n"; $_JCART .= tab(7) . "<input id='jcartItemQty-{$item['id']}' name='jcartItemQty[]' size='2' type='text' value='{$item['qty']}' />\n"; $_JCART .= tab(6) . "</td>\n"; $_JCART .= tab(6) . "<td class='jcart-item-name'>\n"; if ($item['url']) { $_PAGE .= tab(7) . "<a href='{$item['url']}'>{$item['name']}</a>\n"; } else { $_PAGE .= tab(7) . $item['name'] . "\n"; } $_JCART .= tab(7) . "<input name='jcartItemName[]' type='hidden' value='{$item['name']}' />\n"; $_JCART .= tab(6) . "</td>\n"; $_JCART .= tab(6) . "<td class='jcart-item-price'>\n"; $_JCART .= tab(7) . "<span>$currencySymbol" . number_format($item['subtotal'], $priceFormat['decimals'], $priceFormat['dec_point'], $priceFormat['thousands_sep']) . "</span><input name='jcartItemPrice[]' type='hidden' value='{$item['price']}' />\n"; $_JCART .= tab(7) . "<a class='jcart-remove' href='?jcartRemove={$item['id']}'>{$config['text']['removeLink']}</a>\n"; $_JCART .= tab(6) . "</td>\n"; $_JCART .= tab(5) . "</tr>\n"; } } // The cart is empty else { $_PAGE = tab(5) . "<tr><td id='jcart-empty' colspan='3'>{$config['text']['emptyMessage']}</td></tr>\n"; } $_JCART .= tab(4) . "</tbody>\n"; $_JCART .= tab(3) . "</table>\n\n"; $_JCART .= tab(3) . "<div id='jcart-buttons'>\n"; if ($config['button']['update']) { $inputType = "image"; $src = " src='{$config['button']['update']}' alt='{$config['text']['update']}' title='' "; } $_JCART .= tab(4) . "<input type='$inputType' $src name='jcartUpdateCart' value='{$config['text']['update']}' class='jcart-button' />\n"; if ($config['button']['empty']) { $inputType = "image"; $src = " src='{$config['button']['empty']}' alt='{$config['text']['emptyButton']}' title='' "; } $_JCART .= tab(4) . "<input type='$inputType' $src name='jcartEmpty' value='{$config['text']['emptyButton']}' class='jcart-button' />\n"; $_JCART .= tab(3) . "</div>\n"; // If this is the checkout display the PayPal checkout button if ($isCheckout === true) { // Hidden input allows us to determine if we're on the checkout page // We normally check against request uri but ajax update sets value to relay.php $_JCART .= tab(3) . "<input type='hidden' id='jcart-is-checkout' name='jcartIsCheckout' value='true' />\n"; // PayPal checkout button if ($config['button']['checkout']) { $inputType = "image"; $src = " src='{$config['button']['checkout']}' alt='{$config['text']['checkoutPaypal']}' title='' "; } if($this->itemCount <= 0) { $disablePaypalCheckout = " disabled='disabled'"; } $_JCART .= tab(3) . "<input type='$inputType' $src id='jcart-paypal-checkout' name='jcartPaypalCheckout' value='{$config['text']['checkoutPaypal']}' $disablePaypalCheckout />\n"; } $_JCART .= tab(2) . "</fieldset>\n"; $_JCART .= tab(1) . "</form>\n\n"; $_JCART .= tab(1) . "<div id='jcart-tooltip'></div>\n"; return $_JCART; } } and this is my theme script <?php class Theme { var $META = array(); var $JS = array(); var $BodyOn = array(); var $CSS = array(); var $TITLE = ""; var $Charset = "UTF-8"; var $Headers = ''; var $Body = array(); var $Vars = array(); var $ThemeList = array(); var $ThemeDir = ''; var $CacheDir = ''; var $ThemeName = ''; var $FirstTAG = ''; var $FirstPosition = 999999; var $ClassUpdated = 0; var $CompressOutput = true; var $MatchTAG = array( // Find And Replace 'FE' => array( 'Find' => '<FE Array={([^}]+)}>', 'Replace' => "if ( count( \$\\1 ) )\r\n<!TabCount!>{\r\n<!TabCount!>\tforeach ( \$\\1 as \$_KEY => \$_VALUE )\r\n<!TabCount!>\t{\r\n" ), '/FE' => array( 'Find' => '<\/FE>', 'Replace' => "\t}\r\n<!TabCount!>}\r\n" ), 'FF' => array( 'Find' => '<FF Array={([^}]+)}>', 'Replace' => "if ( count( \$\\1 ) )\r\n<!TabCount!>{\r\n<!TabCount!>\tforeach ( \$\\1 as \$_KFY => \$_VALUF )\r\n<!TabCount!>\t{\r\n" ), '/FF' => array( 'Find' => '<\/FF>', 'Replace' => "\t}\r\n<!TabCount!>}\r\n" ), 'IF' => array( 'Find' => '<IF State={([^}]+)}>', 'Replace' => "if ( \\1 )\r\n<!TabCount!>{\r\n" ), '/IF' => array( 'Find' => '<\/IF>', 'Replace' => "}\r\n" ), 'ELIF' => array( 'Find' => '<ELIF State={([^}]+)}>', 'Replace' => "else if ( \\1 )\r\n<!TabCount!>{\r\n" ), '/ELIF' => array( 'Find' => '<\/ELIF>', 'Replace' => "}\r\n" ), 'ELSE' => array( 'Find' => '<ELSE>', 'Replace' => "else\r\n<!TabCount!>{\r\n" ), '/ELSE' => array( 'Find' => '<\/ELSE>', 'Replace' => "}\r\n" ), 'VAR' => array( 'Find' => '<VAR>([^<]+)<\/VAR>', 'Replace' => "\$\\1" ), 'BIT' => array( 'Find' => '<BIT>([a-z0-9_]+)(\(([^<]*)\)|)<\/BIT>', 'Replace' => "t_\\1(\\3)" ), 'DEF' => array( 'Find' => '<DEF>([^<]+)<\/DEF>', 'Replace' => "\\1" ), 'PHP' => array( 'Find' => '<PHP>([^<]+);?<\/PHP>', 'Replace' => "\\1" ), 'THEME' => array( 'Find' => '<THEME Name={([^}]+)}\s*?(Vars?={([^}]+)})?>(.+)<\/THEME>' ), ); var $PredefinedGlobals = array( '_HTML', '_KEY', '_KFY', '_VALUE', '_VALUF', '_GET', '_POST', '_SESSION', '_COOKIE' ); /* * Base Functions * * <FE Array={Dizi}> ... </FE> * <IF State={$a == '4'}> ... </IF> * <ELIF State={$a == '4'}> ... </ELIF> * <ELSE> ... </ELSE> * <VAR> ... </VAR> * <BIT> ... </BIT> * * @param String $ThemeName * @return void */ function Theme() { global $CFG; $this->Charset = $CFG['Theme']['Charset']; $this->META = $CFG['Theme']['Meta']; $this->TITLE = $CFG['Title']; $this->ClassUpdated = filemtime( CLS_DIR . "theme.class.php" ); } /** * * @access public * @return void */ function setTHEME( $ThemeName ) { if ( !is_dir( THM_DIR . $ThemeName ) ) return false; $this->ThemeName = $ThemeName; $this->ThemeDir = THM_DIR . $ThemeName . '/Html/'; $this->CacheDir = CCH_DIR . 'Themes/' . $ThemeName . '/'; $this->initTHEME(); } /** * * @access public * @return void */ function initTHEME() { define( 'IMG_DIR', "http://" . SITE . "/Themes/" . $this->ThemeName . "/Image/" ); $this->loadTheme( "index" ); } function loadTheme( $FileName ) { $FileName = ucfirst( strtolower( $FileName ) ); // Theme HTML Exists ? if ( !file_exists( $this->ThemeDir . $FileName . ".tpl" ) ) { global $CFG; if ( $this->ThemeName != $CFG['Theme']['DefaultTheme'] ) { $_SESSION['ThemeName'] = $CFG['Theme']['DefaultTheme']; header( "Location: ?" ); die( 'falan filan' ); } else die( "Theme File Not Found: " . $FileName . ".tpl" ); } $this->ThemeList = array(); // Theme Cache Exists ? And Newer than the Theme HTML ? if ( file_exists( $this->CacheDir . $FileName . ".tpl.php" ) AND ( filemtime( $this->CacheDir . $FileName . ".tpl.php" ) > max( $this->ClassUpdated, filemtime( $this->ThemeDir . $FileName . ".tpl" ) ) ) ) $this->createFunctions( $FileName ); else $this->cacheTheme( $FileName ); } /** * * @access public * @return void */ function loadCSS( $CssFile ) { if ( eregi( 'http', $CssFile ) ) $this->CSS[] = $CssFile; else { global $_RWBASE; $FileName = THM_DIR . $this->ThemeName . '/Style/' . $CssFile; if ( file_exists( $FileName ) AND is_readable( $FileName ) ) $this->CSS[$CssFile] = $_RWBASE . $FileName; } } /** * * @access public * @return void */ function loadJS( $JsFile, $Code = false ) { if ( !$Code ) { if ( eregi( 'http', $JsFile ) ) $this->JS[] = '<script type="text/javascript" src="' . $JsFile . '"></script>'; else { global $_RWBASE; $FileName = BASE_DIR . 'Sources/JavaScript/' . $JsFile; if ( file_exists( $FileName ) AND is_readable( $FileName ) ) $this->JS[$JsFile] = '<script type="text/javascript" src="' . $_RWBASE . $FileName . '"></script>'; } } else $this->JS[$Code] = '<script type="text/javascript">' . $JsFile . '</script>'; } function addJS( $JsFile, $Code = false ) { $this->loadJS( $JsFile, $Code ); } /** * * @access public * @return void */ function bodyOn( $Type, $Code ) { $this->BodyOn[strtolower( $Type )][] = $Code; } /** * * @access public * @return void */ function writePage( $FinalFunction = "t_Page" ) { foreach ( $this->BodyOn as $key => $value ) { $this->loadJS( 'function bodyOn' . $key . '() {' . implode( $value ) . '}; onAttacher("' . $key . '",bodyOn' . $key . ');', 'on' . $key ); } $header = array( "<title>" . $this->TITLE . "</title>" ); foreach ( $this->META as $value ) $header[] = $value; foreach ( $this->JS as $value ) $header[] = $value; foreach ( $this->CSS as $value ) $header[] = '<style type="text/css" media="all">@import url(' . $value . ');</style>'; $this->Headers = implode( $header ); header( 'Content-Type: text/html; charset=' . $this->Charset ); echo $FinalFunction(); } function createFunctions( $FileName = '' ) { include_once( $this->CacheDir . $FileName . ".tpl.php" ); } function cacheTheme( $FileName ) { $FileContent = rFile( $this->ThemeDir . $FileName . ".tpl" ); if ( $this->CompressOutput ) $FileContent = $this->compressHTML( $FileContent ); $this->parseThemes( $FileContent ); wFile( $this->CacheDir . $FileName . ".tpl.php", "<" . "? \r\n" . $this->createThemeFunctions() . "\r\n?" . ">", 0777 ); $this->createFunctions( $FileName ); } function compressHTML( $Content ) { $Content = preg_replace( "/[\s]{2,}/", " ", $Content ); $Content = preg_replace( "/> </", "><", $Content ); return $Content; } function parseThemes( $Content ) { $Results = $this->findExactTAGs( $Content, "THEME" ); foreach ( $Results as $Value ) { preg_match( "/^" . $this->MatchTAG['THEME']['Find'] . "$/is", trim( $Value ), $Match ); $Vars = array(); if ( trim( $Match[3] ) != '' ) { $tVars = explode( ',', $Match[3] ); foreach ( $tVars as $vValue ) { if ( preg_match( '/^\$?([a-z0-9_]+)=?(.*)$/i', trim( $vValue ), $vMatch ) ) $Vars[$vMatch[1]] = "$" . $vMatch[1] . ( trim( $vMatch[2] ) != "" ? "=" . $vMatch[2] : "" ); } } $this->ThemeList[$Match[1]] = array( 'Code' => $Match[4], 'Vars' => $Vars ); } return true; } function findExactTAGs( $Content, $TAGName ) { $Results = array(); $CurrPos = 0; $Found = false; $Level = 0; // --------------------- $StartTAG = "<" . $TAGName; $EndTAG = "</" . $TAGName . ">"; $Repeat = substr_count( $Content, $StartTAG ); if ( substr_count( $Content, $EndTAG ) != $Repeat ) die( "Template ERROR: <$TAGName> sayısı ile </$TAGName> sayısı eşit değil!" ); // ----------------------------------- for( $i = 0; $i < $Repeat; $i++ ) { $Found = false; $Level = 0; $ContentStart = strpos( $Content, $StartTAG, $CurrPos ); $CurrPos = $ContentStart + strlen( $StartTAG ); while ( $Found == false ) { if ( $Level == 0 ) { $PosS = strpos( $Content, $StartTAG, $CurrPos ); $PosE = strpos( $Content, $EndTAG, $CurrPos ); if ( $PosS < $PosE AND $PosS !== false ) $Level++; else $Found = true; if ( $Found ) $ContentEnd = $PosE; $CurrPos = min( ( $PosS === false ? 999999 : $PosS ), ( $PosE === false ? 999999 : $PosE ) ) + 1; } else if ( $Level > 0 ) { $PosS = strpos( $Content, $StartTAG, $CurrPos ); $PosE = strpos( $Content, $EndTAG, $CurrPos ); if ( $PosS < $PosE AND $PosS !== false ) $Level++; else $Level--; $CurrPos = min( ( $PosS === false ? 999999 : $PosS ), ( $PosE === false ? 999999 : $PosE ) ) + 1; } } $Results[] = trim( substr( $Content, $ContentStart, $ContentEnd - $ContentStart + strlen( $EndTAG ) ) ); } // for return $Results; } function createThemeFunctions() { $FunctionList = array(); foreach ( $this->ThemeList as $Name => $ThemeData ) { $FunctionVars = $ThemeData['Vars']; $Content = $ThemeData['Code']; $FunctionCode = ''; $FunctionGlobals = array(); $this->TabCount = 1; $HtmlOpen = true; while ( ( $StartPoint = $this->getFirstTAG( $Content ) ) !== false ) { if ( $StartPoint == 0 ) { if ( !preg_match( '/^' . $this->MatchTAG[$this->FirstTAG]['Find'] . '/i', $Content, $Match ) ) die( 'Template Tag Error: ' . $this->FirstTAG ); if ( $this->FirstTAG == "THEME" ) { $SubThemes = $this->findExactTAGs( $Match[0], "THEME" ); foreach ( $SubThemes as $SubValue ) { preg_match( "/^" . $this->MatchTAG['THEME']['Find'] . "$/i", $SubValue, $SubMatch ); $SubVars = array(); if ( trim( $SubMatch[3] ) != '' ) { $tVars = explode( ',', $SubMatch[3] ); foreach ( $tVars as $vValue ) { if ( preg_match( '/^\$?([a-z0-9_]+)=?(.*)$/i', trim( $vValue ), $vMatch ) ) $SubVars[$vMatch[1]] = "$" . $vMatch[1] . ( trim( $vMatch[2] ) != "" ? "=" . $vMatch[2] : "" ); } } $this->ThemeList[$SubMatch[1]] = array( 'Code' => $SubMatch[4], 'Vars' => $SubVars ); $Content = str_replace( $SubMatch[0], '<BIT>' . $SubMatch[1] . ( count( $SubVars ) ? "(" . implode( ',', $SubVars ) . ")" : "" ) . '</BIT>', $Content ); } } else { if ( in_array( $this->FirstTAG, array( '/FE', '/FF', '/IF', '/ELIF', '/ELSE' ) ) ) $this->TabCount--; if ( in_array( $this->FirstTAG, array( '/FE', '/FF' ) ) ) $this->TabCount--; $Content = substr( $Content, strlen( $Match[0] ), strlen( $Content ) - strlen( $Match[0] ) ); if ( in_array( $this->FirstTAG, array( 'VAR', 'BIT', 'DEF', 'PHP' ) ) ) { if ( $HtmlOpen ) $FunctionCode .= " . "; else $FunctionCode .= $this->addTab() . "\$_HTML .= "; $HtmlOpen = true; } else { if ( $HtmlOpen ) $FunctionCode .= ";\r\n"; $FunctionCode .= $this->addTab(); $HtmlOpen = false; } $FunctionCode .= preg_replace( '/^' . $this->MatchTAG[$this->FirstTAG]['Find'] . '$/i', str_replace( '<!TabCount!>', $this->addTab(), $this->MatchTAG[$this->FirstTAG]['Replace'] ), $Match[0] ); if ( in_array( $this->FirstTAG, array( 'FE', 'FF', 'IF', 'ELIF', 'ELSE' ) ) ) $this->TabCount++; if ( in_array( $this->FirstTAG, array( 'FE', 'FF' ) ) ) $this->TabCount++; if ( in_array( $this->FirstTAG, array( 'IF', 'ELIF', 'PHP' ) ) ) $FunctionGlobals[] = $Match[1]; if ( in_array( $this->FirstTAG, array( 'FE', 'FF', 'VAR' ) ) ) $FunctionGlobals[] = "$" . $Match[1]; } } else { if ( trim( $HtmlCode = substr( $Content, 0, $StartPoint ) ) != "" ) { if ( $HtmlOpen ) $FunctionCode .= " . "; else $FunctionCode .= $this->addTab() . "\$_HTML .= "; $HtmlOpen = true; $FunctionCode .= "'" . str_replace( "'", "\'", $HtmlCode ) . "'"; $Content = substr( $Content, strlen( $HtmlCode ), strlen( $Content ) - strlen( $HtmlCode ) ); } else $Content = ltrim( $Content ); } } if ( trim( $Content ) != '' ) { if ( $HtmlOpen ) $FunctionCode .= " . "; else $FunctionCode .= $this->addTab() . "\$_HTML .= "; $HtmlOpen = true; $FunctionCode .= "'" . str_replace( "'", "\'", $Content ) . "'"; } if ( $HtmlOpen ) $FunctionCode .= ";\r\n"; $Function = "function t_" . $Name . "(" . implode( ',', $FunctionVars ) . ")\r\n{\r\n"; $Function .= $this->setGlobals( $FunctionGlobals, $FunctionVars ); if ( substr( $FunctionCode, 0, 3 ) == " . " ) { $Function .= "\t\$_HTML = "; $Function .= substr( $FunctionCode, 3, strlen( $FunctionCode )-3 ) ; } else { $Function .= "\t\$_HTML = ''"; $Function .= $FunctionCode ; } $Function .= "\treturn \$_HTML;\r\n"; $Function .= "}\r\n"; $FunctionList[] = $Function; } return implode( "\r\n", $FunctionList ); } function getFirstTAG( $Content, $Offset = 0 ) { $FirstPosition = 999999; foreach ( $this->MatchTAG as $TagName => $TagArray ) { if ( ( $Position = strpos( $Content, "<" . $TagName, $Offset ) ) !== false ) { if ( $Position < $FirstPosition ) { $FirstPosition = $Position; $this->FirstTAG = $TagName; } } } if ( $FirstPosition < 999999 ) return $FirstPosition; else return false; } function addTab() { return str_repeat( "\t", $this->TabCount ); } function setGlobals( $GlobalArray, $VarsArray = array() ) { $Globals = array(); foreach ( $GlobalArray as $Global ) { preg_match( '/\$([a-z0-9_]+)/i', $Global, $Match ); if ( !isset( $Globals[$Match[1]] ) AND !in_array( $Match[1], $this->PredefinedGlobals ) AND !isset( $VarsArray[$Match[1]] ) ) $Globals[$Match[1]] = '$' . $Match[1]; } if ( count( $Globals ) ) return "\tglobal " . implode( ', ', $Globals ) . ";\r\n"; else return ""; } } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.