Skip to content

Instantly share code, notes, and snippets.

View scarstens's full-sized avatar
🌟
Automating workflows.

Seth Carstens scarstens

🌟
Automating workflows.
View GitHub Profile
@scarstens
scarstens / facebook.comments.builder.php
Created October 10, 2012 21:23
Facebook Comments for SEO
<?php
// displays some comments for a certain url
$url = 'http://developers.facebook.com/docs/reference/fql/comment/';
// fql multiquery to fetch all the data we need to display in one go
$queries = array('q1' => 'select post_fbid, fromid, object_id, text, time from comment where object_id in (select comments_fbid from link_stat where url ="'.$url.'")',
'q2' => 'select post_fbid, fromid, object_id, text, time from comment where object_id in (select post_fbid from #q1)',
'q3' => 'select name, id, url, pic_square from profile where id in (select fromid from #q1) or id in (select fromid from #q2)',
);
@scarstens
scarstens / day_between_dates_and_utilities.inc.php
Created November 30, 2012 01:44
Days and Dates Calculation Functions
//pass the function the MySQL standardized date and retreive a date relative to wordpress GMT and wordpress date and time display options
if(!function_exists('sm_display_date')) { function sm_display_date($mysqldate) {
$display_date = date_i18n( get_option('date_format').' '.get_option('time_format'),strtotime($mysqldate), get_option('gmt_offset') );
return $display_date;
}}
//pass the function a UNIX TIMESTAMP or "Properly Formated Date/Time" and retreive a date formated for MySQL database date field type
//optionally pass a number of days to return a time XX days before or after the date/time sent
if(!function_exists('sm_mysql_date')) { function sm_mysql_date($time, $days = 0) {
$seconds = 60*60*24*$days;
@scarstens
scarstens / process-wp-image-uploads.php
Last active December 12, 2015 08:18
Process WordPress image uploads
// now upload the new images
$postvals = cp_process_new_image($_POST['ad_id']);
// associate the already uploaded images to the ad and create multiple image sizes
$attach_id = cp_associate_images($_POST['ad_id'], $postvals['attachment']);
//process each image thats being uploaded
function cp_process_new_image() {
global $wpdb;
$postvals = '';
@scarstens
scarstens / wpfilebase.metasetter.jquery.js
Created April 2, 2013 23:09
Jquery code to use in chrome conolse to automaticly assign and submit a category and meta data selection to wpfilebase plugin since there is no bulk update tool.
jQuery('#file_category').val(4); jQuery('#file_languages\\[\\]').val('en'); jQuery('#file_requirements\\[\\]').val('pdfread');jQuery('#updatefile').submit();
@scarstens
scarstens / wordpress.enable_child_page_templates.php
Last active December 16, 2015 14:28
This is a WordPress function that will extend the "template heirarchy" so that you can also load child pages in your theme using the following syntax: page-{PARENTSLUG}-child-{CHILDSLUG}.php
<?php
//apparently no need for this... page-SLUG.php matches subpage slugs,
//only need this function if subpage slug conflicts occur
//Add this code to you themes functions.php file, or some other file.
//Next create your child page lets says "domain.com/resources/faq"
//Finally, create the php template page following the naming schema:
//page-PARENTSLUG-child-CHILDSLUG.php -> page-resources-child-faq.php
add_filter( 'page_template', 'enable_child_page_templates' );
function enable_child_page_templates( $page_template ){
@scarstens
scarstens / php-class-file-based-password-encryption.example.php
Last active December 16, 2015 17:29
This is the example I built while learning how to properly protect password before they are stored in the database. While hashing passwords is safer, some passwords are used for "3rd party tools" and therefore can't be hashed because they need to be "unencrypted" and sent to the 3rd party service. In my case, we were building an connector betwee…
<?php
//This example encrypts and decrypts a password
//it is a good use case for a "php class file" because the __FILE__ is constant for the key
//*additional security can be added by storing or defining a unique key per website
//using __FILE__ exmaple for class files
$pass = 'samplepassword123!';
echo 'Password: '.$pass.'<br />';
$encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, sha1(basename(__FILE__), TRUE), $pass, MCRYPT_MODE_ECB);
echo 'Encrypted Pass: '.$encrypted.'<br />';
@scarstens
scarstens / jquery-trigger-event-every-x-seconds.js
Created May 16, 2013 21:10
Use jquery to trigger an event every XX amount of seconds. In this example we will trigger the click event on the "increment" ID.
/* WE ARE ASSUMING JQUERY IS LOADED AND USING jQuery instead of $ */
jQuery(document).ready(function($) {
window.setInterval(function(){
/// call your function here
$('#increment').trigger('click');
}, 5000);
});
/*
<apex:page standardStylesheets="false" showHeader="false" sidebar="false">
<apex:stylesheet value="{!URLFOR($Resource.WorkBookStyles, 'styles.css')}" />
@scarstens
scarstens / gmail.sig.sidebyside.html
Created June 12, 2013 22:42
Google Mail Side by Side Signature and Logo
<table border="0" cellpadding="0" cellspacing="0" width="400">
<tbody>
<tr height="10">
<td height="10" colspan="2"><hr style="height: 1px; border: 0; border-bottom: 1px dashed #ccc; padding: 0; margin: 12px 0 5px 0;" /></td>
</tr>
<tr style="vertical-align: middle;" height="100">
<td height="100" width="250" style="border-right: 1px dashed #ccc;"><strong>Seth Carstens</strong><br>
Rapid Recovery<br>
<a href="tel:8773727732">877-372-7732</a> office<br>
<a href="tel:4802033753">480-203-3753</a> cell<br>
@scarstens
scarstens / get-base-website-url.js
Created July 15, 2013 20:20
javascript function that return the main URL
function get_base_website_url() {
if (!window.location.origin)
return window.location.origin = window.location.protocol+"//"+window.location.host;
else
return window.location.origin;
}