private function getSite($id) { if (!isset($this->sites[$id])) { $this->sites[$id] = SweteSite::loadSiteById($id); } return $this->sites[$id]; }
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; } } }
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); }
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!!!! }
function afterInsert($record) { $site = SweteSite::loadSiteById($record->val('website_id')); SweteJob::decorateNewJob($site, $record); }
/** * @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; }
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; }
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; } } }
public function getSite() { if (!isset($this->site)) { $this->site = SweteSite::loadSiteById($this->_rec->val('website_id')); } return $this->site; }