Jump to content

superaktieboy

Members
  • Posts

    32
  • Joined

  • Last visited

    Never

Posts posted by superaktieboy

  1. Ok, so I fixed that error, by renaming the $attributes field to something $attribs, though i have a new error.

     

    Warning: DOMNode::appendChild() [domnode.appendchild]: Couldn't fetch P3TElement in D:\www\p3textract\extract.php on line 103

     

    Can anyone help?

     

    again same file btw, except $attributes within the class P3TElement has been renamed $attribs as mentioned above.

     

    thanks.

     

    EDIT: new uploaded version: http://pastebin.com/SsAV7Zte

  2. I have a class (P3TElement) that extends the DOMElement class in PHP. In there i have a public variable "attributes" which is an array, and an method named add_attribute($attr), the argument is a different class (P3TAttribute). However I am getting an error when trying to use it.

    The exact error is:

    Warning: P3TElement::add_attribute() [p3telement.add-attribute]: Invalid State Error in D:\www\p3textract\extract.php on line 110

     

    Please see the code: http://pastebin.com/CbsM9V5W

     

    This class is supposed to extract .p3t (ps3 themes) files, and is a direct port of the python equivalent found at http://p3textractor.googlecode.com/svn/trunk/p3textractor.py

     

    Could you please help me fix this?

     

    thanks in advance,

     

    Hosh

  3. thanks for the replies guys, this did the trick for me:

    <?php
    
    class lol {
        private $lol = 'HA';
        private $extensions = array();
        function add(ext $obj) {
            $this->extensions[] = $obj;
        }
        
        function loop($text) {
            foreach($this->extensions as $obj) {
                $text = $obj->parse($text);
            }
            return $text;
        }
    }
    
    abstract class ext {
        public abstract function parse($text);
    }
    
    class ext1 extends ext {
        public function parse($text) {
            return $text . 'ext1';
        }
    }
    class ext2 extends ext {
        public function parse($text) {
            return $text . 'ext2';
        }
    }
    
    
    $lol = new lol();
    $lol->add(new ext1());
    $lol->add(new ext2());
    echo $lol->loop('test');
    ?>
    

  4. what i was looking to do is extend on a class (multiple times), call one method on the parent class, and the parent class calls a method in the subclasses, as they edit a specific text.. e.g.

    file main.class.php

    static class main{
        public static function addToText($text);
    }

     

    file plugins/something.class.php

    class something extends main() {
        function addToText($text) {
             return $text.'a';
        }
    }

     

     

    file plugins/somethingElse.class.php

    class somethingElse extends main() {
        function addToText($text) {
             return $text.'b';
        }
    }

     

    this way i would include everything in plugins folder, and it would automatically be initiated and when calling main::addToText(), it would call the rest of the classes' addToText() function.

  5. Hi,

     

    I am looking into a way of adding addons to a class I made.. I thought something like this would work, but not sure how to implement it:

     

    <?php
    class foo {
        function foobar($text) {
            $text = $text . 'b';
            return $text;
        }
    }
    class bar extends foo {
        function foobar($text) {
            $text = $text . 'c';
            return $text;
        }
    }
    
    $var = new bar();
    $var->foobar('a'); // this would then return abc
    ?>
    

     

    Now i want to be able to call up foo, and it calls the foobar of foo, and the foobar of bar.

    is that possible?

     

    hosh

  6. I have noticed that many websites and php software generate a random token and put it in a hidden form field to be sent to the php page that gets the form. I was just wondering, if anyone knows how this makes a php script more secure? And is it worth it to put this in my application?

    I have read up a few tutorials on this, but it doesn't specifically say why this is more secure than not having it. The only reason I could find is that it helps making sure you don't make duplicate form submissions, however, I have always gone around this through by redirecting the user to a page saying the form was submitted successfully.

    Cheers for your help.

  7. superaktieboy, CV's method works if all you want is what is between { and }. If there are specifics that need to be met within those braces, then you should specify (unless you example is about as specific as needed.. even then, my solution would still allow for something like:

     

    {blockname1.blockname1.varname1}

     

    I was admittedly making it somewhat open ended (not as much as CV's granted). So if there is a specific format, let us know.

    yeah i know.. and decided to use CV's method because it picks up more, you never know i might need more than just a-z and 0-9.. thanks to you both anyway :)

  8. are those the only things on the line?

    nope not necessary

     

    Can you give actual examples of the context these things are in?  I'm thinking it would be easier to just

     

    ~\{([^\}]+)\}~

     

    and then explode at the dot.

    hmm sounds like an idea.. im gonna see if nrg_alpha's method works.. if it doesn't ill be using this.. thanks

     

    If I understand correctly, would this be along the lines of what you are looking for?

     

    $str = 'Some garbge...{blockname.blockname.varname1}...more garbage...{blockname.blockname.varname2}.. and more garbge yet...{blockname.blockname.varname3}';
    preg_match_all('#{(?:[a-z0-9]+\.?)+}#i', $str, $matches);
    echo "<pre>".print_r($matches[0], true);
    

     

    output:

    Array
    (
        [0] => {blockname.blockname.varname1}
        [1] => {blockname.blockname.varname2}
        [2] => {blockname.blockname.varname3}
    )
    

     

    this of course makes assumptions like the characters between { and the dots and } are a-z (case insensitive) or 0-9. It's a quick and dirty method which can be made more precise, but does the job for the examples you provided. Is this what you're looking for?

    yeah i think that is it :) thanks :)

  9. hi

    im trying to make a template parser in php.. am a bit stuck tho..

    im trying to parse the following: {blockname.blockname.varname}

    that seems to work fine if there is only one of those. but if i have mutliple vars next to eachother like this: {blockname.blockname.varname1} {blockname.blockname.varname2}

    the same thing doesn't work..

    my regex currently is:

    /(\{([^\}](.*?\.)+(.*?)+)\})/

     

    and im using preg_match to find them. however, it doesn't seem to work, i keep getting the following as the result:

    Array
    (
        [0] => {blockname.blockname.varname1} {blockname.blockname.varname2}
        [1] => {blockname.blockname.varname1} {blockname.blockname.varname2}
        [2] => blockname.blockname.varname1} {blockname.blockname.varname2
        [3] => blockname.
        [4] => 
    )

     

    no i use the third array argument ([2]).. which is supposed to be blockname.blockname.varname1 (without the brackets).. but if i have multiple vars on the same line, i get all the stuff inbetween the first and the last var. as u can see i have also tried adding [^\}] but it doesn't seem to work either..

    how can i get multiple of these vars (without the brackets if possible) if they're on the same line? coz what i put down for the regex seems to fail epicly.

     

    thanks for your help :)

    super...

     

  10. i fixed it..

    it was some bug in remotefsize(), which i rewrote without the use of get_headers()

    this is the new function, works in both php4 & php5:

    <?php
    function remotefsize($url) {
    $path = parse_url($url);
    $fso = @fsockopen($path['host'], 80);
    if ($fso) {
    	$header = 'GET ' . $url . ' HTTP/1.0' . "\n";
    	$header .= 'Host: ' . $path['host'] . "\n\n";
    	fwrite($fso, $header);
    
    	$buffer = '';
    	while ($tmp = fread($fso, 1024)) {
    		$buffer .= $tmp;
    	}
    
    	$matches = Array();
    	preg_match('/Content-Length: ([0-9]+)/', $buffer, $matches);
    
    	return substr($buffer, @$matches[1]);
    } else {
    	return false;
    }
    }
    ?>

  11. nope nothing, but i think i have found the problem.. when downloading the video directly, in php5 the browser knows the filesize, but in php4 it doesn't.. infat it goes even past the actual filesize!

    screenshot, the properties window is downloaded using php5, the download window is downloaded using php4:

    untitled536cc.jpg

  12. yh thats what i thought about the code being ok :S but erm about the settings in php, i am not sure coz i use xampp, and switch using the php switcher, but i haven't changed anything at all in the php.ini for both php4 and php5..

    and what do you mean with "see it all about settings using the header so much mate"

    and last.. so you mean calling the code without javascript, just plain HTML.. btw the flash player is not mine, its JW Flash Player..

    so you mean something like this (copied straight from FireBug after fully loaded):

    <embed id="mediaplayer" width="425" height="350" flashvars="width=425&height=351&showstop=true&file=get.php%3Fvid%3DW2SCxlqR8RU%26did%3DOEgsToPDskIPmpYbK8F3VuFP2Q-zQQiO%26filetype%3D.flv&image=get.php%3Fvid%3DW2SCxlqR8RU%26get_image_only%3Dtrue%26file_type%3D.jpg&type=flv" allowfullscreen="true" quality="high" name="mediaplayer" style="" src="argh_player.swf" type="application/x-shockwave-flash"/>

     

     

    greeetzz

  13. sorry how do you mean? if you mean i how call the flash its like this:

    <?php
    $get_array = YoutubeGetLink('IbrjM4aAWHY'); // YoutubeGetLink() generates a link liket his: get.php?vid=IbrjM4aAWHY&did=OEgsToPDskJ1K9lLbCNe_wgYgqZOPhzG&filetype=.flv
    $link = $get_array['link'];
    ?>
    <div id="container"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.</div>
    <script type="text/javascript">
    <!--
    var object = new SWFObject("argh_player.swf", "mediaplayer", "425", "350", "7");
    object.addParam("allowfullscreen", "true");
    object.addVariable("width", "425");
    object.addVariable("height", "351");
    object.addVariable("showstop", "true");
    object.addVariable("file", encodeURIComponent("<?php echo $link; ?>"));
    object.addVariable("image", encodeURIComponent("<?php echo $img; ?>"));
    object.addVariable("type", "flv"); // this forces to read the file as an .flv file
    object.write("container");
    -->
    </script>

  14. Hey guys

     

    i have just recently created this function to get a video from youtube, it uses the function readfile() to use it also when the website is block and 'remotefsize()' to get the remote file size (custom function)

    the file can also read two images from youtube (also using readfile) depending an the get variables it gets which is 'http://img.youtube.com/vi/youtubeID/default.jpg' amd 'http://img.youtube.com/vi/youtubeID/0.jpg' (where youtubeID is the id that leads to the youtube video)

    in the function remotefsize() it used get_headers() which wasn't available in php4, so i got some kind of 'emulator' for it from php.net

    so i got that all working, so now the file it self works perfect in both php4 and php5 (as in they both download normal files when going directly to that page), but when i use as an flash argument to play it, it works only in php5 but not in php4..

    what am i doing wrong here?

    this is the file itself:

    <?php
    
    /*****
    *  This function is created by "denilson at vialink dot com dot br" from php.net
    *  and was found in the comments for the function 'get_headers'
    *  Please note: a few minor changes have been made in this function!
    *******/
    if(!function_exists('get_headers')) {
        function get_headers($url, $format=0) {
            $url=parse_url($url);
            $end = "\r\n\r\n";
            $fp = fsockopen($url['host'], (empty($url['port']) ? 80 : $url['port']), $errno, $errstr, 30);
            if ($fp) {
                $out  = "GET / HTTP/1.1\r\n";
                $out .= "Host: ".$url['host']."\r\n";
                $out .= "Connection: Close\r\n\r\n";
                $var  = '';
                fwrite($fp, $out);
                while (!feof($fp)) {
                    $var .= fgets($fp, 1280);
                    if(strpos($var,$end)) {
    				break;
    			}
                }
                fclose($fp);
    
                $var=preg_replace("/\r\n\r\n.*\$/",'',$var);
                $var=explode("\r\n",$var);
                if($format) {
                    foreach($var as $i) {
                        if(preg_match('/^([a-zA-Z -]+): +(.*)$/',$i,$parts)) {
                            $v[$parts[1]] = $parts[2];
                        }
                    }
                    return $v;
                } else {
                return $var;
                }
            }
        }
    }
    
    if(isset($_GET['vid']) && isset($_GET['did'])) {
    $vid = $_GET['vid'];
    $did = $_GET['did'];
    } else if (isset($_GET['vid']) && ((isset($_GET['get_image_only']) && $_GET['get_image_only'] == 'true') || (isset($_GET['get_big_image']) && $_GET['get_big_image'] == 'true')))  {
    $vid = $_GET['vid'];
    } else {
    die('We are missing something, you got 3 guesses!');
    }
    function remotefsize($url) {
    $sch = parse_url($url);
    if (($sch['scheme'] != "http") && ($sch['scheme'] != "https")) {
    	return false;
    }
    $headers = get_headers($url, 1);
    if ((!array_key_exists("Content-Length", $headers))) {
    	return false;
    }
    return $headers["Content-Length"];
    }
    
    $yt_url = "http://youtube.com/get_video?video_id=$vid&t=$did";
    $content_type = "video/flv";
    if(isset($_GET['get_image_only']) && $_GET['get_image_only'] == 'true') {
    $yt_url = "http://img.youtube.com/vi/$vid/default.jpg";
    $content_type = "image/jpeg";
    } else if (isset($_GET['get_big_image']) && $_GET['get_big_image'] == 'true') {
    $yt_url = "http://img.youtube.com/vi/$vid/0.jpg";
    $content_type = "image/jpeg";
    }
    
    $yt_size = remotefsize($yt_url);
    header ("Content-transfer-encoding: binary");
    header ("Content-Type: ".$content_type);
    header ("Content-Disposition: attachment; filename=\"" . basename($yt_url) . "\"");
    header ("Content-Length: " . $yt_size);
    header ("Pragma: public");
    header ("Expires: 0");
    header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header ("Cache-Control: private");
    readfile($yt_url);
    
    ?>

     

    thanks

  15. Thx .. it worked, it was without the ON bit .. i added it and it worked :) thx
    here is the query for other people
    [code]
    SELECT DISTINCT
        m.*,
        f.*,
        o.*
    FROM members AS m
        LEFT JOIN online AS o ON o.userid = m.id
        LEFT JOIN friends AS f ON f.userid = m.id
    WHERE
        m.id > 0[/code]
  16. ok i tried this one:
    [code]SELECT DISTINCT
        m.*,
        f.*,
        o.*,
    FROM members AS m
        LEFT JOIN online AS o
        LEFT JOIN friends AS f
    WHERE
        m.id > 0[/code]

    but i get this error from MySQL

    [quote]
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM members AS m LEFT JOIN online AS o LEFT JOIN friends AS f WHERE ' at line 5
    [/quote]

    what does it mean?
×
×
  • 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.