/** * Cannot set files_only and recursive to true */ public static function readDirectory($path, $directories_only = false, $files_only = false, $recursive = false, $extensions = null, $indeep = false) { static $first_path = null; $listing = null; PHPWS_File::appendSlash($path); if (empty($first_path)) { $first_path = $path; } if ($directories_only && $files_only) { $directories_only = $files_only = false; } if (!is_dir($path)) { return false; } $dir = dir($path); while ($file = $dir->read()) { $fullpath = $path . $file; $showpath = str_replace($first_path, '', $fullpath); if (strpos($file, '.') === 0) { // skips hidden files, directories and back references continue; } if (is_dir($fullpath)) { if ($files_only) { continue; } if (empty($extensions)) { $listing[] = $showpath; } if ($recursive) { $subdir = PHPWS_File::readDirectory($fullpath, $directories_only, false, true, $extensions, true); if (!empty($subdir)) { if (!empty($listing)) { $listing = array_merge($listing, $subdir); } else { $listing = $subdir; } } } } elseif ($directories_only) { continue; } else { if (!empty($extensions)) { $aFile = explode('.', $file); $ext = array_pop($aFile); if (!in_array($ext, $extensions)) { continue; } } $listing[] = $showpath; } } $dir->close(); if (!$indeep) { $first_path = null; } return $listing; }
public static function getThemeList() { PHPWS_Core::initCoreClass('File.php'); return PHPWS_File::readDirectory(Layout::getThemeDirRoot(), 1); }
public static function getAllMods() { $all_mods = PHPWS_File::readDirectory(PHPWS_SOURCE_DIR . 'mod/', TRUE); foreach ($all_mods as $key => $module) { if (is_file(PHPWS_SOURCE_DIR . 'mod/' . $module . '/boost/boost.php')) { $dir_mods[] = $module; } elseif (is_file(PHPWS_SOURCE_DIR . 'mod/' . $module . '/conf/boost.php')) { $GLOBALS['Boost_Old_Mods'][] = $module; } } return $dir_mods; }
function manageEditors() { if ($_SESSION["OBJ_user"]->allow_access("xwysiwyg", "settings")) { $this->content .= "<a href=\"" . $this->linkRef . "&action=admin" . "\">" . $_SESSION['translate']->it("Back to administration") . "</a>"; if (isset($_GET['updList'])) { //to update, simply delete the existing file @unlink(PHPWS_HOME_DIR . "files/xwysiwyg/editors/list.txt"); } $editors = array(); $formTags = array(); $table = array(); $this->content .= "<br /><br /><b>" . $_SESSION['translate']->it("Available editors") . "</b>"; $table[] = array("<b>" . $_SESSION['translate']->it("Location") . "</b>", "<b>" . $_SESSION['translate']->it("Editor") . "</b>", "<b>" . $_SESSION['translate']->it("Status") . "</b>", "<b>" . $_SESSION['translate']->it("Action") . "</b>"); $dir = PHPWS_File::readDirectory(PHPWS_HOME_DIR . "files/xwysiwyg/editors/", FALSE, TRUE, FALSE, array('conf')); if (is_array($dir)) { $location = $_SESSION['translate']->it("local"); foreach ($dir as $file) { include PHPWS_HOME_DIR . "files/xwysiwyg/editors/" . $file; $editors[] = $cfg_editor; $result = $GLOBALS['core']->quickFetch("SELECT editor FROM mod_xw_config WHERE editor = '{$cfg_editor}'", TRUE, TRUE); if ($result) { $status = $_SESSION['translate']->it("installed"); $action_link = $this->linkRef . "&action=delEditor&delEditor={$cfg_editor}"; $action_label = $_SESSION['translate']->it("Uninstall"); $action = "<a href=\"{$action_link}\">{$action_label}</a>"; $select = $GLOBALS['core']->quickFetch("SELECT editor FROM mod_xw_editor", TRUE, TRUE); if ($select['editor'] == $cfg_editor) { $editor = "<strong>{$cfg_editor}</strong>"; } else { $action_link = $this->linkRef . "&action=toggle&editor={$cfg_editor}"; $action_label = $_SESSION['translate']->it("Select"); $action .= " || <a href=\"{$action_link}\">{$action_label}</a>"; $editor = $cfg_editor; } } else { $status = $_SESSION['translate']->it("not installed"); $action_link = $this->linkRef . "&action=addEditor&addEditor={$cfg_editor}&fn={$file}"; $action_label = $_SESSION['translate']->it("Install"); $action = "<a href=\"{$action_link}\">{$action_label}</a>"; $action_link = $this->linkRef . "&action=delFile&delFile={$cfg_editor}&filetyp=ext"; $action_label = $_SESSION['translate']->it("Remove"); $action .= " || <a href=\"{$action_link}\">{$action_label}</a>"; $editor = $cfg_editor; } $table[] = array($location, $editor, $status, $action); } } else { $this->content .= "<br />" . $_SESSION['translate']->it("No local editors found"); } if (!$GLOBALS["core"]->isHub) { $table[] = array("<b>" . $_SESSION['translate']->it("Location") . "</b>", "<b>" . $_SESSION['translate']->it("Editor") . "</b>", "<b>" . $_SESSION['translate']->it("Status") . "</b>", "<b>" . $_SESSION['translate']->it("Action") . "</b>"); if (!is_dir("{$GLOBALS['core']->home_dir}files/xwysiwyg/")) { PHPWS_File::makeDir($GLOBALS['core']->home_dir . "files/xwysiwyg/"); } if (!is_dir("{$GLOBALS['core']->home_dir}files/xwysiwyg/editors/")) { PHPWS_File::makeDir($GLOBALS['core']->home_dir . "files/xwysiwyg/editors/"); } $dir = PHPWS_File::readDirectory(PHPWS_SOURCE_DIR . "files/xwysiwyg/editors/", FALSE, TRUE, FALSE, array('conf')); if (is_array($dir)) { $location = $_SESSION['translate']->it("hub"); foreach ($dir as $file) { include_once PHPWS_SOURCE_DIR . "files/xwysiwyg/editors/" . $file; if (!in_array($cfg_editor, $editors)) { $status = $_SESSION['translate']->it("not copied"); $action_link = $this->linkRef . "&action=cpyEditor&cpyEditor={$cfg_editor}"; $action_label = $_SESSION['translate']->it("Copy"); $action = "<a href=\"{$action_link}\">{$action_label}</a>"; $editor = $cfg_editor; } else { $status = $_SESSION['translate']->it("copied"); $action_link = $this->linkRef . "&action=remEditor&remEditor={$cfg_editor}"; $action_label = ""; $action = "na"; $editor = $cfg_editor; } $table[] = array($location, $editor, $status, $action); } } else { $this->content .= "<br />" . $_SESSION['translate']->it("No editors found on hub"); } } $this->content .= PHPWS_Text::ezTable($table, 2, 2, 1, "", NULL, 1, "top"); $this->content .= "<br /><br /><b>" . $_SESSION['translate']->it("Available editor-packages") . "</b>"; $this->content .= " <a href=\"" . $this->linkRef . "&action=manageEditor&updList=1" . "\">" . $_SESSION['translate']->it("Update List") . "</a>"; $table = array(); $table[] = array("<b>" . $_SESSION['translate']->it("Location") . "</b>", "<b>" . $_SESSION['translate']->it("Editor") . "</b>", "<b>" . $_SESSION['translate']->it("Description") . "</b>", "<b>" . $_SESSION['translate']->it("Action") . "</b>"); $dir = PHPWS_File::readDirectory(PHPWS_HOME_DIR . "files/xwysiwyg/editors/", FALSE, TRUE, FALSE, array('tgz')); if (is_array($dir)) { $location = $_SESSION['translate']->it("local"); foreach ($dir as $file) { $status = $_SESSION['translate']->it("Archive package"); $action_link = $this->linkRef . "&action=tarEditor&tarEditor={$file}&local=1"; $action_label = $_SESSION['translate']->it("Extract"); $action = "<a href=\"{$action_link}\">{$action_label}</a>"; $action_link = $this->linkRef . "&action=delFile&delFile={$file}&filetyp=tgz"; $action_label = $_SESSION['translate']->it("Delete"); $action .= " || <a href=\"{$action_link}\">{$action_label}</a>"; $editor = $file; $table[] = array($location, $editor, $status, $action); } } // fixme: remeber to update this entry ! $file_loc = PHPWS_HOME_DIR . "files/xwysiwyg/editors/list.txt"; $file_onl = "http://www.firebird.ch/xwysiwyg/editors/list41.txt"; $location = $_SESSION['translate']->it("remote"); if (!is_file($file_loc)) { PHPWS_File::fileCopy($file_onl, PHPWS_HOME_DIR . "files/xwysiwyg/editors/", "list.txt", TRUE, TRUE); } if ($rows = file($file_loc)) { PHPWS_Array::dropNulls($rows); foreach ($rows as $items) { $item = explode("::", $items); $editor = $item[0]; if (in_array($editor, $editors)) { continue; } $status = $item[1]; $action_label = $_SESSION['translate']->it("Direct install ([var1]kb)", $item[3]); $action_link = $this->linkRef . "&action=tarEditor&tarEditor=" . $item[2]; $action = "<a href=\"{$action_link}\">{$action_label}</a>"; $action_label = $_SESSION['translate']->it("Download"); $action_link = "http://www.firebird.ch/xwysiwyg/editors/" . $item[2]; $action .= " || <a href=\"{$action_link}\" target=\"_blank\">{$action_label}</a>"; $table[] = array($location, $editor, $status, $action); } } $this->content .= PHPWS_Text::ezTable($table, 2, 2, 1, "", NULL, 1, "top"); $this->content .= $_SESSION['translate']->it("Depending on your server's security settings, direct install may not work.") . "<br />"; $this->content .= $_SESSION['translate']->it("If everything fails, or if you want to modify the editor,") . "<br />"; $this->content .= $_SESSION['translate']->it("download the file and copy it to /_phpws_/files/xwysiwyg/editors/ manually") . "<br />"; } else { $this->content .= $_SESSION['translate']->it("Access was denied due to lack of proper permissions."); } // End of ADMINISTRATOR condition }
public static function settings() { $content = array(); $form = new PHPWS_Form('user_settings'); $form->addHidden('module', 'users'); $form->addHidden('action', 'admin'); $form->addHidden('command', 'update_settings'); $form->addSubmit('submit', dgettext('users', 'Update Settings')); $form->addText('site_contact', PHPWS_User::getUserSetting('site_contact')); $form->setLabel('site_contact', dgettext('users', 'Site contact email')); $form->setSize('site_contact', 40); if (Current_User::isDeity()) { $signup_modes = array(0, AUTO_SIGNUP, CONFIRM_SIGNUP); $signup_labels = array(dgettext('users', 'Not allowed'), dgettext('users', 'Immediate'), dgettext('users', 'Email Verification')); $form->addRadio('user_signup', $signup_modes); $form->setLabel('user_signup', $signup_labels); $form->addTplTag('USER_SIGNUP_LABEL', dgettext('users', 'User Signup Mode')); $form->setMatch('user_signup', PHPWS_User::getUserSetting('new_user_method')); if (extension_loaded('gd')) { $form->addCheckbox('graphic_confirm'); $form->setLabel('graphic_confirm', dgettext('users', 'New user CAPTCHA confirmation')); $form->setMatch('graphic_confirm', PHPWS_User::getUserSetting('graphic_confirm')); } $included_usermenu = PHPWS_File::readDirectory(PHPWS_SOURCE_DIR . 'mod/users/templates/usermenus/', FALSE, TRUE, FALSE, array('tpl')); $theme_usermenu = PHPWS_File::readDirectory(PHPWS_SOURCE_DIR . Layout::getThemeDir() . 'templates/users/usermenus/', FALSE, TRUE, FALSE, array('tpl')); if ($theme_usermenu) { $options = array_unique(array_merge($included_usermenu, $theme_usermenu)); } else { $options = $included_usermenu; } $menu_options = array_combine($options, $options); // Replace below with a directory read $menu_options['none'] = dgettext('users', 'None'); $menu_options['css.tpl'] = 'css.tpl'; $menu_options['Default.tpl'] = 'Default.tpl'; $menu_options['top.tpl'] = 'top.tpl'; $form->addSelect('user_menu', $menu_options); $form->setMatch('user_menu', PHPWS_User::getUserSetting('user_menu')); $form->setLabel('user_menu', dgettext('users', 'User Menu')); $form->addCheckBox('show_login', 1); $form->setMatch('show_login', PHPWS_Settings::get('users', 'show_login')); $form->setLabel('show_login', dgettext('users', 'Show login box')); $form->addTplTag('AFFIRM', dgettext('users', 'Yes')); $form->addCheckBox('allow_remember', 1); $form->setMatch('allow_remember', PHPWS_Settings::get('users', 'allow_remember')); $form->setLabel('allow_remember', dgettext('users', 'Allow Remember Me')); $form->addRadioAssoc('allow_new_users', array(1 => 'Yes', 0 => 'No')); $form->setMatch('allow_new_users', PHPWS_Settings::get('users', 'allow_new_users')); $form->addTplTag('ALLOW_NEW_USERS_LABEL', dgettext('users', 'Allow new user creation?')); } $form->addTextArea('forbidden_usernames', PHPWS_Settings::get('users', 'forbidden_usernames')); $form->setLabel('forbidden_usernames', dgettext('users', 'Forbidden usernames (one per line)')); $form->addCheckbox('session_warning', 1); $form->setMatch('session_warning', PHPWS_Settings::get('users', 'session_warning')); $form->setlabel('session_warning', 'Show session warning'); $template = $form->getTemplate(); if (Current_User::isDeity()) { $vars['action'] = 'admin'; $vars['command'] = 'check_permission_tables'; $template['VERIFY_PERMISSIONS'] = PHPWS_Text::secureLink(dgettext('users', 'Register user permissions'), 'users', $vars); $template['VERIFY_EXPLAIN'] = dgettext('users', 'Users module will re-register each module\'s permissions.'); } return PHPWS_Template::process($template, 'users', 'forms/settings.tpl'); }
public static function getEditorList() { return PHPWS_File::readDirectory(PHPWS_SOURCE_DIR . 'javascript/editors/', true); }
public function updateResizes($image) { $dir = $image->getResizePath(); if (!is_dir($dir)) { return; } $images = PHPWS_File::readDirectory($dir, false, true); if (empty($images)) { return; } foreach ($images as $file_name) { if (!preg_match('/\\d+x\\d+\\.\\w{1,4}$/', $file_name)) { continue; } $last_dot = strrpos($file_name, '.'); $base = substr($file_name, 0, $last_dot); $dimensions = explode('x', $base); $image->resize($dir . $file_name, $dimensions[0], $dimensions[1]); } }
/** * This forms lets admins pick files uploaded to the server for sorting on the site. */ public function classifyFileList() { $this->cabinet->title = dgettext('filecabinet', 'Classify files'); $classify_dir = $this->cabinet->getClassifyDir(); if (empty($classify_dir) || !is_dir($classify_dir)) { $this->cabinet->content = dgettext('filecabinet', 'Unable to locate the classify directory. Please check your File Cabinet settings, configuration file and directory permissions.'); return; } $allowed_file_types = $this->cabinet->getAllowedTypes(); $result = PHPWS_File::readDirectory($classify_dir, false, true); if (empty($result)) { $this->cabinet->content = dgettext('filecabinet', 'The incoming file directory is currently empty.'); return; } sort($result); if (PHPWS_Error::logIfError($result)) { $this->cabinet->content = dgettext('filecabinet', 'An error occurred when trying to read your incoming file directory.'); return; } $form = new PHPWS_Form('classify_file_list'); $form->addHidden('aop', 'classify_action'); $form->addHidden('module', 'filecabinet'); $image_folders = Cabinet::listFolders(IMAGE_FOLDER, true); if (!empty($image_folders)) { $form->addSelect('image_folders', $image_folders); $form->addSubmit('image_force', dgettext('filecabinet', 'Put all checked images here')); } $document_folders = Cabinet::listFolders(DOCUMENT_FOLDER, true); if (!empty($document_folders)) { $form->addSelect('document_folders', $document_folders); $form->addSubmit('document_force', dgettext('filecabinet', 'Put all checked documents here')); } $media_folders = Cabinet::listFolders(MULTIMEDIA_FOLDER, true); if (!empty($media_folders)) { $form->addSelect('media_folders', $media_folders); $form->addSubmit('media_force', dgettext('filecabinet', 'Put all checked media here')); } $options['classify'] = dgettext('filecabinet', '-- Pick option --'); $options['classify_file'] = dgettext('filecabinet', 'Classify checked'); $options['delete_incoming'] = dgettext('filecabinet', 'Delete checked'); $form->addSelect('process_checked', $options); $tpl = $form->getTemplate(); $js_vars['value'] = dgettext('filecabinet', 'Go'); $js_vars['select_id'] = 'classify_file_list_aop'; $js_vars['action_match'] = 'delete_incoming'; $js_vars['message'] = dgettext('filecabinet', 'Are you sure you wish to delete these files?'); $tpl['SUBMIT'] = javascript('select_confirm', $js_vars); $tpl['CHECK_ALL'] = javascript('check_all', array('checkbox_name' => 'file_list')); foreach ($result as $file) { $links = array(); $id = preg_replace('/\\W/', '-', $file); $rowtpl['FILE_NAME'] = sprintf('<label for="%s">%s</label>', $id, $file); $rowtpl['FILE_TYPE'] = PHPWS_File::getVbType($file); $vars['file'] = urlencode($file); if (!$this->cabinet->fileTypeAllowed($file)) { $rowtpl['ERROR'] = ' class="error"'; $rowtpl['MESSAGE'] = dgettext('filecabinet', 'File type not allowed'); } elseif (!PHPWS_File::checkMimeType($classify_dir . $file)) { if (!is_readable($classify_dir . $file)) { $rowtpl['ERROR'] = ' class="error"'; $rowtpl['MESSAGE'] = dgettext('filecabinet', 'File is unreadable'); } else { $rowtpl['ERROR'] = ' class="error"'; $rowtpl['MESSAGE'] = dgettext('filecabinet', 'Unknown or mismatched mime type'); } } else { $rowtpl['CHECK'] = sprintf('<input type="checkbox" id="%s" name="file_list[]" value="%s" />', $id, $file); $rowtpl['ERROR'] = $rowtpl['MESSAGE'] = null; $vars['aop'] = 'classify_file'; $links[] = PHPWS_Text::secureLink(dgettext('filecabinet', 'Classify'), 'filecabinet', $vars); } $vars['aop'] = 'delete_incoming'; $cnf_js['QUESTION'] = dgettext('filecabinet', 'Are you sure you want to delete this file?'); $cnf_js['ADDRESS'] = PHPWS_Text::linkAddress('filecabinet', $vars, true); $cnf_js['LINK'] = dgettext('filecabinet', 'Delete'); $links[] = javascript('confirm', $cnf_js); $rowtpl['ACTION'] = implode(' | ', $links); $tpl['file-list'][] = $rowtpl; } $tpl['FILENAME_LABEL'] = dgettext('filecabinet', 'File name'); $tpl['FILETYPE_LABEL'] = dgettext('filecabinet', 'File type'); $tpl['ACTION_LABEL'] = dgettext('filecabinet', 'Action'); $this->cabinet->content = PHPWS_Template::process($tpl, 'filecabinet', 'Forms/classify_list.tpl'); }