本文整理汇总了PHP中K2Model::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP K2Model::getInstance方法的具体用法?PHP K2Model::getInstance怎么用?PHP K2Model::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类K2Model
的用法示例。
在下文中一共展示了K2Model::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: report
function report()
{
$model = K2Model::getInstance('User', 'K2Model');
$model->setState('id', JRequest::getInt('id'));
$model->reportSpammer();
$this->setRedirect('index.php?option=com_k2&view=users');
}
示例2: getInput
protected function getInput()
{
$document = JFactory::getDocument();
$document->addScriptDeclaration('var K2BasePath = "' . JURI::root(true) . '";');
$document->addScript(JURI::root(true) . '/plugins/josetta_ext/k2item/fields/k2extrafields.js');
K2Model::addIncludePath(JPATH_SITE . '/components/com_k2/models');
JLoader::register('K2HelperUtilities', JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'utilities.php');
$model = K2Model::getInstance('Item', 'K2Model');
$extraFields = $model->getItemExtraFields($this->value);
$html = '<div id="extraFieldsContainer">';
if (count($extraFields)) {
$html .= '<table class="admintable" id="extraFields">';
foreach ($extraFields as $extraField) {
$html .= '<tr>
<td align="right" class="key">' . $extraField->name . '</td>
<td>' . $extraField->element . '</td>
</tr>';
}
$html .= '</table>';
} else {
$html .= '<span class="k2Note"> ' . JText::_('K2_PLEASE_SELECT_A_CATEGORY_FIRST_TO_RETRIEVE_ITS_RELATED_EXTRA_FIELDS') . ' </span>';
}
$html .= '</div>';
return $html;
}
示例3: onJosettaLoadItem
public function onJosettaLoadItem($context, $id = '')
{
if (!empty($context) && $context != $this->_context || empty($id)) {
return null;
}
$item = parent::onJosettaLoadItem($context, $id);
// Merge introtext and fulltext
$item->articletext = trim($item->fulltext) != '' ? $item->introtext . "<hr id=\"system-readmore\" />" . $item->fulltext : $item->introtext;
// Get tags
K2Model::addIncludePath(JPATH_SITE . '/components/com_k2/models');
JLoader::register('K2HelperUtilities', JPATH_SITE . '/components/com_k2/helpers/utilities.php');
$model = K2Model::getInstance('Item', 'K2Model');
$tags = $model->getItemTags($item->id);
$tmp = array();
foreach ($tags as $tag) {
$tmp[] = $tag->name;
}
$item->tags = implode(', ', $tmp);
// Get extra fields
$extraFields = $model->getItemExtraFields($item->extra_fields);
$html = '';
if (count($extraFields)) {
$html .= '<ul>';
foreach ($extraFields as $key => $extraField) {
$html .= '<li class="type' . ucfirst($extraField->type) . ' group' . $extraField->group . '">
<span class="itemExtraFieldsLabel">' . $extraField->name . ':</span>
<span class="itemExtraFieldsValue">' . $extraField->value . '</span>
</li>';
}
$html .= '</ul>';
}
$item->extra_fields = $html;
// Return the item
return $item;
}
示例4: getAvatar
public static function getAvatar($userID, $email = NULL, $width = 50)
{
jimport('joomla.filesystem.folder');
jimport('joomla.application.component.model');
$mainframe = JFactory::getApplication();
$params = K2HelperUtilities::getParams('com_k2');
if (K2_CB && $userID != 'alias') {
$cbUser = CBuser::getInstance((int) $userID);
if (is_object($cbUser)) {
$avatar = $cbUser->getField('avatar', null, 'csv', 'none', 'profile');
return $avatar;
}
}
/*
// JomSocial Avatar integration
if(JFolder::exists(JPATH_SITE.DS.'components'.DS.'com_community') && $userID>0){
$userInfo = &CFactory::getUser($userID);
return $userInfo->getThumbAvatar();
}
*/
// Check for placeholder overrides
if (JFile::exists(JPATH_SITE . DS . 'templates' . DS . $mainframe->getTemplate() . DS . 'images' . DS . 'placeholder' . DS . 'user.png')) {
$avatarPath = 'templates/' . $mainframe->getTemplate() . '/images/placeholder/user.png';
} else {
$avatarPath = 'components/com_k2/images/placeholder/user.png';
}
// Continue with default K2 avatar determination
if ($userID == 'alias') {
$avatar = JURI::root(true) . '/' . $avatarPath;
} else {
if ($userID == 0) {
if ($params->get('gravatar') && !is_null($email)) {
$avatar = 'http://www.gravatar.com/avatar/' . md5($email) . '?s=' . $width . '&default=' . urlencode(JURI::root() . $avatarPath);
} else {
$avatar = JURI::root(true) . '/' . $avatarPath;
}
} else {
if (is_numeric($userID) && $userID > 0) {
K2Model::addIncludePath(JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'models');
$model = K2Model::getInstance('Item', 'K2Model');
$profile = $model->getUserProfile($userID);
$avatar = is_null($profile) ? '' : $profile->image;
if (empty($avatar)) {
if ($params->get('gravatar') && !is_null($email)) {
$avatar = 'http://www.gravatar.com/avatar/' . md5($email) . '?s=' . $width . '&default=' . urlencode(JURI::root() . $avatarPath);
} else {
$avatar = JURI::root(true) . '/' . $avatarPath;
}
} else {
$avatar = JURI::root(true) . '/media/k2/users/' . $avatar;
}
}
}
}
if (!$params->get('userImageDefault') && $avatar == JURI::root(true) . '/' . $avatarPath) {
$avatar = '';
}
return $avatar;
}
示例5: display
function display($tpl = null)
{
JRequest::setVar('hidemainmenu', 1);
$model = $this->getModel();
$extraField = $model->getData();
if (!$extraField->id) {
$extraField->published = 1;
}
$this->assignRef('row', $extraField);
$lists = array();
$lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $extraField->published);
$groups[] = JHTML::_('select.option', 0, JText::_('K2_CREATE_NEW_GROUP'));
$extraFieldModel = K2Model::getInstance('ExtraFields', 'K2Model');
$uniqueGroups = $extraFieldModel->getGroups(true);
foreach ($uniqueGroups as $group) {
$groups[] = JHTML::_('select.option', $group->id, $group->name);
}
$lists['group'] = JHTML::_('select.genericlist', $groups, 'groups', '', 'value', 'text', $extraField->group);
$typeOptions[] = JHTML::_('select.option', 0, JText::_('K2_SELECT_TYPE'));
$typeOptions[] = JHTML::_('select.option', 'textfield', JText::_('K2_TEXT_FIELD'));
$typeOptions[] = JHTML::_('select.option', 'textarea', JText::_('K2_TEXTAREA'));
$typeOptions[] = JHTML::_('select.option', 'select', JText::_('K2_DROPDOWN_SELECTION'));
$typeOptions[] = JHTML::_('select.option', 'multipleSelect', JText::_('K2_MULTISELECT_LIST'));
$typeOptions[] = JHTML::_('select.option', 'radio', JText::_('K2_RADIO_BUTTONS'));
$typeOptions[] = JHTML::_('select.option', 'link', JText::_('K2_LINK'));
$typeOptions[] = JHTML::_('select.option', 'csv', JText::_('K2_CSV_DATA'));
$typeOptions[] = JHTML::_('select.option', 'labels', JText::_('K2_SEARCHABLE_LABELS'));
$typeOptions[] = JHTML::_('select.option', 'date', JText::_('K2_DATE'));
$lists['type'] = JHTML::_('select.genericlist', $typeOptions, 'type', '', 'value', 'text', $extraField->type);
$this->assignRef('lists', $lists);
JRequest::getInt('cid') ? $title = JText::_('K2_EDIT_EXTRA_FIELD') : ($title = JText::_('K2_ADD_EXTRA_FIELD'));
JToolBarHelper::title($title, 'k2.png');
JToolBarHelper::save();
JToolBarHelper::apply();
JToolBarHelper::cancel();
JHTML::_('behavior.calendar');
$document = JFactory::getDocument();
$document->addScriptDeclaration('
var K2Language = [
"' . JText::_('K2_REMOVE', true) . '",
"' . JText::_('K2_OPTIONAL', true) . '",
"' . JText::_('K2_COMMA_SEPARATED_VALUES', true) . '",
"' . JText::_('K2_USE_EDITOR', true) . '",
"' . JText::_('K2_ALL_SETTINGS_ABOVE_ARE_OPTIONAL', true) . '",
"' . JText::_('K2_ADD_AN_OPTION', true) . '",
"' . JText::_('K2_LINK_TEXT', true) . '",
"' . JText::_('K2_URL', true) . '",
"' . JText::_('K2_OPEN_IN', true) . '",
"' . JText::_('K2_SAME_WINDOW', true) . '",
"' . JText::_('K2_NEW_WINDOW', true) . '",
"' . JText::_('K2_CLASSIC_JAVASCRIPT_POPUP', true) . '",
"' . JText::_('K2_LIGHTBOX_POPUP', true) . '",
"' . JText::_('K2_RESET_VALUE', true) . '",
"' . JText::_('K2_CALENDAR', true) . '",
"' . JText::_('K2_PLEASE_SELECT_A_FIELD_TYPE_FROM_THE_LIST_ABOVE', true) . '",
];');
parent::display($tpl);
}
示例6: getInstance
/**
* Gets an item instance.
*
* @param integer $id The id of the item to get.
*
* @return K2Tag The tag object.
*/
public static function getInstance($id)
{
if (empty(self::$instances[$id])) {
K2Model::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/models');
$model = K2Model::getInstance('Comments', 'K2Model');
$model->setState('id', $id);
$item = $model->getRow();
self::$instances[$id] = $item;
}
return self::$instances[$id];
}
示例7: getOptions
protected function getOptions()
{
require_once JPATH_ADMINISTRATOR . '/components/com_k2/models/categories.php';
$categoriesModel = K2Model::getInstance('Categories', 'K2Model');
$categories = $categoriesModel->categoriesTree(NULL, true, false);
$options = array();
$options[] = JHtml::_('select.option', 0, 'All');
foreach ($categories as $ca) {
$options[] = JHtml::_('select.option', $ca->value, $ca->text);
}
return $options;
}
示例8: getFields
public function getFields()
{
$fields = array();
if ($this->id) {
K2Model::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/models');
$model = K2Model::getInstance('ExtraFields', 'K2Model');
$model->setState('group', $this->id);
$model->setState('sorting', 'ordering');
$fields = $model->getRows();
}
return $fields;
}
示例9: getList
public static function getList(&$params)
{
$mainframe = JFactory::getApplication();
if ($params->get('catfilter')) {
$cid = $params->get('category_id', NULL);
} else {
$itemListModel = K2Model::getInstance('Itemlist', 'K2Model');
$cid = $itemListModel->getCategoryTree($category = 0);
}
$items = self::getItems($cid, $params);
return $items;
}
示例10: _findItem
public static function _findItem($catid)
{
$component = JComponentHelper::getComponent('com_jak2filter');
$application = JFactory::getApplication();
$menus = $application->getMenu('site', array());
if (K2_JVERSION != '15') {
$items = $menus->getItems('component_id', $component->id);
} else {
$items = $menus->getItems('componentid', $component->id);
}
$match = null;
if (count($items)) {
foreach ($items as $item) {
if ($catid) {
if (@$item->query['view'] == 'itemlist' && @$item->query['category_id'] == $catid) {
$match = $item;
break;
}
} else {
if (@$item->query['view'] == 'itemlist' && !isset($item->query['category_id'])) {
$match = $item;
break;
}
}
}
}
if (is_null($match)) {
// Try to detect any parent category menu item....
if (is_null(self::$tree)) {
include_once JPATH_ADMINISTRATOR . '/components/com_k2/models/model.php';
K2Model::addIncludePath(JPATH_SITE . '/components/com_k2/models');
$model = K2Model::getInstance('Itemlist', 'K2Model');
self::$model = $model;
self::$tree = $model->getCategoriesTree();
}
$parents = self::$model->getTreePath(self::$tree, $catid);
if (is_array($parents)) {
foreach ($parents as $categoryID) {
if ($categoryID != $catid) {
$match = JAK2FilterHelperRoute::_findItem($categoryID);
if (!is_null($match)) {
break;
}
}
}
}
if (is_null($match) && !is_null(self::$anyK2Link)) {
$match = self::$anyK2Link;
}
}
return $match;
}
示例11: display
public function display($cachable = false, $urlparams = array())
{
$model = $this->getModel('itemlist');
$document = JFactory::getDocument();
$viewType = $document->getType();
$view = $this->getView('item', $viewType);
$view->setModel($model);
JRequest::setVar('view', 'item');
$user = JFactory::getUser();
if ($user->guest) {
$cache = true;
} else {
$cache = true;
JTable::addIncludePath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'tables');
$row = JTable::getInstance('K2Item', 'Table');
$row->load(JRequest::getInt('id'));
if (K2HelperPermissions::canEditItem($row->created_by, $row->catid)) {
$cache = false;
}
$params = K2HelperUtilities::getParams('com_k2');
if ($row->created_by == $user->id && $params->get('inlineCommentsModeration')) {
$cache = false;
}
if ($row->access > 0) {
$cache = false;
}
$category = JTable::getInstance('K2Category', 'Table');
$category->load($row->catid);
if ($category->access > 0) {
$cache = false;
}
if ($params->get('comments') && $document->getType() == 'html') {
$itemListModel = K2Model::getInstance('Itemlist', 'K2Model');
$profile = $itemListModel->getUserProfile($user->id);
$script = "\n\$K2(document).ready(function() {\n\$K2('#userName').val('" . $view->escape($user->name) . "').attr('disabled', 'disabled');\n\$K2('#commentEmail').val('" . $user->email . "').attr('disabled', 'disabled');";
if (is_object($profile) && $profile->url) {
$script .= " \$K2('#commentURL').val('" . htmlspecialchars($profile->url, ENT_QUOTES, 'UTF-8') . "').attr('disabled', 'disabled');";
}
$script .= " });";
$document->addScriptDeclaration($script);
}
}
if (K2_JVERSION != '15') {
$urlparams['id'] = 'INT';
$urlparams['print'] = 'INT';
$urlparams['lang'] = 'CMD';
$urlparams['Itemid'] = 'INT';
}
parent::display($cache, $urlparams);
}
示例12: getGroups
public static function getGroups($scope = 'item')
{
if (!isset(self::$groups[$scope])) {
K2Model::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/models');
$model = K2Model::getInstance('ExtraFieldsGroups', 'K2Model');
$model->setState('scope', $scope);
$model->setState('sorting', 'name');
$rows = $model->getRows();
self::$groups[$scope] = array();
foreach ($rows as $row) {
self::$groups[$scope][$row->id] = $row;
}
}
return self::$groups[$scope];
}
示例13: deleteOrphans
public function deleteOrphans()
{
// Check for token
JSession::checkToken() or K2Response::throwError(JText::_('JINVALID_TOKEN'));
// Check permissions
$user = JFactory::getUser();
if (!$user->authorise('k2.tags.manage', 'com_k2')) {
K2Response::throwError(JText::_('K2_YOU_ARE_NOT_AUTHORIZED_TO_PERFORM_THIS_OPERATION'));
}
// Get model
$model = K2Model::getInstance('Tags');
$model->deleteOrphans();
$application = JFactory::getApplication();
$application->enqueueMessage(JText::_('K2_DELETE_COMPLETED'));
echo json_encode(K2Response::render());
return $this;
}
示例14: display
function display($tpl = null)
{
JHTML::_('behavior.tooltip');
JRequest::setVar('hidemainmenu', 1);
$model = $this->getModel();
$userGroup = $model->getData();
if (K2_JVERSION == '15') {
JFilterOutput::objectHTMLSafe($userGroup);
} else {
JFilterOutput::objectHTMLSafe($userGroup, ENT_QUOTES, 'permissions');
}
$this->assignRef('row', $userGroup);
if (K2_JVERSION == '15') {
$form = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'usergroup.xml');
$form->loadINI($userGroup->permissions);
$appliedCategories = $form->get('categories');
$inheritance = $form->get('inheritance');
} else {
jimport('joomla.form.form');
$form = JForm::getInstance('permissions', JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'usergroup.xml');
$values = array('params' => json_decode($userGroup->permissions));
$form->bind($values);
$inheritance = isset($values['params']->inheritance) ? $values['params']->inheritance : 0;
$appliedCategories = isset($values['params']->categories) ? $values['params']->categories : '';
}
$this->assignRef('form', $form);
$this->assignRef('categories', $appliedCategories);
$lists = array();
require_once JPATH_ADMINISTRATOR . '/components/com_k2/models/categories.php';
$categoriesModel = K2Model::getInstance('Categories', 'K2Model');
$categories = $categoriesModel->categoriesTree(NULL, true);
$categories_options = @array_merge($categories_option, $categories);
$lists['categories'] = JHTML::_('select.genericlist', $categories, 'params[categories][]', 'multiple="multiple" size="15"', 'value', 'text', $appliedCategories);
$lists['inheritance'] = JHTML::_('select.booleanlist', 'params[inheritance]', NULL, $inheritance);
$this->assignRef('lists', $lists);
JRequest::getInt('cid') ? $title = JText::_('K2_EDIT_USER_GROUP') : ($title = JText::_('K2_ADD_USER_GROUP'));
JToolBarHelper::title($title, 'k2.png');
JToolBarHelper::save();
JToolBarHelper::apply();
JToolBarHelper::cancel();
parent::display($tpl);
}
示例15: report
public function report()
{
// Check for token
JSession::checkToken() or K2Response::throwError(JText::_('JINVALID_TOKEN'));
// Get application
$application = JFactory::getApplication();
// Get input
$id = $application->input->get('id', 0, 'int');
// Get model
$model = K2Model::getInstance('Users');
$model->setState('id', $id);
$model->report();
if (!$model->report()) {
K2Response::throwError($model->getError());
}
// Response
echo json_encode(K2Response::render());
// Return
return $this;
}