Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. You might wanna pass your API key to your function, since it accesses it but it is not defined in the function scope. header('Content-type: application/json'); $token = "[myapitoken]";//my api token function get_data($url, $token, $timeout = 5) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPGET, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_USERPWD, $token.':api_token'); $data = curl_exec($ch); curl_close($ch); return $data; } $returned_content = get_data("https://toggl.com/reports/api/v2/weekly?&workspace_id=282507&since=2013-05-19&until=2013-08-20&user_agent=[user agent]", $token);//user agent here var_dump($returned_content);
  2. By interchangeable they mean you can swap one for the other, as in setStrategy($strategy), now the object who has that method has his strategy changed, for example if you have a class that displays the filesystem in an hierarchy, a strategy could be to sort it by name (class SortByNameStrategy) or sorted by folders-first (class SortByFolderFirstStrategy). You can change the display by changing the strategy on the filesystem object. Adapter and Strategy are quite alike from a design POV where one is about making one thing work with another, the other is about selecting the proper algorithm/behaviour.
  3. Replacement for If/Switch: http://sourcemaking.com/refactoring/replace-conditional-with-polymorphism Although I mostly agree with HoF in terms of OOP practices and principles. He's wrong about pretty much everything else. Like his view about procedural programming. I don't like hard-liners.
  4. This snippet should remove any and all <link/> tags. echo preg_replace('!<link([^>]+)/?>!', '', file_get_contents('http://domain.top/file.ext'));
  5. Duplicate: http://forums.phpfreaks.com/topic/282282-add-edit-delete-script-problems/?do=findComment&comment=1450234
  6. Do a "forgot password" or contact your hosting company to get your credentials. If you are paying for the hosting this should be no problem.
  7. From their website: LOL $lastClaim = strtotime($lastClaimQ->fetch_assoc());Is wrong what else is in the dispenses table? Also knowing this has been hacked together, not properly tested, you sure you wanna run this on your server?
  8. The url has to be: http://url.com/file_to_process.php
  9. It's a problem many programmers face and this is due to the fact that you don't put any thought into your application before starting to program. To get better at this you need to break your application down into parts you know how to do and parts you don't know how to do. Start with the parts you know how to do, think of how you will achieve them. Then take the one of the parts you don't know how to do and research it, until you have a better understanding of it, and see if you can break it down further again in a part you know how to do and the part you don't know how to do. To take your example: "GETS A LIST OF PDF FILES IN A DIRECTORY AND LOADS THE FILENAMES INTO AN XML DOCUMENT" "CHECKS THE URL VARIABLES, AND DECIDES WHETHER TO RUN THE SPIDER, OR DISPLAY THE XML FILE" "THE OPTIONS LIST WHERE THE USER CAN CHANGE THE WAY THE APPLICATION RUNS" These are just comments in your script, but added together they don't make much sense. Because you just started to hack away and none of the classes in your script have a real goal. From what I deduced from your code I gather that you want a script that checks an url variable then scrapes or displays an xml. When you say it like that it sounds so simple, right? So, thus summarize for yourself what you want to achieve. /** * Crawls an URL endpoint and returns a list of PDF files. * When $crawl_next_pages is true will crawl paginated content. */ function spider_crawl($url, $crawl_next_pages = false) { .. } /** * Given a list of PDF files generates a standard XML file. */ function xml_generate($files, $filename = null) { .. } if ($_GET['action'] == 'scape') { $pdf_files = spider_crawl($_GET['url']); $xml_path = xml_generate($pdf_files); echo 'XML generated.'; } else { readfile($_GET['xml_path']); }When you have all pieces of the puzzle, you may want to consider what your best plan of attack is, like what functions/classes will you have, what will their responsibilities be. Where do you need/want flexibility.
  10. Remember that when cloning an object the object references it holds are left untouched. class Woll { private $thickness; .. } class Sheep { private $woll; public function __construct() { $this->woll = new Woll(3); } public function setWollThickness($thickness) { .. } } $sheep = new Sheep; $dolly = clone $sheep; $dolly->setWollThickness(6); echo $sheep->getWollThickness(); // 6 echo $dolly->getWollThickness(); // 6To avoid this you need to clone the object references inside your object aswell: public function __clone() { $this->woll = clone $this->woll; }Whom in turn would have to do the same thing etc..
  11. Just store it in your database. You can still optimize later.
  12. @Monkuar it IS your computer, you have anti-aliasing disabled. Not all fonts require anti-aliasing, but clearly this one does.
  13. Talking about missing the point of discussion, I think the OP wants an answer to his question.
  14. @Hall of Famer: You are constantly advocating good OO design, yet here you tie your application layer to your model.. A user should not be concerned about how an application handles login or about where a user should go after login.
  15. if ($user['position'] == 'admin') { header('Location: admin.php'); exit; } elseif ($user['position'] == 'student') { header('Location: student.php'); exit; } ..
  16. define('USER_LEVEL_TEACHER', 1); define('USER_LEVEL_STUDENT', 2); define('USER_LEVEL_CASHIER', 4); define('USER_LEVEL_ADMIN', ; if ($userLevel & USER_LEVEL_ADMIN) { // admin }
  17. You are gonna be more specific. I have no idea what you are talking about.
  18. Having done all those tutorials you should be capable of creating your first scripts. Start with the basics: login, registration, and take it from there. If you have specific questions you can always ask them here.
  19. Writer's block. He'll get over it!
  20. 1. Download composer.phar from http://getcomposer.org and drop it inside your project directory 2. Create a composer.json file: { "require": { "imagine/imagine": "0.6.*@dev" } }3. Run $ /path/to/php composer.phar install in the terminal4. Use the imagine library: <?php require_once 'vendor/autoload.php' $imagine = new Imagine\Gd\Imagine(); $image = $imagine->open('/path/to/image'); $image // scale image to 50% ->thumbnail($image->getSize()->scale(0.5)) // display as jpeg at 75% ->show('jpeg', array('quality' => 75));Documentation can be found at http://imagine.readthedocs.org/en/latest/index.htmlAPI is available at http://imagine.readthedocs.org/en/latest/_static/API/
  21. Yes. Simply state your new topic title here, I'll change it for you.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.