Esempio n. 1
1
 protected function menu(&$data)
 {
     if (Sobi::Cfg('general.top_menu', true)) {
         $data['menu'] = array('front' => array('_complex' => 1, '_data' => Sobi::Reg('current_section_name'), '_attributes' => array('lang' => Sobi::Lang(false), 'url' => Sobi::Url(array('sid' => Sobi::Section())))));
         if (Sobi::Can('section.search')) {
             $data['menu']['search'] = array('_complex' => 1, '_data' => Sobi::Txt('MN.SEARCH'), '_attributes' => array('lang' => Sobi::Lang(false), 'url' => Sobi::Url(array('task' => 'search', 'sid' => Sobi::Section()))));
         }
         if (Sobi::Can('entry', 'add', 'own', Sobi::Section())) {
             $data['menu']['add'] = array('_complex' => 1, '_data' => Sobi::Txt('MN.ADD_ENTRY'), '_attributes' => array('lang' => Sobi::Lang(false), 'url' => Sobi::Url(array('task' => 'entry.add', 'sid' => SPRequest::sid()))));
         }
     }
 }
Esempio n. 2
0
 private function load($task)
 {
     $db =& SPFactory::db();
     $adm = defined('SOBIPRO_ADM') ? 'adm.' : null;
     $cond = array($adm . '*', $adm . $task);
     if (strstr($task, '.')) {
         $t = explode('.', $task);
         $cond[] = $adm . $t[0] . '.*';
         $task = $t[0] . '.' . $t[1];
     }
     $this->_actions[$task] = null;
     try {
         $pids = $db->select('pid', 'spdb_plugin_task', array('onAction' => $cond))->loadResultArray();
     } catch (SPException $x) {
         Sobi::Error('Plugins', $x->getMessage(), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     if (!count($pids)) {
         $this->_actions[$task] = array();
     }
     // get section depend apps
     if (Sobi::Section() && count($pids)) {
         try {
             $this->_actions[$task] = $db->select('pid', 'spdb_plugin_section', array('section' => Sobi::Section(), 'enabled' => 1, 'pid' => $pids))->loadResultArray();
         } catch (SPException $x) {
             Sobi::Error('Plugins', $x->getMessage(), SPC::WARNING, 0, __LINE__, __FILE__);
         }
     } elseif (!(SPRequest::sid() || SPRequest::int('pid'))) {
         $this->_actions[$task] = $pids;
     }
     // here is a special exception for the custom listings
     // it can be l.alpha or list.alpha or listing.alpha
     if (preg_match('/^list\\..*/', $task) || preg_match('/^l\\..*/', $task)) {
         $this->_actions['listing' . '.' . $t[1]] = $pids;
     }
 }
Esempio n. 3
0
 /**
  */
 private function edit()
 {
     $id = $this->get('entry.id');
     if ($id) {
         $this->addHidden($id, 'entry.id');
     }
     $sid = SPRequest::int('pid') ? SPRequest::int('pid') : SPRequest::sid();
     $this->assign(Sobi::Url(array('task' => 'category.chooser', 'sid' => $sid, 'out' => 'html', 'multiple' => 1), true), 'cat_chooser_url');
 }
Esempio n. 4
0
 public function chooser()
 {
     $pid = $this->get('category.parent');
     $path = null;
     if (!$pid) {
         $pid = SPRequest::sid();
     }
     $this->assign($pid, 'parent');
     $id = $this->get('category.id');
     $id = $id ? $id : $pid;
     if ($id) {
         $path = $this->parentPath($id);
     }
     $this->assign($path, 'parent_path');
     $this->assign(Sobi::Url(array('task' => 'category.parents', 'out' => 'json', 'format' => 'raw'), true), 'parent_ajax_url');
     /* @TODO  */
     $tpl = str_replace(implode('/', array('usr', 'templates', 'category')), 'views/tpl/', $this->_template . '.php');
     Sobi::Trigger('Display', $this->name(), array(&$this));
     include $tpl;
     Sobi::Trigger('AfterDisplay', $this->name());
 }
Esempio n. 5
0
 public function cachedView($xml, $template, $cacheId, $config = array())
 {
     $this->_xml = $xml;
     Sobi::Trigger('Start', ucfirst(__FUNCTION__), array(&$this->_xml));
     $templatePackage = SPLoader::translateDirPath(Sobi::Cfg('section.template'), 'templates');
     $templateOverride = SPRequest::cmd('sptpl');
     if ($templateOverride) {
         if (strstr($templateOverride, '.')) {
             $templateOverride = str_replace('.', '/', $templateOverride);
         }
         $template = $templateOverride . '.xsl';
     }
     if (file_exists(Sobi::FixPath($templatePackage . '/' . $template))) {
         $template = Sobi::FixPath($templatePackage . '/' . $template);
     } else {
         $type = SPFactory::db()->select('oType', 'spdb_object', array('id' => SPRequest::sid()))->loadResult();
         $template = $templatePackage . '/' . $type . '/' . $template;
     }
     SPFactory::registry()->set('current_template', $templatePackage);
     $this->_templatePath = $templatePackage;
     $this->_template = str_replace('.xsl', null, $template);
     $ini = array();
     if (count($config)) {
         foreach ($config as $file) {
             $file = parse_ini_file($file, true);
             foreach ($file as $section => $keys) {
                 if (isset($ini[$section])) {
                     $ini[$section] = array_merge($ini[$section], $keys);
                 } else {
                     $ini[$section] = $keys;
                 }
             }
         }
     }
     $this->setConfig($ini, SPRequest::task('get'));
     $this->parseXml();
     $this->validateData($cacheId);
     Sobi::Trigger('After', ucfirst(__FUNCTION__), array(&$this->_xml));
 }
Esempio n. 6
0
 /**
  * Save the config
  */
 protected function save($apply, $clone = false)
 {
     $sid = Sobi::Section();
     $this->authorise($sid);
     if ($sid) {
         $this->validate('config.general', array('task' => 'config.general', 'sid' => $sid));
     } else {
         $this->validate('config.global', array('task' => 'config.global'));
     }
     $fields = array();
     $section = false;
     $data = SPRequest::arr('spcfg', array());
     // strange thing =8-O
     if (!isset($data['alphamenu.extra_fields_array'])) {
         $data['alphamenu.extra_fields_array'] = array();
     }
     if (!isset($data['template.icon_fonts_arr'])) {
         $data['template.icon_fonts_arr'] = array();
     }
     foreach ($data as $k => $v) {
         if (is_string($v)) {
             $v = htmlspecialchars_decode($v);
         }
         //			$k = str_replace( array( 'spcfg_', '.' ), array( null, '_' ), $k );
         $k = str_replace('spcfg_', null, $k);
         $s = explode('.', $k);
         $s = $s[0];
         if (!isset($fields[$s])) {
             $fields[$s] = array();
         }
         $k = str_replace("{$s}.", null, $k);
         $c = explode('_', $k);
         if ($c[count($c) - 1] == 'array' && !is_array($v)) {
             if (!strstr($v, '|')) {
                 $v = explode(',', $v);
             } else {
                 $v = explode('|', $v);
             }
         }
         $fields[$s][$k] = $v;
         if (preg_match('/^section.*/', $k)) {
             $section = true;
         }
     }
     $values = array();
     if (count($fields)) {
         foreach ($fields as $sec => $keys) {
             if (count($keys)) {
                 foreach ($keys as $k => $v) {
                     $values[] = array('sKey' => $k, 'sValue' => $v, 'section' => Sobi::Section(), 'critical' => 0, 'cSection' => $sec);
                 }
             }
         }
     }
     if ($section) {
         /* @var $sec SPSection */
         $sec = SPFactory::Model('section');
         $sec->init(SPRequest::sid());
         $sec->getRequest('section');
         $sec->save(true);
     }
     Sobi::Trigger('SaveConfig', $this->name(), array(&$values));
     try {
         SPFactory::db()->insertArray('spdb_config', $values, true);
     } catch (SPException $x) {
         $this->response(Sobi::Back(), $x->getMessage(), false, SPC::ERROR_MSG);
     }
     if (!($section && !Sobi::Section())) {
         SPFactory::cache()->cleanAll();
     } else {
         SPFactory::cache()->cleanSection();
     }
     Sobi::Trigger('After', 'SaveConfig', array(&$values));
     $this->response(Sobi::Back(), Sobi::Txt('MSG.CONFIG_SAVED'), false, 'success');
 }
Esempio n. 7
0
 /**
  * @deprecated
  */
 public function display($return = false)
 {
     $pn = null;
     $pages = $this->limit > 0 ? ceil($this->count / $this->limit) : 0;
     $sid = SPRequest::sid() ? SPRequest::sid() : Sobi::Section();
     $pn .= '<div style="text-align:center;"><div class="pagination">';
     $pn .= '<div class="limit">';
     $pn .= Sobi::Txt('PN.DISPLAY');
     $box = array();
     foreach ($this->limits as $v) {
         if ($v) {
             $box[$v] = $v;
         } else {
             $box[-1] = Sobi::Txt('PN.ALL');
         }
     }
     $pn .= SPHtml_Input::select($this->box, $box, $this->limit, false, array('onchange' => "{$this->boxFunc}( {$sid} )"));
     $pn .= '</div>';
     if ($pages > 1) {
         if ($this->current == 1) {
             $pn .= '<div class="button2-right off"><div class="start"><span>';
             $pn .= Sobi::Txt('PN.START');
             $pn .= '</span></div></div>';
             $pn .= '<div class="button2-right off"><div class="prev"><span>';
             $pn .= Sobi::Txt('PN.PREVIOUS');
             $pn .= '</span></div></div>';
         } else {
             $link = " onclick=\"{$this->func}( 1, {$sid} )\" ";
             $txt = Sobi::Txt('PN.START');
             $pn .= "<div class=\"button2-right\"><div class=\"start\"><a href=\"#\"{$link} title=\"{$txt}\">{$txt}</a></div></div>";
             $prevpage = $this->current - 1;
             $txt = Sobi::Txt('PN.PREVIOUS');
             $link = " onclick=\"{$this->func}( {$prevpage}, {$sid} )\" ";
             $pn .= "<div class=\"button2-right\"><div class=\"start\"><a href=\"#\"{$link} title=\"{$txt}\">{$txt}</a></div></div>";
         }
         $pn .= '<div class="button2-left"><div class="page">';
         for ($page = 1; $page <= $pages; $page++) {
             if ($pages > 1000 && $page % 1000 != 0) {
                 continue;
             } elseif ($pages > 100 && $page % 100 != 0) {
                 continue;
             } elseif ($pages > 20 && $page % 5 != 0) {
                 continue;
             }
             $link = " onclick=\"{$this->func}( {$page}, {$sid} )\" ";
             if ($page == $this->current) {
                 $pn .= '<span>' . $page . '</span>';
             } else {
                 $pn .= "<a href=\"#\"{$link}\" title=\"{$page}\">{$page}</a>";
             }
         }
         $pn .= '</div></div>';
         if ($this->current == $pages) {
             $pn .= '<div class="button2-left off"><div class="next"><span>';
             $pn .= Sobi::Txt('PN.NEXT');
             $pn .= '</span></div></div>';
             $pn .= '<div class="button2-left off"><div class="end"><span>';
             $pn .= Sobi::Txt('PN.END');
             $pn .= '</span></div></div>';
         } else {
             $nextpage = $this->current + 1;
             $link = " onclick=\"{$this->func}( {$nextpage}, {$sid} )\" ";
             $txt = Sobi::Txt('PN.NEXT');
             $pn .= "<div class=\"button2-left\"><div class=\"next\"><a href=\"#\"{$link}title=\"{$txt}\">{$txt}</a></div></div>";
             $link = " onclick=\"{$this->func}( {$pages}, {$sid} )\" ";
             $txt = Sobi::Txt('PN.END');
             $pn .= "<div class=\"button2-left\"><div class=\"end\"><a href=\"#\"{$link}title=\"{$txt}\">{$txt}</a></div></div>";
         }
         $pn .= "<div class=\"limit\">";
         $pn .= Sobi::Txt('PN.CURRENT_SITE', array('current' => $this->current, 'pages' => $pages));
         $pn .= '</div></div>';
     }
     $pn .= '</div><br/>';
     if ($return) {
         return $pn;
     } else {
         echo $pn;
     }
 }
Esempio n. 8
0
 protected function form()
 {
     $ssid = 0;
     /* determine template package */
     $tplPackage = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE);
     /* load template config */
     $this->template();
     $this->tplCfg($tplPackage, 'search');
     if ($this->template == 'results') {
         $this->template = 'view';
     }
     if (!$this->_model) {
         $this->setModel('section');
         $this->_model->init(Sobi::Section());
     }
     /* handle meta data */
     SPFactory::header()->objMeta($this->_model);
     $section = SPFactory::Section(Sobi::Section());
     SPFactory::header()->addKeyword($section->get('sfMetaKeys'))->addDescription($section->get('sfMetaDesc'));
     /* add pathway */
     SPFactory::mainframe()->addToPathway(Sobi::Txt('SH.PATH_TITLE'), Sobi::Url('current'));
     SPFactory::mainframe()->setTitle(Sobi::Txt('SH.TITLE', array('section' => $this->_model->get('name'))));
     Sobi::Trigger('OnFormStart', 'Search');
     SPLoader::loadClass('mlo.input');
     $view = SPFactory::View('search');
     /* if we cannot transfer the search id in cookie */
     if (!$this->session($ssid)) {
         $view->addHidden($ssid, 'ssid');
     }
     if ($this->_task == 'results' && $ssid) {
         /* get limits - if defined in template config - otherwise from the section config */
         $eLimit = $this->tKey($this->template, 'entries_limit', Sobi::Cfg('search.entries_limit', Sobi::Cfg('list.entries_limit', 2)));
         $eInLine = $this->tKey($this->template, 'entries_in_line', Sobi::Cfg('search.entries_in_line', Sobi::Cfg('list.entries_in_line', 2)));
         /* get the site to display */
         $site = SPRequest::int('site', 1);
         $eLimStart = ($site - 1) * $eLimit;
         $view->assign($eLimit, '$eLimit');
         $view->assign($eLimStart, '$eLimStart');
         $view->assign($eInLine, '$eInLine');
         $entries = $this->getResults($ssid, $this->template);
         $view->assign(count($this->_results), '$eCount');
         $view->assign($this->_resultsByPriority, 'priorities');
         $view->assign($entries, 'entries');
         /* create page navigation */
         $pnc = SPLoader::loadClass('helpers.pagenav_' . $this->tKey($this->template, 'template_type', 'xslt'));
         $url = array('task' => 'search.results', 'sid' => SPRequest::sid());
         if (!SPRequest::cmd('ssid', null, 'cookie')) {
             $url['ssid'] = $ssid;
         }
         /* @var SPPageNavXSLT $pn */
         $pn = new $pnc($eLimit, $this->_resultsCount, $site, $url);
         $view->assign($pn->get(), 'navigation');
         /**
          * this is te special case:
          * no matter what task we currently have - if someone called this we need the data for the V-Card
          * Soe we have to trigger all these plugins we need and therefore also fake the task
          */
         $task = 'list.custom';
         SPFactory::registry()->set('task', $task);
     } else {
         $eLimit = -1;
         $view->assign($eLimit, '$eCount');
     }
     /* load all fields */
     $fields = $this->loadFields();
     if (isset($this->_request['search_for'])) {
         $view->assign($this->_request['search_for'], 'search_for');
         $view->assign($this->_request['phrase'], 'search_phrase');
     }
     $view->assign($fields, 'fields');
     $view->assign(SPFactory::user()->getCurrent(), 'visitor');
     $view->assign($this->_task, 'task');
     $view->addHidden(Sobi::Section(), 'sid');
     $view->addHidden('search.search', 'task');
     $view->setConfig($this->_tCfg, $this->template);
     $view->setTemplate($tplPackage . '.' . $this->templateType . '.' . $this->template);
     Sobi::Trigger('OnCreateView', 'Search', array(&$view));
     $view->display();
 }
Esempio n. 9
0
 /**
  * Shows the field in the edit entry or add entry form
  * @param bool $return return or display directly
  * @return string
  */
 public function field($return = false)
 {
     if (!$this->enabled) {
         return false;
     }
     if (!$this->sid) {
         $this->sid = SPRequest::sid();
     }
     $this->_selectedCats = $this->cleanData();
     $this->loadCategories();
     if (!$this->_selectedCats && $this->sid) {
         $entry = SPFactory::Entry($this->sid);
         $this->_selectedCats = array_keys($entry->get('categories'));
     } else {
         $this->cleanData();
     }
     if (!$this->_selectedCats || !count($this->_selectedCats)) {
         $sid = SPRequest::sid();
         if ($sid != Sobi::Section() && $sid != $this->sid) {
             $this->_selectedCats = array(SPRequest::sid());
         }
     }
     $this->showLabel = true;
     if (!(int) $this->catsMaxLimit) {
         $this->catsMaxLimit = 1;
     }
     if (count($this->_selectedCats) > $this->catsMaxLimit) {
         $this->_selectedCats = array_slice($this->_selectedCats, 0, $this->catsMaxLimit);
     }
     switch ($this->method) {
         case 'fixed':
             $this->showLabel = false;
             $this->isOutputOnly = true;
             return null;
             break;
         case 'tree':
             $field = $this->tree();
             break;
         case 'select':
             $field = $this->select();
             break;
         case 'mselect':
             $field = $this->mSelect();
             break;
     }
     if (!$return) {
         echo $field;
     } else {
         return $field;
     }
 }
Esempio n. 10
0
 /**
  * Gets the data for a field and save it in the database
  * @param SPEntry $entry
  * @param string $request
  * @param bool $clone
  * @throws SPException
  * @return bool
  */
 public function saveData(&$entry, $request = 'POST', $clone = false)
 {
     if (!$this->enabled) {
         return false;
     }
     $del = SPRequest::bool($this->nid . '_delete', false, $request);
     if ($clone) {
         $orgSid = SPRequest::sid();
         $this->loadData($orgSid);
         $files = $this->getExistingFiles();
         $cloneFiles = array();
         if (isset($files['original']) && file_exists(SOBI_ROOT . '/' . $files['original'])) {
             return $this->cloneFiles($entry, $request, $files, $cloneFiles);
         }
     }
     $fileSize = SPRequest::file($this->nid, 'size');
     $cropped = null;
     static $store = null;
     $cache = false;
     if ($store == null) {
         $store = SPFactory::registry()->get('requestcache_stored');
     }
     if (is_array($store) && isset($store[$this->nid])) {
         if (!strstr($store[$this->nid], 'file://') && !strstr($store[$this->nid], 'directory://')) {
             $data = $store[$this->nid];
             $cache = true;
             $orgName = SPRequest::file($this->nid, 'name', $request);
         } else {
             SPRequest::set($this->nid, $store[$this->nid]);
             $orgName = SPRequest::file($this->nid, 'name');
             $data = SPRequest::file($this->nid, 'tmp_name');
         }
     } else {
         $data = SPRequest::file($this->nid, 'tmp_name');
         $orgName = SPRequest::file($this->nid, 'name');
     }
     $sPath = $this->parseName($entry, $orgName, $this->savePath);
     $path = SPLoader::dirPath($sPath, 'root', false);
     /** Wed, Oct 15, 2014 13:51:03
      * Implemented a cropper with Ajax checker.
      * This is the actual method to get those files
      * Other methods left for BC
      * */
     if (!$data) {
         $directory = SPRequest::string($this->nid, $store[$this->nid], false, $request);
         if (strlen($directory)) {
             list($data, $dirName, $files, $coordinates) = $this->getAjaxFiles($directory);
             if (count($files)) {
                 foreach ($files as $file) {
                     if ($file == '.') {
                         continue;
                     }
                     if ($file == '..') {
                         continue;
                     }
                     if (strpos($file, 'icon_') !== false) {
                         continue;
                     }
                     if (strpos($file, 'resized_') !== false) {
                         continue;
                     }
                     if (strpos($file, 'cropped_') !== false) {
                         $cropped = $dirName . $file;
                         SPFs::upload($cropped, $path . basename($cropped));
                         continue;
                     }
                     if (strpos($file, '.var') !== false) {
                         continue;
                     }
                     $fileSize = filesize($dirName . $file);
                     $orgName = $file;
                 }
             }
             if (strlen($coordinates)) {
                 $coordinates = json_decode(SPLang::clean($coordinates), true);
                 /** @var SPImage $croppedImage */
                 $croppedImage = SPFactory::Instance('base.fs.image', $dirName . $orgName);
                 $croppedImage->crop($coordinates['width'], $coordinates['height'], $coordinates['x'], $coordinates['y']);
                 $cropped = 'cropped_' . $orgName;
                 $croppedImage->saveAs($path . $cropped);
             }
             $data = strlen($cropped) ? $cropped : $dirName . $file;
         }
     }
     $files = array();
     /* if we have an image */
     if ($data && $orgName) {
         if ($fileSize > $this->maxSize) {
             throw new SPException(SPLang::e('FIELD_IMG_TOO_LARGE', $this->name, $fileSize, $this->maxSize));
         }
         if ($cropped) {
             SPFs::upload($dirName . $orgName, $path . $orgName);
         }
         /**
          * @var SPImage $orgImage
          */
         if ($cache) {
             $orgImage = SPFactory::Instance('base.fs.image', $data);
             $orgImage->move($path . $orgName);
         } else {
             $orgImage = SPFactory::Instance('base.fs.image');
             $nameArray = explode('.', $orgName);
             $ext = strtolower(array_pop($nameArray));
             $nameArray[] = $ext;
             $orgName = implode('.', $nameArray);
             if ($cropped) {
                 // Fri, Jul 3, 2015 17:15:05
                 // it has been actually uploaded at ~425
                 // not sure why we are trying to upload it again
                 if (SPFs::exists($dirName . $data)) {
                     $orgImage->upload($dirName . $data, $path . basename($data));
                 } else {
                     $orgImage->setFile($path . basename($data));
                 }
             } else {
                 $orgImage->upload($dirName . $orgName, $path . $orgName);
             }
         }
         $files['data']['exif'] = $orgImage->exif();
         $this->cleanExif($files['data']['exif']);
         if (Sobi::Cfg('image_field.fix_rotation', true)) {
             if ($orgImage->fixRotation()) {
                 $orgImage->save();
             }
         }
         if ($this->resize) {
             $image = clone $orgImage;
             try {
                 $image->resample($this->resizeWidth, $this->resizeHeight, false);
                 $files['image'] = $this->parseName($entry, $orgName, $this->imageName, true);
                 $image->saveAs($path . $files['image']);
             } catch (SPException $x) {
                 Sobi::Error($this->name(), SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
                 $image->delete();
                 throw new SPException(SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()));
             }
         }
         if ($this->generateThumb) {
             $thumb = clone $orgImage;
             try {
                 $thumb->resample($this->thumbWidth, $this->thumbHeight, false);
                 $files['thumb'] = $this->parseName($entry, $orgName, $this->thumbName, true);
                 $thumb->saveAs($path . $files['thumb']);
             } catch (SPException $x) {
                 Sobi::Error($this->name(), SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
                 $thumb->delete();
                 throw new SPException(SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()));
             }
         }
         $ico = clone $orgImage;
         try {
             $icoSize = explode(':', Sobi::Cfg('image.ico_size', '80:80'));
             $ico->resample($icoSize[0], $icoSize[1], false);
             $files['ico'] = $this->parseName($entry, strtolower($orgName), 'ico_{orgname}_' . $this->nid, true);
             $ico->saveAs($path . $files['ico']);
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
             $ico->delete();
             throw new SPException(SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()));
         }
         if (!$this->keepOrg) {
             $orgImage->delete();
         } else {
             $files['original'] = $this->parseName($entry, $orgName, '{orgname}', true);
         }
         foreach ($files as $i => $file) {
             if ($i == 'data') {
                 continue;
             }
             $files[$i] = $sPath . $file;
         }
     } elseif ($del) {
         $this->delImgs();
         $files = array();
     } else {
         return true;
     }
     $this->storeData($entry, $request, $files);
 }
Esempio n. 11
0
 /**
  * @param $params
  * @param bool $count
  * @return array
  */
 protected function entries($params, $count = false)
 {
     if ($params->get('fieldOrder')) {
         $eOrder = $params->get('fieldOrder');
     } else {
         $eOrder = $params->get('spOrder');
     }
     $entriesRecursive = true;
     $conditions = array();
     $db = SPFactory::db();
     $limits = $params->get('spLimit');
     if ($limits) {
         $limits = explode('::', $limits);
         $fid = $limits[0];
         $value = $limits[1] == 'group' ? $limits[2] : $limits[1];
         $condition = array('fid' => $fid, 'optValue' => $value);
         if ($limits[1] == 'group') {
             $condition['optValue'] = $db->select('optValue', 'spdb_field_option', array('optParent' => $value, 'fid' => $fid))->loadResultArray();
         }
         $conditions['spo.id'] = $db->select('sid', 'spdb_field_option_selected', $condition)->loadResultArray();
         if (!count($conditions['spo.id'])) {
             return array();
         }
     }
     $eDir = $params->get('spOrderDir');
     $oPrefix = null;
     /* get the site to display */
     if ($params->get('engine') != 'static') {
         $site = SPRequest::int('site', 1);
     } else {
         $site = 1;
     }
     $eLimit = $params->get('entriesLimit');
     $eLimStart = ($site - 1) * $eLimit;
     /* get the ordering and the direction */
     if (strstr($eOrder, '.')) {
         $eOrder = explode('.', $eOrder);
         $eDir = $eOrder[1];
         $eOrder = $eOrder[0];
     }
     $sid = $params->get('sid');
     $section = $params->get('section');
     $this->setModel($sid == $section ? 'section' : 'category');
     $this->_model->init($sid);
     $catId = SPRequest::int('pid');
     $catId = $catId ? $catId : SPRequest::sid();
     if ($params->get('autoListing', false) && $catId && $catId != Sobi::Section()) {
         $entries = Sobi::GetUserData('currently-displayed-entries', array());
         if (!count($entries) && $catId) {
             $entries = SPFactory::Category($catId)->getChilds('entry', true, 1);
             $entries = array_unique($entries);
         }
         if (count($entries)) {
             $conditions['spo.id'] = $entries;
         }
     } else {
         if ($entriesRecursive) {
             $pids = $this->_model->getChilds('category', true);
             // getChilds doesn't includes the category id itself
             $pids[$this->_model->get('id')] = $this->_model->get('id');
             if (is_array($pids)) {
                 $pids = array_keys($pids);
             }
             $conditions['sprl.pid'] = $pids;
         } else {
             $conditions['sprl.pid'] = $sid;
         }
         if ($sid == -1) {
             unset($conditions['sprl.pid']);
         }
     }
     if (count($conditions)) {
         /* sort by field */
         if (is_numeric($eOrder)) {
             static $fields = array();
             $specificMethod = false;
             $field = isset($fields[$sid]) ? $fields[$sid] : null;
             if (!$field) {
                 try {
                     $fType = $db->select('fieldType', 'spdb_field', array('fid' => $eOrder))->loadResult();
                 } catch (SPException $x) {
                     Sobi::Error($this->name(), SPLang::e('CANNOT_DETERMINE_FIELD_TYPE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
                 }
                 if ($fType) {
                     $field = SPLoader::loadClass('opt.fields.' . $fType);
                 }
                 $fields[$sid] = $field;
             }
             if ($field && method_exists($field, 'sortBy')) {
                 $table = null;
                 $oPrefix = null;
                 $specificMethod = call_user_func_array(array($field, 'sortBy'), array(&$table, &$conditions, &$oPrefix, &$eOrder, &$eDir));
             }
             if (!$specificMethod) {
                 $table = $db->join(array(array('table' => 'spdb_field', 'as' => 'fdef', 'key' => 'fid'), array('table' => 'spdb_field_data', 'as' => 'fdata', 'key' => 'fid'), array('table' => 'spdb_object', 'as' => 'spo', 'key' => array('fdata.sid', 'spo.id')), array('table' => 'spdb_relations', 'as' => 'sprl', 'key' => array('fdata.sid', 'sprl.id'))));
                 $oPrefix = 'spo.';
                 $conditions['spo.oType'] = 'entry';
                 $conditions['fdef.fid'] = $eOrder;
                 $eOrder = 'baseData.' . $eDir;
             }
         } else {
             $table = $db->join(array(array('table' => 'spdb_relations', 'as' => 'sprl', 'key' => 'id'), array('table' => 'spdb_object', 'as' => 'spo', 'key' => 'id')));
             $conditions['spo.oType'] = 'entry';
             if ($eOrder == 'validUntil') {
                 $eOrder = 'spo.validUntil';
             }
             $eOrder = $eOrder . '.' . $eDir;
             $oPrefix = 'spo.';
         }
         /* check user permissions for the visibility */
         if (Sobi::My('id')) {
             $this->userPermissionsQuery($conditions, $oPrefix);
         } else {
             $conditions = array_merge($conditions, array($oPrefix . 'state' => '1', '@VALID' => $db->valid($oPrefix . 'validUntil', $oPrefix . 'validSince')));
         }
         $conditions['sprl.copy'] = '0';
         try {
             if (!$count) {
                 $results = $db->select($oPrefix . 'id', $table, $conditions, $eOrder, $eLimit, $eLimStart, true)->loadResultArray();
             } else {
                 $results = $db->select("COUNT( DISTINCT {$oPrefix}id )", $table, $conditions, $eOrder)->loadResult();
             }
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
         if ($count) {
             return $results;
         }
         $entries = array();
         if (count($results)) {
             foreach ($results as $i => $sid) {
                 $entries[$i] = $sid;
             }
         }
         return $entries;
     } else {
         return array();
     }
 }
Esempio n. 12
0
 protected function toggle()
 {
     $plugin = SPRequest::cmd('eid');
     $plugin = explode('.', $plugin);
     $ptype = $plugin[0];
     $plugin = $plugin[1];
     $message = null;
     if (SPRequest::sid()) {
         try {
             $app = SPFactory::db()->select('name', 'spdb_plugins', array('pid' => $plugin, 'type' => $ptype))->loadResult();
             $state = !SPFactory::db()->select('enabled', 'spdb_plugin_section', array('section' => SPRequest::sid('get'), 'pid' => $plugin, 'type' => $ptype))->loadResult();
             SPFactory::db()->replace('spdb_plugin_section', array('section' => SPRequest::sid('get'), 'pid' => $plugin, 'type' => $ptype, 'enabled' => $state, 0));
             $message = $state ? Sobi::Txt('EX.APP_ENABLED', $app) : Sobi::Txt('EX.APP_DISABLED', $app);
             $messageType = $state ? 'success' : 'warning';
         } catch (SPException $x) {
             $message = Sobi::Txt('EX.CANNOT_CHANGE_STATE_ERR', 'error');
             $messageType = 'error';
             Sobi::Error('extensions', SPLang::e('CANNOT_UPDATE_PLUGIN', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
     } else {
         try {
             $app = SPFactory::db()->select(array('enabled', 'name'), 'spdb_plugins', array('pid' => $plugin, 'type' => $ptype))->loadObject();
             SPFactory::db()->update('spdb_plugins', array('enabled' => !$app->enabled), array('type' => $ptype, 'pid' => $plugin));
             $message = !$app->enabled ? Sobi::Txt('EX.APP_ENABLED', $app->name) : Sobi::Txt('EX.APP_DISABLED', $app->name);
             $messageType = !$app->enabled ? 'success' : 'warning';
         } catch (SPException $x) {
             $message = Sobi::Txt('EX.CANNOT_CHANGE_STATE_ERR', 'error');
             $messageType = 'error';
             Sobi::Error('extensions', SPLang::e('CANNOT_UPDATE_PLUGIN', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
     }
     $this->response(Sobi::Back(), $message, false, $messageType);
 }
Esempio n. 13
0
 /**
  * Static function to create the right SQL-Query if a entries list should be sorted by this field
  * @param string $tables - table or tables join
  * @param array $conditions - array with conditions
  * @param string $oPrefix
  * @param string $eOrder
  * @param string $eDir
  * @return void
  */
 public static function sortBy(&$tables, &$conditions, &$oPrefix, &$eOrder, $eDir)
 {
     /* @var SPdb $db */
     $db =& SPFactory::db();
     $tables = $db->join(array(array('table' => 'spdb_field_option_selected', 'as' => 'sdata', 'key' => 'fid'), array('table' => 'spdb_object', 'as' => 'spo', 'key' => array('sdata.sid', 'spo.id')), array('table' => 'spdb_field_data', 'as' => 'fdata', 'key' => array('fdata.fid', 'sdata.fid')), array('table' => 'spdb_field', 'as' => 'fdef', 'key' => array('fdef.fid', 'sdata.fid')), array('table' => 'spdb_language', 'as' => 'ldata', 'key' => array('sdata.optValue', 'ldata.sKey')), array('table' => 'spdb_relations', 'as' => 'sprl', 'key' => array('spo.id', 'sprl.id'))));
     $oPrefix = 'spo.';
     $conditions['spo.oType'] = 'entry';
     if (!isset($conditions['sprl.pid'])) {
         $conditions['sprl.pid'] = SPRequest::sid();
     }
     $conditions['ldata.oType'] = 'field_option';
     $conditions['fdef.nid'] = $eOrder;
     $eOrder = 'sValue.' . $eDir . ", field( language, '" . Sobi::Lang(false) . "', '" . Sobi::DefLang() . "' )";
     return true;
 }
Esempio n. 14
0
 protected function entry($entry, $manager, $noId = false)
 {
     $en = array();
     if (is_numeric($entry)) {
         $en = $this->cachedEntry($entry, $manager, $noId);
     }
     if (!is_array($en) || !count($en)) {
         if (is_numeric($entry)) {
             $entry = SPFactory::Entry($entry);
         }
         $en['id'] = $entry->get('id');
         $en['nid'] = $entry->get('nid');
         $en['name'] = array('_complex' => 1, '_data' => $entry->get('name'), '_attributes' => array('lang' => Sobi::Lang(false)));
         $en['url_array'] = array('title' => Sobi::Cfg('sef.alias', true) ? $entry->get('nid') : $entry->get('name'), 'pid' => $entry->get('primary'), 'sid' => $entry->get('id'));
         if (strstr(SPRequest::task(), 'search') || $noId || Sobi::Cfg('section.force_category_id', false) && SPRequest::sid() == Sobi::Section()) {
             $en['url'] = Sobi::Url(array('title' => Sobi::Cfg('sef.alias', true) ? $entry->get('nid') : $entry->get('name'), 'pid' => $entry->get('primary'), 'sid' => $entry->get('id')));
         } else {
             $en['url'] = Sobi::Url(array('title' => Sobi::Cfg('sef.alias', true) ? $entry->get('nid') : $entry->get('name'), 'pid' => SPRequest::sid(), 'sid' => $entry->get('id')));
         }
         if (Sobi::Cfg('list.entry_meta', true)) {
             $en['meta'] = array('description' => $entry->get('metaDesc'), 'keys' => $this->metaKeys($entry), 'author' => $entry->get('metaAuthor'), 'robots' => $entry->get('metaRobots'));
         }
         if ($manager || Sobi::My('id') && Sobi::My('id') == $entry->get('owner') && Sobi::Can('entry', 'edit', 'own', Sobi::Section())) {
             $en['edit_url'] = Sobi::Url(array('task' => 'entry.edit', 'pid' => SPRequest::sid(), 'sid' => $entry->get('id')));
         } else {
             if (isset($en['edit_url'])) {
                 unset($en['edit_url']);
             }
         }
         $en['edit_url_array'] = array('task' => 'entry.edit', 'pid' => SPRequest::sid(), 'sid' => $entry->get('id'));
         $en['created_time'] = $entry->get('createdTime');
         $en['updated_time'] = $entry->get('updatedTime');
         $en['valid_since'] = $entry->get('validSince');
         $en['valid_until'] = $entry->get('validUntil');
         $this->fixTimes($en);
         if ($entry->get('state') == 0) {
             $en['state'] = 'unpublished';
         } else {
             if (strtotime($entry->get('validUntil')) != 0 && strtotime($entry->get('validUntil')) < time()) {
                 $en['state'] = 'expired';
             } elseif (strtotime($entry->get('validSince')) != 0 && strtotime($entry->get('validSince')) > time()) {
                 $en['state'] = 'pending';
             } else {
                 $en['state'] = 'published';
             }
         }
         $en['author'] = $entry->get('owner');
         $en['counter'] = $entry->get('counter');
         $en['approved'] = $entry->get('approved');
         //		$en[ 'confirmed' ] = $entry->get( 'confirmed' );
         if (Sobi::Cfg('list.entry_cats', true)) {
             $cats = $entry->get('categories');
             $categories = array();
             if (count($cats)) {
                 $cn = SPLang::translateObject(array_keys($cats), array('name', 'alias'));
             }
             foreach ($cats as $cid => $cat) {
                 $categories[] = array('_complex' => 1, '_data' => SPLang::clean($cn[$cid]['value']), '_attributes' => array('lang' => Sobi::Lang(false), 'id' => $cat['pid'], 'position' => $cat['position'], 'url' => Sobi::Url(array('sid' => $cat['pid'], 'title' => Sobi::Cfg('sef.alias', true) ? $cat['alias'] : $cat['name']))));
             }
             $en['categories'] = $categories;
         }
         $fields = $entry->getFields();
         if (count($fields)) {
             //				foreach ( $fields as $field ) {
             //					if ( $field->enabled( 'vcard' ) && $field->get( 'id' ) != Sobi::Cfg( 'entry.name_field' ) ) {
             //						$struct = $field->struct();
             //						$options = null;
             //						if ( isset( $struct[ '_options' ] ) ) {
             //							$options = $struct[ '_options' ];
             //							unset( $struct[ '_options' ] );
             //						}
             //						$f[ $field->get( 'nid' ) ] = array(
             //							'_complex' => 1,
             //							'_data' => array(
             //								'label' => array(
             //									'_complex' => 1,
             //									'_data' => $field->get( 'name' ),
             //									'_attributes' => array( 'lang' => Sobi::Lang( false ), 'show' => $field->get( 'withLabel' ) )
             //								),
             //								'data' => $struct,
             //							),
             //							'_attributes' => array( 'id' => $field->get( 'id' ), 'type' => $field->get( 'type' ), 'suffix' => $field->get( 'suffix' ), 'position' => $field->get( 'position' ), 'css_class' => ( strlen( $field->get( 'cssClass' ) ) ? $field->get( 'cssClass' ) : 'spField' ) )
             //						);
             //						if ( Sobi::Cfg( 'list.field_description', false ) ) {
             //							$f[ $field->get( 'nid' ) ][ '_data' ][ 'description' ] = array( '_complex' => 1, '_xml' => 1, '_data' => $field->get( 'description' ) );
             //						}
             //						if ( $options ) {
             //							$f[ $field->get( 'nid' ) ][ '_data' ][ 'options' ] = $options;
             //						}
             //						if ( isset( $struct[ '_xml_out' ] ) && count( $struct[ '_xml_out' ] ) ) {
             //							foreach ( $struct[ '_xml_out' ] as $k => $v )
             //								$f[ $field->get( 'nid' ) ][ '_data' ][ $k ] = $v;
             //						}
             //					}
             //				}
             $en['fields'] = $this->fieldStruct($fields, 'vcard');
         }
         SPFactory::cache()->addObj($entry, 'entry', $entry->get('id'))->addObj($en, 'entry_struct', $entry->get('id'));
         unset($en['url_array']);
         unset($en['edit_url_array']);
         unset($entry);
     }
     $en['counter'] = $this->getNonStaticData($en['id'], 'counter');
     /*
      * this is te special case:
      * no matter what task we currently have - if someone called this we need the data for the V-Card
      * Soe we have to trigger all these plugins we need and therefore also fake the task
      */
     $task = 'list.custom';
     SPFactory::registry()->set('task', $task);
     Sobi::Trigger('List', ucfirst(__FUNCTION__), array(&$en));
     return $en;
 }
Esempio n. 15
0
 /**
  * @param string $eOrder
  * @param int $eLimit
  * @param int $eLimStart
  * @param bool $count
  * @param array $conditions
  * @param bool $entriesRecursive
  * @param int $pid
  * @return array
  */
 public function getEntries($eOrder, $eLimit = null, $eLimStart = null, $count = false, $conditions = array(), $entriesRecursive = false, $pid = 0)
 {
     /* var SPDb $db */
     $db = SPFactory::db();
     $entries = array();
     $eDir = 'asc';
     $oPrefix = null;
     $conditions = is_array($conditions) ? $conditions : array();
     /* get the ordering and the direction */
     if (strstr($eOrder, '.')) {
         $eOr = explode('.', $eOrder);
         $eOrder = array_shift($eOr);
         $eDir = implode('.', $eOr);
     }
     $pid = $pid ? $pid : SPRequest::sid();
     /* if sort by name, then sort by the name field */
     if ($eOrder == 'name') {
         $eOrder = SPFactory::config()->nameField()->get('fid');
     }
     if ($entriesRecursive) {
         $pids = $this->_model->getChilds('category', true);
         if (is_array($pids)) {
             $pids = array_keys($pids);
         }
         $pids[] = SPRequest::sid();
         $conditions['sprl.pid'] = $pids;
     } else {
         $conditions['sprl.pid'] = $pid;
     }
     if ($pid == -1) {
         unset($conditions['sprl.pid']);
     }
     /* sort by field */
     if (strstr($eOrder, 'field_')) {
         static $field = null;
         $specificMethod = false;
         if (!$field) {
             try {
                 $fType = $db->select('fieldType', 'spdb_field', array('nid' => $eOrder, 'section' => Sobi::Section()))->loadResult();
             } catch (SPException $x) {
                 Sobi::Error($this->name(), SPLang::e('CANNOT_DETERMINE_FIELD_TYPE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
             }
             if ($fType) {
                 $field = SPLoader::loadClass('opt.fields.' . $fType);
             }
         }
         if ($field && method_exists($field, 'customOrdering')) {
             $table = null;
             $oPrefix = null;
             $specificMethod = call_user_func_array(array($field, 'customOrdering'), array(&$table, &$conditions, &$oPrefix, &$eOrder, &$eDir));
         } elseif ($field && method_exists($field, 'sortBy')) {
             $table = null;
             $oPrefix = null;
             $specificMethod = call_user_func_array(array($field, 'sortBy'), array(&$table, &$conditions, &$oPrefix, &$eOrder, &$eDir));
         }
         if (!$specificMethod) {
             $table = $db->join(array(array('table' => 'spdb_field', 'as' => 'fdef', 'key' => 'fid'), array('table' => 'spdb_field_data', 'as' => 'fdata', 'key' => 'fid'), array('table' => 'spdb_object', 'as' => 'spo', 'key' => array('fdata.sid', 'spo.id')), array('table' => 'spdb_relations', 'as' => 'sprl', 'key' => array('fdata.sid', 'sprl.id'))));
             $oPrefix = 'spo.';
             $conditions['spo.oType'] = 'entry';
             $conditions['fdef.nid'] = $eOrder;
             $eOrder = 'baseData.' . $eDir;
         }
     } elseif (strstr($eOrder, 'counter')) {
         $table = $db->join(array(array('table' => 'spdb_object', 'as' => 'spo', 'key' => 'id'), array('table' => 'spdb_relations', 'as' => 'sprl', 'key' => array('spo.id', 'sprl.id')), array('table' => 'spdb_counter', 'as' => 'spcounter', 'key' => array('spo.id', 'spcounter.sid'))));
         $oPrefix = 'spo.';
         $conditions['spo.oType'] = 'entry';
         if (strstr($eOrder, '.')) {
             $cOrder = explode('.', $eOrder);
             $eOrder = 'spcounter.counter.' . $cOrder[1];
         } else {
             $eOrder = 'spcounter.counter.desc';
         }
     } else {
         $table = $db->join(array(array('table' => 'spdb_relations', 'as' => 'sprl', 'key' => 'id'), array('table' => 'spdb_object', 'as' => 'spo', 'key' => 'id')));
         $conditions['spo.oType'] = 'entry';
         $eOrder = $eOrder . '.' . $eDir;
         $oPrefix = 'spo.';
         if (strstr($eOrder, 'valid')) {
             $eOrder = $oPrefix . $eOrder;
         }
     }
     /* check user permissions for the visibility */
     if (Sobi::My('id')) {
         $this->userPermissionsQuery($conditions, $oPrefix);
         if (isset($conditions[$oPrefix . 'state']) && $conditions[$oPrefix . 'state']) {
             $conditions['sprl.copy'] = 0;
         }
     } else {
         $conditions = array_merge($conditions, array($oPrefix . 'state' => '1', '@VALID' => $db->valid($oPrefix . 'validUntil', $oPrefix . 'validSince')));
         $conditions['sprl.copy'] = '0';
     }
     try {
         $results = $db->select($oPrefix . 'id', $table, $conditions, $eOrder, $eLimit, $eLimStart, true)->loadResultArray();
     } catch (SPException $x) {
         Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     Sobi::Trigger($this->name(), 'AfterGetEntries', array(&$results, $count));
     if (count($results) && !$count) {
         foreach ($results as $i => $sid) {
             // it needs too much memory moving the object creation to the view
             //$entries[ $i ] = SPFactory::Entry( $sid );
             $entries[$i] = $sid;
         }
     }
     if ($count) {
         Sobi::SetUserData('currently-displayed-entries', $results);
         return $results;
     }
     return $entries;
 }
Esempio n. 16
0
 protected function view()
 {
     /* determine template package */
     $tplPackage = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE);
     Sobi::ReturnPoint();
     $this->_task = 'date';
     if (!$this->_model) {
         $this->setModel('section');
         $this->_model->init(Sobi::Section());
     }
     $this->visible();
     /* load template config */
     $this->template();
     $this->tplCfg($tplPackage);
     /* get limits - if defined in template config - otherwise from the section config */
     $eLimit = $this->tKey($this->template, 'entries_limit', Sobi::Cfg('list.entries_limit', 2));
     $eInLine = $this->tKey($this->template, 'entries_in_line', Sobi::Cfg('list.entries_in_line', 2));
     $date = explode('.', SPRequest::cmd('date'));
     $this->date['year'] = isset($date[0]) && $date[0] ? $date[0] : null;
     $this->date['month'] = isset($date[1]) && $date[1] ? $date[1] : null;
     $this->date['day'] = isset($date[2]) && $date[2] ? $date[2] : null;
     if (!$this->date['year'] || !(int) $this->date['year']) {
         throw new SPException(SPLang::e('INVALID_DATE_GIVEN'));
     }
     /* get the site to display */
     $site = SPRequest::int('site', 1);
     $eLimStart = ($site - 1) * $eLimit;
     $conditions = array('spo.oType' => 'entry', 'year(createdTime)' => $this->date['year']);
     $listing = 'year';
     if ($this->date['month'] && $this->date['month'] < 13 && $this->date['month'] > 0) {
         $conditions['month(createdTime)'] = $this->date['month'];
         $listing = 'month';
     }
     if ($this->date['day'] && $this->date['day'] < 13 && $this->date['day'] > 0) {
         $conditions['day(createdTime)'] = $this->date['day'];
         $listing = 'date';
     }
     $eOrder = 'createdTime';
     $eCount = count($this->getEntries($eOrder, 0, 0, true, $conditions, true, Sobi::Section()));
     $entries = $this->getEntries($eOrder, $eLimit, $eLimStart, true, $conditions, true, Sobi::Section());
     $url = array('sid' => SPRequest::sid(), 'task' => 'list.date', 'date' => SPRequest::cmd('date'));
     $pn = SPFactory::Instance('helpers.pagenav_' . $this->tKey($this->template, 'template_type', 'xslt'), $eLimit, $eCount, $site, $url);
     if (SPRequest::int('site', 0)) {
         $url['site'] = SPRequest::int('site', 0);
     }
     SPFactory::header()->addCanonical(Sobi::Url($url, true, true, true));
     /* handle meta data */
     SPFactory::header()->objMeta($this->_model);
     $date = $this->date;
     $monthsNames = explode(',', Sobi::Txt('JS_CALENDAR_MONTHS'));
     $date['month'] = isset($monthsNames[$date['month'] - 1]) ? trim($monthsNames[$date['month'] - 1]) : null;
     SPFactory::mainframe()->addToPathway(Sobi::Txt('DL.PATH_TITLE_' . strtoupper($listing), $date), Sobi::Url('current'));
     SPFactory::header()->addTitle(Sobi::Txt('DL.TITLE_' . strtoupper($listing), $date), array(ceil($eCount / $eLimit), $site));
     /* get view class */
     $view = SPFactory::View('listing');
     $view->assign($eLimit, '$eLimit');
     $view->assign($eLimStart, '$eLimStart');
     $view->assign($eCount, '$eCount');
     $view->assign($eInLine, '$eInLine');
     $view->assign($this->_task, 'task');
     $view->assign($this->_model, 'section');
     $view->setConfig($this->_tCfg, $this->template);
     $view->setTemplate($tplPackage . '.' . $this->templateType . '.' . $this->template);
     $view->assign($pn->get(), 'navigation');
     $view->assign(SPFactory::user()->getCurrent(), 'visitor');
     $view->assign($entries, 'entries');
     Sobi::Trigger('UserListing', 'View', array(&$view));
     $view->display();
 }
Esempio n. 17
0
 public function languages()
 {
     $subMenu = array();
     if (Sobi::Cfg('lang.multimode', false)) {
         $availableLanguages = SPFactory::CmsHelper()->availableLanguages();
         $sectionLength = 30;
         if (count($availableLanguages)) {
             $sid = SPRequest::sid();
             if (!$sid) {
                 $sid = Sobi::Section();
             }
             $subMenu = array();
             $task = SPRequest::task();
             $url = array('sid' => $sid, 'task' => $task, 'sp-language' => null);
             if ($task == 'field.edit') {
                 $url = array('sid' => $sid, 'task' => $task, 'fid' => SPRequest::int('fid'), 'sp-language' => null);
             }
             foreach ($availableLanguages as $language) {
                 $url['sp-language'] = $language['tag'];
                 $subMenu[] = array('type' => 'url', 'task' => '', 'url' => $url, 'label' => strlen($language['name']) < $sectionLength ? $language['name'] : substr($language['name'], 0, $sectionLength - 3) . ' ...', 'icon' => 'file', 'element' => 'button', 'selected' => $language['tag'] == Sobi::Lang());
             }
         }
     }
     return $subMenu;
 }
Esempio n. 18
0
 /**
  */
 private function editForm()
 {
     if ($this->_task != 'add') {
         $sid = SPRequest::sid();
         $sid = $sid ? $sid : SPRequest::int('pid');
     } else {
         $this->authorise($this->_task, 'own');
         $this->_model = null;
         $sid = SPRequest::int('pid');
         //			$section = SPFactory::Section( Sobi::Section() );
     }
     if ($this->_model && $this->_model->isCheckedOut()) {
         Sobi::Redirect(Sobi::Url(array('sid' => SPRequest::sid())), Sobi::Txt('EN.IS_CHECKED_OUT', $this->_model->get('name')), SPC::ERROR_MSG, true);
     }
     /* determine template package */
     $tplPackage = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE);
     /* load template config */
     $this->template();
     $this->tplCfg($tplPackage);
     /* check if we have stored last edit in cache */
     $this->getCache(SPRequest::string('editentry', null, false, 'cookie'), 'editcache');
     $section = SPFactory::Model('section');
     $section->init(Sobi::Section());
     SPFactory::cache()->setJoomlaCaching(false);
     if ($this->_model) {
         /* handle meta data */
         SPFactory::header()->objMeta($this->_model);
         /* add pathway */
         SPFactory::mainframe()->addObjToPathway($this->_model);
     } else {
         /* handle meta data */
         SPFactory::header()->objMeta($section);
         if ($this->_task == 'add') {
             SPFactory::header()->addKeyword($section->get('efMetaKeys'))->addDescription($section->get('efMetaDesc'));
         }
         SPFactory::mainframe()->addToPathway(Sobi::Txt('EN.ADD_PATH_TITLE'), Sobi::Url('current'));
         SPFactory::mainframe()->setTitle(Sobi::Txt('EN.ADD_TITLE', array('section' => $section->get('name'))));
         /* add pathway */
         SPFactory::mainframe()->addObjToPathway($section);
         $this->setModel(SPLoader::loadModel('entry'));
     }
     $this->_model->formatDatesToEdit();
     $id = $this->_model->get('id');
     if (!$id) {
         $this->_model->set('state', 1);
     }
     if ($this->_task != 'add' && !$this->authorise($this->_task, $this->_model->get('owner') == Sobi::My('id') ? 'own' : '*')) {
         throw new SPException(SPLang::e('YOU_ARE_NOT_AUTH_TO_EDIT_THIS_ENTRY'));
     }
     $this->_model->loadFields(Sobi::Reg('current_section'));
     /* get fields for this section */
     $fields = $this->_model->get('fields');
     if (!count($fields)) {
         throw new SPException(SPLang::e('CANNOT_GET_FIELDS_IN_SECTION', Sobi::Reg('current_section')));
     }
     /* create the validation script to check if required fields are filled in and the filters, if any, match */
     $this->createValidationScript($fields);
     /* check out the model */
     $this->_model->checkOut();
     $class = SPLoader::loadView('entry');
     $view = new $class($this->template);
     $view->assign($this->_model, 'entry');
     $cache = Sobi::Reg('editcache');
     /* get the categories */
     if (isset($cache) && isset($cache['entry_parent'])) {
         $cats = explode(',', $cache['entry_parent']);
     } else {
         $cats = $this->_model->getCategories(true);
     }
     if (count($cats)) {
         $tCats = array();
         foreach ($cats as $cid) {
             $tCats2 = SPFactory::config()->getParentPath((int) $cid, true);
             if (is_array($tCats2) && count($tCats2)) {
                 $tCats[] = implode(Sobi::Cfg('string.path_separator', ' > '), $tCats2);
             }
         }
         if (count($tCats)) {
             $view->assign(implode("\n", $tCats), 'parent_path');
         }
         $view->assign(implode(", ", $cats), 'parents');
     } else {
         $parent = $sid == Sobi::Reg('current_section') ? 0 : $sid;
         if ($parent) {
             $view->assign(implode(Sobi::Cfg('string.path_separator', ' > '), SPFactory::config()->getParentPath($parent, true)), 'parent_path');
         }
         $view->assign($parent, 'parents');
     }
     $view->assign($this->_task, 'task');
     $view->assign($fields, 'fields');
     $view->assign($id, 'id');
     $view->assign($id, 'sid');
     $view->assign(SPFactory::user()->getCurrent(), 'visitor');
     $view->setConfig($this->_tCfg, $this->template);
     $view->setTemplate($tplPackage . '.' . $this->templateType . '.' . ($this->template == 'add' ? 'edit' : $this->template));
     $view->addHidden($sid ? $sid : SPRequest::sid(), 'pid');
     $view->addHidden($id, 'sid');
     $view->addHidden(SPRequest::int('pid') && SPRequest::int('pid') != $id ? SPRequest::int('pid') : Sobi::Section(), 'pid');
     $view->addHidden('entry.submit', SOBI_TASK);
     Sobi::Trigger($this->name(), __FUNCTION__, array(&$view));
     $view->display();
 }
Esempio n. 19
0
 /**
  */
 protected function listSection()
 {
     $parentPath = $this->parentPath(SPRequest::sid());
     $this->assign($parentPath, 'current_path');
     $this->_plgSect = '_SectionListTemplate';
     $c = $this->get('categories');
     $categories = array();
     $entries = array();
     /* get users/authors data first */
     $usersData = array();
     if (count($c)) {
         foreach ($c as $cat) {
             $usersData[] = $cat->get('owner');
         }
         reset($c);
     }
     $usersData = $this->userData($usersData);
     /* handle the categories */
     if (count($c)) {
         foreach ($c as $cat) {
             $category = array();
             /* data needed to display in the list */
             $category['name'] = $cat->get('name');
             $category['state'] = $cat->get('state');
             $category['approved'] = $cat->get('approved');
             if (isset($usersData[$cat->get('owner')])) {
                 $uName = $usersData[$cat->get('owner')]->name;
                 $uUrl = SPUser::userUrl($usersData[$cat->get('owner')]->id);
                 $category['owner'] = "<a href=\"{$uUrl}\">{$uName}</a>";
             } else {
                 $category['owner'] = Sobi::Txt('GUEST');
             }
             /* the rest - case someone need */
             $category['position'] = $cat->get('position');
             $category['createdTime'] = $cat->get('createdTime');
             $category['cout'] = $cat->get('cout');
             $category['coutTime'] = $cat->get('coutTime');
             $category['id'] = $cat->get('id');
             $category['validSince'] = $cat->get('validSince');
             $category['validUntil'] = $cat->get('validUntil');
             $category['description'] = $cat->get('description');
             $category['icon'] = $cat->get('icon');
             $category['introtext'] = $cat->get('introtext');
             $category['parent'] = $cat->get('parent');
             $category['confirmed'] = $cat->get('confirmed');
             $category['counter'] = $cat->get('counter');
             $category['nid'] = $cat->get('nid');
             $category['metaDesc'] = $cat->get('metaDesc');
             $category['metaKeys'] = $cat->get('metaKeys');
             $category['metaAuthor'] = $cat->get('metaAuthor');
             $category['metaRobots'] = $cat->get('metaRobots');
             $category['ownerIP'] = $cat->get('ownerIP');
             $category['updatedTime'] = $cat->get('updatedTime');
             $category['updater'] = $cat->get('updater');
             $category['updaterIP'] = $cat->get('updaterIP');
             $category['version'] = $cat->get('version');
             $category['object'] =& $cat;
             $categories[] = $category;
         }
     }
     /* re-assign the categories */
     $this->assign($categories, 'categories');
     /* handle the fields in this section for header */
     $f = $this->get('fields');
     $entriesOrdering = array(Sobi::Txt('ORDER_BY') => array(), 'e_sid.asc' => Sobi::Txt('EMN.ORDER_BY_ID_ASC'), 'e_sid.desc' => Sobi::Txt('EMN.ORDER_BY_ID_DESC'), $this->get('entries_field') . '.asc' => Sobi::Txt('EMN.ORDER_BY_NAME_ASC'), $this->get('entries_field') . '.desc' => Sobi::Txt('EMN.ORDER_BY_NAME_DESC'), 'state.asc' => Sobi::Txt('EMN.ORDER_BY_STATE_ASC'), 'state.desc' => Sobi::Txt('EMN.ORDER_BY_STATE_DESC'), 'createdTime.asc' => Sobi::Txt('EMN_ORDER_BY_CREATION_DATE_ASC'), 'createdTime.desc' => Sobi::Txt('EMN_ORDER_BY_CREATION_DATE_DESC'), 'updatedTime.asc' => Sobi::Txt('EMN_ORDER_BY_UPDATE_DATE_ASC'), 'updatedTime.desc' => Sobi::Txt('EMN_ORDER_BY_UPDATE_DATE_DESC'), 'approved.asc' => Sobi::Txt('EMN.ORDER_BY_APPROVAL_ASC'), 'approved.desc' => Sobi::Txt('EMN.ORDER_BY_APPROVAL_DESC'));
     if ($this->get('task') == 'view') {
         $entriesOrdering['position.asc'] = Sobi::Txt('EMN.ORDER_BY_ORDER_ASC');
         $entriesOrdering['position.desc'] = Sobi::Txt('EMN.ORDER_BY_ORDER_DESC');
     }
     $customFields = array();
     $customHeader = array();
     if (count($f)) {
         /* @var SPField $fit */
         foreach ($f as $field) {
             $entriesOrdering[Sobi::Txt('EMN.ORDER_BY_FIELD')][$field->get('nid') . '.asc'] = '\'' . $field->get('name') . '\' ' . Sobi::Txt('EMN.ORDER_BY_FIELD_ASC');
             $entriesOrdering[Sobi::Txt('EMN.ORDER_BY_FIELD')][$field->get('nid') . '.desc'] = '\'' . $field->get('name') . '\' ' . Sobi::Txt('EMN.ORDER_BY_FIELD_DESC');
             $customFields[] = $field->get('nid');
             $customHeader[] = array('content' => $field->get('name'), 'attributes' => array('type' => 'text'));
         }
     }
     $entriesOrdering['owner.desc'] = Sobi::Txt('EMN.ORDER_BY_OWNER');
     $this->assign($customHeader, 'customHeader');
     $this->assign($customFields, 'custom_fields');
     $this->assign($entriesOrdering, 'entriesOrdering');
     /* handle the entries */
     $e = $this->get('entries');
     if (count($e)) {
         /* get users/authors data first */
         $usersData = array();
         foreach ($e as $i => $sid) {
             $e[$i] = SPFactory::EntryRow($sid);
             $usersData[] = $e[$i]->get('owner');
         }
         reset($e);
         $usersData = $this->userData($usersData);
         foreach ($e as $sentry) {
             /* @var SPEntryAdm $sentry */
             $entry = array();
             $entry['state'] = $sentry->get('state');
             $entry['approved'] = $sentry->get('approved');
             if (isset($usersData[$sentry->get('owner')])) {
                 $uName = $usersData[$sentry->get('owner')]->name;
                 $uUrl = SPUser::userUrl($usersData[$sentry->get('owner')]->id);
                 $entry['owner'] = "<a href=\"{$uUrl}\">{$uName}</a>";
             } else {
                 $entry['owner'] = Sobi::Txt('GUEST');
             }
             $catPosition = $sentry->getCategories();
             if (SPRequest::sid() && isset($catPosition[SPRequest::sid()])) {
                 $sentry->position = $catPosition[SPRequest::sid()]['position'];
             }
             /* the rest - case someone need */
             $entry['position'] = $sentry->get('position');
             $entry['createdTime'] = $sentry->get('createdTime');
             $entry['cout'] = $sentry->get('cout');
             $entry['coutTime'] = $sentry->get('coutTime');
             $entry['id'] = $sentry->get('id');
             $entry['validSince'] = $sentry->get('validSince');
             $entry['validUntil'] = $sentry->get('validUntil');
             $entry['description'] = $sentry->get('description');
             $entry['icon'] = $sentry->get('icon');
             $entry['introtext'] = $sentry->get('introtext');
             $entry['parent'] = $sentry->get('parent');
             $entry['confirmed'] = $sentry->get('confirmed');
             $entry['counter'] = $sentry->get('counter');
             $entry['nid'] = $sentry->get('nid');
             $entry['metaDesc'] = $sentry->get('metaDesc');
             $entry['metaKeys'] = $sentry->get('metaKeys');
             $entry['metaAuthor'] = $sentry->get('metaAuthor');
             $entry['metaRobots'] = $sentry->get('metaRobots');
             $entry['ownerIP'] = $sentry->get('ownerIP');
             $entry['updatedTime'] = $sentry->get('updatedTime');
             $entry['updater'] = $sentry->get('updater');
             $entry['updaterIP'] = $sentry->get('updaterIP');
             $entry['version'] = $sentry->get('version');
             $fields = $sentry->getFields();
             $entry['fields'] = $fields;
             $entry['valid'] = $sentry->get('valid') ? 'valid' : 'invalid';
             $entry['object'] =& $sentry;
             $entry['name'] = $sentry->get('name');
             /* fields data init */
             if (count($f)) {
                 foreach ($f as $field) {
                     $entry[$field->get('nid')] = null;
                 }
             }
             /* now fill with the real data if any */
             if (count($fields)) {
                 foreach ($fields as $field) {
                     $entry[$field->get('nid')] = $field->data();
                 }
             }
             if (count($customFields)) {
                 foreach ($customFields as $customField) {
                     $entry['customFields'][$customField] = $entry[$customField];
                 }
             }
             $entries[] = $entry;
         }
     }
     $this->assign($entries, 'entries');
 }
Esempio n. 20
0
 /**
  */
 protected function view($allEntries, $term = null)
 {
     if ($allEntries) {
         SPRequest::set('task', 'section.entries');
     } else {
         SPRequest::set('task', 'section.view');
     }
     /* @var SPdb $db */
     $db = SPFactory::db();
     $c = array();
     $e = array();
     if (!Sobi::Section()) {
         Sobi::Error('Section', SPLang::e('Missing section identifier'), SPC::ERROR, 500, __LINE__, __FILE__);
     }
     $this->_model->init(Sobi::Section());
     /* get the lists ordering and limits */
     $eLimit = Sobi::GetUserState('entries.limit', 'elimit', Sobi::Cfg('admin.entries-limit', 25));
     $cLimit = Sobi::GetUserState('categories.limit', 'climit', Sobi::Cfg('admin.categories-limit', 15));
     $eLimStart = SPRequest::int('eSite', 0);
     $cLimStart = SPRequest::int('cSite', 0);
     /* get child categories and entries */
     /* @todo: need better method - the query can be very large with lot of entries */
     if (!$allEntries) {
         $e = $this->_model->getChilds();
         $c = $this->_model->getChilds('category');
     } elseif (!($term && $allEntries)) {
         $c = $this->_model->getChilds('category', true);
         $c[] = Sobi::Section();
         if (count($c)) {
             try {
                 $e1 = $db->dselect('id', 'spdb_relations', array('pid' => $c, 'oType' => 'entry'))->loadResultArray();
                 $e2 = $db->dselect('sid', 'spdb_field_data', array('section' => Sobi::Section(), 'fid' => Sobi::Cfg('entry.name_field')))->loadResultArray();
                 $e = array_merge($e1, $e2);
                 $e = array_unique($e);
             } catch (SPException $x) {
                 Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
             }
         }
     } else {
         try {
             $e = $db->dselect('sid', 'spdb_field_data', array('section' => Sobi::Section(), 'fid' => Sobi::Cfg('entry.name_field'), 'baseData' => "%{$term}%"))->loadResultArray();
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
     }
     // just in case the given site is grater than all existing sites
     $cCount = count($c);
     $cPages = ceil($cCount / $cLimit);
     if ($cLimStart > $cPages) {
         $cLimStart = $cPages;
         SPRequest::set('cSite', $cPages);
     }
     $eCount = count($e);
     $ePages = ceil($eCount / $eLimit);
     if ($eLimStart > $ePages) {
         $eLimStart = $ePages;
         SPRequest::set('eSite', $ePages);
     }
     $entries = array();
     $categories = array();
     /* if there are entries in the root */
     if (count($e)) {
         try {
             $Limit = $eLimit > 0 ? $eLimit : 0;
             $LimStart = $eLimStart ? ($eLimStart - 1) * $eLimit : $eLimStart;
             $eOrder = $this->parseOrdering('entries', 'eorder', 'position.asc', $Limit, $LimStart, $e);
             $results = $db->select('id', 'spdb_object', array('id' => $e, 'oType' => 'entry'), $eOrder, $Limit, $LimStart)->loadResultArray();
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
         foreach ($results as $i => $entry) {
             $entries[$i] = $entry;
         }
     }
     /* if there are categories in the root */
     if (count($c)) {
         try {
             $LimStart = $cLimStart ? ($cLimStart - 1) * $cLimit : $cLimStart;
             $Limit = $cLimit > 0 ? $cLimit : 0;
             $cOrder = $this->parseOrdering('categories', 'corder', 'order.asc', $Limit, $LimStart, $c);
             $results = $db->select('id', 'spdb_object', array('id' => $c, 'oType' => 'category'), $cOrder, $Limit, $LimStart)->loadResultArray();
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
         foreach ($results as $i => $category) {
             $categories[$i] = SPFactory::Category($category);
         }
     }
     /* create menu */
     $mClass = SPLoader::loadClass('views.adm.menu');
     $menu = new $mClass('section.' . $this->_task, Sobi::Section());
     /* load the menu definition */
     $cfg = SPLoader::loadIniFile('etc.adm.section_menu');
     Sobi::Trigger('Create', 'AdmMenu', array(&$cfg));
     if (count($cfg)) {
         foreach ($cfg as $section => $keys) {
             $menu->addSection($section, $keys);
         }
     }
     Sobi::Trigger('AfterCreate', 'AdmMenu', array(&$menu));
     /* create new SigsiuTree */
     $tree = SPLoader::loadClass('mlo.tree');
     $tree = new $tree(Sobi::GetUserState('categories.order', 'corder', 'order.asc'));
     /* set link */
     $tree->setHref(Sobi::Url(array('sid' => '{sid}')));
     $tree->setId('menuTree');
     /* set the task to expand the tree */
     $tree->setTask('category.expand');
     $tree->init(Sobi::Reg('current_section'));
     /* add the tree into the menu */
     $menu->addCustom('AMN.ENT_CAT', $tree->getTree());
     $entriesName = SPFactory::config()->nameField()->get('name');
     $entriesField = SPFactory::config()->nameField()->get('nid');
     $view = SPFactory::View('section', true);
     $view->assign($entriesName, 'entries_name')->assign($entriesField, 'entries_field')->assign($eLimit, 'entries-limit')->assign($cLimit, 'categories-limit')->assign(SPRequest::int('eSite', 1), 'entries-site')->assign(SPRequest::int('cSite', 1), 'categories-site')->assign($cCount, 'categories-count')->assign($eCount, 'entries-count')->assign($this->_task, 'task')->assign($term, 'filter')->assign($this->customCols(), 'fields')->assign($this->_model, 'section')->assign($categories, 'categories')->assign($entries, 'entries')->assign(SPFactory::config()->nameField()->get('name'), 'entries_name')->assign($menu, 'menu')->assign(Sobi::GetUserState('entries.eorder', 'eorder', 'order.asc'), 'ordering')->assign(Sobi::GetUserState('categories.corder', 'corder', 'order.asc'), 'corder')->assign(Sobi::Section(true), 'category')->addHidden(Sobi::Section(), 'pid')->addHidden(SPRequest::sid(), 'sid');
     Sobi::Trigger('Section', 'View', array(&$view));
     $view->display();
 }
Esempio n. 21
0
 protected function view()
 {
     /* determine template package */
     $tplPckg = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE);
     Sobi::ReturnPoint();
     $this->_task = 'alpha';
     if (!$this->_model) {
         $this->setModel('section');
         $this->_model->init(Sobi::Section());
     }
     $this->visible();
     /* load template config */
     $this->template();
     $this->tplCfg($tplPckg);
     /* get limits - if defined in template config - otherwise from the section config */
     $eLimit = $this->tKey($this->template, 'entries_limit', Sobi::Cfg('list.entries_limit', 2));
     $eInLine = $this->tKey($this->template, 'entries_in_line', Sobi::Cfg('list.entries_in_line', 2));
     /* get the site to display */
     $site = SPRequest::int('site', 1);
     $eLimStart = ($site - 1) * $eLimit;
     $eCount = count($this->getEntries(0, 0, true));
     $entries = $this->getEntries($eLimit, $site);
     $compare = $this->_field ? $this->_field : $this->_nid;
     if (strlen($compare) && $compare != Sobi::Cfg('alphamenu.primary_field')) {
         $t = 'list.alpha.' . strtolower($this->_letter) . '.' . $this->_nid;
     } else {
         $t = 'list.alpha.' . strtolower($this->_letter);
     }
     $pn = SPFactory::Instance('helpers.pagenav_' . $this->tKey($this->template, 'template_type', 'xslt'), $eLimit, $eCount, $site, array('sid' => SPRequest::sid(), 'task' => $t));
     $cUrl = array('sid' => SPRequest::sid(), 'task' => $t);
     if (SPRequest::int('site', 0)) {
         $cUrl['site'] = SPRequest::int('site', 0);
     }
     SPFactory::header()->addCanonical(Sobi::Url($cUrl, true, true, true));
     /* handle meta data */
     SPFactory::header()->objMeta($this->_model);
     $letter = urldecode(SPRequest::cmd('letter'));
     /* add pathway */
     if (!$this->_fieldType) {
         SPFactory::mainframe()->addToPathway(Sobi::Txt('AL.PATH_TITLE', array('letter' => $letter)), Sobi::Url('current'));
         SPFactory::header()->addTitle(Sobi::Txt('AL.TITLE', array('letter' => $letter, 'section' => $this->_model->get('name'))), array(ceil($eCount / $eLimit), $site));
     } else {
         $field = SPFactory::Model('field');
         $field->init($this->_field);
         SPFactory::mainframe()->addToPathway(Sobi::Txt('AL.PATH_TITLE_FIELD', array('letter' => $letter, 'field' => $field->get('name'))), Sobi::Url('current'));
         SPFactory::header()->addTitle(Sobi::Txt('AL.TITLE_FIELD', array('letter' => $letter, 'section' => $this->_model->get('name'), 'field' => $field->get('name'))), array(ceil($eCount / $eLimit), $site));
     }
     /* get view class */
     $view = SPFactory::View('listing');
     $view->assign($eLimit, '$eLimit');
     $view->assign($eLimStart, '$eLimStart');
     $view->assign($eCount, '$eCount');
     $view->assign($eInLine, '$eInLine');
     $view->assign($this->_task, 'task');
     $view->assign($this->_model, 'section');
     $view->assign(Sobi::Txt('AL.PATH_TITLE', array('letter' => $this->_letter)), 'listing_name');
     $view->setConfig($this->_tCfg, $this->template);
     $view->setTemplate($tplPckg . '.' . $this->templateType . '.' . $this->template);
     $view->assign($pn->get(), 'navigation');
     $view->assign(SPFactory::user()->getCurrent(), 'visitor');
     $view->assign($entries, 'entries');
     Sobi::Trigger('AlphaListing', 'View', array(&$view));
     $view->display();
 }
Esempio n. 22
0
 protected function view()
 {
     /* determine template package */
     $tplPackage = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE);
     Sobi::ReturnPoint();
     $this->_task = 'user';
     if (!$this->_model) {
         $this->setModel('section');
         $this->_model->init(Sobi::Section());
     }
     $this->visible();
     /* load template config */
     $this->template();
     $this->tplCfg($tplPackage);
     /* get limits - if defined in template config - otherwise from the section config */
     $eLimit = $this->tKey($this->template, 'entries_limit', Sobi::Cfg('list.entries_limit', 2));
     $eInLine = $this->tKey($this->template, 'entries_in_line', Sobi::Cfg('list.entries_in_line', 2));
     $url = array('sid' => SPRequest::sid(), 'task' => 'list.user');
     if (SPRequest::int('uid')) {
         $url['uid'] = SPRequest::int('uid');
         $this->uid = (int) SPRequest::int('uid');
     } else {
         $this->uid = (int) Sobi::My('id');
     }
     $this->user = SPJoomlaUser::getBaseData((int) $this->uid);
     if (!$this->user) {
         throw new SPException(SPLang::e('UNAUTHORIZED_ACCESS'));
     }
     /* get the site to display */
     $site = SPRequest::int('site', 1);
     $eLimStart = ($site - 1) * $eLimit;
     $eOrder = $this->parseOrdering('entries', 'eorder', $this->tKey($this->template, 'entries_ordering', Sobi::Cfg('list.entries_ordering', 'name.asc')));
     $eCount = count($this->getEntries($eOrder, 0, 0, true, array('spo.owner' => $this->uid), true, Sobi::Section()));
     $entries = $this->getEntries($eOrder, $eLimit, $eLimStart, true, array('spo.owner' => $this->uid), true, Sobi::Section());
     //		$eCount = count( $this->_getEntries( 0, 0, true ) );
     //		$entries = $this->_getEntries( $eLimit, $site );
     $pn = SPFactory::Instance('helpers.pagenav_' . $this->tKey($this->template, 'template_type', 'xslt'), $eLimit, $eCount, $site, $url);
     if (SPRequest::int('site', 0)) {
         $url['site'] = SPRequest::int('site', 0);
     }
     SPFactory::header()->addCanonical(Sobi::Url($url, true, true, true));
     /* handle meta data */
     SPFactory::header()->objMeta($this->_model);
     SPFactory::mainframe()->addToPathway(Sobi::Txt('UL.PATH_TITLE', array('username' => $this->user->username, 'user' => $this->user->name)), Sobi::Url('current'));
     SPFactory::header()->addTitle(Sobi::Txt('UL.TITLE', array('username' => $this->user->username, 'user' => $this->user->name, 'section' => $this->_model->get('name'))), array(ceil($eCount / $eLimit), $site));
     /* add pathway */
     /* get view class */
     $view = SPFactory::View('listing');
     $view->assign($eLimit, '$eLimit');
     $view->assign($eLimStart, '$eLimStart');
     $view->assign($eCount, '$eCount');
     $view->assign($eInLine, '$eInLine');
     $view->assign($this->_task, 'task');
     $view->assign($this->_model, 'section');
     $view->setConfig($this->_tCfg, $this->template);
     $view->setTemplate($tplPackage . '.' . $this->templateType . '.' . $this->template);
     $view->assign($pn->get(), 'navigation');
     $view->assign(SPFactory::user()->getCurrent(), 'visitor');
     $view->assign($entries, 'entries');
     Sobi::Trigger('UserListing', 'View', array(&$view));
     $view->display();
 }
Esempio n. 23
0
 /**
  */
 private function editForm()
 {
     /* if adding new */
     if (!$this->_model || $this->_task == 'add') {
         $this->setModel(SPLoader::loadModel('category'));
     }
     $this->checkTranslation();
     $this->_model->formatDatesToEdit();
     $id = $this->_model->get('id');
     if (!$id) {
         $this->_model->set('state', 1);
         $this->_model->set('parent', SPRequest::sid());
     }
     if ($this->_model->isCheckedOut()) {
         SPFactory::message()->error(Sobi::Txt('CAT.IS_CHECKED_OUT'), false);
     } else {
         $this->_model->checkOut();
     }
     $view = SPFactory::View('category', true);
     $view->assign($this->_model, 'category')->assign($this->_task, 'task')->assign(SPFactory::CmsHelper()->userSelect('category.owner', $this->_model->get('owner') ? $this->_model->get('owner') : ($this->_model->get('id') ? 0 : Sobi::My('id')), true), 'owner')->assign($id, 'cid')->addHidden(Sobi::Section(), 'pid');
     Sobi::Trigger('Category', 'EditView', array(&$view));
     $view->display();
 }
Esempio n. 24
0
 /**
  */
 public function storeView($head)
 {
     if (!Sobi::Cfg('cache.xml_enabled') || $this->_cachedView || Sobi::My('id') && Sobi::Cfg('cache.xml_no_reg')) {
         return false;
     }
     if ($this->view['xml']) {
         $xml = $this->view['xml'];
         $template = Sobi::Reg('cache_view_template');
         if (!$template) {
             $template = $this->view['template'];
             $template = str_replace(SPLoader::translateDirPath(Sobi::Cfg('section.template'), 'templates'), null, $template);
         }
         $root = $xml->documentElement;
         $root->removeChild($root->getElementsByTagName('visitor')->item(0));
         if ($root->getElementsByTagName('messages')->length) {
             $root->removeChild($root->getElementsByTagName('messages')->item(0));
         }
         /** @var $header DOMDocument */
         $header = SPFactory::Instance('types.array')->toXML($head, 'header', true);
         $root->appendChild($xml->importNode($header->documentElement, true));
         if ($this->view['data'] && count($this->view['data'])) {
             $data = SPFactory::Instance('types.array')->toXML($this->view['data'], 'cache-data', true);
             $root->appendChild($xml->importNode($data->documentElement, true));
         }
         $request = $this->viewRequest();
         $request['template'] = $template;
         $configFiles = SPFactory::registry()->get('template_config');
         $request['configFile'] = str_replace('"', "'", json_encode($configFiles));
         $request['cid'] = 'NULL';
         $request['created'] = 'FUNCTION:NOW()';
         $fileName = md5(serialize($request));
         $request['fileName'] = $fileName;
         $filePath = SPLoader::path('var.xml.' . $fileName, 'front', false, 'xml');
         $content = $xml->saveXML();
         $content = str_replace('&nbsp;', '&#160;', $content);
         $content = preg_replace('/[^\\x{0009}\\x{000a}\\x{000d}\\x{0020}-\\x{D7FF}\\x{E000}-\\x{FFFD}]+/u', null, $content);
         $matches = array();
         preg_match_all('/<(category|entry|subcategory)[^>]*id="(\\d{1,})"/', $content, $matches);
         try {
             $cid = SPFactory::db()->insert('spdb_view_cache', $request, false, true)->insertid();
             $relations = array(SPRequest::sid() => array('cid' => $cid, 'sid' => SPRequest::sid()));
             if (isset($matches[2])) {
                 $ids = array_unique($matches[2]);
                 foreach ($ids as $sid) {
                     $relations[$sid] = array('cid' => $cid, 'sid' => $sid);
                 }
             }
             SPFactory::db()->insertArray('spdb_view_cache_relation', $relations);
             SPFs::write($filePath, $content);
         } catch (SPException $x) {
             Sobi::Error('XML-Cache', $x->getMessage());
         }
     }
 }
Esempio n. 25
0
 private function getLink($button)
 {
     $link = '#';
     if (isset($button['type'])) {
         switch ($button['type']) {
             case 'help':
                 $link = 'https://www.sigsiu.net/help_screen/' . Sobi::Reg('help_task', SPRequest::task());
                 break;
             case 'url':
                 if (isset($button['sid']) && $button['sid'] == 'true') {
                     $link = Sobi::Url(array('task' => $button['task'], 'sid' => SPRequest::sid('request', SPRequest::int('pid'), true)));
                 } else {
                     $link = Sobi::Url($button['task'] ? $button['task'] : $button['url']);
                 }
                 break;
         }
     }
     return $link;
 }
Esempio n. 26
0
 /**
  * @param string $task
  */
 function __construct($task)
 {
     SPLoader::loadClass('base.exception');
     set_error_handler('SPExceptionHandler');
     $this->_err = ini_set('display_errors', 'on');
     $this->_mem = memory_get_usage();
     $this->_time = microtime();
     $this->_task = $task;
     /* load all needed classes */
     SPLoader::loadClass('base.factory');
     SPLoader::loadClass('base.object');
     SPLoader::loadClass('base.const');
     SPLoader::loadClass('base.filter');
     SPLoader::loadClass('base.request');
     SPLoader::loadClass('sobi');
     SPLoader::loadClass('base.config');
     /* authorise access */
     $this->checkAccess();
     /* initialise mainframe interface to CMS */
     $this->_mainframe =& SPFactory::mainframe();
     /* get sid if any */
     $this->_sid = SPRequest::sid();
     /* determine section */
     $this->getSection();
     /* initialise config */
     $this->createConfig();
     ini_set('display_errors', Sobi::Cfg('debug.display_errors', false));
     $this->_deb = error_reporting(Sobi::Cfg('debug.level', 0));
     /* trigger plugin */
     Sobi::Trigger('AdminStart');
     /* initialise translator and load language files */
     SPLoader::loadClass('cms.base.lang');
     SPLang::setLang(Sobi::Lang());
     try {
         SPLang::registerDomain('admin');
     } catch (SPException $x) {
         Sobi::Error('CoreCtrl', SPLang::e('Cannot register language domain: %s.', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     /* load admin html files */
     SPFactory::header()->initBase(true);
     /** @noinspection PhpParamsInspection */
     if ($this->_section) {
         $sectionName = SPLang::translateObject($this->_section, 'name', 'section');
         SPFactory::registry()->set('current_section_name', SPLang::clean($sectionName[$this->_section]['value']));
     }
     if ($this->_section && !Sobi::Cfg('section.template')) {
         SPFactory::config()->set('template', SPC::DEFAULT_TEMPLATE, 'section');
     }
     /* check if it wasn't plugin custom task */
     if (!Sobi::Trigger('custom', 'task', array($this, SPRequest::task()))) {
         /* if not, start to route */
         try {
             $this->route();
         } catch (SPException $x) {
             Sobi::Error('CoreCtrl', SPLang::e('Cannot route: %s.', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
     }
     return true;
 }
Esempio n. 27
0
    /**
     */
    private function editForm()
    {
        $sid = SPRequest::int('pid');
        $sid = $sid ? $sid : SPRequest::sid();
        $view = SPFactory::View('entry', true);
        $this->checkTranslation();
        /* if adding new */
        if (!$this->_model) {
            $this->setModel(SPLoader::loadModel('entry'));
        }
        $this->_model->formatDatesToEdit();
        $id = $this->_model->get('id');
        if (!$id) {
            $this->_model->set('state', 1);
            $this->_model->set('approved', 1);
        } else {
            $view->assign($view->languages(), 'languages-list');
        }
        $this->_model->loadFields(Sobi::Reg('current_section'), true);
        $this->_model->formatDatesToEdit();
        if ($this->_model->isCheckedOut()) {
            SPFactory::message()->error(Sobi::Txt('EN.IS_CHECKED_OUT', $this->_model->get('name')), false);
        } else {
            /* check out the model */
            $this->_model->checkOut();
        }
        /* get fields for this section */
        /* @var SPEntry $this ->_model */
        $fields = $this->_model->get('fields');
        if (!count($fields)) {
            throw new SPException(SPLang::e('CANNOT_GET_FIELDS_IN_SECTION', Sobi::Reg('current_section')));
        }
        $revisionChange = false;
        $rev = SPRequest::cmd('revision');
        $revisionsDelta = array();
        if ($rev) {
            $revision = SPFactory::message()->getRevision(SPRequest::cmd('revision'));
            if (isset($revision['changes']) && count($revision['changes'])) {
                SPFactory::message()->warning(Sobi::Txt('HISTORY_REVISION_WARNING', $revision['changedAt']), false);
                foreach ($fields as $i => $field) {
                    if ($field->get('enabled') && $field->enabled('form')) {
                        if (isset($revision['changes']['fields'][$field->get('nid')])) {
                            $revisionData = $revision['changes']['fields'][$field->get('nid')];
                        } else {
                            $revisionData = null;
                        }
                        $currentData = $field->getRaw();
                        if (is_array($revisionData) && !is_array($currentData)) {
                            try {
                                $currentData = SPConfig::unserialize($currentData);
                            } catch (SPException $x) {
                            }
                        }
                        if ($revisionData || $currentData) {
                            if (md5(serialize($currentData)) != md5(serialize($revisionData))) {
                                $field->revisionChanged()->setRawData($revisionData);
                            }
                        }
                        $fields[$i] = $field;
                    }
                }
                unset($revision['changes']['fields']);
                foreach ($revision['changes'] as $attr => $value) {
                    if ($value != $this->_model->get($attr)) {
                        $revisionsDelta[$attr] = $value;
                        $this->_model->setRevData($attr, $value);
                    }
                }
                $revisionChange = true;
            } else {
                SPFactory::message()->error(Sobi::Txt('HISTORY_REVISION_NOT_FOUND'), false)->setSystemMessage();
            }
        }
        $f = array();
        foreach ($fields as $field) {
            if ($field->get('enabled') && $field->enabled('form')) {
                $f[] = $field;
            }
        }
        /* create the validation script to check if required fields are filled in and the filters, if any, match */
        $this->createValidationScript($fields);
        $view->assign($this->_model, 'entry');
        /* get the categories */
        $cats = $this->_model->getCategories(true);
        if (count($cats)) {
            $tCats = array();
            foreach ($cats as $cid) {
                /* ROTFL ... damn I like arrays ;-) */
                $tCats2 = SPFactory::config()->getParentPath($cid, true);
                if (is_array($tCats2) && count($tCats2)) {
                    $tCats[] = implode(Sobi::Cfg('string.path_separator'), $tCats2);
                }
            }
            if (count($tCats)) {
                $view->assign(implode("\n", $tCats), 'parent_path');
            }
            $view->assign(implode(", ", $cats), 'parents');
        } elseif ($this->_model->get('valid')) {
            $parent = $sid == Sobi::Reg('current_section') ? 0 : $sid;
            if ($parent) {
                $view->assign(implode(Sobi::Cfg('string.path_separator', ' > '), SPFactory::config()->getParentPath($parent, true)), 'parent_path');
            }
            $view->assign($parent, 'parents');
        } else {
            $n = null;
            $view->assign($n, 'parents');
            $view->assign($n, 'parent_path');
        }
        $history = array();
        $messages = SPFactory::message()->getHistory($id);
        if (count($messages)) {
            foreach ($messages as $message) {
                $message['change'] = Sobi::Txt('HISTORY_CHANGE_TYPE_' . str_replace('-', '_', strtoupper($message['change'])));
                $message['site'] = Sobi::Txt('HISTORY_CHANGE_AREA_' . strtoupper($message['site']));
                if (strlen($message['reason'])) {
                    $message['status'] = 1;
                } else {
                    $message['status'] = 0;
                }
                $history[] = $message;
            }
        }
        $versioningAdminBehaviour = Sobi::Cfg('entry.versioningAdminBehaviour', 1);
        if ($versioningAdminBehaviour || !Sobi::Cfg('entry.versioning', true)) {
            SPFactory::header()->addJsCode('
				SobiPro.jQuery( document ).ready( function () { SobiPro.jQuery( "[rel=\'entry.saveWithRevision\']" ).parent().css( "display", "none" ); } );
			');
        }
        $view->assign($this->_task, 'task')->assign($f, 'fields')->assign($id, 'id')->assign($history, 'history')->assign($revisionChange, 'revision-change')->assign($revisionsDelta, 'revision')->assign($versioningAdminBehaviour, 'history-behaviour')->assign(SPFactory::CmsHelper()->userSelect('entry.owner', $this->_model->get('owner') ? $this->_model->get('owner') : ($this->_model->get('id') ? 0 : Sobi::My('id')), true), 'owner')->assign(Sobi::Reg('current_section'), 'sid')->determineTemplate('entry', 'edit')->addHidden($rev, 'revision')->addHidden($sid, 'pid');
        $view->display();
    }
Esempio n. 28
0
 /**
  * Route task
  */
 public function execute()
 {
     /* parent class executes the plugins */
     $r = false;
     $task = $this->_task;
     if (strstr($this->_task, '.')) {
         $task = explode('.', $this->_task);
         $this->_fieldType = $task[1];
         $task = $task[0];
     }
     switch ($task) {
         case 'list':
             $r = true;
             $this->listFields();
             break;
         case 'add':
         case 'edit':
             $r = true;
             $this->edit();
             break;
         case 'cancel':
             $r = true;
             $this->checkIn();
             $this->response(Sobi::Back());
             break;
         case 'addNew':
             $r = true;
             Sobi::Redirect(Sobi::Url(array('task' => 'field.edit', 'fid' => $this->saveNew(), 'sid' => SPRequest::sid())));
             break;
         case 'apply':
         case 'save':
             $r = true;
             $this->save();
             break;
         case 'clone':
             $r = true;
             $this->save(true);
             break;
         case 'delete':
             $r = true;
             SPFactory::cache()->cleanSection();
             $this->response(Sobi::Url(array('task' => 'field.list', 'pid' => Sobi::Section())), $this->delete(), true);
             break;
         case 'reorder':
             $r = true;
             $this->reorder();
             break;
         case 'revisions':
             $r = true;
             $this->revisions();
             break;
         case 'up':
         case 'down':
             $r = true;
             $this->singleReorder($this->_task == 'up');
             break;
         case 'hide':
         case 'publish':
         case 'setRequired':
         case 'setNotRequired':
         case 'setEditable':
         case 'setNotEditable':
         case 'setFee':
         case 'setFree':
         case 'toggle':
             $r = true;
             $this->authorise($this->_task);
             SPFactory::cache()->cleanSection();
             $this->response(Sobi::Back(), $this->changeState($task), true);
             break;
         default:
             /* case plugin didn't registered this task, it was an error */
             if (!Sobi::Trigger('Execute', $this->name(), array(&$this))) {
                 $fid = SPRequest::int('fid');
                 $method = $this->_task;
                 if ($fid) {
                     SPLoader::loadModel('field', true);
                     $fdata = $this->loadField($fid);
                     $field = new SPAdmField();
                     $field->extend($fdata);
                     try {
                         $field->{$method}();
                     } catch (SPException $x) {
                         Sobi::Error($this->name(), SPLang::e('SUCH_TASK_NOT_FOUND', SPRequest::task()), SPC::NOTICE, 404, __LINE__, __FILE__);
                     }
                 } elseif (!parent::execute()) {
                     Sobi::Error($this->name(), SPLang::e('SUCH_TASK_NOT_FOUND', SPRequest::task()), SPC::NOTICE, 404, __LINE__, __FILE__);
                 }
             }
             break;
     }
     return $r;
 }
Esempio n. 29
0
 /**
  * @todo Enter description here...
  *
  * @param array $ordering
  * @param string $type
  * @param string $id
  * @param string $fname
  * @return string
  */
 public static function tableHeader($ordering, $type, $id = 'sid', $fname = 'order', $def = 'position.asc')
 {
     $header = array();
     $current = SPFactory::user()->getUserState($type . '.order', $fname, $def);
     if (strstr($current, '.')) {
         $current = explode('.', $current);
         $newDirect = trim($current[1]) == 'asc' ? 'desc' : 'asc';
         $current = $current[0];
     }
     $sid = SPRequest::sid() ? SPRequest::sid() : SPRequest::int('pid');
     if (is_array($ordering) && count($ordering)) {
         foreach ($ordering as $order => $active) {
             $class = null;
             $params = array();
             if (is_array($active)) {
                 $params = $active;
                 $active = $active['type'];
             }
             switch ($active) {
                 case SP_TBL_HEAD_RAW:
                     $header[$order] = Sobi::Txt($type . '.header_' . $order);
                     break;
                 case 1:
                 case 3:
                 case 4:
                 case 5:
                 case 6:
                     $direction = 'asc';
                     $ico = null;
                     $aico = null;
                     if (isset($params['order'])) {
                         $sortBy = $params['order'];
                     } else {
                         $sortBy = $order;
                     }
                     $label = Sobi::Txt($type . '.header_' . $order);
                     $title = Sobi::Txt($type . '.header_order_by_' . $order);
                     if ($sortBy == $current) {
                         $class = "class=\"selected\"";
                         $ico = Sobi::Cfg('list_icons.sort_direction_' . ($newDirect == 'asc' ? 'desc' : 'asc'));
                         $ico = "&nbsp;<img src=\"{$ico}\"/>&nbsp;";
                         $direction = $newDirect;
                     }
                     if ($active == SP_TBL_HEAD_SORTABLE_FIELD) {
                         $label = $params['label'];
                         $title = Sobi::Txt('LIST.ORDER_BY_FIELD', array('field' => $label));
                     }
                     if ($active == SP_TBL_HEAD_STATE) {
                         SPLoader::loadClass('html.tooltip');
                         $msg = Sobi::Txt('LIST.MAKE_SELECTION');
                         $onclk = " onclick=\"if( document.adminForm.boxchecked.value == 0 ) { alert( '{$msg}' ); } else { submitbutton( '{$type}.publish' ); }\"";
                         $url = "#";
                         $ai = Sobi::Cfg('list_icons.enable');
                         $s = Sobi::Txt('LIST.ENABLE_S', array('type' => Sobi::Txt(strtoupper($type))));
                         $a = Sobi::Txt($type . '.enable_expl');
                         $aico = SPTooltip::toolTip($a, $s, $ai);
                         $aico = "&nbsp;<span class=\"headerStateIcons\"><a href=\"{$url}\"{$onclk}>{$aico}</a></span>";
                         $ui = Sobi::Cfg('list_icons.disable');
                         $s = Sobi::Txt('LIST.DISABLE_S', array('type' => Sobi::Txt(strtoupper($type))));
                         $a = Sobi::Txt($type . '.disable_expl');
                         $uico = SPTooltip::toolTip($a, $s, $ui);
                         $onclk = " onclick=\"if( document.adminForm.boxchecked.value == 0 ) { alert( '{$msg}' ); } else { submitbutton( '{$type}.hide' ); }\"";
                         $uico = "&nbsp;<span class=\"headerStateIcons\"><a href=\"{$url}\"{$onclk}>{$uico}</a></span>";
                         $aico .= $uico;
                     }
                     if ($active == SP_TBL_HEAD_APPROVAL) {
                         SPLoader::loadClass('html.tooltip');
                         $msg = Sobi::Txt('LIST.MAKE_SELECTION');
                         $onclk = " onclick=\"if( document.adminForm.boxchecked.value == 0 ) { alert( '{$msg}' ); } else { submitbutton( '{$type}.approve' ); }\"";
                         $url = "#";
                         $ai = Sobi::Cfg('list_icons.approve');
                         $s = Sobi::Txt($type . '.approve');
                         $a = Sobi::Txt($type . '.approve_expl');
                         $aico = SPTooltip::toolTip($a, $s, $ai);
                         $aico = "&nbsp;<span class=\"headerAppIcons\"><a href=\"{$url}\"{$onclk}>{$aico}</a></span>";
                         $ui = Sobi::Cfg('list_icons.disable');
                         $s = Sobi::Txt($type . '.unapprove');
                         $a = Sobi::Txt($type . '.unapprove_expl');
                         $uico = SPTooltip::toolTip($a, $s, $ui);
                         $onclk = " onclick=\"if( document.adminForm.boxchecked.value == 0 ) { alert( '{$msg}' ); } else { submitbutton( '{$type}.unapprove' ); }\"";
                         $uico = "&nbsp;<span class=\"headerAppIcons\"><a href=\"{$url}\"{$onclk}>{$uico}</a></span>";
                         $aico .= $uico;
                     }
                     if ($active == SP_TBL_HEAD_ORDER) {
                         SPLoader::loadClass('html.tooltip');
                         $url = "#";
                         $onclk = " onclick=\"SPReorder( '{$type}', {$sid} );\" ";
                         $aico = "&nbsp;<span class=\"headerStateIcons\"><a href=\"{$url}\" title=\"{$a}\">{$aico}</a></span>";
                         $ui = Sobi::Cfg('list_icons.order');
                         $s = Sobi::Txt($type . '.save_order');
                         $a = Sobi::Txt($type . '.save_order_expl');
                         $uico = SPTooltip::toolTip($a, $s, $ui);
                         $uico = "&nbsp;<span class=\"headerOrderIcon\"><a href=\"{$url}\"{$onclk}>{$uico}</a></span>";
                         $aico .= $uico;
                     }
                     $header[$order] = "<a {$class} href=\"javascript:SPOrdering( '{$sortBy}','{$direction}', '{$fname}', {$sid} );\" title=\"{$title}\">{$label}</a>&nbsp;{$ico}{$aico}";
                     break;
                 case SP_TBL_HEAD_SELECTION_BOX:
                     $name = Sobi::Txt($type . '.header_toggle');
                     $header[$order] = "<input type=\"checkbox\" name=\"toggle\" id=\"toggel_{$id}\" title=\"{$name}\" value=\"1\" onclick=\"SPCheckListElements('{$id}', this );\"/>";
                     break;
             }
         }
     }
     return $header;
 }
Esempio n. 30
0
 /**
  * Adding new field
  * Save base data and redirect to the edit function when the field type has been chosed
  * @return integer
  */
 public function saveNew($attr)
 {
     $db = SPFactory::db();
     /* cast all needed data and clean - it is possible just in admin panel but "strzeżonego pan Bóg strzeże" ;-) */
     $base = array();
     $base['section'] = isset($attr['section']) && $attr['section'] ? $attr['section'] : SPRequest::sid();
     if (isset($attr['name'])) {
         $base['name'] = $db->escape($attr['name']);
     }
     if (isset($attr['description'])) {
         $base['description'] = $db->escape($attr['description']);
     } else {
         $base['description'] = null;
     }
     if (isset($attr['suffix'])) {
         $base['suffix'] = $db->escape($attr['suffix']);
     } else {
         $base['suffix'] = null;
     }
     if (isset($attr['nid'])) {
         $base['nid'] = $this->nid($db->escape(preg_replace('/[^[:alnum:]\\-\\_]/', null, $attr['nid'])), true);
     }
     if (isset($attr['cssClass'])) {
         $base['cssClass'] = $db->escape(preg_replace('/[^[:alnum:]\\-\\_ ]/', null, $attr['cssClass']));
     }
     if (isset($attr['notice'])) {
         $base['notice'] = $db->escape($attr['notice']);
     }
     if (isset($attr['showIn'])) {
         $base['showIn'] = $db->escape(preg_replace('/[^[:alnum:]\\.\\-\\_]/', null, $attr['showIn']));
     }
     if (isset($attr['fieldType'])) {
         $base['fieldType'] = preg_replace('/[^[:alnum:]\\.\\-\\_]/', null, $attr['fieldType']);
     }
     if (isset($attr['type'])) {
         $base['fieldType'] = preg_replace('/[^[:alnum:]\\.\\-\\_]/', null, $attr['type']);
     }
     if (isset($attr['description'])) {
         $base['description'] = $db->escape($attr['description']);
     }
     if (isset($attr['enabled'])) {
         $base['enabled'] = (int) $attr['enabled'];
     }
     if (isset($attr['required'])) {
         $base['required'] = (int) $attr['required'];
     }
     if (isset($attr['adminField'])) {
         $base['adminField'] = (int) $attr['adminField'];
     }
     if (isset($attr['adminField']) && $attr['adminField']) {
         $attr['required'] = false;
     }
     if (isset($attr['editable'])) {
         $base['editable'] = (int) $attr['editable'];
     }
     if (isset($attr['editLimit'])) {
         $base['editLimit'] = (int) $attr['editLimit'];
         $base['editLimit'] = $base['editLimit'] > 0 ? $base['editLimit'] : -1;
     }
     if (isset($attr['isFree'])) {
         $base['isFree'] = (int) $attr['isFree'];
     }
     if (isset($attr['withLabel'])) {
         $base['withLabel'] = (int) $attr['withLabel'];
     }
     if (isset($attr['inSearch'])) {
         $base['inSearch'] = (int) $attr['inSearch'];
     }
     if (isset($attr['admList'])) {
         $base['admList'] = (int) $attr['admList'];
     }
     if (isset($attr['fee'])) {
         $base['fee'] = (double) $attr['fee'];
     }
     if (isset($attr['section'])) {
         $base['section'] = (int) $attr['section'];
     }
     $base['version'] = 1;
     /* determine the right position */
     try {
         $db->select('MAX( position )', 'spdb_field', array('section' => SPRequest::sid()));
         $base['position'] = (int) $db->loadResult() + 1;
         if (!$base['position']) {
             $base['position'] = 1;
         }
     } catch (SPException $x) {
         Sobi::Error($this->name(), SPLang::e('CANNOT_GET_FIELD_POSITION_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
     }
     /* get database columns and their ordering */
     $cols = $db->getColumns('spdb_field');
     $values = array();
     /* and sort the properties in the same order */
     foreach ($cols as $col) {
         $values[$col] = array_key_exists($col, $base) ? $base[$col] : '';
     }
     /* save new field */
     try {
         $db->insert('spdb_field', $values);
         $this->fid = $db->insertid();
     } catch (SPException $x) {
         Sobi::Error($this->name(), $x->getMessage(), SPC::ERROR, 500, __LINE__, __FILE__);
     }
     /* save language depend properties */
     $labels = array();
     $defLabels = array();
     $labels[] = array('sKey' => 'name', 'sValue' => $base['name'], 'language' => Sobi::Lang(), 'id' => 0, 'oType' => 'field', 'fid' => $this->fid);
     $labels[] = array('sKey' => 'description', 'sValue' => $base['description'], 'language' => Sobi::Lang(), 'id' => 0, 'oType' => 'field', 'fid' => $this->fid);
     $labels[] = array('sKey' => 'suffix', 'sValue' => $base['suffix'], 'language' => Sobi::Lang(), 'id' => 0, 'oType' => 'field', 'fid' => $this->fid);
     if (Sobi::Lang() != Sobi::DefLang()) {
         $defLabels[] = array('sKey' => 'name', 'sValue' => $base['name'], 'language' => Sobi::DefLang(), 'id' => 0, 'oType' => 'field', 'fid' => $this->fid);
         $defLabels[] = array('sKey' => 'suffix', 'sValue' => $base['suffix'], 'language' => Sobi::DefLang(), 'id' => 0, 'oType' => 'field', 'fid' => $this->fid);
         $defLabels[] = array('sKey' => 'description', 'sValue' => $base['description'], 'language' => Sobi::DefLang(), 'id' => 0, 'oType' => 'field', 'fid' => $this->fid);
     }
     if (count($labels)) {
         try {
             if (Sobi::Lang() != Sobi::DefLang()) {
                 $db->insertArray('spdb_language', $defLabels, false, true);
             }
             $db->insertArray('spdb_language', $labels, true);
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('CANNOT_SAVE_FIELD_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
     }
     SPFactory::cache()->cleanSection();
     return $this->fid;
 }