/** * @param $action * @param int $sid * @param array $changes * @param $message * @return SPMessage */ public function &logAction($action, $sid = 0, $changes = array(), $message = null) { if (Sobi::Cfg('entry.versioning', true)) { $log = array('revision' => microtime(true) . '.' . $sid . '.' . Sobi::My('id'), 'changedAt' => 'FUNCTION:NOW()', 'uid' => Sobi::My('id'), 'userName' => Sobi::My('name'), 'userEmail' => Sobi::My('mail'), 'change' => $action, 'site' => defined('SOBIPRO_ADM') ? 'adm' : 'site', 'sid' => $sid, 'changes' => SPConfig::serialize($changes), 'params' => null, 'reason' => $message, 'language' => Sobi::Lang()); SPFactory::db()->insert('spdb_history', $log); } return $this; }
/** * Try to find out what we have to do * - If we have a task - parse task * - If we don't have a task, but sid, we are going via default object task * - Otherwise it could be only the frontpage * @throws SPException * @return void */ private function route() { $cache = true; if (Sobi::Cfg('cache.xml_enabled')) { if ($this->_model instanceof stdClass && !($this->_model instanceof stdClass && $this->_model->owner == Sobi::My('id'))) { if (in_array($this->_model->owner, array('entry'))) { $cache = false; } } } if ($cache && Sobi::Cfg('cache.xml_enabled')) { $this->_cache = SPFactory::cache()->view(); } if (!$this->_cache) { /* if we have a task */ if ($this->_task && $this->_task != 'panel') { if (!$this->routeTask()) { throw new SPException(SPLang::e('Cannot interpret task "%s"', $this->_task)); } } elseif ($this->_sid) { if (!$this->routeObj()) { throw new SPException(SPLang::e('Cannot route object with id "%d"', $this->_sid)); } } else { $this->frontpage(); } } else { try { $task = $this->_task; if (!$task && $this->_sid) { $ctrl = SPFactory::Controller($this->_model->oType); $this->setController($ctrl); $this->_model = SPFactory::object($this->_sid); $model = SPLoader::loadModel($this->_model->oType, false, false); if ($model) { $this->_ctrl->setModel($model); if ($this->_model instanceof stdClass) { $this->_ctrl->extend($this->_model, true); } } } if (strstr($task, '.')) { $task = explode('.', $task); $obj = trim(array_shift($task)); if ($obj == 'list' || $obj == 'ls') { $obj = 'listing'; } $task = trim(implode('.', $task)); $ctrl = SPFactory::Controller($obj); $this->setController($ctrl); $model = SPLoader::loadModel($obj, false, false); if ($model) { $this->_ctrl->setModel($model); if ($this->_model instanceof stdClass) { $this->_ctrl->extend($this->_model, true); } } else { $this->_ctrl->setModel(SPFactory::Section($this->_section)); if ($this->_model instanceof stdClass) { $this->_ctrl->extend($this->_model, true); } } } elseif ($task) { /** Special controllers not inherited from object and without model */ $ctrl = SPFactory::Controller($task); $this->setController($ctrl); $this->_ctrl->setModel(SPFactory::Section($this->_section)); if ($this->_model instanceof stdClass) { $this->_ctrl->extend($this->_model, true); } } $this->_ctrl->setTask($task); $this->_ctrl->visible(); } catch (SPException $x) { Sobi::Error('CachedView', $x->getMessage()); $this->_cache = null; $this->route(); } } }
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; } }
/** * Gets the data for a field and save it in the database * @param SPEntry $entry * @param string $request * @return bool */ public function saveData(&$entry, $request = 'POST') { if (!$this->enabled) { return false; } /* @var SPdb $db */ $db = SPFactory::db(); $save = $this->verify($entry, $request); $time = SPRequest::now(); $IP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER'); $uid = Sobi::My('id'); /* collect the needed params */ $params = array(); $params['publishUp'] = $entry->get('publishUp'); $params['publishDown'] = $entry->get('publishDown'); $params['fid'] = $this->fid; $params['sid'] = $entry->get('id'); $params['section'] = Sobi::Reg('current_section'); $params['lang'] = Sobi::Lang(); $params['enabled'] = $entry->get('state'); $params['baseData'] = $db->escape(SPConfig::serialize($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 { /* Notices: * If it was new entry - insert * If it was an edit and the field wasn't filled before - insert * If it was an edit and the field was filled before - update * " ... " and changes are not autopublish it should be insert of the copy .... but * " ... " if a copy already exist it is update again * */ $db->insertUpdate('spdb_field_data', $params); } catch (SPException $x) { Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } /* if it wasn't edited in the default language, we have to try to insert it also for def lang */ if (Sobi::Lang() != Sobi::DefLang()) { $params['lang'] = Sobi::DefLang(); try { $db->insert('spdb_field_data', $params, true, true); } catch (SPException $x) { Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } } }
/** * */ public function display($o = null) { if (SPRequest::cmd('format') == 'json' && Sobi::Cfg('output.json_enabled', false)) { return $this->jsonDisplay(); } $type = $this->key('template_type', 'xslt'); $f = null; $task = SPRequest::task(); if ($this->key('functions')) { $f = $this->registerFunctions(); } $out = null; if ($type != 'php' && Sobi::Cfg('global.disable_xslt', false)) { $type = 'php'; } $parserClass = SPLoader::loadClass('mlo.template_' . $type); if ($parserClass) { /** @var $parser SPTemplateXSLT */ $parser = new $parserClass(); } else { throw new SPException(SPLang::e('CANNOT_LOAD_PARSER', $type)); } $this->_attr['template_path'] = Sobi::FixPath(str_replace(SOBI_ROOT, Sobi::Cfg('live_site'), $this->_templatePath)); $messages = SPFactory::message()->getMessages(); if (count($messages)) { foreach ($messages as $type => $content) { $this->_attr['messages'][$type] = array_values($content); } } $parser->setProxy($this); $parser->setData($this->_attr); $parser->setXML($this->_xml); $parser->setCacheData(array('hidden' => $this->_hidden)); $parser->setType($this->_type); $parser->setTemplate($this->_template); Sobi::Trigger('Display', $this->name(), array($type, &$this->_attr)); $o = $o ? $o : strtolower($this->key('output', $this->key('output', 'html'), $this->tTask)); $action = $this->key('form.action'); if ($action) { $opt = SPFactory::mainframe()->form(); if (is_array($opt) && count($opt)) { foreach ($opt as $l => $v) { $this->addHidden($v, $l); } } $form = $this->csection('form'); $form['method'] = isset($form['method']) && $form['method'] ? $form['method'] : 'post'; $out .= "\n<form "; foreach ($form as $p => $v) { $out .= $p . '="' . $v . '" '; } $out .= ">\n"; } $out .= $parser->display($o, $f); $hidden = null; if (count($this->_hidden)) { $this->_hidden[SPFactory::mainframe()->token()] = 1; foreach ($this->_hidden as $name => $value) { $hidden .= "\n<input type=\"hidden\" id=\"SP_{$name}\" name=\"{$name}\" value=\"{$value}\"/>"; } // xhtml strict valid $hidden = "<div>{$hidden}</div>"; $out .= $hidden; } $out .= $action ? "\n</form>\n" : null; /* SobiPro type specific content parser */ Sobi::Trigger('ContentDisplay', $this->name(), array(&$out)); /* common content parser */ $cParse = $this->key('parse', -1); /* if it was specified in the template config file or it was set in the section config and not disabled in the template config */ if (!(strstr($task, '.edit') || strstr($task, '.add') || in_array($task, Sobi::Cfg('plugins.content_disable', array())))) { if ($cParse == 1 || Sobi::Cfg('parse_template_content', false) && $cParse == -1) { Sobi::Trigger('Parse', 'Content', array(&$out)); } } header('SobiPro: ' . Sobi::Section()); if ($o == 'html' && (!strlen(SPRequest::cmd('format')) || SPRequest::cmd('format') == 'html' || SPRequest::int('crawl'))) { $out .= $this->pb(); if ((SPRequest::cmd('dbg') || Sobi::Cfg('debug')) && Sobi::My('id')) { $start = Sobi::Reg('start'); $mem = $start[0]; $time = $start[1]; $queries = SPFactory::db()->getCount(); $mem = number_format(memory_get_usage() - $mem); $time = microtime(true) - $time; SPConfig::debOut("Memory: {$mem}<br/>Time: {$time}<br/> Queries: {$queries}"); } echo "\n<!-- Start of SobiPro component-->\n<div id=\"SobiPro\" class=\"SobiPro\">\n{$out}\n</div>\n<!-- End of SobiPro component Copyright (C) 2011-2014 Sigsiu.NET GmbH -->\n"; } else { $this->customOutput($out); } Sobi::Trigger('AfterDisplay', $this->name()); }
public static function userSelector($name, $value, $groups = null, $params = null, $icon = 'user', $header = 'USER_SELECT_HEADER', $format = '%user', $orderBy = 'id') { static $count = 0; static $session = null; if (!$session) { $session = SPFactory::user()->getUserState('userSelector', null, array()); } $params = self::checkArray($params); if (!isset($params['id'])) { $params['id'] = SPLang::nid($name); } $user = null; SPFactory::header()->addJsFile('user_selector'); $user = SPUser::getBaseData((int) $value); $settings = array('groups' => $groups, 'format' => $format, 'user' => Sobi::My('id'), 'ordering' => $orderBy, 'time' => microtime(true)); if (count($session)) { foreach ($session as $id => $data) { if (microtime(true) - $data['time'] > 3600) { unset($session[$id]); } } } $ssid = md5(microtime() . Sobi::My('id') . ++$count); $session[$ssid] =& $settings; SPFactory::user()->setUserState('userSelector', $session); $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; } } $modal = '<div class="response btn-group" data-toggle="buttons-radio"></div><br/><button class="btn btn-block hide more" type="button">' . Sobi::Txt('LOAD_MORE') . '</button>'; $filter = '<input type="text" placeholder="' . Sobi::Txt('FILTER') . '" class="search pull-right spDisableEnter" name="q">'; $id = $params['id']; $params = self::params($params); $f = "\n"; $f .= '<div class="spUserSelector">'; $f .= '<div class="input-append">'; $f .= "\n\t"; $f .= '<input type="text" value="' . $userData . '" ' . $params . ' name="' . $name . 'Holder" readonly="readonly" class="trigger user-name"/>'; $f .= '<span class="add-on trigger"><i class="icon-' . $icon . '"></i></span>'; $f .= '</div>'; $f .= '<input type="hidden" value="' . $value . '" name="' . $name . '" rel="selected"/>'; $f .= '<input type="hidden" value="' . $ssid . '" name="' . $name . 'Ssid"/>'; $f .= '<input type="hidden" value="1" name="' . SPFactory::mainframe()->token() . '"/>'; $f .= "\n\t"; $f .= "\n"; $f .= self::modalWindow(Sobi::Txt($header) . $filter, $id . '-window', $modal); $f .= '</div>'; $f .= "\n"; Sobi::Trigger('Field', ucfirst(__FUNCTION__), array(&$f)); return "\n<!-- User Picker '{$name}' Output -->{$f}<!-- User Picker '{$name}' End -->\n\n"; }
private function checkCopy() { return !(in_array(SPRequest::task(), array('entry.approve', 'entry.edit', 'entry.save', 'entry.submit', 'entry.payment')) || Sobi::Can('entry.access.unapproved_any') || $this->owner == Sobi::My('id') && Sobi::Can('entry.manage.own') || $this->owner == Sobi::My('id') && Sobi::Can('entry.access.unpublished_own') || Sobi::Can('entry.manage.*')); }
protected function entryData($getFields = true) { /** @var SPEntry $entry */ $entry = $this->get('entry'); $visitor = $this->get('visitor'); $data = array(); $data['section'] = array('_complex' => 1, '_data' => Sobi::Section(true), '_attributes' => array('id' => Sobi::Section(), 'lang' => Sobi::Lang(false))); $en = array(); $en['name'] = array('_complex' => 1, '_data' => $entry->get('name'), '_attributes' => array('lang' => Sobi::Lang(false))); $en['created_time'] = $entry->get('createdTime'); $en['updated_time'] = $entry->get('updatedTime'); $en['valid_since'] = $entry->get('validSince'); $en['valid_until'] = $entry->get('validUntil'); $en['author'] = $entry->get('owner'); $en['counter'] = $entry->get('counter'); $en['approved'] = $entry->get('approved'); $this->fixTimes($en); // $mytime = date( 'Y-m-d H:i:s', time()); if ($entry->get('state') == 0) { $en['state'] = 'unpublished'; } else { if (strtotime($entry->get('validUntil')) != 0 && strtotime($entry->get('validUntil')) < time()) { $en['state'] = 'expired'; } elseif (strtotime($entry->get('validSince')) != 0 && strtotime($entry->get('validSince')) > time()) { $en['state'] = 'pending'; } else { $en['state'] = 'published'; } } $en['url'] = Sobi::Url(array('pid' => $entry->get('parent'), 'sid' => $entry->get('id'), 'title' => Sobi::Cfg('sef.alias', true) ? $entry->get('nid') : $entry->get('name')), true, true, true); if (Sobi::Can('entry', 'edit', '*') || Sobi::My('id') == $entry->get('owner') && Sobi::Can('entry', 'edit', 'own')) { $en['edit_url'] = Sobi::Url(array('task' => 'entry.edit', 'sid' => $entry->get('id'))); } if (Sobi::Can('entry', 'manage', '*')) { $en['approve_url'] = Sobi::Url(array('task' => $entry->get('approved') ? 'entry.unapprove' : 'entry.approve', 'sid' => $entry->get('id'))); } if ($entry->get('owner') == Sobi::My('id') && Sobi::Can('entry', 'delete', 'own') || Sobi::Can('entry', 'delete', '*')) { $en['delete_url'] = Sobi::Url(array('task' => 'entry.delete', 'sid' => $entry->get('id'))); } if (Sobi::Can('entry', 'publish', '*') || Sobi::My('id') == $entry->get('owner') && Sobi::Can('entry', 'publish', 'own')) { $en['publish_url'] = Sobi::Url(array('task' => $entry->get('state') ? 'entry.unpublish' : 'entry.publish', 'sid' => $entry->get('id'))); } $cats = $entry->get('categories'); $categories = array(); if (count($cats)) { $cn = SPLang::translateObject(array_keys($cats), array('name', 'alias'), 'category'); } $primaryCat = $entry->get('parent'); foreach ($cats as $cid => $cat) { $cAttr = array('lang' => Sobi::Lang(false), 'id' => $cat['pid'], 'alias' => $cat['alias'], 'position' => $cat['position'], 'url' => Sobi::Url(array('sid' => $cat['pid'], 'title' => Sobi::Cfg('sef.alias', true) ? $cat['alias'] : $cat['name']))); if ($cat['pid'] == $primaryCat) { $cAttr['primary'] = 'true'; } $categories[] = array('_complex' => 1, '_data' => SPLang::clean($cn[$cid]['value']), '_attributes' => $cAttr); } $en['categories'] = $categories; $en['meta'] = array('description' => $entry->get('metaDesc'), 'keys' => $this->metaKeys($entry), 'author' => $entry->get('metaAuthor'), 'robots' => $entry->get('metaRobots')); if ($getFields) { $fields = $entry->getFields(); if (count($fields)) { $en['fields'] = $this->fieldStruct($fields, 'details'); } } $this->menu($data); $this->alphaMenu($data); $data['entry'] = array('_complex' => 1, '_data' => $en, '_attributes' => array('id' => $entry->get('id'), 'nid' => $entry->get('nid'), 'version' => $entry->get('version'))); $data['visitor'] = $this->visitorArray($visitor); return $data; }
protected function loadTemplate($field, $view) { $nid = '/' . Sobi::Section('nid') . '/'; $disableOverrides = null; if (is_array(Sobi::My('groups'))) { $disableOverrides = array_intersect(Sobi::My('groups'), Sobi::Cfg('templates.disable-overrides', array())); } if (SPLoader::translatePath('field.' . $field->get('fieldType'), 'adm', true, 'xml')) { /** Case we have also override */ /** section override */ if (!$disableOverrides && SPLoader::translatePath('field.' . $nid . $field->get('fieldType'), 'adm', true, 'xml')) { $view->loadDefinition('field.' . $nid . $field->get('fieldType')); } elseif (SPLoader::translatePath('field.' . $field->get('fieldType') . '_override', 'adm', true, 'xml')) { $view->loadDefinition('field.' . $field->get('fieldType') . '_override'); } else { $view->loadDefinition('field.' . $field->get('fieldType')); } if (SPLoader::translatePath('field.templates.' . $field->get('fieldType') . '_override', 'adm')) { $view->setTemplate('field.templates.' . $field->get('fieldType') . '_override'); } elseif (SPLoader::translatePath('field.templates.' . $nid . $field->get('fieldType'), 'adm')) { $view->setTemplate('field.templates.' . $nid . $field->get('fieldType')); } else { $view->setTemplate('default'); } return true; } return false; }
/** * Gets the data for a field and save it in the database * @param SPEntry $entry * @param string $request * @throws SPException * @return bool */ public function saveData(&$entry, $request = 'POST') { if (!$this->enabled) { return false; } if ($this->method == 'fixed') { $fixed = $this->fixedCid; $fixed = explode(',', $fixed); $data = array(); if (count($fixed)) { foreach ($fixed as $cid) { $data[] = trim($cid); } } if (!count($data)) { throw new SPException(SPLang::e('FIELD_CC_FIXED_CID_NOT_SELECTED', $this->name)); } } else { $data = $this->verify($entry, $request); } $time = SPRequest::now(); $IP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER'); $uid = Sobi::My('id'); /* if we are here, we can save these data */ /* @var SPdb $db */ $db = SPFactory::db(); /* collect the needed params */ $params = array(); $params['publishUp'] = $entry->get('publishUp'); $params['publishDown'] = $entry->get('publishDown'); $params['fid'] = $this->fid; $params['sid'] = $entry->get('id'); $params['section'] = Sobi::Reg('current_section'); $params['lang'] = Sobi::Lang(); $params['enabled'] = $entry->get('state'); $params['params'] = null; $params['options'] = null; $params['baseData'] = SPConfig::serialize($data); $params['approved'] = $entry->get('approved'); $params['confirmed'] = $entry->get('confirmed'); /* if it is the first version, it is new entry */ if ($entry->get('version') == 1) { $params['createdTime'] = $time; $params['createdBy'] = $uid; $params['createdIP'] = $IP; } $params['updatedTime'] = $time; $params['updatedBy'] = $uid; $params['updatedIP'] = $IP; $params['copy'] = !$entry->get('approved'); if (Sobi::My('id') == $entry->get('owner')) { --$this->editLimit; } $params['editLimit'] = $this->editLimit; /* save it */ try { /* Notices: * If it was new entry - insert * If it was an edit and the field wasn't filled before - insert * If it was an edit and the field was filled before - update * " ... " and changes are not autopublish it should be insert of the copy .... but * " ... " if a copy already exist it is update again * */ $db->insertUpdate('spdb_field_data', $params); } catch (SPException $x) { Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } /* if it wasn't edited in the default language, we have to try to insert it also for def lang */ if (Sobi::Lang() != Sobi::DefLang()) { $params['lang'] = Sobi::DefLang(); try { $db->insert('spdb_field_data', $params, true, true); } catch (SPException $x) { Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } } /** Last important thing - join selected categories */ $cats = SPFactory::registry()->get('request_categories', array()); $cats = array_unique(array_merge($cats, $data)); SPFactory::registry()->set('request_categories', $cats); if ($this->method == 'select' && $this->isPrimary) { $db->update('spdb_object', array('parent' => $data[0]), array('id' => $params['sid'])); } }
/** */ private function editForm() { /* if adding new */ if (!$this->_model || $this->_task == 'add') { $this->setModel(SPLoader::loadModel('category')); } $this->checkTranslation(); $this->_model->formatDatesToEdit(); $id = $this->_model->get('id'); if (!$id) { $this->_model->set('state', 1); $this->_model->set('parent', SPRequest::sid()); } if ($this->_model->isCheckedOut()) { SPFactory::message()->error(Sobi::Txt('CAT.IS_CHECKED_OUT'), false); } else { $this->_model->checkOut(); } $view = SPFactory::View('category', true); $view->assign($this->_model, 'category')->assign($this->_task, 'task')->assign(SPFactory::CmsHelper()->userSelect('category.owner', $this->_model->get('owner') ? $this->_model->get('owner') : ($this->_model->get('id') ? 0 : Sobi::My('id')), true), 'owner')->assign($id, 'cid')->addHidden(Sobi::Section(), 'pid'); Sobi::Trigger('Category', 'EditView', array(&$view)); $view->display(); }
/** * @param $params * @param bool $count * @return array */ protected function entries($params, $count = false) { if ($params->get('fieldOrder')) { $eOrder = $params->get('fieldOrder'); } else { $eOrder = $params->get('spOrder'); } $entriesRecursive = true; $conditions = array(); $db = SPFactory::db(); $limits = $params->get('spLimit'); if ($limits) { $limits = explode('::', $limits); $fid = $limits[0]; $value = $limits[1] == 'group' ? $limits[2] : $limits[1]; $condition = array('fid' => $fid, 'optValue' => $value); if ($limits[1] == 'group') { $condition['optValue'] = $db->select('optValue', 'spdb_field_option', array('optParent' => $value, 'fid' => $fid))->loadResultArray(); } $conditions['spo.id'] = $db->select('sid', 'spdb_field_option_selected', $condition)->loadResultArray(); if (!count($conditions['spo.id'])) { return array(); } } $eDir = $params->get('spOrderDir'); $oPrefix = null; /* get the site to display */ if ($params->get('engine') != 'static') { $site = SPRequest::int('site', 1); } else { $site = 1; } $eLimit = $params->get('entriesLimit'); $eLimStart = ($site - 1) * $eLimit; /* get the ordering and the direction */ if (strstr($eOrder, '.')) { $eOrder = explode('.', $eOrder); $eDir = $eOrder[1]; $eOrder = $eOrder[0]; } $sid = $params->get('sid'); $section = $params->get('section'); $this->setModel($sid == $section ? 'section' : 'category'); $this->_model->init($sid); $catId = SPRequest::int('pid'); $catId = $catId ? $catId : SPRequest::sid(); if ($params->get('autoListing', false) && $catId && $catId != Sobi::Section()) { $entries = Sobi::GetUserData('currently-displayed-entries', array()); if (!count($entries) && $catId) { $entries = SPFactory::Category($catId)->getChilds('entry', true, 1); $entries = array_unique($entries); } if (count($entries)) { $conditions['spo.id'] = $entries; } } else { if ($entriesRecursive) { $pids = $this->_model->getChilds('category', true); // getChilds doesn't includes the category id itself $pids[$this->_model->get('id')] = $this->_model->get('id'); if (is_array($pids)) { $pids = array_keys($pids); } $conditions['sprl.pid'] = $pids; } else { $conditions['sprl.pid'] = $sid; } if ($sid == -1) { unset($conditions['sprl.pid']); } } if (count($conditions)) { /* sort by field */ if (is_numeric($eOrder)) { static $fields = array(); $specificMethod = false; $field = isset($fields[$sid]) ? $fields[$sid] : null; if (!$field) { try { $fType = $db->select('fieldType', 'spdb_field', array('fid' => $eOrder))->loadResult(); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('CANNOT_DETERMINE_FIELD_TYPE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } if ($fType) { $field = SPLoader::loadClass('opt.fields.' . $fType); } $fields[$sid] = $field; } if ($field && method_exists($field, 'sortBy')) { $table = null; $oPrefix = null; $specificMethod = call_user_func_array(array($field, 'sortBy'), array(&$table, &$conditions, &$oPrefix, &$eOrder, &$eDir)); } if (!$specificMethod) { $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'] = $eOrder; $eOrder = 'baseData.' . $eDir; } } else { $table = $db->join(array(array('table' => 'spdb_relations', 'as' => 'sprl', 'key' => 'id'), array('table' => 'spdb_object', 'as' => 'spo', 'key' => 'id'))); $conditions['spo.oType'] = 'entry'; if ($eOrder == 'validUntil') { $eOrder = 'spo.validUntil'; } $eOrder = $eOrder . '.' . $eDir; $oPrefix = 'spo.'; } /* 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 { if (!$count) { $results = $db->select($oPrefix . 'id', $table, $conditions, $eOrder, $eLimit, $eLimStart, true)->loadResultArray(); } else { $results = $db->select("COUNT( DISTINCT {$oPrefix}id )", $table, $conditions, $eOrder)->loadResult(); } } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } if ($count) { return $results; } $entries = array(); if (count($results)) { foreach ($results as $i => $sid) { $entries[$i] = $sid; } } return $entries; } else { return array(); } }
/** */ public function storeView($head) { if (!Sobi::Cfg('cache.xml_enabled') || $this->_cachedView || Sobi::My('id') && Sobi::Cfg('cache.xml_no_reg')) { return false; } if ($this->view['xml']) { $xml = $this->view['xml']; $template = Sobi::Reg('cache_view_template'); if (!$template) { $template = $this->view['template']; $template = str_replace(SPLoader::translateDirPath(Sobi::Cfg('section.template'), 'templates'), null, $template); } $root = $xml->documentElement; $root->removeChild($root->getElementsByTagName('visitor')->item(0)); if ($root->getElementsByTagName('messages')->length) { $root->removeChild($root->getElementsByTagName('messages')->item(0)); } /** @var $header DOMDocument */ $header = SPFactory::Instance('types.array')->toXML($head, 'header', true); $root->appendChild($xml->importNode($header->documentElement, true)); if ($this->view['data'] && count($this->view['data'])) { $data = SPFactory::Instance('types.array')->toXML($this->view['data'], 'cache-data', true); $root->appendChild($xml->importNode($data->documentElement, true)); } $request = $this->viewRequest(); $request['template'] = $template; $configFiles = SPFactory::registry()->get('template_config'); $request['configFile'] = str_replace('"', "'", json_encode($configFiles)); $request['cid'] = 'NULL'; $request['created'] = 'FUNCTION:NOW()'; $fileName = md5(serialize($request)); $request['fileName'] = $fileName; $filePath = SPLoader::path('var.xml.' . $fileName, 'front', false, 'xml'); $content = $xml->saveXML(); $content = str_replace(' ', ' ', $content); $content = preg_replace('/[^\\x{0009}\\x{000a}\\x{000d}\\x{0020}-\\x{D7FF}\\x{E000}-\\x{FFFD}]+/u', null, $content); $matches = array(); preg_match_all('/<(category|entry|subcategory)[^>]*id="(\\d{1,})"/', $content, $matches); try { $cid = SPFactory::db()->insert('spdb_view_cache', $request, false, true)->insertid(); $relations = array(SPRequest::sid() => array('cid' => $cid, 'sid' => SPRequest::sid())); if (isset($matches[2])) { $ids = array_unique($matches[2]); foreach ($ids as $sid) { $relations[$sid] = array('cid' => $cid, 'sid' => $sid); } } SPFactory::db()->insertArray('spdb_view_cache_relation', $relations); SPFs::write($filePath, $content); } catch (SPException $x) { Sobi::Error('XML-Cache', $x->getMessage()); } } }
/** */ public function visible() { $type = $this->_model->get('oType'); if (Sobi::Can($type, 'access', '*')) { return true; } $error = false; $owner = $this->_model->get('owner'); $state = $this->_model->get('state'); Sobi::Trigger($type, 'CheckVisibility', array(&$state, &$owner)); /* if it's unpublished */ if (!$state) { if ($owner == Sobi::My('id')) { if (!Sobi::Can($type, 'access', 'unpublished_own')) { $error = true; } } else { if (!Sobi::Can($type, 'access', 'unpublished_any')) { $error = true; } } } else { if (!Sobi::Can($type, 'access', 'valid')) { $error = true; } } /** if not approved */ /** and unapproved entry can be accessed * because then the previously created version * should be displayed */ if ($type == 'category') { $approved = $this->_model->get('approved'); if (!$approved) { if (!Sobi::Can($type, 'access', 'unapproved_any')) { $error = true; } } } /* if it's expired or not valid yet */ $va = $this->_model->get('validUntil'); $va = $va ? strtotime($va . ' UTC') : 0; if (!$error) { if (strtotime($this->_model->get('validSince') . ' UTC') > gmdate('U')) { if ($owner == Sobi::My('id')) { if (!Sobi::Can($type, 'access', 'unpublished_own')) { $error = true; } } else { if (!Sobi::Can($type, 'access', 'unpublished_any')) { $error = true; } } } elseif ($va > 0 && $va < gmdate('U')) { if ($owner == Sobi::My('id')) { if (!Sobi::Can($type, 'access', 'unpublished_own')) { $error = true; } } else { if (!Sobi::Can($type, 'access', 'unpublished_any')) { $error = true; } } } } if ($error) { $redirect = Sobi::Cfg('redirects.' . $type . '_access_url', null); if (Sobi::Cfg('redirects.' . $type . '_access_enabled', false) && strlen($redirect)) { $this->escape($redirect, Sobi::Cfg('redirects.' . $type . '_access_msg', SPLang::e('UNAUTHORIZED_ACCESS', SPRequest::task())), Sobi::Cfg('redirects.' . $type . '_access_msgtype', 'message')); exit; } else { Sobi::Error($this->name(), SPLang::e('UNAUTHORIZED_ACCESS', SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__); } } }
/** * @return bool */ public function isCheckedOut() { if ($this->cout && $this->cout != Sobi::My('id') && strtotime($this->coutTime) > time()) { return true; } else { return false; } }
private function fetch() { $msg = SPFactory::Controller('progress'); if (!SPFactory::mainframe()->checkToken('get')) { Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::WARNING, 0, __LINE__, __FILE__); $msg->error(SPLang::e('REPO_ERR', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()))); exit; } $msg->progress(0, Sobi::Txt('EX.GETTING_REPOS')); $repos = SPLoader::dirPath('etc.repos', 'front'); $repos = SPFactory::Instance('base.fs.directory', $repos); $repos = $repos->searchFile('repository.xml', true, 2); $repos = array_keys($repos); $cr = count($repos); $progress = 5; $msg->progress($progress, Sobi::Txt('EX.FOUND_NUM_REPOS', array('count' => $cr))); $repository = SPFactory::Instance('services.installers.repository'); // sleep( 5 ); $steps = 2; $pstep = 80 / $cr / $steps; $list = array(); $r = array(); for ($i = 0; $i < $cr; $i++) { $repository->loadDefinition($repos[$i]); $progress += $pstep / $steps; $msg->progress($progress, Sobi::Txt('EX.CON_TO_REPO_D_D', array('num' => $i + 1, 'from' => $cr))); try { $repository->connect($msg); sleep(1); } catch (SPException $x) { $msg->error(SPLang::e('REPO_ERR', $x->getMessage())); exit; } $progress += $pstep / $steps; $msg->progress($progress, Sobi::Txt('EX.FETCHING_FROM_REPO_D_D', array('num' => $i + 1, 'from' => $cr))); try { $ver = SPFactory::CmsHelper()->cmsVersion(); $l = $repository->fetchList($repository->get('token'), 'Joomla ' . $ver['major'] . '.' . $ver['minor']); // sleep( 1 ); } catch (SPException $x) { $msg->error(SPLang::e('REPO_ERR', $x->getMessage())); } if (is_array($l)) { if (count($l)) { $pid = $repository->get('id'); foreach ($l as $eid => $values) { $eid = str_replace(array('.', '_'), '-', $eid); $values['repository'] = $pid; $l[$eid] = $values; } $r[$pid] = $repository->get('url'); } $list = array_merge($list, $l); } $progress += $pstep / $steps; $msg->progress($progress, Sobi::Txt('EX.FETCHED_LIST_FROM_REPOSITORY', array('count' => count($l), 'num' => $i + 1, 'from' => $cr))); } $progress += 5; if (count($list)) { $msg->progress($progress, Sobi::Txt('EX.FETCHED_D_EXTENSIONS', array('count' => count($list)))); $extensions = array(); $extensions['created'] = time(); $extensions['createdBy'] = array('id' => Sobi::My('id'), 'name' => Sobi::My('name')); $extensions['repositories'] = $r; $extensions['extensions'] = $list; $progress += 10; $msg->progress($progress); /** @var SPFile $file */ $file = SPFactory::Instance('base.fs.file', SPLoader::path('etc.extensions', 'front', false, 'xml')); $def = SPFactory::Instance('types.array'); $file->content($def->toXML($extensions, 'extensionsList')); $msg->progress($progress, $def->toXML($extensions, 'extensionsList')); try { $file->save(); } catch (SPException $x) { $msg->progress($progress, $x->getMessage()); } // sleep( 1 ); } $msg->progress(100, Sobi::Txt('EX.EXT_LIST_UPDATED'), SPC::SUCCESS_MSG); // SPFactory::message()->success( Sobi::Txt( 'EX.EXT_LIST_UPDATED' ), false ); exit; }
/** */ private function editForm() { $sid = SPRequest::int('pid'); $sid = $sid ? $sid : SPRequest::sid(); $view = SPFactory::View('entry', true); $this->checkTranslation(); /* if adding new */ if (!$this->_model) { $this->setModel(SPLoader::loadModel('entry')); } $this->_model->formatDatesToEdit(); $id = $this->_model->get('id'); if (!$id) { $this->_model->set('state', 1); $this->_model->set('approved', 1); } else { $view->assign($view->languages(), 'languages-list'); } $this->_model->loadFields(Sobi::Reg('current_section'), true); $this->_model->formatDatesToEdit(); if ($this->_model->isCheckedOut()) { SPFactory::message()->error(Sobi::Txt('EN.IS_CHECKED_OUT', $this->_model->get('name')), false); } else { /* check out the model */ $this->_model->checkOut(); } /* get fields for this section */ /* @var SPEntry $this ->_model */ $fields = $this->_model->get('fields'); if (!count($fields)) { throw new SPException(SPLang::e('CANNOT_GET_FIELDS_IN_SECTION', Sobi::Reg('current_section'))); } $revisionChange = false; $rev = SPRequest::cmd('revision'); $revisionsDelta = array(); if ($rev) { $revision = SPFactory::message()->getRevision(SPRequest::cmd('revision')); if (isset($revision['changes']) && count($revision['changes'])) { SPFactory::message()->warning(Sobi::Txt('HISTORY_REVISION_WARNING', $revision['changedAt']), false); foreach ($fields as $i => $field) { if ($field->get('enabled') && $field->enabled('form')) { if (isset($revision['changes']['fields'][$field->get('nid')])) { $revisionData = $revision['changes']['fields'][$field->get('nid')]; } else { $revisionData = null; } $currentData = $field->getRaw(); if (is_array($revisionData) && !is_array($currentData)) { try { $currentData = SPConfig::unserialize($currentData); } catch (SPException $x) { } } if ($revisionData || $currentData) { if (md5(serialize($currentData)) != md5(serialize($revisionData))) { $field->revisionChanged()->setRawData($revisionData); } } $fields[$i] = $field; } } unset($revision['changes']['fields']); foreach ($revision['changes'] as $attr => $value) { if ($value != $this->_model->get($attr)) { $revisionsDelta[$attr] = $value; $this->_model->setRevData($attr, $value); } } $revisionChange = true; } else { SPFactory::message()->error(Sobi::Txt('HISTORY_REVISION_NOT_FOUND'), false)->setSystemMessage(); } } $f = array(); foreach ($fields as $field) { if ($field->get('enabled') && $field->enabled('form')) { $f[] = $field; } } /* create the validation script to check if required fields are filled in and the filters, if any, match */ $this->createValidationScript($fields); $view->assign($this->_model, 'entry'); /* get the categories */ $cats = $this->_model->getCategories(true); if (count($cats)) { $tCats = array(); foreach ($cats as $cid) { /* ROTFL ... damn I like arrays ;-) */ $tCats2 = SPFactory::config()->getParentPath($cid, true); if (is_array($tCats2) && count($tCats2)) { $tCats[] = implode(Sobi::Cfg('string.path_separator'), $tCats2); } } if (count($tCats)) { $view->assign(implode("\n", $tCats), 'parent_path'); } $view->assign(implode(", ", $cats), 'parents'); } elseif ($this->_model->get('valid')) { $parent = $sid == Sobi::Reg('current_section') ? 0 : $sid; if ($parent) { $view->assign(implode(Sobi::Cfg('string.path_separator', ' > '), SPFactory::config()->getParentPath($parent, true)), 'parent_path'); } $view->assign($parent, 'parents'); } else { $n = null; $view->assign($n, 'parents'); $view->assign($n, 'parent_path'); } $history = array(); $messages = SPFactory::message()->getHistory($id); if (count($messages)) { foreach ($messages as $message) { $message['change'] = Sobi::Txt('HISTORY_CHANGE_TYPE_' . str_replace('-', '_', strtoupper($message['change']))); $message['site'] = Sobi::Txt('HISTORY_CHANGE_AREA_' . strtoupper($message['site'])); if (strlen($message['reason'])) { $message['status'] = 1; } else { $message['status'] = 0; } $history[] = $message; } } $versioningAdminBehaviour = Sobi::Cfg('entry.versioningAdminBehaviour', 1); if ($versioningAdminBehaviour || !Sobi::Cfg('entry.versioning', true)) { SPFactory::header()->addJsCode(' SobiPro.jQuery( document ).ready( function () { SobiPro.jQuery( "[rel=\'entry.saveWithRevision\']" ).parent().css( "display", "none" ); } ); '); } $view->assign($this->_task, 'task')->assign($f, 'fields')->assign($id, 'id')->assign($history, 'history')->assign($revisionChange, 'revision-change')->assign($revisionsDelta, 'revision')->assign($versioningAdminBehaviour, 'history-behaviour')->assign(SPFactory::CmsHelper()->userSelect('entry.owner', $this->_model->get('owner') ? $this->_model->get('owner') : ($this->_model->get('id') ? 0 : Sobi::My('id')), true), 'owner')->assign(Sobi::Reg('current_section'), 'sid')->determineTemplate('entry', 'edit')->addHidden($rev, 'revision')->addHidden($sid, 'pid'); $view->display(); }
protected function session(&$ssid) { /* if it wasn't new search */ $ssid = SPRequest::cmd('ssid', SPRequest::cmd('ssid', null, 'cookie')); $new = false; /* otherwise create new ssid */ if (!$ssid) { $ssid = microtime(true) * 100 . '.' . rand(0, 99); $new = true; } $attr = array('ssid' => $ssid, 'uid' => Sobi::My('id'), 'browserData' => SPConfig::serialize(SPBrowser::getInstance())); /* get search request */ if (!count($this->_request)) { $r = SPRequest::search('field_'); if (is_array($r) && count($r)) { $attr['requestData'] = SPConfig::serialize($r); } } /* determine the search parameters */ if ($new) { $attr['searchCreated'] = 'FUNCTION:NOW()'; } /* finally save */ try { $this->_db->insertUpdate('spdb_search', $attr); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('CANNOT_CREATE_SESSION_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__); } return SPCookie::set('ssid', $ssid, SPCookie::days(7)); }
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; }
/** */ private function editForm() { if ($this->_task != 'add') { $sid = SPRequest::sid(); $sid = $sid ? $sid : SPRequest::int('pid'); } else { $this->authorise($this->_task, 'own'); $this->_model = null; $sid = SPRequest::int('pid'); // $section = SPFactory::Section( Sobi::Section() ); } if ($this->_model && $this->_model->isCheckedOut()) { Sobi::Redirect(Sobi::Url(array('sid' => SPRequest::sid())), Sobi::Txt('EN.IS_CHECKED_OUT', $this->_model->get('name')), SPC::ERROR_MSG, true); } /* determine template package */ $tplPackage = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE); /* load template config */ $this->template(); $this->tplCfg($tplPackage); /* check if we have stored last edit in cache */ $this->getCache(SPRequest::string('editentry', null, false, 'cookie'), 'editcache'); $section = SPFactory::Model('section'); $section->init(Sobi::Section()); SPFactory::cache()->setJoomlaCaching(false); if ($this->_model) { /* handle meta data */ SPFactory::header()->objMeta($this->_model); /* add pathway */ SPFactory::mainframe()->addObjToPathway($this->_model); } else { /* handle meta data */ SPFactory::header()->objMeta($section); if ($this->_task == 'add') { SPFactory::header()->addKeyword($section->get('efMetaKeys'))->addDescription($section->get('efMetaDesc')); } SPFactory::mainframe()->addToPathway(Sobi::Txt('EN.ADD_PATH_TITLE'), Sobi::Url('current')); SPFactory::mainframe()->setTitle(Sobi::Txt('EN.ADD_TITLE', array('section' => $section->get('name')))); /* add pathway */ SPFactory::mainframe()->addObjToPathway($section); $this->setModel(SPLoader::loadModel('entry')); } $this->_model->formatDatesToEdit(); $id = $this->_model->get('id'); if (!$id) { $this->_model->set('state', 1); } if ($this->_task != 'add' && !$this->authorise($this->_task, $this->_model->get('owner') == Sobi::My('id') ? 'own' : '*')) { throw new SPException(SPLang::e('YOU_ARE_NOT_AUTH_TO_EDIT_THIS_ENTRY')); } $this->_model->loadFields(Sobi::Reg('current_section')); /* get fields for this section */ $fields = $this->_model->get('fields'); if (!count($fields)) { throw new SPException(SPLang::e('CANNOT_GET_FIELDS_IN_SECTION', Sobi::Reg('current_section'))); } /* create the validation script to check if required fields are filled in and the filters, if any, match */ $this->createValidationScript($fields); /* check out the model */ $this->_model->checkOut(); $class = SPLoader::loadView('entry'); $view = new $class($this->template); $view->assign($this->_model, 'entry'); $cache = Sobi::Reg('editcache'); /* get the categories */ if (isset($cache) && isset($cache['entry_parent'])) { $cats = explode(',', $cache['entry_parent']); } else { $cats = $this->_model->getCategories(true); } if (count($cats)) { $tCats = array(); foreach ($cats as $cid) { $tCats2 = SPFactory::config()->getParentPath((int) $cid, true); if (is_array($tCats2) && count($tCats2)) { $tCats[] = implode(Sobi::Cfg('string.path_separator', ' > '), $tCats2); } } if (count($tCats)) { $view->assign(implode("\n", $tCats), 'parent_path'); } $view->assign(implode(", ", $cats), 'parents'); } else { $parent = $sid == Sobi::Reg('current_section') ? 0 : $sid; if ($parent) { $view->assign(implode(Sobi::Cfg('string.path_separator', ' > '), SPFactory::config()->getParentPath($parent, true)), 'parent_path'); } $view->assign($parent, 'parents'); } $view->assign($this->_task, 'task'); $view->assign($fields, 'fields'); $view->assign($id, 'id'); $view->assign($id, 'sid'); $view->assign(SPFactory::user()->getCurrent(), 'visitor'); $view->setConfig($this->_tCfg, $this->template); $view->setTemplate($tplPackage . '.' . $this->templateType . '.' . ($this->template == 'add' ? 'edit' : $this->template)); $view->addHidden($sid ? $sid : SPRequest::sid(), 'pid'); $view->addHidden($id, 'sid'); $view->addHidden(SPRequest::int('pid') && SPRequest::int('pid') != $id ? SPRequest::int('pid') : Sobi::Section(), 'pid'); $view->addHidden('entry.submit', SOBI_TASK); Sobi::Trigger($this->name(), __FUNCTION__, array(&$view)); $view->display(); }
/** * Gets the data for a field and save it in the database * @param SPEntry $entry * @param string $request * @return bool */ public function saveData(&$entry, $request = 'POST') { if (!$this->enabled) { return false; } $data = $this->fetchData($this->multi ? SPRequest::arr($this->nid, array(), $request) : SPRequest::word($this->nid, null, $request), $request); $cdata = $this->verify($entry, $request, $data); $time = SPRequest::now(); $IP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER'); $uid = Sobi::My('id'); /* @var SPdb $db */ $db =& SPFactory::db(); /* if we are here, we can save these data */ if ($cdata) { if ($this->dependency) { return $this->saveDependencyField($entry, $data, $request); } $options = array(); $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['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'] = 0; $params['baseData'] = null; $params['copy'] = (int) (!$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); } catch (SPException $x) { Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } foreach ($data as $selected) { /* collect the needed params */ $params['baseData'] = strip_tags($db->escape($selected)); $options[] = array('fid' => $this->fid, 'sid' => $entry->get('id'), 'optValue' => $selected, 'copy' => $params['copy'], 'params' => null); } /* delete old selected values */ try { $db->delete('spdb_field_option_selected', array('fid' => $this->fid, 'sid' => $entry->get('id'), 'copy' => $params['copy'])); } catch (SPException $x) { Sobi::Error(__CLASS__, SPLang::e('CANNOT_DELETE_PREVIOUS_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } /* insert new selected value */ try { $db->insertArray('spdb_field_option_selected', $options); } catch (SPException $x) { Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_SELECTED_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } } elseif ($entry->get('version') > 1) { if (!$entry->get('approved')) { try { $db->update('spdb_field_option_selected', array('copy' => 1), array('fid' => $this->fid, 'sid' => $entry->get('id'))); } catch (SPException $x) { Sobi::Error(__CLASS__, SPLang::e('CANNOT_UPDATE_PREVIOUS_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } } else { /* delete old selected values */ try { $db->delete('spdb_field_option_selected', array('fid' => $this->fid, 'sid' => $entry->get('id'))); } catch (SPException $x) { Sobi::Error(__CLASS__, SPLang::e('CANNOT_DELETE_PREVIOUS_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } } } }
/** * */ public function display() { $tpl = SPLoader::path($this->_template . '_override', 'adm.template'); if (!$tpl) { $tpl = SPLoader::path($this->_template, 'adm.template'); } if (!$tpl) { $tpl = SPLoader::translatePath($this->_template, 'adm.template', false); Sobi::Error($this->name(), SPLang::e('TEMPLATE_DOES_NOT_EXISTS', $tpl), SPC::ERROR, 500, __LINE__, __FILE__); exit; } Sobi::Trigger('Display', $this->name(), array(&$this)); $action = $this->key('action'); echo "\n<!-- SobiPro output -->\n"; echo '<div class="SobiPro" id="SobiPro">' . "\n"; if ($this->_legacy) { echo SPFactory::AdmToolbar()->render(); echo $this->legacyMessages(); echo '<div class="row-fluid">' . "\n"; } echo $action ? "\n<form action=\"{$action}\" method=\"post\" name=\"adminForm\" id=\"SPAdminForm\" enctype=\"multipart/form-data\" accept-charset=\"utf-8\" >\n" : null; $prefix = null; if (!$this->_legacy) { $prefix = 'SP_'; } include $tpl; if (count($this->_hidden)) { $this->_hidden[SPFactory::mainframe()->token()] = 1; $this->_hidden['spsid'] = microtime(true) + Sobi::My('id') * mt_rand(5, 15) / mt_rand(5, 15); foreach ($this->_hidden as $name => $value) { echo "\n<input type=\"hidden\" name=\"{$name}\" id=\"{$prefix}{$name}\" value=\"{$value}\"/>"; } } echo $action ? "\n</form>\n" : null; if ($this->_legacy) { echo '</div>' . "\n"; } echo '</div>' . "\n"; echo "\n<!-- SobiPro output end -->\n"; Sobi::Trigger('AfterDisplay', $this->name()); }
/** * Gets the data for a field and save it in the database * @param SPEntry $entry * @param string $request * @return bool */ public function saveData(&$entry, $request = 'POST') { if (!$this->enabled) { return false; } $data = $this->verify($entry, $request); $time = SPRequest::now(); $IP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER'); $uid = Sobi::My('id'); /* if we are here, we can save these data */ /* @var SPdb $db */ $db =& SPFactory::db(); if ($this->allowHtml) { /* filter data */ if (count($this->allowedAttributes)) { SPRequest::setAttributesAllowed($this->allowedAttributes); } if (count($this->allowedTags)) { SPRequest::setTagsAllowed($this->allowedTags); } $data = SPRequest::string($this->nid, null, $this->allowHtml, $request); SPRequest::resetFilter(); if (!$this->editor && $this->maxLength && strlen($data) > $this->maxLength) { $data = substr($data, 0, $this->maxLength); } } else { $data = strip_tags($data); } /* collect the needed params */ $params = array(); $params['publishUp'] = $entry->get('publishUp'); $params['publishDown'] = $entry->get('publishDown'); $params['fid'] = $this->fid; $params['sid'] = $entry->get('id'); $params['section'] = Sobi::Reg('current_section'); $params['lang'] = Sobi::Lang(); $params['enabled'] = $entry->get('state'); $params['params'] = null; $params['options'] = null; $params['baseData'] = $data; $params['approved'] = $entry->get('approved'); $params['confirmed'] = $entry->get('confirmed'); /* if it is the first version, it is new entry */ if ($entry->get('version') == 1) { $params['createdTime'] = $time; $params['createdBy'] = $uid; $params['createdIP'] = $IP; } $params['updatedTime'] = $time; $params['updatedBy'] = $uid; $params['updatedIP'] = $IP; $params['copy'] = !$entry->get('approved'); if (Sobi::My('id') == $entry->get('owner')) { --$this->editLimit; } $params['editLimit'] = $this->editLimit; /* save it */ try { $db->insertUpdate('spdb_field_data', $params); } catch (SPException $x) { Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } /* if it wasn't edited in the default language, we have to try to insert it also for def lang */ if (Sobi::Lang() != Sobi::DefLang()) { $params['lang'] = Sobi::DefLang(); try { $db->insert('spdb_field_data', $params, true, true); } catch (SPException $x) { Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } } }
public function ProxyCount() { SPLoader::loadClass('env.browser'); SPLoader::loadClass('env.cookie'); $browser = SPBrowser::getInstance(); $this->nid = str_replace(array('.count', '.'), array(null, '_'), SPRequest::task()); $ident = $this->nid . '_' . SPRequest::int('eid'); $check = SPRequest::cmd('count_' . $ident, null, 'cookie'); if (!$check) { $data = array('date' => 'FUNCTION:NOW()', 'uid' => Sobi::My('id'), 'sid' => SPRequest::int('eid'), 'fid' => $this->nid, 'ip' => SPRequest::ip('REMOTE_ADDR', 0, 'SERVER'), 'section' => Sobi::Section(), 'browserData' => $browser->get('browser'), 'osData' => $browser->get('system'), 'humanity' => $browser->get('humanity')); SPCookie::set('count_' . $ident, 1, SPCookie::hours(2)); SPFactory::db()->insert('spdb_field_url_clicks', $data); } }
/** * @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; }
protected function entry($entry, $manager, $noId = false) { $en = array(); if (is_numeric($entry)) { $en = $this->cachedEntry($entry, $manager, $noId); } if (!is_array($en) || !count($en)) { if (is_numeric($entry)) { $entry = SPFactory::Entry($entry); } $en['id'] = $entry->get('id'); $en['nid'] = $entry->get('nid'); $en['name'] = array('_complex' => 1, '_data' => $entry->get('name'), '_attributes' => array('lang' => Sobi::Lang(false))); $en['url_array'] = array('title' => Sobi::Cfg('sef.alias', true) ? $entry->get('nid') : $entry->get('name'), 'pid' => $entry->get('primary'), 'sid' => $entry->get('id')); if (strstr(SPRequest::task(), 'search') || $noId || Sobi::Cfg('section.force_category_id', false) && SPRequest::sid() == Sobi::Section()) { $en['url'] = Sobi::Url(array('title' => Sobi::Cfg('sef.alias', true) ? $entry->get('nid') : $entry->get('name'), 'pid' => $entry->get('primary'), 'sid' => $entry->get('id'))); } else { $en['url'] = Sobi::Url(array('title' => Sobi::Cfg('sef.alias', true) ? $entry->get('nid') : $entry->get('name'), 'pid' => SPRequest::sid(), 'sid' => $entry->get('id'))); } if (Sobi::Cfg('list.entry_meta', true)) { $en['meta'] = array('description' => $entry->get('metaDesc'), 'keys' => $this->metaKeys($entry), 'author' => $entry->get('metaAuthor'), 'robots' => $entry->get('metaRobots')); } if ($manager || Sobi::My('id') && Sobi::My('id') == $entry->get('owner') && Sobi::Can('entry', 'edit', 'own', Sobi::Section())) { $en['edit_url'] = Sobi::Url(array('task' => 'entry.edit', 'pid' => SPRequest::sid(), 'sid' => $entry->get('id'))); } else { if (isset($en['edit_url'])) { unset($en['edit_url']); } } $en['edit_url_array'] = array('task' => 'entry.edit', 'pid' => SPRequest::sid(), 'sid' => $entry->get('id')); $en['created_time'] = $entry->get('createdTime'); $en['updated_time'] = $entry->get('updatedTime'); $en['valid_since'] = $entry->get('validSince'); $en['valid_until'] = $entry->get('validUntil'); $this->fixTimes($en); if ($entry->get('state') == 0) { $en['state'] = 'unpublished'; } else { if (strtotime($entry->get('validUntil')) != 0 && strtotime($entry->get('validUntil')) < time()) { $en['state'] = 'expired'; } elseif (strtotime($entry->get('validSince')) != 0 && strtotime($entry->get('validSince')) > time()) { $en['state'] = 'pending'; } else { $en['state'] = 'published'; } } $en['author'] = $entry->get('owner'); $en['counter'] = $entry->get('counter'); $en['approved'] = $entry->get('approved'); // $en[ 'confirmed' ] = $entry->get( 'confirmed' ); if (Sobi::Cfg('list.entry_cats', true)) { $cats = $entry->get('categories'); $categories = array(); if (count($cats)) { $cn = SPLang::translateObject(array_keys($cats), array('name', 'alias')); } foreach ($cats as $cid => $cat) { $categories[] = array('_complex' => 1, '_data' => SPLang::clean($cn[$cid]['value']), '_attributes' => array('lang' => Sobi::Lang(false), 'id' => $cat['pid'], 'position' => $cat['position'], 'url' => Sobi::Url(array('sid' => $cat['pid'], 'title' => Sobi::Cfg('sef.alias', true) ? $cat['alias'] : $cat['name'])))); } $en['categories'] = $categories; } $fields = $entry->getFields(); if (count($fields)) { // foreach ( $fields as $field ) { // if ( $field->enabled( 'vcard' ) && $field->get( 'id' ) != Sobi::Cfg( 'entry.name_field' ) ) { // $struct = $field->struct(); // $options = null; // if ( isset( $struct[ '_options' ] ) ) { // $options = $struct[ '_options' ]; // unset( $struct[ '_options' ] ); // } // $f[ $field->get( 'nid' ) ] = array( // '_complex' => 1, // '_data' => array( // 'label' => array( // '_complex' => 1, // '_data' => $field->get( 'name' ), // '_attributes' => array( 'lang' => Sobi::Lang( false ), 'show' => $field->get( 'withLabel' ) ) // ), // 'data' => $struct, // ), // '_attributes' => array( 'id' => $field->get( 'id' ), 'type' => $field->get( 'type' ), 'suffix' => $field->get( 'suffix' ), 'position' => $field->get( 'position' ), 'css_class' => ( strlen( $field->get( 'cssClass' ) ) ? $field->get( 'cssClass' ) : 'spField' ) ) // ); // if ( Sobi::Cfg( 'list.field_description', false ) ) { // $f[ $field->get( 'nid' ) ][ '_data' ][ 'description' ] = array( '_complex' => 1, '_xml' => 1, '_data' => $field->get( 'description' ) ); // } // if ( $options ) { // $f[ $field->get( 'nid' ) ][ '_data' ][ 'options' ] = $options; // } // if ( isset( $struct[ '_xml_out' ] ) && count( $struct[ '_xml_out' ] ) ) { // foreach ( $struct[ '_xml_out' ] as $k => $v ) // $f[ $field->get( 'nid' ) ][ '_data' ][ $k ] = $v; // } // } // } $en['fields'] = $this->fieldStruct($fields, 'vcard'); } SPFactory::cache()->addObj($entry, 'entry', $entry->get('id'))->addObj($en, 'entry_struct', $entry->get('id')); unset($en['url_array']); unset($en['edit_url_array']); unset($entry); } $en['counter'] = $this->getNonStaticData($en['id'], 'counter'); /* * this is te special case: * no matter what task we currently have - if someone called this we need the data for the V-Card * Soe we have to trigger all these plugins we need and therefore also fake the task */ $task = 'list.custom'; SPFactory::registry()->set('task', $task); Sobi::Trigger('List', ucfirst(__FUNCTION__), array(&$en)); return $en; }
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(); }
/** * @param string $eOrder * @param int $eLimit * @param int $eLimStart * @param bool $count * @param array $conditions * @param bool $entriesRecursive * @param int $pid * @return array */ public function getEntries($eOrder, $eLimit = null, $eLimStart = null, $count = false, $conditions = array(), $entriesRecursive = false, $pid = 0) { /* var SPDb $db */ $db = SPFactory::db(); $entries = array(); $eDir = 'asc'; $oPrefix = null; $conditions = is_array($conditions) ? $conditions : array(); /* get the ordering and the direction */ if (strstr($eOrder, '.')) { $eOr = explode('.', $eOrder); $eOrder = array_shift($eOr); $eDir = implode('.', $eOr); } $pid = $pid ? $pid : SPRequest::sid(); /* if sort by name, then sort by the name field */ if ($eOrder == 'name') { $eOrder = SPFactory::config()->nameField()->get('fid'); } if ($entriesRecursive) { $pids = $this->_model->getChilds('category', true); if (is_array($pids)) { $pids = array_keys($pids); } $pids[] = SPRequest::sid(); $conditions['sprl.pid'] = $pids; } else { $conditions['sprl.pid'] = $pid; } if ($pid == -1) { unset($conditions['sprl.pid']); } /* sort by field */ if (strstr($eOrder, 'field_')) { static $field = null; $specificMethod = false; if (!$field) { try { $fType = $db->select('fieldType', 'spdb_field', array('nid' => $eOrder, 'section' => Sobi::Section()))->loadResult(); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('CANNOT_DETERMINE_FIELD_TYPE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } if ($fType) { $field = SPLoader::loadClass('opt.fields.' . $fType); } } if ($field && method_exists($field, 'customOrdering')) { $table = null; $oPrefix = null; $specificMethod = call_user_func_array(array($field, 'customOrdering'), array(&$table, &$conditions, &$oPrefix, &$eOrder, &$eDir)); } elseif ($field && method_exists($field, 'sortBy')) { $table = null; $oPrefix = null; $specificMethod = call_user_func_array(array($field, 'sortBy'), array(&$table, &$conditions, &$oPrefix, &$eOrder, &$eDir)); } if (!$specificMethod) { $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.nid'] = $eOrder; $eOrder = 'baseData.' . $eDir; } } elseif (strstr($eOrder, 'counter')) { $table = $db->join(array(array('table' => 'spdb_object', 'as' => 'spo', 'key' => 'id'), array('table' => 'spdb_relations', 'as' => 'sprl', 'key' => array('spo.id', 'sprl.id')), array('table' => 'spdb_counter', 'as' => 'spcounter', 'key' => array('spo.id', 'spcounter.sid')))); $oPrefix = 'spo.'; $conditions['spo.oType'] = 'entry'; if (strstr($eOrder, '.')) { $cOrder = explode('.', $eOrder); $eOrder = 'spcounter.counter.' . $cOrder[1]; } else { $eOrder = 'spcounter.counter.desc'; } } else { $table = $db->join(array(array('table' => 'spdb_relations', 'as' => 'sprl', 'key' => 'id'), array('table' => 'spdb_object', 'as' => 'spo', 'key' => 'id'))); $conditions['spo.oType'] = 'entry'; $eOrder = $eOrder . '.' . $eDir; $oPrefix = 'spo.'; if (strstr($eOrder, 'valid')) { $eOrder = $oPrefix . $eOrder; } } /* check user permissions for the visibility */ if (Sobi::My('id')) { $this->userPermissionsQuery($conditions, $oPrefix); if (isset($conditions[$oPrefix . 'state']) && $conditions[$oPrefix . 'state']) { $conditions['sprl.copy'] = 0; } } else { $conditions = array_merge($conditions, array($oPrefix . 'state' => '1', '@VALID' => $db->valid($oPrefix . 'validUntil', $oPrefix . 'validSince'))); $conditions['sprl.copy'] = '0'; } try { $results = $db->select($oPrefix . 'id', $table, $conditions, $eOrder, $eLimit, $eLimStart, true)->loadResultArray(); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } Sobi::Trigger($this->name(), 'AfterGetEntries', array(&$results, $count)); if (count($results) && !$count) { 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; } } if ($count) { Sobi::SetUserData('currently-displayed-entries', $results); return $results; } return $entries; }
/** * 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; }
/** * Gets the data for a field and save it in the database * @param SPEntry $entry * @param string $request * @throws SPException * @return bool */ public function saveData(&$entry, $request = 'POST') { if (!$this->enabled) { return false; } $del = SPRequest::bool($this->nid . '_delete', false, $request); $fileSize = SPRequest::file($this->nid, 'size'); $cropped = null; static $store = null; $cache = false; if ($store == null) { $store = SPFactory::registry()->get('requestcache_stored'); } if (is_array($store) && isset($store[$this->nid])) { if (!strstr($store[$this->nid], 'file://') && !strstr($store[$this->nid], 'directory://')) { $data = $store[$this->nid]; $cache = true; $orgName = SPRequest::file($this->nid, 'name', $request); } else { SPRequest::set($this->nid, $store[$this->nid]); $orgName = SPRequest::file($this->nid, 'name'); $data = SPRequest::file($this->nid, 'tmp_name'); } } else { $data = SPRequest::file($this->nid, 'tmp_name'); $orgName = SPRequest::file($this->nid, 'name'); } $sPath = $this->parseName($entry, $orgName, $this->savePath); $path = SPLoader::dirPath($sPath, 'root', false); /** Wed, Oct 15, 2014 13:51:03 * Implemented a cropper with Ajax checker. * This is the actual method to get those files * Other methods left for BC * */ if (!$data) { $directory = SPRequest::string($this->nid, $store[$this->nid], false, $request); if (strlen($directory)) { list($data, $dirName, $files, $coordinates) = $this->getAjaxFiles($directory); if (count($files)) { foreach ($files as $file) { if ($file == '.') { continue; } if ($file == '..') { continue; } if (strpos($file, 'icon_') !== false) { continue; } if (strpos($file, 'resized_') !== false) { continue; } if (strpos($file, 'cropped_') !== false) { $cropped = $dirName . $file; SPFs::upload($cropped, $path . basename($cropped)); continue; } if (strpos($file, '.var') !== false) { continue; } $fileSize = filesize($dirName . $file); $orgName = $file; } } if (strlen($coordinates)) { $coordinates = json_decode(SPLang::clean($coordinates), true); /** @var SPImage $croppedImage */ $croppedImage = SPFactory::Instance('base.fs.image', $dirName . $orgName); $croppedImage->crop($coordinates['width'], $coordinates['height'], $coordinates['x'], $coordinates['y']); $cropped = 'cropped_' . $orgName; $croppedImage->saveAs($path . $cropped); } $data = strlen($cropped) ? $cropped : $dirName . $file; } } $files = array(); /* if we have an image */ if ($data && $orgName) { if ($fileSize > $this->maxSize) { throw new SPException(SPLang::e('FIELD_IMG_TOO_LARGE', $this->name, $fileSize, $this->maxSize)); } if ($cropped) { SPFs::upload($dirName . $orgName, $path . $orgName); } /** * @var SPImage $orgImage */ if ($cache) { $orgImage = SPFactory::Instance('base.fs.image', $data); $orgImage->move($path . $orgName); } else { $orgImage = SPFactory::Instance('base.fs.image'); $nameArray = explode('.', $orgName); $ext = strtolower(array_pop($nameArray)); $nameArray[] = $ext; $orgName = implode('.', $nameArray); if ($cropped) { $orgImage->upload($dirName . $data, $path . basename($data)); } else { $orgImage->upload($dirName . $orgName, $path . $orgName); } } $files['data']['exif'] = $orgImage->exif(); $this->cleanExif($files['data']['exif']); if (Sobi::Cfg('image_field.fix_rotation', true)) { if ($orgImage->fixRotation()) { $orgImage->save(); } } if ($this->resize) { $image = clone $orgImage; try { $image->resample($this->resizeWidth, $this->resizeHeight, false); $files['image'] = $this->parseName($entry, $orgName, $this->imageName, true); $image->saveAs($path . $files['image']); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); $image->delete(); throw new SPException(SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage())); } } if ($this->generateThumb) { $thumb = clone $orgImage; try { $thumb->resample($this->thumbWidth, $this->thumbHeight, false); $files['thumb'] = $this->parseName($entry, $orgName, $this->thumbName, true); $thumb->saveAs($path . $files['thumb']); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); $thumb->delete(); throw new SPException(SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage())); } } $ico = clone $orgImage; try { $icoSize = explode(':', Sobi::Cfg('image.ico_size', '80:80')); $ico->resample($icoSize[0], $icoSize[1], false); $files['ico'] = $this->parseName($entry, strtolower($orgName), 'ico_{orgname}', true); $ico->saveAs($path . $files['ico']); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); $ico->delete(); throw new SPException(SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage())); } if (!$this->keepOrg) { $orgImage->delete(); } else { $files['original'] = $this->parseName($entry, $orgName, '{orgname}', true); } foreach ($files as $i => $file) { if ($i == 'data') { continue; } $files[$i] = $sPath . $file; } } elseif ($del) { $this->delImgs(); $files = array(); } else { return true; } /* @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); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('CANNOT_SAVE_FIELDS_DATA_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } }