Posts Tagged ‘php’
Thursday, March 24th, 2011
In today’s tutorial we show you one way of displaying a list of the most popular posts in your WordPress template or sidebar. To do this you must first set up your site to use Google Analytics and make sure you’ve placed the code snippet in your theme’s footer.php. Next install the “Google Analytics Dashboard” plugin which can be found here:
http://wordpress.org/extend/plugins/google-analytics-dashboard/
We tested this with version 2.0.3 of the Google Analytics Dashboard wordpress plugin.
<?php
// options
$showposts = 3; // how many posts/pages to display?
$days = 30; // how many days back to calculate?
// do not edit below this line
$thispost = 1;
$start = date('Y-m-d', (time() - (60 * 60 * 24 * $days)));
$end = date('Y-m-d');
$login = new GADWidgetData(get_option('gad_auth_token'), get_option('gad_account_id'));
$ga = new GALib('client', $login->auth_token, '', '', $login->account_id);
$pages = $ga->pages_for_date_period($start, $end);
echo "<ul>";
foreach($pages as $page) {
$url = $page['value'];
$title = $page['children']['value'];
// ignore these page titles
$ignore = array(
'(not set)',
'Page Title 1',
'Page Title 2'
);
if(!in_array($title, $ignore)){
// list any strings you would like to remove from the titles
$remove = array(
" | Company Name",
" « Company Name"
);
$newtitle = str_replace($remove, "", $title);
echo '<li><a href="' . $url . '" rel="nofollow">' . $newtitle . '</a></li>';
$thispost++;
}
if($thispost > $showposts) break;
}
echo "</ul>";
?>
Tags: google, Google Analytics, html, php, Popular Posts, seo, web, web design, web development, web standards, web usability, website design, wordpress, wordpress plugins
Posted in PHP Tutorials, Tutorials, Web Design Tutorials, Wordpress Tutorials | 6 Comments »
Monday, April 12th, 2010
Using examples from Troy Wolf’s website, I’ve created a PHP script that will get Tasks for a user in Microsoft Exchange and create an ICS format calendar which can then be loaded (read only) into Mozilla Thunderbird.
<?php
require_once("class_http.php");
require_once("class_xml.php");
$exchange_server = "http://exchange.yourwebsite.com"; // no trailing slash
$exchange_username = "";
$exchange_password = "";
$h = new http();
$h->headers["Content-Type"] = 'text/xml; charset="UTF-8"';
$h->headers["Depth"] = "0";
$h->headers["Translate"] = "f";
$h->xmlrequest = '<?xml version="1.0"?>';
$h->xmlrequest .= <<<end
<g:searchrequest xmlns:g="DAV:">
<g:sql> SELECT "DAV:id" AS uid,
"DAV:href" AS url,
"DAV:creationdate" AS created,
"urn:schemas:httpmail:subject",
"urn:schemas:httpmail:textdescription",
"urn:schemas:calendar:location" AS location,
"http://schemas.microsoft.com/mapi/id/{00062003-0000-0000-C000-000000000046}/0x811c" AS completed,
"http://schemas.microsoft.com/mapi/id/{00062003-0000-0000-C000-000000000046}/0x00008105" AS duedate,
"http://schemas.microsoft.com/mapi/id/{00062003-0000-0000-C000-000000000046}/0x00008104" AS start
FROM Scope('SHALLOW TRAVERSAL OF "/exchange/$exchange_username/Tasks"')
WHERE "DAV:contentclass" = 'urn:content-classes:task'
AND CAST("http://schemas.microsoft.com/mapi/id/{00062003-0000-0000-C000-000000000046}/0x811c" AS "boolean") = CAST(false AS "boolean")
ORDER BY "DAV:creationdate" DESC
</g:sql>
</g:searchrequest>
END;
if (!$h->fetch($exchange_server."/exchange/$exchange_username/Tasks", 0, null, $exchange_username, $exchange_password, "SEARCH")) {
exit();
}
$x = new xml();
if (!$x->fetch($h->body)) {
exit();
}
function format_time($date_string) {
$date = str_replace("-", "", $date_string);
$date = str_replace(":", "", $date);
$date = substr($date, 0, -5);
return $date;
}
function format_time_z($date_string) {
$date = str_replace("-", "", $date_string);
//$date = str_replace(".000Z", "Z", $date);
$date = str_replace(":", "", $date);
$date = substr($date, 0, -5);
return $date."Z";
}
header("Content-Type: text/x-vCalendar");
header("Content-Disposition: inline; filename=tasks.ics");
echo "BEGIN:VCALENDAR\n";
echo "VERSION:2.0\n";
echo "PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN\n";
echo "METHOD:PUBLISH\n";
echo "BEGIN:VTIMEZONE\n";
echo "TZID:America/New_York\n";
echo "X-LIC-LOCATION:America/New_York\n";
echo "BEGIN:DAYLIGHT\n";
echo "TZOFFSETFROM:-0500\n";
echo "TZOFFSETTO:-0400\n";
echo "TZNAME:EDT\n";
echo "DTSTART:19700308T020000\n";
echo "RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3\n";
echo "END:DAYLIGHT\n";
echo "BEGIN:STANDARD\n";
echo "TZOFFSETFROM:-0400\n";
echo "TZOFFSETTO:-0500\n";
echo "TZNAME:EST\n";
echo "DTSTART:19701101T020000\n";
echo "RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11\n";
echo "END:STANDARD\n";
echo "END:VTIMEZONE\n";
foreach($x->data->A_MULTISTATUS[0]->A_RESPONSE as $num => $event) {
$UID = $event->A_PROPSTAT[0]->A_PROP[0]->UID[0]->_text;
$SUMMARY = $event->A_PROPSTAT[0]->A_PROP[0]->D_SUBJECT[0]->_text;
$DESCRIPTION = $event->A_PROPSTAT[0]->A_PROP[0]->D_TEXTDESCRIPTION[0]->_text;
$CREATED = format_time_z($event->A_PROPSTAT[0]->A_PROP[0]->CREATED[0]->_text);
$STAMP = format_time_z($event->A_PROPSTAT[0]->A_PROP[0]->START[0]->_text);
$START = format_time($event->A_PROPSTAT[0]->A_PROP[0]->START[0]->_text);
$DUE = format_time($event->A_PROPSTAT[0]->A_PROP[0]->DUEDATE[0]->_text);
$COMPLETED = $event->A_PROPSTAT[0]->A_PROP[0]->COMPLETED[0]->_text;
echo "BEGIN:VTODO\n";
echo "CREATED:$CREATED\n";
echo "LAST-MODIFIED:$START\n";
echo "SUMMARY:$SUMMARY\n";
echo "DTSTAMP:$START\n";
echo "UID:$UID\n";
echo "SUMMARY:$SUMMARY\n";
echo "DTSTART;TZID=America/New_York:$START\n";
echo "DUE;TZID=America/New_York:$DUE\n";
# echo "X-MOZ-GENERATION:2\n";
# echo "DESCRIPTION:$DESCRIPTION\n";
echo "END:VTODO\n";
#var_dump($x); break; die();
}
echo "END:VCALENDAR";
// You can print out the response to help troubleshoot.
?>
Tags: caldav, calendar, exchange, ical, ics, microsoft, php, webdav
Posted in PHP Tutorials, Tutorials, Web Design Tutorials | No Comments »