public static function get_article_thumbnail($article, $size = 256) { if (!file_exists(CJBLOG_MEDIA_DIR . 'thumbnails/' . $article->id . '_thumb.jpg')) { $params = new JRegistry(); $params->loadString($article->images); $intro = $params->get('image_intro'); $image_found = false; if (!empty($intro)) { $image_found = $intro; } else { preg_match_all('/<img .*src=["|\']([^"|\']+)/i', $article->introtext . $article->fulltext, $matches); foreach ($matches[1] as $key => $file_path) { $image_found = $file_path; break; } } if ($image_found) { $tmp = JFactory::getApplication()->getCfg('tmp_path'); $filename = str_replace(' ', '-', JFile::makeSafe(basename($image_found))); if (preg_match('/(http|https)?:\\/\\/.*$/i', strtolower($image_found))) { CjBlogHelper::fetch_image($image_found, $tmp, 'absolute', true); } else { JFile::copy($image_found, $tmp . '/' . $filename); } if (JFile::exists($tmp . '/' . $filename)) { require_once CJLIB_PATH . '/framework/class.upload.php'; $handle = new thumnail_upload($tmp . '/' . $filename); $handle->file_new_name_body = $article->id . '_thumb'; $handle->image_ratio_y = true; $handle->image_x = $size; $handle->image_resize = true; $handle->file_overwrite = true; $handle->file_auto_rename = false; $handle->image_convert = 'jpg'; $handle->jpeg_quality = 80; $handle->process(CJBLOG_MEDIA_DIR . 'thumbnails/'); // JFactory::getApplication()->enqueueMessage($handle->log); } } } return file_exists(CJBLOG_MEDIA_DIR . 'thumbnails/' . $article->id . '_thumb.jpg') ? CJBLOG_MEDIA_URI . 'thumbnails/' . $article->id . '_thumb.jpg' : CJBLOG_MEDIA_URI . 'images/' . ($size >= 160 ? 'thumbnail-big.png' : 'thumbnail-small.png'); }
function save_avatar() { $input = JFactory::getApplication()->input; $user = JFactory::getUser(); $id = $input->getInt('id', 0); $filename = $input->getString('file_name', null); $coords = $input->getString('coords', null); if ($user->id != $id && !$user->authorise('core.manage')) { echo json_encode(array('error' => JText::_('JERROR_ALERTNOAUTHOR'))); } else { $filename = JFile::makeSafe($filename); $file_path = CJBLOG_AVATAR_BASE_DIR . 'original' . DS . $filename; $coords = explode(',', $coords); $sizes = array(16, 32, 48, 64, 96, 128, 160, 192, 256); if (!$id || empty($coords) || count($coords) != 6 || empty($filename) || !JFile::exists($file_path)) { echo json_encode(array('error' => JText::_('MSG_ERROR_PROCESSING') . '| Error Code 1.')); } else { require_once CJLIB_PATH . DS . 'framework' . DS . 'class.upload.php'; list($temp_image_width, $temp_image_height, $temp_image_type) = getimagesize($file_path); foreach ($sizes as $size) { $handle = new thumnail_upload($file_path); $handle->image_precrop = array($coords[1], $temp_image_width - $coords[2], $temp_image_height - $coords[3], $coords[0]); $handle->file_overwrite = true; $handle->file_auto_rename = false; $handle->image_convert = 'jpg'; $handle->jpeg_quality = 80; $handle->image_resize = true; $handle->image_x = $size; $handle->image_y = $size; $handle->process(CJBLOG_AVATAR_BASE_DIR . 'size-' . $size . DS); if (!$handle->processed) { // echo json_encode(array('error'=>JText::_('MSG_ERROR_PROCESSING').'| Error Code 2.<br/><br/>'.$handle->log)); echo json_encode(array('error' => JText::_('MSG_ERROR_PROCESSING') . '| Error Code 2.')); jexit(); } } $new_file = JFile::stripExt($filename) . '.jpg'; $model = $this->getModel('users'); if ($model->save_user_avatar_name($id, $new_file)) { JFile::delete($file_path); echo json_encode(array('src' => CJBLOG_AVATAR_BASE_URI . 'size-256/' . $new_file)); } else { echo json_encode(array('error' => JText::_('MSG_ERROR_PROCESSING') . '| Error Code 3.' . $model->getError())); } } } jexit(); }