ID)); if ($tallyopiaCID) { Hash::$Data['cid'] = $tallyopiaCID; add_menu_page('Tallyopia NOC','Tallyopia NOC','read','tally-root-noc',null,$tallyopiaIconURL,'4+2.0e-08'); //add_submenu_page('tally-noc-root', 'Live', 'NOC - Live Monitor', 'administrator', 'tally-live-noc', 'TallyDashLive'); add_submenu_page('tally-root-noc', 'Live', 'NOC - Live Monitor', 'read', 'tally-root-noc', 'TallyDashLive'); } // END NOC MENU SETUP // --------------------------------------------------------------- // Nothing below here for non admins if (!current_user_can('administrator')){return;} // --------------------------------------------------------------- // BEGIN ADMIN MENU SETUP add_menu_page('Tallyopia Dash','Tallyopia Dash','administrator','tally-root',null,$tallyopiaIconURL,'4+1.0e-08'); add_submenu_page('tally-root', 'Overview', 'Overview', 'administrator', 'tally-root', 'TallyDashOverview'); add_submenu_page('tally-root', 'Live', 'Live Monitor', 'administrator', 'tally-live', 'TallyDashLive'); add_submenu_page('tally-root', 'Last 24 Hours', 'Last 24 Hrs.', 'administrator', 'tally-24', 'TallyDashLast24'); add_submenu_page('tally-root', 'Last 60 Days', 'Last 60 Days', 'administrator', 'tally-60', 'TallyDashLast90'); add_submenu_page('tally-root', 'Analyze Readers', 'Analyze Readers', 'administrator', 'tally-readers-search', 'TallyDashSearchReaders'); add_submenu_page('tally-root', 'Analyze Content', 'Analyze Content', 'administrator', 'tally-pages-search', 'TallyDashSearchPages'); // Only show the diagnostics and setup menus for the top level admins if ( ( is_multisite() && is_super_admin() ) || (!is_multisite() && current_user_can('administrator')) ) { add_submenu_page('tally-root', 'Diagnostics', 'Diagnostics', 'administrator', 'tally-diagnostics', 'TallyDashDiagnostics'); add_submenu_page('tally-root', 'Setup', 'Setup', 'administrator', 'tally-setup', 'TallyDashSetup'); } // END ADMIN MENU SETUP // --------------------------------------------------------------- } function TallyDashUtility($atts,$dataPath) { $cid = Hash::$Data['cid']; // Set isnoc based on the page name. $isnoc = 0; $page = $_GET['page']; $pageParts = explode('-',$page); if ('noc' == end($pageParts)) {$isnoc = 1;} $data = array(); $data['site'] = TallyWordPressPlugin::GetTallyClientURL(); $data['cid'] = $cid; $data['isnoc'] = $isnoc; $queryString = http_build_query($data); $q = TallyWordPressPlugin::$SERVER . '/' . TallyWordPressPlugin::$VERSION_PATH . '/' . $dataPath . '?' . $queryString; $request = new WP_Http; $result = $request->request($q); $jsInsert = ""; if(!is_wp_error($result)){echo $jsInsert . $result['body'];} else { $str = "
Error retrieving dash.<\n>" . print_r($result,true) . "\n" . $q . "\n
"; echo $str; } } function TallyDashSetup($atts) { // The setup page is a local page include(WP_PLUGIN_DIR . '/TallyopiaWordPressPlugin/includes/SetupScreen.php'); return; } function TallyDashOverview($atts) { $dataPath = '/WidgetAPI/Dash_Overview.php'; TallyDashUtility($atts,$dataPath); } function TallyDashSearchPages($atts) { $dataPath = '/WidgetAPI/Dash_SearchPages.php'; TallyDashUtility($atts,$dataPath); } function TallyDashSearchReaders($atts) { $dataPath = '/WidgetAPI/Dash_SearchReaders.php'; TallyDashUtility($atts,$dataPath); } function TallyDashDiagnostics($atts) { $dataPath = '/WidgetAPI/Dash_PluginSetup.php'; TallyDashUtility($atts,$dataPath); } function TallyDashLive($atts) { $dataPath = '/WidgetAPI/Dash_Live.php'; TallyDashUtility($atts,$dataPath); } function TallyDashLast24($atts) { $dataPath = '/WidgetAPI/Dash_Last24.php'; TallyDashUtility($atts,$dataPath); } function TallyDashLast90($atts) { $dataPath = '/WidgetAPI/Dash_Last90.php'; TallyDashUtility($atts,$dataPath); } function TallyShortcodeFcn_Last24($atts) { $atts = shortcode_atts( array( 'widget' => null ,'width' => 270 ,'height' => 300 ,'float' =>'' ,'showtable' => 1 ,'showview' => 1 ,'showdetail' => 0 // Override this below ,'back' => null ,'items' => '' ), $atts ); if (null == $atts['widget']) {return '';} // Override defaults for eventmap and searchmap if ( stristr($atts['widget'],'eventmap') || stristr($atts['widget'],'searchmap') ) { $atts['showdetail'] = 1; } $data = array(); $url = get_bloginfo('wpurl'); $data['site'] = substr($url,strrpos($url,'/')+1); $data['widget'] = $atts['widget']; $data['height'] = $atts['height']; $data['width'] = $atts['width']; $data['float'] = $atts['float']; $data['showtable'] = $atts['showtable']; $data['showview'] = $atts['showview']; $data['showdetail'] = $atts['showdetail']; $data['back'] = $atts['back']; $data['items'] = $atts['items']; $data['isadmin'] = current_user_can('administrator') ? 1 : 0; global $TALLY_CALLED; $data['tally_called'] = $TALLY_CALLED; $TALLY_CALLED = true; $queryString = http_build_query($data); if (false !== stristr($atts['widget'],'last24_')) { global $TALLY_CALLED_LAST24; $queryString .= '$TALLY_CALLED_LAST24=' . $TALLY_CALLED_LAST24; $q = TallyWordPressPlugin::$SERVER . '/' . TallyWordPressPlugin::$VERSION_PATH . '/' . '/WidgetAPI/Widget_Last24.php?' . $queryString; $TALLY_CALLED_LAST24 = true; } if (false != stristr($atts['widget'],'live_')) { global $TALLY_CALLED_LIVE; $queryString .= '&TALLY_CALLED_LIVE=' . $TALLY_CALLED_LIVE; $q = TallyWordPressPlugin::$SERVER . '/' . TallyWordPressPlugin::$VERSION_PATH . '/' . '/WidgetAPI/Widget_Live.php?' . $queryString; $TALLY_CALLED_LIVE = true; } $request = new WP_Http; $result = $request->request($q); $jsInsert = ""; if(!is_wp_error($result)){return $jsInsert . $result['body'];} else { $str = "
"; return $str; } } class TallyWordPressPlugin { public static $DEBUG = false; public static $METHOD = 'JQUERY';//SERVER_POST'; public static $SERVER = 'http://www.tallyopia.net';// This is replaced at initialization. public static $ANALYTICS_SERVER = 'http://analytics.tallyopia.net'; public static $VERSION_PATH = '/v1.0/'; public static $EVENT_JS = '/Event.js'; public static $LOG_EVENT_SCRIPT = 'LogEvent.php'; public static $LOG_PING_SCRIPT = 'LogPing.php'; public static $SHORTCODE_TAG = 'tallyopia'; public static function EnableShortcodesInWidgets() { if (!is_admin()) {add_filter('widget_text', 'do_shortcode', 11);} } public static function AddDashboardMenu() { add_action('admin_menu', 'TallyInDash'); add_action('network_admin_menu','TallyInDash'); } public static function AddShortcode() { add_shortcode(TallyWordPressPlugin::$SHORTCODE_TAG, 'TallyShortcodeFcn_Last24'); } public static function HookActionToFooter() { add_action('wp_footer', 'TallyWordPressPlugin::DoAction', 9999); } public static function InitJQuery() { add_action('init','TallyWordPressPlugin::LoadJQuery'); } public static function LoadJQuery() { if (!is_admin()) { wp_deregister_script('jquery'); wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js', false, '1.6.1', false); wp_enqueue_script('jquery'); } } public static function DoAction($content) { echo ""; $DEBUG = TallyWordPressPlugin::$DEBUG; $METHOD = TallyWordPressPlugin::$METHOD; // Don't run if user is an admin if (current_user_can('administrator')) {return $content;} // Don't run on admin pages. if (is_admin()) {return $content;} // Don't run on private pages if (TallyWordPressPlugin::GetIsPrivate()) {return $content;} // STATIC, so we can't reference $this $pageType = 'unknown'; $entry = 'unknown'; $dataCount = 1; $dontLog = False; $TITLE = array(); $CATEGORIES = array(); $TAGS = array(); $EVENT = array(); $RESULTS = array(); $AUTHOR = TallyWordPressPlugin::GetBlogName('None'); // print(''); if (true == is_front_page()) { $EVENT = array('home'); $entry = 'home'; $CATEGORIES = array('Home'); $TITLE = TallyWordPressPlugin::GetBlogName('Home'); } if (true == is_home()) { $EVENT = array('home'); $CATEGORIES = array('Home'); $TITLE = TallyWordPressPlugin::GetBlogName('Home'); $entry = 'home'; } if (true == is_single()) { $EVENT = array('single'); $TITLE = TallyWordPressPlugin::GetSinglePageTitle(); $CATEGORIES = TallyWordPressPlugin::GetCategories(); $TAGS = TallyWordPressPlugin::GetTags(); $AUTHOR = array(TallyWordPressPlugin::GetAuthor()); } if (true == is_tag()) { $EVENT = array('tag'); $TITLE = TallyWordPressPlugin::GetSingleTag(); $RESULTS = TallyWordPressPlugin::GetCount(); $CATEGORIES = $TITLE; } if (true == is_category()) { $EVENT = array('category'); $TITLE = TallyWordPressPlugin::GetSingleCategory(); $RESULTS = TallyWordPressPlugin::GetCount(); $CATEGORIES = $TITLE; } if (true == is_author()) { $EVENT = array('author'); $TITLE = TallyWordPressPlugin::GetSinglePageTitle(); $RESULTS = TallyWordPressPlugin::GetCount(); $AUTHOR = $TITLE; } if (true == is_date()) { $EVENT = array('date'); $TITLE = TallyWordPressPlugin::GetSingleDate(); $RESULTS = TallyWordPressPlugin::GetCount(); } if (true == is_search()) { $EVENT = array('search'); $TITLE = get_search_query(); $RESULTS = TallyWordPressPlugin::GetCount(); } if (true == is_page()) { $EVENT = array('page'); $TITLE = TallyWordPressPlugin::GetSinglePageTitle(); $AUTHOR = array(TallyWordPressPlugin::GetAuthor()); $CATEGORIES = TallyWordPressPlugin::GetPageParent(); } if (true == is_404()) { global $wp_query; $EVENT = array('404 Error'); $TITLE = array($wp_query->query['pagename']); } if (true == is_paged()) {$dontLog = true;} // Exit now if we aren't supposed to log. if (true == $dontLog) {return $content;} // Add fields for all the types $IP = $METHOD == 'SERVER_POST' ? array(TallyWordPressPlugin::GetIP()) : array('auto'); $TIMESTAMP = $METHOD == 'SERVER_POST' ? array(date('Y-m-d H:i:s')) : array('auto');; $WEBSITE = TallyWordPressPlugin::GetTallyClientURL(); $LINK = array(esc_url($_SERVER['REQUEST_URI'])); $WEBSITEKEY = array('websitekeyvalue'); $USER_EMAIL = array(TallyWordPressPlugin::GetUserEmail()); $METHOD_ARR = array($METHOD); $fieldsToSend = array($EVENT, $TITLE, $CATEGORIES, $TAGS, $RESULTS, $IP, $TIMESTAMP, $WEBSITE, $WEBSITEKEY, $AUTHOR, $LINK); $fieldNames = array('EVENT','TITLE','CATEGORIES','TAGS','RESULTS','IP','TIMESTAMP','WEBSITE','WEBSITEKEY','AUTHOR','LINK'); $dataHash = array_combine($fieldNames,$fieldsToSend); // Do some debug printing if (true == $DEBUG) { echo ""; } // Serialize it in JSON form, base64 encode, and package. $payload['payload'] = base64_encode(json_encode($dataHash)); // Send the data. switch ($METHOD) { case 'JQUERY': $response = TallyWordPressPlugin::DoJquery(TallyWordPressPlugin::$SERVER,'POST',$payload); break; } if (true == $DEBUG) { echo "\n\n"; } return $content; } private static function GetBlogName($default='Home') { $name = get_bloginfo('name'); if (strlen($name)<1) {$name = $default;} return $name; } private static function GetPageParent() { global $wp_query; $id = $wp_query->post->post_parent; $title = get_the_title($id); return array($title); } private static function GetIsPrivate() { global $post; $privacy = ($post->post_status == 'private'); return $privacy; } private static function GetCount() { global $wp_query; return array($wp_query->found_posts); } private static function GetAuthor() { global $post; $postID = $post->post_author; $data = get_userdata(intval($postID)); return $data->display_name; } private static function GetUserEmail() { $email = NULL; $user = wp_get_current_user(); if (is_user_logged_in()) { $email = array($user->user_email); $name = array($user->display_name); } return $email; } private static function GetSinglePageTitle() { $t = NULL; if (is_home () ) {$t = bloginfo('name');} elseif (is_category()) {$t = single_cat_title('',false);} elseif (is_single()) {$t = single_post_title('',false);} elseif (is_page()) {$t = single_post_title('',false);} elseif (is_author()) {$t = strip_tags(wp_title('',false));} else {$t = wp_title('',false); } if (NULL == $t) {return array('(Untitled)');} return array($t); } private static function GetSingleCategory() { global $wp; return array($wp->query_vars['category_name']); } private static function GetCategories() { $allCategories = array(); $cats = get_the_category(); if (false == $cats) {return $allCategories;} foreach($cats as $category) { array_push($allCategories, $category->cat_name); } return $allCategories; } private static function GetSingleTag() { global $wp; return array($wp->query_vars['tag']); } private static function GetTags() { $maxTagCount = 10; $allTags = array(); $tags = get_the_tags(); if (false == $tags) {return $allTags;} while (count($tags)>0 && count($allTags)<$maxTagCount) { $item = array_pop($tags); array_push($allTags,$item->name); } return $allTags; } private static function GetDates() { return GetSingleDate(); } private static function GetSingleDate() { $d = get_the_date('Y-m-d'); return array($d); } private static function GetIP() { $ip = NULL; if (getenv("HTTP_CLIENT_IP")) {$ip = getenv("HTTP_CLIENT_IP");} else if(getenv("HTTP_X_FORWARDED_FOR")) {$ip = getenv("HTTP_X_FORWARDED_FOR");} else if(getenv("REMOTE_ADDR")) {$ip = getenv("REMOTE_ADDR");} else { //$ip = "UNKNOWN"; } return $ip; } public static function GetTallyClientURL(){ $WEBSITE = get_bloginfo('wpurl'); $WEBSITE = str_replace('https://','',$WEBSITE); $WEBSITE = str_replace('http://' ,'',$WEBSITE); if (preg_match("/^www./",$WEBSITE)) {$WEBSITE=substr($WEBSITE,4);} $websiteParts = explode("/",$WEBSITE); $WEBSITE = $websiteParts[0]; return $WEBSITE; } private static function DoJquery($host,$method,$data=NULL) { if (is_array($data)) { $dataElements = array(); $dataKeys = array_keys($data); foreach ($dataKeys as $k) { array_push($dataElements,urlencode($k) ."=". urlencode($data[$k])); } $data = implode("&",$dataElements); } $scriptSrc = (TallyWordPressPlugin::$SERVER . '/' . TallyWordPressPlugin::$VERSION_PATH . '/' . TallyWordPressPlugin::$EVENT_JS); echo '',"\r\n"; return ''; } } # ---------------------------