/** * @param int $number * @param int $errCode * @param string $errStr * @param string $errFile * @param int $errLine * @param string $errSection * @param string $errContext * @param null $backtrace * @throws SPException * @return bool */ public static function storeError($number, $errCode, $errStr, $errFile, $errLine, $errSection, $errContext, $backtrace = null) { if (!self::$_cs && (self::$_trigger && $number < self::$_trigger)) { self::$_cs = true; throw new SPException($errStr); return false; } SPLoader::loadClass('base.factory'); SPLoader::loadClass('base.database'); SPLoader::loadClass('cms.base.database'); $uid = 0; // unset( $backtrace[ 2 ] ); // unset( $backtrace[ 1 ] ); // unset( $backtrace[ 0 ] ); $errContext = serialize($errContext); $backtrace = serialize($backtrace); if (class_exists('SPUser')) { $uid = SPUser::getCurrent()->get('id'); } $db = SPDb::getInstance(); $date = $db->now(); $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'unknown'; $reff = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'unknown'; $agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'unknown'; $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : 'unknown'; $errStr = $db->escape($errStr); $errSection = $db->escape($errSection); $errContext = $db->escape(base64_encode(gzcompress($errContext))); if (strlen($errContext) > 15000) { $errContext = 'Stack to large - skipping'; } $backtrace = $db->escape(base64_encode(gzcompress($backtrace))); $reff = $db->escape($reff); $agent = $db->escape($agent); $uri = $db->escape($uri); $number = (int) $number; $errCode = (int) $errCode; $errLine = (int) $errLine; // $is = ini_set( 'display_errors', 0 ); // @file_put_contents( SOBI_PATH.DS.'var'.DS.'log'.DS.'error.log', strip_tags( stripslashes( "\n=========\n[ {$date} ][ {$errsection}:{$errno} ][ {$errcode} ]\n{$errstr}\nIn: {$errfile}:{$errline}" ) ), SPC::FS_APP ); // ini_set( 'display_errors', $is ); try { $db->exec("INSERT INTO spdb_errors VALUES ( NULL, '{$date}', '{$number}', '{$errCode}', '{$errStr}', '{$errFile}', '{$errLine}', '{$errSection}', '{$uid}', '{$ip}', '{$reff}', '{$agent}', '{$uri}', '{$errContext}', '{$backtrace}' );"); } catch (SPException $x) { SPLoader::loadClass('base.mainframe'); SPLoader::loadClass('cms.base.mainframe'); SPFactory::mainframe()->runAway('Fatal error while inserting error message. ' . $x->getMessage(), 500); } self::$_cs = false; }
/** * Check access permissions * @return bool */ private function checkAccess() { $this->_user =& SPFactory::user(); /* authorise access permissions */ if (!$this->_user->can('panel')) { Sobi::Error('CoreCtrl', 'UNAUTHORIZED_ACCESS', SPC::ERROR, 403, __LINE__, __FILE__); exit; } /* authorise task permissions */ if (SPRequest::task()) { if (!$this->_user->can(SPRequest::task())) { Sobi::Error('CoreCtrl', 'UNAUTHORIZED_ACCESS', SPC::ERROR, 403, __LINE__, __FILE__); // Sobi::Error( 'CoreCtrl', SPLang::e( 'UNAUTHORIZED_ACCESS_TASK', SPRequest::task() ), SPC::ERROR, 403, __LINE__, __FILE__ ); exit; } } }
/** * Enter description here... * * @param unknown_type $row * @param unknown_type $id * @return unknown */ public static function checkedOut($row, $id = 'sid') { $state = $row->get('cout'); if ($state && $state != Sobi::My('id') && strtotime($row->get('coutTime')) > time()) { /* translate alternative text */ $user = SPUser::getInstance($state); $uname = $user->get('name'); $img = Sobi::Cfg('list_icons.checked_out'); $s = Sobi::Txt($row->get('oType') . '.checked_out'); $a = Sobi::Txt($row->get('oType') . '.checked_out_by', array('user' => $uname, 'time' => $row->get('coutTime'))); $r = SPTooltip::toolTip($a, $s, $img); } else { $sid = $row->get('id'); $r = "<input type=\"checkbox\" name=\"{$id}[]\" value=\"{$sid}\" onclick=\"SPCheckListElement( this )\" />"; } return $r; }
public function checkbox($cell) { /** First let's check if it is not checked out */ if (isset($cell['attributes']['checked-out-by']) && isset($cell['attributes']['checked-out-time']) && $cell['attributes']['checked-out-by'] && $cell['attributes']['checked-out-by'] != Sobi::My('id') && strtotime($cell['attributes']['checked-out-time']) > gmdate('U')) { if (isset($cell['attributes']['checked-out-ico']) && $cell['attributes']['checked-out-ico']) { $icon = $cell['attributes']['checked-out-ico']; } else { $icon = $this->_checkedOutIcon; } $user = SPUser::getInstance($cell['attributes']['checked-out-by']); $txt = Sobi::Txt('CHECKED_OUT', $user->get('name'), $cell['attributes']['checked-out-time']); $this->_out[] = '<a href="#" rel="sp-tooltip" data-original-title="' . $txt . '" class="checkedout">'; $this->_out[] = '<i class="icon-' . $icon . '"></i>'; $this->_out[] = '</a>'; return $cell; } elseif ($this->istSet($cell['attributes'], 'locked', true)) { $icon = $this->istSet($cell['attributes'], 'locked-icon') ? $cell['attributes']['locked-icon'] : $this->_checkedOutIcon; $text = $this->istSet($cell['attributes'], 'locked-text') ? $cell['attributes']['locked-text'] : $this->_checkedOutIcon; $this->_out[] = '<a href="#" rel="sp-tooltip" data-original-title="' . $text . '" class="checkedout">'; $this->_out[] = '<i class="icon-' . $icon . '"></i>'; $this->_out[] = '</a>'; return $cell; } $type = $this->istSet($cell['attributes'], 'input-type') ? $cell['attributes']['input-type'] : 'checkbox'; if (isset($cell['attributes']['rel']) && $cell['attributes']['rel']) { $this->_out[] = '<input type="' . $type . '" name="spToggle" value="1" rel="' . $cell['attributes']['rel'] . '"/>'; return $cell; } else { $multiple = $this->istSet($cell['attributes'], 'multiple', 'false') ? null : '[]'; $this->_out[] = '<input type="' . $type . '" name="' . $cell['attributes']['name'] . $multiple . '" value="' . $cell['content'] . '"/>'; return $cell; } }
protected function parseName($entry, $name, $pattern, $addExt = false) { $nameArray = explode('.', $name); $ext = strtolower(array_pop($nameArray)); $name = implode('.', $nameArray); $user = SPUser::getBaseData((int) $entry->get('owner')); // @todo change to the global method $placeHolders = array('/{id}/', '/{orgname}/', '/{entryname}/', '/{oid}/', '/{ownername}/', '/{uid}/', '/{username}/', '/{nid}/'); $replacements = array($entry->get('id'), $name, $entry->get('nid'), isset($user->id) ? $user->id : null, isset($user->name) ? SPLang::nid($user->name) : 'guest', Sobi::My('id'), SPLang::nid(Sobi::My('name')), $this->nid); $fileName = preg_replace($placeHolders, $replacements, $pattern); return $addExt ? $fileName . '.' . $ext : $fileName; }
public static function userGetter($name, $value, $params = null, $class = null, $format = '%user') { $params = self::checkArray($params); if (!isset($params['id'])) { $params['id'] = SPLang::nid($name); } if ($class) { $params['class'] = $class; } $user = null; $user = SPUser::getBaseData((int) $value); $userData = null; if ($user) { $replacements = array(); preg_match_all('/\\%[a-z]*/', $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 ($placeholders as $attribute) { if (isset($user->{$attribute})) { $format = str_replace('%' . $attribute, $user->{$attribute}, $format); } } $userData = $format; } } $params = self::params($params); $f = "\n"; $f .= '<div class="spOutput">'; $f .= "\n\t"; $f .= '<span ' . $params . '>' . $userData . '</span>'; $f .= "\n"; $f .= '</div>'; $f .= "\n"; Sobi::Trigger('Field', ucfirst(__FUNCTION__), array(&$f)); return "\n<!-- User Getter '{$name}' Output -->{$f}<!-- User Getter '{$name}' End -->\n\n"; }
/** */ protected function listSection() { $parentPath = $this->parentPath(SPRequest::sid()); $this->assign($parentPath, 'current_path'); $this->_plgSect = '_SectionListTemplate'; $c = $this->get('categories'); $categories = array(); $entries = array(); /* get users/authors data first */ $usersData = array(); if (count($c)) { foreach ($c as $cat) { $usersData[] = $cat->get('owner'); } reset($c); } $usersData = $this->userData($usersData); /* handle the categories */ if (count($c)) { foreach ($c as $cat) { $category = array(); /* data needed to display in the list */ $category['name'] = $cat->get('name'); $category['state'] = $cat->get('state'); $category['approved'] = $cat->get('approved'); if (isset($usersData[$cat->get('owner')])) { $uName = $usersData[$cat->get('owner')]->name; $uUrl = SPUser::userUrl($usersData[$cat->get('owner')]->id); $category['owner'] = "<a href=\"{$uUrl}\">{$uName}</a>"; } else { $category['owner'] = Sobi::Txt('GUEST'); } /* the rest - case someone need */ $category['position'] = $cat->get('position'); $category['createdTime'] = $cat->get('createdTime'); $category['cout'] = $cat->get('cout'); $category['coutTime'] = $cat->get('coutTime'); $category['id'] = $cat->get('id'); $category['validSince'] = $cat->get('validSince'); $category['validUntil'] = $cat->get('validUntil'); $category['description'] = $cat->get('description'); $category['icon'] = $cat->get('icon'); $category['introtext'] = $cat->get('introtext'); $category['parent'] = $cat->get('parent'); $category['confirmed'] = $cat->get('confirmed'); $category['counter'] = $cat->get('counter'); $category['nid'] = $cat->get('nid'); $category['metaDesc'] = $cat->get('metaDesc'); $category['metaKeys'] = $cat->get('metaKeys'); $category['metaAuthor'] = $cat->get('metaAuthor'); $category['metaRobots'] = $cat->get('metaRobots'); $category['ownerIP'] = $cat->get('ownerIP'); $category['updatedTime'] = $cat->get('updatedTime'); $category['updater'] = $cat->get('updater'); $category['updaterIP'] = $cat->get('updaterIP'); $category['version'] = $cat->get('version'); $category['object'] =& $cat; $categories[] = $category; } } /* re-assign the categories */ $this->assign($categories, 'categories'); /* handle the fields in this section for header */ $f = $this->get('fields'); $entriesOrdering = array(Sobi::Txt('ORDER_BY') => array(), 'e_sid.asc' => Sobi::Txt('EMN.ORDER_BY_ID_ASC'), 'e_sid.desc' => Sobi::Txt('EMN.ORDER_BY_ID_DESC'), $this->get('entries_field') . '.asc' => Sobi::Txt('EMN.ORDER_BY_NAME_ASC'), $this->get('entries_field') . '.desc' => Sobi::Txt('EMN.ORDER_BY_NAME_DESC'), 'state.asc' => Sobi::Txt('EMN.ORDER_BY_STATE_ASC'), 'state.desc' => Sobi::Txt('EMN.ORDER_BY_STATE_DESC'), 'createdTime.asc' => Sobi::Txt('EMN_ORDER_BY_CREATION_DATE_ASC'), 'createdTime.desc' => Sobi::Txt('EMN_ORDER_BY_CREATION_DATE_DESC'), 'updatedTime.asc' => Sobi::Txt('EMN_ORDER_BY_UPDATE_DATE_ASC'), 'updatedTime.desc' => Sobi::Txt('EMN_ORDER_BY_UPDATE_DATE_DESC'), 'approved.asc' => Sobi::Txt('EMN.ORDER_BY_APPROVAL_ASC'), 'approved.desc' => Sobi::Txt('EMN.ORDER_BY_APPROVAL_DESC')); if ($this->get('task') == 'view') { $entriesOrdering['position.asc'] = Sobi::Txt('EMN.ORDER_BY_ORDER_ASC'); $entriesOrdering['position.desc'] = Sobi::Txt('EMN.ORDER_BY_ORDER_DESC'); } $customFields = array(); $customHeader = array(); if (count($f)) { /* @var SPField $fit */ foreach ($f as $field) { $entriesOrdering[Sobi::Txt('EMN.ORDER_BY_FIELD')][$field->get('nid') . '.asc'] = '\'' . $field->get('name') . '\' ' . Sobi::Txt('EMN.ORDER_BY_FIELD_ASC'); $entriesOrdering[Sobi::Txt('EMN.ORDER_BY_FIELD')][$field->get('nid') . '.desc'] = '\'' . $field->get('name') . '\' ' . Sobi::Txt('EMN.ORDER_BY_FIELD_DESC'); $customFields[] = $field->get('nid'); $customHeader[] = array('content' => $field->get('name'), 'attributes' => array('type' => 'text')); } } $entriesOrdering['owner.desc'] = Sobi::Txt('EMN.ORDER_BY_OWNER'); $this->assign($customHeader, 'customHeader'); $this->assign($customFields, 'custom_fields'); $this->assign($entriesOrdering, 'entriesOrdering'); /* handle the entries */ $e = $this->get('entries'); if (count($e)) { /* get users/authors data first */ $usersData = array(); foreach ($e as $i => $sid) { $e[$i] = SPFactory::EntryRow($sid); $usersData[] = $e[$i]->get('owner'); } reset($e); $usersData = $this->userData($usersData); foreach ($e as $sentry) { /* @var SPEntryAdm $sentry */ $entry = array(); $entry['state'] = $sentry->get('state'); $entry['approved'] = $sentry->get('approved'); if (isset($usersData[$sentry->get('owner')])) { $uName = $usersData[$sentry->get('owner')]->name; $uUrl = SPUser::userUrl($usersData[$sentry->get('owner')]->id); $entry['owner'] = "<a href=\"{$uUrl}\">{$uName}</a>"; } else { $entry['owner'] = Sobi::Txt('GUEST'); } $catPosition = $sentry->getCategories(); if (SPRequest::sid() && isset($catPosition[SPRequest::sid()])) { $sentry->position = $catPosition[SPRequest::sid()]['position']; } /* the rest - case someone need */ $entry['position'] = $sentry->get('position'); $entry['createdTime'] = $sentry->get('createdTime'); $entry['cout'] = $sentry->get('cout'); $entry['coutTime'] = $sentry->get('coutTime'); $entry['id'] = $sentry->get('id'); $entry['validSince'] = $sentry->get('validSince'); $entry['validUntil'] = $sentry->get('validUntil'); $entry['description'] = $sentry->get('description'); $entry['icon'] = $sentry->get('icon'); $entry['introtext'] = $sentry->get('introtext'); $entry['parent'] = $sentry->get('parent'); $entry['confirmed'] = $sentry->get('confirmed'); $entry['counter'] = $sentry->get('counter'); $entry['nid'] = $sentry->get('nid'); $entry['metaDesc'] = $sentry->get('metaDesc'); $entry['metaKeys'] = $sentry->get('metaKeys'); $entry['metaAuthor'] = $sentry->get('metaAuthor'); $entry['metaRobots'] = $sentry->get('metaRobots'); $entry['ownerIP'] = $sentry->get('ownerIP'); $entry['updatedTime'] = $sentry->get('updatedTime'); $entry['updater'] = $sentry->get('updater'); $entry['updaterIP'] = $sentry->get('updaterIP'); $entry['version'] = $sentry->get('version'); $fields = $sentry->getFields(); $entry['fields'] = $fields; $entry['valid'] = $sentry->get('valid') ? 'valid' : 'invalid'; $entry['object'] =& $sentry; $entry['name'] = $sentry->get('name'); /* fields data init */ if (count($f)) { foreach ($f as $field) { $entry[$field->get('nid')] = null; } } /* now fill with the real data if any */ if (count($fields)) { foreach ($fields as $field) { $entry[$field->get('nid')] = $field->data(); } } if (count($customFields)) { foreach ($customFields as $customField) { $entry['customFields'][$customField] = $entry[$customField]; } } $entries[] = $entry; } } $this->assign($entries, 'entries'); }
/** * @return SPUser */ public static function &user() { SPLoader::loadClass('base.user'); SPLoader::loadClass('cms.base.user'); return SPUser::getCurrent(); }
protected function revisions() { $revision = SPFactory::message()->getRevision(SPRequest::cmd('revision')); $sid = SPRequest::sid(); $fid = SPRequest::cmd('fid'); if (strstr($fid, 'field_')) { $fid = SPFactory::db()->select('fid', 'spdb_field', array('nid' => $fid, 'section' => Sobi::Section()))->loadResult(); /** @var SPField $field */ $field = SPFactory::Model('field'); $field->init($fid); $field->loadData($sid); if (isset($revision['changes']['fields'][$field->get('nid')])) { $revision = $revision['changes']['fields'][$field->get('nid')]; } else { $revision = ""; } $current = $field->getRaw(); if (!is_array($current)) { try { $current = SPConfig::unserialize($current); } catch (SPException $x) { } } if (!is_array($revision)) { try { $revision = SPConfig::unserialize($revision); } catch (SPException $x) { } } try { $data = $field->compareRevisions($revision, $current); } catch (SPException $x) { if (is_array($current)) { $current = print_r($current, true); } if (is_array($revision)) { $revision = print_r($revision, true); } $data = array('current' => $current, 'revision' => $revision); } } else { $i = str_replace('entry.', null, $fid); if (isset($revision['changes'][$i])) { $revision = $revision['changes'][$i]; } else { $revision = ""; } switch ($i) { case 'owner': case 'updater': $currentUser = null; $pastUser = null; if ($this->_model->get($i)) { $currentUser = SPUser::getBaseData((int) $this->_model->get($i)); $currentUser = $currentUser->name . ' (' . $currentUser->id . ')'; } if ($revision) { $pastUser = SPUser::getBaseData((int) $revision); $pastUser = $pastUser->name . ' (' . $pastUser->id . ')'; } $data = array('current' => $currentUser, 'revision' => $pastUser); break; default: $data = array('current' => $this->_model->get($i), 'revision' => $revision); break; } } if (!SPRequest::bool('html', false, 'post')) { $data = array('current' => html_entity_decode(strip_tags($data['current']), ENT_QUOTES, 'UTF-8'), 'revision' => html_entity_decode(strip_tags($data['revision']), ENT_QUOTES, 'UTF-8')); } $data = array('current' => explode("\n", $data['current']), 'revision' => explode("\n", $data['revision'])); $diff = SPFactory::Instance('services.third-party.diff.lib.Diff', $data['revision'], $data['current']); $renderer = SPFactory::Instance('services.third-party.diff.lib.Diff.Renderer.Html.SideBySide'); // $renderer = SPFactory::Instance( 'services.third-party.diff.lib.Diff.Renderer.Html.Inline' ); $difference = $diff->Render($renderer); $data['diff'] = $difference; SPFactory::mainframe()->cleanBuffer()->customHeader(); echo json_encode($data); exit; }
public function addNewRule($name, $sections, $perms, $groups, $note = null) { SPLoader::loadClass('cms.base.users'); $db =& SPFactory::db(); try { $db->insertUpdate('spdb_permissions_rules', array('rid' => 'NULL', 'name' => $name, 'nid' => SPLang::nid($name), 'validSince' => $db->getNullDate(), 'validUntil' => $db->getNullDate(), 'note' => $note, 'state' => 1)); $rid = $db->insertid(); } catch (SPException $x) { Sobi::Error('ACL', SPLang::e('CANNOT_CREATE_RULE_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } $affectedGroups = array(); $gids = SPUser::availableGroups(); foreach ($gids as $id => $group) { if (in_array($group, $groups) || in_array(strtolower($group), $groups)) { $affectedGroups[] = array('rid' => $rid, 'gid' => $id); } } try { $db->insertArray('spdb_permissions_groups', $affectedGroups); } catch (SPException $x) { Sobi::Error('ACL', SPLang::e('CANNOT_INSERT_GROUPS_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } if (!count($this->_perms)) { $this->loadPermissions(); } $map = array(); foreach ($perms as $perm) { $perm = explode('.', $perm); $pid = $db->select('pid', 'spdb_permissions', array('subject' => $perm[0], 'action' => $perm[1], 'value' => $perm[2]))->loadResult(); if ($pid) { foreach ($sections as $sid) { $map[] = array('rid' => $rid, 'sid' => $sid, 'pid' => $pid); } } } if (count($map)) { try { $db->insertArray('spdb_permissions_map', $map, true); } catch (SPException $x) { Sobi::Error('ACL', SPLang::e('CANNOT_INSERT_GROUPS_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } } return $rid; }
/** * @param $ids * @internal param int $id * @return SPUser */ protected function userData($ids) { return SPUser::getBaseData($ids); }
function __construct() { // whether the client is logged in $this->is_logged = false; $sessionactive = !empty($_SESSION['username']) && !empty($_SESSION['password']) && !empty($_SESSION['uid']); if (!empty($_COOKIE['mt_username']) && !empty($_COOKIE['mt_password'])) { if (!$sessionactive) { $_SESSION['username'] = $_COOKIE['mt_username']; $_SESSION['password'] = $_COOKIE['mt_password']; $_SESSION['uid'] = $_COOKIE['mt_uid']; $sessionactive = true; } } if ($sessionactive) { // okay, session active, but are they a valid user? if (!$this->is_user($_SESSION['username'], $_SESSION['password'], true)) { unset($_SESSION['username']); unset($_SESSION['password']); unset($_SESSION['uid']); } else { $this->is_logged = true; } } // so if we're logged in, grab our info! if ($this->is_logged) { parent::__construct($_SESSION['uid']); } // whether the client is an admin $this->is_admin = false; if (isset($_SESSION['username'])) { $info = db_query_single("SELECT global_admin FROM groups WHERE id = '{$this->info['group']}'", "Checking whether the client is an administrator"); if ($info[0]) { $this->is_admin = true; } } }
/** * Returns selected property of the a selected user * e.g SobiPro::User( 'id' ); SobiPro::User( 'name' ); * * @param $id * @param string $property * @return mixed */ public static function User($id, $property) { $property = trim($property); if (in_array($property, array('password', 'block', 'sendEmail', 'activation', 'params'))) { return false; } $id = (int) $id; static $loaded = array(); if (!isset($loaded[$id])) { $loaded[$id] = SPUser::getBaseData($id); } return isset($loaded[$id]->{$property}) ? $loaded[$id]->{$property} : null; }