Jump to content

CrimpJiggler

Members
  • Posts

    72
  • Joined

  • Last visited

Everything posted by CrimpJiggler

  1. I read a security article a while ago that claimed it is dangerous to browse the web while you are logged into gmail, facebook, whatever because any website can get the profile ID of these accounts if you are logged into them. That sounds like bs to me, but the article seemed relatively legitimate so I'm wondering about this. Can you, with PHP or javascript get the profile ID of social media/whatever accounts a user is logged into?
  2. I just made this procedure which will do for now: DELIMITER $$ CREATE PROCEDURE rearrangeNodes(IN parentId INT) BEGIN DECLARE parentLft INTEGER; SET parentLft = (SELECT lft FROM table WHERE category_id = NEW.parentId); UPDATE `table` SET lft = CASE WHEN lft > parentLft THEN lft + 2 ELSE lft + 0 END, rght = CASE WHEN rght >= parentLft THEN rght + 2 ELSE rght + 0 END WHERE lft >= newLft; END$$
  3. I can't edit my post, I wanna ask a better question. Is there a simple way to make MySQL handle nested hierarchical database tables for you. My table has a parent_id, lft and rght value. CakePHP handles this automatically but does MySQL have built in functionality for that? If not, can anyone point me towards a simple stored procedure to do it? I know what I need to do, just find out whether the parent node is empty or not, if its empty then I expand it by 2, and shift everything to the left and right of it two. If its not empty, then I just shift everything from the start of the parent node to the right. There must be an automatic way to do it though.
  4. I'm using a CRUD system which won't automatically update the lft and rght values of my hierarchical tables when I enter a new row. I don't know what the best way to solve this is, all I can think of is adding a stored procedure to the table so that whenever a new row gets added, the procedure will make sure the lft and rght values get shifted. Is this even possible with stored procedures?
  5. I've played around with CakePHP, then XCrud (a decent CRUD application) but I gave up on both of them, XCrud was great for everything up until it came to managing complicated relational database tables. Anyhow, I'm using wordpress a lot now cuz it lets me stop reinventing the wheel so much and although I was able to integrate XCrud into WordPress as a plugin, I think the best way to go is just transfer my database tables to WordPress tables and display them as custom post types. My time is really limited right now though, is there a plugin/set of plugins I can use to automate the process? To show you what I mean, heres the XCrud list display of one of the tables: thats great because it automatically sets up the CRUD thing and lets you add and edit fields to the table, and doesn't heavily box you into their system but I have a table of plants, one for products, one for pharmacology, one for categories which are all related to each other, and some of them are structured in a tree/nested hierarchy structure so long story short, I need to do advanced searches based on these relations and handle these tree structured tables and CakePHP didn't work out, and XCrud has crappy documentation and isn't popular enough to find good info. So how would you go about transfering this system to WordPress? I'm guessing I need to make custom post types for each table but what I don't yet know is how to transfer the DB tables to WordPress format, how to handle the relationships between each table and how to handle the hierarchical tree structures.
  6. What you said about the difference, I get that. No need to create an instance of an globally if you only need to create it inside your class, but the method I mentioned above does the exact same thing. I never had to add __construct(ExtraObject $ExtraObject) to the constructor, and to instantiate my class and make sure it instantiates the second class, I never had to do $instance = new MyClass(new ExtraClass()); I just put $this->ExtraClass = new ExtraClass(); inside the constructor function itself. I hope theres something I'm missing here because I was hoping this __construct(Object $object); would let me do something new. Theres a problem I need to learn how to solve right now, I do a shitload of extending classes, I've been extending classes in chains and that can become a problem because sometimes the same class gets inherted twice. Another part of this problem is that only classes at the end of the chain have access to all methods, a class further up the chain can't access the class at the bottom because it hasn't extended it.
  7. Why would something in my website suddenly stop working when I haven't edited it in months. I have a website on a free server, which I recently upgraded to a premium account to host my other sites. When I went to that old site today, I get this error: Heres line 162: $array_cartesian = function() use (&$array_cartesian) { but in my experience errors like this are caused by something before the line with the unexpected code, heres the whole class: class colorCombos { public function __construct() { } static public function get_combos() { $colors = array('blue', 'red', 'green'); $array_cartesian = function() use (&$array_cartesian) { $args = func_get_args(); if(count($args) == 0) { return array(array()); } $a = array_shift($args); $c = call_user_func_array($array_cartesian, $args); $r = array(); foreach($a as $v) { foreach($c as $p) { $r[] = array_merge(array($v), $p); } } return $r; }; $combo = $array_cartesian($colors,$colors); $combo_array['code'] = $combo_array['display'] = array_filter( $combo, function (&$row) { return ($row[0] !== $row[1]); } ); $walk_call = function (&$row,$key) { $row = $row[0] . "-" . $row[1]; }; array_walk_recursive( $combo_array['display'], function(&$item,$key) { $item = ucwords($item); } ); array_walk($combo_array['code'],$walk_call); array_walk($combo_array['display'],$walk_call); return $combo_array; } } Its for generating a list of combinations of two objects, in this case colours, so it'll output an array of items like red-blue, blue-green, green-red etc. It was working fine before, I don't know if it was right after upgrading the account that it happened or not, all I know is I didn't do anything myself to cause the error. Could that empty constructor be the problem? I rarely ever use static methods, I used it here just to learn, do I need to make the constructor static too?
  8. Oh yeah sorry, thats what I meant. What I meant about Config, is it I have a class containing properties common to all my classes. I used extend my classes with that Config class. I just learned about traits, this is brilliant, thanks a lot. This will solve my issues with chains of extended classes.
  9. Brilliant explanations, nice one. So inheritence is what happens when I use "class1 extends class2" and inheretence means that every method and property from class2 becomes part of class one, kind of like if I have a function page and add include('functionspage2.php'). But this $__construct(Objectname $ObjectContainerVariable) thing is more like loading an instance of the Battery object into your Device objects instances. Is that it? I'm still a bit confused. The idea I have in mind, how I do it is like this: class Battery { } class Device { public __construct() { $this->battery = new Battery(); } } then that Battery instance is available to all my methods inside the Device class, and any classes that extent Device. Is this what you mean by me making Battery a subclass of Device, rather than Device having a Battery? An issue I have is lets say Device extends say my Config class, if I need to use the $battery instance inside my Config class I can't access it, I have to make a new instance. I've run into plenty issues like that so my method isn't very good, I'm hoping that this other method solves some of those issues for me. I haven't learned about traits yet but will ASAP, they sound interesting. Nice one for the terminology, but I'm still a bit confused about what inheritence and composition is. Is inheretence what happens when I extend one class with another? If so, then I get it. I see that like merging the two classes. Composition I'm guessing is where you add an instance object of a another class to your class so the second classes methods are contained in the $variable holding the instance.
  10. I've been spending long hours learning about classes and their magic methods. I just came across a tutorial which showed a constructor like this: class Device { //... public function __construct(Battery $battery, $name) { // $battery can only be a valid Battery object $this->battery = $battery; $this->name = $name; // connect to the network $this->connect(); } //... } the Battery part instantly caught my attention. Here had previously made a Battery class (and a more complete Device class) but the next thing he did really caught my interest: $device = new Device(new Battery(), 'iMagic'); // iMagic connected echo $device->name; // iMagic what the hell is going on here? Is this another way to include the methods and properties of one class into another class, in order words is this the same thing as: class Device extends Battery I don't think so because this new Battery() thing looks more like its creating an object inside the Device object. Previously the only way I could to that was to type $battery = new Battery() inside one of my methods. But this looks like hes doing something different. Can anyone explain whats going on here? The whole tutorial is here: http://code.tutsplus.com/tutorials/deciphering-magic-methods-in-php--net-13085 in the main Device method he has a premade $battery variable to hold the Battery object. Sometimes I have multiple classes containing functions which I'd like to include in my main class. I can only extend one class, so I usually extent a class containing only properties, no methods. I still don't know what difference making that info class abstract is, I'd appreciate if anyone could tell me. Also I'd love to know what the point in static methods is. I've never used them because I've never seen the point. Is it just to make it easier to call the methods because you don't need to create an object instance to call them? Sorry for the extra questions, the first one is what I'm really wondering about.
  11. Using CakePHP as an example, the steps I'm talking abot are enabling URL rewriting, chmod 777ing the app/tmp directory, including the plugins in bootstrap.php, setting up a new database + user for the site, enabling jquery etc. All these little things add up and become time consuming. NetBeans has a CakePHP plugin which installs the framework for you and lets you choose which javascript frameworks you wanna install with it and stuff like that, but its still not something that sets the whole thing up for you with the click of a button.
  12. I started learning how to use composer, I read about it numerous times in the past but didn't realise that this is what it does. Does it have built in functions to set the cipher + seed of a new CakePHP project, bootstrap the plugins for you, setup the database, add jquery to webroot/js + include it in layouts/default.ctp etc? I only started learning it recently so I don't know how to use it yet, but the little I do know is gonna make things a whole lot easier for me. An issue I've run into is I don't know how to make it download plugins that don't have composer.json files. To work around that can you just create your own composer.json file for the plugin, then plug it into composer? I'll look into phing, thanks. I'm guessing it would be easy to make a script that controls composer and bake to do the heavy lifting and framework part for you.
  13. I notice plenty of CakePHP plugins don't have composer.json files in their github repositories (I'm not sure where composer downloads from if you don't specify a repository, is it github?) so I can't automatically download and update them. For composer to recognise and download the plugins, all thats needed is the composer.js file itself isn't it? Why wouldn't plugin authors just spend an extra 10 minutes and make a composer.js file? I'm guessing theres something I'm missing here, it must not be that simple. I only started using composer so I don't really know what its about yet.
  14. I hear CakePHP 3.0 being talked about like its something for the future but I also see that you can download it and there are tutorials for it out already. Is it ready for developmental use, or is it still too early for that?
  15. I do a lot of trial and error to learn how to use the frameworks, and sometimes I install lots of plugins and make lots of modifications so things get confusing. When that happens, I prefer to start a fresh install so I can be sure that plugins or whatever don't interfere with the new things I'm testing. The shell script I made does a fair bit of the work, it sets up the config file, edits the salt and cipher, sets up MySQL databases and installs jquery. It does it all in one go though and doesn't give you options (i.e. some people don't want jquery), I couldn't be bothered making an interface for all that.
  16. Its a pain in the ass setting up frameworks like CakePHP or WordPress repeatedly on your local machine, it would be nice to have a program that automatically sets it up for you. Does a program like this exist? I started making a bash script which automatically installs CakePHP but it turned out to be a lot of work, I don't have the time to do it on my own. What would be cool is if this site had a system where a person starts an editable script, then other users that the person invites are able to edit the script, that way a group of us could pitch in and make new scripts rapidly.
  17. The first thing I learned after HTML and CSS is PHP. Its my primary language now, but I also use SQL and javascript and XML regularly, and since I use linux, I use bash scripting. The cool thing is they all work hand in hand. I recently learned how to use SQLite too, which is good because it can be accessed directly by javascript. Are there any other languages which would enable me to make new things and combine them with PHP scripts? I was looking into java but the security restrictions on applets make it pointless. Flash actionscript looks good. What about perl? Or ruby? Would they enable me to do things I can't easily do with PHP? I've heard about node.js recently a lot so I'm looking into that. Bash scripting is great, but the only issue is I could only use it on a server owned by myself, commercial servers won't let you execute commands like that. I'm interested in perl, python and java but I'll only learn them if they enable me to do things I can't do (easily) with PHP.
  18. Is that a good way to do it? How would I do structure it hierarchically? Right now I want to make a list of browser plugins that I find exceptionally useful, and they need to be categorised by what browser they are for, and what purpose (i.e. programming, security, downloading, flash/java compatibility etc.). I suppose I could do that with a spreadsheet, I just make special rows that say "BROWSER", then a special row for each category within that browser. I don't know though, a database or XML file seems much easier. I started using OpenOffice Base and its pretty useful for converting between database and spreadsheets. I started looking at those .sqlite files in the .mozilla/firefox folder and that got me interested. I like the idea of having small database files like that but I don't know anything about sqlite yet.
  19. Often times I need to convert between PHP Arrays, MySQL, XML, JSON sqlite etc. Lately I've been just building PHP arrays with all the data. Its a big hassle though when theres a lot of data. I'm thinking I should have one central location that I store data in, then export to other formats from there, but I dont know what that central location should be. I like MySQL because I'm used to it. Sometimes its not an option though, like if I need to make a really light script, I dont want the hassle of connecting to MySQL. Would XML be the best place to store data, then from the XML file I can convert it to whatever format I want?
  20. Is it for storing classes and functions which you will include in different controllers (or models, views, helpers, components etc.)? Up until now I've just been storing everything in helpers and components, but that would get messy with bigger applications, so it'd be useful if I could store my commonly used functions in separate files. Is this what the lib folder is intended for?
  21. I haven't tried yet actually, I haven't even figured out how to view the XML files through the cake routing system. I could add a new rule to routes.php but I'm thinking theres probably already a built in way to style and view XML files.
  22. $diagramPath is the full path to the folder so its something like /var/www/mysite/app/webroot/img/diagrams. Could the / slashes be causing problems?
  23. I made this script which extracts data from a batch of files, and I'm basically just loading the extracted data into a big multidimensional array. Only issue now is I don't know what to do with the array. I don't feel like making new database tables for the data so instead I converted the array into an XML file, usually I would just use a .xsl file to output the XML file as HTML but I don't know how to do that with CakePHP. The XML file generated by CakePHP is big and ugly like the array: but its so easy to convert arrays into XML with CakePHP, I wanna make use of this feature. What should I do with the XML file? I've seen mention of "XML views" and JSON views but I haven't got my head around what they are yet. I suppose if there was an easy way to convert this XML or array into a database table structure, so it'll automatically create the table and load the data into it, that would be fairly useful. For now though, I need to be able to display this data in a human friendly format, cuz other people need to use this tool. Any tips?
  24. Heres the code: /* Diagrams */ $match["img"] = "~\[img=(.*?) type=(.*?)]~i"; $replace["img"] = "<img src=\"/path/to/img/$1-$2.gif\">"; /* Diagrams */ $match["diagram"] = "~\[diagram=(.*?)]~i"; $replace["diagram"] = "<img src=\"{$diagramPath}/$1\">"; $content = preg_replace($match,$replace,$content); its a simple BBCode type script so its useful the way I can put all the patterns into the $match array, and automatically replace it with values from the $replace array. works fune because the path is hardcoded, but diagram won't work, it just ignores the $diagramPath variable. I've tried different things like changing to single quotes: $replace["diagram"] = '<img src="' . $diagramPath . '/$1">'; but I get the same results, it reads the $1 variable, but won't read any custom variables that I put in there. I want to keep this simple $match $replace array system, is there a way to make it read all variables in the $replace string? I see that the /e modifier is deprecated, and from what I read it sounds like thats what I'm looking for, so I followed the manuals advice and tried using preg_replace_callback but it got messy, it wouldn't automatically use the $replace array. The only use I have for preg_replace() is situations like this, otherwise I'll use str_replace or preg_match. I don't see the purpose for preg_replace_callback when you can just use if(preg_match()) { // do something }
×
×
  • 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.