function folderPermissions($folder) { global $chmod, $f; $curdir = getcwd(); chdir($folder); $files = safe_glob('*.*'); chdir($curdir); foreach ($files as $file) { $path = $folder . '/' . $file; if (is_dir($path)) { if ($file != '.' && $file != '..') { @chmod($path, $chmod); clearstatcache(); if ((fileperms($path) & 0777) == $chmod) { if (!folderPermissions($path)) { return false; } } else { return false; } } } else { @chmod($path, 0666 & $chmod); clearstatcache(); if ((fileperms($path) & 0777) != (0666 & $chmod)) { return false; } } } return true; }
function getOptionsSupported() { global $_zp_gallery; $themename = $_zp_gallery->getCurrentTheme(); $curdir = getcwd(); $root = SERVERPATH . '/' . THEMEFOLDER . '/' . $themename . '/'; chdir($root); $filelist = safe_glob('*.php'); $list = array(); foreach ($filelist as $file) { $file = filesystemToInternal($file); $list[$file] = str_replace('.php', '', $file); } $list = array_diff($list, standardScripts()); $all = query_full_array('SELECT `aux` FROM ' . prefix('plugin_storage') . ' WHERE `type`="favorites"'); $disable = false; $text = gettext('If enabled a user may have multiple (named) favorites.'); foreach ($all as $aux) { $instance = getSerializedArray($aux['aux']); if (isset($instance[1])) { $disable = true; $text .= '<br /><span class="warningbox">' . gettext('Named favorites are present.') . '</span>'; break; } } $options = array(gettext('Link text') => array('key' => 'favorites_linktext', 'type' => OPTION_TYPE_TEXTBOX, 'multilingual' => true, 'order' => 2, 'desc' => gettext('The text for the link to the favorites page.')), gettext('Multiple sets') => array('key' => 'favorites_multi', 'type' => OPTION_TYPE_CHECKBOX, 'order' => 6, 'disabled' => $disable, 'desc' => $text), gettext('Add button') => array('key' => 'favorites_add_button', 'type' => OPTION_TYPE_TEXTBOX, 'multilingual' => true, 'order' => 6, 'desc' => gettext('Default text for the <em>add to favorites</em> button.')), gettext('Remove button') => array('key' => 'favorites_remove_button', 'type' => OPTION_TYPE_TEXTBOX, 'multilingual' => true, 'order' => 7, 'desc' => gettext('Default text for the <em>remove from favorites</em> button.')), gettext('Title') => array('key' => 'favorites_title', 'type' => OPTION_TYPE_TEXTBOX, 'multilingual' => true, 'order' => 3, 'desc' => gettext('The favorites page title text.')), gettext('Description') => array('key' => 'favorites_desc', 'type' => OPTION_TYPE_TEXTAREA, 'multilingual' => true, 'order' => 5, 'desc' => gettext('The favorites page description text.')), gettext('Sort albums by') => array('key' => 'favorites_albumsort', 'type' => OPTION_TYPE_CUSTOM, 'order' => 9, 'desc' => ''), gettext('Sort images by') => array('key' => 'favorites_imagesort', 'type' => OPTION_TYPE_CUSTOM, 'order' => 10, 'desc' => '')); if (!MOD_REWRITE) { $options['note'] = array('key' => 'favorites_note', 'type' => OPTION_TYPE_NOTE, 'order' => 0, 'desc' => gettext('<p class="notebox">Favorites requires the <code>mod_rewrite</code> option be enabled.</p>')); } return $options; }
static function getTileResources($type, $folder = NULL) { $curdir = getcwd(); $theme = basename(dirname(dirname(__FILE__))); $root = SERVERPATH . "/themes/{$theme}/tiles"; chdir($root); $filelist = safe_glob('*'); $list = array(); foreach ($filelist as $file) { if (is_dir($file) && $file != '.' && $file != '..') { $internal = filesystemToInternal($file); $filename = "{$root}/{$internal}/{$internal}.{$type}"; if (!file_exists($filename)) { continue; } $list[WEBPATH . "/themes/{$theme}/tiles/{$internal}/{$internal}.{$type}"] = $filename; } } $root = SERVERPATH . "/themes/{$theme}/{$folder}"; if (is_dir($root)) { chdir($root); $filelist = safe_glob("*.{$type}"); foreach ($filelist as $file) { $internal = filesystemToInternal($file); $list[WEBPATH . "/themes/{$theme}/{$folder}/{$internal}"] = SERVERPATH . "/themes/{$theme}/{$folder}/{$internal}"; } } chdir($curdir); return $list; }
/** * Handles the periodic start of the backup/restore utility to backup the database * @param string $discard */ static function timer_handler($discard) { global $_backupMutex; $_backupMutex->lock(); if (getOption('last_backup_run') + getOption('backup_interval') * 86400 < time()) { // maybe a race condition? Only need one execution $curdir = getcwd(); $folder = SERVERPATH . "/" . BACKUPFOLDER; if (!is_dir($folder)) { mkdir($folder, FOLDER_MOD); } chdir($folder); $filelist = safe_glob('*' . '.zdb'); $list = array(); foreach ($filelist as $file) { $list[$file] = filemtime($file); } chdir($curdir); asort($list); $list = array_flip($list); $keep = getOption('backups_to_keep'); while (!empty($list) && count($list) >= $keep) { $file = array_shift($list); @chmod(SERVERPATH . "/" . BACKUPFOLDER . '/' . $file, 0777); unlink(SERVERPATH . "/" . BACKUPFOLDER . '/' . $file); } cron_starter(SERVERPATH . '/' . ZENFOLDER . '/' . UTILITIES_FOLDER . '/backup_restore.php', array('backup' => 1, 'autobackup' => 1, 'compress' => sprintf('%u', getOption('backup_compression')), 'XSRFTag' => 'backup'), 3); setOption('last_backup_run', time()); } $_backupMutex->unlock(); return $discard; }
/** * Handles the periodic start of the backup/restore utility to backup the database * @param string $discard */ static function timer_handler($discard) { $curdir = getcwd(); $folder = SERVERPATH . "/" . BACKUPFOLDER; if (!is_dir($folder)) { mkdir($folder, FOLDER_MOD); } chdir($folder); $filelist = safe_glob('*' . '.zdb'); $list = array(); foreach ($filelist as $file) { $list[$file] = filemtime($file); } chdir($curdir); asort($list); $list = array_flip($list); $keep = getOption('backups_to_keep'); while (count($list) >= $keep) { $file = array_shift($list); @chmod(SERVERPATH . "/" . BACKUPFOLDER . '/' . $file, 0777); unlink(SERVERPATH . "/" . BACKUPFOLDER . '/' . $file); } cron_starter(SERVERPATH . '/' . ZENFOLDER . '/' . UTILITIES_FOLDER . '/backup_restore.php', array('backup' => 1, 'autobackup' => 1, 'compress' => sprintf('%u', getOption('backup_compression')), 'XSRFTag' => 'backup'), 3); return $discard; }
/** * A safe empowered glob(). * * Function glob() is prohibited on some server (probably in safe mode) * (Message "Warning: glob() has been disabled for security reasons in * (script) on line (line)") for security reasons as stated on: * http://seclists.org/fulldisclosure/2005/Sep/0001.html * * safe_glob() intends to replace glob() using readdir() & fnmatch() instead. * Supported flags: GLOB_MARK, GLOB_NOSORT, GLOB_ONLYDIR * Additional flags: GLOB_NODIR, GLOB_PATH, GLOB_NODOTS, GLOB_RECURSE * (not original glob() flags) * * @author BigueNique AT yahoo DOT ca * @updates * - 080324 Added support for additional flags: GLOB_NODIR, GLOB_PATH, * GLOB_NODOTS, GLOB_RECURSE */ function safe_glob($pattern, $flags = 0) { $split = explode('/', str_replace('\\', '/', $pattern)); $mask = array_pop($split); $path = implode('/', $split); if (($dir = @opendir($path)) !== false) { $glob = array(); while (($file = readdir($dir)) !== false) { // Recurse subdirectories (GLOB_RECURSE); speedup: no need to sort the intermediate results if ($flags & GLOB_RECURSE && is_dir($file) && !in_array($file, array('.', '..'))) { $glob = array_merge($glob, array_prepend(safe_glob($path . '/' . $file . '/' . $mask, $flags | GLOB_NOSORT), $flags & GLOB_PATH ? '' : $file . '/')); } // Match file mask if (fnmatch($mask, $file)) { if ((!($flags & GLOB_ONLYDIR) || is_dir($path . '/' . $file)) && (!($flags & GLOB_NODIR) || !is_dir($path . '/' . $file)) && (!($flags & GLOB_NODOTS) || !in_array($file, array('.', '..')))) { $glob[] = ($flags & GLOB_PATH ? $path . '/' : '') . $file . ($flags & GLOB_MARK && is_dir($path . '/' . $file) ? '/' : ''); } } } closedir($dir); if (!($flags & GLOB_NOSORT)) { sort($glob); } return $glob; } else { return false; } }
function gallerystats_filesize_r($path) { if (!file_exists($path)) { return 0; } if (is_file($path)) { return filesize($path); } $ret = 0; foreach (safe_glob($path . "/*") as $fn) { $ret += gallerystats_filesize_r($fn); } return $ret; }
/** * Reports the supported options * * @return array */ function getOptionsSupported() { $buttons = array(gettext('Allow') => 'allow', gettext('Block') => 'block'); $text = array_flip($buttons); $cwd = getcwd(); chdir(SERVERPATH . '/' . UPLOAD_FOLDER); $list = safe_glob('*.txt'); chdir($cwd); $files = array('' => ''); foreach ($list as $file) { $files[$file] = $file; } $options = array(gettext('IP list') => array('key' => 'ipBlocker_IP', 'type' => OPTION_TYPE_CUSTOM, 'order' => 5, 'desc' => sprintf(gettext('List of IP ranges to %s.'), $text[getOption('ipBlocker_type')])), gettext('Import list') => array('key' => 'ipBlocker_import', 'type' => OPTION_TYPE_SELECTOR, 'order' => 6, 'selections' => $files, 'nullselection' => '', 'disabled' => !extensionEnabled('ipBlocker'), 'desc' => sprintf(gettext('Import an external IP list. <p class="notebox"><strong>NOTE:</strong> If this list is large it may exceed the capacity of zenphoto and %s to process and store the results.'), DATABASE_SOFTWARE)), gettext('Action') => array('key' => 'ipBlocker_type', 'type' => OPTION_TYPE_RADIO, 'order' => 4, 'buttons' => $buttons, 'desc' => gettext('How the plugin will interpret the IP list.')), gettext('Logon threshold') => array('key' => 'ipBlocker_threshold', 'type' => OPTION_TYPE_NUMBER, 'order' => 1, 'desc' => gettext('Admin page requests will be ignored after this many failed tries.')), gettext('404 threshold') => array('key' => 'ipBlocker_404_threshold', 'type' => OPTION_TYPE_NUMBER, 'order' => 1, 'desc' => gettext('Access will be suspended after this many 404 errors.')), gettext('Cool off') => array('key' => 'ipBlocker_timeout', 'type' => OPTION_TYPE_NUMBER, 'order' => 3, 'desc' => gettext('The block will be removed after this many minutes.'))); if (!extensionEnabled('ipBlocker')) { $options['note'] = array('key' => 'ipBlocker_note', 'type' => OPTION_TYPE_NOTE, 'order' => 0, 'desc' => '<p class="notebox">' . gettext('IP list ranges cannot be managed with the plugin disabled') . '</p>'); } return $options; }
function getOptionsSupported() { global $_zp_gallery; $themename = $_zp_gallery->getCurrentTheme(); $curdir = getcwd(); $root = SERVERPATH . '/' . THEMEFOLDER . '/' . $themename . '/'; chdir($root); $filelist = safe_glob('*.php'); $list = array(); foreach ($filelist as $file) { $file = filesystemToInternal($file); $list[$file] = str_replace('.php', '', $file); } $list = array_diff($list, standardScripts()); $options = array(gettext('Link text') => array('key' => 'favorites_linktext', 'type' => OPTION_TYPE_TEXTBOX, 'multilingual' => true, 'order' => 2, 'desc' => gettext('The text for the link to the favorites page.')), gettext('Multiple sets') => array('key' => 'favorites_multi', 'type' => OPTION_TYPE_CHECKBOX, 'order' => 6, 'desc' => gettext('If enabled a user may have multiple (named) favorites.')), gettext('Add button') => array('key' => 'favorites_add_button', 'type' => OPTION_TYPE_TEXTBOX, 'multilingual' => true, 'order' => 6, 'desc' => gettext('Default text for the <em>add to favorites</em> button.')), gettext('Remove button') => array('key' => 'favorites_remove_button', 'type' => OPTION_TYPE_TEXTBOX, 'multilingual' => true, 'order' => 7, 'desc' => gettext('Default text for the <em>remove from favorites</em> button.')), gettext('Title') => array('key' => 'favorites_title', 'type' => OPTION_TYPE_TEXTBOX, 'multilingual' => true, 'order' => 3, 'desc' => gettext('The favorites page title text.')), gettext('Description') => array('key' => 'favorites_desc', 'type' => OPTION_TYPE_TEXTAREA, 'multilingual' => true, 'order' => 5, 'desc' => gettext('The favorites page description text.')), gettext('Sort albums by') => array('key' => 'favorites_albumsort', 'type' => OPTION_TYPE_CUSTOM, 'order' => 9, 'desc' => ''), gettext('Sort images by') => array('key' => 'favorites_imagesort', 'type' => OPTION_TYPE_CUSTOM, 'order' => 10, 'desc' => '')); if (!MOD_REWRITE) { $options['note'] = array('key' => 'favorites_note', 'type' => OPTION_TYPE_NOTE, 'order' => 0, 'desc' => gettext('<p class="notebox">Favorites requires the <code>mod_rewrite</code> option be enabled.</p>')); } return $options; }
function getOptionsSupported() { $gallery = new Gallery(); $opts = array(); $exclude = array('404.php', 'themeoptions.php', 'theme_description.php'); foreach (array_keys($gallery->getThemes()) as $theme) { $curdir = getcwd(); $root = SERVERPATH . '/' . THEMEFOLDER . '/' . $theme . '/'; chdir($root); $filelist = safe_glob('*.php'); $list = array(); foreach ($filelist as $file) { if (!in_array($file, $exclude)) { $list[$script = stripSuffix(filesystemToInternal($file))] = 'colorbox_' . $theme . '_' . $script; } } chdir($curdir); $opts[$theme] = array('key' => 'colorbox_' . $theme . '_scripts', 'type' => OPTION_TYPE_CHECKBOX_ARRAY, 'checkboxes' => $list, 'desc' => gettext('The scripts for which Colorbox is enabled. {Should have been set by the themes!}')); } return $opts; }
function getFolderList($root) { $curdir = getcwd(); chdir($root); $filelist = safe_glob('*'); $list = array(); foreach ($filelist as $file) { if (is_dir($file) && $file != '.' && $file != '..') { $internal = filesystemToInternal($file); if (!file_exists("{$root}/{$file}/persona.properties")) { continue; } $props = new Properties(); $props->load(file_get_contents("{$root}/{$file}/persona.properties")); $name = $props->getProperty('name'); if (!isset($name)) { continue; } $list[$name] = $internal; } } chdir($curdir); return $list; }
?> </td> <td> <select id="custom_index_page" name="custom_index_page"<?php echo $disable; ?> > <option value="" style="background-color:LightGray"><?php echo gettext('none'); ?> </option> <?php $curdir = getcwd(); $root = SERVERPATH . '/' . THEMEFOLDER . '/' . $themename . '/'; chdir($root); $filelist = safe_glob('*.php'); $list = array(); foreach ($filelist as $file) { $file = filesystemToInternal($file); $list[$file] = str_replace('.php', '', $file); } $list = array_diff($list, standardScripts()); generateListFromArray(array(getThemeOption('custom_index_page', $album, $themename)), $list, false, true); chdir($curdir); ?> </select> </td> <td><?php echo gettext("If this option is not empty, the Gallery Index URL that would normally link to the theme <code>index.php</code> script will instead link to this script. This frees up the <code>index.php</code> script so that you can create a customized <em>Home page</em> script. This option applies only to the main theme for the <em>Gallery</em>."); ?> </td>
} $zenphoto_tabs['options'] = array('text' => gettext("options"), 'link' => WEBPATH . "/" . ZENFOLDER . '/admin-options.php?page=options' . $optiondefault, 'subtabs' => $subtabs, 'default' => 'gallery'); } if ($_zp_loggedin & THEMES_RIGHTS) { $zenphoto_tabs['themes'] = array('text' => gettext("themes"), 'link' => WEBPATH . "/" . ZENFOLDER . '/admin-themes.php', 'subtabs' => NULL); } if ($_zp_loggedin & ADMIN_RIGHTS) { list($subtabs, $default) = getPluginTabs(); $zenphoto_tabs['plugins'] = array('text' => gettext("plugins"), 'link' => WEBPATH . "/" . ZENFOLDER . '/admin-plugins.php', 'subtabs' => $subtabs, 'default' => $default); } if ($_zp_loggedin & ADMIN_RIGHTS) { list($subtabs, $default, $new) = getLogTabs(); $zenphoto_tabs['logs'] = array('text' => gettext("logs"), 'link' => WEBPATH . "/" . ZENFOLDER . '/admin-logs.php?page=logs', 'subtabs' => $subtabs, 'alert' => $new, 'default' => $default); } if (!$_zp_current_admin_obj->getID()) { $filelist = safe_glob(SERVERPATH . "/" . BACKUPFOLDER . '/*.zdb'); if (count($filelist) > 0) { $zenphoto_tabs['restore'] = array('text' => gettext("Restore"), 'link' => WEBPATH . "/" . ZENFOLDER . '/utilities/backup_restore.php?page=backup', 'subtabs' => NULL); } } $zenphoto_tabs = zp_apply_filter('admin_tabs', $zenphoto_tabs); foreach ($zenphoto_tabs as $tab => $value) { if (is_null($value)) { unset($zenphoto_tabs[$tab]); } } // so as to make it generally available as we make much use of it if (OFFSET_PATH != 2) { require_once SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/colorbox_js.php'; } loadLocalOptions(false, $_zp_gallery->getCurrentTheme());
/** * returns URL to the original image or to a high quality alternate * e.g. ogg, avi, wmv files that can be handled by the client browser * * @param unknown_type $path */ function getFullImageURL() { // Search for a high quality version of the video if ($vid = parent::getFullImageURL()) { $folder = ALBUM_FOLDER_SERVERPATH . internalToFilesystem($this->album->getFileName()); $video = stripSuffix($this->filename); $curdir = getcwd(); chdir($folder); $candidates = safe_glob($video . '.*'); chdir($curdir); foreach ($candidates as $target) { $ext = getSuffix($target); if (in_array($ext, $this->videoalt)) { $vid = stripSuffix($vid) . '.' . substr(strrchr($target, "."), 1); } } } return $vid; }
chdir(dirname(__FILE__)); $persona = safe_glob('*', GLOB_ONLYDIR); chdir($cwd); $personalities = array(); foreach ($persona as $personality) { if (file_exists(SERVERPATH . '/' . THEMEFOLDER . '/effervescence_plus/' . $personality . '/functions.php')) { $personalities[ucfirst(str_replace('_', ' ', $personality))] = $personality; } } $personality = strtolower(getOption('effervescence_personality')); if (!in_array($personality, $personalities)) { $persona = $personalities; $personality = array_shift($persona); } chdir(SERVERPATH . "/themes/" . basename(dirname(__FILE__)) . "/styles"); $filelist = safe_glob('*.txt'); $themecolors = array(); foreach ($filelist as $file) { $themecolors[basename($file)] = stripSuffix(filesystemToInternal($file)); } chdir($cwd); if (!OFFSET_PATH) { if (extensionEnabled('themeSwitcher')) { $themeColor = getOption('themeSwitcher_effervescence_color'); if (isset($_GET['themeColor'])) { $new = $_GET['themeColor']; if (in_array($new, $themecolors)) { setOption('themeSwitcher_effervescence_color', $new); $themeColor = $new; } }
/** * control when and how setup scripts are turned back into PHP files * @param int reason * 1 No prior install signature * 2 restore setup files button * 4 Clone request * 5 Setup run with proper XSRF token * 6 checkSignature and no prior signature * 11 No config file * 12 No database specified * 13 No DB connection * 14 checkInstall Version has changed */ function restoreSetupScrpts($reason) { //log setup file restore no matter what! require_once SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/security-logger.php'; switch ($reason) { default: $addl = sprintf(gettext('to run setup [%s]'), $reason); break; case 2: $addl = gettext('by Admin request'); break; case 4: $addl = gettext('by cloning'); break; } $allowed = defined('ADMIN_RIGHTS') && zp_loggedin(ADMIN_RIGHTS) && zpFunctions::hasPrimaryScripts(); security_logger::log_setup($allowed, 'restore', $addl); if ($allowed) { if (!defined('FILE_MOD')) { define('FILE_MOD', 0666); } chdir(dirname(__FILE__) . '/setup/'); $found = safe_glob('*.xxx'); foreach ($found as $script) { chmod($script, 0777); if (@rename($script, stripSuffix($script) . '.php')) { chmod(stripSuffix($script) . '.php', FILE_MOD); } else { chmod($script, FILE_MOD); } } } }
/** * Rolls a log over if it has grown too large. * * @param string $log */ function switchLog($log) { $dir = getcwd(); chdir(SERVERPATH . '/' . DATA_FOLDER); $list = safe_glob($log . '-*.log'); if (empty($list)) { $counter = 1; } else { sort($list); $last = array_pop($list); preg_match('|' . $log . '-(.*).log|', $last, $matches); $counter = $matches[1] + 1; } chdir($dir); @copy(SERVERPATH . '/' . DATA_FOLDER . '/' . $log . '.log', SERVERPATH . '/' . DATA_FOLDER . '/' . $log . '-' . $counter . '.log'); if (getOption($log . '_log_mail')) { zp_mail(sprintf(gettext('%s log size limit exceeded'), $log), sprintf(gettext('The %1$s log has exceeded its size limit and has been renamed to %2$s.'), $log, $log . '-' . $counter . '.log')); } }
<?php zp_apply_filter('admin_overview', 'left'); } ?> <br clear="all" /> </div><!-- overview leftcolumn end --> <div id="overview-rightcolumn"> <?php if (zp_loggedin(OVERVIEW_RIGHTS)) { $buttonlist = array(); $curdir = getcwd(); chdir(SERVERPATH . "/" . ZENFOLDER . '/' . UTILITIES_FOLDER . '/'); $filelist = safe_glob('*' . 'php'); natcasesort($filelist); foreach ($filelist as $utility) { $button_text = ''; $button_hint = ''; $button_icon = ''; $button_alt = ''; $button_hidden = ''; $button_action = UTILITIES_FOLDER . '/' . $utility; $button_rights = false; $button_enable = true; $button_XSRFTag = ''; $utilityStream = file_get_contents($utility); eval(isolate('$button_text', $utilityStream)); eval(isolate('$button_hint', $utilityStream)); eval(isolate('$button_icon', $utilityStream));
/** * returns an array of the theme scripts not in the exclude array * @param array $exclude those scripts to ignore * @return array */ function getThemeFiles($exclude) { global $_zp_gallery; $files = array(); foreach (array_keys($_zp_gallery->getThemes()) as $theme) { $curdir = getcwd(); $root = SERVERPATH . '/' . THEMEFOLDER . '/' . $theme . '/'; chdir($root); $filelist = safe_glob('*.php'); $list = array(); foreach ($filelist as $file) { if (!in_array($file, $exclude)) { $files[$theme][] = filesystemToInternal($file); } } chdir($curdir); } return $files; }
static function getPersonaIconList($persona) { $list = array(); if (!isset($persona) || trim($persona) == '') { return $list; } $theme = $theme = basename(dirname(dirname(__FILE__))); $root = SERVERPATH . "/themes/{$theme}/personality/{$persona}/icons"; $curdir = getcwd(); chdir($root); $filelist = safe_glob('*.png'); foreach ($filelist as $file) { $internal = filesystemToInternal($file); $list[] = $internal; } chdir($curdir); return $list; }
function processPlugins() { global $_zp_current_admin_obj; $curdir = getcwd(); $basepath = SERVERPATH . "/" . ZENFOLDER . '/' . PLUGIN_FOLDER . '/'; chdir($basepath); $filelist = safe_glob('*.php'); foreach ($filelist as $file) { $titlelink = stripSuffix(filesystemToInternal($file)); $author = stripSuffix(basename(__FILE__)); $sql = 'SELECT `id` FROM ' . prefix('news') . ' WHERE `titlelink`=' . db_quote($titlelink); $result = query_single_row($sql); if (empty($result)) { $plugin_news = new ZenpageNews($titlelink); $fp = fopen($basepath . $file, 'r'); $empty = true; $desc = '<p>'; $tags = array($titlelink); $incomment = false; while ($line = fgets($fp)) { if (strpos($line, '/*') !== false) { $incomment = true; } if ($incomment) { if (strpos($line, '*/') !== false) { break; } $i = strpos($line, '*'); $line = trim(trim(substr($line, $i + 1), '*')); if (empty($line)) { if (!$empty) { $desc .= '<p>'; } $empty = true; } else { if (strpos($line, '@') === 0) { $line = trim($line, '@'); $i = strpos($line, ' '); $mod = substr($line, 0, $i); $line = trim(substr($line, $i + 1)); switch ($mod) { case 'author': $desc .= 'Author: ' . html_encode($line) . ' '; $empty = false; preg_match_all('|\\((.+?)\\)|', $line, $matches); $tags = array_merge($tags, $matches[1]); $author = array_shift($matches[1]); break; case 'package': case 'subpackage': $tags[] = $line; break; case 'tags': $pluginTags = explode(',', $line); foreach ($pluginTags as $tag) { $tags[] = trim(unQuote($tag)); } break; } } else { $desc .= html_encode($line) . ' '; $empty = false; } } } } $desc .= '</p>'; fclose($fp); $plugin_news->setShow(0); $plugin_news->setDateTime(date('Y-m-d H:i:s'), filemtime($file)); $plugin_news->setAuthor($author); $plugin_news->setTitle($titlelink); $plugin_news->setContent($desc); $plugin_news->setTags($tags); $plugin_news->setCategories(array('officially-supported', 'extensions')); $plugin_news->setCustomData("http://www.zenphoto.org/documentation/plugins/_" . PLUGIN_FOLDER . "---" . $titlelink . ".html"); $plugin_news->save(); } } chdir($curdir); }
/** * Gets the css files for a skin. Helper function for getjPlayerSkins(). * */ function getjPlayerSkinCSS($skins, $dir) { $skin_css = array(); foreach ($skins as $skin) { $css = safe_glob($dir . $skin . '/*.css'); if ($css) { $skin_css = array_merge($skin_css, array($skin => $skin)); // a skin should only have one css file so we just use the first found } } return $skin_css; }
<?php // force UTF-8 Ø require_once SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/image_album_statistics.php'; zp_register_filter('themeSwitcher_head', 'switcher_head'); zp_register_filter('themeSwitcher_Controllink', 'switcher_controllink'); zp_register_filter('load_theme_script', 'fourOhFour'); $cwd = getcwd(); chdir(dirname(__FILE__)); $persona = safe_glob('*', GLOB_ONLYDIR); chdir($cwd); $persona = array_diff($persona, array('images', 'contact_form')); $personalities = array(); foreach ($persona as $personality) { $personalities[ucfirst(str_replace('_', ' ', $personality))] = $personality; } if (!OFFSET_PATH) { if (extensionEnabled('themeSwitcher')) { $personality = getOption('themeSwitcher_garland_personality'); if (isset($_GET['themePersonality'])) { $new = $_GET['themePersonality']; if (in_array($new, $personalities)) { setOption('themeSwitcher_garland_personality', $new); $personality = $new; } } if ($personality) { setOption('garland_personality', $personality, false); } else { $personality = strtolower(getOption('garland_personality')); }
/** * Print the JS configuration of flowplayer * * @param string $moviepath the direct path of a movie (within the slideshow), if empty (within albums) * the zenphoto function getUnprotectedImageURL() is used * * @param string $imagetitle the filename of the movie * */ function getPlayerConfig($moviepath = '', $imagetitle = '', $count = '', $width = NULL, $height = NULL) { global $_zp_current_image; $playerwidth = getOption('flow_player3_width'); $playerheight = getOption('flow_player3_height'); if (empty($moviepath)) { $moviepath = getUnprotectedImageURL(); $ext = strtolower(strrchr(getUnprotectedImageURL(), ".")); } else { $moviepath = $moviepath; $ext = strtolower(strrchr($moviepath, ".")); } if (!empty($count)) { $count = "-" . $count; } $imgextensions = array(".jpg", ".jpeg", ".gif", ".png"); $videoThumbImg = ''; if (is_null($_zp_current_image)) { $albumfolder = $moviepath; $filename = $imagetitle; $videoThumb = ''; } else { $album = $_zp_current_image->getAlbum(); $albumfolder = $album->name; $filename = $_zp_current_image->filename; $splashimagerwidth = $playerwidth; $splashimageheight = $playerheight; getMaxSpaceContainer($splashimagerwidth, $splashimageheight, $_zp_current_image, true); $videoThumb = $_zp_current_image->getCustomImage(null, $splashimagerwidth, $splashimageheight, null, null, null, null, true); if (getOption('flow_player3_splashimage')) { $videoThumbImg = '<img src="' . pathurlencode($videoThumb) . '" alt="" />'; } } if (getOption("flow_player3_autoplay") == 1) { $autoplay = "true"; } else { $autoplay = "false"; } if ($ext == ".mp3") { if (getOption('flow_player3_mp3coverimage')) { if (is_null($height)) { $height = $playerheight; } } else { if (is_null($height)) { $height = FLOW_PLAYER_MP3_HEIGHT; } $videoThumbImg = ''; $videoThumb = ''; } $allowfullscreen = 'false'; } else { if (is_null($height)) { $height = $playerheight; } $allowfullscreen = 'true'; } if (is_null($width)) { $width = $this->getVideoWidth(); } if (is_null($width)) { $width = $playerwidth; } // inline css is kind of ugly but since we need to style dynamically there is no other way $curdir = getcwd(); chdir(SERVERPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/flowplayer3'); $filelist = safe_glob('flowplayer-*.swf'); $swf = array_shift($filelist); $filelist = safe_glob('flowplayer.audio-*.swf'); $audio = array_shift($filelist); $filelist = safe_glob('flowplayer.controls-*.swf'); $controls = array_shift($filelist); chdir($curdir); $playerconfig = ' <span id="player' . $count . '" class="flowplayer" style="display:block; width: ' . $width . 'px; height: ' . $height . 'px"> ' . $videoThumbImg . ' </span> <script type="text/javascript"> // <!-- <![CDATA[ flowplayer("player' . $count . '","' . WEBPATH . '/' . ZENFOLDER . '/' . PLUGIN_FOLDER . '/flowplayer3/' . $swf . '", { plugins: { audio: { url: "' . $audio . '" }, controls: { url: "' . $controls . '", backgroundColor: "' . getOption('flow_player3_controlsbackgroundcolor') . '", backgroundGradient: "' . getOption('flow_player3_controlsbackgroundcolorgradient') . '", autoHide: "' . getOption('flow_player3_controlsautohide') . '", timeColor:"' . getOption('flow_player3_controlstimecolor') . '", durationColor: "' . getOption('flow_player3_controlsdurationcolor') . '", progressColor: "' . getOption('flow_player3_controlsprogresscolor') . '", progressGradient: "' . getOption('flow_player3_controlsprogressgradient') . '", bufferColor: "' . getOption('flow_player3_controlsbuffercolor') . '", bufferGradient: "' . getOption('flow_player3_controlsbuffergradient') . '", sliderColor: "' . getOption('flow_player3_controlsslidercolor') . '", sliderGradient: "' . getOption('flow_player3_controlsslidergradient') . '", buttonColor: "' . getOption('flow_player3_controlsbuttoncolor') . '", buttonOverColor: "' . getOption('flow_player3_controlsbuttonovercolor') . '", fullscreen : ' . $allowfullscreen . ' } }, canvas: { backgroundColor: "' . getOption('flow_player3_backgroundcolor') . '", backgroundGradient: "' . getOption('flow_player3_backgroundcolorgradient') . '" },'; $playerconfigadd = 'clip: { url:"' . pathurlencode($moviepath) . '", autoPlay: ' . $autoplay . ', autoBuffering: ' . $autoplay . ', scaling: "' . getOption('flow_player3_scaling') . '"'; if ($ext == ".mp3" && getOption('flow_player3_mp3coverimage')) { $playerconfigadd .= ', coverImage: { url:"' . urlencode($videoThumb) . '", scaling: "' . getOption('flow_player3_scaling') . '" } '; } $playerconfigadd .= ' } }); // ]]> --> </script>'; $playerconfig = $playerconfig . $playerconfigadd; return $playerconfig; }
/** * Worker function for creating layout selectors. Returns the HTML * * @param object $obj * @param string $type * @param string $text * @param string$secondary */ function getLayoutSelector($obj, $type, $text, $prefix = '', $secondary = false) { global $_zp_gallery; $selectdefault = ''; $selected = ''; $files = array(); $list = array(); $getlayout = ''; $table = $obj->table; $path = SERVERPATH . '/' . THEMEFOLDER . '/' . $_zp_gallery->getCurrentTheme() . '/'; $defaultlayout = ''; $defaulttext = gettext('default'); switch ($table) { case 'albums': if ($secondary) { // the selector for the image default of the album $filesmask = 'image'; } else { $filesmask = 'album'; } $child = $obj->getParentID(); $defaulttext = gettext('inherited'); break; case 'images': $filesmask = 'image'; $album = $obj->album; $child = $album->getID(); $defaulttext = gettext('album default'); break; case 'pages': $filesmask = 'pages'; $child = $obj->getParentID(); $defaulttext = gettext('inherited'); break; case 'news': $child = false; $categories = $obj->getCategories(); if ($categories) { foreach ($categories as $cat) { $cat = new ZenpageCategory($cat['titlelink']); $getlayout = getSelectedLayout($cat, 'multiple_layouts_news_categories'); if ($getlayout && $getlayout['data']) { // in at least one news category with an alternate page $defaulttext = gettext('inherited'); $defaultlayout = gettext('from category'); break; } } } $filesmask = 'news'; break; case 'news_categories': $child = $obj->getParentID(); $defaulttext = gettext('inherited'); $filesmask = 'news'; break; } $curdir = getcwd(); chdir($path); $files = safe_glob($filesmask . '*.php'); chdir($curdir); if ($child) { $defaultlayout = checkParentLayouts($obj, $type); $defaultlayout = $defaultlayout['data']; } if ($defaultlayout) { $defaultlayout = stripSuffix($defaultlayout); } else { $defaultlayout = $filesmask; } if ($obj->transient) { $getlayout = false; } else { $getlayout = query_single_row("SELECT * FROM " . prefix('plugin_storage') . ' WHERE `aux` = ' . $obj->getID() . ' AND `type` = "' . $type . '"'); } if (!$child && ($key = array_search($filesmask . '.php', $files)) !== false) { unset($files[$key]); } foreach ($files as $file) { $file = filesystemToInternal($file); $list[stripSuffix($file)] = $file; } ksort($list); $html = $text; if (count($files) != 0) { $html .= '<select id="' . $type . $prefix . '" name="' . $prefix . $type . '">' . "\n"; if (is_array($getlayout)) { $selectedlayout = $getlayout['data']; } else { $selectedlayout = ''; } $html .= '<option value=""' . ($selectedlayout == '' ? ' selected="selected"' : '') . ' style="background-color:LightGray" >*' . $defaulttext . '* (' . $defaultlayout . ')</option>' . "\n"; foreach ($list as $display => $file) { $html .= '<option value="' . html_encode($file) . '"' . ($selectedlayout == $file ? ' selected="selected"' : '') . '>' . $display . '</option>' . "\n"; } $html .= '</select>' . "\n"; } else { $html = '<p class="no_extra">' . sprintf(gettext('No extra <em>%s</em> theme pages available'), $filesmask) . '</p>' . "\n"; } return $html; }
/** * Generates a selection list from files found on disk * * @param strig $currentValue the current value of the selector * @param string $root directory path to search * @param string $suffix suffix to select for * @param bool $descending set true to get a reverse order sort */ function generateListFromFiles($currentValue, $root, $suffix, $descending = false) { if (is_dir($root)) { $curdir = getcwd(); chdir($root); $filelist = safe_glob('*' . $suffix); $list = array(); foreach ($filelist as $file) { $file = str_replace($suffix, '', $file); $list[] = filesystemToInternal($file); } generateListFromArray(array($currentValue), $list, $descending, false); chdir($curdir); } }
function stdapi_fs_search($req, &$pkt) { my_print("doing search"); $root_tlv = packet_get_tlv($req, TLV_TYPE_SEARCH_ROOT); $root = cononicalize_path($root_tlv['value']); $glob_tlv = packet_get_tlv($req, TLV_TYPE_SEARCH_GLOB); $glob = cononicalize_path($glob_tlv['value']); $recurse_tlv = packet_get_tlv($req, TLV_TYPE_SEARCH_RECURSE); $recurse = $recurse_tlv['value']; if (!$root) { $root = '.'; } my_print("glob: {$glob}, root: {$root}, recurse: {$recurse}"); $flags = GLOB_PATH; if ($recurse) { $flags |= GLOB_RECURSE; } $files = safe_glob($root . "/" . $glob, $flags); if ($files and is_array($files)) { dump_array($files); foreach ($files as $file) { $file_tlvs = ""; $s = stat($file); $p = dirname($file); $f = basename($file); $file_tlvs .= tlv_pack(create_tlv(TLV_TYPE_FILE_PATH, $p)); $file_tlvs .= tlv_pack(create_tlv(TLV_TYPE_FILE_NAME, $f)); $file_tlvs .= tlv_pack(create_tlv(TLV_TYPE_FILE_SIZE, $s['size'])); packet_add_tlv($pkt, create_tlv(TLV_TYPE_SEARCH_RESULTS, $file_tlvs)); } } return ERROR_SUCCESS; }
/** * Returns a list of available fonts * * @return array */ function zp_getFonts() { global $_gd_fontlist; if (!is_array($_gd_fontlist)) { $_gd_fontlist = array('system' => ''); $curdir = getcwd(); $basefile = SERVERPATH . '/' . USER_PLUGIN_FOLDER . 'gd_fonts/'; if (is_dir($basefile)) { chdir($basefile); $filelist = safe_glob('*.gdf'); foreach ($filelist as $file) { $key = filesystemToInternal(str_replace('.gdf', '', $file)); $_gd_fontlist[$key] = $basefile . '/' . $file; } } chdir($basefile = SERVERPATH . '/' . ZENFOLDER . '/gd_fonts'); $filelist = safe_glob('*.gdf'); foreach ($filelist as $file) { $key = filesystemToInternal(preg_replace('/\\.gdf/i', '', $file)); $_gd_fontlist[$key] = $basefile . '/' . $file; } if (GD_FREETYPE) { $basefile = rtrim(getOption('GD_FreeType_Path') . '/'); if (is_dir($basefile)) { chdir($basefile); $filelist = safe_glob('*.ttf'); foreach ($filelist as $file) { $key = filesystemToInternal($file); $_gd_fontlist[$key] = $basefile . '/' . $file; } } } chdir($curdir); } return $_gd_fontlist; }
/** * Delete the entire album PERMANENTLY. Be careful! This is unrecoverable. * Returns true if successful * * @return bool */ function remove() { $rslt = false; if (PersistentObject::remove()) { foreach ($this->getImages() as $filename) { $image = newImage($this, $filename); $image->remove(); } foreach ($this->getAlbums() as $folder) { $subalbum = newAlbum($folder); $subalbum->remove(); } $curdir = getcwd(); chdir($this->localpath); $filelist = safe_glob('*'); foreach ($filelist as $file) { if ($file != '.' && $file != '..') { @chmod($file, 0777); unlink($this->localpath . $file); // clean out any other files in the folder } } chdir($curdir); clearstatcache(); query("DELETE FROM " . prefix('options') . "WHERE `ownerid`=" . $this->id); query("DELETE FROM " . prefix('comments') . "WHERE `type`='albums' AND `ownerid`=" . $this->id); query("DELETE FROM " . prefix('obj_to_tag') . "WHERE `type`='albums' AND `objectid`=" . $this->id); $success = true; $filestoremove = safe_glob(substr($this->localpath, 0, strrpos($this->localpath, '.')) . '.*'); foreach ($filestoremove as $file) { if (in_array(strtolower(getSuffix($file)), $this->sidecars)) { @chmod($file, 0777); $success = $success && unlink($file); } } @chmod($this->localpath, 0777); $rslt = @rmdir($this->localpath) && $success; $cachepath = SERVERCACHE . '/' . pathurlencode($this->name) . '/'; @chmod($cachepath, 0777); @rmdir($cachepath); } clearstatcache(); return $rslt; }
/** * Returns a list of available fonts * * @return array */ function zp_getFonts() { global $_imagick_fontlist; if (!is_array($_imagick_fontlist)) { @($_imagick_fontlist = Imagick::queryFonts()); $_imagick_fontlist = array('system' => '') + array_combine($_imagick_fontlist, $_imagick_fontlist); $basefile = SERVERPATH . '/' . USER_PLUGIN_FOLDER . '/imagick_fonts/'; if (is_dir($basefile)) { chdir($basefile); $filelist = safe_glob('*.ttf'); foreach ($filelist as $file) { $key = filesystemToInternal(str_replace('.ttf', '', $file)); $_imagick_fontlist[$key] = getcwd() . '/' . $file; } } chdir(dirname(__FILE__)); } return $_imagick_fontlist; }