示例#1
0
 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);
 }
示例#2
0
文件: grid.php 项目: vanie3/appland
 public static function id($rowNum, $recId, $checkedOut = false, $name = 'cid')
 {
     if ($checkedOut) {
         return '';
     } else {
         return '<input type="checkbox" id="cb' . $rowNum . '" name="' . $name . '[]" value="' . $recId . '" onclick="Miwi.isChecked(this.checked);" title="' . MText::sprintf('MGRID_CHECKBOX_ROW_N', $rowNum + 1) . '" />';
     }
 }
示例#3
0
 public function register($event, $handler)
 {
     // Are we dealing with a class or function type handler?
     if (function_exists($handler)) {
         // Ok, function type event handler... let's attach it.
         $method = array('event' => $event, 'handler' => $handler);
         $this->attach($method);
     } elseif (class_exists($handler)) {
         // Ok, class type event handler... let's instantiate and attach it.
         $this->attach(new $handler($this));
     } else {
         return MError::raiseWarning('SOME_ERROR_CODE', MText::sprintf('MLIB_EVENT_ERROR_DISPATCHER', $handler));
     }
 }
示例#4
0
文件: rule.php 项目: vanie3/appland
 public function test(&$element, $value, $group = null, &$input = null, &$form = null)
 {
     // Check for a valid regex.
     if (empty($this->regex)) {
         throw new MException(MText::sprintf('MLIB_FORM_INVALID_FORM_RULE', get_class($this)));
     }
     // Add unicode property support if available.
     if (MCOMPAT_UNICODE_PROPERTIES) {
         $this->modifiers = strpos($this->modifiers, 'u') !== false ? $this->modifiers : $this->modifiers . 'u';
     }
     // Test the value against the regular expression.
     if (preg_match(chr(1) . $this->regex . chr(1) . $this->modifiers, $value)) {
         return true;
     }
     return false;
 }
示例#5
0
 protected function connect()
 {
     // Build the configuration object to use for MDatabase.
     $options = array('driver' => $this->driver, 'host' => $this->host, 'user' => $this->user, 'password' => $this->password, 'database' => $this->database, 'prefix' => $this->prefix);
     try {
         $db = MDatabase::getInstance($options);
         if ($db instanceof Exception) {
             throw new LogException('Database Error: ' . (string) $db);
         }
         if ($db->getErrorNum() > 0) {
             throw new LogException(MText::sprintf('MLIB_UTIL_ERROR_CONNECT_DATABASE', $db->getErrorNum(), $db->getErrorMsg()));
         }
         // Assign the database connector to the class.
         $this->dbo = $db;
     } catch (RuntimeException $e) {
         throw new LogException($e->getMessage());
     }
 }
示例#6
0
文件: equals.php 项目: vanie3/appland
 public function test(&$element, $value, $group = null, &$input = null, &$form = null)
 {
     // Initialize variables.
     $field = (string) $element['field'];
     // Check that a validation field is set.
     if (!$field) {
         return new MException(MText::sprintf('MLIB_FORM_INVALID_FORM_RULE', get_class($this)));
     }
     // Check that a valid MForm object is given for retrieving the validation field value.
     if (!$form instanceof MForm) {
         return new MException(MText::sprintf('MLIB_FORM_INVALID_FORM_OBJECT', get_class($this)));
     }
     // Test the two values against each other.
     if ($value == $input->get($field)) {
         return true;
     }
     return false;
 }
示例#7
0
文件: user.php 项目: vanie3/appland
 public static function getInstance($identifier = 0)
 {
     // Find the user id
     if (empty($identifier) and function_exists('wp_get_current_user')) {
         $user = wp_get_current_user();
         $id = $user->ID;
     } else {
         if (!is_numeric($identifier)) {
             if (!($id = MUserHelper::getUserId($identifier))) {
                 MError::raiseWarning('SOME_ERROR_CODE', MText::sprintf('MLIB_USER_ERROR_ID_NOT_EXISTS', $identifier));
                 $retval = false;
                 return $retval;
             }
         } else {
             $id = $identifier;
         }
     }
     if (empty(self::$instances[$id])) {
         $user = new MUser($id);
         self::$instances[$id] = $user;
     }
     return self::$instances[$id];
 }
示例#8
0
文件: html.php 项目: vanie3/appland
 public static function _($key)
 {
     list($key, $prefix, $file, $func) = self::extract($key);
     if (array_key_exists($key, self::$registry)) {
         $function = self::$registry[$key];
         $args = func_get_args();
         // Remove function name from arguments
         array_shift($args);
         return MHtml::call($function, $args);
     }
     $className = $prefix . ucfirst($file);
     if (!class_exists($className)) {
         mimport('framework.filesystem.path');
         self::addIncludePath(MPATH_MIWI . '/proxy/html/html');
         if ($path = MPath::find(MHtml::$includePaths, strtolower($file) . '.php')) {
             require_once $path;
             if (!class_exists($className)) {
                 MError::raiseError(500, MText::sprintf('MLIB_HTML_ERROR_NOTFOUNDINFILE', $className, $func));
                 return false;
             }
         } else {
             MError::raiseError(500, MText::sprintf('MLIB_HTML_ERROR_NOTSUPPORTED_NOFILE', $prefix, $file));
             return false;
         }
     }
     $toCall = array($className, $func);
     if (is_callable($toCall)) {
         MHtml::register($key, $toCall);
         $args = func_get_args();
         // Remove function name from arguments
         array_shift($args);
         return MHtml::call($toCall, $args);
     } else {
         MError::raiseError(500, MText::sprintf('MLIB_HTML_ERROR_NOTSUPPORTED', $className, $func));
         return false;
     }
 }
示例#9
0
    public function shortcodeButton($content)
    {
        $title = explode('miwo', $this->context);
        $content .= '<a href="#TB_inline?width=450&height=550&inlineId=' . $this->context . '-shortcode" class="button thickbox miwi-shortcode-btn" title="' . MText::sprintf('MLIB_X_ADD_SHORTCODE', 'Miwo' . ucfirst($title[1])) . '">
						<img src="' . MURL_WP_CNT . '/plugins/' . $this->context . '/admin/assets/images/icon-16-' . $this->context . '.png" alt="' . MText::sprintf('MLIB_X_ADD_SHORTCODE', 'Miwo' . ucfirst($title[1])) . '" />' . MText::_('MLIB_ADD_SHORTCODE') . '</a>';
        return $content;
    }
示例#10
0
文件: rules.php 项目: vanie3/appland
 protected function getInput()
 {
     MHtml::_('behavior.tooltip');
     // Initialise some field attributes.
     $section = $this->element['section'] ? (string) $this->element['section'] : '';
     $component = $this->element['component'] ? (string) $this->element['component'] : '';
     $assetField = $this->element['asset_field'] ? (string) $this->element['asset_field'] : 'asset_id';
     // Get the actions for the asset.
     $actions = MAccess::getActions($component, $section);
     // Iterate over the children and add to the actions.
     foreach ($this->element->children() as $el) {
         if ($el->getName() == 'action') {
             $actions[] = (object) array('name' => (string) $el['name'], 'title' => (string) $el['title'], 'description' => (string) $el['description']);
         }
     }
     // Get the explicit rules for this asset.
     if ($section == 'component') {
         // Need to find the asset id by the name of the component.
         $db = MFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select($db->quoteName('id'));
         $query->from($db->quoteName('#__assets'));
         $query->where($db->quoteName('name') . ' = ' . $db->quote($component));
         $db->setQuery($query);
         $assetId = (int) $db->loadResult();
         if ($error = $db->getErrorMsg()) {
             MError::raiseNotice(500, $error);
         }
     } else {
         // Find the asset id of the content.
         // Note that for global configuration, com_config injects asset_id = 1 into the form.
         $assetId = $this->form->getValue($assetField);
     }
     // Use the compact form for the content rules (deprecated).
     //if (!empty($component) && $section != 'component') {
     //	return MHtml::_('rules.assetFormWidget', $actions, $assetId, $assetId ? null : $component, $this->name, $this->id);
     //}
     // Full width format.
     // Get the rules for just this asset (non-recursive).
     $assetRules = MAccess::getAssetRules($assetId);
     // Get the available user groups.
     $groups = $this->getUserGroups();
     // Build the form control.
     $curLevel = 0;
     // Prepare output
     $html = array();
     $html[] = '<div id="permissions-sliders" class="pane-sliders">';
     $html[] = '<p class="rule-desc">' . MText::_('MLIB_RULES_SETTINGS_DESC') . '</p>';
     $html[] = '<ul id="rules">';
     // Start a row for each user group.
     foreach ($groups as $group) {
         $difLevel = $group->level - $curLevel;
         if ($difLevel > 0) {
             $html[] = '<li><ul>';
         } elseif ($difLevel < 0) {
             $html[] = str_repeat('</ul></li>', -$difLevel);
         }
         $html[] = '<li>';
         $html[] = '<div class="panel">';
         $html[] = '<h3 class="pane-toggler title"><a href="javascript:void(0);"><span>';
         $html[] = str_repeat('<span class="level">|&ndash;</span> ', $curLevel = $group->level) . $group->text;
         $html[] = '</span></a></h3>';
         $html[] = '<div class="pane-slider content pane-hide">';
         $html[] = '<div class="mypanel">';
         $html[] = '<table class="group-rules">';
         $html[] = '<thead>';
         $html[] = '<tr>';
         $html[] = '<th class="actions" id="actions-th' . $group->value . '">';
         $html[] = '<span class="acl-action">' . MText::_('MLIB_RULES_ACTION') . '</span>';
         $html[] = '</th>';
         $html[] = '<th class="settings" id="settings-th' . $group->value . '">';
         $html[] = '<span class="acl-action">' . MText::_('MLIB_RULES_SELECT_SETTING') . '</span>';
         $html[] = '</th>';
         // The calculated setting is not shown for the root group of global configuration.
         $canCalculateSettings = $group->parent_id || !empty($component);
         if ($canCalculateSettings) {
             $html[] = '<th id="aclactionth' . $group->value . '">';
             $html[] = '<span class="acl-action">' . MText::_('MLIB_RULES_CALCULATED_SETTING') . '</span>';
             $html[] = '</th>';
         }
         $html[] = '</tr>';
         $html[] = '</thead>';
         $html[] = '<tbody>';
         foreach ($actions as $action) {
             $html[] = '<tr>';
             $html[] = '<td headers="actions-th' . $group->value . '">';
             $html[] = '<label class="hasTip" for="' . $this->id . '_' . $action->name . '_' . $group->value . '" title="' . htmlspecialchars(MText::_($action->title) . '::' . MText::_($action->description), ENT_COMPAT, 'UTF-8') . '">';
             $html[] = MText::_($action->title);
             $html[] = '</label>';
             $html[] = '</td>';
             $html[] = '<td headers="settings-th' . $group->value . '">';
             $html[] = '<select name="' . $this->name . '[' . $action->name . '][' . $group->value . ']" id="' . $this->id . '_' . $action->name . '_' . $group->value . '" title="' . MText::sprintf('MLIB_RULES_SELECT_ALLOW_DENY_GROUP', MText::_($action->title), trim($group->text)) . '">';
             $inheritedRule = MAccess::checkGroup($group->value, $action->name, $assetId);
             // Get the actual setting for the action for this group.
             $assetRule = $assetRules->allow($action->name, $group->value);
             // Build the dropdowns for the permissions sliders
             // The parent group has "Not Set", all children can rightly "Inherit" from that.
             $html[] = '<option value=""' . ($assetRule === null ? ' selected="selected"' : '') . '>' . MText::_(empty($group->parent_id) && empty($component) ? 'MLIB_RULES_NOT_SET' : 'MLIB_RULES_INHERITED') . '</option>';
             $html[] = '<option value="1"' . ($assetRule === true ? ' selected="selected"' : '') . '>' . MText::_('MLIB_RULES_ALLOWED') . '</option>';
             $html[] = '<option value="0"' . ($assetRule === false ? ' selected="selected"' : '') . '>' . MText::_('MLIB_RULES_DENIED') . '</option>';
             $html[] = '</select>&#160; ';
             // If this asset's rule is allowed, but the inherited rule is deny, we have a conflict.
             if ($assetRule === true && $inheritedRule === false) {
                 $html[] = MText::_('MLIB_RULES_CONFLICT');
             }
             $html[] = '</td>';
             // Build the Calculated Settings column.
             // The inherited settings column is not displayed for the root group in global configuration.
             if ($canCalculateSettings) {
                 $html[] = '<td headers="aclactionth' . $group->value . '">';
                 // This is where we show the current effective settings considering currrent group, path and cascade.
                 // Check whether this is a component or global. Change the text slightly.
                 if (MAccess::checkGroup($group->value, 'core.admin', $assetId) !== true) {
                     if ($inheritedRule === null) {
                         $html[] = '<span class="icon-16-unset">' . MText::_('MLIB_RULES_NOT_ALLOWED') . '</span>';
                     } elseif ($inheritedRule === true) {
                         $html[] = '<span class="icon-16-allowed">' . MText::_('MLIB_RULES_ALLOWED') . '</span>';
                     } elseif ($inheritedRule === false) {
                         if ($assetRule === false) {
                             $html[] = '<span class="icon-16-denied">' . MText::_('MLIB_RULES_NOT_ALLOWED') . '</span>';
                         } else {
                             $html[] = '<span class="icon-16-denied"><span class="icon-16-locked">' . MText::_('MLIB_RULES_NOT_ALLOWED_LOCKED') . '</span></span>';
                         }
                     }
                 } elseif (!empty($component)) {
                     $html[] = '<span class="icon-16-allowed"><span class="icon-16-locked">' . MText::_('MLIB_RULES_ALLOWED_ADMIN') . '</span></span>';
                 } else {
                     // Special handling for  groups that have global admin because they can't  be denied.
                     // The admin rights can be changed.
                     if ($action->name === 'core.admin') {
                         $html[] = '<span class="icon-16-allowed">' . MText::_('MLIB_RULES_ALLOWED') . '</span>';
                     } elseif ($inheritedRule === false) {
                         // Other actions cannot be changed.
                         $html[] = '<span class="icon-16-denied"><span class="icon-16-locked">' . MText::_('MLIB_RULES_NOT_ALLOWED_ADMIN_CONFLICT') . '</span></span>';
                     } else {
                         $html[] = '<span class="icon-16-allowed"><span class="icon-16-locked">' . MText::_('MLIB_RULES_ALLOWED_ADMIN') . '</span></span>';
                     }
                 }
                 $html[] = '</td>';
             }
             $html[] = '</tr>';
         }
         $html[] = '</tbody>';
         $html[] = '</table></div>';
         $html[] = '</div></div>';
         $html[] = '</li>';
     }
     $html[] = str_repeat('</ul></li>', $curLevel);
     $html[] = '</ul><div class="rule-notes">';
     if ($section == 'component' || $section == null) {
         $html[] = MText::_('MLIB_RULES_SETTING_NOTES');
     } else {
         $html[] = MText::_('MLIB_RULES_SETTING_NOTES_ITEM');
     }
     $html[] = '</div></div>';
     $js = "jQuery(document).ready(function () { new Fx.Accordion(\$\$('div#permissions-sliders.pane-sliders .panel h3.pane-toggler')," . "\$\$('div#permissions-sliders.pane-sliders .panel div.pane-slider'), {onActive: function(toggler, i) {toggler.addClass('pane-toggler-down');" . "toggler.removeClass('pane-toggler');i.addClass('pane-down');i.removeClass('pane-hide');Cookie.write('jpanesliders_permissions-sliders" . $component . "',\$\$('div#permissions-sliders.pane-sliders .panel h3').indexOf(toggler));}," . "onBackground: function(toggler, i) {toggler.addClass('pane-toggler');toggler.removeClass('pane-toggler-down');i.addClass('pane-hide');" . "i.removeClass('pane-down');}, duration: 300, display: " . MRequest::getInt('jpanesliders_permissions-sliders' . $component, 0, 'cookie') . ", show: " . MRequest::getInt('jpanesliders_permissions-sliders' . $component, 0, 'cookie') . ", alwaysHide:true, opacity: false}); });";
     MFactory::getDocument()->addScriptDeclaration($js);
     return implode("\n", $html);
 }
示例#11
0
文件: ftp.php 项目: vanie3/appland
 protected function _mode($mode)
 {
     if ($mode == FTP_BINARY) {
         if (!$this->_putCmd("TYPE I", 200)) {
             MError::raiseWarning('35', MText::sprintf('MLIB_CLIENT_ERROR_MFTP_MODE_BINARY', $this->_response));
             return false;
         }
     } else {
         if (!$this->_putCmd("TYPE A", 200)) {
             MError::raiseWarning('35', MText::sprintf('MLIB_CLIENT_ERROR_MFTP_MODE_ASCII', $this->_response));
             return false;
         }
     }
     return true;
 }
示例#12
0
 protected function getInput()
 {
     // Get the client id.
     $clientId = $this->element['client_id'];
     if (is_null($clientId) && $this->form instanceof MForm) {
         $clientId = $this->form->getValue('client_id');
     }
     $clientId = (int) $clientId;
     $client = MApplicationHelper::getClientInfo($clientId);
     // Get the module.
     $module = (string) $this->element['module'];
     if (empty($module) && $this->form instanceof MForm) {
         $module = $this->form->getValue('module');
     }
     $module = preg_replace('#\\W#', '', $module);
     // Get the template.
     $template = (string) $this->element['template'];
     $template = preg_replace('#\\W#', '', $template);
     // Get the style.
     if ($this->form instanceof MForm) {
         $template_style_id = $this->form->getValue('template_style_id');
     }
     $template_style_id = preg_replace('#\\W#', '', $template_style_id);
     // If an extension and view are present build the options.
     if ($module && $client) {
         // Load language file
         $lang = MFactory::getLanguage();
         $lang->load($module . '.sys', $client->path, null, false, false) || $lang->load($module . '.sys', $client->path . '/modules/' . $module, null, false, false) || $lang->load($module . '.sys', $client->path, $lang->getDefault(), false, false) || $lang->load($module . '.sys', $client->path . '/modules/' . $module, $lang->getDefault(), false, false);
         // Get the database object and a new query object.
         $db = MFactory::getDBO();
         $query = $db->getQuery(true);
         // Build the query.
         $query->select('element, name');
         $query->from('#__extensions as e');
         $query->where('e.client_id = ' . (int) $clientId);
         $query->where('e.type = ' . $db->quote('template'));
         $query->where('e.enabled = 1');
         if ($template) {
             $query->where('e.element = ' . $db->quote($template));
         }
         if ($template_style_id) {
             $query->join('LEFT', '#__template_styles as s on s.template=e.element');
             $query->where('s.id=' . (int) $template_style_id);
         }
         // Set the query and load the templates.
         $db->setQuery($query);
         $templates = $db->loadObjectList('element');
         // Check for a database error.
         if ($db->getErrorNum()) {
             MError::raiseWarning(500, $db->getErrorMsg());
         }
         // Build the search paths for module layouts.
         $module_path = MPath::clean($client->path . '/modules/' . $module . '/tmpl');
         // Prepare array of component layouts
         $module_layouts = array();
         // Prepare the grouped list
         $groups = array();
         // Add the layout options from the module path.
         if (is_dir($module_path) && ($module_layouts = MFolder::files($module_path, '^[^_]*\\.php$'))) {
             // Create the group for the module
             $groups['_'] = array();
             $groups['_']['id'] = $this->id . '__';
             $groups['_']['text'] = MText::sprintf('MOPTION_FROM_MODULE');
             $groups['_']['items'] = array();
             foreach ($module_layouts as $file) {
                 // Add an option to the module group
                 $value = MFile::stripExt($file);
                 $text = $lang->hasKey($key = strtoupper($module . '_LAYOUT_' . $value)) ? MText::_($key) : $value;
                 $groups['_']['items'][] = MHtml::_('select.option', '_:' . $value, $text);
             }
         }
         // Loop on all templates
         if ($templates) {
             foreach ($templates as $template) {
                 // Load language file
                 $lang->load('tpl_' . $template->element . '.sys', $client->path, null, false, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, null, false, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path, $lang->getDefault(), false, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, $lang->getDefault(), false, false);
                 $template_path = MPath::clean($client->path . '/templates/' . $template->element . '/html/' . $module);
                 // Add the layout options from the template path.
                 if (is_dir($template_path) && ($files = MFolder::files($template_path, '^[^_]*\\.php$'))) {
                     foreach ($files as $i => $file) {
                         // Remove layout that already exist in component ones
                         if (in_array($file, $module_layouts)) {
                             unset($files[$i]);
                         }
                     }
                     if (count($files)) {
                         // Create the group for the template
                         $groups[$template->element] = array();
                         $groups[$template->element]['id'] = $this->id . '_' . $template->element;
                         $groups[$template->element]['text'] = MText::sprintf('MOPTION_FROM_TEMPLATE', $template->name);
                         $groups[$template->element]['items'] = array();
                         foreach ($files as $file) {
                             // Add an option to the template group
                             $value = MFile::stripExt($file);
                             $text = $lang->hasKey($key = strtoupper('TPL_' . $template->element . '_' . $module . '_LAYOUT_' . $value)) ? MText::_($key) : $value;
                             $groups[$template->element]['items'][] = MHtml::_('select.option', $template->element . ':' . $value, $text);
                         }
                     }
                 }
             }
         }
         // Compute attributes for the grouped list
         $attr = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
         // Prepare HTML code
         $html = array();
         // Compute the current selected values
         $selected = array($this->value);
         // Add a grouped list
         $html[] = MHtml::_('select.groupedlist', $groups, $this->name, array('id' => $this->id, 'group.id' => 'id', 'list.attr' => $attr, 'list.select' => $selected));
         return implode($html);
     } else {
         return '';
     }
 }
示例#13
0
文件: rules.php 项目: vanie3/appland
 public static function assetFormWidget($actions, $assetId = null, $parent = null, $control = 'mform[rules]', $idPrefix = 'mform_rules')
 {
     $images = self::_getImagesArray();
     // Get the user groups.
     $groups = self::_getUserGroups();
     // Get the incoming inherited rules as well as the asset specific rules.
     $inheriting = MAccess::getAssetRules($parent ? $parent : self::_getParentAssetId($assetId), true);
     $inherited = MAccess::getAssetRules($assetId, true);
     $rules = MAccess::getAssetRules($assetId);
     $html = array();
     $html[] = '<div class="acl-options">';
     $html[] = MHtml::_('tabs.start', 'acl-rules-' . $assetId, array('useCookie' => 1));
     $html[] = MHtml::_('tabs.panel', MText::_('MLIB_HTML_ACCESS_SUMMARY'), 'summary');
     $html[] = '			<p>' . MText::_('MLIB_HTML_ACCESS_SUMMARY_DESC') . '</p>';
     $html[] = '			<table class="aclsummary-table" summary="' . MText::_('MLIB_HTML_ACCESS_SUMMARY_DESC') . '">';
     $html[] = '			<caption>' . MText::_('MLIB_HTML_ACCESS_SUMMARY_DESC_CAPTION') . '</caption>';
     $html[] = '			<tr>';
     $html[] = '				<th class="col1 hidelabeltxt">' . MText::_('MLIB_RULES_GROUPS') . '</th>';
     foreach ($actions as $i => $action) {
         $html[] = '				<th class="col' . ($i + 2) . '">' . MText::_($action->title) . '</th>';
     }
     $html[] = '			</tr>';
     foreach ($groups as $i => $group) {
         $html[] = '			<tr class="row' . $i % 2 . '">';
         $html[] = '				<td class="col1">' . $group->text . '</td>';
         foreach ($actions as $j => $action) {
             $html[] = '				<td class="col' . ($j + 2) . '">' . ($assetId ? $inherited->allow($action->name, $group->identities) ? $images['allow'] : $images['deny'] : ($inheriting->allow($action->name, $group->identities) ? $images['allow'] : $images['deny'])) . '</td>';
         }
         $html[] = '			</tr>';
     }
     $html[] = ' 		</table>';
     foreach ($actions as $action) {
         $actionTitle = MText::_($action->title);
         $actionDesc = MText::_($action->description);
         $html[] = MHtml::_('tabs.panel', $actionTitle, $action->name);
         $html[] = '			<p>' . $actionDesc . '</p>';
         $html[] = '			<table class="aclmodify-table" summary="' . strip_tags($actionDesc) . '">';
         $html[] = '			<caption>' . MText::_('MLIB_HTML_ACCESS_MODIFY_DESC_CAPTION_ACL') . ' ' . $actionTitle . ' ' . MText::_('MLIB_HTML_ACCESS_MODIFY_DESC_CAPTION_TABLE') . '</caption>';
         $html[] = '			<tr>';
         $html[] = '				<th class="col1 hidelabeltxt">' . MText::_('MLIB_RULES_GROUP') . '</th>';
         $html[] = '				<th class="col2">' . MText::_('MLIB_RULES_INHERIT') . '</th>';
         $html[] = '				<th class="col3 hidelabeltxt">' . MText::_('MMODIFY') . '</th>';
         $html[] = '				<th class="col4">' . MText::_('MCURRENT') . '</th>';
         $html[] = '			</tr>';
         foreach ($groups as $i => $group) {
             $selected = $rules->allow($action->name, $group->value);
             $html[] = '			<tr class="row' . $i % 2 . '">';
             $html[] = '				<td class="col1">' . $group->text . '</td>';
             $html[] = '				<td class="col2">' . ($inheriting->allow($action->name, $group->identities) ? $images['allow-i'] : $images['deny-i']) . '</td>';
             $html[] = '				<td class="col3">';
             $html[] = '					<select id="' . $idPrefix . '_' . $action->name . '_' . $group->value . '" class="inputbox" size="1" name="' . $control . '[' . $action->name . '][' . $group->value . ']" title="' . MText::sprintf('MLIB_RULES_SELECT_ALLOW_DENY_GROUP', $actionTitle, $group->text) . '">';
             $html[] = '						<option value=""' . ($selected === null ? ' selected="selected"' : '') . '>' . MText::_('MLIB_RULES_INHERIT') . '</option>';
             $html[] = '						<option value="1"' . ($selected === true ? ' selected="selected"' : '') . '>' . MText::_('MLIB_RULES_ALLOWED') . '</option>';
             $html[] = '						<option value="0"' . ($selected === false ? ' selected="selected"' : '') . '>' . MText::_('MLIB_RULES_DENIED') . '</option>';
             $html[] = '					</select>';
             $html[] = '				</td>';
             $html[] = '				<td class="col4">' . ($assetId ? $inherited->allow($action->name, $group->identities) ? $images['allow'] : $images['deny'] : ($inheriting->allow($action->name, $group->identities) ? $images['allow'] : $images['deny'])) . '</td>';
             $html[] = '			</tr>';
         }
         $html[] = '			</table>';
     }
     $html[] = MHtml::_('tabs.end');
     // Build the footer with legend and special purpose buttons.
     $html[] = '	<div class="clr"></div>';
     $html[] = '	<ul class="acllegend fltlft">';
     $html[] = '		<li class="acl-allowed">' . MText::_('MLIB_RULES_ALLOWED') . '</li>';
     $html[] = '		<li class="acl-denied">' . MText::_('MLIB_RULES_DENIED') . '</li>';
     $html[] = '	</ul>';
     $html[] = '</div>';
     return implode("\n", $html);
 }
示例#14
0
文件: table.php 项目: vanie3/appland
 public function publish($pks = null, $state = 1, $userId = 0)
 {
     // Initialise variables.
     $k = $this->_tbl_key;
     // Sanitize input.
     MArrayHelper::toInteger($pks);
     $userId = (int) $userId;
     $state = (int) $state;
     // If there are no primary keys set check to see if the instance key is set.
     if (empty($pks)) {
         if ($this->{$k}) {
             $pks = array($this->{$k});
         } else {
             $e = new MException(MText::_('MLIB_DATABASE_ERROR_NO_ROWS_SELECTED'));
             $this->setError($e);
             return false;
         }
     }
     // Update the publishing state for rows with the given primary keys.
     $query = $this->_db->getQuery(true);
     $query->update($this->_tbl);
     $query->set('published = ' . (int) $state);
     // Determine if there is checkin support for the table.
     if (property_exists($this, 'checked_out') || property_exists($this, 'checked_out_time')) {
         $query->where('(checked_out = 0 OR checked_out = ' . (int) $userId . ')');
         $checkin = true;
     } else {
         $checkin = false;
     }
     // Build the WHERE clause for the primary keys.
     $query->where($k . ' = ' . implode(' OR ' . $k . ' = ', $pks));
     $this->_db->setQuery($query);
     // Check for a database error.
     if (!$this->_db->execute()) {
         $e = new MException(MText::sprintf('MLIB_DATABASE_ERROR_PUBLISH_FAILED', get_class($this), $this->_db->getErrorMsg()));
         $this->setError($e);
         return false;
     }
     // If checkin is supported and all rows were adjusted, check them in.
     if ($checkin && count($pks) == $this->_db->getAffectedRows()) {
         // Checkin the rows.
         foreach ($pks as $pk) {
             $this->checkin($pk);
         }
     }
     // If the MTable instance value is in the list of primary keys that were set, set the instance.
     if (in_array($this->{$k}, $pks)) {
         $this->published = $state;
     }
     $this->setError('');
     return true;
 }
示例#15
0
文件: file.php 项目: vanie3/appland
 protected function _folders($path, $filter = '.', $recurse = false, $fullpath = false, $exclude = array('.svn', 'CVS', '.DS_Store', '__MACOSX'), $excludefilter = array('^\\..*'))
 {
     $arr = array();
     $path = $this->_cleanPath($path);
     if (!is_dir($path)) {
         MError::raiseWarning(21, 'MCacheStorageFile::_folders' . MText::sprintf('MLIB_FILESYSTEM_ERROR_PATH_IS_NOT_A_FOLDER', $path));
         return false;
     }
     if (!($handle = @opendir($path))) {
         return $arr;
     }
     if (count($excludefilter)) {
         $excludefilter_string = '/(' . implode('|', $excludefilter) . ')/';
     } else {
         $excludefilter_string = '';
     }
     while (($file = readdir($handle)) !== false) {
         if ($file != '.' && $file != '..' && !in_array($file, $exclude) && (empty($excludefilter_string) || !preg_match($excludefilter_string, $file))) {
             $dir = $path . '/' . $file;
             $isDir = is_dir($dir);
             if ($isDir) {
                 if (preg_match("/{$filter}/", $file)) {
                     if ($fullpath) {
                         $arr[] = $dir;
                     } else {
                         $arr[] = $file;
                     }
                 }
                 if ($recurse) {
                     if (is_integer($recurse)) {
                         $arr2 = $this->_folders($dir, $filter, $recurse - 1, $fullpath, $exclude, $excludefilter);
                     } else {
                         $arr2 = $this->_folders($dir, $filter, $recurse, $fullpath, $exclude, $excludefilter);
                     }
                     $arr = array_merge($arr, $arr2);
                 }
             }
         }
     }
     closedir($handle);
     return $arr;
 }
示例#16
0
 public function getView($name = '', $type = '', $prefix = '', $config = array())
 {
     static $views;
     if (!isset($views)) {
         $views = array();
     }
     if (empty($name)) {
         $name = $this->getName();
     }
     if (empty($prefix)) {
         $prefix = $this->getName() . 'View';
     }
     if (empty($views[$name])) {
         if ($view = $this->createView($name, $prefix, $type, $config)) {
             $views[$name] =& $view;
         } else {
             $result = MError::raiseError(500, MText::sprintf('MLIB_APPLICATION_ERROR_VIEW_NOT_FOUND', $name, $type, $prefix));
             return $result;
         }
     }
     return $views[$name];
 }
示例#17
0
文件: admin.php 项目: vanie3/appland
 protected function batchMove($value, $pks, $contexts)
 {
     $categoryId = (int) $value;
     $table = $this->getTable();
     // Check that the category exists
     if ($categoryId) {
         $categoryTable = MTable::getInstance('Category');
         if (!$categoryTable->load($categoryId)) {
             if ($error = $categoryTable->getError()) {
                 // Fatal error
                 $this->setError($error);
                 return false;
             } else {
                 $this->setError(MText::_('MLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND'));
                 return false;
             }
         }
     }
     if (empty($categoryId)) {
         $this->setError(MText::_('MLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND'));
         return false;
     }
     // Check that user has create and edit permission for the component
     $extension = MFactory::getApplication()->input->get('option', '');
     $user = MFactory::getUser();
     if (!$user->authorise('core.create', $extension . '.category.' . $categoryId)) {
         $this->setError(MText::_('MLIB_APPLICATION_ERROR_BATCH_CANNOT_CREATE'));
         return false;
     }
     // Parent exists so we let's proceed
     foreach ($pks as $pk) {
         if (!$user->authorise('core.edit', $contexts[$pk])) {
             $this->setError(MText::_('MLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
             return false;
         }
         // Check that the row actually exists
         if (!$table->load($pk)) {
             if ($error = $table->getError()) {
                 // Fatal error
                 $this->setError($error);
                 return false;
             } else {
                 // Not fatal error
                 $this->setError(MText::sprintf('MLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk));
                 continue;
             }
         }
         // Set the new category ID
         $table->catid = $categoryId;
         // Check the row.
         if (!$table->check()) {
             $this->setError($table->getError());
             return false;
         }
         // Store the row.
         if (!$table->store()) {
             $this->setError($table->getError());
             return false;
         }
     }
     // Clean the cache
     $this->cleanCache();
     return true;
 }
示例#18
0
 public function loadButtonType($type, $new = false)
 {
     $signature = md5($type);
     if (isset($this->_buttons[$signature]) && $new === false) {
         return $this->_buttons[$signature];
     }
     if (!class_exists('MButton')) {
         MError::raiseWarning('SOME_ERROR_CODE', MText::_('MLIB_HTML_BUTTON_BASE_CLASS'));
         return false;
     }
     $buttonClass = 'MButton' . $type;
     if (!class_exists($buttonClass)) {
         if (isset($this->_buttonPath)) {
             $dirs = $this->_buttonPath;
         } else {
             $dirs = array();
         }
         $file = MFilterInput::getInstance()->clean(str_replace('_', DIRECTORY_SEPARATOR, strtolower($type)) . '.php', 'path');
         mimport('framework.filesystem.path');
         if ($buttonFile = MPath::find($dirs, $file)) {
             include_once $buttonFile;
         } else {
             MError::raiseWarning('SOME_ERROR_CODE', MText::sprintf('MLIB_HTML_BUTTON_NO_LOAD', $buttonClass, $buttonFile));
             return false;
         }
     }
     if (!class_exists($buttonClass)) {
         //return	MError::raiseError('SOME_ERROR_CODE', "Module file $buttonFile does not contain class $buttonClass.");
         return false;
     }
     $this->_buttons[$signature] = new $buttonClass($this);
     return $this->_buttons[$signature];
 }
示例#19
0
文件: view.php 项目: vanie3/appland
 public function loadTemplate($tpl = null)
 {
     // Clear prior output
     $this->_output = null;
     $template = MFactory::getApplication()->getTemplate();
     $layout = $this->getLayout();
     $layoutTemplate = $this->getLayoutTemplate();
     // Create the template file name based on the layout
     $file = isset($tpl) ? $layout . '_' . $tpl : $layout;
     // Clean the file name
     $file = preg_replace('/[^A-Z0-9_\\.-]/i', '', $file);
     $tpl = isset($tpl) ? preg_replace('/[^A-Z0-9_\\.-]/i', '', $tpl) : $tpl;
     // Load the language file for the template
     $lang = MFactory::getLanguage();
     $lang->load('tpl_' . $template, MPATH_BASE, null, false, true) || $lang->load('tpl_' . $template, MPATH_THEMES . "/{$template}", null, false, true);
     // Change the template folder if alternative layout is in different template
     if (isset($layoutTemplate) && $layoutTemplate != '_' && $layoutTemplate != $template) {
         $this->_path['template'] = str_replace($template, $layoutTemplate, $this->_path['template']);
     }
     // Load the template script
     mimport('framework.filesystem.path');
     $filetofind = $this->_createFileName('template', array('name' => $file));
     $this->_template = MPath::find($this->_path['template'], $filetofind);
     // If alternate layout can't be found, fall back to default layout
     if ($this->_template == false) {
         $filetofind = $this->_createFileName('', array('name' => 'default' . (isset($tpl) ? '_' . $tpl : $tpl)));
         $this->_template = MPath::find($this->_path['template'], $filetofind);
     }
     if ($this->_template != false) {
         // Unset so as not to introduce into template scope
         unset($tpl);
         unset($file);
         // Never allow a 'this' property
         if (isset($this->this)) {
             unset($this->this);
         }
         // Start capturing output into a buffer
         ob_start();
         // Include the requested template filename in the local scope
         // (this will execute the view logic).
         include $this->_template;
         // Done with the requested template; get the buffer and
         // clear it.
         $this->_output = ob_get_contents();
         ob_end_clean();
         return $this->_output;
     } else {
         return MError::raiseError(500, MText::sprintf('MLIB_APPLICATION_ERROR_LAYOUTFILE_NOT_FOUND', $file));
     }
 }
示例#20
0
文件: mgrid.php 项目: vanie3/appland
 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);
 }
示例#21
0
 public function stderr($showSQL = false)
 {
     // Deprecation warning.
     MLog::add('MDatabase::stderr() is deprecated.', MLog::WARNING, 'deprecated');
     if ($this->errorNum != 0) {
         return MText::sprintf('MLIB_DATABASE_ERROR_FUNCTION_FAILED', $this->errorNum, $this->errorMsg) . ($showSQL ? "<br />SQL = <pre>{$this->sql}</pre>" : '');
     } else {
         return MText::_('MLIB_DATABASE_FUNCTION_NOERROR');
     }
 }
示例#22
0
    public function formOutput($views, $plugin)
    {
        $title = explode('miwo', $plugin);
        ?>
		<script type="text/javascript">
			jQuery(document).ready(function () {
				var plugin = '<?php 
        echo $plugin;
        ?>
';
				var selected_view = jQuery('#'+plugin+'_view_select option:selected').val();
				jQuery('#'+plugin+'-shortcode > div > #'+selected_view).show();
				jQuery('#'+plugin+'_view_select').change(function () {
					var new_view = jQuery(this).val();
					jQuery('#TB_ajaxContent > div > li').hide();
					jQuery('#TB_ajaxContent > div #'+new_view).show();
				});
			});
			function <?php 
        echo $plugin;
        ?>
Shortcode() {
				var win = window.dialogArguments || opener || parent || top;
				var plugin = '<?php 
        echo $plugin;
        ?>
';
				var string = '';
				var view = jQuery('#'+plugin+'_view_select option:selected').val();
				var children = jQuery('#'+view).children(':not(label,br)');
				view = view.split("_");
				if (view[2] !== 'default') {
					string += ' layout="'+view[2]+'"';
				}
				for (i = 0; i < children.length; i++) {
					var id = children[i].id.replace('request_', '');
					id = id.replace('request', '');
					string += ' '+id+'="'+children[i].value+'" ';
				}
				win.send_to_editor('[<?php 
        echo $plugin;
        ?>
 view="'+view[1]+'"'+string+']');
			}
		</script>
		<style>
			#TB_window {height: 350px !important; width: 450px !important; margin-top: 130px !important;}
		</style>
	<div id="<?php 
        echo $plugin;
        ?>
-shortcode" style="display:none;">
		<h3><?php 
        echo MText::sprintf('MLIB_X_SHORTCODE_HELPER', 'Miwo' . ucfirst($title[1]));
        ?>
</h3>

		<div class="miwi_shortcode_view">
			<label for="<?php 
        echo $plugin;
        ?>
view">View:</label>
			<select id="<?php 
        echo $plugin;
        ?>
_view_select" name="<?php 
        echo $plugin;
        ?>
_view_select">;
				<?php 
        foreach ($views as $name => $view) {
            ?>
					<option value="<?php 
            echo $plugin . '_' . $name;
            ?>
"><?php 
            echo $view['title'];
            ?>
</option>
				<?php 
        }
        ?>
			</select>
		</div>
		<div class="miwi_shortcode_fields">
			<?php 
        foreach ($views as $name => $view) {
            ?>
				<li id="<?php 
            echo $plugin . '_' . $name;
            ?>
" style="display:none">
					<?php 
            $hidden_fields = '';
            foreach ($view['form']->getFieldset('request') as $field) {
                if (!$field->hidden) {
                    ?>
							<?php 
                    echo $field->label;
                    ?>
							<?php 
                    echo $field->input;
                    ?>
<br/>
						<?php 
                } else {
                    $hidden_fields .= $field->input;
                }
            }
            echo $hidden_fields;
            ?>
				</li>
			<?php 
        }
        ?>
		</div>
		<div>
			<button class="button" onclick="<?php 
        echo $plugin;
        ?>
Shortcode()"><?php 
        echo MText::_('MLIB_ADD_SHORTCODE');
        ?>
</button>
		</div>
		</div><?php 
    }
示例#23
0
文件: stream.php 项目: vanie3/appland
 public function copy($src, $dest, $context = null, $use_prefix = true, $relative = false)
 {
     $res = false;
     // Capture PHP errors
     $php_errormsg = '';
     $track_errors = ini_get('track_errors');
     ini_set('track_errors', true);
     $chmodDest = $this->_getFilename($dest, 'w', $use_prefix, $relative);
     $exists = file_exists($dest);
     $context_support = version_compare(PHP_VERSION, '5.3', '>=');
     // 5.3 provides context support
     if ($exists && !$context_support) {
         $res = $this->open($src);
         if ($res) {
             $reader = $this->_fh;
             $res = $this->open($dest, 'w');
             if ($res) {
                 $res = stream_copy_to_stream($reader, $this->_fh);
                 $tmperror = $php_errormsg;
                 // save this in case fclose throws an error
                 @fclose($reader);
                 $php_errormsg = $tmperror;
                 // restore after fclose
             } else {
                 @fclose($reader);
                 // close the reader off
                 $php_errormsg = MText::sprintf('MLIB_FILESYSTEM_ERROR_STREAMS_FAILED_TO_OPEN_WRITER', $this->getError());
             }
         } else {
             if (!$php_errormsg) {
                 $php_errormsg = MText::sprintf('MLIB_FILESYSTEM_ERROR_STREAMS_FAILED_TO_OPEN_READER', $this->getError());
             }
         }
     } else {
         // Since we're going to open the file directly we need to get the filename.
         // We need to use the same prefix so force everything to write.
         $src = $this->_getFilename($src, 'w', $use_prefix, $relative);
         $dest = $this->_getFilename($dest, 'w', $use_prefix, $relative);
         if ($context_support && $context) {
             // Use the provided context
             $res = @copy($src, $dest, $context);
         } elseif ($context_support && $this->_context) {
             // Use the objects context
             $res = @copy($src, $dest, $this->_context);
         } else {
             // Don't use any context
             $res = @copy($src, $dest);
         }
     }
     if (!$res && $php_errormsg) {
         $this->setError($php_errormsg);
     } else {
         $this->chmod($chmodDest);
     }
     // Restore error tracking to what it was before
     ini_set('track_errors', $track_errors);
     return $res;
 }
示例#24
0
文件: model.php 项目: vanie3/appland
 public function getTable($name = '', $prefix = 'Table', $options = array())
 {
     if (empty($name)) {
         $name = $this->getName();
     }
     if ($table = $this->_createTable($name, $prefix, $options)) {
         return $table;
     }
     MError::raiseError(0, MText::sprintf('MLIB_APPLICATION_ERROR_TABLE_NAME_NOT_SUPPORTED', $name));
     return null;
 }
示例#25
0
 public function authenticate($credentials, $options = array())
 {
     // Get plugins
     $plugins = MPluginHelper::getPlugin('authentication');
     // Create authentication response
     $response = new MAuthenticationResponse();
     foreach ($plugins as $plugin) {
         $className = 'plg' . $plugin->type . $plugin->name;
         if (class_exists($className)) {
             $plugin = new $className($this, (array) $plugin);
         } else {
             // Bail here if the plugin can't be created
             MError::raiseWarning(50, MText::sprintf('MLIB_USER_ERROR_AUTHENTICATION_FAILED_LOAD_PLUGIN', $className));
             continue;
         }
         // Try to authenticate
         $plugin->onUserAuthenticate($credentials, $options, $response);
         // If authentication is successful break out of the loop
         if ($response->status === MAuthentication::STATUS_SUCCESS) {
             if (empty($response->type)) {
                 $response->type = isset($plugin->_name) ? $plugin->_name : $plugin->name;
             }
             break;
         }
     }
     if (empty($response->username)) {
         $response->username = $credentials['username'];
     }
     if (empty($response->fullname)) {
         $response->fullname = $credentials['username'];
     }
     if (empty($response->password)) {
         $response->password = $credentials['password'];
     }
     return $response;
 }
示例#26
0
文件: folder.php 项目: vanie3/appland
 public static function folders($path, $filter = '.', $recurse = false, $full = false, $exclude = array('.svn', 'CVS', '.DS_Store', '__MACOSX'), $excludefilter = array('^\\..*'))
 {
     // Check to make sure the path valid and clean
     $path = MPath::clean($path);
     // Is the path a folder?
     if (!is_dir($path)) {
         MError::raiseWarning(21, MText::sprintf('MLIB_FILESYSTEM_ERROR_PATH_IS_NOT_A_FOLDER_FOLDER', $path));
         return false;
     }
     // Compute the excludefilter string
     if (count($excludefilter)) {
         $excludefilter_string = '/(' . implode('|', $excludefilter) . ')/';
     } else {
         $excludefilter_string = '';
     }
     // Get the folders
     $arr = self::_items($path, $filter, $recurse, $full, $exclude, $excludefilter_string, false);
     // Sort the folders
     asort($arr);
     return array_values($arr);
 }
示例#27
0
文件: form.php 项目: vanie3/appland
 protected function validateField($element, $group = null, $value = null, $input = null)
 {
     // Make sure there is a valid SimpleXMLElement.
     if (!$element instanceof SimpleXMLElement) {
         return new MException(MText::_('MLIB_FORM_ERROR_VALIDATE_FIELD'), -1, E_ERROR);
     }
     // Initialise variables.
     $valid = true;
     // Check if the field is required.
     $required = (string) $element['required'] == 'true' || (string) $element['required'] == 'required';
     if ($required) {
         // If the field is required and the value is empty return an error message.
         if ($value === '' || $value === null) {
             // Does the field have a defined error message?
             if ($element['message']) {
                 $message = $element['message'];
             } else {
                 if ($element['label']) {
                     $message = MText::_($element['label']);
                 } else {
                     $message = MText::_($element['name']);
                 }
                 $message = MText::sprintf('MLIB_FORM_VALIDATE_FIELD_REQUIRED', $message);
             }
             return new MException($message, 2, E_WARNING);
         }
     }
     // Get the field validation rule.
     if ($type = (string) $element['validate']) {
         // Load the MFormRule object for the field.
         $rule = $this->loadRuleType($type);
         // If the object could not be loaded return an error message.
         if ($rule === false) {
             return new MException(MText::sprintf('MLIB_FORM_VALIDATE_FIELD_RULE_MISSING', $type), -2, E_ERROR);
         }
         // Run the field validation rule test.
         $valid = $rule->test($element, $value, $group, $input, $this);
         // Check for an error in the validation test.
         if ($valid instanceof Exception) {
             return $valid;
         }
     }
     // Check if the field is valid.
     if ($valid === false) {
         // Does the field have a defined error message?
         $message = (string) $element['message'];
         if ($message) {
             return new MException(MText::_($message), 1, E_WARNING);
         } else {
             return new MException(MText::sprintf('MLIB_FORM_VALIDATE_FIELD_INVALID', MText::_((string) $element['label'])), 1, E_WARNING);
         }
     }
     return true;
 }
示例#28
0
 protected function _runQuery($query, $errorMessage)
 {
     $this->_db->setQuery($query);
     if (!$this->_db->execute()) {
         $e = new MException(MText::sprintf('$errorMessage', get_class($this), $this->_db->getErrorMsg()));
         $this->setError($e);
         $this->_unlock();
         return false;
     }
     if ($this->_debug) {
         $this->_logtable();
     }
 }
示例#29
0
文件: mysql.php 项目: vanie3/appland
 public function execute()
 {
     if (!is_resource($this->connection)) {
         if (MError::$legacy) {
             if ($this->debug) {
                 MError::raiseError(500, 'MDatabaseMySQL::query: ' . $this->errorNum . ' - ' . $this->errorMsg);
             }
             return false;
         } else {
             MLog::add(MText::sprintf('MLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), MLog::ERROR, 'database');
             throw new MDatabaseException($this->errorMsg, $this->errorNum);
         }
     }
     // Take a local copy so that we don't modify the original query and cause issues later
     $sql = $this->replacePrefix((string) $this->sql);
     if ($this->limit > 0 || $this->offset > 0) {
         $sql .= ' LIMIT ' . $this->offset . ', ' . $this->limit;
     }
     // If debugging is enabled then let's log the query.
     if ($this->debug) {
         // Increment the query counter and add the query to the object queue.
         $this->count++;
         $this->log[] = $sql;
         MLog::add($sql, MLog::DEBUG, 'databasequery');
     }
     // Reset the error values.
     $this->errorNum = 0;
     $this->errorMsg = '';
     #for-multi-db
     global $wpdb;
     $multidb_file = MPATH_WP_CNT . '/db.php';
     if (!empty($wpdb) and file_exists($multidb_file)) {
         $this->connection = $wpdb->db_connect($sql);
         #for-multi-db
         $sql = $wpdb->sanitize_multidb_query_tables($sql);
     }
     // Execute the query.
     $this->cursor = mysql_query($sql, $this->connection);
     // If an error occurred handle it.
     if (!$this->cursor) {
         $this->errorNum = (int) mysql_errno($this->connection);
         $this->errorMsg = (string) mysql_error($this->connection) . ' SQL=' . $sql;
         if (MError::$legacy) {
             if ($this->debug) {
                 MError::raiseError(500, 'MDatabaseMySQL::query: ' . $this->errorNum . ' - ' . $this->errorMsg);
             }
             return false;
         } else {
             MLog::add(MText::sprintf('MLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), MLog::ERROR, 'databasequery');
             throw new MDatabaseException($this->errorMsg, $this->errorNum);
         }
     }
     return $this->cursor;
 }
示例#30
0
 protected function getInput()
 {
     // Initialize variables.
     // Get the client id.
     $clientId = $this->element['client_id'];
     if (is_null($clientId) && $this->form instanceof MForm) {
         $clientId = $this->form->getValue('client_id');
     }
     $clientId = (int) $clientId;
     $client = MApplicationHelper::getClientInfo($clientId);
     // Get the extension.
     $extn = (string) $this->element['extension'];
     if (empty($extn) && $this->form instanceof MForm) {
         $extn = $this->form->getValue('extension');
     }
     $extn = preg_replace('#\\W#', '', $extn);
     // Get the template.
     $template = (string) $this->element['template'];
     $template = preg_replace('#\\W#', '', $template);
     // Get the style.
     if ($this->form instanceof MForm) {
         $template_style_id = $this->form->getValue('template_style_id');
     }
     $template_style_id = preg_replace('#\\W#', '', $template_style_id);
     // Get the view.
     $view = (string) $this->element['view'];
     $view = preg_replace('#\\W#', '', $view);
     // If a template, extension and view are present build the options.
     if ($extn && $view && $client) {
         // Load language file
         $lang = MFactory::getLanguage();
         $lang->load($extn . '.sys', MPATH_ADMINISTRATOR, null, false, false) || $lang->load($extn . '.sys', MPATH_ADMINISTRATOR . '/components/' . $extn, null, false, false) || $lang->load($extn . '.sys', MPATH_ADMINISTRATOR, $lang->getDefault(), false, false) || $lang->load($extn . '.sys', MPATH_ADMINISTRATOR . '/components/' . $extn, $lang->getDefault(), false, false);
         // Get the database object and a new query object.
         $db = MFactory::getDBO();
         $query = $db->getQuery(true);
         // Build the query.
         $query->select('e.element, e.name');
         $query->from('#__extensions as e');
         $query->where('e.client_id = ' . (int) $clientId);
         $query->where('e.type = ' . $db->quote('template'));
         $query->where('e.enabled = 1');
         if ($template) {
             $query->where('e.element = ' . $db->quote($template));
         }
         if ($template_style_id) {
             $query->join('LEFT', '#__template_styles as s on s.template=e.element');
             $query->where('s.id=' . (int) $template_style_id);
         }
         // Set the query and load the templates.
         $db->setQuery($query);
         $templates = $db->loadObjectList('element');
         // Check for a database error.
         if ($db->getErrorNum()) {
             MError::raiseWarning(500, $db->getErrorMsg());
         }
         // Build the search paths for component layouts.
         $component_path = MPath::clean($client->path . '/components/' . $extn . '/views/' . $view . '/tmpl');
         // Prepare array of component layouts
         $component_layouts = array();
         // Prepare the grouped list
         $groups = array();
         // Add a Use Global option if useglobal="true" in XML file
         if ($this->element['useglobal'] == 'true') {
             $groups[MText::_('MOPTION_FROM_STANDARD')]['items'][] = MHtml::_('select.option', '', MText::_('MGLOBAL_USE_GLOBAL'));
         }
         // Add the layout options from the component path.
         if (is_dir($component_path) && ($component_layouts = MFolder::files($component_path, '^[^_]*\\.xml$', false, true))) {
             // Create the group for the component
             $groups['_'] = array();
             $groups['_']['id'] = $this->id . '__';
             $groups['_']['text'] = MText::sprintf('MOPTION_FROM_COMPONENT');
             $groups['_']['items'] = array();
             foreach ($component_layouts as $i => $file) {
                 // Attempt to load the XML file.
                 if (!($xml = simplexml_load_file($file))) {
                     unset($component_layouts[$i]);
                     continue;
                 }
                 // Get the help data from the XML file if present.
                 if (!($menu = $xml->xpath('layout[1]'))) {
                     unset($component_layouts[$i]);
                     continue;
                 }
                 $menu = $menu[0];
                 // Add an option to the component group
                 $value = MFile::stripext(MFile::getName($file));
                 $component_layouts[$i] = $value;
                 $text = isset($menu['option']) ? MText::_($menu['option']) : (isset($menu['title']) ? MText::_($menu['title']) : $value);
                 $groups['_']['items'][] = MHtml::_('select.option', '_:' . $value, $text);
             }
         }
         // Loop on all templates
         if ($templates) {
             foreach ($templates as $template) {
                 // Load language file
                 $lang->load('tpl_' . $template->element . '.sys', $client->path, null, false, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, null, false, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path, $lang->getDefault(), false, false) || $lang->load('tpl_' . $template->element . '.sys', $client->path . '/templates/' . $template->element, $lang->getDefault(), false, false);
                 $template_path = MPath::clean($client->path . '/templates/' . $template->element . '/html/' . $extn . '/' . $view);
                 // Add the layout options from the template path.
                 if (is_dir($template_path) && ($files = MFolder::files($template_path, '^[^_]*\\.php$', false, true))) {
                     // Files with corresponding XML files are alternate menu items, not alternate layout files
                     // so we need to exclude these files from the list.
                     $xml_files = MFolder::files($template_path, '^[^_]*\\.xml$', false, true);
                     for ($j = 0, $count = count($xml_files); $j < $count; $j++) {
                         $xml_files[$j] = MFile::stripext(MFile::getName($xml_files[$j]));
                     }
                     foreach ($files as $i => $file) {
                         // Remove layout files that exist in the component folder or that have XML files
                         if (in_array(MFile::stripext(MFile::getName($file)), $component_layouts) || in_array(MFile::stripext(MFile::getName($file)), $xml_files)) {
                             unset($files[$i]);
                         }
                     }
                     if (count($files)) {
                         // Create the group for the template
                         $groups[$template->name] = array();
                         $groups[$template->name]['id'] = $this->id . '_' . $template->element;
                         $groups[$template->name]['text'] = MText::sprintf('MOPTION_FROM_TEMPLATE', $template->name);
                         $groups[$template->name]['items'] = array();
                         foreach ($files as $file) {
                             // Add an option to the template group
                             $value = MFile::stripext(MFile::getName($file));
                             $text = $lang->hasKey($key = strtoupper('TPL_' . $template->name . '_' . $extn . '_' . $view . '_LAYOUT_' . $value)) ? MText::_($key) : $value;
                             $groups[$template->name]['items'][] = MHtml::_('select.option', $template->element . ':' . $value, $text);
                         }
                     }
                 }
             }
         }
         // Compute attributes for the grouped list
         $attr = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
         // Prepare HTML code
         $html = array();
         // Compute the current selected values
         $selected = array($this->value);
         // Add a grouped list
         $html[] = MHtml::_('select.groupedlist', $groups, $this->name, array('id' => $this->id, 'group.id' => 'id', 'list.attr' => $attr, 'list.select' => $selected));
         return implode($html);
     } else {
         return '';
     }
 }