Пример #1
0
 protected function __construct($class, $table, $table_key)
 {
     $this->_dbo = YDatabase::getInstance();
     $this->_class = $class;
     $this->_table = $table;
     $this->_table_key = $table_key;
 }
Пример #2
0
 public static function getInstance()
 {
     if (!isset(self::$_instance)) {
         self::$_instance = new YDatabase();
     }
     return self::$_instance;
 }
Пример #3
0
 public static function translateAliasToID($alias)
 {
     // init vars
     $db = YDatabase::getInstance();
     // search alias
     $query = 'SELECT id' . ' FROM ' . ZOO_TABLE_APPLICATION . ' WHERE alias = ' . $db->Quote($alias) . ' LIMIT 1';
     return $db->queryResult($query);
 }
Пример #4
0
 public function export()
 {
     $db = YDatabase::getInstance();
     $query = "SELECT * FROM #__sections" . " WHERE scope='content'";
     $sections = $db->queryObjectList($query);
     // get category table
     $category_table = YTable::getInstance('category');
     // get item table
     $item_table = YTable::getInstance('item');
     // get image path
     $image_path = JComponentHelper::getParams('com_media')->get('image_path');
     foreach ($sections as $section) {
         $attributes = array();
         foreach (self::$category_attributes as $attribute) {
             if (isset($section->{$attribute})) {
                 $attributes[$attribute] = $section->{$attribute};
             }
         }
         $category_xml = $this->_buildCategory($section->alias, $section->title, $attributes);
         if ($section->image) {
             $this->_attachCategoryImage($category_xml, $image_path . '/' . $section->image, 'Image');
         }
         $this->_addCategory($category_xml);
         $query = "SELECT * FROM #__categories WHERE section = " . $section->id;
         $joomla_categories = $db->queryObjectList($query);
         foreach ($joomla_categories as $joomla_category) {
             $attributes = array();
             foreach (self::$category_attributes as $attribute) {
                 if (isset($joomla_category->{$attribute})) {
                     $attributes[$attribute] = $joomla_category->{$attribute};
                 }
             }
             $attributes['parent'] = $section->alias;
             $category_xml = $this->_buildCategory($joomla_category->alias, $joomla_category->title, $attributes);
             if ($joomla_category->image) {
                 $this->_attachCategoryImage($category_xml, $image_path . '/' . $joomla_category->image, 'Image');
             }
             $this->_addCategory($category_xml);
             $query = "SELECT * FROM #__content WHERE catid =" . $joomla_category->id;
             $articles = $db->queryObjectList($query);
             foreach ($articles as $article) {
                 if ($article->state != -2) {
                     $this->_addItem(JText::_('Joomla article'), $this->_articleToXML($article, $joomla_category->alias));
                 }
             }
         }
     }
     $query = "SELECT * FROM #__content WHERE catid = 0";
     $articles = $db->queryObjectList($query);
     foreach ($articles as $article) {
         if ($article->state != -2) {
             $this->_addItem(JText::_('Joomla article'), $this->_articleToXML($article, 0));
         }
     }
     return parent::export();
 }
Пример #5
0
 public function bindItem()
 {
     $data = array();
     if ($this->_item) {
         $tzoffset = JFactory::getConfig()->getValue('config.offset');
         $null = YDatabase::getInstance()->getNullDate();
         $data['name'] = $this->_item->name;
         $data['state'] = $this->_item->state;
         $publish_up = $this->_item->publish_up;
         if ($publish_up != $null) {
             $publish_up = JFactory::getDate($publish_up, -$tzoffset)->toMySQL();
         }
         $data['publish_up'] = $publish_up;
         $publish_down = $this->_item->publish_down;
         if ($publish_down != $null) {
             $publish_down = JFactory::getDate($publish_down, -$tzoffset)->toMySQL();
         }
         $data['publish_down'] = $publish_down;
         $data['searchable'] = $this->_item->searchable;
         $data['enable_comments'] = $this->_item->isCommentsEnabled();
         $related_categories = $this->_item->getRelatedCategoryIds();
         $data['frontpage'] = in_array(0, $related_categories);
         $data['categories'] = $related_categories;
         $data['tags'] = $this->_item->getTags();
         foreach (array_keys($this->_elements_config) as $identifier) {
             if ($element = $this->_item->getElement($identifier)) {
                 if (is_subclass_of($element, 'ElementRepeatable')) {
                     $element->rewind();
                     foreach ($element as $index => $instance) {
                         if (is_a($element, 'ElementDate')) {
                             $value = $instance->getElementData()->get('value');
                             if (!empty($value)) {
                                 $value = JFactory::getDate($value, -$tzoffset)->toMySQL();
                             }
                             $data[$identifier][$index]['value'] = $value;
                         } else {
                             $data[$identifier][$index] = $instance->getElementData()->getParams()->toArray();
                         }
                     }
                 } else {
                     $data[$identifier] = $element->getElementData()->getParams()->toArray();
                 }
             }
         }
     }
     parent::bind($data);
 }
Пример #6
0
 protected function _getRelatedItems()
 {
     if ($this->_related_items == null) {
         // init vars
         $table = YTable::getInstance('item');
         // get user access id
         $access_id = JFactory::getUser()->get('aid', 0);
         // get items
         $items = $this->_data->get('item', array());
         if (!empty($items)) {
             // get dates
             $db = YDatabase::getInstance();
             $date = JFactory::getDate();
             $now = $db->Quote($date->toMySQL());
             $null = $db->Quote($db->getNullDate());
             $conditions = $table->getKeyName() . ' IN (' . implode(', ', $items) . ')' . ' AND state = 1' . ' AND access <= ' . $access_id . ' AND (publish_up = ' . $null . ' OR publish_up <= ' . $now . ')' . ' AND (publish_down = ' . $null . ' OR publish_down >= ' . $now . ')';
             $order = 'FIELD(' . $table->getKeyName() . ',' . implode(', ', $items) . ')';
             $this->_related_items = $table->all(compact('conditions', 'order'));
         }
     }
     return $this->_related_items;
 }
Пример #7
0
             $file = $element->getElementData()->get('file');
             $directory = $element->getConfig()->get('directory');
             $directory = trim($directory, '\\/') . '/';
             $element->getElementData()->set('file', $directory . $file);
             $found = true;
         }
     }
     if ($found) {
         try {
             $table->save($item);
         } catch (ItemTableException $e) {
         }
     }
 }
 // add application group field
 $db = YDatabase::getInstance();
 $fields = $db->getTableFields(ZOO_TABLE_APPLICATION);
 if (isset($fields[ZOO_TABLE_APPLICATION]) && !array_key_exists('alias', $fields[ZOO_TABLE_APPLICATION])) {
     $db->query('ALTER TABLE ' . ZOO_TABLE_APPLICATION . ' ADD alias VARCHAR(255) AFTER name');
 }
 // sanatize alias fields of the application
 $table = YTable::getInstance('application');
 $apps = $table->all();
 $apps = empty($apps) ? array() : $apps;
 foreach ($apps as $app) {
     if (empty($app->alias)) {
         $app->alias = ApplicationHelper::getUniqueAlias($app->id, YString::sluggify($app->name));
         try {
             $table->save($app);
         } catch (ApplicationTableException $e) {
         }
Пример #8
0
 protected function _getAlphaindex()
 {
     // set alphaindex
     $alpha_index = new YAlphaindex($this->application->getPath() . '/config/alphaindex.xml');
     // add categories
     $add_alpha_index = $this->application->getParams('site')->get('config.alpha_index', 0);
     if ($add_alpha_index == 1 || $add_alpha_index == 3) {
         $alpha_index->addObjects(array_filter($this->categories, create_function('$category', 'return $category->id != 0 && $category->itemCount();')), 'name');
     }
     // add items
     if ($add_alpha_index == 2 || $add_alpha_index == 3) {
         $db = YDatabase::getInstance();
         $access_id = $this->user->get('aid', 0);
         // get date
         $date = JFactory::getDate();
         $now = $db->Quote($date->toMySQL());
         $null = $db->Quote($db->getNullDate());
         $query = 'SELECT DISTINCT BINARY CONVERT(LOWER(LEFT(name, 1)) USING utf8) letter' . ' FROM ' . ZOO_TABLE_ITEM . ' AS ci' . ' WHERE id IN (SELECT item_id FROM ' . ZOO_TABLE_CATEGORY_ITEM . ')' . ' AND application_id = ' . (int) $this->application->id . ' AND access <= ' . (int) $access_id . ' AND state = 1' . ' AND (publish_up = ' . $null . ' OR publish_up <= ' . $now . ')' . ' AND (publish_down = ' . $null . ' OR publish_down >= ' . $now . ')';
         $alpha_index->addObjects($db->queryObjectList($query), 'letter');
     }
     return $alpha_index;
 }
Пример #9
0
if ($this->form->hasError('publish_up')) {
    ?>
<div class="error-message"><?php 
    echo $this->form->getError('publish_up');
    ?>
</div><?php 
}
?>
			</div>

			<div class="element element-publish_down<?php 
echo $this->form->hasError('publish_down') ? ' error' : '';
?>
">
				<?php 
if (!($publish_down = $this->form->getTaintedValue('publish_down')) || $publish_down == YDatabase::getInstance()->getNullDate()) {
    $publish_down = JText::_('Never');
}
?>
				<strong><?php 
echo JText::_('Finish Publishing');
?>
</strong>
				<?php 
echo JHTML::_('zoo.calendar', $publish_down, 'publish_down', 'publish_down', array('class' => 'calendar-element'));
?>
				<?php 
if ($this->form->hasError('publish_down')) {
    ?>
<div class="error-message"><?php 
    echo $this->form->getError('publish_down');
Пример #10
0
 public function isPublished()
 {
     // get database
     $db = YDatabase::getInstance();
     // get dates
     $date = JFactory::getDate();
     $now = $date->toMySQL();
     $null = $db->getNullDate();
     return $this->state == 1 && ($this->publish_up == $null || $this->publish_up <= $now) && ($this->publish_down == $null || $this->publish_down >= $now);
 }
Пример #11
0
 public function display()
 {
     jimport('joomla.html.pagination');
     // get application
     $app = Zoo::getApplication();
     // get request vars
     $db = YDatabase::getInstance();
     $state_prefix = $this->option . '_' . $app->id . '.comment.';
     $limit = $this->joomla->getUserStateFromRequest('global.list.limit', 'limit', $this->joomla->getCfg('list_limit'), 'int');
     $offset = $this->joomla->getUserStateFromRequest($state_prefix . 'limitstart', 'limitstart', 0, 'int');
     $filter_state = $this->joomla->getUserStateFromRequest($state_prefix . 'filter-state', 'filter-state', '', 'string');
     $filter_item = $this->joomla->getUserStateFromRequest($state_prefix . 'filter-item', 'filter-item', 0, 'int');
     $filter_author = $this->joomla->getUserStateFromRequest($state_prefix . 'filter-author', 'filter-author', '', 'string');
     $search = $this->joomla->getUserStateFromRequest($state_prefix . 'search', 'search', '', 'string');
     $search = JString::strtolower($search);
     // is filtered ?
     $this->is_filtered = $filter_state != '' || !empty($filter_item) || !empty($filter_author) || !empty($search);
     // in case limit has been changed, adjust offset accordingly
     $offset = $limit != 0 ? floor($offset / $limit) * $limit : 0;
     // set toolbar items
     if ($filter_item && ($item_object = YTable::getInstance('item')->get($filter_item))) {
         $this->joomla->set('JComponentTitle', $app->getToolbarTitle(JText::_('Comments on') . ': ' . $item_object->name));
     } else {
         $this->joomla->set('JComponentTitle', $app->getToolbarTitle(JText::_('Comments')));
     }
     JToolBarHelper::custom('approve', 'publish', '', 'Approve');
     JToolBarHelper::custom('unapprove', 'unpublish', '', 'Unapprove');
     JToolBarHelper::custom('spam', 'trash', '', 'Spam');
     JToolBarHelper::deleteList();
     // build where condition
     $where = array('b.application_id = ' . (int) $app->id);
     if ($filter_state === '') {
         $where[] = 'a.state <> 2';
         // all except spam
     } else {
         $where[] = 'a.state = ' . (int) $filter_state;
     }
     if ($filter_item) {
         $where[] = 'a.item_id = ' . (int) $filter_item;
     }
     if ($filter_author == '_anonymous_') {
         $where[] = 'a.author = ""';
     } elseif ($filter_author) {
         $where[] = 'a.author = "' . $db->getEscaped($filter_author) . '"';
     }
     if ($search) {
         $where[] = 'LOWER(a.content) LIKE "%' . $db->getEscaped($search, true) . '%"';
     }
     // build query options
     $options = array('select' => 'a.*', 'from' => ZOO_TABLE_COMMENT . ' AS a LEFT JOIN ' . ZOO_TABLE_ITEM . ' AS b ON a.item_id = b.id', 'conditions' => array(implode(' AND ', $where)), 'order' => 'created DESC');
     // query comment table
     $table = YTable::getInstance('comment');
     $this->comments = $table->all($limit > 0 ? array_merge($options, compact('offset', 'limit')) : $options);
     $this->pagination = new JPagination($table->count($options), $offset, $limit);
     // search filter
     $this->lists['search'] = $search;
     // state select
     $options = array(JHTML::_('select.option', '', '- ' . JText::_('Select Status') . ' -'), JHTML::_('select.option', '0', JText::_('Pending')), JHTML::_('select.option', '1', JText::_('Approved')), JHTML::_('select.option', '2', JText::_('Spam')));
     $this->lists['select_state'] = JHTML::_('select.genericlist', $options, 'filter-state', 'class="inputbox auto-submit"', 'value', 'text', $filter_state);
     // item select
     $options = array(JHTML::_('select.option', 0, '- ' . JText::_('Select Item') . ' -'));
     $this->lists['select_item'] = JHTML::_('zoo.itemlist', $app, $options, 'filter-item', 'class="inputbox auto-submit"', 'value', 'text', $filter_item);
     // author select
     $options = array(JHTML::_('select.option', '', '- ' . JText::_('Select Author') . ' -'), JHTML::_('select.option', '_anonymous_', '- ' . JText::_('Anonymous') . ' -'));
     $this->lists['select_author'] = JHTML::_('zoo.commentauthorlist', $app, $options, 'filter-author', 'class="inputbox auto-submit"', 'value', 'text', $filter_author);
     // get comment params
     $this->params = new YParameter();
     $this->params->loadArray($app->getParams()->get('global.comments.', array()));
     // display view
     $this->getView()->display();
 }
Пример #12
0
 protected function _configure($options = array(), $messages = array())
 {
     $this->addOption('date_format_regex', '/^((\\d{2}|\\d{4}))-(\\d{1,2})-(\\d{1,2})(\\s(\\d{1,2}):(\\d{1,2}):(\\d{1,2}))?$/');
     $this->addOption('date_format', '%Y-%m-%d %H:%M:%S');
     $this->addOption('allow_db_null_date', false);
     $this->addOption('db_null_date', YDatabase::getInstance()->getNullDate());
     $this->addMessage('bad_format', '"%s" is not a valid date.');
 }
Пример #13
0
 public function getByName($application_id, $name)
 {
     if (empty($name) || empty($application_id)) {
         return array();
     }
     $conditions = "application_id=" . (int) $application_id . " AND name=" . YDatabase::getInstance()->quote($name);
     return $this->all(compact('conditions'));
 }
Пример #14
0
 private static function _importItems(Application $application, $items_xml_array = array(), $element_assignment = array(), $types = array())
 {
     // init vars
     $db = YDatabase::getInstance();
     $table = YTable::getInstance('item');
     $item_vars = array_keys(get_class_vars('Item'));
     $user_id = JFactory::getUser()->get('id');
     $app_types = $application->getTypes();
     $authors = new YArray(YDatabase::getInstance()->queryObjectList('SELECT id, username FROM #__users'));
     $items = array();
     foreach ($items_xml_array as $key => $items_xml) {
         $index = (string) $items_xml->attributes()->name;
         if (isset($types[$index]) && !empty($types[$index]) && ($type = $app_types[$types[$index]])) {
             $elements = $type->getElements();
             $traverse = true;
             while ($traverse) {
                 $traverse = false;
                 foreach ($items_xml->item as $item_xml) {
                     $traverse = true;
                     $item = new Item();
                     $item->old_alias = (string) $item_xml->attributes()->id;
                     $item->alias = YString::sluggify($item->old_alias);
                     $item->type = $type->id;
                     // set a valid category alias
                     while (ItemHelper::checkAliasExists($item->alias)) {
                         $item->alias .= '-2';
                     }
                     $db->query('INSERT INTO ' . ZOO_TABLE_ITEM . '(alias) VALUES (' . $db->quote($item->alias) . ')');
                     $item->id = $db->insertid();
                     // set item values
                     foreach ($item_xml->children() as $child) {
                         $name = $child->getName();
                         if (in_array($name, $item_vars)) {
                             $item->{$name} = (string) $child;
                         }
                     }
                     // store application id
                     $item->application_id = $application->id;
                     // store categories
                     $item->categories = array();
                     foreach ($item_xml->getElementsByPath('categories/category') as $category_xml) {
                         $item->categories[] = (string) $category_xml;
                     }
                     // store tags
                     $tags = array();
                     foreach ($item_xml->getElementsByPath('tags/tag') as $tag_xml) {
                         $tags[] = (string) $tag_xml;
                     }
                     $item->setTags($tags);
                     // store author
                     $item->created_by_alias = "";
                     if ($item_xml->author) {
                         $author = (string) $item_xml->author;
                         $key = $authors->searchRecursive($author);
                         if ($key !== false) {
                             $item->created_by = (int) $authors[$key]->id;
                         } else {
                             $item->created_by_alias = $author;
                         }
                     }
                     // if author is unknown set current user as author
                     if (!$item->created_by) {
                         $item->created_by = $user_id;
                     }
                     // store modified_by
                     $item->modified_by = $user_id;
                     // store element_data
                     if ($data = $item_xml->data) {
                         $elements_xml = YXMLElement::create('elements');
                         $nodes_to_delete = array();
                         foreach ($data->children() as $key => $element_xml) {
                             $old_element_alias = (string) $element_xml->attributes()->identifier;
                             if (isset($element_assignment[$index][$old_element_alias][$type->id]) && ($element_alias = $element_assignment[$index][$old_element_alias][$type->id])) {
                                 $element_xml->addAttribute('identifier', $element_alias);
                                 $elements_xml->appendChild($element_xml);
                             } else {
                                 $nodes_to_delete[] = $element_xml;
                             }
                         }
                         foreach ($nodes_to_delete as $node) {
                             $data->removeChild($node);
                         }
                         $item->elements = $elements_xml->asXML(true, true);
                     }
                     // store metadata
                     $params = $item->getParams();
                     if ($metadata = $item_xml->metadata) {
                         foreach ($metadata->children() as $metadata_xml) {
                             $params->set('metadata.' . $metadata_xml->getName(), (string) $metadata_xml);
                         }
                     }
                     $item->params = $params->toString();
                     $items[$item->old_alias] = $item;
                     $items_xml->removeChild($item_xml);
                 }
             }
         }
     }
     // sanatize relateditems elements
     foreach ($items as $key => $item) {
         foreach ($item->getElements() as $element) {
             if ($element->getElementType() == 'relateditems') {
                 $relateditems = $element->getElementData()->get('item', array());
                 $new_related_items = array();
                 foreach ($relateditems as $key => $relateditem) {
                     if (isset($items[$relateditem])) {
                         $new_related_items[] = $items[$relateditem]->id;
                     }
                 }
                 $element->getElementData()->set('item', $new_related_items);
             }
         }
         try {
             $table->save($item);
             $item->unsetElementData();
         } catch (YException $e) {
             JError::raiseNotice(0, JText::_('Error Importing Item') . ' (' . $e . ')');
         }
     }
     return $items;
 }
Пример #15
0
 protected function _itemToXML($item, $categories = array())
 {
     $attributes = array();
     foreach (self::$item_attributes as $attribute) {
         if (isset($item->{$attribute})) {
             $attributes[$attribute] = $item->{$attribute};
         }
     }
     // add attributes
     $attributes['state'] = $item->published;
     $attributes['author'] = JFactory::getUser($item->user_id)->username;
     // build item xml
     $item_xml = $this->_buildItem($item->alias, $item->name, $attributes);
     // add category
     $db = YDatabase::getInstance();
     // get mtree categories
     $query = "SELECT cat_id" . " FROM #__mt_cl" . " WHERE link_id = " . (int) $item->id;
     $related_categories = $db->queryResultArray($query);
     if (!empty($related_categories)) {
         foreach ($related_categories as $category_id) {
             if (empty($category_id)) {
                 $alias = '_root';
             } else {
                 $alias = $categories[$category_id]->alias;
             }
             $this->_addItemCategory($item_xml, $alias);
         }
     }
     // get mtree content
     $query = "SELECT *" . " FROM #__mt_customfields as cf" . " LEFT JOIN #__mt_cfvalues as v on cf.cf_id = v.cf_id AND v.link_id = " . (int) $item->id . " LEFT JOIN #__mt_cfvalues_att as va on va.cf_id = v.cf_id AND va.link_id = v.link_id";
     $custom_fields = $db->queryObjectList($query);
     // add item content
     $i = 0;
     // Load images
     $query = 'SELECT img_id, filename FROM #__mt_images WHERE link_id = ' . $db->quote($item->id) . ' ORDER BY ordering ASC';
     $images = $db->queryObjectList($query);
     $folder = preg_replace('/[^a-z0-9]*/i', '', $item->alias);
     $path = $this->import_path_gallery . $folder . '/';
     if (!JFolder::exists($path)) {
         JFolder::create($path);
     }
     if (!empty($images)) {
         foreach ($images as $image) {
             $old_file_name = JPATH_ROOT . '/' . $this->listing_image_path . $image->filename;
             $file_info = pathinfo($image->filename);
             $file_name = $path . $image->filename;
             $j = 2;
             while (JFile::exists($file_name)) {
                 $file_name = $path . $file_info['filename'] . '-' . $j++ . '.' . $file_info['extension'];
             }
             $file = '';
             if (!empty($image->filename)) {
                 JFile::copy($old_file_name, $file_name);
             }
         }
     }
     $path = trim(str_replace('\\', '/', preg_replace('/^' . preg_quote(JPATH_ROOT . '/' . $this->file_path, '/') . '/i', '', $path)), '/');
     $this->_addItemData($item_xml, $this->_buildElement('gallery', $i++, 'Gallery', array('value' => $path)));
     if (!empty($custom_fields)) {
         foreach ($custom_fields as $field) {
             switch ($field->field_type) {
                 case 'mtags':
                     $tags = explode(',', $field->value);
                     // add tags
                     foreach ($tags as $tag) {
                         $this->_addItemTag($item_xml, trim($tag));
                     }
                     break;
                 case 'weblinknewwin':
                     $this->_addItemData($item_xml, $this->_buildElement('link', $i++, $field->caption, array('value' => $field->value)));
                     break;
                 case 'image':
                     $old_file_name = JPATH_ROOT . '/' . $this->attachement_path . $field->raw_filename;
                     $file_info = pathinfo($field->filename);
                     $file_name = $this->import_path_item_images . $field->filename;
                     $j = 2;
                     while (JFile::exists($file_name)) {
                         $file_name = $this->import_path_item_images . $file_info['filename'] . '-' . $j++ . '.' . $file_info['extension'];
                     }
                     $file = '';
                     if (!empty($field->filename)) {
                         if (JFile::copy($old_file_name, $file_name)) {
                             $file = trim(str_replace('\\', '/', preg_replace('/^' . preg_quote(JPATH_ROOT, '/') . '/i', '', $file_name)), '/');
                         }
                     }
                     $this->_addItemData($item_xml, $this->_buildElement('image', $i++, $field->caption, array('file' => $file)));
                     break;
                 case 'mfile':
                     $old_file_name = JPATH_ROOT . '/' . $this->attachement_path . $field->raw_filename;
                     $file_info = pathinfo($field->filename);
                     $file_name = $this->import_path_attachments . $field->filename;
                     $j = 2;
                     while (JFile::exists($file_name)) {
                         $file_name = $this->import_path_attachments . $file_info['filename'] . '-' . $j++ . '.' . $file_info['extension'];
                     }
                     $file = '';
                     if (!empty($field->filename)) {
                         if (JFile::copy($old_file_name, $file_name)) {
                             $file = trim(str_replace('\\', '/', preg_replace('/^' . preg_quote(JPATH_ROOT, '/') . '/i', '', $file_name)), '/');
                         }
                     }
                     $this->_addItemData($item_xml, $this->_buildElement('download', $i++, $field->caption, array('file' => $file)));
                     break;
                 case 'videoplayer':
                 case 'audioplayer':
                     $old_file_name = JPATH_ROOT . '/' . $this->attachement_path . $field->raw_filename;
                     $file_info = pathinfo($field->filename);
                     $file_name = $this->import_path_attachments . $field->filename;
                     $j = 2;
                     while (JFile::exists($file_name)) {
                         $file_name = $this->import_path_attachments . $file_info['filename'] . '-' . $j++ . '.' . $file_info['extension'];
                     }
                     $file = '';
                     if (!empty($field->filename)) {
                         if (JFile::copy($old_file_name, $file_name)) {
                             $file = trim(str_replace('\\', '/', preg_replace('/^' . preg_quote(JPATH_ROOT, '/') . '/i', '', $file_name)), '/');
                         }
                     }
                     $this->_addItemData($item_xml, $this->_buildElement('video', $i++, $field->caption, array('file' => $file)));
                     break;
                 case 'memail':
                     $this->_addItemData($item_xml, $this->_buildElement('email', $i++, $field->caption, array('value' => $field->value)));
                     break;
                 case 'mnumber':
                 case 'year':
                     $this->_addItemData($item_xml, $this->_buildElement('text', $i++, $field->caption, array('value' => $field->value)));
                     break;
                 case 'mdate':
                     $this->_addItemData($item_xml, $this->_buildElement('date', $i++, $field->caption, array('value' => $field->value)));
                     break;
                 case 'onlinevideo':
                     $this->_addItemData($item_xml, $this->_buildElement('video', $i++, $field->caption, array('url' => $field->value)));
                     break;
                 case 'coredesc':
                     $this->_addItemData($item_xml, $this->_buildElement('textarea', $i++, $field->caption, array('value' => $item->link_desc)));
                     break;
                 case 'coreaddress':
                 case 'corecity':
                 case 'corestate':
                 case 'corecountry':
                 case 'corepostcode':
                 case 'coretelephone':
                 case 'corefax':
                 case 'coreprice':
                     $attribute = substr($field->field_type, 4);
                     $this->_addItemData($item_xml, $this->_buildElement('text', $i++, $field->caption, array('value' => $item->{$attribute})));
                     break;
                 case 'coreemail':
                     $this->_addItemData($item_xml, $this->_buildElement('email', $i++, $field->caption, array('value' => $item->email)));
                     break;
                 case 'corewebsite':
                     $this->_addItemData($item_xml, $this->_buildElement('link', $i++, $field->caption, array('value' => $item->website)));
                     break;
             }
         }
     }
     return $item_xml;
 }
Пример #16
0
 public static function queryList($query, $options, $name, $attribs = null, $key = 'value', $text = 'text', $selected = null, $idtag = false, $translate = false)
 {
     if (is_array($options)) {
         reset($options);
     } else {
         $options = array($options);
     }
     $db = YDatabase::getInstance();
     $list = $db->queryObjectList($query);
     $options = array_merge($options, $list);
     return JHTML::_('select.genericlist', $options, $name, $attribs, $key, $text, $selected, $idtag, $translate);
 }
Пример #17
0
 protected function _init()
 {
     //init vars
     $type_id = JRequest::getString('type_id');
     $hash = JRequest::getString('submission_hash');
     $this->redirect = YRequest::getString('redirect');
     // check config
     $this->_checkConfig();
     // get submission info from request
     if ($type_id) {
         if ($hash != SubmissionHelper::getSubmissionHash($this->submission->id, $type_id, $this->item_id)) {
             throw new SubmissionControllerException('Hashes did not match.');
         }
         // else get submission info from active menu
     } elseif ($this->menu_params) {
         $type_id = $this->menu_params->get('type');
         // remove item_id (menu item may not have an item_id)
         $this->item_id = null;
     }
     // set type
     $this->type = $this->submission->getType($type_id);
     // check type
     if (!$this->type) {
         throw new SubmissionControllerException('Submissions are not configured correctly.');
     }
     // set hash
     $this->hash = $hash ? $hash : SubmissionHelper::getSubmissionHash($this->submission->id, $this->type->id, $this->item_id);
     // set layout
     $this->layout = $this->submission->getForm($this->type->id)->get('layout', '');
     // check layout
     if (empty($this->layout)) {
         throw new SubmissionControllerException('Submission is not configured correctly.');
     }
     // set layout path
     $this->layout_path = 'item.';
     if ($this->renderer->pathExists('item/' . $this->type->id)) {
         $this->layout_path .= $this->type->id . '.';
     }
     $this->layout_path .= $this->layout;
     // get positions
     $positions = $this->renderer->getConfig('item')->get($this->application->getGroup() . '.' . $this->type->id . '.' . $this->layout, array());
     // get elements from positions
     $this->elements_config = array();
     foreach ($positions as $position) {
         foreach ($position as $element) {
             if ($element_obj = $this->type->getElement($element->element)) {
                 if (!$this->submission->isInTrustedMode()) {
                     $metadata = $element_obj->getMetaData();
                     if ($metadata['trusted'] == 'true') {
                         continue;
                     }
                 }
                 $this->elements_config[$element->element] = $element;
             }
         }
     }
     // get item table
     $table = YTable::getInstance('item');
     // get item
     if (!$this->item_id || !($this->item = $table->get($this->item_id))) {
         $this->item = new Item();
         $this->item->application_id = $this->application->id;
         $this->item->type = $this->type->id;
         $now = JFactory::getDate();
         $config = JFactory::getConfig();
         $offset = $config->getValue('config.offset');
         $now->setOffset($offset);
         $this->item->publish_up = $now->toFormat(SubmissionController::EDIT_DATE_FORMAT);
         $this->item->publish_down = YDatabase::getInstance()->getNullDate();
     }
 }
Пример #18
0
 public function export()
 {
     $db = YDatabase::getInstance();
     // get docman categories
     $query = "SELECT  c.*, c.parent_id as parent" . " FROM #__categories AS c" . " WHERE c.section = 'com_docman'" . " AND c.published != -2" . " ORDER BY c.parent_id, c.ordering";
     $categories = $db->queryObjectList($query, 'id');
     // get category table
     $category_table = YTable::getInstance('category');
     // get item table
     $item_table = YTable::getInstance('item');
     // sanatize category aliases
     $aliases = array();
     foreach ($categories as $category) {
         $i = 2;
         $alias = YString::sluggify($category->alias);
         if (empty($alias)) {
             $alias = YString::sluggify($category->title);
         }
         while (in_array($alias, $aliases)) {
             $alias = $category->alias . '-' . $i++;
         }
         $category->alias = $alias;
         // remember used aliases to ensure unique aliases
         $aliases[] = $category->alias;
     }
     // get image path
     $this->image_path = JComponentHelper::getParams('com_media')->get('image_path');
     $this->image_path = trim($this->image_path, '\\/') . '/';
     // export categories
     foreach ($categories as $category) {
         // assign attributes
         $attributes = array();
         foreach (self::$category_attributes as $attribute) {
             if (isset($category->{$attribute})) {
                 $attributes[$attribute] = $category->{$attribute};
             }
         }
         // sanatize parent
         if ($category->parent && isset($categories[$category->parent])) {
             $attributes['parent'] = $categories[$category->parent]->alias;
         }
         // add category
         $category_xml = $this->_buildCategory($category->alias, $category->name, $attributes);
         if ($category->image) {
             $this->_attachCategoryImage($category_xml, $this->image_path . $category->image, 'Image');
         }
         $this->_addCategory($category_xml);
     }
     // get docman items
     $query = "SELECT * FROM #__docman";
     $items = $db->queryObjectList($query, 'id');
     // sanatize item aliases
     $aliases = array();
     foreach ($items as $item) {
         $i = 2;
         $alias = YString::sluggify($item->dmname);
         while (in_array($alias, $aliases)) {
             $alias = YString::sluggify($item->dmname) . '-' . $i++;
         }
         $item->alias = $alias;
         // remember used aliases to ensure unique aliases
         $aliases[] = $item->alias;
     }
     require_once JPATH_ADMINISTRATOR . '/components/com_docman/docman.config.php';
     $config = new dmConfig();
     $document_path = trim(str_replace('\\', '/', preg_replace('/^' . preg_quote(JPATH_ROOT, '/') . '/i', '', $config->dmpath)), '/') . '/';
     // export items
     foreach ($items as $item) {
         if (preg_match('/^Link:/', $item->dmfilename)) {
             $type = 'Linked File';
             $item->dmfilename = preg_replace('/^Link:/', '', $item->dmfilename);
         } else {
             $type = 'File';
             $item->dmfilename = $document_path . $item->dmfilename;
         }
         $this->_addItem($type, $this->_itemToXML($item, $categories, $type));
     }
     return parent::export();
 }
Пример #19
0
 public function export()
 {
     $db = YDatabase::getInstance();
     // get k2 categories
     $query = "SELECT a.*, b.name AS extra_field_group_name " . " FROM #__k2_categories AS a" . " LEFT JOIN #__k2_extra_fields_groups AS b ON b.id = a.extraFieldsGroup";
     $categories = $db->queryObjectList($query, 'id');
     // get category table
     $category_table = YTable::getInstance('category');
     // get item table
     $item_table = YTable::getInstance('item');
     // sanatize category aliases
     $aliases = array();
     foreach ($categories as $category) {
         $i = 2;
         $alias = YString::sluggify($category->alias);
         while (in_array($alias, $aliases)) {
             $alias = $category->alias . '-' . $i++;
         }
         $category->alias = $alias;
         // remember used aliases to ensure unique aliases
         $aliases[] = $category->alias;
     }
     // export categories
     foreach ($categories as $category) {
         // assign attributes
         $attributes = array();
         foreach (self::$category_attributes as $attribute) {
             if (isset($category->{$attribute})) {
                 $attributes[$attribute] = $category->{$attribute};
             }
         }
         // sanatize parent
         if ($category->parent && isset($categories[$category->parent])) {
             $attributes['parent'] = $categories[$category->parent]->alias;
         }
         // add category
         $category_xml = $this->_buildCategory($category->alias, $category->name, $attributes);
         if ($category->image) {
             $this->_attachCategoryImage($category_xml, '/media/k2/categories/' . $category->image, 'Image');
         }
         $this->_addCategory($category_xml);
     }
     // get k2 items
     $query = "SELECT * FROM #__k2_items";
     $items = $db->queryObjectList($query, 'id');
     // get k2 extra fields
     $query = "SELECT * FROM #__k2_extra_fields";
     $extra_fields = $db->queryObjectList($query, 'id');
     // get k2 tags
     $query = "SELECT a.itemID, b.name" . " FROM #__k2_tags_xref as a" . " JOIN #__k2_tags AS b ON a.tagID = b.id";
     $tag_result = $db->queryObjectList($query);
     $tags = array();
     foreach ($tag_result as $tag) {
         $tags[$tag->itemID][] = $tag->name;
     }
     // sanatize item aliases
     $aliases = array();
     foreach ($items as $item) {
         $i = 2;
         $alias = YString::sluggify($item->alias);
         while (in_array($alias, $aliases)) {
             $alias = $item->alias . '-' . $i++;
         }
         $item->alias = $alias;
         // remember used aliases to ensure unique aliases
         $aliases[] = $item->alias;
     }
     // export items
     foreach ($items as $item) {
         if (!$item->trash) {
             if (!($type = $categories[$item->catid]->extra_field_group_name)) {
                 $type = JText::_('K2-Unassigned');
             }
             $this->_addItem($type, $this->_itemToXML($item, $categories, $tags, $extra_fields));
         }
     }
     return parent::export();
 }
Пример #20
0
 protected static function _applicationExists($group)
 {
     $result = YTable::getInstance('application')->first(array('conditions' => 'application_group = ' . YDatabase::getInstance()->quote($group)));
     return !empty($result);
 }
Пример #21
0
 public static function deleteCategoryItemRelations($category_id)
 {
     // delete category to item relations
     $query = "DELETE FROM " . ZOO_TABLE_CATEGORY_ITEM . " WHERE category_id = " . (int) $category_id;
     // execute database query
     YDatabase::getInstance()->query($query);
     return true;
 }
Пример #22
0
 public function encodeData()
 {
     if ($this->_element->getItem()) {
         $db = YDatabase::getInstance();
         // calculate rating/votes
         $query = 'SELECT AVG(value) AS rating, COUNT(id) AS votes' . ' FROM ' . ZOO_TABLE_RATING . ' WHERE element_id = ' . $db->Quote($this->_element->identifier) . ' AND item_id = ' . $this->_element->getItem()->id . ' GROUP BY item_id';
         if ($res = $db->queryAssoc($query)) {
             $this->set('votes', $res['votes']);
             $this->set('value', $res['rating']);
         } else {
             $this->set('votes', 0);
             $this->set('value', 0);
         }
     }
     return parent::encodeData();
 }
Пример #23
0
 public function docopy()
 {
     // check for request forgeries
     YRequest::checkToken() or jexit('Invalid Token');
     // init vars
     $now = JFactory::getDate();
     $post = YRequest::get('post');
     $cid = YRequest::getArray('cid', array(), 'int');
     if (count($cid) < 1) {
         JError::raiseError(500, JText::_('Select a item to copy'));
     }
     try {
         // get item table
         $item_table = YTable::getInstance('item');
         $tag_table = YTable::getInstance('tag');
         // get database
         $db = YDatabase::getInstance();
         // copy items
         foreach ($cid as $id) {
             // get item
             $item = $item_table->get($id);
             $elements = $item->getElements();
             $categories = $item->getRelatedCategoryIds();
             // copy item
             $item->id = 0;
             // set id to 0, to force new item
             $item->name .= ' (' . JText::_('Copy') . ')';
             // set copied name
             $item->alias = ItemHelper::getUniqueAlias($id, $item->alias . '-copy');
             // set copied alias
             $item->state = 0;
             // unpublish item
             $item->created = $now->toMySQL();
             $item->created_by = $this->user->get('id');
             $item->modified = $now->toMySQL();
             $item->modified_by = $this->user->get('id');
             $item->hits = 0;
             // copy tags
             $item->setTags($tag_table->getItemTags($id));
             // save copied item/element data
             $item_table->save($item);
             // save category relations
             CategoryHelper::saveCategoryItemRelations($item->id, $categories);
         }
         // set redirect message
         $msg = JText::_('Item Copied');
     } catch (YException $e) {
         // raise notice on exception
         JError::raiseNotice(0, JText::_('Error Copying Item') . ' (' . $e . ')');
         $msg = null;
     }
     $this->setRedirect($this->baseurl, $msg);
 }
Пример #24
0
 public static function doInstall(JInstallerComponent &$component)
 {
     // fix joomla 1.5 bug
     $component->parent->getDBO = $component->parent->getDBO();
     // initialize zoo framework
     require_once $component->parent->getPath('source') . '/admin/config.php';
     // sanatize table indexes
     $index_sql_path = $component->parent->getPath('source') . '/admin/installation/index.sql';
     if (JFile::exists($index_sql_path)) {
         $db = YDatabase::getInstance();
         // read index.sql
         $buffer = JFile::read($index_sql_path);
         // Create an array of queries from the sql file
         jimport('joomla.installer.helper');
         $queries = JInstallerHelper::splitSql($buffer);
         if (!empty($queries)) {
             foreach ($queries as $query) {
                 // replace table prefixes
                 $query = $db->replacePrefix($query);
                 // parse table name
                 preg_match('/ALTER\\s*TABLE\\s*`(.*)`/i', $query, $result);
                 if (count($result) < 2) {
                     continue;
                 }
                 $table = $result[1];
                 // get existing indexes
                 $indexes = $db->queryObjectList('SHOW INDEX FROM ' . $table);
                 // drop existing indexes
                 $removed = array();
                 foreach ($indexes as $index) {
                     if (in_array($index->Key_name, $removed)) {
                         continue;
                     }
                     if ($index->Key_name != 'PRIMARY') {
                         $db->query('DROP INDEX ' . $index->Key_name . ' ON ' . $table);
                         $removed[] = $index->Key_name;
                     }
                 }
                 // add new indexes
                 $db->query($query);
             }
         }
     }
     // applications
     if (!JFolder::exists(ZOO_APPLICATION_PATH)) {
         JFolder::create(ZOO_APPLICATION_PATH);
     }
     $applications = array();
     foreach (JFolder::folders($component->parent->getPath('source') . '/applications', '.', false, true) as $folder) {
         try {
             if ($manifest = InstallHelper::findManifest($folder)) {
                 $name = InstallHelper::getName($manifest);
                 $status = InstallHelper::installApplicationFromFolder($folder);
                 $applications[] = compact('name', 'status');
             }
         } catch (YException $e) {
             $name = basename($folder);
             $status = false;
             $applications[] = compact('name', 'status');
         }
     }
     self::displayResults($applications, 'Applications', 'Application');
     // additional extensions
     // init vars
     $error = false;
     $extensions = array();
     // get plugin files
     $plugin_files = array();
     foreach (YFile::readDirectoryFiles(JPATH_PLUGINS, JPATH_PLUGINS . '/', '/\\.php$/', true) as $file) {
         $plugin_files[] = basename($file);
     }
     // get extensions
     if (isset($component->manifest->additional[0])) {
         $add = $component->manifest->additional[0];
         if (count($add->children())) {
             $exts = $add->children();
             foreach ($exts as $ext) {
                 $installer = new JInstaller();
                 $installer->setOverwrite(true);
                 $update = false;
                 if ($ext->name() == 'module' && JFolder::exists(JPATH_ROOT . '/modules/' . $ext->attributes('name')) || $ext->name() == 'plugin' && in_array($ext->attributes('name') . '.php', $plugin_files)) {
                     $update = true;
                 }
                 $folder = $component->parent->getPath('source') . '/' . $ext->attributes('folder');
                 $folder = rtrim($folder, "\\/") . '/';
                 if (JFolder::exists($folder)) {
                     if ($update) {
                         foreach (YFile::readDirectoryFiles($folder, $folder, '/positions\\.config$/', true) as $file) {
                             JFile::delete($file);
                         }
                     }
                     $extensions[] = array('name' => $ext->data(), 'type' => $ext->name(), 'folder' => $folder, 'installer' => $installer, 'status' => false, 'update' => $update);
                 }
             }
         }
     }
     // install additional extensions
     for ($i = 0; $i < count($extensions); $i++) {
         if (is_dir($extensions[$i]['folder'])) {
             if (@$extensions[$i]['installer']->install($extensions[$i]['folder'])) {
                 $extensions[$i]['status'] = $extensions[$i]['update'] ? 2 : 1;
             } else {
                 $error = true;
                 break;
             }
         }
     }
     // rollback on installation errors
     if ($error) {
         $component->parent->abort(JText::_('Component') . ' ' . JText::_('Install') . ': ' . JText::_('Error'), 'component');
         for ($i = 0; $i < count($extensions); $i++) {
             if ($extensions[$i]['status']) {
                 $extensions[$i]['installer']->abort(JText::_($extensions[$i]['type']) . ' ' . JText::_('Install') . ': ' . JText::_('Error'), $extensions[$i]['type']);
                 $extensions[$i]['status'] = false;
             }
         }
         return false;
     }
     self::displayResults($extensions, 'Extensions', 'Extension');
     // UPGRADES
     // get versions
     $new_version = $component->manifest->getElementByPath('version')->data();
     $version = '';
     // check for old version number
     $version_file_path = $component->parent->getPath('extension_administrator') . '/version.php';
     if (JFile::exists($version_file_path)) {
         require_once $version_file_path;
     }
     // write new version file
     $buffer = "<?php\n\ndefined('_JEXEC') or die('Restricted access');\n\n\$version = '{$new_version}';";
     JFile::write($version_file_path, $buffer);
     // include update script
     require_once $component->parent->getPath('source') . '/admin/installation/update.php';
     return true;
 }
Пример #25
0
 protected function _loadGeneralCSS()
 {
     // Load the template name from the database
     $query = 'SELECT template' . ' FROM #__templates_menu' . ' WHERE client_id = 1' . ' AND menuid = 0';
     $template = YDatabase::getInstance()->queryResult($query);
     $template = JFilterInput::clean($template, 'cmd');
     if (!file_exists(JPATH_ROOT . DS . 'administrator' . DS . $template . DS . 'index.php')) {
         $template = 'khepri';
     }
     JHTML::stylesheet('general.css', 'administrator/templates/' . $template . '/css/');
 }