Re: [PHP] enabling domdocument

2010-07-19 Thread Michael A. Peters

Ashley Sheridan wrote:




OK, I seem to have answered my own question!

It seems that even though PHP had the XML module enabled, I still needed
to run 'yum update php-xml' in order for it to load in the DOM module.
It's now working fine, and for those of you interested, the ./configure
line in phpinfo() still says --disable-dom!


Yes.
I'm quite familiar with the rpm build process for php.

The initial build of php is without support for any of the modules. Then 
the modules are built. So the configure command for the core php apache 
DSO has just about everything disabled.


A nasty side effect of doing it this way - if you ever need to rebuild 
the src.rpm, either do it in a chroot build environment (such as mock) 
or be sure to remove all the old php packages - because what can happen 
is the new php is built but when it then goes to build the modules, it 
links them against installed php instead of the php it just built.


They may have fixed that in the Makefile, I don't know, but the net 
result can be a set of rpms that are broken.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Stumped - MDB2 pgsql

2010-07-15 Thread Michael A. Peters
I need to switch from MySQL (where everything is peachy) to Postgresql - 
reason I need to switch is I need to use PostGIS and I don't see a need 
to run two databases.


I got Postgresql installed (stock CentOS / RHEL 5) and installed the 
postgresql php module and mdb2 driver. Restarted the web server.


Did a MySQL dump, ran it through a perl script, and managed to get it 
load into Postgresql without any apparent hickups. I can connect to 
postgresql and issue queries and expected results are in fact returned.


Made a user called webuser (what, you expect the real name to be 
disclosed here ??) in postgresql and gave it a password and access to 
the database. Updated the data/pg_hba.conf to add the following line:


localmydbname webuser   127.0.0.1 password

restarted the postgresql server.

I *thought* that all I would then have to do is change my mdb2 dsn to 
reflect the new driver to use and then find parts of my code that are 
not standard enough SQL - but when I try to use anything, I get -


Fatal error: Call to undefined method MDB2_Error::execute() in 
/path/to/blah  on line 63


I'm missing something here.

Here's my dsn -

$dsn = array(
   'phptype'  = 'pgsql',
   'username' = 'webuser',
   'password' = 'secret',
   'hostspec' = 'localhost',
   'database' = 'mydbname');

What am I doing wrong?
I get the same error no matter what I set 
username/password/hostspec/database to - so I think it is a basic 
connection error.


I'm hoping to be able to get the switch to postgresql finished soon so 
that I can start playing with using the PostGIS extension.


I'm running php 5.2.12 (my own build, based on Fedora src.rpm) w/ pear 
1.8.1:


pear list
Installed packages, channel pear.php.net:
=
Package   Version State
Archive_Tar   1.3.3   stable
Console_Getopt1.2.3   stable
Date  1.4.7   stable
MDB2  2.4.1   stable
MDB2_Driver_mysql 1.4.1   stable
MDB2_Driver_pgsql 1.4.1   stable
PEAR  1.8.1   stable
Structures_Graph  1.0.2   stable
Text_Highlighter  0.7.1   beta
XML_Parser1.3.2   stable
XML_RPC   1.5.1   stable
XML_Util  1.2.1   stable

Thanks for suggestions.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Stumped - MDB2 pgsql

2010-07-15 Thread Michael A. Peters

Michael A. Peters wrote:
I need to switch from MySQL (where everything is peachy) to Postgresql - 
reason I need to switch is I need to use PostGIS and I don't see a need 
to run two databases.


I got Postgresql installed (stock CentOS / RHEL 5) and installed the 
postgresql php module and mdb2 driver. Restarted the web server.


Did a MySQL dump, ran it through a perl script, and managed to get it 
load into Postgresql without any apparent hickups. I can connect to 
postgresql and issue queries and expected results are in fact returned.


Made a user called webuser (what, you expect the real name to be 
disclosed here ??) in postgresql and gave it a password and access to 
the database. Updated the data/pg_hba.conf to add the following line:


localmydbname webuser   127.0.0.1 password

restarted the postgresql server.

I *thought* that all I would then have to do is change my mdb2 dsn to 
reflect the new driver to use and then find parts of my code that are 
not standard enough SQL - but when I try to use anything, I get -


Fatal error: Call to undefined method MDB2_Error::execute() in 
/path/to/blah  on line 63


I'm missing something here.

Here's my dsn -

$dsn = array(
   'phptype'  = 'pgsql',
   'username' = 'webuser',
   'password' = 'secret',
   'hostspec' = 'localhost',
   'database' = 'mydbname');

What am I doing wrong?
I get the same error no matter what I set 
username/password/hostspec/database to - so I think it is a basic 
connection error.


Yes, I put some error catching in -

MDB2 Error: connect failed, _doConnect: [Error message: unable to 
establish a connection]


So it looks like pg_hba.conf file either isn't allowing it or something 
else is blocking it.


*sigh* - guess back to trying to find document on setting up 
authentication for an account for a pgsql web app user because the docs 
I did find don't seem to be accurate.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Stumped - MDB2 pgsql

2010-07-15 Thread Michael A. Peters

Michael A. Peters wrote:

Michael A. Peters wrote:
I need to switch from MySQL (where everything is peachy) to Postgresql 
- reason I need to switch is I need to use PostGIS and I don't see a 
need to run two databases.


I got Postgresql installed (stock CentOS / RHEL 5) and installed the 
postgresql php module and mdb2 driver. Restarted the web server.


Did a MySQL dump, ran it through a perl script, and managed to get it 
load into Postgresql without any apparent hickups. I can connect to 
postgresql and issue queries and expected results are in fact returned.


Made a user called webuser (what, you expect the real name to be 
disclosed here ??) in postgresql and gave it a password and access to 
the database. Updated the data/pg_hba.conf to add the following line:


localmydbname webuser   127.0.0.1 password

restarted the postgresql server.

I *thought* that all I would then have to do is change my mdb2 dsn to 
reflect the new driver to use and then find parts of my code that are 
not standard enough SQL - but when I try to use anything, I get -


Fatal error: Call to undefined method MDB2_Error::execute() in 
/path/to/blah  on line 63


I'm missing something here.

Here's my dsn -

$dsn = array(
   'phptype'  = 'pgsql',
   'username' = 'webuser',
   'password' = 'secret',
   'hostspec' = 'localhost',
   'database' = 'mydbname');

What am I doing wrong?
I get the same error no matter what I set 
username/password/hostspec/database to - so I think it is a basic 
connection error.


Yes, I put some error catching in -

MDB2 Error: connect failed, _doConnect: [Error message: unable to 
establish a connection]


So it looks like pg_hba.conf file either isn't allowing it or something 
else is blocking it.


Possibly solved.
This line works -

hostmydbname webuser   127.0.0.1/32 password

provided I removed the previous host line that specified authentication 
by ident for all users connection via tcp from localhost.


Still getting errors, but now its a db grant issue and not a connection 
issue, so i think I'm good to go.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Will PHP ever grow up and have threading?

2010-03-24 Thread Michael A. Peters

Tommy Pham wrote:



The response time, max 5 seconds, will be tested on local gigabit LAN
to ensure the adequate response (optimized DB  code  proper
hardware) without worrying about users' connection limit and site's
upload bandwidth limit (which can easily rectify).  Then thereafter
will be doing stress test of about 10 concurrent users.  As for the
major queries, that's where threads come in, IMO, because those
queries depend on 1 primary parameter (category ID) and 1 secondary
parameter (language ID).  This particular site starts with 500
products about 15 categories, without many of those mentioned filters,
later grew to its current state.



I don't know about the proposed scenario you give.
But I do know when my own site felt a little sluggish, I implemented APC 
and a cron job that preloads all the queries at the beginning of the 
day. Any changes to a table dump the cache and reload it. Site is now 
fast and the database is only pounded in the early AM cache preload 
(which may actually not even be necessary, but I do it just in case 
there are any scenarios where I change DB and forget to nuke cache for 
effected queries).


If database is your bottleneck, APC (or other caching methods) is your 
friend.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Will PHP ever grow up and have threading?

2010-03-23 Thread Michael A. Peters

Rene Veerman wrote:



But i've yet to find a way to keep global objects in memory between
http requests, outside $_SESSION, which i believe is just stored to-
and loaded from disk between http requests.


You can store sessions in a cache and avoid the disk IO.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Will PHP ever grow up and have threading?

2010-03-23 Thread Michael A. Peters

Tommy Pham wrote:

On Tue, Mar 23, 2010 at 3:33 PM, Per Jessen p...@computer.org wrote:

Tommy Pham wrote:


On Tue, Mar 23, 2010 at 2:04 AM, Per Jessen p...@computer.org wrote:

Use the right tool for the right job - PHP is a scripting/interpreted
language, it does not need threading (IMO of course).


--
Per Jessen, Zürich (9.4°C)



I couldn't agree more.  But here's a real life example.  Your client
has a forum and is using phpbb for their in house use.  They also have
an in house custom PHP app, integrated with phpbb, built to suit their
needs.  Now they want to implement some kind of CMS.  You come in and
implemented a PHP based CMS to integrate into their existing
applications.  Then you realize something troublesome, you have a
performance issue where it could be resolved by implementing thread.
What are you going to do?

The standard, mature, experienced answer is - buy a bigger box.



The company started small.  As their business grows because they have
products  services that do not exist in the marketplace, their
hardware are already growing along side with it, (load balancers,
clusters).  So then your solution is buy bigger/more boxes?  What if
the their server room is filled and already using recent hardware.
Their current business needs doesn't need to move to a bigger
building.  What then? Hire data center's services?


Very few companies have a legitimate reason to run their own server room 
at this point in time and should be using a data center if they are not 
already.


Data centers have excellent bandwidth, diesel generators to keep things 
live during sustained power outages, temperature control to keep things 
cool, and often have technicians on hand with spare parts that can take 
care of many hardware issues 24/7.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP SMTP Mailers

2010-03-22 Thread Michael A. Peters

King Coffee wrote:

Hi,

I'm executing a third-parity standard PHP application on a Windows IIS 7 
shared hosting server.


I need to convert, or use, a SMTP mailer service.  I found two SMTP PHP 
scripts - I think may work.


The sourceforge.net PHPMailer project and the pear.php.net (Mail, 
Net_SMTP) project.


Can any body please help me choose one and probably give a code snip of 
useage?


Currently, I'm leaning forward the PHPMailer, with little to base the 
decision on.


Thanks in advanced,
King Coffee



I use phpmailer and find it to be painless and consistent.

I extend the class and call the extended class:

?php
require(class.phpmailer.php);

class MyMailer extends PHPMailer {
// Set default variables for all new objects
var $From = zon...@shastaherps.org;
var $FromName = Lampro P. Eltis;
var $ReplyTo  = mpet...@mac.com;
var $Host = localhost;
var $Mailer   = smtp;  // Alternative to IsSMTP()
var $WordWrap = 75;
}
?

Then when I want to use it -

$mail = new MyMailer();
$mail-Subject  = Some Subject;
$mail-Body = Some content;
if($mail-Send()) {
   // it was successfully sent, code on success here
   } else {
   // there was an error, error code here
   }

I never send HTML mail or attachments or bulk mail, but I believe it is 
capable of doing them quite easily.


Tip: Whatever solution you use, set the wordwrap to something that works 
well on an 80 char display. Some clients do not autowrap unwrapped 
messages and other clients wrap for display but when replying, it 
doesn't wrap.


I use 75 because it gives a little room for the   that accompanies a 
reply.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP in HTML code

2010-03-19 Thread Michael A. Peters

Jan G.B. wrote:

2010/3/18 tedd tedd.sperl...@gmail.com:

Calling it ranting or religious unjustly demeans the discussion and is
inflammatory.
In all of this, I've simply said it's your choice.


What I said was:
*persons ranting about short open tags* *are just like some religious people
*


I don't care what people do in their code.
I do not like released code with short tags, it has caused me problems 
when trying to run php webapps that use short tags, I have to go through 
the code and change them.


So what people do with their private code, I could care less about.
But if releasing php code for public consumption, I guess I'm a preacher 
asking people to get religion, because short tags do not belong in 
projects that are released to the public. Just like addslashes and magic 
quotes and most html entities should not be used in php code released 
for public consumption.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] any reason *not* to use PEAR DB module when accessing mysql?

2010-03-19 Thread Michael A. Peters

Mattias Thorslund wrote:

Robert P. J. Day wrote:

  (just a warning -- as a relative newbie to PHP, i'll probably have
the occasional dumb question.  just humour me.)

  i'm looking at some existing PHP code that accesses a mysql 5.0 db,
and it's coded using the mysql-specific calls:  mysql_connect,
mysql_select_db, etc, etc.

  is there any reason i *wouldn't* want to rewrite that code using the
more general PEAR DB module, and use mysqli?  certainly, as i read it,
using the PEAR DB module would make it easier down the road if i
suddenly decide to change the DB backend.

  anyway, any compelling arguments for or against?

rday
--
  


Well, the reason you shouldn't use PEAR DB in a new project is that it's 
being deprecated. MDB2 is the PEAR successor, and does provide emulation 
for some features that don't exist on all database platforms, such as 
LastInsertID. It can also help you convert your database from one 
platform to another, since it also provides methods for detecting and 
managing the database structure itself (the Manager and Reverse modules).


That said, if I were to start a new project at this time, I would look 
closer at whether PDO fits my needs.


I use MDB2.
I hear PDO hyped a lot, what does it really give me that MDB2 does not, 
other than making the application dependent upon a binary module?


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: Fwd: Re: [PHP] any reason *not* to use PEAR DB module when accessing mysql?

2010-03-19 Thread Michael A. Peters

Nilesh Govindarajan wrote:

On 03/20/2010 02:31 AM, Michael A. Peters wrote:

Mattias Thorslund wrote:

Robert P. J. Day wrote:

(just a warning -- as a relative newbie to PHP, i'll probably have
the occasional dumb question. just humour me.)

i'm looking at some existing PHP code that accesses a mysql 5.0 db,
and it's coded using the mysql-specific calls: mysql_connect,
mysql_select_db, etc, etc.

is there any reason i *wouldn't* want to rewrite that code using the
more general PEAR DB module, and use mysqli? certainly, as i read it,
using the PEAR DB module would make it easier down the road if i
suddenly decide to change the DB backend.

anyway, any compelling arguments for or against?

rday
--


Well, the reason you shouldn't use PEAR DB in a new project is that
it's being deprecated. MDB2 is the PEAR successor, and does provide
emulation for some features that don't exist on all database
platforms, such as LastInsertID. It can also help you convert your
database from one platform to another, since it also provides methods
for detecting and managing the database structure itself (the Manager
and Reverse modules).

That said, if I were to start a new project at this time, I would look
closer at whether PDO fits my needs.


I use MDB2.
I hear PDO hyped a lot, what does it really give me that MDB2 does not,
other than making the application dependent upon a binary module?



binary module makes a lot of difference. If you use MDB2, the
interpreter has to compile MDB2's code along with your program logic.
Whereas PDO is already compiled one, so it will do the job much much 
faster.




So since I already cash my db requests via APC the benefits to me would 
be small.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] XML functions

2010-03-06 Thread Michael A. Peters

Ahmad F AlTwaijiry wrote:

Dears

When i checked the php manual i found many Solutions to read/write xml 
files and im confused now :)


Which function/library is better and is there any new article that 
compare each function/library?


I use DOMDocument.
It works best if the input file you are reading is UTF-8.

It has some issues I haven't yet figured out related to namespaces, 
sometimes when loading perfectly valid XML that uses namespaces for 
import into another document, I lose the namespace and get default 
prepended to the node name. I do not understand why it feels it needs to 
do this, but it apparently does in some cases.


For those cases, I currently use hackish workarounds where I remove the 
namespace with a preg_replace before import into the DOM and then add 
the namespace again using the DOM tools after it has been imported.


Where I have run into this problem is MathML and SVG within XHTML when I 
cache the MathML/SVG as a string in APC for import into documents.


It is not so much an issue with SVG in XHTML as SVG probably is best 
done as an object rather than directly embedded (but when generating SVG 
via DOMDocument I have a similar problem if I am using xlink namespace) 
but it is a problem with MathML which is usually done inline.


It could just be that I'm doing things wrong, but the documentation 
isn't exactly full of working example code.


So anyway, if you use namespaces, you may run into a few frustrating 
kinks, but DOMDocument is what I use, and it is very convenient because 
it is very similar to the JavaScript DOM2 methods (I believe intentionally).


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] XML functions

2010-03-06 Thread Michael A. Peters

Andre Polykanine wrote:

Hello Ahmad and all,

  I will expand a little bit your question joining to it: what is
  the better technique to make an RSS feed on the website? The
  website is manually written, no CMS.


I wrote a class to do it -

http://www.phpclasses.org/browse/package/5942.html

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PEAR clases don't work with PHP 5.3

2010-03-05 Thread Michael A. Peters

Martín Marqués wrote:

A few days ago I upgraded my development server with PHP 5.3, and
found that some pear packages stopped working giving FATAL ERRORs,
like this (this one is from package Image_Graph):

PHP Fatal error:  Call to undefined method
Image_Graph_Plotarea_Element::Image_Graph_Element() in
/usr/share/php/Image/Graph/Layout.php on line 73

I found that the problem is when calling the parents constructors like
parent::ClassName.

Changing that fixes the problem, but there are alot of clases with this problem.

Are these problems being addressed?



I found similar problems with some of the pear stuff I use when I tried 
5.3.0 awhile back. For the present, I am just sticking with 5.2.x branch 
and will give some time for the various pear maintainers to work out the 
kinks.


One thing you can do is file bug reports with the pear components you 
use. I did not because I moved my test server back to 5.2.x thus I would 
have no way of testing whether the fixes actually worked, but if you 
have a box you can dedicate to 5.3.x testing, file the bug reports and 
it will bring the problem to the attention of the pear maintainers.


Some pear packages are better maintained than others.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] svg 2 gif/png

2010-03-03 Thread Michael A. Peters

I'm moving all of my dynamic image generation to svg.
Not only does it look better, but it is less resource intensive on my 
server allowing me to generate the svg on demand instead of 
pre-generating (via cron) twice a month like I had to do with gd dynamic 
generation.


However, some browsers *cough*IE*cough* do not support SVG, so I still 
need png or gif fallback (I'll decide which after investigating size 
difference).


Example SVG to convert -

http://www.shastaherps.org/map/map22.svg

Using convert from ImageMagick in the CLI is fast enough that I may just 
use the ImageMagick php module and do the fallback dynamic for the IE 
users, but I've run into a bit of a snag - it seems that ImageMagick 
doesn't understand xlink.


IE running

convert --size=800x574 map22.svg map22.png

on above file results in a nice pretty map with the county and text, but 
the colored hexagons are not displayed.


Is there an easy way around this? IE a php class/function that 
understands SVG w/ xlink and can replace the use tags with the polygons 
they refer to? If not, I'll have to try to write one, but I'd rather not ...


Thanks for suggestions. It is too bad ImageMagick doesn't understand the 
use tag and xlink, that is one of the more useful features of SVG that I 
have personally found, makes dynamic generation so much easier.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] svg 2 gif/png

2010-03-03 Thread Michael A. Peters

Michael A. Peters wrote:
*snip*


Is there an easy way around this? IE a php class/function that 
understands SVG w/ xlink and can replace the use tags with the polygons 
they refer to? If not, I'll have to try to write one, but I'd rather not 
...


I just did, haven't tested yet, but this may work -

function use2polygon($use,$polygon) {
   // get the xy coords
   $x = 0; $y = 0;
   if ($use-hasAttribute('x') {
  $x = 0 + $use-getAttribute('x');
  }
   if ($use-hasAttribute('y') {
  $y = 0 + $use-getAttribute('y');
  }
   // clone the polygon
   if ($polygon-hasAttribute('points') {
$points = preg_replace('/\s+/',' ',$polygon-getAttribute('points'));
  $pointArray = explode(' ',$points);
  $sizeof = sizeof($pointArray);
  for ($i=0;$i$sizeof;$i++) {
 $foo = explode(',',$pointArray[$i]);
 $foo[0] = $x + $foo[0];
 $foo[1] = $y + $foo[1];
 $pointArray[$i] = $foo[0] . ',' . $foo[1];
 }
  $points = implode(' ',$points);
  $newPolygon = $polygon-cloneNode(true);
  $newPolygon-setAttribute('points',$points);
  $use-parentNode-replaceChild($newPolygon,$use);
  }
   }

of course that requires domdocument and probably requires looping 
through the dom node list backwards, but hopefully that will do it.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] svg 2 gif/png

2010-03-03 Thread Michael A. Peters

Michael A. Peters wrote:

Michael A. Peters wrote:
*snip*


Is there an easy way around this? IE a php class/function that 
understands SVG w/ xlink and can replace the use tags with the 
polygons they refer to? If not, I'll have to try to write one, but I'd 
rather not ...


I just did, haven't tested yet, but this may work -


This does work (fixed version of function):

function use2polygon($use,$polygon) {
   // get the xy coords
   $x = 0; $y = 0;
   if ($use-hasAttribute('x')) {
  $x = 0 + $use-getAttribute('x');
  }
   if ($use-hasAttribute('y')) {
  $y = 0 + $use-getAttribute('y');
  }
   // clone the polygon
   if ($polygon-hasAttribute('points')) {
$points = preg_replace('/\s+/',' ',$polygon-getAttribute('points'));
  $pointArray = explode(' ',$points);
  $sizeof = sizeof($pointArray);
  for ($i=0;$i$sizeof;$i++) {
 $foo = explode(',',$pointArray[$i]);
 $foo[0] = $x + $foo[0];
 $foo[1] = $y + $foo[1];
 $pointArray[$i] = $foo[0] . ',' . $foo[1];
 }
  $points = implode(' ',$pointArray);
  $newPolygon = $polygon-cloneNode(true);
  $newPolygon-setAttribute('points',$points);
  $use-parentNode-replaceChild($newPolygon,$use);
  }
   }

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] svg 2 gif/png

2010-03-03 Thread Michael A. Peters

Michael A. Peters wrote:

Michael A. Peters wrote:

Michael A. Peters wrote:
*snip*


Is there an easy way around this? IE a php class/function that 
understands SVG w/ xlink and can replace the use tags with the 
polygons they refer to? If not, I'll have to try to write one, but 
I'd rather not ...


I just did, haven't tested yet, but this may work -


This does work (fixed version of function):

function use2polygon($use,$polygon) {
   // get the xy coords
   $x = 0; $y = 0;
   if ($use-hasAttribute('x')) {
  $x = 0 + $use-getAttribute('x');
  }
   if ($use-hasAttribute('y')) {
  $y = 0 + $use-getAttribute('y');
  }
   // clone the polygon
   if ($polygon-hasAttribute('points')) {
$points = preg_replace('/\s+/',' ',$polygon-getAttribute('points'));
  $pointArray = explode(' ',$points);
  $sizeof = sizeof($pointArray);
  for ($i=0;$i$sizeof;$i++) {
 $foo = explode(',',$pointArray[$i]);
 $foo[0] = $x + $foo[0];
 $foo[1] = $y + $foo[1];
 $pointArray[$i] = $foo[0] . ',' . $foo[1];
 }
  $points = implode(' ',$pointArray);
  $newPolygon = $polygon-cloneNode(true);
  $newPolygon-setAttribute('points',$points);
  $use-parentNode-replaceChild($newPolygon,$use);
  }
   }



doh - for xml sanity, add this before the replaceChild

if ($newPolygon-hasAttribute('id')) {
 $newPolygon-removeAttribute('id');
 }

Now it works, and makes identical svg image that works with convert.

http://www.shastaherps.org/map/map22.svg vs
http://www.shastaherps.org/map/map22.svg?convert=true

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] loadXML() and namespace

2010-02-17 Thread Michael A. Peters

Michael A. Peters wrote:
It seems that if I use loadXML($string) and the $string has a namespace 
defined in it, domdocument is nuking the namespace and changing the 
nodenames from whatever to defaultwhatever.


Example -

math xmlns=http://www.w3.org/1998/Math/MathML;
  mrow

*snip*

  /mrow
/math

would get changed to

defaultmath
  defaultmrow

*snip*

  /defaultmrow
/defaultmath

which of course breaks the page.


It seems to be related to the xml island concept of (x)html 5 where 
for compatibility with IE and MathType etc. an xmlns is declared as an 
attribute but a prefix isn't declared (IE no m:math).


To solve it, on the buffered string that gets imported I run:

function nsIsland($string) {
   $search[]  = /math\s([^xmlns]*)xmlns=[^\s]*/;
   $replace[] = math $1;
   return preg_replace($search,$replace,$string);
   }

(I assume I may have to add a search/replace for svg) - then after 
import I look for math nodes and add the xmlns attribute back to them, 
and it seems to work.


A bit hackish, I'm guessing a future version of DOMDocument may take the 
html5 xml island into consideration, but this works now.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: UK Project Opportunity

2010-02-17 Thread Michael A. Peters

Daniel Brown wrote:

On Wed, Feb 17, 2010 at 16:23, Manuel Lemos mle...@acm.org wrote:

What about you? How many times have you shared your Open Source code?


HA!  That's hilarious that you would say that to *me.*  I actually
laughed out loud.  I'll probably do it a few more times before the day
is out.

Well, Manuel, you've just earned a rightful spot in my permanent
SPAM-direction filter, and I will now publicly state that I will NEVER
use phpclasses.org, nor will I recommend that anyone else do the same.


That's your choice to make, but I think this thread has got out of hand 
and needs to stop.


Some people do not like his decisions. Fine, we get it. Those people do 
not have to use his resource. There, problem solved.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] importNode issue

2010-02-16 Thread Michael A. Peters

Michael A. Peters wrote:
I'm experiencing a slight problem with importNODE putting unwanted 
carriage returns in the the output.


Here's my function:

// syntax highlighting
include_once('Text/Highlighter.php');

function syntaxHighlight($dom,$lang,$code) {
   $hl = Text_Highlighter::factory($lang);
   $out = $hl-highlight($code);
   //die($out);
   $tmpDOM = new DOMDocument('1.0','UTF-8');
   $tmpDOM-loadXML($out);
   $foo = $tmpDOM-saveXML();
   //die($foo);

   $nodeList = $tmpDOM-getElementsByTagName('div');
   $impDIV = $nodeList-item(0);
   $returnDIV = $dom-importNode($impDIV,true);

   return $returnDIV;
   }

-=-

Here's my test:

$code  =?php . \n\n;
$code .=require_once('/path/to/something'); . \n;
$code .=function somefunc(\$myfoo,\$mybar) { . \n;
$code .=   \$myfoobar = \$myfoo . \$mybar; . \n;
$code .=   return \$myfoobar; . \n;
$code .=   } . \n;
$code .=? . \n;

$fooTest = syntaxHighlight($dom,'PHP',$code);

-=-

If I uncomment the die($out) - I get what I expect spit to the screen, 
view source shows code that will do what I want.


If instead I uncomment die($foo) - I also get what I expect spit to 
screen. view source shows code that will do what I want.


However, if the function is allowed to continue, the imported div has 
carriage returns between each and every /spanspan which of course 
completely breaks the browser display because they are inside a 
pre/pre node.


Anyone know why importNode does this and how to fix it?

The only (untried) solution I can think of is to replace each carriage 
return with a br / and every space with #160; and then replace the 
pre with a div class='monospace' or some such hackery before running 
loadXML() on it. But I would rather not do that.


php 5.2.12 built against libxml 2.6.26



Found the solution - the problem was where Text/Highlighter.php was 
putting the newline in the code it generates.


$out = preg_replace(/span class=\hl-code\\n/,\nspan 
class=\hl-code\,$out);


fixes the issue, I don't have to set

$dom-formatOutput = false;

to avoid broken display now.
I think it's a DOMDocument bug, well, maybe, it shouldn't do any 
modifications with newlines inside a pre node with formatOutput - but I 
suppose it has no way of knowing what the pre node is use for since html 
5 doctype doesn't identify itself as html.


But anyway, that preg_replace fixes it.
I may send a demo of problem and patch to the pear Text/Highlighter.php 
maintainer so that the preg_replace isn't needed.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] FTP Site

2010-02-16 Thread Michael A. Peters

Ben Miller wrote:

Hi,

 


I'm building a site for a client that has a need to allow their users to
upload large files (up to 100mb or more) and store them on the server.  I've
never had a need to work with PHP's FTP functions until now and, before I go
reading the manual to learn how, I wanted to see if this something that I
can handle with just PHP, or if I'm going to need to adopt a third party
Ajax app or something like that?  Any thoughts or even a point in the right
direction would be greatly appreciated.  Thanks,

 


You might want to look at how the mozilla add-on firefogg does it.
They have server code example for php.

Basically it splits the file up into chunks (as it encodes it but 
encoding isn't your concern) and when a chunk is received, message is 
sent back to the client telling the client it is OK to send the next chunk.


It may be dependent upon browser functionality though, since it is the 
browser that splits the large upload into smaller manageable chunks.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: UK Project Opportunity

2010-02-16 Thread Michael A. Peters

Nathan Rixham wrote:



You make every interaction with your site a horrible, painful
interaction that is purely there to get as many adverts as you can in
front of people, so that you can bleed every cent possible from the hard
work and effort of PHP developers and innocent users. In short, you take
advantage of your users, members and the PHP community.


While you are entitled to your opinion, as someone with a few classes on 
that site I do not feel taken advantage of in the slightest.


I find it to be a great resource for finding existing classes that often 
do exactly what I need but is not available in pear, and I also have 
found it to be an excellent resource for seeing how other coders solved 
certain problems.


Yes, there are advertisements on the site. Some of the advertisers 
donate useful products to be given as innovation awards and I assume 
some of them do not. Resources like that are not free to operate.


I use to run a yum repository for RHEL/CentOS that provided packages 
from Fedora/Livna that were not available in EPEL.


I had to close it down because after a couple months, my bandwidth costs 
were way too high. I do not know what phpclasses uses in terms of 
bandwidth, but I do not blame him for trying to cover his costs or even 
profiting from the service he provides, I find it to be a service that 
is of a great benefit to me.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] loadXML() and namespace

2010-02-15 Thread Michael A. Peters
It seems that if I use loadXML($string) and the $string has a namespace 
defined in it, domdocument is nuking the namespace and changing the 
nodenames from whatever to defaultwhatever.


Example -

math xmlns=http://www.w3.org/1998/Math/MathML;
  mrow
mrow
  msup
mix/mi
mn2/mn
  /msup
  mo+/mo
  mrow
mn4/mn
mo/mo
mix/mi
  /mrow
  mo+/mo
  mn4/mn
/mrow
mo=/mo
mn0/mn
  /mrow
/math

would get changed to

defaultmath
  defaultmrow
defaultmrow
  defaultmsup
defaultmix/defaultmi
defaultmn2/defaultmn
  /defaultmsup
  defaultmo+/defaultmo
  defaultmrow
defaultmn4/defaultmn
defaultmo/defaultmo
defaultmix/defaultmi
  /defaultmrow
  defaultmo+/defaultmo
  defaultmn4/defaultmn
/defaultmrow
defaultmo=/defaultmo
defaultmn0/defaultmn
  /defaultmrow
/defaultmath

which of course breaks the page.
So it seems I need to somehow tell loadXML() about the namespace so it 
doesn't do that, but I'm not having much luck with the php manual, 
DOMDocument documentation seems a little on the not written side.


When I create the nodes and add them to the dom via domdocument it works 
fine, but the issue is I like to cache the content div as a string and 
load it when the page is requested (stuff outside the content div needs 
to be dynamic and not cached) but this namespace issue prevents that.


Any tips would be appreciated, caching makes a huge difference.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] optional object arguments to a function

2010-02-14 Thread Michael A. Peters

Shawn McKenzie wrote:

Michael A. Peters wrote:

Rene Veerman wrote:

On Sat, Feb 13, 2010 at 9:05 AM, Michael A. Peters mpet...@mac.com
wrote:

How do I specify a default null object, or otherwise make the argument
argument optional?


To my knowledge: can't be done.

But you can check any args through the func_get_arg*() functions, then
per-parameter push 'm through a check function that checks if their
primary properties are set.
It's equivalent to checking for null ( / bad) objects.


Thank you to everybody. I think I will see how far I can get with
func_get_arg - it may solve the problem.

The other hackish solution I thought of is to put the object arguments
into a key/value array and pass the array as a single argument to the
function. That way I can check for the key and if the key is set, grab
the object associated with it.


Maybe I mis-read your post, but what's wrong with Jochem's method.
That's what I was going to propose.



Possibly nothing - but passing an array with keys I think makes it 
easier to determine what the object (a DOM node) corresponds with by 
just looking at the key (IE for a single integral there can be lower 
limit, upper limit, etc.)


Maybe after implementing it that way and actually getting things 
working, I can look into passing the dom objects as actual arguments 
instead of wrapping them in array.


But some existing functions like tidy take some of their optional 
arguments in a key-value array and it is now in php core so it isn't 
unprecedented to use a key-value array.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] optional object arguments to a function

2010-02-13 Thread Michael A. Peters
I've started working on a class using DOMDocument to assemble MathML in 
php. The class, assuming I actually succeed, will eventually be used for 
parsing LaTeX math equations to MathML without the need to have TeX 
installed. I probably won't be able to support all the possibilities for 
equations that LaTeX does w/o a TeX install (and definitely not user 
defined macros) but I suspect I can (hopefully) cover most of the common 
stuff.


One thing I don't know how to do, though, is write a function where 
arguments are optional object.


IE for a function to generate an integral, the limits are optional but 
if specified must be an object (since they may be an equation 
themselves). I want the default to be some kind of a null object so I 
know to do nothing with it if it is null.


With string/integer you just do

function foo($a='',$b='',$c=false) {
  }

How do I specify a default null object, or otherwise make the argument 
argument optional?


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How to secure this

2010-02-13 Thread Michael A. Peters

John Allsopp wrote:

Well no they are not logged in, it's just an embedded iframe so that's 
my main issue with my method, anyone could look at the web page source, 
pinch the URL of the iframe and they'd have the username and password.


I think the only way to do it is to make a key per referring url and use 
the key as a get variable.


Either the referring url matches the key or it doesn't.

That should work with an object/iframe embedding of a resource, browsers 
by default send the referrer header.


A user may turn that off in a browser, but if a user turns that off, the 
user is denied the resource because they changed a default setting. Kind 
of like how I don't get some resources when I turn JavaScript off.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How to secure this

2010-02-13 Thread Michael A. Peters

Michael A. Peters wrote:

John Allsopp wrote:

Well no they are not logged in, it's just an embedded iframe so that's 
my main issue with my method, anyone could look at the web page 
source, pinch the URL of the iframe and they'd have the username and 
password.


I think the only way to do it is to make a key per referring url and use 
the key as a get variable.


Either the referring url matches the key or it doesn't.

That should work with an object/iframe embedding of a resource, browsers 
by default send the referrer header.


Except when the object is handled by a plugin, they are notorious for 
not sending that header (and thus IMHO are broken). But it sounds like 
the resource you are providing is not requested by a plugin.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] optional object arguments to a function

2010-02-13 Thread Michael A. Peters

Rene Veerman wrote:

On Sat, Feb 13, 2010 at 9:05 AM, Michael A. Peters mpet...@mac.com wrote:

How do I specify a default null object, or otherwise make the argument
argument optional?


To my knowledge: can't be done.

But you can check any args through the func_get_arg*() functions, then
per-parameter push 'm through a check function that checks if their
primary properties are set.
It's equivalent to checking for null ( / bad) objects.



Thank you to everybody. I think I will see how far I can get with 
func_get_arg - it may solve the problem.


The other hackish solution I thought of is to put the object arguments 
into a key/value array and pass the array as a single argument to the 
function. That way I can check for the key and if the key is set, grab 
the object associated with it.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] HTML plain text in Outlook 2007

2010-02-12 Thread Michael A. Peters

Ashley Sheridan wrote:




That last reason could be why your email is failing! HTML email is the
one place where it is actually better to code the old way with tables
for markup, font tags, and very little (if any) CSS. If you do use any
CSS, it's best left inline as well, as some email clients strip out
anything within the head tags of your email.


Do e-mail clients handle RTF?
That would seem a better way to do fancy styled e-mail to me than to use 
html tags in an e-mail.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] HTML5 aside description

2010-02-11 Thread Michael A. Peters

If aside is not proper to use for this purpose, what would be?

sidebar suggests a particular type of layout.
section suggests content.
nav is appropriate for some items in a side bar, but not all, and is 
often a child of how aside is being used.

div give no semantics.

I would like to see a toc tag for nav that serves as a table of 
contents of sorts (what I often have at the top of a side bar) but I 
suspect nav is considered sufficient.


Maybe sidebar would be best, and the reference to column type layout 
can just be understood that isn't necessarily on the side?


Reading up on it, I saw some suggest figure for what some of you want 
aside used for, but a figure is often important content and has its 
own meaning so that's not exactly appropriate.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] HTML5 aside description

2010-02-11 Thread Michael A. Peters

Michael A. Peters wrote:

If aside is not proper to use for this purpose, what would be?


How about margin ??

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] HTML5 aside description

2010-02-11 Thread Michael A. Peters

Robert Cummings wrote:

Michael A. Peters wrote:

If aside is not proper to use for this purpose, what would be?

sidebar suggests a particular type of layout.
section suggests content.
nav is appropriate for some items in a side bar, but not all, and is 
often a child of how aside is being used.

div give no semantics.

I would like to see a toc tag for nav that serves as a table of 
contents of sorts (what I often have at the top of a side bar) but I 
suspect nav is considered sufficient.


Maybe sidebar would be best, and the reference to column type layout 
can just be understood that isn't necessarily on the side?


Reading up on it, I saw some suggest figure for what some of you 
want aside used for, but a figure is often important content and 
has its own meaning so that's not exactly appropriate.


I would lean towards div if there is no appropriate semantic tag to 
markup the information. But in the case of ads, there really should be a 
n ad tag :)


I don't know.
I understand making it cake for ad blockers is attractive, but I run a 
web site that benefits the local community and is paid for out of my 
pocket and while some donations have come in, nowhere near what it 
costs. There are a few select ads (no flash or animated) and even they 
don't make up the difference, but I wouldn't use something like ad 
because I personally have taken a huge financial cut this year (20% 
income reduction) yet I'm kind enough to out of pocket provide this 
service, including things like a SSL certificate so that users who want 
to log on can do so without fear of password sniffing etc. and I will 
never charge for use of my site, so while I don't specifically look for 
people running ad blockers, when they do, it kind of feels like they are 
giving me the finger.


I do not mind script/flash blockers (and will never use flash ads 
because of how many behave poorly and do things like expand to cover 
content or flash at high rates giving headaches and possibly even 
causing seizures) but I know people use ad blockers, so I host the ad 
images myself which seems to neuter them, but I would never use 
something like ad until someone paid me to, and it would have to cover 
costs (which are not covered even right now even with ads).


I've been accused (once) of trying to profit from the site.
I'd post how I replied to the jerk, but I assume some children read this 
list.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Manual problems

2010-02-10 Thread Michael A. Peters

Bob McConnell wrote:



Our SOP is to generate standards compliant pages, validate them with
Firefox and the HTML Validator add-on, then deal with the deviant
browsers. It's a lot less work than trying to do it the other way
around. There are a few minor issues, such as W3C still refusing to
allow the autocomplete attribute for forms, while PCI requires it. But
those are few and far between.


Go HTML 5.
It doesn't work with the validator plugin but it validates at W3C.

And while going HTML 5, start migrating to HTML 5 layout.

IE

div id=aside
aside
// stuff
/aside
/div

Most browsers do not recognize the HTML 5 layout tags yet, so you have 
to wrap them in a div and attach the style to the div, but as browsers 
start adopting HTML 5 your content will work with context features even 
while still wrapped in the div tags.


It is particularly useful for article and section, where the depth of a 
section within an article can be helpful for non visual browsers.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Manual problems

2010-02-10 Thread Michael A. Peters

Ashley Sheridan wrote:




The W3C validator rejects that autocomplete attribute because it still
isn't in any valid standard. Some browsers have introduced it, and PCI
requires it to be there for browsers that recognise it, but it's not a
good security feature, as browsers don't have to honor it and they can
still claim standards compliance. It's a good attribute though, and
makes sense in many situations, so it probably should be included in the
standards I think.


It is in HTML 5.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Manual problems

2010-02-10 Thread Michael A. Peters

Ashley Sheridan wrote:





What about search engines? Will there be any impact on these, 
particularly with regards to semantic content?


I expect semantic markup to (eventually) improve how pages are indexed.



Also, are there any browsers that would fall over with unknown tags? I 
know IE used to not take too kindly to these sorts of things, but that 
was a good few years ago (I'm thinking IE2/IE3 here)!


As far as I know, browsers just ignore the unknown tags, which is why 
you need to attach your css to the div wrapped around the html 5 layout 
tags and not to the html 5 layout tags themselves.




Thanks,
Ash
http://www.ashleysheridan.co.uk





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Manual problems

2010-02-10 Thread Michael A. Peters

Robert Cummings wrote:



Just a word of thought... if you're doing styling... use classes and not 
IDs. Use of IDs for styling is very often indicative of inexperience, 
inability, or lack of understanding with respect to CSS.


I use ID when there will only be one element that needs to be styled 
that way. Whether it implies a lack of understanding or not, I don't 
care about. It's not incorrect and if you are doing a fixed width layout 
where the aside (sidebar) is positioned on the page by the style sheet 
(allowing your content to be the very first thing in the page source), 
you only want one element attached to it anyway.


For the wrapper divs around article and section I do use class because 
there may be more than one article on a page (though usually not) and 
there almost certainly are multiple sections within an article.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Manual problems

2010-02-10 Thread Michael A. Peters

Michael A. Peters wrote:

Robert Cummings wrote:



Just a word of thought... if you're doing styling... use classes and 
not IDs. Use of IDs for styling is very often indicative of 
inexperience, inability, or lack of understanding with respect to CSS.


I use ID when there will only be one element that needs to be styled 
that way.


I should also point out that when all your js is external (as it should 
be) rather than inline, using an id tag makes it much easier to modify 
the DOM client side.


Yes, you can do document.getElementsByTagName('whatever').item(n) if you 
know what item the node will happen to be in the nodelist, but if you 
don't know, then you have to look at other characteristics of the node 
to find out which node in the list you want.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Manual problems

2010-02-10 Thread Michael A. Peters

Robert Cummings wrote:



Many government documents have the concept of aside as appearing 
through the document and contextually near to the information to which 
the aside relates. The entire sidebar seems a bit gratuitous as an 
aside. Sure it's aside, but it's not exactly the semantic meaning of 
aside.


 From the W3C Working Draft:

The aside element represents a section of a page that consists
 of content that is tangentially related to the content around
 the aside element, and which could be considered separate from
 that content. Such sections are often represented as sidebars
 in printed typography.

 The element can also be used for typographical effects like pull
 quotes.

 http://www.w3.org/TR/html5/semantics.html#the-aside-element

Cheers,
Rob.


I'm basically following this model -

http://www.alistapart.com/articles/previewofhtml5

It took very little work since I was essentially doing that already.
aside is the most logical html 5 layout tag for describing the sidebar 
in a two column layout.


I suppose one could put multiple aside elements in a classic div 
{id,class}=sidebar but I don't really see the benefit.


Since the aside used as a sidebar is neither a child of the article or 
section, it is an aside to the main content div.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Manual problems

2010-02-10 Thread Michael A. Peters

Nathan Rixham wrote:

Michael A. Peters wrote:

Robert Cummings wrote:


Many government documents have the concept of aside as appearing
through the document and contextually near to the information to which
the aside relates. The entire sidebar seems a bit gratuitous as an
aside. Sure it's aside, but it's not exactly the semantic meaning of
aside.

 From the W3C Working Draft:

The aside element represents a section of a page that consists
 of content that is tangentially related to the content around
 the aside element, and which could be considered separate from
 that content. Such sections are often represented as sidebars
 in printed typography.

 The element can also be used for typographical effects like pull
 quotes.

 http://www.w3.org/TR/html5/semantics.html#the-aside-element

Cheers,
Rob.

I'm basically following this model -

http://www.alistapart.com/articles/previewofhtml5

It took very little work since I was essentially doing that already.
aside is the most logical html 5 layout tag for describing the sidebar
in a two column layout.

I suppose one could put multiple aside elements in a classic div
{id,class}=sidebar but I don't really see the benefit.

Since the aside used as a sidebar is neither a child of the article or
section, it is an aside to the main content div.


no offence but I have to agree with Rob here, it seems like confusion
between a side and aside is entering.


http://www.merriam-webster.com/netdict/aside

1 : to or toward the side

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP Manual problems

2010-02-10 Thread Michael A. Peters

Andrew Ballard wrote:

On Wed, Feb 10, 2010 at 3:48 PM, Robert Cummings rob...@interjinn.com wrote:

Nathan Rixham wrote:

The most common misconception of how this element should be used is for
the standard sidebar. - see: http://html5doctor.com/understanding-aside/

Unfortunatley I examined that side quite thoroughly and got smacked with a
link to the W3C Editor's Draft. I stand corrected by ignorance:

   The element can be used for typographical effects like pull
quotes or sidebars, for advertising, for groups of nav elements,
and for other content that is considered separate from the main
content of the page.

   http://dev.w3.org/html5/spec/Overview.html#the-aside-element

Looks like the W3C watered it down to appease the worlds morons. I mean
seriously... for advertising?? I have a better tag for that:

   crap
   Buy my shit now... 50% off!!!
   /crap

Seriously, then screen readers would know exactly what not to read to their
listeners. Of course, it wouldn't get used... someone would use aside
instead :B

Oh, well... so much for the much anticipated semantic web. I shall strive to
use it correctly, as I'm sure the original author intended.

aside
   I think I need a snack... all this abuse of English is making
   me hungry :B
/aside

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP


I agree. Of course, it isn't final yet, so perhaps there is time for
comments to be heard.

Andrew



I assume you can still use aside the way you want, just make it a child 
of the article or the section it is meant to compliment.


In the case of two column layout, it is not a child of the content 
column but of the body node, and is an aside to the content itself.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php selecting multiple stylesheets

2010-02-08 Thread Michael A. Peters

TG wrote:
You could use PHP and cookies (session variables are only useful until the 
browser is closed, so it's not as persistant as it sounds like you may 
want).


Persistent sessions are possible.

The way I'm doing it in the CMS I am working on is via GET which saves 
selection in session.


I can't use a selector because I tailor the web page to the style sheet 
and some of them require different page design (IE search bar in aside 
opposed to header)


I don't use persistent sessions, but session is kept in cookie and you 
can configure it to be a persistent cookie if you want.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] php selecting multiple stylesheets

2010-02-08 Thread Michael A. Peters

Ashley Sheridan wrote:




There is a good reason for having different stylesheets that use
differing colour systems. For example, some people with learning
difficulties benefit from yellow text on blue backgrounds, as apparently
those colours together are better at capturing a users attention for
longer durations. This is often coupled with other layout changes such
as narrower width text blocks to aid readability.


It's also not a bad idea to have a layout designed for small computer 
screens, 1024x is what most of my style sheets are designed for but one 
is designed for 800x.


There are still some people with small displays, and horizontal 
scrolling really sucks.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP generated HTML has submit button which picks up the wrong url.

2010-02-06 Thread Michael A. Peters

Ashley Sheridan wrote:




Bit of advice though, don't use Javascript to submit a form. Firstly,
Javascript isn't available on all browsers, and on those it is available
on, not everyone has it turned on. The W3C has the stats for Javascript
being unavailable in a browser at about 5%.


Yup.
Just the other day a company lost my business because after registering 
for their web site, the login form did not work w/o JavaScript. 
Interesting that the registration form itself did.


A freaking login form that had nothing but an e-mail address, password 
field, and a button that was not a standard submit button, but a html 
button elements with a JavaScript event attached to it.


There was no valid reason for them to require JavaScript for that, I do 
not mind allowing JavaScript for local server if the site is of value to 
me but the fact that they used JavaScript for a submit button in a form 
that had two very standard fields told me that they did not know what 
they are doing, indicating they probably did not have their site 
properly protected from XSS injection, and I'm not going to white list a 
web site that I have reason to suspect may not have proper server side 
protection against XSS injection.


My guess is they don't even have a web master but are using some cms 
that autogenerates everything for them, which probably means any input 
validation is rather weak.


Use JavaScript when it is the best tool for the job. It is not the best 
tool for form submission. Client side form validation, sure - it's nice 
for catching problems before the user submits so he doesn't have to 
submit again, but not for the submit action itself.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] DOM TextArea (and dom chart please)

2010-02-03 Thread Michael A. Peters

Michael A. Peters wrote:



$website_data = new tidy('dom_test.html',$tidy_config);


Doh!

Should be

$website_data = new tidy('dom_test.html',$tidy_config,'utf8');

Otherwise it has the same problem with multibyte characters that 
loadHTML() has. But with the 'utf8' specified it works beautifully.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Thinking of moving to .NET because of standalone... any suggestions?

2010-02-03 Thread Michael A. Peters

Ryan S wrote:



I need to make a few standalones programs that will run (mostly) on
Windows... is there any other way that I have not found that i can
use PHP instead of learning something new like .NET?


Use the best tool for the job.

I suspect that if your primary target is MS you will have an application 
that is more consistent with MS interface guidelines if you use MS tools 
to develop it.


I've only played a little bit with php-gtk and just didn't get it but 
I do know the few times I have used Windows, the gtk+ apps I used on it 
always felt a bit out of place (so does iTunes, btw) on the system.


I don't know the details, but I know that at least some .NET apps can be 
ported to *nix without too much trouble using mono, so by using .NET you 
may not be sacrificing portability.


I'm not saying use .NET, I don't know, but if I was developing GUI 
desktop apps where Windows was the primary target, I would use a Windows 
 native programming environment to do it as I suspect it would result 
in far less headaches and far easier time finding solutions to problems 
via google when I'm stumped.


I believe .NET is pretty much how it is done on Windows now (but I 
really don't know, I stay away from Windows, I'm a ABM'r).


Just my 2 cents.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Can't get my PHP-generated RSS to serve properly

2010-02-03 Thread Michael A. Peters

Brian Dunning wrote:

Hey all -

Glad some of you found that sample data helpful.   :-)

I use PHP/MySQL to generate RSS feeds of my podcasts. The feed is
submitted as *.xml and I use .htaccess to redirect it to my PHP
document. The start of the document sets the right header and outputs
the ?  ? to prevent PHP from trying to process the leading XML
line as code (this is cleaned up a bit for readability):

?php header(content-type: application/rss+xml); echo '?'; ? xml
version=1.0 encoding=UTF-8 ?php echo '?'; ? rss
xmlns:itunes=http://www.itunes.com/dtds/podcast-1.0.dtd;
xmlns:atom=http://www.w3.org/2005/Atom; version=2.0

This has always worked fine on one podcast, but on a new one it's
not. You can see the results here: 
http://validator.w3.org/feed/check.cgi?url=http%3A%2F%2Finfactvideo.com%2Fpodcast.php



It's throwing a 500 error, a parsing error, and complaining that
feeds should not be served with the text/html type, even though I'm
serving the right header. Other PHP pages on this site work fine, and
there are no special Apache directives on my site that works that are
missing here. Can anyone suggest what I might be missing?

- Brian


Don't know if it is beneficial to you, but this is what I use (and 
wrote) for RSS feeds -


http://www.phpclasses.org/browse/package/5942.html

Not tried it for podcasts.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] DOM TextArea (and dom chart please)

2010-02-02 Thread Michael A. Peters

Ryan S wrote:



$website_data = file_get_contents('dom_test.html');//load the website data,

$dom = new DomDocument; //make a new DOM container in PHP
$dom-loadHTML($website_data);  //load all the fetched data into the DOM 
container


I'm not sure what the answer to your issue is, but mind if I make a 
couple off topic recommondations?


1) Use loadXML() instead of loadHTML()

The reason is that loadHTML() will mutilate multibyte utf8 characters, 
replacing them with entities.


You can still use $dom-saveHTML() to present the data if html is your 
target output.


2) loadXML() is less forgiving of malformed content, but you can fix 
that by using tidy to import your data


$website_data = new tidy('dom_test.html',$tidy_config);
$website_data-cleanRepair();
$dom-loadXML($website_data);

where

$tidy_config is the tidy configuration array.
Make sure you set

$tidy_config['output-xhtml'] = true;

so that the output of tidy is clean X(ht)ML for loadXML().

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] database abstraction layer

2010-02-02 Thread Michael A. Peters

Lars Nielsen wrote:

Hi List

I am trying to make a Database Abstraction Layer so I can which the DB
of my application between MySQL and Postgresql. I have been looking at
the way phpBB does it, and it seems that it is only then php-functions
which are different. The SQL seems to be the same.

Is it save to assume that I can use the same SQL, or should i make some
exceptions?


Is there a reason why you want to write your own instead of using 
something like Pear MDB2?


With Pear MDB2 - if your SQL syntax is database specific it will work in 
the specific database but MDB2 will not try to port a specialized SQL 
string to another database.


It will port some features to some databases, IE if you use the MDB2 
facilities for prepared statements (highly recommended) and the target 
database does not support prepared statements, it will emulate them (I 
think, haven't tried, that's what I recall reading anyway) but for your 
actual SQL syntax it is best to stick to standard SQL.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] database abstraction layer

2010-02-02 Thread Michael A. Peters

Robert Cummings wrote:
*snip*


Einstein I believe said something along the lines of

A smart person solves a problem.
A wise person avoids it in the first place

Might not have been Einstein, but anyway ...


Do you mean the following quote?

The difference between a smart person and a wise person is that
a smart person knows what to say and a wise person knows whether
or not to say it.

Cheers,
Rob.


No - this is it:

http://www.famousquotes.com/show/1022246/

 “A clever person solves a problem. A wise person avoids it.”

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] OpenID

2010-02-01 Thread Michael A. Peters

Daevid Vincent wrote:
 


-Original Message-
From: Al [mailto:n...@ridersite.org] 
Sent: Monday, February 01, 2010 12:09 PM

To: php-general@lists.php.net
Subject: [PHP] OpenID

This is a bit off subject, but

What is your opinion on OpenID?


Failed gimick. 
Tried to resurface again about a year ago. 
Still seems like failure.


++

Session ID hijacking is bad enough, it gives the malicious user access 
to one resource.


OpenID hijacking gives the malicious user access to a ton of resources.
And what does a user do when their OpenID provider disappears?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Do you use a public framework or roll your own?

2010-01-29 Thread Michael A. Peters

Michael A. Peters wrote:

Daevid Vincent wrote:
 
I'm not looking to start a holy war here or re-hash the tired debate. 
I just want some hard cold numbers to look at.


Do you use a public framework or roll your own?
http://www.rapidpoll.net/8opnt1e


And for those interested, here are the results of the last poll:

To add the final ? in PHP or not...
http://www.rapidpoll.net/show.aspx?id=arc1opy

I'm relieved to know I'm in the majority (almost 2:1) who close their
opening PHP tags. :)




I roll my own, partially from classes I wrote and partially from classes 
at phpclasses.org and partially from neat stuff I find on the web.


Not sure you could call it framework though, just a loose collection of 
independent classes.




Just spent a couple days bringing that loose collection together along 
with CSS templates from http://www.freecsstemplates.org/ and now 
actually have my own (not quite finished) CMS.


And it looks / works a hell of a lot better than anything I've done 
before (er, other than it not quite being finished ...)


Making my classes work together specifically to make a generic CMS 
exposed a lot of bugs and poor design decisions in them that are now 
largely fixes (er, well, we'll see ...)


Last few days have been like an epiphany for me.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Creating an Entire .html page with PHP

2010-01-28 Thread Michael A. Peters

clanc...@cybec.com.au wrote:

On Thu, 28 Jan 2010 21:10:42 +0100, rene7...@gmail.com (Rene Veerman) wrote:


On Thu, Jan 28, 2010 at 12:31 AM,  clanc...@cybec.com.au wrote:

On Wed, 27 Jan 2010 10:21:00 -0800, deal...@gmail.com (dealtek) wrote:
Opening tables, etc, wrongly generally messes the page up completely, but
forgetting to close them again often has no affect no visible effect at all -- 
until you
make some innocent change and everything goes haywire!

whenever i write an opening tag, i immediately write the closing tag
next, then cursor back to fill it in.


Not so easy when you are using PHP to generate a complex layout!




Use DOMDocument.
Then you don't have to worry about closing the tags ;)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Pointers For Newbies, Reminders For Oldies

2010-01-27 Thread Michael A. Peters

Paul M Foster wrote:

... should be obvious - but are often overlooked - points within coding
practice that can cause the programmer to develop bad habits and bad
code. - Dan Brown

Tip #1:

Don't use count() in loops unless there are very few items to count and
performance doesn't matter, or the number will vary over the loop. That
is, don't do this:

for ($i = 0; $i  count($items); $i++)

Instead, do this:

$number = count($items);
for ($i = 0; $i  $number; $i++)


Gah!

for ($i=0;$isizeof($array);$i++)

is something I do all the time.
So the array size is being calculated each iteration?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Pointers For Newbies, Reminders For Oldies

2010-01-27 Thread Michael A. Peters

Richard Quadling wrote:






for ($i = 0, $j = count($a) ; $i  $j ; ++$i) {
}

is a very common way to handle that.


Thanks!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] preg_replace help

2010-01-26 Thread Michael A. Peters

$fixSrch[] = '/\n/';
$fixRplc[] = '[br]';

is what I need except I want it to leave anything between [code] and 
[/code] alone.


I figured it out before but with element /element but I don't even 
remember what I was working on when I did that and I can't for the life 
of me find it now.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_replace help

2010-01-26 Thread Michael A. Peters

Kim Madsen wrote:

Michael A. Peters wrote on 26/01/2010 14:18:

$fixSrch[] = '/\n/';
$fixRplc[] = '[br]';

is what I need except I want it to leave anything between [code] and 
[/code] alone.


I figured it out before but with element /element but I don't even 
remember what I was working on when I did that and I can't for the 
life of me find it now.


Just use the function nl2br()

If you wanna match \n, you need to add a backslash before the 
backslash: \\n




No, I do NOT want to use nl2br.
For one thing, nl2br isn't xml safe so I'd have to do another 
preg_replace to fix that. My bbcode parser is xml safe.


For another thing, my bbcode parser doesn't like html in its input, and 
this needs to be done before the parser.


'/\n/','[br]'

works exactly as I want it to right now except I do not want it replace 
the newlines inside [code][/code] as that messes up the syntax 
highlighting that is then done one the code block.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] preg_replace help

2010-01-26 Thread Michael A. Peters

Michael A. Peters wrote:

Kim Madsen wrote:

Michael A. Peters wrote on 26/01/2010 14:18:

$fixSrch[] = '/\n/';
$fixRplc[] = '[br]';

is what I need except I want it to leave anything between [code] and 
[/code] alone.


I figured it out before but with element /element but I don't 
even remember what I was working on when I did that and I can't for 
the life of me find it now.


Just use the function nl2br()

If you wanna match \n, you need to add a backslash before the 
backslash: \\n




No, I do NOT want to use nl2br.
For one thing, nl2br isn't xml safe so I'd have to do another 
preg_replace to fix that. My bbcode parser is xml safe.


For another thing, my bbcode parser doesn't like html in its input, and 
this needs to be done before the parser.


'/\n/','[br]'

works exactly as I want it to right now except I do not want it replace 
the newlines inside [code][/code] as that messes up the syntax 
highlighting that is then done one the code block.




I got it, though it may not be the most elegant way.

I split the input up into array and do the preg_replace on array 
elements that are not inside [code]. Seems to work, and also solves the 
other problem (other problem being proper application of strip_tags 
except inside [code].


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Creating an Entire .html page with PHP

2010-01-26 Thread Michael A. Peters

Ashley Sheridan wrote:






I think generally though, it's usual to have the pages created and
output on the fly, rather than output the .html page.


Yes, though often using a cache if it is dynamic content that doesn't 
change often. No reason to hit the db continuously if the content is the 
same as when you hit it the last 278 times.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Do you use a public framework or roll your own?

2010-01-26 Thread Michael A. Peters

Daevid Vincent wrote:
 
I'm not looking to start a holy war here or re-hash the tired debate. 
I just want some hard cold numbers to look at.


Do you use a public framework or roll your own?
http://www.rapidpoll.net/8opnt1e


And for those interested, here are the results of the last poll:

To add the final ? in PHP or not...
http://www.rapidpoll.net/show.aspx?id=arc1opy

I'm relieved to know I'm in the majority (almost 2:1) who close their
opening PHP tags. :)




I roll my own, partially from classes I wrote and partially from classes 
at phpclasses.org and partially from neat stuff I find on the web.


Not sure you could call it framework though, just a loose collection of 
independent classes.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Reliable way to identify Ogg types?

2010-01-26 Thread Michael A. Peters
When I use fileinfo on an uploaded Ogg file, the mime it returns is 
Application/Ogg which is almost useless.


Is there a reliable php way, preferably without needing to execute shell 
commands, to positively identify a file as Ogg Theora or Ogg Vorbis?


Thanks for suggestions.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Reliable way to identify Ogg types?

2010-01-26 Thread Michael A. Peters

Eric Lee wrote:


Hi Micheal,

One of way for this should be by checking the header of the file with 
its OggS magic number.

You may take a look at this page to see if it could help !

http://en.wikipedia.org/wiki/Ogg


But I'am confused that the mime type should be enough what type of data 
its coming !

Are there are any more  things you need to concern ?


The problem is that fileinfo just reports application/ogg for both Ogg 
Vorbis and Ogg Theora files, and I never want to trust extension or user 
to properly identify file.


Maybe I need to update some library that fileinfo function is built 
against or uses.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] importNode issue

2010-01-25 Thread Michael A. Peters
I'm experiencing a slight problem with importNODE putting unwanted 
carriage returns in the the output.


Here's my function:

// syntax highlighting
include_once('Text/Highlighter.php');

function syntaxHighlight($dom,$lang,$code) {
   $hl = Text_Highlighter::factory($lang);
   $out = $hl-highlight($code);
   //die($out);
   $tmpDOM = new DOMDocument('1.0','UTF-8');
   $tmpDOM-loadXML($out);
   $foo = $tmpDOM-saveXML();
   //die($foo);

   $nodeList = $tmpDOM-getElementsByTagName('div');
   $impDIV = $nodeList-item(0);
   $returnDIV = $dom-importNode($impDIV,true);

   return $returnDIV;
   }

-=-

Here's my test:

$code  =?php . \n\n;
$code .=require_once('/path/to/something'); . \n;
$code .=function somefunc(\$myfoo,\$mybar) { . \n;
$code .=   \$myfoobar = \$myfoo . \$mybar; . \n;
$code .=   return \$myfoobar; . \n;
$code .=   } . \n;
$code .=? . \n;

$fooTest = syntaxHighlight($dom,'PHP',$code);

-=-

If I uncomment the die($out) - I get what I expect spit to the screen, 
view source shows code that will do what I want.


If instead I uncomment die($foo) - I also get what I expect spit to 
screen. view source shows code that will do what I want.


However, if the function is allowed to continue, the imported div has 
carriage returns between each and every /spanspan which of course 
completely breaks the browser display because they are inside a 
pre/pre node.


Anyone know why importNode does this and how to fix it?

The only (untried) solution I can think of is to replace each carriage 
return with a br / and every space with #160; and then replace the 
pre with a div class='monospace' or some such hackery before running 
loadXML() on it. But I would rather not do that.


php 5.2.12 built against libxml 2.6.26

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] importNode issue

2010-01-25 Thread Michael A. Peters

Michael A. Peters wrote:



The only (untried) solution I can think of is to replace each carriage 
return with a br / and every space with #160; and then replace the 
pre with a div class='monospace' or some such hackery before running 
loadXML() on it. But I would rather not do that.


Even that isn't really working but what I think I may be able to do, 
though it would be a PITA, is go through the list of nodes one by one 
and create identical nodes and append them to a node that isn't imported.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] importNode issue

2010-01-25 Thread Michael A. Peters

Jochem Maas wrote:

highlight_string() function might be an easier route?


If I only ever wanted to highlight php it might be.

I found a workaround, though I don't like it.

add

$dom-formatOutput = false;

to the function and it displays perfectly, though viewing the generated 
source isn't as nice (hence why I add it only when that function is called).


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] MySQL ID -- what happens when you run out of range?

2010-01-25 Thread Michael A. Peters

Shawn McKenzie wrote:

Joseph Thayne wrote:

That is incorrect.  What will happen is as follows:

1.  The value will be incremented by 1 causing the value to be greater
than the maximum integer allowed.
2.  MySQL will see this as a problem and truncate it to the closest
value.
3.  MySQL will then try and insert the new row with the updated id.
4.  MySQL will find that the id already exists, and will return a
duplicate ID error.


5. A tear is rendered in the space time continuum!



6. An alternate version of Dr. Rodney McKay from an alternate universe 
appears, and goes by Rod.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] SQL question

2010-01-25 Thread Michael A. Peters

Paul M Foster wrote:


Typically, coders try to store dates in unix timestamps internally, and
then add 86400 seconds for every day to calculate intervals and such.
This is often inaccurate. Julian days are far more accurate.)

Paul



I use seconds from epoch in the database simply because it works so well 
with the php date() function.


If you need something where Julian day really is better, I assume it 
isn't that hard to convert between posix and julian day, though it seems 
odd to me that it isn't part of the date() function. It probably should be.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] SQL question

2010-01-25 Thread Michael A. Peters

Michael A. Peters wrote:



If you need something where Julian day really is better, I assume it 
isn't that hard to convert between posix and julian day, though it seems 
odd to me that it isn't part of the date() function. It probably should be.




Looks like unixtojd() and jdtounix() do it.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Cookies sessions

2010-01-24 Thread Michael A. Peters

clanc...@cybec.com.au wrote:

On Sat, 23 Jan 2010 09:32:37 -0500, tedd.sperl...@gmail.com (tedd) wrote:


At 1:13 PM +1100 1/23/10, clanc...@cybec.com.au wrote:

 but I would be grateful for any suggestions how I
could make this procedure more secure.
We have given you advice that you should NOT use Cookies in any 
fashion to secure your site, but you remain steadfast that you know 
better -- so, what else can we say other than good luck.


BUT you have told me to use sessions, and sessions use a Cookie!

If the Cookie I use contains random data, the only difference in security is in 
the time
that it remains valid.  Neither contains any useful information, but while they 
are valid
both will enable you to bypass security.



Using only sessions means you have the tried and true php session 
handling to manage the cookie, rather than re-inventing the wheel 
yourself by using your own random string to do the same thing that a 
session cookie already does.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Cookies sessions

2010-01-23 Thread Michael A. Peters

tedd wrote:

At 1:13 PM +1100 1/23/10, clanc...@cybec.com.au wrote:

 but I would be grateful for any suggestions how I
could make this procedure more secure.


We have given you advice that you should NOT use Cookies in any fashion 
to secure your site, but you remain steadfast that you know better -- 
so, what else can we say other than good luck.


tedd



These are my basic guidelines - what I like to do.
It may not be the best thing for every type od web site.

1) I have a user database that has username and a password hash. The 
password itself is never stored.


The password hash is sha1sum(strtolower($username) . $salt . $password)

The salt is something like 5dgudsdgh5673g and should be stored as a 
private variable in your user authentication class.


The reason I have the username there to is because some passwords are 
very popular, using the username when generating the hash ensures that 
two users with identical password will have different hashes. This is 
important if an sql injection attack ever manages to get a dump of your 
user database.


You should protect against sql injection by using prepared statements 
for any database query that involves user submitted data (such as 
username and password) but you still want to make sure that hashes are 
unique, and you do that by adding the username to the salt.


When a user successfully logs in, the unique id of the user is then 
stored as a session variable.


For administrative tasks, in addition to requiring that the user be 
logged in to an account with admin privileges, all administrative tasks 
are in a directory that is protected by apache authentication.


So to get to those kind of pages, the user has to have a 
username/password that is stored in a .htpasswd file for Apache to let 
them in AND they have to be logged in as a user that has been 
authenticated as an administrative user.


I personally do all login via https so that username/password combos are 
never sent plain text. That's more expensive because you need to 
purchase a SSL certificate. You can use self-signed but it is better to 
use an SSL certificate from a certificate authority.


For session security, I have the following directives set in my php.ini 
file:


session.use_only_cookies = 1
- That prevents the session id from being sent via get.
session.cookie_lifetime = 0
- That instructs the browser to delete the cookie when the browsing 
session ends.

session.cookie_httponly = 1
- That theoretically denies access to the cookie from scripting 
languages. I say theoretically because when testing my site for XSS 
security, I was initially able to get some XSS attacks to display my 
session id (tested in firefox 2 w/o noscript - noscript blocked it even 
with the domain allowed), so they were getting it somehow.


Since I have secure login which is a different domain from main domain, 
in my web app itself I set


if (file_exists('/srv/path/DEVEL')) {
   ini_set(session.cookie_domain,.mydomain.devel);
   } else {
   ini_set(session.cookie_domain,.mydomain.org);
   }

That way, secure.mydomain.org (which is used for login) uses the same 
session variable as www.mydomain.org (used for rest of site) so that 
when the user logs in, the session variable that specifies the user on 
the non secure domain gets updated when the user logs in on the secure 
domain.


There are several good php books that discuss session security and php 
web applications. I don't remember which books I used when learning my 
technique, but it would be a good idea to buy or borrow some recent 
books on php web application design.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Foreign Characters Break in MySQL

2010-01-22 Thread Michael A. Peters

Ashley Sheridan wrote:




You're also forgetting one of the most important elements of this. If
you're displaying the characters on a web page, chances are that you
need to add a corresponding meta tag to inform the browser that the
content is utf-8

meta http-equiv=content-type content=text/html; charset=UTF-8/

Otherwise the browser will attempt to guess from the first few
characters of output, and because of the large headers in some websites,
will guess completely wrong.


Just to add - I had to deal with this, I think I got it right now but 
I'm not positive.


My /etc/my.cnf file has the following:

default-character-set=utf8

That way I don't have to remember to specify the charset when I create a 
new table.


If you don't have control over that file (IE shared host) when you 
create your database tables, I believe you need to do


SET character_set_client = utf8;

before your create table commands.

You should also send the charset in a header, IE

header('Content-type: text/html; charset=utf-8');

but for html you also need to have the meta tag as mentioned because if 
the page is saved to disk, there's no other way for a browser to know 
the charset (and if it isn't there, w3c validator complains).


proper xhtml doesn't need the meta tag because it has the charset in the
?xml version=1.0 encoding=UTF-8?
that opens a proper xhtml document.

If the charset isn't set, then any information sent via post will 
probably be sent using whatever charset the operating system uses by 
default, so setting the charset to utf-8 is important for pages that are 
forms as well as pages that display data.


I'm by no means an expert, that's just what I had to do to get
Aneides iëcanus
to properly display.

I already was doing the utf-8 for the web pages, but MySQL defaults to a 
different character set - I consider it a CentOS bug, they should have 
shipped with my.cnf set to utf-8 IMHO because just about everything else 
in the OS is utf-8 by default, but I pulled my hair out for half an hour 
trying to figure out why it wasn't working when the reason was the 
default charset of the MySQL client used to initially create the 
database table.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Cookies sessions

2010-01-22 Thread Michael A. Peters

clanc...@cybec.com.au wrote:



My reasoning in using a cookie for user recognition, rather than relying on the 
session
ID, was that with a cookie I could ensure that the connection effectively 
lasted for some
specified period, whereas the session ID lifetime seems to be somewhat short and
ill-defined.


Shouldn't be.
You can tell sessions to last as long or short as you want.

As far as login goes, there are many ways to do it and the best way 
depends upon what you are doing.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Cookies sessions

2010-01-21 Thread Michael A. Peters

clanc...@cybec.com.au wrote:



Yes; I'm doing that too.  I am setting up a private website, and using cookies 
to control
access to it.

Clancy



The only variable I store in a cookie is the session id.
Everything else is stored in the session database.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How do I remove unused GET parameters from the URL?

2010-01-20 Thread Michael A. Peters

Rene Veerman wrote:

Michael, while i respect your choices, i think you should know that
jquery.com is pretty good at minimizing browser-incompatibility
headaches (and keeping js apps small), and the quircks that are left
are easy enough to learn about.

for things whereby
- the server needs to generate tons of HTML for a small(ish) dataset, or
- the client generates data (also to be translated to html) that the
server doesnt really need to know about (yet)

js can really take some stress off the server.


I also like to run any content that has user contributed data through a 
server side filter that enforces Content Security Policy -


http://www.clfsrpm.net/xss/

That filter makes sure the content sent to the browser does not include 
stuff that violates the defined CSP, and thus greatly reduces the risk 
of malicious content that input filtering missed from reaching the end user.


Furthermore, when it does catch a violation, it reports the violating to 
a log file notifying me of the problem.


The only way that works for content generated client side would be if 
the user was running a browser that is CSP aware, and right now, they 
just don't exist. Firefox has an experimental add-on for CSP but 
virtually no one uses it.


Doing dynamic content server side allows me to run that content through 
the enforcement filter server side thus catching policy violating 
content before it is ever sent to the user.


That itself, btw, is probably the biggest stress on the server.

I understand prototype etc. is the web 2.0 way but I really don't have 
a high opinion of Web 2.0. JavaScript, flash, etc. all have been used 
far too often to do bad things.


Right now, if I don't block except for white listed web sites, I end up 
with advertisements I don't care about expanding and covering the 
content I do care about. Unfortunately the web is full of jerks who do 
rude things with scripts, and people who do malicious things with scripts.


You wouldn't execute code that someone you don't know sent you an 
e-mail, would you? I wouldn't, nor do I execute code someone I don't 
know embeds in a web page.


I surf with script blockers (NoScript to be specific) and when I come 
upon web sites that don't properly function, I'm a lot liklier to head 
elsewhere than to enable scripting for that site. Since I surf that way, 
I expect others do as well, doing things server side that can be done 
server side allows users like me who block scripting to access the 
content without compromising the security of our systems.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How do I remove unused GET parameters from the URL?

2010-01-19 Thread Michael A. Peters

Daevid Vincent wrote:
*snip*
 
The problem as I see it, is that this magic happens when the user hits

Submit, so not sure PHP has any way to intercept at that point.
Javascript might be able to do something on the onClick event or
onSubmit I suspect. But this seems like something that someone should
have solved before and common enough that I would think Apache could handle
it transparently with a directive or module enabled so I don't have to code
some hack on every page.
 
I guess I could always redirect to some 'scrubber' page that strips them

out and redirects on to the refering page again, but that seems klunky.
 
BTW, I want to use GET so that the page can be bookmarked for future

searches of the same data (or modified easily with different dates, etc.),
so that's why I don't use POST.



JavaScript is the only client side way I know of.
Use document.getelementbyid() and yank the unused nodes before submit.

server side, redirect - it shouldn't be that clunky.
Put in a hidden input that tells your action script to redirect to 
itself without the unused get variables (and w/o the hidden input).


That's how I would do it personally (opposed to js).

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] How do I remove unused GET parameters from the URL?

2010-01-19 Thread Michael A. Peters

Daevid Vincent wrote:

 
I guess I could always redirect to some 'scrubber' page that strips them

out and redirects on to the refering page again, but that seems klunky.
 
BTW, I want to use GET so that the page can be bookmarked for future

searches of the same data (or modified easily with different dates, etc.),
so that's why I don't use POST.



Another option is to use post in the form, and when your action page 
receives post, it redirects to itself with the used variables as get.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] 64 bit date in 32 bit php ??

2010-01-18 Thread Michael A. Peters

php 5.2.12 running in CentOS 5.x

Unfortunately, both my server (xen linode) and my test server (crappy 
old dell I found in a field) are 32-bit. I need to work with some dates 
earlier than 1901 and I would really prefer to store them in *nix time 
in the database and use the date() function to format them for display 
when I need to.


My understanding is that 32 bit php has a lower limit in 1901 and upper 
limit in 2038 for the date function.


Is there a pcre / pecl / other wrapper that behaves identical to the 
date function but uses a 64 bit float in 32 bit php?


Yes, the right thing to do is probably to use 64 bit, and if I could I 
would. A wrapper that just passes it off to date on 64 bit systems and 
to date on 32 bit systems within what data can handle and only does its 
magic on 32 bit systems with values beyond 32-bit date capabilities 
would be sweet.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP 5.3 shared hosting

2010-01-15 Thread Michael A. Peters

Adam Richardson wrote:

Hi,

I've developed a framework that requires PHP 5.3 (it takes a more functional
approach.)  I'm hosting my own apps on a dedicated server running cpanel
(thanks to their recent upgrade.)  However, for client work I prefer not to
personally host the websites.

I've been contacting hosts about their shared hosting options, and I've only
found a couple that accommodate PHP 5.3 so far.  Anybody have
recommendations for shared hosting providers that are supporting php 5.3
(many of the smaller sites I'm working with don't merit a VPS?)

Thank you very much for your help,

Adam



I would suggest pointing your clients at something like linode that 
allows them to run whatever they hell they want to run.


I'm running CentOS 5.x w/ php 5.2.12 for example.

I need to update them, but if you want, here are some php 5.3 src.rpm's 
that can be used to build php 5.3 on a CentOS / RHEL 5.x system -


http://www.clfsrpm.net/php/

Running a xen instance is a lot nicer than shared hosting, and not 
really that expensive, and is really preferable to shared hosting.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] php and XML BibTeX

2010-01-13 Thread Michael A. Peters

Hi -

Currently on my web site, book and article references are just stored in 
the database. While it works, I actually would like to move that out of 
the database and to an XML file, the reason being is that if/when I need 
to add fields etc. to the referenced sources, it's a lot easier to just 
edit a text file than modify database and recode my form interface for 
modifying the database. Also, there's an existing XML format for bibTeX 
and there already are tools to go from that to real bibTex, which I 
may need to do at some point.


What I'm hoping is that already exists some php classes / functions for 
dealing with the XML bibTeX but I haven't found them. Anyone know of any?


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] corect way to use mail() function

2010-01-12 Thread Michael A. Peters

Angus Mann wrote:

There are only 11 types of people in this world. Those that think binary
jokes are funny, those that don't, and those that don't know binary.

ErUmmm.shouldn't that read ...only 10 types of people... ?





1 - those that think they are funny
10 - those that don't
11 - those that don't know binary

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] corect way to use mail() function

2010-01-12 Thread Michael A. Peters

Bob McConnell wrote:



I believe the correct way to do this is to use the Sender: header for
ord...@computility.com to show where it actually came from. Then it
doesn't matter what you put in From.

Bob McConnell



I believe that is correct.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] POLL: To add the final ? or not...

2010-01-12 Thread Michael A. Peters

LinuxManMikeC wrote:

On Fri, Jan 8, 2010 at 1:24 PM, Daevid Vincent dae...@daevid.com wrote:

I'm having a debate with a co-worker about adding the final ? on a PHP
page...



So everybody, when do we get to the real discussion?  Which end of an
egg do we break?



Depends upon how far away the Perl developer is when we throw it, and 
how much spin we put on it.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Upgraded PHP now website doesn't work properly?

2010-01-11 Thread Michael A. Peters

Ashley Sheridan wrote:




I never bother with X-forwarding for development work, it is too slow I
agree.


My development box is a Dell Optiplex G50 I found discarded in an 
illegal trash pile. Hard drive was bad, I had a spare. Heat sink was 
dislodged, I had thermal paste. CDROM is not reliable, but reliable 
enough to boot off of a 4MB CentOS boot.iso and network install. Video 
gives snow, but after install, it's headless so who cares.


It's been problem free for a couple months now (found it a couple months 
ago). Only thing I had to purchase was a mouse for install - as I don't 
have a spare and didn't feel like detaching a mouse from an existing 
computer.


I installed bluefish on it and use bluefish over ssh via x forwarding on 
my local lan and sometimes have the bluefish window open for days. When 
I'm ready to publish to live, I simple ssh in and rsync to live. Never 
had a slowness problem.


It's an old crap computer, ram limit of 512MB (currently has 384 in it), 
but having the devel box local makes things like X forwarded a GUI text 
editor cake w/o performance issues.


I use Ubuntu for my desktop, no server crap installed on it, I prefer 
CentOS for serving - so this a cheap crap local box for devel server is 
the perfect solution. Since I'm the only user, the low performance of 
the CPU/Intel i815 chipset really isn't an issue (I think the mobo was 
swapped at some point, Dell website indicates i810 but it has i815).


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Upgraded PHP now website doesn't work properly?

2010-01-11 Thread Michael A. Peters

Kaya Saman wrote:






Thanks for that info I do admit that old computers do make the coolest 
machines especially home servers and when running something like FreeBSD 
they end up being awsome!


However we were talking about SSH over continents not local LAN! With 
local LAN you get round 100Mbps unless really old in which case you 
would get 10Mbps half duplex. This is no way an issue when in such close 
proximity. I however am round 3500 km's away at the moment from my web 
server and the internet connection I am getting is really poor as it 
locks up quite a bit and I end up with failed routes between my PoP 
(point of presence) server or the countries main gateway.




But what you can do is keep your dev box local, and then use rsync over 
ssh to publish to the production (or dev) server that is across ocean(s).


I use .devel as my TLD for my dev hosts (IE www.something.devel) but 
otherwise have the dev box configured identical to the production 
server, so that if it works on dev box I know it works on production.


Other thing I do, cron job on production dumps the database once a 
night, cron job on dev fetches it (via rsync over ssh w/ keys) and 
applies it to dev database so that the dev database is always very close 
to production database.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Clean PHP 5.2.12 Build Core Dumping

2010-01-10 Thread Michael A. Peters

Don O'Neil wrote:



Core was generated by `php'.
Program terminated with signal 11, Segmentation fault.
#0  0x081d50a7 in sqlite3Select (pParse=0xbbc00080, p=0x0, eDest=164102200,
iParm=0, pParent=0x24, parentTab=139141440, pParentAgg=0x84c10d8,
aff=0x0)
at
/usr/local/directadmin/customapache/php-5.2.11/ext/pdo_sqlite/sqlite/src/sel
ect.c:3172
3172  for(j=0; jpGroupBy-nExpr; j++){


First off, the compile directory listed is wrong, don't know where it got
php-5.2.11 from


I've experienced the same type of issue when building php RPM's on Linux.

The solution is to either remove the previous php build or build it in a 
chroot build environment (such as mock for RPM based distros).


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] POLL: To add the final ? or not...

2010-01-10 Thread Michael A. Peters

Daevid Vincent wrote:



What do you guys all do?


I keep it there, and just make sure not to have white space where it 
should not be.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] POLL: To add the final ? or not...

2010-01-10 Thread Michael A. Peters

Stuart Dallas wrote:



That's a massive assumption. There are a number of editors that
automatically add a blank line to the end of source files. I stand by
taking the option that requires the least conscious thought from your
developers - they have enough important stuff to occupy their brain
that remembering to make sure there is no whitespace at the end of
their source files should not be one of them.

-Stuart



I would suggest getting a text editor that doesn't do that then. There 
are text editors that don't.


There also are e-mail clients that properly wrap the body content before 
sending ;)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] POLL: To add the final ? or not...

2010-01-10 Thread Michael A. Peters

Stuart Dallas wrote:

On 10 Jan 2010, at 14:44, Michael A. Peters wrote:


Stuart Dallas wrote:


That's a massive assumption. There are a number of editors that
automatically add a blank line to the end of source files. I stand by
taking the option that requires the least conscious thought from your
developers - they have enough important stuff to occupy their brain
that remembering to make sure there is no whitespace at the end of
their source files should not be one of them.
-Stuart

I would suggest getting a text editor that doesn't do that then. There are text 
editors that don't.

There also are e-mail clients that properly wrap the body content before 
sending ;)


I would rather not have a requirement on the tools my developers use which 
potentially (and usually) improves their productivity than impose a requirement 
that has no apparent benefit outside of XML files, and even then the benefit is 
irrelevant since it's already a file that contains both code and XML.

And if you don't like the way my emails look feel free to forward them into a black hole, 
I'll be fine with that. Alternatively talk to Apple and get them to change their Mail app 
to your idea or properly. Either way I'm going to get back to worrying about 
things that matter. ;)

-Stuart



I suspect that you just don't word wrap enabled in your Mail.app 
preferences. That use to be an option anyway (I haven't used OS X since 
10.1)


Anyway, I didn't fix the wrap on this before replying just to show what 
happens. Each paragraph end up as a big long line instead of having a 
break put in.


Ah well, doesn't bother me as much as HTML mail to lists does ;)

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: SimpleXML or DOMDocument help

2009-12-09 Thread Michael A. Peters

Shawn McKenzie wrote:

Michael Alaimo wrote:

Hello All,

I have an XML document that has elements as such:
Query:Expression
  Query:ResourceID
Query:EqualTest/Query:Equal
  /Query:ResourceID
/Query:Expression


I cannot figure out how to access these with simple xml.  I am not opposed
to a DOMDocument solution either.

Would anyone know what to do in this case?  I think the problem is the :.

Regards,

Mike







What's the entire XML document?  You need a xmlns declaration as Query
is a namespace.



I have run into documents that use a namespace without properly defining it.

Seems fairly common in data sets from academic sources (IE vertebrate 
museum records). Usually there is only one namespace, and you can use a 
regular expression to just remove it before importing the document.


IE -

$buffer = preg_replace('/Query:/','',$input);

then import the $buffer

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] How to properly serve a file via a wrapper.

2009-12-08 Thread Michael A. Peters

Please help.

I thought I had this squared away, but apparently not.
I need to be able to use a php wrapper to serve a file stored outside 
the web root.


Works great for downloads / images - but my wrapper seems broken for 
media files to be played.


My wrapper:

http://www.shastaherps.org/bugs/rdb_audio.phps

Demonstration of issue:

http://www.shastaherps.org/bugs/wrapperBug.html

What am I missing??

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] cookies and carts

2009-12-08 Thread Michael A. Peters

Allen McCabe wrote:

I have a shopping cart type system set up which keeps track of the cart
contents using a SESSION variable, where $_SESSION['cart'][$item_id'] is
equal to the quantity, so the name/value pair is all the information I need.

But sessions are unreliable on the free server I am currently using for this
website (not my choice), so I had start using cookies because users were
being sporadically logged out, sometimes just on a page refresh.


Have access to a database?
If yes, then run your own session management in the database.

This is what I use.
You don't want to use APC on a multiuser system, but this works without 
APC as well.


?php
//require_once(sessions_apc.php);
//$sess = new SessionManager($mdb2);
//session_start();

// from :
//  http://www.devshed.com/c/a/PHP/Storing-PHP-Sessions-in-a-Database/
//  Rich Smith - 2007-05-02
//
// Modified by mpet...@mac.com to use mdb2 w/ prepared statements
//  and attempt to use caching

class SessionManager {
   public  $sesstable = 'new_sessions';
   private $life_time;
   private $mdb2;
   // CHANGE THE SALT BEFORE USING
   private $apcSalt = '2d8lyds45a@0KLybafz';
   private $apcMaxLife = 1500; // delete from cache after that many seconds
// even if session still active
   function SessionManager($mdb2) {
  // constructor function
  // Read the maxlifetime setting from PHP
  $this-life_time = get_cfg_var(session.gc_maxlifetime);
  $this-mdb2 = $mdb2;

  // Register this object as the session handler
  session_set_save_handler(
 array( $this, open ),
 array( $this, close ),
 array( $this, read ),
 array( $this, write),
 array( $this, destroy),
 array( $this, gc )
 );
  }

   function open($save_path,$session_name) {
  global $sess_save_path;
  $sess_save_path = $save_path;
  // Don't need to do anything. Just return TRUE.
  return true;
  }

   function close() {
  return true;
  }

   function read($id) {
  // Set empty result
  $data = '';
  $myreturn = $this-wrap_fetch($id);
  if (! $myreturn) {
 // Fetch session data from the selected database
 $time = time();
 $types = Array('text','integer');
 $q = 'SELECT session_data FROM ' . $this-sesstable . ' WHERE 
session_id=? AND expires  ?';

 $sql = $this-mdb2-prepare($q,$types,MDB2_PREPARE_RESULT);
  //   if(PEAR::isError($sql)) {
  //  die('Failed to make prepared 58: ' . $sql-getMessage() . 
', ' . $sql-getDebugInfo());

  //  }
 $args = Array($id,$time);
 $rs = $sql-execute($args);
  //   if(PEAR::isError($rs)) {
  //  die('Failed to issue query 63: ' . $rs-getMessage() . ', 
' . $rs-getDebugInfo());

  //  }
 if ($rs-numRows()  0) {
$row = $rs-fetchRow(MDB2_FETCHMODE_OBJECT);
$myreturn = $row-session_data;
} else {
$myreturn = '';
}
 }
  return $myreturn;
  }

   function write($id,$data) {
  // Build query
  $time = time() + $this-life_time;

  // see if a session exists
  $sessTest = wrap_fetch($id);
  if (! $sessTest) {
 $types = Array('text');
 $q = 'SELECT COUNT(session_id) from ' . $this-sesstable . ' 
WHERE session_id=?';

 $sql = $this-mdb2-prepare($q,$types,MDB2_PREPARE_RESULT);
 //if (PEAR::isError($sql)) {
 //   die('Failed to make prepared 86: ' . $sql-getMessage() . 
', ' . $sql-getDebugInfo());

 //   }
 $args = Array($id);
 $rs = $sql-execute($args);
  //if(PEAR::isError($rs)) {
  //   die('Failed to issue query 91: ' . $rs-getMessage() . ', ' 
. $rs-getDebugInfo());

  //   }
 $row = $rs-fetchRow(MDB2_FETCHMODE_ORDERED);
 $count = $row[0];
 } else {
 $count = 1;
 }

 if ($count  0) {
 // update the session
 $types = Array('text','integer','text');
 $q = 'UPDATE ' . $this-sesstable . ' SET session_data=?, 
expires=? WHERE session_id=?';

 $args = Array($data,$time,$id);
 } else {
 $types = Array('text','text','integer');
 $q = 'INSERT INTO ' . $this-sesstable . ' 
(session_id,session_data,expires) VALUES (?,?,?)';

 $args = Array($id,$data,$time);
 }
  $sql = $this-mdb2-prepare($q,$types,MDB2_PREPARE_MANIP);
  //if(PEAR::isError($sql)) {
  //   die('Failed to make prepared 111: ' . $sql-getMessage() . 
', ' . $sql-getDebugInfo());

  //   }
  $rs = $sql-execute($args);
  //if(PEAR::isError($rs)) {
  //   die('Failed to issue query 115: ' . $rs-getMessage() . ', ' 
. $rs-getDebugInfo());

  //   }
  $this-wrap_store($id,$data);
  return TRUE;
  }

   function destroy($id) {
  // Build query
  $this-wrap_delete($id);
  $types = Array('text');
  $args  = Array($id);
   

[PHP] curl spider and being a good citizen

2009-10-24 Thread Michael A. Peters
I'm writing a custom search engine for my site, it seemed easier than 
modifying sphyder (what I currently use) to do what I want especially 
since sphyder has a lot of stuff that isn't personally of use to me.


One of the things I want to do when I index is list external links and 
check them.


The idea is to have curl download just the headers but not content from 
external links.


This is what I have as part of my class to do that -

function meta($url) {
  $process = curl_init($url);
  curl_setopt($process, CURLOPT_CONNECTTIMEOUT, 15);
  curl_setopt($process, CURLOPT_TIMEOUT, 20);

  curl_setopt($process, CURLOPT_HTTPHEADER, $this-headers);
  curl_setopt($process, CURLOPT_USERAGENT, $this-user_agent);
  curl_setopt($process, CURLOPT_NOBODY, true);
  curl_setopt($process, CURLOPT_HEADER, 0);

  $fetch = curl_exec($process);

  $return[] = curl_getinfo($process, CURLINFO_HTTP_CODE);
  $meta = split(';',curl_getinfo($process, CURLINFO_CONTENT_TYPE));
  $return[] = $meta[0];

  curl_close($process);
  return $return;
  }

I am under the impression that
curl_setopt($process, CURLOPT_NOBODY, true);

does what I want - but the curl docs can be confusing.

Will that work to just download the headers needed to get the http 
status code and mime type w/o grabbing content?


And secondly, will making 40 or so connections to the same remote site 
just to grab headers but not content (there are two I link to quite a 
bit with permission) to check for moved files possibly cause issues with 
their server software? It doesn't seem to for me (Apache on Linux) but 
that's me, and I'm not positive curl stopped the download after getting 
last http header.


Pages on those sites do move as taxonomy moves and the people in charge 
don't seem to keep 301 moved redirects in place when they reorganize, so 
I do need to check with some frequency, but I don't want to cause problems.


Thanks for suggestions.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Download Wrapper

2009-10-07 Thread Michael A. Peters

I'm using flowplay (flash) for embedded audio/video.
Initially I was using html5 w/ flowplay as fall back, but I stopped 
because flowplay is better than html5 on browsers that support html5.


Anyway - I also am making direct links to the media available as mp4/ogm 
and mp3/ogg.


The problem is browsers would often try to handle the media themselves 
instead of letting it download - so I made a wrapper php script that 
sends the right headers -


header(Content-type:  . $mime);
header(Content-Disposition: attachment; filename= . $thispage);
header(Content-Transfer-Encoding: binary);

Browsers now do the right thing and let the media download, but there is 
no estimate on when the download the will complete.


I'm guessing I need to send a header with the content length for them to 
do that?


This is the function I use (stolen from web) to send the media:

define('CHUNK_SIZE', 1024*1024);
function readfile_chunked($filename, $retbytes = TRUE) {
$buffer = '';
$cnt =0;
 // $handle = fopen($filename, 'rb');
$handle = fopen($filename, 'rb');
if ($handle === false) {
   return false;
   }
while (!feof($handle)) {
   $buffer = fread($handle, CHUNK_SIZE);
   echo $buffer;
   ob_flush();
   flush();
   if ($retbytes) {
  $cnt += strlen($buffer);
  }
   }
$status = fclose($handle);
if ($retbytes  $status) {
   return $cnt; // return num. bytes delivered like readfile() does.
   }
return $status;
}

Can someone suggest an improvement that will send the content length?
Looking around I see this used with images:

$length = strlen($imagedata);
header('Content-Length: '.$length);

Is that good enough?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Developer Question [DOMDocument]

2009-10-05 Thread Michael A. Peters

I'm hoping someone who knows the answer to this question is on this list.

I need to modify either libxml2 and/or php DOMDocument to make a small 
change.


Issue - saveHTML() function predates html5 (which isn't even finalized 
yet) and thus does not know about it's tags.


the source element is new in html5 and may not have any children, so 
when using saveHTML() from DOMDocument, it should NOT add a closing 
/source tag (it should be handled the same way the param element is 
handled). It does the right thing with saveXML() where it properly self 
closes the tag, but it does not do the right thing with saveHTML().


I suspect it is a minor easy to do change, but I don't even have the 
foggiest idea where to look in the source to make a patch.


It's not all that big of a deal, but I would like my server to spit out 
the correct code without me having to pass it through preg_replace.


Thanks for any suggestions on where/how to define that tag in the source.

Michael A. Peters

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Developer Question [DOMDocument]

2009-10-05 Thread Michael A. Peters

Ashley Sheridan wrote:



I've not had a look at DOMDocument myself, having only used DomDocument 
before (there's a slight difference in the capitalisation of the 2nd and 
3rd letters which made it a pain in the proverbial to work with at 
first!) but I would assume that if it might offer a method by which you 
could specify certain self closing tags. This would be necessary at 
least internally, to differentiate between things like param/ which 
can be self closing and script which can't (even though the latter 
might only be referencing an external .js file and have no inline code!)


saveXML() does self close a script tag with no children.
self closing script is only a problem if sent as html, it works when 
sent with application/xml+xhtml mime type. But you're right, saveHTML() 
does not do self closing nor /script.




If not, then I'd do a file find on the code for any files containing the 
text 'param' for example, to see if that leads you to the right place.


I tried that on libxml2 source - grep -R param didn't work so well, a 
bazillion files with that use the phrase param.




You may have problems doing this on a Windows XP system,


I'm on linux.
I'll find it eventually. Probably just before upstream does an official 
html5 patch ;)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Developer Question [DOMDocument]

2009-10-05 Thread Michael A. Peters

Michael A. Peters wrote:

Ashley Sheridan wrote:



I've not had a look at DOMDocument myself, having only used 
DomDocument before (there's a slight difference in the capitalisation 
of the 2nd and 3rd letters which made it a pain in the proverbial to 
work with at first!) but I would assume that if it might offer a 
method by which you could specify certain self closing tags. This 
would be necessary at least internally, to differentiate between 
things like param/ which can be self closing and script which 
can't (even though the latter might only be referencing an external 
.js file and have no inline code!)


saveXML() does self close a script tag with no children.
self closing script is only a problem if sent as html, it works when 
sent with application/xml+xhtml mime type. But you're right, saveHTML() 
does not do self closing nor /script.


Doh!
I was thing meta, script does self close as saveXML() w/ no children but 
does do /script with saveHTML().


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Developer Question [DOMDocument]

2009-10-05 Thread Michael A. Peters

Ashley Sheridan wrote:




I never tried to say that classes are case-sensitive, that was
actually mentioned by Lupus who misunderstood what I was trying to
say. What I was meaning is exactly what you just said here, that the
PECL DomDocument is very different from the more typical DOMDocument.
I was trying to run code examples that just weren't compatible with
the differing classes which was quite frustrating!


Yes - I found instructions that just don't work that were for what I 
thought was an older version of it, I didn't know the previous version 
was PECL.


Interestingly, it's often not too hard to figure out how to do things in 
php DOMDocument from tutorials written for the Java implementation.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] class to generate Javascript Object ??

2009-10-04 Thread Michael A. Peters

I wrote a php class to generate flowplayer/html5 media code for my site:

http://www.shastaherps.org/xml_MMmediaClass.phps

The buildFlashvars() function in it is really ugly and will be a pain 
to update as I modify the class in the future.


What it does is generate a JavaScript object string, as described here:

http://flowplayer.org/tools/flashembed.html

I'm thinking (hoping) there is already a php class somewhere for 
generating JavaScript object strings that I can instead of my ugly 
easily breakable way of doing it.


Anyone know of one?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] class to generate Javascript Object ??

2009-10-04 Thread Michael A. Peters

Tom Worster wrote:

On 10/4/09 9:39 AM, Michael A. Peters mpet...@mac.com wrote:


I wrote a php class to generate flowplayer/html5 media code for my site:

http://www.shastaherps.org/xml_MMmediaClass.phps

The buildFlashvars() function in it is really ugly and will be a pain
to update as I modify the class in the future.

What it does is generate a JavaScript object string, as described here:

http://flowplayer.org/tools/flashembed.html

I'm thinking (hoping) there is already a php class somewhere for
generating JavaScript object strings that I can instead of my ugly
easily breakable way of doing it.

Anyone know of one?


would json_encode() work for you... ?

http://www.php.net/manual/en/function.json-encode.php




Yes - it worked beautifully :)

Thank you.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] [SOLVED] class to generate Javascript Object ??

2009-10-04 Thread Michael A. Peters

Andrea Giammarchi wrote:


  I'm thinking (hoping) there is already a php class somewhere for
  generating JavaScript object strings that I can instead of my ugly
  easily breakable way of doing it.
 
  Anyone know of one?


json_encode
http://uk3.php.net/manual/en/function.json-encode.php



Thank you, worked beautifully.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



  1   2   3   4   5   >