function display($tpl = null) { //initialise variables $mainframe = JFactory::getApplication(); $option = JRequest::getVar('option'); $document = JFactory::getDocument(); $user = JFactory::getUser(); $db = JFactory::getDBO(); JHTML::_('behavior.tooltip'); JHTML::_('behavior.modal'); //add css and submenu to document $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/flexicontentbackend.css'); if (FLEXI_J30GE) { $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j3x.css'); } else { if (FLEXI_J16GE) { $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j25.css'); } else { $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j15.css'); } } $permission = FlexicontentHelperPerm::getPerm(); if (!$permission->CanTemplates) { $mainframe->redirect('index.php?option=com_flexicontent', JText::_('FLEXI_NO_ACCESS')); } // Get User's Global Permissions $perms = FlexicontentHelperPerm::getPerm(); //Create Submenu FLEXISubmenu('CanTemplates'); // Create document/toolbar titles $doc_title = JText::_('FLEXI_TEMPLATES'); $site_title = $document->getTitle(); JToolBarHelper::title($doc_title, 'templates'); $document->setTitle($doc_title . ' - ' . $site_title); // Create the toolbar //JToolBarHelper::Back(); if ($perms->CanConfig) { //JToolBarHelper::divider(); JToolBarHelper::spacer(); $session = JFactory::getSession(); $fc_screen_width = (int) $session->get('fc_screen_width', 0, 'flexicontent'); $_width = $fc_screen_width && $fc_screen_width - 84 > 940 ? $fc_screen_width - 84 > 1400 ? 1400 : $fc_screen_width - 84 : 940; $fc_screen_height = (int) $session->get('fc_screen_height', 0, 'flexicontent'); $_height = $fc_screen_height && $fc_screen_height - 128 > 550 ? $fc_screen_height - 128 > 1000 ? 1000 : $fc_screen_height - 128 : 550; JToolBarHelper::preferences('com_flexicontent', $_height, $_width, 'Configuration'); } $tmpldirectory = JPATH_COMPONENT_SITE . DS . 'templates' . DS; $source = JRequest::getString('source', ''); $dest = $source ? flexicontent_upload::sanitizedir($tmpldirectory, $source) : ''; //Get data from the model $rows = $this->get('Data'); //assign data to template $this->assignRef('rows', $rows); $this->assignRef('user', $user); $this->assignRef('tmpldirectory', $tmpldirectory); $this->assignRef('source', $source); $this->assignRef('dest', $dest); parent::display($tpl); }
function getUploadLimitsTxt(&$field) { $tip_class = FLEXI_J30GE ? ' hasTooltip' : ' hasTip'; $hint_image = JHTML::image('components/com_flexicontent/assets/images/comment.png', JText::_('FLEXI_NOTES'), ''); $upload_maxsize = $field->parameters->get('upload_maxsize'); $phpUploadLimit = flexicontent_upload::getPHPuploadLimit(); $server_limit_exceeded = $phpUploadLimit['value'] < $upload_maxsize; if ($server_limit_exceeded) { $warn_image = JHTML::image('components/com_flexicontent/assets/images/warning.png', JText::_('FLEXI_NOTES'), ''); } $conf_limit_class = $server_limit_exceeded ? '' : 'badge-success'; $conf_limit_style = $server_limit_exceeded ? 'text-decoration: line-through;' : ''; $conf_lim_image = $server_limit_exceeded ? $warn_image . $hint_image : $hint_image; $sys_limit_class = $server_limit_exceeded ? 'badge-important' : ''; return ' <span class="fc-img-field-upload-limits-box"> <span class="label label-info fc-upload-box-lbl">' . JText::_($server_limit_exceeded ? 'FLEXI_UPLOAD_LIMITS' : 'FLEXI_UPLOAD_LIMIT') . '</span> <span class="fc-php-upload-limit-box"> <span class="' . $tip_class . '" style="margin-left:24px;" title="' . flexicontent_html::getToolTip('FLEXI_FIELD_CONF_UPLOAD_MAX_LIMIT', 'FLEXI_FIELD_CONF_UPLOAD_MAX_LIMIT_DESC', 1, 1) . '">' . $conf_lim_image . '</span> <span class="badge ' . $conf_limit_class . '" style="' . $conf_limit_style . '">' . round($upload_maxsize / (1024 * 1024), 2) . ' M </span> </span> ' . ($server_limit_exceeded ? ' <span class="fc-sys-upload-limit-box"> <span class="' . $tip_class . '" style="margin-left:24px;" title="' . flexicontent_html::getToolTip(JText::_('FLEXI_SERVER_UPLOAD_MAX_LIMIT'), JText::sprintf('FLEXI_SERVER_UPLOAD_MAX_LIMIT_DESC', $phpUploadLimit['name']), 0, 1) . '">' . $hint_image . '</span> <span class="badge ' . $sys_limit_class . '">' . round($phpUploadLimit['value'] / (1024 * 1024), 2) . ' M </span> </span>' : '') . ' </span> '; }
/** * Upload a file from a server directory * * @since 1.0 */ function addlocal() { // Check for request forgeries JRequest::checkToken('request') or jexit('Invalid Token'); $app = JFactory::getApplication(); $db = JFactory::getDBO(); $user = JFactory::getUser(); $return = JRequest::getVar('return-url', null, 'post', 'base64'); $filesdir = JRequest::getVar('file-dir-path', '', 'post'); $regexp = JRequest::getVar('file-filter-re', '.', 'post'); $secure = JRequest::getInt('secure', 1, 'post'); $secure = $secure ? 1 : 0; $keep = JRequest::getInt('keep', 1, 'post'); $params = JComponentHelper::getParams('com_flexicontent'); $destpath = $secure ? COM_FLEXICONTENT_FILEPATH . DS : COM_FLEXICONTENT_MEDIAPATH . DS; $filedesc = JRequest::getVar('file-desc', ''); $filelang = JRequest::getVar('file-lang', ''); // allowed extensions $filterext = JRequest::getVar('file-filter-ext', '', 'post'); $filterext = $filterext ? explode(',', $filterext) : array(); foreach ($filterext as $_i => $_ext) { $filterext[$_i] = strtolower($_ext); } $confext = preg_split("/[\\s]*,[\\s]*/", strtolower($params->get('upload_extensions', 'bmp,csv,doc,gif,ico,jpg,jpeg,odg,odp,ods,odt,pdf,png,ppt,swf,txt,xcf,xls,zip,ics'))); // (optionally) Limit COMPONENT configured extensions, to those extensions requested by the FORM/URL variable $allowed = $filterext ? array_intersect($filterext, $confext) : $confext; jimport('joomla.utilities.date'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); $filesdir = JPath::clean(JPATH_SITE . $filesdir . DS); $filenames = JFolder::files($filesdir, $regexp); // create the folder if it doesnt exists if (!JFolder::exists($destpath)) { if (!JFolder::create($destpath)) { JError::raiseWarning(100, JText::_('Error. Unable to create folders')); return; } } // check if the form fields are not empty if (!$filesdir) { JError::raiseNotice(1, JText::_('FLEXI_WARN_NO_FILE_DIR')); if (!$return) { return; } // REDIRECT only if this was requested $app->redirect(base64_decode($return) . "&" . (FLEXI_J30GE ? JSession::getFormToken() : JUtility::getToken()) . "=1"); } $c = 0; $file_ids = array(); if ($filenames) { for ($n = 0; $n < count($filenames); $n++) { $ext = strtolower(JFile::getExt($filesdir . $filenames[$n])); if (!in_array($ext, $allowed)) { continue; } $source = $filesdir . $filenames[$n]; $filename = flexicontent_upload::sanitize($destpath, $filenames[$n]); $destination = $destpath . $filename; // Copy or move the file $success = $keep ? JFile::copy($source, $destination) : JFile::move($source, $destination); if ($success) { $filesize = filesize($destination); $obj = new stdClass(); $obj->filename = $filename; $obj->altname = $filename; $obj->url = 0; $obj->secure = $secure; $obj->ext = $ext; $obj->description = $filedesc; $obj->language = $filelang ? $filelang : '*'; $obj->hits = 0; $obj->size = $filesize; $obj->uploaded = JFactory::getDate('now')->toSql(); $obj->uploaded_by = $user->get('id'); // Add the record to the DB $db->insertObject('#__flexicontent_files', $obj); $file_ids[$filename] = $db->insertid(); $c++; } } $app->enqueueMessage(JText::sprintf('FLEXI_FILES_COPIED_SUCCESS', $c)); } else { JError::raiseNotice(1, JText::_('FLEXI_WARN_NO_FILES_IN_DIR')); if (!$return) { return; } // REDIRECT only if this was requested $app->redirect(base64_decode($return) . "&" . (FLEXI_J30GE ? JSession::getFormToken() : JUtility::getToken()) . "=1"); } if (!$return) { return $file_ids; } // REDIRECT only if this was requested $app->redirect(base64_decode($return) . "&" . (FLEXI_J30GE ? JSession::getFormToken() : JUtility::getToken()) . "=1"); }
/** * Checks uploaded file * * @param string $file The file name * @param string $err Set (return) the error string in it * @param string $file view 's parameters * @return string The file extension * @since 1.5 */ static function check(&$file, &$err, &$params) { if (!$params) { $params = JComponentHelper::getParams('com_flexicontent'); } if (empty($file['name'])) { $err = 'FLEXI_PLEASE_INPUT_A_FILE'; return false; } jimport('joomla.filesystem.file'); $file['altname'] = $file['name']; if ($file['name'] !== JFile::makesafe($file['name'])) { //$err = JText::_('FLEXI_WARNFILENAME').','.$file['name'].'|'.JFile::makesafe($file['name'])."<br/>"; //return false; $file['name'] = date('Y-m-d-H-i-s') . "." . flexicontent_upload::getExt($file['name']); } // *************************************** // Check if the image file type is allowed // *************************************** $format = strtolower(flexicontent_upload::getExt($file['name'])); $allowed_exts = $params->get('upload_extensions', 'bmp,csv,doc,docx,gif,ico,jpg,jpeg,odg,odp,ods,odt,pdf,png,ppt,pptx,swf,txt,xcf,xls,xlsx,zip,ics'); $allowed_exts = preg_split("/[\\s]*,[\\s]*/", $allowed_exts); foreach ($allowed_exts as $a => $allowed_ext) { $allowed_exts[$a] = strtolower($allowed_ext); } $ignored = explode(',', $params->get('ignore_extensions')); foreach ($ignored as $a => $ignored_ext) { $ignored[$a] = strtolower($ignored_ext); } if (!in_array($format, $allowed_exts) && !in_array($format, $ignored)) { $err = 'FLEXI_WARNFILETYPE'; return false; } // ************** // Check filesize // ************** $maxSize = (int) $params->get('upload_maxsize', 0); if ($maxSize > 0 && (int) $file['size'] > $maxSize) { $err = 'FLEXI_WARNFILETOOLARGE'; return false; } $imginfo = null; $images = explode(',', $params->get('image_extensions')); if ($params->get('restrict_uploads', 1)) { if (in_array($format, $images)) { // if its an image run it through getimagesize if (($imginfo = getimagesize($file['tmp_name'])) === FALSE) { $err = 'FLEXI_WARNINVALIDIMG'; return false; } } else { if (!in_array($format, $ignored)) { // if its not an image...and we're not ignoring it $allowed_mime = explode(',', $params->get('upload_mime')); $illegal_mime = explode(',', $params->get('upload_mime_illegal')); if (function_exists('finfo_open') && $params->get('check_mime', 1)) { // We have fileinfo $finfo = finfo_open(FILEINFO_MIME); $type = finfo_file($finfo, $file['tmp_name']); if (strlen($type) && !in_array($type, $allowed_mime) && in_array($type, $illegal_mime)) { $err = 'FLEXI_WARNINVALIDMIME'; return false; } finfo_close($finfo); } else { if (function_exists('mime_content_type') && $params->get('check_mime', 1)) { // we have mime magic $type = mime_content_type($file['tmp_name']); if (strlen($type) && !in_array($type, $allowed_mime) && in_array($type, $illegal_mime)) { $err = 'FLEXI_WARNINVALIDMIME'; return false; } } } } } } // *************************** // Check fof XSS safe contents // *************************** $xss_check = JFile::read($file['tmp_name'], false, 256); $html_tags = array('abbr', 'acronym', 'address', 'applet', 'area', 'audioscope', 'base', 'basefont', 'bdo', 'bgsound', 'big', 'blackface', 'blink', 'blockquote', 'body', 'bq', 'br', 'button', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'comment', 'custom', 'dd', 'del', 'dfn', 'dir', 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'fn', 'font', 'form', 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'hr', 'html', 'iframe', 'ilayer', 'img', 'input', 'ins', 'isindex', 'keygen', 'kbd', 'label', 'layer', 'legend', 'li', 'limittext', 'link', 'listing', 'map', 'marquee', 'menu', 'meta', 'multicol', 'nobr', 'noembed', 'noframes', 'noscript', 'nosmartquotes', 'object', 'ol', 'optgroup', 'option', 'param', 'plaintext', 'pre', 'rt', 'ruby', 's', 'samp', 'script', 'select', 'server', 'shadow', 'sidebar', 'small', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'title', 'tr', 'tt', 'ul', 'var', 'wbr', 'xml', 'xmp', '!DOCTYPE', '!--'); foreach ($html_tags as $tag) { // A tag is '<tagname ', so we need to add < and a space or '<tagname>' if (stristr($xss_check, '<' . $tag . ' ') || stristr($xss_check, '<' . $tag . '>')) { $err = 'FLEXI_WARNIEXSS'; return false; } } return true; }
/** * Method to add flexi extended datas to standard content * * @params object the unassociated items rows * @params boolean add the records from the items_ext table * @return boolean * @since 1.5 */ function bindExtData($rows) { if (!$rows || !count($rows)) { return; } $app = JFactory::getApplication(); $jinput = $app->input; $search_prefix = $this->cparams->get('add_search_prefix') ? 'vvv' : ''; // SEARCH WORD Prefix $typeid = $jinput->get('typeid', 1, 'int'); $default_cat = $jinput->get('default_cat', 0, 'int'); $default_lang = flexicontent_html::getSiteDefaultLang(); // Get invalid cats, to avoid using them during binding, this is only done once $session = JFactory::getSession(); $badcats_fixed = $session->get('badcats', null, 'flexicontent'); if ($badcats_fixed === null) { // Correct non-existent main category in content table $query = 'UPDATE #__content as c ' . ' LEFT JOIN #__categories as cat ON c.catid=cat.id' . ' SET c.catid=' . $default_cat . ' WHERE cat.id IS NULL'; $this->_db->setQuery($query); $this->_db->execute(); $session->set('badcats_fixed', 1, 'flexicontent'); } // Calculate item data to be used for current bind STEP $catrel = array(); foreach ($rows as $row) { $row_catid = (int) $row->catid; $catrel[] = '(' . $row_catid . ', ' . (int) $row->id . ')'; // append the text property to the object if (JString::strlen($row->fulltext) > 1) { $row->text_stripped = $row->introtext . '<hr id="system-readmore" />' . $row->fulltext; } else { $row->text_stripped = flexicontent_html::striptagsandcut($row->introtext); } } // Insert main category-item relation via single query $catrel = implode(', ', $catrel); $query = "INSERT INTO #__flexicontent_cats_item_relations (`catid`, `itemid`) " . " VALUES " . $catrel . " ON DUPLICATE KEY UPDATE ordering=ordering"; $this->_db->setQuery($query); $this->_db->execute(); $query = "SHOW VARIABLES LIKE 'max_allowed_packet'"; $this->_db->setQuery($query); $_dbvariable = $this->_db->loadObject(); $max_allowed_packet = flexicontent_upload::parseByteLimit(@$_dbvariable->Value); $max_allowed_packet = $max_allowed_packet ? $max_allowed_packet : 256 * 1024; $query_lim = (int) (3 * $max_allowed_packet / 4); // Insert items_ext datas, // NOTE: we will not use a single query for creating multiple records, instead we will create only e.g. 100 at once, // because of the column search_index which can be quite long $itemext = array(); $id_arr = array(); $row_count = count($rows); $n = 0; $i = 0; $query_len = 0; foreach ($rows as $row) { $ilang = $row->language ? $row->language : $default_lang; if ($search_prefix) { $_search_index = preg_replace('/(\\b[^\\s,\\.]+\\b)/u', $search_prefix . '$0', $row->title . ' | ' . $row->text_stripped); } else { $_search_index = $row->title . ' | ' . $row->text_stripped; } $itemext[$i] = '(' . (int) $row->id . ', ' . $typeid . ', ' . $this->_db->Quote($ilang) . ', ' . $this->_db->Quote($_search_index) . ', 0)'; $id_arr[$i] = (int) $row->id; $query_len += strlen($itemext[$i]) + 2; // Sum of query length so far $n++; $i++; if ($n % 101 == 0 || $n == $row_count || $query_len > $query_lim) { $itemext_list = implode(', ', $itemext); $query = "INSERT INTO #__flexicontent_items_ext (`item_id`, `type_id`, `language`, `search_index`, `lang_parent_id`)" . " VALUES " . $itemext_list . " ON DUPLICATE KEY UPDATE type_id=VALUES(type_id), language=VALUES(language), search_index=VALUES(search_index)"; $this->_db->setQuery($query); $this->_db->execute(); // reset the item array $itemext = array(); $query = "UPDATE #__flexicontent_items_tmp" . " SET type_id=" . $typeid . " WHERE id IN(" . implode(',', $id_arr) . ")"; $this->_db->setQuery($query); $this->_db->execute(); // reset the item id array $id_arr = array(); $i = 0; // reset sub-counter, and query length $query_len = 0; } } // Update temporary item data $this->updateItemCountingData($rows); }
/** * Method to duplicate a template folder * * @access public * @return boolean true on success * @since 1.5 */ function duplicate($source, $dest) { jimport('joomla.filesystem.folder'); $path = JPATH_COMPONENT_SITE . DS . 'templates' . DS; $dest = $dest ? flexicontent_upload::sanitizedir($path, $dest) : ''; if (!$source || !$dest) { return false; } if (!JFolder::copy($source, $dest, $path)) { return false; } return true; }
<?php if (!$this->CanUpload) { ?> <?php echo sprintf($alert_box, '', 'note', '', JText::_('FLEXI_YOUR_ACCOUNT_CANNOT_UPLOAD')); ?> <?php } else { ?> <!-- File Upload Form --> <fieldset class="filemanager-tab" > <?php // Configuration $upload_maxsize = $this->params->get('upload_maxsize'); $phpUploadLimit = flexicontent_upload::getPHPuploadLimit(); $server_limit_exceeded = $phpUploadLimit['value'] < $upload_maxsize; $conf_limit_class = $server_limit_exceeded ? '' : 'badge-success'; $conf_limit_style = $server_limit_exceeded ? 'text-decoration: line-through;' : ''; $conf_lim_image = $server_limit_exceeded ? $warn_image . $hint_image : $hint_image; $sys_limit_class = $server_limit_exceeded ? 'badge-important' : ''; echo ' <span class="fc-fileman-upload-limits-box"> <span class="label label-info">' . JText::_('FLEXI_UPLOAD_LIMITS') . '</span> <span class="fc-sys-upload-limit-box"> <span class="' . $tip_class . '" style="margin-left:24px;" title="' . flexicontent_html::getToolTip('FLEXI_CONF_UPLOAD_MAX_LIMIT', 'FLEXI_CONF_UPLOAD_MAX_LIMIT_DESC', 1, 1) . '">' . $conf_lim_image . '</span> <span class="badge ' . $conf_limit_class . '" style="' . $conf_limit_style . '">' . round($upload_maxsize / (1024 * 1024), 2) . ' M </span> </span> <span class="fc-php-upload-limit-box"> <span class="' . $tip_class . '" style="margin-left:24px;" title="' . flexicontent_html::getToolTip(JText::_('FLEXI_SERVER_UPLOAD_MAX_LIMIT'), JText::sprintf('FLEXI_SERVER_UPLOAD_MAX_LIMIT_DESC', $phpUploadLimit['name']), 0, 1) . '">' . $hint_image . '</span> <span class="badge ' . $sys_limit_class . '">' . round($phpUploadLimit['value'] / (1024 * 1024), 2) . ' M </span>
function display($tpl = null) { // ******************** // Initialise variables // ******************** $app = JFactory::getApplication(); $jinput = $app->input; $option = $jinput->get('option', '', 'cmd'); $view = $jinput->get('view', '', 'cmd'); $cparams = JComponentHelper::getParams('com_flexicontent'); $user = JFactory::getUser(); $db = JFactory::getDBO(); $document = JFactory::getDocument(); // ************************** // Add css and js to document // ************************** flexicontent_html::loadFramework('select2'); //JHTML::_('behavior.tooltip'); $document->addStyleSheetVersion(JURI::base(true) . '/components/com_flexicontent/assets/css/flexicontentbackend.css', FLEXI_VHASH); $document->addStyleSheetVersion(JURI::base(true) . '/components/com_flexicontent/assets/css/j3x.css', FLEXI_VHASH); // ***************************** // Get user's global permissions // ***************************** $perms = FlexicontentHelperPerm::getPerm(); if (!$perms->CanTemplates) { $app->redirect('index.php?option=com_flexicontent', JText::_('FLEXI_NO_ACCESS')); } // ************************ // Create Submenu & Toolbar // ************************ // Create Submenu (and also check access to current view) FLEXISubmenu('CanTemplates'); // Create document/toolbar titles $doc_title = JText::_('FLEXI_TEMPLATES'); $site_title = $document->getTitle(); JToolBarHelper::title($doc_title, 'templates'); $document->setTitle($doc_title . ' - ' . $site_title); // Create the toolbar $appsman_path = JPATH_COMPONENT_ADMINISTRATOR . DS . 'views' . DS . 'appsman'; if (file_exists($appsman_path)) { $btn_icon = 'icon-download'; $btn_name = 'download'; $btn_task = 'appsman.exportxml'; $extra_js = " var f=document.getElementById('adminForm'); f.elements['view'].value='appsman'; jQuery('<input>').attr({type: 'hidden', name: 'table', value: 'flexicontent_templates'}).appendTo(jQuery(f));"; flexicontent_html::addToolBarButton('Export now', $btn_name, $full_js = '', $msg_alert = '', $msg_confirm = 'Export now as XML', $btn_task, $extra_js, $btn_list = false, $btn_menu = true, $btn_confirm = true, $btn_class = "btn-warning", $btn_icon); $btn_icon = 'icon-box-add'; $btn_name = 'box-add'; $btn_task = 'appsman.addtoexport'; $extra_js = " var f=document.getElementById('adminForm'); f.elements['view'].value='appsman'; jQuery('<input>').attr({type: 'hidden', name: 'table', value: 'flexicontent_templates'}).appendTo(jQuery(f));"; flexicontent_html::addToolBarButton('Add to export', $btn_name, $full_js = '', $msg_alert = '', $msg_confirm = 'Add to export list', $btn_task, $extra_js, $btn_list = false, $btn_menu = true, $btn_confirm = true, $btn_class = "btn-warning", $btn_icon); } //JToolBarHelper::Back(); if ($perms->CanConfig) { //JToolBarHelper::divider(); JToolBarHelper::spacer(); $session = JFactory::getSession(); $fc_screen_width = (int) $session->get('fc_screen_width', 0, 'flexicontent'); $_width = $fc_screen_width && $fc_screen_width - 84 > 940 ? $fc_screen_width - 84 > 1400 ? 1400 : $fc_screen_width - 84 : 940; $fc_screen_height = (int) $session->get('fc_screen_height', 0, 'flexicontent'); $_height = $fc_screen_height && $fc_screen_height - 128 > 550 ? $fc_screen_height - 128 > 1000 ? 1000 : $fc_screen_height - 128 : 550; JToolBarHelper::preferences('com_flexicontent', $_height, $_width, 'Configuration'); } $tmpldirectory = JPATH_COMPONENT_SITE . DS . 'templates' . DS; $source = JRequest::getString('source', ''); $dest = $source ? flexicontent_upload::sanitizedir($tmpldirectory, $source) : ''; //Get data from the model $rows = $this->get('Data'); // Get layout data /*$tmpl = flexicontent_tmpl::getTemplates(); foreach($rows as $row) { $row->item_layout = @ $tmpl->items->{$row->name}; $row->category_layout = @ $tmpl->category->{$row->name}; }*/ //assign data to template $this->assignRef('rows', $rows); $this->assignRef('user', $user); $this->assignRef('tmpldirectory', $tmpldirectory); $this->assignRef('source', $source); $this->assignRef('dest', $dest); $this->sidebar = FLEXI_J30GE ? JHtmlSidebar::render() : null; parent::display($tpl); }
function uploadOriginalFile($field, &$post, $file) { $app = JFactory::getApplication(); $format = JRequest::getVar('format', 'html', '', 'cmd'); $err = null; // Get the component configuration $cparams = JComponentHelper::getParams('com_flexicontent'); $params = clone $cparams; // Merge field parameters into the global parameters $fparams = $field->parameters; $params->merge($fparams); jimport('joomla.utilities.date'); jimport('joomla.filesystem.file'); jimport('joomla.client.helper'); // Set FTP credentials, if given JClientHelper::setCredentialsFromRequest('ftp'); // Make the filename safe $file['name'] = JFile::makeSafe($file['name']); $all_media = $field->parameters->get('list_all_media_files', 0); $unique_thumb_method = $field->parameters->get('unique_thumb_method', 0); $image_source = $field->parameters->get('image_source', 0); // This should be always ZERO inside this function if ($image_source > 1) { global $fc_folder_mode_err; if (empty($fc_folder_mode_err[$field->id])) { echo __FUNCTION__ . "(): folder-mode: " . $image_source . " not implemented please change image-source mode in image/gallery field with id: " . $field->id; $fc_folder_mode_err[$field->id] = 1; $image_source = 1; } } // FLAG to indicate if images are shared across fields, has the effect of adding field id to image thumbnails $multiple_image_usages = !$image_source && $all_media && $unique_thumb_method == 0; $extra_prefix = $multiple_image_usages ? 'fld' . $field->id . '_' : ''; if (isset($file['name']) && $file['name'] != '') { // only handle the secure folder $path = COM_FLEXICONTENT_FILEPATH . DS; //sanitize filename further and make unique $filename = flexicontent_upload::sanitize($path, $file['name']); $filepath = JPath::clean(COM_FLEXICONTENT_FILEPATH . DS . strtolower($filename)); //perform security check according if (!flexicontent_upload::check($file, $err, $params)) { if ($format == 'json') { jimport('joomla.error.log'); $log = JLog::getInstance('com_flexicontent.error.php'); $log->addEntry(array('comment' => 'Invalid: ' . $filepath . ': ' . $err)); header('HTTP/1.0 415 Unsupported Media Type'); die('Error. Unsupported Media Type!'); } else { JError::raiseNotice(100, $field->label . ' : ' . JText::_($err)); return; } } //get the extension to record it in the DB $ext = strtolower(JFile::getExt($filename)); if (!JFile::upload($file['tmp_name'], $filepath)) { if ($format == 'json') { jimport('joomla.error.log'); $log = JLog::getInstance('com_flexicontent.error.php'); $log->addEntry(array('comment' => 'Cannot upload: ' . $filepath)); header('HTTP/1.0 409 Conflict'); jexit('Error. File already exists'); } else { JError::raiseWarning(100, $field->label . ' : ' . JText::_('Error. Unable to upload file')); return; } } else { $db = JFactory::getDBO(); $user = JFactory::getUser(); $config = JFactory::getConfig(); $timezone = $config->get('offset'); if (FLEXI_J16GE) { $date = JFactory::getDate('now'); $date->setTimeZone(new DateTimeZone($timezone)); } else { $tz_offset = $timezone; $date = JFactory::getDate('now', $tz_offset); } $obj = new stdClass(); $obj->filename = $filename; $obj->altname = $file['name']; $obj->url = 0; $obj->secure = 1; $obj->ext = $ext; $obj->hits = 0; $obj->uploaded = FLEXI_J16GE ? $date->toSql() : $date->toMySQL(); $obj->uploaded_by = $user->get('id'); if ($format == 'json') { jimport('joomla.error.log'); $log = JLog::getInstance(); $log->addEntry(array('comment' => $filepath)); $db->insertObject('#__flexicontent_files', $obj); jexit('Upload complete'); } else { $db->insertObject('#__flexicontent_files', $obj); $app->enqueueMessage($field->label . ' : ' . JText::_('Upload complete')); $sizes = array('l', 'm', 's', 'b'); foreach ($sizes as $size) { // create the thumbnail $this->create_thumb($field, $filename, $size, $origpath = '', $destpath = '', $copy_original = 0, $extra_prefix); // set the filename for posting $post['originalname'] = $filename; } return; } } } }
function index() { $start_microtime = microtime(true); $session = JFactory::getSession(); $db = JFactory::getDBO(); // Test indexing with limited memory //ini_set("memory_limit", "20M"); @ob_end_clean(); $search_prefix = JComponentHelper::getParams('com_flexicontent')->get('add_search_prefix') ? 'vvv' : ''; // SEARCH WORD Prefix $indexer = JRequest::getVar('indexer', 'advanced'); $rebuildmode = JRequest::getVar('rebuildmode', ''); $items_per_call = JRequest::getVar('items_per_call', 20); // Number of item to index per HTTP request $itemcnt = JRequest::getVar('itemcnt', 0); // Counter of items indexed so far, this is given via HTTP request // TAKE CARE: this code depends on countrows() to set session variables // Retrieve fields, that are assigned as (advanced/basic) searchable/filterable if ($rebuildmode == 'quick' && $indexer == 'advanced') { $nse_fields = $session->get($indexer . '_nse_fields', array(), 'flexicontent'); $nsp_fields = $session->get($indexer . '_nsp_fields', array(), 'flexicontent'); $fields = $session->get($indexer . '_fields', array(), 'flexicontent'); //echo 'fail|'; print_r(array_keys($fields)); exit; // Get the field ids of the fields removed from searching $del_fieldids = array_unique(array_merge(array_keys($nse_fields), array_keys($nsp_fields), array_keys($fields))); } else { $fields = $session->get($indexer . '_fields', array(), 'flexicontent'); //echo 'fail|'; print_r(array_keys($fields)); exit; } // Get the field ids of the searchable fields $fieldids = array_keys($fields); // Get fields that will have atomic search tables, (current for advanced index only) if ($indexer == 'advanced') { $filterables = FlexicontentFields::getSearchFields('id', $indexer, null, null, $_load_params = false, 0, $search_type = 'filter'); $filterables = array_keys($filterables); $filterables = array_flip($filterables); } else { $filterables = array(); } // Get items ids that have value for any of the searchable fields, but use session to avoid recalculation $itemids = $session->get($indexer . '_items_to_index', array(), 'flexicontent'); $_fields = array(); foreach ($fields as $field_id => $field) { // Clone field to avoid problems $_fields[$field_id] = clone $field; // Create field parameters if not already created if (empty($_fields[$field_id]->parameters)) { $_fields[$field_id]->parameters = new JRegistry($_fields[$field_id]->attribs); } } $fields = $_fields; // Get query size limit $query = "SHOW VARIABLES LIKE 'max_allowed_packet'"; $db->setQuery($query); $_dbvariable = $db->loadObject(); $max_allowed_packet = flexicontent_upload::parseByteLimit(@$_dbvariable->Value); $max_allowed_packet = $max_allowed_packet ? $max_allowed_packet : 256 * 1024; $query_lim = (int) (3 * $max_allowed_packet / 4); //echo 'fail|'.$query_lim; exit; // Get script max $max_execution_time = ini_get("max_execution_time"); //echo 'fail|'.$max_execution_time; exit; $query_count = 0; $max_items_per_query = 100; $max_items_per_query = $max_items_per_query > $items_per_call ? $items_per_call : $max_items_per_query; $cnt = $itemcnt; while ($cnt < count($itemids) && $cnt < $itemcnt + $items_per_call) { $query_itemids = array_slice($itemids, $cnt, $max_items_per_query); $cnt += $max_items_per_query; // Item is not needed, later and only if field uses item replacements then it will be loaded $item = null; // Items language is needed to do (if needed) special per language handling $lang_query = "SELECT id, language" . " FROM #__content AS i " . " WHERE id IN (" . implode(', ', $query_itemids) . ")"; $db->setQuery($lang_query); $items_data = $db->loadObjectList('id'); if ($indexer == 'basic') { $searchindex = array(); // Add all query itemids to searchindex array so that it will be cleared even if zero fields are indexed foreach ($query_itemids as $query_itemid) { $searchindex[$query_itemid] = array(); } } else { // This will hold the SQL inserting new advanced search records for multiple item/values $ai_query_vals = array(); $ai_query_vals_f = array(); // Current for advanced index only } // For current item: Loop though all searchable fields according to their type foreach ($fieldids as $fieldid) { // Must SHALLOW clone because we will be setting some properties , e.g. 'ai_query_vals', that we do not $field = clone $fields[$fieldid]; // Indicate multiple items per query $field->item_id = 0; $field->query_itemids = $query_itemids; $field->items_data = $items_data; // Includes item langyage, which may be used for special per language handling // Indicate that the indexing fuction should retrieve the values $values = null; // Add values to advanced search index $fieldname = $field->iscore ? 'core' : $field->field_type; if ($indexer == 'advanced') { FLEXIUtilities::call_FC_Field_Func($fieldname, 'onIndexAdvSearch', array(&$field, &$values, &$item)); //print_r($field->ai_query_vals); if (isset($field->ai_query_vals)) { foreach ($field->ai_query_vals as $query_val) { $ai_query_vals[] = $query_val; } if (isset($filterables[$field->id])) { // Current for advanced index only foreach ($field->ai_query_vals as $query_val) { $ai_query_vals_f[$field->id][] = $query_val; } } } //else echo "Not set for : ". $field->name; } else { if ($indexer == 'basic') { FLEXIUtilities::call_FC_Field_Func($fieldname, 'onIndexSearch', array(&$field, &$values, &$item)); foreach ($query_itemids as $query_itemid) { if (@$field->search[$query_itemid]) { $searchindex[$query_itemid][] = $field->search[$query_itemid]; } } } } } // Create query that will update/insert data into the DB unset($queries); // make sure it is not set above $queries = array(); if ($indexer == 'basic') { if (count($searchindex)) { // check for zero search index records $query_vals = ''; $query_ids = array(); // Start new query foreach ($searchindex as $query_itemid => $search_text) { if (strlen($query_vals) > $query_lim) { $query = "UPDATE #__flexicontent_items_ext SET search_index = CASE item_id " . $query_vals . " END " . " WHERE item_id IN (" . implode(',', $query_ids) . ")"; $queries[] = $query; $query_vals = ''; $query_ids = array(); // Start new query } $query_ids[] = $query_itemid; $_search_text = implode(' | ', $search_text); if ($search_prefix && $_search_text) { $_search_text = preg_replace('/(\\b[^\\s,\\.]+\\b)/u', $search_prefix . '$0', trim($_search_text)); } $query_vals .= " WHEN {$query_itemid} THEN " . $db->Quote($_search_text); } if (count($query_ids)) { $query = "UPDATE #__flexicontent_items_ext SET search_index = CASE item_id " . $query_vals . " END " . " WHERE item_id IN (" . implode(',', $query_ids) . ")"; $queries[] = $query; } } } else { if (count($ai_query_vals)) { // check for zero search index records $query_vals = ''; // Start new query foreach ($ai_query_vals as &$query_value) { $query_vals .= ($query_vals ? ',' : '') . $query_value; if (strlen($query_vals) > $query_lim) { $queries[] = "INSERT INTO #__flexicontent_advsearch_index " . " (field_id,item_id,extraid,search_index,value_id) VALUES " . $query_vals; $query_vals = ''; // Start new query } } unset($query_value); if (strlen($query_vals)) { $queries[] = "INSERT INTO #__flexicontent_advsearch_index " . " (field_id,item_id,extraid,search_index,value_id) VALUES " . $query_vals; } } foreach ($ai_query_vals_f as $_field_id => $_query_vals) { $query_vals = ''; // Start new query foreach ($_query_vals as &$query_value) { $query_vals .= ($query_vals ? ',' : '') . $query_value; if (strlen($query_vals) > $query_lim) { $queries[] = "INSERT INTO #__flexicontent_advsearch_index_field_" . $_field_id . " (field_id,item_id,extraid,search_index,value_id) VALUES " . $query_vals; $query_vals = ''; // Start new query } } if (strlen($query_vals)) { $queries[] = "INSERT INTO #__flexicontent_advsearch_index_field_" . $_field_id . " (field_id,item_id,extraid,search_index,value_id) VALUES " . $query_vals; $query_vals = ''; // Start new query } } } foreach ($queries as $query) { $db->setQuery($query); try { $db->execute(); } catch (RuntimeException $e) { echo "fail|" . $e->getMessage(); exit; } } $query_count += count($queries); $elapsed_microseconds = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; $elapsed_seconds = $elapsed_microseconds / 1000000.0; if ($elapsed_seconds > $max_execution_time / 3 || $elapsed_seconds > 5) { break; } } // Check if items have finished, otherwise continue with -next- group of item ids if ($cnt >= count($itemids)) { // Reset dirty SEARCH properties of published fields to be: normal ON/OFF $set_clause = ' SET' . ($indexer == 'basic' ? ' issearch = CASE issearch WHEN 2 THEN 1 WHEN -1 THEN 0 ELSE issearch END' : ' isadvsearch = CASE isadvsearch WHEN 2 THEN 1 WHEN -1 THEN 0 ELSE isadvsearch END,' . ' isadvfilter = CASE isadvfilter WHEN 2 THEN 1 WHEN -1 THEN 0 ELSE isadvfilter END'); $query = 'UPDATE #__flexicontent_fields' . $set_clause . " WHERE published=1"; $db->setQuery($query); $db->execute(); // Force SEARCH properties of unpublished fields to be: normal OFF if ($indexer == 'basic') { $query = 'UPDATE #__flexicontent_fields SET issearch = 0 WHERE published=0'; $db->setQuery($query); $db->execute(); } else { $query = 'UPDATE #__flexicontent_fields SET isadvsearch = 0, isadvfilter = 0 WHERE published=0'; $db->setQuery($query); $db->execute(); } } if (!count($fieldids)) { echo 'fail|Index was only cleaned-up, <br/>since no <b>fields</b> were marked as: ' . '<br> -- ' . ($indexer == 'basic' ? 'Text Searchable (CONTENT LISTS)' : 'Text Searchable OR filterable (SEARCH VIEW)'); exit; } if (!count($itemids)) { echo 'fail|Index was only cleaned-up, <br/>since no <b>items</b> were found to have value for fields marked as: ' . '<br> -- ' . ($indexer == 'basic' ? 'Text Searchable (CONTENT LISTS)' : 'Text Searchable OR filterable (SEARCH VIEW)'); exit; } $elapsed_microseconds = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; if ($session->has($indexer . '_total_runtime', 'flexicontent')) { $_total_runtime = $session->get($indexer . '_total_runtime', 0, 'flexicontent'); } else { $_total_runtime = 0; } $_total_runtime += $elapsed_microseconds; $session->set($indexer . '_total_runtime', $_total_runtime, 'flexicontent'); if ($session->has($indexer . '_total_queries', 'flexicontent')) { $_total_queries = $session->get($indexer . '_total_queries', 0, 'flexicontent'); } else { $_total_queries = 0; } $_total_queries += $query_count; $session->set($indexer . '_total_queries', $_total_queries, 'flexicontent'); echo sprintf($cnt . ' | Server execution time: %.2f secs ', $_total_runtime / 1000000) . ' | Total DB updates: ' . $_total_queries; exit; }
function index() { $start_microtime = microtime(true); $session = JFactory::getSession(); $db = JFactory::getDBO(); @ob_end_clean(); $indexer = JRequest::getVar('indexer', 'fileman_default'); $rebuildmode = JRequest::getVar('rebuildmode', ''); $items_per_call = JRequest::getVar('items_per_call', 20); // Number of item to index per HTTP request $itemcnt = JRequest::getVar('itemcnt', 0); // Counter of items indexed so far, this is given via HTTP request // Actions according to rebuildmode if ($indexer != 'fileman_default') { die("'rebuildmode': '" . $rebuildmode . "'. not supported"); } // Get items ids that have value for any of the searchable fields, but use session to avoid recalculation $itemids = $session->get($indexer . '_items_to_index', array(), 'flexicontent'); // Get query size limit $query = "SHOW VARIABLES LIKE 'max_allowed_packet'"; $db->setQuery($query); $_dbvariable = $db->loadObject(); $max_allowed_packet = flexicontent_upload::parseByteLimit(@$_dbvariable->Value); $max_allowed_packet = $max_allowed_packet ? $max_allowed_packet : 256 * 1024; $query_lim = (int) (3 * $max_allowed_packet / 4); //echo 'fail|'.$query_lim; exit; // Get script max $max_execution_time = ini_get("max_execution_time"); //echo 'fail|'.$max_execution_time; exit; $query_count = 0; $max_items_per_query = 100; $max_items_per_query = $max_items_per_query > $items_per_call ? $items_per_call : $max_items_per_query; $cnt = $itemcnt; while ($cnt < count($itemids) && $cnt < $itemcnt + $items_per_call) { $query_itemids = array_slice($itemids, $cnt, $max_items_per_query); $cnt += $max_items_per_query; // Get files $data_query = "SELECT * " . " FROM #__flexicontent_files" . " WHERE id IN (" . implode(', ', $query_itemids) . ")"; $db->setQuery($data_query); $file_data = $db->loadObjectList('id'); $vindex = array(); // For current item: Loop though all searchable fields according to their type foreach ($file_data as $file_id => $file) { $path = $file->secure ? COM_FLEXICONTENT_FILEPATH : COM_FLEXICONTENT_MEDIAPATH; // JPATH_ROOT . DS . <media_path | file_path> $file_path = $path . DS . $file->filename; $file->size = !$file->url && file_exists($file_path) ? filesize($file_path) : 0; $vindex[] = ' WHEN ' . $file->id . ' THEN ' . $file->size; } // Create query that will update/insert data into the DB unset($query); $query = 'UPDATE #__flexicontent_files ' . ' SET size = CASE id ' . implode('', $vindex) . ' END ' . ' WHERE id IN (' . implode(', ', $query_itemids) . ')'; $db->setQuery($query); $db->execute(); $query_count++; $elapsed_microseconds = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; $elapsed_seconds = $elapsed_microseconds / 1000000.0; if ($elapsed_seconds > $max_execution_time / 3 || $elapsed_seconds > 5) { break; } } $elapsed_microseconds = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; if ($session->has($indexer . '_total_runtime', 'flexicontent')) { $_total_runtime = $session->get($indexer . '_total_runtime', 0, 'flexicontent'); } else { $_total_runtime = 0; } $_total_runtime += $elapsed_microseconds; $session->set($indexer . '_total_runtime', $_total_runtime, 'flexicontent'); if ($session->has($indexer . '_total_queries', 'flexicontent')) { $_total_queries = $session->get($indexer . '_total_queries', 0, 'flexicontent'); } else { $_total_queries = 0; } $_total_queries += $query_count; $session->set($indexer . '_total_queries', $_total_queries, 'flexicontent'); echo sprintf($cnt . ' | Server execution time: %.2f secs ', $_total_runtime / 1000000) . ' | Total DB updates: ' . $_total_queries; exit; }