public static function fallback($root, $imageVars, $textVars = array())
 {
     $return = '';
     if (is_array($imageVars)) {
         foreach ($imageVars as $image) {
             if (!empty($image)) {
                 $return = N2ImageHelper::dynamic($root . $image);
                 break;
             }
         }
         if ($return == '' && !empty($textVars)) {
             foreach ($textVars as $text) {
                 $imageInText = self::findImage($text);
                 if (!empty($imageInText)) {
                     $return = N2ImageHelper::dynamic($root . $imageInText);
                     if ($return != '$/') {
                         break;
                     } else {
                         $return = '';
                     }
                 }
             }
         }
         if ($return != '') {
             if (strpos($return, '$/http:') !== false || strpos($return, '$/https:') !== false) {
                 $return = substr($return, 2);
             } else {
                 if (strpos($return, '$http:') !== false || strpos($return, '$https:') !== false || strpos($return, '$//') !== false) {
                     $return = substr($return, 1);
                 }
             }
         }
     }
     return $return;
 }
Beispiel #2
0
 public function actionSaveImage()
 {
     $this->validateToken();
     N2Loader::import('libraries.image.aviary');
     $image = N2Request::getVar('aviaryUrl');
     $this->validateVariable(!empty($image), 'image');
     require_once dirname(__FILE__) . '/Browse.php';
     $root = N2Filesystem::getImagesFolder();
     $folder = 'aviary';
     $path = N2Filesystem::realpath($root . '/' . $folder);
     if ($path === false || $path == '') {
         N2Filesystem::createFolder($root . '/' . $folder);
         $path = N2Filesystem::realpath($root . '/' . $folder);
     }
     $tmp = tempnam(sys_get_temp_dir(), 'image-');
     file_put_contents($tmp, file_get_contents($image));
     $src = null;
     // Set variables for storage
     // fix file filename for query strings
     preg_match('/([^\\?]+)\\.(jpe?g|gif|png)\\b/i', $image, $matches);
     $file_array['name'] = basename($matches[1]);
     $file_array['tmp_name'] = $tmp;
     $file_array['size'] = filesize($tmp);
     $file_array['error'] = 0;
     try {
         $fileName = preg_replace('/[^a-zA-Z0-9_-]/', '', $file_array['name']);
         $upload = new N2BulletProof();
         $file = $upload->uploadDir($path)->upload($file_array, $fileName);
         $src = N2ImageHelper::dynamic(N2Filesystem::pathToAbsoluteURL($file));
     } catch (Exception $e) {
         N2Message::error($e->getMessage());
         $this->response->error();
     }
     if ($src) {
         $this->response->respond(array('image' => $src));
     } else {
         N2Message::error(sprintf(n2_('Unexpected error: %s'), $image));
         $this->response->error();
     }
 }
Beispiel #3
0
 private static function _search($keyword = '')
 {
     $result = array();
     require_once JPATH_ROOT . '/components/com_content/helpers/route.php';
     require_once JPATH_ADMINISTRATOR . '/components/com_content/models/articles.php';
     $a = new ContentModelArticles();
     $db = $a->getDbo();
     $query = $db->getQuery(true);
     // Select the required fields from the table.
     $query->select($a->getState('list.select', 'a.id, a.title, a.introtext, a.images, a.alias, a.catid, a.language'));
     $query->from('#__content AS a');
     // Join over the categories.
     $query->select('c.title AS category_title')->join('LEFT', '#__categories AS c ON c.id = a.catid');
     if (!empty($keyword)) {
         if (stripos($keyword, 'id:') === 0) {
             $query->where('a.id = ' . (int) substr($keyword, 3));
         } elseif (stripos($keyword, 'author:') === 0) {
             $keyword2 = $db->quote('%' . $db->escape(substr($keyword, 7), true) . '%');
             $query->where('(ua.name LIKE ' . $keyword2 . ' OR ua.username LIKE ' . $keyword2 . ')');
         } else {
             $keyword2 = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($keyword), true) . '%'));
             $query->where('(a.title LIKE ' . $keyword2 . ' OR a.alias LIKE ' . $keyword2 . ')');
         }
     }
     $db->setQuery($query, 0, 10);
     $articles = $db->loadAssocList();
     foreach ($articles as $article) {
         $images = new N2Data($article['images'], true);
         $image = $images->get('image_fulltext', $images->get('image_intro', ''));
         if (substr($image, 0, 2) != '//' && substr($image, 0, 4) != 'http') {
             $image = JUri::root(false) . $image;
         }
         $result[] = array('title' => $article['title'], 'description' => $article['introtext'], 'image' => N2ImageHelper::dynamic($image), 'link' => ContentHelperRoute::getArticleRoute($article['id'], $article['catid'], $article['language']), 'info' => $article['category_title']);
     }
     if (count($result) == 0 && !empty($keyword)) {
         return self::_search();
     }
     return $result;
 }
Beispiel #4
0
 public function getRow()
 {
     $this->fillParameters();
     return array('title' => $this->getTitle(), 'slide' => $this->getFilledSlide(), 'description' => $this->getDescription(), 'thumbnail' => N2ImageHelper::dynamic($this->getThumbnail()), 'published' => $this->published, 'publish_up' => $this->publish_up, 'publish_down' => $this->publish_down, 'first' => $this->first, 'params' => $this->parameters->toJSON(), 'slider' => $this->slider, 'ordering' => $this->ordering, 'generator_id' => 0);
 }
Beispiel #5
0
 public static function scaleImage($group, $imageUrl, $scale = 1, $resizeRemote = false)
 {
     $originalImageUrl = $imageUrl;
     $imageUrl = N2ImageHelper::fixed($imageUrl);
     if ($scale > 0 && function_exists('exif_imagetype') && function_exists('imagecreatefrompng')) {
         if (substr($imageUrl, 0, 2) == '//') {
             $imageUrl = parse_url(N2Uri::getBaseuri(), PHP_URL_SCHEME) . ':' . $imageUrl;
         }
         $imageUrl = N2Uri::relativetoabsolute($imageUrl);
         $imagePath = N2Filesystem::absoluteURLToPath($imageUrl);
         $cache = new self($group);
         if ($imagePath == $imageUrl) {
             // The image is not local
             if (!$resizeRemote) {
                 return $originalImageUrl;
             }
             $pathInfo = pathinfo(parse_url($imageUrl, PHP_URL_PATH));
             $extension = self::validateExtension($pathInfo['extension']);
             if (!$extension) {
                 return $originalImageUrl;
             }
             return N2ImageHelper::dynamic(N2Filesystem::pathToAbsoluteURL($cache->makeCache($extension, array($cache, '_scaleRemoteImage'), array($extension, $imageUrl, $scale))));
         } else {
             $extension = false;
             $imageType = @exif_imagetype($imagePath);
             switch ($imageType) {
                 case IMAGETYPE_JPEG:
                     $extension = 'jpg';
                     break;
                 case IMAGETYPE_PNG:
                     $extension = 'png';
                     $fp = fopen($imagePath, 'r');
                     fseek($fp, 25);
                     $data = fgets($fp, 2);
                     fclose($fp);
                     if (ord($data) == 3) {
                         // GD cannot resize palette PNG so we return the original image
                         return $originalImageUrl;
                     }
                     break;
             }
             if (!$extension) {
                 throw new Exception('Filtype of the image is not supported: #' . $imageType . ' code  ' . $imagePath);
             }
             return N2ImageHelper::dynamic(N2Filesystem::pathToAbsoluteURL($cache->makeCache($extension, array($cache, '_scaleImage'), array($extension, $imagePath, $scale, filemtime($imagePath)))));
         }
     }
 }
Beispiel #6
0
 function parseValue($image)
 {
     return N2ImageHelper::dynamic($image);
 }
Beispiel #7
0
 public function actionUpload()
 {
     if (defined('N2_IMAGE_UPLOAD_DISABLE')) {
         N2Message::error(n2_('You are not allowed to upload!'));
         $this->response->error();
     }
     $this->validateToken();
     $root = N2Filesystem::getImagesFolder();
     $folder = ltrim(rtrim(N2Request::getVar('path', ''), '/'), '/');
     $path = N2Filesystem::realpath($root . '/' . $folder);
     if ($path === false || $path == '') {
         $folder = preg_replace("/[^A-Za-z0-9]/", '', $folder);
         if (empty($folder)) {
             N2Message::error(n2_('Folder is missing!'));
             $this->response->error();
         } else {
             N2Filesystem::createFolder($root . '/' . $folder);
             $path = N2Filesystem::realpath($root . '/' . $folder);
         }
     }
     $relativePath = $this->relative($path, $root);
     if (!$relativePath) {
         $relativePath = '';
     }
     $response = array('path' => $relativePath);
     try {
         if (isset($_FILES) && isset($_FILES['image']) && isset($_FILES['image']['name'])) {
             $info = pathinfo($_FILES['image']['name']);
             $fileName = preg_replace('/[^a-zA-Z0-9_-]/', '', $info['filename']);
             if (strlen($fileName) == 0) {
                 $fileName = '';
             }
             $upload = new N2BulletProof();
             $file = $upload->uploadDir($path)->upload($_FILES['image'], $fileName);
             $response['name'] = basename($file);
             $response['url'] = N2ImageHelper::dynamic(N2Filesystem::pathToAbsoluteURL($file));
         }
     } catch (Exception $e) {
         N2Message::error($e->getMessage());
         $this->response->error();
     }
     $this->response->respond($response);
 }
Beispiel #8
0
 public function import($filePathOrData, $imageImportMode = 'clone', $linkedVisuals = 1, $isFilePath = true)
 {
     $zip = new N2ZipRead();
     $importData = $zip->read_zip($filePathOrData, $isFilePath);
     if (!isset($importData['data'])) {
         if (array_key_exists("slider.ss2", $importData)) {
             N2Message::error(n2_('You can\'t import sliders from Smart Slider 2.'));
         }
         return false;
     }
     $this->backup = unserialize($importData['data']);
     $this->sectionTranslation = array();
     $this->importVisuals($this->backup->visuals, $linkedVisuals);
     $sliderModel = new N2SmartsliderSlidersModel();
     if ($this->restore) {
         $this->sliderId = $sliderModel->restore($this->backup->slider);
     } else {
         $this->sliderId = $sliderModel->import($this->backup->slider);
     }
     if (!$this->sliderId) {
         return false;
     }
     switch ($imageImportMode) {
         case 'clone':
             $images = $importData['images'];
             $imageStore = new N2StoreImage('slider' . $this->sliderId, true);
             foreach ($images as $file => $content) {
                 $localImage = $imageStore->makeCache($file, $content);
                 if ($localImage) {
                     $this->imageTranslation[$file] = N2ImageHelper::dynamic(N2Uri::pathToUri($localImage));
                 } else {
                     $this->imageTranslation[$file] = $file;
                 }
                 if (!$this->imageTranslation[$file]) {
                     $this->imageTranslation[$file] = array_search($file, $this->backup->imageTranslation);
                 }
             }
             break;
         case 'update':
             $keys = array_keys($this->backup->NextendImageHelper_Export);
             $values = array_values($this->backup->NextendImageHelper_Export);
             foreach ($this->backup->imageTranslation as $image => $value) {
                 $this->imageTranslation[$value] = str_replace($keys, $values, $image);
             }
             break;
         default:
             break;
     }
     foreach ($this->backup->NextendImageManager_ImageData as $image => $data) {
         $data['tablet']['image'] = $this->fixImage($data['tablet']['image']);
         $data['mobile']['image'] = $this->fixImage($data['mobile']['image']);
         N2ImageManager::addImageData($this->fixImage($image), $data);
     }
     unset($importData);
     if (empty($this->backup->slider['type'])) {
         $this->backup->slider['type'] = 'simple';
     }
     $class = 'N2SSPluginType' . $this->backup->slider['type'];
     N2Loader::importPath(call_user_func(array($class, "getPath")) . NDS . 'backup');
     $class = 'N2SmartSliderBackup' . $this->backup->slider['type'];
     call_user_func_array(array($class, 'import'), array($this, &$this->backup->slider));
     $enabledWidgets = array();
     $plugins = array();
     N2Plugin::callPlugin('sswidget', 'onWidgetList', array(&$plugins));
     $params = $this->backup->slider['params'];
     foreach ($plugins as $k => $v) {
         $widget = $params->get('widget' . $k);
         if ($widget && $widget != 'disabled') {
             $enabledWidgets[$k] = $widget;
         }
     }
     foreach ($enabledWidgets as $k => $v) {
         $class = 'N2SSPluginWidget' . $k . $v;
         if (class_exists($class, false)) {
             $params->fillDefault(call_user_func(array($class, 'getDefaults')));
             call_user_func_array(array($class, 'prepareImport'), array($this, $params));
         } else {
             unset($enabledWidgets);
         }
     }
     $sliderModel->importUpdate($this->sliderId, $params);
     $generatorTranslation = array();
     N2Loader::import("models.generator", "smartslider");
     $generatorModel = new N2SmartsliderGeneratorModel();
     foreach ($this->backup->generators as $generator) {
         $generatorTranslation[$generator['id']] = $generatorModel->import($generator);
     }
     $slidesModel = new N2SmartsliderSlidesModel();
     for ($i = 0; $i < count($this->backup->slides); $i++) {
         $slide = $this->backup->slides[$i];
         $slide['params'] = new N2Data($slide['params'], true);
         $slide['thumbnail'] = $this->fixImage($slide['thumbnail']);
         $slide['params']->set('backgroundImage', $this->fixImage($slide['params']->get('backgroundImage')));
         $slide['params']->set('link', $this->fixLightbox($slide['params']->get('link')));
         $slide['slide'] = N2SmartSliderLayer::prepareImport($this, $slide['slide']);
         if (isset($generatorTranslation[$slide['generator_id']])) {
             $slide['generator_id'] = $generatorTranslation[$slide['generator_id']];
         }
         $slidesModel->import($slide, $this->sliderId);
     }
     return $this->sliderId;
 }
Beispiel #9
0
 protected function _getData($count, $startIndex)
 {
     N2Loader::import('nextend.database.database');
     $db = JFactory::getDbo();
     $categories = array_map('intval', explode('||', $this->data->get('sourcecategories', '')));
     $tags = array_map('intval', explode('||', $this->data->get('sourcetags', '0')));
     $query = 'SELECT ';
     $query .= 'con.id, ';
     $query .= 'con.title, ';
     $query .= 'con.alias, ';
     $query .= 'con.introtext, ';
     $query .= 'con.fulltext, ';
     $query .= 'con.catid, ';
     $query .= 'cat.title AS cat_title, ';
     $query .= 'cat.alias AS cat_alias, ';
     $query .= 'con.created_by, con.state, ';
     $query .= 'usr.name AS created_by_alias, ';
     $query .= 'con.images ';
     $query .= 'FROM #__content AS con ';
     $query .= 'LEFT JOIN #__users AS usr ON usr.id = con.created_by ';
     $query .= 'LEFT JOIN #__categories AS cat ON cat.id = con.catid ';
     $jNow = JFactory::getDate();
     $now = $jNow->toSql();
     $where = array('con.state = 1 ', "(con.publish_up = '0000-00-00 00:00:00' OR con.publish_up < '" . $now . "') AND (con.publish_down = '0000-00-00 00:00:00' OR con.publish_down > '" . $now . "') ");
     if (!in_array(0, $categories)) {
         $where[] = 'con.catid IN (' . implode(',', $categories) . ') ';
     }
     if (!in_array(0, $tags)) {
         $where[] = 'con.id IN (SELECT content_item_id FROM #__contentitem_tag_map WHERE type_alias = \'com_content.article\' AND tag_id IN (' . implode(',', $tags) . ')) ';
     }
     $sourceUserID = intval($this->data->get('sourceuserid', ''));
     if ($sourceUserID) {
         $where[] = 'con.created_by = ' . $sourceUserID . ' ';
     }
     switch ($this->data->get('sourcefeatured', 0)) {
         case 1:
             $where[] = 'con.featured = 1 ';
             break;
         case -1:
             $where[] = 'con.featured = 0 ';
             break;
     }
     $language = $this->data->get('sourcelanguage', '*');
     if ($language) {
         $where[] = 'con.language = ' . $db->quote($language) . ' ';
     }
     if (count($where) > 0) {
         $query .= 'WHERE ' . implode(' AND ', $where) . ' ';
     }
     $order = N2Parse::parse($this->data->get('joomlaorder', 'con.title|*|asc'));
     if ($order[0]) {
         $query .= 'ORDER BY ' . $order[0] . ' ' . $order[1] . ' ';
     }
     $query .= 'LIMIT ' . $startIndex . ', ' . $count;
     $db->setQuery($query);
     $result = $db->loadAssocList();
     $dispatcher = JDispatcher::getInstance();
     JPluginHelper::importPlugin('content');
     $uri = N2Uri::getBaseUri();
     $data = array();
     for ($i = 0; $i < count($result); $i++) {
         $r = array('title' => $result[$i]['title']);
         $article = new stdClass();
         $article->text = N2SmartSlider::removeShortcode($result[$i]['introtext']);
         $_p = array();
         $dispatcher->trigger('onContentPrepare', array('com_smartslider3', &$article, &$_p, 0));
         if (!empty($article->text)) {
             $r['description'] = $article->text;
         }
         $article->text = $result[$i]['fulltext'];
         $_p = array();
         $dispatcher->trigger('onContentPrepare', array('com_smartslider3', &$article, &$_p, 0));
         if (!empty($article->text)) {
             $result[$i]['fulltext'] = $article->text;
             if (!isset($r['description'])) {
                 $r['description'] = $result[$i]['fulltext'];
             } else {
                 $r['fulltext'] = $result[$i]['fulltext'];
             }
         }
         $images = (array) json_decode($result[$i]['images'], true);
         $r['image'] = $r['thumbnail'] = NextendImageFallBack::fallback($uri . "/", array(@$images['image_intro'], @$images['image_fulltext']), array(@$r['description']));
         $r += array('url' => ContentHelperRoute::getArticleRoute($result[$i]['id'] . ':' . $result[$i]['alias'], $result[$i]['catid'] . ':' . $result[$i]['cat_alias']), 'url_label' => sprintf(n2_('View %s'), n2_('article')), 'category_list_url' => 'index.php?option=com_content&view=category&id=' . $result[$i]['catid'], 'category_blog_url' => 'index.php?option=com_content&view=category&layout=blog&id=' . $result[$i]['catid'], 'fulltext_image' => !empty($images['image_fulltext']) ? N2ImageHelper::dynamic($uri . "/" . $images['image_fulltext']) : '', 'category_title' => $result[$i]['cat_title'], 'created_by' => $result[$i]['created_by_alias'], 'id' => $result[$i]['id']);
         $data[] = $r;
     }
     return $data;
 }