Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 2
0
 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();
 }
Ejemplo n.º 3
0
 protected function _launch($id)
 {
     //$this->getHelper()->run($id);
     // implemented via remote request because potentially some package's cron task
     // may use front classes which will cause conflicts if executed from backend side.
     // otherwise, the only call of iaCore::run() would be enough
     $cronUrl = IA_CLEAR_URL . 'cron/?_t&t=' . (int) $id;
     iaUtil::getPageContent($cronUrl, 300);
     //
     $this->_iaCore->iaView->setMessages(iaLanguage::get('scheduled_task_ran'), iaView::SUCCESS);
     iaUtil::go_to($this->getPath());
 }
Ejemplo n.º 4
0
 public function titleAlias($title)
 {
     $result = iaSanitize::tags($title);
     $this->iaCore->factory('util');
     iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii');
     utf8_is_ascii($result) || ($result = utf8_to_ascii($result));
     $result = preg_replace('#' . self::ALIAS_SUFFIX . '$#i', '', $result);
     $result = iaSanitize::alias($result);
     $result = substr($result, 0, 150);
     // the DB scheme applies this limitation
     $result .= self::ALIAS_SUFFIX;
     return $result;
 }
Ejemplo n.º 5
0
 protected function _gridRead($params)
 {
     switch ($_POST['action']) {
         case 'delete-file':
             return $this->_deleteFile($_POST);
         case 'remove-installer':
             $result = iaUtil::deleteFile(IA_HOME . 'install/modules/module.install.php');
             return array('error' => !$result, 'message' => iaLanguage::get($result ? 'deleted' : 'error'));
         default:
             $result = array();
             $this->_iaCore->startHook('phpAdminActionsJsonHandle', array('action' => $_POST['action'], 'output' => &$result));
             return $result;
     }
 }
Ejemplo n.º 6
0
function smarty_function_preventCsrf($params, &$smarty)
{
    // support several post forms in the page
    $calledTimes = 0;
    if (!isset($_SESSION['prevent_csrf']) || !is_array($_SESSION['prevent_csrf'])) {
        $_SESSION['prevent_csrf'] = array();
    }
    $count = count($_SESSION['prevent_csrf']);
    if ($count > 30) {
        $_SESSION['prevent_csrf'] = isset($_SESSION['prevent_csrf'][$count - 1]) ? array($_SESSION['prevent_csrf'][$count - 1]) : array();
    }
    $_SESSION['prevent_csrf'][] = $token = iaUtil::generateToken();
    $calledTimes++;
    return '<input type="hidden" name="prevent_csrf" value="' . $token . '" />';
}
Ejemplo n.º 7
0
 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();
     }
 }
Ejemplo n.º 8
0
 public static function snippet($text, $length = 600)
 {
     $iaUtil = iaCore::instance()->factory('util');
     iaUtil::loadUTF8Functions();
     // Strip HTML and BB codes
     $pattern = '#(\\[\\w+[^\\]]*?\\]|\\[\\/\\w+\\]|<\\w+[^>]*?>|<\\/\\w+>)#i';
     $text = preg_replace($pattern, '', $text);
     // remove repeated spaces and new lines
     $text = preg_replace('/\\s{2,}/', PHP_EOL, $text);
     $text = trim($text, PHP_EOL);
     if (utf8_strlen($text) > $length) {
         $text = utf8_substr($text, 0, $length);
         $_tmp = utf8_decode($text);
         if (preg_match('#.*([\\.\\s]).*#s', $_tmp, $matches, PREG_OFFSET_CAPTURE)) {
             $end_pos = $matches[1][1];
             $text = utf8_substr($text, 0, $end_pos + 1);
             $text .= ' ...';
         }
     }
     return $text;
 }
Ejemplo n.º 9
0
 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();
     }
 }
Ejemplo n.º 10
0
 /**
  * Generates invoice for an item
  *
  * @param string $title plan title
  * @param double $cost plan cost
  * @param string $itemName item name
  * @param array $itemData item details
  * @param string $returnUrl return URL
  * @param int $planId plan id
  * @param bool $return true redirects to invoice payment URL
  *
  * @return string
  */
 public function createInvoice($title, $cost, $itemName = 'members', $itemData = array(), $returnUrl = '', $planId = 0, $return = false)
 {
     if (!isset($itemData['id'])) {
         $itemData['id'] = 0;
     }
     $title = empty($title) ? iaLanguage::get('plan_title_' . $planId) : $title;
     $title .= $itemData['id'] ? ' - #' . $itemData['id'] : '';
     $transactionId = uniqid('t');
     $transaction = array('member_id' => (int) (isset($itemData['member_id']) && $itemData['member_id'] ? $itemData['member_id'] : iaUsers::getIdentity()->id), 'item' => $itemName, 'item_id' => $itemData['id'], 'amount' => $cost, 'currency' => $this->iaCore->get('currency'), 'sec_key' => $transactionId, 'status' => self::PENDING, 'plan_id' => $planId, 'return_url' => $returnUrl, 'operation' => $title, 'date' => date(iaDb::DATETIME_FORMAT));
     $result = (bool) $this->iaDb->insert($transaction, null, $this->getTable());
     $return || iaUtil::go_to(IA_URL . 'pay' . IA_URL_DELIMITER . $transactionId . IA_URL_DELIMITER);
     return $result ? $transactionId : false;
 }
Ejemplo n.º 11
0
 protected function _indexPage(&$iaView)
 {
     if ('phrases' == $iaView->get('name')) {
         iaBreadcrumb::preEnd(iaLanguage::get('languages'), IA_ADMIN_URL . 'languages/');
         $iaView->assign('action', 'phrases');
         $iaView->display('languages');
         return true;
     }
     $action = isset($this->_iaCore->requestPath[0]) ? $this->_iaCore->requestPath[0] : 'list';
     $iaView->assign('action', $action);
     switch ($action) {
         case 'search':
             $pageCaption = iaLanguage::get('search_in_phrases');
             break;
         case 'download':
             $pageCaption = iaLanguage::get('export_language');
             if (isset($_POST['lang']) && $_POST['lang'] || isset($this->_iaCore->requestPath[1]) && array_key_exists($this->_iaCore->requestPath[1], $this->_iaCore->languages)) {
                 $this->_downloadLanguage($iaView);
             }
             break;
         case 'comparison':
             $pageCaption = iaLanguage::get('languages_comparison');
             $this->_compareLanguages($iaView);
             break;
         case 'rm':
             // TODO: set checkAccess
             $this->_removeLanguage($iaView);
             iaUtil::go_to($this->getPath());
             break;
         case 'default':
             $this->_setLanguageAsDefault($iaView);
             iaUtil::go_to($this->getPath());
             break;
         case 'import':
             $result = $this->_importLanguage($iaView);
             iaUtil::go_to($this->getPath() . ($result ? '' : 'download/'));
             break;
     }
     if (isset($pageCaption)) {
         iaBreadcrumb::toEnd($pageCaption, IA_SELF);
         $iaView->title($pageCaption);
     }
 }
Ejemplo n.º 12
0
 private function _consistencyPage(&$iaView)
 {
     if (!empty($_GET['type'])) {
         if (in_array($_GET['type'], array('optimize', 'repair'))) {
             $tables = $this->getHelper()->getTables();
             $type = $_GET['type'];
             $query = strtoupper($type) . ' TABLE ';
             foreach ($tables as $tableName) {
                 $query .= '`' . $tableName . '`,';
             }
             $query = rtrim($query, ',');
             $this->_iaDb->query($query);
             $iaView->setMessages(iaLanguage::get($type . '_complete'), iaView::SUCCESS);
             iaUtil::reload();
         } else {
             $this->_iaCore->startHook('phpAdminDatabaseConsistencyType', array('type' => $_GET['type']));
         }
     }
 }
Ejemplo n.º 13
0
 protected function _createJsFile($file, $type = 'config')
 {
     $this->iaCore->factory('util');
     // required in order the class iaUtil to be loaded
     $iaDb =& $this->iaCore->iaDb;
     switch ($type) {
         case 'lang':
         case 'admin_lang':
             // get phrases
             $stmt = "`code` = :lang AND `category` NOT IN ('tooltip', 'page', :category)";
             $iaDb->bind($stmt, array('lang' => $this->iaCore->iaView->language, 'category' => $type == 'admin_lang' ? 'frontend' : iaCore::ADMIN));
             $phrases = $iaDb->keyvalue(array('key', 'value'), $stmt, iaLanguage::getTable());
             // get list of languages
             $languagesList = $iaDb->assoc(array('code', 'title', 'direction', 'flagicon', 'iso' => 'code'), 'admin_lang' == $type ? null : "`status` = 'active'", 'languages');
             $fileContent = 'intelli.' . ('admin_lang' == $type ? 'admin.' : '') . 'lang = ' . iaUtil::jsonEncode($phrases) . ';' . 'intelli.languages = ' . iaUtil::jsonEncode($languagesList) . ';';
             break;
         case 'config':
             $stmt = "`private` = 0 && `type` != 'divider' && `config_group` != 'email_templates'";
             $config = $iaDb->keyvalue(array('name', 'value'), $stmt, iaCore::getConfigTable());
             if (file_exists(IA_INCLUDES . 'custom.inc.php')) {
                 include IA_INCLUDES . 'custom.inc.php';
             }
             $config['ia_url'] = IA_CLEAR_URL;
             $config['packages'] = $this->iaCore->setPackagesData();
             $config['items'] = array();
             $config['extras'] = array(array('core', iaLanguage::get('core', 'Core')));
             $array = $iaDb->all(array('name', 'title'), "`status` = 'active' ORDER BY `type`", null, null, 'extras');
             foreach ($array as $item) {
                 $config['extras'][] = array($item['name'], $item['title']);
             }
             $array = $iaDb->onefield('`item`', "`item` != 'transactions'", null, null, 'items');
             foreach ($array as $item) {
                 $config['items'][] = array($item, iaLanguage::get($item, $item));
             }
             $fileContent = 'intelli.config = ' . iaUtil::jsonEncode($config) . ';';
     }
     if (isset($fileContent)) {
         if ($fh = fopen($file, 'w')) {
             fwrite($fh, $fileContent);
             fclose($fh);
         }
     }
 }
Ejemplo n.º 14
0
 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();
 }
Ejemplo n.º 15
0
 public function jsonp($data)
 {
     $this->iaCore->factory('util');
     echo sprintf('%s(%s)', isset($_GET['fn']) ? $_GET['fn'] : '', iaUtil::jsonEncode($data));
     exit;
 }
Ejemplo n.º 16
0
 protected function _parseTreeNodes($packedNodes)
 {
     $result = array();
     $nodes = iaUtil::jsonDecode($packedNodes);
     $indent = array();
     foreach ($nodes as $node) {
         $id = $node['id'];
         $parent = $node['parent'];
         $indent[$id] = 0;
         '#' != $parent && ++$indent[$id] && (isset($indent[$parent]) ? $indent[$id] += $indent[$parent] : ($indent[$parent] = 0));
     }
     foreach ($nodes as $node) {
         $result[$node['id']] = str_repeat('&nbsp;&nbsp;&nbsp;', $indent[$node['id']]) . ' &mdash; ' . $node['text'];
     }
     return $result;
 }
Ejemplo n.º 17
0
                     if ($url = $iaPlan->prePayment($iaUsers->getItemName(), $itemData, $plan['id'])) {
                         iaUtil::redirect(iaLanguage::get('thanks'), iaLanguage::get('member_created'), $url);
                     }
                 }
             }
         }
     } elseif ('register_confirm' == $iaView->name()) {
         if (!isset($_GET['email']) || !isset($_GET['key'])) {
             return iaView::accessDenied();
         }
         $error = true;
         if ($iaUsers->confirmation($_GET['email'], $_GET['key'])) {
             $messages[] = $iaCore->get('members_autoapproval') ? iaLanguage::get('reg_confirmed') : iaLanguage::get('reg_confirm_adm_approve');
             $error = false;
             $url = $iaCore->get('members_autoapproval') ? IA_URL . 'login/' : IA_URL;
             iaUtil::redirect(iaLanguage::get('reg_confirmation'), $messages, $url);
         } else {
             $messages[] = iaLanguage::get('confirmation_key_incorrect');
         }
         $iaView->assign('success', !$error);
     }
 }
 switch ($iaView->name()) {
     case 'member_password_forgot':
         $template = 'forgot';
         break;
     case 'register_confirm':
         $template = 'registration-confirmation';
         break;
     default:
         if ($memberId) {
Ejemplo n.º 18
0
 protected function _preSaveEntry(array &$entry, array $data, $action)
 {
     $this->_iaCore->startHook('adminAddMemberValidation');
     $iaAcl = $this->_iaCore->factory('acl');
     $iaField = $this->_iaCore->factory('field');
     $fields = iaField::getAcoFieldsList(iaCore::ADMIN, $this->_itemName);
     // below is the hacky way to force the script to upload files to the appropriate user's folder
     // FIXME
     $activeUser = iaUsers::getIdentity(true);
     $_SESSION[iaUsers::SESSION_KEY] = array('id' => $this->getEntryId(), 'username' => $data['username']);
     list($entry, $error, $this->_messages, ) = $iaField->parsePost($fields, $entry);
     $_SESSION[iaUsers::SESSION_KEY] = $activeUser;
     //
     if ($iaAcl->isAccessible($this->getName(), 'usergroup')) {
         if (isset($data['usergroup_id'])) {
             $entry['usergroup_id'] = array_key_exists($data['usergroup_id'], $this->_userGroups) ? $data['usergroup_id'] : iaUsers::MEMBERSHIP_REGULAR;
         }
     } elseif (iaCore::ACTION_ADD == $action) {
         $entry['usergroup_id'] = iaUsers::MEMBERSHIP_REGULAR;
     }
     if ($error) {
         return false;
     }
     $stmt = '`email` = :email';
     if (iaCore::ACTION_EDIT == $action) {
         if (isset($entry['status']) && $entry['status'] == $this->_iaDb->one('status', iaDb::convertIds((int) $this->getEntryId()))) {
             unset($entry['status']);
         }
         $stmt .= ' AND `id` != ' . (int) $this->getEntryId();
     }
     if ($this->_iaDb->exists($stmt, $entry)) {
         $this->addMessage('error_duplicate_email');
     }
     if ($this->_iaDb->exists('`username` = :username AND `id` != :id', array('username' => $entry['username'], 'id' => $this->getEntryId()))) {
         $this->addMessage('username_already_taken');
     }
     if ($iaAcl->checkAccess($this->getName(), 'password') || iaCore::ACTION_ADD == $action) {
         $this->_password = trim($data['_password']);
         if ($this->_password || !empty($data['_password2'])) {
             $entry['password'] = $this->getHelper()->encodePassword($this->_password);
             iaUtil::loadUTF8Functions('ascii', 'validation', 'bad', 'utf8_to_ascii');
             if (empty($entry['password'])) {
                 $this->addMessage('error_password_empty');
             } elseif (!utf8_is_ascii($entry['password'])) {
                 $this->addMessage(iaLanguage::get('password') . ': ' . iaLanguage::get('ascii_required'));
             } elseif ($entry['password'] != $this->getHelper()->encodePassword($data['_password2'])) {
                 $this->addMessage('error_password_match');
             }
         }
     }
     if (empty($data['_password']) && iaCore::ACTION_ADD == $action) {
         $this->addMessage('error_password_empty');
     }
     return !$this->getMessages();
 }
Ejemplo n.º 19
0
 protected function _processQueries(array $entries)
 {
     $iaDb =& $this->iaDb;
     $iaDbControl = $this->iaCore->factory('dbcontrol', iaCore::ADMIN);
     require_once IA_INCLUDES . 'utils' . IA_DS . 'pclzip.lib.php';
     $mysqlOptions = 'ENGINE=MyISAM DEFAULT CHARSET=utf8';
     $pathsMap = array(self::TYPE_PLUGIN => IA_PLUGINS, self::TYPE_PACKAGE => IA_PACKAGES);
     $path = isset($pathsMap[$this->itemData['type']]) ? $pathsMap[$this->itemData['type']] : IA_HOME;
     $versionInstalled = $iaDb->one_bind('version', '`name` = :name', array('name' => $this->itemData['name']), self::getTable());
     foreach ($entries as $version => $entry) {
         if ($versionInstalled && version_compare($versionInstalled, $version, '>')) {
             continue;
         }
         foreach ($entry as $data) {
             if ($data['external']) {
                 $filePath = str_replace(array('{DIRECTORY_SEPARATOR}', '{DS}'), IA_DS, $data['query']);
                 $fileFullPath = $path . $this->itemData['name'] . IA_DS . $filePath;
                 if (iaUtil::isZip($fileFullPath)) {
                     $archive = new PclZip($fileFullPath);
                     $files = $archive->extract(PCLZIP_OPT_PATH, IA_TMP);
                     if (0 == $files) {
                         continue;
                     }
                     foreach ($files as $file) {
                         $iaDbControl->splitSQL($file['filename']);
                         iaUtil::deleteFile($file['filename']);
                     }
                 } else {
                     $iaDbControl->splitSQL($fileFullPath);
                 }
             } else {
                 if ($data['query']) {
                     $iaDb->query(str_replace(array('{prefix}', '{mysql_version}'), array($iaDb->prefix, $mysqlOptions), $data['query']));
                 }
             }
         }
     }
 }
Ejemplo n.º 20
0
 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;
 }
Ejemplo n.º 21
0
 protected function _reopen($option, $action)
 {
     $options = array('add' => $this->getPath() . 'add/', 'list' => $this->getPath(), 'stay' => $this->getPath() . 'edit/' . $this->getEntryId() . '/');
     $option = isset($options[$option]) ? $option : 'list';
     if (iaCore::ACTION_EDIT == $action && 'stay' != $option || iaCore::ACTION_ADD == $action) {
         $this->_iaCore->factory('util');
         iaUtil::go_to($options[$option]);
     }
 }
Ejemplo n.º 22
0
 private function _checkForUpdates()
 {
     $url = sprintf(iaUtil::REMOTE_TOOLS_URL . 'get/updates/%s/', IA_VERSION);
     $content = iaUtil::getPageContent($url);
     if (!$content) {
         return;
     }
     $content = iaUtil::jsonDecode($content);
     if (is_array($content) && $content) {
         $messages = array();
         foreach ($content as $entry) {
             switch ($entry['type']) {
                 case self::UPDATE_TYPE_INFO:
                     $messages[] = array($entry['id'], $entry['message']);
                     break;
                 case self::UPDATE_TYPE_PATCH:
                     $version = explode('.', $entry['version']);
                     if (count($version) > 3) {
                         if ($this->_iaCore->get('auto_apply_critical_upgrades')) {
                             $result = iaSystem::forceUpgrade($entry['version']);
                             if (is_bool($result) && $result) {
                                 $this->_iaCore->factory('cache')->clearGlobalCache();
                                 $message = iaLanguage::getf('script_upgraded', array('version' => $entry['version']));
                                 $this->_iaCore->iaView->setMessages($message, iaView::SUCCESS);
                                 iaUtil::go_to(IA_SELF);
                             } else {
                                 iaDebug::debug($result, 'Forced upgrade to the version ' . $entry['version']);
                             }
                         }
                     } else {
                         $url = sprintf('%sinstall/upgrade/check/%s/', IA_CLEAR_URL, $entry['version']);
                         $this->_iaCore->iaView->setMessages(iaLanguage::getf('upgrade_available', array('url' => $url, 'version' => $entry['version'])), iaView::SYSTEM);
                     }
             }
         }
         $this->_iaCore->iaView->assign('updatesInfo', $messages);
     }
 }
Ejemplo n.º 23
0
 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(iaLanguage::getf('field_is_empty', array('field' => iaLanguage::get('body'))));
     }
     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');
         $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)) {
             empty($entry['image']) || $iaPicture->delete($entry['image']);
             // already has an assigned image
             $entry['image'] = $image;
         }
     }
     unset($entry['tags']);
     return true;
 }
Ejemplo n.º 24
0
 public static function forceUpgrade($version)
 {
     iaCore::instance()->factory('util');
     $patchUrl = iaUtil::REMOTE_TOOLS_URL . 'get/patch/%s/%s/';
     $patchUrl = sprintf($patchUrl, IA_VERSION, $version);
     $filePath = IA_TMP . 'patch.iap';
     iaUtil::downloadRemoteContent($patchUrl, $filePath);
     if ($contents = file_get_contents($filePath)) {
         require_once IA_HOME . 'install/classes/ia.patch.parser.php';
         require_once IA_HOME . 'install/classes/ia.patch.applier.php';
         try {
             $iaPatchParser = new iaPatchParser($contents);
             $patch = $iaPatchParser->patch;
             $iaPatchApplier = new iaPatchApplier(IA_HOME, array('host' => INTELLI_DBHOST . ':' . INTELLI_DBPORT, 'database' => INTELLI_DBNAME, 'user' => INTELLI_DBUSER, 'password' => INTELLI_DBPASS, 'prefix' => INTELLI_DBPREFIX), true);
             $iaPatchApplier->process($patch, $version);
             $logFile = 'upgrade-log-' . $patch['info']['version_to'] . '_' . date('d-m-y-Hi') . '.txt';
             if ($fh = fopen(IA_UPLOADS . $logFile, 'wt')) {
                 fwrite($fh, $iaPatchApplier->getLog());
                 fclose($fh);
             }
             $logParams = array('type' => 'app-forced', 'from' => IA_VERSION, 'to' => $version, 'file' => $logFile);
             $iaLog = iaCore::instance()->factory('log');
             $iaLog->write(iaLog::ACTION_UPGRADE, $logParams);
             return true;
         } catch (Exception $e) {
             return $e->getMessage();
         }
     }
     return false;
 }
Ejemplo n.º 25
0
     $tags = iaCore::ACTION_ADD == $pageAction ? '' : $iaBlog->getTagsString($id);
     $iaView->assign('item', $entry);
     $iaView->assign('tags', $tags);
     break;
 case iaCore::ACTION_DELETE:
     if (1 != count($iaCore->requestPath)) {
         return iaView::errorPage(iaView::ERROR_NOT_FOUND);
     }
     $id = (int) $iaCore->requestPath[0];
     $entry = $iaDb->row(iaDb::ALL_COLUMNS_SELECTION, iaDb::convertIds($id));
     if (!$entry) {
         return iaView::errorPage(iaView::ERROR_NOT_FOUND);
     }
     $result = $iaBlog->delete($id);
     $iaView->setMessages(iaLanguage::get($result ? 'deleted' : 'db_error'), $result ? iaView::SUCCESS : iaView::ERROR);
     iaUtil::go_to($baseUrl);
     break;
 default:
     $iaView->display('index');
     $pageActions = array();
     if (isset($iaCore->requestPath[0])) {
         $id = (int) $iaCore->requestPath[0];
         if (!$id) {
             return iaView::errorPage(iaView::ERROR_NOT_FOUND);
         }
         $entry = $iaBlog->getById($id);
         if (empty($entry)) {
             return iaView::errorPage(iaView::ERROR_NOT_FOUND);
         }
         $title = iaSanitize::tags($entry['title']);
         iaBreadcrumb::toEnd($title);
Ejemplo n.º 26
0
 private function getRemoteList($localPackages)
 {
     $remotePackages = array();
     if ($cachedData = $this->_iaCore->iaCache->get('subrion_packages', 3600 * 24 * 7, true)) {
         $remotePackages = $cachedData;
         // get templates list from cache, cache lives for 1 hour
     } else {
         if ($response = iaUtil::getPageContent(iaUtil::REMOTE_TOOLS_URL . 'list/package/' . IA_VERSION)) {
             $response = iaUtil::jsonDecode($response);
             if (!empty($response['error'])) {
                 $this->_messages[] = $response['error'];
                 $this->_error = true;
             } elseif ($response['total'] > 0) {
                 if (isset($response['extensions']) && is_array($response['extensions'])) {
                     foreach ($response['extensions'] as $entry) {
                         $packageInfo = (array) $entry;
                         // exclude uploaded packages
                         if (!in_array($packageInfo['name'], $localPackages)) {
                             $packageInfo['date'] = gmdate(iaDb::DATE_FORMAT, $packageInfo['date']);
                             $packageInfo['status'] = '';
                             $packageInfo['summary'] = $packageInfo['description'];
                             $packageInfo['buttons'] = false;
                             $packageInfo['remote'] = true;
                             $remotePackages[] = $packageInfo;
                         }
                     }
                     // cache well-formed results
                     $this->_iaCore->iaCache->write('subrion_packages', $remotePackages);
                 } else {
                     $this->addMessage('error_incorrect_format_from_subrion');
                     $this->_error = true;
                 }
             }
         } else {
             $this->addMessage('error_incorrect_response_from_subrion');
             $this->_error = true;
         }
     }
     return $remotePackages;
 }
Ejemplo n.º 27
0
 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(iaLanguage::getf('field_is_empty', array('field' => iaLanguage::get('body'))), false);
     }
     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;
     }
     unset($entry['owner'], $entry['tags']);
     if (isset($_FILES['image']['tmp_name']) && $_FILES['image']['tmp_name']) {
         $iaPicture = $this->_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)) {
             empty($entry['image']) || $iaPicture->delete($entry['image']);
             // already has an assigned image
             $entry['image'] = $image;
         }
     }
     return true;
 }
Ejemplo n.º 28
0
 protected function _assignValues(&$iaView, array &$entryData)
 {
     $pageGroups = array();
     $visibleOn = array();
     // get groups
     $groups = $this->_iaDb->onefield('`group`', '1 GROUP BY `group`', null, null, 'pages');
     $rows = $this->_iaDb->all(array('id', 'name', 'title'), null, null, null, 'admin_pages_groups');
     foreach ($rows as $row) {
         if (in_array($row['id'], $groups)) {
             $pageGroups[$row['id']] = $row;
         }
     }
     if (iaCore::ACTION_EDIT == $iaView->get('action')) {
         if ($array = $this->_iaDb->onefield('page_name', "`object_type` = 'blocks' && " . iaDb::convertIds($this->getEntryId(), 'object'), null, null, 'objects_pages')) {
             $visibleOn = $array;
         }
     } elseif (!empty($_POST['pages'])) {
         $visibleOn = $_POST['pages'];
     }
     if (!empty($_POST['menus'])) {
         $iaView->assign('treeData', iaSanitize::html(iaUtil::jsonEncode($_POST['menus'])));
     }
     $iaView->assign('visibleOn', $visibleOn);
     $iaView->assign('pages', $this->_getPages());
     $iaView->assign('pagesGroup', $pageGroups);
     $iaView->assign('positions', $this->getHelper()->getPositions());
 }
Ejemplo n.º 29
0
 protected static function _generateFileName($filename = '', $prefix = '', $glue = true)
 {
     if (empty($filename)) {
         return $prefix . iaUtil::generateToken();
     }
     $extension = '';
     if (false !== strpos($filename, '.')) {
         $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
         $filename = $prefix . pathinfo($filename, PATHINFO_FILENAME);
         if (false !== strpos($filename, '.')) {
             $filename = str_replace(array('.', '~'), '-', $filename);
         }
     }
     $filename = iaSanitize::alias($filename) . '_' . iaUtil::generateToken(5);
     return $glue ? $filename . '.' . $extension : array($filename, $extension);
 }
Ejemplo n.º 30
0
 private function _getParams($groupName)
 {
     $where = "`config_group` = '{$groupName}' AND `type` != 'hidden' " . ($this->_type ? 'AND `custom` = 1' : '') . ' ORDER BY `order`';
     $params = $this->_iaDb->all(iaDb::ALL_COLUMNS_SELECTION, $where, null, null, iaCore::getConfigTable());
     if ($this->_type) {
         $custom = 'user' == $this->_type ? $this->_iaCore->getCustomConfig($this->_typeId) : $this->_iaCore->getCustomConfig(null, $this->_typeId);
         $custom2 = 'user' == $this->_type ? $this->_getUsersSpecificConfig() : array();
     }
     $iaItem = $this->_iaCore->factory('item');
     $itemsList = $iaItem->getItems();
     foreach ($params as &$entry) {
         $className = 'default';
         if ($this->_type) {
             $className = 'custom';
             if (self::TYPE_DIVIDER != $entry['type']) {
                 if (isset($custom2[$entry['name']])) {
                     $entry['default'] = $custom2[$entry['name']];
                     $entry['value'] = $custom2[$entry['name']];
                 } else {
                     $entry['default'] = $this->_iaCore->get($entry['name']);
                 }
                 if (isset($custom[$entry['name']])) {
                     $className = 'common';
                     $entry['value'] = $custom[$entry['name']];
                 }
             }
         }
         if ('itemscheckbox' == $entry['type']) {
             $array = $this->_iaCore->get($entry['extras'] . '_items_implemented');
             $array = $array ? explode(',', $array) : array();
             $array = array_values(array_intersect($array, $itemsList));
             if ($array) {
                 $enabledItems = $iaItem->getEnabledItemsForPlugin($entry['extras']);
                 for ($i = 0; $i < count($array); $i++) {
                     $array[$i] = trim($array[$i]);
                     $entry['items'][] = array('name' => $array[$i], 'title' => iaLanguage::get($array[$i]), 'checked' => (int) in_array($array[$i], $enabledItems));
                 }
             }
         }
         if (self::TYPE_SELECT == $entry['type']) {
             switch ($entry['name']) {
                 case 'timezone':
                     $entry['values'] = iaUtil::getFormattedTimezones();
                     break;
                 case 'lang':
                     $entry['values'] = $this->_iaCore->languages;
                     break;
                 default:
                     $entry['values'] = explode(',', $entry['multiple_values']);
             }
         }
         $entry['class'] = $className;
     }
     return $params;
 }