TinyMCE File Manager

This tutorial will show you how to take the media manager from WordPress and use it on an external page with a stock version of TinyMCE. I saw some posts about this and people were calling the WordPress editor to achieve this. Its an option, but it is not what this guide is for. If you have downloaded a standard version of TinyMCE and want the be able to browse and upload images using the WordPress media manager then this guide will show you how to do it. There are several file managers for TinyMCE, all which work perfectly fine. I have always found the WordPress media manager to be very powerful and easy to use. Unfortunately its part of WordPress and cant be downloaded on its own. Thankfully I have been able to find a way to use the media uploader within TinyMCE a lot more easy than i though. Here is how to use WordPress media manager with TinyMCE.

The first thing you will need to do is be able to load up the WordPress media manager on the page you are using. This means you need to either load the core of WordPress or just call the media method from WP. The following code will load the WordPress core and que all of the files you need to be able to call the media manager.

The next thing to do is create a javascript function that will load up the WordPress media manager. The following function will do this and will then return the selected image to the instance of TinyMCE that triggered it. The reason for this, is you may have more than one instance of TinyMCE on the page and you want to make sure you return data to the correct one.

You can test if the function works by calling it using a href. The final step to do is to link this function in with the init of TinyMCE. The following code is all you need

This variable in the TinyMCE init will tell the app that you are using a file manager and to call a function called “wpmediabrowser” when the browse button is clicked. When you select the image from the WordPress file manager it will return the image url back into the box.

When pulling comments from a database table, it can be very costly when you are performing a query that will automatically sort all of the comments into the parent child hierarchy. Every extra ms your SQL server spends performing calculations is time that is wasted. If you can easily move this logic to the programming language that you are using it will free up your DB server to serve more data. If you have a blog post that has comments, obtaining the comments from the DB for this post is a simple process, but the problem is that the order of the comments will not be right. If someone replies to the first comment days after lots of other comments have been made, this comment will show up at the end of the list returned from the DB. There are ways in which you can construct your query so that it will return an array of child comments for each comment, but this is way too wasteful. Using a simple recursive method you can sort out the comments using a programming language so as not to lock up your DB server any longer.

A simple SQL query like this is going to pull some comments from a database table that is storing comments for a blog post.

This query now leaves you with a list of comments that are a mix of parent and child comments are not in order. This seems a bit messy and can be a daunting problem to solve, but look at how simple that SQL query is. It is worth the effort when your DB server has very little to do to sort the comments. We are going to start this by creating the recursive function. A recursive function is a function that calls itself many times. The following function is written in PHP, but can be easily translated to any other programming languages.

This function accepts 2 parameters. The parent ID which is the Id of the comment that we want to get the child comments for, and then it contains the full list of all comments that were returned from the database query. When you want to see if a comment has children, you will loop through all of the comments checking to see if any of the comments have a parent ID that is equal to the current comment. Once we find a match we first need to check and make sure that this child comment doesn’t also have child comments,. This is why we use a recursive method. We cant tell how many comments have replies and how deep they go. This way we can do it without needing to know. Once we have checked for more child comments we can add this child comment to an array of child comments for the current comment we are checking.

The only thing left to do now is to determine how to set it off. We need a way to call this method and restart the recursive loop. Here is a completed method that will show you how to pull them from the database and then how to trigger the calling of the recursive loop.

 

Setting up a redirect using Apache is quite simple, but getting it to work with dynamic URLs can be a lot more difficult. Lets say you want to redirect all traffic from one file to another file in a different location/server. How do you perform this redirect while keeping all of the url variables intact? I have seen some many answers from people that suggest you use a mod rewrite matching method that has all sorts of complicated matching parameters that make it almost impossible to convert that answer into a solution that works for you. This solution is far more simple and will work for most instances without needing to be heavily modified.

In order to setup this redirect you will need to add some code to the .htaccess file of your website. This file can usually be found in the root directory of your website. It is more efficient to use your htaccess file when compared to using PHP. When you use PHP, Apache will need to call it and then PHP does the work. It might be easier to work with PHP, but doing the job with Apache cuts out the work the server has to do. The following piece of code will perform a simple redirect from a file in one server to a file on a different server/subdomain.

It’s as simple as that. By putting the $1 at the end, it is telling apache to match a url that starts “script1.php” and treat everything after this as a variable, when performing the redirect, put all of this content at the end of the new URL. If your files are inside a sub folder you can easily add this onto the first part of the redirect match.

This is a much cleaner and simple method of performing a redirect for a single file while keeping all of the URL variables in place.

Sometimes you get hit with a load capacity issue that you may have not expected. For example, you have created a site with multiple scripts and these scripts are now being accessed so much that the one server isn’t able to cope with all of the traffic. Rather than spending a fortune setting up fancy hadoop cluster, you can simply setup subdomains. For example if you moved http://website.com/scripts/script1.php to http://scriptserver1.website.com/scripts/script1.php you could better balance the load across multiple servers and use DNS records to change where it is pointing. Setting the subdomains up is simple, but the problem is how do you setup a redirect on the old server that will push all traffic to the new url? You could use PHP, but why not let Apache do the job instead of bringing PHP into the mix.

Using the .htaccess file in the root directory of your website you can make Apache redirect

If you are using a script that required some extra variables you can instead use the RedirectMatch method instead. This will allow you to perform the same redirect above where you will redirect a file from one location and send it to a file in a different location. The only difference here is that any url variables will be passed along with the redirect. For example, if your original URL contained something like script1.php?foo=123&bar=123454. All of the information after the ? would also be passed along to the new script.

 

By default, most instillation of Centos will end up having the default protocol set to be dynamic (DHCP) for obtaining the IP address. For a web server this is not what we want as it will be no good having the IP change and then having to change DHCP records to correctly point to the new IP address. This tutorial will show you how to change the IP protocol for a Centos 7 OS to use a static IP instead of a dynamic IP.

Start by navigating to the directory that contains the IP config files.

You should get a list of files that are inside this directory. Most of the time there will be a file named “ifcfg-eth0”, but its not always the case. The name may vary, but it will always begin with “ifcfg”. When you are looking at the results have a look and see what files are in this directory that begin with “ifcfg” and work from there.

Once you have found the correct file you will see that there is a variable near the top of the file called “BOOTPROTO”. This will be set to “dhcp” this needs to be changed to be static. You will then need to go to the bottom of the file and alter or add some values for the network information. Your file should look like the file below once you have finished. (be sure to replace the placeholder info with actual IP information).

If you are in a situation where you have no access to the machine other than command line, you will need to use VI to edit the file. Once you have a static IP you should be able to connect to the machine using SFTP and modify the file using a text editor.

Once you have made edits to the file, you will need to restart the networking on the server. The following command will restart the networking and should now allow you to access the server using the static IP that you have defined.

 

There are many different ways to get the IP of the current server on linux machines which causes a lot of conflict across the different variations. Not all operating systems use the same command and sometimes the command used is not built in as part of the operating system. If you are running the minimal install of Centos 7 you will find that the standard command “ifconfig” does not exist. You could install this if you wish, but there are methods to obtain this using the tools you have available already. There are 2 possible ways to get the IP address.

This will dump out quite a bit of info, the import part being the IP address of the server. This can be a bit messy, but is a more reliable method of obtaining the servers IP. If you want a quick an easy way of finding out what it is, you can run the following command to display just the IP. This is not as reliable and will sometimes return a blank value for a server that has not been configured correctly.

 

Most people start blogging and get excited about the fact that you can actually make real money just from putting a few ads on your blog. This then leads to the main reason that ad-blocker and other ad blocking software has become so popular. When people to choose to monetize their blogs they seem to think that more ads means more money. This is true, but it is not now you monetize your blog efficiently and is exactly how you can trigger the downfall of your website. People do not want to visit your site and have to dig through layers of adverts in order to find the content they came for. Yes you may get a nice amount of money per visit, but over time the visits will slowly decrease until your site gets no visitors. Knowing how to effectively monetize a site with ads will save you a lot of heartache and is not as difficult as it seems. Sites like answers.com have become the most horrible websites on the web, you don’t want to become another site like this.

The first rule when running a site is never assume that your site is so good that people are going to flock from far and wide to view it. Unless you have a really particular talent or skill that is not something many people can do, chances are the content you post on your website can be found in several other places. In order to make your site work well, is to build a better user experience. If a user comes to your site and is plagued ad every corner with ads, the user will not enjoy their experience, and will likely avoid engaging with your site any further. A click from a search engine is like a fish biting a worm, you don’t want the fish to grab the worm and leave without biting the hook. You need to make the presentation as appealing as possible. If your site is better than other sites, you will get more traffic. More traffic means more ad impressions and more money for you. As always, never take advantage of the traffic by adding more ads. Make it look natural and never shove ads in visitors faces. More visitors will come if your site is good and this is how you get more ad impressions. Never sell out! Perseverance is the only way to make a successful website.

With everything that I have said above you are likely asking yourself, how many ads is too many and where should i place them. This is a very subjective question and there is no general answer that will cover all website, but here are a few things you should know to reduce the chance of making any mistakes.

Don’t bunch ads together

There is no point putting several ads all in the same location. Cluttered adverts look ugly, and usually cause the user not to look at this area of the page because they know its all ugly spam.

Don’t slow down page load speed

Adsense may be one of the most popular ad networks, but it is also one of the slowest. From experience i have seen each adsense advert add up to 1 second to the page load. Even when you use async ads, the page still is not considered loaded and it can make the users browser run very slow if they are not using a powerful device. Every ad you add to a page means more processing and more delay it takes to load the page.

Blend ads in with content 

Putting ads in obvious locations with big flashy banners is exactly what most people have trained their eyes to ignore. You need to merge your ads in with the content. Never put more than 1 ad in the body of an article. Putting it near the upper 3rd of an article is usually the best place to put your ads.

Consider Mobile

Sidebars are a popular and often effective location to place adverts, but these do not work for mobile sites. If you have a responsive site, chances are the sidebar gets moved to the very bottom of the page when viewed on mobile. If you have all your ads here or a large number of them on the sidebar, it will slow down the page and a large amount of visitors will never go down to this part of the page and never see these ads.

Users don’t need to see an ad on every page

When placing ads people often set it up in a way so that a user will see an advert on screen no matter what part of the website they are currently looking at. There is no need for this. A user is here to view your website, this is more valuable than the couple of cents you get from a user clicking the ad. Don’t make a user leave your site for a couple of cents. It can also make users dislike your site. They don’t want to feel like they are subject to a plague of adverts. Subtle advertising works far better than in your face. If a user visits one page and sees the same add 10 times all they will remember is that the website sucks. If they visit 10 pages and see the same add once, they will subconsciously remember the ad. This doesn’t benefit you, but it does benefit your long term income since you can guarantee effective advertising.

Don’t use popups for ads

If you want to use a popup for your newsletter then go ahead, but use a cookie to make sure it doesn’t keep popping up every time the user visits the site. Making ads pop up or even pop under are horrible intrusions to the user experience. They make you quick money and also make your site look bad. If you are running a viral site that has a 100% bounce rate then do what you wish, but if you want to run a proper website, don’t do this. It makes your site cheap and will push users away.

Anyone who has ever run a blog will have encountered at least 1 of the 2 common guest blogging scenarios for boosting SEO. The most common scenario is when a site owner gets contacted by someone claiming to work for a marketing agency. They “love” your blog and would like to post an article on it, sometimes they may even offer to pay you money to do it. This is enough to get any small site owner excited, its almost like a triple win. Someone likes your blog, they want to give you easy money and you get extra content for your blog without doing any work. Like anything else in live, if it sounds too good to be true, it probably is. The question you need to ask yourself is “what do they get out of this?”. The answer is quite simple, but isn’t something a lot of people know if they aren’t fully familiar with how SEO and Google works.

One of the many different ways that Google considers the value of a website is to check how many websites link to your website. Think of it in the real world. If the CEO of Microsoft says that your tech blog is the best site ever it will really hold a lot of weight, now if a junkie down an alley says the same, his opinion isn’t worth as much. The same goes for websites. When a site links to your website it’s like that website saying that your website is worth visiting. It is of course very hard to make high profile sites link to a website, so often people will pay a bunch of small websites to give them a referral. This is a very common practice and is accepted by Google, but you need to remember is that Google is very smart and can often tell when the link is genuine.

If you have a blog that is all about cooking and in the middle you get paid to place a link to a casino website. Casinos have nothing to do with your niche and 99% of the time these articles will either sneak the link in or blatantly promote it with something like “While you enjoy this meal, why not checkout this online blackjack”. You are really just providing a backlink and wrapping it up in an article. Google consider this spam and if you get caught it could generate penalty toward your website. There is a line between a spammy guest post and a genuine one and you need to be able to identify them. If you run a site dedicated to movies, and a small indie movie producer asks you to promote his upcoming movie with a link then by all means do so if you want. The niche matches and it’s a genuine request. You need to determine why they want the link. If it’s to promote a new product or help boost their business, then there is nothing wrong with this. If you personally think its worthwhile for your readers then its all good. If the purpose of the link is to increase the websites SEO performance and increase search engine results, then stay well away. The small amount of money you get from these links isn’t going to be worth loosing your entire website. It’s pretty much impossible to build a successful website these days if the site doesn’t show up in search engine results.

This tutorial will show you how to programmatically create a subsite in Sharepoint. This can be done a few different ways and if you have server access you may prefer to do this on the server side, but you can just as easily create one using the Client-Side Object Model.

You can do this using a standard C# console application. For this example I used Visual Studio 2013 with .NET 4.0. You will need to include 2 assemblies in order for the code to work.

If this code throws an error then you will need to add the reference to your project. For me, I was not able to find Microsoft.Sharepoint but when I added the .client assembly it worked.

Thats it! The code above is all you need to create a new subsite. If you make a mistake and want to change it, you can also do this quite easy using similar code. You can modify pretty much everything on a subsite, but the URL becomes read only so you cannot change this once it has been set.

This is all you need to be able to add a subsite and to be able to edit it.

File downloads can be a bit of a nuance sometimes as web browsers often support a lot of document types. Simply adding the file path to the href of a html element, wont be enough for you to be able to download the file. There are dozens of work arounds to make this work, but using an ASP.NET ashx handler is definitely one of the cleanest methods to do it using code.

I will paste the contents of the entire ashx file below as the script is very simple. This solution will only work if you are using the non razor MVC models that are part of the ASP.NET framework. First you will need to create a new “Generic Handler” this will create a file with a .ashx extension. Once this is done you can point all of your links to this page when you want to download a file. There are many ways you can direct the downloads to this page. To keep things very simple, I have setup the script to accept the file path in the URL of the request.

In order to make the request work you will need to urlencode the value that is being passed into the url. The following code will be all you need to setup the url.

You could alternatively use javascript or pretty much anything that is capable of generating a request to your download script. This method has massive security risks, so please take this into consideration. This code will be enough to get a working prototype for you to built upon. This should never be used in any public facing code without some security measures being implemented to stop people tampering with the URL.