Exemplo n.º 1
0
 public static function &getUser($userid = 0, $profile = true, $preferences = false)
 {
     if (!$userid) {
         $user = JFactory::getUser();
     } else {
         $user = JFactory::getUser($userid);
     }
     // Session
     if ($user->id && $user->guest != 1) {
         $user->session_id = null;
         $user->where_clause = 'user_id=' . $user->id;
     } else {
         $user->session_id = JFactory::getSession()->getId();
         $user->where_clause = 'session_id="' . $user->session_id . '"';
     }
     // IP
     $user->ip = getenv('REMOTE_ADDR');
     // $_SERVER["REMOTE_ADDR"]
     // Profile
     if ($user->id && $profile) {
         $text = '';
         //CCK_User::getProfile( $user->id );
         if ($profile) {
             $regex = CCK_Content::getRegex();
             preg_match_all($regex, $text, $matches);
             if (count($matches[1])) {
                 foreach ($matches[1] as $key => $val) {
                     $user->{$val} = $matches[2][$key];
                 }
             }
         }
     }
     // Preferences
     if ($user->id && $preferences) {
         $preferences = JCckDatabase::loadResult('SELECT a.options FROM #__cck_core_preferences AS a WHERE a.userid = ' . (int) $user->id);
         if ($preferences) {
             $registry = new JRegistry();
             $registry->loadString($preferences);
             $preferences = $registry->toArray();
             if (count($preferences)) {
                 foreach ($preferences as $k => $v) {
                     $k = 'preferences_' . $k;
                     $user->{$k} = $v;
                 }
             }
         }
     }
     return $user;
 }
Exemplo n.º 2
0
 public static function onCCK_Storage_LocationExport($items, &$config = array())
 {
     // Init
     $excluded2 = array('cck' => '');
     $tables = array();
     $user = JFactory::getUser();
     // Prepare
     $table = self::_getTable();
     $fields = $table->getProperties();
     if (isset($config['fields']) && $config['fields'] === false) {
         $fields = array();
     } elseif (isset($config['fields']) && count($config['fields'])) {
         $fields = $config['fields'];
     } else {
         if (count(self::$columns_ignored)) {
             foreach (self::$columns_ignored as $exclude) {
                 unset($fields[$exclude]);
             }
         }
     }
     if (count($config['fields2'])) {
         foreach ($config['fields2'] as $k => $field) {
             if (!isset($storages[$field->storage_table])) {
                 $tables[$field->storage_table] = JCckDatabase::loadObjectList('SELECT * FROM ' . $field->storage_table, 'id');
             }
             if ($config['component'] == 'com_cck_exporter') {
                 $key = $field->name;
             } else {
                 $key = $field->label2 ? $field->label2 : ($field->label ? $field->label : $field->name);
             }
             $fields[$key] = '';
         }
     }
     $fields = array_keys($fields);
     if ($config['ftp'] == '1') {
         $config['buffer'] .= str_putcsv($fields, $config['separator']) . "\n";
     } else {
         fputcsv($config['handle'], $fields, $config['separator']);
     }
     // Set
     if (count($items)) {
         foreach ($items as $item) {
             // Check Permissions?
             if ($config['authorise'] == 0) {
                 continue;
             } elseif ($config['authorise'] == 2) {
                 if (!isset($config['types'][$item->cck])) {
                     $config['types'][$item->cck] = JCckDatabase::loadResult('SELECT id FROM #__cck_core_types WHERE name = "' . $item->cck . '"');
                 }
                 if (!$user->authorise('core.export', 'com_cck.form.' . $config['types'][$item->cck])) {
                     continue;
                 }
             }
             // Core
             $table = self::_getTable($item->pk);
             if (isset($config['fields']) && $config['fields'] === false) {
                 $fields = array();
             } elseif (isset($config['fields']) && count($config['fields'])) {
                 $fields = array();
                 $vars = get_object_vars($table);
                 foreach ($vars as $key => $val) {
                     if (isset($config['fields'][$key])) {
                         $fields[$key] = $val;
                     }
                 }
             } else {
                 $fields = $table->getProperties();
                 if (count(self::$columns_ignored)) {
                     foreach (self::$columns_ignored as $exclude) {
                         unset($fields[$exclude]);
                     }
                 }
             }
             // Core > Custom
             if (self::$custom && isset($fields[self::$custom])) {
                 preg_match_all(CCK_Content::getRegex(), $fields[self::$custom], $values);
                 $tables[self::$table][$item->pk]->{self::$custom} = array();
                 $fields[self::$custom] = '';
                 if (count($values[1])) {
                     foreach ($values[1] as $k => $v) {
                         if ($v == self::$custom) {
                             $fields[self::$custom] = $values[2][$k];
                         } elseif (!isset($excluded2[$v])) {
                             $tables[self::$table][$item->pk]->{self::$custom}[$v] = $values[2][$k];
                         }
                     }
                 }
             }
             // More
             if (count($config['fields2'])) {
                 foreach ($config['fields2'] as $name => $field) {
                     if ($field->storage == 'standard') {
                         if ($config['component'] == 'com_cck_exporter') {
                             $key = $field->name;
                         } else {
                             $key = $field->label2 ? $field->label2 : ($field->label ? $field->label : $field->name);
                         }
                         $fields[$key] = @$tables[$field->storage_table][$item->pk]->{$field->storage_field};
                     } else {
                         $name = $field->storage_field2 ? $field->storage_field2 : $name;
                         if ($config['component'] == 'com_cck_exporter') {
                             $key = $field->name;
                         } else {
                             $key = $field->label2 ? $field->label2 : ($field->label ? $field->label : $field->name);
                         }
                         if (!isset($tables[$field->storage_table][$item->pk]->{$field->storage_field})) {
                             $tables[$field->storage_table][$item->pk]->{$field->storage_field} = array();
                             // TODO
                         }
                         $fields[$key] = is_array($tables[$field->storage_table][$item->pk]->{$field->storage_field}) && isset($tables[$field->storage_table][$item->pk]->{$field->storage_field}[$name]) ? $tables[$field->storage_table][$item->pk]->{$field->storage_field}[$name] : $tables[$field->storage_table][$item->pk]->{$field->storage_field};
                     }
                 }
             }
             // Export
             if ($config['ftp'] == '1') {
                 $config['buffer'] .= str_putcsv($fields, $config['separator']) . "\n";
             } else {
                 fputcsv($config['handle'], $fields, $config['separator']);
             }
             $config['count']++;
         }
     }
 }
 public function download()
 {
     $app = JFactory::getApplication();
     $id = $app->input->getInt('id', 0);
     $fieldname = $app->input->getString('file', '');
     $collection = $app->input->getString('collection', '');
     $xi = $app->input->getString('xi', 0);
     $client = $app->input->getString('client', 'content');
     $restricted = '';
     $user = JFactory::getUser();
     if (!$id) {
         $file = $fieldname;
         $path = JPATH_ROOT . '/' . $file;
         $paths = JCck::getConfig_Param('media_paths', '');
         if ($paths != '') {
             $allowed = false;
             $paths = strtr($paths, array("\r\n" => '<br />', "\r" => '<br />', "\n" => '<br />'));
             $paths = explode('<br />', $paths);
             if (count($paths)) {
                 $paths[] = 'tmp/';
                 foreach ($paths as $p) {
                     if (strpos($path, JPATH_ROOT . '/' . $p) !== false) {
                         $allowed = true;
                         break;
                     }
                 }
             }
             if (!$allowed) {
                 $this->setRedirect(JUri::root(), JText::_('COM_CCK_ALERT_FILE_NOT_AUTH'), "error");
                 return;
             }
         } elseif (strpos($path, JPATH_ROOT . '/tmp/') === false) {
             $this->setRedirect(JUri::base(), JText::_('COM_CCK_ALERT_FILE_NOT_AUTH'), "error");
             return;
         }
     } else {
         $field = JCckDatabase::loadObject('SELECT a.* FROM #__cck_core_fields AS a WHERE a.name="' . ($collection != '' ? $collection : $fieldname) . '"');
         //#
         $query = 'SELECT a.pk, a.author_id, a.cck as type, b.' . $field->storage_field . ' as value FROM #__cck_core AS a LEFT JOIN ' . $field->storage_table . ' AS b on b.id = a.pk WHERE a.id =' . (int) $id;
         $core = JCckDatabase::loadObject($query);
         switch ($field->storage) {
             //todo: call plugins!
             case 'custom':
                 if ($collection != '') {
                     $regex = CCK_Content::getRegex_Group($fieldname, $collection, $xi);
                     preg_match($regex, $core->value, $matches);
                     $value = $matches[1];
                 } else {
                     $regex = CCK_Content::getRegex_Field($fieldname);
                     preg_match($regex, $core->value, $matches);
                     $value = $matches[1];
                 }
                 break;
             case 'standard':
             default:
                 $value = $core->value;
                 break;
         }
         // Access
         // $current	=	JSite::getMenu()->getActive()->id;
         $clients = JCckDatabase::loadObjectList('SELECT a.fieldid, a.client, a.access, a.restriction, a.restriction_options FROM #__cck_core_type_field AS a LEFT JOIN #__cck_core_types AS b ON b.id = a.typeid' . ' WHERE a.fieldid = ' . (int) $field->id . ' AND b.name="' . (string) $core->type . '"', 'client');
         $access = isset($clients[$client]->access) ? (int) $clients[$client]->access : 0;
         $autorised = $user->getAuthorisedViewLevels();
         $restricted = isset($clients[$client]->restriction) ? $clients[$client]->restriction : '';
         if (!($access > 0 && array_search($access, $autorised) !== false)) {
             $this->setRedirect('index.php', JText::_('COM_CCK_ALERT_FILE_NOT_AUTH'), "error");
             return;
         }
         JPluginHelper::importPlugin('cck_field');
         $dispatcher = JDispatcher::getInstance();
         $config = array('client' => $client, 'id' => id, 'pk' => $core->pk, 'pkb' => 0);
         $field = JCckDatabase::loadObject('SELECT a.* FROM #__cck_core_fields AS a WHERE a.name="' . $fieldname . '"');
         //#
         if ($restricted) {
             JPluginHelper::importPlugin('cck_field_restriction');
             $field->restriction = $restricted;
             $field->restriction_options = $clients[$client]->restriction_options;
             $allowed = JCck::callFunc_Array('plgCCK_Field_Restriction' . $restricted, 'onCCK_Field_RestrictionPrepareContent', array(&$field, &$config));
             if ($allowed !== true) {
                 $this->setRedirect('index.php', JText::_('COM_CCK_ALERT_FILE_NOT_AUTH'), "error");
                 return;
             }
         }
         $dispatcher->trigger('onCCK_FieldPrepareContent', array(&$field, $value, &$config));
         // Path Folder
         if ($collection != '') {
             $group_x = JCckDatabase::loadObject('SELECT a.options2 FROM #__cck_core_fields AS a WHERE a.name="' . $fieldname . '"');
             $f_opt2 = JCckDev::fromJSON($group_x->options2);
         } else {
             $f_opt2 = JCckDev::fromJSON($field->options2);
         }
         $file = '';
         if (isset($f_opt2['storage_format']) && $f_opt2['storage_format']) {
             $file .= $f_opt2['path'];
             $file .= isset($f_opt2['path_user']) && $f_opt2['path_user'] ? $core->author_id . '/' : '';
             $file .= isset($f_opt2['path_content']) && $f_opt2['path_content'] ? $core->pk . '/' : '';
         }
         $file .= $field->value;
     }
     $path = JPATH_ROOT . '/' . $file;
     if (is_file($path) && $file) {
         $size = filesize($path);
         $ext = strtolower(substr(strrchr($path, '.'), 1));
         if ($ext == 'php' || $file == '.htaccess') {
             return;
         }
         $name = substr($path, strrpos($path, '/') + 1, strrpos($path, '.'));
         if ($path) {
             set_time_limit(0);
             @ob_end_clean();
             include JPATH_ROOT . '/components/com_cck/download.php';
         }
     } else {
         $this->setRedirect('index.php', JText::_('COM_CCK_ALERT_FILE_DOESNT_EXIST'), 'error');
     }
 }
Exemplo n.º 4
0
 public static function setValues($text, $fieldnames, $values, $old_values = '')
 {
     $res = $text;
     $n_fieldnames = count($fieldnames);
     $n_values = count($values);
     $n_old_values = count($old_values);
     if (is_array($old_values)) {
         if ($n_fieldnames == $n_values && $n_fieldnames == $n_old_values) {
             for ($i = 0; $i < $n_fieldnames; $i++) {
                 $res = CCK_Content::setValue($res, $fieldnames[$i], $values[$i], $old_values[$i]);
             }
         }
     } else {
         if ($n_fieldnames == $n_values) {
             for ($i = 0; $i < $n_fieldnames; $i++) {
                 $res = CCK_Content::setValue($res, $fieldnames[$i], $values[$i], $old_values);
             }
         }
     }
     return $res;
 }
Exemplo n.º 5
0
 public static function setValues($id, $fieldnames, $values, $old_values = '')
 {
     $row = CCK_Article::getRow($id);
     if (!$row) {
         return false;
     }
     $row->introtext = CCK_Content::setValues($row->introtext, $fieldnames, $values, $old_values);
     $row->fulltext = CCK_Content::setValues($row->fulltext, $fieldnames, $values, $old_values);
     if (!$row->store()) {
         return false;
     }
     return true;
 }
Exemplo n.º 6
0
 /**
  * @param      $id
  *
  * @param bool $raw return the raw object not the RokSprocket_Item
  *
  * @return stdClass|RokSprocket_Item
  * @throws RokSprocket_Exception
  */
 public function getArticleInfo($id, $raw = false)
 {
     require_once JPath::clean(JPATH_SITE . '/libraries/cck/content/content.php');
     /** @var $filer_processor RokCommon_Filter_IProcessor */
     $filer_processor = $this->getFilterProcessor();
     $filer_processor->process(array('id' => array($id)));
     $query = $filer_processor->getQuery();
     $db = JFactory::getDbo();
     $db->setQuery($query);
     $db->query();
     if ($error = $db->getErrorMsg()) {
         throw new RokSprocket_Exception($error);
     }
     $ret = $db->loadObject();
     if ($raw) {
         //if its Seblod we have to do a match to get the introtext and full text
         $introtext = CCK_Content::getValue($ret->introtext, 'introtext');
         $fulltext = CCK_Content::getValue($ret->introtext, 'fulltext');
         if ($introtext || $fulltext) {
             $ret->preview = $this->_cleanPreview($introtext . $fulltext);
         } else {
             $ret->preview = $this->_cleanPreview($ret->introtext . $ret->fulltext);
         }
         $ret->editUrl = $this->getArticleEditUrl($id);
         return $ret;
     } else {
         $item = $this->convertRawToItem($ret);
         $item->editUrl = $this->getArticleEditUrl($id);
         $item->preview = $this->_cleanPreview($item->getText());
         return $item;
     }
 }
Exemplo n.º 7
0
 protected function _initValues($value)
 {
     preg_match_all(CCK_Content::getRegex(), $value, $values);
     return $values;
 }