function resetAttachments() { $helpdir = JPATH_BASE . '/components/' . $GLOBALS["com_name"] . '/helpers/'; @(require_once $helpdir . "b2jsession.php"); $jsession = JFactory::getSession(); $bid = JFactory::getApplication()->input->get("bid", false); $b2jcomid = JFactory::getApplication()->input->get("b2jcomid", false); $b2jmoduleid = JFactory::getApplication()->input->get("b2jmoduleid", false); $b2jsession = new B2JSession($jsession->getId(), $b2jcomid, $b2jmoduleid, $bid); $b2jsession->Clear('filelist'); exit; }
protected function DoUpload() { $file = JRequest::getVar('b2jstdupload', NULL, 'files', 'array'); if (!$this->Submitted || !$file || $file['error'] == UPLOAD_ERR_NO_FILE) { return true; } $upload_directory = JPATH_SITE . "/components/" . $GLOBALS["com_name"] . "/uploads/"; if (!is_writable($upload_directory)) { $this->MessageBoard->Add(JText::_($GLOBALS["COM_NAME"] . '_ERR_DIR_NOT_WRITABLE'), B2JMessageBoard::error); return false; } if ($file['error']) { $this->MessageBoard->Add(JText::sprintf($GLOBALS["COM_NAME"] . '_ERR_UPLOAD', $file['error']), B2JMessageBoard::error); return false; } $size = $file['size']; if ($size == 0) { $this->MessageBoard->Add(JText::_($GLOBALS["COM_NAME"] . '_ERR_FILE_EMPTY'), B2JMessageBoard::error); return false; } $max_filesize = intval($this->Params->get("uploadmax_file_size", "0")) * KB; if ($size > $max_filesize) { $this->MessageBoard->Add(JText::_($GLOBALS["COM_NAME"] . '_ERR_FILE_TOO_LARGE'), B2JMessageBoard::error); return false; } $mimetype = new B2JMimeType(); if (!$mimetype->Check($file['tmp_name'], $this->Params)) { $this->MessageBoard->Add(JText::_($GLOBALS["COM_NAME"] . '_ERR_MIME') . " [" . $mimetype->Mimetype . "]", B2JMessageBoard::error); return false; } jimport('joomla.filesystem.file'); $filename = JFile::makeSafe($file['name']); $filename = uniqid() . "-" . $filename; $dest = $upload_directory . $filename; if (!JFile::upload($file['tmp_name'], $dest)) { return false; } $jsession =& JFactory::getSession(); $b2jsession = new B2JSession($jsession->getId(), $this->Application->b2jcomid, $this->Application->b2jmoduleid, $this->Application->bid); // session_id, cid, mid $data = $b2jsession->Load('filelist'); if ($data) { $filelist = explode("|", $data); } else { $filelist = array(); } $filelist[] = $filename; $data = implode("|", $filelist); $b2jsession->Save($data, "filelist"); return true; }
public function Draw() { $jsession = JFactory::getSession(); $b2jcomid = $b2jmoduleid = 0; switch (JFactory::getApplication()->input->get("owner", NULL)) { case "component": $b2jcomid = JFactory::getApplication()->input->get("id", NULL); break; case "module": $b2jmoduleid = JFactory::getApplication()->input->get("id", NULL); } $bid = JFactory::getApplication()->input->get("bid", NULL); $b2jsession = new B2JSession($jsession->getId(), $b2jcomid, $b2jmoduleid, $bid); if ($b2jsession->Save($this->Answer, "captcha_answer")) { $this->DebugLog->Write("Answer saved into session"); } else { $this->DebugLog->Write("Database query failed"); } imagefill($this->Image['data'], 0, 0, $this->Colors['Background']); $this->DrawGrid(); $len = strlen($this->Question); $space = $this->Image['width'] / $len; for ($p = 0; $p < 2 * $len; ++$p) { $this->Render(chr(rand(33, 126)), $p, $space / 2, $this->Colors['Disturb']); } for ($p = 0; $p < $len; ++$p) { $this->Render($this->Question[$p], $p, $space, $this->Colors['Text']); } $this->DebugLog->Write("Render done"); if (JFactory::getApplication()->input->get("noimage", NULL)) { return; } header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); header("Content-Type:image/jpeg"); header("Content-Disposition:inline ; filename=b2jcaptcha.jpg"); imagejpeg($this->Image['data']); imagedestroy($this->Image['data']); $this->DebugLog->Write("Image sent to client"); }
public function Show() { if (!(bool) $this->Params->get("uploaddisplay")) { return ""; } $id = $this->GetId(); $action = JRoute::_("index.php?option=" . $GLOBALS["com_name"] . "&view=loader" . "&owner=" . $this->Application->owner . "&id=" . $this->Application->oid . "&bid=" . $this->Application->bid . "&root=none" . "&filename=none" . "&type=uploader"); $label = ""; $span = ""; if ((bool) $this->Params->get("labelsdisplay")) { $label = '<label class="control-label">' . $this->Params->get('upload') . '</label>'; } else { $span = '<span class="help-block">' . $this->Params->get('upload') . '</span>'; } $result = '<div class="control-group">' . $label . '<div class="controls">' . $span . '<div id="b2jupload_' . $id . '"></div>' . '<span class="help-block">' . JText::_($GLOBALS["COM_NAME"] . '_FILE_SIZE_LIMIT') . " " . $this->human_readable($this->Params->get("uploadmax_file_size") * 1024) . '</span>' . '</div>' . "<script language=\"javascript\" type=\"text/javascript\">" . "jQuery(document).ready(function () {" . "if (typeof Joomla == 'undefined')" . "{" . "\tJoomla = {};" . "\tJoomla.JText =" . "\t{" . "\t\tstrings:{}," . "\t\t'_':function (key, def)" . "\t\t{" . "\t\t\treturn typeof this.strings[key.toUpperCase()] !== 'undefined' ? this.strings[key.toUpperCase()] : def;" . "\t\t}," . "\t\tload:function (object)" . "\t\t{" . "\t\t\tfor (var key in object)" . "\t\t\t{" . "\t\t\t\tthis.strings[key.toUpperCase()] = object[key];" . "\t\t\t}" . "\t\t\treturn this;" . "\t\t}" . "\t};" . "}" . "Joomla.JText.load(" . "{" . "\"COM_B2JCONTACT_BROWSE_FILES\":'" . $this->Params->get("upload_btn") . "'," . "\"JCANCEL\":'" . JText::_("JCANCEL") . "'," . "\"COM_B2JCONTACT_FAILED\":'" . JText::_("COM_B2JCONTACT_FAILED") . "'," . "\"COM_B2JCONTACT_SUCCESS\":'" . JText::_("COM_B2JCONTACT_SUCCESS") . "'," . "\"COM_B2JCONTACT_NO_RESULTS_MATCH\":'" . JText::_("COM_B2JCONTACT_NO_RESULTS_MATCH") . "'" . "}" . ");" . "CreateUploadButton('b2jupload_{$id}', '{$action}', " . $this->Application->b2jcomid . ", " . $this->Application->b2jmoduleid . ", '" . $this->Application->owner . "', " . $this->Application->oid . ");" . "ResetBind('{$id}', " . $this->Application->bid . ", " . $this->Application->b2jcomid . ", " . $this->Application->b2jmoduleid . ", '" . $this->Application->owner . "');" . "});" . "</script>" . '<noscript>' . '<input ' . 'type="file" ' . 'name="b2jstdupload"' . " />" . '</noscript>' . "</div>" . PHP_EOL; $jsession = JFactory::getSession(); $b2jsession = new B2JSession($jsession->getId(), $this->Application->b2jcomid, $this->Application->b2jmoduleid, $this->Application->bid); $data = $b2jsession->Load('filelist'); if ($data) { $filelist = explode("|", $data); } else { $filelist = array(); } $result .= '<div class="control-group">'; if ($this->Params->get("labelsdisplay") == 1) { $result .= '<label class="control-label"></label>'; } $result .= '<div class="controls">'; $result .= '<ul id="uploadlist-' . $this->Application->owner . $this->Application->oid . '" class="qq-upload-list">'; foreach ($filelist as &$file) { $result .= '<li class="qq-upload-success">' . '<span class="qq-upload-file">' . $this->format_filename(substr($file, 14)) . '</span>' . '<span class="qq-upload-success-text">' . JTEXT::_($GLOBALS["COM_NAME"] . '_SUCCESS') . ' </span>' . '</li>'; } $result .= '</ul>' . PHP_EOL; $result .= '<a href="javascript:void(0)" class="" onClick="ResetAttachments(this.parentNode.parentNode.parentNode)">' . $this->Params->get("reset_attachment_btn") . '</a>'; $result .= '</div>' . '</div>' . PHP_EOL; return $result; }
function display($tpl = null) { $this->Application = JFactory::getApplication(); $user = JFactory::getUser(); $this->cparams = $this->Application->getMenu()->getActive()->params; if ($description = $this->cparams->get('menu-meta_description')) { $this->document->setDescription($description); } if ($keywords = $this->cparams->get('menu-meta_keywords')) { $this->document->setMetadata('keywords', $keywords); } if ($robots = $this->cparams->get('robots')) { $this->document->setMetadata('robots', $robots); } $prefix = "index.php?option=" . $this->Application->scope . "&view=loader" . "&owner=" . $this->Application->owner . "&bid=" . $this->Application->bid . "&id=" . $this->Application->oid; $b2jContactModel = new B2jContactModelContact(); $b2jContactItem = $b2jContactModel->getItem($this->Application->bid, $this->cparams); $this->cparams = $b2jContactItem->params; $groups = $user->getAuthorisedViewLevels(); if (!in_array($b2jContactItem->access, $groups)) { JError::raiseWarning(403, JText::_('JERROR_ALERTNOAUTHOR')); return; } $stylesheet = "b2jcontact.css"; $css_name = preg_replace("/\\.[^.\\s]{3,4}\$/", "", $stylesheet); $this->document->addStyleSheet($prefix . "&root=components&type=css&filename=" . $css_name); $this->MessageBoard = new B2JMessageBoard(); $this->FieldsBuilder = new B2JFieldsBuilder($this->cparams, $this->MessageBoard); $this->Submitter = new B2JSubmitter($this->cparams, $this->MessageBoard, $this->FieldsBuilder); $this->AjaxUploader = new B2JAjaxUploader($this->cparams, $this->MessageBoard); $this->Uploader = new B2JUploader($this->cparams, $this->MessageBoard); $this->B2jCaptcha = new B2JCaptcha($this->cparams, $this->MessageBoard); $this->JMessenger = new B2JJMessenger($this->cparams, $this->MessageBoard, $this->FieldsBuilder); $this->Antispam = new B2JAntispam($this->cparams, $this->MessageBoard, $this->FieldsBuilder); $this->AdminMailer = new B2JAdminMailer($this->cparams, $this->MessageBoard, $this->FieldsBuilder); $this->SubmitterMailer = new B2JSubmitterMailer($this->cparams, $this->MessageBoard, $this->FieldsBuilder); $this->FormText .= $this->FieldsBuilder->Show(); $this->FormText .= $this->AjaxUploader->Show(); $this->FormText .= $this->B2jCaptcha->Show(); $this->FormText .= $this->Antispam->Show(); $this->FormText .= $this->Submitter->Show(); switch (0) { case $this->Submitter->IsValid(): break; case $this->FieldsBuilder->IsValid(): break; case $this->AjaxUploader->IsValid(): break; case $this->Uploader->IsValid(): break; case $this->B2jCaptcha->IsValid(): break; case $this->Antispam->IsValid(): break; case $this->JMessenger->Process(): break; case $this->AdminMailer->Process(): break; case $this->SubmitterMailer->Process(): break; default: $this->FormText = ""; $jsession = JFactory::getSession(); $b2jsession = new B2JSession($jsession->getId(), $this->Application->b2jcomid, $this->Application->b2jmoduleid, $this->Application->bid); $b2jsession->PurgeValue("captcha_answer"); B2JHeaderRedirect($this->cparams); } if (count($errors = $this->get('Errors'))) { $this->Application->enqueueMessage(implode('<br />', $errors), 'error'); } parent::display($tpl); }
public function HandleUpload($uploadDirectory) { $this->DebugLog->Write("HandleUpload() started"); if (!is_writable($uploadDirectory)) { $this->DebugLog->Write("Directory " . $uploadDirectory . " is not writable"); return array('error' => JFactory::getLanguage()->_($GLOBALS["COM_NAME"] . '_ERR_DIR_NOT_WRITABLE')); } $this->DebugLog->Write("Directory " . $uploadDirectory . " is ok"); $size = $this->get_file_size(); if ($size == 0) { $this->DebugLog->Write("File size is 0"); return array('error' => JFactory::getLanguage()->_($GLOBALS["COM_NAME"] . '_ERR_FILE_EMPTY')); } $this->DebugLog->Write("File size is > 0"); $max = $this->Params->get("uploadmax_file_size", 0) * KB; if ($size > $max) { $this->DebugLog->Write("File size too large ({$size} > {$max})"); return array('error' => JFactory::getLanguage()->_($GLOBALS["COM_NAME"] . '_ERR_FILE_TOO_LARGE')); } $this->DebugLog->Write("File size ({$size} / {$max}) is ok"); $filename = preg_replace("/[^\\w\\.-_]/", "_", $this->get_file_name()); $filename = uniqid() . "-" . $filename; $full_filename = $uploadDirectory . $filename; if (!$this->save_file($full_filename)) { $this->DebugLog->Write("Error saving file"); return array('error' => JFactory::getLanguage()->_($GLOBALS["COM_NAME"] . '_ERR_SAVE_FILE')); } $this->DebugLog->Write("File saved"); $mimetype = new B2JMimeType(); if (!$mimetype->Check($full_filename, $this->Params)) { unlink($full_filename); $this->DebugLog->Write("File type [" . $mimetype->Mimetype . "] is not allowed. Allowed types are:" . PHP_EOL . print_r($mimetype->Allowed, true)); return array('error' => JFactory::getLanguage()->_($GLOBALS["COM_NAME"] . '_ERR_MIME') . " [" . $mimetype->Mimetype . "]"); } $this->DebugLog->Write("File type [" . $mimetype->Mimetype . "] is allowed"); $b2jcomid = JFactory::getApplication()->input->get("b2jcomid", NULL); $b2jmoduleid = JFactory::getApplication()->input->get("b2jmoduleid", NULL); $owner = JFactory::getApplication()->input->get("owner", NULL); $id = JFactory::getApplication()->input->get("id", NULL); $bid = JFactory::getApplication()->input->get("bid", NULL); $jsession = JFactory::getSession(); $b2jsession = new B2JSession($jsession->getId(), $b2jcomid, $b2jmoduleid, $bid); $data = $b2jsession->Load('filelist'); if ($data) { $filelist = explode("|", $data); } else { $filelist = array(); } $filelist[] = $filename; $data = implode("|", $filelist); $b2jsession->Save($data, "filelist"); $this->Log->Write("File " . $filename . " uploaded succesful."); $this->DebugLog->Write("File uploaded succesful."); return array("success" => true); }
$form_text .= $ajax_uploader->Show(); $form_text .= $b2jcaptcha->Show(); $form_text .= $antispam->Show(); $form_text .= $submitter->Show(); switch (0) { case $submitter->IsValid(): break; case $fieldsBuilder->IsValid(): break; case $ajax_uploader->IsValid(): break; case $uploader->IsValid(): break; case $b2jcaptcha->IsValid(): break; case $antispam->IsValid(): break; case $jMessenger->Process(): break; case $adminMailer->Process(): break; case $submitterMailer->Process(): break; default: $form_text = ""; $jsession = JFactory::getSession(); $b2jsession = new B2JSession($jsession->getId(), 0, $module->id, $app->bid); $b2jsession->PurgeValue("captcha_answer"); B2JHeaderRedirect($params); } require JModuleHelper::getLayoutPath($app->scope, $params->get('layout', 'default'));