/** * Gets file information out of $_FILES and stores it locally in $files. * Checks file against max upload file size. * Scans file for viruses. * @return false for no errors, or a string describing the error */ function preprocess_file() { $name = $this->inputname; if (!isset($_FILES[$name])) { return get_string('noinputnamesupplied'); } $file = $_FILES[$name]; $maxsize = get_config('maxuploadsize'); if ($maxsize && $file['size'] > $maxsize) { return get_string('uploadedfiletoobig'); } if ($file['error'] != UPLOAD_ERR_OK) { $errormsg = get_string('phpuploaderror', 'mahara', get_string('phpuploaderror_' . $file['error']), $file['error']); log_debug($errormsg); if ($file['error'] == UPLOAD_ERR_NO_TMP_DIR || $file['error'] == UPLOAD_ERR_CANT_WRITE) { // The admin probably needs to fix this; notify them // @TODO: Create a new activity type for general admin messages. $message = (object) array('users' => get_column('usr', 'id', 'admin', 1), 'subject' => get_string('adminphpuploaderror'), 'message' => $errormsg); require_once 'activity.php'; activity_occurred('maharamessage', $message); } else { if ($file['error'] == UPLOAD_ERR_INI_SIZE || $file['error'] == UPLOAD_ERR_FORM_SIZE) { return get_string('uploadedfiletoobig'); } } } if (!is_uploaded_file($file['tmp_name'])) { return get_string('notphpuploadedfile'); } if (get_config('viruschecking') && ($errormsg = mahara_clam_scan_file($file))) { return $errormsg; } $this->file = $file; return false; }
/** * Initialize instance * * @param Charcoal_Config $config configuration data */ public function configure($config) { parent::configure($config); $session_name = $config->getString('session_name', ''); $save_path = $config->getString('save_path', '', TRUE); $lifetime = $config->getInteger('lifetime', 0); $valid_path = $config->getString('valid_path', ''); $valid_domain = $config->getString('valid_domain', ''); $ssl_only = $config->getBoolean('ssl_only', FALSE); $save_path = us($save_path); $lifetime = ui($lifetime); $ssl_only = ub($ssl_only); $session_name = us($session_name); // デフォルトのセッション保存先 if (!$save_path || !is_dir($save_path)) { $save_path = Charcoal_ResourceLocator::getApplicationPath('sessions'); } // セッション初期化処理 // session_set_cookie_params( $lifetime, "$valid_path", "$valid_domain", $ssl_only ); session_save_path($save_path); // $session_name = session_name( $session_name ? $session_name : APPLICATION ); session_name("PHPSESSID"); //session_regenerate_id( TRUE ); if ($this->getSandbox()->isDebug()) { log_debug("session", "session_name:{$session_name}", self::TAG); log_debug("session", "save_path:{$save_path}", self::TAG); log_debug("session", "lifetime:{$lifetime}", self::TAG); log_debug("session", "valid_path:{$valid_path}", self::TAG); log_debug("session", "valid_domain:{$valid_domain}", self::TAG); log_debug("session", "ssl_only:{$ssl_only}", self::TAG); } // メンバーに保存 $this->save_path = $save_path; }
public function onPageRequest(PageRequestEvent $event) { global $config, $page; // hax. if ($page->mode == "page" && (!isset($page->blocks) || $this->count_main($page->blocks) == 0)) { $h_pagename = html_escape(implode('/', $event->args)); $f_pagename = preg_replace("/[^a-z_\\-\\.]+/", "_", $h_pagename); $theme_name = $config->get_string("theme", "default"); if (file_exists("themes/{$theme_name}/{$f_pagename}") || file_exists("lib/static/{$f_pagename}")) { $filename = file_exists("themes/{$theme_name}/{$f_pagename}") ? "themes/{$theme_name}/{$f_pagename}" : "lib/static/{$f_pagename}"; $page->add_http_header("Cache-control: public, max-age=600"); $page->add_http_header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 600) . ' GMT'); $page->set_mode("data"); $page->set_data(file_get_contents($filename)); if (endsWith($filename, ".ico")) { $page->set_type("image/x-icon"); } if (endsWith($filename, ".png")) { $page->set_type("image/png"); } if (endsWith($filename, ".txt")) { $page->set_type("text/plain"); } } else { log_debug("handle_404", "Hit 404: {$h_pagename}"); $page->set_code(404); $page->set_title("404"); $page->set_heading("404 - No Handler Found"); $page->add_block(new NavBlock()); $page->add_block(new Block("Explanation", "No handler could be found for the page '{$h_pagename}'")); } } }
/** * Initialize instance * * @param Charcoal_Config $config configuration data */ public function configure($config) { parent::configure($config); $this->_unit = $config->getString('unit', 'mm')->getValue(); $this->_creator = $config->getString('creator', 'CharcoalPHP')->getValue(); $this->_authhor = $config->getString('authhor', 'CharcoalPHP')->getValue(); $this->_zoom = $config->getString('zoom', 'real')->getValue(); $this->_layout = $config->getString('layout', 'continuous')->getValue(); $this->_auto_break = $config->getBoolean('auto_break', TRUE)->getValue(); $this->_auto_break_margin = $config->getInteger('auto_break_margin', 5)->getValue(); $this->_fill_color = $config->getArray('fill_color', array(255, 255, 255))->getValue(); $this->_margin_left = $config->getInteger('margin_left', 10.0)->getValue(); $this->_margin_top = $config->getInteger('margin_left', 10.0)->getValue(); $this->_margin_right = $config->getInteger('margin_left', 10.0)->getValue(); log_debug("debug,pdf", "unit:" . $this->_unit); log_debug("debug,pdf", "creator:" . $this->_creator); log_debug("debug,pdf", "authhor:" . $this->_authhor); log_debug("debug,pdf", "zoom:" . $this->_zoom); log_debug("debug,pdf", "layout:" . $this->_layout); log_debug("debug,pdf", "auto_break:" . $this->_auto_break); log_debug("debug,pdf", "auto_break_margin:" . $this->_auto_break_margin); log_debug("debug,pdf", "fill_color:" . implode(",", $this->_fill_color)); log_debug("debug,pdf", "margin_left:" . $this->_margin_left); log_debug("debug,pdf", "margin_top:" . $this->_margin_top); log_debug("debug,pdf", "margin_right:" . $this->_margin_right); }
/** * Generate the Thumbnail image for particular file. * * @param string $hash * @return bool Returns true on successful thumbnail creation. */ protected function create_thumb($hash) { global $config; $ok = false; switch ($config->get_string("video_thumb_engine")) { default: case 'static': $outname = warehouse_path("thumbs", $hash); copy("ext/handle_video/thumb.jpg", $outname); $ok = true; break; case 'ffmpeg': $ffmpeg = escapeshellcmd($config->get_string("thumb_ffmpeg_path")); $w = (int) $config->get_int("thumb_width"); $h = (int) $config->get_int("thumb_height"); $inname = escapeshellarg(warehouse_path("images", $hash)); $outname = escapeshellarg(warehouse_path("thumbs", $hash)); if ($config->get_bool("video_thumb_ignore_aspect_ratio") == true) { $cmd = escapeshellcmd("{$ffmpeg} -i {$inname} -ss 00:00:00.0 -f image2 -vframes 1 {$outname}"); } else { $scale = 'scale="' . escapeshellarg("if(gt(a,{$w}/{$h}),{$w},-1)") . ':' . escapeshellarg("if(gt(a,{$w}/{$h}),-1,{$h})") . '"'; $cmd = "{$ffmpeg} -i {$inname} -vf {$scale} -ss 00:00:00.0 -f image2 -vframes 1 {$outname}"; } exec($cmd, $output, $returnValue); if ((int) $returnValue == (int) 1) { $ok = true; } log_debug('handle_video', "Generating thumbnail with command `{$cmd}`, returns {$returnValue}"); break; } return $ok; }
/** * @attribute[RequestParam('title','string')] * @attribute[RequestParam('body','string')] */ function AddPost($title, $body) { log_debug("Add Post"); $ds = model_datasource('system'); $ds->ExecuteSql("INSERT INTO blog(title,body)VALUES(?,?)", array($title, $body)); redirect('blog', 'index'); }
public static function render_instance(BlockInstance $instance, $editing = false) { require_once get_config('docroot') . 'artefact/lib.php'; $smarty = smarty_core(); $configdata = $instance->get('configdata'); $data = array(); // add in the selected email address if (!empty($configdata['email'])) { $configdata['artefactids'][] = $configdata['email']; } // Get data about the profile fields in this blockinstance if (!empty($configdata['artefactids'])) { $viewowner = get_field('view', 'owner', 'id', $instance->get('view')); foreach ($configdata['artefactids'] as $id) { try { $artefact = artefact_instance_from_id($id); if (is_a($artefact, 'ArtefactTypeProfile') && $artefact->get('owner') == $viewowner) { $rendered = $artefact->render_self(array('link' => true)); $data[$artefact->get('artefacttype')] = $rendered['html']; } } catch (ArtefactNotFoundException $e) { log_debug('Artefact not found when rendering contactinfo block instance. ' . 'There might be a bug with deleting artefacts of this type? ' . 'Original error follows:'); log_debug($e->getMessage()); } } } $smarty->assign('profileinfo', $data); return $smarty->fetch('blocktype:contactinfo:content.tpl'); }
function process($info) { $commit_info = $info['commit_info']; $module = $info['module']; $git_path = $info['git_path']; $svn_path = $info['svn_path']; if (empty($module) || empty($git_path) || empty($svn_path)) { log_warning(sprintf("some parameter is invalid. " . "module[%s] git_path[%s] svn_path[%s]", $module, $git_path, $svn_path)); return false; } $svn_path_name = basename($svn_path); if ($svn_path_name != $module) { log_warning("svn module does not match git module", $svn_path_name, $module); return false; } if ($commit_info['ref'] != 'refs/heads/master') { log_debug("omit non master commit"); return true; } $pwd = dirname(__FILE__); $cmd = "(source ~/.bashrc && cd {$pwd} && nohup ./git2svn.sh {$module} {$git_path} {$svn_path}) >./log/job.\$\$.log 2>&1 & echo \$!"; exec($cmd, $output, $ret); log_debug(sprintf("start background sync script. cmd[%s] ret[%s] job-pid[%s]", $cmd, $ret, $output[0])); if ($ret == 0) { return true; } else { return false; } }
public function log($level, &$message) { switch ($level) { case LogHelper::LEVEL_DEBUG: log_debug($message); break; case LogHelper::LEVEL_INFO: log_info($message); break; case LogHelper::LEVEL_NOTICE: log_notice($message); break; case LogHelper::LEVEL_WARNING: log_warn($message); break; case LogHelper::LEVEL_ERROR: log_error($message); break; case LogHelper::LEVEL_CRITICAL: log_critical($message); break; case LogHelper::LEVEL_ALERT: log_alert($message); break; case LogHelper::LEVEL_EMERGENCY: log_emergency($message); break; } }
function log_post($log_type, $log_contents, $timestamp = NULL) { log_debug("changelog", "Executing log_post({$log_type}, {$log_contents}, {$timestamp})"); // check audit logging if (!$GLOBALS["config"]["FEATURE_LOGS_AUDIT"] && $log_type == "audit") { // audit logging is disabled return 0; } // do retention clean check if ($GLOBALS["config"]["LOG_RETENTION_PERIOD"]) { // check when we last ran a retention clean if ($GLOBALS["config"]["LOG_RETENTION_CHECKTIME"] < time() - 86400) { $this->log_retention_clean(); } } if (empty($timestamp)) { $timestamp = time(); } // write log $sql_obj = new sql_query(); $sql_obj->string = "INSERT INTO logs (id_server, id_domain, username, timestamp, log_type, log_contents) VALUES ('" . $this->id_server . "', '" . $this->id_domain . "', '" . $this->username . "', '{$timestamp}', '{$log_type}', '{$log_contents}')"; $sql_obj->execute(); // update last sync on name server if ($this->id_server) { $obj_server = new name_server(); $obj_server->id = $this->id_server; $obj_server->action_update_log_version($timestamp); } return 1; }
/** * Constructor * * @access public */ function __construct($props = array()) { if (count($props) > 0) { $this->initialize($props); } log_debug("Upload Class Initialized"); }
public function symbolicate() { $addresses = null; $targets = null; $matches = null; $symbolicated_report = $this->report; if ($this->appVersion === null) { preg_match('/^App Version: ([^\\s]+)/m', $symbolicated_report, $matches); if (!isset($matches[1]) || count($matches[1]) == 0) { preg_match('/Version:\\s+([\\S]+)\\s+/m', $symbolicated_report, $matches); } if (!isset($matches[1]) || count($matches[1]) == 0) { $msg = "Unknown format of crash or exception report."; throw new UnknownReportFormatSymbolicatorException($msg); } $this->appVersion = $matches[1]; } $full_path = sprintf("%s/tower1/%s/Tower.app/Contents/MacOS/Tower", RELEASES_DIR, $this->appVersion); # FIXME if (!file_exists($full_path)) { $msg = "Could not find dsym files for product `{$this->appIdentifier}`, version `{$this->appVersion}`. Please copy dsym files to `releases/PRODUCT/VERSION/`.\n\nFull path: `{$full_path}`"; throw new ReleaseNotFoundSymbolicatorException($msg); } # # Find lines like this: # # 1 com.fournova.Tower 0x00091c91 0x1000 + 593041 # # Resolve address and replace starting address (0x1000) with symbolicated name. # preg_match_all('/[0-9]+\\s.+\\s(0x[0-9a-f]+)\\s(\\w+\\s\\+\\s[0-9]+)/m', $this->report, $matches); if (!isset($matches[1]) || count($matches[1]) == 0) { preg_match_all('/^(0x[0-9a-f]+)$/m', $this->report, $matches); } $addresses = $matches[1]; if (isset($matches[2])) { $targets = $matches[2]; } $cmd = sprintf("/usr/bin/atos -arch %s -o %s %s", $this->arch, $full_path, implode(' ', $addresses)); log_debug($cmd); $output = null; exec($cmd, $output); foreach ($output as $i => $line) { if (substr($line, 0, 2) !== '0x') { $replacement = null; if ($targets !== null) { $target = $targets[$i]; // e.g. "0x1000 + 593041" $tokens = explode(' + ', $target); $replacement = "{$line} + {$tokens[1]}"; } else { $target = $addresses[$i]; $replacement = $line; } $symbolicated_report = str_replace($target, $replacement, $symbolicated_report); } } return $symbolicated_report; }
function print_debug($message, $var = 'messageonly', $part = 'app', $level = 3) { if ($var == 'messageonly') { log_debug($message); } else { log_debug($message, $var); } }
function xmldb_search_elasticsearch_upgrade($oldversion = 0) { if ($oldversion < 2015012800) { // Adding indices on the table search_elasticsearch_queue $table = new XMLDBTable('search_elasticsearch_queue'); $index = new XMLDBIndex('itemidix'); $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('itemid')); add_index($table, $index); } if ($oldversion < 2015060900) { log_debug('Add "status" and "lastprocessed" columns to search_elasticsearch_queue table'); $table = new XMLDBTable('search_elasticsearch_queue'); $field = new XMLDBField('status'); $field->setAttributes(XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, null, null, null, 0); add_field($table, $field); $table = new XMLDBTable('search_elasticsearch_queue'); $field = new XMLDBField('lastprocessed'); $field->setAttributes(XMLDB_TYPE_DATETIME); add_field($table, $field); $table = new XMLDBTable('search_elasticsearch_queue'); $index = new XMLDBIndex('statusix'); $index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('status')); add_index($table, $index); } if ($oldversion < 2015072700) { log_debug('Adding ability to search by "Text" blocks in elasticsearch'); // Need to add the 'block_instance' to the default types to index for elasticsearch // Note: the $cfg->plugin_search_elasticsearch_types can be overriding this // We don't want to run the re-indexing now as that will take ages for large sites // It should be run from the Extensions -> Elasticsearch -> Configuration page if ($types = get_field('search_config', 'value', 'plugin', 'elasticsearch', 'field', 'types')) { $types = explode(',', $types); if (!in_array('block_instance', $types)) { $types[] = 'block_instance'; } $types = implode(',', $types); update_record('search_config', array('value' => $types), array('plugin' => 'elasticsearch', 'field' => 'types')); log_warn(get_string('newindextype', 'search.elasticsearch', 'block_instance'), true, false); } } if ($oldversion < 2015100800) { log_debug('Adding ability to search by collection in elasticsearch'); // The code for this existed since the beginning but 'collection' was not // added to the $cfg->plugin_search_elasticsearch_types // We don't want to run the re-indexing now as that will take ages for large sites // It should be run from the Extensions -> Elasticsearch -> Configuration page if ($types = get_field('search_config', 'value', 'plugin', 'elasticsearch', 'field', 'types')) { $types = explode(',', $types); if (!in_array('collection', $types)) { $types[] = 'collection'; } $types = implode(',', $types); update_record('search_config', array('value' => $types), array('plugin' => 'elasticsearch', 'field' => 'types')); log_warn(get_string('newindextype', 'search.elasticsearch', 'collection'), true, false); } } return true; }
function quotes_render_summarybox($id) { log_debug("inc_quotes", "quotes_render_summarybox({$id})"); // fetch quote information $sql_obj = new sql_query(); $sql_obj->string = "SELECT code_quote, amount_total, date_validtill, date_sent, sentmethod FROM account_quotes WHERE id='{$id}' LIMIT 1"; $sql_obj->execute(); if ($sql_obj->num_rows()) { $sql_obj->fetch_array(); if ($sql_obj->data[0]["amount_total"] == 0) { print "<table width=\"100%\" class=\"table_highlight_important\">"; print "<tr>"; print "<td>"; print "<b>Quote " . $sql_obj->data[0]["code_quote"] . " has no items on it</b>"; print "<p>This quote needs to have some items added to it using the links in the nav menu above.</p>"; print "</td>"; print "</tr>"; print "</table>"; } else { if (time_date_to_timestamp($sql_obj->data[0]["date_validtill"]) <= time()) { print "<table width=\"100%\" class=\"table_highlight_important\">"; print "<tr>"; print "<td>"; print "<p><b>Quote " . $sql_obj->data[0]["code_quote"] . " has now expired and is no longer valid.</b></p>"; print "</td>"; print "</tr>"; print "</table>"; } else { print "<table width=\"100%\" class=\"table_highlight_important\">"; print "<tr>"; print "<td>"; print "<b>Quote " . $sql_obj->data[0]["code_quote"] . " is currently valid.</b>"; print "<table cellpadding=\"4\">"; print "<tr>"; print "<td>Quote Total:</td>"; print "<td>" . format_money($sql_obj->data[0]["amount_total"]) . "</td>"; print "</tr>"; print "<tr>"; print "<td>Valid Until:</td>"; print "<td>" . $sql_obj->data[0]["date_validtill"] . "</td>"; print "</tr>"; print "<tr>"; print "<td>Date Sent:</td>"; if ($sql_obj->data[0]["sentmethod"] == "") { print "<td><i>Has not been sent to customer</i></td>"; } else { print "<td>" . $sql_obj->data[0]["date_sent"] . " (" . $sql_obj->data[0]["sentmethod"] . ")</td>"; } print "</tr>"; print "</tr></table>"; print "</td>"; print "</tr>"; print "</table>"; } } print "<br>"; } }
/** * @param float $defvalue Initial value * @param string $onchange onChange JS code */ function __initialize($defvalue = 0, $onchange = "") { parent::__initialize("div"); $defvalue = floatval(str_replace(",", ".", $defvalue)); $e = floor($defvalue); $c = round($defvalue - $e, 2) * 100; log_debug("CurrencyInput({$id}): {$defvalue} {$e} {$c}"); $id = $this->id; $this->class = "currencyinput ui-widget-content ui-widget ui-corner-all"; $this->css("border", "1px solid transparent"); $this->onmouseover = "\$(this).css({border:''});"; $this->onmouseout = "\$(this).css({border:'1px solid transparent'});"; $euro = new uiSlider(); $euro->id = "{$id}_euro"; $euro->range = 'min'; $euro->min = 0; $euro->max = 100; $euro->value = $e; $euro->css("margin-bottom", "8px"); $euro->onslide = "function(event, ui){ \$('#{$id}_euro_value').text(ui.value); "; $euro->onslide .= "\$('#{$id}_hidden').val( \$('#{$id}_euro_value').text()+'.'+\$('#{$id}_cent_value').text() ).change(); }"; $euro->onmouseover = "\$('#{$id}_euro_value').css({color:'red'});"; $euro->onmouseout = "\$('#{$id}_euro_value').css({color:'black'});"; $cent = new uiSlider(); $cent->id = "{$id}_cent"; $cent->range = 'min'; $cent->min = 0; $cent->max = 99; $cent->value = $c; $cent->onslide = "function(event, ui){ \$('#{$id}_cent_value').text(ui.value<10?'0'+ui.value:ui.value); "; $cent->onslide .= "\$('#{$id}_hidden').val( \$('#{$id}_euro_value').text()+'.'+\$('#{$id}_cent_value').text() ).change(); }"; $cent->onmouseover = "\$('#{$id}_cent_value').css({color:'red'});"; $cent->onmouseout = "\$('#{$id}_cent_value').css({color:'black'});"; $container = new Control("div"); $container->class = "container"; $container->content($euro); $container->content($cent); $value = new Control("div"); $value->class = "value"; $euroval = new Control("div"); $euroval->id = "{$id}_euro_value"; $euroval->css("float", "left"); $euroval->content($e); $centval = new Control("div"); $centval->id = "{$id}_cent_value"; $centval->css("float", "left"); $centval->content($c < 9 ? "0{$c}" : $c); $value->content("<div style='float:left'>€</div>"); $value->content($euroval); $value->content("<div style='float:left'>,</div>"); $value->content($centval); $this->content($container); $this->content($value); $this->content("<input type='hidden' id='{$id}_hidden' name='{$id}' value='{$defvalue}' onchange='{$onchange}'/>"); $this->content("<br style='clear:both; line-height:0'/>"); }
/** * Constructor method * * @param call stack $m */ function __construct($m) { $msg = urlencode($m); // log the exception log_debug($m); // do the cleanup $this->cleanUp($msg); // send out the pretty error page $this->diePage($msg); }
function storage_s3_file_exists($object_id, $more = array()) { $rsp = s3_head(storage_s3_bucket(), $object_id); if ($rsp['ok']) { log_debug('s3', "exists: {$object_id}"); return 1; } else { return 0; } }
public static function render_instance(BlockInstance $instance, $editing = false) { require_once get_config('docroot') . 'artefact/lib.php'; $smarty = smarty_core(); $configdata = $instance->get('configdata'); $data = array(); $data['socialprofiles'] = array(); // add in the selected email address if (!empty($configdata['email'])) { $configdata['artefactids'][] = $configdata['email']; } $viewowner = get_field('view', 'owner', 'id', $instance->get('view')); // Get data about the profile fields in this blockinstance if (!empty($configdata['artefactids'])) { foreach ($configdata['artefactids'] as $id) { try { $artefact = artefact_instance_from_id($id); if (is_a($artefact, 'ArtefactTypeProfile') && $artefact->get('owner') == $viewowner) { $rendered = $artefact->render_self(array('link' => true)); $artefacttype = $artefact->get('artefacttype'); if ($artefacttype == 'socialprofile') { if (get_record('blocktype_installed', 'active', 1, 'name', 'socialprofile', 'artefactplugin', 'internal')) { $data['socialprofiles'][] = array('link' => ArtefactTypeSocialprofile::get_profile_link($artefact->get('title'), $artefact->get('note')), 'title' => $artefact->get('title'), 'description' => $artefact->get('description'), 'note' => $artefact->get('note')); } } else { $data[$artefacttype] = $rendered['html']; } } } catch (ArtefactNotFoundException $e) { log_debug('Artefact not found when rendering a block instance. ' . 'There might be a bug with deleting artefacts of this type? ' . 'Original error follows:'); log_debug($e->getMessage()); } } // Sort social profiles alphabetically (in ASC order) $description = array(); foreach ($data['socialprofiles'] as $key => $row) { $description[$key] = $row['description']; } array_multisort($description, SORT_ASC, $data['socialprofiles']); } // Work out the path to the thumbnail for the profile image if (!empty($configdata['profileicon'])) { $downloadpath = get_config('wwwroot') . 'thumb.php?type=profileiconbyid&id=' . $configdata['profileicon']; $downloadpath .= '&maxwidth=80'; $smarty->assign('profileiconpath', $downloadpath); $smarty->assign('profileiconalt', get_string('profileimagetext', 'mahara', display_default_name(get_user($viewowner)))); } // Override the introduction text if the user has any for this // particular blockinstance if (!empty($configdata['introtext'])) { $data['introduction'] = $configdata['introtext']; } $smarty->assign('profileinfo', $data); return $smarty->fetch('blocktype:profileinfo:content.tpl'); }
function xmldb_interaction_forum_upgrade($oldversion = 0) { if ($oldversion < 2009062300) { foreach (array('topic', 'forum') as $type) { log_debug("Subscription upgrade for {$type}s"); // Add missing primary key to the subscription tables // Step 1: remove duplicates if ($dupes = get_records_sql_array(' SELECT "user", ' . $type . ', COUNT(*) FROM {interaction_forum_subscription_' . $type . '} GROUP BY "user", ' . $type . ' HAVING COUNT(*) > 1', array())) { // We found duplicate subscriptions to a topic/forum foreach ($dupes as $dupe) { log_debug("interaction.forum: Removing duplicate {$type} subscription for {$dupe->user}"); delete_records('interaction_forum_subscription_' . $type, 'user', $dupe->user, $type, $dupe->{$type}); insert_record('interaction_forum_subscription_' . $type, (object) array('user' => $dupe->user, $type => $dupe->{$type})); } } // Step 2: add the actual key $table = new XMLDBTable('interaction_forum_subscription_' . $type); $key = new XMLDBKey('primary'); $key->setAttributes(XMLDB_KEY_PRIMARY, array('user', $type)); add_key($table, $key); // Add a 'key' column, used for unsubscriptions $field = new XMLDBField('key'); $field->setAttributes(XMLDB_TYPE_CHAR, 50, XMLDB_UNSIGNED, null); add_field($table, $field); $key = new XMLDBKey('keyuk'); $key->setAttributes(XMLDB_KEY_UNIQUE, array('key')); add_key($table, $key); // Populate the key column if ($records = get_records_array('interaction_forum_subscription_' . $type, '', '', '', '"user", ' . $type)) { foreach ($records as $where) { $new = (object) array('user' => $where->user, $type => $where->{$type}, 'key' => dechex(mt_rand())); update_record('interaction_forum_subscription_' . $type, $new, $where); } } // Now make the key column not null $field->setAttributes(XMLDB_TYPE_CHAR, 50, XMLDB_UNSIGNED, XMLDB_NOTNULL); change_field_notnull($table, $field); } } if ($oldversion < 2009081700) { if (!get_record('interaction_config', 'plugin', 'forum', 'field', 'postdelay')) { insert_record('interaction_config', (object) array('plugin' => 'forum', 'field' => 'postdelay', 'value' => 30)); } } if ($oldversion < 2009081800) { $subscription = (object) array('plugin' => 'forum', 'event' => 'creategroup', 'callfunction' => 'create_default_forum'); ensure_record_exists('interaction_event_subscription', $subscription, $subscription); } return true; }
function xmldb_blocktype_textbox_upgrade($oldversion = 0) { if ($oldversion < 2011082200) { // Convert all textbox html content to artefacts $tbcount = count_records('block_instance', 'blocktype', 'textbox'); $sql = ' SELECT b.id, b.title, b.configdata, b.view, v.owner, v.group, v.institution, v.ctime, v.mtime, v.atime FROM {block_instance} b JOIN {view} v ON b.view = v.id WHERE b.id > ? AND b.blocktype = ? ORDER BY b.id'; $done = 0; $lastid = 0; if (is_mysql()) { $mp = mysql_get_variable('max_allowed_packet'); $limit = $mp && is_numeric($mp) && $mp > 1048576 ? $mp / 8192 : 100; } else { $limit = 5000; } while ($records = get_records_sql_array($sql, array($lastid, 'textbox'), 0, $limit)) { // Create the new artefacts $values = array(); foreach ($records as $r) { $configdata = unserialize($r->configdata); array_push($values, 'html', $r->ctime, $r->mtime, $r->atime, $r->title, isset($configdata['text']) ? $configdata['text'] : '', $r->owner, $r->group, $r->institution, $r->owner > 0 ? $r->owner : null, $r->owner > 0 ? null : '?', $r->id); // Dumping the block id in the note column makes it easier to update block_instance later } $insertsql = "\n INSERT INTO {artefact}\n (artefacttype, ctime, mtime, atime, title, description, owner, \"group\", institution, author, authorname, note)\n VALUES "; $insertsql .= join(',', array_fill(0, count($records), '(?,?,?,?,?,?,?,?,?,?,?,?)')); execute_sql($insertsql, $values); // Update block_instance configdata to point at the new artefacts if (is_postgres()) { execute_sql("\n UPDATE {block_instance}\n SET configdata = 'a:1:{s:10:\"artefactid\";i:' || a.id::text || ';}'\n FROM (\n SELECT id, note FROM {artefact} WHERE artefacttype = 'html' AND note IS NOT NULL\n ) a\n WHERE blocktype = 'textbox' AND {block_instance}.id::text = a.note"); // Update view_artefact table execute_sql("\n INSERT INTO {view_artefact} (view, block, artefact)\n SELECT b.view, b.id, a.id\n FROM {block_instance} b, {artefact} a\n WHERE b.blocktype = 'textbox' AND a.artefacttype = 'html' AND a.note IS NOT NULL AND CAST(b.id AS TEXT) = a.note", array()); } else { if (is_mysql()) { execute_sql("\n UPDATE {block_instance}, {artefact}\n SET {block_instance}.configdata = CONCAT('a:1:{s:10:\"artefactid\";i:', {artefact}.id, ';}')\n WHERE\n {artefact}.artefacttype = 'html'\n AND {artefact}.note IS NOT NULL\n AND {block_instance}.blocktype = 'textbox'\n AND {block_instance}.id = {artefact}.note"); // Update view_artefact table execute_sql("\n INSERT INTO {view_artefact} (view, block, artefact)\n SELECT b.view, b.id, a.id\n FROM {block_instance} b, {artefact} a\n WHERE b.blocktype = 'textbox' AND a.artefacttype = 'html' AND a.note IS NOT NULL AND b.id = a.note", array()); } } // Remove the dodgy block id in the note column execute_sql("UPDATE {artefact} SET note = NULL WHERE artefacttype = 'html' AND note IS NOT NULL"); $done += count($records); log_debug("Upgrading textbox blocks: {$done}/{$tbcount}"); $last = end($records); $lastid = $last->id; } } return true; }
/** * execute tests */ public function test($action, $context) { $action = us($action); log_debug("debug,event", "action:{$action}"); switch ($action) { case "new_instance": $klass = new Charcoal_Class(s('Foo')); $object = $klass->newInstance(); $this->assertEquals("Foo", get_class($object)); return TRUE; } return FALSE; }
/** * Initialize instance * * @param Charcoal_Config $config configuration data */ public function configure($config) { parent::configure($config); $this->name_space = $config->getString('name_space', ''); $this->event_filters = $config->getArray('event_filters', array()); $this->post_actions = $config->getArray('post_actions', array('remove_event')); $this->priority = $config->getInteger('priority', 0); if ($this->getSandbox()->isDebug()) { log_debug("debug,event", "Task[{$this}] name space: {$this->name_space}", self::TAG); log_debug("debug,event", "Task[{$this}] event filters: " . $this->event_filters, self::TAG); log_debug("debug,event", "Task[{$this}] post actions: " . $this->post_actions, self::TAG); log_debug("debug,event", "Task[{$this}] priority: {$this->priority}", self::TAG); } }
public function onPageRequest(PageRequestEvent $event) { global $page; // hax. if ($page->mode == "page" && (!isset($page->blocks) || $this->count_main($page->blocks) == 0)) { $h_pagename = html_escape(implode('/', $event->args)); header("HTTP/1.0 404 Page Not Found"); log_debug("handle_404", "Hit 404: {$h_pagename}"); $page->set_title("404"); $page->set_heading("404 - No Handler Found"); $page->add_block(new NavBlock()); $page->add_block(new Block("Explanation", "No handler could be found for the page '{$h_pagename}'")); } }
/** * Initialize instance * * @param Charcoal_Config $config configuration data */ public function configure($config) { parent::configure($config); $this->_host = $config->getString('host', 'localhost'); $this->_port = $config->getInteger('port', 11211); $this->_weight = $config->getInteger('weight', 100); $this->_default_duration = $config->getInteger('default_duration', 0); log_debug("system, debug, cache", "cache", "host=[{$this->_host}]"); log_debug("system, debug, cache", "cache", "port=[{$this->_port}]"); log_debug("system, debug, cache", "cache", "weight=[{$this->_weight}]"); log_debug("system, debug, cache", "cache", "default_duration=[{$this->_default_duration}]"); $this->_memcache->addServer(us($this->_host), ui($this->_port), TRUE, ui($this->_weight)); log_info("system, debug, cache", "cache", "server added."); }
public function getDefinition($params) { // get word $param = $params->getParam(0); if (!XML_RPC_Value::isValue($param)) { log_debug($param); } $word = $param->scalarval(); // get the definition by the word. $message = $this->objMxitDictionary->getDefinition($word); $val = $message['definition']; // return the value as an XML-RPC value and response. $val2send = new XML_RPC_Value($val, 'string'); return new XML_RPC_Response($val2send); }
function GetExcelFormat($cellformat) { $f = strtolower($cellformat->GetFormat()); if (isset(self::$FORMAT_MAP[$f])) { return self::$FORMAT_MAP[$f]; } switch ($f) { case 'time': case 'duration': self::$FORMAT_MAP[$f] = PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4; break; case 'date': self::$FORMAT_MAP[$f] = PHPExcel_Style_NumberFormat::FORMAT_DATE_DDMMYYYY; break; case 'datetime': self::$FORMAT_MAP[$f] = PHPExcel_Style_NumberFormat::FORMAT_DATE_DATETIME; break; case 'currency': $res = '#' . $this->CurrencyFormat->GroupSeparator . '##0' . $this->CurrencyFormat->DecimalSeparator . str_repeat('0', $this->CurrencyFormat->DecimalDigits); log_debug("CurrencyFormat -> " . $res); $pos = str_replace('%v', $res, $this->CurrencyFormat->PositiveFormat); $neg = str_replace('%v', $res, $this->CurrencyFormat->NegativeFormat); self::$FORMAT_MAP[$f] = "{$pos};{$neg}"; break; case 'int': case 'integer': $res = '#' . $this->NumberFormat->GroupSeparator . '##0'; log_debug("IntegerFormat -> " . $res); $pos = $res; $neg = str_replace('%v', $res, $this->NumberFormat->NegativeFormat); self::$FORMAT_MAP[$f] = "{$pos};{$neg}"; break; case 'float': case 'double': $res = '#' . $this->NumberFormat->GroupSeparator . '##0' . $this->NumberFormat->DecimalSeparator . str_repeat('0', $this->NumberFormat->DecimalDigits); log_debug("DoubleFormat -> " . $res); $pos = $res; $neg = str_replace('%v', $res, $this->NumberFormat->NegativeFormat); self::$FORMAT_MAP[$f] = "{$pos};{$neg}"; break; default: log_warn("Unknown column format: {$f}"); self::$FORMAT_MAP[$f] = PHPExcel_Style_NumberFormat::FORMAT_GENERAL; break; } return self::$FORMAT_MAP[$f]; }
/** * Kernel response listener callback. * * @param FilterResponseEvent $event */ public function onResponse(FilterResponseEvent $event) { if (!$event->isMasterRequest()) { return; } $log = '** after *****************************************:' . PHP_EOL; $response = $event->getResponse(); $log .= $this->logResponse($response); $request = $event->getRequest(); $log .= $this->logRequest($request); $Session = $request->getSession(); if ($request->hasSession()) { $log .= $this->logSession($Session); } $this->app->log($log, array(), Logger::DEBUG); log_debug($log); }
public static function loadModule($sandbox, $module_path, $task_manager) { // Charcoal_ParamTrait::validateSandbox( 1, $sandbox ); // Charcoal_ParamTrait::validateStringOrObjectPath( 2, $module_path ); // Charcoal_ParamTrait::validateImplements( 3, 'Charcoal_ITaskManager', $task_manager ); try { log_debug('debug, event', "loading module: {$module_path}"); if ($module_path instanceof Charcoal_ObjectPath) { $module_path = $module_path->toString(); } else { $module_path = us($module_path); } // check if module is already loaded if (isset(self::$loaded_paths[$module_path])) { log_warning('system, event, debug', "module[{$module_path}] is already loaded."); return; } /** @var Charcoal_IModule $module */ /** @var Charcoal_Sandbox $sandbox */ $module = $sandbox->createObject($module_path, 'module', array(), 'Charcoal_IModule', 'Charcoal_SimpleModule'); // load module tasks $loaded_tasks = $module->loadTasks($task_manager); // load module events source code $loaded_events = $module->loadEvents($task_manager); // if no tasks or events are loaded, you maybe passed a wrong module path if (empty($loaded_tasks) && empty($loaded_events)) { _throw(new Charcoal_ModuleLoaderException($module_path, "no tasks and events are loaded.")); } // load required modules $required_modules = $module->getRequiredModules(); if ($required_modules) { $loaded_modules = NULL; foreach ($required_modules as $module_name) { if (strlen($module_name) === 0) { continue; } self::loadModule($sandbox, $module_name, $task_manager); } } self::$loaded_paths[$module_path] = $module_path; log_debug('debug, event, module', "loaded module: {$module_path}"); } catch (Exception $ex) { _catch($ex); _throw(new Charcoal_ModuleLoaderException($module_path, "failed to load module.", $ex)); } }
public function onImageDeletion(ImageDeletionEvent $event) { global $config; $access = $config->get_string("amazon_s3_access"); $secret = $config->get_string("amazon_s3_secret"); $bucket = $config->get_string("amazon_s3_bucket"); if (!empty($bucket)) { log_debug("amazon_s3", "Deleting Image #" . $event->image->id . " from S3"); $s3 = new S3($access, $secret); $s3->deleteObject($bucket, "images/" + $event->image->hash); $s3->deleteObject($bucket, "thumbs/" + $event->image->hash); } }