How to archive/zip folder on your server

This might not be the best code for this, yet its the most concise code I found that doesnt require a bunch of additional classes.  I found this online dont remember where and I added a few lines cause of errors.  If you get memory errors you can increase the memory (ini_set(‘memory_limit’, ‘300M’).

<?php
ini_set(‘memory_limit’, ‘300M’);
$archive = ‘zipbackup.zip’; // File Name ;
$source = ‘wp-content/gallery/’; // Path To the folder;
$destination = ‘zipbackup.zip’; // Path to the file and file name ;
$include_dir = false;

if(file_exists($destination)) {
unlink($destination);
}
ob_start();

if (!extension_loaded(‘zip’) || !file_exists($source)) {
return false;
}

if (file_exists($destination)) {
unlink ($destination);
}

$zip = new ZipArchive;

if (!$zip->open($archive, ZipArchive::CREATE)) {
return false;
}
$source = str_replace(‘\\’, ‘/’, realpath($source));
if (is_dir($source) === true)
{

$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);

if ($include_dir) {

$arr = explode(“/”,$source);
$maindir = $arr[count($arr)- 1];

$source = “”;
for ($i=0; $i < count($arr) – 1; $i++) {
$source .= ‘/’ . $arr[$i];
}

$source = substr($source, 1);

$zip->addEmptyDir($maindir);

}

foreach ($files as $file)
{
$file = str_replace(‘\\’, ‘/’, $file);

// Ignore “.” and “..” folders
if( in_array(substr($file, strrpos($file, ‘/’)+1), array(‘.’, ‘..’)) )
continue;

$file = realpath($file);

if (is_dir($file) === true)
{
$zip->addEmptyDir(str_replace($source . ‘/’, ”, $file . ‘/’));
//echo “added directory: ” . $file . “<br>”;
}
else if (is_file($file) === true)
{
$zip->addFromString(str_replace($source . ‘/’, ”, $file), file_get_contents($file));
//echo “added image: ” . $file . “<br>”;
}
}
}
else if (is_file($source) === true)
{
$zip->addFromString(basename($source), file_get_contents($source));
}
$zip->close();

echo ‘ location.replace(“backup.zip”); ‘; //name of zip here
?>

How to rename nggallery folders

Ok so if you were in a hurry to set up your wordpress site and didnt pay much attention to the folder structure of the nggalleries, then you might want to rename them and possibly keep a backup copy.

To do this you will ftp into your wp-content/gallery folder, (make a backup copy first) and then rename the folder.  Keep track of what you are fixing.  Then change the path in the nggallery > manage gallery tab, selecting the same gallery.

rename

Then one step often missed is to clear the nggallery cache, in nggallery > other options tab.

clear

Add NGGallery gallery previewpic, title, desc and info to any page via php

Was having a difficult time finding the code for this as many people have different code.  I figure it should be real simple as the fields are provided in each gallery to add a title, desc, previewpic, and other info.  The issue is that many are using $nggdb->get_gallery.   The answer is to use $nggdb->find_gallery.  You will need to know the gallery id.  You can then get info for the previewpic using $nggdb->find_image.  This is the code for both:

<?php

global $nggdb;

$galleryID = 22; // add image id here

$gallery = $nggdb->find_gallery($galleryID);

echo “gallery id: ” . $gallery->gid . “<br>”;
echo “gallery name: ” . $gallery->name . “<br>”;
echo “gallery slug: ” . $gallery->slug . “<br>”;
echo “gallery path: ” . $gallery->path . “<br>”;
echo “gallery title: ” . $gallery->title . “<br>”;
echo “gallery desc: ” . $gallery->galdesc . “<br>”;
echo “gallery page linked id: ” . $gallery->pageid . “<br>”;
echo “gallery preview image id: ” . $gallery->previewpic . “<br>”;
echo “gallery author: ” . $gallery->author . “<br>”;

$previewimg = $gallery->previewpic;
echo “preview image is ” . $previewimg . “<br><br>”;

$detail = $nggdb->find_image($previewimg);

echo “<br><br>”;
echo “url: “;
echo $detail->imageURL;
echo “<br>”;
echo “title: “;
echo $detail->description;
echo “<br>”;
echo “alttext: “;
echo $detail->alttext;
echo “<br>”;
echo “thumbURL: “;
echo $detail->thumbURL;

?>

if you need more info about the image you see all available fields with this code:

<?php
echo “<pre>”;
var_dump($detail);
echo “</pre>”;
?>

 

 

 

How to fix a mac exfat formatted disk

If you have a mac, you might format an external disk in the exfat format to make it compatible with mac and windows.  This formatting for a hard drive disk is available in the disk utility app in the Applications > Utilities.

Now, if for some reason your disk is acting up, because you might have unplugged it while it was transferring a file or instead of ejecting the hard drive disk (by selecting it and right clicking eject), there is a way to fix it with these steps:

  1. find the terminal app in Applications > Utilities > Terminal.app and launch it (by double clicking it).
  2. at the flashing character prompt, type “diskutil list” and return key.
  3. then look for your disk in the list, you will probably recognize it from the gigabytes size and it will probably say something like “Windows_NTFS”.  find the disk “IDENTIFIER” name and copy it down.
  4. type the following line replacing the disk identifier with your disk name identifier:sudo fsck_exfat -d disk1s1
  5. it might say that your disk is busy.  keep trying until you see it start to name off all the files on the disk.  this could take a while, but take a breath cause you saved your disk drive.
  6. after its finished repairing, your disk will work as before.  you can then close the terminal app. bravo!

How to log visits with php

There is a lot of insight available when logging traffic to your website.  There are sometimes people trying to log into your wp admin and you can see that traffic and block it with htaccess.  Also you can see what keywords are being used to arrive at your site.  These keywords you can use to then create dedicated pages to boost seo.  Be sure to set your timezone.  Be sure to fix the apostrophes once you copy to php.  This code will create a new .csv doc for each day.

<?php

date_default_timezone_set(‘America/Los_Angeles’);
$today = date(“m-d-y g:ia”);
$logData = $_SERVER[‘REMOTE_ADDR’] . “,” .
$today . “,” .
$_SERVER[‘REQUEST_METHOD’] . “,” .
$_SERVER[‘REQUEST_URI’] . “,” .
$_SERVER[‘HTTP_REFERER’] . “,” .
$_SERVER[‘HTTP_USER_AGENT’];
$file = “folder/“ . date(“m-d-y”) . “.csv”;
$fp = fopen($file,”a”);
fwrite($fp,”$logData\n”);
fclose($fp);
?>

Fixed Error Warning: Division by zero in nggallery scroll

replace 287-302 with this…the issue is that $picture[“width”] and $picture[“height”] are not returning values :

if($adjustImagesize==true){
$imgsize = @getimagesize($picture[“img”]);//0=width 1=height
$imgwidth = $imgsize[0];
$imgheight = $imgsize[1];
//$imgwidth = $picture[“width”];
//$imgheight = $picture[“height”];
if($width>$height){//landscape
//get new size
$newimageheight=$imgheight;
$newimagewidth=($imgwidth/$imgheight)*$newimageheight;
//check ob passt, sonst weiter verkleinern
if($newimagewidth>$width){
$newimagewidth2=$width;
$newimageheight=($newimageheight/$newimagewidth)*$newimagewidth2;
$newimagewidth=$newimagewidth2;
}

 

Sendpress and WPDB

If your sending out a newsletter and you run out of relays, there seems to be no simple way to reset the queue in sendpress. It takes forever to press each email to reset queue. So we can make a php page that will access the wpdb and do a queue reset. Its very simple page. As an added protection, it will only work if your signed in as admin to wordpress. Also if you want to do more wordpress database queries, just take note of the code and adjust accordingly.  More about WP Database at http://codex.wordpress.org/Class_Reference/wpdb .

Copy/paste the text into a text document and save with the .php extension. Also make sure the wp-load.php path is correct. If you have wordpress in another folder it will be:
require(‘foldername/wp-load.php’);

 

sendpress_reset.pdf

Jcart and Authorize.net

This is an updated version. Allows Jcart to work with Paypal and SIM Authorize.net. Good idea to validate pricing in auth_gateway.php via database. Use at your own risk.

Read documentation on jcarts website. Make sure you have an account with Authorize.net. Set your Login-ID and transaction key in the auth_gateway.php file. File paths in config.php. Paypal ID in config.php.

The info I have changed was in jcart.php, config.php, and the new gateway file: auth_gateway.php for adding the  Authorize option.  Also the variables for the cart all start with x and have underscores instead of the dash.

The Authorize url is set in testing mode.  Uncomment the non-testing mode url and comment the testing url when your cart goes live.

You can download it at google drive:

jcart folder

Featured image for Wp Geo Map Mashup

Here is the code to use featured images on maps.  Works with custom content type manager.  You can use wp_query to add more elements to the query.  Specify your post type then add this to functions:

function my_wpgeo_markers( $markers ) {
$custom = new WP_Query();
$custom->query(‘post_type=custom_post_type_name&posts_per_page=-1’);
$i = 1;
while ($custom->have_posts()) : $custom->the_post();
$title = get_the_title();
$content = get_the_content();
$slug = basename(get_permalink());
$slug = str_replace(“-“, “_”, $slug);
$post_id = get_the_ID();
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ‘thumbnail’ );
$url = $thumb[‘0’];
$thumb_shadow = “add_image_here.png”;

$imageurl = get_post_meta( $post_id, ‘first_gallery_image_meta_box’, TRUE );

$markers[$i] = new WPGeo_Marker(
$slug, // custom post slug
$title, // readable marker text
$content, // info text
30, 30, 10, 34, // width, height, anchorx, anchor y
$url, //image url
$thumb_shadow //image shadow
);

$i++;
endwhile;
return $markers;
}
add_action( ‘wpgeo_markers’, ‘my_wpgeo_markers’ );


If any content is missing the code will break so you might want to include if statements if fields are empty within the function.
ie:
if ($url == “”) {
$url = “default_image_link.png
}


Here is the code for the template page: