public function setUp()
 {
     parent::setUp();
     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     $webapp_plugin_registrar->registerPlugin('youtube', 'YouTubePlugin');
     $_SERVER['SERVER_NAME'] = 'test';
 }
 public function setUp()
 {
     parent::setUp();
     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     $webapp_plugin_registrar->registerPlugin('expandurls', 'ExpandURLsPlugin');
     $this->builders = self::buildData();
 }
 /**
  * Load the view with required variables
  */
 private function loadView()
 {
     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     if ($this->view_name == 'default') {
         $this->loadDefaultDashboard();
     } else {
         $menu_item = $webapp_plugin_registrar->getDashboardMenuItem($this->view_name, $this->instance);
         if (isset($menu_item)) {
             $this->addToView('data_template', $menu_item->view_template);
             $this->addToView('display', $this->view_name);
             $this->addToView('header', $menu_item->name);
             $this->addToView('description', $menu_item->description);
             $this->addToView('parent', $menu_item->parent);
             $this->setPageTitle($this->instance->network_username . ' on ' . ucfirst($this->instance->network));
             $page = isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1;
             foreach ($menu_item->datasets as $dataset) {
                 if (array_search('#page_number#', $dataset->method_params) !== false) {
                     //there's paging
                     $this->addToView('next_page', $page + 1);
                     $this->addToView('last_page', $page - 1);
                 }
                 $this->addToView($dataset->name, $dataset->retrieveDataset($page));
                 if (Session::isLoggedIn() && $dataset->isSearchable()) {
                     $view_name = 'is_searchable';
                     $this->addToView($view_name, true);
                 }
                 $this->view_mgr->addHelp($this->view_name, $dataset->getHelp());
             }
         } else {
             $this->loadDefaultDashboard();
         }
     }
 }
 public function adminControl()
 {
     if (!$this->is_missing_param) {
         // verify CSRF token
         $this->validateCSRFToken();
         $is_active = $_GET["a"] != 1 ? false : true;
         $plugin_dao = DAOFactory::getDAO('PluginDAO');
         $result = $plugin_dao->setActive($_GET["pid"], $is_active);
         if ($result > 0) {
             $plugin_folder = $plugin_dao->getPluginFolder($_GET["pid"]);
             $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
             try {
                 $plugin_class_name = $webapp_plugin_registrar->getPluginObject($plugin_folder);
                 $p = new $plugin_class_name();
                 if ($is_active) {
                     $p->activate();
                 } else {
                     $p->deactivate();
                 }
             } catch (Exception $e) {
                 //plugin object isn't registered, do nothing
                 //echo $e->getMessage();
             }
         }
         $this->addToView('result', $result);
         $this->view_mgr->clear_all_cache();
     }
     return $this->generateView();
 }
 public function setUp()
 {
     parent::setUp();
     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     $webapp_plugin_registrar->registerPlugin('twitter', 'TwitterPlugin');
     $this->builders = self::buildData();
 }
Example #6
0
 public function setUp()
 {
     parent::setUp();
     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     $webapp_plugin_registrar->registerPlugin('youtube', 'YouTubePlugin');
     $webapp_plugin_registrar->setActivePlugin('youtube');
 }
 public function setUp()
 {
     parent::setUp();
     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     $webapp_plugin_registrar->registerPlugin('google+', 'HelloThinkUpPlugin');
     $webapp_plugin_registrar->setActivePlugin('google+');
 }
 /**
  * Destroy Config, Webapp, $_SESSION, $_POST, $_GET, $_REQUEST
  */
 public function tearDown()
 {
     Config::destroyInstance();
     PluginRegistrarWebapp::destroyInstance();
     PluginRegistrarCrawler::destroyInstance();
     if (isset($_SESSION)) {
         $this->unsetArray($_SESSION);
     }
     $this->unsetArray($_POST);
     $this->unsetArray($_GET);
     $this->unsetArray($_REQUEST);
     $this->unsetArray($_SERVER);
     $this->unsetArray($_FILES);
     Loader::unregister();
     $backup_dir = FileDataManager::getBackupPath();
     if (file_exists($backup_dir)) {
         try {
             @exec('cd ' . $backup_dir . '; rm -rf *');
             rmdir($backup_dir);
             // won't delete if has files
         } catch (Exception $e) {
         }
     }
     $data_dir = FileDataManager::getDataPath();
     if (file_exists($data_dir . 'compiled_view')) {
         try {
             @exec('cd ' . $data_dir . '; rm -rf compiled_view');
         } catch (Exception $e) {
         }
     }
     parent::tearDown();
 }
 public function setUp()
 {
     parent::setUp();
     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     $webapp_plugin_registrar->registerPlugin('google+', 'TwitterRealtimePlugin');
     $webapp_plugin_registrar->setActivePlugin('google+');
 }
 public function setUp()
 {
     parent::setUp();
     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     $webapp_plugin_registrar->registerPlugin('googleplus', 'GooglePlusPlugin');
     $_SERVER['SERVER_NAME'] = 'test';
 }
Example #11
0
 public function setUp()
 {
     parent::setUp();
     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     $webapp_plugin_registrar->registerPlugin('twitter', 'TwitterPlugin');
     $this->config = Config::getInstance();
 }
 public function setUp()
 {
     parent::setUp();
     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     $webapp_plugin_registrar->registerPlugin('twitter', 'TwitterPlugin');
     $webapp_plugin_registrar->registerPlugin('facebook', 'FacebookPlugin');
     $webapp_plugin_registrar->registerPlugin('google+', 'GooglePlusPlugin');
 }
 public function setUp()
 {
     parent::setUp();
     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     $webapp_plugin_registrar->registerPlugin('geoencoder', 'GeoEncoderPlugin');
     $_SERVER['SERVER_NAME'] = 'dev.thinkup.com';
     $_SERVER['HTTP_HOST'] = 'dev.thinkup.com';
 }
 public function setUp()
 {
     parent::setUp();
     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     $webapp_plugin_registrar->registerPlugin('twitter', 'TwitterPlugin');
     $this->builders = self::buildData();
     $_SERVER['HTTP_HOST'] = "mytesthost";
     $_SERVER['SERVER_NAME'] = 'dev.thinkup.com';
 }
Example #15
0
 /**
  * Test activePlugin getter/setter
  */
 public function testWebappGetSetActivePlugin()
 {
     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     $this->assertEqual($webapp_plugin_registrar->getActivePlugin(), "twitter");
     $webapp_plugin_registrar->setActivePlugin('facebook');
     $this->assertEqual($webapp_plugin_registrar->getActivePlugin(), "facebook");
     //make sure another instance reports back the same values
     $webapp_plugin_registrar_two = PluginRegistrarWebapp::getInstance();
     $this->assertEqual($webapp_plugin_registrar_two->getActivePlugin(), "facebook");
 }
Example #16
0
 public function setUp()
 {
     parent::setUp();
     $this->webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     $this->webapp_plugin_registrar->registerPlugin('geoencoder', 'GeoEncoderPlugin');
     $this->webapp_plugin_registrar->registerPlugin('twitter', 'TwitterPlugin');
     $crawler_plugin_registrar = PluginRegistrarCrawler::getInstance();
     $crawler_plugin_registrar->registerCrawlerPlugin('GeoEncoderPlugin');
     $this->builders = self::buildData();
 }
 public function setUp()
 {
     parent::setUp();
     $this->webapp = PluginRegistrarWebapp::getInstance();
     $this->crawler = PluginRegistrarCrawler::getInstance();
     $this->webapp->registerPlugin('twitter', 'TwitterPlugin');
     $this->crawler->registerCrawlerPlugin('TwitterPlugin');
     $this->webapp->setActivePlugin('twitter');
     $this->logger = Logger::getInstance();
 }
 public function setUp()
 {
     // Call the ThinkUpUnitTestCase constructor
     parent::setUp();
     // Get an instance
     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     // Register the foursquare plugin
     $webapp_plugin_registrar->registerPlugin('foursquare', 'FoursquarePlugin');
     // Set the server name variable as we don't actually have a server
     $_SERVER['SERVER_NAME'] = 'test';
 }
 public function setUp()
 {
     parent::setUp();
     $this->builders = array();
     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     $webapp_plugin_registrar->registerPlugin('facebook', 'FacebookPlugin');
     $_SERVER['SERVER_NAME'] = 'dev.thinkup.com';
     $_SERVER['HTTP_HOST'] = 'dev.thinkup.com';
     $_SERVER['REQUEST_URI'] = '';
     //Add owners
     $owner_builder = FixtureBuilder::build('owners', array('id' => 1, 'full_name' => 'ThinkUp J. User', 'email' => '*****@*****.**', 'is_activated' => 1));
     array_push($this->builders, $owner_builder);
     //Add second owner
     $owner2_builder = FixtureBuilder::build('owners', array('id' => 2, 'full_name' => 'ThinkUp J. User 2', 'email' => '*****@*****.**', 'is_activated' => 1));
     array_push($this->builders, $owner2_builder);
 }
Example #20
0
 public function testMenuItemRegistration()
 {
     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     $instance = new Instance();
     $instance->network_user_id = 1;
     $menus = $webapp_plugin_registrar->getDashboardMenu($instance);
     // We only have one menu so far, the checkins
     $this->assertEqual(sizeof($menus), 1);
     $post_tab = $menus['posts'];
     $this->assertEqual($post_tab->name, "Checkins");
     $this->assertEqual($post_tab->description, "Your checkins");
     $post_tab_datasets = $post_tab->getDatasets();
     $this->assertEqual(count($post_tab_datasets), 1);
     $post_tab_dataset = $post_tab_datasets[0];
     $this->assertEqual($post_tab_dataset->name, "all_checkins");
     $this->assertEqual($post_tab_dataset->dao_name, 'PostDAO');
     $this->assertEqual($post_tab_dataset->dao_method_name, "getAllCheckins");
 }
 public function testDeactivate()
 {
     //all instagram accounts should be set to inactive on plugin deactivation
     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     $logger = Logger::getInstance();
     $pd = DAOFactory::getDAO('PostDAO');
     $instance = new Instance();
     $instance->network_user_id = 1;
     $instance_builder_1 = FixtureBuilder::build('instances', array('network_username' => 'julie', 'network' => 'instagram', 'crawler_last_run' => '-1d', 'is_activated' => '1', 'is_public' => '1'));
     $instance_dao = DAOFactory::getDAO('InstanceDAO');
     $fb_active_instances = $instance_dao->getAllInstances("DESC", true, "instagram");
     $this->assertEqual(sizeof($fb_active_instances), 1);
     $fb_plugin = new InstagramPlugin();
     $fb_plugin->deactivate();
     $fb_active_instances = $instance_dao->getAllInstances("DESC", true, "instagram");
     $this->assertEqual(sizeof($fb_active_instances), 0);
     $logger->close();
 }
 public function testMenuItemRegistration()
 {
     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     $logger = Logger::getInstance();
     $pd = DAOFactory::getDAO('PostDAO');
     $instance = new Instance();
     $instance->network_user_id = 1;
     $menus = $webapp_plugin_registrar->getDashboardMenu($instance);
     $posts_menu = $menus["posts-all"];
     $this->assertEqual(sizeof($menus), 5);
     $post_tab = $menus['posts-all'];
     $this->assertEqual($post_tab->name, "All posts");
     $this->assertEqual($post_tab->description, "All posts");
     $post_tab_datasets = $post_tab->getDatasets();
     $post_tab_dataset = $post_tab_datasets[0];
     $this->assertEqual($post_tab_dataset->name, "gplus_posts");
     $this->assertEqual($post_tab_dataset->dao_name, 'PostDAO');
     $this->assertEqual($post_tab_dataset->dao_method_name, "getAllPosts");
     $post_tab = $menus['posts-mostreplies'];
     $this->assertEqual($post_tab->name, "Most discussed");
     $this->assertEqual($post_tab->description, "Posts with the most comments");
     $post_tab_datasets = $post_tab->getDatasets();
     $post_tab_dataset = $post_tab_datasets[0];
     $this->assertEqual($post_tab_dataset->name, "gplus_posts");
     $this->assertEqual($post_tab_dataset->dao_name, 'PostDAO');
     $this->assertEqual($post_tab_dataset->dao_method_name, "getMostRepliedToPosts");
     $post_tab = $menus['posts-mostplusones'];
     $this->assertEqual($post_tab->name, "Most +1'ed");
     $this->assertEqual($post_tab->description, "Posts with most +1s");
     $post_tab_datasets = $post_tab->getDatasets();
     $post_tab_dataset = $post_tab_datasets[0];
     $this->assertEqual($post_tab_dataset->name, "gplus_posts");
     $this->assertEqual($post_tab_dataset->dao_name, 'PostDAO');
     $this->assertEqual($post_tab_dataset->dao_method_name, "getMostFavedPosts");
     $post_tab = $menus['posts-questions'];
     $this->assertEqual($post_tab->name, "Inquiries");
     $this->assertEqual($post_tab->description, "Inquiries, or posts with a question mark in them");
     $post_tab_datasets = $post_tab->getDatasets();
     $post_tab_dataset = $post_tab_datasets[0];
     $this->assertEqual($post_tab_dataset->name, "gplus_posts");
     $this->assertEqual($post_tab_dataset->dao_name, 'PostDAO');
     $this->assertEqual($post_tab_dataset->dao_method_name, "getAllQuestionPosts");
     $logger->close();
 }
Example #23
0
 public function testGetPostDetailMenuItem()
 {
     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     $config = Config::getInstance();
     $webapp_plugin_registrar->registerPlugin('twitter', "TwitterPlugin");
     $webapp_plugin_registrar->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, '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_plugin_registrar->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_plugin_registrar->getPostDetailMenuItem('nonexistent', $post);
     $this->assertEqual($menu_item, null);
 }
 /**
  * Provided only for tests that want to kill object in tearDown()
  */
 public static function destroyInstance()
 {
     if (isset(self::$instance)) {
         self::$instance = null;
     }
 }
Example #25
0
 /**
  * Outputs JavaScript callback string with json array/list of post as an argument
  */
 public function authControl($owner = false)
 {
     $public_search = false;
     if ($owner) {
         $public_search = true;
     }
     $private_reply_search = false;
     $this->setContentType('text/javascript');
     if (!$this->is_missing_param) {
         $instance_dao = DAOFactory::getDAO('InstanceDAO');
         if ($instance_dao->isUserConfigured($_GET['u'], $_GET['n'])) {
             $username = $_GET['u'];
             $ownerinstance_dao = DAOFactory::getDAO('OwnerInstanceDAO');
             $owner_dao = DAOFactory::getDAO('OwnerDAO');
             if (!$owner) {
                 $owner = $owner_dao->getByEmail($this->getLoggedInUser());
             }
             $instance = $instance_dao->getByUsername($username, $_GET['n']);
             if (!$ownerinstance_dao->doesOwnerHaveAccessToInstance($owner, $instance)) {
                 echo '{"status":"failed","message":"Insufficient privileges."}';
             } else {
                 echo "tu_grid_search.populate_grid(";
                 $posts_it;
                 if (isset($_GET['t'])) {
                     // replies?
                     $post_dao = DAOFactory::getDAO('PostDAO');
                     $posts_it = $post_dao->getRepliesToPostIterator($_GET['t'], $_GET['n'], 'default', 'km', $public_search);
                     if (!$public_search) {
                         $private_reply_search = true;
                     }
                 } else {
                     if (isset($_GET['nolimit']) && $_GET['nolimit'] == 'true') {
                         self::$MAX_ROWS = 0;
                     }
                     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
                     $webapp_plugin_registrar->setActivePlugin($instance->network);
                     $tab = $webapp_plugin_registrar->getDashboardMenuItem($_GET['d'], $instance);
                     $posts_it = $tab->datasets[0]->retrieveIterator();
                 }
                 echo '{"status":"success","limit":' . self::$MAX_ROWS . ',"posts": [' . "\n";
                 $cnt = 0;
                 // lets make sure we have a post iterator, and not just a list of posts
                 if (get_class($posts_it) != 'PostIterator') {
                     throw Exception("Grid Search should use a PostIterator to conserve memory");
                 }
                 foreach ($posts_it as $key => $value) {
                     if ($private_reply_search) {
                         if (!$ownerinstance_dao->doesOwnerHaveAccessToPost($owner, $value)) {
                             continue;
                         }
                     }
                     $cnt++;
                     $data = array('id' => $cnt, 'text' => $value->post_text, 'post_id_str' => $value->post_id . '_str', 'author' => $value->author_username, 'date' => $value->adj_pub_date, 'network' => $value->network);
                     echo json_encode($data) . ",\n";
                     flush();
                 }
                 $data = array('id' => -1, 'text' => 'Last Post', 'author' => 'nobody');
                 echo json_encode($data);
                 echo ']});';
             }
         } else {
             echo '{"status":"failed","message":"' . $_GET['u'] . 'is not configured."}';
         }
     } else {
         echo '{"status":"failed","message":"Missing Parameters"}';
     }
 }
 public function authControl()
 {
     $this->disableCaching();
     $this->addHeaderJavaScript('assets/js/jqBootstrapValidation.js');
     $this->addHeaderJavaScript('assets/js/validate-fields.js');
     $this->addHeaderJavaScript('assets/js/jstz-1.0.4.min.js');
     $owner_dao = DAOFactory::getDAO('OwnerDAO');
     $invite_dao = DAOFactory::getDAO('InviteDAO');
     $owner = $owner_dao->getByEmail($this->getLoggedInUser());
     $this->addToView('owner', $owner);
     $this->addToView('notification_options', $this->notification_frequencies);
     $this->addToView('tz_list', Installer::getTimeZoneList());
     $this->view_mgr->addHelp('api', 'userguide/api/posts/index');
     $this->view_mgr->addHelp('application_settings', 'userguide/settings/application');
     $this->view_mgr->addHelp('users', 'userguide/settings/allaccounts');
     $this->view_mgr->addHelp('backup', 'install/backup');
     $this->view_mgr->addHelp('account', 'userguide/settings/account');
     //process password change
     if (isset($_POST['changepass']) && $_POST['changepass'] == 'Change password' && isset($_POST['oldpass']) && isset($_POST['pass1']) && isset($_POST['pass2'])) {
         // Check their old password is correct
         if (!$owner_dao->isOwnerAuthorized($this->getLoggedInUser(), $_POST['oldpass'])) {
             $this->addErrorMessage("Password is incorrect.", 'password');
         } elseif ($_POST['pass1'] != $_POST['pass2']) {
             $this->addErrorMessage("New passwords did not match. Your password has not been changed.", 'password');
         } elseif (!preg_match("/(?=.{8,})(?=.*[a-zA-Z])(?=.*[0-9])/", $_POST['pass1'])) {
             $this->addErrorMessage("Your new password must be at least 8 characters and contain both numbers " . "and letters. Your password has not been changed.", 'password');
         } else {
             // verify CSRF token
             $this->validateCSRFToken();
             // Try to update the password
             if ($owner_dao->updatePassword($this->getLoggedInUser(), $_POST['pass1']) < 1) {
                 $this->addErrorMessage("Your password has NOT been updated.", 'password');
             } else {
                 $this->addSuccessMessage("Your password has been updated.", 'password');
             }
         }
     }
     //reset api_key
     if (isset($_POST['reset_api_key']) && $_POST['reset_api_key'] == 'Reset API Key') {
         $this->validateCSRFToken();
         $api_key = $owner_dao->resetAPIKey($owner->id);
         if (!$api_key) {
             throw new Exception("Unbale to update user's api_key, something bad must have happened");
         }
         $this->addSuccessMessage("Your API Key has been reset! Please update your ThinkUp RSS feed subscription.", 'api_key');
         $owner->api_key = $api_key;
     }
     // process invite
     if (isset($_POST['invite']) && $_POST['invite'] == 'Create Invitation') {
         // verify CSRF token
         $this->validateCSRFToken();
         $invite_code = substr(md5(uniqid(rand(), true)), 0, 10);
         $invite_added = $invite_dao->addInviteCode($invite_code);
         if ($invite_added == 1) {
             //invite generated and inserted
             $invite_link = Utils::getApplicationURL() . 'session/register.php?code=' . $invite_code;
             $this->addSuccessMessage("Invitation created!<br />Copy this link and send it to someone you want to " . 'invite to register on your ThinkUp installation.<br /><a href="' . $invite_link . '" id="clippy_12345">' . $invite_link . '</a>
               <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
                       width="100"
                       height="14"
                       class="clippy"
                       id="clippy" >
               <param name="movie" value="' . Utils::getApplicationURL() . 'assets/flash/clippy.swf"/>
               <param name="allowScriptAccess" value="always" />
               <param name="quality" value="high" />
               <param name="scale" value="noscale" />
               <param NAME="FlashVars" value="id=clippy_12345&amp;copied=copied!&amp;copyto=copy to clipboard">
               <param name="bgcolor" value="#D5F0FC">
               <param name="wmode" value="opaque">
               <embed src="' . Utils::getApplicationURL() . 'assets/flash/clippy.swf"
                      width="100"
                      height="14"
                      name="clippy"
                      quality="high"
                      allowScriptAccess="always"
                      type="application/x-shockwave-flash"
                      pluginspage="http://www.macromedia.com/go/getflashplayer"
                      FlashVars="id=clippy_12345&amp;copied=copied!&amp;copyto=copy to clipboard"
                      bgcolor="#dff0d8"
                      wmode="opaque"/></object>
             <br /> Good for one new registration. Expires in 7 days.', 'invite', true);
         } else {
             $this->addErrorMessage("There was an error creating a new invite. Please try again.", 'invite');
         }
     }
     //process service user deletion
     if (isset($_POST['action']) && $_POST['action'] == 'Delete' && isset($_POST['instance_id']) && is_numeric($_POST['instance_id']) && !isset($_POST['hashtag_id']) && !isset($_POST['new_hashtag_name'])) {
         $owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO');
         $instance_dao = DAOFactory::getDAO('InstanceDAO');
         $instancehashtag_dao = DAOFactory::getDAO('InstanceHashtagDAO');
         $hashtagpost_dao = DAOFactory::getDAO('HashtagPostDAO');
         $hashtag_dao = DAOFactory::getDAO('HashtagDAO');
         $instance = $instance_dao->get($_POST['instance_id']);
         $message = '';
         if (isset($instance)) {
             // verify CSRF token
             $this->validateCSRFToken();
             if ($this->isAdmin()) {
                 //Retrieve this instance's saved searches
                 $instances_hashtags = $instancehashtag_dao->getByInstance($instance->id);
                 $deleted_searches = 0;
                 foreach ($instances_hashtags as $instance_hashtag) {
                     $hashtag_id = $instance_hashtag->hashtag_id;
                     $deleted_searches += $instancehashtag_dao->delete($instance_hashtag->instance_id, $hashtag_id);
                     //Continue deletions if no other owner has saved this search
                     if (!$instancehashtag_dao->isHashtagSaved($hashtag_id)) {
                         $deleted_searchposts = $hashtagpost_dao->deleteHashtagsPostsByHashtagID($hashtag_id);
                         $deleted_hashtag = $hashtag_dao->deleteHashtagByID($hashtag_id);
                     }
                 }
                 //delete all owner_instances
                 $owner_instance_dao->deleteByInstance($instance->id);
                 //delete instance
                 $instance_dao->delete($instance->network_username, $instance->network);
                 $this->addSuccessMessage('Account ' . ($deleted_searches > 0 ? 'and its saved searches ' : '') . 'deleted.', 'account');
             } else {
                 if ($owner_instance_dao->doesOwnerHaveAccessToInstance($owner, $instance)) {
                     //delete owner instance
                     $total_deletions = $owner_instance_dao->delete($owner->id, $instance->id);
                     if ($total_deletions > 0) {
                         //delete instance if no other owners have it
                         $remaining_owner_instances = $owner_instance_dao->getByInstance($instance->id);
                         $deleted_searches = 0;
                         if (sizeof($remaining_owner_instances) == 0) {
                             //Retrieve this instance's saved searches
                             $instances_hashtags = $instancehashtag_dao->getByInstance($instance->id);
                             foreach ($instances_hashtags as $instance_hashtag) {
                                 $hashtag_id = $instance_hashtag->hashtag_id;
                                 $deleted_searches += $instancehashtag_dao->delete($instance_hashtag->instance_id, $hashtag_id);
                                 //Continue deletions if no other owner has saved this search
                                 if (!$instancehashtag_dao->isHashtagSaved($hashtag_id)) {
                                     $deleted_searchposts = $hashtagpost_dao->deleteHashtagsPostsByHashtagID($hashtag_id);
                                     $deleted_hashtag = $hashtag_dao->deleteHashtagByID($hashtag_id);
                                 }
                             }
                             $instance_dao->delete($instance->network_username, $instance->network);
                         }
                         $this->addSuccessMessage('Account ' . ($deleted_searches > 0 ? 'and its saved searches ' : '') . 'deleted.', 'account');
                     }
                 } else {
                     $this->addErrorMessage('Insufficient privileges.', 'account');
                 }
             }
         } else {
             $this->addErrorMessage('Instance doesn\'t exist.', 'account');
         }
     }
     //process hashtag deletion
     if (isset($_POST['action']) && $_POST['action'] == 'Delete' && isset($_POST['hashtag_id']) && is_numeric($_POST['hashtag_id']) && isset($_POST['instance_id']) && is_numeric($_POST['instance_id'])) {
         $instancehashtag_dao = DAOFactory::getDAO('InstanceHashtagDAO');
         $hashtag_dao = DAOFactory::getDAO('HashtagDAO');
         $hashtagpost_dao = DAOFactory::getDAO('HashtagPostDAO');
         $hashtag_id = $_POST['hashtag_id'];
         $instance_id = $_POST['instance_id'];
         $instance_dao = DAOFactory::getDAO('InstanceDAO');
         $instance = $instance_dao->get($instance_id);
         if (isset($instance)) {
             $instances_hashtags_deleted = $instancehashtag_dao->delete($instance_id, $hashtag_id);
             if (!$instancehashtag_dao->isHashtagSaved($hashtag_id)) {
                 $deleted_searchposts = $hashtagpost_dao->deleteHashtagsPostsByHashtagID($hashtag_id);
                 $deleted_hashtag = $hashtag_dao->deleteHashtagByID($hashtag_id);
             }
             $message = "Deleted saved search.";
             $this->addSuccessMessage($message, 'account');
         } else {
             $this->addErrorMessage('Instance doesn\'t exist.', 'account');
         }
     }
     //process service user hashtag addition
     if (isset($_POST['action']) && $_POST['action'] == 'Save search' && isset($_POST['new_hashtag_name']) && $_POST['new_hashtag_name'] != '' && isset($_POST['instance_id']) && is_numeric($_POST['instance_id'])) {
         $instancehashtag_dao = DAOFactory::getDAO('InstanceHashtagDAO');
         $hashtag_dao = DAOFactory::getDAO('HashtagDAO');
         $instance_id = $_POST['instance_id'];
         $new_hashtag_name = $_POST['new_hashtag_name'];
         //Check if $new_hashtag_name is an individual word (no spaces)
         if (strpos($new_hashtag_name, " ") === false) {
             $instance_dao = DAOFactory::getDAO('InstanceDAO');
             $instance = $instance_dao->get($instance_id);
             if (isset($instance)) {
                 $hashtag = $hashtag_dao->getHashtag($new_hashtag_name, $instance->network);
                 if (!isset($hashtag)) {
                     $hashtag_id = $hashtag_dao->insertHashtag($new_hashtag_name, $instance->network);
                     $row_inserted = $instancehashtag_dao->insert($instance_id, $hashtag_id);
                     $message = "Saved search for " . $new_hashtag_name . ".";
                     $this->addSuccessMessage($message, 'account');
                 } else {
                     $row_inserted = $instancehashtag_dao->insert($instance_id, $hashtag->id);
                     $message = "Saved search for " . $new_hashtag_name . ".";
                     $this->addSuccessMessage($message, 'account');
                 }
             } else {
                 $this->addErrorMessage('Instance doesn\'t exist.', 'account');
             }
         } else {
             $this->addErrorMessage('You can only search for an individual keyword or hashtag, not a phrase. ' . 'Please try again.', 'account');
         }
     }
     //process change to notification frequency
     if (isset($_POST['updatefrequency'])) {
         $this->validateCSRFToken();
         $new_freq = isset($_POST['notificationfrequency']) ? $_POST['notificationfrequency'] : null;
         $updates = 0;
         if ($new_freq && isset($this->notification_frequencies[$new_freq])) {
             $updates = $owner_dao->setEmailNotificationFrequency($this->getLoggedInUser(), $new_freq);
         }
         if ($updates > 0) {
             // Update the user in the view to match
             $owner->email_notification_frequency = $new_freq;
             $this->addToView('owner', $owner);
             $this->addSuccessMessage('Your email notification frequency has been updated.', 'notifications');
         }
     }
     //process change to timezone
     if (isset($_POST['updatetimezone'])) {
         $this->validateCSRFToken();
         $new_tz = isset($_POST['timezone']) ? $_POST['timezone'] : null;
         $updates = 0;
         if (isset($new_tz)) {
             $possible_timezones = timezone_identifiers_list();
             if (in_array($new_tz, $possible_timezones)) {
                 $updates = $owner_dao->setTimezone($this->getLoggedInUser(), $new_tz);
             }
         }
         if ($updates > 0) {
             // Update the user in the view to match
             $owner->timezone = $new_tz;
             $this->addToView('owner', $owner);
             $this->addSuccessMessage('Your time zone has been saved.', 'timezone');
         }
     }
     $this->view_mgr->clear_all_cache();
     /* Begin plugin-specific configuration handling */
     if (isset($_GET['p']) && !isset($_GET['u'])) {
         // add config js to header
         if ($this->isAdmin()) {
             $this->addHeaderJavaScript('assets/js/plugin_options.js');
         }
         $active_plugin = $_GET['p'];
         $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
         $pobj = $webapp_plugin_registrar->getPluginObject($active_plugin);
         $p = new $pobj();
         $this->addToView('body', $p->renderConfiguration($owner));
         $this->addToView('force_plugin', true);
         $profiler = Profiler::getInstance();
         $profiler->clearLog();
     } elseif (isset($_GET['p']) && isset($_GET['u']) && isset($_GET['n'])) {
         if ($this->isAdmin()) {
             $this->addHeaderJavaScript('assets/js/plugin_options.js');
         }
         $active_plugin = $_GET['p'];
         $instance_username = $_GET['u'];
         $instance_network = $_GET['n'];
         $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
         $pobj = $webapp_plugin_registrar->getPluginObject($active_plugin);
         $p = new $pobj();
         $this->addToView('body', $p->renderInstanceConfiguration($owner, $instance_username, $instance_network));
         $this->addToView('force_plugin', true);
         $profiler = Profiler::getInstance();
         $profiler->clearLog();
     }
     $plugin_dao = DAOFactory::getDAO('PluginDAO');
     $config = Config::getInstance();
     $installed_plugins = $plugin_dao->getInstalledPlugins();
     $this->addToView('installed_plugins', $installed_plugins);
     /* End plugin-specific configuration handling */
     if ($owner->is_admin) {
         if (!isset($instance_dao)) {
             $instance_dao = DAOFactory::getDAO('InstanceDAO');
         }
         $owners = $owner_dao->getAllOwners();
         foreach ($owners as $o) {
             $instances = $instance_dao->getByOwner($o, true);
             $o->setInstances($instances);
         }
         $this->addToView('owners', $owners);
         $this->addToView('public_instances', $instance_dao->getPublicInstances());
     }
     $whichphp = @exec('which php');
     $php_path = !empty($whichphp) ? $whichphp : 'php';
     $email = $this->getLoggedInUser();
     //rss_crawl_url
     $rss_crawl_url = Utils::getApplicationURL() . sprintf('crawler/rss.php?un=%s&as=%s', urlencode($email), $owner->api_key);
     $this->addToView('rss_crawl_url', $rss_crawl_url);
     //cli_crawl_command
     $cli_crawl_command = 'cd ' . THINKUP_WEBAPP_PATH . 'crawler/;export THINKUP_PASSWORD=yourpassword; ' . $php_path . ' crawl.php ' . $email;
     $this->addToView('cli_crawl_command', $cli_crawl_command);
     //help link
     $this->view_mgr->addHelp('rss', 'userguide/datacapture');
     return $this->generateView();
 }
Example #27
0
*/
/**
 *
 * ThinkUp/webapp/plugins/facebook/controller/facebook.php
 *
 * Copyright (c) 2009-2015 Gina Trapani
 *
 * LICENSE:
 *
 * This file is part of ThinkUp (http://thinkup.com).
 *
 * ThinkUp is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any
 * later version.
 *
 * ThinkUp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with ThinkUp.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 * @author Gina Trapani <ginatrapani[at]gmail[dot]com>
 * @license http://www.gnu.org/licenses/gpl.html
 * @copyright 2009-2015 Gina Trapani
 */
$webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
$webapp_plugin_registrar->registerPlugin('facebook', 'FacebookPlugin');
$webapp_plugin_registrar->registerPlugin('facebook page', 'FacebookPlugin');
$crawler_plugin_registrar = PluginRegistrarCrawler::getInstance();
$crawler_plugin_registrar->registerCrawlerPlugin('FacebookPlugin');
Example #28
0
 public function setUp()
 {
     parent::setUp();
     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     $webapp_plugin_registrar->registerPlugin('embedthread', 'EmbedThreadPlugin');
 }
Example #29
0
 /**
  * Load the view with required variables
  */
 private function loadView($post)
 {
     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     if ($this->view_name != 'default') {
         $menu_item = $webapp_plugin_registrar->getPostDetailMenuItem($this->view_name, $post);
         if ($menu_item != null) {
             $this->addToView('data_template', $menu_item->view_template);
             $this->addToView('display', $this->view_name);
             $this->addToView('header', $menu_item->name);
             $this->addToView('description', $menu_item->description);
             $page = isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1;
             foreach ($menu_item->datasets as $dataset) {
                 if (array_search('#page_number#', $dataset->method_params) !== false) {
                     //there's paging
                     $this->addToView('next_page', $page + 1);
                     $this->addToView('last_page', $page - 1);
                 }
                 $this->addToView($dataset->name, $dataset->retrieveDataset($page));
                 if (Session::isLoggedIn() && $dataset->isSearchable()) {
                     $view_name = 'is_searchable';
                     $this->addToView($view_name, true);
                 }
             }
         }
     }
 }
 public function authControl()
 {
     $this->disableCaching();
     //passsswd reset validation
     $this->addHeaderCSS('assets/css/validate_password.css');
     $this->addHeaderJavaScript('assets/js/jquery.validate.min.js');
     $this->addHeaderJavaScript('assets/js/jquery.validate.password.js');
     $this->addHeaderJavaScript('assets/js/validate_password.js');
     $webapp_plugin_registrar = PluginRegistrarWebapp::getInstance();
     $owner_dao = DAOFactory::getDAO('OwnerDAO');
     $invite_dao = DAOFactory::getDAO('InviteDAO');
     $owner = $owner_dao->getByEmail($this->getLoggedInUser());
     $this->addToView('owner', $owner);
     $this->addToView('logo_link', '');
     $this->view_mgr->addHelp('api', 'userguide/api/posts/index');
     $this->view_mgr->addHelp('application_settings', 'userguide/settings/application');
     $this->view_mgr->addHelp('users', 'userguide/settings/allaccounts');
     $this->view_mgr->addHelp('backup', 'install/backup');
     $this->view_mgr->addHelp('account', 'userguide/settings/account');
     //process password change
     if (isset($_POST['changepass']) && $_POST['changepass'] == 'Change password' && isset($_POST['oldpass']) && isset($_POST['pass1']) && isset($_POST['pass2'])) {
         // Check their old password is correct
         if (!$owner_dao->isOwnerAuthorized($this->getLoggedInUser(), $_POST['oldpass'])) {
             $this->addErrorMessage("Old password does not match or empty.", 'password');
         } elseif ($_POST['pass1'] != $_POST['pass2']) {
             $this->addErrorMessage("New passwords did not match. Your password has not been changed.", 'password');
         } elseif (!preg_match("/(?=.{8,})(?=.*[a-zA-Z])(?=.*[0-9])/", $_POST['pass1'])) {
             $this->addErrorMessage("Your new password must be at least 8 characters and contain both numbers " . "and letters. Your password has not been changed.", 'password');
         } else {
             // verify CSRF token
             $this->validateCSRFToken();
             // Try to update the password
             if ($owner_dao->updatePassword($this->getLoggedInUser(), $_POST['pass1']) < 1) {
                 $this->addErrorMessage("Your password has NOT been updated.", 'password');
             } else {
                 $this->addSuccessMessage("Your password has been updated.", 'password');
             }
         }
     }
     //reset api_key
     if (isset($_POST['reset_api_key']) && $_POST['reset_api_key'] == 'Reset API Key') {
         $this->validateCSRFToken();
         $api_key = $owner_dao->resetAPIKey($owner->id);
         if (!$api_key) {
             throw new Exception("Unbale to update user's api_key, something bad must have happened");
         }
         $this->addSuccessMessage("Your API Key has been reset! Please update your ThinkUp RSS feed subscription.", 'api_key');
         $owner->api_key = $api_key;
     }
     // process invite
     if (isset($_POST['invite']) && $_POST['invite'] == 'Create Invitation') {
         // verify CSRF token
         $this->validateCSRFToken();
         $invite_code = substr(md5(uniqid(rand(), true)), 0, 10);
         $invite_added = $invite_dao->addInviteCode($invite_code);
         if ($invite_added == 1) {
             //invite generated and inserted
             $server = $_SERVER['HTTP_HOST'];
             $invite_link = Utils::getApplicationURL() . 'session/register.php?code=' . $invite_code;
             $this->addSuccessMessage("Invitation created!<br />Copy this link and send it to someone you want to " . 'invite to register on your ThinkUp installation.<br /><a href="' . $invite_link . '" id="clippy_12345">' . $invite_link . '</a>
               <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
                       width="100"
                       height="14"
                       class="clippy"
                       id="clippy" >
               <param name="movie" value="' . Utils::getApplicationURL() . 'assets/flash/clippy.swf"/>
               <param name="allowScriptAccess" value="always" />
               <param name="quality" value="high" />
               <param name="scale" value="noscale" />
               <param NAME="FlashVars" value="id=clippy_12345&amp;copied=copied!&amp;copyto=copy to clipboard">
               <param name="bgcolor" value="#D5F0FC">
               <param name="wmode" value="opaque">
               <embed src="' . Utils::getApplicationURL() . 'assets/flash/clippy.swf"
                      width="100"
                      height="14"
                      name="clippy"
                      quality="high"
                      allowScriptAccess="always"
                      type="application/x-shockwave-flash"
                      pluginspage="http://www.macromedia.com/go/getflashplayer"
                      FlashVars="id=clippy_12345&amp;copied=copied!&amp;copyto=copy to clipboard"
                      bgcolor="#D5F0FC"
                      wmode="opaque"/></object>
             <br /> Good for one new registration. Expires in 7 days.', 'invite', true);
         } else {
             $this->addErrorMessage("There was an error creating a new invite. Please try again.", 'invite');
         }
     }
     //process service user deletion
     if (isset($_POST['action']) && $_POST['action'] == 'delete' && isset($_POST['instance_id']) && is_numeric($_POST['instance_id'])) {
         $owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO');
         $instance_dao = DAOFactory::getDAO('InstanceDAO');
         $instance = $instance_dao->get($_POST['instance_id']);
         if (isset($instance)) {
             // verify CSRF token
             $this->validateCSRFToken();
             if ($this->isAdmin()) {
                 //delete all owner_instances
                 $owner_instance_dao->deleteByInstance($instance->id);
                 //delete instance
                 $instance_dao->delete($instance->network_username, $instance->network);
                 $this->addSuccessMessage('Account deleted.', 'account');
             } else {
                 if ($owner_instance_dao->doesOwnerHaveAccessToInstance($owner, $instance)) {
                     //delete owner instance
                     $total_deletions = $owner_instance_dao->delete($owner->id, $instance->id);
                     if ($total_deletions > 0) {
                         //delete instance if no other owners have it
                         $remaining_owner_instances = $owner_instance_dao->getByInstance($instance->id);
                         if (sizeof($remaining_owner_instances) == 0) {
                             $instance_dao->delete($instance->network_username, $instance->network);
                         }
                         $this->addSuccessMessage('Account deleted.', 'account');
                     }
                 } else {
                     $this->addErrorMessage('Insufficient privileges.', 'account');
                 }
             }
         } else {
             $this->addErrorMessage('Instance doesn\'t exist.', 'account');
         }
     }
     $this->view_mgr->clear_all_cache();
     /* Begin plugin-specific configuration handling */
     if (isset($_GET['p'])) {
         // add config js to header
         if ($this->isAdmin()) {
             $this->addHeaderJavaScript('assets/js/plugin_options.js');
         }
         $active_plugin = $_GET['p'];
         $pobj = $webapp_plugin_registrar->getPluginObject($active_plugin);
         $p = new $pobj();
         $this->addToView('body', $p->renderConfiguration($owner));
         $profiler = Profiler::getInstance();
         $profiler->clearLog();
     } else {
         $plugin_dao = DAOFactory::getDAO('PluginDAO');
         $config = Config::getInstance();
         $installed_plugins = $plugin_dao->getInstalledPlugins();
         $this->addToView('installed_plugins', $installed_plugins);
     }
     /* End plugin-specific configuration handling */
     if ($owner->is_admin) {
         if (!isset($instance_dao)) {
             $instance_dao = DAOFactory::getDAO('InstanceDAO');
         }
         $owners = $owner_dao->getAllOwners();
         foreach ($owners as $o) {
             $instances = $instance_dao->getByOwner($o, true);
             $o->setInstances($instances);
         }
         $this->addToView('owners', $owners);
         $this->addToView('public_instances', $instance_dao->getPublicInstances());
     }
     $whichphp = @exec('which php');
     $php_path = !empty($whichphp) ? $whichphp : 'php';
     $email = $this->getLoggedInUser();
     //rss_crawl_url
     $rss_crawl_url = Utils::getApplicationURL() . sprintf('crawler/rss.php?un=%s&as=%s', urlencode($email), $owner->api_key);
     $this->addToView('rss_crawl_url', $rss_crawl_url);
     //cli_crawl_command
     $cli_crawl_command = 'cd ' . THINKUP_WEBAPP_PATH . 'crawler/;export THINKUP_PASSWORD=yourpassword; ' . $php_path . ' crawl.php ' . $email;
     $this->addToView('cli_crawl_command', $cli_crawl_command);
     //help link
     $this->view_mgr->addHelp('rss', 'userguide/datacapture');
     return $this->generateView();
 }