/**
  * Initializes array containing objectid, icon, and language code
  * for each defined translation
  * @static
  * @param smdoc $foowd Reference to the foowd environment object.
  * @param bool $forceRefresh Force refresh of session cache.
  */
 function initialize($foowd, $forceRefresh = FALSE)
 {
     $foowd->track('smdoc_translation::initialize', $forceRefresh);
     $session_links = new input_session('lang_links', NULL);
     $session_langs = new input_session('languages', NULL);
     if (isset($session_links->value) && isset($session_langs->value) && !$forceRefresh) {
         $foowd->track();
         return;
     }
     $default_title = getConstOrDefault('TRANSLATION_DEFAULT_LANGUAGE', 'en_US');
     $default_icon = getConstOrDefault('TRANSLATION_DEFAULT_LANGUAGE_ICON', '');
     $links = array();
     $languages = array();
     $url_arr['class'] = 'smdoc_translation';
     $url_arr['method'] = 'enter';
     $url_arr['langid'] = '';
     $url = getURI($url_arr);
     // Add elements for the default translation
     $the_url = '<a href="' . $url . '0">';
     if (!empty($default_icon)) {
         $the_url .= '<img src="' . $default_icon . '" ';
         $the_url .= 'alt="' . $default_title . '" ';
         $the_url .= 'title="' . $default_title . '" ';
         $the_rul .= ' />';
     } else {
         $the_url .= $default_title;
     }
     $the_url .= '</a>';
     $links[0] = $the_url;
     $languages[0] = $default_title;
     // Fetch available translations
     // no limit, retrieve objects, and don't bother with workspaces.
     $index[] = 'object';
     $where['classid'] = TRANSLATION_CLASS_ID;
     $order = 'title';
     $t_objects =& $foowd->getObjList($index, NULL, $where, $order, NULL, TRUE, FALSE);
     // Add each translation to the list
     foreach ($t_objects as $trans_obj) {
         $the_url = '<a href="' . $url . $trans_obj->objectid . '">';
         if (isset($trans_obj->language_icon)) {
             $the_url .= '<img src="' . $trans_obj->language_icon . '" ';
             $the_url .= 'title="' . $trans_obj->title . '" ';
             $the_url .= 'alt="' . $trans_obj->title . '" />';
         } else {
             $the_url .= $trans_obj->title;
         }
         $the_url .= '</a>';
         $links[$trans_obj->objectid] = $the_url;
         $languages[$trans_obj->objectid] = $trans_obj->title;
         unset($trans_obj);
     }
     $session_links->set($links);
     $session_langs->set($languages);
     $foowd->track();
 }
 /**
  * Output the generated diff.
  */
 function method_diff()
 {
     $this->foowd->track('foowd_text_plain->method_diff');
     $diffResultArray = NULL;
     $result = $this->diff($diffResultArray);
     switch ($result) {
         case -1:
             $this->foowd->template->assign('failure', _("Object can not be compared to itself."));
             break;
         case -2:
             $this->foowd->template->assign('failure', INVALID_METHOD);
             break;
         case -3:
             $this->foowd->template->assign('failure', _("Object versions are identical."));
             break;
         default:
             $this->foowd->template->assign('version1', $this->version);
             $this->foowd->template->assign('version2', $result);
             $diffAddRegex = getConstOrDefault('DIFF_ADD_REGEX', '/^>(.*)$/');
             $diffMinusRegex = getConstOrDefault('DIFF_MINUS_REGEX', '/^<(.*)$/');
             $diffSameRegex = getConstOrDefault('DIFF_SAME_REGEX', '/^ (.*)$/');
             foreach ($diffResultArray as $diffLine) {
                 $diff = array();
                 if (preg_match($diffAddRegex, $diffLine, $lineResult)) {
                     $diff['add'] = htmlspecialchars($lineResult[1]);
                 } elseif (preg_match($diffMinusRegex, $diffLine, $lineResult)) {
                     $diff['minus'] = htmlspecialchars($lineResult[1]);
                 } elseif (preg_match($diffSameRegex, $diffLine, $lineResult)) {
                     $diff['same'] = htmlspecialchars($lineResult[1]);
                 }
                 $this->foowd->template->append('diff', $diff);
             }
             break;
     }
     $this->foowd->track();
 }
 /**
  * Display the import workspace form and process its input.
  */
 function method_import()
 {
     $this->foowd->track('foowd_workspace->method_import');
     include_once INPUT_DIR . 'input.form.php';
     include_once INPUT_DIR . 'input.file.php';
     $importForm = new input_form('importForm', NULL, SQ_POST, _("Import"), NULL);
     $importFile = new input_file('importFile', _("Import file") . ':', NULL, getConstOrDefault('INPUT_FILE_SIZE_MAX', 2097152));
     if ($importForm->submitted()) {
         $result = $this->import($importFile);
         if ($result == 0) {
             $this->foowd->template->assign('success', TRUE);
             $this->foowd->template->assign('objectid', $this->objectid);
             $this->foowd->template->assign('classid', $this->classid);
         } else {
             $this->foowd->template->assign('success', FALSE);
             $this->foowd->template->assign('error', $result);
         }
     } else {
         $importForm->addObject($importFile);
         $this->foowd->template->assign_by_ref('form', $importForm);
     }
     $this->foowd->track();
 }
Exemple #4
0
 /**
  * Create Anonymous Foowd User
  *
  * @param smdoc $foowd Reference to the foowd environment object.
  * @return new instance of anonymous user class.
  */
 function &fetchAnonymousUser(&$foowd)
 {
     $anonUserClass = getConstOrDefault('ANONYMOUS_USER_CLASS', 'foowd_anonuser');
     if (class_exists($anonUserClass)) {
         return new $anonUserClass($foowd);
     } else {
         trigger_error('Could not find anonymous user class.', E_USER_ERROR);
     }
 }