예제 #1
0
파일: form.php 프로젝트: vanie3/appland
 protected function loadForm($name, $source = null, $options = array(), $clear = false, $xpath = false)
 {
     // Handle the optional arguments.
     $options['control'] = MArrayHelper::getValue($options, 'control', false);
     // Create a signature hash.
     $hash = md5($source . serialize($options));
     // Check if we can use a previously loaded form.
     if (isset($this->_forms[$hash]) && !$clear) {
         return $this->_forms[$hash];
     }
     // Get the form.
     MForm::addFormPath(MPATH_COMPONENT . '/models/forms');
     MForm::addFieldPath(MPATH_COMPONENT . '/models/fields');
     try {
         $form = MForm::getInstance($name, $source, $options, false, $xpath);
         if (isset($options['load_data']) && $options['load_data']) {
             // Get the data for the form.
             $data = $this->loadFormData();
         } else {
             $data = array();
         }
         // Allow for additional modification of the form, and events to be triggered.
         // We pass the data because plugins may require it.
         $this->preprocessForm($form, $data);
         // Load the data into the form after the plugins have operated.
         $form->bind($data);
     } catch (Exception $e) {
         $this->setError($e->getMessage());
         return false;
     }
     // Store the form for later.
     $this->_forms[$hash] = $form;
     return $form;
 }
예제 #2
0
파일: user.php 프로젝트: vanie3/appland
 public function bind($array, $ignore = '')
 {
     if (key_exists('params', $array) && is_array($array['params'])) {
         $registry = new MRegistry();
         $registry->loadArray($array['params']);
         $array['params'] = (string) $registry;
     }
     // Attempt to bind the data.
     $return = parent::bind($array, $ignore);
     // Load the real group data based on the bound ids.
     if ($return && !empty($this->groups)) {
         // Set the group ids.
         MArrayHelper::toInteger($this->groups);
         // Get the titles for the user groups.
         $query = $this->_db->getQuery(true);
         $query->select($this->_db->quoteName('id'));
         $query->select($this->_db->quoteName('title'));
         $query->from($this->_db->quoteName('#__usergroups'));
         $query->where($this->_db->quoteName('id') . ' = ' . implode(' OR ' . $this->_db->quoteName('id') . ' = ', $this->groups));
         $this->_db->setQuery($query);
         // Set the titles for the user groups.
         $this->groups = $this->_db->loadAssocList('id', 'id');
         // Check for a database error.
         if ($this->_db->getErrorNum()) {
             $this->setError($this->_db->getErrorMsg());
             return false;
         }
     }
     return $return;
 }
예제 #3
0
파일: queries.php 프로젝트: vanie3/appland
 public function remove()
 {
     // Check for request forgeries
     MRequest::checkToken() or jexit('Invalid Token');
     $cid = MRequest::getVar('cid', array(), '', 'array');
     MArrayHelper::toInteger($cid);
     $msg = '';
     for ($i = 0, $n = count($cid); $i < $n; $i++) {
         $query = MTable::getInstance('Query', 'Table');
         if (!$query->delete($cid[$i])) {
             $msg .= $query->getError();
             $tom = "error";
         } else {
             $msg = MTEXT::_('COM_MIWOSQL_QUERY_DELETED');
             $tom = "";
         }
     }
     $this->setRedirect('index.php?option=com_miwosql&controller=queries', $msg, $tom);
 }
예제 #4
0
파일: mgrid.php 프로젝트: vanie3/appland
 public static function state($states, $value, $i, $prefix = '', $enabled = true, $translate = true, $checkbox = 'cb')
 {
     if (is_array($prefix)) {
         $options = $prefix;
         $enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled;
         $translate = array_key_exists('translate', $options) ? $options['translate'] : $translate;
         $checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox;
         $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
     }
     $state = MArrayHelper::getValue($states, (int) $value, $states[0]);
     $task = array_key_exists('task', $state) ? $state['task'] : $state[0];
     $text = array_key_exists('text', $state) ? $state['text'] : (array_key_exists(1, $state) ? $state[1] : '');
     $active_title = array_key_exists('active_title', $state) ? $state['active_title'] : (array_key_exists(2, $state) ? $state[2] : '');
     $inactive_title = array_key_exists('inactive_title', $state) ? $state['inactive_title'] : (array_key_exists(3, $state) ? $state[3] : '');
     $tip = array_key_exists('tip', $state) ? $state['tip'] : (array_key_exists(4, $state) ? $state[4] : false);
     $active_class = array_key_exists('active_class', $state) ? $state['active_class'] : (array_key_exists(5, $state) ? $state[5] : '');
     $inactive_class = array_key_exists('inactive_class', $state) ? $state['inactive_class'] : (array_key_exists(6, $state) ? $state[6] : '');
     return self::action($i, $task, $prefix, $text, $active_title, $inactive_title, $tip, $active_class, $inactive_class, $enabled, $translate, $checkbox);
 }
예제 #5
0
파일: image.php 프로젝트: vanie3/appland
 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;
 }
예제 #6
0
파일: category.php 프로젝트: vanie3/appland
 public static function categories($extension, $config = array('filter.published' => array(0, 1)))
 {
     $hash = md5($extension . '.' . serialize($config));
     if (!isset(self::$items[$hash])) {
         $config = (array) $config;
         $db = MFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select('a.id, a.title, a.level, a.parent_id');
         $query->from('#__categories AS a');
         $query->where('a.parent_id > 0');
         // Filter on extension.
         $query->where('extension = ' . $db->quote($extension));
         // Filter on the published state
         if (isset($config['filter.published'])) {
             if (is_numeric($config['filter.published'])) {
                 $query->where('a.published = ' . (int) $config['filter.published']);
             } elseif (is_array($config['filter.published'])) {
                 MArrayHelper::toInteger($config['filter.published']);
                 $query->where('a.published IN (' . implode(',', $config['filter.published']) . ')');
             }
         }
         $query->order('a.lft');
         $db->setQuery($query);
         $items = $db->loadObjectList();
         // Assemble the list options.
         self::$items[$hash] = array();
         foreach ($items as &$item) {
             $repeat = $item->level - 1 >= 0 ? $item->level - 1 : 0;
             $item->title = str_repeat('- ', $repeat) . $item->title;
             self::$items[$hash][] = MHtml::_('select.option', $item->id, $item->title);
         }
         // Special "Add to root" option:
         self::$items[$hash][] = MHtml::_('select.option', '1', MText::_('MLIB_HTML_ADD_TO_ROOT'));
     }
     return self::$items[$hash];
 }
예제 #7
0
파일: form.php 프로젝트: vanie3/appland
 protected function filterField($element, $value)
 {
     // Make sure there is a valid SimpleXMLElement.
     if (!$element instanceof SimpleXMLElement) {
         return false;
     }
     // Get the field filter type.
     $filter = (string) $element['filter'];
     // Process the input value based on the filter.
     $return = null;
     switch (strtoupper($filter)) {
         // Access Control Rules.
         case 'RULES':
             $return = array();
             foreach ((array) $value as $action => $ids) {
                 // Build the rules array.
                 $return[$action] = array();
                 foreach ($ids as $id => $p) {
                     if ($p !== '') {
                         $return[$action][$id] = $p == '1' || $p == 'true' ? true : false;
                     }
                 }
             }
             break;
             // Do nothing, thus leaving the return value as null.
         // Do nothing, thus leaving the return value as null.
         case 'UNSET':
             break;
             // No Filter.
         // No Filter.
         case 'RAW':
             $return = $value;
             break;
             // Filter the input as an array of integers.
         // Filter the input as an array of integers.
         case 'INT_ARRAY':
             // Make sure the input is an array.
             if (is_object($value)) {
                 $value = get_object_vars($value);
             }
             $value = is_array($value) ? $value : array($value);
             MArrayHelper::toInteger($value);
             $return = $value;
             break;
             // Filter safe HTML.
         // Filter safe HTML.
         case 'SAFEHTML':
             $return = MFilterInput::getInstance(null, null, 1, 1)->clean($value, 'string');
             break;
             // Convert a date to UTC based on the server timezone offset.
         // Convert a date to UTC based on the server timezone offset.
         case 'SERVER_UTC':
             if (intval($value) > 0) {
                 // Get the server timezone setting.
                 $offset = MFactory::getConfig()->get('offset');
                 // Return an SQL formatted datetime string in UTC.
                 $return = MFactory::getDate($value, $offset)->toSql();
             } else {
                 $return = '';
             }
             break;
             // Convert a date to UTC based on the user timezone offset.
         // Convert a date to UTC based on the user timezone offset.
         case 'USER_UTC':
             if (intval($value) > 0) {
                 // Get the user timezone setting defaulting to the server timezone setting.
                 $offset = MFactory::getUser()->getParam('timezone', MFactory::getConfig()->get('offset'));
                 // Return a MySQL formatted datetime string in UTC.
                 $return = MFactory::getDate($value, $offset)->toSql();
             } else {
                 $return = '';
             }
             break;
             // Ensures a protocol is present in the saved field. Only use when
             // the only permitted protocols requre '://'. See MFormRuleUrl for list of these.
         // Ensures a protocol is present in the saved field. Only use when
         // the only permitted protocols requre '://'. See MFormRuleUrl for list of these.
         case 'URL':
             if (empty($value)) {
                 return false;
             }
             $value = MFilterInput::getInstance()->clean($value, 'html');
             $value = trim($value);
             // <>" are never valid in a uri see http://www.ietf.org/rfc/rfc1738.txt.
             $value = str_replace(array('<', '>', '"'), '', $value);
             // Check for a protocol
             $protocol = parse_url($value, PHP_URL_SCHEME);
             // If there is no protocol and the relative option is not specified,
             // we assume that it is an external URL and prepend http://.
             if ($element['type'] == 'url' && !$protocol && !$element['relative'] || !$element['type'] == 'url' && !$protocol) {
                 $protocol = 'http';
                 // If it looks like an internal link, then add the root.
                 if (substr($value, 0) == 'index.php') {
                     $value = MURI::root() . $value;
                 }
                 // Otherwise we treat it is an external link.
                 // Put the url back together.
                 $value = $protocol . '://' . $value;
             } elseif (!$protocol && $element['relative']) {
                 $host = MURI::getInstance('SERVER')->gethost();
                 // If it starts with the host string, just prepend the protocol.
                 if (substr($value, 0) == $host) {
                     $value = 'http://' . $value;
                 } else {
                     $value = MURI::root() . $value;
                 }
             }
             $return = $value;
             break;
         case 'TEL':
             $value = trim($value);
             // Does it match the NANP pattern?
             if (preg_match('/^(?:\\+?1[-. ]?)?\\(?([2-9][0-8][0-9])\\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})$/', $value) == 1) {
                 $number = (string) preg_replace('/[^\\d]/', '', $value);
                 if (substr($number, 0, 1) == 1) {
                     $number = substr($number, 1);
                 }
                 if (substr($number, 0, 2) == '+1') {
                     $number = substr($number, 2);
                 }
                 $result = '1.' . $number;
             } elseif (preg_match('/^\\+(?:[0-9] ?){6,14}[0-9]$/', $value) == 1) {
                 $countrycode = substr($value, 0, strpos($value, ' '));
                 $countrycode = (string) preg_replace('/[^\\d]/', '', $countrycode);
                 $number = strstr($value, ' ');
                 $number = (string) preg_replace('/[^\\d]/', '', $number);
                 $result = $countrycode . '.' . $number;
             } elseif (preg_match('/^\\+[0-9]{1,3}\\.[0-9]{4,14}(?:x.+)?$/', $value) == 1) {
                 if (strstr($value, 'x')) {
                     $xpos = strpos($value, 'x');
                     $value = substr($value, 0, $xpos);
                 }
                 $result = str_replace('+', '', $value);
             } elseif (preg_match('/[0-9]{1,3}\\.[0-9]{4,14}$/', $value) == 1) {
                 $result = $value;
             } else {
                 $value = (string) preg_replace('/[^\\d]/', '', $value);
                 if ($value != null && strlen($value) <= 15) {
                     $length = strlen($value);
                     // if it is fewer than 13 digits assume it is a local number
                     if ($length <= 12) {
                         $result = '.' . $value;
                     } else {
                         // If it has 13 or more digits let's make a country code.
                         $cclen = $length - 12;
                         $result = substr($value, 0, $cclen) . '.' . substr($value, $cclen);
                     }
                 } else {
                     $result = '';
                 }
             }
             $return = $result;
             break;
         default:
             // Check for a callback filter.
             if (strpos($filter, '::') !== false && is_callable(explode('::', $filter))) {
                 $return = call_user_func(explode('::', $filter), $value);
             } elseif (function_exists($filter)) {
                 $return = call_user_func($filter, $value);
             } else {
                 $return = MFilterInput::getInstance()->clean($value, $filter);
             }
             break;
     }
     return $return;
 }
예제 #8
0
 public static function sortObjects(&$a, $k, $direction = 1, $caseSensitive = true, $locale = false)
 {
     if (!is_array($locale) or !is_array($locale[0])) {
         $locale = array($locale);
     }
     self::$sortCase = (array) $caseSensitive;
     self::$sortDirection = (array) $direction;
     self::$sortKey = (array) $k;
     self::$sortLocale = $locale;
     usort($a, array(__CLASS__, '_sortObjects'));
     self::$sortCase = null;
     self::$sortDirection = null;
     self::$sortKey = null;
     self::$sortLocale = null;
     return $a;
 }
예제 #9
0
파일: select.php 프로젝트: vanie3/appland
 public static function radiolist($data, $name, $attribs = null, $optKey = 'value', $optText = 'text', $selected = null, $idtag = false, $translate = false)
 {
     reset($data);
     $html = '';
     if (is_array($attribs)) {
         $attribs = MArrayHelper::toString($attribs);
     }
     $id_text = $idtag ? $idtag : $name;
     foreach ($data as $obj) {
         $k = $obj->{$optKey};
         $t = $translate ? MText::_($obj->{$optText}) : $obj->{$optText};
         $id = isset($obj->id) ? $obj->id : null;
         $extra = '';
         $extra .= $id ? ' id="' . $obj->id . '"' : '';
         if (is_array($selected)) {
             foreach ($selected as $val) {
                 $k2 = is_object($val) ? $val->{$optKey} : $val;
                 if ($k == $k2) {
                     $extra .= ' selected="selected"';
                     break;
                 }
             }
         } else {
             $extra .= (string) $k == (string) $selected ? ' checked="checked"' : '';
         }
         $html .= "\n\t" . '<input type="radio" name="' . $name . '"' . ' id="' . $id_text . $k . '" value="' . $k . '"' . ' ' . $extra . ' ' . $attribs . '/>' . "\n\t" . '<label for="' . $id_text . $k . '"' . ' id="' . $id_text . $k . '-lbl" class="radiobtn">' . $t . '</label>';
     }
     $html .= "\n";
     return $html;
 }
예제 #10
0
파일: registry.php 프로젝트: vanie3/appland
 protected function bindData(&$parent, $data)
 {
     // Ensure the input data is an array.
     if (is_object($data)) {
         $data = get_object_vars($data);
     } else {
         $data = (array) $data;
     }
     foreach ($data as $k => $v) {
         if (is_array($v) && MArrayHelper::isAssociative($v) || is_object($v)) {
             $parent->{$k} = new stdClass();
             $this->bindData($parent->{$k}, $v);
         } else {
             $parent->{$k} = $v;
         }
     }
 }
예제 #11
0
파일: head.php 프로젝트: vanie3/appland
 public function fetchHead(&$document)
 {
     // Trigger the onBeforeCompileHead event (skip for installation, since it causes an error)
     $app = MFactory::getApplication();
     $app->triggerEvent('onBeforeCompileHead');
     // Get line endings
     $lnEnd = $document->_getLineEnd();
     $tab = $document->_getTab();
     $tagEnd = ' />';
     $buffer = '';
     // Generate base tag (need to happen first)
     $base = $document->getBase();
     if (!empty($base)) {
         $buffer .= $tab . '<base href="' . $document->getBase() . '" />' . $lnEnd;
     }
     // Generate META tags (needs to happen as early as possible in the head)
     foreach ($document->_metaTags as $type => $tag) {
         foreach ($tag as $name => $content) {
             if ($type == 'http-equiv') {
                 $content .= '; charset=' . $document->getCharset();
                 $buffer .= $tab . '<meta http-equiv="' . $name . '" content="' . htmlspecialchars($content) . '" />' . $lnEnd;
             } elseif ($type == 'standard' && !empty($content)) {
                 $buffer .= $tab . '<meta name="' . $name . '" content="' . htmlspecialchars($content) . '" />' . $lnEnd;
             }
         }
     }
     // Don't add empty descriptions
     $documentDescription = $document->getDescription();
     if ($documentDescription) {
         $buffer .= $tab . '<meta name="description" content="' . htmlspecialchars($documentDescription) . '" />' . $lnEnd;
     }
     // Don't add empty generators
     $generator = $document->getGenerator();
     if ($generator) {
         $buffer .= $tab . '<meta name="generator" content="' . htmlspecialchars($generator) . '" />' . $lnEnd;
     }
     $buffer .= $tab . '<title>' . htmlspecialchars($document->getTitle(), ENT_COMPAT, 'UTF-8') . '</title>' . $lnEnd;
     // Generate link declarations
     foreach ($document->_links as $link => $linkAtrr) {
         $buffer .= $tab . '<link href="' . $link . '" ' . $linkAtrr['relType'] . '="' . $linkAtrr['relation'] . '"';
         if ($temp = MArrayHelper::toString($linkAtrr['attribs'])) {
             $buffer .= ' ' . $temp;
         }
         $buffer .= ' />' . $lnEnd;
     }
     // Generate stylesheet links
     foreach ($document->_styleSheets as $strSrc => $strAttr) {
         $buffer .= $tab . '<link rel="stylesheet" href="' . $strSrc . '" type="' . $strAttr['mime'] . '"';
         if (!is_null($strAttr['media'])) {
             $buffer .= ' media="' . $strAttr['media'] . '" ';
         }
         if ($temp = MArrayHelper::toString($strAttr['attribs'])) {
             $buffer .= ' ' . $temp;
         }
         $buffer .= $tagEnd . $lnEnd;
     }
     // Generate stylesheet declarations
     foreach ($document->_style as $type => $content) {
         $buffer .= $tab . '<style type="' . $type . '">' . $lnEnd;
         // This is for full XHTML support.
         if ($document->_mime != 'text/html') {
             $buffer .= $tab . $tab . '<![CDATA[' . $lnEnd;
         }
         $buffer .= $content . $lnEnd;
         // See above note
         if ($document->_mime != 'text/html') {
             $buffer .= $tab . $tab . ']]>' . $lnEnd;
         }
         $buffer .= $tab . '</style>' . $lnEnd;
     }
     // Generate script file links
     foreach ($document->_scripts as $strSrc => $strAttr) {
         $buffer .= $tab . '<script src="' . $strSrc . '"';
         if (!is_null($strAttr['mime'])) {
             $buffer .= ' type="' . $strAttr['mime'] . '"';
         }
         if ($strAttr['defer']) {
             $buffer .= ' defer="defer"';
         }
         if ($strAttr['async']) {
             $buffer .= ' async="async"';
         }
         $buffer .= '></script>' . $lnEnd;
     }
     // Generate script declarations
     foreach ($document->_script as $type => $content) {
         $buffer .= $tab . '<script type="' . $type . '">' . $lnEnd;
         // This is for full XHTML support.
         if ($document->_mime != 'text/html') {
             $buffer .= $tab . $tab . '<![CDATA[' . $lnEnd;
         }
         $buffer .= $content . $lnEnd;
         // See above note
         if ($document->_mime != 'text/html') {
             $buffer .= $tab . $tab . ']]>' . $lnEnd;
         }
         $buffer .= $tab . '</script>' . $lnEnd;
     }
     // Generate script language declarations.
     if (count(MText::script())) {
         $buffer .= $tab . '<script type="text/javascript">' . $lnEnd;
         $buffer .= $tab . $tab . '(function() {' . $lnEnd;
         $buffer .= $tab . $tab . $tab . 'var strings = ' . json_encode(MText::script()) . ';' . $lnEnd;
         $buffer .= $tab . $tab . $tab . 'if (typeof Miwi == \'undefined\') {' . $lnEnd;
         $buffer .= $tab . $tab . $tab . $tab . 'Miwi = {};' . $lnEnd;
         $buffer .= $tab . $tab . $tab . $tab . 'Miwi.MText = strings;' . $lnEnd;
         $buffer .= $tab . $tab . $tab . '}' . $lnEnd;
         $buffer .= $tab . $tab . $tab . 'else {' . $lnEnd;
         $buffer .= $tab . $tab . $tab . $tab . 'Miwi.MText.load(strings);' . $lnEnd;
         $buffer .= $tab . $tab . $tab . '}' . $lnEnd;
         $buffer .= $tab . $tab . '})();' . $lnEnd;
         $buffer .= $tab . '</script>' . $lnEnd;
     }
     foreach ($document->_custom as $custom) {
         $buffer .= $tab . $custom . $lnEnd;
     }
     return $buffer;
 }
예제 #12
0
 public function publish($pks = null, $state = 1, $userId = 0)
 {
     $k = $this->_tbl_key;
     MArrayHelper::toInteger($pks);
     $userId = (int) $userId;
     $state = (int) $state;
     $compareState = $state > 1 ? 1 : $state;
     if (empty($pks)) {
         if ($this->{$k}) {
             $pks = explode(',', $this->{$k});
         } else {
             $e = new MException(MText::sprintf('MLIB_DATABASE_ERROR_NO_ROWS_SELECTED', get_class($this)));
             $this->setError($e);
             return false;
         }
     }
     $checkoutSupport = property_exists($this, 'checked_out') || property_exists($this, 'checked_out_time');
     foreach ($pks as $pk) {
         if (!($node = $this->_getNode($pk))) {
             return false;
         }
         if ($checkoutSupport) {
             $query = $this->_db->getQuery(true);
             $query->select('COUNT(' . $k . ')');
             $query->from($this->_tbl);
             $query->where('lft BETWEEN ' . (int) $node->lft . ' AND ' . (int) $node->rgt);
             $query->where('(checked_out <> 0 AND checked_out <> ' . (int) $userId . ')');
             $this->_db->setQuery($query);
             // Check for checked out children.
             if ($this->_db->loadResult()) {
                 $e = new MException(MText::sprintf('MLIB_DATABASE_ERROR_CHILD_ROWS_CHECKED_OUT', get_class($this)));
                 $this->setError($e);
                 return false;
             }
         }
         if ($node->parent_id) {
             $query = $this->_db->getQuery(true)->select('n.' . $k)->from($this->_db->quoteName($this->_tbl) . ' AS n')->where('n.lft < ' . (int) $node->lft)->where('n.rgt > ' . (int) $node->rgt)->where('n.parent_id > 0')->where('n.published < ' . (int) $compareState);
             $this->_db->setQuery($query, 0, 1);
             $rows = $this->_db->loadColumn();
             if ($this->_db->getErrorNum()) {
                 $e = new MException(MText::sprintf('MLIB_DATABASE_ERROR_PUBLISH_FAILED', get_class($this), $this->_db->getErrorMsg()));
                 $this->setError($e);
                 return false;
             }
             if (!empty($rows)) {
                 $e = new MException(MText::_('MLIB_DATABASE_ERROR_ANCESTOR_NODES_LOWER_STATE'));
                 $this->setError($e);
                 return false;
             }
         }
         $query = $this->_db->getQuery(true)->update($this->_db->quoteName($this->_tbl))->set('published = ' . (int) $state)->where('(lft > ' . (int) $node->lft . ' AND rgt < ' . (int) $node->rgt . ')' . ' OR ' . $k . ' = ' . (int) $pk);
         $this->_db->setQuery($query);
         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 ($checkoutSupport) {
             $this->checkin($pk);
         }
     }
     if (in_array($this->{$k}, $pks)) {
         $this->published = $state;
     }
     $this->setError('');
     return true;
 }
예제 #13
0
파일: admin.php 프로젝트: vanie3/appland
 public function getItem($pk = null)
 {
     $pk = !empty($pk) ? $pk : (int) $this->getState($this->getName() . '.id');
     $table = $this->getTable();
     if ($pk > 0) {
         // Attempt to load the row.
         $return = $table->load($pk);
         // Check for a table object error.
         if ($return === false && $table->getError()) {
             $this->setError($table->getError());
             return false;
         }
     }
     // Convert to the MObject before adding other data.
     $properties = $table->getProperties(1);
     $item = MArrayHelper::toObject($properties, 'MObject');
     if (property_exists($item, 'params')) {
         $registry = new MRegistry();
         $registry->loadString($item->params);
         $item->params = $registry->toArray();
     }
     return $item;
 }
예제 #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
파일: html.php 프로젝트: vanie3/appland
 public static function calendar($value, $name, $id, $format = 'Y-m-d', $attribs = null)
 {
     static $done;
     if ($done === null) {
         $done = array();
     }
     $readonly = isset($attribs['readonly']) && $attribs['readonly'] == 'readonly';
     $disabled = isset($attribs['disabled']) && $attribs['disabled'] == 'disabled';
     if (is_array($attribs)) {
         $attribs = MArrayHelper::toString($attribs);
     }
     if (!$readonly && !$disabled) {
         // Load the calendar behavior
         self::_('behavior.calendar');
         self::_('behavior.tooltip');
         // Only display the triggers once for each control.
         if (!in_array($id, $done)) {
             $document = MFactory::getDocument();
             $document->addScriptDeclaration('jQuery(document).ready(function () {
                         Calendar.setup({
                             // Id of the input field
                             inputField: "' . $id . '",
                             // Format of the input field
                             ifFormat: "' . $format . '",
                             // Trigger for the calendar (button ID)
                             button: "' . $id . '_img",
                             // Alignment (defaults to "Bl")
                             align: "Tl",
                             singleClick: true,
                             firstDay: ' . MFactory::getLanguage()->getFirstDay() . '
                         });
                     });');
             $done[] = $id;
         }
         return '<input type="text" title="' . (0 !== (int) $value ? self::_('date', $value, null, null) : '') . '" name="' . $name . '" id="' . $id . '" value="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '" ' . $attribs . ' />' . self::_('image', 'system/calendar.png', MText::_('MLIB_HTML_CALENDAR'), array('class' => 'calendar', 'id' => $id . '_img'), true);
     } else {
         return '<input type="text" title="' . (0 !== (int) $value ? self::_('date', $value, null, null) : '') . '" value="' . (0 !== (int) $value ? self::_('date', $value, 'Y-m-d H:i:s', null) : '') . '" ' . $attribs . ' /><input type="hidden" name="' . $name . '" id="' . $id . '" value="' . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '" />';
     }
 }