function translate() { $translate = array(); if (!$this->saved_content['Text']) { $translate[] = 'Text'; } $trFrom = $trSect = $trText = array(); if (!empty($translate)) { $newest = $DB->asArray("SELECT t1.section, t1.* FROM content AS t1\n LEFT JOIN content t2 ON t1.section = t2.section\n AND t1.language = t2.language\n AND t1.revision < t2.revision\n WHERE t2.section IS NULL\n AND t1.id='" . Database::escape($id) . "'\n AND (t1.section='" . implode("' OR t1.section='", Database::escape($translate, true)) . "')\n ORDER BY t1.revision DESC", true); foreach ($newest as $s => $translation) { $trFrom[] = $translation['language']; $trText[] = $translation['content']; $trSect[] = $s; } } if (!$obj->Name && !$_POST['etitle']) { if ($info = $DB->metadata->getRow(array('id' => $obj->ID, 'field' => 'Name'), 'value, metameta')) { $trFrom[] = $info['metameta']; $trText[] = $info['value']; $trSect[] = 'Name'; } } $translation = array(); if (!empty($trText)) { $translation = @array_combine($trSect, google::translate($trText, $trFrom, $language)); } return $translation; }
function viewRevisions($page, $l, $sectionMap = false) { global $DB, $Controller; if (is_numeric($page)) { $page = $Controller->{(string) $page}(EDIT); } $lang = google::languages($l); $revisions = array(); $_REQUEST->setType('rev1', 'numeric', true); $_REQUEST->setType('rev2', 'numeric', true); //FIXME: Move to CSS Head::add('ins {background: lightgreen;} del {background: pink;} .revlegend {text-align: right;display:inline;margin: 0 0 0 45px;} .revlegend ins,.revlegend del {margin: 0 5px;}', 'css-raw'); $r1 = false; $r2 = false; $r = $DB->content->get(array('id' => $this->that->ID, 'language' => $l), false, false, 'revision DESC'); while ($rev = Database::fetchAssoc($r)) { $revisions[$rev['section']][$rev['revision']] = strftime('%c', $rev['revision']); if ($_REQUEST['rev1'][$rev['section']] === $rev['revision']) { $r1[$rev['section']] = $rev; } if ($_REQUEST['rev2'][$rev['section']] === $rev['revision']) { $r2[$rev['section']] = $rev; } } $revArray = array(); if ($revisions) { foreach ($revisions as $sectionName => $sectContent) { $revArray[] = new Tab($sectionMap && isset($sectionMap[$sectionName]) ? $sectionMap[$sectionName] : $sectionName, new Li(new Select('View revision', 'rev1[' . $sectionName . ']', $sectContent, $_REQUEST['rev1'][$sectionName], false, __('None')), new Submit('Revert to this', 'revert1[' . $sectionName . ']')), new Li(new Select('Compare to', 'rev2[' . $sectionName . ']', $sectContent, $_REQUEST['rev2'][$sectionName], false, __('None')), new Submit('Revert to this', 'revert2[' . $sectionName . ']')), isset($r1[$sectionName]) ? '<div class="revlegend"><ins>' . strftime('%c', $r1[$sectionName]['revision']) . '</ins>' . (isset($r2[$sectionName]) ? '<del>' . strftime('%c', $r2[$sectionName]['revision']) . '</del></div>' . '<div id="revdiff">' . diff($r2[$sectionName]['content'], $r1[$sectionName]['content']) . '</div>' : '<div id="revdiff">' . strip_tags($r1[$sectionName]['content'], '<p><div>') . '</div>') : null); } $rForm = new Form('revisionsForm', url(null, array('id', 'edit', 'view', 'lang'), false)); return '<div class="nav">' . Short::backn() . '</div>' . $rForm->collection(new Hidden('lang', $l), new Tabber('r' . $l, $revArray)); } else { return '<div class="nav">' . Short::backn() . '</div>' . __('There are no saved revisions for this page and language'); } }
function selectLanguage() { global $CONFIG; JS::loadjQuery(false); JS::raw("\$(function(){\$('#" . idfy('user_settings::language') . "').change(function(e){\$(e.target).closest('form').submit();})});"); echo Form::quick(url(null, true), false, new Select(false, 'user_settings::language', google::languages($CONFIG->Site->languages), @$_COOKIE['user_settings::language'], false, __('Choose language'))); }
/** * @return string */ private function mainView() { global $USER, $CONFIG, $DB, $Controller; $form = new Form('newEvent'); $calendarSettings = new Accordion(__('Calendar settings'), new Set(new Checkbox(__('Insert into calendar'), 'einscal'), Short::datetime(__('Starts'), 'cstart'), Short::datetime(__('Ends'), 'cend'))); $calendarSettings->params = 'collapsible:true,active:false'; return new Tabber('flows', __('New item'), $form->collection($calendarSettings, new Hidden('esave', 1), new Hidden('edit', $_REQUEST['edit'] ? $_REQUEST['edit'] : 'new'), new Set(new Select(__('Language'), 'lang', google::languages($CONFIG->Site->languages), $_POST['lang'] ? $_POST['lang'] : $USER->settings['language']), new Input(__('Title'), 'etitle', $_POST['etitle']), new ImagePicker(__('Image'), 'eimg'), new Li(Short::datetime(__('Publish'), 'estart', $_POST['estart']), $this->mayI(PUBLISH) ? new Minicheck(__('Activate post'), 'activated', true) : null), Short::datetime(__('Hide'), 'eend', $_POST['eend']), new TagInput(__('Flow'), 'flows', Flow::flows(), $_POST['flows'] ? $_POST['flows'] : '', true, false, 'required'), new htmlfield(_('Text'), 'etxt', $_POST['etxt']))), __('Flows'), $this->flowList()); }
/** * View the page for editing the user terms * @return string */ function changeTerms() { global $CONFIG, $DB; $languages = google::languages((array) $CONFIG->Site->languages); $terms = $DB->{'aliases,content'}->asList(array('aliases.alias' => 'Terms', 'content.section' => 'Terms'), 'content.language,content.content', false, true); reset($terms); $norm = array('lang' => key($terms), 'text' => current($terms)); $lTabs = array(); foreach ($languages as $l => $lang) { $lTabs[] = new Tab($lang, new htmlfield(__('Terms'), 'terms[' . $l . ']', isset($terms[$l]) ? @$terms[$l] : google::translate(@$norm['text'], @$norm['lang'], $l))); } $form = new Form('saveTerms'); return '<div class="nav"><a href="' . url(null, 'id') . '">' . icon('small/arrow_left') . __('Back') . '</a></div>' . $form->collection(new Tabber('tT', $lTabs)); }
/** * Loads the contents of a page * @access public * @return void */ function loadContent($force = false, $prohibit_translation = false) { if ($this->cLoaded && !$force) { return; } global $DB, $USER, $Templates, $CONFIG; if ($this->ID == false) { return; } if ($force) { $this->content = false; } $this->cLoaded = true; if (is_array($this->content)) { $skip = array_keys($this->content); $m = $this->content; } else { $skip = $m = array(); } // READ THIS: This part is not obvious at all! // Language list, NB: reverse preferred order, fallback languages starting with least preferred language first continued in increasing relevance and primary language last $languagelist = "'" . join("','", array_unique(array('en', $this->loadedLanguage))) . "'"; $this->saved_content = array_merge($m, (array) @$DB->asList("\nSELECT t1.`section`,t1.`content`\nFROM\n (\n `content` AS t1\n LEFT OUTER JOIN `content` t2 ON t1.`section` = t2.`section`\n AND t1.`id` = t2.`id`\n AND t1.`revision` < t2.`revision`\n AND field( t1.`language` , " . $languagelist . " ) = field( t2.`language` , " . $languagelist . " )\n )\n LEFT OUTER JOIN\n (\n `content` AS t3\n LEFT OUTER JOIN `content` t4 ON t3.`section` = t4.`section`\n AND t3.`id` = t4.`id`\n AND t3.`revision` < t4.`revision`\n AND field( t3.`language` , " . $languagelist . " ) = field( t4.`language` , " . $languagelist . " )\n )\n ON t1.`section` = t3.`section`\n AND t1.`id` = t3.`id`\n AND field( t1.`language` , " . $languagelist . " ) < field( t3.`language` , " . $languagelist . " )\nWHERE t1.`id` = " . (int) $this->ID . "\n AND t2.id IS NULL\n AND t4.id IS NULL\n AND t3.id IS NULL" . (empty($skip) ? '' : " AND t1.section NOT IN ('" . join("','", $skip) . "')"), true)); if ($this->AutoTranslate && !$prohibit_translation && $USER->settings['language'] && $USER->settings['auto_Translate'] && $CONFIG->Site->auto_Translate === 'yes') { $diff = array_diff($Templates->current->sections, array_keys($this->content)); if (!empty($diff)) { $c = $DB->content->asList(array("id" => $this->ID, 'section' => $diff), 'section,content,language', false, true, "revision DESC"); $sections = $content = $languages = array(); foreach ($c as $section => $data) { if (!empty($data[0])) { $sections[] = $section; $content[] = $data[0]; $languages[] = $data[1]; } } if (!empty($sections) && ($translation = google::translate($content, $languages, $this->loadedLanguage))) { foreach ($translation as &$tr) { $tr = '<div class="warn_autotranslate">' . __('Warning: auto-translated text') . '</div>' . $tr; } $this->content = array_combine($sections, $translation); } } } }
require_once './flickrTagRelated.php'; require_once './googleDownloader.php'; $start = microtime(true); $count1 = 0; $count2 = 0; $count3 = 0; $count4 = 0; global $imgid; ############################################################### # Initialize Classes ############################################################### $downloadIMAGE = new downloadIMAGE(); $Flickr = new Flickr(); $TAG = new TAG(); $FlickrRelated = new FlickrRalated(); $google = new google(); ############################################################### # Get images ids ############################################################### /*$keywords = ['big+backpack','white+backpack','blue+bacpack']; for ($c=0;$c<sizeof($keywords);$c++){ $data = $google->queryengine($keywords[$c]); print_r($data); echo '<br/><br/>'; } exit;*/ if (!empty($addMe)) { $info = $queryInput . '+' . $addMe; } else { $info = $queryInput;
/** * execute function. * * @access public * @return this object */ public function execute() { if ($this->encodingState > -1) { switch ($this->audio_method) { case speech::METHOD_FESTIVAL: $this->decode(); $this->initSanitise(); $this->writePlaylist(); $output = shell_exec("nice -n 19 /var/www/production/server-services/speech/tts/SB_generateAudio.sh {$this->scratch_path}{$this->uniqueID}.txt {$this->uniqueID} awb"); break; case speech::METHOD_INSIPIO: require_once dirname(__FILE__) . "/insipio.class.php"; $this->decode(); $this->initSanitise(); $path = $this->output_path . "INSIPIO-TTS-" . $this->uniqueID . "-" . 0 . ".mp3"; $language = isset($_GET['l']) ? strtolower($_GET['l']) : "en"; $in = new insipio($this->decodedData, $path, $language, $this->voice); $response = $in->send(); $this->chunks = 1; $this->writePlaylist(); // Flush any out of date fields. $this->flushCache(); break; case speech::METHOD_GOOGLE: require_once dirname(__FILE__) . "/google.class.php"; $this->initSanitise(); $path = $this->output_path . "GOOGLE-TTS-" . $this->uniqueID . "-" . 0 . ".mp3"; $language = isset($_GET['l']) ? strtolower($_GET['l']) : "en"; $google = new google($this->rawData, $path, $language); $response = $google->send(); $this->chunks = 1; $this->writePlaylist(); // Flush any out of date fields. $this->flushCache(); break; case speech::METHOD_ESPEAK: require_once dirname(__FILE__) . "/espeak.class.php"; $this->decode(); $this->initSanitise(); $path = $this->output_path . "ESPEAK-TTS-" . $this->uniqueID . "-" . 0 . ".mp3"; $language = isset($_GET['l']) ? strtolower($_GET['l']) : "en"; $in = new espeak($this->output_path . $this->uniqueID . ".txt", $path, $language, $this->voice); $response = $in->send(); $this->chunks = 1; $this->writePlaylist(); // Flush any out of date fields. $this->flushCache(); break; } // SCS fix 13/09/2011 // Don't wait for output. Version 2 of the toolbar waits for a response, which will hang the UI unless this is run in the background. // Sending to /dev/null & achieves this. Left the old command above just incase we need to put back at a later point. //exec("nice -n 19 /var/scripts/SB_generateAudio.sh {$this->scratch_path}{$this->uniqueID}.txt {$this->uniqueID} awb > /dev/null &"); if ($this->debug == 1) { file_put_contents($this->script_path . "debug/" . $this->uniqueID . ".txt", "execute:> Running generateAudio on dataset: {$this->clean}\n\n", FILE_APPEND); } if ($this->debug == 1) { file_put_contents($this->script_path . "debug/" . $this->uniqueID . ".txt", "execute:> result: " . $output . "\n\n", FILE_APPEND); } //file_put_contents($this->scratch_path . "chunks/clean-" . rand(0, 99) . ".txt", $this->returnClean() ); //echo $output; //echo "Execution string: /var/scripts/SB_generateAudio.sh {$this->scratch_path}/{$this->uniqueID}.txt {$this->uniqueID} awb"; } return $this; }
<?php require_once "db.php"; require_once "google.php"; $db = new db(); $db->clear(); $google = new google(); if (isset($_POST['cities'])) { $i = 0; foreach ($_POST['cities'] as $city) { $id = $db->getLocationByName($city['citry']); if ($id == False) { list($lat, $long) = $google->getLocation($city['citry']); $do = new stdClass(); $do->name = $city['citry']; $do->long = $long; $do->lat = $lat; $id = $db->insertLocations($do); } else { $id = $id[0]['id']; } $db->insertDestination($id, $i); $i += 1; } }
/** * @return string */ private function mainView() { global $USER, $CONFIG, $DB, $Controller; $aList = array(); $total = $DB->getCell("SELECT DISTINCT COUNT(*) FROM updates AS t1 \n LEFT JOIN spine sp ON sp.id = t1.id\n LEFT JOIN updates t2 ON t1.id = t2.id\n AND t1.edited < t2.edited\n WHERE t2.edited IS NULL\n AND sp.class = 'Article'\n ORDER BY t1.edited DESC"); $perpage = 20; $pager = Pagination::getRange($perpage, $total); $r = $DB->query("SELECT DISTINCT sp.id FROM updates AS t1 \n LEFT JOIN spine sp ON sp.id = t1.id\n LEFT JOIN updates t2 ON t1.id = t2.id\n AND t1.edited < t2.edited\n WHERE t2.edited IS NULL\n AND sp.class = 'Article'\n ORDER BY t1.edited DESC\n LIMIT " . $pager['range']['start'] . ", " . $perpage); while (false !== ($article = $DB->fetchAssoc($r))) { $article = $Controller->{$article['id']}; $aList[] = '<li><span class="fixed-width">' . $article->Name . '</span><div class="tools">' . icon('small/eye', __('View'), url(array('id' => $article->ID))) . icon('small/pencil', __('Edit'), url(array('edit' => $article->ID), array('id'))) . icon('small/delete', __('Delete'), url(array('del' => $article->ID), 'id')) . '</div></li>'; } $aList = listify($aList); if ($total > $perpage) { $aList .= $pager['links']; } $form = new Form('newArticle'); $calendarSettings->params = 'collapsible:true,active:false'; return new Tabber('events', __('Article manager'), $aList, __('New article'), $form->collection(new Hidden('asave', 1), new Hidden('edit', $_REQUEST['edit'] ? $_REQUEST['edit'] : 'new'), new Set(new Select(__('Language'), 'lang', google::languages($CONFIG->Site->languages), $USER->settings['language']), new Input(__('Title'), 'atitle'), new Li(new Datepicker(__('Publish'), 'apubd'), new Timepickr(false, 'apubt')), new htmlfield(__('Text'), 'atxt'), new htmlfield(__('Preamble'), 'apre')))); }