Jump to content

requinix

Administrators
  • Posts

    15,286
  • Joined

  • Last visited

  • Days Won

    435

Everything posted by requinix

  1. If you have Apache and shared hosting (ie, you don't control the system) then yes, you'd use a .htaccess with mod_rewrite rules. Looks like RewriteEngine on # only match if the requested file doesn't exist RewriteCond %{REQUEST_FILENAME} !-f # only match if the requested directory doesn't exist RewriteCond %{REQUEST_FILENAME} !-d # rewrite 123.php to page.php?id=123 and stop processing RewriteRule ^(\d+)\.php$ page.php?id=$1 [L]Though the two RewriteConds probably aren't even necessary.
  2. So you're doing 400+ API calls on this page? It's going to be slow - no way around that. Even if each call took only 100ms (which includes sending the request, the server processing data, and then it sending the response back), that's 40 seconds to do all of them. Why do you need so many galleries' data at once?
  3. Well, I can't speak to WordPress stuff (I hate it) so... Use your browser to find out what is happening when that AJAX request gets fired off. For example, Chrome has a Network tab in the inspector/console thing (hit F12) that can show you not just that the request was sent, but what data was sent and what the server returned. Odds are you're getting a 403 Forbidden (may be a WP configuration issue) or a 404 Not Found (using the wrong URL) response from the server, and neither of those will trigger the success callback.
  4. Sure. It's called URL rewriting. What actually happens is requests for /654321.php transparently (user doesn't know) get rewritten to something like /page.php?code=654321. Then you can get your $CODE from the $_GET array.
  5. "Can't get" what? Does the AJAX not happen? Does it happen but the data doesn't get deleted in the database?
  6. Your input is named "user_file" but your code (which I'm sure has other problems besides this) is looking for "uploadedfile".
  7. $zooelements is an array. You can't just stick an array into a string like that. Do you mean to store the JSON? Use json_encode() to turn the modified array back into a JSON string, then escape it (with mysql_real_escape_string()) before sticking it, quoted, into the SQL.
  8. foreach ($output['data'] as $item){
  9. "Perfectly" spaced how? 20 isn't a nice number like 19 (hexagonal) or 25 (square).
  10. As the error message says, you still have a duplicate. You added a "1" to the ID but somehow there's another element that got the change. Is the XML being generated dynamically? Have you checked the XML in string form to see where "timesheet-wrapper1" appears?
  11. Forms can't natively do that. 1. Put a redirect in picture.php so people accidentally going to that URL get redirected to the correct one automatically. (Which only works for GET requests.) 2. Put some Javascript in your form that will alter the form information as it gets submitted. As in you can set the target to /album/picture.php normally in the HTML, then use Javascript to change the action to /lang/album/picture (getting the lang from the form data) when it's submitted. My take on the second half: <form action="/album/picture.php" method="get" data-rewrite-action="/:lang/album/picture"> $(function() { $(document).on("submit", "form[data-rewrite-action]", function() { var elements = this.elements; this.action = $(this).data("rewrite-action").replace(/:([a-z-]+)/i, function($0, $1) { return encodeURIComponent(elements[$1] ? $(elements[$1]).val() : $1); }); }); }); POC For the www thing, RewriteCond %{HTTP_HOST} !=example.com RewriteRule ^ http://www.example.com%{REQUEST_URI} [L,R=301](replacing example.com with your domain)
  12. An addon for Visual Studio to support PHP? VS.PHP is the best one I've seen, but when I checked it a couple years ago it didn't work very well. If you mean IDEs in general and not just Visual Studio then yeah, there are many.
  13. Whatever XML you're transforming, or maybe the XSLT you're using, has some duplicate ids in it. That is not allowed. Each ID must be unique in the entire XML document.
  14. So being able to handle white makes things awkward: it's not a hue range but both a saturation (how much color bleeds in) and lightness (grayscale) range. Playing around, it looks like good ranges are - White is S=[0.0,0.1] L=[0.9,1.0] - Gray is S=[0.0,0.1] L=[0.1,0.9] - Black is S=[0.0,0.1] L=[0.0,0.1] I figure* the best approach would be deciding what HSL ranges constitute each color, then doing some quick math to convert each component between the current color's ranges and the desired color's ranges. For example, you might say that red is H=[330,15] (meaning both [330,360] and [0,15]) S=[0.1,1.0] (so not to overlap with the grayscale) L=[0.1,1.0]; mapping a value which you've determined to qualify as "red" onto "white" could be h[white] = h[red] // hue unchanged s[white] = (s[red] - S[red,min]) / (S[red,max] - S[red,min]) * (S[white,max] - S[white,min]) + S[white,min] // convert 0.1<s[red]<1.0 to 0.0<s[white]<0.1 l[white] = (l[red] - L[red,min]) / (L[red,max] - L[red,min]) * (L[white,max] - L[white,min]) + L[white,min] // convert 0.1<l[red]<1.0 to 0.9<l[white]<1.0 That's a linear transformation - something polynomial (eg, bell curve, sigmoid) would get different results but it would take more planning and math. * I know math and the RGB and HSL colorspaces, but beyond that it's just educated guesswork.
  15. Well, the class name is "row" + number, right? So "row" + numberThen use jQuery to do the search. Remember to put a period before the class name, otherwise you'll be telling it to look for a element.
  16. That technique works well (for images that aren't too large, at least) but only works because it recolors by shifting the hue of each relevant pixel (it being much easier to do this using HSL than with RGB). It's not so much a mapping of blue to green but a mapping of a range of green colors of some size to a range of blue colors of the same size. So you have to figure out two ranges: what you want to recolor from and what you want to recolor to. If all you have to work with is "blue" or "green" then you can guess by picking the midpoint of the hue range for that color and adding/subtracting roughly 60° *. Those will affect the if condition and the colorshift value, so it's probably best to make those all parameters. function recolorPants(hueStart, hueEnd, colorshift) { // correct hueStart and hueEnd for out-of-range values, both <0 and >=360 hueStart = (360 + (hueStart % 360)) % 360; hueEnd = (360 + (hueEnd % 360)) % 360; if (hueStart < hueEnd && hue > hueStart && hue < hueEnd || hueStart > hueEnd && (hue > hueStart || hue < hueEnd)) {- If the color you're starting with is RGB, convert it to HSL and use the hue value.- I suggest "bold" colors for the color choices; you can convert hue=0..360°, saturation=100%, lightness=50% to get them. * Hue ranges from 0 to 360°, and with 6 basic colors that's 60° per color and ±30°. But there's also overlap - consider how teal is greenish and blueish. So you bump that limit out to, say, 50-60° instead.
  17. Cool. Are you storing them as strings or numbers? Or to be more clear, is the data type for the column in the table a string type or a number type?
  18. Are you storing the phone number in your database as a string or as a number? Hint: it should be a string.
  19. id="alunos[]"That's wrong. The ID should just be "alunos". The [] is only for the name.
  20. How you display results is your decision. So how do you want to display it? For the checkboxes, name them all clients[] and then you'll get an array of values instead of just a single value. Then use a loop to execute the command on every machine.
  21. A bit. So you have a parent method which does a thing, but it doesn't have the full picture (you made it protected so somebody else in the class hierarchy has to call it) while the child classes have the rest (the usethis1 and usethis2 values, which comes from within the class and doesn't need to be passed in)? Two approaches: a) The parent's method becomes a helper method with a different name, and the child classes call it with the right value. b) The parent's method is the real method, defines an abstract method (which the children implement) to get whatever value, and calls it within the method to get the value. Requires your parent be abstract. And you can use traits for a variation on either of those. That adds onto the "if something then call method" option, which is a lot like the (b) approach in that the parent's method calls other methods to get data and to perform additional actions. Anonymous functions are appealing, it's true, but there's an object-oriented design solution here that would be more appropriate.
  22. 1. Making $extra optional with a default value needs to be handled below the parent class. If you use "dummy" a lot, that hints at those child classes having something more in common than simply that one argument, which then suggests you create another class between the parent and child which redefines those methods. 2. If the "if something then call method" pattern is very common, and kinda even if it isn't, then move that logic into the parent class. Parent has "something; $this->bla();", defines an empty bla(), and each child overrides it with their own code (ie, renaming bla_a and bla_b to bla).
  23. You're asking for information about why stuff is working, but you're only talking about half of the work you've done. "Altering [the images] with str_replace or preg_replace" can work fine if done correctly. That getimage.php could work fine if everything else is in line with it. So I'm not sure what to say. If you're simply migrating data and not looking too much into the future (where the images may change yet again) then I'd recommend just running a one-time script that updates all the tags in all the pages with whatever you want. Like that getimage.php stuff, which also necessitates storing the replaced image data somewhere else at the same time.
  24. So, this isn't really OOP... It's still procedural code like before, except you're using functions instead of having to copy/paste code around. An OOP version would be like class Flag { private $FlagName = ""; private $pdo = null; public function __construct($pdo, $FlagName) { $this->FlagName = $FlagName; $this->pdo = $pdo; } public function CheckValue($FlagValue) { $sql = "SELECT 1 FROM flags WHERE flagname = ? AND flagvalue = ? LIMIT 1"; $stmt = $this->pdo->prepare($sql); $stmt->execute([$this->FlagName, $FlagValue]); return $stmt->fetchColumn(); } public function GetDescription($FlagValue) { $sql = "SELECT flagdescription FROM flags WHERE flagname = ? AND flagvalue = ? LIMIT 1"; $stmt = $this->pdo->prepare($sql); $stmt->execute([$this->FlagName, $FlagValue]); return $stmt->fetchColumn(); } } $pdo = new PDO($dsn, $username, $password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); $intent = new Flag($pdo, 'intent'); if ($intent->CheckValue(2)) { echo "valid"; } else { echo "invalid"; }1. It could be that "a flag" is not just a name but a name/value pair, in which case you'd set up the name and value with the Flag class and then not have to pass the value into the CheckValue and GetDescription methods.2. If you did that name/value pair thing, better than querying the database in each method would be to simply load up all data when the class gets constructed - then CheckValue and GetDescription could just return values already available.
  25. If you don't want it overwriting then what do you mean by having the image "changed"?
×
×
  • 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.