Jump to content

Library


The Little Guy

Recommended Posts

Auth: http://tests.phpsnips.com/phpfreaks.txt

 

For the past year or so, I have been working on a library to help people program. It is a fairly easy to use library (In My Opinion), my site has documentation on a fair amount of the library, but the documentation is still not complete.

 

So, I have 2 questions to ask of you:

 

1. What do you think of the documentation that is there, was it helpful?

2. What do you think of the library its self? What could be improved and what did/din't you like?

 

Some powerful/Useful features in my opinion are:

 

- Easily send mail with 1+ attachments

$to = array("Billy Bob", "billybob@example.com");
$from = array("Jimmy", "jimmy@example.com");
$subject = "Hello Billy Bob!";
$message = "Just cheking up on you!";
$files = array("/files/file1.png", "/files/file2.jpg");
$live->mail($to, $from, $subject, $message, MAIL_ATTACHMENT, $files);

 

- Easily zip up some files and download them on the fly

$files = array(
    "/path/to/file1.php" => "file1.php",
    "/path/to/text/license.txt" => "docs/license.txt",
    "extensions/"
);
$live->zip($files)->download(PHP_TMPFILE, "myFiles.zip");
exit;

 

- Grab all the links from a webpage:

print_r($live->getHttp("http://somesite.com")->getLinks()->list);

 

- Some methods have a callback function, such as each(), where the following code can convert a handful links into full URLS (following method format requires php 5.3.x or higher. You could place the function in another function and call the function for php 5.2.x and lower)

print_r($live->getHttp("http://phplive.org")->getLinks()->each(function($link){
    global $live;
    $url_info = (object)parse_url($live->endingUrl);
    $domain = $url_info->scheme."://".$url_info->host;
    if(preg_match("/^\//", $link)){
        return $domain.$link;
    }elseif(!preg_match("/^http/", $link)){
        return $live->endingUrl."/".$link;
    }
    return $link;
}));

 

There are many other things, such as database methods, threading, mobile device check, operating system check, etc.

 

Here are the related links:

Docs: http://tests.phpsnips.com/docs

Download: http://tests.phpsnips.com/download.php

 

Thank you for your help!

Link to comment
Share on other sites

The use of global in your callback example could (and should) be avoided.

 

print_r($live->getHttp("http://phplive.org")->getLinks()->each(function($link) use ($live) {
    $url_info = (object)parse_url($live->endingUrl);
    $domain = $url_info->scheme."://".$url_info->host;
    if(preg_match("/^\//", $link)){
        return $domain.$link;
    }elseif(!preg_match("/^http/", $link)){
        return $live->endingUrl."/".$link;
    }
    return $link;
}));

Link to comment
Share on other sites

  • 3 weeks later...

I just added a new feature, that some may like some would be like what ever, but it kind of makes one of the php constructs easier:

 

$value = mt_rand(0, 600);
// normal php:
if($value == 1 || $value == 10 || $value == 22 || $value == 25 || $value == 567 || $value == 124)

// phpLive:
if($live->in($value, 1, 10, 22, 25, 567, 124))

Link to comment
Share on other sites

  • 2 weeks later...
  • 6 months later...

Just wanted to let you know that I'm still looking at your class, in amongst the other stuff I got on my plate. It's a big class, and not a whole lot of comments, so it's slow progress I'm afraid.

 

Anyway, I have noticed some conundrums in your code. For instance at line 252 & 253:

		if ($string != null)
		$string = $string;

Missing something here, or..?

 

The getCleanData () method also features some unnecessary escaping, plus some missing escaping. Last bit in the RegExp that's meant to remove HTML comments, as you've only escaped one of the dashes.

 

I'm not quite sure the eval () call on line 1061 is necessary either, and I suspect you can do a lot better without it.

 

There's a typo at line 1091, where you've used $im instead of $img.

 

On line 1387 you have used an undefined function: mysql_fetch_fields (). It's strictly a MySQLi function, an the comparable function would be mysql_fetch_object ().

 

Line 1529 has a minor issue, where you've passed a variable by reference without first declaring it.

 

On line 2008, on the other hand, we find this:

$this->list = $_GETS;

Typo?

 

On lines 2285, 2297, 2312, 2327, 2342, 2357 and 2372 we find another undefined variable, namely $var. Did you meant to use $date instead?

 

On lines 2528-2530 you're sending multiple content-type headers. This has no effect, as the latter one will replace the previous. This means that the only content type that's being sent to the browser, is the last one. As evidenced by this example, where I used these three lines:

HTTP/1.1 200 OK
Date: Tue, 14 Aug 2012 16:36:58 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.3.14 ZendServer/5.0
Set-Cookie: ZDEDebuggerPresent=php,phtml,php3; path=/
Content-Length: 0
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/download;

 

That's the primary look at your code, but I'll go more in depth as soon as I get the time for it.

 

As for the manual, it's quite well written. Though, I'm missing the "why's" behind what you do what you do. Explain a bit more around the reasoning behind the choices, and what happens in the background, and I people will find it a lot easier to really learn from it. ;)

Link to comment
Share on other sites

×
×
  • 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.