Some plugins and themes use in database json (?) where is used "s" parameter. Maybe example will be good here:
(9238, 14133, '_mail', 'a:9:{s:6:"active";b:1;s:7:"subject";s:25:"Website title";s:6:"sender";s:49:"[your-name] <wordpress#domain.com>";s:9:"recipient";s:46:"mail1#domain.com";s:4:"body";s:210:"Nadawca: [your-name] <[your-email]>\n\nTreść wiadomości:\n[your-message]\n\n-- \nTa wiadomość została wysłana przez formularz kontaktowy na stronie";s:18:"additional_headers";s:22:"Reply-To: [your-email]";s:11:"attachments";s:0:"";s:8:"use_html";b:0;s:13:"exclude_blank";b:0;}'),
As you can see every string in this row has something like "s:6". It means that following string has 6 chars. I moved from example real domains, etc. so not all lengths are correct now.
Why I'm writing about that. I usually prepare project on my my dev copy on my server and when it's done I copy that to target server (prod). I make this deployment in this standard way:
Copy all files from dev to prod (using ssh usually)
Export dev database
Manually change dev links to prod links in database (e.g. website.dev.domain.com to website-prod-domain.com)
Import database with changes to prod
Change database credentials in wp-config
And everything goes easy until there are in database some "s:" parameters. Then I usually have to go to WP admin panel and manually set all configuration in plugins and personalize options which are not working after deployment.
Is there any good solution or script to make my deployment easy also in case when I meet "s:" on my way?
My problem was about serialized data. The best way I found is using plugin dedicated to migrate database: https://pl.wordpress.org/plugins/wp-migrate-db/
The plugin works very nice with serialized data (Find & replace that handles serialized data).
Related
I'm attempting to find a way to sanitize/filter file names in a Bash script the exact same way as the sanitize_file_name function from WordPress works. It has to take a filename string and spit out a clean version that is identical to that function.
You can see the function here.
GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)
Ubuntu 14.04.5 LTS (GNU/Linux 3.13.0-57-generic x86_64)
This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-linux-gnu-thread-multi
Example input file names
These can be and often are practically anything you can make a filename on any operating system, especially Mac and Windows.
This File + Name.mov
Some, Other - File & Name.mov
ANOTHER FILE 2 NAME vs2_.m4v
some & file-name Alpha.m4v
Some Strange & File ++ Name__.mp4
This is a - Weird -# Filename!.mp4
Example output file names
These are how the WordPress sanitize_file_name function makes the examples above.
This-File-Name.mov
Some-Other-File-Name.mov
ANOTHER-FILE-2-NAME-vs2_.m4v
some-file-name-Alpha.m4v
Some-Strange-File-Name__.mp4
This-is-a-Weird-#-Filename.mp4
It doesn't just have to solve these cases, it has perform the same functions that the sanitize_file_name function does or it will produce duplicate files and they won't be updated on the site.
Some thoughts I've had are maybe I can somehow use that function itself but this video encoding server doesn't have PHP on it since it's quite a tiny server and normally just encodes videos and uploads them. It doesn't have much memory, CPU power or disk space, it's a DigitalOcean 512MB RAM server. Maybe I can somehow create a remote PHP script on the web server to handle it through HTTP but again I'm not entirely sure how to do that either through Bash.
It's too complicated for my limited Bash skills so I'm wondering if anyone can help or knows where a script is that does this already. I couldn't find one. All I could find are scripts that change spaces or special characters into underscores or dashes. But this isn't all the sanitize_file_name function does.
In case you are curious, the filenames have to be compatible with this WordPress function because of the way this website is setup to handle videos. It allows people to upload videos through WordPress that are then sent to a separate video server for encoding and then sent to Amazon S3 and CloudFront for serving on the site. However it also allows adding videos through Dropbox using the External Media plugin (which actually is duplicating the video upload with the Dropbox sync now but that's another minor issue). This video server is also syncing to a Dropbox account and whitelisting the folders in it and has this Bash script watching a VideoServer Dropbox folder using inotifywait which copies videos from it to another folder temporarily where the video encoder encodes them. This way when they update the videos in their Dropbox it will automatically re-encode and update the video shown on the site. They could just upload the files through WordPress but they don't seem to want to or don't know how to do that for some reason.
If you have Perl installed, try with:
#!/bin/bash
function sanitize_file_name {
echo -n $1 | perl -pe 's/[\?\[\]\/\\=<>:;,''"&\$#*()|~`!{}%+]//g;' -pe 's/[\r\n\t -]+/-/g;'
}
filename="Wh00t? it's a -- re#lly-weird {file&name} (with + Plus and__1% #of# [\$qRots\$!]).mov"
cleaned=$(sanitize_file_name "$filename")
echo original : "$filename"
echo sanitised: "$cleaned"
Result is:
original : Wh00t? it's a -- re#lly-weird {file&name} (with + Plus and__1% #of# [$qRots$!]).mov
sanitised: Wh00t-it's-a-re#lly-weird-filename-with-Plus-and__1-of-qRots.mov
Looking at WP function, this emulates it quite well.
Inspired by the answer.
EscapeFilename()
{
printf '%s' "$#" | perl -pe 's/[:;,\?\[\]\/\\=<>''"&\$#*()|~`!{}%+]//g; s/[\s-]+/-/g;';
}
This question already has answers here:
Project Links do not work on Wamp Server
(13 answers)
Closed 7 years ago.
I'm on windows 8, I downloaded the wamp server and I have my index.php saved into the "www" folder within a subfolder called websites. When I'm on the localhost page, it displays the subfolder under "Your Projects" but when I click it, it takes me here
http://www.dnsrsearch.com/index.php?origURL=http%3A//websites/&r=http%3A//localhost/
and it says
"Why Am I Here?
You entered an unknown web address that was used to present site suggestions that you may find useful. Clicking any of these suggestions provides you with search results, which may include relevant sponsored links.
If this service is not right for you, please visit your Preferences page to opt out. At any point in time, you can opt back in to the service by visiting your Preferences page.
If you have other questions about this service, please visit our FAQ."
Basically, it's taking me to a search engine and trying to show some suggestions for what I could've wanted, but I'm not trying to go to a website. I'm trying to access and display my test site so I can start practicing PHP. It's been really frustrating just getting started with this because I've come across all these different ways to do php and different problems and so far, using this wampserver seems like the best option but I'm stuck. Please please please help. This is driving me nuts!
Summary:
I installed the WAMP server, I have my index.php saved in my www folder with its designated www subfolder (wamp\www\Websites\index.php), it displays on the localhost under my projects, but the link to display it doesn't work.
Any answers?
FOLLOWING UP A YEAR LATER
I appreciate the responses I've received. What I ended up doing to get the ball rolling (I went on a web development hiatus to pursue other things) and make things a lot easier to work with is I setup a LAMP server instead and it made the install process super easy and straight forward, and from there I've had no problems at all creating virtual hosts and making my websites work and having everything interact the way it should. If you're stuck where I was, setting up and using WAMP on windows is a lot more involved and touchy than setting it up on a linux system. On a linux system, you won't get a dedicated gui program like WAMP, but you'll have everything running in your operating system to handle it and it basically turns your computer into a local web server with php/sql support, and whatever else you'd like to add onto it. I'm using kali linux and it's working out fine for me. If you just want to dive into php without having to get over the huge hurdle on windows virtual hosts, I highly recommend just doing the research and setting it up on a linux system. If you have an additional hard drive, put linux on it. If you don't, setup a dual boot configuration on your drive so you'll have windows and linux. It helped me out a ton with learning how to make things on the backend reference each other the way I wanted to while also getting a significantly better understanding of it as I went. All you need installed is apache, mysql, and php and after setting everything up, it should work just fine on your local machine. Learning linux can seem scary at first, but this process is a lot more straight forward and easier to understand than doing it on windows.
I believe this is the best and easiest solution:
Open index.php in www folder and set
change line 30:$suppress_localhost = true;
to $suppress_localhost = false;
This will ensure the project is prefixed with your local host IP/name
Just change the value in wamp/www/index.php line no 338.
Change this :
From
$projectContents .= '<li>'.$file.'</li>';
to
$projectContents .= '<li>'.$file.'</li>';
Run the wamp server, Start apachee and enter the url as
http://localhost/websites/index.php
There is a document on the WAMPServer forum HERE is the link that documents an amendment you can make to revert the Project links back to Pre 2.5 mechanisms
Look for the section entitled Revert WAMPServer 2.5 "Your Projects" links to pre 2.5 mechanism
Here is the amendment :-
Revert WAMPServer 2.5 "Your Projects" links to pre 2.5 mechanism
It would appear that some WAMPServer users cannot cope with creating Virtual Hosts for each of their sites/projects.
This is code that will be in the next version of WAMPServer so if you want your "Your Projects" menu to provide links in the form 'localhost/folder_name' rather than 'folder_name' so you dont have to create a simple Virtual Host definition, here is how it should be done.
I would enphasise, this is not the recommended mechanism. The only GOOD solution is to use the Virtual Host mechanism
However, making these changes will not harm WampServer and you can always set suppressLocalhost = "yes" to keep the WAMPServer2.5 mechanism.
Edit wamp/wampmanager.conf
In the section [main] add this line :
suppressLocalhost = "no"
Save the file
If this is set to "no" Your Project links will be in the form localhost/folder_name i.e. the pre WAMPServer 2.5 way.
If this is set to "yes" Your Project links will be in the form folder_name and require a Virtual Hosts definitions to work.
Edit \wamp\www\index.php
Locate this line
$suppress_localhost = true;
and comment it out like so:
//$suppress_localhost = true;
Find this line
$wampserverVersion = str_replace('"','',$result1); ajouter/add
and after that line add this code
//[modif oto] - On récupère la valeur de suppressLocalhost
preg_match('|suppressLocalhost = "(.*)"|',$wampConfFileContents,$result);
if($result[1] != "yes" )
$suppress_localhost = false;
else
$suppress_localhost = true;
Save this file
Edit /wamp/scripts/config.inc.php
Find this line
$c_editor = $wampConf['editor']; ajouter/add :
and after that line add
//[modif oto] Ajout variable suppressLocalhost
if($wampConf['suppressLocalhost'] != "yes" )
$c_suppressLocalhost = false;
else
$c_suppressLocalhost = true;
Save the file
Edit /wamp/scripts/refresh.php
Find this line
{
$myreplacesubmenuProjects .= 'Type: item; Caption: "'.$projectContents[$i].'"; Action: run; FileName: "'.$c_navigator.'"; Parameters: "['.$projectContents][$i].'/"; Glyph: 5
and REPLACE it with
{ //[modif oto] Support de suppressLocalhost dans wampmanager.conf
$myreplacesubmenuProjects .= 'Type: item; Caption: "'.$projectContents[$i].'"; Action: run; FileName: "'.$c_navigator.'"; Parameters: "'.($c_suppressLocalhost ? "["]; : 'http://localhost/').$projectContents[$i].'/"; Glyph: 5
Save this file.
The changes are now complete.
Now restart WAMPServer
Having trouble capturing the following dynamic image on disk, all I get is a 1K size file
http://water.weather.gov/precip/save.php?timetype=RECENT&loctype=NWS&units=engl&timeframe=current&product=observed&loc=regionER
I have setup PHP cURL feature to work just fine on static imagery, but does not work for the above link. Similarly, also copy function, file_put_contents (file_get_contents)...they all work fine for static image. Plenty of references in SO for usage of these PHP functions, so I will not get into details here. Just the copy command:
copy('http://water.weather.gov/precip/save.php?timetype=RECENT&loctype=NWS&units=engl&timeframe=current&product=observed&loc=regionER', 'precip5.png');
Behavior is same, getting precip5.png size 760 bytes, on my windows development box and linux staging box, so can rule OS issues out. Again, all PHP functions do exactly the same thing - generate a file - but empty. Command line curl program is also generating that same junk 1K file.
So, the issue seems to be source and the best I can tell is that it is a dynamic (streaming?) image.
Ideally, I would like this be done in PHP or some command line utility like curl. I am trying to avoid adding java (imageio) dependency just for this...until I absolutely have have to go there...
I am trying to understand the nature of the beast (the image) first ;-)...
The URL you are saving produces HTML output, not the image. You are missing the parameter &print=1
http://water.weather.gov/precip/save.php?timetype=RECENT&loctype=NWS&units=engl&timeframe=current&product=observed&loc=regionER&print=1
I have a php script that logs into my servers via the ftp function, and backs up the entire thing easily and quickly, but I can't seem to find a way to let the script determine the folder where the main index file is located.
For example, I have 6 servers with a slew of ftp accounts all set up differently. Some log into the FTP root that has httpdocs/httpsdocs/public_html/error_docs/sub_domains and folders like that, and some log in directly to the httpdocs where the index file is. I only want to backup the main working web files and not all the other stuff that may be in there
I've set up a way to define the working directory, but that means I have to have different scripts for each server or backup I want to do.
Is it possible to have the php script find or work out the main web directory?
One option would be to set up a database that has either the directory to use or nothing if the ftp logs in directly to that directory, but I'm going for automation here.
If it's not possible I'll go with the database option though.
You cannot figure out through FTP alone what the root directory configured in apache is - unless you fetch httpd.conf and parse it, which I'm fairly sure you don't want to do. Presumably you are looping to do this backup from multiple servers with the same script?
If so, just define everything in an array, and loop it with a foreach and all the relevant data will be available in each iteration.
So I would do something like this:
// This will hold all our configuration
$serverData = array();
// First server
$serverData['server1']['ftp_address'] = 'ftp://11.22.33.44/';
$serverData['server1']['ftp_username'] = 'admin';
$serverData['server1']['ftp_password'] = 'password';
$serverData['server1']['root_dir'] = 'myuser/public_html';
// Second server
$serverData['server2']['ftp_address'] = 'ftp://11.22.22.11/';
$serverData['server2']['ftp_username'] = 'root';
$serverData['server2']['ftp_password'] = 'hackmeplease';
$serverData['server2']['root_dir'] = 'myuser/public_html';
// ...and so on
// Of course, you could also query a database to populate the $serverData array
foreach ($serverData as $server) {
// Process each server - all the data is available in $server['ftp_address'], $server['root_dir'] etc etc
}
No, you can't do it reliably without knowledge of how Apache is setup for each of those domains. You'd be better off with the database/config file route. One-time setup cost for that plus a teensy bit of maintenance as sites are added/modded/removed.
You'll probably spend days getting a detector script going, and it'll fail the next time some unknown configuration comes up. Attemping to create an AI is hard... you have to get it to the Artificial Stupidity level first (e.g. the MS Paperclip).
I'm making a GWT project that uses PHP to connect to a DB2 database. When I compile the project and deploy it to the server (copy the contents of the WAR directory over), it works fine, obviously in hosted mode I run into the SOP issue since GWT is on port 8888 while the php script is running on port 80.
I'm trying to get the -noserver option to work but I must be missing something.. I went back and created the basic sample app from the command line (webApplicationCreator -out /home/mike/gwt/sample1)
I edited the build.xml to include the -noserver and -port 80 arguements for devmode. I want my app to be hosted at localhost/sample1 so I edited the -startupUrl to the whole URL I want to use: http://localhost/sample1/sample1.html
I compiled (ant), copied over the sample1.html, sample1.css from war to the webserver sample1 directory, and the (md5).gwt.rpc, clear.cache.gif, sample1.nocache.js and hosted.html files from the war/sample1 to sample1/sample1 directory as described in the GWT documentation (no history.html file was created).
I then run ant devmode from the project directory (/home/mike/gwt/sample1)
I can get to the sample1.html page, but when I click the button to send the name to the server it returns with
Remote Procedure Call - Failure
Server replies:
An error occurred while attempting to contact the server. Please check your network connection and try again.
I turned on firebug and it's returning a 404 for http://localhost/sample1/sample1/greet. This is where I'm stuck.. this file obviously doesn't exist on my webserver.. but why? Isn't this something that is supposed to be getting compiled by GWT?
Can anyone give me a hand? Thanks!
So, basically you've copied over the client-side of a client/server application. When your GWT client application attempts to make a Remote Procedure Call (RPC) to the server to a greeting service that is part of the initial sample, it can't find that service.
If you wanted to copy that service over, you'd need to have a Java application server, copy over the GreetingService, the web.xml that references it and possibly a few other things (I'd have to check in more detail). That doesn't sound like what you actually want, so either you'll want to build a GWT-RPC service in PHP that responds to that URL, or remove the reference in the GWT code to RPC call to the greeting service.
With a PHP back-end, you're probably not going to use GWT-RPC, I'm guessing that you're more likely to use JSON or XML, and if that's the case, then I'd go with removing the RPC call altogether for now.
Does this all make sense? Feel free to ask for further clarification.
To solve the SOP issue, I used the HttpProxyServlet to proxy the HTTP requests to my webserver through the development server.
Download httpProxyPackage.jar, copy it into WEB-INF/lib/, and configure it like so in WEB-INF/web.xml (this is for the StockWatcher tutorial, assuming your web root is the folder that contains the StockWatcher directory):
<servlet>
<servlet-name>jsonStockData</servlet-name>
<servlet-class>com.jsos.httpproxy.HttpProxyServlet</servlet-class>
<init-param>
<param-name>host</param-name>
<param-value>http://localhost/StockWatcher/war/stockPrices.php</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>jsonStockData</servlet-name>
<!--
http://127.0.0.1:8888/stockPrices.php in dev mode
http://gwt/StockWatcher/war/stockPrices.php in prod mode
-->
<url-pattern>/stockPrices.php</url-pattern>
</servlet-mapping>
Then redefine your JSON URL as:
GWT.getHostPageBaseURL() + "stockPrices.php?q=";
instead of:
GWT.getModuleBaseURL() + "stockPrices.php?q=";
It’s maybe not the best way, but if it can get someone else started… There was another way using php-cgi, but I didn’t have it installed.