Exemple #1
0
 public function getIconView($mode = 'icon')
 {
     static $icon_list = NULL;
     if (empty($icon_list)) {
         $file = PHPWS_Core::getConfigFile('filecabinet', 'icons.php');
         if (!$file) {
             return sprintf('<img class="fc-mime-icon" src="' . PHPWS_SOURCE_HTTP . 'mod/filecabinet/img/mime_types/text.png" title="%s" alt="%s" />', htmlspecialchars($this->title, ENT_QUOTES), htmlspecialchars($this->title, ENT_QUOTES));
         } else {
             include $file;
         }
     }
     if (isset($icon_list[$this->file_type])) {
         $graphic = $icon_list[$this->file_type];
         if ($mode == 'small_icon') {
             $graphic = 's_' . $graphic;
         }
         return sprintf('<img class="fc-mime-icon" src="' . PHPWS_SOURCE_HTTP . 'mod/filecabinet/img/mime_types/%s" title="%s" alt="%s" />', $graphic, htmlspecialchars($this->title, ENT_QUOTES), htmlspecialchars($this->title, ENT_QUOTES));
     } else {
         if ($mode == 'small_icon') {
             return sprintf('<img class="fc-mime-icon" src="' . PHPWS_SOURCE_HTTP . 'mod/filecabinet/img/mime_types/s_text.png" title="%s" alt="%s" />', htmlspecialchars($this->title, ENT_QUOTES), htmlspecialchars($this->title, ENT_QUOTES));
         } else {
             return sprintf('<img class="fc-mime-icon" src="' . PHPWS_SOURCE_HTTP . 'mod/filecabinet/img/mime_types/text.png" title="%s" alt="%s" />', htmlspecialchars($this->title, ENT_QUOTES), htmlspecialchars($this->title, ENT_QUOTES));
         }
     }
 }
Exemple #2
0
 public static function get($value, $module, $funcName = NULL, $extraInfo = NULL)
 {
     $current_language = Language::getLocale();
     Language::setLocale(DEFAULT_LANGUAGE);
     if (empty($module)) {
         return PHPWS_Error::get(PHPWS_NO_MODULE, 'core', 'PHPWS_Error::get', 'Value: ' . $value . ', Function: ' . $funcName);
     }
     try {
         $errorFile = PHPWS_Core::getConfigFile($module, 'error.php');
     } catch (\Exception $e) {
         $errorFile = null;
     }
     if (empty($errorFile)) {
         // Error file not found in local config directory. Checking inc/ source directory
         if ($module == 'core') {
             $errorFile = PHPWS_SOURCE_DIR . 'core/inc/error.php';
         } else {
             $errorFile = PHPWS_SOURCE_DIR . 'mod/' . $module . '/inc/error.php';
         }
         if (!is_file($errorFile)) {
             // prevent infinite loop
             if ($module == 'core') {
                 echo _('Core could not locate its error.php file.');
                 die;
             }
             return PHPWS_Error::get(PHPWS_NO_ERROR_FILE, 'core', 'PHPWS_Error::get', 'Module: ' . $module);
         }
     }
     include $errorFile;
     if (!isset($errors)) {
         return FALSE;
     }
     if (PHPWS_Error::isError($value)) {
         $value = $value->getCode();
     }
     if ($module != 'core') {
         $fullError[] = $module;
     } else {
         $fullError[] = 'Core';
     }
     if (isset($funcName)) {
         $fullError[] = " - {$funcName}()";
     }
     if (isset($errors[$value])) {
         $message = $errors[$value];
     } else {
         $message = _('Unknown error code.');
     }
     $fullError[] = ' - ' . $message;
     if (isset($extraInfo)) {
         if (is_array($extraInfo)) {
             $message = vsprintf($message, $extraInfo);
         } else {
             $fullError[] = ' [' . $extraInfo . ']';
         }
     }
     $error = PHPWS_Error::raiseError($message, $value, NULL, NULL, implode('', $fullError));
     Language::setLocale($current_language);
     return $error;
 }
Exemple #3
0
 public static function registerModule($module, &$content)
 {
     if (is_file(PHPWS_SOURCE_DIR . 'mod/' . $module . '/conf/rss.php')) {
         $reg_file = PHPWS_Core::getConfigFile($module, 'rss.php');
     } else {
         $reg_file = false;
     }
     if ($reg_file == FALSE) {
         PHPWS_Boost::addLog($module, dgettext('rss', 'No RSS file found.'));
         return FALSE;
     }
     PHPWS_Core::initModClass('rss', 'Channel.php');
     include $reg_file;
     $oChannel = new RSS_Channel();
     $oChannel->module = $module;
     if (!isset($channel) || !is_array($channel)) {
         $content[] = dgettext('rss', 'RSS file found but no channel information.');
         PHPWS_Boost::addLog($module, dgettext('rss', 'RSS file found but no channel information.'));
     }
     $oModule = new PHPWS_Module($module);
     if (!empty($channel['title'])) {
         $oChannel->title = strip_tags($channel['title']);
     } else {
         $oChannel->title = $oModule->proper_name;
     }
     if (!empty($channel['description'])) {
         $oChannel->description = strip_tags($channel['description']);
     }
     if (!empty($channel['link'])) {
         $oChannel->link = strip_tags($channel['link']);
     } else {
         $oChannel->link = PHPWS_Core::getHomeHttp();
     }
     $result = $oChannel->save();
     if (PHPWS_Error::isError($result)) {
         PHPWS_Error::log($result);
         PHPWS_Boost::addLog($module, dgettext('rss', 'An error occurred registering to RSS module.'));
         $content[] = dgettext('rss', 'An error occurred registering to RSS module.');
         return NULL;
     } else {
         $content[] = sprintf(dgettext('rss', 'RSS registration to %s module successful.'), $oModule->proper_name);
         return TRUE;
     }
 }
Exemple #4
0
 public static function userForm(PHPWS_User $user, $message = NULL)
 {
     require_once PHPWS_SOURCE_DIR . 'core/class/Time.php';
     javascript('jquery');
     $form = new PHPWS_Form();
     $form->addHidden('module', 'users');
     $form->addHidden('action', 'user');
     $form->addHidden('command', 'my_page');
     $form->addHidden('subcommand', 'postUser');
     if (Current_User::allow('users') || $user->display_name == $user->username) {
         $form->addText('display_name', $user->display_name);
         $form->setClass('display_name', 'form-control');
         $form->setLabel('display_name', dgettext('users', 'Display Name'));
     } else {
         $form->addTplTag('DISPLAY_NAME_LABEL', dgettext('users', 'Display Name'));
         $tpl['DISPLAY_NAME'] = javascript('slider', array('link' => $user->display_name, 'id' => 'name-info', 'message' => dgettext('users', 'Once you change your display name, you may not change it again until reset by the site administrator.')));
     }
     if ($user->canChangePassword()) {
         $form->addPassword('password1');
         $form->setAutoComplete('password1');
         $form->setClass('password1', 'form-control');
         $form->addPassword('password2');
         $form->setAutoComplete('password2');
         $form->setClass('password2', 'form-control');
         $form->setTitle('password2', dgettext('users', 'Password confirm'));
         $form->setLabel('password1', dgettext('users', 'Password'));
     } else {
         $tpl['PASSWORD1_LABEL'] = dgettext('users', 'Password');
         $tpl['PASSWORD1'] = javascript('slider', array('link' => dgettext('users', 'Why can\'t I change my password?'), 'id' => 'pw-info', 'message' => dgettext('users', 'Your account is authorized external to this site. You will need to update it at the source.')));
     }
     $form->addText('email', $user->getEmail());
     $form->setSize('email', 40);
     $form->setLabel('email', dgettext('users', 'Email Address'));
     $form->setClass('email', 'form-control');
     if (isset($tpl)) {
         $form->mergeTemplate($tpl);
     }
     $tz_list = PHPWS_Time::getTZList();
     $timezones['server'] = dgettext('users', '-- Use server\'s time zone --');
     foreach ($tz_list as $tz) {
         if (!empty($tz['codes'])) {
             $timezones[$tz['id']] = sprintf('%s : %s', $tz['id'], $tz['codes'][0]);
         } elseif (!empty($tz['city'])) {
             $timezones[$tz['id']] = sprintf('%s : %s', $tz['id'], $tz['city'][0]);
         } else {
             $timezones[$tz['id']] = $tz['id'];
         }
     }
     if (isset($_REQUEST['timezone'])) {
         $user_tz = $_REQUEST['timezone'];
     } else {
         $user_tz = PHPWS_Cookie::read('user_tz');
     }
     $form->addSelect('timezone', $timezones);
     $form->setLabel('timezone', dgettext('users', 'Time Zone'));
     $form->setMatch('timezone', $user_tz);
     $form->setClass('timezone', 'form-control');
     if (isset($_REQUEST['dst']) && $_REQUEST['timezone'] != 'server') {
         $dst = $_REQUEST['dst'];
     } else {
         $dst = PHPWS_Cookie::read('user_dst');
     }
     $form->addCheckbox('dst', 1);
     $form->setMatch('dst', $dst);
     $form->setLabel('dst', dgettext('users', 'Use Daylight Savings Time'));
     if (isset($_POST['cp'])) {
         $cp = (int) $_POST['cp'];
     } else {
         $cp = (int) PHPWS_Cookie::read('user_cp');
     }
     if (Current_User::allowRememberMe()) {
         // User must authorize locally
         if ($_SESSION['User']->authorize == 1) {
             $form->addCheckbox('remember_me', 1);
             if (PHPWS_Cookie::read('remember_me')) {
                 $form->setMatch('remember_me', 1);
             }
             $form->setLabel('remember_me', dgettext('users', 'Remember me'));
         }
     }
     $form->addHidden('userId', $user->getId());
     $form->addSubmit('submit', dgettext('users', 'Update my information'));
     $form->setClass('submit', 'btn btn-primary');
     if (!DISABLE_TRANSLATION && !FORCE_DEFAULT_LANGUAGE) {
         $language_file = PHPWS_Core::getConfigFile('users', 'languages.php');
         if ($language_file) {
             include $language_file;
             $form->addSelect('language', $languages);
             $form->setClass('language', 'form-control');
             $form->setLabel('language', dgettext('users', 'Language preference'));
             if (isset($_COOKIE['phpws_default_language'])) {
                 $language = preg_replace('/\\W/', '', $_COOKIE['phpws_default_language']);
                 $form->setMatch('language', $language);
             }
         }
     }
     $template = $form->getTemplate();
     if (isset($message)) {
         foreach ($message as $tag => $error) {
             $template[$tag] = $error;
         }
     }
     $template['ACCT_INFO'] = dgettext('users', 'Account Information');
     $template['LOCAL_INFO'] = dgettext('users', 'Localization');
     $template['PREF'] = dgettext('users', 'Preferences');
     return PHPWS_Template::process($template, 'users', 'my_page/user_setting.tpl');
 }
Exemple #5
0
 /**
  * Filters text and clears common words from the inputed text
  */
 public function parseKeywords($text)
 {
     if (empty($text)) {
         return;
     }
     $text = $this->filterWords($text, false);
     /*
      $language = str_ireplace('.utf-8', '',
      Settings::get('Global', 'language'));
      $file_name = strtolower($language . '_wordlist.txt');
     */
     $file_name = 'en_us_wordlist.txt';
     // Removes trademark/registered, contractions, and website suffix
     $text = preg_replace('/(n\'t|\'([sd]|ll|re|ve))|\\.(com|edu|net|org)|\\(tm\\)|\\(r\\)/', '', $text);
     $config_file = PHPWS_Core::getConfigFile('search', $file_name);
     if (!$config_file) {
         $config_file = PHPWS_Core::getConfigFile('search', 'wordlist.txt');
         if (!$config_file) {
             return $text;
         }
     }
     $common_words = file($config_file);
     foreach ($common_words as $word) {
         $word = trim($word);
         // This line below does the majority of the work
         $text = preg_replace("/^{$word}\\s|\\s{$word}\\s|\\s{$word}\$/", ' ', $text);
         // This line removes repeats AND English language suffixes.
         $text = preg_replace("/ {$word}(es|s|ing|ed|d|ly|ings|ful|er|est)? /", ' ', $text);
     }
     return $text;
 }
Exemple #6
0
 /**
  * Returns an array of the core modules. Set from the core_modules.php file.
  */
 public static function coreModList()
 {
     static $core_modules = NULL;
     if (is_array($core_modules)) {
         return $core_modules;
     }
     $file = PHPWS_Core::getConfigFile('core', 'core_modules.php');
     if (PHPWS_Error::isError($file)) {
         return $file;
     }
     include $file;
     return $core_modules;
 }
Exemple #7
0
 public static function addAlternates(PHPWS_Form $form)
 {
     $file = PHPWS_Core::getConfigFile('search', 'alternate.php');
     if ($file) {
         include $file;
         if (!empty($alternate_search_engine) && is_array($alternate_search_engine)) {
             $alternate_sites['local'] = dgettext('search', 'Local');
             foreach ($alternate_search_engine as $title => $altSite) {
                 $alternate_sites[$title] = $altSite['title'];
             }
             $form->addRadio('alternate', array_keys($alternate_sites));
             $form->setLabel('alternate', $alternate_sites);
             $form->setMatch('alternate', 'local');
         }
     }
 }
Exemple #8
0
 public static function getTZList()
 {
     $file = PHPWS_Core::getConfigFile('core', 'timezone.php');
     include $file;
     return $timezones;
 }