示例#1
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"}';
     }
 }
示例#2
0
 public function testOwnerWithAccessTweetsAllMaxNoLimit()
 {
     $builders = $this->buildData();
     GridController::$MAX_ROWS = 0;
     $this->simulateLogin('*****@*****.**');
     $_GET['u'] = 'someuser1';
     $_GET['n'] = 'twitter';
     $_GET['d'] = 'tweets-all';
     $_GET['nolimit'] = '1';
     $controller = new GridController(true);
     $this->assertTrue(isset($controller));
     ob_start();
     $controller->go();
     $results = ob_get_contents();
     ob_end_clean();
     $json = substr($results, 29, strrpos($results, ';') - 30);
     $ob = json_decode($json);
     $this->assertEqual($ob->status, 'success');
     $this->assertEqual(count($ob->posts), 3);
 }