Example #1
0
 public function __construct($task = null, $sid = 0)
 {
     SPFactory::header()->addCSSFile('menu', true)->addJsFile('menu', true);
     $this->_task = $task ? $task : SPRequest::task();
     $this->_sid = $sid;
     SPFactory::registry()->set('adm_menu', $this);
 }
Example #2
0
 private function screen()
 {
     $data = SPFactory::registry()->loadDBSection('paypal_' . Sobi::Section())->get('paypal_' . Sobi::Section());
     if (!count($data)) {
         $data = SPFactory::registry()->loadDBSection('paypal')->get('paypal');
     }
     $ppexpl = SPLang::getValue('ppexpl', 'application', Sobi::Section());
     $ppsubj = SPLang::getValue('ppsubject', 'application', Sobi::Section());
     if (!strlen($ppsubj)) {
         $ppsubj = SPLang::getValue('ppsubject', 'application');
     }
     $this->getView('paypal')->assign($tile, 'title')->assign($data['ppurl']['value'], 'ppurl')->assign($data['ppemail']['value'], 'ppemail')->assign($data['pprurl']['value'], 'pprurl')->assign($data['ppcc']['value'], 'ppcc')->assign($ppexpl, 'ppexpl')->assign($ppsubj, 'ppsubject')->determineTemplate('extensions', 'paypal')->display();
 }
Example #3
0
 /**
  * This function have to add own string into the given array
  * Basically: $methods[ $this->id ] = "Some String To Output";
  * Optionally the value can be also SobiPro Arr2XML array.
  * Check the documentation for more information
  * @param array $methods
  * @param SPEntry $entry
  * @param array $payment
  * @param bool $message
  * @return void
  */
 public function PaymentMethodView(&$methods, $entry, &$payment, $message = false)
 {
     $data = SPFactory::registry()->loadDBSection('paypal_' . Sobi::Section())->get('paypal_' . Sobi::Section());
     if (!count($data)) {
         $data = SPFactory::registry()->loadDBSection('paypal')->get('paypal');
     }
     $cfg = SPLoader::loadIniFile('etc.paypal');
     $rp = $cfg['general']['replace'];
     $to = $cfg['general']['replace'] == ',' ? '.' : ',';
     $amount = str_replace($rp, $to, $payment['summary']['sum_brutto']);
     $values = array('entry' => $entry, 'amount' => preg_replace('/[^0-9\\.,]/', null, $amount), 'ppurl' => SPLang::replacePlaceHolders($data['ppurl']['value'], $entry), 'ppemail' => SPLang::replacePlaceHolders($data['ppemail']['value'], $entry), 'pprurl' => SPLang::replacePlaceHolders($data['pprurl']['value'], $entry), 'ppcc' => SPLang::replacePlaceHolders($data['ppcc']['value'], $entry));
     $expl = SPLang::replacePlaceHolders(SPLang::getValue('ppexpl', 'plugin', Sobi::Section()), $values);
     $subject = SPLang::replacePlaceHolders(SPLang::getValue('ppsubject', 'plugin', Sobi::Section()), $values);
     $values['expl'] = $expl;
     $values['subject'] = $subject;
     $values['ip'] = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER');
     $methods[$this->id] = array('content' => $message ? $this->raw($cfg, $values) : $this->content($cfg, $values), 'title' => Sobi::Txt('APP.PPP.PAY_TITLE'));
 }
Example #4
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));
 }
Example #5
0
 /**
  * @param int $sid
  * @return SPCache
  */
 public static function &cache($sid = 0)
 {
     if (!Sobi::Section()) {
         $path = array();
         $id = $sid;
         while ($id > 0) {
             try {
                 $id = SPFactory::db()->select('pid', 'spdb_relations', array('id' => $id))->loadResult();
                 if ($id) {
                     $path[] = (int) $id;
                 }
             } catch (SPException $x) {
                 Sobi::Error('CoreCtrl', SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
             }
         }
         if (count($path)) {
             $path = array_reverse($path);
         }
         SPFactory::registry()->set('current_section', $path[0]);
     }
     SPLoader::loadClass('base.cache');
     return SPCache::getInstance($sid);
 }
Example #6
0
 /**
  * get the right section
  * @return void
  */
 private function getSection()
 {
     $pid = SPRequest::int('pid');
     $pid = $pid ? $pid : $this->_sid;
     if ($pid) {
         $this->_model = SPFactory::object($pid);
         /** @noinspection PhpParamsInspection
          * @var $this ->_model stdClass
          */
         if ($this->_model->oType == 'section') {
             $this->_section = $this->_model->id;
         } else {
             $db = SPFactory::db();
             $path = array();
             $id = $pid;
             while ($id > 0) {
                 try {
                     $db->select('pid', 'spdb_relations', array('id' => $id));
                     $id = $db->loadResult();
                     if ($id) {
                         $path[] = (int) $id;
                     }
                 } catch (SPException $x) {
                     Sobi::Error('CoreCtrl', SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
                 }
             }
             $path = array_reverse($path);
             $this->_section = $path[0];
         }
     } else {
         $this->_section = '0';
     }
     SPFactory::registry()->set('current_section', $this->_section);
 }
Example #7
0
 /**
  * @param string
  * @return SPConfigAdmView
  */
 protected function getView($task)
 {
     SPLoader::loadClass('html.input');
     $sid = Sobi::Reg('current_section');
     /* create menu */
     $class = SPLoader::loadClass('views.adm.menu');
     $menu = new $class($task, $sid);
     /* load the menu definition */
     if ($sid) {
         $cfg = SPLoader::loadIniFile('etc.adm.section_menu');
     } else {
         $cfg = SPLoader::loadIniFile('etc.adm.config_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));
     if ($sid) {
         if (Sobi::Cfg('section.template') == SPC::DEFAULT_TEMPLATE && strstr(SPRequest::task(), 'config')) {
             SPFactory::message()->warning(Sobi::Txt('TP.DEFAULT_WARN', 'https://www.sigsiu.net/help_screen/template.info'), false)->setSystemMessage();
         }
         /* create new SigsiuTree */
         $tree = SPLoader::loadClass('mlo.tree');
         $tree = new $tree(Sobi::GetUserState('categories.order', 'corder', 'position.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($sid);
         /* add the tree into the menu */
         $menu->addCustom('AMN.ENT_CAT', $tree->getTree());
         $seClass = SPLoader::loadModel('section');
         $cSec = new $seClass();
         $cSec->init($sid);
     } else {
         $cSec = array('name' => Sobi::Txt('GB.CFG.GLOBAL_CONFIGURATION'));
         $menu->addCustom('GB.CFG.GLOBAL_TEMPLATES', $this->listTemplates());
     }
     $view = SPFactory::View('config', true);
     $view->assign($task, 'task');
     $view->assign($cSec, 'section');
     $view->assign($menu, 'menu');
     $view->addHidden(SPFactory::registry()->get('current_section'), 'sid');
     return $view;
 }
Example #8
0
 /**
  */
 protected function tplCfg($path, $task = null)
 {
     $file = explode('.', $path);
     $files = array();
     if (strstr($file[0], 'cms:')) {
         $file[0] = str_replace('cms:', null, $file[0]);
         $file = SPFactory::mainframe()->path(implode('.', $file));
         $path = SPLoader::dirPath($file, 'root', true);
         $this->_tCfg = SPLoader::loadIniFile("{$path}.config", true, false, false, true);
         $files[] = SPLoader::iniStorage();
     } else {
         $this->_tCfg = SPLoader::loadIniFile("usr.templates.{$path}.config");
         $files[] = SPLoader::iniStorage();
         $path = SPLoader::dirPath('usr.templates.' . $path, 'front', true);
     }
     if (!$task) {
         $task = $this->_task == 'add' || $this->_task == 'submit' ? 'edit' : $this->template;
     }
     if (SPLoader::translatePath("{$path}.{$this->templateType}.{$task}", 'absolute', true, 'ini')) {
         $taskCfg = SPLoader::loadIniFile("{$path}.{$this->templateType}.{$task}", true, false, false, true);
         $files[] = SPLoader::iniStorage();
         foreach ($taskCfg as $section => $keys) {
             if (isset($this->_tCfg[$section])) {
                 $this->_tCfg[$section] = array_merge($this->_tCfg[$section], $keys);
             } else {
                 $this->_tCfg[$section] = $keys;
             }
         }
     }
     if (count($files)) {
         foreach ($files as $i => $file) {
             $files[$i] = array('file' => str_replace(SPLoader::translateDirPath(Sobi::Cfg('section.template'), 'templates'), null, $file), 'checksum' => md5_file($file));
         }
         SPFactory::registry()->set('template_config', $files);
     }
     if (SPLoader::translatePath("{$path}.config", 'absolute', true, 'json')) {
         $config = json_decode(SPFs::read(SPLoader::translatePath("{$path}.config", 'absolute', true, 'json')), true);
         $settings = array();
         foreach ($config as $section => $setting) {
             $settings[str_replace('-', '.', $section)] = $setting;
         }
         if (SPLoader::translatePath("{$path}.{$this->templateType}.{$task}", 'absolute', true, 'json')) {
             $subConfig = json_decode(SPFs::read(SPLoader::translatePath("{$path}.{$this->templateType}.{$task}", 'absolute', true, 'json')), true);
             if (count($subConfig)) {
                 foreach ($subConfig as $section => $subSettings) {
                     foreach ($subSettings as $k => $v) {
                         $settings[str_replace('-', '.', $section)][$k] = $v;
                     }
                 }
             }
         }
         if (isset($settings['general'])) {
             foreach ($settings['general'] as $k => $v) {
                 $this->_tCfg['general'][$k] = $v;
             }
         }
         $task = SPRequest::task() == 'entry.add' ? 'entry.edit' : SPRequest::task();
         if (isset($settings[$task])) {
             foreach ($settings[$task] as $k => $v) {
                 $this->_tCfg['general'][$k] = $v;
             }
         }
     }
     Sobi::Trigger($this->name(), __FUNCTION__, array(&$this->_tCfg));
     SPFactory::registry()->set('current_template', $path);
 }
Example #9
0
 /**
  * initialising
  *
  * @param string $name
  * @param string $method
  * @throws SPException
  */
 private static function init($name, $method)
 {
     if (!is_string($method)) {
         throw new SPException('Wrong method given: ' . get_class($method));
     }
     self::$method = strtoupper($method);
     $name = self::$method == 'COOKIE' ? 'SPro_' . $name : $name;
     self::$name = $name;
     switch (self::$method) {
         case 'GET':
             // it's seems that Joomla! is storing the decoded variables from menu
             // into $_REQUEST instead of $_GET
             self::$request =& $_REQUEST;
             //				self::$request =& $_GET;
             break;
         case 'POST':
             self::$request =& $_POST;
             break;
         case 'FILES':
             self::$request =& $_FILES;
             break;
         case 'COOKIE':
             self::$request =& $_COOKIE;
             break;
         case 'ENV':
             self::$request =& $_ENV;
             break;
         case 'SERVER':
             self::$request =& $_SERVER;
             break;
         case 'REQUESTCACHE':
             self::$request =& SPFactory::registry()->__get('requestcache');
             break;
         default:
             self::$request =& $_REQUEST;
             self::$method = 'REQUEST';
             break;
     }
 }
Example #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);
 }
Example #11
0
 /**
  * @deprecated since 1.1 replaced by {@link #Initialise()}
  * @param int $sid - section id
  * @param null $root - root of Joomla!
  * @param null $lang - language
  * @return null
  */
 public static function Init($root = null, $lang = null, $sid = 0)
 {
     static $loaded = false;
     if (!$loaded) {
         if (!defined('SOBI_CMS')) {
             define('SOBI_CMS', version_compare(JVERSION, '3.0.0', 'ge') ? 'joomla3' : (version_compare(JVERSION, '1.6.0', 'ge') ? 'joomla16' : 'joomla15'));
         }
         defined('SOBIPRO') || define('SOBIPRO', true);
         defined('SOBI_TASK') || define('SOBI_TASK', 'task');
         defined('SOBI_DEFLANG') || define('SOBI_DEFLANG', $lang);
         defined('SOBI_ACL') || define('SOBI_ACL', 'front');
         defined('SOBI_ROOT') || define('SOBI_ROOT', $root);
         defined('SOBI_MEDIA') || define('SOBI_MEDIA', implode('/', array($root, 'media', 'sobipro')));
         defined('SOBI_PATH') || define('SOBI_PATH', SOBI_ROOT . '/components/com_sobipro');
         defined('SOBI_LIVE_PATH') || define('SOBI_LIVE_PATH', 'components/com_sobipro');
         require_once SOBI_PATH . '/lib/base/fs/loader.php';
         SPLoader::loadController('sobipro');
         SPLoader::loadController('interface');
         SPLoader::loadClass('base.exception');
         SPLoader::loadClass('base.const');
         SPLoader::loadClass('base.object');
         SPLoader::loadClass('base.filter');
         SPLoader::loadClass('base.request');
         SPLoader::loadClass('cms.base.lang');
         SPLoader::loadClass('models.dbobject');
         SPLoader::loadClass('base.factory');
         SPLoader::loadClass('base.config');
         SPLoader::loadClass('cms.base.fs');
         // in case it is a CLI call
         if (isset($_SERVER['REQUEST_URI'])) {
             SPFactory::config()->set('live_site', JURI::root());
         }
         $loaded = true;
     }
     if ($sid) {
         $section = null;
         if ($sid) {
             $path = array();
             $id = $sid;
             $path[] = (int) $id;
             while ($id > 0) {
                 try {
                     $id = SPFactory::db()->select('pid', 'spdb_relations', array('id' => $id))->loadResult();
                     if ($id) {
                         $path[] = (int) $id;
                     }
                 } catch (SPException $x) {
                     Sobi::Error('ExtCoreCtrl', SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
                 }
             }
             $path = array_reverse($path);
             $section = SPFactory::object($path[0]);
         }
         /* set current section in the registry */
         SPFactory::registry()->set('current_section', $section->id);
         $_config =& SPFactory::config();
         /* load basic configuration settings */
         $_config->addIniFile('etc.config', true);
         $_config->addTable('spdb_config', $sid);
         /* initialise interface config setting */
         SPFactory::mainframe()->getBasicCfg();
         /* initialise config */
         $_config->init();
     }
 }
Example #12
0
 /**
  * @param null $spsid
  * @return array
  */
 public function getReports($spsid)
 {
     $reports = array();
     if ($this->reports[$spsid]) {
         //			$messages = SPConfig::serialize( $this->reports );
         $reports = $this->reports[$spsid];
         unset($this->reports[$spsid]);
         /** Thu, Jul 31, 2014 11:12:02
          * Why the hell we are setting these messages into the db again?
          */
         $store = array('params' => array(), 'key' => 'queue', 'value' => date(DATE_RFC822), 'description' => null, 'options' => null);
         SPFactory::registry()->saveDBSection(array('reports' => $store), 'reports');
     }
     return $reports;
 }
Example #13
0
 protected function tplPath()
 {
     if (!$this->_templatePath) {
         $tpl = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE);
         $file = explode('.', $tpl);
         if (strstr($file[0], 'cms:')) {
             $file[0] = str_replace('cms:', null, $file[0]);
             $file = SPFactory::mainframe()->path(implode('.', $file));
             $this->_templatePath = SPLoader::dirPath($file, 'root', false, null);
         } else {
             $this->_templatePath = SPLoader::dirPath('usr.templates.' . $tpl, 'front', false, null);
         }
     }
     SPFactory::registry()->set('current_template_path', $this->_templatePath);
     return $this->_templatePath;
 }
Example #14
0
 /**
  * @param SPField[] $fields
  * @return void
  */
 protected function createValidationScript($fields)
 {
     /* get input filters */
     $registry =& SPFactory::registry();
     $registry->loadDBSection('fields_filter');
     $filters = $registry->get('fields_filter');
     $validate = array();
     foreach ($fields as $field) {
         $filter = $field->get('filter');
         if ($filter && isset($filters[$filter])) {
             $f = new stdClass();
             $f->name = $field->get('nid');
             $f->filter = base64_decode($filters[$filter]['params']);
             $f->msg = Sobi::Txt('[JS]' . $filters[$filter]['description']);
             $validate[] = $f;
         }
     }
     if (count($validate)) {
         Sobi::Trigger($this->name(), __FUNCTION__, array(&$validate));
         $validate = json_encode($validate);
         $header =& SPFactory::header();
         $header->addJsVarFile('efilter', md5($validate), array('OBJ' => addslashes($validate)));
     }
 }
Example #15
0
 /**
  * Parse text and replaces placeholders
  * @param string $text
  * @param SPDBObject $obj
  * @param bool $html
  * @param bool $dropEmpty
  * @return string
  */
 public static function replacePlaceHolders($text, $obj = null, $html = false, $dropEmpty = false)
 {
     preg_match_all('/{([a-zA-Z0-9\\-_\\:\\.\\%\\s]+)}/', $text, $placeHolders);
     if (count($placeHolders[1])) {
         foreach ($placeHolders[1] as $placeHolder) {
             $replacement = null;
             switch ($placeHolder) {
                 case 'section':
                 case 'section.id':
                 case 'section.name':
                     $replacement = Sobi::Section($placeHolder == 'section' || $placeHolder == 'section.name');
                     break;
                     /*
                      * eat own dog food is so true. Isn't it?!
                      */
                 /*
                  * eat own dog food is so true. Isn't it?!
                  */
                 case 'token':
                     $replacement = SPFactory::mainframe()->token();
                     break;
                 default:
                     if (strstr($placeHolder, 'date%')) {
                         $date = explode('%', $placeHolder);
                         $replacement = date($date[1]);
                         break;
                     }
                     if (strstr($placeHolder, 'cfg:')) {
                         $replacement = Sobi::Cfg(str_replace('cfg:', null, $placeHolder));
                         break;
                     } else {
                         if (strstr($placeHolder, 'messages')) {
                             $obj = SPFactory::registry()->get('messages');
                         }
                         $replacement = self::parseVal($placeHolder, $obj, $html);
                     }
             }
             if ($replacement && (is_string($replacement) || is_numeric($replacement))) {
                 $text = str_replace('{' . $placeHolder . '}', (string) $replacement, $text);
             } elseif ($dropEmpty) {
                 $text = str_replace('{' . $placeHolder . '}', null, $text);
             }
         }
     }
     return $text;
 }
Example #16
0
 protected function getResults($ssid, $template)
 {
     $results = array();
     /* case some plugin overwrites this method */
     Sobi::Trigger('GetResults', 'Search', array(&$results, &$ssid, &$template));
     if (count($results)) {
         return $results;
     }
     /* get limits - if defined in template config - otherwise from the section config */
     $eLimit = $this->tKey($template, 'entries_limit', Sobi::Cfg('search.entries_limit', Sobi::Cfg('list.entries_limit', 2)));
     $eInLine = $this->tKey($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;
     try {
         $this->_db->select(array('entriesResults', 'requestData'), 'spdb_search', array('ssid' => $ssid));
         $r = $this->_db->loadAssocList();
         if (strlen($r[0]['entriesResults'])) {
             $store = SPConfig::unserialize($r[0]['entriesResults']);
             if ($store['results']) {
                 $this->_results = array_unique(explode(',', $store['results']));
                 $this->_resultsByPriority = $store['resultsByPriority'];
             }
             $this->_resultsCount = count($this->_results);
         }
         $this->_request = SPConfig::unserialize($r[0]['requestData']);
         SPFactory::registry()->set('requestcache', $this->_request);
         if (count($this->_results)) {
             $r = array_slice($this->_results, $eLimStart, $eLimit);
             /* so we have a results */
             foreach ($r as $i => $sid) {
                 $results[$i] = (int) $sid;
                 //$results[ $i ] = new $eClass();
                 //$results[ $i ]->init( $sid );
             }
         }
     } catch (SPException $x) {
         Sobi::Error($this->name(), SPLang::e('CANNOT_GET_SESSION_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
     }
     Sobi::SetUserData('currently-displayed-entries', $results);
     return $results;
 }
Example #17
0
 /**
  * Just when adding new field - first step
  */
 private function add()
 {
     if ($this->_fieldType) {
         $groups = $this->getFieldGroup($this->_fieldType);
         $field = SPFactory::Model('field', true);
         $field->loadType($this->_fieldType);
     } else {
         $groups = $this->getFieldTypes();
         /* create dummy field with initial values */
         $field = array('name' => '', 'nid' => '', 'notice' => '', 'description' => '', 'adminField' => 0, 'enabled' => 1, 'fee' => 0, 'isFree' => 1, 'withLabel' => 1, 'version' => 1, 'editable' => 1, 'required' => 0, 'priority' => 5, 'showIn' => 'details', 'editLimit' => '', 'version' => 1, 'inSearch' => 0, 'cssClass' => '', 'fieldType' => $this->_fieldType);
     }
     /* get view class */
     $view = SPFactory::View('field', true);
     $task = 'add';
     $view->addHidden(SPRequest::sid(), 'sid');
     $view->addHidden(0, 'fid');
     $view->assign($groups, 'types');
     $view->assign($field, 'field');
     $view->assign($task, 'task');
     if ($this->_fieldType) {
         $field->onFieldEdit($view);
     }
     $registry = SPFactory::registry();
     $registry->loadDBSection('fields_filter');
     $helpTask = 'field.' . $field->get('fieldType');
     $registry->set('help_task', $helpTask);
     $filters = $registry->get('fields_filter');
     $f = array(0 => Sobi::Txt('FM.NO_FILTER'));
     if (count($filters)) {
         foreach ($filters as $filter => $data) {
             $f[$filter] = Sobi::Txt($data['value']);
         }
     }
     $view->assign($f, 'filters');
     if ($this->loadTemplate($field, $view)) {
         $view->display();
     } elseif (SPLoader::translatePath('field.edit.' . $this->_fieldType, 'adm')) {
         $view->assign($helpTask, '_compatibility');
         if (SPLoader::translatePath('field.edit.' . $this->_fieldType, 'adm', true, 'ini')) {
             $view->loadConfig('field.edit.' . $this->_fieldType);
         }
         $view->setTemplate('field.edit');
         if (SPLoader::translatePath('field.edit.' . $this->_fieldType, 'adm')) {
             $view->setTemplate('field.edit.' . $this->_fieldType);
         }
         SPFactory::header()->addCSSCode('#toolbar-box { display: block }');
         $view->display();
     } else {
         Sobi::Error($this->name(), SPLang::e('NO_FIELD_DEF'), SPC::WARNING, 500, __LINE__, __FILE__);
     }
 }
Example #18
0
 /**
  * @param SPEntry $entry
  * @param string $request
  * @throws SPException
  * @return string
  */
 private function verify($entry, $request)
 {
     $data = SPRequest::raw($this->nid, null, $request);
     $dexs = strlen($data);
     /* check if it was required */
     if ($this->required && !$dexs) {
         throw new SPException(SPLang::e('FIELD_REQUIRED_ERR', $this->name));
     }
     /* check if there was a filter */
     if ($this->filter && $dexs) {
         $registry =& SPFactory::registry();
         $registry->loadDBSection('fields_filter');
         $filters = $registry->get('fields_filter');
         $filter = isset($filters[$this->filter]) ? $filters[$this->filter] : null;
         if (!count($filter)) {
             throw new SPException(SPLang::e('FIELD_FILTER_ERR', $this->filter));
         } else {
             if (!preg_match(base64_decode($filter['params']), $data)) {
                 throw new SPException(str_replace('$field', $this->name, SPLang::e($filter['description'])));
             }
         }
     }
     /* check if there was an adminField */
     if ($this->adminField && $dexs) {
         if (!Sobi::Can('entry.adm_fields.edit')) {
             throw new SPException(SPLang::e('FIELD_NOT_AUTH', $this->name));
         }
     }
     /* check if it was free */
     if (!$this->isFree && $this->fee && $dexs) {
         SPFactory::payment()->add($this->fee, $this->name, $entry->get('id'), $this->fid);
     }
     /* check if it should contains unique data */
     if ($this->uniqueData && $dexs) {
         $matches = $this->searchData($data, Sobi::Reg('current_section'));
         if (count($matches) > 1 || count($matches) == 1 && $matches[0] != $entry->get('id')) {
             throw new SPException(SPLang::e('FIELD_NOT_UNIQUE', $this->name));
         }
     }
     /* check if it was editLimit */
     if ($this->editLimit == 0 && !Sobi::Can('entry.adm_fields.edit') && $dexs) {
         throw new SPException(SPLang::e('FIELD_NOT_AUTH_EXP', $this->name));
     }
     /* check if it was editable */
     if (!$this->editable && !Sobi::Can('entry.adm_fields.edit') && $dexs && $entry->get('version') > 1) {
         throw new SPException(SPLang::e('FIELD_NOT_AUTH_NOT_ED', $this->name));
     }
     if (!$dexs) {
         $data = null;
     }
     $this->setData($data);
     return $data;
 }
Example #19
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(' ', ' ', $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());
         }
     }
 }
Example #20
0
 /**
  * Gets the data for a field and save it in the database
  * @param SPEntry $entry
  * @param string $request
  * @throws SPException
  * @return bool
  */
 public function saveData(&$entry, $request = 'POST')
 {
     if (!$this->enabled) {
         return false;
     }
     if ($this->method == 'fixed') {
         $fixed = $this->fixedCid;
         $fixed = explode(',', $fixed);
         $data = array();
         if (count($fixed)) {
             foreach ($fixed as $cid) {
                 $data[] = trim($cid);
             }
         }
         if (!count($data)) {
             throw new SPException(SPLang::e('FIELD_CC_FIXED_CID_NOT_SELECTED', $this->name));
         }
     } else {
         $data = $this->verify($entry, $request);
     }
     $time = SPRequest::now();
     $IP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER');
     $uid = Sobi::My('id');
     /* if we are here, we can save these data */
     /* @var SPdb $db */
     $db = SPFactory::db();
     /* collect the needed params */
     $params = array();
     $params['publishUp'] = $entry->get('publishUp');
     $params['publishDown'] = $entry->get('publishDown');
     $params['fid'] = $this->fid;
     $params['sid'] = $entry->get('id');
     $params['section'] = Sobi::Reg('current_section');
     $params['lang'] = Sobi::Lang();
     $params['enabled'] = $entry->get('state');
     $params['params'] = null;
     $params['options'] = null;
     $params['baseData'] = SPConfig::serialize($data);
     $params['approved'] = $entry->get('approved');
     $params['confirmed'] = $entry->get('confirmed');
     /* if it is the first version, it is new entry */
     if ($entry->get('version') == 1) {
         $params['createdTime'] = $time;
         $params['createdBy'] = $uid;
         $params['createdIP'] = $IP;
     }
     $params['updatedTime'] = $time;
     $params['updatedBy'] = $uid;
     $params['updatedIP'] = $IP;
     $params['copy'] = !$entry->get('approved');
     if (Sobi::My('id') == $entry->get('owner')) {
         --$this->editLimit;
     }
     $params['editLimit'] = $this->editLimit;
     /* save it */
     try {
         /* Notices:
          * If it was new entry - insert
          * If it was an edit and the field wasn't filled before - insert
          * If it was an edit and the field was filled before - update
          *     " ... " and changes are not autopublish it should be insert of the copy .... but
          * " ... " if a copy already exist it is update again
          * */
         $db->insertUpdate('spdb_field_data', $params);
     } catch (SPException $x) {
         Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     /* if it wasn't edited in the default language, we have to try to insert it also for def lang */
     if (Sobi::Lang() != Sobi::DefLang()) {
         $params['lang'] = Sobi::DefLang();
         try {
             $db->insert('spdb_field_data', $params, true, true);
         } catch (SPException $x) {
             Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
     }
     /** Last important thing - join selected categories  */
     $cats = SPFactory::registry()->get('request_categories', array());
     $cats = array_unique(array_merge($cats, $data));
     SPFactory::registry()->set('request_categories', $cats);
     if ($this->method == 'select' && $this->isPrimary) {
         $db->update('spdb_object', array('parent' => $data[0]), array('id' => $params['sid']));
     }
 }
Example #21
0
 /**
  * (non-PHPdoc)
  * @see Site/lib/models/SPDBObject#save()
  */
 public function save($request = 'post')
 {
     $this->loadFields(Sobi::Section(), true);
     // Thu, Feb 19, 2015 12:12:47 - it should be actually "beforeSave"
     Sobi::Trigger($this->name(), 'Before' . ucfirst(__FUNCTION__), array($this->id));
     /* save the base object data */
     /* @var SPdb $db */
     $db = SPFactory::db();
     $db->transaction();
     if (!$this->nid || SPRequest::task() == 'entry.clone') {
         $this->nid = SPRequest::string($this->nameField, null, false, $request);
         $this->nid = $this->createAlias();
         $this->name = $this->nid;
     }
     if (Sobi::Cfg('entry.publish_limit', 0) && !defined('SOBI_ADM_PATH')) {
         SPRequest::set('entry_createdTime', 0, $request);
         SPRequest::set('entry_validSince', 0, $request);
         SPRequest::set('entry_validUntil', 0, $request);
         $this->validUntil = gmdate('Y-m-d H:i:s', time() + Sobi::Cfg('entry.publish_limit', 0) * 24 * 3600);
     }
     $preState = Sobi::Reg('object_previous_state');
     parent::save($request);
     $nameField = $this->nameField();
     /* get the fields for this section */
     foreach ($this->fields as $field) {
         /* @var $field SPField */
         try {
             if ($field->enabled('form', $preState['new'])) {
                 $field->saveData($this, $request);
             } else {
                 $field->finaliseSave($this, $request);
             }
             if ($field->get('id') == $nameField) {
                 /* get the entry name */
                 $this->name = $field->getRaw();
                 /* save the nid (name id) of the field where the entry name is saved */
                 $this->nameField = $field->get('nid');
             }
         } catch (SPException $x) {
             if (SPRequest::task() != 'entry.clone') {
                 $db->rollback();
                 throw new SPException(SPLang::e('CANNOT_SAVE_FIELS_DATA', $x->getMessage()));
             } else {
                 Sobi::Error($this->name(), SPLang::e('CANNOT_SAVE_FIELS_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
             }
         }
     }
     $values = array();
     /* get categories */
     $cats = Sobi::Reg('request_categories');
     if (!count($cats)) {
         $cats = SPRequest::arr('entry_parent', SPFactory::registry()->get('request_categories', array()), $request);
     }
     /* by default it should be comma separated string */
     if (!count($cats)) {
         $cats = SPRequest::string('entry_parent', null, $request);
         if (strlen($cats) && strpos($cats, ',')) {
             $cats = explode(',', $cats);
             foreach ($cats as $i => $cat) {
                 $c = (int) trim($cat);
                 if ($c) {
                     $cats[$i] = $c;
                 } else {
                     unset($cats[$i]);
                 }
             }
         } elseif (strlen($cats)) {
             $cats = array((int) $cats);
         }
     }
     if (is_array($cats) && count($cats)) {
         foreach ($cats as $i => $v) {
             if (!$v) {
                 unset($cats[$i]);
             }
         }
     }
     if (is_array($cats) && count($cats)) {
         /* get the ordering in these categories */
         try {
             $db->select('pid, MAX(position)', 'spdb_relations', array('pid' => $cats, 'oType' => 'entry'), null, 0, 0, false, 'pid');
             $cPos = $db->loadAssocList('pid');
             $currPos = $db->select(array('pid', 'position'), 'spdb_relations', array('id' => $this->id, 'oType' => 'entry'))->loadAssocList('pid');
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
         /* set the right position */
         foreach ($cats as $i => $cat) {
             $copy = 0;
             if (!$this->approved) {
                 $copy = isset($this->categories[$cats[$i]]) ? 0 : 1;
             } else {
                 $db->delete('spdb_relations', array('id' => $this->id, 'oType' => 'entry'));
             }
             if (isset($currPos[$cat])) {
                 $pos = $currPos[$cat]['position'];
             } else {
                 $pos = isset($cPos[$cat]) ? $cPos[$cat]['MAX(position)'] : 0;
                 $pos++;
             }
             $values[] = array('id' => $this->id, 'pid' => $cats[$i], 'oType' => 'entry', 'position' => $pos, 'validSince' => $this->validSince, 'validUntil' => $this->validUntil, 'copy' => $copy);
         }
         try {
             $db->insertArray('spdb_relations', $values, true);
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
     } elseif (!count($this->categories)) {
         throw new SPException(SPLang::e('MISSING_CAT'));
     }
     /* trigger possible state changes */
     if ($preState['approved'] != $this->approved) {
         if ($this->approved) {
             $this->approveFields(true);
             // it's being done by the method above - removing
             //Sobi::Trigger( $this->name(), 'AfterApprove', array( $this->id, $this->approved ) );
         }
     }
     if ($preState['state'] != $this->state) {
         Sobi::Trigger($this->name(), 'AfterChangeState', array($this->id, $this->state));
     }
     SPFactory::cache()->purgeSectionVars();
     SPFactory::cache()->deleteObj('entry', $this->id);
     if (count($cats)) {
         foreach ($cats as $cat) {
             SPFactory::cache()->deleteObj('category', $cat);
         }
     }
     Sobi::Trigger($this->name(), 'After' . ucfirst($preState['new'] ? __FUNCTION__ : 'Update'), array(&$this));
 }
Example #22
0
 /**
  * @param SPEntry $entry
  * @param SPdb $db
  * @param string $request
  * @throws SPException
  * @return array
  */
 private function verify($entry, &$db, $request)
 {
     $save = array();
     if ($this->ownLabel) {
         $save['label'] = SPRequest::raw($this->nid, null, $request);
         /* check if there was a filter */
         if ($this->filter && strlen($save['label'])) {
             $registry =& SPFactory::registry();
             $registry->loadDBSection('fields_filter');
             $filters = $registry->get('fields_filter');
             $filter = isset($filters[$this->filter]) ? $filters[$this->filter] : null;
             if (!count($filter)) {
                 throw new SPException(SPLang::e('FIELD_FILTER_ERR', $this->filter));
             } else {
                 if (!preg_match(base64_decode($filter['params']), $save['label'])) {
                     throw new SPException(str_replace('$field', $this->name, SPLang::e($filter['description'])));
                 }
             }
         }
     }
     $data = SPRequest::raw($this->nid . '_url', null, $request);
     $save['protocol'] = $db->escape(SPRequest::word($this->nid . '_protocol', null, $request));
     $dexs = strlen($data);
     $data = $db->escape($data);
     $data = preg_replace('/([a-z]{1,5}\\:\\/\\/)/i', null, $data);
     $save['url'] = $data;
     /* check if it was required */
     if ($this->required && !$dexs) {
         throw new SPException(SPLang::e('FIELD_REQUIRED_ERR', $this->name));
     }
     /* check if there was an adminField */
     if ($this->adminField && $dexs) {
         if (!Sobi::Can('entry.adm_fields.edit')) {
             throw new SPException(SPLang::e('FIELD_NOT_AUTH', $this->name));
         }
     }
     /* check if it was free */
     if (!$this->isFree && $this->fee && $dexs) {
         SPFactory::payment()->add($this->fee, $this->name, $entry->get('id'), $this->fid);
     }
     /* check if it should contains unique data */
     if ($this->uniqueData && $dexs) {
         $matches = $this->searchData($data, Sobi::Reg('current_section'));
         if (count($matches)) {
             throw new SPException(SPLang::e('FIELD_NOT_UNIQUE', $this->name));
         }
     }
     /* check if it was editLimit */
     if ($this->editLimit == 0 && !Sobi::Can('entry.adm_fields.edit') && $dexs) {
         throw new SPException(SPLang::e('FIELD_NOT_AUTH_EXP', $this->name));
     }
     /* check if it was editable */
     if (!$this->editable && !Sobi::Can('entry.adm_fields.edit') && $dexs && $entry->get('version') > 1) {
         throw new SPException(SPLang::e('FIELD_NOT_AUTH_NOT_ED', $this->name));
     }
     /* check the response code */
     if ($dexs && $this->validateUrl) {
         $rclass = SPLoader::loadClass('services.remote');
         $err = 0;
         $response = 0;
         try {
             $connection = new $rclass();
             $connection->setOptions(array('url' => $save['protocol'] . '://' . $data, 'connecttimeout' => 10, 'header' => false, 'returntransfer' => true));
             $connection->exec();
             $response = $connection->info('response_code');
             $err = $connection->error(false);
             $errTxt = $connection->error();
             $connection->close();
             if ($err) {
                 Sobi::Error($this->name(), SPLang::e('FIELD_URL_CANNOT_VALIDATE', $errTxt), SPC::WARNING, 0, __LINE__, __FILE__);
             }
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('FIELD_URL_CANNOT_VALIDATE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
         if ($err || $response != 200) {
             $response = $err ? $errTxt : $response;
             Sobi::Error($this->name(), SPLang::e('FIELD_URL_ERR', $save['protocol'] . '://' . $data, $response), SPC::WARNING, 0, __LINE__, __FILE__);
             throw new SPException(SPLang::e('FIELD_URL_ERR', $save['protocol'] . '://' . $data, $response));
         }
     }
     if (!$dexs) {
         $save = null;
     }
     return $save;
 }
Example #23
0
 private function getFilters()
 {
     $registry =& SPFactory::registry();
     $registry->loadDBSection('fields_filter');
     $filters = $registry->get('fields_filter');
     $f = array();
     foreach ($filters as $fid => $filter) {
         $f[$fid] = array('params' => $filter['params'], 'key' => $fid, 'value' => $filter['value'], 'description' => $filter['description'], 'options' => $filter['options']);
     }
     ksort($f);
     return $f;
 }
Example #24
0
 /**
  * check permission for an action
  * @param $subject
  * @param string $action - e.g. edit
  * @param string $value
  * @param null $section
  * @internal param string $ownership - e.g. own, all or global
  * @return bool - true if authorized
  */
 public function can($subject, $action = 'access', $value = 'valid', $section = null)
 {
     if (strstr($subject, '.')) {
         $subject = explode('.', $subject);
         $action = $subject[1];
         if (isset($subject[2])) {
             $value = $subject[2];
         }
         $subject = $subject[0];
     }
     if (!$section) {
         $section = SPFactory::registry()->get('current_section', 0);
     }
     $can = $this->authorise($section, $subject, $action, $value);
     if (SPFactory::registry()->__isset('plugins')) {
         Sobi::Trigger('Authorise', 'Permission', array(&$can, $section, $subject, $action, $value));
     }
     return $can;
 }
Example #25
0
 /**
  * Adds object to the pathway
  * @param SPDBObject $obj
  * @param array $site
  * @return void
  */
 public function &addObjToPathway($obj, $site = array())
 {
     if (defined('SOBI_ADM_PATH')) {
         return true;
     }
     $menu = JSite::getMenu()->getActive()->query;
     $sid = isset($menu['sid']) ? $menu['sid'] : 0;
     $resetPathway = false;
     if ($obj->get('oType') == 'entry') {
         $id = SPRequest::int('pid');
         /** if the entry isn't linked directly in the menu */
         if (!($obj->get('id') == $sid)) {
             /* if we didn't entered this entry via category */
             if (!$id || $id == Sobi::Section() || Sobi::Cfg('entry.primary_path_always')) {
                 $id = $obj->get('parent');
                 $resetPathway = true;
             }
         } else {
             /** ok - here is the weird thing:
              * When it is accessed via menu we have to force cache to create another version
              * because the pathway is stored in the cache
              * @todo find better solution for it
              */
             $mid = true;
             SPFactory::registry()->set('cache_view_recreate_request', $mid)->set('cache_view_add_itemid', JSite::getMenu()->getActive()->id);
             return $this;
         }
     } else {
         $id = $obj->get('id');
     }
     $path = SPFactory::cache()->getVar('parent_path', $id);
     if (!$path) {
         $path = SPFactory::config()->getParentPath($id, true, false, true);
         SPFactory::cache()->addVar($path, 'parent_path', $id);
     }
     if (count($path)) {
         /* skip everything above the linked sid */
         $rpath = array_reverse($path);
         $path = array();
         foreach ($rpath as $part) {
             if ($part['id'] == $sid) {
                 break;
             }
             $path[] = $part;
         }
         $path = array_reverse($path);
         /* ^^ skip everything above the linked sid */
     }
     $title = array();
     // if there was an active menu - add its title to the browser title as well
     if ($sid) {
         $title[] = JFactory::getDocument()->getTitle();
     }
     /**
      * Mon, Jul 16, 2012
      * I would relay like to know why I've added the "htmlentities" call here.
      * The second param of the 'addItem' method is URL so there should be definitely no such thing
      * Related to Bug #692
      */
     if (count($path)) {
         if ($resetPathway) {
             /** we have to reset the J! pathway in case:
              *  - we are entering an entry and we want to show the pathway corresponding to the main parent if of the entry
              *    but we have also an Itemid and Joomla! set already the pathway partialy so we need to override it
              *    It wouldn't be normally a problem but when SEF is enabled we do not have the pid so we don't know how it has been enetered
              */
             JFactory::getApplication()->getPathway()->setPathway(array());
         }
         foreach ($path as $data) {
             if (!(isset($data['name']) || isset($data['id'])) || !$data['id']) {
                 continue;
             }
             $title[] = $data['name'];
             $this->addToPathway($data['name'], self::url(array('title' => Sobi::Cfg('sef.alias', true) ? $data['alias'] : $data['name'], 'sid' => $data['id'])));
         }
     }
     if ($obj->get('oType') == 'entry') {
         $this->addToPathway($obj->get('name'), self::url(array('task' => 'entry.details', 'title' => Sobi::Cfg('sef.alias', true) ? $obj->get('nid') : $obj->get('name'), 'sid' => $obj->get('id'))));
         $title[] = $obj->get('name');
     }
     //		if ( count( $site ) && $site[ 0 ] ) {
     //			$title[ ] = Sobi::Txt( 'SITES_COUNTER', $site[ 1 ], $site[ 0 ] );
     //		}
     SPFactory::header()->addTitle($title, $site);
     return $this;
 }
Example #26
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;
 }
Example #27
0
 /**
  * @param SPEntry $entry
  * @param string $request
  * @throws SPException
  * @return array
  */
 protected function verify($entry, $request)
 {
     $save = array();
     $data = SPRequest::raw($this->nid . '_url', null, $request);
     $dexs = strlen($data);
     $data = SPFactory::db()->escape($data);
     if ($this->ownLabel) {
         $save['label'] = SPRequest::raw($this->nid, null, $request);
         /* check if there was a filter */
         if ($this->filter && strlen($save['label'])) {
             $registry =& SPFactory::registry();
             $registry->loadDBSection('fields_filter');
             $filters = $registry->get('fields_filter');
             $filter = isset($filters[$this->filter]) ? $filters[$this->filter] : null;
             if (!count($filter)) {
                 throw new SPException(SPLang::e('FIELD_FILTER_ERR', $this->filter));
             } else {
                 if (!preg_match(base64_decode($filter['params']), $save['label'])) {
                     throw new SPException(str_replace('$field', $this->name, SPLang::e($filter['description'])));
                 }
             }
         }
     }
     /* check if it was required */
     if ($this->required && !$dexs) {
         throw new SPException(SPLang::e('FIELD_REQUIRED_ERR', $this->name));
     }
     /* check if there was an adminField */
     if ($this->adminField && $dexs) {
         if (!Sobi::Can('adm_fields.edit')) {
             throw new SPException(SPLang::e('FIELD_NOT_AUTH', $this->name));
         }
     }
     /* check if it was free */
     if (!$this->isFree && $this->fee && $dexs) {
         SPFactory::payment()->add($this->fee, $this->name, $entry->get('id'), $this->fid);
     }
     /* check if it should contains unique data */
     if ($this->uniqueData && $dexs) {
         $matches = $this->searchData($data, Sobi::Reg('current_section'));
         if (count($matches)) {
             throw new SPException(SPLang::e('FIELD_NOT_UNIQUE', $this->name));
         }
     }
     /* check if it was editLimit */
     if ($this->editLimit == 0 && !Sobi::Can('entry.adm_fields.edit') && $dexs) {
         throw new SPException(SPLang::e('FIELD_NOT_AUTH_EXP', $this->name));
     }
     /* check if it was editable */
     if (!$this->editable && !Sobi::Can('entry.adm_fields.edit') && $dexs && $entry->get('version') > 1) {
         throw new SPException(SPLang::e('FIELD_NOT_AUTH_NOT_ED', $this->name));
     }
     /* check the response code */
     if ($dexs && $this->validateUrl) {
         if (preg_match('/[a-z0-9]@[a-z0-9].[a-z]/i', $data)) {
             $domain = explode('@', $data, 2);
             $domain = $domain[1];
             if (!checkdnsrr($domain, 'MX')) {
                 throw new SPException(SPLang::e('FIELD_MAIL_NO_MX', $data));
             }
         } else {
             throw new SPException(SPLang::e('FIELD_MAIL_WRONG_FORM', $data));
         }
     }
     if ($dexs) {
         /* if we are here, we can save these data */
         $save['url'] = $data;
     } else {
         $save = null;
     }
     $this->setData($save);
     return $save;
 }
Example #28
0
 protected function save($apply, $clone = false)
 {
     if (!SPFactory::mainframe()->checkToken()) {
         Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__);
     }
     $sets = array();
     if (!$clone) {
         $sid = SPRequest::sid() ? SPRequest::sid() : SPRequest::int('entry_id');
     } else {
         $sid = 0;
     }
     $apply = (int) $apply;
     if (!$this->_model) {
         $this->setModel(SPLoader::loadModel($this->_type));
     }
     $this->_model->init($sid);
     $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, $_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);
     $this->authorise($this->_model->get('id') ? 'edit' : 'add');
     try {
         $this->_model->validate('post');
     } catch (SPException $x) {
         $back = Sobi::GetUserState('back_url', Sobi::Url(array('task' => 'entry.add', 'sid' => Sobi::Section())));
         $data = $x->getData();
         $this->response($back, $x->getMessage(), false, 'error', array('required' => $data['field']));
     }
     try {
         $this->_model->save();
     } catch (SPException $x) {
         $back = Sobi::GetUserState('back_url', Sobi::Url(array('task' => 'entry.add', 'sid' => Sobi::Section())));
         $this->response($back, $x->getMessage(), false, 'error');
     }
     $sid = $this->_model->get('id');
     $sets['sid'] = $sid;
     $sets['entry.nid'] = $this->_model->get('nid');
     $sets['entry.id'] = $sid;
     if ($customClass && method_exists($customClass, 'AfterStoreEntry')) {
         $customClass::AfterStoreEntry($this->_model);
     }
     if (SPRequest::string('history-note') || $this->_task == 'saveWithRevision' || Sobi::Cfg('entry.versioningAdminBehaviour', 1)) {
         $this->logChanges('save', SPRequest::string('history-note'));
     }
     if ($apply || $clone) {
         if ($clone) {
             $msg = Sobi::Txt('MSG.OBJ_CLONED', array('type' => Sobi::Txt($this->_model->get('oType'))));
             $this->response(Sobi::Url(array('task' => $this->_type . '.edit', 'sid' => $sid)), $msg);
         } else {
             $msg = Sobi::Txt('MSG.OBJ_SAVED', array('type' => Sobi::Txt($this->_model->get('oType'))));
             $this->response(Sobi::Url(array('task' => $this->_type . '.edit', 'sid' => $sid)), $msg, false, 'success', array('sets' => $sets));
         }
     } elseif ($this->_task == 'saveAndNew') {
         $msg = Sobi::Txt('MSG.ALL_CHANGES_SAVED');
         $sid = $this->_model->get('parent');
         if (!$sid) {
             $sid = Sobi::Section();
         }
         $this->response(Sobi::Url(array('task' => $this->_type . '.add', 'sid' => $sid)), $msg, true, 'success', array('sets' => $sets));
     } else {
         $this->response(Sobi::Back(), Sobi::Txt('MSG.OBJ_SAVED', array('type' => Sobi::Txt($this->_model->get('oType')))));
     }
 }
Example #29
0
 /**
  * @param string $task
  */
 public function setTask($task)
 {
     $this->_task = strlen($task) ? $task : $this->_defTask;
     $helpTask = $this->_type . '.' . $this->_task;
     Sobi::Trigger($this->name(), __FUNCTION__, array(&$this->_task));
     SPFactory::registry()->set('task', $helpTask);
 }
Example #30
0
 /**
  */
 public function save($update = false, $init = true)
 {
     /* @var SPdb $db */
     $db =& SPFactory::db();
     /* check nid */
     if (!$update) {
         $c = 1;
         while ($c) {
             /* section name id has to be unique */
             try {
                 $db->select('COUNT(nid)', 'spdb_object', array('oType' => 'section', 'nid' => $this->nid));
                 $c = $db->loadResult();
                 if ($c > 0) {
                     $this->nid = $this->nid . '_' . rand(0, 1000);
                 }
             } catch (SPException $x) {
                 Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
             }
         }
     }
     SPFactory::registry()->set('current_section', $this->id);
     $db->transaction();
     parent::save();
     /* case adding new section, define the default title field */
     if (!$update && $init) {
         $field = SPFactory::Model('field', true);
         $fid = $field->saveNew(array('name' => 'Name', 'nid' => 'field_name', 'showIn' => 'both', 'fieldType' => 'inbox', 'enabled' => 1, 'required' => 1, 'editable' => 1, 'section' => $this->id, 'inSearch' => 1, 'searchMethod' => 'general', 'isFree' => 1, 'editLimit' => -1, 'withLabel' => 1));
         $field = SPFactory::Model('field', true);
         $field->saveNew(array('name' => 'Category', 'nid' => 'field_category', 'showIn' => 'hidden', 'fieldType' => 'category', 'enabled' => 1, 'required' => 1, 'editable' => 1, 'section' => $this->id, 'inSearch' => 1, 'searchMethod' => 'select', 'isFree' => 1, 'editLimit' => -1, 'withLabel' => 1, 'method' => 'select', 'isPrimary' => true));
         SPFactory::config()->saveCfg('entry.name_field', $fid)->saveCfg('list.entries_ordering', 'field_name')->saveCfg('template.icon_fonts_arr', array('font-awesome-3-local'));
         SPFactory::Controller('acl', true)->addNewRule($this->get('name'), array($this->id), array('section.access.valid', 'category.access.valid', 'entry.access.valid', 'entry.add.own', 'section.search.*'), array('visitor', 'registered'), 'Default permissions for the section "' . $this->get('name') . '"');
     }
     /* insert relation */
     try {
         $db->insertUpdate('spdb_relations', array('id' => $this->id, 'pid' => 0, 'oType' => 'section', 'position' => 1, 'validSince' => $this->validSince, 'validUntil' => $this->validUntil));
     } catch (SPException $x) {
         $db->rollback();
         Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
     }
     /* if there was no errors, commit the database changes */
     $db->commit();
     //		if( !$update ) {
     //			SPFactory::mainframe()->msg( Sobi::Txt( 'SEC.CREATED' ) );
     //		}
     SPFactory::cache()->cleanSection();
     /* trigger plugins */
     Sobi::Trigger('afterSave', $this->name(), array(&$this));
 }