public function actionMeta() { list($content, $album) = $this->_getPhotoOrError(); if (empty($content['photo_exif'])) { return $this->responseMessage(new XenForo_Phrase('sonnb_xengallery_this_photo_does_not_contain_any_exif_information')); } if (!empty($content['photo_exif']['ExposureProgram']) && is_int($content['photo_exif']['ExposureProgram']) && $content['photo_exif']['ExposureProgram'] > 0) { $phrase = @sonnb_XenGallery_Model_Photo::$exifExposureProgram[$content['photo_exif']['ExposureProgram']]; if ($phrase) { $phrase = new XenForo_Phrase($phrase); $content['photo_exif']['ExposureProgram'] = $phrase->render(); } } if (!empty($content['photo_exif']['ExposureTime'])) { $content['photo_exif']['ExposureTime'] .= ' (' . $content['photo_exif']['ExposureTimeOrigin'] . ')'; } if (isset($content['photo_exif']['Software'])) { $content['photo_exif']['Software'] = utf8_bad_replace($content['photo_exif']['Software'], ''); } if (isset($content['photo_exif']['ImageDescription'])) { $content['photo_exif']['ImageDescription'] = utf8_bad_replace($content['photo_exif']['ImageDescription'], ''); } if (isset($content['photo_exif']['Artist'])) { $content['photo_exif']['Artist'] = utf8_bad_replace($content['photo_exif']['Artist'], ''); } if (isset($content['photo_exif']['Copyright'])) { $content['photo_exif']['Copyright'] = utf8_bad_replace($content['photo_exif']['Copyright'], ''); } $viewParams = array('album' => $album, 'content' => $content, 'breadCrumbs' => $this->_getPhotoModel()->getContentBreadCrumbs($content, $album)); return $this->responseView('sonnb_XenGallery_ViewPublic_Photo_Exif', 'sonnb_xengallery_photo_exif', $viewParams); }
protected function _preSaveEntry(array &$entry, array $data, $action) { $iaAcl = $this->_iaCore->factory('acl'); iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii'); $entry['id'] = $iaAcl->obtainFreeId(); $entry['assignable'] = $data['visible']; $entry['visible'] = $data['visible']; if (iaCore::ACTION_ADD == $action) { if (empty($data['name'])) { $this->addMessage('error_usergroup_incorrect'); } else { $entry['name'] = strtolower(iaSanitize::paranoid($data['name'])); if (!iaValidate::isAlphaNumericValid($entry['name'])) { $this->addMessage('error_usergroup_incorrect'); } elseif ($this->_iaDb->exists('`name` = :name', array('name' => $entry['name']))) { $this->addMessage('error_usergroup_exists'); } } } foreach ($this->_iaCore->languages as $iso => $title) { if (empty($data['title'][$iso])) { $this->addMessage(iaLanguage::getf('error_lang_title', array('lang' => $this->_iaCore->languages[$iso])), false); } elseif (!utf8_is_valid($data['title'][$iso])) { $data['title'][$iso] = utf8_bad_replace($data['title'][$iso]); } } if (!$this->getMessages()) { foreach ($this->_iaCore->languages as $iso => $title) { iaLanguage::addPhrase('usergroup_' . $entry['name'], $data['title'][$iso], $iso); } } return !$this->getMessages(); }
protected function _preSaveEntry(array &$entry, array $data, $action) { parent::_preSaveEntry($entry, $data, $action); iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii'); if (!utf8_is_valid($entry['title'])) { $entry['title'] = utf8_bad_replace($entry['title']); } if (empty($entry['title'])) { $this->addMessage('title_is_empty'); } if (!utf8_is_valid($entry['body'])) { $entry['body'] = utf8_bad_replace($entry['body']); } if (empty($entry['body'])) { $this->addMessage('body_is_empty'); } if (empty($entry['date_added'])) { $entry['date_added'] = date(iaDb::DATETIME_FORMAT); } $entry['alias'] = $this->getHelper()->titleAlias(empty($entry['alias']) ? $entry['title'] : $entry['alias']); if (!empty($data['owner'])) { if ($memberId = $this->_iaCore->iaDb->one_bind('id', '`username` = :name OR `fullname` = :name', array('name' => iaSanitize::sql($_POST['owner'])), iaUsers::getTable())) { $entry['member_id'] = $memberId; } else { $this->addMessage('incorrect_owner_specified'); } } else { $entry['member_id'] = iaUsers::getIdentity()->id; } if ($this->getMessages()) { return false; } unset($entry['owner']); if (isset($_FILES['image']['tmp_name']) && $_FILES['image']['tmp_name']) { $iaPicture = $this->_iaCore->factory('picture'); $path = iaUtil::getAccountDir(); $file = $_FILES['image']; $token = iaUtil::generateToken(); $info = array('image_width' => 1000, 'image_height' => 750, 'thumb_width' => 250, 'thumb_height' => 250, 'resize_mode' => iaPicture::CROP); if ($image = $iaPicture->processImage($file, $path, $token, $info)) { if ($entry['image']) { $iaPicture = $this->_iaCore->factory('picture'); $iaPicture->delete($entry['image']); } $entry['image'] = $image; } } unset($entry['tags']); return true; }
protected function _preSaveEntry(array &$entry, array $data, $action) { parent::_preSaveEntry($entry, $data, $action); iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii'); if (!utf8_is_valid($entry['title'])) { $entry['title'] = utf8_bad_replace($entry['title']); } if (empty($entry['title'])) { $this->addMessage('title_is_empty'); } if (!utf8_is_valid($entry['body'])) { $entry['body'] = utf8_bad_replace($entry['body']); } if (empty($entry['body'])) { $this->addMessage('body_is_empty'); } if (empty($entry['date_added'])) { $entry['date_added'] = date(iaDb::DATETIME_FORMAT); } $entry['alias'] = $this->getHelper()->titleAlias(empty($entry['alias']) ? $entry['title'] : $entry['alias']); if (isset($_FILES['image']['tmp_name']) && $_FILES['image']['tmp_name']) { $this->_iaCore->loadClass(iaCore::CORE, 'picture'); $iaImage = $this->_iaCore->factoryPlugin($this->getPluginName(), iaCore::ADMIN, 'image'); $imageData = json_decode($entry['image-data'], true); $path = iaUtil::getAccountDir(); $file = $_FILES['image']; $token = iaUtil::generateToken(); $info = array('image_width' => $this->_iaCore->get('portfolio_image_width'), 'image_height' => $this->_iaCore->get('portfolio_image_height'), 'crop_width' => $imageData['width'], 'crop_height' => $imageData['height'], 'thumb_width' => $this->_iaCore->get('portfolio_thumbnail_width'), 'thumb_height' => $this->_iaCore->get('portfolio_thumbnail_height'), 'positionX' => $imageData['x'], 'positionY' => $imageData['y'], 'position' => 'LT', 'resize' => 'after_crop', 'resize_mode' => iaImage::CROP); if ($image = $iaImage->processFolioImage($file, $path, $token, $info)) { if ($entry['image']) { $iaImage = $this->_iaCore->factory('picture'); $iaImage->delete($entry['image']); } $entry['image'] = $image; } } if (empty($entry['image'])) { $this->addMessage('invalid_image_file'); } if ($this->getMessages()) { return false; } unset($entry['image-src']); unset($entry['image-data']); return true; }
protected function _postSaveEntry(array &$entry, array $data, $action) { iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii'); foreach ($this->_iaCore->languages as $code => $language) { $title = utf8_is_valid($data['title'][$code]) ? $data['title'][$code] : utf8_bad_replace($data['title'][$code]); iaLanguage::addPhrase('usergroup_' . $entry['name'], $title, $code); } // copy privileges $copyFrom = isset($data['copy_from']) ? (int) $data['copy_from'] : 0; if ($copyFrom) { $this->_iaDb->setTable('acl_privileges'); $rows = $this->_iaDb->all(iaDb::ALL_COLUMNS_SELECTION, "`type_id` = '{$copyFrom}' AND `type` = 'group'"); foreach ($rows as $key => &$row) { $row['type_id'] = $entry['id']; unset($rows[$key]['id']); } $this->_iaDb->insert($rows); $this->_iaDb->resetTable(); } }
protected function _postSaveEntry(array &$entry, array $data, $action) { iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii'); foreach ($this->_iaCore->languages as $code => $language) { $title = iaSanitize::tags($data['title'][$code]); utf8_is_valid($title) || ($title = utf8_bad_replace($title)); iaLanguage::addPhrase('usergroup_' . $entry['name'], $title, $code); } // copy privileges if ($data['copy_from']) { $this->_iaDb->setTable('acl_privileges'); $where = '`type_id` = :id AND `type` = :type'; $this->_iaDb->bind($where, array('id' => (int) $data['copy_from'], 'type' => 'group')); $rows = $this->_iaDb->all(iaDb::ALL_COLUMNS_SELECTION, $where); foreach ($rows as $key => &$row) { $row['type_id'] = $this->getEntryId(); unset($rows[$key]['id']); } $this->_iaDb->insert($rows); $this->_iaDb->resetTable(); } }
protected function _preSaveEntry(array &$entry, array $data, $action) { parent::_preSaveEntry($entry, $data, $action); iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii'); if (!utf8_is_valid($entry['title'])) { $entry['title'] = utf8_bad_replace($entry['title']); } if (empty($entry['title'])) { $this->addMessage('title_is_empty'); } if (!utf8_is_valid($entry['body'])) { $entry['body'] = utf8_bad_replace($entry['body']); } if (empty($entry['body'])) { $this->addMessage('body_is_empty'); } if (empty($entry['date_added'])) { $entry['date_added'] = date(iaDb::DATETIME_FORMAT); } $entry['alias'] = $this->getHelper()->titleAlias(empty($entry['alias']) ? $entry['title'] : $entry['alias']); if ($this->getMessages()) { return false; } if (isset($_FILES['image']['tmp_name']) && $_FILES['image']['tmp_name']) { $iaPicture = $this->_iaCore->factory('picture'); $path = iaUtil::getAccountDir(); $file = $_FILES['image']; $token = iaUtil::generateToken(); $info = array('image_width' => 1000, 'image_height' => 750, 'thumb_width' => 250, 'thumb_height' => 250, 'resize_mode' => iaPicture::CROP); if ($image = $iaPicture->processImage($file, $path, $token, $info)) { if ($entry['image']) { $iaPicture = $this->_iaCore->factory('picture'); $iaPicture->delete($entry['image']); } $entry['image'] = $image; } } return true; }
/** * Strips out any bad bytes from a UTF-8 string and returns the rest * PCRE Pattern to locate bad bytes in a UTF-8 string * Comes from W3 FAQ: Multilingual Forms * Note: modified to include full ASCII range including control chars * @see http://www.w3.org/International/questions/qa-forms-utf-8 * @param string * @return string * @package utf8 * @subpackage bad */ function utf8_bad_strip($original) { return utf8_bad_replace($original, ''); }
public function parsePost(array $fields, $previousValues = null) { $iaCore =& $this->iaCore; $error = false; $messages = array(); $invalidFields = array(); $item = array(); $data =& $_POST; // access to the data source by link if (iaCore::ACCESS_ADMIN == $this->iaCore->getAccessType()) { if (isset($data['sponsored'])) { $item['sponsored'] = (int) $data['sponsored']; $item['sponsored_plan_id'] = $item['sponsored'] ? (int) $data['plan_id'] : 0; $item['sponsored_start'] = $item['sponsored'] ? date(iaDb::DATETIME_SHORT_FORMAT) : null; $item['sponsored_end'] = $item['sponsored'] ? $data['sponsored_end'] : null; } if (isset($data['featured'])) { $item['featured'] = (int) $data['featured']; if ($item['featured']) { if (isset($data['featured_end']) && $data['featured_end']) { $item['featured_start'] = date(iaDb::DATETIME_SHORT_FORMAT); $item['featured_end'] = iaSanitize::html($data['featured_end']); } else { $error = true; $messages[] = iaLanguage::get('featured_status_finished_date_is_empty'); $invalidFields[] = 'featured_end'; } } else { $item['featured_start'] = null; $item['featured_end'] = null; } } if (isset($data['status'])) { $item['status'] = iaSanitize::html($data['status']); } if (isset($data['date_added'])) { $time = strtotime($data['date_added']); if (!$time) { $error = true; $messages[] = iaLanguage::get('added_date_is_incorrect'); } elseif ($time > time()) { $error = true; $messages[] = iaLanguage::get('future_date_specified_for_added_date'); } else { $item['date_added'] = date(iaDb::DATETIME_SHORT_FORMAT, $time); } } if (isset($data['owner'])) { if (empty($data['owner'])) { $error = true; $messages[] = iaLanguage::get('owner_is_not_specified'); } else { if ($memberId = $iaCore->iaDb->one_bind('id', '`username` = :name OR `fullname` = :name', array('name' => iaSanitize::sql($_POST['owner'])), iaUsers::getTable())) { $item['member_id'] = $memberId; } else { $error = true; $messages[] = iaLanguage::get('incorrect_owner_specified'); } } } if (isset($data['locked'])) { $item['locked'] = (int) $data['locked']; } } // the code block below filters fields based on parent/dependent structure $activeFields = array(); $parentFields = array(); foreach ($fields as $field) { $activeFields[$field['name']] = $field; if (iaField::RELATION_PARENT == $field['relation']) { $parentFields[$field['name']] = $field['children']; } } foreach ($parentFields as $fieldName => $dependencies) { if (isset($data[$fieldName])) { $value = $data[$fieldName]; foreach ($dependencies as $dependentFieldName => $values) { if (!in_array($value, $values)) { unset($activeFields[$dependentFieldName]); } } } } // $iaCore->factory('util'); iaUtil::loadUTF8Functions('validation', 'bad'); foreach ($activeFields as $fieldName => $field) { isset($data[$fieldName]) || ($data[$fieldName] = ''); // Check the UTF-8 is well formed if (!is_array($data[$fieldName]) && !utf8_is_valid($data[$fieldName])) { $data[$fieldName] = utf8_bad_replace($data[$fieldName]); } if ($field['extra_actions']) { if (false === eval($field['extra_actions'])) { continue; // make possible to stop further processing of this field by returning FALSE } } if (in_array($field['type'], array(self::TEXT, self::TEXTAREA, self::NUMBER, self::RADIO, self::CHECKBOX, self::COMBO))) { if ($field['required']) { if ($field['required_checks']) { eval($field['required_checks']); } if (empty($data[$fieldName])) { $error = true; $messages[] = in_array($field['type'], array(self::RADIO, self::CHECKBOX, self::COMBO)) ? iaLanguage::getf('field_is_not_selected', array('field' => iaLanguage::get('field_' . $fieldName))) : iaLanguage::getf('field_is_empty', array('field' => iaLanguage::get('field_' . $fieldName))); $invalidFields[] = $fieldName; } } switch ($field['type']) { case self::NUMBER: $item[$fieldName] = (double) str_replace(' ', '', $data[$fieldName]); break; case self::TEXT: $item[$fieldName] = iaSanitize::tags($data[$fieldName]); break; case self::TEXTAREA: $item[$fieldName] = $field['use_editor'] ? iaUtil::safeHTML($data[$fieldName]) : iaSanitize::tags($data[$fieldName]); break; default: $item[$fieldName] = is_array($data[$fieldName]) ? implode(',', $data[$fieldName]) : $data[$fieldName]; } } elseif (self::DATE == $field['type']) { if ($field['required'] && $field['required_checks']) { eval($field['required_checks']); } elseif ($field['required'] && empty($data[$fieldName])) { $error = true; $messages[] = iaLanguage::getf('field_is_empty', array('field' => iaLanguage::get('field_' . $fieldName))); $invalidFields[] = $fieldName; } $data[$fieldName] = trim($data[$fieldName]); if (empty($data[$fieldName])) { $item[$fieldName] = $field['allow_null'] ? null : ''; } else { if (strpos($data[$fieldName], ' ') === false) { $date = $data[$fieldName]; $time = false; } else { list($date, $time) = explode(' ', $data[$fieldName]); } // FIXME: f*****g shit $array = explode('-', $date); $year = (int) $array[0]; $month = max(1, (int) $array[1]); $day = max(1, (int) $array[2]); $year = strlen($year) == 4 ? $year : 2000; $month = strlen($month) < 2 ? '0' . $month : $month; $day = strlen($day) < 2 ? '0' . $day : $day; $item[$fieldName] = $year . '-' . $month . '-' . $day; if ($field['timepicker'] && $time) { $time = explode(':', $time); $hour = max(1, (int) $time[0]); $minute = max(1, (int) $time[1]); $seconds = max(1, (int) $time[2]); $hour = strlen($hour) < 2 ? '0' . $hour : $hour; $minute = strlen($minute) < 2 ? '0' . $minute : $minute; $seconds = strlen($seconds) < 2 ? '0' . $seconds : $seconds; $item[$fieldName] .= ' ' . $hour . ':' . $minute . ':' . $seconds; } } } elseif (self::URL == $field['type']) { $validProtocols = array('http://', 'https://'); $item[$fieldName] = ''; $req_error = false; if ($field['required']) { if ($field['required_checks']) { eval($field['required_checks']); } elseif (empty($data[$fieldName]['url']) || in_array($data[$fieldName]['url'], $validProtocols)) { $error = $req_error = true; $messages[] = iaLanguage::getf('field_is_empty', array('field' => iaLanguage::get('field_' . $fieldName))); $invalidFields[] = $fieldName; } } if (!$req_error && !empty($data[$fieldName]['url']) && !in_array($data[$fieldName]['url'], $validProtocols)) { if (false === stripos($data[$fieldName]['url'], 'http://') && false === stripos($data[$fieldName]['url'], 'https://')) { $data[$fieldName]['url'] = 'http://' . $data[$fieldName]['url']; } if (iaValidate::isUrl($data[$fieldName]['url'])) { $item[$fieldName] = array(); $item[$fieldName]['url'] = iaSanitize::tags($data[$fieldName]['url']); $item[$fieldName]['title'] = empty($data[$fieldName]['title']) ? str_replace($validProtocols, '', $data[$fieldName]['url']) : $data[$fieldName]['title']; $item[$fieldName] = implode('|', $item[$fieldName]); } else { $error = true; $messages[] = iaLanguage::get('field_' . $fieldName) . ': ' . iaLanguage::get('error_url'); $invalidFields[] = $fieldName; } } } elseif (in_array($field['type'], array(self::IMAGE, self::STORAGE, self::PICTURES)) && is_array($_FILES[$fieldName]['tmp_name']) && !empty($_FILES[$fieldName]['tmp_name'])) { if (!is_writable(IA_UPLOADS)) { $error = true; $messages[] = iaLanguage::get('error_directory_readonly'); } else { // run required field checks if ($field['required'] && $field['required_checks']) { eval($field['required_checks']); } elseif ($field['required'] && empty($_FILES[$fieldName]['tmp_name'])) { $error = true; $messages[] = iaLanguage::getf('field_is_empty', array('field' => iaLanguage::get('field_' . $fieldName))); $invalidFields[] = $fieldName; } // custom folder for uploaded images if (!empty($field['folder_name'])) { if (!is_dir(IA_UPLOADS . $field['folder_name'])) { mkdir(IA_UPLOADS . $field['folder_name']); } $path = $field['folder_name'] . IA_DS; } else { $path = iaUtil::getAccountDir(); } $item[$fieldName] = isset($data[$fieldName]) && $data[$fieldName] ? $data[$fieldName] : array(); // initialize class to work with images $methodName = self::STORAGE == $field['type'] ? '_processFileField' : '_processImageField'; // process uploaded files foreach ($_FILES[$fieldName]['tmp_name'] as $id => $tmp_name) { if ($_FILES[$fieldName]['error'][$id]) { continue; } // files limit exceeded or rewrite image value if (self::IMAGE != $field['type'] && count($item[$fieldName]) >= $field['length']) { break; } $file = array(); foreach ($_FILES[$fieldName] as $key => $value) { $file[$key] = $_FILES[$fieldName][$key][$id]; } $processing = self::$methodName($field, $file, $path); // 0 - filename, 1 - error, 2 - textual error description if (!$processing[1]) { $fieldValue = array('title' => isset($data[$fieldName . '_title'][$id]) ? substr(trim($data[$fieldName . '_title'][$id]), 0, 100) : '', 'path' => $processing[0]); if (self::IMAGE == $field['type']) { $item[$fieldName] = $fieldValue; } else { $item[$fieldName][] = $fieldValue; } } else { $error = true; $messages[] = $processing[2]; } } } // If already has images, append them. $item[$fieldName] = empty($item[$fieldName]) ? '' : serialize(array_merge($item[$fieldName])); // array_merge is used to reset numeric keys } if (isset($item[$fieldName])) { // process hook if field value exists $iaCore->startHook('phpParsePostAfterCheckField', array('field_name' => $fieldName, 'item' => &$item[$fieldName], 'value' => $field, 'error' => &$error, 'error_fields' => &$invalidFields, 'msg' => &$messages)); } } return array($item, $error, $messages, implode(',', $invalidFields)); }
private function _save(&$iaView) { $iaAcl = $this->_iaCore->factory('acl'); if (!$iaAcl->checkAccess($iaView->name() . iaAcl::SEPARATOR . iaCore::ACTION_EDIT)) { return iaView::accessDenied(); } $where = "`type` != 'hidden' " . ($this->_type ? 'AND `custom` = 1' : ''); $params = $this->_iaDb->keyvalue(array('name', 'type'), $where, iaCore::getConfigTable()); // correct admin dashboard URL generation $adminPage = $this->_iaCore->get('admin_page'); iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii'); $messages = array(); $error = false; if ($_POST['v'] && is_array($_POST['v'])) { $values = $_POST['v']; $this->_iaCore->startHook('phpConfigurationChange', array('configurationValues' => &$values)); $this->_iaDb->setTable(iaCore::getConfigTable()); foreach ($values as $key => $value) { $s = strpos($key, '_items_enabled'); if ($s !== false) { $p = $this->_iaCore->get($key, '', !is_null($this->_type)); $array = $p ? explode(',', $p) : array(); $data = array(); array_shift($value); if ($diff = array_diff($value, $array)) { foreach ($diff as $item) { array_push($data, array('action' => '+', 'item' => $item)); } } if ($diff = array_diff($array, $value)) { foreach ($diff as $item) { array_push($data, array('action' => '-', 'item' => $item)); } } $extra = substr($key, 0, $s); $this->_iaCore->startHook('phpPackageItemChangedForPlugin', array('data' => $data), $extra); } if (is_array($value)) { $value = implode(',', $value); } if (!utf8_is_valid($value)) { $value = utf8_bad_replace($value); trigger_error('Bad UTF-8 detected (replacing with "?") in configuration', E_USER_NOTICE); } if (self::TYPE_IMAGE == $params[$key]) { if (isset($_POST['delete'][$key])) { $value = ''; } elseif (!empty($_FILES[$key]['name'])) { if (!(bool) $_FILES[$key]['error']) { if (@is_uploaded_file($_FILES[$key]['tmp_name'])) { $ext = strtolower(utf8_substr($_FILES[$key]['name'], -3)); // if jpeg if ($ext == 'peg') { $ext = 'jpg'; } if (!array_key_exists(strtolower($_FILES[$key]['type']), $this->_imageTypes) || !in_array($ext, $this->_imageTypes, true) || !getimagesize($_FILES[$key]['tmp_name'])) { $error = true; $messages[] = iaLanguage::getf('file_type_error', array('extension' => implode(', ', array_unique($this->_imageTypes)))); } else { if ($this->_iaCore->get($key) && file_exists(IA_UPLOADS . $this->_iaCore->get($key))) { iaUtil::deleteFile(IA_UPLOADS . $this->_iaCore->get($key)); } $value = $fileName = $key . '.' . $ext; @move_uploaded_file($_FILES[$key]['tmp_name'], IA_UPLOADS . $fileName); @chmod(IA_UPLOADS . $fileName, 0777); } } } } else { $value = $this->_iaCore->get($key, '', !is_null($this->_type)); } } if ($this->_type) { $where = sprintf("`name` = '%s' AND `type` = '%s' AND `type_id` = %d", $key, $this->_type, $this->_typeId); $this->_iaDb->setTable(iaCore::getCustomConfigTable()); if ($_POST['c'][$key]) { $values = array('name' => $key, 'value' => $value, 'type' => $this->_type, 'type_id' => $this->_typeId); if ($this->_iaDb->exists($where)) { unset($values['value']); $this->_iaDb->bind($where, $values); $this->_iaDb->update(array('value' => $value), $where); } else { $this->_iaDb->insert($values); } } else { $this->_iaDb->delete($where); } $this->_iaDb->resetTable(); } else { $this->_iaDb->update(array('value' => $value), iaDb::convertIds($key, 'name')); } } $this->_iaDb->resetTable(); $this->_iaCore->iaCache->clearAll(); } if (!$error) { $iaView->setMessages(iaLanguage::get('saved'), iaView::SUCCESS); if (isset($_POST['param']['admin_page']) && $_POST['param']['admin_page'] != $adminPage) { iaUtil::go_to(IA_URL . $_POST['param']['admin_page'] . '/configuration/general/'); } } elseif ($messages) { $iaView->setMessages($messages); } }
public function insertLocation($contentType, $contentId, $locationData) { $existingLocation = $this->getLocationByContentId($contentType, $contentId); $locationData['location_name'] = utf8_bad_replace($locationData['location_name'], ''); if ($existingLocation) { if (sonnb_XenGallery_Model_Gallery::getTitleForUrl($locationData['location_name']) !== sonnb_XenGallery_Model_Gallery::getTitleForUrl($existingLocation['location_name'])) { $this->_getDb()->update('sonnb_xengallery_location', array('location_lat' => floatval($locationData['location_lat']), 'location_lng' => floatval($locationData['location_lng']), 'location_name' => trim($locationData['location_name']), 'location_url' => sonnb_XenGallery_Model_Gallery::getTitleForUrl($locationData['location_name'])), 'location_id = ' . $existingLocation['location_id']); } } else { if (utf8_strlen($locationData['location_name'])) { $this->_getDb()->insert('sonnb_xengallery_location', array('content_type' => $contentType, 'content_id' => $contentId, 'location_lat' => floatval($locationData['location_lat']), 'location_lng' => floatval($locationData['location_lng']), 'location_name' => trim($locationData['location_name']), 'location_url' => sonnb_XenGallery_Model_Gallery::getTitleForUrl($locationData['location_name']))); } } }
} else { $error = true; $messages[] = iaLanguage::get('error_gb_email'); } // checking email if (isset($_POST['aurl']) && !empty($_POST['aurl']) && 'http://' != $_POST['aurl']) { $entry['author_url'] = $_POST['aurl']; if (!iaValidate::isUrl($entry['author_url'])) { $error = true; $messages[] = iaLanguage::get('error_url'); } } // checking body $entry['body'] = $_POST['message']; if (!utf8_is_valid($entry['body'])) { $entry['body'] = utf8_bad_replace($entry['body']); } $length = utf8_is_ascii($entry['body']) ? strlen($entry['body']) : utf8_strlen($entry['body']); if ($iaCore->get('gb_min_chars') > 0) { if ($length < $iaCore->get('gb_min_chars')) { $error = true; $messages[] = iaLanguage::getf('error_min_gb', array('length' => $iaCore->get('gb_min_chars'))); } } if ($iaCore->get('gb_max_chars') > 0) { if ($length > $iaCore->get('gb_max_chars')) { $error = true; $messages[] = iaLanguage::getf('error_max_gb', array('length' => $iaCore->get('gb_max_chars'))); } } if (empty($entry['body'])) {
/** * Replace bad bytes with an alternative character - ASCII character * @param $str string input string * @param $replace string optional * @return string */ function utf8_bad_replace($str, $replace = '?') { require_once 'utils/bad.php'; return utf8_bad_replace($str, $replace); }
protected function _preSaveEntry(array &$entry, array $data, $action) { $entry = array('name' => iaSanitize::alias(iaUtil::checkPostParam('name')), 'item' => iaUtil::checkPostParam('item'), 'default' => iaUtil::checkPostParam('default'), 'lang_values' => iaUtil::checkPostParam('lang_values'), 'text_default' => iaSanitize::html(iaUtil::checkPostParam('text_default')), 'type' => iaUtil::checkPostParam('type'), 'annotation' => iaUtil::checkPostParam('annotation'), 'fieldgroup_id' => (int) iaUtil::checkPostParam('fieldgroup_id'), 'text_length' => (int) iaUtil::checkPostParam('text_length', 255), 'length' => iaUtil::checkPostParam('length', false), 'title' => iaUtil::checkPostParam('title'), 'pages' => iaUtil::checkPostParam('pages', array()), 'required' => iaUtil::checkPostParam('required'), 'use_editor' => (int) iaUtil::checkPostParam('use_editor'), 'empty_field' => iaSanitize::html(iaUtil::checkPostParam('empty_field')), 'url_nofollow' => (int) iaUtil::checkPostParam('url_nofollow'), 'groups' => iaUtil::checkPostParam('groups'), 'searchable' => (int) iaUtil::checkPostParam('searchable'), 'adminonly' => (int) iaUtil::checkPostParam('adminonly'), 'for_plan' => (int) iaUtil::checkPostParam('for_plan'), 'required_checks' => iaUtil::checkPostParam('required_checks'), 'extra_actions' => iaUtil::checkPostParam('extra_actions'), 'link_to' => (int) iaUtil::checkPostParam('link_to'), 'values' => '', 'relation' => iaUtil::checkPostParam('relation', iaField::RELATION_REGULAR), 'parents' => isset($data['parents']) && is_array($data['parents']) ? $data['parents'] : array(), 'children' => isset($data['children']) && is_array($data['children']) ? $data['children'] : array(), 'status' => iaUtil::checkPostParam('status', iaCore::STATUS_ACTIVE)); iaUtil::loadUTF8Functions('ascii', 'validation', 'bad'); if (!$this->_iaDb->exists(iaDb::convertIds($entry['fieldgroup_id']), null, iaField::getTableGroups())) { $entry['fieldgroup_id'] = 0; } foreach ($this->_iaCore->languages as $code => $language) { if (!empty($entry['annotation'][$code])) { if (!utf8_is_valid($entry['annotation'][$code])) { $entry['annotation'][$code] = utf8_bad_replace($entry['annotation'][$code]); } } if (!empty($entry['title'][$code])) { if (!utf8_is_valid($entry['title'][$code])) { $entry['title'][$code] = utf8_bad_replace($entry['title'][$code]); } } else { $this->addMessage(iaLanguage::getf('field_is_empty', array('field' => $language['title'] . ' ' . iaLanguage::get('title'))), false); break; } } if (iaCore::ACTION_ADD == $action) { $entry['name'] = trim(strtolower(iaSanitize::paranoid($entry['name']))); if (empty($entry['name'])) { $this->addMessage('field_name_incorrect'); } } else { unset($entry['name']); } $fieldTypes = $this->_iaDb->getEnumValues(iaField::getTable(), 'type'); if ($fieldTypes['values'] && !in_array($entry['type'], $fieldTypes['values'])) { $this->addMessage('field_type_invalid'); } else { if (!$entry['length']) { $entry['length'] = iaField::DEFAULT_LENGTH; } switch ($entry['type']) { case iaField::TEXT: if (empty($entry['text_length'])) { $entry['text_length'] = 255; } $entry['length'] = min(255, max(1, $entry['text_length'])); $entry['default'] = $entry['text_default']; break; case iaField::TEXTAREA: $entry['default'] = ''; break; case iaField::COMBO: case iaField::RADIO: case iaField::CHECKBOX: if (!empty($data['values']) && is_array($data['values'])) { $keys = array(); $lang_values = array(); $multiDefault = explode('|', iaUtil::checkPostParam('multiple_default')); $_keys = iaUtil::checkPostParam('keys'); $_values = iaUtil::checkPostParam('values'); $_langValues = iaUtil::checkPostParam('lang_values'); foreach ($_keys as $index => $key) { if (trim($key) == '') { $key = $index + 1; $_keys[$index] = $key; } if (isset($_values[$index]) && trim($_values[$index]) != '') { $values[$key] = $_values[$index]; $keys[$key] = $key; } else { unset($_keys[$index], $_values[$index]); } if ($_langValues) { foreach ($this->_iaCore->languages as $code => $language) { if ($code != $this->_iaCore->iaView->language) { if (!isset($_values[$index])) { unset($_langValues[$code][$index]); } elseif (!isset($_langValues[$code][$index]) || trim($_langValues[$code][$index]) == '') { $lang_values[$code][$key] = $values[$key]; } else { $lang_values[$code][$key] = $_langValues[$code][$index]; } } } } } // delete default values if not exists in values foreach ($multiDefault as $index => $default) { if (!in_array($default, $values)) { unset($multiDefault[$index]); } else { $k = array_search($default, $values); $multiDefault[$index] = $k; } } $multiDefault = array_values($multiDefault); if (iaField::CHECKBOX == $entry['type']) { $multiDefault = implode(',', $multiDefault); } elseif (isset($multiDefault[0])) { // multiple default is available for checkboxes only $_POST['multiple_default'] = $multiDefault = $multiDefault[0]; } else { $_POST['multiple_default'] = $multiDefault = ''; } $entry['default'] = $multiDefault; $entry['keys'] = $keys; $entry['values'] = $values; $entry['lang_values'] = $lang_values; } else { $this->addMessage('one_value'); } break; case iaField::STORAGE: if (!empty($data['file_types'])) { $entry['file_types'] = str_replace(' ', '', iaUtil::checkPostParam('file_types')); $entry['length'] = (int) iaUtil::checkPostParam('max_files', 5); } else { $this->addMessage('error_file_type'); } break; case iaField::DATE: $entry['timepicker'] = (int) iaUtil::checkPostParam('timepicker'); break; case iaField::URL: $entry['url_nofollow'] = (int) iaUtil::checkPostParam('url_nofollow'); break; case iaField::IMAGE: $entry['length'] = 1; $entry['image_height'] = (int) iaUtil::checkPostParam('image_height'); $entry['image_width'] = (int) iaUtil::checkPostParam('image_width'); $entry['thumb_height'] = (int) iaUtil::checkPostParam('thumb_height'); $entry['thumb_width'] = (int) iaUtil::checkPostParam('thumb_width'); $entry['file_prefix'] = iaUtil::checkPostParam('file_prefix'); $entry['resize_mode'] = iaUtil::checkPostParam('resize_mode'); break; case iaField::NUMBER: $entry['length'] = (int) iaUtil::checkPostParam('number_length', 8); $entry['default'] = iaUtil::checkPostParam('number_default'); break; case iaField::PICTURES: $entry['length'] = (int) iaUtil::checkPostParam('pic_max_images', 5); $entry['file_prefix'] = iaUtil::checkPostParam('pic_file_prefix'); $entry['image_height'] = (int) iaUtil::checkPostParam('pic_image_height'); $entry['image_width'] = (int) iaUtil::checkPostParam('pic_image_width'); $entry['thumb_height'] = (int) iaUtil::checkPostParam('pic_thumb_height'); $entry['thumb_width'] = (int) iaUtil::checkPostParam('pic_thumb_width'); $entry['resize_mode'] = iaUtil::checkPostParam('pic_resize_mode'); break; case iaField::TREE: $parsedTree = $this->_parseTreeNodes(iaUtil::checkPostParam('nodes')); $entry['values'] = $parsedTree[0]; $entry['tree_nodes'] = $parsedTree[1]; $entry['timepicker'] = (int) iaUtil::checkPostParam('multiple'); } unset($entry['text_length'], $entry['text_default'], $entry['nodes'], $entry['multiple']); } if (!$entry['adminonly'] && empty($entry['pages']) && 'transactions' != $entry['item']) { $this->addMessage('mark_at_least_one_page'); } $entry['required'] = (int) iaUtil::checkPostParam('required'); if ($entry['required']) { $entry['required_checks'] = iaUtil::checkPostParam('required_checks'); } $entry['extra_actions'] = iaUtil::checkPostParam('extra_actions'); if ($entry['searchable']) { if (isset($data['show_as']) && $entry['type'] != iaField::NUMBER && in_array($data['show_as'], array(iaField::COMBO, iaField::RADIO, iaField::CHECKBOX))) { $entry['show_as'] = $data['show_as']; } elseif ($entry['type'] == iaField::NUMBER && !empty($data['_values'])) { $entry['sort_order'] = 'asc' == $data['sort_order'] ? $data['sort_order'] : 'desc'; $entry['_numberRangeForSearch'] = $data['_values']; } } $this->_iaCore->startHook('phpAdminFieldsEdit', array('field' => &$entry)); return !$this->getMessages(); }
public function getPhotoExif(array $contentData, $filePath = null) { $xenOptions = XenForo_Application::getOptions(); $exif = array(); if (!empty($contentData) && function_exists('exif_read_data')) { $exifKeys = array('DateTime', 'DateTimeOriginal', 'DateTimeDigitized', 'Make', 'Model', 'ExposureTime', 'ExposureProgram', 'ExposureMode', 'FNumber', 'BrightnessValue', 'MeteringMode', 'Flash', 'ExposureMode', 'WhiteBalance', 'ISOSpeedRatings', 'ShutterSpeedValue', 'ApertureValue', 'LightSource', 'FocalLength', 'Artist', 'Copyright', 'ImageDescription', 'Software', 'Orientation', 'LensType', 'LensInfo', 'LensMake', 'LensModel', 'LensSerialNumber', 'LensSpecification', 'GPS', 'GPSLatitude', 'GPSLongitude', 'GPSLatitudeRef', 'GPSLongitudeRef', 'GPSAltitudeRef', 'GPSAltitude'); if ($filePath === null) { $filePath = $this->_getContentDataModel()->getContentDataFile($contentData); } if (file_exists($filePath) || is_readable($filePath)) { //@ini_set('exif.encode_unicode', 'UTF-8'); $exif = @exif_read_data($filePath, 0); $exif = $exif ? array_intersect_key($exif, array_flip($exifKeys)) : array(); @getimagesize($filePath, $info); if (function_exists('iptcparse') && isset($info['APP13'])) { $iptc = iptcparse($info['APP13']); if (!empty($iptc['2#105'][0])) { $exif['title'] = trim($iptc['2#105'][0]); $exif['title'] = utf8_bad_replace($exif['title'], ''); } elseif (!empty($iptc['2#005'][0])) { $exif['title'] = trim($iptc['2#005'][0]); $exif['title'] = utf8_bad_replace($exif['title'], ''); } if (!empty($iptc['2#120'][0])) { $caption = trim($iptc['2#120'][0]); $caption = utf8_bad_replace($caption, ''); if (empty($exif['title'])) { if (strlen($caption) < 80) { $exif['title'] = $caption; } else { $exif['description'] = $caption; } } elseif ($caption != $exif['title']) { $exif['description'] = $caption; } } } if ($exif) { if (!empty($exif['ImageDescription'])) { $exif['ImageDescription'] = utf8_bad_replace($exif['ImageDescription'], ''); if (empty($exif['title']) && strlen($exif['ImageDescription']) < 80) { $exif['title'] = $exif['ImageDescription']; } elseif (empty($exif['description'])) { $exif['description'] = $exif['ImageDescription']; } } if (isset($exif['Software'])) { $exif['Software'] = utf8_bad_replace($exif['Software'], ''); } if (isset($exif['ImageDescription'])) { $exif['ImageDescription'] = utf8_bad_replace($exif['ImageDescription'], ''); } if (isset($exif['Artist'])) { $exif['Artist'] = utf8_bad_replace($exif['Artist'], ''); } if (isset($exif['Copyright'])) { $exif['Copyright'] = utf8_bad_replace($exif['Copyright'], ''); } if (!empty($exif['DateTime'])) { try { $test = explode(':', $exif['DateTime']); if (count($test) > 3) { $exif['DateTime'] = preg_replace('/:/', '/', $exif['DateTime'], 2); } $date = new DateTime($exif['DateTime']); $exif['DateTime'] = $date->format('U'); } catch (Exception $e) { } } if (!empty($exif['DateTimeOriginal'])) { try { $test = explode(':', $exif['DateTimeOriginal']); if (count($test) > 3) { $exif['DateTimeOriginal'] = preg_replace('/:/', '/', $exif['DateTimeOriginal'], 2); } $date = new DateTime($exif['DateTimeOriginal']); $exif['DateTimeOriginal'] = $date->format('U'); } catch (Exception $e) { } } if (!empty($exif['DateTimeDigitized'])) { try { $test = explode(':', $exif['DateTimeDigitized']); if (count($test) > 3) { $exif['DateTimeDigitized'] = preg_replace('/:/', '/', $exif['DateTimeDigitized'], 2); } $date = new DateTime($exif['DateTimeDigitized']); $exif['DateTimeDigitized'] = $date->format('U'); } catch (Exception $e) { } } if (!empty($exif['Make'])) { if (!isset($exif['Model'])) { $exif['Model'] = ""; } $exif['Model'] = utf8_bad_replace($exif['Model']); $exif['Make'] = utf8_bad_replace($exif['Make']); $exif['Make'] = ucfirst(strtolower($exif['Make'])); $longVendors = array('OLYMPUS IMAGING CORP.' => 'Olympus', 'OLYMPUS OPTICAL CO.,LTD ' => 'Olympus', 'SAMSUNG TECHWIN CO., LTD.' => 'Samsung', 'OLYMPUS CORPORATION' => 'Olympus', 'Zoran Corporation' => 'Zoran', 'Medion OPTICAL CO,LTD' => 'Medion', 'SANYO Electric Co.,Ltd.' => 'Sanyo', 'CASIO COMPUTER CO.,LTD.' => 'Casio', 'minolta Co., Ltd.' => 'Minolta', 'Hewlett-Packard' => 'HP', 'Research In Motion' => ''); foreach ($longVendors as $longVendor => $newName) { if (preg_match('#' . preg_quote($longVendor) . '#is', $exif['Make'])) { $exif['Make'] = $newName; } } if (empty($exif['Model'])) { $exif['Model'] = $exif['Make']; } else { $vendors = array('Acer', 'Apple', 'BenQ', 'BlackBerry', 'Canon', 'Casio', 'Concord', 'DoCoMo', 'Epson', 'Fujifilm', 'Google', 'GoPro', 'Helio', 'HP', 'HTC', 'JVC', 'KDDI', 'Kodak', 'Konica Minolta', 'Kyocera', 'Leaf', 'Leica', 'LG', 'Motorola', 'Nikon', 'Nintendo', 'Nokia', 'Olympus', 'Palm', 'Panasonic', 'Pentax', 'Phase One', 'Polaroid', 'Ricoh', 'Samsung', 'Sanyo', 'Sharp', 'Sigma', 'Sony', 'Sony Ericsson', 'Toshiba', 'Vivitar'); foreach ($vendors as $_vendor) { if (preg_match('#' . preg_quote($_vendor) . '#is', $exif['Model']) && preg_match('#' . preg_quote($_vendor) . '#is', $exif['Make'])) { $exif['Make'] = ''; } } $exif['Model'] = $exif['Make'] . ' ' . $exif['Model']; } $exif['Model'] = trim($exif['Model']); } if (!empty($exif['FNumber'])) { $ele = $exif['FNumber']; if (!is_array($ele)) { $ele = explode('/', $ele); } $ele = array_map('intval', $ele); if (!empty($ele[0]) && !empty($ele[1])) { $exif['FNumber'] = 'ƒ/' . round($ele[0] / $ele[1], 1); } else { $exif['FNumber'] = 'ƒ/' . (!empty($ele[0]) ? round($ele[0], 1) : (!empty($ele[1]) ? round($ele[1], 1) : 0)); } } if (!empty($exif['FocalLength'])) { $ele = $exif['FocalLength']; if (!is_array($ele)) { $ele = explode('/', $ele); } $ele = array_map('intval', $ele); if (!empty($ele[0]) && !empty($ele[1])) { $exif['FocalLength'] = floor($ele[0] / $ele[1]) . ' mm'; } else { $exif['FocalLength'] = (!empty($ele[0]) ? floor($ele[0]) : (!empty($ele[1]) ? floor($ele[1]) : 0)) . ' mm'; } } if (!empty($exif['ApertureValue'])) { $ele = $exif['ApertureValue']; if (!is_array($ele)) { $ele = explode('/', $ele); } $ele = array_map('intval', $ele); if (!empty($ele[0]) && !empty($ele[1])) { $exif['ApertureValue'] = round($ele[0] / $ele[1], 1); } else { $exif['ApertureValue'] = !empty($ele[0]) ? round($ele[0], 1) : (!empty($ele[1]) ? round($ele[1], 1) : 0); } } if (!$xenOptions->sonnb_XG_disableLocation && (!empty($exif['GPS']) || !empty($exif['GPSLatitude']))) { $data = $exif; if (!empty($exif['GPS'])) { $data = $exif['GPS']; } $exif['latitude'] = $this->getCoordinateFromExif($data['GPSLatitude'], $data['GPSLatitudeRef']); $exif['longitude'] = $this->getCoordinateFromExif($data['GPSLongitude'], $data['GPSLongitudeRef']); try { $client = XenForo_Helper_Http::getClient($this->_getLocationModel()->getGeocodeUrlForCoordinate($exif['latitude'], $exif['longitude'])); $response = $client->request('GET'); $response = json_decode($response->getBody(), true); $exif['address'] = $response['results'][0]['formatted_address']; } catch (Exception $e) { } } } } } return $exif; }
private function _queryPage(&$iaView) { if (isset($_SESSION['queries'])) { $iaView->assign('history', $_SESSION['queries']); } if (isset($_POST['exec_query'])) { iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii'); $sql = $_POST['query']; $outerData = ''; utf8_is_valid($sql) || ($sql = utf8_bad_replace($sql)); $queries = false === strpos($sql, ';' . PHP_EOL) ? array($sql) : explode(";\r\n", $sql); foreach ($queries as $key => $sqlQuery) { $sql = trim(str_replace('{prefix}', $this->_iaDb->prefix, $sqlQuery)); $this->_iaCore->startHook('phpAdminBeforeRunSqlQuery', array('query' => $sql)); $result = $this->_iaDb->query($sql); $this->_iaCore->startHook('phpAdminAfterRunSqlQuery'); $numrows = 0; if ($result) { isset($_SESSION['queries']) || ($_SESSION['queries'] = array()); if (!in_array($sqlQuery, $_SESSION['queries'])) { if (count($_SESSION['queries']) >= 5) { array_shift($_SESSION['queries']); } $_SESSION['queries'][] = $sqlQuery; } $numrows = $rows = $this->_iaDb->getNumRows($result); if ($rows) { $rows .= $rows > 1 ? ' rows' : ' row'; $this->addMessage("<b>Query OK:</b> {$rows} selected.", false); } else { $this->addMessage('<b>Query OK:</b> ' . $this->_iaDb->getAffected() . ' rows affected.', false); } } else { $this->_error = true; $this->addMessage('<b>Query Failed:</b><br />' . $this->_iaDb->getError()); } if ($numrows) { // get field names $fieldNames = $this->_iaDb->getFieldNames($result); $outerData .= '<table class="table table-hover table-condensed"><thead><tr>'; $i = 0; foreach ($fieldNames as $field) { $outerData .= '<th ' . (!$i ? 'class="first"' : '') . '>' . $field->name . '</th>'; $i++; } $outerData .= '</tr></thead><tbody>'; $numFields = $this->_iaDb->getNumFields($result); while ($row = $this->_iaDb->fetchRow($result)) { $outerData .= '<tr>'; for ($i = 0; $i < $numFields; $i++) { $outerData .= '<td' . (!$i ? ' class="first"' : '') . '>' . iaSanitize::html($row[$i]) . '</td>'; } $outerData .= '</tr>'; } $outerData .= '</tbody></table>'; } } $iaView->assign('sql', $sql); $iaView->assign('queryOut', $outerData); } $iaView->assign('tables', $this->getHelper()->getTables()); }
protected function _preSaveEntry(array &$entry, array $data, $action) { $entry['item'] = in_array($data['item'], $this->_items) ? $data['item'] : null; if (!$entry['item']) { $this->addMessage('incorrect_item'); } if ($entry['item'] == iaUsers::getItemName()) { if (isset($data['usergroup'])) { $entry['usergroup'] = (int) $data['usergroup']; } } if (isset($this->_fields[$entry['item']])) { $entry['data'] = array(); if (!empty($data['fields']) && !$this->getMessages()) { $f = $this->_fields[$entry['item']]; $array = array(); foreach ($data['fields'] as $field) { if (in_array($field, $f[0])) { $entry['data']['fields'][] = $field; $array[] = $field; } elseif (in_array($field, $f[1])) { $entry['data']['fields'][] = $field; } } if ($array) { $this->_iaDb->update(array('for_plan' => 1), "`name` IN ('" . implode("','", $entry['data']['fields']) . "')", null, iaField::getTable()); } } $entry['data'] = serialize($entry['data']); } $this->_iaCore->startHook('phpAdminAddPlanValidation'); iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii'); $lang = array('title' => $data['title'], 'description' => $data['description']); foreach ($this->_iaCore->languages as $code => $language) { if (isset($lang['title'][$code])) { if (empty($lang['title'][$code])) { $this->addMessage(iaLanguage::getf('error_lang_title', array('lang' => $language['title'])), false); } elseif (!utf8_is_valid($lang['title'][$code])) { $lang['title'][$code] = utf8_bad_replace($lang['title'][$code]); } } if (isset($lang['description'][$code])) { if (empty($lang['description'][$code])) { $this->addMessage(iaLanguage::getf('error_lang_description', array('lang' => $language['title'])), false); } elseif (!utf8_is_valid($lang['description'][$code])) { $lang['description'][$code] = utf8_bad_replace($lang['description'][$code]); } } } $this->_languages = $lang; $entry['duration'] = isset($data['duration']) ? $data['duration'] : 0; if (!is_numeric($entry['duration'])) { $this->addMessage('error_plan_duration'); } $entry['cost'] = (double) $data['cost']; $entry['cycles'] = (int) $data['cycles']; $entry['unit'] = $data['unit']; $entry['status'] = $data['status']; $entry['recurring'] = (int) $data['recurring']; $entry['expiration_status'] = $data['expiration_status']; $this->_iaCore->startHook('phpAdminPlanCommonFieldFilled', array('item' => &$entry)); $entry['cost'] || ($this->_phraseAddSuccess = 'free_plan_added'); return !$this->getMessages(); }
return iaView::errorPage(iaView::ERROR_NOT_FOUND); } iaBreadcrumb::replaceEnd(iaLanguage::get('edit')); $guestbook = array('status' => iaCore::STATUS_ACTIVE); if (iaCore::ACTION_EDIT == $pageAction) { $id = (int) $iaCore->requestPath[0]; $guestbook = $iaDb->row(iaDb::ALL_COLUMNS_SELECTION, iaDb::convertIds($id)); } $guestbook = array('id' => isset($id) ? $id : 0, 'author_name' => iaUtil::checkPostParam('author_name', $guestbook), 'email' => iaUtil::checkPostParam('email', $guestbook), 'member_id' => iaUtil::checkPostParam('member_id', $guestbook), 'author_url' => iaUtil::checkPostParam('author_url', $guestbook), 'body' => iaUtil::checkPostParam('body', $guestbook), 'status' => iaUtil::checkPostParam('status', $guestbook), 'avatar' => iaUtil::checkPostParam('avatar', $guestbook), 'date' => iaUtil::checkPostParam('date', $guestbook)); if (isset($_POST['save'])) { iaUtil::loadUTF8Functions('ascii', 'validation', 'bad'); $error = false; $messages = array(); $guestbook['avatar'] = iaSanitize::html($guestbook['avatar']); if (utf8_is_valid($guestbook['author_name'])) { $guestbook['author_name'] = utf8_bad_replace($guestbook['author_name']); } if (isset($_FILES['image']['tmp_name']) && $_FILES['image']['tmp_name']) { $iaPicture = $iaCore->factory('picture'); $info = array('image_width' => 500, 'image_height' => 500, 'thumb_width' => 150, 'thumb_height' => 150, 'resize_mode' => iaPicture::CROP); if ($image = $iaPicture->processImage($_FILES['image'], '', iaUtil::generateToken(), $info)) { empty($guestbook['avatar']) || $iaPicture->delete($guestbook['avatar']); // already has an assigned image $guestbook['avatar'] = $image; } } if (isset($_POST['status'])) { $guestbook['status'] = isset($_POST['status']) && !empty($_POST['status']) && in_array($_POST['status'], array(iaCore::STATUS_ACTIVE, iaCore::STATUS_INACTIVE)) ? $_POST['status'] : 'inactive'; } if (isset($_POST['email']) && iaValidate::isEmail($_POST['email'])) { $guestbook['email'] = $_POST['email'];
protected function _preSaveEntry(array &$entry, array $data, $action) { $entry = array('name' => iaUtil::checkPostParam('name'), 'item' => iaUtil::checkPostParam('item'), 'collapsible' => iaUtil::checkPostParam('collapsible'), 'collapsed' => iaUtil::checkPostParam('collapsed'), 'tabview' => iaUtil::checkPostParam('tabview'), 'tabcontainer' => iaUtil::checkPostParam('tabcontainer')); iaUtil::loadUTF8Functions('ascii', 'bad', 'validation'); if (iaCore::ACTION_ADD == $action) { if (!utf8_is_ascii($entry['name'])) { $this->addMessage('ascii_required'); } else { $entry['name'] = strtolower($entry['name']); } if (!$this->getMessages() && !preg_match('/^[a-z0-9\\-_]{2,50}$/', $entry['name'])) { $this->addMessage('name_is_incorrect'); } if (empty($data['item'])) { $this->addMessage('at_least_one_item_should_be_checked'); } $entry['order'] = $this->_iaDb->getMaxOrder(iaField::getTableGroups()) + 1; } foreach ($this->_iaCore->languages as $code => $language) { if ($data['titles'][$code]) { if (!utf8_is_valid($data['titles'][$code])) { $data['titles'][$code] = utf8_bad_replace($data['titles'][$code]); } } else { $this->addMessage($language['title'] . ': ' . iaLanguage::get('title_incorrect'), false); } if ($data['description'][$code]) { if (!utf8_is_valid($data['description'][$code])) { $data['description'][$code] = utf8_bad_replace($data['description'][$code]); } } } return !$this->getMessages(); }
/** * Replace bad bytes with an alternative character - ASCII character * @param $str string input string * @param $replace string optional * @return string */ static function utf8_bad_replace($str, $replace = '?') { require_once './lib/pkp/lib/phputf8/utils/bad.php'; return utf8_bad_replace($str, $replace); }
function utf8_validation(&$item) { $item = !utf8_is_valid($item) ? utf8_bad_replace($item) : $item; }
} if ($entry['member_id'] != iaUsers::getIdentity()->id) { return iaView::errorPage(iaView::ERROR_FORBIDDEN); } } if (isset($_POST['data-blog-entry'])) { $result = false; $messages = array(); iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii'); $entry['title'] = $_POST['title']; utf8_is_valid($entry['title']) || ($entry['title'] = utf8_bad_replace($entry['title'])); if (empty($entry['title'])) { $messages[] = iaLanguage::get('title_is_empty'); } $entry['body'] = $_POST['body']; utf8_is_valid($entry['body']) || ($entry['body'] = utf8_bad_replace($entry['body'])); if (empty($entry['body'])) { $messages[] = iaLanguage::getf('field_is_empty', array('field' => iaLanguage::get('body'))); } $entry['alias'] = $iaBlog->titleAlias(empty($_POST['alias']) ? $entry['title'] : $_POST['alias']); if (!$messages) { if (isset($_FILES['image']['tmp_name']) && $_FILES['image']['tmp_name']) { $iaPicture = $iaCore->factory('picture'); $info = array('image_width' => 1000, 'image_height' => 750, 'thumb_width' => 250, 'thumb_height' => 250, 'resize_mode' => iaPicture::CROP); if ($image = $iaPicture->processImage($_FILES['image'], iaUtil::getAccountDir(), iaUtil::generateToken(), $info)) { if ($entry['image']) { $iaPicture = $iaCore->factory('picture'); $iaPicture->delete($entry['image']); } $entry['image'] = $image; }
protected function _preSaveEntry(array &$entry, array $data, $action) { $this->_iaCore->startHook('adminAddBlockValidation'); iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii'); // validate block name if (iaCore::ACTION_ADD == $action) { if (empty($data['name'])) { $entry['name'] = 'block_' . mt_rand(1000, 9999); } else { $entry['name'] = strtolower(iaSanitize::paranoid($data['name'])); if (!iaValidate::isAlphaNumericValid($entry['name'])) { $this->addMessage('error_block_name'); } elseif ($this->_iaDb->exists('`name` = :name', array('name' => $entry['name']))) { $this->addMessage('error_block_name_duplicate'); } } } $entry['classname'] = $data['classname']; $entry['position'] = $data['position']; $entry['type'] = $data['type']; $entry['status'] = isset($data['status']) ? in_array($data['status'], array(iaCore::STATUS_ACTIVE, iaCore::STATUS_INACTIVE)) ? $data['status'] : iaCore::STATUS_ACTIVE : iaCore::STATUS_ACTIVE; $entry['header'] = (int) $data['header']; $entry['collapsible'] = (int) $data['collapsible']; $entry['collapsed'] = (int) $data['collapsed']; $entry['multilingual'] = (int) $data['multilingual']; $entry['sticky'] = (int) $data['sticky']; $entry['external'] = (int) $data['external']; $entry['filename'] = $data['filename']; $entry['pages'] = isset($data['pages']) ? $data['pages'] : array(); $entry['title'] = $data['title']; $entry['contents'] = $data['content']; if ($entry['multilingual']) { if (empty($entry['title'])) { $this->addMessage('title_is_empty'); } elseif (!utf8_is_valid($entry['title'])) { $entry['title'] = utf8_bad_replace($entry['title']); } if (empty($entry['contents']) && !$entry['external']) { $this->addMessage('error_contents'); } elseif (empty($entry['filename']) && $entry['external']) { $this->addMessage('error_filename'); } if (iaBlock::TYPE_HTML != $entry['type']) { if (!utf8_is_valid($entry['contents'])) { $entry['contents'] = utf8_bad_replace($entry['contents']); } } } else { $this->_multilingualContent = $data['content']; if (isset($data['languages']) && $data['languages']) { $entry['languages'] = $data['languages']; $entry['titles'] = $data['titles']; $entry['contents'] = $data['contents']; foreach ($entry['languages'] as $langCode) { if (isset($entry['titles'][$langCode])) { if (empty($entry['titles'][$langCode])) { $this->addMessage(iaLanguage::getf('error_lang_title', array('lang' => $this->_iaCore->languages[$langCode]['title'])), false); } elseif (!utf8_is_valid($entry['titles'][$langCode])) { $entry['titles'][$langCode] = utf8_bad_replace($entry['titles'][$langCode]); } } if (isset($entry['contents'][$langCode])) { if (empty($entry['contents'][$langCode])) { $this->addMessage(iaLanguage::getf('error_lang_contents', array('lang' => $this->_iaCore->languages[$langCode]['title'])), false); } if (iaBlock::TYPE_HTML != $entry['type']) { if (!utf8_is_valid($entry['contents'][$langCode])) { $entry['contents'][$langCode] = utf8_bad_replace($entry['contents'][$langCode]); } } } } } else { $this->addMessage('block_languages_empty'); } } $this->_iaCore->startHook('phpAdminBlocksEdit', array('block' => &$entry)); return !$this->getMessages(); }