100){ array_shift($_SESSION['TTT']); } } if(strpos($_SERVER['REQUEST_URI'], '/admin/')===FALSE){ if(TT)TTT('break'); if(TT)TTT('path',$_SERVER['REQUEST_URI']); } //////////////////////////////////////////////////////// ///////////// end admin_ttt TRACING /////////// //////////////////////////////////////////////////////// function getRootURL() { $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $sp = strtolower($_SERVER["SERVER_PROTOCOL"]); $protocol = substr($sp, 0, strpos($sp, "/")) . $s; $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); $url = $protocol . "://" . $_SERVER['SERVER_NAME'];// . $port . $_SERVER['REQUEST_URI']; if(substr("$url",-1) != "/"){ $url .= "/"; } return $url; } $siteURL = getRootURL(); if($_SERVER['REMOTE_ADDR']=='::1'){ define('IS_LOCAL',1); $siteURL = substr($siteURL, 0,-1) . '/'; }else{ define('IS_LOCAL',0); } //////////////////////////////////////////////////////// ///////////// EDIT THESE SETTINGS !! /////////// //////////////////////////////////////////////////////// if(defined('OMIT_HTTPS')){ define('FORCE_HTTPS',0); }else{ define('FORCE_HTTPS',0); } //define('SHARE_URL','http://prpe.la/'); // USERS & PERMISSIONS SWITCH define('CMS_USER_PERMS',0); // admin access: // admin // LudKing!23 define('PERLMAIL_HOST','mail.emailsrvr.com'); define('PERLMAIL_EMAIL','email@ludlowkingsley.com'); define('PERLMAIL_PASS','LudKing!23'); if(!isset($_SESSION['FORCE_DEV_SANDBOX'])){ $_SESSION['FORCE_DEV_SANDBOX'] = FALSE; } if($_SESSION['FORCE_DEV_SANDBOX'] == 1 || $subdomain == 'dev'){ define('IS_DEV',1); define('IS_SANDBOX',1); }else{ /// EDIT THESE TO BE ACCURATE WHEN LIVE !!!! /// EDIT THESE TO BE ACCURATE WHEN LIVE !!!! define('IS_DEV',0); define('IS_SANDBOX',0); } if(IS_DEV){ error_reporting(E_ALL); ini_set('error_reporting', E_ALL ^ E_DEPRECATED ^ E_NOTICE); //E_NOTICE ini_set('display_errors', 'Off'); }else{ //ini_set('error_reporting', E_ALL & E_NOTICE); error_reporting(0); ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT & ~E_DEPRECATED); ini_set('display_errors', 'Off'); ini_set('log_errors', 'Off'); } define('MIN_DONATION',3); define('IGNOR_INVENTORY',0); define('SHOP_SECTION_ID',3); define('SHIP_SECTION_ID',55); define('CCODE_SECTION_ID',54); define('CARTNAME','cart'); define('TAX_STATE','CA'); define('TAX_STATE_RATE','7.25'); define('TAX_CITY','Moss Landing'); define('TAX_CITY_RATE','7.75'); define('RECEIPT_PAGE_ID',614); define('CONFIRM_EMAIL_PAGE_ID',613); // define('CONFIRM_EMAIL_PAGE_ID',701); define('REFUND_EMAIL_PAGE_ID',1016); define('COMMISSION_PERCENT',10); // moonjuice specific for Local Delivery define('MOON_LD_BID',264); define('LD_SECTION_ID',70); define('LD_BLACKOUT_SECTION_ID',76); // not moonjuice //define('MOON_LD_BID',0); //LIVE $DBhost = "localhost"; $DBuser = "utbecbgban"; $DBpass = "YbaCWCj7XN"; $DBname = "utbecbgban"; ///DEV /* $DBhost = "mariadb-116.wc1.dfw3.stabletransit.com"; $DBuser = "933341_realgdf"; $DBpass = "3D4qUXXwaB"; $DBname = "933341_realgdf"; */ if(IS_LOCAL){ $DBhost = "localhost"; $DBuser = "root"; $DBpass = "clark123"; $DBname = "LK-CMS-2016"; } define("DB_HOST",$DBhost); define("DB_USERNAME",$DBuser); define("DB_PASSWORD",$DBpass); define("DB_NAME",$DBname); // for auth $fb_app_id = "661401113928400"; $fb_secret = "aabb40be58e9da13cf967095d5788743"; $tw_key = "5tNArcO2aEIq6iHvRyVOkEven"; $tw_secret = "hbfXZTz1TxHjcCoJo72d4f0CzCHhI36HERm4QGT6Y0eMuQsuDu"; define("MAILGUN_KEY",'key-0oe6s7ti5s5sh2nhq46tp77sx4mymue7'); define("MAILGUN_DOMAIN",'ludlowkingsley.email'); //require 'includes/mailgun-php-1.7/vendor/autoload.php'; //use Mailgun\Mailgun; define("GOOGLE_JS_KEY",'AIzaSyDVbsoqiQqO-qk1CS73GvhxGwSlslk1HhE'); define("GOOGLE_GEOCODE_KEY",'AIzaSyDyJcHMaD2EQHZ_YLUB1te6afkIASmd28M'); define("MAIL_CHIMP_KEY",'9a64f7fd73cd21dc0dea605c4903ffd6-us10'); define("MAIL_CHIMP_LIST_ID",'1b99f4a0c3'); ////// LK's propeller.la stripe account define('TOKEN_URI', 'https://connect.stripe.com/oauth/token'); define('AUTHORIZE_URI', 'https://connect.stripe.com/oauth/authorize'); if(IS_SANDBOX){ //test define("STRIPE_PUB_KEY","pk_test_kpTWYxH8jdYkYLc8wo0xlIHu"); define("STRIPE_SECRET_KEY","sk_test_oeyMK9qqIwDEwNet3XpJAVXV"); }else{ // live define("STRIPE_PUB_KEY","pk_live_H7F3hCftIuxnF1n5uZTgkMa5"); define("STRIPE_SECRET_KEY","sk_live_s9NyMKSXnXgMvLLflSNHZtm6"); } //FEED_WORDPRESS// define("FEED_WORDPRESS",FALSE); define("FEED_WP_RSS_URL",'http://santamonicacentric.com/feed/'); //FEED_TUMBLR// define("FEED_TUMBLR",TRUE); define("FEED_TUMBLR_API_KEY",'rXMnAKa1pxxDpAwKAXxJ9syk1RoQnAfbQtQh3MUbOCDke2r3By'); define("FEED_TUMBLR_URL",'ludlowkingsley.tumblr.com'); //FEED_FACEBOOK// define("FEED_FACEBOOK",TRUE); define("FEED_FACEBOOK_USERNAME",'ludlow.kingsley'); //FEED_TWITTER// define("FEED_TWITTER",TRUE); define("FEED_TWITTER_SCREENNAME",'ludlowkingsley'); //FEED_INSTAGRAM// define("FEED_INSTAGRAM",TRUE); define("FEED_INSTAGRAM_ID",'528466574'); // user_id ////http://jelled.com/instagram/lookup-user-id define("FEED_INSTAGRAM_TAGS",FALSE); define("FEED_INSTAGRAM_TAG",'ludlowkingsley'); //FEED_YOUTUBE// define("FEED_YOUTUBE",FALSE); define("FEED_YOUTUBE_PLAYLIST_ID",''); //////////////////////////////////////////////////////// ///////// DON'T EDIT THESE SETTINGS !! //////// //////////////////////////////////////////////////////// if(!isset($IS_CRON)){ // add $IS_CRON=1 to top of any script being cron_jobed if(FORCE_HTTPS){ if (strtolower($_SERVER['HTTPS']) != 'on') { exit(header("location: https://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}")); } } } $err_level = error_reporting(0); $link = mysql_connect(DB_HOST,DB_USERNAME,DB_PASSWORD,true); error_reporting($err_level); mysql_set_charset("UTF8", $link); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db(DB_NAME); class dbh{ private static $instance = NULL; private function __construct() { /*** maybe set the db name here later ***/ } public static function getInstance() { if(!self::$instance){ $hostname = DB_HOST; $username = DB_USERNAME; $dbname = DB_NAME; $password = DB_PASSWORD; self::$instance = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password); // ERRMODE_SILENT ERRMODE_WARNING ERRMODE_EXCEPTION self::$instance-> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } return self::$instance; } private function __clone(){ } //usage //$dbh = DB::getInstance(); } /*** db ***/ $dbh = DBH::getInstance(); // try to stop using this! /* SEE: https://phpdelusions.net/pdo/pdo_wrapper */ class DBP { protected static $instance = null; protected function __construct() {} protected function __clone() {} public static function instance() { if (self::$instance === null) { $opt = array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => FALSE, ); $dsn = 'mysql:host='.DB_HOST.';dbname='.DB_NAME.';charset=utf8'; self::$instance = new PDO($dsn, DB_USERNAME, DB_PASSWORD, $opt); } return self::$instance; } public static function __callStatic($method, $args) { return call_user_func_array(array(self::instance(), $method), $args); } public static function run($sql, $args = []) { if (!$args) { return $this->query($sql); } $stmt = self::instance()->prepare($sql); $stmt->execute($args); return $stmt; } } define('INSTAGRAM_ID','6edb035540934626bd1b087da40c78e6'); define('INSTAGRAM_SECRET','82e769575e9c4d93b75b50d04f6bb336'); define('FB_APP_ID',$fb_app_id); define('FB_SECRET',$fb_secret); define('TW_KEY',$tw_key); define('TW_SECRET',$tw_secret); define('SITE_URL',$siteURL); define('BASE',SITE_URL); ?> 1, "side" => 0, "name1" => "Plain Text", "fields" => array("long_text")), array("id" => 111, "side" => 0, "name1" => "Unique Text", "fields" => array("long_text","short_text")), array("id" => 112, "side" => 0, "name1" => "Unique Root URL", "fields" => array("long_text")), array("id" => 2, "side" => 0, "name1" => "Rich Text", "fields" => array("rich_text")), array("id" => 6, "side" => 0, "name1" => "Raw Text", "fields" => array("rich_text")), array("id" => 18, "side" => 0, "name1" => "Link", "fields" => array("short_text","long_text")), array("id" => 3, "side" => 0, "name1" => "Image", "fields" => array("file_name","img_alt")), array("id" => 4, "side" => 0, "name1" => "Image Gallery", "fields" => array("file_name","short_text","rich_text","long_text","vid_src","vid_id","img_alt")), array("id" => 32, "side" => 0, "name1" => "Image Coorinates", "fields" => array("short_text","long_text","address_1","address_2")), array("id" => 5, "side" => 0, "name1" => "Video", "fields" => array("short_text","long_text","file_name")), array("id" => 7, "side" => 1, "name1" => "Date", "fields" => array("date")), array("id" => 71, "side" => 1, "name1" => "Time", "fields" => array("time")), array("id" => 72, "side" => 1, "name1" => "Date & Time", "fields" => array("timestamp")), array("id" => 73, "side" => 0, "name1" => "Schedule", "fields" => array()), array("id" => 8, "side" => 1, "name1" => "Color", "fields" => array("color","short_text")), array("id" => 9, "side" => 1, "name1" => "Number", "fields" => array("number")), array("id" => 91, "side" => 1, "name1" => "Timestamp", "fields" => array("number")), array("id" => 10, "side" => 1, "name1" => "Price", "fields" => array("price")), array("id" => 11, "side" => 1, "name1" => "Checkbox", "fields" => array("checkbox")), array("id" => 110, "side" => 0, "name1" => "Select Option", "fields" => array("rich_text")), //Map State Select array("id" => 120, "side" => 0, "name1" => "Select States on Map", "fields" => array("rich_text")), array("id" => 12, "side" => 0, "name1" => "Address", "fields" => array("address_1","address_2","city","state","zip","country")), array("id" => 13, "side" => 1, "name1" => "Telephone", "fields" => array("telephone")), array("id" => 14, "side" => 0, "name1" => "File", "fields" => array("file_name","long_text")), array("id" => 15, "side" => 1, "name1" => "Tags", "fields" => array()), array("id" => 16, "side" => 1, "name1" => "Grouping", "fields" => array()), array("id" => 17, "side" => 1, "name1" => "Relation", "fields" => array("short_text","number")), array("id" => 25, "side" => 2, "name1" => "Database Relation", "fields" => array("short_text","number")), array("id" => 251, "side" => 1, "name1" => "Database Field", "fields" => array("short_text")), array("id" => 26, "side" => 1, "name1" => "Section Relation", "fields" => array("number")), array("id" => 19, "side" => 1, "name1" => "Associations", "fields" => array()), array("id" => 20, "side" => 2, "name1" => "Pages", "fields" => array("short_text","number")), array("id" => 21, "side" => 0, "name1" => "Children", "fields" => array("short_text","number")), array("id" => 222, "side" => 2, "name1" => "Variations", "fields" => array("short_text","number")), array("id" => 23, "side" => 0, "name1" => "Child From Sub-Sections", "fields" => array("short_text","number")), array("id" => 22, "side" => 1, "name1" => "Size SKU Qty", "fields" => array("short_text","long_text","number")), array("id" => 221, "side" => 0, "name1" => "Size SKU Qty Price", "fields" => array("short_text","long_text","number","price")), array("id" => 100, "side" => 0, "name1" => "UN Actions", "fields" => array()), array("id" => 30, "side" => 2, "name1" => "Section Permissions", "fields" => array("rich_text")), array("id" => 31, "side" => 1, "name1" => "User Password", "fields" => array("long_text","short_text")), //Page table options array("id" => 200, "side" => 200, "name1" => "Hide - In 'page' table", "fields" => array()), array("id" => 201, "side" => 200, "name1" => "Feature - In 'page' table", "fields" => array()), array("id" => 202, "side" => 200, "name1" => "Date Created - In 'page' table", "fields" => array()), array("id" => 203, "side" => 200, "name1" => "Date Modified - In 'page' table", "fields" => array()), array("id" => 300, "side" => 1, "name1" => "API Button", "fields" => array("short_text","rich_text")), array("id" => 301, "side" => 1, "name1" => "Open Window URL", "fields" => array("long_text")), array("id" => 302, "side" => 1, "name1" => "Help", "fields" => array("long_text")), //Social Feed - Insert Page array("id" => 400, "side" => 400, "name1" => "Social Feed - Insert Page", "fields" => array()), //Google array("id" => 410, "side" => 0, "name1" => "Google Get Lat/Lon", "fields" => array("lat","lon")), //Printful array("id" => 500, "side" => 0, "name1" => "Printful Variation Importer", "fields" => array("short_text","long_text","file_name")), ); ///////////// MAILGUN MAIL SENDER VIA LudlowKingsley.Email ///////////// $RELPATH = explode('public_html',getcwd())[0].'public_html'; require $RELPATH.'/includes/mailgun-php-1.7/vendor/autoload.php'; use Mailgun\Mailgun; function mailgun_send_email($from=FALSE,$to=FALSE,$subject=FALSE,$body=FALSE,$replyto=FALSE){ $return = array('success'=>FALSE,'msg'=>'function error'); if(!$from || !$to || !$subject || !$body){ $return['msg'] = 'inputs invalid'; return $return; } $MAILGUN = new Mailgun(MAILGUN_KEY); $mailVars = array(); $mailVars['from'] = $from; $mailVars['to'] = $to; $mailVars['subject']= $subject; $mailVars['text'] = $body; $mailVars['h:Reply-To'] = $replyto; //$mailVars['html'] = $this->get('html'); $mg_result = $MAILGUN->sendMessage(MAILGUN_DOMAIN,$mailVars); $mg_result1 = json_encode($mg_result); $mg_result2 = json_decode($mg_result1, true); if ($mg_result2['http_response_code'] != 200) { $return['msg'] = $mg_result2['http_response_body']['message']; } else { $return['success'] = TRUE; $return['msg'] = 'Email successfully sent to '. htmlspecialchars($to) . ' ' . $mg_result2['http_response_body']['id']; } return $return; } ///////////// END MAILGUN MAIL SENDER VIA LudlowKingsley.Email ///////////// function rs_mail_pear($from=FALSE,$to=FALSE,$subject=FALSE,$body=FALSE){ if($_SESSION['PEAR_MAIL']){ $return = array('success'=>FALSE,'msg'=>'function error'); if(!$from || !$to || !$subject || !$body){ $return['msg'] = 'inputs invalid'; return $return; } $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $settings = array(); $settings['host'] = PERLMAIL_HOST; $settings['auth'] = true; $settings['username'] = PERLMAIL_EMAIL; $settings['password'] = PERLMAIL_PASS; if(PERLMAIL_SSL){ // $settings['host'] = "ssl://" . PERLMAIL_HOST; // $settings['port'] = '465'; } $smtp = Mail::factory('smtp',$settings); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { $return['msg'] = $mail->getMessage(); } else { $return['success'] = TRUE; $return['msg'] = 'Email successfully sent to '. htmlspecialchars($to); } return $return; }else{ return array('success'=>FALSE,'msg'=>'Mail.php not available.'); } } /** **IMPORTANT-- madrid reversed the strings in both functions to match legacy code so the site keeps flowing * A nice shorting class based on Ryan Charmley's suggestion see the link on stackoverflow below. * @author Svetoslav Marinov (Slavi) | http://WebWeb.ca * @see http://stackoverflow.com/questions/742013/how-to-code-a-url-shortener/10386945#10386945 */ class App_Shorty { /** * Explicitely omitted: i, o, 1, 0 because they are confusing. Also use only lowercase ... as * dictating this over the phone might be tough. * @var string */ private $dictionary = "123456789abcdefghijklmnopqrstuvwxyz"; //private $dictionary = "abcdfghjklmnpqrstvwxyz23456789"; private $dictionary_array = array(); public function __construct() { $this->dictionary_array = str_split($this->dictionary); } /** * Gets ID and converts it into a string. * @param int $id */ public function encode($id) { $str_id = ''; $base = count($this->dictionary_array); while ($id > 0) { $rem = $id % $base; $id = ($id - $rem) / $base; $str_id .= $this->dictionary_array[$rem]; } //notes: madrid - keep up with already installed old code $str_id = strrev($str_id); return $str_id; } /** * Converts /abc into an integer ID * @param string * @return int $id */ public function decode($str_id) { //notes: madrid - keep up with already installed old code $str_id = strrev($str_id); $id = 0; $id_ar = str_split($str_id); $base = count($this->dictionary_array); for ($i = count($id_ar); $i > 0; $i--) { $id += array_search($id_ar[$i - 1], $this->dictionary_array) * pow($base, $i - 1); } return $id; } } function ordinal_suffix($num){ $num = $num % 100; // protect against large numbers if($num < 11 || $num > 13){ switch($num % 10){ case 1: return 'st'; case 2: return 'nd'; case 3: return 'rd'; } } return 'th'; } function getSectName($sid){ $sectQ = mysql_query("SELECT * FROM `section` WHERE `id` = '$sid'"); while($line1 = mysql_fetch_assoc($sectQ)) { return $line1["name1"]; } } function deletePageAndStuff($id){ $query = "DELETE FROM `page` WHERE `id`='$id'"; mysql_query($query) or die('Error, delete query failed'); $query = "DELETE FROM `post` WHERE `PAGE_ID`='$id'"; mysql_query($query) or die('Error, delete query failed'); $query = "DELETE FROM `ssq` WHERE `PAGE_ID`='$id'"; mysql_query($query) or die('Error, delete query failed'); $query = "DELETE FROM `schedule` WHERE `PAGE_ID`='$id'"; mysql_query($query) or die('Error, delete query failed'); $query = "DELETE FROM `schedule_events` WHERE `PAGE_ID`='$id'"; mysql_query($query) or die('Error, delete query failed'); $query = "DELETE FROM `group_page_x` WHERE `PAGE_ID`='$id'"; mysql_query($query) or die('Error, delete query failed'); $query = "DELETE FROM `tag_page_block_x` WHERE `PAGE_ID`='$id'"; mysql_query($query) or die('Error, delete query failed'); $query = "DELETE FROM `content` WHERE `PAGE_ID`='$id'"; mysql_query($query) or die('Error, delete query failed'); $query = "DELETE FROM `ssq` WHERE `PAGE_ID`='$id'"; mysql_query($query) or die('Error, delete query failed'); $postsQ = mysql_query("SELECT * FROM `page` WHERE `PARENT_ID`='$id' ORDER BY `order`"); while($line1 = mysql_fetch_assoc($postsQ)) { $postID = $line1["id"]; deletePageAndStuff($postID); /* $posts2Q = mysql_query("SELECT * FROM `page` WHERE `PARENT_ID`='$postID' ORDER BY `order`"); while($line2 = mysql_fetch_assoc($posts2Q)) { $postID2 = $line2["id"]; deletePageAndStuff($postID2); } */ } return $id; } function updateSEO($page_id,$updateJson=false){ if(TT)TTT('updateSEO',$page_id); global $siteInfo; $config = array(); $configQ = mysql_query("SELECT * FROM `config` ORDER BY `order`"); while($line1 = mysql_fetch_assoc($configQ)) { $config[$line1['id']] = $line1; } $addTitle = (!empty($config[4]['value'])?$config[4]['value']:'Yes'); $addSect = (!empty($config[5]['value'])?$config[5]['value']:'Yes'); $sect_id = FALSE; $pageQ = mysql_query("SELECT * FROM `page` WHERE `id` = '$page_id'"); while($line1 = mysql_fetch_assoc($pageQ)) { $page = $line1; $sect_id = $page['SECTION_ID']; } if($sect_id){ $sectionQ = mysql_query("SELECT * FROM `section` WHERE `id` = '$sect_id'"); while($line1 = mysql_fetch_assoc($sectionQ)) { $section = $line1; } } $block_id = FALSE; if(isset($page['update_meta_desc']) && $sect_id){ $richQ = mysql_query("SELECT * FROM `block` WHERE `SECTION_ID` = '$sect_id' AND `BLOCK_TYPES_ID`='2' ORDER BY `order` LIMIT 0,1"); while($line1 = mysql_fetch_assoc($richQ)) { $block_id = $line1['id']; } if($block_id){ $richQ = mysql_query("SELECT * FROM `post` WHERE `PAGE_ID` = '$page_id' AND `BLOCK_ID`='$block_id'"); while($line1 = mysql_fetch_assoc($richQ)) { $richText = $line1['rich_text']; } } } if(isset($page)){ $newPage = array(); if(empty($page['meta_title']) || $page['update_meta_title']){ $seoTitle = ''; if($addTitle == 'Yes'){ $seoTitle .= SITE_NAME; if($addSect == 'Yes'){ $seoTitle .= ' | '; } } if($addSect == 'Yes'){ $seoTitle .= $section['name1'] . ' | '; } //$seoTitle = SITE_NAME . ' | ' . $section['name1']; if(!empty($page['name1'])){ if($addTitle == 'Yes'){ $seoTitle .= ' | '; } $seoTitle .= $page['name1']; } if($page_id == 1){ $seoTitle = SITE_TITLE; } $seoTitle = chk($seoTitle); $query = "UPDATE `page` SET `meta_title`='$seoTitle' WHERE `id`='$page_id'"; mysql_query($query) or die('Error, insert meta_title query failed'); $newPage['meta_title'] = $seoTitle; } if(empty($page['meta_desc']) || $page['update_meta_desc']){ if(!isset($richText)){ $seoDesc = SITE_DESCRIPTION; }else{ $seoDesc = html_entity_decode(myTruncate($richText,150," ","...")); } $seoDesc = trim(preg_replace('/\s\s+/', ' ', $seoDesc)); $seoDesc = chk($seoDesc); $query = "UPDATE `page` SET `meta_desc`='$seoDesc' WHERE `id`='$page_id'"; mysql_query($query) or die('Error, insert meta_desc query failed'); $newPage['meta_desc'] = $seoDesc; } if(empty($page['meta_json'])){ $seoJson = mysql_real_escape_string(SITE_JSON_LD); $query = "UPDATE `page` SET `meta_json`='$seoJson' WHERE `id`='$page_id'"; mysql_query($query) or die('Error, insert meta_json query failed'); } if(empty($page['meta_img']) || ($page['meta_img'] != $page['lead_img']) && !$page['update_meta_img']){ //if(TT)TTT('$page[lead_img]',$page['lead_img']); if(empty($page['lead_img'])){ $img = $siteInfo["Logo"][0]; }else{ $img = $page['lead_img']; } $img = chk($img); $query = "UPDATE `page` SET `meta_img`='$img' WHERE `id`='$page_id'"; mysql_query($query) or die('Error, insert meta_img query failed'); $newPage['meta_img'] = $img; } if($page_id == 1){ if(empty($page['lead_img'])){ $SITE_LOGO = chk($siteInfo["Logo"][0]); $query = "UPDATE `page` SET `lead_img`='$SITE_LOGO' WHERE `id`='$page_id'"; mysql_query($query) or die('Error, insert meta_json query failed'); } } if($updateJson){ $json = updateJson($page_id); } if(isset($page['meta_title']) && isset($newPage['meta_title'])){ if($page['meta_title'] != $newPage['meta_title'] || $page['meta_desc'] != $newPage['meta_desc'] || $page['meta_img'] != $newPage['meta_img']){ $purl = getURLfromPageId($page['id']); $url = SITE_URL . $purl; clear_open_graph_cache($url); // facebook cache } } return $page; }else{ return false; } } function getShortenedURLFromID ($integer, $base = '123456789abcdefghijklmnopqrstuvwxyz'){ $length = strlen($base); while($integer > $length - 1){ $out = $base[fmod($integer, $length)] . $out; $integer = floor( $integer / $length ); } return $base[$integer] . $out; } function getMoonAccountingCatfrom_ssq_id($ssq_id){ $ssqQ = mysql_query("SELECT `PAGE_ID` FROM `ssq` WHERE `id`='$ssq_id'"); while ($ssq = mysql_fetch_assoc($ssqQ)){ $pageQ = mysql_query("SELECT `PARENT_ID` FROM `page` WHERE `id`=$ssq[PAGE_ID]"); while ($page = mysql_fetch_assoc($pageQ)){ $page_PARENT_ID = $page['PARENT_ID']; } } $block_id = 432; //$group_PARENT_ID = 55; $groupQ = mysql_query("SELECT `group`.`name1` FROM `group`,`group_page_x` WHERE `group_page_x`.`PAGE_ID`='$page_PARENT_ID' AND `group_page_x`.`BLOCK_ID`='$block_id' AND `group_page_x`.`GROUP_ID`=`group`.`id` "); while ($group = mysql_fetch_assoc($groupQ)){ $groupName = $group['name1']; } $grp = explode(':',$groupName); return (empty($grp[1])?'No Accounting Cat':$grp[1]); } function getAssociated($page_id,$block_id,$typ='bid'){ // a function for get associated // pass page id of the page you are viewing // pass the block id from where you want to find associations for the page you are viewing $pages = array(); $hide = (IS_DEV?'':'AND `hide`=0'); $pageQ = mysql_query("SELECT `page`.`id` FROM `page`,`page_block_apage_x` WHERE `page_block_apage_x`.`assoc_PAGE_ID`='$page_id' AND `page_block_apage_x`.`PAGE_ID` = `page`.`id` AND `page_block_apage_x`.`BLOCK_ID` = '$block_id' AND `page`.`visible` = '1' $hide ORDER BY `page_block_apage_x`.`order` "); while($line1 = mysql_fetch_assoc($pageQ)) { $rew = getContent($line1["id"],$typ); $pages[] = $rew; } return $pages; } function getBlockContentFromPageViaRelatedPage($block_id,$per_page_id){ /* This will return the field names -> values for a page that has a related block to a page with the id of the requested page id. */ global $blockTypes; $blockQ = mysql_query("SELECT * FROM `block` WHERE `id`='$block_id'"); while($line1 = mysql_fetch_assoc($blockQ)) { foreach($blockTypes as $type){ if($type["id"] == $line1["BLOCK_TYPES_ID"]){ $block_type = $type; break; } } $section_id = $line1['SECTION_ID']; } $fieldName = $block_type['fields']; $sel = ""; if(count($fieldName)>0){ foreach($fieldName as $fn){ $sel .= " `post`." . $fn . ","; } $sel = substr($sel,0,-1); } $pages = array(); $pageQ = mysql_query("SELECT `page`.* FROM `page`,`post` WHERE `page`.`SECTION_ID`='$section_id' AND `page`.`visible`='1' AND `post`.`PAGE_ID`=`page`.`id` AND `post`.`number`='$per_page_id'"); while($line1 = mysql_fetch_assoc($pageQ)) { $page_id = $line1["id"]; $pagesQ = mysql_query("SELECT $sel FROM `post` WHERE `post`.`PAGE_ID` = '$page_id' AND `post`.`BLOCK_ID` = '$block_id' "); while($line2 = mysql_fetch_assoc($pagesQ)) { $line2['page_id'] = $page_id; $pages[] = $line2; } } return $pages; } function getMatrix($id){ $matrix = array(); $tags = array(); $matrixQ = mysql_query("SELECT * FROM `matrix` WHERE `id`='$id'"); while($line1 = mysql_fetch_assoc($matrixQ)) { $m1id = $line1['id']; $matrixSectionsQ = mysql_query("SELECT * FROM `matrix` WHERE `PARENT_ID`='$m1id' AND `type`='section'"); while($line2 = mysql_fetch_assoc($matrixSectionsQ)) { $matrixSectionIds[] = $line2['SECTION_ID']; $line1['sections'][] = $line2; } $matrixTagsQ = mysql_query("SELECT * FROM `matrix` WHERE `PARENT_ID`='$m1id' AND `type`='tag' ORDER BY `order`"); while($line3 = mysql_fetch_assoc($matrixTagsQ)) { $line1['tags'][] = $line3; $tags[$line3['name1']] = 'bid_' . $line3['BLOCK_ID']; } $matrix = $line1; } //return $matrix; return $tags; } function getMatrixBySectionId($section_id){ $matrixSectionsQ = mysql_query("SELECT `PARENT_ID` FROM `matrix` WHERE `SECTION_ID`='$section_id' AND `type`='section' LIMIT 0,1"); while($line2 = mysql_fetch_assoc($matrixSectionsQ)) { $matrix_id = $line2['PARENT_ID']; } return getMatrix($matrix_id); } $unActionTypes = array( array("id" => 1, "name1" => "Watch A Video", "global_points_id" => 707, "f1" => "Video URL"), array("id" => 3, "name1" => "Connect", "global_points_id" => 709), array("id" => 2, "name1" => "Listen To A Song", "global_points_id" => 711, "f1" => "Spotify URI"), array("id" => 4, "name1" => "Read A Webpage", "global_points_id" => 708, "f1" => "Webpage URL", "f2" => "Tracking #"), //array("id" => 5, "name1" => "Share A Link", "global_points_id" => 710, "f1" => "Link URL", "f2" => "Tracking Id"), array("id" => 6, "name1" => "Sign A Petition", "global_points_id" => 712, "f1" => "Petition URL", "f2" => "Petition Id"), array("id" => 7, "name1" => "Answer A Question", "global_points_id" => 707, "f1" => "Question","f2"=>"Answer") ); function getGlobalPoints($uat_id){ global $unActionTypes; $uat_points = 0; foreach($unActionTypes as $uat){ if($uat["id"] == $uat_id){ $global_points_id = $uat["global_points_id"]; $page = getPageContentNew($global_points_id); $uat_points = $page["bid_1182"]["content"][0]; break; } } return $uat_points; } function daysbig($t){ if(!$t){ $t = time(); } $y = date("Y",$t); $d = str_pad( date("z",$t), 3, "0", STR_PAD_LEFT ); return intval($y.$d); } function chk(& $var) { if(!isset($var)) { $non = ""; return $non; }else{ $non = trim(mysql_real_escape_string($var)); return $non; } } function zer(& $var) { if(!isset($var)) { $non = 0; return $non; }else{ $non = trim(mysql_real_escape_string($var)); return $non; } } function entQ($str){ //return htmlentities($str,ENT_QUOTES); return htmlentities($str, ENT_COMPAT, 'UTF-8'); } function entQ2($str){ return html_entity_decode(entQ($str),ENT_HTML5); } function priceFormatter($str,$abs=''){ //this will strip $ and , from string and return a float // priceFormatter('-$1,435.122','abs'); // abs will return a positive number $a = $str; $b = str_replace( ',', '', $a ); $c = str_replace( '$', '', $b ); if( is_numeric( $c ) ) { $a = $c; } $d = str_replace('$', '', $a); $e = number_format($d,2,'.',''); if($abs == 'abs'){ return number_format(abs($e),2,'.',''); }else{ return $e; } } function updateJson($page_id,$updateSEO=true){ if(TT)TTT('updateJson',$page_id); if($updateSEO){ $seo = updateSEO($page_id); } $lang_ids = array(); $languagesQ = mysql_query("SELECT * FROM `language` WHERE `visible`='1' ORDER BY `order`"); while($line1 = mysql_fetch_assoc($languagesQ)) { $lang_ids[] = $line1['id']; } $updated_it = FALSE; foreach($lang_ids as $lang_id){ $rr = 0; $ccQ = mysql_query("SELECT * FROM `content` WHERE `PAGE_ID`='$page_id' AND `LANG_ID`='$lang_id' ORDER BY `id`"); $struc = array(); while($line2 = mysql_fetch_assoc($ccQ)) { $struc[] = $line2; } if($page_id == 1){ $cont = getPageContent($page_id); $json_bid = mysql_real_escape_string(json_encode($cont)); $cont_bid = array(); }else{ //$bitly = getAndUpdateBitly($page_id); $cont_bid = getPageContentNew($page_id,$lang_id); $json_bid = mysql_real_escape_string(json_encode($cont_bid)); $cont_typ = getPageContentAll($page_id); $json_typ = mysql_real_escape_string(json_encode($cont_typ)); $cont_alias = cobConverter($cont_bid); $json_alias = mysql_real_escape_string(json_encode($cont_alias)); } $dateTime = date("Y-m-d H:i:s",time()); $msg = ""; $page_link = (!empty($cont_bid['page_link'])?$cont_bid['page_link']:''); if(count($struc)>1){ $skip = 1; foreach($struc as $std){ if($skip > 1){ $thStdId = $std['id']; $query = "DELETE FROM `content` WHERE `id` = '$thStdId'"; mysql_query($query) or die('Error, delete extra content rows failed ' . mysql_error()); echo $skip; } $skip++; } } if(empty($struc)){ $updated_it = 1; $query = "INSERT INTO `content` (`PAGE_ID`,`page_link`,`LANG_ID`,`content_json_bid`,`content_json_typ`,`content_json_alias`,`date_updated`) VALUES ('$page_id','$page_link','$lang_id','$json_bid','$json_typ','$json_alias','$dateTime')"; mysql_query($query) or die('Error, write content insert query failed'); $msg = "inserted content page id: " . $page_id; }else if($struc[0]["content_json_bid"] != json_encode($cont_bid) || $struc[0]["content_json_alias"] != json_encode($cont_alias) || empty($struc[0]["page_link"])){ $updated_it = 1; $json_typ = (isset($json_typ)?$json_typ:''); $json_alias = (isset($json_alias)?$json_alias:''); $query = "UPDATE `content` SET `content_json_bid` = '$json_bid',`content_json_typ` = '$json_typ',`content_json_alias`='$json_alias',`date_updated`='$dateTime',`page_link`='$page_link' WHERE `PAGE_ID`='$page_id' AND `LANG_ID`='$lang_id'"; mysql_query($query) or die('Error, rename query failed'); $msg = "updated content page id: " . $page_id; }else{ $msg = "skipped content page id: " . $page_id; } } if($updated_it){ ///FOR PROPELLER/// /* if(SITE_URL=='https://www.propeller.la/' && $page_id > 1){ $url = 'https://www.propeller.la/api/rest/?method=urls.update_pro_urls&PAGE_ID='.$page_id; $resp = get_curl($url); } */ } return $msg; } function getPages($section_id,$content=false,$limit=0,$hide=0,$daterange=0,$feat=0){ $pages = array(); if($hide == 0){ $hidet = 'AND `hide`=0'; }else if($hide == 1){ $hidet = ''; } $featu = ''; if($feat==1){ $featu = 'AND `feature`=1'; } if($limit == 0){ $pagesQ = mysql_query("SELECT * FROM `page` WHERE `SECTION_ID`='$section_id' AND `visible`=1 ".$hidet." ".$featu." ORDER BY `order`"); }else{ $pagesQ = mysql_query("SELECT * FROM `page` WHERE `SECTION_ID`='$section_id' AND `visible`=1 ".$hidet." ".$featu." ORDER BY `order` LIMIT 0,$limit"); } if($daterange != 0){ $now = time(); $pagesQ = mysql_query("SELECT * FROM `page` WHERE `SECTION_ID`='$section_id' AND `visible`=1 ".$hidet." ".$featu." AND ((`start_time`<'$now' AND `end_time`>'$now') OR (`start_time`=0 AND `end_time`=0)) ORDER BY `order`"); } while($line1 = mysql_fetch_assoc($pagesQ)) { if($content == 'bid'){ $line1['content'] = getContent($line1['id'],'bid'); } if($content == 'typ'){ $line1['content'] = getContent($line1['id'],'typ'); } if($content == 'alias'){ $line1['content'] = getContent($line1['id'],'alias'); } $pages[] = $line1; } return $pages; } function getFirstPageBidFromChildSections($section_id){ $pages = array(); $sects = getChildSections($section_id); foreach($sects as $s){ $page = getPages($s['id'],'bid',1); $pages[] = $page[0]; } return $pages; } function getChildSections($section_id){ $pages = array(); $pagesQ = mysql_query("SELECT * FROM `section` WHERE `PARENT_ID`='$section_id' AND `visible`=1 and `hide`=0 ORDER BY `order`"); while($line1 = mysql_fetch_assoc($pagesQ)) { $pages[] = $line1; } return $pages; } function initPageBlocks($page_id){ $pageQ = mysql_query("SELECT * FROM `page` WHERE `id`='$page_id' LIMIT 0,1"); while($line1 = mysql_fetch_assoc($pageQ)) { $page = $line1; } $section_id = $page["SECTION_ID"]; $page_id = $page["id"]; $page_url = $page["url"]; $block = array(); $blockQ = mysql_query("SELECT * FROM `block` WHERE `SECTION_ID`='$section_id' ORDER BY `order`"); while($line1 = mysql_fetch_assoc($blockQ)) { $block[] = $line1; } foreach($block as $line1){ $bid = $line1["id"]; $postQ = mysql_query("SELECT * FROM `post` WHERE (`BLOCK_ID`,`PAGE_ID`)=('$bid','$page_id') AND `PARENT_ID`=0 LIMIT 0,1"); while($line2 = mysql_fetch_assoc($postQ)) { $line1["post"] = $line2; } if(!isset($line1["post"])){ $query = "INSERT INTO `post` (`BLOCK_ID`,`PAGE_ID`) VALUES ('$line1[id]','$page_id')"; mysql_query($query) or die('Error, insert PAGE query failed'); //header("Location: " . $currentURL); } } updateJson($page_id); return $page_id; } function curPageURL() { $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $sp = strtolower($_SERVER["SERVER_PROTOCOL"]); $protocol = substr($sp, 0, strpos($sp, "/")) . $s; $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); return $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . $_SERVER['REQUEST_URI']; } function parseImgForAlt($alias_image){ //$img = parseImgForAlt($pa['content']['lead_img']); // $img['img'] $img['alt'] global $siteName; global $siteTitle; $alt = (!empty($siteTitle)?$siteTitle:$siteName); if(is_array($alias_image)){ if(!empty($alias_image[6])){ $alt = $alias_image[6]; }else if(!empty($alias_image[1])){ $alt = $alias_image[1]; } } $alt = cleanForAttr($alt); $img = (is_array($alias_image)?$alias_image[0]:$alias_image); return array('img'=>$img,'alt'=>$alt); } function cleanForShortURL($toClean) { $toClean = str_replace('&', '-and-', $toClean); $toClean = trim(preg_replace('/[^\w\d_ -]/si', '', $toClean));//remove all illegal chars $toClean = str_replace(' ', '-', $toClean); $toClean = str_replace('--', '-', $toClean); return strtolower($toClean); } function cleanForTags($toClean) { $toClean = str_replace('&', '-and-', $toClean); $toClean = trim(preg_replace('/[^\w\d_ -]/si', '', $toClean));//remove all illegal chars $toClean = str_replace(' ', ' ', $toClean); $toClean = str_replace(' ', ' ', $toClean); return strtolower($toClean); } function cleanForAttr($toClean) { //$toClean = json_encode(htmlspecialchars($toClean)); //$toClean = substr($toClean,1); //$toClean = substr($toClean,0,-1); $toClean = htmlspecialchars(strip_tags($toClean), ENT_QUOTES, 'UTF-8'); return $toClean; } function cleanForFilename($toClean,$appendTime=FALSE) { $at = ''; if($appendTime){ $at = '_' . substr(time(),-4); } if(strtolower(substr($toClean,-4)) == "jpeg"){ $fn = substr($toClean,0,-5); $ext = ".jpg"; }else if(strtolower(substr($toClean,-4)) == "tiff"){ $fn = substr($toClean,0,-5); $ext = ".tiff"; }else if(strtolower(substr($toClean,-3)) == "zip"){ $fn = substr($toClean,0,-4); $ext = ".zip"; }else if(strtolower(substr($toClean,-2)) == "ai"){ $fn = substr($toClean,0,-3); $ext = ".ai"; }else{ $fn = substr($toClean,0,-4); $ext = substr($toClean,-4); } $toClean = str_replace('&', '-and-', $fn); $toClean = str_replace('%20', '_', $toClean); $toClean = trim(preg_replace('/[^\w\d_ -]/si', '', $toClean));//remove all illegal chars $toClean = str_replace(' ', '-', $toClean); $toClean = str_replace('--', '-', $toClean); return strtolower($toClean . $at . $ext); } function build_sorter($key) { return function ($a, $b) use ($key) { return strnatcmp($a[$key], $b[$key]); }; } //usort($byOrder, build_sorter('date')); sort array of arrays by arrays key name ie 'date' or 'link', etc function reverseSecondHalfOfArray($arr){ $ret = array(); $cc = floor(count($arr) /2); for($i=0;$i 0){ //}else{ // insert the new record and get the new auto_increment id mysql_query("INSERT INTO {$table} (`{$id_field}`) VALUES (NULL)"); $newid = mysql_insert_id(); // generate the query to update the new record with the previous values $query = "UPDATE {$table} SET "; foreach ($original_record as $key => $value) { if ($key != $id_field) { if($x_id_field == $key){ $query .= '`'.$key.'` = "'.str_replace('"','\"',$x_id).'", '; }else if($y_id_field == $key){ $query .= '`'.$key.'` = "'.str_replace('"','\"',$y_id).'", '; }else if($z_id_field == $key){ $query .= '`'.$key.'` = "'.str_replace('"','\"',$z_id).'", '; }else if($q_id_field == $key){ $query .= '`'.$key.'` = "'.str_replace('"','\"',$q_id).'", '; }else{ $query .= '`'.$key.'` = "'.str_replace('"','\"',$value).'", '; } } } $query = substr($query,0,strlen($query)-2); # lop off the extra trailing comma $query .= " WHERE {$id_field}={$newid}"; mysql_query($query); return $newid; //} } //http://www.epigroove.com/posts/79/how%5Fto%5Fduplicate%5Fa%5Frecord%5Fin%5Fmysql%5Fusing%5Fphp //truncateHtml($co["rich"][0], 500, '.', false, true, true); function truncateHtml($text, $length = 100, $ending = '...', $exact = false, $periodspace = false, $considerHtml = true) { if ($considerHtml) { // if the plain text is shorter than the maximum length, return the whole text if (strlen(preg_replace('/<.*?>/', '', $text)) <= $length) { return $text; } // splits all html-tag to scanable lines preg_match_all('/(<.+?>)?([^<>]*)/s', $text, $lines, PREG_SET_ORDER); $total_length = strlen($ending); $open_tag = array(); $truncate = ''; foreach ($lines as $line_matchings) { // if there is any html-tag in this line, handle it and add it (uncounted) to the output if (!empty($line_matchings[1])) { // if it's an "empty element" with or without xhtml-conform closing slash if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $line_matchings[1])) { // do nothing // if tag is a closing tag } else if (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $line_matchings[1], $tag_matchings)) { // delete tag from $open_tag list $pos = array_search($tag_matchings[1], $open_tag); if ($pos !== false) { unset($open_tag[$pos]); } // if tag is an opening tag } else if (preg_match('/^<\s*([^\s>!]+).*?>$/s', $line_matchings[1], $tag_matchings)) { // add tag to the beginning of $open_tag list array_unshift($open_tag, strtolower($tag_matchings[1])); } // add html-tag to $truncate'd text $truncate .= $line_matchings[1]; } // calculate the length of the plain text part of the line; handle entities as one character $content_length = strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', ' ', $line_matchings[2])); if ($total_length+$content_length> $length) { // the number of characters which are left $left = $length - $total_length; $entities_length = 0; // search for html entities if (preg_match_all('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', $line_matchings[2], $entities, PREG_OFFSET_CAPTURE)) { // calculate the real length of all entities in the legal range foreach ($entities[0] as $entity) { if ($entity[1]+1-$entities_length <= $left) { $left--; $entities_length += strlen($entity[0]); } else { // no more characters left break; } } } $truncate .= substr($line_matchings[2], 0, $left+$entities_length); // maximum lenght is reached, so get off the loop break; } else { $truncate .= $line_matchings[2]; $total_length += $content_length; } // if the maximum length is reached, get off the loop if($total_length>= $length) { break; } } } else { if (strlen($text) <= $length) { return $text; } else { $truncate = substr($text, 0, $length - strlen($ending)); } } // if the words shouldn't be cut in the middle... if (!$exact) { // ...search the last occurance of a space... $spacepos = strrpos($truncate, ' '); if (isset($spacepos)) { // ...and cut the text in this position $truncate = substr($truncate, 0, $spacepos); } } if ($periodspace) { // ...search the last occurance of a space... $spacepos = strrpos($truncate, '.'); if (isset($spacepos)) { // ...and cut the text in this position $truncate = substr($truncate, 0, $spacepos); } } // add the defined ending to the text $truncate .= $ending; if($considerHtml) { // close all unclosed html-tag foreach ($open_tag as $tag) { $truncate .= ''; } } return $truncate; } function myTruncate($string2, $limit, $break=" ", $pad="..."){ $cleanRT0 = str_replace('
', ' - ',$string2); $cleanRT1 = preg_replace('#<[^>]+>#', ' ',$cleanRT0); $cleanRT2 = str_replace(" "," ",$cleanRT1); $string2 = htmlspecialchars($cleanRT2,ENT_QUOTES); $string = strip_tags($string2); if(strlen($string) <= $limit) return $string; $string = substr($string, 0, $limit); if(false !== ($breakpoint = strrpos($string, $break))) { $string = substr($string, 0, $breakpoint); } $ret = $string . $pad; return html_entity_decode($ret); } function arrayUnique($array, $preserveKeys = false){ $arrayRewrite = array(); $arrayHashes = array(); foreach($array as $key => $item) { $hash = md5(serialize($item)); if (!isset($arrayHashes[$hash])) { $arrayHashes[$hash] = $hash; if ($preserveKeys) { $arrayRewrite[$key] = $item; } else { $arrayRewrite[] = $item; } } } return $arrayRewrite; } function msort($array, $id="id") { $temp_array = array(); while(count($array)>0) { $lowest_id = 0; $index=0; foreach ($array as $item) { if (isset($item[$id]) && $array[$lowest_id][$id]) { if ($item[$id]<$array[$lowest_id][$id]) { $lowest_id = $index; } } $index++; } $temp_array[] = $array[$lowest_id]; $array = array_merge(array_slice($array, 0,$lowest_id), array_slice($array, $lowest_id+1)); } return $temp_array; } function getTweets($search_string,$limit=10) { //https://dev.twitter.com/docs/api/1.1/get/search/tweets $time = time(); // less 5 minutes $time_less = $time - 300; // less 5 minutes $a = 0; $tweetsQ = mysql_query("SELECT * FROM `tweets` WHERE `search_string`='$search_string' LIMIT 0,1"); while($line1 = mysql_fetch_assoc($tweetsQ)) { $tw = $line1["tweets_json"]; $twtime = $line1["timestamp"]; $tweets = json_decode($tw, true); $a .= 1; } if(!isset($twtime)){ $tw_json2 = getNewTweetsJson($search_string); $tw_json = mysql_real_escape_string($tw_json2); $query = "INSERT INTO `tweets` (`search_string`,`timestamp`,`tweets_json`) VALUES ('$search_string','$time','$tw_json')"; mysql_query($query) or die('Error, insert tweets failed ' . mysql_error()); $tweets = json_decode($tw_json2, true); $a .= 2; }else if($twtime > $time_less){ $a .= 3; }else{ $tw_json2 = getNewTweetsJson($search_string); $tw_json = mysql_real_escape_string($tw_json2); $query = "UPDATE `tweets` SET `timestamp`='$time',`tweets_json`='$tw_json' WHERE `search_string`='$search_string'"; mysql_query($query) or die('Error, update tweets failed ' . mysql_error()); $tweets = json_decode($tw_json2, true); $a .= 4; } $tweet = array(); $tt = 0; foreach ($tweets as $entry) { if($tt < $limit){ //break; $a .= 5; $text = trim($entry["text"]); $author = trim($entry["from_user_name"]); $time = trim($entry["created_at"]); $time = strtotime ('-8 hours' , strtotime($time)); // change the "8" to offset hours $time = date('n/j/y g:i a', $time); $id = $entry["id"]; $tweet[] = array("tweet"=>$text,"time"=>$time,"author"=>$author,"id"=>$id); $tt++; } } //$tweet[] = $a; return $tweet; } function getNewTweetsJson($search_string) { /* define('CONSUMER_KEY','KTtFs92fr5YWVwUiilE12A'); define('CONSUMER_SECRET','9nrlF84Q6YLwMSOs0VOei6QHWdptQtl9c1DQXA8pw'); define('ACCESS_TOKEN','31590752-NBaM1ylN8ckkt4ZiiZRqc1cNHOutT9S9Kz5KCY6or'); define('ACCESS_TOKEN_SECRET','ZOhsNq4ADtoVNpwgQgw5zuGqmr40New9DrpMkibUG4'); require_once('admin/twitteroauth-master/twitteroauth/twitteroauth.php'); $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); */ ///// return ""; /* global $connection; $timeline2 = $connection->get('search/tweets',array('q'=>$search_string)); $timeline = $timeline2->statuses; $json = json_encode($timeline); if(count($timeline)>0){ return $json; }else{ return ""; } */ } function stripVidId($var) { $wel = strpos($var, "://"); if ($wel > 0) { $pos = strpos($var, "youtube."); if ($pos > 0) { // is youtube parse_str( parse_url( $var, PHP_URL_QUERY ) ); return $v; }else{ // is vimeo $ar = explode("/",$var); return $ar[(count($ar) -1)]; } }else{ // do nothing return $var; } } function stripVidSrc($var) { if (strpos($var, "youtube.") > 0) { return 'youtube'; }else if (strpos($var, "vimeo.") > 0) { return 'vimeo'; } } function getVidImg($vid_source,$vid_id){ if($vid_source == "vimeo"){ $hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$vid_id.php")); $videoImg = $hash[0]['thumbnail_large']; }else{ $videoImg = "http://i2.ytimg.com/vi/" . $vid_id . "/hqdefault.jpg"; } $uploadDir = "../../files/"; $uploadNam = "v_" . $vid_source . "_" . $vid_id . "_" . substr(time(),-5) . ".jpg"; $uploadFile = $uploadDir . $uploadNam; $fc = file_get_contents($videoImg); file_put_contents($uploadFile, $fc); chmod($uploadFile, 0766); return $uploadNam; } function getStructure($page_id){ $structure = array(); $structureQ = mysql_query("SELECT * FROM `structure` WHERE `PAGE_ID`='$page_id'"); while($line1 = mysql_fetch_assoc($structureQ)) { $structure = json_decode($line1["structure_json"], true); } return $structure; } function getChildren($page_id, $block_id){ $structure = array(); $structureQ = mysql_query("SELECT `id`,`url`,`name1` FROM `page` WHERE (`PARENT_ID`,`BLOCK_ID`,`visible`)=('$page_id','$block_id','1') ORDER BY `order`"); $kids = array(); while($line1 = mysql_fetch_assoc($structureQ)) { $kids[] = $line1; } return $kids; } // SITE SPECIFIC - FOR URGENCY NETWORK // function getChildrenUN($page_id, $block_id){ $structure = array(); $structureQ = mysql_query("SELECT `id`,`SECTION_ID`,`url`,`name1` FROM `page` WHERE (`PARENT_ID`,`BLOCK_ID`,`visible`)=('$page_id','$block_id','1') ORDER BY `order` LIMIT 0,1"); $kids = array(); while($line1 = mysql_fetch_assoc($structureQ)) { $kids[] = $line1; } $specificContent = getPageContentNew($kids[0]["id"]); //mission impacto $entriesScale = getPageContentNew(766); $entriesArray = array('share'=>$entriesScale['bid_443']['content'][0], 'quiz'=>$entriesScale['bid_444']['content'][0], 'video'=>$entriesScale['bid_445']['content'][0], 'read'=>$entriesScale['bid_446']['content'][0], 'infographic'=>$entriesScale['bid_447']['content'][0], 'pledge'=>$entriesScale['bid_448']['content'][0], 'donate'=>$entriesScale['bid_449']['content'][0], 'ideas'=>$entriesScale['bid_459']['content'][0], ); $actionType = $specificContent['section']['url']; $kids[0]["mi_action_type"] = $actionType; $kids[0]["mi_points"] = $entriesArray[$actionType]; //urgency network $actionType = getActionType($specificContent["section"]["id"]); $entriesScaleId = $actionType["bid_1233"]["content"][0]["page_id"]; $entriesScale = getPageContentNew($entriesScaleId); $kids[0]["parent_page_id"] = $page_id; $kids[0]["parent_block_id"] = $block_id; $kids[0]["action_thumb"] = $actionType["lead_img"]; $kids[0]["action_type_id"] = $actionType["page"]["id"]; $kids[0]["entries_scale_id"] = $entriesScaleId; $kids[0]["entries"] = $entriesScale["bid_1182"]["content"][0]; $kids[0]["entries_limit"] = $entriesScale["bid_1203"]["content"][0]; $kids[0]["content"] = $specificContent; $kids[0]["action_type"] = $actionType; return $kids; } function getActionType($section_id){ $actionTypesSectionId = 210; $actionTypesSectionIDBlockId = 1306; $postQ = mysql_query("SELECT `PAGE_ID` FROM `post` WHERE (`BLOCK_ID`,`number`)=('$actionTypesSectionIDBlockId','$section_id') LIMIT 0,1"); while($line1 = mysql_fetch_assoc($postQ)) { $page_id = $line1["PAGE_ID"]; } $pageContent = getPageContentNew($page_id); return $pageContent; } //end SITE SPECIFIC - FOR URGENCY NETWORK // function getDbEntryForRelatedBlock($related_DB_TABLE,$db_id){ $pageQ = mysql_query("SELECT * FROM `$related_DB_TABLE` WHERE `id`='$db_id' AND `active`='1'"); while($line1 = mysql_fetch_assoc($pageQ)) { return $line1; } return 0; } function getPageForRelatedBlock($page_id){ global $blockTypes; $simple = array(); $min = array(); $noPage = 0; $pageQ = mysql_query("SELECT * FROM `page` WHERE `id`='$page_id' AND `visible`='1'"); while($line1 = mysql_fetch_assoc($pageQ)) { $noPage = 1; } if($noPage == 0){ return 0; } $blockQ = mysql_query("SELECT `block`.* FROM `block`,`page` WHERE `page`.`id`='$page_id' AND `block`.`BLOCK_TYPES_ID`='1' AND `block`.`SECTION_ID`=`page`.`SECTION_ID` ORDER BY `block`.`order` LIMIT 0,1"); while($line1 = mysql_fetch_assoc($blockQ)) { $min[] = $line1; } $blockQ = mysql_query("SELECT `block`.* FROM `block`,`page` WHERE `page`.`id`='$page_id' AND (`block`.`BLOCK_TYPES_ID`='3' OR `block`.`BLOCK_TYPES_ID`='4') AND `block`.`SECTION_ID`=`page`.`SECTION_ID` ORDER BY `block`.`order` LIMIT 0,1"); while($line1 = mysql_fetch_assoc($blockQ)) { $min[] = $line1; } $simple[] = $page_id; foreach($min as $line1){ // this attached the $blockTypes array to the $line1 foreach($blockTypes as $type){ if($type["id"] == $line1["BLOCK_TYPES_ID"]){ $line1["type"] = $type; break; } } $postQ = mysql_query("SELECT * FROM `post` WHERE (`BLOCK_ID`,`PAGE_ID`)=('".$line1["id"]."','$page_id') LIMIT 0,1"); while($line2 = mysql_fetch_assoc($postQ)) { if($line1["BLOCK_TYPES_ID"] == 4){ // is gall - get kid instead $kidsQ = mysql_query("SELECT * FROM `post` WHERE (`PARENT_ID`)=('".$line2["id"]."') ORDER BY `order` LIMIT 0,1"); while($line3 = mysql_fetch_assoc($kidsQ)) { $line2 = $line3; } } $arr = array("block_name" => $line1["name1"]); foreach($line2 as $key => $val){ $arr[$key] = $val; } $simple[] = $arr[$line1["type"]["fields"][0]]; // need to loop fields } } //$simple[] = getURLfromPageId($page_id); return $simple; } function getRelatedPageIdsFrom($from_section_url,$for_page_id,$limit=3){ $from_section_idQ = mysql_query("SELECT `id` FROM `section` WHERE `url`='$from_section_url' LIMIT 0,1"); while($line1 = mysql_fetch_assoc($from_section_idQ)) { $from_section_id = $line1["id"]; } $pageIdsQ = mysql_query("SELECT `page`.`id` FROM `page`,`block`,`post` WHERE `block`.`SECTION_ID`='$from_section_id' AND `block`.`BLOCK_TYPES_ID`='17' AND `post`.`BLOCK_ID` = `block`.`id` AND `post`.`number` = '$for_page_id' AND `post`.`PAGE_ID` = `page`.`id` AND `page`.`visible` = '1' ORDER BY `page`.`order` LIMIT 0,$limit "); $pageIds = array(); while($line1 = mysql_fetch_assoc($pageIdsQ)) { $pageIds[] = $line1["id"]; } return $pageIds; //array(); //$rel; } function getPageGroupingsForList($section_id,$block_id){ $groups = array(); $groups["all"] = array("name1" => "All", "id" => $block_id); $groupsQ = mysql_query("SELECT `GROUP_ID` FROM `group_page_x` WHERE `BLOCK_ID`='$block_id'"); while($line1 = mysql_fetch_assoc($groupsQ)) { $groupQ = mysql_query("SELECT * FROM `group` WHERE `id` = '".$line1["GROUP_ID"]."' ORDER BY `order` "); while($line2 = mysql_fetch_assoc($groupQ)) { $groups[$line2["name1"]] = $line2; } } return $groups; } function getPagesFromSectionWithTheseGroupIds($section_id,$group_ids,$limit=0,$assoc=1,$DESC=''){ // $group_ids must be a string, comma delimited ie '14' or '14,33,55' $lim = ($limit>0?'LIMIT 0,' .$limit:''); $pages = array(); $groupsQ = mysql_query("SELECT DISTINCT `page`.`id` FROM `page`,`group_page_x` WHERE `group_page_x`.`GROUP_ID` in ($group_ids) AND `group_page_x`.`PAGE_ID` = `page`.`id` AND `page`.`SECTION_ID` = '$section_id' AND `page`.`visible` = 1 AND `page`.`hide` = 0 ORDER BY `page`.`id` $DESC $lim "); while($line1 = mysql_fetch_assoc($groupsQ)) { if($assoc){ $pages[] = $line1; }else{ $pages[] = $line1['id']; } } return $pages; } function getGroupAndSubs($block_id){ $grps = array(); $grps["all"] = array("name1" => "All", "id" => $block_id); $groupQ = mysql_query("SELECT * FROM `block` WHERE `id`='$block_id' LIMIT 0,1"); while($grp = mysql_fetch_assoc($groupQ)) { $group_id = $grp["related_GROUP_ID"]; } $grpQ = mysql_query("SELECT * FROM `group` WHERE `id`='$group_id' LIMIT 0,1"); while($line1 = mysql_fetch_assoc($grpQ)) { $grp = $line1; } //$grps = array(); $grpsQ = mysql_query("SELECT * FROM `group` WHERE `PARENT_ID`='".$grp["id"]."' ORDER BY `order`"); while($line1 = mysql_fetch_assoc($grpsQ)) { $line1['indent'] = 0; array_push($grps, $line1); // $gid1 = $line1['id']; $grps2Q = mysql_query("SELECT * FROM `group` WHERE `PARENT_ID`='$gid1' ORDER BY `order`"); while($line2 = mysql_fetch_assoc($grps2Q)) { $line2['indent'] = 1; array_push($grps, $line2); // $gid2 = $line2['id']; $grps3Q = mysql_query("SELECT * FROM `group` WHERE `PARENT_ID`='$gid2' ORDER BY `order`"); while($line3 = mysql_fetch_assoc($grps3Q)) { $line3['indent'] = 2; array_push($grps, $line3); } } } return $grps; //return $groupy; } function getPageRelationsForList($section_id,$block_id){ $pages = array(); $pages["all"] = array("name1" => "All", "id" => $block_id); $pageQ = mysql_query("SELECT `id` FROM `page` WHERE `SECTION_ID`='$section_id'"); while($line1 = mysql_fetch_assoc($pageQ)) { $page_id = $line1["id"]; $pagesQ = mysql_query("SELECT `page`.* FROM `page`,`post` WHERE `post`.`PAGE_ID` = '$page_id' AND `post`.`BLOCK_ID` = '$block_id' AND `post`.`number` = `page`.`id` "); while($line2 = mysql_fetch_assoc($pagesQ)) { $pages[$line2["url"]] = $line2; } } return $pages; } // this is for the ADMIN logic.php file, do not change function getPageAssociationsForList($section_id,$block_id){ $pages = array(); $pages["all"] = array("name1" => "All", "url" => "all", "id" => $block_id, "order" => 0); $pageQ = mysql_query("SELECT `id`,`name1` FROM `page` WHERE `SECTION_ID`='$section_id'"); while($line1 = mysql_fetch_assoc($pageQ)) { $page_id = $line1["id"]; $page_name = $line1["name1"]; $assoc = array(); $tagQ = mysql_query("SELECT `assoc_PAGE_ID` FROM `page_block_apage_x` WHERE `PAGE_ID`='".$page_id."' AND `BLOCK_ID`='".$block_id."' ORDER BY `order`"); while($lineT = mysql_fetch_assoc($tagQ)) { $ass = array(); $ass_id = $ass["id"] = $lineT["assoc_PAGE_ID"]; $ass_id = $ass["id"]; $page2Q = mysql_query("SELECT `name1`,`url`,`order` FROM `page` WHERE `id`='$ass_id'"); while($lineAss = mysql_fetch_assoc($page2Q)) { $ass["name1"] = $lineAss['name1']; $ass["url"] = $lineAss['url']; $ass["order"] = $lineAss['order']; } //$rela = getPageContentAll_db($ass["id"],"bid"); //$ass["name1"] = $page_name; $pages[$ass["name1"]] = $ass; } } //this will sort the array by order of the associated pages order usort($pages, build_sorter('order')); return $pages; } function getAllRelatedPageIds($for_page_id){ $pageIdsQ = mysql_query("SELECT `page`.`id` FROM `page`,`block`,`post` WHERE `block`.`BLOCK_TYPES_ID`='17' AND `post`.`BLOCK_ID` = `block`.`id` AND `post`.`number` = '$for_page_id' AND `post`.`PAGE_ID` = `page`.`id` AND `page`.`visible` = '1' "); $pageIds = array(); while($line1 = mysql_fetch_assoc($pageIdsQ)) { $pageIds[] = $line1["id"]; } return $pageIds; //array(); //$rel; } function getRelatedUrl($to_section_url,$from_page_id){ $fromQ = mysql_query("SELECT * FROM `page` WHERE `id`='$from_page_id'"); while($line1 = mysql_fetch_assoc($fromQ)) { $from_section_id = $line1["SECTION_ID"]; } $toQ = mysql_query("SELECT * FROM `section` WHERE `url`='$to_section_url'"); while($line1 = mysql_fetch_assoc($toQ)) { $to_section_id = $line1["id"]; } $to_pageQ = mysql_query("SELECT `page`.* FROM `page`,`block` WHERE `block`.`SECTION_ID`='$from_section_id' AND `block`.`related_SECTION_ID`='$to_section_id' AND `page`.`SECTION_ID` = '$to_section_id' "); $to_page = ""; while($line1 = mysql_fetch_assoc($to_pageQ)) { $to_page .= $line1["id"] . ","; } $to_page = substr($to_page,0,-1); return $from_page_id ."= ".$to_page; $the_pageQ = mysql_query("SELECT `page`.* FROM `page`,`post` WHERE `page`.`id` in ($to_page) AND `post`.`PAGE_ID` = `page`.`id` AND `post`.`number` = '$from_page_id' ORDER BY `page`.`order` LIMIT 0,1 "); $the_page = ""; while($line1 = mysql_fetch_assoc($the_pageQ)) { $the_page .= $line1["id"] . "/" . $line1["url"]; } return "/" . $to_section_url . "/" . $the_page; } function getURLfromPageId($page_id){ $hasSubPages = 0; $section_url = ""; //check for force native child page url to associated parent section $pagePQ = mysql_query("SELECT `PARENT_ID`,`BLOCK_ID` FROM `page` WHERE `id`=$page_id LIMIT 0,1"); while($line1 = mysql_fetch_assoc($pagePQ)) { $pageParId = $line1['PARENT_ID']; $pageBlockId = $line1['BLOCK_ID']; } $parSectId = 0; if($pageParId > 0){ $blockPQ = mysql_query("SELECT `SECTION_ID` FROM `block` WHERE `id`=$pageBlockId AND `gall_has_vid` = 1 LIMIT 0,1"); while($line1 = mysql_fetch_assoc($blockPQ)) { $parSectId = $line1['SECTION_ID']; } } if($parSectId > 0){ $sectionQ = mysql_query("SELECT * FROM `section` WHERE `id`=$parSectId LIMIT 0,1"); }else{ $sectionQ = mysql_query("SELECT `section`.* FROM `section`,`page` WHERE `section`.`id`=`page`.`SECTION_ID` AND `page`.`id`=$page_id LIMIT 0,1"); } while($line1 = mysql_fetch_assoc($sectionQ)) { // if a section is a pages of a page section if($line1["PAGE_ID"] > 0){ $ppid = $line1["PAGE_ID"]; $pageQ = mysql_query("SELECT `page`.* FROM `page` WHERE `page`.`id`=$ppid LIMIT 0,1"); while($linePP = mysql_fetch_assoc($pageQ)) { $pageS_id = $linePP["SECTION_ID"]; $section2Q = mysql_query("SELECT `section`.* FROM `section`,`page` WHERE `section`.`id`=$pageS_id LIMIT 0,1"); while($line1s = mysql_fetch_assoc($section2Q)) { $section_url .= "/" . $line1s["url"]; $sec_id = $line1s["id"]; } $section_url .= "/" . $ppid . "/" . $linePP["url"]; } } if($line1["landing_slave"] == 1){ $landingSlaveParSectId = $line1["PARENT_ID"]; } $section_url .= "/" . $line1["url"]; $hasDet = $line1["has_detail"]; } if($hasDet || $parSectId > 0){ $pageQ = mysql_query("SELECT `url` FROM `page` WHERE `id`=$page_id LIMIT 0,1"); while($line1 = mysql_fetch_assoc($pageQ)) { $section_url .= "/" . $page_id . "/" . $line1["url"]; } } if($hasDet == 0 || $parSectId > 0){ $pageQ = mysql_query("SELECT `url` FROM `page` WHERE `id`=$pageParId LIMIT 0,1"); while($line1 = mysql_fetch_assoc($pageQ)) { $section_url = '/' . $line1["url"]; } } if($landingSlaveParSectId > 0){ $section2Q = mysql_query("SELECT `url` FROM `section` WHERE `id`='$landingSlaveParSectId' LIMIT 0,1"); while($line1s = mysql_fetch_assoc($section2Q)) { $section_url = "/" . $line1s["url"]; } } return $section_url; } function getPageAndContent($page_id,$j="both",$lang_id=1){ $pageQ = mysql_query("SELECT * FROM `page` WHERE `id`='$page_id' LIMIT 0,1"); while($line1 = mysql_fetch_assoc($pageQ)) { $page = $line1; } $page['content'] = getPageContentAll_db($page_id,$j,$lang_id); return $page; } function getContent($page_id,$j="both",$lang_id=1){ return getPageContentAll_db($page_id,$j,$lang_id); } function getPageContentAll_db($page_id,$j="both",$lang_id=1){ $content = array(); $contentQ = mysql_query("SELECT * FROM `content` WHERE `PAGE_ID`='$page_id' AND `LANG_ID`='$lang_id' LIMIT 0,1"); while($line1 = mysql_fetch_assoc($contentQ)) { $content["typ"] = json_decode($line1["content_json_typ"], true); $content["bid"] = json_decode($line1["content_json_bid"], true); $content["alias"] = json_decode($line1["content_json_alias"], true); } if(!empty($content["typ"]["relation"])){ for($i=0;$i'0' AND `BLOCK_TYPES_ID`='21' LIMIT 0,1"); while($linep3 = mysql_fetch_assoc($page3Q)) { $block_parent_id = $linep3["PARENT_ID"]; } if($block_parent_id){ $page3Q = mysql_query("SELECT * FROM `block` WHERE `id`='$block_parent_id' AND `block_from_SECTION_ID`>'0' AND `BLOCK_TYPES_ID`='21' LIMIT 0,1"); while($linep3 = mysql_fetch_assoc($page3Q)) { $block_section_id = $linep3["block_from_SECTION_ID"]; } //$content["fuckme"][] = $block_section_id; } } $sectionQ = mysql_query("SELECT `section`.* FROM `section`,`page` WHERE `page`.`id`='$page_id' AND `page`.`SECTION_ID`=`section`.`id` LIMIT 0,1"); while($line1 = mysql_fetch_assoc($sectionQ)) { $content["root_url"] = $line1["url"]; $content["root"] = $line1["name1"]; $section2Q = mysql_query("SELECT * FROM `section` WHERE `id`='".$line1["PARENT_ID"]."' LIMIT 0,1"); while($line2 = mysql_fetch_assoc($section2Q)) { $content["root_url"] = $line2["url"]; $content["root"] = $line2["name1"]; } } if(isset($block_section_id)){ // is a child page of a pages page, yea crzy i know.. $blockQ = mysql_query("SELECT `block`.* FROM `block` WHERE `block`.`SECTION_ID`='$block_section_id' ORDER BY `block`.`order`"); }else{ $blockQ = mysql_query("SELECT `block`.* FROM `block`,`page` WHERE `page`.`id`='$page_id' AND `block`.`SECTION_ID`=`page`.`SECTION_ID` ORDER BY `block`.`order`"); } $blockNum = 0; while($line1 = mysql_fetch_assoc($blockQ)) { $blockNum++; foreach($blockTypes as $type){ if($type["id"] == $line1["BLOCK_TYPES_ID"]){ $line1["type"] = $type; break; } } $this_block_id = $line1["id"]; $block = $line1; /* if($line1["BLOCK_TYPES_ID"] == 21 && $line1["PARENT_ID"] > 0){ ///??? $block2Q = mysql_query("SELECT * FROM `block` WHERE `id`='".$line1["PARENT_ID"]."' LIMIT 0,1"); while($lineb1 = mysql_fetch_assoc($block2Q)) { //$pagecQ = mysql_query("SELECT * FROM `section` WHERE `id`='".$lineb1["block_from_SECTION_ID"]."' LIMIT 0,1"); //$this_block_id = $lineb1["id"]; } }else{ */ //$fields = implode(",",$line1["type"]["fields"]); // you can sub * below with $fields, but it will exclude other fields $postQ = mysql_query("SELECT * FROM `post` WHERE (`BLOCK_ID`,`PAGE_ID`,`visible`)=('$this_block_id','$page_id','1') ORDER BY `order`"); //} while($line2 = mysql_fetch_assoc($postQ)) { $arr = array(); foreach($line2 as $key => $val){ $arr[$key] = $val; } $data = array(); $related = array(); $gallery = array(); $video = array(); $group = array(); //$db = array(); $post = $line2; foreach($line1["type"]["fields"] as $field){ if($line1["type"]["name1"] == "Address"){ $content["address"][] = $arr[$field]; }else if($line1["type"]["name1"] == "Telephone"){ $content["telephone"][] = $arr[$field]; }else if($line1["type"]["name1"] == "Checkbox"){ $content["checkbox"][] = $arr[$field]; }else if($line1["type"]["name1"] == "Timestamp"){ $content["timestamp"][] = $arr[$field]; }else if($line1["type"]["name1"] == "Link" && $blockNum == 1){ if($field == "long_text"){ $content["url"] = $arr[$field]; } }else if($line1["type"]["name1"] == "Link"){ $content["link"][] = $arr[$field]; }else if($line1["type"]["name1"] == "Video"){ $video[] = $arr[$field]; }else if($line1["type"]["name1"] == "Database Relation"){ if($field == "number" && $arr[$field]){ $block_rel_table = $block['related_DB_TABLE']; $post_number = $post['number']; $dbQ = mysql_query("SELECT * FROM `$block_rel_table` WHERE `id`='$post_number'"); while($lineDB = mysql_fetch_assoc($dbQ)) { //$db[] = $lineDB; $content["$db"][] = $lineDB; } }else{ //$related["custom"][] = $arr[$field]; //Related Title } }else if($line1["type"]["name1"] == "Relation"){ if($field == "number" && $arr[$field]){ if($getRelated){ //$related["page_id"] = $arr[$field]; $related["page_id"] = 0; $pageRQ = mysql_query("SELECT * FROM `page` WHERE `id`='".$arr[$field]."' AND `visible`='1' LIMIT 0,1"); while($lineR2 = mysql_fetch_assoc($pageRQ)) { $related["page_id"] = $arr[$field]; } //$related["basic"] = getPageContentAll($arr[$field],0); //$related["basic"] = getPageContentAll_db($arr[$field],0); // DON'T DO THIS!! } }else{ $related["custom"][] = $arr[$field]; //Related Title } }else if($line1["type"]["name1"] == "Image Gallery"){ if($getRelated){ $gallery[] = $arr[$field]; } }else if($line1["type"]["name1"] == "File"){ $content["file"][] = $arr[$field]; }else if($line1["type"]["name1"] == "Image"){ $content["images"][] = $arr[$field]; }else if($line1["type"]["name1"] == "Pages"){ $content["section"] = getStructure($page_id); }else if($line1["type"]["name1"] == "Children"){ $content["children"] = getChildren($page_id, $this_block_id); }else if($line1["type"]["name1"] == "Variations"){ $content["variations"] = getChildren($page_id, $this_block_id); }else if($line1["type"]["name1"] == "Raw Text"){ $content["raw"][] = $arr[$field]; }else if($line1["type"]["name1"] == "Price"){ $content["price"][] = $arr[$field]; }else if($line1["type"]["name1"] == "Color"){ $content["color"][] = $arr[$field]; }else if($field == "file_name"){ $content["files"][] = $arr[$field]; }else if($field == "rich_text"){ //if($getRelated){ $content["rich"][] = $arr[$field]; //} }else if($field == "date"){ $content["date"][] = $arr[$field]; }else{ $content["text"][] = $arr[$field]; } if($field == "file_name" && empty($content["lead_img"])){ if($line1["type"]["name1"] == "Image Gallery"){ $content["lead_img"] = $arr[$field]; }else if($line1["type"]["name1"] == "Image"){ $content["lead_img"] = $arr[$field]; }else if($line1["type"]["name1"] == "Video"){ $content["lead_img"] = $arr[$field]; } } } if($line1["type"]["name1"] == "Size SKU Qty"){ $ssqQ = mysql_query("SELECT * FROM `ssq` WHERE `PAGE_ID`='".$page_id."' ORDER BY `order`"); while($line3 = mysql_fetch_assoc($ssqQ)) { $content["ssq"][] = $line3; } } if($line1["type"]["name1"] == "Video" && $video[0]){ $content["video"][] = $video; } if($line1["type"]["name1"] == "Grouping"){ $groupQ = mysql_query("SELECT `group`.* FROM `group`,`group_page_x` WHERE `group_page_x`.`PAGE_ID`='".$page_id."' AND `group_page_x`.`GROUP_ID`=`group`.`id` ORDER BY `group`.`order`"); while($lineG = mysql_fetch_assoc($groupQ)) { $content["group"][] = $lineG; } } //if($line1["type"]["name1"] == "Relation" && $getRelated && isset($related["basic"])){ if($line1["type"]["name1"] == "Relation" && $getRelated && $related["page_id"] > 0){ $content["relation"][] = $related; } if($line1["type"]["name1"] == "Image Gallery" && $arr["PARENT_ID"] != 0 && $getRelated){ $content["gallery"][] = $gallery; } } } if(!isset($content["lead_img"]) || strlen($content["lead_img"]) < 5){ //$site_info = getPageContent_db(1); //$content["lead_img"] = $site_info["Place Holder Image"][0]; } if(!isset($content["url"])){ $content["url"] = getURLfromPageId($page_id); } return $content; } function getPageContent_db($page_id){ $contentQ = mysql_query("SELECT * FROM `content` WHERE `PAGE_ID`='$page_id' LIMIT 0,1"); while($line1 = mysql_fetch_assoc($contentQ)) { $content = json_decode($line1["content_json_bid"], true); } return $content; } function buildShareURL($pageID,$addUID=1){ $uID = Auth::getUserID(); $shorty = new App_Shorty(); $pageCode = $shorty->encode($pageID); $shareURL = SHARE_URL.$pageCode; //$shareURL=''; $userCode=0; if($uID > 0 && $addUID==1){ $userCode = $shorty->encode($uID); $shareURL .= ':'.$userCode; } return $shareURL; } function getAndUpdateBitly($page_id){ global $siteURL; $linkName = getURLfromPageId($page_id); $link = substr($siteURL,0,-1) . $linkName; $bitly = json_decode(file_get_contents("http://api.bit.ly/v3/shorten?login=o_10rh6otqn&apiKey=R_47a4a7f9a56808553e13a55cd63e75fd&longUrl=".urlencode($link)."&format=json"))->data->url; if(!empty($bitly)){ $query = "UPDATE `page` SET `bitly`='$bitly' WHERE `id`='$page_id'"; mysql_query($query) or die('Error, query failed updating bitly ' . mysql_error()); } return $bitly; } function getPageContentNew($page_id,$lang_id=1){ // this is for 'bid' global $blockTypes; $simple = array(); $pageQ = mysql_query("SELECT * FROM `page` WHERE `id`='$page_id' LIMIT 0,1"); while($line1 = mysql_fetch_assoc($pageQ)) { $page = $line1; } $sectionQ = mysql_query("SELECT `id`,`PARENT_ID`,`PAGE_ID`,`name1`,`url`,`hide`,`order` FROM `section` WHERE `id`='".$page["SECTION_ID"]."' LIMIT 0,1"); while($line1 = mysql_fetch_assoc($sectionQ)) { $section = $line1; $section2Q = mysql_query("SELECT * FROM `section` WHERE `id`='".$line1["PARENT_ID"]."' LIMIT 0,1"); while($line2 = mysql_fetch_assoc($section2Q)) { $root = $line2; } if(empty($root)){ $root = $section; } } $simple["page_link"] = getURLfromPageId($page_id); $simple["bitly"] = $page["bitly"]; $simple["root_url"] = $root["url"]; $simple["root"] = $root["name1"]; $simple["lead_img"] = ""; $simple["rich_snippet"] = ""; if(!empty($page)){ foreach($page as $key=>$val){ $simple["page"][$key] = $val; } } if(isset($section)){ foreach($section as $key=>$val){ $simple["section"][$key] = $val; } } $blockQ = mysql_query("SELECT `block`.* FROM `block`,`page` WHERE `page`.`id`='$page_id' AND `block`.`visible` = 1 AND `block`.`SECTION_ID`=`page`.`SECTION_ID` ORDER BY `block`.`order`"); while($line1 = mysql_fetch_assoc($blockQ)) { foreach($blockTypes as $type){ if($type["id"] == $line1["BLOCK_TYPES_ID"]){ $line1["type"] = $type; break; } } $this_block_id = $line1["id"]; $this_block_GROUP_ID = $line1["related_GROUP_ID"]; $block = $line1; $postQ = mysql_query("SELECT * FROM `post` WHERE (`BLOCK_ID`,`PAGE_ID`,`visible`)=('".$line1["id"]."','$page_id','1') ORDER BY `order`"); $data = array(); while($line2 = mysql_fetch_assoc($postQ)) { $post_id = $line2['id']; if($lang_id > 1){ $langQ = mysql_query("SELECT * FROM `languages_text` WHERE (`POST_ID`,`LANG_ID`)=('$post_id','$lang_id') LIMIT 0,1"); while($lineL = mysql_fetch_assoc($langQ)) { $line2["short_text"] = $lineL["short_text"]; $line2["long_text"] = $lineL["long_text"]; $line2["rich_text"] = $lineL["rich_text"]; } } $post = $line2; $arr = array(); foreach($line2 as $key => $val){ $arr[$key] = $val; } $gallery = array(); $relation = array(); foreach($line1["type"]["fields"] as $field){ if($line1["type"]["name1"] == "Image Gallery"){ if($field == 'img_alt' && empty($arr[$field])){ $arr[$field] = $simple["page"]["name1"]; } $gallery[] = $arr[$field]; }else if($line1["type"]["name1"] == "Relation"){ if($field == "number" && $arr[$field]){ // //$relation["page_id"] = $arr[$field]; $relation["page_id"] = 0; $pageRQ = mysql_query("SELECT * FROM `page` WHERE `id`='".$arr[$field]."' AND `visible`='1' LIMIT 0,1"); while($lineR2 = mysql_fetch_assoc($pageRQ)) { $relation["page_id"] = $arr[$field]; } }else{ $relation["custom_title"] = $arr[$field]; //Related Title } }else if($line1["type"]["name1"] == "Database Relation"){ if($field == "number" && $arr[$field]){ // $block_rel_table = $block['related_DB_TABLE']; $post_number = $post['number']; $dbQ = mysql_query("SELECT * FROM `$block_rel_table` WHERE `id`='$post_number'"); while($lineDB = mysql_fetch_assoc($dbQ)) { $data[] = $lineDB; } }else{ //$relation["custom_title"] = $arr[$field]; //Related Title } }else{ $data[] = $arr[$field]; } if($field == "file_name" && empty($simple["lead_img"])){ if($line1["type"]["name1"] == "Image Gallery"){ $simple["lead_img"] = $arr[$field]; }else if($line1["type"]["name1"] == "Image"){ $simple["lead_img"] = $arr[$field]; }else if($line1["type"]["name1"] == "Video"){ $simple["lead_img"] = $arr[$field]; } } if($field == "rich_text" && empty($simple["rich_snippet"])){ if($line1["type"]["name1"] == "Rich Text"){ $simple["rich_snippet"] = html_entity_decode(myTruncate($arr[$field],250,".",".")); //$simple["rich_snippet"] = myTruncate($arr[$field],250,".","."); } } } if($line1["type"]["name1"] == "Image Gallery"){ if($line2["PARENT_ID"] > 0){ $data[] = $gallery; } }else if($line1["type"]["name1"] == "Relation"){ $rpid = $relation["page_id"]; if($rpid > 0){ $rela = getPageContentAll_db($rpid,"bid"); $relation["name1"] = $rela["page"]["name1"]; $relation["section_name1"] = $rela["section"]["name1"]; $relation["page_link"] = $rela["page_link"]; $relation["lead_img"] = $rela["lead_img"]; $relation["rich_snippet"] = $rela["rich_snippet"]; $data[] = $relation; } }else if($line1["type"]["name1"] == "Associations"){ $assoc = array(); $tagQ = mysql_query("SELECT `assoc_PAGE_ID` FROM `page_block_apage_x` WHERE `PAGE_ID`='".$page_id."' AND `BLOCK_ID`='".$this_block_id."' ORDER BY `order`"); while($lineT = mysql_fetch_assoc($tagQ)) { $ass = array(); $ass["id"] = $lineT["assoc_PAGE_ID"]; $rela = getPageContentAll_db($ass["id"],"bid"); $ass["name1"] = $rela["page"]["name1"]; $ass["url"] = $rela["page"]["url"]; $assoc[] = $ass; } $data = $assoc; }else if($line1["type"]["name1"] == "Tags"){ $tag = array(); $tagQ = mysql_query("SELECT DISTINCT `tag`.* FROM `tag`,`tag_page_block_x` WHERE `tag_page_block_x`.`PAGE_ID`='".$page_id."' AND `tag_page_block_x`.`BLOCK_ID`='".$this_block_id."' AND `tag_page_block_x`.`TAG_ID`=`tag`.`id` ORDER BY `tag`.`tag`"); while($lineT = mysql_fetch_assoc($tagQ)) { $tag[] = $lineT; } $data = $tag; }else if($line1["type"]["name1"] == "Grouping"){ $group = array(); $groupQ = mysql_query("SELECT DISTINCT `group`.* FROM `group`,`group_page_x` WHERE `group`.`PARENT_ID`='$this_block_GROUP_ID' AND `group_page_x`.`PAGE_ID`='".$page_id."' AND `group_page_x`.`GROUP_ID`=`group`.`id` AND `group_page_x`.`BLOCK_ID`='".$this_block_id."' ORDER BY `group`.`order`"); while($lineG = mysql_fetch_assoc($groupQ)) { $thig1id = $lineG['id']; $group2Q = mysql_query("SELECT DISTINCT `group`.* FROM `group`,`group_page_x` WHERE `group`.`PARENT_ID`='$thig1id' AND `group_page_x`.`PAGE_ID`='".$page_id."' AND `group_page_x`.`GROUP_ID`=`group`.`id` AND `group_page_x`.`BLOCK_ID`='".$this_block_id."' ORDER BY `group`.`order`"); while($line2Q = mysql_fetch_assoc($group2Q)) { $thig2id = $line2Q['id']; $group3Q = mysql_query("SELECT DISTINCT `group`.* FROM `group`,`group_page_x` WHERE `group`.`PARENT_ID`='$thig2id' AND `group_page_x`.`PAGE_ID`='".$page_id."' AND `group_page_x`.`GROUP_ID`=`group`.`id` AND `group_page_x`.`BLOCK_ID`='".$this_block_id."' ORDER BY `group`.`order`"); while($line3Q = mysql_fetch_assoc($group3Q)) { $line2Q['sub_groups'][] = $line3Q; } $lineG['sub_groups'][] = $line2Q; } $group[] = $lineG; } $data = $group; }else if($line1["type"]["name1"] == "Pages"){ $stru = getStructure($page_id); $struViz = array(); foreach($stru as $st){ foreach($st as $key=>$val){ if($key == "visible" && $val == 1){ $struViz[] = $st; } } } $data = $struViz; }else if($line1["type"]["name1"] == "Children"){ $data = getChildren($page_id,$this_block_id); }else if($line1["type"]["name1"] == "Variations"){ $data = getChildren($page_id,$this_block_id); }else if($line1["type"]["name1"] == "Child From Sub-Sections"){ //$data = getChildren($page_id,$this_block_id); // SITE SPECIFIC - FOR URGENCY NETWORK // $data = getChildrenUN($page_id,$this_block_id); // SITE SPECIFIC - FOR URGENCY NETWORK // //un override if($simple["bid_1364"]["content"][0] > 0){ $data[0]["entries"] = $simple["bid_1364"]["content"][0]; } //mi override if($simple["bid_450"]["content"][0] > 0){ $data[0]["mi_points"] = $simple["bid_450"]["content"][0]; } }else if($line1["type"]["name1"] == "Size SKU Qty" || $line1["type"]["name1"] == "Size SKU Qty Price"){ $ssq = array(); $ssqQ = mysql_query("SELECT * FROM `ssq` WHERE `PAGE_ID`='$page_id' ORDER BY `order`"); while($lineSSQ = mysql_fetch_assoc($ssqQ)) { $ssq[] = $lineSSQ; } $data = $ssq; }else if($line1["type"]["name1"] == "Schedule"){ $data = array(); $ssqQ = mysql_query("SELECT * FROM `schedule` WHERE `PAGE_ID`='$page_id'"); while($lineSSQ = mysql_fetch_assoc($ssqQ)) { $lineSSQ['events'] = getEventsFromSchedule($lineSSQ['id']); $data = $lineSSQ; } } } $this_block_id = "bid_".$line1["id"]; $simple[$this_block_id]["block_name"] = $line1["name1"]; $simple[$this_block_id]["block_type"] = $line1["type"]["name1"]; $simple[$this_block_id]["block_alias"] = $line1["alias"]; $simple[$this_block_id]["post_id"] = $post_id; $simple[$this_block_id]["content"] = $data; } //if(!empty($simple['lead_img'])){ if($simple['lead_img'] != $page['lead_img']){ $leadimg = $simple['lead_img']; $query = "UPDATE `page` SET `lead_img`='$leadimg' WHERE `id`='$page_id'"; mysql_query($query) or die('Error, insert PAGE query failed'); } //} return $simple; } function getPageContent($page_id){ //used in /for basic site info only, it's good for specific block name targeting global $blockTypes; $content = array(); $simple = array(); $blockQ = mysql_query("SELECT `block`.* FROM `block`,`page` WHERE `page`.`id`='$page_id' AND `block`.`SECTION_ID`=`page`.`SECTION_ID` ORDER BY `block`.`order`"); while($line1 = mysql_fetch_assoc($blockQ)) { foreach($blockTypes as $type){ if($type["id"] == $line1["BLOCK_TYPES_ID"]){ $line1["type"] = $type; break; } } $fields = implode(",",$line1["type"]["fields"]); $postQ = mysql_query("SELECT $fields FROM `post` WHERE (`BLOCK_ID`,`PAGE_ID`)=('".$line1["id"]."','$page_id') LIMIT 0,1"); while($line2 = mysql_fetch_assoc($postQ)) { //$line2f = array_filter($line2, 'strlen'); $arr = array("block_name" => $line1["name1"]); //foreach($line2f as $key => $val){ foreach($line2 as $key => $val){ $arr[$key] = $val; } $data = array(); foreach($line1["type"]["fields"] as $field){ $data[] = $arr[$field]; } $simple[$line1["name1"]] = $data; // need to loop fields //$content[] = $arr; } } array_unshift($content,$simple); return $simple; //$content; } // this puts the block ALIAS into the array instead of bid_ function cobConverter($cob){ global $siteName; global $siteTitle; $aa = array(); $co = array(); if(!empty($cob)){ foreach($cob as $key => $arr){ if(strpos($key, 'bid_') !== FALSE && !empty($arr['content'])){ if(count($arr['content'])==1 && $arr['block_alias'] != 'sku' && $arr['block_type'] != 'Schedule' && $arr['block_type'] != 'Image' && $arr['block_type'] != 'Image Gallery' && $arr['block_type'] != 'Grouping' && $arr['block_type'] != 'Variations' && $arr['block_type'] != 'Children' && $arr['block_type'] != 'Associations'){ $co[$arr['block_alias']] = $arr['content'][0]; }else{ $co[$arr['block_alias']] = $arr['content']; } if($arr['block_type'] == 'Image'){ $alt = cleanForAttr($cob['page']['name1']);//(!empty($siteTitle)?$siteTitle:$siteName); $co[$arr['block_alias']][1] = (empty($arr['content'][1])?$alt:$arr['content'][1]); $co[$arr['block_alias']][2] = ''; $co[$arr['block_alias']][3] = ''; if(!empty($arr['content'][0])){ $imgfile = "../../files/" . $arr['content'][0]; if(file_exists($imgfile)){ $image = getimagesize($imgfile); if($image){ list($imw, $imh, $imtype, $imattr) = $image; $co[$arr['block_alias']][2] = $imw; $co[$arr['block_alias']][3] = $imh; } } } } if($arr['block_type'] == 'Image Gallery'){ for($i=0;$i$co,'rel'=>$rel,'fea'=>$fea,'ass'=>$ass); } function getPageContentMin($page_id){ // only used in edit_window.php global $blockTypes; $simple = array(); $min = array(); //21 - children typeid $blockQ = mysql_query("SELECT `block`.`id` FROM `block`,`page` WHERE `page`.`id`='$page_id' AND `block`.`BLOCK_TYPES_ID`='21' AND `block`.`SECTION_ID`=`page`.`SECTION_ID` ORDER BY `block`.`order` LIMIT 0,1"); while($line1 = mysql_fetch_assoc($blockQ)) { $block_id = $line1['id']; } $blockQ = mysql_query("SELECT `block`.* FROM `block`,`page` WHERE `page`.`id`='$page_id' AND `block`.`BLOCK_TYPES_ID`='1' AND `block`.`SECTION_ID`=`page`.`SECTION_ID` ORDER BY `block`.`order` LIMIT 0,1"); while($line1 = mysql_fetch_assoc($blockQ)) { $min[] = $line1; } $blockQ = mysql_query("SELECT `block`.* FROM `block`,`page` WHERE `page`.`id`='$page_id' AND `block`.`BLOCK_TYPES_ID` IN ('3','4') AND `block`.`SECTION_ID`=`page`.`SECTION_ID` ORDER BY `block`.`order` LIMIT 0,1"); while($line1 = mysql_fetch_assoc($blockQ)) { $min[] = $line1; } $blockQ = mysql_query("SELECT `block`.* FROM `block`,`page` WHERE `page`.`id`='$page_id' AND `block`.`BLOCK_TYPES_ID` = '20' AND `block`.`SECTION_ID`=`page`.`SECTION_ID` ORDER BY `block`.`order` LIMIT 0,1"); while($line1 = mysql_fetch_assoc($blockQ)) { $subStructure = getStructure($page_id); $subpages = array(); foreach($subStructure as $str){ $ssaa = array(); $ssaa[] = $str["id"]; $ssaa[] = $str["name1"]; $subpages[] = $ssaa; } } $simple[] = $page_id; foreach($min as $line1){ foreach($blockTypes as $type){ if($type["id"] == $line1["BLOCK_TYPES_ID"]){ $line1["type"] = $type; break; } } $postQ = mysql_query("SELECT * FROM `post` WHERE (`BLOCK_ID`,`PAGE_ID`)=('".$line1["id"]."','$page_id') LIMIT 0,1"); while($line2 = mysql_fetch_assoc($postQ)) { if($line1["BLOCK_TYPES_ID"] == 4){ // is gall - get kid instead $kidsQ = mysql_query("SELECT * FROM `post` WHERE (`PARENT_ID`)=('".$line2["id"]."') ORDER BY `order` LIMIT 0,1"); while($line3 = mysql_fetch_assoc($kidsQ)) { $line2 = $line3; } } $arr = array("block_name" => $line1["name1"]); foreach($line2 as $key => $val){ $arr[$key] = $val; } if($line1["BLOCK_TYPES_ID"] == 5){ $simple[] = $arr[$line1["type"]["fields"][2]]; }else{ $simple[] = $arr[$line1["type"]["fields"][0]]; } } } $simple[] = getURLfromPageId($page_id); if(!empty($subpages)){ foreach($subpages as $sbp){ $simple[] = $sbp; } } if($block_id > 0){ $simple[] = getChildren($page_id,$block_id); } return $simple; } function updateTagCount($tag_id){ $tagCountQ = mysql_query("SELECT COUNT(*) FROM `tag_page_block_x` WHERE `TAG_ID`='$tag_id'"); $r = mysql_fetch_row($tagCountQ); $tagCount = $r[0]; $query = "UPDATE `tag` SET `count`='$tagCount' WHERE `id`='$tag_id'"; if(!mysql_query($query)){ echo "Error, updateTagX failed " . mysql_error(); die(); } //echo "count:".$tagCount." --"; } function getPageContentMin2($page_id){ // only used in edit_window.php global $blockTypes; $simple = array(); $min = array(); //21 - children typeid $blockQ = mysql_query("SELECT `block`.`id` FROM `block`,`page` WHERE `page`.`id`='$page_id' AND `block`.`BLOCK_TYPES_ID`='21' AND `block`.`SECTION_ID`=`page`.`SECTION_ID` ORDER BY `block`.`order` LIMIT 0,1"); while($line1 = mysql_fetch_assoc($blockQ)) { $block_id = $line1['id']; } $blockQ = mysql_query("SELECT `block`.* FROM `block`,`page` WHERE `page`.`id`='$page_id' AND `block`.`BLOCK_TYPES_ID`='1' AND `block`.`SECTION_ID`=`page`.`SECTION_ID` ORDER BY `block`.`order` LIMIT 0,1"); while($line1 = mysql_fetch_assoc($blockQ)) { $min[] = $line1; } $blockQ = mysql_query("SELECT `block`.* FROM `block`,`page` WHERE `page`.`id`='$page_id' AND `block`.`BLOCK_TYPES_ID` IN ('3','4') AND `block`.`SECTION_ID`=`page`.`SECTION_ID` ORDER BY `block`.`order` LIMIT 0,1"); while($line1 = mysql_fetch_assoc($blockQ)) { $min[] = $line1; } $blockQ = mysql_query("SELECT `block`.* FROM `block`,`page` WHERE `page`.`id`='$page_id' AND `block`.`BLOCK_TYPES_ID` = '20' AND `block`.`SECTION_ID`=`page`.`SECTION_ID` ORDER BY `block`.`order` LIMIT 0,1"); while($line1 = mysql_fetch_assoc($blockQ)) { $subStructure = getStructure($page_id); $subpages = array(); foreach($subStructure as $str){ $ssaa = array(); $ssaa[] = $str["id"]; $ssaa[] = $str["name1"]; $subpages[] = $ssaa; } } $simple['id'] = $page_id; foreach($min as $line1){ foreach($blockTypes as $type){ if($type["id"] == $line1["BLOCK_TYPES_ID"]){ $line1["type"] = $type; break; } } $postQ = mysql_query("SELECT * FROM `post` WHERE (`BLOCK_ID`,`PAGE_ID`)=('".$line1["id"]."','$page_id') LIMIT 0,1"); while($line2 = mysql_fetch_assoc($postQ)) { if($line1["BLOCK_TYPES_ID"] == 4){ // is gall - get kid instead $kidsQ = mysql_query("SELECT * FROM `post` WHERE (`PARENT_ID`)=('".$line2["id"]."') ORDER BY `order` LIMIT 0,1"); while($line3 = mysql_fetch_assoc($kidsQ)) { $line2 = $line3; } } $arr = array("block_name" => $line1["name1"]); foreach($line2 as $key => $val){ $arr[$key] = $val; } if($line1["BLOCK_TYPES_ID"] == 5){ $simple['image'] = $arr[$line1["type"]["fields"][2]]; }else if($line1["BLOCK_TYPES_ID"] == 1){ $simple['name1'] = $arr[$line1["type"]["fields"][0]]; }else{ $simple['image'] = $arr[$line1["type"]["fields"][0]]; } } } $simple['url'] = getURLfromPageId($page_id); if(!empty($subpages)){ foreach($subpages as $sbp){ $simple['subpages'][] = $sbp; } } if($block_id > 0){ $simple['kids'] = getChildren($page_id,$block_id); } return $simple; } function get_curl($url){ if(function_exists('curl_init')){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); $output = curl_exec($ch); echo curl_error($ch); curl_close($ch); return $output; }else{ return file_get_contents($url); } } function lookup_geocode($string){ //http://www.andrew-kirkpatrick.com/2011/10/google-geocoding-api-with-php/ $string = str_replace (" ", "+", urlencode($string)); $details_url = "http://maps.googleapis.com/maps/api/geocode/json?address=".$string."&sensor=false"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $details_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = json_decode(curl_exec($ch), true); // If Status Code is ZERO_RESULTS, OVER_QUERY_LIMIT, REQUEST_DENIED or INVALID_REQUEST if ($response['status'] != 'OK') { return null; } // print_r($response); $geometry = $response['results'][0]['geometry']; $longitude = $geometry['location']['lat']; $latitude = $geometry['location']['lng']; $array = array( 'latitude' => $geometry['location']['lng'], 'longitude' => $geometry['location']['lat'], 'location_type' => $geometry['location_type']//, // 'geocode' => $response ); return $array; } function getUserIP() { $client = @$_SERVER['HTTP_CLIENT_IP']; $forward = @$_SERVER['HTTP_X_FORWARDED_FOR']; $remote = $_SERVER['REMOTE_ADDR']; if(filter_var($client, FILTER_VALIDATE_IP)) { $ip = $client; } elseif(filter_var($forward, FILTER_VALIDATE_IP)) { $ip = $forward; } else { $ip = $remote; } return $ip; } /* USAGE echo ip_info("Visitor", "Country"); // India echo ip_info("Visitor", "Country Code"); // IN echo ip_info("Visitor", "State"); // Andhra Pradesh echo ip_info("Visitor", "City"); // Proddatur echo ip_info("Visitor", "Address"); // Proddatur, Andhra Pradesh, India echo ip_info("Visitor", "Location"); // Array ( [city] => Proddatur [state] => Andhra Pradesh [country] => India [country_code] => IN [continent] => Asia [continent_code] => AS ) */ function ip_info($ip = NULL, $purpose = "location", $deep_detect = false) { $output = NULL; if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) { $ip = $_SERVER["REMOTE_ADDR"]; if ($deep_detect) { if (filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP)) $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; if (filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP)) $ip = $_SERVER['HTTP_CLIENT_IP']; } } $purpose = str_replace(array("name", "\n", "\t", " ", "-", "_"), NULL, strtolower(trim($purpose))); $support = array("country", "countrycode", "state", "region", "city", "location", "address"); $continents = array( "AF" => "Africa", "AN" => "Antarctica", "AS" => "Asia", "EU" => "Europe", "OC" => "Australia (Oceania)", "NA" => "North America", "SA" => "South America" ); /* if (filter_var($ip, FILTER_VALIDATE_IP) && in_array($purpose, $support)) { $ipdat = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip)); if (@strlen(trim($ipdat->geoplugin_countryCode)) == 2) { switch ($purpose) { case "location": $output = array( "city" => @$ipdat->geoplugin_city, "state" => @$ipdat->geoplugin_regionName, "country" => @$ipdat->geoplugin_countryName, "country_code" => @$ipdat->geoplugin_countryCode, "continent" => @$continents[strtoupper($ipdat->geoplugin_continentCode)], "continent_code" => @$ipdat->geoplugin_continentCode ); break; case "address": $address = array($ipdat->geoplugin_countryName); if (@strlen($ipdat->geoplugin_regionName) >= 1) $address[] = $ipdat->geoplugin_regionName; if (@strlen($ipdat->geoplugin_city) >= 1) $address[] = $ipdat->geoplugin_city; $output = implode(", ", array_reverse($address)); break; case "city": $output = @$ipdat->geoplugin_city; break; case "state": $output = @$ipdat->geoplugin_regionName; break; case "region": $output = @$ipdat->geoplugin_regionName; break; case "country": $output = @$ipdat->geoplugin_countryName; break; case "countrycode": $output = @$ipdat->geoplugin_countryCode; break; } } } */ return $output; } // clear facebook cache for a url function clear_open_graph_cache($url) { $vars = array('id' => $url, 'scrape' => 'true'); $body = http_build_query($vars); $fp = fsockopen('ssl://graph.facebook.com', 443); fwrite($fp, "POST / HTTP/1.1\r\n"); fwrite($fp, "Host: graph.facebook.com\r\n"); fwrite($fp, "Content-Type: application/x-www-form-urlencoded\r\n"); fwrite($fp, "Content-Length: ".strlen($body)."\r\n"); fwrite($fp, "Connection: close\r\n"); fwrite($fp, "\r\n"); fwrite($fp, $body); fclose($fp); } function getEventsFromSchedule($schedule_id){ $exp = array(); $expQ = mysql_query("SELECT * FROM `schedule_events` WHERE `SCHEDULE_ID` = '$schedule_id' ORDER BY `date_start`"); while($line1 = mysql_fetch_assoc($expQ)) { if($line1['has_start_time']){ $line1['start'] = date('l, F j, Y, g:ia',strtotime($line1['date_start'])); }else{ $line1['start'] = date('l, F j, Y',strtotime($line1['date_start'])); } if($line1['has_end_time']){ $line1['end'] = date('l, F j, Y, g:ia',strtotime($line1['date_end'])); }else{ $line1['end'] = date('l, F j, Y',strtotime($line1['date_end'])); if(date('Y-m-d',strtotime($line1['date_start'])) == date('Y-m-d',strtotime($line1['date_end']))){ $line1['end'] = ''; } } if($line1['start'] == $line1['end']){ $line1['end'] = ''; } $exp[] = $line1; } return $exp; } function getEventsFromSection($section_id){ $events = array(); $eventsQ = mysql_query("SELECT `schedule_events`.* FROM `page`,`schedule_events` WHERE `page`.`SECTION_ID` = '$section_id' AND `page`.`visible` = 1 AND `page`.`hide` = 0 AND `page`.`id` = `schedule_events`.`PAGE_ID` ORDER BY `schedule_events`.`date_start`"); while($line1 = mysql_fetch_assoc($eventsQ)) { $events[] = $line1; } return $events; } function getEventsByDateFromSection($section_id,$start_date,$end_date){ $start_date = date('Y-m-d',strtotime($start_date)) . ' 00:00:00'; $end_date = date('Y-m-d',strtotime($end_date)) . ' 23:59:59'; $events = array(); $eventsQ = mysql_query("SELECT `schedule_events`.* FROM `page`,`schedule_events` WHERE (('$end_date' >= `schedule_events`.`date_start` AND '$end_date' <= `schedule_events`.`date_end`) OR ('$start_date' >= `schedule_events`.`date_start` AND '$start_date' <= `schedule_events`.`date_end`) OR ('$end_date' >= `schedule_events`.`date_end` AND '$start_date' <= `schedule_events`.`date_start`)) AND `page`.`id` = `schedule_events`.`PAGE_ID` AND `page`.`SECTION_ID` = '$section_id' AND `page`.`visible` = 1 AND `page`.`hide` = 0 ORDER BY `schedule_events`.`date_start`"); while($line1 = mysql_fetch_assoc($eventsQ)) { $events[] = $line1; } return $events; } function getGETvars($plink){ if(substr($plink,0,1) == '/'){ $plink = substr($plink,1); } $url = SITE_URL . $plink; $data = array('GET_GET' => 1); $options = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data) ) ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); if ($result === FALSE) { /* Handle error */ } return $result; } ?> query("SELECT * FROM `content` WHERE `PAGE_ID`='1'"); $content = $stmt->fetch(); $siteInfo = json_decode($content["content_json_bid"], true); $siteName = $siteInfo["Site Name"][0]; $siteTitle = $siteInfo["Site Title"][0]; $siteDesc = strip_tags($siteInfo["Site Description"][0]); define('SITE_NAME',$siteName); define('SITE_TITLE',$siteTitle); define('SITE_DESCRIPTION',$siteDesc); $siteSchema = $siteInfo["Schema JSON-LD"][0]; define('SITE_JSON_LD',$siteSchema); define('SITE_FROM_EMAIL', $siteInfo["Site From Email"][0]); define('SHOP_FROM_EMAIL', $siteInfo["Shop From Email"][0]); define('OWNER_EMAIL', $siteInfo["Owner Email"][0]); define('SUPPORT_EMAIL', $siteInfo["CMS Support Email"][0]); $filePath = $siteURL . "files/"; $heroPic = $siteURL . "files/" . $siteInfo["Logo"][0]; $heroPicSq = $siteURL . "files/" . $siteInfo["Logo Square"][0]; define('SITE_LOGO', $heroPic); define('SITE_LOGO_SQ', $heroPicSq); if(!empty($siteInfo["Facebook Link"][1])){ define('SOCIAL_FB',$siteInfo["Facebook Link"][1]); } if(!empty($siteInfo["Twitter Link"][1])){ define('SOCIAL_TW',$siteInfo["Twitter Link"][1]); } if(!empty($siteInfo["Instagram Link"][1])){ define('SOCIAL_IG',$siteInfo["Instagram Link"][1]); } if(!empty($siteInfo["Pinterest Link"][1])){ define('SOCIAL_PI',$siteInfo["Pinterest Link"][1]); } $siteKeywords = $siteInfo["Keywords"][0]; ?>