예제 #1
1
 protected function menu(&$data)
 {
     if (Sobi::Cfg('general.top_menu', true)) {
         $data['menu'] = array('front' => array('_complex' => 1, '_data' => Sobi::Reg('current_section_name'), '_attributes' => array('lang' => Sobi::Lang(false), 'url' => Sobi::Url(array('sid' => Sobi::Section())))));
         if (Sobi::Can('section.search')) {
             $data['menu']['search'] = array('_complex' => 1, '_data' => Sobi::Txt('MN.SEARCH'), '_attributes' => array('lang' => Sobi::Lang(false), 'url' => Sobi::Url(array('task' => 'search', 'sid' => Sobi::Section()))));
         }
         if (Sobi::Can('entry', 'add', 'own', Sobi::Section())) {
             $data['menu']['add'] = array('_complex' => 1, '_data' => Sobi::Txt('MN.ADD_ENTRY'), '_attributes' => array('lang' => Sobi::Lang(false), 'url' => Sobi::Url(array('task' => 'entry.add', 'sid' => SPRequest::sid()))));
         }
     }
 }
예제 #2
0
 public static function __callStatic($name, $args)
 {
     if (defined('SOBIPRO_ADM')) {
         return call_user_func_array(array('self', '_' . $name), $args);
     } else {
         static $className = false;
         if (!$className) {
             $package = Sobi::Reg('current_template');
             if (SPFs::exists(Sobi::FixPath($package . '/input.php'))) {
                 $path = Sobi::FixPath($package . '/input.php');
                 ob_start();
                 $content = file_get_contents($path);
                 $class = array();
                 preg_match('/\\s*(class)\\s+(\\w+)/', $content, $class);
                 if (isset($class[2])) {
                     $className = $class[2];
                 } else {
                     Sobi::Error('Custom Input Class', SPLang::e('Cannot determine class name in file %s.', str_replace(SOBI_ROOT, null, $path)), SPC::WARNING, 0);
                     return false;
                 }
                 require_once $path;
             } else {
                 $className = true;
             }
         }
         if (is_string($className) && method_exists($className, $name)) {
             return call_user_func_array(array($className, $name), $args);
         } else {
             return call_user_func_array(array('self', '_' . $name), $args);
         }
     }
 }
예제 #3
0
 /**
  * @param int $sid
  * @return void
  */
 public function loadData($sid)
 {
     if ($this->_off) {
         return null;
     }
     $this->sid = $sid;
     $fdata = Sobi::Reg('fields_data_' . $sid, array());
     $this->suffix = SPLang::clean($this->suffix);
     if ($sid && count($fdata) && isset($fdata[$this->id])) {
         $this->_fData = $fdata[$this->id];
         $this->lang = $this->_fData->lang;
         $this->_rawData = $this->_fData->baseData;
         $this->_data = $this->_fData->baseData;
         // if the field has own method we have to re-init
         $this->checkMethod('loadData');
         if ($this->_type && method_exists($this->_type, 'loadData')) {
             $this->_type->loadData($sid, $this->_fData, $this->_rawData, $this->_data);
         }
         if ($this->editLimit > 0 && is_numeric($this->_fData->editLimit)) {
             $this->editLimit = $this->_fData->editLimit;
         } elseif ($this->editLimit < 0) {
             $this->editLimit = 2;
         } else {
             $this->editLimit = 2;
         }
         // if the limit has been reached - this field cannot be required
         if (!Sobi::Can('entry.manage.*') && $this->editLimit < 1 && in_array(SPRequest::task(), array('entry.save', 'entry.edit', 'entry.submit'))) {
             $this->required = false;
             $this->enabled = false;
             $this->_off = true;
         }
     } else {
         $fdata = Sobi::Reg('editcache');
         if (is_array($fdata) && isset($fdata[$this->nid])) {
             $this->_data = $fdata[$this->nid];
             $this->_rawData = $fdata[$this->nid];
         } else {
             $this->checkMethod('loadData');
             if ($this->_type && method_exists($this->_type, 'loadData')) {
                 $this->_type->loadData($sid, $this->_fData, $this->_rawData, $this->_data);
             } else {
                 $this->_rawData = SPFactory::db()->select('baseData', 'spdb_field_data', array('sid' => $this->sid, 'fid' => $this->fid, 'lang' => Sobi::Lang(false)))->loadResult();
             }
         }
     }
     if (!$this->isFree && SPRequest::task() == 'entry.edit') {
         /* in case we are editing - check if this field wasn't paid already */
         SPLoader::loadClass('services.payment');
         if (SPPayment::check($sid, $this->id)) {
             $this->fee = 0;
             $this->isFree = true;
         }
     }
 }
예제 #4
0
파일: config.php 프로젝트: pelloq1/SobiPro
 protected function initIcons()
 {
     if (!count($this->_icons)) {
         if (Sobi::Reg('current_template') && SPFs::exists(Sobi::Reg('current_template') . '/js/icons.json')) {
             $this->_icons = json_decode(Sobi::Reg('current_template') . '/js/icons.json', true);
         } else {
             $this->_icons = json_decode(SPFs::read(SOBI_PATH . '/etc/icons.json'), true);
         }
     }
 }
예제 #5
0
 private function getLink($button)
 {
     $link = '#';
     if (isset($button['type'])) {
         switch ($button['type']) {
             case 'help':
                 $link = 'https://www.sigsiu.net/help_screen/' . Sobi::Reg('help_task', SPRequest::task());
                 break;
             case 'url':
                 if (isset($button['sid']) && $button['sid'] == 'true') {
                     $link = Sobi::Url(array('task' => $button['task'], 'sid' => SPRequest::sid('request', SPRequest::int('pid'), true)));
                 } else {
                     $link = Sobi::Url($button['task'] ? $button['task'] : $button['url']);
                 }
                 break;
         }
     }
     return $link;
 }
예제 #6
0
 /**
  * (non-PHPdoc)
  * @see Site/lib/models/SPDBObject#save()
  */
 public function save($request = 'post')
 {
     $this->loadFields(Sobi::Section(), true);
     // Thu, Feb 19, 2015 12:12:47 - it should be actually "beforeSave"
     Sobi::Trigger($this->name(), 'Before' . ucfirst(__FUNCTION__), array($this->id));
     /* save the base object data */
     /* @var SPdb $db */
     $db = SPFactory::db();
     $db->transaction();
     if (!$this->nid || SPRequest::task() == 'entry.clone') {
         $this->nid = SPRequest::string($this->nameField, null, false, $request);
         $this->nid = $this->createAlias();
         $this->name = $this->nid;
     }
     if (Sobi::Cfg('entry.publish_limit', 0) && !defined('SOBI_ADM_PATH')) {
         SPRequest::set('entry_createdTime', 0, $request);
         SPRequest::set('entry_validSince', 0, $request);
         SPRequest::set('entry_validUntil', 0, $request);
         $this->validUntil = gmdate('Y-m-d H:i:s', time() + Sobi::Cfg('entry.publish_limit', 0) * 24 * 3600);
     }
     $preState = Sobi::Reg('object_previous_state');
     parent::save($request);
     $nameField = $this->nameField();
     /* get the fields for this section */
     foreach ($this->fields as $field) {
         /* @var $field SPField */
         try {
             if ($field->enabled('form', $preState['new'])) {
                 $field->saveData($this, $request);
             } else {
                 $field->finaliseSave($this, $request);
             }
             if ($field->get('id') == $nameField) {
                 /* get the entry name */
                 $this->name = $field->getRaw();
                 /* save the nid (name id) of the field where the entry name is saved */
                 $this->nameField = $field->get('nid');
             }
         } catch (SPException $x) {
             if (SPRequest::task() != 'entry.clone') {
                 $db->rollback();
                 throw new SPException(SPLang::e('CANNOT_SAVE_FIELS_DATA', $x->getMessage()));
             } else {
                 Sobi::Error($this->name(), SPLang::e('CANNOT_SAVE_FIELS_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
             }
         }
     }
     $values = array();
     /* get categories */
     $cats = Sobi::Reg('request_categories');
     if (!count($cats)) {
         $cats = SPRequest::arr('entry_parent', SPFactory::registry()->get('request_categories', array()), $request);
     }
     /* by default it should be comma separated string */
     if (!count($cats)) {
         $cats = SPRequest::string('entry_parent', null, $request);
         if (strlen($cats) && strpos($cats, ',')) {
             $cats = explode(',', $cats);
             foreach ($cats as $i => $cat) {
                 $c = (int) trim($cat);
                 if ($c) {
                     $cats[$i] = $c;
                 } else {
                     unset($cats[$i]);
                 }
             }
         } elseif (strlen($cats)) {
             $cats = array((int) $cats);
         }
     }
     if (is_array($cats) && count($cats)) {
         foreach ($cats as $i => $v) {
             if (!$v) {
                 unset($cats[$i]);
             }
         }
     }
     if (is_array($cats) && count($cats)) {
         /* get the ordering in these categories */
         try {
             $db->select('pid, MAX(position)', 'spdb_relations', array('pid' => $cats, 'oType' => 'entry'), null, 0, 0, false, 'pid');
             $cPos = $db->loadAssocList('pid');
             $currPos = $db->select(array('pid', 'position'), 'spdb_relations', array('id' => $this->id, 'oType' => 'entry'))->loadAssocList('pid');
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
         /* set the right position */
         foreach ($cats as $i => $cat) {
             $copy = 0;
             if (!$this->approved) {
                 $copy = isset($this->categories[$cats[$i]]) ? 0 : 1;
             } else {
                 $db->delete('spdb_relations', array('id' => $this->id, 'oType' => 'entry'));
             }
             if (isset($currPos[$cat])) {
                 $pos = $currPos[$cat]['position'];
             } else {
                 $pos = isset($cPos[$cat]) ? $cPos[$cat]['MAX(position)'] : 0;
                 $pos++;
             }
             $values[] = array('id' => $this->id, 'pid' => $cats[$i], 'oType' => 'entry', 'position' => $pos, 'validSince' => $this->validSince, 'validUntil' => $this->validUntil, 'copy' => $copy);
         }
         try {
             $db->insertArray('spdb_relations', $values, true);
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
     } elseif (!count($this->categories)) {
         throw new SPException(SPLang::e('MISSING_CAT'));
     }
     /* trigger possible state changes */
     if ($preState['approved'] != $this->approved) {
         if ($this->approved) {
             $this->approveFields(true);
             // it's being done by the method above - removing
             //Sobi::Trigger( $this->name(), 'AfterApprove', array( $this->id, $this->approved ) );
         }
     }
     if ($preState['state'] != $this->state) {
         Sobi::Trigger($this->name(), 'AfterChangeState', array($this->id, $this->state));
     }
     SPFactory::cache()->purgeSectionVars();
     SPFactory::cache()->deleteObj('entry', $this->id);
     if (count($cats)) {
         foreach ($cats as $cat) {
             SPFactory::cache()->deleteObj('category', $cat);
         }
     }
     Sobi::Trigger($this->name(), 'After' . ucfirst($preState['new'] ? __FUNCTION__ : 'Update'), array(&$this));
 }
예제 #7
0
 /**
  * init tree
  * @param int $sid - sobi id / section id
  * @param int $current - actually displayed category
  * @return string $tree
  */
 public function init($sid, $current = 0)
 {
     $head =& SPFactory::header();
     if (defined('SOBIPRO_ADM')) {
         $head->addCssFile('tree', true);
     } else {
         if (Sobi::Reg('current_template_path', null) && SPFs::exists(Sobi::Reg('current_template_path') . 'css/tree.css')) {
             $head->addCssFile('absolute.' . Sobi::Reg('current_template_path') . 'css/tree.css');
         } else {
             $head->addCssFile('tree');
         }
     }
     $tree = null;
     $matrix = null;
     $this->_sid = $sid;
     if ($current) {
         $this->startScript($current);
     }
     $section = $this->getSection($sid);
     $sectionLink = $this->parseLink($section);
     $sectionName = $section->get('name');
     $childs = $this->getChilds($sid);
     //		if( count( $cats ) ) {
     //			foreach ( $cats as $i => $cat ) {
     //				$childs[ $cat->get( 'name' ).$i ] = $cat;
     //			}
     //		}
     //		ksort( $childs );
     $countNodes = count($childs, 0);
     $lastNode = 0;
     $tree .= "\n\t<{$this->_tag} class=\"sigsiuTree {$this->_id}SigsiuTree\">";
     $tree .= "\n\t\t<{$this->_tag} class=\"sigsiuTreeNode\" id=\"{$this->_id}stNode0\">";
     if (!in_array($sid, $this->_disabled)) {
         $tree .= "<a href=\"{$sectionLink}\" id=\"{$this->_id}_imgFolderUrl0\"><img id=\"{$this->_id}0\" src=\"{$this->_images['root']}\" alt=\"{$sectionName}\"/></a>";
     } else {
         $tree .= "<img id=\"{$this->_id}0\" src=\"{$this->_images['root']}\" alt=\"{$sectionName}\"/>";
     }
     if (!in_array($sid, $this->_disabled)) {
         $tree .= "<a href=\"{$sectionLink}\"  rel=\"{$sid}\" data-sid=\"{$sid}\" class=\"treeNode\" id=\"{$this->_id}_CatUrl0\">{$sectionName}</a>";
     } else {
         $tree .= $sectionName;
     }
     $tree .= "</{$this->_tag}>";
     $tree .= "\n\t\t<{$this->_tag} id=\"{$this->_id}\" class=\"clip\" style=\"display: block;\">";
     if (count($childs)) {
         foreach ($childs as $cat) {
             $countNodes--;
             // clean string produces htmlents and these are invalid in XML
             $catName = $cat->get('name');
             $hasChilds = count($cat->getChilds('category'));
             $cid = $cat->get('id');
             $url = $this->parseLink($cat);
             $disabled = in_array($cid, $this->_disabled) ? true : false;
             $tree .= "\n\t\t\t<{$this->_tag} class=\"sigsiuTreeNode\" id=\"{$this->_id}stNode{$cid}\">";
             if ($hasChilds) {
                 if ($countNodes == 0 && !$disabled) {
                     $lastNode = $cid;
                     $tree .= "\n\t\t\t\t\t<a href=\"javascript:{$this->_id}_stmExpand( {$cid}, 0, {$this->_pid} );\" id=\"{$this->_id}_imgUrlExpand{$cid}\">\n\t\t\t\t\t\t<img src=\"{$this->_images['plusBottom']}\" id=\"{$this->_id}_imgExpand{$cid}\"  style=\"border-style:none;\" alt=\"expand\"/>\n\t\t\t\t\t</a>";
                     $matrix .= "\n{$this->_id}_stmImgMatrix[ {$cid} ] = new Array( 'plusBottom' );";
                 } elseif (!$disabled) {
                     $tree .= "\n\t\t\t\t\t<a href=\"javascript:{$this->_id}_stmExpand( {$cid}, 0, {$this->_pid} );\" id=\"{$this->_id}_imgUrlExpand{$cid}\">\n\t\t\t\t\t\t<img src=\"{$this->_images['plus']}\" id=\"{$this->_id}_imgExpand{$cid}\"  style=\"border-style:none;\" alt=\"expand\"/>\n\t\t\t\t\t</a>";
                     $matrix .= "\n{$this->_id}_stmImgMatrix[ {$cid} ] = new Array( 'plus' );";
                 } else {
                     $tree .= "\n\t\t\t\t\t<img src=\"{$this->_images['join']}\" id=\"{$this->_id}_imgExpand{$cid}\" style=\"border-style:none;\" alt=\"expand\"/>";
                     $matrix .= "\n{$this->_id}_stmImgMatrix[ {$cid} ] = new Array( 'plus' );";
                 }
             } else {
                 if ($countNodes == 0 && !$disabled) {
                     $lastNode = $cid;
                     $tree .= "\n\t\t\t\t\t<img src=\"{$this->_images['joinBottom']}\" style=\"border-style:none;\" id=\"{$this->_id}_imgJoin{$cid}\" alt=\"\"/>";
                     $matrix .= "\n{$this->_id}_stmImgMatrix[ {$cid} ] = new Array( 'join' );";
                 } elseif (!$disabled) {
                     $tree .= "\n\t\t\t\t\t<img src=\"{$this->_images['join']}\" style=\"border-style:none;\" id=\"{$this->_id}_imgJoin{$cid}\" alt=\"\"/>";
                     $matrix .= "\n{$this->_id}_stmImgMatrix[ {$cid} ] = new Array( 'joinBottom' );";
                 } else {
                     $tree .= "\n\t\t\t\t\t<img src=\"{$this->_images['joinBottom']}\" id=\"{$this->_id}_imgExpand{$cid}\" style=\"border-style:none;\" alt=\"expand\"/>";
                     $matrix .= "\n{$this->_id}_stmImgMatrix[ {$cid} ] = new Array( 'plus' );";
                 }
             }
             if (!$disabled) {
                 $tree .= "\n\t\t\t\t\t<a href=\"{$url}\" id=\"{$this->_id}_imgFolderUrl{$cid}\">\n\t\t\t\t\t\t<img src=\"{$this->_images['folder']}\" style=\"border-style:none;\" id=\"{$this->_id}_imgFolder{$cid}\" alt=\"\"/>\n\t\t\t\t\t</a>\n\t\t\t\t\t<a href=\"{$url}\" rel=\"{$cid}\" data-sid=\"{$cid}\" class=\"treeNode\" id=\"{$this->_id}_CatUrl{$cid}\">\n\t\t\t\t\t\t{$catName}\n\t\t\t\t\t</a>";
             } else {
                 $tree .= "\n\t\t\t\t\t<img src=\"{$this->_images['disabled']}\" style=\"border-style:none;\" id=\"{$this->_id}_imgFolder{$cid}\" alt=\"\"/>\n\t\t\t\t\t{$catName}\n\t\t\t\t\t</a>";
             }
             $tree .= "\n\t\t\t</{$this->_tag}>";
             if ($hasChilds && !$disabled) {
                 $tree .= "\n\t\t\t<{$this->_tag} id=\"{$this->_id}_childsContainer{$cid}\" class=\"clip\" style=\"display: block; display:none;\"></{$this->_tag}>";
             }
         }
     }
     $tree .= "\n\t\t</{$this->_tag}>";
     $tree .= "\n\t</{$this->_tag}>\n\n";
     $this->createScript($lastNode, $childs, $matrix, $head);
     $this->tree = $tree;
 }
예제 #8
0
 /**
  * @param string $action
  * @param string $subject
  * @param mixed $params
  * @return bool
  */
 public function trigger($action, $subject = null, $params = array())
 {
     static $actions = array();
     static $count = 0;
     $action = ucfirst($action) . ucfirst($subject);
     $action = str_replace('SP', null, $action);
     $task = Sobi::Reg('task', SPRequest::task());
     $task = strlen($task) ? $task : '*';
     if (strstr($task, '.')) {
         $t = explode('.', $task);
         $task = $t[0] . '.' . $t[1];
     }
     /**
      * Joomla! -> Unable to load renderer class
      */
     if ($action == 'ParseContent' && SPRequest::cmd('format') == 'raw') {
         return;
     }
     $actions[$count++] = $action;
     // this always
     SPFactory::mainframe()->trigger($action, $params);
     //	    SPConfig::debOut( $action, false, false, true );
     /**
      * An Application should not trigger other applications
      * Apps are running non parallel
      * Exception, if an app will an action to be
      * triggered this action has to begin with App
      */
     /*
      * it's important to write comments in own code ..
      * It may be also helpful to read own comments sometimes
      * How the hell "has to begin with App" == substr( $action, 0, 3 ) != 'App' ) ???
      * ========================================================================================
      * Note for intelligent people: it caused for example that the payment method wasn't delivered to the notification App
      */
     if ($count < 2 || substr($action, 0, 3) == 'App') {
         /* load all plugins having method for this action */
         if (!isset($this->_actions[$task])) {
             $this->load($task);
         }
         /* if there were any plugin for this action, check if these are loaded */
         if (count($this->_actions[$task])) {
             foreach ($this->_actions[$task] as $plugin) {
                 /* in case this plugin wasn't initialised */
                 if (!isset($this->_plugins[$plugin])) {
                     $this->initPlugin($plugin);
                 }
                 /* call the method */
                 if (isset($this->_plugins[$plugin]) && $this->_plugins[$plugin]->provide($action)) {
                     call_user_func_array(array($this->_plugins[$plugin], $action), $params);
                 }
             }
         }
     }
     //	    SPConfig::debOut( $action, true, false, true );
     unset($actions[$count]);
     $count--;
     return true;
 }
예제 #9
0
 /**
  * Gets the data for a field and save it in the database
  * @param SPEntry $entry
  * @param string $request
  * @throws SPException
  * @return bool
  */
 public function saveData(&$entry, $request = 'POST')
 {
     if (!$this->enabled) {
         return false;
     }
     if ($this->method == 'fixed') {
         $fixed = $this->fixedCid;
         $fixed = explode(',', $fixed);
         $data = array();
         if (count($fixed)) {
             foreach ($fixed as $cid) {
                 $data[] = trim($cid);
             }
         }
         if (!count($data)) {
             throw new SPException(SPLang::e('FIELD_CC_FIXED_CID_NOT_SELECTED', $this->name));
         }
     } else {
         $data = $this->verify($entry, $request);
     }
     $time = SPRequest::now();
     $IP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER');
     $uid = Sobi::My('id');
     /* if we are here, we can save these data */
     /* @var SPdb $db */
     $db = SPFactory::db();
     /* collect the needed params */
     $params = array();
     $params['publishUp'] = $entry->get('publishUp');
     $params['publishDown'] = $entry->get('publishDown');
     $params['fid'] = $this->fid;
     $params['sid'] = $entry->get('id');
     $params['section'] = Sobi::Reg('current_section');
     $params['lang'] = Sobi::Lang();
     $params['enabled'] = $entry->get('state');
     $params['params'] = null;
     $params['options'] = null;
     $params['baseData'] = SPConfig::serialize($data);
     $params['approved'] = $entry->get('approved');
     $params['confirmed'] = $entry->get('confirmed');
     /* if it is the first version, it is new entry */
     if ($entry->get('version') == 1) {
         $params['createdTime'] = $time;
         $params['createdBy'] = $uid;
         $params['createdIP'] = $IP;
     }
     $params['updatedTime'] = $time;
     $params['updatedBy'] = $uid;
     $params['updatedIP'] = $IP;
     $params['copy'] = !$entry->get('approved');
     if (Sobi::My('id') == $entry->get('owner')) {
         --$this->editLimit;
     }
     $params['editLimit'] = $this->editLimit;
     /* save it */
     try {
         /* Notices:
          * If it was new entry - insert
          * If it was an edit and the field wasn't filled before - insert
          * If it was an edit and the field was filled before - update
          *     " ... " and changes are not autopublish it should be insert of the copy .... but
          * " ... " if a copy already exist it is update again
          * */
         $db->insertUpdate('spdb_field_data', $params);
     } catch (SPException $x) {
         Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     /* if it wasn't edited in the default language, we have to try to insert it also for def lang */
     if (Sobi::Lang() != Sobi::DefLang()) {
         $params['lang'] = Sobi::DefLang();
         try {
             $db->insert('spdb_field_data', $params, true, true);
         } catch (SPException $x) {
             Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
     }
     /** Last important thing - join selected categories  */
     $cats = SPFactory::registry()->get('request_categories', array());
     $cats = array_unique(array_merge($cats, $data));
     SPFactory::registry()->set('request_categories', $cats);
     if ($this->method == 'select' && $this->isPrimary) {
         $db->update('spdb_object', array('parent' => $data[0]), array('id' => $params['sid']));
     }
 }
예제 #10
0
 /**
  * List all fields in this section
  */
 private function listFields()
 {
     /* @var SPdb $db */
     $ord = $this->parseOrdering('forder', 'position.asc');
     SPLoader::loadClass('html.input');
     Sobi::ReturnPoint();
     /* create menu */
     $sid = Sobi::Reg('current_section');
     $menu = SPFactory::Instance('views.adm.menu', 'field.list', $sid);
     $cfg = SPLoader::loadIniFile('etc.adm.section_menu');
     Sobi::Trigger('Create', 'AdmMenu', array(&$cfg));
     if (count($cfg)) {
         foreach ($cfg as $section => $keys) {
             $menu->addSection($section, $keys);
         }
     }
     Sobi::Trigger('AfterCreate', 'AdmMenu', array(&$menu));
     /* create new SigsiuTree */
     $tree = SPLoader::loadClass('mlo.tree');
     $tree = new $tree(Sobi::GetUserState('categories.order', 'corder', 'position.asc'));
     /* set link */
     $tree->setHref(Sobi::Url(array('sid' => '{sid}')));
     $tree->setId('menuTree');
     /* set the task to expand the tree */
     $tree->setTask('category.expand');
     $tree->init($sid);
     /* add the tree into the menu */
     $menu->addCustom('AMN.ENT_CAT', $tree->getTree());
     try {
         $results = SPFactory::db()->select('*', 'spdb_field', array('section' => $sid), $ord)->loadObjectList();
     } catch (SPException $x) {
         //			SPConfig::debOut(SPFactory::db()->getQuery());
         Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     $fields = array();
     if (count($results)) {
         foreach ($results as $result) {
             $field = SPFactory::Model('field', true);
             $field->extend($result);
             $fields[] = $field;
         }
     }
     $fieldTypes = $this->getFieldTypes();
     $subMenu = array();
     foreach ($fieldTypes as $type => $group) {
         asort($group);
         $subMenu[] = array('label' => $type, 'element' => 'nav-header');
         foreach ($group as $t => $l) {
             $subMenu[] = array('type' => null, 'task' => 'field.add.' . $t, 'label' => $l, 'icon' => 'tasks', 'element' => 'button');
         }
     }
     SPFactory::View('field', true)->addHidden($sid, 'sid')->assign($fields, 'fields')->assign($subMenu, 'fieldTypes')->assign(Sobi::Section(true), 'section')->assign($menu, 'menu')->assign(Sobi::GetUserState('fields.order', 'forder', 'position.asc'), 'ordering')->assign($this->_task, 'task')->determineTemplate('field', 'list')->display();
 }
예제 #11
0
파일: cache.php 프로젝트: pelloq1/SobiPro
 /**
  */
 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('&nbsp;', '&#160;', $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());
         }
     }
 }
예제 #12
0
 /**
  * Show category chooser
  *
  */
 protected function chooser($menu = false)
 {
     $out = SPRequest::cmd('out', null);
     $exp = SPRequest::int('expand', 0);
     $multi = SPRequest::int('multiple', 0);
     $tpl = SPRequest::word('treetpl', null);
     /* load the SigsiuTree class */
     $tree = SPLoader::loadClass('mlo.tree');
     $ordering = defined('SOBI_ADM_PATH') ? Sobi::GetUserState('categories.order', 'corder', 'position.asc') : Sobi::Cfg('list.categories_ordering');
     /* create new instance */
     $tree = new $tree($ordering);
     /* set link */
     if ($menu) {
         $tree->setId('menuTree');
         if (defined('SOBIPRO_ADM')) {
             $link = Sobi::Url(array('sid' => '{sid}'), false, false, true);
         } else {
             $link = Sobi::Url(array('sid' => '{sid}'));
         }
     } else {
         $link = "javascript:SP_selectCat( '{sid}' )";
     }
     $tree->setHref($link);
     /* set the task to expand the tree */
     $tree->setTask('category.chooser');
     /* disable the category which is currently edited - category cannot be within it self */
     if (!$multi) {
         if (SPRequest::sid() != Sobi::Section()) {
             $tree->disable(SPRequest::sid());
         }
         $tree->setPid(SPRequest::sid());
     } else {
         $tree->disable(Sobi::Reg('current_section'));
     }
     /* case we extending existing tree */
     if ($out == 'xml' && $exp) {
         $pid = SPRequest::int('pid', 0);
         $pid = $pid ? $pid : SPRequest::sid();
         $tree->setPid($pid);
         $tree->disable($pid);
         $tree->extend($exp);
     } else {
         /* init the tree for the current section */
         $tree->init(Sobi::Reg('current_section'));
         /* load model */
         if (!$this->_model) {
             $this->setModel(SPLoader::loadModel('category'));
         }
         /* create new view */
         $class = SPLoader::loadView('category');
         $view = new $class();
         /* assign the task and the tree */
         $view->assign($this->_task, 'task');
         $view->assign($tree, 'tree');
         $view->assign($this->_model, 'category');
         /* select template to show */
         if ($tpl) {
             $view->setTemplate('category.' . $tpl);
         } elseif ($multi) {
             $view->setTemplate('category.mchooser');
         } else {
             $view->setTemplate('category.chooser');
         }
         Sobi::Trigger('Category', 'ChooserView', array(&$view));
         $view->chooser();
     }
 }
예제 #13
0
 /**
  * @return bool
  */
 private function routeObj()
 {
     try {
         $ctrl = SPFactory::Controller($this->_model->oType);
         if ($ctrl instanceof SPController) {
             $this->setController($ctrl);
             if ($this->_model->id == SPRequest::sid()) {
                 // just to use the pre-fetched entry
                 if ($this->_model->oType == 'entry') {
                     $e = SPFactory::Entry($this->_model->id);
                     // object has been stored anyway in the SPFactory::object method
                     // and also already initialized
                     // therefore it will be now rewritten and because the init flag is set to true
                     // the name is getting lost
                     // $e->extend( $this->_model );
                     $this->_ctrl->setModel($e);
                 } else {
                     $this->_ctrl->setModel(SPLoader::loadModel($this->_model->oType));
                     $this->_ctrl->extend($this->_model);
                 }
             } else {
                 $this->_ctrl->extend(SPFactory::object(SPRequest::sid()));
             }
             $this->_ctrl->setTask($this->_task);
         }
     } catch (SPException $x) {
         if (defined('SOBI_TESTS')) {
             Sobi::Error('CoreCtrl', SPLang::e('Cannot set controller. %s.', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         } else {
             SPFactory::mainframe()->setRedirect(Sobi::Reg('live_site'), SPLang::e('PAGE_NOT_FOUND'), SPC::ERROR_MSG, true);
         }
     }
     return true;
 }
예제 #14
0
    /**
     */
    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();
    }
예제 #15
0
 private function submit()
 {
     $xml = $this->payment();
     $visitor = $this->get('visitor');
     $id = $this->get('entry')->get('id');
     SPLoader::loadClass('mlo.input');
     if ($id) {
         $saveUrl = Sobi::Url(array('task' => 'entry.save', 'pid' => Sobi::Reg('current_section'), 'sid' => $id), false, false);
         $backUrl = Sobi::Url(array('task' => 'entry.edit', 'pid' => Sobi::Reg('current_section'), 'sid' => $id));
     } else {
         $saveUrl = Sobi::Url(array('task' => 'entry.save', 'pid' => Sobi::Reg('current_section')), false, false);
         $backUrl = Sobi::Url(array('task' => 'entry.add', 'pid' => Sobi::Reg('current_section')));
     }
     $xml['buttons']['save_button'] = array('_complex' => 1, '_data' => array('data' => array('_complex' => 1, '_xml' => 1, '_data' => SPHtml_Input::button('save', Sobi::Txt('EN.PAYMENT_SAVE_ENTRY_BT'), array('href' => $saveUrl)))));
     $xml['buttons']['back_button'] = array('_complex' => 1, '_data' => array('data' => array('_complex' => 1, '_xml' => 1, '_data' => SPHtml_Input::button('back', Sobi::Txt('EN.PAYMENT_BACK_BT'), array('href' => $backUrl)))));
     $xml['buttons']['cancel_button'] = array('_complex' => 1, '_data' => array('data' => array('_complex' => 1, '_xml' => 1, '_data' => SPHtml_Input::submit('save', Sobi::Txt('EN.CANCEL_BT')), '_data' => SPHtml_Input::button('cancel', Sobi::Txt('EN.CANCEL_BT'), array('href' => Sobi::Url(array('task' => 'entry.cancel', 'pid' => Sobi::Reg('current_section'))))))));
     $xml['save_url'] = $saveUrl;
     $xml['visitor'] = $this->visitorArray($visitor);
     $this->_attr = $xml;
     Sobi::Trigger('PaymentView', ucfirst(__FUNCTION__), array(&$this->_attr));
 }
예제 #16
0
파일: section.php 프로젝트: pelloq1/SobiPro
 public function &getInstance($id = 0)
 {
     static $instances = array();
     $id = $id ? $id : Sobi::Reg('current_section');
     if (!isset($instances[$id]) || !$instances[$id] instanceof self) {
         $instances[$id] = new self();
         $instances[$id]->extend(SPFactory::object($id));
     }
     return $instances[$id];
 }
예제 #17
0
파일: entry.php 프로젝트: pelloq1/SobiPro
 /**
  * Details view
  * @return void
  */
 private function details()
 {
     /* determine template package */
     $tplPackage = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE);
     /* load template config */
     $this->template();
     $this->tplCfg($tplPackage);
     if ($this->_model->get('oType') != 'entry') {
         Sobi::Error('Entry', sprintf('Serious security violation. Trying to save an object which claims to be an entry but it is a %s. Task was %s', $this->_model->get('oType'), SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__);
         exit;
     }
     /* add pathway */
     SPFactory::mainframe()->addObjToPathway($this->_model);
     $this->_model->countVisit();
     $this->_model->loadFields(Sobi::Reg('current_section'));
     $class = SPLoader::loadView('entry');
     $view = new $class($this->template);
     $view->assign($this->_model, 'entry');
     $view->assign(SPFactory::user()->getCurrent(), 'visitor');
     $view->assign($this->_task, 'task');
     $view->setConfig($this->_tCfg, $this->template);
     $view->setTemplate($tplPackage . '.' . $this->templateType . '.' . $this->template);
     Sobi::Trigger($this->name(), __FUNCTION__, array(&$view));
     SPFactory::header()->objMeta($this->_model);
     $view->display();
     SPFactory::cache()->addObj($this->_model, 'entry', $this->_model->get('id'));
 }
예제 #18
0
 /**
  * Add CSS file to the site header
  * @param string $file file name
  * @param bool $adm
  * @param null $media
  * @param bool $force
  * @param string $ext
  * @param string $params
  * @return SPHeader
  */
 public function &addCssFile($file, $adm = false, $media = null, $force = false, $ext = 'css', $params = null)
 {
     if (is_array($file) && count($file)) {
         foreach ($file as $f) {
             $this->addCssFile($f, $adm, $media, $force, $ext, $params);
         }
     } else {
         $checksum = md5(json_encode(get_defined_vars()));
         if (!isset($this->_checksums[__FUNCTION__][$checksum])) {
             $this->_checksums[__FUNCTION__][$checksum] = true;
             $this->store(get_defined_vars(), __FUNCTION__);
             $cssFile = SPLoader::CssFile($file, $adm, true, false, $ext);
             $index = ++$this->count;
             // if this is a template CSS file - ensure it will be loaded after all others CSS files
             if (Sobi::Reg('current_template') && strstr(dirname($cssFile), Sobi::Reg('current_template'))) {
                 $index *= 100;
             }
             if ($file == 'bootstrap.bootstrap') {
                 if (!Sobi::Cfg('template.bootstrap-disabled') || defined('SOBIPRO_ADM')) {
                     /** we want bootstrap loaded as the very first because we have to override some things */
                     $index = -100;
                 } else {
                     /** Not nice but it's just easier like this :/ */
                     return $this;
                 }
             }
             if ($cssFile) {
                 $override = false;
                 if (Sobi::Reg('current_template') && !strstr(dirname($cssFile), Sobi::Reg('current_template')) && SPFs::exists(Sobi::Reg('current_template') . '/css/' . basename($cssFile)) && !strstr(dirname($cssFile), 'templates')) {
                     $cssFile = explode('.', basename($cssFile));
                     $ext = $cssFile[count($cssFile) - 1];
                     unset($cssFile[count($cssFile) - 1]);
                     $f = implode('.', $cssFile);
                     $cssFile = SPLoader::CssFile('absolute.' . Sobi::Reg('current_template') . '/css/' . $f, $adm, true, true, $ext);
                     $override = true;
                     $index *= 100;
                 } else {
                     $cssFile = SPLoader::CssFile($file, $adm, true, true, $ext);
                 }
                 if (Sobi::Cfg('cache.include_css_files', false) && !($media || $params || $force || $adm || defined('SOBIPRO_ADM'))) {
                     if (!$override) {
                         $cssFile = SPLoader::CssFile($file, $adm, true, false, $ext);
                     }
                     if (!in_array($cssFile, $this->_cache['css']) || $force) {
                         $this->_cache['css'][$index] = $cssFile;
                         ksort($this->_cache['css']);
                     }
                 } else {
                     $params = $params ? '?' . $params : null;
                     $media = $media ? "media=\"{$media}\"" : null;
                     $file = "<link rel=\"stylesheet\" href=\"{$cssFile}{$params}\" type=\"text/css\" {$media} />";
                     if (!in_array($file, $this->cssFiles) || $force) {
                         $this->cssFiles[$index] = $file;
                         ksort($this->cssFiles);
                     }
                 }
             } else {
                 $file = SPLoader::CssFile($file, $adm, false, false, $ext);
                 Sobi::Error('add_css_file', SPLang::e('FILE_DOES_NOT_EXIST', $file), SPC::NOTICE, 0, __LINE__, __CLASS__);
             }
         }
     }
     return $this;
 }
예제 #19
0
 /**
  * @param $key
  * @param $val
  * @param $cfgSection
  * @return SPConfig
  */
 public function &saveCfg($key, $val, $cfgSection = 'general')
 {
     if (Sobi::Can('configure', 'section')) {
         if (strstr($key, '.')) {
             $key = explode('.', $key);
             $cfgSection = $key[0];
             $key = $key[1];
         }
         Sobi::Trigger('Config', 'Save', array(&$key, &$val, &$cfgSection));
         /* @var SPdb $db */
         $db =& SPFactory::db();
         try {
             $db->insertUpdate('spdb_config', array('sKey' => $key, 'sValue' => $val, 'section' => Sobi::Reg('current_section', 0), 'critical' => 0, 'cSection' => $cfgSection));
         } catch (SPException $x) {
             Sobi::Error('config', SPLang::e('CANNOT_SAVE_CONFIG', $x->getMessage()), SPC::WARNING, 500, __LINE__, __CLASS__);
         }
     }
     return $this;
 }
예제 #20
0
 /**
  * Returns an array with field object of field type which is possible to use it as entry name field
  * @param bool $pos
  * @param array $types
  * @return array
  */
 public function getNameFields($pos = false, $types = array())
 {
     // removed static because we have different settings for Alpha Index
     /*static */
     $cache = array('pos' => null, 'npos' => null);
     /**
      * alpha index/ordering
      */
     if ($pos) {
         if ($cache['pos']) {
             return $cache['pos'];
         }
         if (!count($types)) {
             $types = explode(', ', Sobi::Cfg('field_types_for_ordering', 'inbox, select'));
         }
     } else {
         if ($cache['npos']) {
             return $cache['npos'];
         }
         if (!count($types)) {
             $types = explode(', ', Sobi::Cfg('field_types_for_name', 'inbox'));
         }
     }
     try {
         $fids = SPFactory::db()->select('fid', 'spdb_field', array('fieldType' => $types, 'section' => Sobi::Reg('current_section')))->loadResultArray();
     } catch (SPException $x) {
         Sobi::Error($this->name(), SPLang::e('CANNOT_GET_FIELD_FOR_NAMES', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     $fields = array();
     if (count($fids)) {
         foreach ($fids as $fid) {
             $f = SPFactory::Model('field', true);
             $f->init($fid);
             try {
                 $f->setCustomOrdering($fields);
             } catch (SPException $x) {
                 $fields[$fid] = $f;
             }
         }
     }
     $cache[$pos ? 'pos' : 'npos'] = $fields;
     return $fields;
 }
예제 #21
0
 /**
  * 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__);
         }
     }
 }
예제 #22
0
 /**
  * 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__);
             }
         }
     }
 }
예제 #23
0
 /**
  * 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, $db, $request);
     $this->setRawData($save);
     $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 */
     $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__);
         }
     }
 }
예제 #24
0
 /**
  * @param $entry
  * @param $request
  * @param $files
  * @return SPdb
  * @throws SPException
  */
 protected function storeData(&$entry, $request, $files)
 {
     /* @var SPdb $db */
     $db =& SPFactory::db();
     $this->verify($entry, $request);
     $time = SPRequest::now();
     $IP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER');
     $uid = Sobi::My('id');
     /* if we are here, we can save these data */
     /* collect the needed params */
     $save = count($files) ? SPConfig::serialize($files) : null;
     $params = array();
     $params['publishUp'] = $entry->get('publishUp');
     $params['publishDown'] = $entry->get('publishDown');
     $params['fid'] = $this->fid;
     $params['sid'] = $entry->get('id');
     $params['section'] = Sobi::Reg('current_section');
     $params['lang'] = Sobi::Lang();
     $params['enabled'] = $entry->get('state');
     $params['baseData'] = $db->escape($save);
     $params['approved'] = $entry->get('approved');
     $params['confirmed'] = $entry->get('confirmed');
     /* if it is the first version, it is new entry */
     if ($entry->get('version') == 1) {
         $params['createdTime'] = $time;
         $params['createdBy'] = $uid;
         $params['createdIP'] = $IP;
     }
     $params['updatedTime'] = $time;
     $params['updatedBy'] = $uid;
     $params['updatedIP'] = $IP;
     $params['copy'] = !$entry->get('approved');
     if (Sobi::My('id') == $entry->get('owner')) {
         --$this->editLimit;
     }
     $params['editLimit'] = $this->editLimit;
     /* save it */
     try {
         $db->insertUpdate('spdb_field_data', $params);
         return $db;
     } catch (SPException $x) {
         Sobi::Error($this->name(), SPLang::e('CANNOT_SAVE_FIELDS_DATA_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         return $db;
     }
     return $db;
 }
예제 #25
0
 protected function customCols()
 {
     /* get fields for header */
     $fields = array();
     try {
         $fieldsData = SPFactory::db()->select('*', 'spdb_field', array('!admList' => 0, 'section' => Sobi::Reg('current_section')), 'admList')->loadObjectList();
     } catch (SPException $x) {
         Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     if (count($fieldsData)) {
         $fModel = SPLoader::loadModel('field', true);
         foreach ($fieldsData as $field) {
             $fit = new $fModel();
             /* @var SPField $fit */
             $fit->extend($field);
             $fields[] = $fit;
         }
     }
     return $fields;
 }
예제 #26
0
 /**
  * @param SPEntry $entry
  * @param string $request
  * @throws SPException
  * @return array
  */
 protected function verify($entry, $request)
 {
     $save = array();
     $data = SPRequest::raw($this->nid . '_url', null, $request);
     $dexs = strlen($data);
     $data = SPFactory::db()->escape($data);
     if ($this->ownLabel) {
         $save['label'] = SPRequest::raw($this->nid, null, $request);
         /* check if there was a filter */
         if ($this->filter && strlen($save['label'])) {
             $registry =& SPFactory::registry();
             $registry->loadDBSection('fields_filter');
             $filters = $registry->get('fields_filter');
             $filter = isset($filters[$this->filter]) ? $filters[$this->filter] : null;
             if (!count($filter)) {
                 throw new SPException(SPLang::e('FIELD_FILTER_ERR', $this->filter));
             } else {
                 if (!preg_match(base64_decode($filter['params']), $save['label'])) {
                     throw new SPException(str_replace('$field', $this->name, SPLang::e($filter['description'])));
                 }
             }
         }
     }
     /* check if it was required */
     if ($this->required && !$dexs) {
         throw new SPException(SPLang::e('FIELD_REQUIRED_ERR', $this->name));
     }
     /* check if there was an adminField */
     if ($this->adminField && $dexs) {
         if (!Sobi::Can('adm_fields.edit')) {
             throw new SPException(SPLang::e('FIELD_NOT_AUTH', $this->name));
         }
     }
     /* check if it was free */
     if (!$this->isFree && $this->fee && $dexs) {
         SPFactory::payment()->add($this->fee, $this->name, $entry->get('id'), $this->fid);
     }
     /* check if it should contains unique data */
     if ($this->uniqueData && $dexs) {
         $matches = $this->searchData($data, Sobi::Reg('current_section'));
         if (count($matches)) {
             throw new SPException(SPLang::e('FIELD_NOT_UNIQUE', $this->name));
         }
     }
     /* check if it was editLimit */
     if ($this->editLimit == 0 && !Sobi::Can('entry.adm_fields.edit') && $dexs) {
         throw new SPException(SPLang::e('FIELD_NOT_AUTH_EXP', $this->name));
     }
     /* check if it was editable */
     if (!$this->editable && !Sobi::Can('entry.adm_fields.edit') && $dexs && $entry->get('version') > 1) {
         throw new SPException(SPLang::e('FIELD_NOT_AUTH_NOT_ED', $this->name));
     }
     /* check the response code */
     if ($dexs && $this->validateUrl) {
         if (preg_match('/[a-z0-9]@[a-z0-9].[a-z]/i', $data)) {
             $domain = explode('@', $data, 2);
             $domain = $domain[1];
             if (!checkdnsrr($domain, 'MX')) {
                 throw new SPException(SPLang::e('FIELD_MAIL_NO_MX', $data));
             }
         } else {
             throw new SPException(SPLang::e('FIELD_MAIL_WRONG_FORM', $data));
         }
     }
     if ($dexs) {
         /* if we are here, we can save these data */
         $save['url'] = $data;
     } else {
         $save = null;
     }
     $this->setData($save);
     return $save;
 }
예제 #27
0
 /**
  * Gets the data for a field and save it in the database
  * @param SPEntry $entry
  * @param string $request
  * @throws SPException
  * @return bool
  */
 public function saveData(&$entry, $request = 'POST')
 {
     if (!$this->enabled) {
         return false;
     }
     $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__);
     }
 }