Exemplo n.º 1
0
 public function actionEdit()
 {
     if ($this->validatePermission('smartslider_edit')) {
         $generatorId = N2Request::getInt('generator_id');
         $generatorModel = new N2SmartsliderGeneratorModel();
         $generator = $generatorModel->get($generatorId);
         if ($this->validateDatabase($generator)) {
             $slidesModel = new N2SmartsliderSlidesModel();
             $slides = $slidesModel->getAll(-1, 'OR generator_id = ' . $generator['id'] . '');
             if (count($slides) > 0) {
                 $slide = $slides[0];
                 if (N2Request::getInt('save')) {
                     $request = new N2Data(N2Request::getVar('generator'));
                     $slideParams = new N2Data($slide['params'], true);
                     $slideParams->set('record-slides', $request->get('record-slides', 1));
                     $slidesModel->updateParams($slide['id'], $slideParams->toArray());
                     $request->un_set('record-slides');
                     $generatorModel->save($generatorId, $request->toArray());
                     N2SmartsliderSlidesModel::markChanged($slide['slider']);
                     N2Message::success(n2_('Generator updated and cache cleared.'));
                     $this->redirect(array("generator/edit", array("generator_id" => $generatorId)), 302, true);
                 }
                 N2Request::set('sliderid', $slide['slider']);
                 $this->addView("../../inline/_sliders", array("appObj" => $this), "sidebar");
                 $this->addView("edit", array("generatorModel" => $generatorModel, "generator" => $generator, "slide" => $slide));
                 $this->render();
             } else {
                 $this->redirect(array("sliders/index"), 302, true);
             }
         } else {
             $this->redirect(array("sliders/index"), 302, true);
         }
     }
 }
Exemplo n.º 2
0
 public function actionRecordsTable()
 {
     $this->validateToken();
     $this->validatePermission('smartslider_edit');
     $generatorId = N2Request::getInt('generator_id');
     $generatorModel = new N2SmartsliderGeneratorModel();
     if ($generatorId > 0) {
         $generator = $generatorModel->get($generatorId);
         $this->validateDatabase($generator);
     } else {
         $info = new N2Data(N2Request::getVar('generator'));
         $generator = array('group' => $info->get('group'), 'type' => $info->get('type'), 'params' => '{}');
     }
     $info = $generatorModel->getGeneratorInfo($generator['group'], $generator['type']);
     $generator['params'] = new N2Data($generator['params'], true);
     $generator['params']->loadArray(N2Request::getVar('generator'));
     require_once $info->path . '/generator.php';
     $class = 'N2Generator' . $generator['group'] . $generator['type'];
     /** @var N2GeneratorAbstract $dataSource */
     $dataSource = new $class($info, $generator['params']);
     $request = new N2Data(N2Request::getVar('generator'));
     $group = max(intval($request->get('record-group', 1)), 1);
     $result = $dataSource->getData(max($request->get('record-slides', 1), 1), max($request->get('record-start', 1), 1), $group);
     if (count($result)) {
         ob_start();
         $headings = array();
         for ($i = 1; $i <= $group; $i++) {
             $headings[] = '#';
             foreach ($result[0][0] as $k => $v) {
                 $headings[] = '{' . $k . '/' . $i . '}';
             }
         }
         $headingHTML = N2Html::tag('thead', array(), N2Html::tag('tr', array(), '<th>' . implode('</th><th>', $headings) . '</th>'));
         $rows = array();
         $i = 0;
         foreach ($result as $records) {
             foreach ($records as $g => $record) {
                 $rows[$i][] = $i + 1;
                 foreach ($record as $k => $v) {
                     $rows[$i][] = N2Html::tag('div', array(), htmlentities($v));
                 }
             }
             $i++;
         }
         for ($i = 0; $i < count($rows); $i++) {
             $rows[$i] = '<td>' . implode('</td><td>', $rows[$i]) . '</td>';
         }
         $recordHTML = N2Html::tag('tbody', array(), '<tr>' . implode('</tr><tr>', $rows) . '</tr>');
         echo N2Html::tag('div', array('style' => 'width: 100%; height: 100%; overflow: auto;'), N2Html::tag('table', array('class' => 'n2-generator-records n2-table n2-table-fancy', 'style' => 'margin: 10px; width: auto; table-layout: fixed;'), $headingHTML . $recordHTML));
         $this->response->respond(array('html' => ob_get_clean()));
     } else {
         N2Message::notice('No records found for the filter');
         $this->response->error();
     }
 }
Exemplo n.º 3
0
 /**
  * @param $slide N2SmartSliderSlide
  * @param $slider
  * @param $extend
  */
 public function __construct($slide, $slider, $extend)
 {
     N2Loader::import("libraries.slider.cache.generator", "smartslider");
     N2Loader::import("models.generator", "smartslider");
     $this->slide = $slide;
     $this->slider = $slider;
     $this->generatorModel = new N2SmartsliderGeneratorModel();
     $this->currentGenerator = $this->generatorModel->get($this->slide->generator_id);
     $this->currentGenerator['params'] = new N2Data($this->currentGenerator['params'], true);
     if (isset($extend[$this->slide->generator_id])) {
         $extend = new N2Data($extend[$this->slide->generator_id]);
         $slide->parameters->set('record-slides', $extend->get('record-slides', 1));
         $extend->un_set('record-slides');
         $this->currentGenerator['params']->loadArray($extend->toArray());
     }
 }
Exemplo n.º 4
0
 /**
  *
  * App type must be decalred if you need to route in the parameters. Route is needed for example for subform!!!
  *
  * @param $appType N2ApplicationType|bool
  */
 public function __construct($appType = false)
 {
     $this->appType = $appType;
     $this->_xml = null;
     $this->_tabs = array();
     parent::__construct();
 }
 public function createGenerator($sliderId, $params)
 {
     $data = new N2Data($params);
     unset($params['type']);
     unset($params['group']);
     unset($params['record-slides']);
     try {
         $generatorId = $this->_create($data->get('type'), $data->get('group'), json_encode($params));
         $info = $this->getGeneratorInfo($data->get('group'), $data->get('type'));
         $slideData = self::getLayout($info->type);
         /*if (self::$layouts[$info->type]) {
               $slideData = json_decode(self::$layouts[$info->type], true);
           } else {
               $slideData = array(
                   'title'       => 'title',
                   'slide'       => array(),
                   'description' => '',
                   'thumbnail'   => '',
                   'published'   => 1
               );
           }*/
         $slideData['published'] = '1';
         $slideData['publishdates'] = '|*|';
         $slideData['generator_id'] = $generatorId;
         $slideData['record-slides'] = intval($data->get('record-slides', 1));
         $slideData['slide'] = json_encode($slideData['slide']);
         $slidesModel = new N2SmartsliderSlidesModel();
         $slideId = $slidesModel->create($sliderId, $slideData, false);
         return array('slideId' => $slideId, 'generatorId' => $generatorId);
     } catch (Exception $e) {
         throw new Exception($e->getMessage());
     }
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
0
<?php

$this->widget->init('topbar', array("menu" => array(N2Html::tag('a', array('id' => 'n2-ss-preview', 'href' => '#', 'class' => 'n2-h3 n2-uc n2-has-underline n2-button n2-button-blue n2-button-big', 'style' => 'font-size: 12px;'), n2_('Preview'))), "actions" => array(N2Html::tag('a', array('href' => $this->appType->router->createUrl(array("slider/edit", array("sliderid" => N2Request::getInt('sliderid')))), 'class' => 'n2-button n2-button-red n2-button-big n2-h4 n2-b n2-uc'), n2_('Cancel')), N2Html::tag('a', array('href' => '#', 'class' => 'n2-button n2-button-green n2-button-big n2-h4 n2-b n2-uc', 'onclick' => 'return NextendForm.submit("#smartslider-form");'), n2_('Save')))));
?>

<form id="smartslider-form" action="" method="post">
    <?php 
$params = new N2Data($generator['params'], true);
$group = $generator['group'];
$type = $generator['type'];
$generatorModel = new N2SmartsliderGeneratorModel();
$info = $generatorModel->getGeneratorInfo($group, $type);
$this->widget->init('heading', array('title' => $info->group . ' - ' . $info->title));
$xml = $generatorModel->generatorSpecificForm($group, $type, $params->toArray());
$slideParams = new N2Data($slide['params'], true);
$params->set('record-slides', $slideParams->get('record-slides', 1));
$generatorModel->generatorEditForm($params->toArray());
?>
    <input name="save" value="1" type="hidden"/>
</form>
<style>
    #generatorrecords {
        overflow: auto;
        width: 100%;
    }

    #generatorrecords table div {
        max-width: 200px;
        max-height: 200px;
        overflow: auto;
    }
Exemplo n.º 8
0
 public function copy($id, $targetSliderId)
 {
     $id = intval($id);
     $slide = $this->get($id);
     if ($slide['generator_id'] > 0) {
         $generatorModel = new N2SmartSliderGeneratorModel();
         $slide['generator_id'] = $generatorModel->duplicate($slide['generator_id'], $targetSliderId);
     }
     $slide['slide'] = N2Data::json_encode(N2SmartSliderLayer::translateIds(json_decode($slide['slide'], true)));
     $slideId = $this->_create($slide['title'] . ' - copy', $slide['slide'], $slide['description'], $slide['thumbnail'], $slide['published'], $slide['publish_up'], $slide['publish_down'], 0, $slide['params'], $targetSliderId, $slide['ordering'], $slide['generator_id']);
     self::markChanged($slide['slider']);
     return $slideId;
 }
Exemplo n.º 9
0
 public function actionImportFromServer()
 {
     if ($this->validatePermission('smartslider_edit')) {
         if (N2Request::getInt('save')) {
             if ($this->validateToken()) {
                 $data = new N2Data(N2Request::getVar('slider'));
                 $file = $data->get('import-file');
                 if (empty($file)) {
                     N2Message::error(n2_('Please select a file!'));
                     $this->refresh();
                 } else {
                     $dir = N2Platform::getPublicDir();
                     if (N2Filesystem::fileexists($dir . '/' . $file)) {
                         N2Loader::import('libraries.import', 'smartslider');
                         $import = new N2SmartSliderImport();
                         $sliderId = $import->import($dir . '/' . $file, $data->get('image-mode', 'clone'), $data->get('linked-visuals', 0));
                         if ($sliderId !== false) {
                             if ($data->get('delete')) {
                                 @unlink($dir . '/' . $file);
                             }
                             N2Message::success(n2_('Slider imported.'));
                             $this->redirect(array("slider/edit", array("sliderid" => $sliderId)));
                         } else {
                             N2Message::error(n2_('Import error!'));
                             $this->refresh();
                         }
                     } else {
                         N2Message::error(n2_('The chosen file is missing!'));
                         $this->refresh();
                     }
                 }
             } else {
                 $this->refresh();
             }
         }
         $this->addView('importFromServer');
         $this->render();
     }
 }