Example #1
0
 private function limits($selected)
 {
     $f = SPConfig::fields($this->settings()->get('section'), array('chbxgroup', 'select', 'radio'));
     $fields = array('' => null);
     if (count($f)) {
         foreach ($f as $id => $type) {
             $labels = SPFactory::db()->select(array('sValue', 'language', 'sKey'), 'spdb_language', array('fid' => $id, 'oType' => 'field_option'))->loadAssocList();
             /** @var SPField $field */
             $field = SPFactory::Model('field');
             $field->init($id)->loadType();
             $options = $field->get('options');
             if (count($options)) {
                 foreach ($options as $value) {
                     $label = $value['label'];
                     foreach ($labels as $l) {
                         if ($l['sKey'] == $value['label']) {
                             $label = $l['sValue'];
                         }
                     }
                     if (isset($value['options'])) {
                         $fields[$type][$id . '::group::' . $value['id']] = '<b>' . $label . '</b>';
                         foreach ($value['options'] as $subOption) {
                             $fields[$type][$id . '::' . $subOption['id']] = $label . ' &gt; ' . $subOption['label'];
                         }
                     } else {
                         $fields[$type][$id . '::' . $value['id']] = $label;
                     }
                 }
             }
         }
     }
     return SPHtml_Input::select('jform[params][spLimit]', $fields, $selected, false, array('style' => 'width: 300px'));
 }
Example #2
0
 private function load($task)
 {
     $db =& SPFactory::db();
     $adm = defined('SOBIPRO_ADM') ? 'adm.' : null;
     $cond = array($adm . '*', $adm . $task);
     if (strstr($task, '.')) {
         $t = explode('.', $task);
         $cond[] = $adm . $t[0] . '.*';
         $task = $t[0] . '.' . $t[1];
     }
     $this->_actions[$task] = null;
     try {
         $pids = $db->select('pid', 'spdb_plugin_task', array('onAction' => $cond))->loadResultArray();
     } catch (SPException $x) {
         Sobi::Error('Plugins', $x->getMessage(), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     if (!count($pids)) {
         $this->_actions[$task] = array();
     }
     // get section depend apps
     if (Sobi::Section() && count($pids)) {
         try {
             $this->_actions[$task] = $db->select('pid', 'spdb_plugin_section', array('section' => Sobi::Section(), 'enabled' => 1, 'pid' => $pids))->loadResultArray();
         } catch (SPException $x) {
             Sobi::Error('Plugins', $x->getMessage(), SPC::WARNING, 0, __LINE__, __FILE__);
         }
     } elseif (!(SPRequest::sid() || SPRequest::int('pid'))) {
         $this->_actions[$task] = $pids;
     }
     // here is a special exception for the custom listings
     // it can be l.alpha or list.alpha or listing.alpha
     if (preg_match('/^list\\..*/', $task) || preg_match('/^l\\..*/', $task)) {
         $this->_actions['listing' . '.' . $t[1]] = $pids;
     }
 }
Example #3
0
 protected function validateData($cacheId)
 {
     $sids = SPFactory::db()->select('sid', 'spdb_view_cache_relation', array('cid' => $cacheId))->loadResultArray();
     if ($sids && count($sids)) {
         $this->loadNonStaticData($sids);
         $this->validateNodes();
     }
 }
Example #4
0
 public function execute()
 {
     $method = explode('.', $this->_task);
     $this->nid = 'field_' . $method[0];
     $method = 'Proxy' . ucfirst($method[1]);
     $this->fid = SPFactory::db()->select('fid', 'spdb_field', array('nid' => $this->nid, 'section' => Sobi::Section()))->loadResult();
     $this->field = SPFactory::Model('field');
     $this->field->init($this->fid);
     $this->field->{$method}();
     return true;
 }
Example #5
0
 /**
  * Return min or recommend Joomla! version
  * @param $recommended
  * @return array
  */
 public static function minCmsVersion($recommended = false)
 {
     $updater = JUpdater::getInstance();
     $updater->findUpdates(700, 0);
     $version = SPFactory::db()->select('version', '#__updates', array('extension_id' => 700))->loadResult();
     $recommendedVersion = array('major' => 3, 'minor' => 2, 'build' => 3);
     if ($version) {
         $version = explode('.', $version);
         $recommendedVersion = array('major' => $version[0], 'minor' => $version[1], 'build' => $version[2]);
     }
     return $recommended ? $recommendedVersion : array('major' => 3, 'minor' => 2, 'build' => 0);
 }
Example #6
0
 public function getRevision($rev)
 {
     if (Sobi::Cfg('entry.versioning', true)) {
         $log = (array) SPFactory::db()->select('*', 'spdb_history', array('revision' => $rev))->loadObject('revision');
         if (count($log)) {
             $log['changes'] = SPConfig::unserialize($log['changes']);
         }
         return $log;
     } else {
         return array();
     }
 }
Example #7
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;
 }
Example #8
0
 public function remove($def)
 {
     $eid = $def->getElementsByTagName('id')->item(0)->nodeValue;
     $name = $def->getElementsByTagName('name')->item(0)->nodeValue;
     $type = $def->getElementsByTagName('type')->item(0)->nodeValue;
     $id = SPFactory::db()->select('extension_id', '#__extensions', array('type' => $type, 'element' => $eid))->loadResult();
     jimport('joomla.installer.installer');
     if (JInstaller::getInstance()->uninstall($type, $id)) {
         SPFactory::db()->delete('spdb_plugins', array('pid' => $eid, 'type' => $type), 1);
         return Sobi::Txt('CMS_EXT_REMOVED', $name);
     }
     return array('msg' => Sobi::Txt('CMS_EXT_NOT_REMOVED', $name), 'msgtype' => 'error');
 }
Example #9
0
 /**
  */
 private function getSections()
 {
     try {
         $sections = SPFactory::db()->select('*', 'spdb_object', array('oType' => 'section'), 'id')->loadObjectList();
     } catch (SPException $x) {
         Sobi::Error($this->name(), SPLang::e('CANNOT_GET_SECTIONS_LIST', $x->getMessage()), SPC::WARNING, 500, __LINE__, __FILE__);
     }
     if (count($sections)) {
         foreach ($sections as $section) {
             if (Sobi::Can('section', 'access', $section->id, 'valid')) {
                 $s = SPFactory::Section($section->id);
                 $s->extend($section);
                 $this->_sections[] = $s;
             }
         }
         Sobi::Trigger($this->name(), __FUNCTION__, array(&$this->_sections));
     }
 }
Example #10
0
 public function execute($argv)
 {
     Sobi::Initialise();
     $continue = $this->parseParameters($argv);
     if ($continue) {
         if (!$this->section) {
             $this->sections = SPFactory::db()->select('id', 'spdb_object', array('oType' => 'section', 'state' => '1', '@VALID' => SPFactory::db()->valid('validUntil', 'validSince')))->loadResultArray();
         } else {
             $this->sections = SPFactory::db()->select('id', 'spdb_object', array('id' => $this->section, 'oType' => 'section', 'state' => '1', '@VALID' => SPFactory::db()->valid('validUntil', 'validSince')))->loadResultArray();
         }
         if (!$this->liveURL || !preg_match('/http[s]?:\\/\\/.*/i', $this->liveURL)) {
             $this->out('[ERROR] A valid live URL address is required');
         }
         if (count($this->sections)) {
             $this->start = time();
             foreach ($this->sections as $sid) {
                 $this->crawlSobiSection($sid);
             }
         } else {
             $this->out('[ERROR] No valid sections found');
         }
     }
 }
Example #11
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 #12
0
 private function download()
 {
     //		$file = SPLoader::path( 'tmp.info', 'front', false, 'txt' );
     $cont = null;
     $settings = array();
     $settings['SobiPro'] = array('Version' => SPFactory::CmsHelper()->myVersion(true), 'Version_Num' => implode('.', SPFactory::CmsHelper()->myVersion()));
     $file = SPLoader::path('tmp.info', 'front', false, 'txt');
     //		if ( SPFs::exists( $file ) ) {
     //			$cont = SPFs::read( $file );
     //		}
     //		$cont = explode( "\n", $cont );
     //		if ( count( $cont ) ) {
     //			foreach ( $cont as $line ) {
     //				if ( strstr( $line, '=' ) ) {
     //					$line = explode( "=", $line );
     //					$line[ 1 ] = explode( ';', $line[ 1 ] );
     //					$settings[ $line[ 0 ] ] = array( 'key' => $line[ 0 ], 'response' => $line[ 1 ][ 0 ], 'status' => $line[ 1 ][ 1 ] );
     //				}
     //			}
     //		}
     $this->prepareStoredData($settings);
     $settings['env'] = array('PHP_OS' => PHP_OS, 'php_uname' => php_uname(), 'PHP_VERSION_ID' => PHP_VERSION_ID);
     $settings['ftp'] = $this->ftp();
     $settings['curl'] = $this->curlFull();
     $settings['exec']['response'] = $this->execResp();
     $settings['SOBI_SETTINGS'] = SPFactory::config()->getSettings();
     $c = SPFactory::db()->select('*', 'spdb_config')->loadObjectList();
     $sections = SPFactory::db()->select(array('nid', 'id'), 'spdb_object', array('oType' => 'section'))->loadAssocList('id');
     $as = array();
     foreach ($c as $key) {
         if ($key->section == 0 || !isset($sections[$key->section])) {
             continue;
         }
         $key->section = $sections[$key->section]['nid'];
         if (!isset($as[$key->section])) {
             $as[$key->section] = array();
         }
         if (!isset($as[$key->section][$key->cSection])) {
             $as[$key->section][$key->cSection] = array();
         }
         $_c = explode('_', $key->sKey);
         if ($_c[count($_c) - 1] == 'array') {
             $key->sValue = SPConfig::unserialize($key->sValue);
         }
         $as[$key->section][$key->cSection][$key->sKey] = $key->sValue;
     }
     $settings['SOBI_SETTINGS']['sections'] = $as;
     $apps = SPFactory::db()->select('*', 'spdb_plugins')->loadObjectList();
     foreach ($apps as $app) {
         $settings['Apps'][$app->pid] = get_object_vars($app);
     }
     $settings['SOBI_SETTINGS']['mail']['smtphost'] = $settings['SOBI_SETTINGS']['mail']['smtphost'] ? 'SET' : 0;
     $settings['SOBI_SETTINGS']['mail']['smtpuser'] = $settings['SOBI_SETTINGS']['mail']['smtpuser'] ? 'SET' : 0;
     $settings['SOBI_SETTINGS']['mail']['smtppass'] = $settings['SOBI_SETTINGS']['mail']['smtppass'] ? 'SET' : 0;
     $php = ini_get_all();
     unset($php['extension_dir']);
     unset($php['include_path']);
     unset($php['mysql.default_user']);
     unset($php['mysql.default_password']);
     unset($php['mysqli.default_pw']);
     unset($php['mysqli.default_user']);
     unset($php['open_basedir']);
     unset($php['pdo_mysql.default_socket']);
     unset($php['sendmail_path']);
     unset($php['session.name']);
     unset($php['session.save_path']);
     unset($php['soap.wsdl_cache_dir']);
     unset($php['upload_tmp_dir']);
     unset($php['doc_root']);
     unset($php['docref_ext']);
     unset($php['docref_root']);
     unset($php['mysql.default_socket']);
     $settings['PHP_SETTINGS'] = $php;
     $php = get_loaded_extensions();
     $settings['PHP_EXT'] = $php;
     $out = SPFactory::Instance('types.array');
     $data = $out->toXML($settings, 'settings');
     $data = str_replace(array(SOBI_ROOT, '></'), array('REMOVED', '>0</'), $data);
     $f = SPLang::nid($settings['SOBI_SETTINGS']['general']['site_name'] . '-' . date(DATE_RFC822));
     SPFactory::mainframe()->cleanBuffer();
     header('Cache-Control: no-cache, must-revalidate');
     header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
     header("Content-type: application/xml");
     header("Content-Disposition: attachment; filename=\"sobipro_system_{$f}.xml\"");
     header('Content-Length: ' . strlen($data));
     ob_clean();
     flush();
     echo $data;
     exit;
 }
Example #13
0
 protected function loadNonStaticData($objects)
 {
     $this->nonStaticData = SPFactory::db()->select(array('counter', 'sid'), 'spdb_counter', array('sid' => $objects))->loadAssocList('sid');
 }
Example #14
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;
 }
Example #15
0
 protected function getTemplates($type)
 {
     $templates = array();
     $templates[''] = Sobi::Txt('SELECT_TEMPLATE_OVERRIDE');
     $template = SPFactory::db()->select('sValue', 'spdb_config', array('section' => SPRequest::int('section'), 'sKey' => 'template', 'cSection' => 'section'))->loadResult();
     $templateDir = $this->templatePath($template);
     $this->listTemplates($templates, $templateDir, $type);
     return $templates;
 }
Example #16
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 #17
0
 protected function getEntries()
 {
     $entries = array();
     $popular = SPFactory::db()->select('id', 'spdb_object', array('oType' => 'entry'), 'counter.desc', 5)->loadResultArray();
     $entries['popular'] = $this->addEntries($popular);
     $latest = SPFactory::db()->select('id', 'spdb_object', array('oType' => 'entry'), 'createdTime.desc', 5)->loadResultArray();
     $entries['latest'] = $this->addEntries($latest);
     $unapproved = SPFactory::db()->select('id', 'spdb_object', array('oType' => 'entry', 'approved' => 0), 'createdTime.desc', 5)->loadResultArray();
     $entries['unapproved'] = $this->addEntries($unapproved);
     return $entries;
 }
Example #18
0
 protected function getSites()
 {
     return SPFactory::db()->select('url', self::DB_TABLE, array('state' => 0))->loadResultArray();
 }
Example #19
0
 /**
  * Save the config
  */
 protected function save($apply, $clone = false)
 {
     $sid = Sobi::Section();
     $this->authorise($sid);
     if ($sid) {
         $this->validate('config.general', array('task' => 'config.general', 'sid' => $sid));
     } else {
         $this->validate('config.global', array('task' => 'config.global'));
     }
     $fields = array();
     $section = false;
     $data = SPRequest::arr('spcfg', array());
     // strange thing =8-O
     if (!isset($data['alphamenu.extra_fields_array'])) {
         $data['alphamenu.extra_fields_array'] = array();
     }
     if (!isset($data['template.icon_fonts_arr'])) {
         $data['template.icon_fonts_arr'] = array();
     }
     foreach ($data as $k => $v) {
         if (is_string($v)) {
             $v = htmlspecialchars_decode($v);
         }
         //			$k = str_replace( array( 'spcfg_', '.' ), array( null, '_' ), $k );
         $k = str_replace('spcfg_', null, $k);
         $s = explode('.', $k);
         $s = $s[0];
         if (!isset($fields[$s])) {
             $fields[$s] = array();
         }
         $k = str_replace("{$s}.", null, $k);
         $c = explode('_', $k);
         if ($c[count($c) - 1] == 'array' && !is_array($v)) {
             if (!strstr($v, '|')) {
                 $v = explode(',', $v);
             } else {
                 $v = explode('|', $v);
             }
         }
         $fields[$s][$k] = $v;
         if (preg_match('/^section.*/', $k)) {
             $section = true;
         }
     }
     $values = array();
     if (count($fields)) {
         foreach ($fields as $sec => $keys) {
             if (count($keys)) {
                 foreach ($keys as $k => $v) {
                     $values[] = array('sKey' => $k, 'sValue' => $v, 'section' => Sobi::Section(), 'critical' => 0, 'cSection' => $sec);
                 }
             }
         }
     }
     if ($section) {
         /* @var $sec SPSection */
         $sec = SPFactory::Model('section');
         $sec->init(SPRequest::sid());
         $sec->getRequest('section');
         $sec->save(true);
     }
     Sobi::Trigger('SaveConfig', $this->name(), array(&$values));
     try {
         SPFactory::db()->insertArray('spdb_config', $values, true);
     } catch (SPException $x) {
         $this->response(Sobi::Back(), $x->getMessage(), false, SPC::ERROR_MSG);
     }
     if (!($section && !Sobi::Section())) {
         SPFactory::cache()->cleanAll();
     } else {
         SPFactory::cache()->cleanSection();
     }
     Sobi::Trigger('After', 'SaveConfig', array(&$values));
     $this->response(Sobi::Back(), Sobi::Txt('MSG.CONFIG_SAVED'), false, 'success');
 }
Example #20
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 #21
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;
 }
Example #22
0
 /**
  * @return SPDb
  */
 public function getDb()
 {
     return SPFactory::db();
 }
Example #23
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);
 }
Example #24
0
 /**
  * Translating language depend attributes of objects
  *
  * @param array $sids - array with ids of objects to translate
  * @param array $fields - (optional) array (or string) with properties names to translate. If not given, translates all
  * @param string $type - (optional) type of object (section, category, entry). If not given, translates all
  * @param string $lang - (optional) specific language. If not given, use currently set language
  * @param string $ident
  * @return array
  */
 public static function translateObject($sids, $fields = array(), $type = null, $lang = null, $ident = 'id')
 {
     /** @todo multiple attr does not work because the id is the object id */
     $fields = is_array($fields) ? $fields : (strlen($fields) ? array($fields) : null);
     $lang = $lang ? $lang : Sobi::Lang(false);
     // we don't need to specify the language as we want to have all of them and then order it right
     // when an object name has been entered in a particular language but this language isn't used later
     // we won't have any label for this certain object
     // Wed, Dec 18, 2013 09:57:04
     //$params = array( 'id' => $sids, 'language' => array( $lang, Sobi::DefLang(), 'en-GB' ) );
     $params = array($ident => $sids);
     $result = array();
     if ($type) {
         $params['oType'] = $type;
     }
     if (in_array('alias', $fields)) {
         $fields[] = 'nid';
     }
     if ($fields && count($fields)) {
         $params['sKey'] = $fields;
     }
     try {
         $labels = SPFactory::db()->select($ident . ' AS id, sKey AS label, sValue AS value, language', 'spdb_language', $params, "FIELD( language, '{$lang}', '" . Sobi::DefLang() . "' )")->loadAssocList();
         if (count($labels)) {
             $aliases = array();
             if (in_array('alias', $fields)) {
                 $aliases = SPFactory::db()->select(array('nid', 'id'), 'spdb_object', array('id' => $sids))->loadAssocList('id');
             }
             foreach ($labels as $label) {
                 if ($label['label'] == 'nid') {
                     $result[$label['id']]['alias'] = $label['value'];
                 } else {
                     if (!isset($result[$label['id']]) || $label['language'] == Sobi::Lang()) {
                         $result[$label['id']] = $label;
                     }
                 }
                 if (in_array('nid', $fields)) {
                     if (!isset($result[$label['id']]['alias'])) {
                         $result[$label['id']]['alias'] = isset($aliases[$label['id']]) ? $aliases[$label['id']]['nid'] : null;
                     }
                 }
             }
         }
     } catch (SPError $x) {
         Sobi::Error('language', SPLang::e('CANNOT_TRANSLATE_OBJECT', $x->getMessage()), SPC::WARNING, 500, __LINE__, __CLASS__);
     }
     return $result;
 }
Example #25
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 #26
0
 public function delete()
 {
     /* @var SPdb $db */
     $db = SPFactory::db();
     try {
         $db->delete('spdb_field_option', array('fid' => $this->id));
     } catch (SPException $x) {
         Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
 }
Example #27
0
 /**
  * @return array
  */
 public function struct()
 {
     $baseData = $this->getRaw();
     $list = array();
     $struct = array();
     $order = SPFactory::cache()->getVar('order_' . $this->nid);
     if (!$order) {
         $order = SPFactory::db()->select('optValue', 'spdb_field_option', array('fid' => $this->id), 'optPos')->loadResultArray();
         SPFactory::cache()->addVar($order, 'order_' . $this->nid);
     }
     if (is_array($baseData) && count($baseData)) {
         $this->cssClass = strlen($this->cssClass) ? $this->cssClass : 'spFieldsData';
         $this->cssClass = $this->cssClass . ' ' . $this->nid;
         $this->cleanCss();
         foreach ($order as $opt) {
             if (isset($baseData[$opt])) {
                 $list[] = array('_tag' => 'li', '_value' => SPLang::clean($baseData[$opt]), '_class' => $opt);
             }
         }
         foreach ($this->options as $opt) {
             $struct[] = array('_complex' => 1, '_data' => $opt['label'], '_attributes' => array('selected' => isset($baseData[$opt['id']]) ? 'true' : 'false', 'id' => $opt['id'], 'position' => $opt['position']));
         }
         $data = array('ul' => array('_complex' => 1, '_data' => $list, '_attributes' => array('class' => $this->cssClass)));
     }
     if (count($list)) {
         return array('_complex' => 1, '_data' => $data, '_attributes' => array('lang' => $this->lang, 'class' => $this->cssClass), '_options' => $struct);
     }
 }
Example #28
0
 /**
  * Saves whole section in the db registry
  * @param array $values
  * @param string $section
  * @return void
  */
 public function saveDBSection($values, $section)
 {
     foreach ($values as $i => $value) {
         $value['section'] = $section;
         $value['params'] = isset($value['params']) ? $value['params'] : null;
         $value['description'] = isset($value['description']) ? $value['description'] : null;
         $value['options'] = isset($value['options']) ? $value['options'] : null;
         $values[$i] = $value;
     }
     Sobi::Trigger('Registry', 'SaveDb', array(&$values));
     try {
         SPFactory::db()->delete('spdb_registry', array('section' => $section));
         SPFactory::db()->insertArray('spdb_registry', $values);
     } catch (SPException $x) {
         Sobi::Error(__FUNCTION__, SPLang::e('Cannot save registry section. Db reports %s.', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
 }
Example #29
0
 public function getEntries($eLimit, $site, $ids = false)
 {
     $conditions = array();
     $entries = array();
     /* get the site to display */
     $eLimStart = ($site - 1) * $eLimit;
     if (isset($this->_letter[1]) && $this->_letter[1] == '-') {
         $this->_letter = "[{$this->_letter[0]}-{$this->_letter[2]}]";
     }
     $db = SPFactory::db();
     /*
      * Don't know exactly why but on Windows servers there seems to be some problem with unicode chars
      *     - strtolower/strtoupper is destroying these chars completely
      *     - MySQL seems to be suddenly case sensitive with non-latin chars so we need to ask both
      *
      * Wed, Apr 4, 2012: Apparently it's not only Windows related
      */
     if (!preg_match('/^[\\x20-\\x7f]*$/D', $this->_letter) && function_exists('mb_strtolower')) {
         // if we have multibyte string support - ask both cases ...
         $baseCondition = "REGEXP:^{$this->_letter}|^" . mb_strtoupper($this->_letter);
     } else {
         // if no unicode - great, it'll work.
         // if we don't have MB - shit happens
         $baseCondition = "REGEXP:^{$this->_letter}";
     }
     switch ($this->_fieldType) {
         case 'chbxgroup':
         case 'select':
         case 'multiselect':
             $eOrder = 'sValue';
             $table = $db->join(array(array('table' => 'spdb_field_option_selected', 'as' => 'opts'), array('table' => 'spdb_language', 'as' => 'lang', 'key' => array('opts.optValue', 'lang.sKey')), array('table' => 'spdb_object', 'as' => 'spo', 'key' => array('opts.sid', 'spo.id')), array('table' => 'spdb_relations', 'as' => 'sprl', 'key' => array('opts.sid', 'sprl.id'))));
             $oPrefix = 'spo.';
             $conditions['spo.oType'] = 'entry';
             $conditions['opts.fid'] = $this->_field;
             $conditions['lang.sValue'] = $baseCondition;
             break;
         default:
             $eOrder = 'baseData';
             $table = $db->join(array(array('table' => 'spdb_field', 'as' => 'fdef', 'key' => 'fid'), array('table' => 'spdb_field_data', 'as' => 'fdata', 'key' => 'fid'), array('table' => 'spdb_object', 'as' => 'spo', 'key' => array('fdata.sid', 'spo.id')), array('table' => 'spdb_relations', 'as' => 'sprl', 'key' => array('fdata.sid', 'sprl.id'))));
             $oPrefix = 'spo.';
             $conditions['spo.oType'] = 'entry';
             $conditions['fdef.fid'] = $this->_field;
             $conditions['fdata.baseData'] = $baseCondition;
             break;
     }
     $this->_field = $this->_field ? $this->_field : Sobi::Cfg('alphamenu.primary_field', SPFactory::config()->nameField()->get('id'));
     /* check user permissions for the visibility */
     if (Sobi::My('id')) {
         $this->userPermissionsQuery($conditions, $oPrefix);
     } else {
         $conditions = array_merge($conditions, array($oPrefix . 'state' => '1', '@VALID' => $db->valid($oPrefix . 'validUntil', $oPrefix . 'validSince')));
     }
     $conditions['sprl.copy'] = '0';
     try {
         $db->select($oPrefix . 'id', $table, $conditions, $eOrder, $eLimit, $eLimStart, true);
         $results = $db->loadResultArray();
     } catch (SPException $x) {
         Sobi::Error('AlphaListing', SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     if ($ids) {
         Sobi::SetUserData('currently-displayed-entries', $results);
         return $results;
     }
     if (count($results)) {
         foreach ($results as $i => $sid) {
             // it needs too much memory moving the object creation to the view
             //$entries[ $i ] = SPFactory::Entry( $sid );
             $entries[$i] = $sid;
         }
     }
     Sobi::Trigger($this->name(), 'AfterGetEntries', array(&$entries, false));
     return $entries;
 }
Example #30
-2
 protected function loadSection()
 {
     $sections = array();
     $sectionsOutput = array();
     try {
         $sections = SPFactory::db()->select('*', 'spdb_object', array('oType' => 'section'), 'id')->loadObjectList();
     } catch (SPException $x) {
         Sobi::Error($this->name(), $x->getMessage(), SPC::ERROR, 500, __LINE__, __FILE__);
     }
     if (count($sections)) {
         $sectionsOutput[] = Sobi::Txt('SOBI_SELECT_SECTION');
         foreach ($sections as $section) {
             if (Sobi::Can('section', 'access', 'valid', $section->id)) {
                 $s = new SPSection();
                 $s->extend($section);
                 $sectionsOutput[$s->get('id')] = $s->get('name');
             }
         }
     }
     $params = array('id' => 'SobiSection', 'class' => 'required');
     return SPHtml_Input::select('section', $sectionsOutput, self::$section, false, $params);
 }