Created
October 22, 2010 17:45
-
-
Save robrocker7/641017 to your computer and use it in GitHub Desktop.
Changes added for guided tour
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Custom Testimonal scripts written by Robert | |
class Helper { | |
protected static $db_connection = false; | |
protected static $debug = true; | |
protected static function connect_to_database($args = array()) { | |
// Create a Database Connection | |
// accepts an option $args array for testing database connections | |
// if there is an error, then fail without breaking site | |
try { | |
if(count($args) > 0) { | |
self::$db_connection = mysql_connect($args['DB_HOST'], | |
$args['DB_USER'], $args['DB_PASSWORD']); | |
} else { | |
self::$db_connection = mysql_connect(DB_HOST, | |
DB_USER, DB_PASSWORD); | |
} | |
return true; | |
} catch (Exception $e) { | |
error_log($e); | |
debug_message($e); | |
return false; | |
} | |
} | |
public static function debug_message($message) { | |
if(self::$debug == true) { | |
throw new Exception($message); | |
} | |
} | |
} | |
class SuccessStory extends Helper { | |
public function __constructor($args = array()) { | |
// Initial Constructor for Success Story Class | |
// accepts an array of arguments that can be used to set settings | |
self::connect_to_database(); | |
if(isset($args['debug'])) { | |
self::$debug = $args['debug']; | |
} | |
} | |
public static function render_all() { | |
// Static function to return all success stories in the database | |
self::connect_to_database(); | |
$sql = "SELECT * FROM `wp_posts` | |
WHERE `post_type` = 'successes'"; | |
$result = mysql_query($sql); | |
$t_array = array(); | |
while($story = mysql_fetch_array($result)) { | |
$id = $story['ID']; | |
$search_result_sql = "SELECT * | |
FROM `wp_postmeta` | |
WHERE `meta_key` | |
REGEXP 'google.|bing.|yahoo.|^url$' | |
AND `post_id` = " . $id; | |
$search_result_result = mysql_query($search_result_sql); | |
$result_array = array(); | |
while($re = mysql_fetch_array($search_result_result)) { | |
$result_array[$re['meta_key']] = $re['meta_value']; | |
} | |
$extra_info_sql = "SELECT t3.name AS 'name', | |
t2.taxonomy AS 'type' | |
FROM `wp_term_relationships` AS t1 | |
INNER JOIN `wp_term_taxonomy` AS t2 | |
ON t1.term_taxonomy_id = t2.term_taxonomy_id | |
INNER JOIN `wp_terms` AS t3 | |
ON t2.term_id = t3.term_id | |
WHERE t1.object_id = " . $id; | |
$extra_info_result = mysql_query($extra_info_sql); | |
$extra_info = array(); | |
while($info = mysql_fetch_array($extra_info_result)) { | |
$extra_info[$info['type']] = $info['name']; | |
} | |
$t_array[] = array( | |
'title' => $story['post_title'], | |
'location' => $extra_info['success_location'], | |
'industry' => $extra_info['success_industry'], | |
'results' => $result_array | |
); | |
} | |
return $t_array; | |
} | |
} | |
class Testimonial extends Helper { | |
public function __constructor($args = array()) { | |
// Initial Constructior for Testimoninals Class | |
// accepts an array of arguments that can be used to set settings | |
self::connect_to_database(); | |
if(isset($args['debug'])) { | |
self::$debug = $args['debug']; | |
} | |
} | |
public static function random($num = 1) { | |
// static function to pull a random testimonial | |
// optional argument can be passed to specify the number results | |
self::connect_to_database(); | |
$sql = "SELECT * FROM `wp_posts`"; | |
$sql .= " WHERE `post_type` = 'testimonials'"; | |
$sql .= " ORDER BY RAND() LIMIT " . $num; | |
try { | |
$result = mysql_query( $sql ); | |
} catch (Exception $e) { | |
error_log($e); | |
debug_message($e); | |
return false; | |
} | |
if($result) { | |
$t_array = array(); | |
while($test = mysql_fetch_array($result)) { | |
$sql_2 = "SELECT t3.name AS 'name', | |
t2.taxonomy AS 'type' | |
FROM `wp_term_relationships` AS t1 | |
INNER JOIN `wp_term_taxonomy` AS t2 | |
ON t1.term_taxonomy_id = t2.term_taxonomy_id | |
INNER JOIN `wp_terms` AS t3 | |
ON t2.term_id = t3.term_id | |
WHERE t1.object_id = " . $test['ID']; | |
$result_2 = mysql_query($sql_2); | |
$extra_info = array(); | |
while($info = mysql_fetch_array($result_2)) { | |
$extra_info[$info['type']] = $info['name']; | |
} | |
$sql_3 = "SELECT `meta_value` | |
FROM `wp_postmeta` | |
WHERE `meta_key` = 'audio_url' AND | |
`post_id` = " . $test['ID']; | |
$result_3 = mysql_query($sql_3); | |
$file_name = mysql_fetch_assoc($result_3); | |
$file_name = $file_name['meta_value']; | |
$t_array[] = array( | |
'file' => $file_name, | |
'name' => $test['post_title'], | |
'content' => $test['post_content'], | |
'location' => $extra_info['location'], | |
'type' => $extra_info['industry'], | |
'date_created' => $test['post_date'] | |
); | |
} | |
return $t_array; | |
} else { | |
return false; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment