public function render($name, $params = array(), $content = null) { // Initialise variables. $buffer = null; $lists = null; // Get the message queue $messages = MFactory::getApplication()->getMessageQueue(); // Build the sorted message list if (is_array($messages) && !empty($messages)) { foreach ($messages as $msg) { if (isset($msg['type']) && isset($msg['message'])) { $lists[$msg['type']][] = $msg['message']; } } } // If messages exist render them if (is_array($lists)) { foreach ($lists as $type => $msgs) { $class = 'updated'; if ($type == 'error' or $type == 'warning') { $class = 'error'; } if (count($msgs)) { foreach ($msgs as $msg) { $buffer .= "\n" . '<div id="message" class="' . $class . '">'; $buffer .= "\n\t\t" . '<p>' . $msg . '</p>'; $buffer .= "</div>"; } } } } return $buffer; }
public static function getInstance($handler = null, $options = array()) { static $now = null; MCacheStorage::addIncludePath(MPATH_WP_CNT . '/miwi/framework/cache/storage'); if (!isset($handler)) { $conf = MFactory::getConfig(); $handler = $conf->get('cache_handler'); if (empty($handler)) { return MError::raiseWarning(500, MText::_('MLIB_CACHE_ERROR_CACHE_HANDLER_NOT_SET')); } } if (is_null($now)) { $now = time(); } $options['now'] = $now; $handler = strtolower(preg_replace('/[^A-Z0-9_\\.-]/i', '', $handler)); $class = 'MCacheStorage' . ucfirst($handler); if (!class_exists($class)) { mimport('joomla.filesystem.path'); if ($path = MPath::find(MCacheStorage::addIncludePath(), strtolower($handler) . '.php')) { include_once $path; } else { return MError::raiseWarning(500, MText::sprintf('MLIB_CACHE_ERROR_CACHE_STORAGE_LOAD', $handler)); } } return new $class($options); }
protected function getOptions() { // Initialize variables. $options = array(); // Initialize some field attributes. $key = $this->element['key_field'] ? (string) $this->element['key_field'] : 'value'; $value = $this->element['value_field'] ? (string) $this->element['value_field'] : (string) $this->element['name']; $translate = $this->element['translate'] ? (string) $this->element['translate'] : false; $query = (string) $this->element['query']; // Get the database object. $db = MFactory::getDBO(); // Set the query and get the result list. $db->setQuery($query); $items = $db->loadObjectlist(); // Check for an error. if ($db->getErrorNum()) { MError::raiseWarning(500, $db->getErrorMsg()); return $options; } // Build the field options. if (!empty($items)) { foreach ($items as $item) { if ($translate == true) { $options[] = MHtml::_('select.option', $item->{$key}, MText::_($item->{$value})); } else { $options[] = MHtml::_('select.option', $item->{$key}, $item->{$value}); } } } // Merge any additional options in the XML definition. $options = array_merge(parent::getOptions(), $options); return $options; }
public function __construct(array &$options) { // Call the parent constructor. parent::__construct($options); // The name of the text file defaults to 'error.php' if not explicitly given. if (empty($this->options['text_file'])) { $this->options['text_file'] = 'error.php'; } // The name of the text file path defaults to that which is set in configuration if not explicitly given. if (empty($this->options['text_file_path'])) { $this->options['text_file_path'] = MFactory::getConfig()->get('log_path'); } // False to treat the log file as a php file. if (empty($this->options['text_file_no_php'])) { $this->options['text_file_no_php'] = false; } // Build the full path to the log file. $this->path = $this->options['text_file_path'] . '/' . $this->options['text_file']; // Use the default entry format unless explicitly set otherwise. if (!empty($this->options['text_entry_format'])) { $this->format = (string) $this->options['text_entry_format']; } // Build the fields array based on the format string. $this->parseFields(); }
protected static function _loadBehavior($group, $params = array()) { static $loaded = array(); if (!array_key_exists($group, $loaded)) { $loaded[$group] = true; // Include mootools framework. MHtml::_('behavior.framework', true); $document = MFactory::getDocument(); $display = isset($params['startOffset']) && isset($params['startTransition']) && $params['startTransition'] ? (int) $params['startOffset'] : null; $show = isset($params['startOffset']) && !(isset($params['startTransition']) && $params['startTransition']) ? (int) $params['startOffset'] : null; $options = '{'; $opt['onActive'] = "function(toggler, i) {toggler.addClass('pane-toggler-down');" . "toggler.removeClass('pane-toggler');i.addClass('pane-down');i.removeClass('pane-hide');Cookie.write('jpanesliders_" . $group . "',\$\$('div#" . $group . ".pane-sliders > .panel > h3').indexOf(toggler));}"; $opt['onBackground'] = "function(toggler, i) {toggler.addClass('pane-toggler');" . "toggler.removeClass('pane-toggler-down');i.addClass('pane-hide');i.removeClass('pane-down');if(\$\$('div#" . $group . ".pane-sliders > .panel > h3').length==\$\$('div#" . $group . ".pane-sliders > .panel > h3.pane-toggler').length) Cookie.write('jpanesliders_" . $group . "',-1);}"; $opt['duration'] = isset($params['duration']) ? (int) $params['duration'] : 300; $opt['display'] = isset($params['useCookie']) && $params['useCookie'] ? MRequest::getInt('jpanesliders_' . $group, $display, 'cookie') : $display; $opt['show'] = isset($params['useCookie']) && $params['useCookie'] ? MRequest::getInt('jpanesliders_' . $group, $show, 'cookie') : $show; $opt['opacity'] = isset($params['opacityTransition']) && $params['opacityTransition'] ? 'true' : 'false'; $opt['alwaysHide'] = isset($params['allowAllClose']) && !$params['allowAllClose'] ? 'false' : 'true'; foreach ($opt as $k => $v) { if ($v) { $options .= $k . ': ' . $v . ','; } } if (substr($options, -1) == ',') { $options = substr($options, 0, -1); } $options .= '}'; $js = "jQuery(document).ready(function () { new Fx.Accordion(\$\$('div#" . $group . ".pane-sliders > .panel > h3.pane-toggler'), \$\$('div#" . $group . ".pane-sliders > .panel > div.pane-slider'), " . $options . "); });"; $document->addScriptDeclaration($js); } }
public static function runSqlFile($sql_file) { $db = MFactory::getDbo(); if (!file_exists($sql_file)) { return; } $buffer = file_get_contents($sql_file); if ($buffer === false) { return; } $queries = $db->splitSql($buffer); if (count($queries) == 0) { return; } foreach ($queries as $query) { $query = trim($query); if ($query != '' && $query[0] != '#') { $db->setQuery($query); if (!$db->query()) { MError::raiseWarning(1, 'MInstaller::install: ' . MText::_('SQL Error') . " " . $db->stderr(true)); return; } } } }
protected function getOptions() { MLog::add('MFormFieldEditors is deprecated. Use MFormFieldPlugins instead (with folder="editors").', MLog::WARNING, 'deprecated'); // Get the database object and a new query object. $db = MFactory::getDBO(); $query = $db->getQuery(true); // Build the query. $query->select('element AS value, name AS text'); $query->from('#__extensions'); $query->where('folder = ' . $db->quote('editors')); $query->where('enabled = 1'); $query->order('ordering, name'); // Set the query and load the options. $db->setQuery($query); $options = $db->loadObjectList(); $lang = MFactory::getLanguage(); foreach ($options as $i => $option) { $lang->load('plg_editors_' . $option->value, MPATH_ADMINISTRATOR, null, false, false) || $lang->load('plg_editors_' . $option->value, MPATH_PLUGINS . '/editors/' . $option->value, null, false, false) || $lang->load('plg_editors_' . $option->value, MPATH_ADMINISTRATOR, $lang->getDefault(), false, false) || $lang->load('plg_editors_' . $option->value, MPATH_PLUGINS . '/editors/' . $option->value, $lang->getDefault(), false, false); $options[$i]->text = MText::_($option->text); } // Check for a database error. if ($db->getErrorNum()) { MError::raiseWarning(500, $db->getErrorMsg()); } // Merge any additional options in the XML definition. $options = array_merge(parent::getOptions(), $options); return $options; }
public static function base($pathonly = false) { if (empty(self::$base)) { $config = MFactory::getConfig(); $live_site = $config->get('live_site'); if (trim($live_site) != '') { $uri = self::getInstance($live_site); self::$base['prefix'] = $uri->toString(array('scheme', 'host', 'port')); self::$base['path'] = rtrim($uri->toString(array('path')), '/\\'); if (is_admin()) { self::$base['path'] .= '/admin'; } } else { $uri = self::getInstance(); self::$base['prefix'] = $uri->toString(array('scheme', 'host', 'port')); if (strpos(php_sapi_name(), 'cgi') !== false && !ini_get('cgi.fix_pathinfo') && !empty($_SERVER['REQUEST_URI'])) { $script_name = $_SERVER['PHP_SELF']; } else { $script_name = $_SERVER['SCRIPT_NAME']; } self::$base['path'] = rtrim(dirname($script_name), '/\\'); } } return $pathonly === false ? self::$base['prefix'] . self::$base['path'] . '/' : self::$base['path']; }
public static function getInstance($file = 'error.php', $options = null, $path = null) { // Deprecation warning. MLog::add('MLog::getInstance() is deprecated. See MLog::addLogger().', MLog::WARNING, 'deprecated'); // Get the system configuration object. $config = MFactory::getConfig(); // Set default path if not set and sanitize it. if (!$path) { $path = $config->get('log_path'); } // If no options were explicitly set use the default from configuration. if (empty($options)) { $options = (array) $config->get('log_options'); } // Fix up the options so that we use the w3c format. $options['text_entry_format'] = empty($options['format']) ? null : $options['format']; $options['text_file'] = $file; $options['text_file_path'] = $path; $options['logger'] = 'w3c'; // Generate a unique signature for the MLog instance based on its options. $signature = md5(serialize($options)); // Only create the object if not already created. if (empty(self::$legacy[$signature])) { self::$legacy[$signature] = new MLog(); // Register the configuration. self::$legacy[$signature]->configurations[$signature] = $options; // Setup the lookup to catch all. self::$legacy[$signature]->lookup[$signature] = (object) array('priorities' => MLog::ALL, 'categories' => array()); } return self::$legacy[$signature]; }
public static function isWinOS() { // Deprecation warning. MLog::add('MUtility::isWinOS() is deprecated.', MLog::WARNING, 'deprecated'); $application = MFactory::getApplication(); return $application->isWinOS(); }
protected function getOptions() { // Initialise variables $folder = $this->element['folder']; if (!empty($folder)) { // Get list of plugins $db = MFactory::getDbo(); $query = $db->getQuery(true); $query->select('element AS value, name AS text'); $query->from('#__extensions'); $query->where('folder = ' . $db->q($folder)); $query->where('enabled = 1'); $query->order('ordering, name'); $db->setQuery($query); $options = $db->loadObjectList(); $lang = MFactory::getLanguage(); foreach ($options as $i => $item) { $source = MPATH_PLUGINS . '/' . $folder . '/' . $item->value; $extension = 'plg_' . $folder . '_' . $item->value; $lang->load($extension . '.sys', MPATH_ADMINISTRATOR, null, false, false) || $lang->load($extension . '.sys', $source, null, false, false) || $lang->load($extension . '.sys', MPATH_ADMINISTRATOR, $lang->getDefault(), false, false) || $lang->load($extension . '.sys', $source, $lang->getDefault(), false, false); $options[$i]->text = MText::_($item->text); } if ($db->getErrorMsg()) { MError::raiseWarning(500, MText::_('MFRAMEWORK_FORM_FIELDS_PLUGINS_ERROR_FOLDER_EMPTY')); return ''; } } else { MError::raiseWarning(500, MText::_('MFRAMEWORK_FORM_FIELDS_PLUGINS_ERROR_FOLDER_EMPTY')); } // Merge any additional options in the XML definition. $options = array_merge(parent::getOptions(), $options); return $options; }
protected static function _loadBehavior($group, $params = array()) { static $loaded = array(); if (!array_key_exists((string) $group, $loaded)) { // Include MooTools framework MHtml::_('behavior.framework', true); $options = '{'; $opt['onActive'] = isset($params['onActive']) ? $params['onActive'] : null; $opt['onBackground'] = isset($params['onBackground']) ? $params['onBackground'] : null; $opt['display'] = isset($params['startOffset']) ? (int) $params['startOffset'] : null; $opt['useStorage'] = isset($params['useCookie']) && $params['useCookie'] ? 'true' : 'false'; $opt['titleSelector'] = "'dt.tabs'"; $opt['descriptionSelector'] = "'dd.tabs'"; foreach ($opt as $k => $v) { if ($v) { $options .= $k . ': ' . $v . ','; } } if (substr($options, -1) == ',') { $options = substr($options, 0, -1); } $options .= '}'; $js = ' jQuery(document).ready(function () { $$(\'dl#' . $group . '.tabs\').each(function(tabs){ new MTabs(tabs, ' . $options . '); }); });'; $document = MFactory::getDocument(); $document->addScriptDeclaration($js); MHtml::_('script', 'system/tabs.js', false, true); $loaded[(string) $group] = true; } }
public function display($tpl = null) { $document = MFactory::getDocument(); $document->addStyleSheet(MURL_MIWOSQL . '/admin/assets/css/miwosql.css'); // Toolbar MToolBarHelper::title(MText::_('MiwoSQL') . ' - ' . MText::_('COM_MIWOSQL_RUN_QUERY'), 'miwosql'); if (MiwosqlHelper::is30()) { MToolBarHelper::custom('run', 'play.png', 'play.png', MText::_('COM_MIWOSQL_RUN_QUERY'), false); MToolBarHelper::divider(); MToolBarHelper::custom('savequery', 'folder-close.png', 'folder-close.png', MText::_('COM_MIWOSQL_SAVE_QUERY'), false); MToolBarHelper::divider(); MToolBarHelper::custom('csv', 'upload.png', 'upload.png', MText::_('COM_MIWOSQL_EXPORT_CSV'), false); } else { MToolBarHelper::custom('run', 'run.png', 'run.png', MText::_('COM_MIWOSQL_RUN_QUERY'), false); MToolBarHelper::divider(); MToolBarHelper::custom('savequery', 'savequery.png', 'savequery.png', MText::_('COM_MIWOSQL_SAVE_QUERY'), false); MToolBarHelper::divider(); MToolBarHelper::custom('csv', 'csv.png', 'csv.png', MText::_('COM_MIWOSQL_EXPORT_CSV'), false); } // ACL if (version_compare(MVERSION, '1.6.0', 'ge') && MFactory::getUser()->authorise('core.admin', 'com_miwosql')) { MToolBarHelper::divider(); MToolBarHelper::preferences('com_miwosql', '550'); } $this->data = $this->get('Data'); $this->tables = $this->get('Tables'); $this->prefix = $this->get('Prefix'); parent::display($tpl); }
function display($tpl = null) { $mainframe = MFactory::getApplication(); $option = MRequest::getCmd('option'); $document = MFactory::getDocument(); $document->addStyleSheet(MURL_MIWOSQL . '/admin/assets/css/miwosql.css'); MToolBarHelper::title(MText::_('MiwoSQL') . ' - ' . MText::_('COM_MIWOSQL_SAVED_QUERIES'), 'miwosql'); MToolBarHelper::editList(); MToolBarHelper::deleteList(); // ACL if (version_compare(MVERSION, '1.6.0', 'ge') && MFactory::getUser()->authorise('core.admin', 'com_miwosql')) { MToolBarHelper::divider(); MToolBarHelper::preferences('com_miwosql', '550'); } $this->mainframe = MFactory::getApplication(); $this->option = MRequest::getWord('option'); $filter_order = $mainframe->getUserStateFromRequest($option . '.queries.filter_order', 'filter_order', 'title', 'string'); $filter_order_Dir = $mainframe->getUserStateFromRequest($option . '.queries.filter_order_Dir', 'filter_order_Dir', '', 'word'); $search = $mainframe->getUserStateFromRequest($option . '.queries.search', 'search', '', 'string'); // table ordering $lists['order_Dir'] = $filter_order_Dir; $lists['order'] = $filter_order; // search filter $lists['search'] = $search; $this->lists = $lists; $this->items = $this->get('Data'); $this->pagination = $this->get('Pagination'); parent::display($tpl); }
public function loadLanguage($extension = '', $basePath = MPATH_ADMINISTRATOR) { if (empty($extension)) { $extension = 'plg_' . $this->_type . '_' . $this->_name; } $lang = MFactory::getLanguage(); return $lang->load(strtolower($extension), $basePath, null, false, true) || $lang->load(strtolower($extension), MPATH_PLUGINS . '/' . $extension, null, false, true); }
public function __construct($default = array()) { parent::__construct($default); $this->_db = MFactory::getDBO(); $this->_table = MiwosqlHelper::getVar('tbl'); $this->_query = MiwosqlHelper::getVar('qry'); $this->registerTask('add', 'edit'); $this->registerTask('new', 'edit'); }
protected function getInput() { // Initialize some field attributes. $format = $this->element['format'] ? (string) $this->element['format'] : '%Y-%m-%d'; // Build the attributes array. $attributes = array(); if ($this->element['size']) { $attributes['size'] = (int) $this->element['size']; } if ($this->element['maxlength']) { $attributes['maxlength'] = (int) $this->element['maxlength']; } if ($this->element['class']) { $attributes['class'] = (string) $this->element['class']; } if ((string) $this->element['readonly'] == 'true') { $attributes['readonly'] = 'readonly'; } if ((string) $this->element['disabled'] == 'true') { $attributes['disabled'] = 'disabled'; } if ($this->element['onchange']) { $attributes['onchange'] = (string) $this->element['onchange']; } // Handle the special case for "now". if (strtoupper($this->value) == 'NOW') { $this->value = strftime($format); } // Get some system objects. $config = MFactory::getConfig(); $user = MFactory::getUser(); // If a known filter is given use it. switch (strtoupper((string) $this->element['filter'])) { case 'SERVER_UTC': // Convert a date to UTC based on the server timezone. if (intval($this->value)) { // Get a date object based on the correct timezone. $date = MFactory::getDate($this->value, 'UTC'); $date->setTimezone(new DateTimeZone($config->get('offset'))); // Transform the date string. $this->value = $date->format('Y-m-d H:i:s', true, false); } break; case 'USER_UTC': // Convert a date to UTC based on the user timezone. if (intval($this->value)) { // Get a date object based on the correct timezone. $date = MFactory::getDate($this->value, 'UTC'); $date->setTimezone(new DateTimeZone($user->getParam('timezone', $config->get('offset')))); // Transform the date string. $this->value = $date->format('Y-m-d H:i:s', true, false); } break; } return MHtml::_('calendar', $this->value, $this->name, $this->id, $format, $attributes); }
protected function getOptions() { // Initialise variables. $options = array(); $extension = $this->element['extension'] ? (string) $this->element['extension'] : (string) $this->element['scope']; $published = (string) $this->element['published']; $name = (string) $this->element['name']; // Load the category options for a given extension. if (!empty($extension)) { // Filter over published state or not depending upon if it is present. if ($published) { $options = MHtml::_('category.options', $extension, array('filter.published' => explode(',', $published))); } else { $options = MHtml::_('category.options', $extension); } // Verify permissions. If the action attribute is set, then we scan the options. if ((string) $this->element['action']) { // Get the current user object. $user = MFactory::getUser(); // For new items we want a list of categories you are allowed to create in. if (!$this->form->getValue($name)) { foreach ($options as $i => $option) { // To take save or create in a category you need to have create rights for that category // unless the item is already in that category. // Unset the option if the user isn't authorised for it. In this field assets are always categories. if ($user->authorise('core.create', $extension . '.category.' . $option->value) != true) { unset($options[$i]); } } } else { $categoryOld = $this->form->getValue($name); foreach ($options as $i => $option) { // If you are only allowed to edit in this category but not edit.state, you should not get any // option to change the category. if ($user->authorise('core.edit.state', $extension . '.category.' . $categoryOld) != true) { if ($option->value != $categoryOld) { unset($options[$i]); } } elseif ($user->authorise('core.create', $extension . '.category.' . $option->value) != true && $option->value != $categoryOld) { unset($options[$i]); } } } } if (isset($this->element['show_root'])) { array_unshift($options, MHtml::_('select.option', '0', MText::_('MGLOBAL_ROOT'))); } } else { MError::raiseWarning(500, MText::_('MLIB_FORM_ERROR_FIELDS_CATEGORY_ERROR_EXTENSION_EMPTY')); } // Merge any additional options in the XML definition. $options = array_merge(parent::getOptions(), $options); return $options; }
public function extract($archive, $destination, $options = array()) { // Initialise variables. $this->_data = null; if (!extension_loaded('bz2')) { $this->set('error.message', MText::_('MLIB_FILESYSTEM_BZIP_NOT_SUPPORTED')); return MError::raiseWarning(100, $this->get('error.message')); } if (!isset($options['use_streams']) || $options['use_streams'] == false) { // Old style: read the whole file and then parse it if (!($this->_data = MFile::read($archive))) { $this->set('error.message', 'Unable to read archive'); return MError::raiseWarning(100, $this->get('error.message')); } $buffer = bzdecompress($this->_data); unset($this->_data); if (empty($buffer)) { $this->set('error.message', 'Unable to decompress data'); return MError::raiseWarning(100, $this->get('error.message')); } if (MFile::write($destination, $buffer) === false) { $this->set('error.message', 'Unable to write archive'); return MError::raiseWarning(100, $this->get('error.message')); } } else { // New style! streams! $input = MFactory::getStream(); $input->set('processingmethod', 'bz'); // use bzip if (!$input->open($archive)) { $this->set('error.message', MText::_('MLIB_FILESYSTEM_BZIP_UNABLE_TO_READ')); return MError::raiseWarning(100, $this->get('error.message')); } $output = MFactory::getStream(); if (!$output->open($destination, 'w')) { $this->set('error.message', MText::_('MLIB_FILESYSTEM_BZIP_UNABLE_TO_WRITE')); $input->close(); // close the previous file return MError::raiseWarning(100, $this->get('error.message')); } do { $this->_data = $input->read($input->get('chunksize', 8196)); if ($this->_data) { if (!$output->write($this->_data)) { $this->set('error.message', MText::_('MLIB_FILESYSTEM_BZIP_UNABLE_TO_WRITE_FILE')); return MError::raiseWarning(100, $this->get('error.message')); } } } while ($this->_data); $output->close(); $input->close(); } return true; }
public function display($tpl = null) { $document = MFactory::getDocument(); $document->addStyleSheet(MURL_MIWOSQL . '/admin/assets/css/miwosql.css'); // Toolbar MToolBarHelper::title(MText::_('MiwoSQL'), 'miwosql'); MToolBarHelper::save(); MToolBarHelper::cancel(); $this->row = $this->get('QueryData'); parent::display($tpl); }
function _buildViewWhere() { $db = MFactory::getDBO(); $search = $this->mainframe->getUserStateFromRequest($this->option . '.queries.search', 'search', '', 'string'); $search = MString::strtolower($search); $where = array(); if ($search) { $where[] = 'LOWER(title) LIKE ' . $db->Quote('%' . $db->getEscaped($search, true) . '%', false); } $where = count($where) ? ' WHERE ' . implode(' AND ', $where) : ''; return $where; }
public static function published($value, $i, $prefix = '', $enabled = true, $checkbox = 'cb', $publish_up = null, $publish_down = null) { if (is_array($prefix)) { $options = $prefix; $enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled; $checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox; $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : ''; } $states = array(1 => array('unpublish', 'MPUBLISHED', 'MLIB_HTML_UNPUBLISH_ITEM', 'MPUBLISHED', false, 'publish', 'publish'), 0 => array('publish', 'MUNPUBLISHED', 'MLIB_HTML_PUBLISH_ITEM', 'MUNPUBLISHED', false, 'unpublish', 'unpublish'), 2 => array('unpublish', 'MARCHIVED', 'MLIB_HTML_UNPUBLISH_ITEM', 'MARCHIVED', false, 'archive', 'archive'), -2 => array('publish', 'MTRASHED', 'MLIB_HTML_PUBLISH_ITEM', 'MTRASHED', false, 'trash', 'trash')); // Special state for dates if ($publish_up || $publish_down) { $nullDate = MFactory::getDBO()->getNullDate(); $nowDate = MFactory::getDate()->toUnix(); $tz = new DateTimeZone(MFactory::getUser()->getParam('timezone', MFactory::getConfig()->get('offset'))); $publish_up = $publish_up != $nullDate ? MFactory::getDate($publish_up, 'UTC')->setTimeZone($tz) : false; $publish_down = $publish_down != $nullDate ? MFactory::getDate($publish_down, 'UTC')->setTimeZone($tz) : false; // Create tip text, only we have publish up or down settings $tips = array(); if ($publish_up) { $tips[] = MText::sprintf('MLIB_HTML_PUBLISHED_START', $publish_up->format(MDate::$format, true)); } if ($publish_down) { $tips[] = MText::sprintf('MLIB_HTML_PUBLISHED_FINISHED', $publish_down->format(MDate::$format, true)); } $tip = empty($tips) ? false : implode('<br/>', $tips); // Add tips and special titles foreach ($states as $key => $state) { // Create special titles for published items if ($key == 1) { $states[$key][2] = $states[$key][3] = 'MLIB_HTML_PUBLISHED_ITEM'; if ($publish_up > $nullDate && $nowDate < $publish_up->toUnix()) { $states[$key][2] = $states[$key][3] = 'MLIB_HTML_PUBLISHED_PENDING_ITEM'; $states[$key][5] = $states[$key][6] = 'pending'; } if ($publish_down > $nullDate && $nowDate > $publish_down->toUnix()) { $states[$key][2] = $states[$key][3] = 'MLIB_HTML_PUBLISHED_EXPIRED_ITEM'; $states[$key][5] = $states[$key][6] = 'expired'; } } // Add tips to titles if ($tip) { $states[$key][1] = MText::_($states[$key][1]); $states[$key][2] = MText::_($states[$key][2]) . '::' . $tip; $states[$key][3] = MText::_($states[$key][3]) . '::' . $tip; $states[$key][4] = true; } } return self::state($states, $value, $i, array('prefix' => $prefix, 'translate' => !$tip), $enabled, true, $checkbox); } return self::state($states, $value, $i, $prefix, $enabled, true, $checkbox); }
public static function stringURLSafe($string) { // Remove any '-' from the string since they will be used as concatenaters $str = str_replace('-', ' ', $string); $lang = MFactory::getLanguage(); $str = $lang->transliterate($str); // Trim white spaces at beginning and end of alias and make lowercase $str = trim(MString::strtolower($str)); // Remove any duplicate whitespace, and ensure all characters are alphanumeric $str = preg_replace('/(\\s|[^A-Za-z0-9\\-])+/', '-', $str); // Trim dashes at beginning and end of alias $str = trim($str, '-'); return $str; }
public static function userlist() { // Get the database object and a new query object. $db = MFactory::getDBO(); $query = $db->getQuery(true); // Build the query. $query->select('a.ID AS value, a.display_name AS text'); $query->from('#__users AS a'); $query->where('a.user_status = 0'); $query->order('a.display_name'); // Set the query and load the options. $db->setQuery($query); $items = $db->loadObjectList(); // Detect errors if ($db->getErrorNum()) { MError::raiseWarning(500, $db->getErrorMsg()); } return $items; }
protected function getGroups() { // Initialize variables. $groups = array(); $keyField = $this->element['key_field'] ? (string) $this->element['key_field'] : 'id'; $keyValue = $this->form->getValue($keyField); // If the timezone is not set use the server setting. if (strlen($this->value) == 0 && empty($keyValue)) { $this->value = MFactory::getConfig()->get('offset'); } // Get the list of time zones from the server. $zones = DateTimeZone::listIdentifiers(); // Build the group lists. foreach ($zones as $zone) { // Time zones not in a group we will ignore. if (strpos($zone, '/') === false) { continue; } // Get the group/locale from the timezone. list($group, $locale) = explode('/', $zone, 2); // Only use known groups. if (in_array($group, self::$zones)) { // Initialize the group if necessary. if (!isset($groups[$group])) { $groups[$group] = array(); } // Only add options where a locale exists. if (!empty($locale)) { $groups[$group][$zone] = MHtml::_('select.option', $zone, str_replace('_', ' ', $locale), 'value', 'text', false); } } } // Sort the group lists. ksort($groups); foreach ($groups as $zone => &$location) { sort($location); } // Merge any additional groups in the XML definition. $groups = array_merge(parent::getGroups(), $groups); return $groups; }
public function sendMail($from_mail = null, $from_name = null, $to_mail, $subject, $body, $is_html = true, $cc = null, $bcc = null, $attachment = null, $reply_to = null, $reply_to_name = null) { $this->from_mail = $from_mail; $this->from_name = $from_name; $this->to_mail = $to_mail; $this->subject = $subject; $this->body = $body; $this->is_html = $is_html; $this->cc = $cc; $this->bcc = $bcc; $this->attachment = $attachment; $this->reply_to = $reply_to; $this->reply_to_name = $reply_to_name; if (empty($this->from_mail)) { $this->from_mail = MFactory::getWOption('admin_email'); } if (empty($this->from_name)) { $this->from_name = MFactory::getWOption('blogname'); } $this->fromWP(); }
public function render($module, $attribs = array(), $content = null) { if (!is_object($module)) { $title = isset($attribs['title']) ? $attribs['title'] : null; $module_id = isset($attribs['number']) ? $attribs['number'] : null; $module = MModuleHelper::getModule($module, $title, $module_id); if (!is_object($module)) { if (is_null($content)) { return ''; } else { $tmp = $module; $module = new stdClass(); $module->params = null; $module->module = $tmp; $module->id = 0; $module->user = 0; } } } // Get the user and configuration object // $user = MFactory::getUser(); $conf = MFactory::getConfig(); // Set the module content if (!is_null($content)) { $module->content = $content; } // Get module parameters $params = new MRegistry(); $params->loadString($module->params); // Use parameters from template if (isset($attribs['params'])) { $template_params = new MRegistry(); $template_params->loadString(html_entity_decode($attribs['params'], ENT_COMPAT, 'UTF-8')); $params->merge($template_params); $module = clone $module; $module->params = (string) $params; } $contents = MModuleHelper::renderModule($module, $attribs); return $contents; }
public static function relative($date, $unit = null, $time = null) { if (is_null($time)) { // Get now $time = MFactory::getDate('now'); } // Get the difference in seconds between now and the time $diff = strtotime($time) - strtotime($date); // Less than a minute if ($diff < 60) { return MText::_('MLIB_HTML_DATE_RELATIVE_LESSTHANAMINUTE'); } // Round to minutes $diff = round($diff / 60); // 1 to 59 minutes if ($diff < 60 || $unit == 'minute') { return MText::plural('MLIB_HTML_DATE_RELATIVE_MINUTES', $diff); } // Round to hours $diff = round($diff / 60); // 1 to 23 hours if ($diff < 24 || $unit == 'hour') { return MText::plural('MLIB_HTML_DATE_RELATIVE_HOURS', $diff); } // Round to days $diff = round($diff / 24); // 1 to 6 days if ($diff < 7 || $unit == 'day') { return MText::plural('MLIB_HTML_DATE_RELATIVE_DAYS', $diff); } // Round to weeks $diff = round($diff / 7); // 1 to 4 weeks if ($diff <= 4 || $unit == 'week') { return MText::plural('MLIB_HTML_DATE_RELATIVE_WEEKS', $diff); } // Over a month, return the absolute time return MHtml::_('date', $date); }
public static function administrator($file, $folder = '/images/', $altFile = null, $altFolder = '/images/', $alt = null, $attribs = null, $asTag = true) { // Deprecation warning. MLog::add('MImage::administrator is deprecated.', MLog::WARNING, 'deprecated'); $app = MFactory::getApplication(); if (is_array($attribs)) { $attribs = MArrayHelper::toString($attribs); } $cur_template = $app->getTemplate(); // Strip HTML. $alt = html_entity_decode($alt, ENT_COMPAT, 'UTF-8'); if ($altFile) { $image = $altFolder . $altFile; } elseif ($altFile == -1) { $image = ''; } else { if (file_exists(MPATH_ADMINISTRATOR . '/templates/' . $cur_template . '/images/' . $file)) { $image = 'templates/' . $cur_template . '/images/' . $file; } else { // Compatibility with previous versions. if (substr($folder, 0, 14) == "/administrator") { $image = substr($folder, 15) . $file; } else { $image = $folder . $file; } } } if (substr($image, 0, 1) == "/") { $image = substr_replace($image, '', 0, 1); } // Prepend the base path. $image = MURI::base(true) . '/' . $image; // Outputs actual HTML <img> tag. if ($asTag) { $image = '<img src="' . $image . '" alt="' . $alt . '" ' . $attribs . ' />'; } return $image; }
public function deleteTables() { if (!MFile::exists($filename = MPATH_WP_PLG . '/' . $this->context . '/admin/uninstall.sql')) { return null; } $db = MFactory::getDbo(); $file_content = file($filename); if (empty($file_content)) { return null; } $query = ''; foreach ($file_content as $sql_line) { $tsl = trim($sql_line); if ($tsl != '' && (strpos($tsl, '--') != 0 || strpos($tsl, '--') != 1) && substr($tsl, 0, 1) != '#') { $query .= $sql_line; if (preg_match('/;\\s*$/', $sql_line)) { $db->setQuery($query); $db->query(); $query = ''; } } } }