public function rebuildCommentTree() { $model = $this->getModel(); JUDownloadHelper::obCleanData(); echo $model->rebuildCommentTree(); exit; }
public function changeTemplateId() { $app = JFactory::getApplication(); $jInput = $app->input; $templateId = $jInput->post->getInt("value"); $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('parent_id'); $query->from('#__judownload_templates'); $query->where('id = ' . $templateId); $db->setQuery($query); $templateParentId = $db->loadResult(); $query = $db->getQuery(true); $query->select('*'); $query->select('title AS text'); $query->select('id AS value'); $query->from('#__judownload_template_styles'); $query->where('template_id =' . $templateParentId); $query->order('lft ASC'); $db->setQuery($query); $styleObjectList = $db->loadObjectList(); $html = ""; $html .= "<option value=\"\">" . JText::_('COM_JUDOWNLOAD_SELECT_PARENT_TEMPLATE') . "</option>"; if (!empty($styleObjectList)) { foreach ($styleObjectList as $styleObject) { $html .= "<option value=\"" . $styleObject->value . "\">" . $styleObject->text . "</option>"; } } JUDownloadHelper::obCleanData(); echo $html; exit; }
public static function captchaSecurityImages($namespace = null) { $secureImage = JUDownloadFrontHelperCaptcha::initCaptcha($namespace); JUDownloadHelper::obCleanData(); $secureImage->show(); $secureImage->getCode(); }
public function docChangeCategory() { $model = $this->getModel(); $data = $model->docChangeCategory(); JUDownloadHelper::obCleanData(); echo $data; exit; }
public function docChangeCategory() { require_once JPATH_ADMINISTRATOR . '/components/com_judownload/models/category.php'; JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_judownload/models'); $backendCategoryModel = JModelLegacy::getInstance('Category', 'JUDownloadModel'); $data = $backendCategoryModel->docChangeCategory(); JUDownloadHelper::obCleanData(); echo $data; exit(); }
public function getChartData() { $app = JFactory::getApplication(); $type = $app->input->get('type'); $model = $this->getModel(); $data = $model->getUploadDownloadData($type); $app = JFactory::getApplication(); $app->setUserState('com_judownload.dashboard.chart.type', $type); JUDownloadHelper::obCleanData(); echo json_encode($data); exit; }
public function voteComment($commentId) { $commentObj = JUDownloadFrontHelperComment::getCommentObject($commentId); if (!$commentObj) { return; } $vote_up = JFactory::getApplication()->input->getInt('vote_up', 0); $helpful_votes = intval($commentObj->helpful_votes); $total_votes = intval($commentObj->total_votes); $params = JUDownloadHelper::getParams(null, $commentObj->doc_id); $allow_vote_down_comment = $params->get('allow_vote_down_comment', 1); if (!$allow_vote_down_comment) { $like_system = true; if ($vote_up != 1) { $voteType = 0; $reference = 'unlike'; $total_votes--; $helpful_votes--; } else { $voteType = 1; $reference = 'like'; $total_votes++; $helpful_votes++; } } else { $like_system = false; if ($vote_up != 1) { $voteType = -1; $reference = 'vote_down'; $total_votes++; } else { $voteType = 1; $reference = 'vote_up'; $total_votes++; $helpful_votes++; } } $votedValue = $this->getCommentVotedValue($commentObj->id); if (($allow_vote_down_comment && $votedValue) || ($votedValue == $voteType)) { $return = array(); $return['message'] = JText::_('COM_JUDOWNLOAD_VOTING_ERROR'); $return['like_system'] = $like_system; $return['vote_type'] = null; JUDownloadHelper::obCleanData(); echo json_encode($return); exit(); } $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->update('#__judownload_comments') ->set('helpful_votes = ' . $helpful_votes) ->set('total_votes = ' . $total_votes) ->where('id = ' . $commentObj->id); $db->setQuery($query); if ($db->execute()) { $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('judownload'); $dispatcher->trigger('onVoteComment', $commentObj, $like_system, $voteType); $user = JFactory::getUser(); $userId = $user->id; $logData = array( 'user_id' => $user->id, 'event' => 'comment.vote', 'item_id' => $commentObj->id, 'doc_id' => $commentObj->doc_id, 'value' => $voteType, 'reference' => $reference ); JUDownloadFrontHelperLog::addLog($logData); if ($userId > 0) { $cookieName = 'judl-comment-vote-' . $commentObj->id . '_' . $userId; } else { $ipAddress = JUDownloadFrontHelper::getIpAddress(); $ipAddress = str_replace('.', '_', $ipAddress); $cookieName = 'judl-comment-vote-' . $commentObj->id . '_' . $ipAddress; } $config = JFactory::getConfig(); $cookie_domain = $config->get('cookie_domain', ''); $cookie_path = $config->get('cookie_path', '/'); setcookie($cookieName, $voteType, time() + 60 * 60 * 24 * 30, $cookie_path, $cookie_domain); $return = array(); $return['message'] = JText::sprintf('COM_JUDOWNLOAD_N_HELPFUL_VOTES_N_TOTAL_VOTES', $helpful_votes, $total_votes); $return['like_system'] = $like_system; $return['vote_type'] = $voteType; } else { $return = array(); $return['message'] = JText::_('COM_JUDOWNLOAD_VOTING_ERROR'); $return['like_system'] = $like_system; $return['vote_type'] = null; } JUDownloadHelper::obCleanData(); echo json_encode($return); exit(); }
public function updateComment() { JSession::checkToken() or die(JText::_('JINVALID_TOKEN')); $user = JFactory::getUser(); $model = $this->getModel(); $app = JFactory::getApplication(); $data = $app->input->getArray($_POST); $documentId = $data['doc_id']; $commentId = $data['comment_id']; $canEditComment = JUDownloadFrontHelperPermission::canEditComment($commentId); $redirectUrl = JRoute::_(JUDownloadHelperRoute::getDocumentRoute($documentId) . '#comment-item-' . $commentId); if (!$canEditComment) { $this->setMessage(JText::_('COM_JUDOWNLOAD_UPDATE_COMMENT_ERROR')); $this->setRedirect($redirectUrl); return false; } $params = JUDownloadHelper::getParams(null, $documentId); $ratingValue = $this->validateCriteria($data); if ($ratingValue) { $data = array_merge($data, $ratingValue); } else { $this->setMessage(JText::_('COM_JUDOWNLOAD_UPDATE_COMMENT_ERROR')); $this->setRedirect($redirectUrl); return false; } JUDownloadHelper::obCleanData(); if ($model->updateComment($data, $params)) { $logData = array( 'user_id' => $user->id, 'event' => 'comment.edit', 'item_id' => $commentId, 'doc_id' => $documentId, 'value' => 0, 'reference' => '', ); JUDownloadFrontHelperLog::addLog($logData); $this->setMessage(JText::_('COM_JUDOWNLOAD_UPDATE_COMMENT_SUCCESSFULLY')); $this->setRedirect($redirectUrl); return true; } else { $this->setMessage(JText::_('COM_JUDOWNLOAD_UPDATE_COMMENT_ERROR')); $this->setRedirect($redirectUrl); return false; } }
public function testPhpCode() { JSession::checkToken() or die(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); $field_id = $app->input->post->getInt('field_id', 0); $plugin_id = $app->input->post->getInt('plugin_id', 0); $php_code = $app->input->post->get('php_predefined_values', '', 'raw'); if (trim($php_code)) { if ($plugin_id) { $db = JFactory::getDbo(); $query = "SELECT folder FROM #__judownload_plugins WHERE id = " . $plugin_id; $db->setQuery($query); $folder = $db->loadResult(); $fieldClassName = 'JUDownloadField' . $folder; if ($field_id) { $fieldObj = new $fieldClassName($field_id); } else { $fieldObj = new $fieldClassName(); } } else { echo 'No plugin selected'; exit; } $fieldObj->php_predefined_values = $php_code; JUDownloadHelper::obCleanData(true); $result = $fieldObj->getPredefinedFunction(); echo '<div class="return">'; var_dump($result); echo '</div>'; } exit; }
public function checkInheritedDataWhenChangeParentCat() { $app = JFactory::getApplication(); $model = $this->getModel(); $jInput = $app->input; $data = array(); $data['id'] = $jInput->post->getInt('id'); $data['parent_id'] = $jInput->post->getInt('parent_id'); $data['selected_fieldgroup'] = $jInput->post->getInt('selected_fieldgroup'); $data['selected_criteriagroup'] = $jInput->post->getInt('selected_criteriagroup'); $data['style_id'] = $jInput->post->getInt('style_id'); $result = $model->checkInheritedDataWhenChangeParentCat($data); JUDownloadHelper::obCleanData(); $result = json_encode($result); echo $result; exit; }
public function changeBLVorder() { JSession::checkToken() or die(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); $id = $app->input->getInt('id', 0); $value = $app->input->getInt('value', 0); $data = array(0, 1, 2); $value = JArrayHelper::getValue($data, $value, 0, 'int'); if (!$id) { die; } $model = $this->getModel(); $result = $model->changeBLVorder($id, $value); JUDownloadHelper::obCleanData(); if ($result) { echo $result; } exit; }
public static function downloadFile($file, $fileName, $transport = 'php', $speed = 50, $resume = true, $downloadMultiParts = true, $mimeType = false) { if (ini_get('zlib.output_compression')) { @ini_set('zlib.output_compression', 'Off'); } if (function_exists('apache_setenv')) { apache_setenv('no-gzip', '1'); } $agent = isset($_SERVER['HTTP_USER_AGENT']) ? trim($_SERVER['HTTP_USER_AGENT']) : null; if ($agent && preg_match('#(?:MSIE |Internet Explorer/)(?:[0-9.]+)#', $agent) && (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')) { header('Pragma: '); header('Cache-Control: '); } else { header('Pragma: no-store,no-cache'); header('Cache-Control: no-cache, no-store, must-revalidate, max-age=-1'); header('Cache-Control: post-check=0, pre-check=0', false); } header('Expires: Mon, 14 Jul 1789 12:30:00 GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); if (is_resource($file) && get_resource_type($file) == "stream") { $transport = 'php'; } elseif (!JFile::exists($file)) { return JText::sprintf("COM_JUDOWNLOAD_FILE_NOT_FOUND_X", $fileName); } $transport = 'php'; if ($transport != 'php') { header('Content-Description: File Transfer'); header('Date: ' . @gmdate("D, j M m Y H:i:s ") . 'GMT'); if ($resume) { header('Accept-Ranges: bytes'); } elseif (isset($_SERVER['HTTP_RANGE'])) { exit; } if (!$downloadMultiParts) { header('Accept-Ranges: none'); } header('Content-Type: application/force-download'); header('Content-Disposition: attachment; filename="' . $fileName . '"'); } switch ($transport) { case 'php': default: JLoader::register('JUDownload', JPATH_ADMINISTRATOR . '/components/com_judownload/helpers/judownload.class.php'); JUDownloadHelper::obCleanData(); $download = new JUDownload($file); $download->rename($fileName); if ($mimeType) { $download->mime($mimeType); } if ($resume) { $download->resume(); } $download->speed($speed); $download->start(); if ($download->error) { return $download->error; } unset($download); break; } return true; }
public function checkPasswordAjax() { JSession::checkToken('request') or die(JText::_('JINVALID_TOKEN')); $model = $this->getModel(); $app = JFactory::getApplication(); $documentId = $app->input->post->getInt('doc_id', 0); $password = $app->input->post->get('download_password', null, null); if (($documentId > 0) && $password) { $session = JFactory::getSession(); $timeNow = JFactory::getDate()->toSql(); $timeNowStamp = strtotime($timeNow); $params = JUDownloadHelper::getParams(null, $documentId); $blockEnterPasswordTime = $params->get('block_enter_password_time', 600); $maxWrongPasswordTimes = $params->get('max_wrong_password_times', 5); if ($maxWrongPasswordTimes < 1) { $maxWrongPasswordTimes = 1; } $ss_wrongPasswordTimes = 'judl-wrong-password-' . $documentId; $ss_blockDownloadTime = 'judl-block-download-time-' . $documentId; $wrongPasswordTimes = $session->get($ss_wrongPasswordTimes, 0); if ($wrongPasswordTimes >= $maxWrongPasswordTimes) { if ($blockEnterPasswordTime == 0) { $passwordStatus = -1; } else { $lastTime = $session->get($ss_blockDownloadTime, 0); $interval = $timeNowStamp - $lastTime; if ($interval >= 0) { if ($interval <= $blockEnterPasswordTime) { $passwordStatus = -1; } else { $session->clear($ss_wrongPasswordTimes); $session->clear($ss_blockDownloadTime); $checkPassword = $model->checkPassword($documentId, $password); if (!$checkPassword) { $passwordStatus = 0; } else { $passwordStatus = 1; } } } else { $session->clear($ss_wrongPasswordTimes); $session->clear($ss_blockDownloadTime); $passwordStatus = ''; } } } else { $checkPassword = $model->checkPassword($documentId, $password); if (!$checkPassword) { $passwordStatus = 0; } else { $passwordStatus = 1; } } } else { $passwordStatus = ''; } if ($passwordStatus == 1) { $html = '<div class="alert alert-success">'; $html .= '<button type="button" class="close" data-dismiss="alert">×</button>'; $html .= JText::_('COM_JUDOWNLOAD_VALID_PASSWORD'); $html .= '</div>'; $token = JSession::getFormToken(); $link = JRoute::_('index.php?option=com_judownload&task=download.download&doc_id=' . $documentId . '&' . $token . '=1', false); $documentObject = JUDownloadHelper::getDocumentById($documentId); $result = array('status' => '1', 'message' => $html, 'link' => $link, 'id' => $documentObject->id, 'title' => $documentObject->title, 'downloads' => $documentObject->downloads); } elseif ($passwordStatus == 0) { $wrongPasswordTimes = $session->get($ss_wrongPasswordTimes, 0); $html = '<div class="alert alert-error">'; $html .= '<button type="button" class="close" data-dismiss="alert">×</button>'; $html .= JText::plural('COM_JUDOWNLOAD_YOU_HAVE_ENTERED_WRONG_PASSWORD_N_TIMES_PLEASE_TRY_AGAIN', $wrongPasswordTimes); $html .= '</div>'; $result = array('status' => '0', 'message' => $html); } elseif ($passwordStatus == -1) { $html = '<div class="alert alert-error">'; $html .= '<button type="button" class="close" data-dismiss="alert">×</button>'; if ($blockEnterPasswordTime == 0) { $html .= JText::plural('COM_JUDOWNLOAD_YOU_HAVE_ENTERED_WRONG_PASSWORD_OVER_MAX_N_TIMES_YOU_HAVE_BEEN_LOCKED_OUT', $maxWrongPasswordTimes); } else { $html .= JText::plural('COM_JUDOWNLOAD_YOU_HAVE_ENTERED_WRONG_PASSWORD_OVER_MAX_N_TIMES_YOU_HAVE_BEEN_LOCKED_OUT_FOR_N_SECONDS', $maxWrongPasswordTimes, $blockEnterPasswordTime); } $html .= '</div>'; $result = array('status' => '-1', 'message' => $html); } else { $result = null; } JUDownloadHelper::obCleanData(); $result = json_encode($result); echo $result; exit; }
public function getGroupIdsByCats() { $db = JFactory::getDbo(); $app = JFactory::getApplication(); $cats = $app->input->get('cats', array(), 'array'); $groupIds = array(); foreach ($cats as $cat) { $db->setQuery("SELECT fieldgroup_id FROM #__judownload_categories WHERE id = " . $cat); if ($db->loadResult()) { $groupIds[] = $db->loadResult(); } } $groupIds = array_unique($groupIds); JUDownloadHelper::obCleanData(); echo json_encode($groupIds); exit; }
public function checkDeleteTemplateHasChild() { $app = JFactory::getApplication(); $jInput = $app->input; $result = array('status' => 0, 'message' => ''); $data = $jInput->post->get("pluginIDs", array(), 'array'); $dataTemplateId = array(); $dataTemplateTree = array(); foreach ($data as $pluginId) { $templateId = $this->getTemplateId($pluginId); if ($templateId) { $dataTemplateId[] = $templateId; } } $dataTemplateId = array_unique($dataTemplateId); foreach ($dataTemplateId as $templateId) { $dataTemplateTree = array_merge($dataTemplateTree, $this->getChildTemplateIdByTree($templateId)); $dataTemplateTree = array_unique($dataTemplateTree); } $dataTemplateTree = array_unique($dataTemplateTree); if (!empty($dataTemplateId) && !empty($dataTemplateTree)) { if (implode(',', $dataTemplateId) != implode(',', $dataTemplateTree)) { $result['status'] = 1; $dataMessage = array(); if (is_array($dataTemplateTree) && count($dataTemplateTree)) { $dataTemplateTreeString = implode(',', $dataTemplateTree); $dataMessage = $this->orderTemplateTreeBeforeDelete($dataTemplateTreeString); } $html = '<div class="alert alert-warning">' . JText::_('COM_JUDOWNLOAD_DELETE_TEMPLATE_WARNING_MESSAGE') . '</div>'; $html .= '<table class="table table-condensed">'; $html .= '<thead>'; $html .= '<tr>'; $html .= '<th>' . JText::_('COM_JUDOWNLOAD_TEMPLATE_ID') . '</th>'; $html .= '<th>' . JText::_('COM_JUDOWNLOAD_TEMPLATE_TITLE') . '</th>'; $html .= '</tr>'; $html .= '</thead>'; $html .= '<tbody>'; foreach ($dataMessage as $element) { $html .= '<tr>'; $html .= '<td>' . $element->id . '</td>'; $html .= '<td>' . str_repeat('<span class="gi">—</span>', $element->level - 1) . ' ' . ucfirst($element->title) . '</td>'; $html .= '</tr>'; } $html .= '</tbody>'; $html .= '</table>'; $result['message'] = $html; } } JUDownloadHelper::obCleanData(); $result = json_encode($result); echo $result; exit; }
$app = JFactory::getApplication(); $task = $app->input->get('task'); switch ($task) { case 'captcha': $namespace = $app->input->getString('captcha_namespace', ''); JUDownloadFrontHelperCaptcha::captchaSecurityImages($namespace); exit; break; case 'rawdata': $field_id = $app->input->getInt('field_id', 0); $doc_id = $app->input->getInt('doc_id', 0); $fieldObj = JUDownloadFrontHelperField::getField($field_id, $doc_id); JUDownloadHelper::obCleanData(); $fieldObj->getRawData(); exit; break; case 'cron': JUDownloadFrontHelperMail::sendMailq(); exit; break; default: $controller = JControllerLegacy::getInstance('judownload'); $controller->execute($app->input->get('task'));
public function remoteFile() { $app = JFactory::getApplication(); if (!$this->isValidUploadURL() || !JUDownloadFrontHelperPermission::canUploadFromUrl($app->input->get('doc_id', null))) { $result = array(); $result['success'] = 0; $result['alert'] = JText::_('COM_JUDOWNLOAD_YOU_ARE_NOT_AUTHORIZED_TO_UPLOAD_FILE'); JUDownloadHelper::obCleanData(); echo json_encode($result); exit; } $type = $app->input->get('type', ''); $result = array(); $file_directory = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("file_directory", "media/com_judownload/files/"); $file_directory_tmp = $file_directory . "tmp/"; if (!JFolder::exists($file_directory_tmp)) { JFolder::create($file_directory_tmp); $file_index = $file_directory_tmp . 'index.html'; $buffer = "<!DOCTYPE html><title></title>"; JFile::write($file_index, $buffer); } if (!is_writable($file_directory_tmp)) { $file_directory_tmp = sys_get_temp_dir() . "/plupload/"; } if ($type === 'loadtransfer') { $source_url = $app->input->get('source_url', '', 'string'); if (!$source_url) { $result['success'] = 0; $result['alert'] = JText::_('COM_JUDOWNLOAD_SOURCE_URL_IS_MISSING'); } $file = $this->loadTransfer($source_url); if ($file) { $file_name = end(explode("/", $source_url)); $file_extension = end(explode(".", $file_name)); do { $target_name = md5(JUDownloadHelper::generateRandomString(10)) . "." . $file_extension; } while (JFile::exists($file_directory_tmp . $target_name)); $result['success'] = 1; $result['size'] = (int) $file[1]; $result['type'] = (string) $file[2]; $result['name'] = $file_name; $result['target_name'] = $target_name; } else { $result['success'] = 0; $result['alert'] = JText::_('COM_JUDOWNLOAD_INVALID_FILE'); } } elseif ($type === 'transferfile') { $target_name = $app->input->get('target_name', '', 'string'); $source_url = $app->input->get('source_url', '', 'string'); if (!$source_url) { $result['success'] = 0; $result['alert'] = JText::_('COM_JUDOWNLOAD_INVALID_SOURCE_URL'); } elseif (!$target_name) { $result['success'] = 0; $result['alert'] = JText::_('COM_JUDOWNLOAD_INVALID_TARGET_NAME'); } elseif ($this->remoteDownload($source_url, $file_directory_tmp . $target_name, 1024)) { $result['success'] = 1; $result['alert'] = JText::_('COM_JUDOWNLOAD_DOWNLOAD_REMOTE_FILE_SUCCESSFULLY'); } else { $result['success'] = 0; $result['alert'] = JText::_('COM_JUDOWNLOAD_FAIL_TO_DOWNLOAD_REMOTE_FILE'); } } elseif ($type === 'getprocess') { $target_name = $app->input->get('target_name', '', 'string'); $file_size = $app->input->getInt('file_size', 0); $current_size = filesize($file_directory_tmp . $target_name); if ($current_size === false || !$file_size) { $result['success'] = 0; $result['alert'] = JText::_('COM_JUDOWNLOAD_FAIL_TO_GET_FILE_TRANSFER_STATUS'); } else { if ($current_size >= $file_size) { $percent = 100; } else { $percent = round($current_size / $file_size * 100); } $result['success'] = 1; $result['alert'] = ''; $result['percent'] = $percent; } } if ($type === 'cancel') { $target_name = $app->input->get('target_name', '', 'string'); if (JFile::exists($file_directory_tmp . $target_name)) { JFile::delete($file_directory_tmp . $target_name); } } JUDownloadHelper::obCleanData(); echo json_encode($result); exit; }
public function uploader() { $model = $this->getModel(); if (!$model->isValidUploadURL()) { die(json_encode(array( 'OK' => 0, 'error' => array( 'code' => -1, 'message' => JText::_('COM_JUDOWNLOAD_YOU_ARE_NOT_AUTHORIZED_TO_UPLOAD_FILE') ) ))); } JUDownloadHelper::obCleanData(); $model->uploader(); }