ٹیگ آرکائیو: ورڈپریس

اعلی کارکردگی بلاگز اور ویب سائٹس

آپ کو ایک ویب سائٹ یا ایک بلاگ ہے اور یہ بھاری ٹریفک کے ساتھ نیچے فنس گیا ہو رہی ہے کہ لگتا ہے? سب سے پہلے, مبارک ہو - یہ ویبماسٹرس اور بلاگرز سے محبت کرے گا کہ ان مسائل میں سے ایک ہے. لیکن کس طرح آپ کو اسے حل کریں گے? سب سے پہلے کام پی ایچ پی کی تیزی کو چالو کرنے کے لئے ہے, آپ کی ویب سائٹ / بلاگ کی بنیاد پر پی ایچ پی کی ہے. یہ براہ راست ہونا چاہئے اگرچہ (اصول میں), یہ حق حاصل کرنے میں کچھ وقت لگ سکتا ہے. تم وہ کیا کہتے ہیں - اصول میں, اصول اور عمل ایک ہی ہیں. عملی طور پر, وہ نہیں ہیں. سرعت کاری, تاہم, ایک کم پھانسی پھل ہے, اور آپ کے مسائل کو حل کرنے میں ایک طویل راستہ جائیں گے.

آپ کو سرعت کے حل کی تمام مائلیج نکالا ہے ایک بار, یہ ایک مواد کی ترسیل کے نیٹ ورک یا CDN شامل کرنے کا وقت ہے. کیا CDN کرتا ہے اپنے تمام جامد فائلوں کی خدمت ہے (تصاویر, سٹائل شیٹس, جاوا اسکرپٹ فائلوں, اور بھی بلاگ کے صفحات محفوظ) آپ کے اپنے مقابلے میں دوسرے سرورز کے ایک نیٹ ورک سے. یہ سرور سامری براعظم کے ارد گرد رکھی جاتی ہیں (اور دنیا بھر میں) آپ کے قارئین اس سے جغرافیائی بند ایک جگہ سے مواد حاصل تاکہ. کی وجہ سے فاصلے پر تاخیر کو کم کرنے کے علاوہ میں, CDN بھی آپ کے سرور پر لوڈ کو کم کرنے کی طرف سے آپ کی مدد کرتا ہے.

پڑھنے کے آگے

پی ایچ پی میں ایک مقامی فائل میں ایک تار کو بچانے کے لئے کس طرح?

This post is the second one in my geek series.

While programming my Theme Tweaker, I came across this problem. I had a string on my server in my php program (the tweaked stylesheet, حقیقت میں), and I wanted to give the user the option of saving it to a file his computer. I would’ve thought this was a common problem, and all common problems can be solved by Googling. لیکن, lo and behold, I just couldn’t find a satisfactory solution. I found my own, and thought I would share it here, for the benefit of all the future Googlers yet to come and go.

Before we go into the solution, let’s understand what the problem is. The problem is in the division of labor between two computers — one is the server, where your WordPress and PHP are running; the other is the client’s computer where the viewing is taking place. The string we are talking about is on the server. We want to save it in a file on the client’s computer. The only way to do it is by serving the string as an html reply.

پہلی نظر میں, this doesn’t look like a major problem. سب کے بعد, servers regularly send strings and data to clients — that’s how we see anything on the the browser, including what you are reading. If it was just any PHP program that wants to save the string, it wouldn’t be a problem. You could just dump the string into a file on the server and serve the file.

But what do you do if you don’t want to give the whole world a way of dumping strings to files on your server? ٹھیک ہے, you could do something like this:

<?php
header('Content-Disposition: attachment; filename="style.css"');
header("Content-Transfer-Encoding: ascii");
header('Expires: 0');
header('Pragma: no-cache');
print $stylestr ;
?>

تو, just put this code in your foo.php that computes the string $stylestr and you are done. But our trouble is that we are working in the WordPress plugin framework, and cannot use the header() calls. When you try to do that, you will get the error message saying that header is already done dude. For this problem, I found the ingenious solution in one of the plugins that I use. Forgot which one, but I guess it is a common technique. The solution is to define an empty iFrame and set its source to what the PHP function would write. Since iFrame expects a full HTML source, you are allowed (حقیقت میں, obliged) to give the header() directives. The code snippet looks something like:

<iframe id="saveCSS" src="about:blank" style="visibility:hidden;border:none;height:1em;width:1px;"></iframe>
<script type="text/javascript">
var fram = document.getElementById("saveCSS");
<?php echo 'fram.src = "' . $styleurl .'"' ;
?>

Now the question is, what should the source be? دوسرے الفاظ میں, what is $styleurl? واضح طور پر, it is not going to be a static file on your server. And the purpose of this post is to show that it doesn’t have to be a file on the server at all. It is a two-part answer. You have to remember that you are working within the WordPress framework, and you cannot make standalone php files. The only thing you can do is to add arguments to the existing php files, or the plugins you have created. So you first make a submit button as follows:

<form method="post" action="<?php echo $_SERVER["REQUEST_URI"]?>">
<div class="submit">
<input type="submit" name="saveCSS" title="Download the tweaked stylesheet to your computer" value="Download Stylesheet" />
</div>

Note that the name attribute of the button is “saveCSS.” اب, in the part of the code that handles submits, you do something like:

<?php
if (isset($_POST['saveCSS']))
$styleurl = get_option('siteurl') . '/' . "/wp-admin/themes.php?page=theme-tweaker.php&save" ;

?>

This is the $styleurl that you would give as the source of your iFrame, fram. Note that it is the same as your pluging page URL, except that you managed to add “?save” at the end of it. The next trick is to capture that argument and handle it. For that, you use the WordPress API function, add_action as:

<?php
if (isset($_GET['save'] ))
add_action('init', array(&$thmTwk, 'saveCSS'));
else
remove_action('init', array(&$thmTwk, 'saveCSS'));
?>

This adds a function saveCSS to the init part of your plugin. Now you have to define this function:

<?php
function saveCSS() {
header('Content-Disposition: attachment; filename="style.css"');
header("Content-Transfer-Encoding: ascii");
header('Expires: 0');
header('Pragma: no-cache');
$stylestr = "Whatever string you want to save";
ob_start() ;
print $stylestr ;
ob_end_flush() ;
die() ;
}
?>

Now we are almost home free. The only thing to understand is that you do need the die(). If your function doesn’t die, it will spew out the rest of the WordPress generated stuff into your save file, appending it to your string $stylestr.

It may look complicated. ٹھیک ہے, I guess it is a bit complicated, but once you implement it and get it running, آپ کر سکتے ہیں (and do) forget about it. کم از کم, مجھے کیا کرنا. That’s why I posted it here, so that the next time I need to do it, I can look it up.

Geeks

I have been doing a bit of geeky stuff lately — writing ورڈپریس پلگ ان. ٹھیک ہے, it is because I’m suffering from a terrible writer’s block.

تم نے دیکھا, I’m supposed to be working on my next book. I foolishly promised a couple of chapters of ماتراتمک ترقی کے اصول to my commissioning editor at John Wiley & Sons within a month; now I find myself writing everything other than those darned chapters! Including plugins. اس کے بارے میں سوچنا آ, writing those chapters wouldn’t be any less geeky, گے یہ?

That made me wonder… We all started off as geeks, didn’t we? No use denying it. Remember how our teachers loved us, and the sexy cheerleaders, اچھی طرح سے, didn’t? Later in life, due to exigencies of circumstances, we may have tried to lose our techie halo and simulate a managerial posture. لیکن, in our moments of panic, we go back to our geek roots. کم از کم, مجھے کیا کرنا.

You think you don’t? ٹھیک ہے, check out these geek jokes. If you find them funny, chances are your roots are not too different from mine.

Heisenberg was driving down the highway when he was pulled over for speeding. The officer says, “Do you know how fast you were going?” Heisenberg says, “نہیں, but I do know where I am!”

Two Hydrogen atoms walk into a bar. One says, “I’ve lost my electron!” The other says, “Are you sure?” The first replies, “جی ہاں, I’m positive…”

Geek Pickup Lines:

  • Tell me of this thing you humans call [dramatic pause] love.
  • If you turn me down now, I will become more drunk than you can possibly imagine.
  • They don’t call me Bones because I’m a doctor.
  • Your name is Leslie? دیکھو, I can spell your name on my calculator!
  • What’s a nice girl like you doing in a wretched hive of scum and villainy like this?
  • You must be Windows 95 because you got me so unstable.
  • My ‘up-time’ is better than BSD.
  • I can tell by your emoticons that you’re looking for some company.
  • Is that an iPod mini in your pocket or are you just happy to see me.
  • Want to see my Red Hat?
  • If you won’t let me buy you a drink, at least let me fix your laptop.
  • You had me at “Hello World.”
  • Mind if I run a sniffer to see if your ports are open?
  • You make me want to upgrade my Tivo.
  • By looking at you I can tell you’re 36-25-36, which by the way are all perfect squares.
  • Jedi Mind Trick: “This is the geek you’re looking for.” [Waves hand]
  • You can put a Trojan on my Hard Drive anytime.
  • Have you ever Googled yourself?
  • How about we do a little peer-to-peer saliva swapping?
  • With my IQ and your body we could begin a race of genetic superchildren to conquer the earth.
  • What’s a girl like you doing in a place like this when there’s a Farscape marathon on right now on the Sci Fi channel.
  • I’m attracted to you so strongly, scientists will have to develop a fifth fundamental force.

What Makes 100%?

What does it mean to give MORE than 100%? Ever wonder about those people who say they are giving more than 100%? We have all been to those meetings where someone wants you to give over 100%. How about achieving 103%? What makes up 100% in life? Here’s a little mathematical formula that might help you answer these questions:

تو:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z are represented as:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

then H-A-R-D-W-O-R-K = 8+1+18+4+23+15+18+11 = 98%

and K-N-O-W-L-E-D-G-E = 11+14+15+23+12+5+4+7+5 = 96%

but A-T-T-I-T-U-D-E = 1+20+20+9+20+21+4+5 = 100%

and B-U-L-L-S-H-I-T = 2+21+12+12+19+8+9+20 = 103%

but look how far ass kissing will take you.

A-S-S-K-I-S-S-I-N-G = 1+19+19+11+9+19+19+9+14+7 = 118%

تو, one can conclude with mathematical certainty that While Hard work and Knowledge will get you close, and Attitude will get you there, it’s the Bullshit and Ass kissing that will put you over the top.