function isImgCached($file) { if (!USE_CACHE) { return false; } if ($file == 'auto') { $file = GenImgName(); // imported from jpgraph.php } $filename = catfile(CACHE_DIR, $file); if (file_exists($filename)) { if (CACHE_TIMEOUT == 0) { return true; } $diff = time() - filemtime($filename); return $diff < CACHE_TIMEOUT * 60; } return false; }
function flagimg($cc, $args = array()) { $args += array('alt' => NULL, 'height' => NULL, 'width' => NULL, 'path' => '', 'noimg' => '', 'urlonly' => false, 'style' => '', 'class' => '', 'id' => '', 'extra' => ''); if (empty($cc)) { return ''; } $cc = strtolower($cc); $path = !empty($args['path']) ? $args['path'] : ''; $basedir = catfile($this->conf['theme']['flags_dir'], $path); $baseurl = catfile($this->conf['theme']['flags_url'], $path); $alt = ps_escape_html($args['alt'] !== NULL ? $args['alt'] : $cc); $label = $alt; $ext = array_map('trim', explode(',', str_replace('.', '', $this->conf['theme']['images']['search_ext']))); $name = rawurlencode($cc); $img = ""; $file = ""; $url = ""; foreach ($ext as $e) { $file = catfile($basedir, $cc) . '.' . $e; $url = catfile($baseurl, $name) . '.' . $e; if (@file_exists($file)) { break; } $file = ""; } if (!@file_exists($file)) { // we're done... return $args['noimg'] !== NULL ? $args['noimg'] : $label; } if ($args['urlonly']) { return $url; } $attrs = ""; if (is_numeric($args['width'])) { $attrs .= " width='" . $args['width'] . "'"; } if (is_numeric($args['height'])) { $attrs .= " height='" . $args['height'] . "'"; } if (!empty($args['style'])) { $attrs .= " style='" . $args['style'] . "'"; } if (!empty($args['class'])) { $attrs .= " class='" . $args['class'] . "'"; } if (!empty($args['id'])) { $attrs .= " id='" . $args['id'] . "'"; } if (!empty($args['extra'])) { $attrs .= " " . $args['extra']; } $img = "<img src='{$url}' title='{$label}' alt='{$alt}'{$attrs} />"; return $img; }
function _smarty_include($params) { $params['smarty_include_tpl_file'] = catfile($this->theme, $params['smarty_include_tpl_file']); /// if ($this->debugging) { $_params = array(); require_once SMARTY_CORE_DIR . 'core.get_microtime.php'; $debug_start_time = smarty_core_get_microtime($_params, $this); $this->_smarty_debug_info[] = array('type' => 'template', 'filename' => $params['smarty_include_tpl_file'], 'depth' => ++$this->_inclusion_depth); $included_tpls_idx = count($this->_smarty_debug_info) - 1; } $this->_tpl_vars = array_merge($this->_tpl_vars, $params['smarty_include_vars']); // config vars are treated as local, so push a copy of the // current ones onto the front of the stack array_unshift($this->_config, $this->_config[0]); $_smarty_compile_path = $this->_get_compile_path($params['smarty_include_tpl_file']); if ($this->_is_compiled($params['smarty_include_tpl_file'], $_smarty_compile_path) || $this->_compile_resource($params['smarty_include_tpl_file'], $_smarty_compile_path)) { if ($this->fetch_compile) { /// include $_smarty_compile_path; } else { /// ob_start(); $this->_eval('?>' . $this->_last_compiled); $_contents = ob_get_contents(); ob_end_clean(); print $_contents; } } // pop the local vars off the front of the stack array_shift($this->_config); $this->_inclusion_depth--; if ($this->debugging) { // capture time for debugging info $_params = array(); require_once SMARTY_CORE_DIR . 'core.get_microtime.php'; $this->_smarty_debug_info[$included_tpls_idx]['exec_time'] = smarty_core_get_microtime($_params, $this) - $debug_start_time; } if ($this->caching) { $this->_cache_info['template'][$params['smarty_include_tpl_file']] = true; } }
* * Version: $Id: common.php 539 2008-08-15 19:24:26Z lifo $ */ if (!defined("PSYCHOSTATS_ADMIN_PAGE")) { die("Unauthorized access to " . basename(__FILE__)); } // ADMIN pages need to setup the theme a little differently than the others $opts = array('theme_default' => 'acp', 'theme_opt' => 'admin_theme', 'force_theme' => true, 'in_db' => false, 'template_dir' => dirname(__FILE__) . '/themes', 'theme_url' => 'themes', 'compile_id' => 'admin'); $opts = array_merge($ps->conf['theme'], $opts); // At all costs the admin page should never break due to file permissions. If // the compile directory is not writable we fallback to not saving compiled // themes to disk which is slower. But shouldn't be a big problem since only a // single person is usually accessing the admin page. if ($opts['fetch_compile'] and !is_writable($opts['compile_dir'])) { $opts['fetch_compile'] = false; } $cms->init_theme('acp', $opts); $ps->theme_setup($cms->theme); $cms->crumb('Stats', dirname(dirname(SAFE_PHP_SELF)) . '/'); $cms->crumb('Admin', 'index.php'); $file = basename(PHP_SELF, '.php'); if (!$cms->user->admin_logged_in()) { if (!defined("PSYCHOSTATS_LOGIN_PAGE")) { gotopage(ps_url_wrapper(array('_base' => dirname($_SERVER['SCRIPT_NAME']) . '/login.php', '_ref' => $_SERVER['REQUEST_URI']))); } } // Set flag if the install directory (go script) is still readable by the // webserver. Admins need to remove the install directory after installation. if (is_readable(catfile(dirname(dirname(__FILE__)), 'install', 'go.php'))) { $cms->theme->assign(array('install_dir_insecure' => true, 'install_dir' => catfile(dirname(dirname(__FILE__)), 'install'))); }
// make sure each file exists and update the newest timestamp $len = strlen($root); $file = realpath($root . '/' . $sources[$i]); // Only allow files within the template directory. Avoids exploiting // other files like ../../../etc/passwd if (substr($file, 0, $len) == $root and @file_exists($file)) { $files[] = $file; $lastupdate = max($lastupdate, filemtime($file)); } else { $missing[] = $sources[$i]; } } // create a resource name for this set of files. This mimics the way // Smarty creates a compiled file. $hex = sprintf('%8X', $lastupdate ? $lastupdate : time()); $compiled_file = catfile($cms->theme->compile_dir, $cms->theme->theme() . '-' . $cms->theme->language() . '-' . $cms->theme->compile_id . '^%%' . substr($hex, 0, 2) . '^' . substr($hex, 0, 3) . '^' . $hex . '%%' . md5(implode('', $sources)) . '.js'); $is_compiled = file_exists($compiled_file); // Check and see if the client has the text cached. // This only works on apache servers. if ($is_compiled and function_exists('apache_request_headers')) { $headers = apache_request_headers(); $if_modified_since = preg_replace('/;.*$/', '', $headers['If-Modified-Since']); if ($if_modified_since) { $gmtime = gmdate("D, d M Y H:i:s", $lastupdate) . " GMT"; if ($if_modified_since == $gmtime) { header("HTTP/1.1 304 Not Modified", true); exit; } } } // the client does not have the file cached... so we output it below ...
if (!in_array($t, array('csv', 'xml', 'dom', 'img'))) { $t = 'img'; } $list = array(); // first build a list of icons from our local directory $dir = $ps->conf['theme']['icons_dir']; $url = $ps->conf['theme']['icons_url']; if ($dh = @opendir($dir)) { while (($file = @readdir($dh)) !== false) { if (substr($file, 0, 1) == '.') { continue; } // skip dot files $fullfile = catfile($dir, $file); if (is_dir($fullfile)) { continue; } // skip directories if (is_link($fullfile)) { continue; } // skip symlinks $info = getimagesize($fullfile); $size = @filesize($fullfile); $list[$file] = array('filename' => rawurlencode($file), 'url' => catfile($url, rawurlencode($file)), 'desc' => ps_escape_html(sprintf("%s - %dx%d - %s", $file, $info[0], $info[1], abbrnum($size))), 'size' => $size, 'width' => $info[0], 'height' => $info[1], 'attr' => $info[3]); } @closedir($dh); } ksort($list); $fields = array('filename', 'url', 'size', 'width', 'height'); output_list($t, $list, $fields, $idstr);
$list = explode(',', $ext); $list = array_map('trim', $list); $match = '\\.(' . implode('|', $list) . ')$'; $dir = $ps->conf['theme']['icons_dir']; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if (substr($file, 0, 1) == '.') { continue; } // ignore dot and hidden files if (!preg_match("/{$match}/", $file)) { continue; } // ignore files not matching the search_ext $full = catfile($dir, $file); $icons[] = array('filename' => $file, 'fullfile' => $full, 'size' => @filesize($full), 'is_writable' => is_writable($full) || is_writable(dirname($full)), 'basename' => basename($file), 'path' => $dir); } closedir($dh); } } if (!is_writable($dir)) { $msg_not_writable = $cms->message('not_writable', array('message_title' => $cms->trans("Permissions Error!"), 'message' => $cms->trans("The icons directory is not writable.") . ' ' . $cms->trans("You can not upload any new icons until the permissions are corrected."))); } $cms->crumb('Manage', ps_url_wrapper(array('_base' => 'manage.php'))); $cms->crumb('Icon Avatars', ps_url_wrapper(array('_base' => 'icons.php'))); // assign variables to the theme $cms->theme->assign(array('page' => basename(__FILE__, '.php'), 'icons' => $icons, 'message' => $message, 'icons_url' => $ps->conf['theme']['icons_url'], 'form' => $form ? $form->values() : array(), 'errors' => $form ? $form->errors() : array())); // display the output $basename = basename(__FILE__, '.php'); $cms->theme->add_css('css/2column.css');
} $allow_next = true; $ajax_request = !empty($a) ? true : false; // verify our install key still matches this session // if the install key from the form does not match what is in the option cookie // then we know the user either opened a second install page, or went back // to the install index, which destroyed the previous cookie (and the DB settings) if ($install != $opts['install']) { if ($ajax_request) { print "<script type='text/javascript'>window.location = 'index.php?re=1';</script>"; exit; } else { gotopage("index.php?re=1"); } } $pagename = basename(__FILE__, '.php'); $cms->theme->add_css('css/2column.css'); $cms->theme->add_js("js/go.js"); $cms->theme->add_js("js/go-{$s}.js"); $cms->theme->assign_by_ref('allow_next', $allow_next); $cms->theme->assign_by_ref('dbhost', $dbhost); $cms->theme->assign_by_ref('dbport', $dbport); $cms->theme->assign_by_ref('dbname', $dbname); $cms->theme->assign_by_ref('dbuser', $dbuser); $cms->theme->assign_by_ref('dbpass', $dbpass); $cms->theme->assign_by_ref('dbtblprefix', $dbtblprefix); $cms->theme->assign(array('step' => $s, 'db_connected' => $db->connected, 'is_windows' => strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')); // allow custom code to handle our current progress/event include catfile(dirname(__FILE__), "go-{$s}.php"); // display the output $cms->full_page($pagename, $pagename, $pagename . '_header', $pagename . '_footer');
function skill_change($args = array()) { global $cms, $ps; if (!is_array($args)) { $args['plr'] = array('plr' => $args); } $args += array('plr' => NULL, 'skill' => 0, 'prevskill' => 0, 'imgfmt' => "skill_%s.png", 'difffmt' => "%.02f", 'attr' => "", 'acronym' => true, 'textonly' => false); $output = ""; $skill = $prevskill = 0; if (is_array($args['plr'])) { $skill = $args['plr']['skill']; $prevskill = $args['plr']['prevskill']; } else { $skill = $args['skill']; $prevskill = $args['prevskill']; } $alt = $cms->trans("no change"); $dir = "same"; $diff = sprintf($args['difffmt'], $skill - $prevskill); if ($prevskill == 0) { # no change } elseif ($diff > 0) { $dir = "up"; $alt = $cms->trans("Diff") . ": +{$diff}"; } elseif ($diff < 0) { $dir = "down"; $alt = $cms->trans("Diff") . ": {$diff}"; } if ($args['textonly']) { $output = sprintf("<span class='skillchange-{$dir}'>%s%s</span>", $diff > 0 ? '+' : '', $prevskill == 0 ? '' : $diff); } else { $img = '/img/icons/' . sprintf($args['imgfmt'], $dir); $path = catfile($ps->conf['theme']['template_dir'], $cms->theme->theme(), $img); if (!@file_exists($path) and $cms->theme->is_child()) { $img = $cms->theme->url($cms->theme->is_child()) . $img; } else { $img = $cms->theme->url() . $img; } $output = sprintf("<img src='%s' alt='%s' title='%s' %s/>", $img, $alt, $alt, $args['attr']); # if ($args['acronym']) { # $output = "<acronym title='$alt'>$output</acronym>"; # } $output = "<span class='skillchange-{$dir}'>{$output}</span>"; } return $output; }
$dir = $ps->conf['theme']['flags_dir']; $url = $ps->conf['theme']['flags_url']; if ($dh = @opendir($dir)) { while (($file = @readdir($dh)) !== false) { if (substr($file, 0, 1) == '.') { continue; } // skip dot files list($cc) = explode('.', $file); if ($cc == '00' or $cc == 'a2') { continue; } // skip the blank flags $fullfile = catfile($dir, $file); if (is_dir($fullfile)) { continue; } // skip directories if (is_link($fullfile)) { continue; } // skip symlinks $info = getimagesize($fullfile); $size = @filesize($fullfile); $list[$file] = array('filename' => rawurlencode($file), 'url' => catfile($url, rawurlencode($file)), 'desc' => strtoupper($cc), 'size' => $size, 'width' => $info[0], 'height' => $info[1], 'attr' => $info[3]); } @closedir($dh); } ksort($list); $fields = array('filename', 'url', 'size', 'width', 'height'); output_list($t, $list, $fields, $idstr);
function template_dir($dir = null) { if ($dir === null) { $this->template_dir = catfile(PS_ROOTDIR, 'themes'); } else { $this->template_dir = $dir; } }
function uninstall_plugin($plugin) { $exists = $this->db->exists($this->db->table('plugins'), 'plugin', $plugin); if (!$exists) { return false; } $p = null; if (array_key_exists($plugin, $this->plugins)) { $p =& $this->plugins[$plugin]; } else { $file = catfile($this->plugin_dir, $plugin); if (is_dir($file)) { $file .= '/' . $plugin . '.php'; } else { $file .= '.php'; } $ok = $this->include_plugin_file($file, $err); $p = $ok ? new $plugin() : false; // do not $p->load() the plugin } $ok = $p ? $p->uninstall($this) : false; if ($ok) { $this->db->delete($this->db->table('plugins'), 'plugin', $plugin); } return $ok; }
$theme_dir = $ps->conf['theme']['template_dir']; // make sure the server environment will allow themes to be installed $allow = array(); $allow['url'] = (bool) ini_get('allow_url_fopen'); $allow['write'] = is_writable($theme_dir); $allow['install'] = $allow['url'] && $allow['write']; ini_set('user_agent', "PsychoStats Theme Installer"); $newtheme = new PsychoThemeManager($ps); if ($cancel) { $submit = false; } if ($reinstall and $dir) { // reinstall a local theme already on the hard drive $dir = basename($dir); // remove any potentially malicous paths if (file_exists(catfile($newtheme->template_dir, $dir))) { $t = $newtheme->reinstall($dir); if ($t) { $message = $cms->message('success', array('message_title' => "Theme reinstalled successfully!", 'message' => "Theme \"" . $t->xml_title() . "\" was installed successfully and is now available for use.")); } else { $message = $cms->message('theme-failure', array('message_title' => "Error reinstalling theme", 'message' => $newtheme->error())); } } else { $message = $cms->message('theme-failure', array('message_title' => "Error installing theme", 'message' => "Theme not found!")); } } elseif ($submit and $url and $allow['install']) { // attempt to install new theme if one is submitted $newtheme->load_theme($url); if ($newtheme->error()) { $submit = false; if ($newtheme->code() != PSTHEME_ERR_XML) {
} $path .= DIRECTORY_SEPARATOR . $dirs[$i]; // print "$path<br/>\n"; if (!is_dir($path) && !@mkdir($path, 0777)) { $ok = false; break; } } } if (!$ok) { $errors[] = "Error creating compile directory (Permission Denied)"; } } if (is_writable($compiledir)) { // now absolutely make sure we can create a file in the directory (open_basedir restrictions) $file = catfile($compiledir, 'pstest_' . uniqid(rand(), true)); $fh = @fopen($file, "w"); if (!$fh || !@fwrite($fh, "test")) { $errors[] = "Directory is not writable! (probably do to open_basedir restrictions)"; } else { $can_write = $allow_next = true; } @fclose($fh); @unlink($file); } // change $compiledir to empty if it matches the default /* on second thought, lets not.... always write the path no matter what if ($compiledir == $defaultdir) { $compiledir = ''; } */
if (empty($t['roles_dir'])) { $t['roles_dir'] = catfile($t['root_img_dir'], 'roles'); } if (empty($t['roles_url'])) { $t['roles_url'] = catfile($t['root_img_url'], 'roles'); } if (empty($t['flags_dir'])) { $t['flags_dir'] = catfile($t['root_img_dir'], 'flags'); } if (empty($t['flags_url'])) { $t['flags_url'] = catfile($t['root_img_url'], 'flags'); } if (empty($t['icons_dir'])) { $t['icons_dir'] = catfile($t['root_img_dir'], 'icons'); } if (empty($t['icons_url'])) { $t['icons_url'] = catfile($t['root_img_url'], 'icons'); } if (empty($t['maps_dir'])) { $t['maps_dir'] = catfile($t['root_img_dir'], 'maps'); } if (empty($t['maps_url'])) { $t['maps_url'] = catfile($t['root_img_url'], 'maps'); } // verify the compile_dir is valid. create it if possible. // If the dir is not valid try to find a valid directory or at least print out why. // TODO ... unset($t); // start the PS CMS object $cms = new PsychoCMS(array('dbhandle' => &$ps->db, 'plugin_dir' => PS_ROOTDIR . '/plugins', 'site_url' => $site_url)); $cms->init();