Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
spacebard
Jan 1, 2007

Football~

Gnack posted:

Ah okay, thank you. I did wonder if that's what he was getting at. I was hoping to avoid that but it makes sense so I think I'll go for that approach. Thanks both of you.

Sorry, I was suggesting that functional programming makes things easier to test. :goonsay:

isLocked() probably does't make sense to take any parameters, but return a boolean based off some property on the object. Having a getter/setter for date would help.

Basically,

php:
<?
// Create a date that's in the future.
$date = new Date(time() + 3660);

$mock = new MyMatchClass();
$mock->setMatchTime($date);

$this->assertTrue($mock->isLocked());

// Subtract enough time to be in the past, and set matchtime
$date->sub(DateInterval::createFromDateString('4000 seconds'));
$mock->setMatchTime($date);

$this->assertFalse($mock->isLocked());
?>

Adbot
ADBOT LOVES YOU

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

spacebard posted:

Sorry, I was suggesting that functional programming makes things easier to test. :goonsay:

isLocked() probably does't make sense to take any parameters, but return a boolean based off some property on the object. Having a getter/setter for date would help.

Basically,

php:
<?
// Create a date that's in the future.
$date = new Date(time() + 3660);

$mock = new MyMatchClass();
$mock->setMatchTime($date);

$this->assertTrue($mock->isLocked());

// Subtract enough time to be in the past, and set matchtime
$date->sub(DateInterval::createFromDateString('4000 seconds'));
$mock->setMatchTime($date);

$this->assertFalse($mock->isLocked());
?>

This really is the opposite of how I was thinking, and it makes perfect sense thanks. Shows you just need to be creative sometimes.

v1nce
Sep 19, 2004

Plant your brassicas in may and cover them in mulch.

PlesantDilemma posted:

Anyone written an Excel file using PHP and have a recommendation on a library to use? This PHPExcel is my best find but I thought I would ask here too.

Depends on your needs. If you're making some kind of complex spreadsheet with calculations and cell references and what have you, it'll work just fine. There's a big fat stack overflow answer with alternatives, but PHPExcel is often the go-to library in my experience.

That said , PHPExcel tends to eat around 1kb of memory per cell, last time I used it, which is obviously a big problem if you're trying to say, export 100 columns and 10000 rows of data.
Alternately, if you're just exporting craploads of tabular data, you can just create a blank HTML doc with a table in it containing your data, and name it .xls. Excel will pick that up, complain about the formatting, then open it. It sounds like a hacky workaround, butit's surprising how many systems make use of this trick to get around working with the xls format.

An additional advantage is you can process say, 10 rows at a time and output the content to a file, so unlike PHPExcel you don't have to have the entire file in memory, which lets you output as much data as you need.

PleasantDilemma
Dec 5, 2006

The Last Hope for Peace

v1nce posted:

Depends on your needs. If you're making some kind of complex spreadsheet with calculations and cell references and what have you, it'll work just fine. There's a big fat stack overflow answer with alternatives, but PHPExcel is often the go-to library in my experience.

That said , PHPExcel tends to eat around 1kb of memory per cell, last time I used it, which is obviously a big problem if you're trying to say, export 100 columns and 10000 rows of data.
Alternately, if you're just exporting craploads of tabular data, you can just create a blank HTML doc with a table in it containing your data, and name it .xls. Excel will pick that up, complain about the formatting, then open it. It sounds like a hacky workaround, butit's surprising how many systems make use of this trick to get around working with the xls format.

An additional advantage is you can process say, 10 rows at a time and output the content to a file, so unlike PHPExcel you don't have to have the entire file in memory, which lets you output as much data as you need.

We've been doing the html-as-fake-excel thing but customers complained because apparently Excel on mac wouldn't load the file. Or not load it correctly or something.

The memory overhead sounds like a bummer but our reports aren't super huge so it should be fine. I'll have to add in something to track memory usage when I use it. Thanks for the tips I'll check out that SO post too.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
I'm using Laravel for a project I'm working on and I'd like to start using LESS to make CSS a little easier to maintain. I'm wondering if anyone has some pointers on decent asset managers for Laravel that will take care of auto-compiling the LESS for me? Preferably I'd like it to autocompile the LESS to CSS whenever it picks up that the LESS file has changed.

Depressing Box
Jun 27, 2010

Half-price sideshow.
I haven't found a good asset manager for Laravel yet, but I've gotten pretty good results setting up a watcher and some build tasks with Gulp (formerly with Grunt, but I find Gulp a lot easier to work with). Here's a quick overview, and a more in-depth video tutorial.

If you mean a PHP-only LESS compiler, the only one I know of is lessphp. It's functional enough, but slow. Not an ideal solution.

substitute
Aug 30, 2003

you for my mum

Gnack posted:

I'm using Laravel for a project I'm working on and I'd like to start using LESS to make CSS a little easier to maintain. I'm wondering if anyone has some pointers on decent asset managers for Laravel that will take care of auto-compiling the LESS for me? Preferably I'd like it to autocompile the LESS to CSS whenever it picks up that the LESS file has changed.

I stumbled upon this over the weekend. It sounds like what you're describing.

http://mun.ee/

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Depressing Box posted:

I haven't found a good asset manager for Laravel yet, but I've gotten pretty good results setting up a watcher and some build tasks with Gulp (formerly with Grunt, but I find Gulp a lot easier to work with). Here's a quick overview, and a more in-depth video tutorial.

If you mean a PHP-only LESS compiler, the only one I know of is lessphp. It's functional enough, but slow. Not an ideal solution.

I don't mind if it's slow-ish, as it will only be used in development. But I've started using LessPHP and I'm having trouble already at the starting line. I have this in my less file:

code:
@red: #ff0000;

body {
    background-color: @red;
}
and LessPHP barfs on it straight away saying that there's a "parse error". I've been debugging this for a while now and can't figure it out.

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.
You might want to look into using Foundation with Sass and Compass. I know you wanted LESS, but Sass is hard to beat (Bootstrap was also just released with Sass support as well giving some people the idea that Sass "won").

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

musclecoder posted:

You might want to look into using Foundation with Sass and Compass. I know you wanted LESS, but Sass is hard to beat (Bootstrap was also just released with Sass support as well giving some people the idea that Sass "won").

To be honest I'm only just starting to delve into LESS/SASS and this is a brand new personal project so I don't have a preference for either here. I'll give SASS a try - thanks!

v1nce
Sep 19, 2004

Plant your brassicas in may and cover them in mulch.

substitute posted:

I stumbled upon this over the weekend. It sounds like what you're describing.

http://mun.ee/

This. Supports compiling LessCSS, SCSS (Sass), condensing files to one request, minifying javascript and basic image manipulation (and I know the guy who made it).

You can install Munee really easily with composer or just download it, and one php file and .htaccess rule later, you'll have it handling all your assets. Seriously worth checking out.

Nebulon Gate
Feb 23, 2013
God, you kids and your repositories and composers and frameworks. In my day, everything was done by scratch, and if you dared using anything close to even resembling a library, your paranoid boss would be afraid he'd be accused of stealing code.

substitute
Aug 30, 2003

you for my mum

Nebulon Gate posted:

God, you kids and your repositories and composers and frameworks. In my day, everything was done by scratch, and if you dared using anything close to even resembling a library, your paranoid boss would be afraid he'd be accused of stealing code.

Oh man I'm still partially at this stage at work because of various factors and it sucks (not the "stealing code" thing). I so wish I could scrap several aspects in our setup and workflow, and use actual tested and well maintained PHP frameworks for projects. I constantly say I reinvent the wheel for a living, but some days/weeks, it's feels like I'm reinventing the hammer and chisel.

substitute fucked around with this message at 18:20 on Feb 5, 2014

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

Nebulon Gate posted:

God, you kids and your repositories and composers and frameworks. In my day, everything was done by scratch, and if you dared using anything close to even resembling a library, your paranoid boss would be afraid he'd be accused of stealing code.

Yeah I'm in a real period of adjustment at the moment where I'm trying to catch up with some pretty serious shifts in the way web development works these days. All these libraries and utilities that used to be unnecessary but now have very genuine usefulness, and somehow I missed it all so now I'm catching up.

I thought Composer would come and go, I thought Node.js would come and go, I thought SASS and LESS would always remain just kind of a niche thing. I suck at predicting the web is what I'm saying.

Sulla Faex
May 14, 2010

No man ever did me so much good, or enemy so much harm, but I repaid him with ENDLESS SHITPOSTING

Gnack posted:

I suck at predicting the web is what I'm saying.

Today's your lucky day, friend. I'm putting together a team of enthusiasts to develop an online player-controlled graphical video computer console game.

It's this fantastic new thing called an Em Em Oh and it's the closest thing you'll get to legally printing your own money. It's on the cutting edge of computer technology and it will transform the way children and the mentally deranged spend their time.

Rather than creating a software video game and selling it only once to each child, we sell them the software and they then pay us to continue using it.

Now, you may be asking -- what money does a child have to pay for console video playables? They don't let children work anymore! But today's new urban parents are paying more and more money to distract their chubby children, and if we act now, the right product could completely monopolise this emerging market and secure a virtually limitless income -- for ever.

Please send all inquiries via pneumatic tube.

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope

That site does a horrible job of explaining what Foundation is to someone who does not already know what Foundation is.

Apparently it's some kind of a framework, but then again, everything is these days.

Nebulon Gate
Feb 23, 2013
What the gently caress? There's a foundation 5 now?

Wheany
Mar 17, 2006

Spinyahahahahahahahahahahahaha!

Doctor Rope
How do adults parse XML in PHP in the year 2014?

I don't really have much experience in XML parsing in general, but recently I have done it in Java and C# semiautomatically by generating a class structure from schema. It was a surprisingly pleasant experience. Nothing similar for PHP immediately jumped forward when I googled for it, except for one apparently unfinished project.

Well, now I'm going to have to interface with a web service that both inputs and outputs XML. So I need something to generate valid XML for making requests and I need to parse the response to get the data I requested.

Looking at SimpleXML, that looks painless enough for generating simple requests. I might be able to live with that.
But processing incoming XML with, say DOM, sounds potentially lovely. I can probably live with that as well if need be, but if there are better options, I'd like to hear about them at least.

late edit: Looks like I misunderstood SimpleXML's purpose. I thought it was meant for encoding data into XML, but looks like it also parses XML. Well, I'm going to try that for now and see if I run into some massive problems.

Wheany fucked around with this message at 15:35 on Feb 7, 2014

spacebard
Jan 1, 2007

Football~

Wheany posted:


Well, now I'm going to have to interface with a web service that both inputs and outputs XML. So I need something to generate valid XML for making requests and I need to parse the response to get the data I requested.

Looking at SimpleXML, that looks painless enough for generating simple requests. I might be able to live with that.
But processing incoming XML with, say DOM, sounds potentially lovely. I can probably live with that as well if need be, but if there are better options, I'd like to hear about them at least.

late edit: Looks like I misunderstood SimpleXML's purpose. I thought it was meant for encoding data into XML, but looks like it also parses XML. Well, I'm going to try that for now and see if I run into some massive problems.

Guzzle can output SimpleXML and probably you could extend guzzle to use DOM. If you need to validate with a schema than I think DOMDocument works better.

McGlockenshire
Dec 16, 2005

GOLLOCKS!
It also depends on the size and complexity of the document. SimpleXML gets funky when the XML has, oh, I dunno, attributes. And gods help you if there are namespaces!

While the XML parser functions will do a fine enough job, they're kind of annoying to deal with. Also, take every bit of code in the comments on the xml_parse page with a tablespoon of salt. Yikes.

There's also XMLReader, which is a pull parser, designed for large document reading without huge memory use.

Sulla Faex
May 14, 2010

No man ever did me so much good, or enemy so much harm, but I repaid him with ENDLESS SHITPOSTING
I don't know if its because im sick as a dog and my eyeballs feel bruised or if im missing something obvious but i feel like an idiot, i cant get simplexml to output the text string it would dump into the xml file. As in, i need to save a copy as an xml and a copy in the database and strip the xml tag (i.e. Versioning and document declaration) as well. No matter how i manipulate it, or output and try to re read the file line by line (not using simplexml), it only ever gets the values of the content. What am i missing? I know its not a common need and i probably don't need to strip the declaration but why am i having such a hard time transforming an xml document or simplexml object into a simple string?

revmoo
May 25, 2006

#basta
asXML() ?

Edit: If you wanted to go the other direction, I'm pretty sure you can cast the SimpleXML object to a string.

revmoo fucked around with this message at 00:08 on Feb 8, 2014

mooky
Jan 14, 2012
I'm looking for a little help with regex, I'm working on fun little script that is parsing my video files and pulling down information from a movie database. To make it easy to determine an accurate name based on the filename, I have some regex that works great from the command line but not so great with preg_match or preg_replace...

I'm trying to insert a space before all capital letters and the first number in a sequence. Look at the example below.

echo 'ChroniclesOfRiddick or LethalWeapon3 or Dracula2000' | sed 's/\(\S\)\([A-Z0-9][0-9]*\)/\1 \2/g'
Chronicles Of Riddick or Lethal Weapon 3 or Dracula 2000

How can I do this in PHP? I figured out how to split on capital letters, but I can't get the numbers to work as well.
$new_title = preg_replace('/(?<!^)([A-Z])/', ' \\1', $title);

obstipator
Nov 8, 2009

by FactsAreUseless

mooky posted:

I'm looking for a little help with regex, I'm working on fun little script that is parsing my video files and pulling down information from a movie database. To make it easy to determine an accurate name based on the filename, I have some regex that works great from the command line but not so great with preg_match or preg_replace...

I'm trying to insert a space before all capital letters and the first number in a sequence. Look at the example below.

echo 'ChroniclesOfRiddick or LethalWeapon3 or Dracula2000' | sed 's/\(\S\)\([A-Z0-9][0-9]*\)/\1 \2/g'
Chronicles Of Riddick or Lethal Weapon 3 or Dracula 2000

How can I do this in PHP? I figured out how to split on capital letters, but I can't get the numbers to work as well.
$new_title = preg_replace('/(?<!^)([A-Z])/', ' \\1', $title);

This seems to get the job done:
$new_title = preg_replace('#(?<!^|\s)([A-Z]|\d+)#', ' $1', $title);

Those "#" are used as delimiters. You can pick any character you want, so I usually opt for them rather than "/", so there's not as much escaping needed.

Sulla Faex
May 14, 2010

No man ever did me so much good, or enemy so much harm, but I repaid him with ENDLESS SHITPOSTING

revmoo posted:

asXML() ?

Edit: If you wanted to go the other direction, I'm pretty sure you can cast the SimpleXML object to a string.

asXML was also outputting just the content but now I can't remember if I did the obvious thing and escaped all the characters etc.. The browser might have just been parsing it as part of the HTML elements.

mooky
Jan 14, 2012

obstipator posted:

This seems to get the job done:
$new_title = preg_replace('#(?<!^|\s)([A-Z]|\d+)#', ' $1', $title);

Those "#" are used as delimiters. You can pick any character you want, so I usually opt for them rather than "/", so there's not as much escaping needed.

Hey thanks, that works great. I do have a problem if the file name already contains spaces. Is there an easy way to work around this? In a perfect world I would just rename everything...

Sulla Faex
May 14, 2010

No man ever did me so much good, or enemy so much harm, but I repaid him with ENDLESS SHITPOSTING
e: disregard

Sulla Faex fucked around with this message at 00:29 on Feb 9, 2014

The Gripper
Sep 14, 2004
i am winner

mooky posted:

Hey thanks, that works great. I do have a problem if the file name already contains spaces. Is there an easy way to work around this? In a perfect world I would just rename everything...
You'd probably get by OK by just running $title through str_replace first, $title = str_replace(' ', '', $title)

revmoo
May 25, 2006

#basta
What's the proper way to filter content with html entities in it into something RSS xml compliant? I tried a bunch of things last night and nothing seemed to convert them or filter them out right.

E: nm ENT_XML1 worked well.

revmoo fucked around with this message at 17:59 on Feb 12, 2014

Vintersorg
Mar 3, 2004

President of
the Brendan Fraser
Fan Club



Any good "empty" frameworks to use? Trying to get away from the enormity of CodeIgniter.

DarkLotus
Sep 30, 2001

Lithium Hosting
Personal, Reseller & VPS Hosting
30-day no risk Free Trial &
90-days Money Back Guarantee!

Vintersorg posted:

Any good "empty" frameworks to use? Trying to get away from the enormity of CodeIgniter.

If you're looking for truly empty...
https://github.com/phillipsdata/minphp

It's what the billing software Blesta is built from. It looks good if you want nothing to start with.
The documentation is lacking and it isn't great on the inline comments, but you can download the blesta trial and look at most of the source code to get an idea of how it all ties together.
I decided on this for a very small project that just needed basic MVC functionality with a PDO wrapper.

substitute
Aug 30, 2003

you for my mum

Vintersorg posted:

Any good "empty" frameworks to use? Trying to get away from the enormity of CodeIgniter.

Here's one I found, from looking at the guy's PHP-login project. I haven't used this framework, but it looks pretty simple and lightweight.

http://www.php-mvc.net/

musclecoder
Oct 23, 2006

I'm all about meeting girls. I'm all about meeting guys.
I would avoid anything that doesn't use Composer.

There's Slim and Silex for doing basic sites.

What's your use case though? Sometimes the "big" frameworks are the right tool.

Lareous
Feb 19, 2008

EDIT: Nevermind, figured it out. That's a rare one for me.

Lareous fucked around with this message at 20:46 on Feb 17, 2014

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker

Lareous posted:

EDIT: Nevermind, figured it out. That's a rare one for me.

Why the hell do people keep doing this? :confused: Just put the answer in the next post.

Sulla Faex
May 14, 2010

No man ever did me so much good, or enemy so much harm, but I repaid him with ENDLESS SHITPOSTING
Probably just a non-erroring typo or something similar. It doesn't help anybody else because it's a project-specific fuckup and by leaving the original post it can skew future searches that hit on the keywords. That's why I removed mine half a page up, I had a problem with something or other that just boiled down to a misnamed folder caused by reading the wrong lovely tutorial.

Colonel J
Jan 3, 2008
I'm doing a web site for some friends of mine and most of the important data will be stored in an SQL database. I set up a password-protected page so they could enter data in the DB and send files to the server and I'm wondering how secure it has to be and if the authentication scheme I used is a horror; bear in mind this is the first time I try such a thing.

So the way I did it is they have to go to a "not public" page (i.e. no link to it from the front site) , input a username and password which are sent as POST to the target page. If the (sanitized) passwords match it echos the form to add data to the server, otherwise it echos nothing.

It feels secure to me as first you have to know the login page even exists, second even though the login information is in the php files, if I turn error reporting off it seems like there'd be no way for an attacker to even know what variable names he has to POST the protected page, much less what values they have to take. Am I underthinking this? I couldve stored the password as hashes in the DB but it didnt really feel necessary cause only 3 people will be using this.

Colonel J fucked around with this message at 18:17 on Feb 20, 2014

DholmbladRU
May 4, 2006
Currently I am using wamp on a windows machine and have kohana up and running for one site. I would like to deploy another site which is completely separate and uses a different copy of kohana. To do so I added file structure and deployed kohana as follows

+wamp
++www
+++site1
++++kohana
+++site2
++++kohana

Currently my apache httpd.conf listener is as follows

Listen 0.0.0.0:80

And my hosts file in the windows directory is set up as

127.0.0.1 localhost
127.0.0.1 site1.localhost
127.0.0.1 site2.localhost

Currently when I go to localhost it will go to site1.localhost. Or if i go to site1.localhost it will go to site 1. If I go to site2.localhost the application will redirect to site1.localhost

I am very new to PHP/Kohana so this may be a very basic issue, for that I apologize.

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker
Set up apache to run vhosts. This way you can redirect a request to a different root folder depending on the domain name. It looks like this in your httpd/conf:


code:
<VirtualHost site1.localhost>
    ServerAdmin webmaster@site1
    ServerName site1

    DocumentRoot "C:/wamp/www/site1"

    <Directory "C:/wamp/www/site1">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
  </Directory>

    
    ErrorLog "logs/site1-error.log"
    CustomLog "logs/site1-access.log" common
</VirtualHost>

<VirtualHost site2.localhost>
    ServerAdmin webmaster@site2
    ServerName site2

    DocumentRoot "C:/wamp/www/site2"

    <Directory "C:/wamp/www/site2">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
  </Directory>

    
    ErrorLog "logs/site2-error.log"
    CustomLog "logs/site2-access.log" common
</VirtualHost>


I myself use a bitnami package, and they have an extra vhosts config file to put this stuff in; wamp might have the same.


Additionally, you don't need to put the sites under the wamp/www folder; you can direct it to anywhere. I've set it up to redirect to another folder for easier access to the code so I don't have to root around every time I want to make a change.

Adbot
ADBOT LOVES YOU

DholmbladRU
May 4, 2006
Ah thanks for your reply. Got it working based on that recomendation

DholmbladRU fucked around with this message at 20:47 on Feb 20, 2014

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply