127) $i-=256; return ($i<<8)+ord($str{0}); //return (ord($str{1})<<8)+ord($str{0}); } function bin2int32($str) { $i = ord($str{3}); if ($i>127) $i-=256; return ($i<<24)+(ord($str{2})<<16)+(ord($str{1})<<8)+ord($str{0}); //return (ord($str{3})<<24)+(ord($str{2})<<16)+ (ord($str{1})<<8)+ord($str{0}); } function bin2int64($str) { $i = ord($str{7}); if ($i>127) $i-=256; return ($i<<56)+(ord($str{6})<<48) + (ord($str{5})<<40)+(ord($str{4})<<32) + (ord($str{3})<<24)+(ord($str{2})<<16) + (ord($str{1})<<8)+ord($str{0}); //return (ord($str{7})<<56)+(ord($str{6})<<48) + (ord($str{5})<<40)+(ord($str{4})<<32) + // (ord($str{3})<<24)+(ord($str{2})<<16) + (ord($str{1})<<8)+ord($str{0}); } function readInt($fp) { return bin2int16(fread($fp,2)); } function readLong($fp) { return bin2int32(fread($fp,4)); } function readByte($fp) { return ord(fread($fp,1)); } function readBool($fp) { return readInt($fp); } function bin2int16_2($str) { $i = ord($str{1}); echo "\n Character: ".$str."\n"; if ($i>127) $i-=256; $temp = ($i<<8)+ord($str{0}); echo "\n
Convertido: ".$temp."
\n"; return $temp; // return (ord($str{1})<<8)+ord($str{0}); } /*function readString($fp) { $strSize = bin2int16(fread($fp,2)); //echo $strSize."
"; if($strSize>0) { /* $temp = fread($fp,$strSize); echo "\n
String: ".$temp."\n
String End
\n"; // o problema está no fread, q n apanha só a parte em rtf. $rtf2htmlCom = new COM("RTF2HTML.Converter"); $rtf2htmlCom->PreserveImages=false; $rtf2htmlCom->OutputFormat = 1; $rtf2htmlCom->HtmlParts = 1; $rtf2htmlCom->encoding = 9; $temp = $rtf2htmlCom->ConvertString($temp, "", ""); unset($rtf2htmlCom); $temp = trim(strip_tags($temp,'

')); $removablestring = "The unregistered version can convert no more than 15000 symbols.Please register: http://www.sautin.com/rtf-to-html/developers.htm"; //$temp = trim($temp,$removablestring); $temp = rtrim(str_replace($removablestring, "", $temp)); return $temp; } else return ""; }*/ function readString($fp) { $strSize = readInt($fp); if($strSize>0) return fread($fp,$strSize); else return ""; } function readInt64($fp) { return bin2int64(fread($fp,8)); } class rect { var $tipo; // n usado por enquanto var $top; var $left; var $width; var $height; var $backcolor; function rect() { } function toJavascript() { return "new Rect($this->top, $this->left, $this->width, $this->height)"; } function load($fp) { $this->tipo = readByte($fp); $this->left = readInt($fp); $this->top = readInt($fp); $this->width = readInt($fp); $this->height = readInt($fp); $this->backcolor = readLong($fp); } } class shapesCol { var $tipo; // n usado por enquanto var $shapes = array(); var $defaultShape = 0; function shapesCol() {} function setDefault($id) { $this->defaultShape = $id; } function add($shape) { $this->shapes[] = $shape; } function toJavascript() { if(func_num_args()==1) $js="new ".func_get_arg(0)."("; else $js = "new ShapesCol("; foreach($this->shapes as $shape) { $js.=$shape->toJavascript().","; } $js[strlen($js)-1]=')'; // tirar a ultima vigula e fechar o parenteses return $js; } function load($fp) { $this->tipo = readByte($fp); $numItens = readInt($fp); for($i=0; $i<$numItens; $i++) { $rect = new rect(); $rect->load($fp); $this->shapes[] = $rect; } } } class infoClick { var $shapes; var $tipo; var $modifiers; var $cursor; var $startPoint; //se >0 indica que deve ser mostrado um ponto inicial function infoClick() { } function toJavascript() { return "$this->tipo,$this->modifiers,$this->cursor,$this->startPoint,".$this->shapes->toJavascript("AreasClick"); } function load($fp) { $this->modifiers = readByte($fp); $this->cursor = readByte($fp); $this->tipo = readByte($fp); $this->shapes = new shapesCol(); $this->shapes->load($fp); $this->startPoint = readByte($fp); $this->free = readInt($fp); $this->strFree = readString($fp); } } class infoKeyboard { var $key; var $modifiers; var $posX; var $posY; function infoKeyboard() { } function toJavascript() { return "\\'$this->key\\', $this->modifiers,$this->posX,$this->posY"; } function load($fp) { $this->modifiers = readByte($fp); $this->key = readByte($fp); $this->posX = readInt($fp); $this->posY = readInt($fp); $this->free = readInt($fp); $this->strFree = readString($fp); } } class infoTimeout { var $tipo; var $tempo; var $rectInsertArea; function infoTimeout() { } function toJavascript() { return "$this->tipo, $this->tempo"; } function load($fp) { $this->tipo = readByte($fp); $this->tempo = readInt($fp); $this->rectInsertArea = new rect(); $this->rectInsertArea->load($fp); $this->free = readInt($fp); $this->strFree = readString($fp); } } class infoInput { var $fontName; var $fontSize; var $fontColor; var $fontWeight; var $fontItalic; var $fontStrikethrough; var $fontBold; var $text; var $rect; var $trans; var $pressEnter; function infoInput() { } function toJavascript() { return "\\'$this->fontName\\', \\'$this->fontSize\\', \\'$this->fontColor\\',escape(\\'$this->text\\'),".$this->rect->toJavascript().", $this->trans,$this->pressEnter"; } function load($fp) { $this->fontSize = round(readInt64($fp)/10000); $this->fontWeight = readInt($fp); $this->fontItalic = readBool($fp); $this->fontUnderline = readBool($fp); $this->fontStrikethrough = readBool($fp); $this->fontBold = readBool($fp); $this->fontName = readString($fp); $this->fontColor = readLong($fp); $this->pressEnter = readBool($fp); $this->text = readString($fp); $this->rect = new rect(); $this->rect->load($fp); $this->trans = readBool($fp); $this->strFree = readString($fp); } } class infoDrag { var $shapesSelInicial; var $shapesSelFinal; //var $shapesDragArea; var $dragAreaTop; var $dragAreaLeft; var $dragAreaWidth; var $dragAreaHeight; var $accaoRato; var $tipo; var $startPoint; var $endPoint; var $modifiers; var $cursor; function infoDrag() { } function toJavascript() { return $this->shapesSelInicial->toJavascript("DragSelsIniciais").",".$this->shapesSelFinal->toJavascript("DragSelsFinais").",".//$this->shapesDragArea->toJavascript().",". "$this->accaoRato, $this->tipo, $this->startPoint, $this->endPoint, $this->modifiers, $this->cursor"; } function load($fp) { $this->modifiers=readByte($fp); $this->cursor=readByte($fp); $this->shapesSelInicial = new shapesCol(); $this->shapesSelInicial->load($fp); $this->shapesSelFinal= new shapesCol(); $this->shapesSelFinal->load($fp); //$this->garbage->load($fp); // faltava aqui uma shape. $this->startPoint = readByte($fp); $this->endPoint = readByte($fp); $this->tipo = readLong($fp); $this->accaoRato = readInt($fp); $this->strFree = readString($fp); } } class infoMenu { var $cmdHeight; var $sepHeight; var $topBorder; var $rightBorder; var $leftBorder; var $bottomBorder; var $cmdNumber; var $numCommands; var $commands = array(); function infoMenu() { } function toJavascript() { $js = "$this->cmdHeight,$this->sepHeight,$this->topBorder,$this->rightBorder,$this->leftBorder,$this->bottomBorder,$this->cmdNumber,$this->numCommands"; for($i=0; $i<$this->numCommands; $i++) { if($i==0) $js.=",[".$this->commands[$i]; else $js.=",".$this->commands[$i]; } $js.="]"; return $js; } /*function load($fp) { // é aqui q é causado o problema. $this->cmdHeight = readInt($fp); $this->sepHeight = readInt($fp); $this->topBorder = readInt($fp); $this->rightBorder = readInt($fp); $this->leftBorder = readInt($fp); $this->cmdNumber = readInt($fp); $this->bottomBorder = readInt($fp); $this->strFree = readString($fp); $this->numCommands = readInt($fp); // este é o problema. formato?? $temp = "\n
cmdHeight: ".$this->cmdHeight; $temp .= "\n
sepHeight: ".$this->sepHeight; $temp .= "\n
topBorder: ".$this->topBorder; $temp .= "\n
rightBorder: ".$this->rightBorder; $temp .= "\n
leftBorder: ".$this->leftBorder; $temp .= "\n
cmdNumber: ".$this->cmdNumber; $temp .= "\n
bottomBorder: ".$this->bottomBorder; $temp .= "\n
numCommands: ".$this->numCommands; $temp .= "\n
strFree: ".$this->strFree; echo $temp; // vb metia + uma coisa no file, mas n faz parte for($i=0; $i<$this->numCommands; $i++) $this->commands[] = readInt($fp); //var_dump($this->commands); // problema em cima. }*/ function load($fp) { $this->cmdHeight = readInt($fp); $this->sepHeight = readInt($fp); $this->topBorder = readInt($fp); $this->rightBorder = readInt($fp); $this->leftBorder = readInt($fp); $this->cmdNumber = readInt($fp); $this->bottomBorder = readInt($fp); $this->strFree = readString($fp); $this->numCommands = readInt($fp); readInt($fp); // !?!? será que o VB guarda a array com um byte de lixo logo no inicio? for($i=0; $i<$this->numCommands; $i++) $this->commands[] = readInt($fp); } } ?> path = $path; $fp = @fopen($path, "rb"); if (!$fp) die('Exercício não encontrado!'); //MS $size = filesize($path); $this->ver = readString($fp); if ($this->ver == "DM40") { $this->title = readString($fp); } else { fclose($fp); $fp = @fopen($path, "rb"); } while(ftell($fp)<$size) // feof aqui n funciona pq tinha de ler mais um byte para chegar ao EOF. { $frame= new frame(); $frame->load($fp); $this->frames[] = $frame; $this->totalFrames++; } fclose($fp); print_r($frames); } function getTotalFrames() { return $this->totalFrames; } function printSacData($my_fp) { //print("var sac=new SAC(".$this->totalFrames.");\n"); echo("var sac=new SAC("); echo($this->totalFrames); echo(");\n"); // MS 07-09-2007: passar objectivo para o loading das sacs, e loading % $obj = $this->frames[0]; $obj->comentario = str_replace("\/\/'","'",$obj->comentario); $imgNone = sprintf("%03d", $this->frames[0]->img); $image= $this->sacPath . "I$imgNone.png"; echo("\nvar objectivo ='".$obj->comentario."';\n var objectivoX =".$obj->comentarioX."; var objectivoY =".$obj->comentarioY."; var accao ='".$obj->accao."'; var accaoX =".$obj->accaoX."; var accaoY =".$obj->accaoY."; function updateLoader(x) { clearInterval(firstImgSim); x++; imgPercent = Math.floor((x * 100) / (totalFrames)); updateSlider(imgPercent); if ((x == totalFrames) || (imgPercent >= 100)) { setTimeout(function() { document.getElementById('imgLoading').style.display = 'none'; document.getElementById('imgLoading').style.visibility = 'hidden'; },1000); } } var primeira = document.getElementById('tmp_bg'); primeira.onload = loadAllSacFrames; primeira.src = '".$image."'; function clearLoadingBar() { document.getElementById('imgLoading').style.display = 'none'; document.getElementById('imgLoading').style.visibility = 'hidden'; } var sacsMayload = 0; function loadAllSacFrames() { if (isMSIE) loadAllSacFramesIE(); else loadAllSacFramesDefault(); } function loadAllSacFramesIE() { preloadIt() Preloader.onFinish(loadAllSacFramesDefault); Preloader.load(); } function preloadIt() { var imagens = new Array();\n"); for ($i=1;$i<$this->totalFrames;$i++) { $imgN = sprintf("%03d", $this->frames[$i]->img); $image= $this->sacPath . "I$imgN.png"; echo("imagens[".($i-1)."] = '$image';\n"); } echo(" Preloader.add(imagens); } function loadAllSacFramesDefault() { if (!isMSIE) { preloadIt() Preloader.onFinish(clearLoadingBar); Preloader.load(); } else clearLoadingBar();\n"); // -------------------------------------------------------------------------- for($i=0; $i<$this->totalFrames; $i++) { $frame = $this->frames[$i]; // MS - 13-08-2007: Remover problemas com quotes que quebravam o javascript if ($frame->cometario) $frame->comentario = str_replace("\/\/'","'",$frame->comentario); if ($frame->accao) $frame->accao = str_replace("\/\/'","'",$frame->accao); // ---------------------- $imgNum = sprintf("%03d", $frame->img); if(file_exists(dirname($this->path)."/I$imgNum.png")) { $img = dirname($this->path)."/I$imgNum.png"; $img2= $this->sacPath . "I$imgNum.png"; } else { $img = dirname($this->path)."/i$imgNum.png"; $img2 = $this->sacPath . "I$imgNum.png"; } //print("sac.addFrame("); echo("setTimeout('sac.addFrame("); if($i==$this->totalFrames-1) //last Frame echo("new FrameEnd"); else { switch($frame->tipo) { case 0: echo("new FrameClick"); break; case 1: echo("new FrameKeyboard"); break; case 2: echo("new FrameInput"); break; case 3: switch($this->frames[$i]->info->tipo) { case 0: // sem limite case 5: // rect branco case 7: // linha echo("new FrameDragSemLimite"); break; case 1: // rect trans echo("new FrameDragRectTrans"); break; case 2: // redim rect echo("new FrameDragSelHorizontal"); break; case 3: // redim horiz echo("new FrameDragRedimRect"); //print("new FrameDragRedimHoriz"); break; case 4: // rect ajustado invertido echo("new FrameDragRectAjustInv"); break; case 9: // sel-celulas echo("new FrameDragSelCelulas"); break; case 10: // sel vertical echo("new FrameDragSelVertical"); break; case 11: // arrast rect echo("new FrameDragArrastRect"); break; case 12: // arrast linha vertical echo("new FrameDragArrastLinhaVert"); break; case 13: // arrast linha horizontal echo("new FrameDragArrastLinhaHorz"); break; default: // fail safe echo("new FrameDrag"); break; } break; case 4: echo("new FrameMenu"); break; case 5: switch($frame->info->tipo) { case 0: echo("new FrameTimeoutIMG"); break; case 1: echo("new FrameTimeoutAVI"); break; } break; } } //print("($i,'$img',$frame->tipo,escape('$frame->comentario'), $frame->comentarioX, $frame->comentarioY,"); echo("("); echo($i); echo(",\\'"); //#################### bta-- 8/8/2006 //echo($img); //para o caminho +/- absoluto echo($img2); //para o caminho relativo //#################### echo("\\',"); echo($frame->tipo); echo(","); echo("escape(\\'"); echo($frame->comentario); echo("\\')"); echo(", "); echo($frame->comentarioX); echo(", "); echo($frame->comentarioY); echo(","); if($i==$this->totalFrames-1) //na ultima frame n se imprimem info's { //print(" escape('$frame->accao'), $frame->accaoX, $frame->accaoY"); //bta-- 8/8/2006 echo("escape(\\'"); echo($frame->accao); echo("\\')"); echo(", "); echo($frame->accaoX); echo(", "); echo($frame->accaoY); } else { //print(" escape('$frame->accao'), $frame->accaoX, $frame->accaoY, ".$frame->printInfo()); //bta-- 8/8/2006 echo( "escape(\\'"); echo( $frame->accao); echo( "\\')"); echo( " , "); echo( $frame->accaoX); echo( ", "); echo( $frame->accaoY); echo( ", "); echo( $frame->printInfo()); } if($frame->tipo == 4) //frames de menu têm posX, posY, imgWidth, imgHeight { echo( ","); echo( $frame->posX); echo( ", "); echo( $frame->posY); echo( ","); $info = getImageSize($img); echo( $info[0]); echo( ", "); echo( $info[1]); // width e height } echo("))',0);\n"); } echo("\n sacsMayload++; }\n"); } } class frame { var $img; var $info; var $tipo; var $comentario; var $comentarioTitle; var $comentarioX; var $comentarioY; var $posX; var $posY; var $accao; var $accaoX; var $accaoY; var $key; var $keyModifier; function printInfo() { return $this->info->toJavascript(); } function load($fp) { /* $imgNum = sprintf("%03d",readByte($fp)); $this->img = "I$imgNum.png"; */ $this->img = readByte($fp); $this->tipo = readLong($fp); $this->tempo = readByte($fp); // isto é usado para q!?? $this->comentario = readString($fp); $this->comentario = str_replace("'","\'",$this->comentario); //$this->comentario = str_replace("\\","\\\\",$this->comentario); $this->comentario = str_replace("\\","\/\/",$this->comentario); $this->comentarioX = readInt($fp); $this->comentarioY = readInt($fp); readInt($fp); readInt($fp); // verticeCalloutX e verticeCalloutY - n sao usados $this->posX = readInt($fp); $this->posY = readInt($fp); $this->accao = readString($fp); $this->accao = str_replace("'","\'",$this->accao); //$this->accao = str_replace("\\","\\\\",$this->accao); $this->accao = str_replace("\\","\/\/",$this->accao); $this->accaoX = readInt($fp); $this->accaoY = readInt($fp); switch($this->tipo) { case 0: // click $this->info = new infoClick(); $this->info->load($fp); break; case 1: // keyboard $this->info = new infoKeyboard(); $this->info->load($fp); break; case 2: // input $this->info = new infoInput(); $this->info->load($fp); break; case 3: //drag $this->info = new infoDrag(); $this->info->load($fp); break; case 4: // menu $this->info = new infoMenu(); $this->info->load($fp); break; case 5: //timeout $this->info = new infoTimeout(); $this->info->load($fp); break; } $this->linkedFrame = readByte($fp); $this->strFree = readString($fp); $this->free = readInt($fp); // !?!? } } //$demo = new demo(); //$demo->load("data/input/ddd.dm"); ?> load("sac_htm.dm"); $demo->sacPath = ""; $keywords = str_replace(" ",", ",$demo->title); echo(" ".$demo->title." title."\" /> Exercício

Por favor aguarde um momento. A carregar Exercicio...
"; //Fim do fwrite } // fim da função criaSAC(path) ?>