Beispiel #1
0
 public function progress($percent, $message = null, $type = SPC::INFO_MSG, $interval = 1000)
 {
     $this->id = SPRequest::cmd('ProgressMsg', null, 'cookie');
     $percent = ceil($percent);
     $this->msg = strlen($message) ? $message : $this->msg;
     $this->status($message, $percent, $interval, $type);
 }
Beispiel #2
0
 protected function upload()
 {
     $ident = SPRequest::cmd('ident', null, 'post');
     $data = SPRequest::file($ident, 'tmp_name');
     $secret = md5(Sobi::Cfg('secret'));
     if ($data) {
         $properties = SPRequest::file($ident);
         $fileName = md5(SPRequest::file($ident, 'name') . time() . $secret);
         $path = SPLoader::dirPath("tmp.files.{$secret}", 'front', false) . '/' . $fileName;
         /** @var $file SPFile */
         $file = SPFactory::Instance('base.fs.file');
         if (!$file->upload($data, $path)) {
             $this->message(array('type' => 'error', 'text' => SPLang::e('CANNOT_UPLOAD_FILE'), 'id' => ''));
         }
         $path = $file->getPathname();
         $type = $this->check($path);
         $properties['tmp_name'] = $path;
         SPFs::write($path . '.var', SPConfig::serialize($properties));
         $response = array('type' => 'success', 'text' => Sobi::Txt('FILE_UPLOADED', $properties['name'], $type), 'id' => 'file://' . $fileName, 'data' => array('name' => $properties['name'], 'type' => $properties['type'], 'size' => $properties['size']));
     } else {
         $response = array('type' => 'error', 'text' => SPLang::e('CANNOT_UPLOAD_FILE_NO_DATA'), 'id' => '');
     }
     //		$field = SPRequest::cmd( 'field', null );
     $this->message($response);
 }
Beispiel #3
0
 /**
  * @param    string    The control name
  * @param    string    The contents of the text area
  * @param    string    The width of the text area (px or %)
  * @param    string    The height of the text area (px or %)
  * @param    boolean    True and the editor buttons will be displayed
  * @param    array    Associative array of editor parameters
  * @return string
  */
 public function display($name, $html, $width, $height, $buttons, $params)
 {
     if (SPRequest::cmd('format') != 'raw') {
         // public function display($name, $html, $width, $height, $col, $row, $buttons = true, $id = null, $asset = null, $author = null, $params = array())
         $editor = JEditor::getInstance(JFactory::getConfig()->get('editor'));
         //			JFactory::getEditor()->display( $name, $html, $width, $height, '75', '20', $buttons, $params );
         return $editor->display($name, $html, $width, $height, 75, 20, $buttons, null, null, null, $params);
     }
 }
Beispiel #4
0
 public function execute()
 {
     $function = SPRequest::cmd('function');
     SPFactory::header()->addJsFile('jnmenu', true);
     SPLang::load('com_sobipro.sys');
     if (!$function) {
         $this->listFunctions();
     } else {
         $this->loadFunction($function);
     }
 }
Beispiel #5
0
 /**
  */
 protected function view()
 {
     /* determine template package */
     $tplPackage = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE);
     Sobi::ReturnPoint();
     /* 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));
     $cInLine = $this->tKey($this->template, 'categories_in_line', Sobi::Cfg('list.categories_in_line', 2));
     $cLim = $this->tKey($this->template, 'categories_limit', -1);
     $entriesRecursive = $this->tKey($this->template, 'entries_recursive', Sobi::Cfg('list.entries_recursive', false));
     /* get the site to display */
     $site = SPRequest::int('site', 1);
     $eLimStart = ($site - 1) * $eLimit;
     /* get the right ordering */
     $eOrder = $this->parseOrdering('entries', 'eorder', $this->tKey($this->template, 'entries_ordering', Sobi::Cfg('list.entries_ordering', 'name.asc')));
     $cOrder = $this->parseOrdering('categories', 'corder', $this->tKey($this->template, 'categories_ordering', Sobi::Cfg('list.categories_ordering', 'name.asc')));
     $orderings = array('entries' => $eOrder, 'categories' => $cOrder);
     /* get entries */
     $eCount = count($this->getEntries($eOrder, 0, 0, true, null, $entriesRecursive));
     $entries = $this->getEntries($eOrder, $eLimit, $eLimStart, false, null, $entriesRecursive);
     $categories = array();
     if ($cLim) {
         $categories = $this->getCats($cOrder, $cLim);
     }
     /* create page navigation */
     $url = array('sid' => SPRequest::sid(), 'title' => Sobi::Cfg('sef.alias', true) ? $this->_model->get('nid') : $this->_model->get('name'));
     if (SPRequest::cmd('sptpl')) {
         $url['sptpl'] = SPRequest::cmd('sptpl');
     }
     $pnc = SPLoader::loadClass('helpers.pagenav_' . $this->tKey($this->template, 'template_type', 'xslt'));
     /* @var SPPageNavXSLT $pn */
     $pn = new $pnc($eLimit, $eCount, $site, array('sid' => SPRequest::sid(), 'title' => Sobi::Cfg('sef.alias', true) ? $this->_model->get('nid') : $this->_model->get('name')));
     /* handle meta data */
     SPFactory::header()->objMeta($this->_model);
     /* add pathway */
     SPFactory::mainframe()->addObjToPathway($this->_model, array(ceil($eCount / $eLimit), $site));
     $this->_model->countVisit();
     /* get view class */
     //		$class = SPLoader::loadView( $this->_type );
     $view = SPFactory::View($this->_type);
     //		$view = new $class( $this->template );
     $view->assign($eLimit, '$eLimit')->assign($eLimStart, '$eLimStart')->assign($eCount, '$eCount')->assign($cInLine, '$cInLine')->assign($eInLine, '$eInLine')->assign($this->_task, 'task')->assign($this->_model, $this->_type)->setConfig($this->_tCfg, $this->template)->setTemplate($tplPackage . '.' . $this->templateType . '.' . $this->template)->assign($categories, 'categories')->assign($pn->get(), 'navigation')->assign(SPFactory::user()->getCurrent(), 'visitor')->assign($entries, 'entries')->assign($orderings, 'orderings');
     Sobi::Trigger($this->name(), 'View', array(&$view));
     $view->display($this->_type);
 }
Beispiel #6
0
 protected function messages()
 {
     $messages = SPFactory::message()->getReports(SPRequest::cmd('spsid'));
     $response = array();
     if (count($messages)) {
         foreach ($messages as $type => $content) {
             if (count($content)) {
                 foreach ($content as $message) {
                     $response[] = array('type' => $type, 'text' => $message);
                 }
             }
         }
     }
     $this->response(null, null, false, SPC::INFO_MSG, array('messages' => $response));
 }
Beispiel #7
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));
 }
Beispiel #8
0
 private function screen()
 {
     $view =& SPFactory::View('view', true);
     $view->setTemplate('config.help');
     if (SPLoader::path('etc.repos.sobipro_core.repository', 'front', true, 'xml')) {
         $repository = SPFactory::Instance('services.installers.repository');
         $repository->loadDefinition(SPLoader::path("etc.repos.sobipro_core.repository", 'front', true, 'xml'));
         try {
             $repository->connect();
         } catch (SPException $x) {
             $view->assign(SPLang::e('REPO_ERR', $x->getMessage()), 'message');
         }
         try {
             $response = $repository->help($repository->get('token'), SPRequest::cmd('mid'));
             $view->assign($response, 'message');
         } catch (SPException $x) {
             $view->assign(SPLang::e('REPO_ERR', $x->getMessage()), 'message');
         }
     } else {
         $view->assign(Sobi::Txt('MSG.HELP_ADD_CORE_REPO'), 'message');
     }
     $view->display();
 }
Beispiel #9
0
 /**
  * @param array $head
  * @return bool
  */
 public function addHead($head)
 {
     if (strlen(SPRequest::cmd('format')) && SPRequest::cmd('format') != 'html') {
         return true;
     }
     /** @var JDocument $document */
     $document = JFactory::getDocument();
     $c = 0;
     if (count($head)) {
         $document->addCustomTag("\n\t<!--  SobiPro Head Tags Output  -->\n");
         $document->addCustomTag("\n\t<script type=\"text/javascript\">/*\n<![CDATA[*/ \n\tvar SobiProUrl = '" . Sobi::FixPath(self::Url(array('task' => '%task%'), true, false, true)) . "'; \n\tvar SobiProSection = " . (Sobi::Section() ? Sobi::Section() : 0) . "; \n\tvar SPLiveSite = '" . Sobi::Cfg('live_site') . "'; \n/*]]>*/\n</script>\n");
         if (defined('SOBI_ADM_PATH')) {
             $document->addCustomTag("\n\t<script type=\"text/javascript\">/* <![CDATA[ */ \n\tvar SobiProAdmUrl = '" . Sobi::FixPath(Sobi::Cfg('live_site') . SOBI_ADM_FOLDER . '/' . self::Url(array('task' => '%task%'), true, false)) . "'; \n/* ]]> */</script>\n");
         }
         foreach ($head as $type => $code) {
             switch ($type) {
                 default:
                     if (count($code)) {
                         foreach ($code as $html) {
                             ++$c;
                             $document->addCustomTag($html);
                         }
                     }
                     break;
                 case 'robots':
                 case 'author':
                     $document->setMetaData($type, implode(', ', $code));
                     //						$document->setHeadData( array( $type => implode( ', ', $code ) ) );
                     break;
                 case 'keywords':
                     $metaKeys = trim(implode(', ', $code));
                     if (Sobi::Cfg('meta.keys_append', true)) {
                         $metaKeys .= Sobi::Cfg('string.meta_keys_separator', ',') . $document->getMetaData('keywords');
                     }
                     $metaKeys = explode(Sobi::Cfg('string.meta_keys_separator', ','), $metaKeys);
                     if (count($metaKeys)) {
                         $metaKeys = array_unique($metaKeys);
                         foreach ($metaKeys as $i => $p) {
                             if (strlen(trim($p))) {
                                 $metaKeys[$i] = trim($p);
                             } else {
                                 unset($metaKeys[$i]);
                             }
                         }
                         $metaKeys = implode(', ', $metaKeys);
                     } else {
                         $metaKeys = null;
                     }
                     $document->setMetadata('keywords', $metaKeys);
                     break;
                 case 'description':
                     $metaDesc = implode(Sobi::Cfg('string.meta_desc_separator', ' '), $code);
                     if (strlen($metaDesc)) {
                         if (Sobi::Cfg('meta.desc_append', true)) {
                             $metaDesc .= $this->getMetaDescription($document);
                         }
                         $metaDesc = explode(' ', $metaDesc);
                         if (count($metaDesc)) {
                             foreach ($metaDesc as $i => $p) {
                                 if (strlen(trim($p))) {
                                     $metaDesc[$i] = trim($p);
                                 } else {
                                     unset($metaDesc[$i]);
                                 }
                             }
                             $metaDesc = implode(' ', $metaDesc);
                         } else {
                             $metaDesc = null;
                         }
                         $document->setDescription($metaDesc);
                     }
                     break;
             }
         }
         $jsUrl = Sobi::FixPath(self::Url(array('task' => 'txt.js', 'format' => 'json'), true, false, false));
         $document->addCustomTag("\n\t<script type=\"text/javascript\" src=\"" . str_replace('&', '&amp;', $jsUrl) . "\"></script>\n");
         $c++;
         $document->addCustomTag("\n\t<!--  SobiPro ({$c}) Head Tags Output -->\n");
         // we would like to set our own canonical please :P
         // https://groups.google.com/forum/?fromgroups=#!topic/joomla-dev-cms/sF3-JBQspQU
         if (count($document->_links)) {
             foreach ($document->_links as $index => $link) {
                 if ($link['relation'] == 'canonical') {
                     unset($document->_links[$index]);
                 }
             }
         }
     }
 }
Beispiel #10
0
 /**
  * Save existing field
  */
 protected function save($clone = false)
 {
     $sets = array();
     if (!SPFactory::mainframe()->checkToken()) {
         Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__);
     }
     $fid = SPRequest::int('fid');
     $field = SPFactory::Model('field', true);
     if ($fid) {
         $f = $this->loadField($fid);
         $field->extend($f);
     } else {
         $field->loadType(SPRequest::cmd('field_fieldType'));
     }
     $nid = SPRequest::cmd('field_nid');
     if (!$nid || !strstr($nid, 'field_')) {
         /** give me my spaces back!!! */
         $nid = strtolower(str_replace('-', '_', SPLang::nid('field_' . SPRequest::string('field_name'))));
         SPRequest::set('field_nid', $nid);
     }
     $this->getRequest();
     $this->validate($field);
     if ($clone || !$fid) {
         try {
             $fid = $field->saveNew($this->attr);
             $field->save($this->attr);
         } catch (SPException $x) {
             $this->response(Sobi::Url(array('task' => 'field.edit', 'fid' => $fid, 'sid' => SPRequest::sid())), $x->getMessage(), false, SPC::ERROR_MSG);
         }
     } else {
         try {
             $field->save($this->attr);
         } catch (SPException $x) {
             $this->response(Sobi::Url(array('task' => 'field.edit', 'fid' => $fid, 'sid' => SPRequest::sid())), $x->getMessage(), false, SPC::ERROR_MSG);
         }
     }
     $alias = $field->get('nid');
     $fieldSets = $field->get('sets');
     if (is_array($fieldSets) && count($fieldSets)) {
         $sets = array_merge($fieldSets, $sets);
     }
     $sets['fid'] = $field->get('fid');
     $sets['field.nid'] = $alias;
     /* in case we are changing the sort by field */
     if (Sobi::Cfg('list.entries_ordering') == $alias && $field->get('nid') != $alias) {
         SPFactory::config()->saveCfg('list.entries_ordering', $field->get('nid'));
     }
     SPFactory::cache()->cleanSection();
     if ($this->_task == 'apply' || $clone) {
         if ($clone) {
             $msg = Sobi::Txt('FM.FIELD_CLONED');
             $this->response(Sobi::Url(array('task' => 'field.edit', 'fid' => $fid, 'sid' => SPRequest::sid())), $msg);
         } else {
             $msg = Sobi::Txt('MSG.ALL_CHANGES_SAVED');
             $this->response(Sobi::Url(array('task' => 'field.edit', 'fid' => $fid, 'sid' => SPRequest::sid())), $msg, false, 'success', array('sets' => $sets));
         }
     } else {
         $this->response(Sobi::Back(), Sobi::Txt('MSG.ALL_CHANGES_SAVED'));
     }
 }
Beispiel #11
0
 protected function session(&$ssid)
 {
     /* if it wasn't new search */
     $ssid = SPRequest::cmd('ssid', SPRequest::cmd('ssid', null, 'cookie'));
     $new = false;
     /* otherwise create new ssid */
     if (!$ssid) {
         $ssid = microtime(true) * 100 . '.' . rand(0, 99);
         $new = true;
     }
     $attr = array('ssid' => $ssid, 'uid' => Sobi::My('id'), 'browserData' => SPConfig::serialize(SPBrowser::getInstance()));
     /* get search request */
     if (!count($this->_request)) {
         $r = SPRequest::search('field_');
         if (is_array($r) && count($r)) {
             $attr['requestData'] = SPConfig::serialize($r);
         }
     }
     /* determine the search parameters */
     if ($new) {
         $attr['searchCreated'] = 'FUNCTION:NOW()';
     }
     /* finally save */
     try {
         $this->_db->insertUpdate('spdb_search', $attr);
     } catch (SPException $x) {
         Sobi::Error($this->name(), SPLang::e('CANNOT_CREATE_SESSION_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
     }
     return SPCookie::set('ssid', $ssid, SPCookie::days(7));
 }
Beispiel #12
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();
 }
Beispiel #13
0
 protected function saveDefaultOrdering()
 {
     $target = SPRequest::cmd('target');
     $order = Sobi::GetUserState($target . '.order', null);
     $saved = false;
     if (strlen($order)) {
         SPFactory::config()->saveCfg('admin.' . $target . '-order', $order);
         $saved = true;
     }
     $limit = Sobi::GetUserState($target . '.limit', 10);
     if ($limit) {
         SPFactory::config()->saveCfg('admin.' . $target . '-limit', $limit);
         $saved = true;
     }
     if ($saved) {
         $this->response(Sobi::Back(), Sobi::Txt('MSG_DEFAULT_ORDERING_SAVED'), false);
     }
 }
Beispiel #14
0
 /**
  * Save an entry
  *
  * @param bool $apply
  */
 protected function save($apply)
 {
     $new = true;
     if (!$this->_model) {
         $this->setModel(SPLoader::loadModel($this->_type));
     }
     if ($this->_model->get('oType') != 'entry') {
         Sobi::Error('Entry', sprintf('Serious security violation. Trying to save an object which claims to be an entry but it is a %s. Task was %s', $this->_model->get('oType'), SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__);
         exit;
     }
     /* check if we have stored last edit in cache */
     $tsId = SPRequest::string('editentry', null, false, 'cookie');
     if (!$tsId) {
         $tsId = SPRequest::cmd('ssid');
     }
     $request = $this->getCache($tsId);
     $this->_model->init(SPRequest::sid($request));
     $tplPackage = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE);
     $this->tplCfg($tplPackage);
     $customClass = null;
     if (isset($this->_tCfg['general']['functions']) && $this->_tCfg['general']['functions']) {
         $customClass = SPLoader::loadClass('/' . str_replace('.php', null, $this->_tCfg['general']['functions']), false, 'templates');
         if (method_exists($customClass, 'BeforeStoreEntry')) {
             $customClass::BeforeStoreEntry($this->_model, $this->store['post']);
             SPFactory::registry()->set('requestcache_stored', $this->store);
             SPFactory::registry()->set('requestcache', $this->store['post']);
         }
     }
     $preState = array('approved' => $this->_model->get('approved'), 'state' => $this->_model->get('state'), 'new' => !$this->_model->get('id'));
     SPFactory::registry()->set('object_previous_state', $preState);
     $this->_model->getRequest($this->_type, $request);
     Sobi::Trigger($this->name(), __FUNCTION__, array(&$this->_model));
     if ($this->_model->get('id') && $this->_model->get('id') == SPRequest::sid()) {
         $new = false;
         if (Sobi::My('id') && Sobi::My('id') == $this->_model->get('owner')) {
             $this->authorise('edit', 'own');
         } else {
             $this->authorise('edit', '*');
         }
     } else {
         $this->authorise('add', 'own');
     }
     $this->_model->save($request);
     /* if there is something pay */
     $pCount = SPFactory::payment()->count($this->_model->get('id'));
     if ($pCount && !Sobi::Can('entry.payment.free')) {
         //			$this->paymentView( $tsid );
         if ($customClass && method_exists($customClass, 'BeforeStoreEntryPayment')) {
             $customClass::BeforeStoreEntryPayment($this->_model->get('id'));
         }
         SPFactory::payment()->store($this->_model->get('id'));
     }
     /* delete cache files on after */
     $file = str_replace('.', '-', $tsId);
     if (SPLoader::dirPath('tmp.edit.' . $file)) {
         SPFs::delete(SPLoader::dirPath('tmp.edit.' . $file));
     } else {
         SPFactory::cache()->deleteVar('request_cache_' . $tsId);
     }
     SPLoader::loadClass('env.cookie');
     SPCookie::delete('editentry');
     $sid = $this->_model->get('id');
     $pid = SPRequest::int('pid') ? SPRequest::int('pid') : Sobi::Section();
     if ($new) {
         if ($this->_model->get('state') || Sobi::Can('entry.see_unpublished.own')) {
             $msg = $this->_model->get('state') ? Sobi::Txt('EN.ENTRY_SAVED') : Sobi::Txt('EN.ENTRY_SAVED_NP');
             $url = Sobi::Url(array('sid' => $sid, 'pid' => $pid));
         } else {
             // determine if there is a custom redirect
             if (Sobi::Cfg('redirects.entry_save_enabled') && !($pCount && !Sobi::Can('entry.payment.free'))) {
                 $redirect = Sobi::Cfg('redirects.entry_save_url', null);
                 if (!preg_match('/http[s]?:\\/\\/.*/', $redirect) && $redirect != 'index.php') {
                     $redirect = Sobi::Url($redirect);
                 }
                 $this->response($redirect, Sobi::Txt(Sobi::Cfg('redirects.entry_save_msg', 'EN.ENTRY_SAVED_NP')), true, Sobi::Cfg('redirects.entry_save_msgtype', SPC::SUCCESS_MSG));
             } else {
                 $msg = Sobi::Txt('EN.ENTRY_SAVED_NP');
                 $url = Sobi::Url(array('sid' => $pid));
             }
         }
     } elseif ($this->_model->get('approved') || Sobi::Can('entry.see_unapproved.own')) {
         $url = Sobi::Url(array('sid' => $sid, 'pid' => $pid));
         $msg = $this->_model->get('approved') ? Sobi::Txt('EN.ENTRY_SAVED') : Sobi::Txt('EN.ENTRY_SAVED_NA');
     } else {
         if ($this->_model->get('approved')) {
             $msg = Sobi::Txt('EN.ENTRY_SAVED');
         } else {
             $msg = Sobi::Txt('EN.ENTRY_SAVED_NA');
         }
         $url = Sobi::Url(array('sid' => $sid, 'pid' => $pid));
     }
     if ($pCount && !Sobi::Can('entry.payment.free')) {
         $ident = md5(microtime() . $tsId . $sid . time());
         $data = array('data' => SPFactory::payment()->summary($sid), 'ident' => $ident);
         $url = Sobi::Url(array('sid' => $sid, 'task' => 'entry.payment'), false, false);
         if (Sobi::Cfg('cache.l3_enabled', true)) {
             SPFactory::cache()->addObj($data, 'payment', $sid, Sobi::Section(), true);
         } else {
             SPFs::write(SPLoader::path('tmp.edit.' . $ident . '.payment', 'front', false, 'var'), SPConfig::serialize($data));
             $url = Sobi::Url(array('sid' => $sid, 'task' => 'entry.payment', 'tsid' => $ident), false, false);
         }
         SPLoader::loadClass('env.cookie');
         SPCookie::set('payment_' . $sid, $ident, SPCookie::days(1));
     }
     if ($customClass && method_exists($customClass, 'AfterStoreEntry')) {
         $customClass::AfterStoreEntry($this->_model);
     }
     $this->logChanges('save', SPRequest::string('history-note'));
     $this->response($url, $msg, true, SPC::SUCCESS_MSG);
 }
Beispiel #15
0
 /**
  * @return void
  */
 private function parents()
 {
     //		sleep( 5 );
     $sid = SPRequest::sid();
     $out = SPRequest::cmd('out', 'json');
     $path = SPFactory::config()->getParentPath($sid, true, false, true);
     $cats = array();
     if (count($path)) {
         $childs = 0;
         foreach ($path as $category) {
             if ($category['id'] == $sid) {
                 $childs = count(SPFactory::Category($sid)->getChilds('category', false, 1));
             }
             $cats[] = array('id' => $category['id'], 'name' => $category['name'], 'childsCount' => $childs);
         }
     }
     switch ($out) {
         case 'json':
             SPFactory::mainframe()->cleanBuffer()->customHeader();
             echo json_encode(array('id' => $sid, 'categories' => $cats));
             exit;
     }
 }
Beispiel #16
0
 protected function legacyToolbar($settings)
 {
     if (!(SPRequest::cmd('tmpl') == 'component')) {
         $buttons = array();
         foreach ($settings as $row) {
             $button = array('type' => null, 'task' => null, 'label' => null, 'icon' => null, 'target' => null, 'buttons' => null, 'element' => 'button-legacy');
             switch ($row['type']) {
                 case 'title':
                     SPFactory::AdmToolbar()->setTitle(array('title' => $row['settings'][0], 'icon' => $row['settings'][1]));
                     break;
                 case 'delete':
                 case 'save':
                 case 'cancel':
                 case 'duplicate':
                 case 'apply':
                 case 'addNew':
                 case 'back':
                 case 'forward':
                     $button['task'] = $row['settings'][0];
                     $button['label'] = $row['settings'][1];
                     $button['type'] = $row['type'];
                     $buttons[] = $button;
                     break;
                 case 'divider':
                     $buttons[] = array('element' => 'divider');
                     break;
                 case 'custom':
                     $button['task'] = $row['settings'][0];
                     $button['icon'] = $row['settings'][1];
                     $button['label'] = $row['settings'][3];
                     $button['type'] = $row['settings'][2];
                     $buttons[] = $button;
                     break;
             }
         }
         SPFactory::AdmToolbar()->addButtons($buttons);
     }
     SPFactory::message()->warning('COMPAT_MODE_WARNING');
 }
Beispiel #17
0
 /**
  *
  */
 public function endOut()
 {
     if (!strlen(SPRequest::cmd('format')) || SPRequest::cmd('format') == 'html') {
         /* something like 'onDomReady' but it should be bit faster */
         echo '<script type="text/javascript">SobiPro.Ready();</script>';
     }
 }
Beispiel #18
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();
 }
Beispiel #19
0
 private function edit()
 {
     $id = SPRequest::cmd('fid');
     $filters = $this->getFilters();
     if (count($filters) && isset($filters[$id])) {
         $Filter = array('id' => $id, 'regex' => str_replace('\\"' . "\\'", '[:apostrophes:]', base64_decode($filters[$id]['params'])), 'name' => $filters[$id]['value'], 'message' => $filters[$id]['description'], 'editable' => strlen($filters[$id]['options']), 'readonly' => !strlen($filters[$id]['options']));
     } else {
         $Filter = array('id' => '', 'regex' => '', 'name' => '', 'message' => '', 'editable' => true, 'readonly' => false);
     }
     $view = SPFactory::View('view', true);
     $view->assign($this->_task, 'task');
     $view->assign($Filter, 'filter');
     $view->determineTemplate('field', 'filter');
     $view->setTemplate('default');
     $view->display();
 }
 /**
  * @param string $out - output type
  * @param array $functions - array with PHP function to register
  * @throws SPException
  * @return mixed|string
  */
 public function display($out = 'html', $functions = array())
 {
     $class = SPLoader::loadClass('helpers.template');
     $methods = get_class_methods($class);
     if (count($methods)) {
         foreach ($methods as $method) {
             $functions[] = $class . '::' . $method;
         }
     }
     /* standard function registered via the core ini file */
     $stdFunctions = SPLoader::loadIniFile('etc.template_functions');
     if (count($stdFunctions)) {
         foreach ($stdFunctions as $class => $fns) {
             if (strstr($class, '.')) {
                 $class = SPLoader::loadClass($class, false, 'sp-root');
             }
             if (count($fns)) {
                 foreach ($fns as $method => $state) {
                     if ($state) {
                         $functions[] = $class == 'functions' ? $method : $class . '::' . $method;
                     }
                 }
             }
         }
     }
     Sobi::Trigger('TemplateEngine', 'RegisterFunctions', array(&$functions));
     $this->createXML();
     if (SPRequest::cmd('xml') && Sobi::Cfg('debug.xml_raw', false) && (!Sobi::Cfg('debug.xml_ip', null) || Sobi::Cfg('debug.xml_ip') == SPRequest::ip('REMOTE_ADDR', 0, 'SERVER'))) {
         SPFactory::mainframe()->cleanBuffer();
         echo $this->_xml->saveXML();
         exit;
     } elseif (SPRequest::cmd('xml')) {
         Sobi::Error('Debug', 'You have no permission to access this site', SPC::ERROR, 403, __LINE__, __FILE__);
     }
     $template = SPLoader::loadTemplate($this->_tpl, 'xsl');
     if (!$template) {
         $template = SPLoader::loadTemplate($this->_tpl, 'xslt');
     }
     if (Sobi::Cfg('cache.xml_enabled')) {
         SPFactory::cache()->addView($this->_xml, $template, $this->_cacheData);
     }
     if ($template) {
         try {
             if (!($style = DOMDocument::load($template))) {
                 Sobi::Error('template', SPLang::e('CANNOT_PARSE_TEMPLATE_FILE', $template), SPC::ERROR, 500, __LINE__, __FILE__);
             }
         } catch (DOMException $x) {
             Sobi::Error('template', SPLang::e('CANNOT_LOAD_TEMPLATE_FILE', $template, $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
         Sobi::Trigger('TemplateEngine', 'LoadStyle', array(&$style));
         $processor = new XSLTProcessor();
         $processor->setParameter('block', 'xmlns', 'http://www.w3.org/1999/xhtml');
         $processor->registerPHPFunctions($functions);
         SPException::catchErrors(SPC::WARNING);
         try {
             $processor->importStylesheet($style);
         } catch (SPException $x) {
             Sobi::Error('template', SPLang::e('CANNOT_PARSE_TEMPLATE_FILE', $template) . $x->getMessage(), SPC::ERROR, 500, __LINE__, __FILE__);
         }
         SPException::catchErrors(0);
         if ($out == 'html') {
             $doc = $processor->transformToDoc($this->_xml);
             $doc->formatOutput = true;
             return $this->cleanOut($doc->saveXML());
         } else {
             $doc = $processor->transformToDoc($this->_xml);
             $doc->formatOutput = true;
             return $doc->saveXML();
         }
     } else {
         throw new SPException(SPLang::e('CANNOT_LOAD_TEMPLATE_FILE_AT', SPLoader::loadTemplate($this->_tpl, 'xsl', false)));
     }
 }
Beispiel #21
0
 public function ProxyCount()
 {
     SPLoader::loadClass('env.browser');
     SPLoader::loadClass('env.cookie');
     $browser = SPBrowser::getInstance();
     $this->nid = str_replace(array('.count', '.'), array(null, '_'), SPRequest::task());
     $ident = $this->nid . '_' . SPRequest::int('eid');
     $check = SPRequest::cmd('count_' . $ident, null, 'cookie');
     if (!$check) {
         $data = array('date' => 'FUNCTION:NOW()', 'uid' => Sobi::My('id'), 'sid' => SPRequest::int('eid'), 'fid' => $this->nid, 'ip' => SPRequest::ip('REMOTE_ADDR', 0, 'SERVER'), 'section' => Sobi::Section(), 'browserData' => $browser->get('browser'), 'osData' => $browser->get('system'), 'humanity' => $browser->get('humanity'));
         SPCookie::set('count_' . $ident, 1, SPCookie::hours(2));
         SPFactory::db()->insert('spdb_field_url_clicks', $data);
     }
 }
Beispiel #22
0
 /**
  * @param	string	The control name
  * @param	string	The contents of the text area
  * @param	string	The width of the text area (px or %)
  * @param	string	The height of the text area (px or %)
  * @param	boolean	True and the editor buttons will be displayed
  * @param	array	Associative array of editor parameters
  */
 public function display($name, $html, $width, $height, $buttons = true, $params = array())
 {
     if (SPRequest::cmd('format') != 'raw') {
         return JFactory::getEditor()->display($name, $html, $width, $height, '75', '20', $buttons, $params);
     }
 }
Beispiel #23
0
 private function editFile()
 {
     if (Sobi::Section() && Sobi::Cfg('section.template') == SPC::DEFAULT_TEMPLATE) {
         SPFactory::message()->warning(Sobi::Txt('TP.DEFAULT_WARN', 'https://www.sigsiu.net/help_screen/template.info'), false)->setSystemMessage();
     }
     $file = SPRequest::cmd('file');
     $file = $this->file($file);
     $ext = SPFs::getExt($file);
     $fileContent = SPFs::read($file);
     $path = str_replace('\\', '/', SOBI_PATH);
     if (strstr($file, $path)) {
         $filename = str_replace($path . '/usr/templates/', null, $file);
     } else {
         $filename = str_replace(SOBI_ROOT, null, $file);
     }
     $menu = $this->createMenu();
     if (Sobi::Section()) {
         $menu->setOpen('AMN.APPS_SECTION_TPL');
     } else {
         $menu->setOpen('GB.CFG.GLOBAL_TEMPLATES');
     }
     /** @var $view SPAdmTemplateView */
     $view = SPFactory::View('template', true)->assign($fileContent, 'file_content')->assign($filename, 'file_name')->assign($ext, 'file_ext')->assign($menu, 'menu')->assign($this->_task, 'task')->assign(Sobi::Section(), 'sid')->addHidden(SPRequest::cmd('file'), 'fileName')->addHidden($filename, 'filePath')->determineTemplate('template', 'edit');
     Sobi::Trigger('Edit', $this->name(), array(&$file, &$view));
     $view->display();
 }
Beispiel #24
0
 private function install($file = null)
 {
     $arch = SPFactory::Instance('base.fs.archive');
     $ajax = strlen(SPRequest::cmd('ident', null, 'post'));
     if (!$file && SPRequest::string('root')) {
         $file = str_replace('.xml', null, SPRequest::string('root'));
         $file = SPLoader::path('tmp.install.' . $file, 'front', true, 'xml');
     }
     if (!$file) {
         $ident = SPRequest::cmd('ident', null, 'post');
         $data = SPRequest::file($ident);
         $name = str_replace(array('.' . SPFs::getExt($data['name']), '.'), null, $data['name']);
         $path = SPLoader::dirPath('tmp.install.' . $name, 'front', false);
         $c = 0;
         while (SPFs::exists($path)) {
             $path = SPLoader::dirPath('tmp.install.' . $name . '_' . ++$c, 'front', false);
         }
         /*
          * temp directory - will be removed later but it needs to be writable for apache and Joomla! fs (FTP mode)
          */
         try {
             if (Sobi::Cfg('ftp_mode')) {
                 SPFs::mkdir($path, 0777);
             } else {
                 SPFs::mkdir($path);
             }
         } catch (SPException $x) {
             return $this->ajaxResponse($ajax, $x->getMessage(), false, SPC::ERROR_MSG);
         }
         $file = $path . '/' . $data['name'];
         try {
             $arch->upload($data['tmp_name'], $file);
         } catch (SPException $x) {
             return $this->ajaxResponse($ajax, $x->getMessage(), false, SPC::ERROR_MSG);
         }
     } elseif (SPRequest::string('root') && $file) {
         $path = dirname($file);
     } else {
         $arch->setFile($file);
         $name = str_replace(array('.' . SPFs::getExt($file), '.'), null, basename($file));
         $path = SPLoader::dirPath('tmp.install.' . $name, 'front', false);
         $c = 0;
         while (SPFs::exists($path)) {
             $path = SPLoader::dirPath('tmp.install.' . $name . '_' . ++$c, 'front', false);
         }
         /*
          * temp directory - will be removed later but it needs to  writable for apache and Joomla! fs (FTP mode)
          */
         try {
             if (Sobi::Cfg('ftp_mode')) {
                 SPFs::mkdir($path, 0777);
             } else {
                 SPFs::mkdir($path);
             }
         } catch (SPException $x) {
             return $this->ajaxResponse($ajax, $x->getMessage(), false, SPC::ERROR_MSG);
         }
     }
     if ($path) {
         if (!SPRequest::string('root')) {
             if (!$arch->extract($path)) {
                 return $this->ajaxResponse($ajax, SPLang::e('CANNOT_EXTRACT_ARCHIVE', basename($file), $path), false, SPC::ERROR_MSG);
             }
         }
         $dir =& SPFactory::Instance('base.fs.directory', $path);
         $xml = array_keys($dir->searchFile('.xml', false, 2));
         if (!count($xml)) {
             return $this->ajaxResponse($ajax, SPLang::e('NO_INSTALL_FILE_IN_PACKAGE'), false, SPC::ERROR_MSG);
         }
         $definition = $this->searchInstallFile($xml);
         if (!$definition) {
             if (SPFactory::CmsHelper()->installerFile($xml)) {
                 try {
                     $message = SPFactory::CmsHelper()->install($xml, $path);
                     return $this->ajaxResponse($ajax, $message['msg'], $ajax, $message['msgtype']);
                 } catch (SPException $x) {
                     return $this->ajaxResponse($ajax, $x->getMessage(), $ajax, SPC::ERROR_MSG);
                 }
             } else {
                 return $this->ajaxResponse($ajax, SPLang::e('NO_INSTALL_FILE_IN_PACKAGE'), false, SPC::ERROR_MSG);
             }
         }
         /** @var $installer SPInstaller */
         $installer =& SPFactory::Instance('services.installers.' . trim(strtolower($definition->documentElement->tagName)), $xml[0], trim($definition->documentElement->tagName));
         try {
             $installer->validate();
             $msg = $installer->install();
             return $this->ajaxResponse($ajax, $msg, true, SPC::SUCCESS_MSG);
         } catch (SPException $x) {
             return $this->ajaxResponse($ajax, $x->getMessage(), false, SPC::ERROR_MSG);
         }
     } else {
         return $this->ajaxResponse($ajax, SPLang::e('NO_FILE_HAS_BEEN_UPLOADED'), false, SPC::ERROR_MSG);
     }
 }
Beispiel #25
0
 /**
  *
  */
 public function display($o = null)
 {
     if (SPRequest::cmd('format') == 'json' && Sobi::Cfg('output.json_enabled', false)) {
         return $this->jsonDisplay();
     }
     $type = $this->key('template_type', 'xslt');
     $f = null;
     $task = SPRequest::task();
     if ($this->key('functions')) {
         $f = $this->registerFunctions();
     }
     $out = null;
     if ($type != 'php' && Sobi::Cfg('global.disable_xslt', false)) {
         $type = 'php';
     }
     $parserClass = SPLoader::loadClass('mlo.template_' . $type);
     if ($parserClass) {
         /** @var $parser SPTemplateXSLT */
         $parser = new $parserClass();
     } else {
         throw new SPException(SPLang::e('CANNOT_LOAD_PARSER', $type));
     }
     $this->_attr['template_path'] = Sobi::FixPath(str_replace(SOBI_ROOT, Sobi::Cfg('live_site'), $this->_templatePath));
     $messages = SPFactory::message()->getMessages();
     if (count($messages)) {
         foreach ($messages as $type => $content) {
             $this->_attr['messages'][$type] = array_values($content);
         }
     }
     $parser->setProxy($this);
     $parser->setData($this->_attr);
     $parser->setXML($this->_xml);
     $parser->setCacheData(array('hidden' => $this->_hidden));
     $parser->setType($this->_type);
     $parser->setTemplate($this->_template);
     Sobi::Trigger('Display', $this->name(), array($type, &$this->_attr));
     $o = $o ? $o : strtolower($this->key('output', $this->key('output', 'html'), $this->tTask));
     $action = $this->key('form.action');
     if ($action) {
         $opt = SPFactory::mainframe()->form();
         if (is_array($opt) && count($opt)) {
             foreach ($opt as $l => $v) {
                 $this->addHidden($v, $l);
             }
         }
         $form = $this->csection('form');
         $form['method'] = isset($form['method']) && $form['method'] ? $form['method'] : 'post';
         $out .= "\n<form ";
         foreach ($form as $p => $v) {
             $out .= $p . '="' . $v . '" ';
         }
         $out .= ">\n";
     }
     $out .= $parser->display($o, $f);
     $hidden = null;
     if (count($this->_hidden)) {
         $this->_hidden[SPFactory::mainframe()->token()] = 1;
         foreach ($this->_hidden as $name => $value) {
             $hidden .= "\n<input type=\"hidden\" id=\"SP_{$name}\" name=\"{$name}\" value=\"{$value}\"/>";
         }
         // xhtml strict valid
         $hidden = "<div>{$hidden}</div>";
         $out .= $hidden;
     }
     $out .= $action ? "\n</form>\n" : null;
     /* SobiPro type specific content parser */
     Sobi::Trigger('ContentDisplay', $this->name(), array(&$out));
     /* common content parser */
     $cParse = $this->key('parse', -1);
     /* if it was specified in the template config file or it was set in the section config and not disabled in the template config */
     if (!(strstr($task, '.edit') || strstr($task, '.add') || in_array($task, Sobi::Cfg('plugins.content_disable', array())))) {
         if ($cParse == 1 || Sobi::Cfg('parse_template_content', false) && $cParse == -1) {
             Sobi::Trigger('Parse', 'Content', array(&$out));
         }
     }
     header('SobiPro: ' . Sobi::Section());
     if ($o == 'html' && (!strlen(SPRequest::cmd('format')) || SPRequest::cmd('format') == 'html' || SPRequest::int('crawl'))) {
         $out .= $this->pb();
         if ((SPRequest::cmd('dbg') || Sobi::Cfg('debug')) && Sobi::My('id')) {
             $start = Sobi::Reg('start');
             $mem = $start[0];
             $time = $start[1];
             $queries = SPFactory::db()->getCount();
             $mem = number_format(memory_get_usage() - $mem);
             $time = microtime(true) - $time;
             SPConfig::debOut("Memory: {$mem}<br/>Time: {$time}<br/> Queries: {$queries}");
         }
         echo "\n<!-- Start of SobiPro component-->\n<div id=\"SobiPro\" class=\"SobiPro\">\n{$out}\n</div>\n<!-- End of SobiPro component Copyright (C) 2011-2014 Sigsiu.NET GmbH -->\n";
     } else {
         $this->customOutput($out);
     }
     Sobi::Trigger('AfterDisplay', $this->name());
 }
Beispiel #26
0
 /**
  * Save a rule
  *
  * @param bool $apply
  */
 protected function save($apply)
 {
     Sobi::Trigger('Save', 'Acl', array(&$this));
     if (!SPFactory::mainframe()->checkToken()) {
         Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__);
     }
     $rid = SPRequest::int('rid', 'null');
     $this->validate('acl.edit', array('task' => 'acl.edit', 'rid' => $rid));
     if ($rid) {
         $this->remove($rid);
     }
     $vs = SPRequest::timestamp('set_validSince');
     $vu = SPRequest::timestamp('set_validUntil');
     $vs = $vs ? date(Sobi::Cfg('db.date_format', 'Y-m-d H:i:s'), $vs) : null;
     $vu = $vu ? date(Sobi::Cfg('db.date_format', 'Y-m-d H:i:s'), $vu) : null;
     $name = SPRequest::string('set_name');
     $nid = SPRequest::cmd('set_nid');
     $note = SPRequest::string('set_note');
     $state = SPRequest::int('set_state', 1);
     $gids = SPRequest::arr('set_groups');
     $sids = SPRequest::arr('set_sections');
     $pf = SPRequest::arr('set_permissions', array());
     $pa = SPRequest::arr('set_adm_permissions', array());
     // if can publish any, then can see any unpublished
     if (in_array(20, $pf)) {
         $pf[] = 14;
     }
     // if can publish own, then can see own unpublished
     if (in_array(21, $pf)) {
         $pf[] = 12;
     }
     if (in_array(19, $pf)) {
         $pf[] = 15;
     }
     $perms = array_merge($pf, $pa);
     /* @var SPdb $db */
     $db = SPFactory::db();
     /* update or insert the rule definition */
     try {
         $db->insertUpdate('spdb_permissions_rules', array('rid' => $rid, 'name' => $name, 'nid' => $nid, 'validSince' => $vs, 'validUntil' => $vu, 'note' => $note, 'state' => $state));
     } catch (SPException $x) {
         Sobi::Error('ACL', SPLang::e('CANNOT_CREATE_RULE_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     $rid = (int) $rid ? (int) $rid : $db->insertid();
     /* insert the groups ids */
     if (count($gids)) {
         foreach ($gids as $i => $gid) {
             $gids[$i] = array('rid' => $rid, 'gid' => $gid);
         }
         try {
             $db->insertArray('spdb_permissions_groups', $gids);
         } catch (SPException $x) {
             Sobi::Error('ACL', SPLang::e('CANNOT_INSERT_GROUPS_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
     }
     try {
         $db->select('*', 'spdb_permissions', array('site' => 'adm', 'value' => 'global'));
         $admPermissions = $db->loadResultArray();
     } catch (SPException $x) {
         Sobi::Error('ACL', SPLang::e('CANNOT_GET_PERMISSIONS_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     /* create permission and section map */
     if (count($sids) && count($perms)) {
         $map = array();
         /* travel the sections */
         foreach ($sids as $sid) {
             foreach ($perms as $pid) {
                 if (in_array($pid, $admPermissions)) {
                     $map[] = array('rid' => $rid, 'sid' => 0, 'pid' => $pid);
                 } else {
                     $map[] = array('rid' => $rid, 'sid' => $sid, 'pid' => $pid);
                 }
             }
         }
         try {
             $db->insertArray('spdb_permissions_map', $map, true);
         } catch (SPException $x) {
             Sobi::Error('ACL', SPLang::e('CANNOT_INSERT_GROUPS_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
     }
     SPFactory::cache()->cleanAll();
     /* trigger plugins */
     Sobi::Trigger('AfterSave', 'Acl', array(&$this));
     /* set redirect */
     $this->response(Sobi::Url($apply ? array('task' => 'acl.edit', 'rid' => $rid) : 'acl'), Sobi::Txt('ACL_RULE_SAVED'), !$apply, SPC::SUCCESS_MSG, array('sets' => array('rid' => $rid)));
 }
Beispiel #27
0
 /**
  * */
 public function ProxyUpload()
 {
     $ident = SPRequest::cmd('ident', null, 'post');
     $data = SPRequest::file($ident, 'tmp_name');
     $secret = md5(Sobi::Cfg('secret'));
     if ($data) {
         $properties = SPRequest::file($ident);
         $orgFileName = $properties['name'];
         $extension = SPFs::getExt($orgFileName);
         $orgFileName = str_replace('.' . $extension, '.' . strtolower($extension), $orgFileName);
         if ($properties['size'] > $this->maxSize) {
             $this->message(array('type' => 'error', 'text' => SPLang::e('FIELD_IMG_TOO_LARGE', $this->name, $properties['size'], $this->maxSize), 'id' => ''));
         }
         $dirNameHash = md5($orgFileName . time() . $secret);
         $dirName = SPLoader::dirPath("tmp.files.{$secret}.{$dirNameHash}", 'front', false);
         SPFs::mkdir($dirName);
         $path = $dirName . $orgFileName;
         /** @var $file SPImage */
         $orgImage = SPFactory::Instance('base.fs.image');
         if (!$orgImage->upload($data, $path)) {
             $this->message(array('type' => 'error', 'text' => SPLang::e('CANNOT_UPLOAD_FILE'), 'id' => ''));
         }
         if (Sobi::Cfg('image_field.fix_rotation', true)) {
             if ($orgImage->fixRotation()) {
                 $orgImage->save();
             }
         }
         if ($this->crop) {
             $croppedImage = clone $orgImage;
             list($originalWidth, $originalHeight) = getimagesize($path);
             $aspectRatio = $this->resizeWidth / $this->resizeHeight;
             $width = $aspectRatio * $originalHeight > $originalWidth ? $originalWidth : $aspectRatio * $originalHeight;
             $height = $originalWidth / $aspectRatio > $originalHeight ? $originalHeight : $originalWidth / $aspectRatio;
             try {
                 $croppedImage->crop($width, $height);
                 $croppedImage->saveAs($dirName . 'cropped_' . $orgFileName);
                 $ico = SPFactory::Instance('base.fs.image', $dirName . 'cropped_' . $orgFileName);
             } catch (SPException $x) {
                 $this->message(array('type' => 'error', 'text' => SPLang::e('FIELD_IMG_CANNOT_CROP', $x->getMessage()), 'id' => ''));
             }
         } else {
             $ico = clone $orgImage;
         }
         $image = clone $orgImage;
         try {
             $previewSize = explode(':', Sobi::Cfg('image.preview_size', '500:500'));
             $image->resample($previewSize[0], $previewSize[1], false);
             $image->saveAs($dirName . 'resized_' . $orgFileName);
         } catch (SPException $x) {
             $image->delete();
             $this->message(array('type' => 'error', 'text' => SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), 'id' => ''));
         }
         try {
             $icoSize = explode(':', Sobi::Cfg('image.ico_size', '80:80'));
             $ico->resample($icoSize[0], $icoSize[1], false);
             $ico->saveAs($dirName . 'icon_' . $orgFileName);
         } catch (SPException $x) {
             $ico->delete();
             $this->message(array('type' => 'error', 'text' => SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), 'id' => ''));
         }
         $path = $orgImage->getPathname();
         $type = $this->check($path);
         $properties['tmp_name'] = $path;
         SPFs::write(SPLoader::dirPath("tmp.files.{$secret}", 'front', false) . '/' . $orgFileName . '.var', SPConfig::serialize($properties));
         $response = array('type' => 'success', 'text' => $this->crop ? Sobi::Txt('IMAGE_UPLOADED_CROP', $properties['name'], $type) : Sobi::Txt('FILE_UPLOADED', $properties['name']), 'id' => 'directory://' . $dirNameHash, 'data' => array('name' => $properties['name'], 'type' => $properties['type'], 'size' => $properties['size'], 'original' => $dirNameHash . '/' . $properties['name'], 'icon' => $dirNameHash . '/' . 'icon_' . $orgFileName, 'crop' => $this->crop, 'height' => $this->resizeHeight, 'width' => $this->resizeWidth));
     } else {
         $response = array('type' => 'error', 'text' => SPLang::e('CANNOT_UPLOAD_FILE_NO_DATA'), 'id' => '');
     }
     $this->message($response);
 }
Beispiel #28
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();
    }
Beispiel #29
0
 /**
  * Returns currently used language
  * @param bool $storage - force lang for storage.
  * If the $_POST array contain "sp_language" index and the $storage param is set, this language will be returned.
  * In other cases it is recommended to call this function with $storage = false. However because this happen only while recieving data from POST ///
  * @param bool $allowEmpty
  * @return string
  */
 public static function Lang($storage = true, $allowEmpty = false)
 {
     /* when storing lang depend values and there was lang in request */
     static $langPost = -1;
     static $langGet = -1;
     if ($langPost == -1 || $langGet == -1) {
         $langPost = SPRequest::cmd('sp-language', false, 'post');
         $langGet = SPRequest::cmd('sp-language', false, 'get');
     }
     if ($storage && $langPost) {
         $lang = SPRequest::cmd('sp-language', false, 'post');
     } elseif ($langGet && self::Cfg('lang.multimode', false)) {
         $lang = SPRequest::cmd('sp-language', false, 'get');
     } else {
         static $lang = null;
         if (!strlen($lang)) {
             if (self::Cfg('lang.multimode', false)) {
                 $lang = SPFactory::config()->key('language');
             } else {
                 $lang = self::DefLang();
             }
             self::Trigger('Language', 'Determine', array(&$lang));
         }
     }
     $lang = strlen($lang) ? $lang : ($allowEmpty ? self::DefLang() : self::Lang(false, true));
     return $lang;
 }
Beispiel #30
0
 /**
  * @param string $action
  * @param string $subject
  * @param mixed $params
  * @return bool
  */
 public function trigger($action, $subject = null, $params = array())
 {
     static $actions = array();
     static $count = 0;
     $action = ucfirst($action) . ucfirst($subject);
     $action = str_replace('SP', null, $action);
     $task = Sobi::Reg('task', SPRequest::task());
     $task = strlen($task) ? $task : '*';
     if (strstr($task, '.')) {
         $t = explode('.', $task);
         $task = $t[0] . '.' . $t[1];
     }
     /**
      * Joomla! -> Unable to load renderer class
      */
     if ($action == 'ParseContent' && SPRequest::cmd('format') == 'raw') {
         return;
     }
     $actions[$count++] = $action;
     // this always
     SPFactory::mainframe()->trigger($action, $params);
     //	    SPConfig::debOut( $action, false, false, true );
     /**
      * An Application should not trigger other applications
      * Apps are running non parallel
      * Exception, if an app will an action to be
      * triggered this action has to begin with App
      */
     /*
      * it's important to write comments in own code ..
      * It may be also helpful to read own comments sometimes
      * How the hell "has to begin with App" == substr( $action, 0, 3 ) != 'App' ) ???
      * ========================================================================================
      * Note for intelligent people: it caused for example that the payment method wasn't delivered to the notification App
      */
     if ($count < 2 || substr($action, 0, 3) == 'App') {
         /* load all plugins having method for this action */
         if (!isset($this->_actions[$task])) {
             $this->load($task);
         }
         /* if there were any plugin for this action, check if these are loaded */
         if (count($this->_actions[$task])) {
             foreach ($this->_actions[$task] as $plugin) {
                 /* in case this plugin wasn't initialised */
                 if (!isset($this->_plugins[$plugin])) {
                     $this->initPlugin($plugin);
                 }
                 /* call the method */
                 if (isset($this->_plugins[$plugin]) && $this->_plugins[$plugin]->provide($action)) {
                     call_user_func_array(array($this->_plugins[$plugin], $action), $params);
                 }
             }
         }
     }
     //	    SPConfig::debOut( $action, true, false, true );
     unset($actions[$count]);
     $count--;
     return true;
 }