Ejemplo n.º 1
0
 public function save(&$attr)
 {
     if (($attr['resize'] || $attr['crop']) && !($attr['resizeWidth'] && $attr['resizeHeight'])) {
         throw new SPException(SPLang::e('IMG_FIELD_RESIZE_NO_SIZE'));
     }
     parent::save($attr);
 }
Ejemplo n.º 2
0
 public static function __callStatic($name, $args)
 {
     if (defined('SOBIPRO_ADM')) {
         return call_user_func_array(array('self', '_' . $name), $args);
     } else {
         static $className = false;
         if (!$className) {
             $package = Sobi::Reg('current_template');
             if (SPFs::exists(Sobi::FixPath($package . '/input.php'))) {
                 $path = Sobi::FixPath($package . '/input.php');
                 ob_start();
                 $content = file_get_contents($path);
                 $class = array();
                 preg_match('/\\s*(class)\\s+(\\w+)/', $content, $class);
                 if (isset($class[2])) {
                     $className = $class[2];
                 } else {
                     Sobi::Error('Custom Input Class', SPLang::e('Cannot determine class name in file %s.', str_replace(SOBI_ROOT, null, $path)), SPC::WARNING, 0);
                     return false;
                 }
                 require_once $path;
             } else {
                 $className = true;
             }
         }
         if (is_string($className) && method_exists($className, $name)) {
             return call_user_func_array(array($className, $name), $args);
         } else {
             return call_user_func_array(array('self', '_' . $name), $args);
         }
     }
 }
Ejemplo n.º 3
0
 public function save(&$attr)
 {
     parent::save($attr);
     if ($attr['method'] == 'fixed') {
         if (!$attr['fixedCid']) {
             throw new SPException(SPLang::e('FIELD_FIXED_CID_MISSING'));
         } else {
             $cids = explode(',', $attr['fixedCid']);
             if (count($cids)) {
                 foreach ($cids as $cid) {
                     $catId = (int) $cid;
                     if (!$catId) {
                         throw new SPException(SPLang::e('FIELD_FIXED_CID_INVALID', $cid));
                     }
                     if ($catId == Sobi::Section()) {
                         throw new SPException(SPLang::e('FIELD_FIXED_CID_INVALID', $cid));
                     } else {
                         $parents = SPFactory::config()->getParentPath($catId);
                         if (!isset($parents[0]) || $parents[0] != Sobi::Section()) {
                             throw new SPException(SPLang::e('FIELD_FIXED_CID_INVALID_SECTION', $catId));
                         }
                     }
                 }
             } else {
                 throw new SPException(SPLang::e('FIELD_FIXED_CID_MISSING'));
             }
         }
     }
 }
Ejemplo n.º 4
0
 /**
  */
 public function execute()
 {
     $r = false;
     switch ($this->_task) {
         case 'chooser':
         case 'expand':
             SPLoader::loadClass('html.input');
             $r = true;
             $this->chooser($this->_task == 'expand');
             break;
         case 'parents':
             $r = true;
             $this->parents();
             break;
         case 'icon':
             $r = true;
             $this->iconChooser();
             break;
         default:
             /* case parent didn't registered this task, it was an error */
             if (!parent::execute() && $this->name() == __CLASS__) {
                 Sobi::Error($this->name(), SPLang::e('SUCH_TASK_NOT_FOUND', SPRequest::task()), SPC::NOTICE, 404, __LINE__, __FILE__);
             } else {
                 $r = true;
             }
             break;
     }
     return $r;
 }
Ejemplo n.º 5
0
 /**
  *
  */
 public function __construct()
 {
     if (self::$cs) {
         Sobi::Error('mainframe', SPLang::e('CRITICAL_SECTION'), SPC::ERROR, 500, __LINE__, __CLASS__);
     } else {
         self::$cs = true;
         self::$cs = false;
     }
 }
Ejemplo n.º 6
0
 public function display()
 {
     $template = SPLoader::loadTemplate($this->_tpl, 'php');
     if ($template) {
         include $template;
     } else {
         throw new SPException(SPLang::e('CANNOT_LOAD_TEMPLATE_FILE_AT', SPLoader::loadTemplate($this->_tpl, 'php', false)));
     }
 }
Ejemplo n.º 7
0
 protected function check($file)
 {
     $allowed = SPLoader::loadIniFile('etc.files');
     $mType = SPFactory::Instance('services.fileinfo', $file)->mimeType();
     if (strlen($mType) && !in_array($mType, $allowed)) {
         SPFs::delete($file);
         $this->message(array('type' => 'error', 'text' => SPLang::e('FILE_WRONG_TYPE', $mType), 'id' => ''));
     }
     return $mType;
 }
Ejemplo n.º 8
0
 protected function search()
 {
     if (!SPFactory::mainframe()->checkToken()) {
         Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__);
     }
     //		$selected = SPRequest::int( 'selected', 0 );
     $ssid = SPRequest::base64('ssid');
     $query = SPRequest::string('q', null);
     $session = SPFactory::user()->getUserState('userSelector', null, array());
     $setting = $session[$ssid];
     /* get the site to display */
     $site = SPRequest::int('site', 1);
     $eLim = Sobi::Cfg('user_selector.entries_limit', 18);
     $eLimStart = ($site - 1) * $eLim;
     $params = array();
     if ($query) {
         $q = '%' . $query . '%';
         $params = SPFactory::db()->where(array('name' => $q, 'username' => $q, 'email' => $q), 'OR');
     }
     try {
         $count = SPFactory::db()->select('COUNT(*)', '#__users', $params, $setting['ordering'])->loadResult();
         $data = SPFactory::db()->select(array('id', 'name', 'username', 'email', 'registerDate', 'lastvisitDate'), '#__users', $params, $setting['ordering'], $eLim, $eLimStart)->loadAssocList();
     } catch (SPException $x) {
         echo $x->getMessage();
         exit;
     }
     $response = array('sites' => ceil($count / $eLim), 'site' => $site);
     if (count($data)) {
         $replacements = array();
         preg_match_all('/\\%[a-z]*/', $setting['format'], $replacements);
         $placeholders = array();
         if (isset($replacements[0]) && count($replacements[0])) {
             foreach ($replacements[0] as $placeholder) {
                 $placeholders[] = str_replace('%', null, $placeholder);
             }
         }
         if (count($replacements)) {
             foreach ($data as $index => $user) {
                 $txt = $setting['format'];
                 foreach ($placeholders as $attribute) {
                     if (isset($user[$attribute])) {
                         $txt = str_replace('%' . $attribute, $user[$attribute], $txt);
                     }
                 }
                 $data[$index]['text'] = $txt;
             }
         }
         $response['users'] = $data;
     }
     SPFactory::mainframe()->cleanBuffer();
     echo json_encode($response);
     exit;
 }
Ejemplo n.º 9
0
 protected function save()
 {
     if (!SPFactory::mainframe()->checkToken()) {
         Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__);
     }
     $data = SPRequest::string('bankdata', null, true);
     $data = array('key' => 'bankdata', 'value' => $data, 'type' => 'application', 'id' => Sobi::Section(), 'section' => Sobi::Section());
     try {
         SPLang::saveValues($data);
     } catch (SPException $x) {
         $message = SPLang::e('DB_REPORTS_ERR', $x->getMessage());
         Sobi::Error('SPPaymentBt', $message, SPC::WARNING, 0, __LINE__, __FILE__);
         $this->response(Sobi::Back(), $message, false, 'error');
     }
     $this->response(Sobi::Back(), Sobi::Txt('MSG.ALL_CHANGES_SAVED'), false, 'success');
 }
Ejemplo n.º 10
0
 protected function save()
 {
     if (!SPFactory::mainframe()->checkToken()) {
         Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__);
     }
     $this->validate('extensions.paypal', array('task' => 'paypal', 'pid' => Sobi::Section()));
     SPFactory::registry()->saveDBSection(array(array('key' => 'ppurl', 'value' => SPRequest::string('ppurl')), array('key' => 'ppemail', 'value' => SPRequest::string('ppemail')), array('key' => 'ppcc', 'value' => SPRequest::string('ppcc')), array('key' => 'pprurl', 'value' => SPRequest::string('pprurl'))), 'paypal_' . Sobi::Section());
     $data = array('key' => 'ppexpl', 'value' => SPRequest::string('ppexpl', null, true), 'type' => 'application', 'id' => Sobi::Section(), 'section' => Sobi::Section());
     try {
         SPLang::saveValues($data);
         $data['key'] = 'ppsubject';
         $data['value'] = SPRequest::string('ppsubject', true);
         SPLang::saveValues($data);
     } catch (SPException $x) {
         $message = SPLang::e('DB_REPORTS_ERR', $x->getMessage());
         Sobi::Error('SPPaymentBt', $message, SPC::WARNING, 0, __LINE__, __FILE__);
         $this->response(Sobi::Back(), $message, false, 'error');
     }
     $this->response(Sobi::Back(), Sobi::Txt('MSG.ALL_CHANGES_SAVED'), false, 'success');
 }
Ejemplo n.º 11
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();
 }
Ejemplo n.º 12
0
 public function execute()
 {
     SPRequest::set('task', $this->_type . '.' . $this->_task);
     if (strstr($this->_task, '.')) {
         $task = explode('.', $this->_task);
         $class = SPLoader::loadClass('opt.listing.' . $task[0], false, null, true);
     } else {
         $class = SPLoader::loadClass('opt.listing.' . $this->_task, false, null, true);
     }
     if ($class) {
         $imp = class_implements($class);
         if (is_array($imp) && in_array('SPListing', $imp)) {
             /** @noinspection PhpIncludeInspection $compatibility */
             $listing = new $class();
             if (!isset($class::$compatibility)) {
                 define('SOBI_LEGACY_LISTING', true);
                 if (strstr($this->_task, '.')) {
                     $t = explode('.', $this->_task);
                     $listing->setTask($t[0]);
                 } else {
                     $listing->setTask($this->_task);
                 }
             } else {
                 $listing->setTask($this->_task);
             }
             return $listing->execute();
         } else {
             Sobi::Error($this->name(), SPLang::e('SUCH_TASK_NOT_FOUND Wrong class definition', SPRequest::task()), SPC::NOTICE, 404, __LINE__, __FILE__);
         }
     } else {
         /* case parent didn't registered this task, it was an error */
         if (!parent::execute() && $this->name() == __CLASS__) {
             Sobi::Error($this->name(), SPLang::e('SUCH_TASK_NOT_FOUND', SPRequest::task()), SPC::NOTICE, 404, __LINE__, __FILE__);
         }
     }
 }
Ejemplo n.º 13
0
 /**
  */
 public function execute()
 {
     /* parent class executes the plugins */
     SPRequest::set('task', $this->_type . '.' . $this->_task);
     switch ($this->_task) {
         case 'front':
             $this->getSections();
             /** @var $view SPAdmPanelView */
             $view = SPFactory::View('front');
             /* load template config */
             //				$this->tplCfg( 'front' );
             //				$view->setConfig( $this->_tCfg, 'general' );
             $view->determineTemplate('front', SPC::DEFAULT_TEMPLATE);
             $view->assign($this->_sections, 'sections');
             $view->display();
             break;
         default:
             /* case parents or plugin didn't registered this task, it was an error */
             if (!parent::execute()) {
                 Sobi::Error($this->name(), SPLang::e('SUCH_TASK_NOT_FOUND', SPRequest::task()), SPC::NOTICE, 404, __LINE__, __FILE__);
             }
             break;
     }
 }
Ejemplo n.º 14
0
 protected function view()
 {
     /* determine template package */
     $tplPackage = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE);
     Sobi::ReturnPoint();
     $this->_task = 'user';
     if (!$this->_model) {
         $this->setModel('section');
         $this->_model->init(Sobi::Section());
     }
     $this->visible();
     /* load template config */
     $this->template();
     $this->tplCfg($tplPackage);
     /* get limits - if defined in template config - otherwise from the section config */
     $eLimit = $this->tKey($this->template, 'entries_limit', Sobi::Cfg('list.entries_limit', 2));
     $eInLine = $this->tKey($this->template, 'entries_in_line', Sobi::Cfg('list.entries_in_line', 2));
     $url = array('sid' => SPRequest::sid(), 'task' => 'list.user');
     if (SPRequest::int('uid')) {
         $url['uid'] = SPRequest::int('uid');
         $this->uid = (int) SPRequest::int('uid');
     } else {
         $this->uid = (int) Sobi::My('id');
     }
     $this->user = SPJoomlaUser::getBaseData((int) $this->uid);
     if (!$this->user) {
         throw new SPException(SPLang::e('UNAUTHORIZED_ACCESS'));
     }
     /* get the site to display */
     $site = SPRequest::int('site', 1);
     $eLimStart = ($site - 1) * $eLimit;
     $eOrder = $this->parseOrdering('entries', 'eorder', $this->tKey($this->template, 'entries_ordering', Sobi::Cfg('list.entries_ordering', 'name.asc')));
     $eCount = count($this->getEntries($eOrder, 0, 0, true, array('spo.owner' => $this->uid), true, Sobi::Section()));
     $entries = $this->getEntries($eOrder, $eLimit, $eLimStart, true, array('spo.owner' => $this->uid), true, Sobi::Section());
     //		$eCount = count( $this->_getEntries( 0, 0, true ) );
     //		$entries = $this->_getEntries( $eLimit, $site );
     $pn = SPFactory::Instance('helpers.pagenav_' . $this->tKey($this->template, 'template_type', 'xslt'), $eLimit, $eCount, $site, $url);
     if (SPRequest::int('site', 0)) {
         $url['site'] = SPRequest::int('site', 0);
     }
     SPFactory::header()->addCanonical(Sobi::Url($url, true, true, true));
     /* handle meta data */
     SPFactory::header()->objMeta($this->_model);
     SPFactory::mainframe()->addToPathway(Sobi::Txt('UL.PATH_TITLE', array('username' => $this->user->username, 'user' => $this->user->name)), Sobi::Url('current'));
     SPFactory::header()->addTitle(Sobi::Txt('UL.TITLE', array('username' => $this->user->username, 'user' => $this->user->name, 'section' => $this->_model->get('name'))), array(ceil($eCount / $eLimit), $site));
     /* add pathway */
     /* get view class */
     $view = SPFactory::View('listing');
     $view->assign($eLimit, '$eLimit');
     $view->assign($eLimStart, '$eLimStart');
     $view->assign($eCount, '$eCount');
     $view->assign($eInLine, '$eInLine');
     $view->assign($this->_task, 'task');
     $view->assign($this->_model, 'section');
     $view->setConfig($this->_tCfg, $this->template);
     $view->setTemplate($tplPackage . '.' . $this->templateType . '.' . $this->template);
     $view->assign($pn->get(), 'navigation');
     $view->assign(SPFactory::user()->getCurrent(), 'visitor');
     $view->assign($entries, 'entries');
     Sobi::Trigger('UserListing', 'View', array(&$view));
     $view->display();
 }
Ejemplo n.º 15
0
 protected function fetchData($data)
 {
     if (is_array($data) && count($data)) {
         $selected = array();
         foreach ($data as $opt) {
             /* check if such option exist at all */
             if (!isset($this->optionsById[$opt])) {
                 throw new SPException(SPLang::e('FIELD_NO_SUCH_OPT', $opt, $this->name));
             }
             $selected[] = preg_replace('/^[a-z0-9]\\.\\-\\_/ei', null, $opt);
         }
         return $selected;
     } else {
         return array();
     }
 }
Ejemplo n.º 16
0
 /**
  *
  */
 public function displayForm()
 {
     Sobi::Trigger('Display', $this->name(), array(&$this));
     $action = $this->key('action');
     echo '<div class="SobiPro" id="SobiPro">' . "\n";
     if ($this->get('_compatibility')) {
         echo SPFactory::AdmToolbar()->render();
         echo $this->legacyMessages();
     }
     echo $action ? "\n<form action=\"{$action}\" method=\"post\" name=\"adminForm\" id=\"SPAdminForm\" enctype=\"multipart/form-data\" accept-charset=\"utf-8\" >\n" : null;
     foreach ($this->_templates as $tpl) {
         $template = SPLoader::path($tpl, 'adm.template');
         if (!$template) {
             $tpl = SPLoader::translatePath($tpl, 'adm.template', false);
             Sobi::Error($this->name(), SPLang::e('CANNOT_LOAD_TEMPLATE_AT', $tpl), SPC::ERROR, 500, __LINE__, __FILE__);
         } else {
             include $template;
         }
     }
     if (count($this->_hidden)) {
         $this->_hidden[SPFactory::mainframe()->token()] = 1;
         $prefix = null;
         if (!$this->get('_compatibility')) {
             $prefix = 'SP_';
         }
         foreach ($this->_hidden as $name => $value) {
             echo "\n<input type=\"hidden\" name=\"{$name}\" id=\"{$prefix}{$name}\" value=\"{$value}\"/>";
         }
     }
     echo $action ? "\n</form>\n" : null;
     echo '</div>';
     Sobi::Trigger('AfterDisplay', $this->name());
 }
Ejemplo n.º 17
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();
     }
 }
Ejemplo n.º 18
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;
 }
Ejemplo n.º 19
0
 /**
  *
  */
 private function mimeFromExt()
 {
     $ext = SPFs::getExt($this->_path);
     if (!count(self::$_exts)) {
         self::$_exts = SPLoader::loadIniFile('etc.mime', false);
     }
     if (!isset(self::$_exts[$ext])) {
         Sobi::Error('FileInfo', SPLang::e('Cannot determine the right file type from extension'), SPC::WARNING, 0);
     } else {
         $this->_mime = self::$_exts[$ext];
     }
 }
Ejemplo n.º 20
0
 protected function save()
 {
     if (!SPFactory::mainframe()->checkToken()) {
         Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__);
     }
     $id = SPRequest::cmd('filter_id');
     if ($id) {
         $this->validate('field.filter', 'filter');
         $filters = $this->getFilters();
         $name = SPRequest::string('filter_name', 'Filter Name');
         $msg = str_replace(array("\n", "\t", "\r"), null, SPLang::clean(SPRequest::string('filter_message', 'The data entered in the $field field contains not allowed characters')));
         $regex = SPLang::clean(SPRequest::raw('filter_regex', '/^[\\.*]+$/'));
         $regex = str_replace('[:apostrophes:]', '\\"' . "\\'", $regex);
         $regex = base64_encode(str_replace(array("\n", "\t", "\r"), null, $regex));
         $custom = 'custom';
         if (isset($filters[$id]) && !strlen($filters[$id]['options'])) {
             $regex = $filters[$id]['params'];
             $custom = null;
         }
         $filters[$id] = array('params' => $regex, 'key' => $id, 'value' => $name, 'description' => $msg, 'options' => $custom);
         SPFactory::registry()->saveDBSection($filters, 'fields_filter');
         $this->response(Sobi::Url('filter'), Sobi::Txt('FLR.MSG_FILTER_SAVED'), false, 'success');
     } else {
         $this->response(Sobi::Url('filter'), SPLang::e('FILTER_NOT_FOUND'), true, SPC::ERROR_MSG);
     }
 }
Ejemplo n.º 21
0
 public function save(&$attr)
 {
     static $lang = null;
     static $defLang = null;
     if (!$lang) {
         $lang = Sobi::Lang();
         $defLang = Sobi::DefLang();
     }
     $file = SPRequest::file('spfieldsopts', 'tmp_name');
     if ($file) {
         $data = parse_ini_file($file, true);
     } elseif (is_string($attr['options'])) {
         $data = parse_ini_string($attr['options'], true);
     } else {
         $data = null;
     }
     $options = $this->parseOptsFile($data);
     if (!count($options) && count($attr['options'])) {
         $p = 0;
         $hold = array();
         foreach ($attr['options'] as $o) {
             if (is_numeric($o['id'])) {
                 $o['id'] = $this->nid . '_' . $o['id'];
             }
             if (isset($o['id'])) {
                 $i = 0;
                 $oid = $o['id'];
                 while (isset($hold[$oid])) {
                     $oid = $o['id'] . '_' . ++$i;
                 }
                 $options[] = array('id' => $oid, 'name' => $o['name'], 'parent' => null, 'position' => ++$p);
                 $hold[$oid] = $oid;
             }
         }
     }
     if (count($options)) {
         unset($attr['options']);
         $optionsArr = array();
         $labelsArr = array();
         $defLabelsArr = array();
         $optsIds = array();
         foreach ($options as $i => $option) {
             /* check for doubles */
             foreach ($options as $pos => $opt) {
                 if ($i == $pos) {
                     continue;
                 }
                 if ($option['id'] == $opt['id']) {
                     $option['id'] = $option['id'] . '_' . substr((string) microtime(), 2, 8) . rand(1, 100);
                     SPFactory::message()->warning('FIELD_WARN_DUPLICATE_OPT_ID');
                 }
             }
             $optionsArr[] = array('fid' => $this->id, 'optValue' => $option['id'], 'optPos' => $option['position'], 'optParent' => $option['parent']);
             $defLabelsArr[] = array('sKey' => $option['id'], 'sValue' => $option['name'], 'language' => $defLang, 'oType' => 'field_option', 'fid' => $this->id);
             $labelsArr[] = array('sKey' => $option['id'], 'sValue' => $option['name'], 'language' => $lang, 'oType' => 'field_option', 'fid' => $this->id);
             $optsIds[] = $option['id'];
         }
         /* @var SPdb $db */
         $db =& SPFactory::db();
         /* try to delete the existing labels */
         try {
             $db->delete('spdb_field_option', array('fid' => $this->id));
             $db->delete('spdb_language', array('oType' => 'field_option', 'fid' => $this->id, '!sKey' => $optsIds));
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('CANNOT_DELETE_SELECTED_OPTIONS', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
         /* insert new values */
         try {
             $db->insertArray('spdb_field_option', $optionsArr);
             $db->insertArray('spdb_language', $labelsArr, true);
             if ($defLang != $lang) {
                 $db->insertArray('spdb_language', $defLabelsArr, false, true);
             }
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('CANNOT_STORE_FIELD_OPTIONS_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
     }
     if (!isset($attr['params'])) {
         $attr['params'] = array();
     }
     $myAttr = $this->getAttr();
     $properties = array();
     if (count($myAttr)) {
         foreach ($myAttr as $property) {
             $properties[$property] = isset($attr[$property]) ? $attr[$property] : null;
         }
     }
     $attr['params'] = $properties;
     $this->sets['field.options'] = SPFactory::Instance('types.array')->toINIString($data);
 }
Ejemplo n.º 22
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));
 }
Ejemplo n.º 23
0
 /**
  *
  * @param mixed $attr
  * @param int $index
  * @return mixed
  */
 public function &get($attr, $index = -1)
 {
     $r = null;
     if (strstr($attr, '.')) {
         $properties = explode('.', $attr);
     } else {
         $properties[0] = $attr;
     }
     if (isset($this->_attr[$properties[0]])) {
         $var = null;
         /* if array field */
         if ($index > -1) {
             if (is_array($this->_attr[$properties[0]]) && isset($this->_attr[$properties[0]][trim($index)])) {
                 $var = $this->_attr[$properties[0]][trim($index)];
             } else {
                 Sobi::Error($this->name(), SPLang::e('ATTR_DOES_NOT_EXISTS', $attr), SPC::NOTICE, 0, __LINE__, __FILE__);
             }
         } else {
             $var = $this->_attr[$properties[0]];
         }
         /* remove first field of properties */
         array_shift($properties);
         /* if there are still fields in array, accessing object attribute or array field */
         if (is_array($properties) && count($properties)) {
             foreach ($properties as $property) {
                 $property = trim($property);
                 /* it has to be SPObject subclass to access the attribute */
                 if (method_exists($var, 'has') && $var->has($property)) {
                     if (method_exists($var, 'get')) {
                         $var = $var->get($property);
                     } else {
                         /*@TODO need to create error object */
                         $r = '';
                         return $r;
                     }
                 } elseif (is_array($var)) {
                     $var = $var[$property];
                 } else {
                     /* nothing to show */
                     Sobi::Error($this->name(), SPLang::e('NO_PROPERTY_TO_SHOW', $attr), SPC::NOTICE, 0, __LINE__, __FILE__);
                     /*@TODO need to create error object */
                     $r = '';
                     return $r;
                 }
             }
         }
         $r = $var;
     } else {
         $r = null;
     }
     $r = is_string($r) ? Sobi::Clean($r) : $r;
     return $r;
 }
Ejemplo n.º 24
0
 private function getNews()
 {
     $out = array();
     $path = SPLoader::path('etc.news', 'front', false, 'xml');
     if (SPFs::exists($path) && time() - filemtime($path) < 60 * 60 * 12) {
         $content = SPFs::read(SPLoader::path('etc.news', 'front', false, 'xml'));
     } else {
         try {
             $connection = SPFactory::Instance('services.remote');
             $news = 'http://rss.sigsiu.net';
             $connection->setOptions(array('url' => $news, 'connecttimeout' => 10, 'header' => false, 'returntransfer' => true));
             $file = SPFactory::Instance('base.fs.file', $path);
             $content = $connection->exec();
             $cinf = $connection->info();
             if (isset($cinf['http_code']) && $cinf['http_code'] != 200) {
                 return Sobi::Error('about', sprintf('CANNOT_GET_NEWS', $news, $cinf['http_code']), SPC::WARNING, 0, __LINE__, __FILE__);
             }
             $file->content($content);
             $file->save();
         } catch (SPException $x) {
             return Sobi::Error('about', SPLang::e('CANNOT_LOAD_NEWS', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
     }
     try {
         if (strlen($content)) {
             $news = new DOMXPath(DOMDocument::loadXML($content));
             $atom = false;
             if ($atom) {
                 //Atom
                 $news->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
                 $out['title'] = $news->query('/atom:feed/atom:title')->item(0)->nodeValue;
                 $items = $news->query('/atom:feed/atom:entry[*]');
                 $c = 5;
                 $open = false;
                 foreach ($items as $item) {
                     $date = $item->getElementsByTagName('updated')->item(0)->nodeValue;
                     if (!$open && time() - strtotime($date) < 60 * 60 * 24) {
                         $open = true;
                     }
                     $feed = array('url' => $item->getElementsByTagName('link')->item(0)->nodeValue, 'title' => $item->getElementsByTagName('title')->item(0)->nodeValue, 'content' => $item->getElementsByTagName('content')->item(0)->nodeValue);
                     if (!$c--) {
                         break;
                     }
                     $out['feeds'][] = $feed;
                 }
             } else {
                 //RSS
                 $out['title'] = $news->query('/rss/channel/title')->item(0)->nodeValue;
                 $items = $news->query('/rss/channel/item[*]');
                 $c = 5;
                 $open = false;
                 foreach ($items as $item) {
                     $date = $item->getElementsByTagName('pubDate')->item(0)->nodeValue;
                     if (!$open && time() - strtotime($date) < 60 * 60 * 24) {
                         $open = true;
                     }
                     $feed = array('url' => $item->getElementsByTagName('link')->item(0)->nodeValue, 'title' => $item->getElementsByTagName('title')->item(0)->nodeValue, 'content' => $item->getElementsByTagName('description')->item(0)->nodeValue, 'image' => $item->getElementsByTagName('enclosure')->item(0)->attributes->getNamedItem('url')->nodeValue);
                     if (!$c--) {
                         break;
                     }
                     $out['feeds'][] = $feed;
                 }
             }
         }
         if ($open) {
             SPFactory::header()->addJsCode('SobiPro.jQuery( document ).ready( function () { SobiPro.jQuery( \'#SobiProNews\' ).trigger(\'click\'); } );');
         }
     } catch (DOMException $x) {
         return Sobi::Error('about', SPLang::e('CANNOT_LOAD_NEWS', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     return $out;
 }
Ejemplo n.º 25
0
 public function searchData($request, $section)
 {
     if ($this->dependency) {
         $path = json_decode(Sobi::Clean(SPRequest::string($this->nid . '_path')), true);
         if (count($path)) {
             $request = array_pop($path);
         }
     }
     $sids = array();
     /* check if there was something to search for */
     if (is_array($request) && count($request) || is_string($request) && strlen($request)) {
         /** @var SPDb $db */
         $db = SPFactory::db();
         try {
             /* if we are searching for multiple options
              * and the field contains 'predefined_multi_data_multi_choice'
              * - we have to find entries matches all these options */
             if (is_array($request) && $this->multi) {
                 foreach ($request as $opt) {
                     $db->select('sid', 'spdb_field_option_selected', array('copy' => '0', 'fid' => $this->fid, 'optValue' => $opt));
                     if (!isset($results)) {
                         $results = $db->loadResultArray();
                     } else {
                         $cids = $db->loadResultArray();
                         $results = array_intersect($results, $cids);
                     }
                 }
                 $sids = $results;
             } else {
                 $db->select('sid', 'spdb_field_option_selected', array('copy' => '0', 'fid' => $this->fid, 'optValue' => $request));
                 $sids = $db->loadResultArray();
             }
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('CANNOT_SEARCH_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
     }
     return $sids;
 }
Ejemplo n.º 26
0
 /**
  * Proxy pattern
  *
  * @param string $method
  * @param array $args
  * @throws SPException
  * @return mixed
  */
 public function __call($method, $args)
 {
     if ($this->db && method_exists($this->db, $method)) {
         $Args = array();
         // http://www.php.net/manual/en/function.call-user-func-array.php#91503
         foreach ($args as $k => &$arg) {
             $Args[$k] =& $arg;
         }
         return call_user_func_array(array($this->db, $method), $Args);
     } else {
         throw new SPException(SPLang::e('CALL_TO_UNDEFINED_CLASS_METHOD', get_class($this->_type), $method));
     }
 }
Ejemplo n.º 27
0
 private function dir($file)
 {
     $file = explode('.', $file);
     if (strstr($file[0], 'cms:')) {
         $file[0] = str_replace('cms:', null, $file[0]);
         $file = SPFactory::mainframe()->path(implode('.', $file));
         $file = SPLoader::dirPath($file, 'root', true);
     } else {
         $file = SPLoader::dirPath('usr.templates.' . implode('.', $file), 'front', true);
     }
     if (!$file) {
         $file = SPLoader::path('usr.templates.' . implode('.', $file), 'front', false);
         Sobi::Error($this->name(), SPLang::e('FILE_NOT_FOUND', $file), SPC::WARNING, 404, __LINE__, __FILE__);
     }
     return $file;
 }
Ejemplo n.º 28
0
 /**
  * @param $entry
  * @param $request
  * @param $files
  * @return SPdb
  * @throws SPException
  */
 protected function storeData(&$entry, $request, $files)
 {
     /* @var SPdb $db */
     $db =& SPFactory::db();
     $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 */
     /* collect the needed params */
     $save = count($files) ? SPConfig::serialize($files) : null;
     $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['baseData'] = $db->escape($save);
     $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 {
         $db->insertUpdate('spdb_field_data', $params);
         return $db;
     } catch (SPException $x) {
         Sobi::Error($this->name(), SPLang::e('CANNOT_SAVE_FIELDS_DATA_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         return $db;
     }
     return $db;
 }
Ejemplo n.º 29
0
 public function connect()
 {
     if ($this->definition instanceof DOMDocument && $this->xGetString('url')) {
         $connection = SPFactory::Instance('services.remote');
         $ssl = $connection->certificate($this->xGetString('url'));
         if (isset($ssl['err'])) {
             throw new SPException($ssl['msg']);
         }
         if ($ssl['serialNumber'] != $this->xGetString('certificate/serialnumber')) {
             throw new SPException(SPLang::e('SSL validation error: stored serial number is %s but the serial number for the repository at %s has the number %s.', $this->xGetString('certificate/serialnumber'), $this->xGetString('url'), $ssl['serialNumber']));
         }
         // for some reason on some servers the hash is being indeed modified
         // although it has been correctly transferred
         // it seems that it is depend on the protocol used (TSL/SSL)
         //			if ( $ssl[ 'hash' ] != $this->xGetString( 'certificate/hash' ) ) {
         //				throw new SPException(
         //					SPLang::e(
         //						'SSL validation error: stored hash does not accords the hash for the repository at %s. %s != %s',
         //						$this->xGetString( 'url' ), $ssl[ 'hash' ], $this->xGetString( 'certificate/hash' )
         //					)
         //				);
         //			}
         if ($ssl['validTo'] < time()) {
             throw new SPException(SPLang::e('SSL validation error: SSL certificate for %s is expired.', $this->xGetString('url')));
         }
         $this->_server = SPFactory::Instance('services.soap', null, array('location' => $this->xGetString('url')));
     } else {
         throw new SPException(SPLang::e('No repository definition file at %s or the definition is invalid.', $this->xmlFile));
     }
 }
Ejemplo n.º 30
0
 public function validate()
 {
     $type = $this->type == 'SobiProApp' ? 'application' : $this->type;
     $schemaDef = SPLoader::path('lib.services.installers.schemas.' . $type, 'front', false, 'xsd');
     if (!SPFs::exists($schemaDef) || time() - filemtime($schemaDef) > 60 * 60 * 24 * 7) {
         $connection = SPFactory::Instance('services.remote');
         $def = "https://xml.sigsiu.net/SobiPro/{$type}.xsd";
         $connection->setOptions(array('url' => $def, 'connecttimeout' => 10, 'header' => false, 'returntransfer' => true, 'ssl_verifypeer' => false, 'ssl_verifyhost' => 2));
         $schema =& SPFactory::Instance('base.fs.file', SPLoader::path('lib.services.installers.schemas.' . $type, 'front', false, 'xsd'));
         $file = $connection->exec();
         if (!strlen($file)) {
             throw new SPException(SPLang::e('CANNOT_ACCESS_SCHEMA_DEF', $def));
         }
         $schema->content($file);
         $schema->save();
         $schemaDef = $schema->filename();
     }
     if (!$this->definition->schemaValidate($schemaDef)) {
         throw new SPException(SPLang::e('CANNOT_VALIDATE_SCHEMA_DEF_AT', str_replace(SOBI_ROOT . DS, null, $this->xmlFile), $def));
     }
 }