public function add($aVals, $bClean = false) { $sPhrase = $this->prepare($aVals['var_name']); $oParseInput = Phpfox_Parse_Input::instance(); if (isset($aVals['module'])) { $aParts = explode('|', $aVals['module']); } foreach ($aVals['text'] as $iId => $sText) { $sText = trim($sText); if (empty($sText)) { // continue; } if ($bClean === true) { $sText = $oParseInput->clean($sText); } else { $sText = $oParseInput->convert($sText); } $this->database()->insert($this->_sTable, array('language_id' => $iId, 'module_id' => isset($aParts) ? $aParts[0] : 'core', 'product_id' => $aVals['product_id'], 'version_id' => PhpFox::getId(), 'var_name' => $sPhrase, 'text' => $sText, 'text_default' => $sText, 'added' => PHPFOX_TIME)); } $sFinalPhrase = isset($aVals['module']) ? $aParts[1] . '.' . $sPhrase : $sPhrase; if (isset($aVals['is_help'])) { Phpfox::getService('help.process')->add(array('var_name' => $sFinalPhrase)); } Phpfox::getService('log.staff')->add('phrase', 'add', array('phrase' => $sPhrase)); $this->cache()->remove('locale', 'substr'); return $sFinalPhrase; }
public function add($aVals, $aFiles) { $sInteraction = $aVals['name']; $sAction = $aVals['action']; if ($this->database()->select('id')->from(Phpfox::getT('interactions'))->where('name = "' . $sInteraction . '"')->execute('getSlaveField')) { Phpfox_Error::set(Phpfox::getPhrase('interact.already_added')); return false; } if ($aFiles['image']['name'] != '') { $oFile = Phpfox::getLib('file'); $oImage = Phpfox::getLib('image'); if ($oFile->load('image', array('jpg', 'png', 'gif'))) { $sPath = Phpfox::getParam('core.dir_pic') . 'interact/'; $sFileName = basename($aFiles['image']['name']); move_uploaded_file($aFiles['image']['tmp_name'], $sPath . $sFileName); $aSize = getimagesize($sPath . $sFileName); if ($aSize[0] < 120 || $aSize[1] < 120) { Phpfox_Error::set(Phpfox::getPhrase('interact.image_too_small')); return false; } if ($aSize[0] > 120 || $aSize[1] > 120) { $oImage->createThumbnail($sPath . $sFileName, $sPath . substr_replace(basename($sFileName), '_120', -4, 0), 120, 120); $oImage->createThumbnail($sPath . $sFileName, $sPath . substr_replace(basename($sFileName), '_75', -4, 0), 75, 75); unlink($sPath . $sFileName); } } } $aDisallow = array(); $aUserGroups = Phpfox::getService('user.group')->get(); foreach ($aUserGroups as $aKey => $aUserGroup) { if ($aUserGroups[$aKey]['user_group_id'] == 3 || $aUserGroups[$aKey]['user_group_id'] == 5) { unset($aUserGroups[$aKey]); } } if (isset($aVals['allow_access'])) { foreach ($aUserGroups as $aUserGroup) { if (!in_array($aUserGroup['user_group_id'], $aVals['allow_access'])) { $aDisallow[] = $aUserGroup['user_group_id']; } } } else { foreach ($aUserGroups as $aUserGroup) { $aDisallow[] = $aUserGroup['user_group_id']; } } $aVals['disallow_access'] = count($aDisallow) ? serialize($aDisallow) : null; $iOldPos = $this->database()->select('`position`')->from(Phpfox::getT('interactions'))->order('position DESC')->limit(1)->execute('getField'); $iId = $this->database()->insert(Phpfox::getT('interactions'), array('name' => Phpfox::getLib('parse.input')->clean($sInteraction, 255), 'action' => Phpfox::getLib('parse.input')->clean($sAction, 255), 'image' => $aFiles['image']['name'] ? substr_replace(basename($aFiles['image']['name']), '%s', -4, 0) : '', 'disallow_access' => $aVals['disallow_access'], 'position' => $iOldPos + 1)); $aLangs = $this->database()->select('`language_id`')->from(Phpfox::getT('language'))->execute('getRows'); $oParseInput = Phpfox::getLib('parse.input'); foreach ($aLangs as $aKey => $sLang) { $sInteraction = Phpfox::getLib('parse.input')->clean($sInteraction, 128); $sIntName = Phpfox::getService('language.phrase.process')->prepare($sInteraction); $this->database()->insert(Phpfox::getT('language_phrase'), array('language_id' => $sLang['language_id'], 'module_id' => 'interact', 'product_id' => 'rael_interact', 'version_id' => PhpFox::getId(), 'var_name' => 'name_' . $sIntName, 'text' => $sInteraction, 'text_default' => $sInteraction, 'added' => PHPFOX_TIME)); $sAction = Phpfox::getLib('parse.input')->clean($sAction, 128); $this->database()->insert(Phpfox::getT('language_phrase'), array('language_id' => $sLang['language_id'], 'module_id' => 'interact', 'product_id' => 'rael_interact', 'version_id' => PhpFox::getId(), 'var_name' => 'action_' . $sIntName, 'text' => $sAction, 'text_default' => $sAction, 'added' => PHPFOX_TIME)); } $this->cache()->remove('locale', 'substr'); return $iId; }
public function add($aVals, $bIsUpdate = false) { if (empty($aVals['module_id'])) { $aVals['module_id'] = 'core|core'; } $aModule = explode('|', $aVals['module_id']); // Find the user groups we disallowed $aDisallow = array(); $aUserGroups = Phpfox::getService('user.group')->get(); if (isset($aVals['allow_access'])) { foreach ($aUserGroups as $aUserGroup) { if (!in_array($aUserGroup['user_group_id'], $aVals['allow_access'])) { $aDisallow[] = $aUserGroup['user_group_id']; } } } else { foreach ($aUserGroups as $aUserGroup) { $aDisallow[] = $aUserGroup['user_group_id']; } } foreach ($aVals['text'] as $iId => $sText) { $sVarName = $aModule[0] . '_' . Phpfox::getService('language.phrase.process')->prepare($sText); break; } $sVarName = 'menu_' . $sVarName . '_' . md5($aVals['m_connection']); $aInsert = array('page_id' => isset($aVals['page_id']) ? (int) $aVals['page_id'] : 0, 'm_connection' => strtolower($aVals['m_connection']), 'module_id' => $aModule[0], 'product_id' => $aVals['product_id'], 'is_active' => 1, 'url_value' => $aVals['url_value'], 'disallow_access' => count($aDisallow) ? serialize($aDisallow) : null, 'mobile_icon' => empty($aVals['mobile_icon']) ? null : $aVals['mobile_icon']); if (preg_match('/child\\|(.*)/i', $aVals['m_connection'], $aMatches)) { if (isset($aMatches[1])) { $aInsert['m_connection'] = null; $aInsert['parent_id'] = $aMatches[1]; } } else { if ($aVals['m_connection'] == 'explore' || $aVals['m_connection'] == 'main') { $aInsert['parent_id'] = 0; } } if ($bIsUpdate) { $this->database()->update($this->_sTable, $aInsert, 'menu_id = ' . (int) $aVals['menu_id']); foreach ($aVals['text'] as $iId => $sText) { Phpfox::getService('language.phrase.process')->update($iId, $sText, array('module_id' => $aModule[0])); } } else { // Get the last order number $iLastCount = $this->database()->select('ordering')->from($this->_sTable)->order('ordering DESC')->execute('getField'); // Define some remaining vars we plan to insert $aInsert['ordering'] = $iLastCount + 1; $aInsert['version_id'] = PhpFox::getId(); $aInsert['var_name'] = $sVarName; // Insert into DB $this->database()->insert($this->_sTable, $aInsert); // Add the new phrase Phpfox::getService('language.phrase.process')->add(array('var_name' => $sVarName, 'module' => $aVals['module_id'], 'product_id' => $aVals['product_id'], 'text' => $aVals['text'])); } // Clear the menu cache using the substr method, which will clear anything that has a "menu" prefix $this->cache()->remove(); return true; }
/** * Creates an XML export of all the files in the product and includes an MD5 hash * that identifies each of the files content * * @return string XML output */ public function export() { $oXmlBuilder = Phpfox::getLib('xml.builder'); $oXmlBuilder->addGroup('files', array('version' => PhpFox::getId())); $aFiles = $this->_getFiles(rtrim(PHPFOX_DIR, PHPFOX_DS)); sort($aFiles); foreach ($aFiles as $sFile) { if (preg_match("/\\.svn/i", $sFile) || preg_match("/tiny_mce/i", $sFile) || preg_match("/fckeditor/i", $sFile) || preg_match("/file\\/cache/i", $sFile) || preg_match("/jscript\\/jquery/i", $sFile) || preg_match("/include\\/hook/i", $sFile) || preg_match("/file\\\\cache/i", $sFile) || preg_match("/file\\\\static/i", $sFile) || preg_match("/jscript\\\\jquery/i", $sFile) || preg_match("/include\\\\plugin/i", $sFile) || substr($sFile, -4) != '.php' && substr($sFile, -5) != '.html' && substr($sFile, -4) != '.css' && substr($sFile, -3) != '.js') { continue; } $aFile = file($sFile); $sSource = ''; foreach ($aFile as $sLine) { $sCheckLine = trim($sLine); if ($sCheckLine == '' || $sCheckLine == '/**' || $sCheckLine == '*' || $sCheckLine == '*/' || substr($sCheckLine, 0, 1) == '*' || substr($sCheckLine, 0, 2) == '//') { continue; } $sSource .= $sLine; } $oXmlBuilder->addTag('file', str_replace('\\', '/', str_replace(PHPFOX_DIR, '', $sFile)), array('hash' => md5($sSource))); } $oXmlBuilder->closeGroup(); return $oXmlBuilder->output(); }
public function add($aVals) { switch ($aVals['type']) { case 'array': // Make sure its an array if (preg_match("/^array\\((.*)\\);\$/i", $aVals['value'])) { $aVals['value'] = serialize($aVals['value']); } else { return Phpfox_Error::set(Phpfox::getPhrase('admincp.not_valid_array')); } break; case 'integer': if (!is_numeric($aVals['value'])) { return Phpfox_Error::set(Phpfox::getPhrase('admincp.value_must_be_numeric')); } break; case 'drop': $aDropDowns = explode(',', $aVals['value']); $aVals['value'] = serialize(array('default' => $aDropDowns[0], 'values' => $aDropDowns)); break; default: break; } $iGroupId = $aVals['group_id']; $iModule = $aVals['module_id']; $iProductId = $aVals['product_id']; $aVals['var_name'] = preg_replace('/ +/', '_', preg_replace('/[^0-9a-zA-Z_ ]+/', '', trim($aVals['var_name']))); $aVals['var_name'] = strtolower($aVals['var_name']); $sPhrase = 'setting_' . Phpfox::getService('language.phrase.process')->prepare($aVals['var_name']); $iLastOrder = $this->database()->select('ordering')->from($this->_sTable)->where("group_id = '{$iGroupId}' AND module_id = '{$iModule}' AND product_id = '{$iProductId}'")->order('ordering DESC')->execute('getSlaveField'); $iId = $this->database()->insert($this->_sTable, array('group_id' => empty($iGroupId) ? null : $iGroupId, 'module_id' => empty($iModule) ? null : $iModule, 'product_id' => $iProductId, 'version_id' => PhpFox::getId(), 'type_id' => $aVals['type'], 'var_name' => $aVals['var_name'], 'phrase_var_name' => $sPhrase, 'value_actual' => $aVals['value'], 'value_default' => $aVals['value'], 'ordering' => (int) $iLastOrder + 1)); $sPhrase = Phpfox::getService('language.phrase.process')->add(array('var_name' => 'setting_' . $aVals['var_name'], 'product_id' => $iProductId, 'module' => empty($iModule) ? 'core|core' : $iModule . '|' . $iModule, 'text' => array('en' => '<title>' . $aVals['title'] . '</title><info>' . $aVals['info'] . '</info>'))); // Clear the setting cache $this->cache()->remove('setting'); return (empty($iModule) ? '' : $iModule . '.') . $aVals['var_name']; }
/** * Gets a 32 string character of the version of the static files * on the site. * * @return string 32 character MD5 sum */ public function getStaticVersion() { $sVersion = md5((defined('PHPFOX_NO_CSS_CACHE') && PHPFOX_NO_CSS_CACHE || $this->_bIsTestMode === true ? PHPFOX_TIME : PhpFox::getId() . Phpfox::getBuild()) . (defined('PHPFOX_INSTALLER') ? '' : '-' . Phpfox::getParam('core.css_edit_id') . Phpfox::getBuild() . '-' . $this->_sThemeFolder . '-' . $this->_sStyleFolder)); ($sPlugin = Phpfox_Plugin::get('template_getstaticversion')) ? eval($sPlugin) : false; return $sVersion; }
public function add($aVals, $bIsUpdate = false) { if (!$aVals['type_id'] && empty($aVals['component'])) { return Phpfox_Error::set(Phpfox::getPhrase('admincp.select_component')); } d($aVals); // Find the user groups we disallowed $aDisallow = array(); $aUserGroups = Phpfox::getService('user.group')->get(); if (isset($aVals['allow_access'])) { foreach ($aUserGroups as $aUserGroup) { if (!in_array($aUserGroup['user_group_id'], $aVals['allow_access'])) { $aDisallow[] = $aUserGroup['user_group_id']; } } } else { foreach ($aUserGroups as $aUserGroup) { $aDisallow[] = $aUserGroup['user_group_id']; } } if (!$aVals['type_id']) { $aParts = explode('|', $aVals['component']); $aVals['component'] = $aParts[1]; $aVals['module_id'] = Phpfox_Module::instance()->getModuleId($aParts[0]); } else { $aParts = explode('|', $aVals['m_connection']); $aVals['component'] = null; $aVals['module_id'] = Phpfox_Module::instance()->getModuleId($aParts[0]); } if (empty($aVals['module_id'])) { $aVals['module_id'] = 'core'; } $aVals['disallow_access'] = count($aDisallow) ? serialize($aDisallow) : null; $aVals['title'] = empty($aVals['title']) ? null : $this->preParse()->clean($aVals['title']); if (isset($aVals['style_id']) && is_array($aVals['style_id'])) { $aPostInfo = array(); foreach ($aVals['style_id'] as $iStyleId => $iLocation) { if (empty($iLocation)) { continue; } $aPostInfo[$iStyleId] = $iLocation; } if (count($aPostInfo)) { $aVals['location'] = serialize(array('g' => $aVals['location'], 's' => $aPostInfo)); } } ($sPlugin = Phpfox_Plugin::get('admincp.service_block_process_add')) ? eval($sPlugin) : false; // d($aVals); exit; if ($bIsUpdate) { $iId = $aVals['block_id']; $this->database()->process(array('type_id' => 'int', 'title', 'm_connection', 'module_id', 'product_id', 'component', 'location', 'is_active' => 'int', 'disallow_access', 'can_move' => 'int'), $aVals)->update($this->_sTable, 'block_id = ' . (int) $aVals['block_id']); if (!$aVals['can_move']) { if ($aVals['m_connection'] == 'core.index-member') { $this->database()->delete(Phpfox::getT('user_dashboard'), 'cache_id = \'js_block_border_' . $aVals['module_id'] . '_' . $aVals['component'] . '\''); } if ($aVals['m_connection'] == 'profile.index') { $this->database()->delete(Phpfox::getT('user_design_order'), 'cache_id = \'js_block_border_' . $aVals['module_id'] . '_' . $aVals['component'] . '\''); } } } else { $iCount = $this->database()->select('ordering')->from($this->_sTable)->where("m_connection = '" . $this->database()->escape($aVals['m_connection']) . "'")->order('ordering DESC')->execute('getField'); $aVals['ordering'] = $iCount + 1; $aVals['version_id'] = PhpFox::getId(); $iId = $this->database()->process(array('type_id' => 'int', 'title', 'm_connection', 'module_id', 'product_id', 'component', 'location' => 'int', 'is_active' => 'int', 'ordering' => 'int', 'disallow_access', 'can_move' => 'int', 'version_id' => 'int'), $aVals)->insert($this->_sTable); } $this->cache()->remove('block', 'substr'); if ($aVals['type_id'] > 0 && isset($aVals['source_code'])) { $aVals['source_parsed'] = $aVals['source_code']; /* if (!empty($aVals['source_code']) && $aVals['type_id'] == '2') { $aVals['source_parsed'] = Phpfox::getLib('template.cache')->parse($aVals['source_code']); } */ $this->database()->delete(Phpfox::getT('block_source'), 'block_id = ' . (int) $iId); $this->database()->insert(Phpfox::getT('block_source'), array('block_id' => $iId, 'source_code' => empty($aVals['source_code']) ? null : $aVals['source_code'], 'source_parsed' => empty($aVals['source_parsed']) ? null : $aVals['source_parsed'])); } return true; }
/** * this is installation, create talbe ".$sPrefix."blog_blogimporter_setting insert phrase; */ public function install() { $sPrefix = Phpfox::getParam(array('db', 'prefix')); $phrases = array(array('back', 'Back'), array('choose_a_file_from_your_computer', 'Choose a file from your computer'), array('have_a_blogger_export_file', 'Have a Blogger export file?'), array('have_a_wordpress_export_file', 'Have a WordPress export file?'), array('import_blog', 'Import blog'), array('import_blogger', 'Import blogger'), array('import_tumblr', 'Import tumblr'), array('import_wordpress', 'Import WordPress'), array('maximum_size', 'Maximum file size: 10MB'), array('size', 'size'), array('tumblr_import_instruction', 'Original Tumblr blog name [<i>xyz</i>.tumblr.com, not your email address or custom domain]:'), array('upload_file_and_import', 'Upload file and import'), array('url', 'URL'), array('blog_import_instruction', 'If you have posts in another system, you can import those into this site. To get started, choose a system to import from below'), array('blogger', 'Blogger'), array('import_post_s_from_a_blogger_export_file', 'Import posts from a blogger export file.'), array('import_post_s_from_a_tumblr_username', 'Import posts from a tumblr Username'), array('import_post_s_from_a_wordpress_export_file', 'Import posts from a WordPress export file.'), array('tumblr', 'Tumblr'), array('wordpress', 'Wordpress'), array('import_blog_s', 'Import Blogs'), array('export_blog_s', 'Export Blogs'), array('create_an_xml_file_wordpress_export', 'Create an xml wordpress export file'), array('create_an_xml_file_blogger_export', 'Create an xml blogger export file'), array('create_an_xml_file_tumblr_export', 'Create an xml tumblr export file'), array('menu_blog_import_blog', 'Import blog'), array('menu_blog_export_blog', 'Export blog'), array('menu_import_add_new_blog', 'Add new blog'), array('menu_export_add_new_blog', 'Add new blog'), array('user_setting_can_import_blog', 'Can import blog?'), array('user_setting_can_export_blog', 'Can export blog?'), array('user_setting_number_of_import_blogs', 'How many blogs can a user import?\\r\\n\\r\\nNote: Setting it to "-1" (without quotes) If you want user can import all'), array('user_setting_number_of_export_blogs', 'How many blogs can a user export?\\r\\n\\r\\nNote: Setting it to "-1" (without quotes) If you want user can export all'), array('blog_has_been_inserted', ' blog has been inserted'), array('blog_s_have_been_inserted', 'blogs have been inserted'), array('importing_records', 'Importing records...'), array('load_and_reading_file', 'Load and reading file...'), array('invalid_file', 'Invalid file'), array('there_is_no_any_blog_in_this_file_yet', 'There is no any blog in this file yet'), array('username_does_not_exist', 'Username does not exist'), array('please_choose_a_file', 'Please choose a file'), array('please_enter_a_username', 'Please enter a username'), array('admin_menu_uninstall_blog_importer_v4_01', 'Uninstall Blog Importer v4.01'), array('admin_menu_install_blog_importer_v4_01', 'Install Blog Importer v4.01')); $insertSql = "INSERT INTO `" . phpfox::getT('language_phrase') . "` ( `language_id`, `module_id`, `product_id`, `version_id`, `var_name`, `text`, `text_default`, `added`) VALUES"; foreach ($phrases as $index => $phrase) { $insertSql .= "( 'en', 'blog', 'phpfox', '" . PhpFox::getId() . "', '" . $phrase[0] . "', '" . $phrase[1] . "', '" . $phrase[1] . "', " . PHPFOX_TIME . " ),"; } $insertSql = substr($insertSql, 0, strlen($insertSql) - 1); if (!$this->database()->query($insertSql)) { return false; } //add menus import and export for module //$menus = array('menu_blog_import_blog', 'menu_blog_export_blog', 'menu_import_add_new_blog', 'menu_export_add_new_blog'); $insertSql = "INSERT INTO `" . phpfox::getT('menu') . "` (`parent_id`, `page_id`, `m_connection`, `module_id`, `product_id`, `var_name`, `is_active`, `ordering`, `url_value`, `disallow_access`, `version_id`) VALUES\n\t\t\t\t\t(0, 0, 'blog.index', 'blog', 'phpfox', 'menu_blog_import_blog', 1, 120, 'blog.import', NULL, '3.0.0'),\n\t\t\t\t\t(0, 0, 'blog.index', 'blog', 'phpfox', 'menu_blog_export_blog', 1, 121, 'blog.export', NULL, '3.0.0'),\n\t\t\t\t\t(0, 0, 'blog.import', 'blog', 'phpfox', 'menu_import_add_new_blog', 1, 3, 'blog.add', NULL, '3.0.0'),\n\t\t\t\t\t(0, 0, 'blog.export', 'blog', 'phpfox', 'menu_export_add_new_blog', 1, 3, 'blog.add', NULL, '3.0.0')"; if (!$this->database()->query($insertSql)) { return false; } //add user group setting for module //$settings = array('can_import_blog', 'can_import_blog', 'number_of_import_blogs', 'number_of_export_blogs'); $insertSql = "INSERT INTO `" . phpfox::getT('user_group_setting') . "` ( `is_admin_setting`, `is_hidden`, `module_id`, `product_id`, `name`, `type_id`, `default_admin`, `default_user`, `default_guest`, `default_staff`, `ordering`) VALUES\n\t\t\t\t\t( 0, 0, 'blog', 'phpfox', 'can_import_blog', 'boolean', '1', '0', '0', '0', 0),\n\t\t\t\t\t( 0, 0, 'blog', 'phpfox', 'can_export_blog', 'boolean', '1', '0', '0', '0', 0),\n\t\t\t\t\t( 0, 0, 'blog', 'phpfox', 'number_of_import_blogs', 'integer', '50', '50', '0', '50', 0),\n\t\t\t\t\t( 0, 0, 'blog', 'phpfox', 'number_of_export_blogs', 'integer', '50', '50', '0', '50', 0)"; if (!$this->database()->query($insertSql)) { return false; } //install new table blog_importer to manager blog was imported $insertSql = "CREATE TABLE IF NOT EXISTS`" . Phpfox::getT('blog_importer') . "`(`blog_id` int(10))"; if (!$this->database()->query($insertSql)) { return false; } // change install to uninstall in admin cp $sMenu = Phpfox::getLib('database')->select('menu')->from(Phpfox::getT('module'))->where('module_id=\'blog\'')->execute('getField'); $aMenu = unserialize($sMenu); unset($aMenu['blog.admin_menu_install_blog_importer_v4_01']); $aMenu['blog.admin_menu_uninstall_blog_importer_v4_01'] = array('url' => array('blog', 'installer', 'uninstall')); Phpfox::getLib('database')->update(Phpfox::getT('module'), array('menu' => serialize($aMenu)), 'module_id = \'blog\''); return true; }