Ejemplo n.º 1
0
 function getSite($siteId)
 {
     if (!isset($this->_sites[$siteId])) {
         $this->_sites[$siteId] = SweteSite::loadSiteById($siteId);
     }
     return $this->_sites[$siteId];
 }
 function handle(&$params)
 {
     try {
         $app = Dataface_Application::getInstance();
         $query = $app->getQuery();
         $selectedRecords = df_get_selected_records($query);
         $isNewJob = false;
         if ($query['-job'] && is_numeric($query['-job'])) {
             $selectedJob = df_get_record('jobs', array('job_id' => '=' . $query['-job']));
         } else {
             //no job was selected by user
             $site_id = $selectedRecords[0]->val('website_id');
             $jobs = df_get_records_array('jobs', array('website_id' => $site_id, 'compiled' => 'false'));
             $createNewJob = false;
             if ($query['-job'] == "new") {
                 $createNewJob = true;
             }
             if (count($jobs) == 0 || $createNewJob) {
                 //create a new job
                 $selectedJob = SweteJob::createJob(SweteSite::loadSiteById($site_id))->getRecord();
                 $isNewJob = true;
             } else {
                 if (count($jobs) == 1) {
                     //only one available job
                     $selectedJob = $jobs[0];
                 } else {
                     throw new Exception("No Job id was specified, but there are " . $count($jobs) . " available jobs to add to");
                 }
             }
         }
         if (!$selectedJob) {
             throw new Exception("Job could not be found", E_USER_ERROR);
         }
         if (!$selectedJob->checkPermission('edit')) {
             throw new Exception("You don't have permission to edit this job");
         }
         $job = new SweteJob($selectedJob);
         $stringsAdded = array();
         foreach ($selectedRecords as $record) {
             if (intval($record->val('website_id')) !== intval($selectedJob->val("website_id"))) {
                 throw new Exception("The string " . $record->val('string') . " is not in the same site as the job.");
             }
             //If string was already added to ANOTHER job, it doesn't matter
             //It will also be added to this one
             //if string was already added to this job, do nothing
             if (!$job->containsString($record->val('string'))) {
                 $job->addTranslationMiss($record->val('translation_miss_log_id'));
                 array_push($stringsAdded, $record->val('string'));
             }
         }
         $results = array('stringsAdded' => $stringsAdded, 'jobId' => $selectedJob->val('job_id'), 'isNewJob' => $isNewJob);
         echo json_encode($results);
     } catch (Exception $e) {
         if ($e->getCode() == E_USER_ERROR) {
             echo $e->getMessage();
         } else {
             throw $e;
         }
     }
 }
Ejemplo n.º 3
0
 private function getSite($id)
 {
     if (!isset($this->sites[$id])) {
         $this->sites[$id] = SweteSite::loadSiteById($id);
     }
     return $this->sites[$id];
 }
Ejemplo n.º 4
0
 public function run()
 {
     $page = SweteWebpage::loadById($this->rootPageId, $this->lang);
     if (!$page) {
         throw new Exception("Failed to load page :" . $this->rootPageId . " language " . $this->lang);
     }
     $page->getInheritableProperty($this->property, true, $this->inheritVal);
     $site = $page->getSite();
     SweteSite::calculateEffectivePropertyToTree($this->property, $page, $page->getInheritableProperty($this->property, false, $this->inheritVal));
 }
Ejemplo n.º 5
0
 function testCrawlSite()
 {
     $s = new Dataface_Record('websites', array());
     $s->setValues(array('website_url' => 'http://solutions.weblite.ca/', 'source_language' => 'en', 'target_language' => 'fr', 'website_name' => 'Site 1 french', 'active' => 1, 'base_path' => '/fr/', 'host' => 'localhost'));
     $s->save();
     $site = SweteSite::loadSiteById($s->val('website_id'));
     $crawler = new SiteCrawler();
     $crawler->site = $site;
     $crawler->startingPoint = 'http://solutions.weblite.ca/';
     $crawler->depth = 3;
     $crawler->crawl();
     //print_r($crawler->root);
 }
Ejemplo n.º 6
0
 function testPage()
 {
     $url = DATAFACE_SITE_URL . '/tests/testsites/site1/index.html';
     $site = new Dataface_Record('websites', array());
     $site->setValues(array('website_url' => df_absolute_url(DATAFACE_SITE_URL . '/tests/testsites/site1/'), 'source_language' => 'en', 'target_language' => 'fr', 'website_name' => 'Site 1 French', 'active' => 1, 'base_path' => DATAFACE_SITE_URL . '/proxies/site1/', 'host' => $_SERVER['HTTP_HOST']));
     $site->save();
     df_q("delete from site_text_filters where website_id='" . addslashes($site->val('website_id')) . "'");
     $server = new ProxyServer();
     $server->site = SweteSite::loadSiteById($site->val('website_id'));
     $server->SERVER = array('REQUEST_METHOD' => 'get');
     $server->URL = df_absolute_url(DATAFACE_SITE_URL . '/proxies/site1/index.html');
     $server->buffer = true;
     $server->handleRequest();
     $doc = new DOMDocument();
     $doc->loadHtml(file_get_contents('tests/testsites/site1_output/index.out.html'));
     $expected = $doc->saveHtml();
     //echo $server->contentBuffer;
     $doc2 = new DOMDocument();
     $doc2->loadHtml($server->contentBuffer);
     $actual = $doc2->saveHtml();
     //$this->assertEquals(trim($expected), trim($actual));
     // Cancelled this test because WTF!!!!  Even if I print the actual output, copy it to the file
     // and compare it to itself, it still fails!!!! WTF!!!!
 }
Ejemplo n.º 7
0
 function afterInsert($record)
 {
     $site = SweteSite::loadSiteById($record->val('website_id'));
     SweteJob::decorateNewJob($site, $record);
 }
Ejemplo n.º 8
0
 /**
  * @brief Returns the site of which this page is a member.
  * @returns SweteSite The site.
  */
 public function getSite()
 {
     if (!isset($this->_site)) {
         $this->_site = SweteSite::loadSiteById($this->_rec->val('website_id'));
         if (!$this->_site) {
             $this->_site = new SweteSite(new Dataface_Record('websites', array()));
         }
     }
     return $this->_site;
 }
Ejemplo n.º 9
0
 function handlePost($params)
 {
     session_write_close();
     header('Connection: close');
     $app = Dataface_Application::getInstance();
     try {
         require_once 'inc/PageImporter.php';
         require_once 'inc/SweteSite.class.php';
         if (!@$_POST['website_id']) {
             throw new Exception("No Site Specified");
         }
         $site = SweteSite::loadSiteById($_POST['website_id']);
         if (!$site) {
             throw new Exception("No site found by that ID.");
         }
         $importer = new PageImporter();
         $importer->site = $site;
         $importer->translate = true;
         $importer->logTranslationMisses = true;
         if (@$_POST['--depth'] and intval($_POST['--depth'])) {
             $importer->depth = intval($_POST['--depth']);
         }
         if (@$_POST['--startingPoint']) {
             $importer->startingPoint = trim($_POST['--startingPoint']);
         }
         $importer->loadContent = true;
         $importer->doImport();
         $addedIds = array();
         $updatedIds = array();
         foreach ($importer->pagesAdded as $p) {
             $addedIds[] = $p->val('webpage_id');
         }
         foreach ($importer->pagesUpdated as $p) {
             $updatedIds[] = $p->val("webpage_id");
         }
         $out = array('code' => 200, 'message' => 'Successfully imported ' . count($importer->pagesAdded) . ' pages updated ' . count($importer->pagesUpdated) . ' pages.', 'pagesUpdated' => count($importer->pagesUpdated), 'pagesAdded' => count($importer->pagesAdded), 'addedIds' => $addedIds, 'updatedIds' => $updatedIds);
     } catch (Exception $ex) {
         $out = array('code' => $ex->getCode(), 'message' => $ex->getMessage());
     }
     header('Content-type: text/json; charset="' . $app->_conf['oe'] . '"');
     echo json_encode($out);
     return;
 }
Ejemplo n.º 10
0
 function handle(&$params)
 {
     try {
         // First get the selected records
         $app =& Dataface_Application::getInstance();
         $query =& $app->getQuery();
         $isNewJob = false;
         if (!@$query['-record-id']) {
             throw new Exception("No record id was specified");
         }
         $record = df_get_record_by_id($query['-record-id']);
         //get the selected job
         if ($query['-job'] && is_numeric($query['-job'])) {
             $selectedJob = df_get_record('jobs', array('job_id' => '=' . $query['-job']));
         } else {
             //no job was selected by user
             $site_id = $record->val('website_id');
             $jobs = df_get_records_array('jobs', array('website_id' => $site_id, 'compiled' => 'false'));
             $createNewJob = false;
             if ($query['-job'] == "new") {
                 $createNewJob = true;
             }
             if (count($jobs) == 0 || $createNewJob) {
                 //create a new job
                 $selectedJob = SweteJob::createJob(SweteSite::loadSiteById($site_id))->getRecord();
                 $isNewJob = true;
             } else {
                 if (count($jobs) == 1) {
                     //only one available job
                     $selectedJob = $jobs[0];
                 } else {
                     throw new Exception("No Job id was specified, but there are " . $count($jobs) . " available jobs to add to");
                 }
             }
         }
         if (!$selectedJob) {
             throw new Exception("Job could not be found", E_USER_ERROR);
         }
         if (!$selectedJob->checkPermission('edit')) {
             throw new Exception("You don't have permission to edit this job");
         }
         $job = new SweteJob($selectedJob);
         if (intval($record->val('website_id')) !== intval($selectedJob->val("website_id"))) {
             throw new Exception("The webpage " . $record->val('webpage_id') . " is not in the same site as the job.");
         }
         $webpage = new SweteWebpage($record);
         //if webpage was already added to this job, do nothing
         if (!$job->containsWebpage($webpage)) {
             $job->addWebpage($webpage, null, true);
             $results = array('pageAdded' => $record->val('webpage_id'), 'jobId' => $selectedJob->val('job_id'), 'isNewJob' => $isNewJob);
         } else {
             $results = array('pageAdded' => "false", 'jobId' => $selectedJob->val('job_id'), 'isNewJob' => $isNewJob);
         }
         echo json_encode($results);
     } catch (Exception $e) {
         if ($e->getCode() == E_USER_ERROR) {
             echo $e->getMessage();
         } else {
             throw $e;
         }
     }
 }
Ejemplo n.º 11
0
 public function getSite()
 {
     if (!isset($this->site)) {
         $this->site = SweteSite::loadSiteById($this->_rec->val('website_id'));
     }
     return $this->site;
 }
Ejemplo n.º 12
0
 function handle($params)
 {
     global $ORIG_POST, $ORIG_REQUEST, $ORIG_GET;
     $_GET = $ORIG_GET;
     $_POST = $ORIG_POST;
     $_REQUEST = $ORIG_REQUEST;
     @session_write_close();
     $app = Dataface_Application::getInstance();
     $query = $app->getQuery();
     //print_r($_SERVER);
     $url = implode('/', array_map('rawurlencode', explode('/', $_SERVER['REDIRECT_URL'])));
     $url = str_replace("%3A", ":", $url);
     if (isset($_SERVER['REQUEST_URI'])) {
         if (strpos($_SERVER['REQUEST_URI'], '?') !== false) {
             list($junk, $_SERVER['REDIRECT_QUERY_STRING']) = explode('?', $_SERVER['REQUEST_URI']);
         } else {
             $_SERVER['REDIRECT_QUERY_STRING'] = '';
         }
     }
     $sweteDirectives = array();
     if (@$_SERVER['REDIRECT_QUERY_STRING']) {
         $qstr = $_SERVER['REDIRECT_QUERY_STRING'];
         $parts = explode('&', $qstr);
         $qstrout = array();
         foreach ($parts as $pt) {
             if (preg_match('/^swete\\:/', $pt)) {
                 list($d1, $d2) = explode('=', $pt);
                 $sweteDirectives[urldecode($d1)] = urldecode($d2);
             } else {
                 $qstrout[] = $pt;
             }
         }
         $url .= '?' . implode('&', $qstrout);
     }
     $url = df_absolute_url($url);
     //echo "The URL: ".$url;
     //echo "$url";exit;
     $site = SweteSite::loadSiteByUrl($url);
     if (!$site and $url and $url[strlen($url) - 1] != '/') {
         $url .= '/';
         $site = SweteSite::loadSiteByUrl($url);
         if ($site) {
             header('Location: ' . $url);
             exit;
         }
     }
     if (!$site) {
         die("[ERROR] No site found");
     }
     $server = new ProxyServer();
     if (defined('SWETE_USE_HTML5_PARSER') and SWETE_USE_HTML5_PARSER) {
         $server->useHtml5Parser = true;
     }
     if (@$_POST['swete:input']) {
         if (@$_POST['swete:key'] and @$_POST['swete:salt']) {
             if (is_numeric($_POST['swete:salt'])) {
                 $salt = intval($_POST['swete:salt']);
                 if (abs($salt - time()) < 3600) {
                     $password = $site->getRecord()->val('webservice_secret_key');
                     if ($password) {
                         $key = sha1($_POST['swete:salt'] . $password);
                         //if ( $key === $_POST['swete:key'] ){
                         if (strcasecmp($key, $_POST['swete:key']) === 0) {
                             $server->inputContent = $_POST['swete:input'];
                             if (@$_POST['swete:content-type']) {
                                 $server->inputContentType = $_POST['swete:content-type'];
                             }
                         } else {
                             die("[ERROR] Incorrect Key");
                         }
                     } else {
                         die("[ERROR] No secret key set in the website settings.");
                     }
                 } else {
                     die("[ERROR] Invalid salt value");
                 }
             } else {
                 die("[ERROR] Invalid salt value.  Salt must be an integer");
             }
         } else {
             die("[ERROR] Both swete:key and swete:salt must be provided");
         }
     }
     //$server->buffer = true;
     $server->logTranslationMisses = true;
     $server->site = $site;
     if ($site->getRecord()->val('log_requests')) {
         if (isset($server->logger)) {
             $server->logger->requestLoggingEnabled = true;
         }
     } else {
         if (isset($server->logger)) {
             $server->logger->requestLoggingEnabled = false;
         }
     }
     if ($site->getRecord()->val('log_translation_misses')) {
         $server->logTranslationMisses = true;
         if (isset($server->logger)) {
             // If we are logging translation misses we also need to log requests
             $server->logger->requestLoggingEnabled = true;
         }
     } else {
         $server->logTranslationMisses = false;
     }
     $server->URL = $url;
     // Deal with live cache
     // The first time a page is requested, it won't yet have a livecache
     // descriptor, so we needed to wait until we had loaded the
     // site so we can calculate the unproxified url.
     // Then we will try to flush it again.
     $isPost = strtolower($server->SERVER['REQUEST_METHOD']) === 'post';
     if (class_exists('LiveCache')) {
         $server->liveCache = LiveCache::getCurrentPage();
         if (!$isPost and !isset($server->liveCache->unproxifiedUrl)) {
             $server->liveCache->unproxifiedUrl = $server->site->getProxyWriter()->unproxifyUrl($server->URL);
             $server->liveCache->logger = $server->logger;
             $server->liveCache->flush();
         }
     }
     //
     $server->handleRequest();
     //print_r($server->headerBuffer);
     //$site = SweteSite::loadSiteByUrl(
 }