Esempio n. 1
0
    /**
     * Main control method
     * @return Page markup
     */
    public function control() {
        if ($this->shouldRefreshCache()) {
            $this->setViewTemplate(Utils::getPluginViewDirectory('geoencoder').'geoencoder.map.iframe.tpl');
            $this->setPageTitle('Locate Post on Map');
            $post_dao = DAOFactory::getDAO('PostDAO');

            $plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
            $options = $plugin_option_dao->getOptionsHash('geoencoder', true);
            if (isset($options['gmaps_api_key']->option_value)) {
                $api_key = $options['gmaps_api_key']->option_value;
            } else {
                $api_key = NULL;
            }
            $network = (isset($_GET['n']))?$_GET['n']:'twitter';
            $type = (isset($_GET['t']))?$_GET['t']:'post';
            $post_id = (isset($_GET['pid']))?$_GET['pid']:'post_id';
            $post = $post_dao->getPost($post_id, $network);

            if ($type == 'post' && isset($post) && $post->is_geo_encoded == 1) {
                $this->addToView('post', $post);

                $this->addHeaderJavaScript('plugins/geoencoder/assets/js/generatemap.js');
                $this->addToView('gmaps_api', $api_key);

                $post_rows =  $post_dao->getRelatedPostsArray($post_id, $network, !$this->isLoggedIn());

                $posts_json = $this->processLocations($post_rows, $post_id);
                $this->addToView('posts_data', $posts_json);
            } else {
                $this->addErrorMessage('This post has not been geoencoded yet; cannot display map.');
            }
        }
        return $this->generateView();
    }
Esempio n. 2
0
    public function getPostDetailMenuItems($post) {
        $menus = array();
        $map_template_path = Utils::getPluginViewDirectory('geoencoder').'geoencoder.map.tpl';

        //Define a menu item
        $map_menu_item = new MenuItem("Response Map", "", $map_template_path, 'Geoencoder');
        //Define a dataset to be displayed when that menu item is selected
        $map_menu_item_dataset_1 = new Dataset("geoencoder_map", 'PostDAO', "getRelatedPosts",
        array($post->post_id, $post->network, 'location') );
        //Associate dataset with menu item
        $map_menu_item->addDataset($map_menu_item_dataset_1);
        //Add menu item to menu
        $menus["geoencoder_map"] = $map_menu_item;

        $nearest_template_path = Utils::getPluginViewDirectory('geoencoder').'geoencoder.nearest.tpl';
        //Define a menu item
        $nearest_menu_item = new MenuItem("Nearest Responses", "", $nearest_template_path);
        //Define a dataset to be displayed when that menu item is selected
        $nearest_dataset = new Dataset("geoencoder_nearest", 'PostDAO', "getRelatedPosts",
        array($post->post_id, $post->network, !Session::isLoggedIn()));
        //Associate dataset with menu item
        $nearest_menu_item->addDataset($nearest_dataset);
        $nearest_dataset_2 = new Dataset("geoencoder_options", 'PluginOptionDAO', 'getOptionsHash',
        array('geoencoder', true));
        $nearest_menu_item->addDataset($nearest_dataset_2);
        //Add menu item to menu
        $menus["geoencoder_nearest"] = $nearest_menu_item;

        return $menus;
    }
    public function getPostDetailMenuItems($post) {
        $template_path = Utils::getPluginViewDirectory('hellothinkup').'hellothinkup.inline.view.tpl';
        $menu_items = array();

        //Define a menu item
        $hello_menu_item_1 = new MenuItem("Data vis 1", "First data visualization", $template_path,
        'Hello ThinkUp Plugin Menu Header');
        //Define a dataset to be displayed when that menu item is selected
        $hello_menu_item_dataset_1 = new Dataset("replies_1", 'PostDAO', "getRepliesToPost",
        array($post->post_id, $post->network, 'location') );
        //Associate dataset with menu item
        $hello_menu_item_1->addDataset($hello_menu_item_dataset_1);
        //Add menu item to menu items array
        $menu_items['data_vis_1'] = $hello_menu_item_1;

        //Define a menu item
        $hello_menu_item_2 = new MenuItem("Data vis 2", "Second data visualization", $template_path);
        //Define a dataset to be displayed when that menu item is selected
        $hello_menu_item_dataset_2 = new Dataset("replies_2", 'PostDAO', "getRepliesToPost",
        array($post->post_id, $post->network, 'location') );
        //Associate dataset with menu item
        $hello_menu_item_2->addDataset($hello_menu_item_dataset_2);
        //Add menu item to menu items array
        $menu_items['data_vis_2'] = $hello_menu_item_2;

        return $menu_items;
    }
 public function getPostDetailMenuItems($post){
     $data_tpl = Utils::getPluginViewDirectory('embedthread').'embedthread.inline.view.tpl';
     $menus = array();
     $embed_menu_item = new MenuItem("Embed Thread", '', $data_tpl, 'Share and Publish');
     $menus["embed_thread"] = $embed_menu_item;
     return $menus;
 }
Esempio n. 5
0
 function testgetPluginViewDirectory()
 {
     global $THINKTANK_CFG;
     $path = Utils::getPluginViewDirectory('twitter');
     $this->assertEqual($path, $THINKTANK_CFG['source_root_path'] . 'webapp/plugins/twitter/view/');
     $path = Utils::getPluginViewDirectory('sweetmaryjane');
     $this->assertEqual($path, $THINKTANK_CFG['source_root_path'] . 'webapp/plugins/sweetmaryjane/view/');
 }
Esempio n. 6
0
 public function testgetPluginViewDirectory()
 {
     $config = Config::getInstance();
     $path = Utils::getPluginViewDirectory('twitter');
     $this->assertEqual(realpath($path), realpath(THINKUP_WEBAPP_PATH . 'plugins/twitter/view'));
     $path = Utils::getPluginViewDirectory('sweetmaryjane');
     $this->assertEqual(realpath($path), realpath($config->getValue('source_root_path') . '/webapp/plugins/sweetmaryjane/view/'));
 }
Esempio n. 7
0
 public function testgetPluginViewDirectory()
 {
     $config = Config::getInstance();
     $path = Utils::getPluginViewDirectory('twitter');
     $this->assertEqual($path, $config->getValue('source_root_path') . 'webapp/plugins/twitter/view/');
     $path = Utils::getPluginViewDirectory('sweetmaryjane');
     $this->assertEqual($path, $config->getValue('source_root_path') . 'webapp/plugins/sweetmaryjane/view/');
 }
Esempio n. 8
0
 /**
  * Test getTab
  */
 public function testGetTab()
 {
     $webapp = Webapp::getInstance();
     $config = Config::getInstance();
     $webapp->registerPlugin('twitter', "TwitterPlugin");
     $webapp->setActivePlugin('twitter');
     $instance = new Instance();
     $instance->network_user_id = 930061;
     $tab = $webapp->getTab('tweets-all', $instance);
     $this->assertIsA($tab, 'WebappTab');
     $this->assertEqual($tab->view_template, Utils::getPluginViewDirectory('twitter') . 'twitter.inline.view.tpl', "Template ");
     $this->assertEqual($tab->short_name, 'tweets-all', "Short name");
     $this->assertEqual($tab->name, 'All', "Name");
     $this->assertEqual($tab->description, 'All tweets', "Description");
     $this->assertIsA($tab->datasets, 'array');
     $this->assertEqual(sizeOf($tab->datasets), 1);
     $tab = $webapp->getTab('nonexistent', $instance);
     $this->assertEqual($tab, null);
 }
 /**
  * Send out insight email digest for a given time period.
  * @param Owner $owner Owner to send for
  * @param str $start When to start insight lookup
  * @param str $template Email view template to use
  * @param array $options Plugin options
  * return bool Whether email was sent
  */
 private function sendDigestSinceWithTemplate($owner, $start, $template, &$options)
 {
     $insights_dao = DAOFactory::GetDAO('InsightDAO');
     $start_time = date('Y-m-d H:i:s', strtotime($start, $this->current_timestamp));
     $insights = $insights_dao->getAllOwnerInstanceInsightsSince($owner->id, $start_time);
     if (count($insights) == 0) {
         return false;
     }
     $config = Config::getInstance();
     $view = new ViewManager();
     $view->caching = false;
     // If we've got a Mandrill key and template, send HTML
     if ($config->getValue('mandrill_api_key') != null && !empty($options['mandrill_template'])) {
         $view->assign('insights', $insights);
         $insights = $view->fetch(Utils::getPluginViewDirectory($this->folder_name) . '_email.insights_html.tpl');
         $parameters = array();
         $parameters['insights'] = $insights;
         $parameters['app_title'] = $config->getValue('app_title_prefix') . "ThinkUp";
         $parameters['app_url'] = Utils::getApplicationURL();
         $parameters['unsub_url'] = Utils::getApplicationURL() . 'account/index.php?m=manage#instances';
         // It's a weekly digest if we're going back more than a day or two.
         $days_ago = ($this->current_timestamp - strtotime($start)) / (60 * 60 * 24);
         $parameters['weekly_or_daily'] = $days_ago > 2 ? 'Weekly' : 'Daily';
         try {
             Mailer::mailHTMLViaMandrillTemplate($owner->email, 'ThinkUp has new insights for you!', $options['mandrill_template']->option_value, $parameters);
             return true;
         } catch (Mandrill_Unknown_Template $e) {
             // In this case, we'll fall back to plain text sending and warn the user in the log
             $logger = Logger::getInstance();
             $logger->logUserError("Invalid mandrill template configured:" . $options['mandrill_template']->option_value . ".", __METHOD__ . ',' . __LINE__);
             unset($options['mandrill_template']);
         }
     }
     $view->assign('apptitle', $config->getValue('app_title_prefix') . "ThinkUp");
     $view->assign('application_url', Utils::getApplicationURL());
     $view->assign('insights', $insights);
     $message = $view->fetch(Utils::getPluginViewDirectory($this->folder_name) . $template);
     list($subject, $message) = explode("\n", $message, 2);
     Mailer::mail($owner->email, $subject, $message);
     return true;
 }
 /**
  * Send user email alert about invalid OAuth tokens, at most one message per week.
  * In test mode, this will only write the message body to a file in the application data directory.
  * @param str $email
  * @param str $username
  */
 private function sendInvalidOAuthEmailAlert($email, $username)
 {
     //Determine whether or not an email about invalid tokens was sent in the past 7 days
     $should_send_email = true;
     $option_dao = DAOFactory::getDAO('OptionDAO');
     $plugin_dao = DAOFactory::getDAO('PluginDAO');
     $plugin_id = $plugin_dao->getPluginId('instagram');
     $last_email_timestamp = $option_dao->getOptionByName(OptionDAO::PLUGIN_OPTIONS . '-' . $plugin_id, 'invalid_oauth_email_sent_timestamp');
     if (isset($last_email_timestamp)) {
         //option exists, a message was sent
         //a message was sent in the past week
         if ($last_email_timestamp->option_value > strtotime('-1 week')) {
             $should_send_email = false;
         } else {
             $option_dao->updateOption($last_email_timestamp->option_id, time());
         }
     } else {
         $option_dao->insertOption(OptionDAO::PLUGIN_OPTIONS . '-' . $plugin_id, 'invalid_oauth_email_sent_timestamp', time());
     }
     if ($should_send_email) {
         $mailer_view_mgr = new ViewManager();
         $mailer_view_mgr->caching = false;
         $mailer_view_mgr->assign('thinkup_site_url', Utils::getApplicationURL());
         $mailer_view_mgr->assign('email', $email);
         $mailer_view_mgr->assign('faceboook_user_name', $username);
         $message = $mailer_view_mgr->fetch(Utils::getPluginViewDirectory('instagram') . '_email.invalidtoken.tpl');
         Mailer::mail($email, "Please re-authorize ThinkUp to access " . $username . " on Instagram", $message);
     }
 }
 /**
  * @param Post $post
  * @return array MenuItems
  */
 public function getPostDetailMenuItems($post)
 {
     $twitter_data_tpl = Utils::getPluginViewDirectory('twitter') . 'twitter.post.retweets.tpl';
     $menus = array();
     if ($post->network == 'twitter') {
         $retweets_menu_item = new MenuItem("Retweets", "Retweets of this tweet", $twitter_data_tpl, 'Twitter');
         //if not logged in, show only public retweets
         $retweets_dataset = new Dataset("retweets", 'PostDAO', "getRetweetsOfPost", array($post->post_id, 'twitter', 'default', 'km', !Session::isLoggedIn()));
         $retweets_menu_item->addDataset($retweets_dataset);
         $menus['fwds'] = $retweets_menu_item;
         // aju
         $favd_menu_item = new MenuItem("Favorited", "Those who favorited this tweet", $twitter_data_tpl);
         //if not logged in, show only public fav'd info
         $favd_dataset = new Dataset("favds", 'FavoritePostDAO', "getFavdsOfPost", array($post->post_id, 'twitter', !Session::isLoggedIn()));
         $favd_menu_item->addDataset($favd_dataset);
         $menus['favs'] = $favd_menu_item;
     }
     return $menus;
 }
 /**
  * Get Dashboard menu
  * @param $instance Instance
  * @return array of MenuItem objects (Tweets, Friends, Followers, etc)
  */
 public function getDashboardMenuItems($instance)
 {
     // An array to store our list of menu items in
     $menus = array();
     // Set the view template to checkins.tpl
     $checkins_data_tpl = Utils::getPluginViewDirectory('foursquare') . 'checkins.tpl';
     // Add a checkins link to the list of pages on the left
     $checkins_menu_item = new MenuItem("Checkins", "Your checkins", $checkins_data_tpl);
     // Get the data for our checkins link
     $checkins_menu_ds_1 = new Dataset("all_checkins", 'PostDAO', "getAllCheckins", array($instance->network_user_id, $instance->network, 15, "#page_number#"));
     $checkins_menu_ds_1->addHelp('userguide/listings/foursquare/dashboard_posts');
     $checkins_menu_item->addDataset($checkins_menu_ds_1);
     // Add the checkins to our array of items
     $menus['posts'] = $checkins_menu_item;
     // Return the list of items we want to display
     return $menus;
 }
Esempio n. 13
0
 /**
  * @param Post $post
  * @return array MenuItems
  */
 public function getPostDetailMenuItems($post)
 {
     $twitter_data_tpl = Utils::getPluginViewDirectory('twitter') . 'twitter.post.retweets.tpl';
     $menus = array();
     $rt_plugin_active = false;
     $plugin_dao = DAOFactory::getDAO('PluginDAO');
     $plugin_id = $plugin_dao->getPluginId('twitterrealtime');
     if (isset($plugin_id)) {
         $rt_plugin_active = $plugin_dao->isPluginActive($plugin_id);
     }
     if ($post->network == 'twitter') {
         $retweets_menu_item = new MenuItem("Retweets", "Retweets of this tweet", $twitter_data_tpl);
         //if not logged in, show only public retweets
         $retweets_dataset = new Dataset("retweets", 'PostDAO', "getRetweetsOfPost", array($post->post_id, 'twitter', 'default', 'km', !Session::isLoggedIn()));
         $retweets_menu_item->addDataset($retweets_dataset);
         $menus['fwds'] = $retweets_menu_item;
         if ($rt_plugin_active) {
             $favd_menu_item = new MenuItem("Favorited", "Those who favorited this tweet", $twitter_data_tpl);
             //if not logged in, show only public fav'd info
             $favd_dataset = new Dataset("favds", 'FavoritePostDAO', "getUsersWhoFavedPost", array($post->post_id, 'twitter', !Session::isLoggedIn()));
             $favd_menu_item->addDataset($favd_dataset);
             $menus['favs'] = $favd_menu_item;
         }
     }
     return $menus;
 }
Esempio n. 14
0
    public function getDashboardMenuItems($instance) {
        $fb_data_tpl = Utils::getPluginViewDirectory('facebook').'facebook.inline.view.tpl';

        $menus = array();

        //All tab
        $alltab = new MenuItem("All", '', $fb_data_tpl, 'Posts');
        $alltabds = new Dataset("all_facebook_posts", 'PostDAO', "getAllPosts",
        array($instance->network_user_id, $instance->network, 15, "#page_number#"),
        'getAllPostsIterator', array($instance->network_user_id, $instance->network, GridController::MAX_ROWS), false );
        $alltab->addDataset($alltabds);
        $menus["all_facebook_posts"] = $alltab;

        // Most replied-to tab
        $mrttab = new MenuItem("Most replied-to", "Posts with most replies", $fb_data_tpl);
        $mrttabds = new Dataset("most_replied_to_posts", 'PostDAO', "getMostRepliedToPosts",
        array($instance->network_user_id, $instance->network, 15, '#page_number#'));
        $mrttab->addDataset($mrttabds);
        $menus["mostreplies"] = $mrttab;

        //Questions tab
        $qtab = new MenuItem("Inquiries", "Inquiries, or posts with a question mark in them",
        $fb_data_tpl);
        $qtabds = new Dataset("all_facebook_posts", 'PostDAO', "getAllQuestionPosts",
        array($instance->network_user_id, $instance->network, 15, "#page_number#"));
        $qtab->addDataset($qtabds);
        $menus["questions"] = $qtab;

        return $menus;
    }
Esempio n. 15
0
 public function testGetPostDetailMenuItem()
 {
     $webapp = Webapp::getInstance();
     $config = Config::getInstance();
     $webapp->registerPlugin('twitter', "TwitterPlugin");
     $webapp->setActivePlugin('twitter');
     $post = new Post(array('id' => 1, 'author_user_id' => 10, 'author_username' => 'no one', 'author_fullname' => "No One", 'author_avatar' => 'yo.jpg', 'source' => 'TweetDeck', 'pub_date' => '', 'adj_pub_date' => '', 'in_reply_to_user_id' => '', 'in_reply_to_post_id' => '', 'reply_count_cache' => '', 'in_retweet_of_post_id' => '', 'retweet_count_cache' => '', 'retweet_count_api' => '', 'old_retweet_count_cache' => '', 'in_rt_of_user_id' => '', 'post_id' => 9021481076.0, 'is_protected' => 0, 'place_id' => 'ece7b97d252718cc', 'favlike_count_cache' => 0, 'post_text' => 'I look cookies', 'network' => 'twitter', 'geo' => '', 'place' => '', 'location' => '', 'is_geo_encoded' => 0, 'is_reply_by_friend' => 0, 'is_retweet_by_friend' => 0, 'reply_retweet_distance' => 0));
     $menu_item = $webapp->getPostDetailMenuItem('fwds', $post);
     $this->assertIsA($menu_item, 'MenuItem');
     $this->assertEqual($menu_item->view_template, Utils::getPluginViewDirectory('twitter') . 'twitter.post.retweets.tpl', "Template ");
     $this->assertEqual($menu_item->name, 'Retweets', "Name");
     $this->assertEqual($menu_item->description, 'Retweets of this tweet', "Description");
     $this->assertIsA($menu_item->datasets, 'array');
     $this->assertEqual(sizeOf($menu_item->datasets), 1);
     $menu_item = $webapp->getPostDetailMenuItem('nonexistent', $post);
     $this->assertEqual($menu_item, null);
 }
Esempio n. 16
0
 public function getChildTabsUnderLinks($instance)
 {
     global $ld;
     $fb_data_tpl = Utils::getPluginViewDirectory('facebook') . 'facebook.inline.view.tpl';
     $child_tabs = array();
     //Links from friends
     $fltab = new WebappTab("links_from_friends", 'Links', 'Links posted on your wall', $fb_data_tpl);
     $fltabds = new WebappTabDataset("links_from_friends", $ld, "getLinksByFriends", array($instance->network_user_id));
     $fltab->addDataset($fltabds);
     array_push($child_tabs, $fltab);
     return $child_tabs;
 }
Esempio n. 17
0
 public function getDashboardMenuItems($instance)
 {
     $menus = array();
     $posts_data_tpl = Utils::getPluginViewDirectory('googleplus') . 'posts.tpl';
     $posts_menu_item = new MenuItem("Posts", "Post insights", $posts_data_tpl);
     $posts_menu_ds_1 = new Dataset("all_posts", 'PostDAO', "getAllPosts", array($instance->network_user_id, $instance->network, 3, "#page_number#"), 'getAllPostsIterator', array($instance->network_user_id, $instance->network, GridController::getMaxRows()), false);
     $posts_menu_item->addDataset($posts_menu_ds_1);
     $posts_menu_ds_2 = new Dataset("most_replied_to", 'PostDAO', "getMostRepliedToPosts", array($instance->network_user_id, $instance->network, 3, '#page_number#'));
     $posts_menu_item->addDataset($posts_menu_ds_2);
     $posts_menu_ds_3 = new Dataset("plus_oned", 'PostDAO', "getMostFavedPosts", array($instance->network_user_id, $instance->network, 3, '#page_number#'));
     $posts_menu_item->addDataset($posts_menu_ds_3);
     $posts_menu_ds_4 = new Dataset("questions", 'PostDAO', "getAllQuestionPosts", array($instance->network_user_id, $instance->network, 3, "#page_number#"));
     $posts_menu_item->addDataset($posts_menu_ds_4);
     $menus['posts'] = $posts_menu_item;
     $gp_data_tpl = Utils::getPluginViewDirectory('googleplus') . 'googleplus.inline.view.tpl';
     //All tab
     $alltab = new MenuItem("All posts", 'All posts', $gp_data_tpl, 'posts');
     $alltabds = new Dataset("gplus_posts", 'PostDAO', "getAllPosts", array($instance->network_user_id, $instance->network, 15, "#page_number#"), 'getAllPostsIterator', array($instance->network_user_id, $instance->network, GridController::getMaxRows()), false);
     $alltabds->addHelp('userguide/listings/googleplus/dashboard_all_gplus_posts');
     $alltab->addDataset($alltabds);
     $menus["posts-all"] = $alltab;
     // Most replied-to tab
     $mrttab = new MenuItem("Most discussed", "Posts with the most comments", $gp_data_tpl, 'posts');
     $mrttabds = new Dataset("gplus_posts", 'PostDAO', "getMostRepliedToPosts", array($instance->network_user_id, $instance->network, 15, '#page_number#'));
     $mrttabds->addHelp('userguide/listings/googleplus/dashboard_mostreplies');
     $mrttab->addDataset($mrttabds);
     $menus["posts-mostreplies"] = $mrttab;
     // Most liked posts
     $mltab = new MenuItem("Most +1'ed", "Posts with most +1s", $gp_data_tpl, 'posts');
     $mltabds = new Dataset("gplus_posts", 'PostDAO', "getMostFavedPosts", array($instance->network_user_id, $instance->network, 15, '#page_number#'));
     $mltabds->addHelp('userguide/listings/googleplus/dashboard_mostlikes');
     $mltab->addDataset($mltabds);
     $menus["posts-mostplusones"] = $mltab;
     //Questions tab
     $qtab = new MenuItem("Inquiries", "Inquiries, or posts with a question mark in them", $gp_data_tpl, 'posts');
     $qtabds = new Dataset("gplus_posts", 'PostDAO', "getAllQuestionPosts", array($instance->network_user_id, $instance->network, 15, "#page_number#"));
     $qtabds->addHelp('userguide/listings/googleplus/dashboard_questions');
     $qtab->addDataset($qtabds);
     $menus["posts-questions"] = $qtab;
     return $menus;
 }
 /**
  * Send out insight email digest for a given time period.
  * @param Owner $owner Owner to send for
  * @param str $start When to start insight lookup
  * @param str $template Email view template to use
  * @param array $options Plugin options
  * @param bool $weekly Is this a weekly email?
  * return bool Whether email was sent
  */
 private function sendDigestSinceWithTemplate($owner, $start, $template, &$options, $weekly)
 {
     $insights_dao = DAOFactory::GetDAO('InsightDAO');
     $start_time = date('Y-m-d H:i:s', strtotime($start, $this->current_timestamp));
     $insights = $insights_dao->getAllOwnerInstanceInsightsSince($owner->id, $start_time);
     $num_insights = count($insights);
     if ($num_insights == 0) {
         return false;
     }
     $config = Config::getInstance();
     $view = new ViewManager();
     $view->caching = false;
     $logger = Logger::getInstance();
     // If we've got a Mandrill key and template, send HTML
     if ($config->getValue('mandrill_api_key') != null && !empty($options['mandrill_template'])) {
         $logger->logUserInfo("Mandrill API key and template set; sending HTML", __METHOD__ . ',' . __LINE__);
         $view->assign('insights', $insights);
         $view->assign('application_url', Utils::getApplicationURL());
         $view->assign('header_text', $this->getEmailMessageHeaderText());
         if (Utils::isThinkUpLLC()) {
             $logger->logUserInfo("Email via ThinkUpLLC, process welcome / free trial messaging", __METHOD__ . ',' . __LINE__);
             $thinkupllc_endpoint = $config->getValue('thinkupllc_endpoint');
             $view->assign('thinkupllc_endpoint', $thinkupllc_endpoint);
             $view->assign('unsub_url', $thinkupllc_endpoint . 'settings.php');
             $view->assign('install_folder', $config->getValue('install_folder'));
             if (!isset($options['last_daily_email'])) {
                 $logger->logUserInfo("No daily email ever sent before, include welcome message", __METHOD__ . ',' . __LINE__);
                 $view->assign('show_welcome_message', true);
             } else {
                 if ($owner->is_free_trial) {
                     $logger->logUserInfo("Owner is in free trial", __METHOD__ . ',' . __LINE__);
                     $creation_date = new DateTime($owner->joined);
                     $now = new DateTime();
                     $end_of_trial = $creation_date->add(new DateInterval('P15D'));
                     if ($end_of_trial >= $now) {
                         $interval = $now->diff($end_of_trial);
                         $days_left = $interval->format('%a');
                         if ($days_left > 2) {
                             $view->assign('pay_prompt_headline', $days_left . ' days left in your free trial!');
                         } elseif ($days_left == 0) {
                             //Last day
                             $view->assign('pay_prompt_headline', 'Last chance!');
                         } else {
                             //Show hours if it's 24 or 48 hours
                             $view->assign('pay_prompt_headline', 'Only ' . $days_left * 24 . ' hours left!');
                         }
                         $explainer_copy_options = array("Your free trial expires today. Don't lose any of your insights!", "It's time to become a member. We'd love to have you.", "It's just " . ($owner->membership_level == 'Member' ? '16' : '32') . " cents a day to get smarter about the time you spend online.", "Isn't this better than boring \"analytics\"?", "Just wait 'til you see ThinkUp next week.", "We never sell your data and we don't show you ads.", "Get our exclusive book on the future of social media for free.", "ThinkUp gives you social network superpowers.", "The longer you use ThinkUp, the smarter it gets.", "ThinkUp helps you be more thoughtful about your time online.", "ThinkUp works in email, on the web, and on all your devices.", "ThinkUp members can cancel at any time—with no hassles.", 'Wait until you see what ThinkUp has in store tomorrow.', "Your morning ThinkUp email will make your day.");
                         $view->assign('pay_prompt_explainer', $explainer_copy_options[$days_left]);
                         if ($owner->membership_level == 'Member') {
                             $view->assign('pay_prompt_button_label', 'Just $5/month');
                         } elseif ($owner->membership_level == 'Pro') {
                             $view->assign('pay_prompt_button_label', 'Just $10/month');
                         }
                     }
                 } else {
                     //Check subscription status and show a message if Payment failed or due
                     $logger->logUserInfo("User is not in free trial; check subscription status", __METHOD__ . ',' . __LINE__);
                     $thinkupllc_api_accessor = new ThinkUpLLCAPIAccessor();
                     $membership_details = $thinkupllc_api_accessor->getSubscriptionStatus($owner->email);
                     $logger->logUserInfo("Subscription status is " . Utils::varDumpToString($membership_details), __METHOD__ . ',' . __LINE__);
                     if (isset($membership_details->subscription_status) && ($membership_details->subscription_status == 'Payment failed' || $membership_details->subscription_status == 'Payment due')) {
                         $logger->logUserInfo("Owner has payment failure; include alert in email", __METHOD__ . ',' . __LINE__);
                         $payment_failed_copy = array();
                         if ($membership_details->subscription_status == 'Payment failed') {
                             $payment_failed_copy[] = array('headline' => 'Oops! Your account needs attention', 'explainer' => "We had a problem processing your membership payment. " . "But it's easy to fix.");
                             $payment_failed_copy[] = array('headline' => 'Uh oh, problem with your subscription...', 'explainer' => "There was a problem processing your membership payment. " . "To fix it, update your payment info.");
                             $payment_failed_copy[] = array('headline' => 'Your ThinkUp subscription is out of date...', 'explainer' => "We tried to charge your Amazon account for your ThinkUp membership," . " and there was an error. But it's easy to fix.");
                             $payment_failed_copy[] = array('headline' => 'Action required to keep your ThinkUp account active', 'explainer' => "We weren't able to process your last membership payment—maybe your " . "info is out of date? Fixing it just takes a moment.");
                             $payment_failed_copy[] = array('headline' => "Urgent! Keep your ThinkUp account active", 'explainer' => "We tried to process your ThinkUp subscription, but " . "the payment was not successful. Please update your payment information " . "now to make sure your ThinkUp membership stays in good standing.");
                             $payment_failed_button_label = "Update your payment info";
                         } else {
                             //Payment due
                             $payment_failed_copy[] = array('headline' => 'Oops! Your ThinkUp membership needs attention', 'explainer' => "Looks like you've got a membership payment due. " . "But it's easy to make it.");
                             $payment_failed_copy[] = array('headline' => "Uh-oh, don't let your subscription expire", 'explainer' => "Looks like your ThinkUp payment is due. " . "Make it now so your account doesn't expire.");
                             $payment_failed_copy[] = array('headline' => 'Hey, your ThinkUp subscription payment is due', 'explainer' => "Your membership payment isn't up-to-date. " . " But it's easy to fix.");
                             $payment_failed_copy[] = array('headline' => 'Action required: Keep your ThinkUp account active', 'explainer' => "Looks like you've got a membership payment due. " . "Making it just takes a moment.");
                             $payment_failed_copy[] = array('headline' => "Urgent! Keep your ThinkUp account active", 'explainer' => "Your subscription payment is due. " . "Please update your information now to keep your ThinkUp membership " . "in good standing.");
                             $payment_failed_button_label = "Make your payment";
                         }
                         $copy_index = TimeHelper::getDayOfYear() % count($payment_failed_copy);
                         $payment_failed_headline = $payment_failed_copy[$copy_index]['headline'];
                         $payment_failed_explainer = $payment_failed_copy[$copy_index]['explainer'];
                         $view->assign('payment_failed_headline', $payment_failed_headline);
                         $view->assign('payment_failed_explainer', $payment_failed_explainer);
                         $view->assign('payment_failed_button_label', $payment_failed_button_label);
                     }
                 }
             }
             $thinkupllc_email_tout = $config->getValue('thinkupllc_email_tout');
             if (isset($thinkupllc_email_tout)) {
                 $view->assign('thinkupllc_email_tout', $thinkupllc_email_tout);
             }
         } else {
             $logger->logUserInfo("Email is NOT via ThinkUpLLC", __METHOD__ . ',' . __LINE__);
             $view->assign('unsub_url', Utils::getApplicationURL() . 'account/index.php?m=manage#instances');
         }
         // It's a weekly digest if we're going back more than a day or two.
         $daily_or_weekly = $weekly ? 'Weekly' : 'Daily';
         $view->assign('weekly_or_daily', $daily_or_weekly);
         $view->assign('pay_prompt_url', $config->getValue('thinkupllc_endpoint') . 'membership.php');
         if ($config->getValue('image_proxy_enabled') == true) {
             $view->assign('image_proxy_sig', $config->getValue('image_proxy_sig'));
         }
         $insights_markup = $view->fetch(Utils::getPluginViewDirectory($this->folder_name) . '_email.insights_html.tpl');
         $parameters = array();
         $parameters['insights'] = $insights_markup;
         $parameters['app_title'] = $config->getValue('app_title_prefix') . "ThinkUp";
         $parameters['application_url'] = Utils::getApplicationURL();
         $parameters['weekly_or_daily'] = $daily_or_weekly;
         try {
             if (!isset($options['last_daily_email'])) {
                 $subject_line = "Welcome to ThinkUp! Here are your insights.";
             } else {
                 $subject_line = $this->getEmailMessageSubjectLine($daily_or_weekly, $insights);
             }
             $logger->logUserInfo("About to call Mailer::mailHTMLViaMandrillTemplate", __METHOD__ . ',' . __LINE__);
             Mailer::mailHTMLViaMandrillTemplate($owner->email, $subject_line, $options['mandrill_template']->option_value, $parameters);
             return true;
         } catch (Mandrill_Unknown_Template $e) {
             // In this case, we'll fall back to plain text sending and warn the user in the log
             $logger->logUserError("Invalid mandrill template configured:" . $options['mandrill_template']->option_value . ".", __METHOD__ . ',' . __LINE__);
             unset($options['mandrill_template']);
         }
     } else {
         if ($config->getValue('mandrill_api_key') == null) {
             $logger->logUserInfo("Mandrill API key is null", __METHOD__ . ',' . __LINE__);
         }
         if (empty($options['mandrill_template'])) {
             $logger->logUserInfo("Mandrill template is not set", __METHOD__ . ',' . __LINE__);
         }
     }
     $view->assign('app_title', $config->getValue('app_title_prefix') . "ThinkUp");
     $view->assign('application_url', Utils::getApplicationURL());
     $view->assign('insights', $insights);
     $message = $view->fetch(Utils::getPluginViewDirectory($this->folder_name) . $template);
     list($subject, $message) = explode("\n", $message, 2);
     $logger->logUserInfo("About to call Mailer::mail", __METHOD__ . ',' . __LINE__);
     Mailer::mail($owner->email, $subject, $message);
     return true;
 }
Esempio n. 19
0
 public function getChildTabsUnderLinks($instance)
 {
     $ld = DAOFactory::getDAO('LinkDAO');
     $twitter_data_tpl = Utils::getPluginViewDirectory('twitter') . 'twitter.inline.view.tpl';
     $child_tabs = array();
     //Links from friends
     $fltab = new WebappTab("links-friends", 'Links From Friends', 'Links your friends posted', $twitter_data_tpl);
     $fltabds = new WebappTabDataset("links", $ld, "getLinksByFriends", array($instance->network_user_id));
     $fltab->addDataset($fltabds);
     array_push($child_tabs, $fltab);
     //Links from favorites
     /* $lftab = new WebappTab("links-favorites", 'Links From Favorites', 'Links in posts you favorited');
        $lftabds = new WebappTabDataset("links", $ld, "getLinksByFriends", array($instance->network_user_id));
        $lftab->addDataset($lftabds);
        array_push($child_tabs, $lftab);
        */
     //Photos
     $ptab = new WebappTab("links-photos", "Photos", 'Photos your friends have posted', $twitter_data_tpl);
     $ptabds = new WebappTabDataset("links", $ld, "getPhotosByFriends", array($instance->network_user_id));
     array_push($child_tabs, $ptab);
     return $child_tabs;
 }
Esempio n. 20
0
 public function getPostDetailMenuItems($post)
 {
     $facebook_data_tpl = Utils::getPluginViewDirectory('facebook') . 'facebook.post.likes.tpl';
     $menus = array();
     if ($post->network == 'facebook' || $post->network == 'facebook page') {
         $likes_menu_item = new MenuItem("Likes", "Those who liked this post", $facebook_data_tpl);
         //if not logged in, show only public fav'd info
         $liked_dataset = new Dataset("likes", 'FavoritePostDAO', "getUsersWhoFavedPost", array($post->post_id, $post->network, !Session::isLoggedIn()));
         $likes_menu_item->addDataset($liked_dataset);
         $menus['likes'] = $likes_menu_item;
     }
     return $menus;
 }
Esempio n. 21
0
 public function getDashboardMenu($instance)
 {
     $twitter_data_tpl = Utils::getPluginViewDirectory('twitter') . 'twitter.inline.view.tpl';
     $menus = array();
     $tweets_menu = new Menu('Tweets');
     //All tab
     $all_mi = new MenuItem("tweets-all", "All Tweets", "All tweets", $twitter_data_tpl);
     $all_mi_ds = new Dataset("all_tweets", 'PostDAO', "getAllPosts", array($instance->network_user_id, 'twitter', 15, "#page_number#"), 'getAllPostsIterator', array($instance->network_user_id, 'twitter', GridController::MAX_ROWS));
     $all_mi->addDataset($all_mi_ds);
     $tweets_menu->addMenuItem($all_mi);
     //Questions
     $q_mi = new MenuItem("tweets-questions", "Inquiries", "Inquiries, or tweets with a question mark in them", $twitter_data_tpl);
     $q_mi_ds = new Dataset("all_tweets", 'PostDAO', "getAllQuestionPosts", array($instance->network_user_id, 'twitter', 15, "#page_number#"));
     $q_mi->addDataset($q_mi_ds);
     $tweets_menu->addMenuItem($q_mi);
     // Most replied-to
     $mrt_mi = new MenuItem("tweets-mostreplies", "Most replied-to", "Tweets with most replies", $twitter_data_tpl);
     $mrt_mi_ds = new Dataset("most_replied_to_tweets", 'PostDAO', "getMostRepliedToPosts", array($instance->network_user_id, 'twitter', 15, '#page_number#'));
     $mrt_mi->addDataset($mrt_mi_ds);
     $tweets_menu->addMenuItem($mrt_mi);
     // Most shared
     $mstab = new MenuItem("tweets-mostretweeted", "Most retweeted", "Most retweeted tweets", $twitter_data_tpl);
     $mstabds = new Dataset("most_retweeted", 'PostDAO', "getMostRetweetedPosts", array($instance->network_user_id, 'twitter', 15, '#page_number#'));
     $mstab->addDataset($mstabds);
     $tweets_menu->addMenuItem($mstab);
     array_push($menus, $tweets_menu);
     $replies_menu = new Menu('Replies');
     if (Session::isLoggedIn()) {
         //show protected tweets
         //All Mentions
         $amtab = new MenuItem("mentions-all", "All Mentions", "Any post that mentions you", $twitter_data_tpl);
         $amtabds1 = new Dataset("all_tweets", 'PostDAO', "getAllPosts", array($instance->network_user_id, 'twitter', 15), "getAllMentionsIterator", array($instance->network_username, GridController::MAX_ROWS, 'twitter'));
         $amtabds2 = new Dataset("all_mentions", 'PostDAO', "getAllMentions", array($instance->network_username, 15, $instance->network, '#page_number#'));
         $amtab->addDataset($amtabds1);
         $amtab->addDataset($amtabds2);
         $replies_menu->addMenuItem($amtab);
         //All Replies
         $artab = new MenuItem("mentions-allreplies", "Replies", "Posts that directly reply to you (i.e., start with your name)", $twitter_data_tpl);
         $artabds = new Dataset("all_replies", 'PostDAO', "getAllReplies", array($instance->network_user_id, 'twitter', 15));
         $artab->addDataset($artabds);
         $replies_menu->addMenuItem($artab);
         //All Orphan Mentions
         $omtab = new MenuItem("mentions-orphan", "Not Replies or Forwards", "Mentions that are not associated with a specific post", $twitter_data_tpl);
         $omtabds1 = new Dataset("all_tweets", 'PostDAO', "getAllPosts", array($instance->network_user_id, 'twitter', 15));
         $omtabds2 = new Dataset("orphan_replies", 'PostDAO', "getOrphanReplies", array($instance->network_username, 5, $instance->network));
         $omtab->addDataset($omtabds1);
         $omtab->addDataset($omtabds2);
         $replies_menu->addMenuItem($omtab);
         //All Mentions Standalone
         $sttab = new MenuItem("mentions-standalone", "Standalone Mentions", "Mentions you have marked as standalone", $twitter_data_tpl);
         $sttabds1 = new Dataset("standalone_replies", 'PostDAO', "getStandaloneReplies", array($instance->network_username, 'twitter', 15));
         $sttabds2 = new Dataset("all_tweets", 'PostDAO', "getAllPosts", array($instance->network_user_id, 'twitter', 15));
         $sttab->addDataset($sttabds1);
         $sttab->addDataset($sttabds2);
         $replies_menu->addMenuItem($sttab);
     } else {
         //All public mentions
         $amtab = new MenuItem("mentions-all", "All Mentions", "Any post that mentions you", $twitter_data_tpl);
         $amtabds2 = new Dataset("all_mentions", 'PostDAO', "getAllMentions", array($instance->network_username, 15, $instance->network, '#page_number#', true));
         $amtab->addDataset($amtabds2);
         $replies_menu->addMenuItem($amtab);
     }
     // Conversations
     $convotab = new MenuItem("tweets-convo", "Conversations", "Exchanges between you and other users", $twitter_data_tpl);
     $convotabds = new Dataset("author_replies", 'PostDAO', "getPostsAuthorHasRepliedTo", array($instance->network_user_id, 15, 'twitter', '#page_number#'));
     $convotab->addDataset($convotabds);
     $replies_menu->addMenuItem($convotab);
     array_push($menus, $replies_menu);
     $friends_menu = new Menu('Who You Follow');
     //Most Active Friends
     $motab = new MenuItem("friends-mostactive", 'Chatterboxes', '', $twitter_data_tpl);
     $motabds = new Dataset('people', 'FollowDAO', "getMostActiveFollowees", array($instance->network_user_id, 'twitter', 15));
     $motab->addDataset($motabds);
     $friends_menu->addMenuItem($motab);
     //Least Active Friends
     $latab = new MenuItem("friends-leastactive", 'Deadbeats', '', $twitter_data_tpl);
     $latabds = new Dataset("people", 'FollowDAO', "getLeastActiveFollowees", array($instance->network_user_id, 'twitter', 15));
     $latab->addDataset($latabds);
     $friends_menu->addMenuItem($latab);
     //Popular friends
     $poptab = new MenuItem("friends-mostfollowed", 'Popular', '', $twitter_data_tpl);
     $poptabds = new Dataset("people", 'FollowDAO', "getMostFollowedFollowees", array($instance->network_user_id, 'twitter', 15));
     $poptab->addDataset($poptabds);
     $friends_menu->addMenuItem($poptab);
     if (Session::isLoggedIn()) {
         //Former Friends
         $fftab = new MenuItem("friends-former", "Former", '', $twitter_data_tpl);
         $fftabds = new Dataset("people", 'FollowDAO', "getFormerFollowees", array($instance->network_user_id, 'twitter', 15));
         $fftab->addDataset($fftabds);
         $friends_menu->addMenuItem($fftab);
         //Not Mutual Friends
         $nmtab = new MenuItem("friends-notmutual", "Not Mutual", '', $twitter_data_tpl);
         $nmtabds = new Dataset("people", 'FollowDAO', "getFriendsNotFollowingBack", array('twitter', $instance->network_user_id));
         $nmtab->addDataset($nmtabds);
         $friends_menu->addMenuItem($nmtab);
     }
     array_push($menus, $friends_menu);
     $followers_menu = new Menu('Followers');
     //Follower count history
     $follower_history_tpl = Utils::getPluginViewDirectory('twitter') . 'twitter.followercount.tpl';
     $trendtab = new MenuItem('followers-history', 'Follower Count', 'Your follower count over time', $follower_history_tpl);
     $trendtabds = new Dataset("historybyday", 'FollowerCountDAO', 'getHistory', array($instance->network_user_id, 'twitter', 'DAY', 20));
     $trendtab->addDataset($trendtabds);
     $trendtabweekds = new Dataset("historybyweek", 'FollowerCountDAO', 'getHistory', array($instance->network_user_id, 'twitter', 'WEEK', 20));
     $trendtab->addDataset($trendtabweekds);
     $trendtabmonthds = new Dataset("historybymonth", 'FollowerCountDAO', 'getHistory', array($instance->network_user_id, 'twitter', 'MONTH', 20));
     $trendtab->addDataset($trendtabmonthds);
     $followers_menu->addMenuItem($trendtab);
     //Most followed
     $mftab = new MenuItem("followers-mostfollowed", 'Most-followed', 'Followers with most followers', $twitter_data_tpl);
     $mftabds = new Dataset("people", 'FollowDAO', "getMostFollowedFollowers", array($instance->network_user_id, 'twitter', 15));
     $mftab->addDataset($mftabds);
     $followers_menu->addMenuItem($mftab);
     //Least likely
     $lltab = new MenuItem("followers-leastlikely", "Least Likely", 'Followers with the greatest follower-to-friend ratio', $twitter_data_tpl);
     $lltabds = new Dataset("people", 'FollowDAO', "getLeastLikelyFollowers", array($instance->network_user_id, 'twitter', 15));
     $lltab->addDataset($lltabds);
     $followers_menu->addMenuItem($lltab);
     if (Session::isLoggedIn()) {
         //Former followers
         $fftab = new MenuItem("followers-former", "Former", '', $twitter_data_tpl);
         $fftabds = new Dataset("people", 'FollowDAO', "getFormerFollowers", array($instance->network_user_id, 'twitter', 15));
         $fftab->addDataset($fftabds);
         $followers_menu->addMenuItem($fftab);
     }
     //Earliest
     $eftab = new MenuItem("followers-earliest", "Earliest Joiners", '', $twitter_data_tpl);
     $eftabds = new Dataset("people", 'FollowDAO', "getEarliestJoinerFollowers", array($instance->network_user_id, 'twitter', 15));
     $eftab->addDataset($eftabds);
     $followers_menu->addMenuItem($eftab);
     array_push($menus, $followers_menu);
     $links_menu = new Menu('Links');
     //Links from friends
     $fltab = new MenuItem("links-friends", 'Links from People You Follow', 'Links your friends posted', $twitter_data_tpl);
     $fltabds = new Dataset("links", 'LinkDAO', "getLinksByFriends", array($instance->network_user_id, 'twitter'));
     $fltab->addDataset($fltabds);
     $links_menu->addMenuItem($fltab);
     //Links from favorites
     /* $lftab = new MenuItem("links-favorites", 'Links From Favorites', 'Links in posts you favorited');
        $lftabds = new Dataset("links", 'LinkDAO', "getLinksByFriends", array($instance->network_user_id,
        'twitter'));
        $lftab->addDataset($lftabds);
        array_push($child_tabs, $lftab);
        */
     //Photos
     $ptab = new MenuItem("links-photos", "Photos from People You Follow", 'Photos your friends have posted', $twitter_data_tpl);
     $ptabds = new Dataset("links", 'LinkDAO', "getPhotosByFriends", array($instance->network_user_id, 'twitter'));
     $ptab->addDataset($ptabds);
     $links_menu->addMenuItem($ptab);
     array_push($menus, $links_menu);
     return $menus;
 }