function sess_update($name = null, $update_id = null, $row = null) { $CI =& get_instance(); $wagon = $CI->session->userData($name); if (isset($wagon[$update_id])) { $wagon[$update_id] = $row; $CI->session->set_userData($name, $wagon); } else { sess_add($name, $row, $update_id); } return array("row" => $row, "id" => $update_id); }
function onupload() { $success = false; if (!file_exists(IMAGES_DIR)) { fs_mkdir(IMAGES_DIR); } if (!file_exists(ATTACHS_DIR)) { fs_mkdir(ATTACHS_DIR); } $imgs = array('.jpg', '.gif', '.png', '.jpeg'); //intentionally //I've not put BMPs $uploaded_files = array(); foreach ($_FILES["upload"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["upload"]["tmp_name"][$key]; $name = $_FILES["upload"]["name"][$key]; $dir = ATTACHS_DIR; $ext = strtolower(strrchr($name, '.')); if (in_array($ext, $imgs)) { $dir = IMAGES_DIR; } $name = sanitize_title(substr($name, 0, -strlen($ext))) . $ext; $target = "{$dir}/{$name}"; @umask(022); $success = move_uploaded_file($tmp_name, $target); @chmod($target, 0766); $uploaded_files[] = $name; // one failure will make $success == false :) $success &= $success; } } if ($uploaded_files) { $this->smarty->assign('success', $success ? 1 : -1); sess_add('admin_uploader_files', $uploaded_files); } return 1; }
function plugin_aaspam_comment_form() { // we get a random arithmetic operation // between sum, subtraction and multiplication; // we intentionally left out division because // it can lead to situations like division by zero // or floating point numbers $myop = array_rand($ops = array('+', '-', '*')); $op = $ops[$myop]; // we get two random integers between 1 and 10 $v1 = mt_rand(1, 10); // we rand $v2 until it differs from $v1 // (otherwise result for subtractions is zero) while (($v2 = mt_rand(1, 10)) == $v1) { } // if operation is subtraction // the higher number must always come first // or you'll get a negative integer if ($v2 > $v1 && $op == '-') { $tmp = $v1; $v1 = $v2; $v2 = $tmp; } // execute the operation switch ($op) { case '+': $v = $v1 + $v2; break; case '-': $v = $v1 - $v2; break; case '*': $v = $v1 * $v2; break; } sess_add('aaspam', $v); // load plugin strings // they're located under plugin.PLUGINNAME/lang/LANGID/ $lang = lang_load('plugin:accessibleantispam'); $langstrings =& $lang['plugin']['accessibleantispam']; // get the correct question depending on the operation switch ($op) { case '+': $question = $langstrings['sum']; break; case '-': $question = $langstrings['sub']; break; case '*': $question = $langstrings['prod']; break; } // format the question with numbers at the proper positions $question = sprintf($question, $v1, $v2); if (AASPAM_DEBUG && ($f = @fopen(AASPAM_LOG, 'a'))) { $arr['aaspam-q'] = $v; @fwrite($f, date('r') . '|' . session_id() . '|' . utils_kimplode($arr) . "\r\n"); @fclose($f); } // echoes the question and the form part echo <<<STR \t<p><label class="textlabel" for="aaspam">{$lang['plugin']['accessibleantispam']['prefix']} <strong>{$question} (*)</strong></label><br /> \t\t<input type="text" name="aaspam" id="aaspam" /></p> STR; }
function main() { // general setup global $panel, $action, $lang, $smarty, $fp_admin, $fp_admin_action; $panels = admin_getpanels(); $panel = isset($_GET['p']) ? $_GET['p'] : $panels[0]; define('ADMIN_PANEL', $panel); $smarty->assign('panel', $panel); if (!admin_panelexists($panel)) { trigger_error('Requested panel does not exists!', E_USER_ERROR); } $panelprefix = "admin.{$panel}"; $panelpath = ADMIN_DIR . "panels/{$panel}/{$panelprefix}.php"; $fp_admin = null; if (file_exists($panelpath)) { include $panelpath; $panelclass = "admin_{$panel}"; if (!class_exists($panelclass)) { trigger_error("No class defined for requested panel", E_USER_ERROR); } $fp_admin = new $panelclass($smarty); } /* check if user is loggedin */ if (!user_loggedin()) { utils_redirect("login.php"); die; } $action = isset($_GET['action']) ? $_GET['action'] : 'default'; if (!$fp_admin) { return; } $fp_admin_action = $fp_admin->get_action($action); define('ADMIN_PANEL_ACTION', $action); $smarty->assign('action', $action); $panel_url = BLOG_BASEURL . "admin.php?p={$panel}"; $action_url = $panel_url . "&action={$action}"; $smarty->assign('panel_url', $panel_url); $smarty->assign('action_url', $action_url); if (!empty($_POST)) { check_admin_referer("admin_{$panel}_{$action}"); } $smarty->assign('success', sess_remove("success_{$panel}")); $retval = $fp_admin_action->exec(); if ($retval > 0) { // if has REDIRECT option // clear postdata by a redirect sess_add("success_{$panel}", $smarty->get_template_vars('success')); $smarty->get_template_vars('success'); $to_action = $retval > 1 ? '&action=' . $action : ''; $with_mod = isset($_GET['mod']) ? '&mod=' . $_GET['mod'] : ''; $with_arguments = ''; if ($retval == PANEL_REDIRECT_CURRENT) { foreach ($fp_admin_action->args as $mandatory_argument) { $with_arguments .= '&' . $mandatory_argument . '=' . $_REQUEST[$mandatory_argument]; } } $url = "admin.php?p={$panel}{$to_action}{$with_mod}{$with_arguments}"; utils_redirect($url); } $smarty->register_modifier('action_link', 'admin_filter_action'); $smarty->register_modifier('cmd_link', 'admin_filter_command'); }
function system_seterr($module, $val) { if ($module) { $elem = 'success_' . $module; } else { $elem = 'success'; } sess_add($elem, $val); }