function upload_avatar() { $input = JFactory::getApplication()->input; $user = JFactory::getUser(); $id = $input->getInt('id', 0); $xhr = $input->server->get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'; if (!$xhr) { echo '<textarea>'; } if ($user->id != $id && !$user->authorise('core.manage')) { echo json_encode(array('error' => JText::_('JERROR_ALERTNOAUTHOR'))); } else { if (!$id) { echo json_encode(array('error' => JText::_('MSG_ERROR_PROCESSING'))); } else { $tmp_file = $input->files->get('input-avatar-image'); if ($tmp_file['error'] > 0) { echo json_encode(array('error' => JText::_('MSG_ERROR_PROCESSING'))); } else { $temp_image_path = $tmp_file['tmp_name']; $temp_image_name = $tmp_file['name']; $temp_image_ext = JFile::getExt($temp_image_name); list($temp_image_width, $temp_image_height, $temp_image_type) = getimagesize($temp_image_path); if ($temp_image_type === NULL || $temp_image_width < 128 || $temp_image_height < 128 || !in_array(strtolower($temp_image_ext), array('png', 'jpg', 'gif')) || !in_array($temp_image_type, array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF))) { echo json_encode(array('error' => JText::_('MSG_INVALID_IMAGE_FILE'))); } else { $user_profile = CjBlogApi::get_user_profile($id); $file_name = ''; if (!empty($user_profile['avatar'])) { $file_name = $user_profile['avatar']; } else { $file_name = CJFunctions::generate_random_key(25, 'abcdefghijklmnopqrstuvwxyz1234567890') . '.' . $temp_image_ext; } $uploaded_image_path = CJBLOG_AVATAR_BASE_DIR . 'original' . DS . $file_name; if (JFile::upload($temp_image_path, $uploaded_image_path)) { echo json_encode(array('avatar' => array('url' => CJBLOG_AVATAR_BASE_URI . 'original/' . $file_name, 'file_name' => $file_name, 'width' => $temp_image_width, 'height' => $temp_image_height))); } else { echo json_encode(array('error' => JText::_('MSG_ERROR_PROCESSING'))); } } } } } if (!$xhr) { echo '</textarea>'; } jexit(); }
function copy_survey($sid) { $user = JFactory::getUser(); $key = CJFunctions::generate_random_key(); $createdate = JFactory::getDate()->toSql(); $query = ' insert into #__survey( title, alias, catid, introtext, endtext, created_by, created, publish_up, publish_down, responses, private_survey, max_responses, anonymous, custom_header, public_permissions, published, survey_key, redirect_url, display_template, skip_intro, restriction, backward_navigation, display_notice, display_progress, notification ) ( select concat(title, \'_Copy\'), concat(alias, \'_copy\'), catid, introtext, endtext, ' . $user->id . ',' . $this->_db->quote($createdate) . ', publish_up, publish_down, 0, private_survey, max_responses, anonymous, custom_header, public_permissions, published, ' . $this->_db->quote($key) . ', redirect_url, display_template, skip_intro, restriction, backward_navigation, display_notice, display_progress, notification from #__survey where id = ' . $sid . ' )'; $this->_db->setQuery($query); if ($this->_db->query()) { $newid = $this->_db->insertid(); if ($newid > 0) { $query = 'select id, sort_order, title from #__survey_pages where sid = ' . $sid . ' order by sort_order'; $this->_db->setQuery($query); $pages = $this->_db->loadObjectList(); $query = ' select id, title, description, question_type, page_number, sort_order, mandatory, custom_choice, orientation from #__survey_questions where survey_id = ' . $sid; $this->_db->setQuery($query); $questions = $this->_db->loadObjectList(); if (empty($pages) || empty($questions)) { return false; } foreach ($pages as $page) { $query = 'insert into #__survey_pages (sid, sort_order, title) values (' . $newid . ',' . $page->sort_order . ',' . $this->_db->quote($page->title) . ')'; $this->_db->setQuery($query); if ($this->_db->query()) { $newpage = $this->_db->insertid(); if ($newpage <= 0) { return false; } foreach ($questions as $question) { if ($question->page_number == $page->id) { $query = ' insert into #__survey_questions( title, description, survey_id, question_type, page_number, responses, sort_order, mandatory, created_by, custom_choice, orientation) values (' . $this->_db->quote($question->title) . ',' . $this->_db->quote($question->description) . ',' . $newid . ',' . $question->question_type . ',' . $newpage . ',' . '0,' . $question->sort_order . ',' . $question->mandatory . ',' . $user->id . ',' . $question->custom_choice . ',' . $this->_db->quote($question->orientation) . ' )'; $this->_db->setQuery($query); if ($this->_db->query()) { $newqnid = $this->_db->insertid(); if ($newqnid <= 0) { return false; } $query = ' insert into #__survey_answers(survey_id, question_id, answer_type, answer_label, sort_order, image) ( select ' . $newid . ', ' . $newqnid . ', answer_type, answer_label, sort_order, image from #__survey_answers where survey_id = ' . $sid . ' and question_id = ' . $question->id . ' )'; $this->_db->setQuery($query); if (!$this->_db->query()) { return false; } $query = ' insert into #__survey_rules(survey_id, question_id, rulecontent) ( select ' . $newid . ',' . $newqnid . ', rulecontent from #__survey_rules where survey_id = ' . $sid . ' and question_id = ' . $question->id . ' )'; $this->_db->setQuery($query); if (!$this->_db->query()) { return false; } } } } } } return true; } } $this->setError($this->_db->getErrorMsg()); return false; }
function upload_answer_image() { $user = JFactory::getUser(); $xhr = $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'; if (!$xhr) { echo '<textarea>'; } if ($user->authorise('core.create', S_APP_NAME) || $user->authorise('core.manage', S_APP_NAME)) { $params = JComponentHelper::getParams(S_APP_NAME); $allowed_extensions = $params->get('allowed_image_types', 'jpg,png,gif'); $allowed_size = (int) $params->get('max_attachment_size', 256) * 1024; $input = JFactory::getApplication()->input; if (!empty($allowed_extensions)) { $tmp_file = $input->files->get('input-attachment'); if ($tmp_file['error'] > 0) { echo json_encode(array('error' => JText::_('MSG_ERROR_PROCESSING'))); } else { $temp_file_path = $tmp_file['tmp_name']; $temp_file_name = $tmp_file['name']; $temp_file_ext = JFile::getExt($temp_file_name); if (!in_array(strtolower($temp_file_ext), explode(',', strtolower($allowed_extensions)))) { echo json_encode(array('error' => JText::_('MSG_INVALID_FILETYPE'))); } else { if ($tmp_file['size'] > $allowed_size) { echo json_encode(array('error' => JText::_('MSG_MAX_SIZE_FAILURE'))); } else { $file_name = CJFunctions::generate_random_key(25, 'abcdefghijklmnopqrstuvwxyz1234567890') . '.' . $temp_file_ext; if (JFile::upload($temp_file_path, S_TEMP_STORE . DS . $file_name)) { echo json_encode(array('file_name' => $file_name, 'url' => S_TEMP_STORE_URI . $file_name)); } else { echo json_encode(array('error' => JText::_('MSG_ERROR_PROCESSING'))); } } } } } else { echo '{"file_name": null, "url": null}'; } } else { echo json_encode(array('error' => JText::_('JERROR_ALERTNOAUTHOR'))); } if (!$xhr) { echo '</textarea>'; } jexit(); }
function acymailing_replaceusertags(&$email, &$user, $send = true) { if (!$send) { return; } $match = '#{surveyurl:(.*)}#Ui'; $variables = array('body', 'altbody'); $found = false; $results = array(); foreach ($variables as $var) { if (empty($email->{$var})) { continue; } $found = preg_match_all($match, $email->{$var}, $results[$var]) || $found; if (empty($results[$var][0])) { unset($results[$var]); } } if (!$found) { return; } // CJLib includes $cjlib = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_cjlib' . DIRECTORY_SEPARATOR . 'framework.php'; if (file_exists($cjlib)) { require_once $cjlib; } else { die('CJLib (CoreJoomla API Library) component not found. Please download and install it to continue.'); } CJLib::import('corejoomla.framework.core'); $htmlreplace = array(); $textreplace = array(); $db = JFactory::getDbo(); $mailerHelper = acymailing_get('helper.mailer'); foreach ($results as $var => $allresults) { foreach ($allresults[0] as $i => $oneTag) { if (isset($htmlreplace[$oneTag])) { continue; } $start = strpos($oneTag, ':') + 1; $length = strpos($oneTag, '}') - strpos($oneTag, ':') - 1; $sid = intval(substr($oneTag, $start, $length)); if ($sid > 0) { $keys = array(); $key = CJFunctions::generate_random_key(); $query = 'insert into #__survey_keys(key_name, survey_id, response_id) values (' . $db->quote($key) . ',' . $sid . ', 0)'; $db->setQuery($query); if ($db->query()) { $itemid = CJFunctions::get_active_menu_id(); $link = JRoute::_('index.php?option=' . S_APP_NAME . '&view=survey&task=take_survey&key=' . $key . $itemid, false, -1); $link = str_replace('/administrator/', '/', $link); $link = '<a href="' . $link . '">' . $link . '</a>'; } $htmlreplace[$oneTag] = $link; $textreplace[$oneTag] = $mailerHelper->textVersion($link); } } } $email->body = str_replace(array_keys($htmlreplace), $htmlreplace, $email->body); $email->altbody = str_replace(array_keys($textreplace), $textreplace, $email->altbody); }
public static function get_cjconfig($rebuild = false) { $app = JFactory::getApplication(); $config = $app->getUserState('CJLIB_CONFIG'); if (empty($config) || $rebuild) { $db = JFactory::getDbo(); $config = array(); $query = 'select config_name, config_value from #__cjlib_config'; $db->setQuery($query); $params = $db->loadObjectList(); if (!empty($params)) { foreach ($params as $param) { $config[$param->config_name] = $param->config_value; } } else { $app = JApplication::getInstance('site'); $router = $app->getRouter(); $random = CJFunctions::generate_random_key(16); $query = "\n\t\t \tinsert into \n\t\t \t\t#__cjlib_config (config_name, config_value) \n\t\t \tvalues \n\t\t \t\t('cron_secret', " . $db->quote($random) . "),\n\t\t \t\t('manual_cron', 1),\n\t\t \t\t('cron_emails', 60),\n\t\t \t\t('cron_delay', 10) \n\t\t \ton duplicate key \n\t\t \t\tupdate config_value = values (config_value)"; $db->setQuery($query); $db->query(); $query = 'select config_name, config_value from #__cjlib_config'; $db->setQuery($query); $params = $db->loadObjectList(); foreach ($params as $param) { $config[$param->config_name] = $param->config_value; } } $app->setUserState('CJLIB_CONFIG', $config); } return $config; }