public function onCCK_StoragePrepareDownload(&$field, &$value, &$config = array()) { if (self::$type != $field->storage) { return; } // Init // Set if ($config['collection'] != '') { $regex = CCK_Content::getRegex_Group($config['fieldname'], $config['collection'], $config['xi']); preg_match($regex, $field->value, $matches); $value = $matches[1]; } else { if (is_object($field) && $field->storage_field2) { $config['fieldname'] = $field->storage_field2; } $regex = CCK_Content::getRegex_Field($config['fieldname']); preg_match($regex, $field->value, $matches); $value = $matches[1]; } }
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'); } }
public static function setValue($text, $fieldname, $value, $old_value = '') { $res = $text; $search = ''; if ($old_value) { $search = CCK_Content::getSyntax($fieldname, $old_value); } else { $regex = CCK_Content::getRegex_Field($fieldname); preg_match($regex, $text, $matches); if (count($matches)) { $search = $matches[0]; } } if ($search) { $replace = CCK_Content::getSyntax($fieldname, $value); if (strpos($text, $search) !== false) { $res = str_replace($search, $replace, $text); } } return $res; }