/** * upgrade the blocks module * * @param string $oldversion version being upgraded * * @return bool true if successful, false otherwise */ public function upgrade($oldversion) { // Upgrade dependent on old version number switch ($oldversion) { case '3.8.1': HookUtil::registerSubscriberBundles($this->version->getHookSubscriberBundles()); case '3.8.2': case '3.9.0': $blocks = $this->entityManager->getRepository('ZikulaBlocksModule:BlockEntity')->findAll(); /** @var \Zikula\Module\BlocksModule\Entity\BlockEntity $block */ foreach ($blocks as $block) { $content = $block->getContent(); if (\DataUtil::is_serialized($content)) { $content = unserialize($content); foreach ($content as $k => $item) { if (is_string($item)) { if (strpos($item, 'blocks_block_extmenu_topnav.tpl') !== false) { $content[$k] = str_replace('blocks_block_extmenu_topnav.tpl', 'Block/Extmenu/topnav.tpl', $item); } elseif (strpos($item, 'blocks_block_extmenu.tpl') !== false) { $content[$k] = str_replace('blocks_block_extmenu.tpl', 'Block/Extmenu/extmenu.tpl', $item); } elseif (strpos($item, 'menutree/blocks_block_menutree_') !== false) { $content[$k] = str_replace('menutree/blocks_block_menutree_', 'Block/Menutree/', $item); } } } $block->setContent(serialize($content)); } } $this->entityManager->flush(); // check if request is available (#2073) $templateWarning = $this->__('Warning: Block template locations modified, you may need to fix your template overrides if you have any.'); if (is_object($this->request) && method_exists($this->request, 'getSession') && is_object($this->request->getSession())) { $this->request->getSession()->getFlashBag()->add(\Zikula_Session::MESSAGE_WARNING, $templateWarning); } else { \LogUtil::registerWarning($templateWarning); } case '3.9.1': // future upgrade routines } // Update successful return true; }
if (!$f) { header('HTTP/1.0 404 Not Found'); exit; } // clean $f $f = preg_replace('`/`', '', $f); // set full path to the file $f = $ZConfig['System']['temp'] . '/Theme_cache/' . $f; if (!is_readable($f)) { header('HTTP/1.0 400 Bad request'); die('ERROR: Requested file not readable.'); } // child lock $signingKey = md5(serialize($ZConfig['DBInfo']['databases']['default'])); $contents = file_get_contents($f); if (!DataUtil::is_serialized($contents, false)) { header('HTTP/1.0 500 Internal error'); die('ERROR: Corrupted file.'); } $dataArray = unserialize($contents); if (!isset($dataArray['contents']) || !isset($dataArray['ctype']) || !isset($dataArray['lifetime']) || !isset($dataArray['gz']) || !isset($dataArray['signature'])) { header('HTTP/1.0 500 Interal error'); die('ERROR: Invalid data.'); } // check signature if (md5($dataArray['contents'] . $dataArray['ctype'] . $dataArray['lifetime'] . $dataArray['gz'] . $signingKey) != $dataArray['signature']) { header('HTTP/1.0 500 Interal error'); die('ERROR: File has been altered.'); } // gz handlers if requested if ($dataArray['gz']) {
/** * Extract an array of config variables out of the content field of a block. * * @param string $content The content from the db. * * @return array */ public static function varsFromContent($content) { // Try to unserialize first if (DataUtil::is_serialized($content, false)) { // Serialised content $vars = unserialize($content); if ($vars !== false && is_array($vars)) { return $vars; } } // Unserialised content $links = explode("\n", $content); $vars = array(); foreach ($links as $link) { $link = trim($link); if ($link) { $var = explode(':=', $link); if (isset($var[1])) { $vars[$var[0]] = $var[1]; } } } return $vars; }
/** * Smarty function to display an editable dynamic user data field. * * Example * {duditemdisplay propattribute='avatar'} * * Example * {duditemdisplay propattribute='realname' uid=$uid} * * Example * {duditemdisplay item=$item} * * Parameters passed in the $params array: * --------------------------------------- * string item The Profile DUD item. * string userinfo The userinfo information [if not set uid must be specified]. * string uid User ID to display the field value for (-1 = do not load). * string proplabel Property label to display (optional overrides the preformated dud item $item). * string propattribute Property attribute to display. * string default Default content for an empty DUD. * boolean showlabel Show the label? default = true. * * @param array $params All attributes passed to this function from the template. * @param object &$smarty Reference to the Zikula_View/Smarty object. * * @return string|boolean The results of the module function; empty string if the Profile module is not available; false if error. */ function smarty_function_duditemdisplay($params, &$smarty) { extract($params); unset($params); if (!ModUtil::available('Profile')) { return ''; } if (!isset($item)) { if (isset($proplabel)) { $item = ModUtil::apiFunc('Profile', 'user', 'get', array('proplabel' => $proplabel)); } else if (isset($propattribute)) { $item = ModUtil::apiFunc('Profile', 'user', 'get', array('propattribute' => $propattribute)); } else { return false; } } if (!isset($item) || empty ($item)) { return false; } $dom = ZLanguage::getModuleDomain('Profile'); // check for a template set if (!isset($tplset)) { $tplset = 'profile_duddisplay'; } // a default value if the user data is empty if (!isset($default)) { $default = ''; } if (!isset($uid)) { $uid = UserUtil::getVar('uid'); } if (!isset($userinfo)) { $userinfo = UserUtil::getVars($uid); } // get the value of this field from the userinfo array if (isset($userinfo['__ATTRIBUTES__'][$item['prop_attribute_name']])) { $uservalue = $userinfo['__ATTRIBUTES__'][$item['prop_attribute_name']]; } elseif (isset($userinfo[$item['prop_attribute_name']])) { // user's temp view for non-approved users needs this $uservalue = $userinfo[$item['prop_attribute_name']]; } else { // can be a non-marked checkbox in the user temp data $uservalue = ''; } // try to get the DUD output if it's Third Party if ($item['prop_dtype'] != 1) { $output = ModUtil::apiFunc($item['prop_modname'], 'dud', 'edit', array('item' => $item, 'userinfo' => $userinfo, 'uservalue' => $uservalue, 'default' => $default)); if ($output) { return $output; } } // build the output $output = ''; $render = Zikula_View::getInstance('Profile', false, null, true); $render->assign('item', $item); $render->assign('userinfo', $userinfo); $render->assign('uservalue', $uservalue); // detects the template to use $template = $tplset.'_'.$item['prop_id'].'.tpl'; if (!$render->template_exists($template)) { $template = $tplset.'_generic.tpl'; } $output = ''; // checks the different attributes and types // avatar if ($item['prop_attribute_name'] == 'avatar') { $baseurl = System::getBaseUrl(); $avatarpath = ModUtil::getVar(Users_Constant::MODNAME, Users_Constant::MODVAR_AVATAR_IMAGE_PATH, Users_Constant::DEFAULT_AVATAR_IMAGE_PATH); if (empty($uservalue)) { $uservalue = 'blank.png'; } $output = "<img alt=\"\" src=\"{$baseurl}{$avatarpath}/{$uservalue}\" />"; } elseif ($item['prop_attribute_name'] == 'tzoffset') { // timezone if (empty($uservalue)) { $uservalue = UserUtil::getVar('tzoffset') ? UserUtil::getVar('tzoffset') : System::getVar('timezone_offset'); } $output = DateUtil::getTimezoneText($uservalue); if (!$output) { return ''; } } elseif ($item['prop_displaytype'] == 2) { // checkbox $default = array('No', 'Yes'); $output = array_splice(explode('@@', $item['prop_listoptions']), 1); if (!is_array($output) || count($output) < 2) { $output = $default; } $output = isset($output[(int)$uservalue]) && !empty($output[(int)$uservalue]) ? __($output[(int)$uservalue], $dom) : __($default[(int)$uservalue], $dom); } elseif ($item['prop_displaytype'] == 3) { // radio $options = ModUtil::apiFunc('Profile', 'dud', 'getoptions', array('item' => $item)); // process the user value and get the translated label $output = isset($options[$uservalue]) ? $options[$uservalue] : $default; } elseif ($item['prop_displaytype'] == 4) { // select $options = ModUtil::apiFunc('Profile', 'dud', 'getoptions', array('item' => $item)); // process the user values and get the translated label $uservalue = @unserialize($uservalue); $output = array(); foreach ((array)$uservalue as $id) { if (isset($options[$id])) { $output[] = $options[$id]; } } } elseif (!empty($uservalue) && $item['prop_displaytype'] == 5) { // date $format = ModUtil::apiFunc('Profile', 'dud', 'getoptions', array('item' => $item)); //! This is from the core domain (datebrief) $format = !empty($format) ? $format : __('%b %d, %Y'); $output = DateUtil::getDatetime(strtotime($uservalue), $format); } elseif ($item['prop_displaytype'] == 7) { // multicheckbox $options = ModUtil::apiFunc('Profile', 'dud', 'getoptions', array('item' => $item)); // process the user values and get the translated label $uservalue = @unserialize($uservalue); $output = array(); foreach ((array)$uservalue as $id) { if (isset($options[$id])) { $output[] = $options[$id]; } } } elseif ($item['prop_attribute_name'] == 'url') { // url if (!empty($uservalue) && $uservalue != 'http://') { //! string to describe the user's site $output = '<a href="'.DataUtil::formatForDisplay($uservalue).'" title="'.__f("%s's site", $userinfo['uname'], $dom).'" rel="nofollow">'.DataUtil::formatForDisplay($uservalue).'</a>'; } } elseif (empty($uservalue)) { // process the generics $output = $default; } elseif (DataUtil::is_serialized($uservalue) || is_array($uservalue)) { // serialized data $uservalue = !is_array($uservalue) ? unserialize($uservalue) : $uservalue; $output = array(); foreach ((array)$uservalue as $option) { $output[] = __($option, $dom); } } else { // a string $output .= __($uservalue, $dom); } // omit this field if is empty after the process if (empty($output)) { return ''; } return $render->assign('output', is_array($output) ? $output : array($output)) ->fetch($template); }
public function upgrade($oldversion) { switch ($oldversion) { case '1.0': // no changes made // no changes made case '1.1': // delete old paths $this->delVar('xinha_path'); $this->delVar('tinymce_path'); // set new path $this->setVar('editors_path', 'javascript/scribite_editors'); case '1.2': if (!DBUtil::createTable('scribite')) { return false; } // create the default data for the module scribite_defaultdata(); // del old module vars $this->delVar('editor'); $this->delVar('editor_activemodules'); case '1.21': // create new values $this->setVar('openwysiwyg_barmode', 'full'); $this->setVar('openwysiwyg_width', '400'); $this->setVar('openwysiwyg_height', '300'); $this->setVar('xinha_statusbar', 1); case '1.3': // create new values $this->setVar('openwysiwyg_barmode', 'full'); $this->setVar('openwysiwyg_width', '400'); $this->setVar('openwysiwyg_height', '300'); $this->setVar('xinha_statusbar', 1); case '2.0': // create new values $this->setVar('DefaultEditor', '-'); $this->setVar('nicedit_fullpanel', 1); // fill some vars with defaults if (!$this->getVar('xinha_converturls')) { $this->setVar('xinha_converturls', 1); } if (!$this->getVar('xinha_showloading')) { $this->setVar('xinha_showloading', 1); } if (!$this->getVar('xinha_activeplugins')) { $this->setVar('xinha_activeplugins', 'a:2:{i:0;s:7:"GetHtml";i:1;s:12:"SmartReplace";}'); } if (!$this->getVar('tinymce_activeplugins')) { $this->setVar('tinymce_activeplugins', ''); } if (!$this->getVar('fckeditor_autolang')) { $this->setVar('fckeditor_autolang', 1); } //create new module vars for crpCalendar $item = array('modname' => 'crpCalendar', 'modfuncs' => 'a:2:{i:0;s:3:"new";i:1;s:6:"modify";}', 'modareas' => 'a:1:{i:0;s:22:"crpcalendar_event_text";}', 'modeditor' => '-'); if (!DBUtil::insertObject($item, 'scribite', false, 'mid')) { LogUtil::registerError($this->__('Error! Could not update module configuration.')); return '2.0'; } case '2.1': //create new module vars for Content $record = array(array('modname' => 'content', 'modfuncs' => 'a:1:{i:0;s:5:"dummy";}', 'modareas' => 'a:1:{i:0;s:5:"dummy";}', 'modeditor' => '-')); DBUtil::insertObjectArray($record, 'scribite', 'mid'); case '2.2': //create new module vars for Blocks #14 $record = array(array('modname' => 'Blocks', 'modfuncs' => 'a:1:{i:0;s:6:"modify";}', 'modareas' => 'a:1:{i:0;s:14:"blocks_content";}', 'modeditor' => '-')); DBUtil::insertObjectArray($record, 'scribite', 'mid'); // check for Zikula 1.1.x version if (Zikula_Core::VERSION_NUM < '1.1.0') { LogUtil::registerError($this->__('This version from scribite! only works with Zikula 1.1.x and higher. Please upgrade your Zikula version or use scribite! version 2.x .')); return '2.2'; } // create systeminit hook - new in Zikula 1.1.0 if (!ModUtil::registerHook('zikula', 'systeminit', 'GUI', 'scribite', 'user', 'run')) { LogUtil::registerError($this->__('Error creating Hook!')); return '2.2'; } ModUtil::apiFunc('Modules', 'admin', 'enablehooks', array('callermodname' => 'zikula', 'hookmodname' => 'scribite')); LogUtil::registerStatus($this->__('<strong>scribite!</strong> was activated as core hook. You can check settings <a href="index.php?module=Modules&type=admin&func=hooks&id=0">here</a>!<br />The template plugin from previous versions of scribite! can be removed from templates.')); case '3.0': //create new module vars for Newsletter and Web_Links $record = array(array('modname' => 'Newsletter', 'modfuncs' => 'a:1:{i:0;s:11:"add_message";}', 'modareas' => 'a:1:{i:0;s:7:"message";}', 'modeditor' => '-'), array('modname' => 'crpVideo', 'modfuncs' => 'a:2:{i:0;s:3:"new";i:1;s:6:"modify";}', 'modareas' => 'a:1:{i:0;s:13:"video_content";}', 'modeditor' => '-'), array('modname' => 'Web_Links', 'modfuncs' => 'a:3:{i:0;s:8:"linkview";i:1;s:7:"addlink";i:2;s:17:"modifylinkrequest";}', 'modareas' => 'a:1:{i:0;s:11:"description";}', 'modeditor' => '-')); DBUtil::insertObjectArray($record, 'scribite', 'mid'); // set vars for YUI Rich Text Editor if (!$this->getVar('yui_type')) { $this->setVar('yui_type', 'Simple'); } if (!$this->getVar('yui_width')) { $this->setVar('yui_width', 'auto'); } if (!$this->getVar('yui_height')) { $this->setVar('yui_height', '300'); } if (!$this->getVar('yui_dombar')) { $this->setVar('yui_dombar', true); } if (!$this->getVar('yui_animate')) { $this->setVar('yui_animate', true); } if (!$this->getVar('yui_collapse')) { $this->setVar('yui_collapse', true); } case '3.1': // modify Profile module $originalconfig = ModUtil::apiFunc('Scribite', 'user', 'getModuleConfig', array('modulename' => "Profile")); $newconfig = array('mid' => $originalconfig['mid'], 'modulename' => 'Profile', 'modfuncs' => "modify", 'modareas' => "prop_signature,prop_extrainfo,prop_yinterests", 'modeditor' => $originalconfig['modeditor']); $modupdate = ModUtil::apiFunc('Scribite', 'admin', 'editmodule', $newconfig); case '3.2': // set new editors folder $this->setVar('editors_path', 'modules/scribite/pnincludes'); LogUtil::registerStatus($this->__('<strong>Caution!</strong><br />All editors have moved to /modules/scribite/pnincludes in preparation for upcoming features of Zikula. Please check all your settings!<br />If you have adapted files from editors you have to check them too.<br /><br /><strong>Dropped support for FCKeditor and TinyMCE</strong><br />For security reasons these editors will not be supported anymore. Please change editors to an other editor.')); case '4.0': case '4.1': case '4.2': $this->setVar('nicedit_xhtml', 1); case '4.2.1': if (!$this->getVar('ckeditor_language')) { $this->setVar('ckeditor_language', 'en'); } if (!$this->getVar('ckeditor_barmode')) { $this->setVar('ckeditor_barmode', 'Full'); } if (!$this->getVar('ckeditor_width')) { $this->setVar('ckeditor_width', '"70%"'); } if (!$this->getVar('ckeditor_height')) { $this->setVar('ckeditor_height', '400'); } case '4.2.2': // this renames the table and the columns per new z1.3.0 standards $this->renameColumns(); EventUtil::registerPersistentModuleHandler('Scribite', 'core.postinit', array('Scribite_Listeners', 'coreinit')); $this->setVar('editors_path', 'modules/Scribite/includes'); LogUtil::registerStatus($this->__('<strong>Caution!</strong><br />All editors have moved to /modules/Scribite/includes.<br />If you have adapted files from editors you have to check them too.')); case '4.2.3': //set vars for markitup if (!$this->getVar('markitup_width')) { $this->setVar('markitup_width', '650px'); } if (!$this->getVar('markitup_height')) { $this->setVar('markitup_height', '400px'); } // remove fckeditor (was deprecated in 4.1) $this->delVar('fckeditor_language'); $this->delVar('fckeditor_barmode'); $this->delVar('fckeditor_width'); $this->delVar('fckeditor_height'); $this->delVar('fckeditor_autolang'); // update module assignments to correct removed and deprecated editors $dbtable = DBUtil::getTables(); $columns = $dbtable['scribite_column']; $sql = "UPDATE `{$dbtable['scribite']}` SET `{$columns['modeditor']}`='-' WHERE `{$columns['modeditor']}`='fckeditor' OR `{$columns['modeditor']}`='tinymce' OR `{$columns['modeditor']}`='openwysiwyg'"; DBUtil::executeSQL($sql); // reset modules $this->resetModuleConfig('News'); $this->resetModuleConfig('Pages'); $this->resetModuleConfig('ContentExpress'); $this->resetModuleConfig('Mediashare'); // correct possible serialized data corruption if (!DataUtil::is_serialized($this->getVar('xinha_activeplugins'))) { $this->delVar('xinha_activeplugins'); } // relocate xinha styles $this->setVar('xinha_style', 'modules/Scribite/style/xinha/editor.css'); // remove content settings DBUtil::deleteObjectById('scribite', 'content', 'modname'); case '4.3.0': /* reimplement TinyMCE */ // future updates // notice - remove openwysiwyg vars @>4.3.0 } return true; }
/** * Migrate from version 1.13 to 2.2.0 * * @param string $oldversion The old version from which this upgrade is being processed. * * @return bool True on success; otherwise false. */ public function upgrade113XTablesTo220Tables($oldversion) { if (!DBUtil::changeTable('users_temp')) { return false; } // Get the dbinfo for the new version ModUtil::dbInfoLoad('Users', 'Users'); $nowUTC = new DateTime(null, new DateTimeZone('UTC')); $nowUTCStr = $nowUTC->format(Users_Constant::DATETIME_FORMAT); $serviceManager = ServiceUtil::getManager(); $dbinfoSystem = $serviceManager['dbtables']; $dbinfo113X = Users_tables('1.13'); $dbinfo220 = Users_tables('2.2.0'); $usersOldFields = array( 'user_theme', 'user_viewemail', 'storynum', 'counter', 'hash_method', 'validfrom', 'validuntil', ); $usersOldFieldsDB = array( $dbinfo113X['users_column']['user_theme'], $dbinfo113X['users_column']['user_viewemail'], $dbinfo113X['users_column']['storynum'], $dbinfo113X['users_column']['counter'], $dbinfo113X['users_column']['hash_method'], $dbinfo113X['users_column']['validfrom'], $dbinfo113X['users_column']['validuntil'] ); // Upgrade the tables // Update the users table with new and altered fields. No fields are removed at this point, and no fields // are getting a new data type that is incompatible, so no need to save anything off first. // Also, create the users_verifychg tables at this point. // Merge the global dbtables with the new field information. $tables['users_column'] = $dbinfo220['users_column']; $tables['users_column_def'] = $dbinfo220['users_column_def']; $tables['users_verifychg'] = $dbinfo220['users_verifychg']; $tables['users_verifychg_column'] = $dbinfo220['users_verifychg_column']; $tables['users_verifychg_column_def'] = $dbinfo220['users_verifychg_column_def']; $serviceManager['dbtables'] = array_merge($dbinfoSystem, $tables); // Now change the tables if (!DBUtil::changeTable('users')) { return false; } if (!DBUtil::createTable('users_verifychg')) { return false; } // First users_temp pending email verification records to users_verifychg. $tempColumn = $dbinfo113X['users_temp_column']; $verifyColumn = $dbinfo220['users_verifychg_column']; $usersColumn = $dbinfo220['users_column']; $legalModInfo = ModUtil::getInfoFromName('Legal'); if (($legalModInfo['state'] == ModUtil::STATE_ACTIVE) || ($legalModInfo['state'] == ModUtil::STATE_UPGRADED)) { $legalModuleActive = true; $termsOfUseActive = ModUtil::getVar('Legal', 'termsofuse', false); $privacyPolicyActive = ModUtil::getVar('Legal', 'privacypolicy', false); $agePolicyActive = ($this->getVar('minage', 0) > 0); } else { $legalModuleActive = false; } // Next, users table conversion // We need to convert some information over from the old users table fields, so merge the old field list into // the new one. The order of array_merge parameters is important here! $tables = array('users_column' => array_merge($dbinfo113X['users_column'], $dbinfo220['users_column'])); $serviceManager['dbtables'] = array_merge($dbinfoSystem, $tables); // Do the conversion in PHP we use mb_strtolower, and even if MySQL had an equivalent, there is // no guarantee that another supported DB platform would. $limitNumRows = 100; $limitOffset = 0; $updated = true; $userCount = DBUtil::selectObjectCount('users'); while ($limitOffset < $userCount) { $userArray = DBUtil::selectObjectArray('users', "{$usersColumn['uid']} != 1", '', $limitOffset, $limitNumRows, '', null, null, array('uid', 'uname', 'email', 'pass', 'hash_method', 'user_regdate', 'lastlogin', 'approved_by', 'approved_date')); if (!empty($userArray) && is_array($userArray)) { foreach ($userArray as $key => $userObj) { // force user names and emails to lower case $userArray[$key]['uname'] = mb_strtolower($userArray[$key]['uname']); $userArray[$key]['email'] = mb_strtolower($userArray[$key]['email']); if ($userArray[$key]['user_regdate'] == '1970-01-01 00:00:00') { $userArray[$key]['user_regdate'] = $nowUTCStr; $userArray[$key]['approved_date'] = $nowUTCStr; } else { $userArray[$key]['approved_date'] = $userArray[$key]['user_regdate']; } $userArray[$key]['approved_by'] = 2; // merge hash method for salted passwords, leave salt blank if (!empty($userArray[$key]['pass']) && (strpos($userArray[$key]['pass'], '$$') === false)) { $userArray[$key]['pass'] = (isset($userArray[$key]['hash_method']) ? $userArray[$key]['hash_method'] : '1') . '$$' . $userArray[$key]['pass']; } // Save some disappearing fields as attributes, just in case someone actually used them for // something. But don't overwrite if there already if (!isset($userArray[$key]['__ATTRIBUTES__']) || !is_array($userArray[$key]['__ATTRIBUTES__'])) { $userArray[$key]['__ATTRIBUTES__'] = array(); } foreach ($usersOldFields as $fieldName) { if (($fieldName != 'hash_method') && isset($userArray[$key][$fieldName]) && !empty($userArray[$key][$fieldName]) && !isset($userArray[$key]['__ATTRIBUTES__'][$fieldName])) { $userArray[$key]['__ATTRIBUTES__'][$fieldName] = $userArray[$key][$fieldName]; } } if ($legalModuleActive && ($userArray[$key]['uid'] > 2)) { $userRegDateTime = new DateTime($userArray[$key]['user_regdate'], new DateTimeZone('UTC')); $policyDateTimeStr = $userRegDateTime->format(DATE_ISO8601); if ($termsOfUseActive) { $userArray[$key]['__ATTRIBUTES__']['_Legal_termsOfUseAccepted'] = $policyDateTimeStr; } if ($privacyPolicyActive) { $userArray[$key]['__ATTRIBUTES__']['_Legal_privacyPolicyAccepted'] = $policyDateTimeStr; } if ($agePolicyActive) { $userArray[$key]['__ATTRIBUTES__']['_Legal_agePolicyConfirmed'] = $policyDateTimeStr; } } } } if (!DBUtil::updateObjectArray($userArray, 'users', 'uid', false)) { $updated = false; break; } $limitOffset += $limitNumRows; } if (!$updated) { return false; } $obaColumn = $dbinfoSystem['objectdata_attributes_column']; $limitNumRows = 100; $limitOffset = 0; $updated = true; $userCount = DBUtil::selectObjectCount('users_temp'); // Pass through the users_temp table in chunks of 100 // * ensure unames and email addresses are lower case, while ($limitOffset < $userCount) { $userTempArray = DBUtil::selectObjectArray('users_temp', '', '', $limitOffset, $limitNumRows, '', null, null, array('tid', 'type', 'uname', 'email', 'pass', 'hash_method', 'dynamics', 'comment')); $userArray = array(); if (!empty($userTempArray) && is_array($userTempArray)) { foreach ($userTempArray as $key => $userTempOpj) { // type == 1: User registration pending approval (moderation) if ($userTempArray[$key]['type'] == 1) { $userObj = array(); // Ensure uname and email are lower case $userObj['uname'] = mb_strtolower($userTempArray[$key]['uname']); $userObj['email'] = mb_strtolower($userTempArray[$key]['email']); // Convert pass to salted pass with embedded hash method, leave salt blank $userObj['pass'] = $userTempArray[$key]['hash_method'] . '$$' . $userTempArray[$key]['pass']; $userObj['approved_by'] = 0; $userObj['activated'] = Users_Constant::ACTIVATED_PENDING_REG; if (!empty($userTempArray[$key]['dynamics'])) { $userObj['__ATTRIBUTES__'] = unserialize($userTempArray[$key]['dynamics']); } else { $userObj['__ATTRIBUTES__'] = array(); } if (isset($userObj['dynamics']) && !empty($userObj['dynamics'])) { if (DataUtil::is_serialized($userObj['dynamics'])) { $dynamics = @unserialize($userObj['dynamics']); if (!empty($dynamics) && is_array($dynamics)) { foreach ($dynamics as $key => $value) { $userObj['__ATTRIBUTES__'][$key] = $value; } } } } $userObj['__ATTRIBUTES__']['_Users_isVerified'] = 0; if ($legalModuleActive) { $userRegDateTime = new DateTime($userArray[$key]['user_regdate'], new DateTimeZone('UTC')); $policyDateTimeStr = $userRegDateTime->format(DATE_ISO8601); if ($termsOfUseActive) { $userObj['__ATTRIBUTES__']['_Legal_termsOfUseAccepted'] = $policyDateTimeStr; } if ($privacyPolicyActive) { $userObj['__ATTRIBUTES__']['_Legal_privacyPolicyAccepted'] = $policyDateTimeStr; } if ($agePolicyActive) { $userObj['__ATTRIBUTES__']['_Legal_agePolicyConfirmed'] = $policyDateTimeStr; } } $userArray[] = $userObj; } else { throw new Zikula_Exception_Fatal($this->__f('Unknown users_temp record type: %1$s', array($userTempArray[$key]['type']))); } } } if (!DBUtil::insertObjectArray($userArray, 'users', 'uid', false)) { $updated = false; break; } $limitOffset += $limitNumRows; } if (!$updated) { return false; } // Done upgrading. Let's lose some old fields and tables we no longer need. DBUtil::dropColumn('users', $usersOldFieldsDB); DBUtil::dropTable('users_temp'); // Reset the system tables to the new table definitons, so the rest of the // system upgrade goes smoothly. $dbinfoSystem = $serviceManager['dbtables']; foreach ($dbinfo113X as $key => $value) { unset($dbinfoSystem[$key]); } foreach ($dbinfo220 as $key => $value) { $dbinfoSystem[$key] = $value; } $serviceManager['dbtables'] = $dbinfoSystem; // Update users table for data type change of activated field. if (!DBUtil::changeTable('users')) { return false; } return true; }
/** * Smarty function to display an editable dynamic user data field. * * Example * {duditemmodify propattribute='avatar'} * * Example * {duditemmodify propattribute='realname' uid=$uid} * * Example * {duditemmodify item=$item} * * Parameters passed in via the $params array: * ------------------------------------------- * string item The Profile DUD item. * string uid User ID to display the field value for (-1 = do not load). * string class CSS class to assign to the table row/form row div (optional). * string proplabel Property label to display (optional overrides the preformated dud item $item). * string propattribute Property attribute to display. * string error Property error message. * * @param array $params All attributes passed to this function from the template. * @param object &$smarty Reference to the Zikula_View/Smarty object. * * @return string|boolean The results of the module function; empty string if the Profile module is not available; false if error. */ function smarty_function_duditemmodify($params, &$smarty) { extract($params); unset($params); if (!ModUtil::available('Profile')) { return ''; } if (!isset($item)) { if (isset($proplabel)) { $item = ModUtil::apiFunc('Profile', 'user', 'get', array('proplabel' => $proplabel)); } else if (isset($propattribute)) { $item = ModUtil::apiFunc('Profile', 'user', 'get', array('propattribute' => $propattribute)); } else { return false; } } if (!isset($item) || empty ($item)) { return false; } // detect if we are in the registration form $onregistrationform = false; // TODO - will these globals always be available? Is there a utility method out there somewhere to get these? global $module, $func; if (strtolower($module) == 'users' && strtolower($func) == 'register') { $onregistrationform = true; } // skip the field if not configured to be on the registration form if ($onregistrationform && !$item['prop_required']) { $dudregshow = ModUtil::getVar('Profile', 'dudregshow', array()); if (!in_array($item['prop_id'], $dudregshow)) { return ''; } } $dom = ZLanguage::getModuleDomain('Profile'); if (!isset($uid)) { $uid = UserUtil::getVar('uid'); } if (!isset($class) || !is_string($class)) { $class = ''; } if (isset($item['temp_propdata'])) { $uservalue = $item['temp_propdata']; } elseif ($uid >= 0) { // TODO - This is a bit of a hack for admin editing. Need to know if it is a reg. $user = UserUtil::getVars($uid); $isRegistration = UserUtil::isRegistration($uid); $uservalue = UserUtil::getVar($item['prop_attribute_name'], $uid, false, $isRegistration); // ($alias, $uid); } // try to get the DUD output if it's Third Party if ($item['prop_dtype'] != 1) { $output = ModUtil::apiFunc($item['prop_modname'], 'dud', 'edit', array('item' => $item, 'uservalue' => $uservalue, 'class' => $class)); if ($output) { return $output; } } $render = $smarty;//Zikula_View::getInstance('Profile', false, null, true); // assign the default values for the control $render->assign('class', $class); $render->assign('value', DataUtil::formatForDisplay($uservalue)); $render->assign('attributename', $item['prop_attribute_name']); $render->assign('proplabeltext', $item['prop_label']); $render->assign('note', $item['prop_note']); $render->assign('required', (bool)$item['prop_required']); $render->assign('error', isset($error) ? $error : ''); // Excluding Timezone of the generics if ($item['prop_attribute_name'] == 'tzoffset') { if (empty($uservalue)) { $uservalue = UserUtil::getVar('tzoffset') ? UserUtil::getVar('tzoffset') : System::getVar('timezone_offset'); } $tzinfo = DateUtil::getTimezones(); $render->assign('value', isset($tzinfo["$uservalue"]) ? "$uservalue" : null); $render->assign('selectmultiple', ''); $render->assign('listoptions', array_keys($tzinfo)); $render->assign('listoutput', array_values($tzinfo)); return $render->fetch('profile_dudedit_select.tpl'); } if ($item['prop_attribute_name'] == 'avatar') { // detect if it's the registration form to skip this if ($onregistrationform) { return ''; } // only shows a link to the Avatar module if available if (ModUtil::available('Avatar')) { // TODO Add a change-link to the admins // only shows the link for the own user if (UserUtil::getVar('uid') != $uid) { return ''; } $render->assign('linktext', __('Go to the Avatar manager', $dom)); $render->assign('linkurl', ModUtil::url('Avatar', 'user', 'main')); $output = $render->fetch('profile_dudedit_link.tpl'); // add a hidden input if this is required if ($item['prop_required']) { $output .= $render->fetch('profile_dudedit_hidden.tpl'); } return $output; } // display the avatar selector if (empty($uservalue)) { $uservalue = 'gravatar.gif'; } $render->assign('value', DataUtil::formatForDisplay($uservalue)); $avatarPath = ModUtil::getVar(Users_Constant::MODNAME, Users_Constant::MODVAR_AVATAR_IMAGE_PATH, Users_Constant::DEFAULT_AVATAR_IMAGE_PATH); $filelist = FileUtil::getFiles($avatarPath, false, true, array('gif', 'jpg', 'png'), 'f'); asort($filelist); $listoutput = $listoptions = $filelist; // strip the extension of the output list foreach ($listoutput as $k => $output) { $listoutput[$k] = $output;//substr($output, 0, strrpos($output, '.')); } $selectedvalue = $uservalue; // if (in_array($uservalue, $filelist)) { // $selectedvalue = $uservalue; // } $render->assign('value', $selectedvalue); $render->assign('selectmultiple', ''); $render->assign('listoptions', $listoptions); $render->assign('listoutput', $listoutput); return $render->fetch('profile_dudedit_select.tpl'); } switch ($item['prop_displaytype']) { case 0: // TEXT $type = 'text'; break; case 1: // TEXTAREA $type = 'textarea'; break; case 2: // CHECKBOX $type = 'checkbox'; $editlabel = array_splice(explode('@@', $item['prop_listoptions']), 0, 1); if (!empty($editlabel[0])) { $render->assign('proplabeltext', __($editlabel[0], $dom)); } break; case 3: // RADIO $type = 'radio'; $options = ModUtil::apiFunc('Profile', 'dud', 'getoptions', array('item' => $item)); $render->assign('listoptions', array_keys($options)); $render->assign('listoutput', array_values($options)); break; case 4: // SELECT $type = 'select'; if (DataUtil::is_serialized($uservalue)) { $render->assign('value', unserialize($uservalue)); } // multiple flag is the first field $options = explode('@@', $item['prop_listoptions'], 2); $selectmultiple = $options[0] ? ' multiple="multiple"' : ''; $render->assign('selectmultiple', $selectmultiple); $options = ModUtil::apiFunc('Profile', 'dud', 'getoptions', array('item' => $item)); $render->assign('listoptions', array_keys($options)); $render->assign('listoutput', array_values($options)); break; case 5: // DATE $type = 'date'; // gets the format to use $format = ModUtil::apiFunc('Profile', 'dud', 'getoptions', array('item' => $item)); switch (trim(strtolower($format))) { case 'datelong': //! This is from the core domain (datelong) $format = __('%A, %B %d, %Y'); break; case 'datebrief': //! This is from the core domain (datebrief) $format = __('%b %d, %Y'); break; case 'datestring': //! This is from the core domain (datestring) $format = __('%A, %B %d @ %H:%M:%S'); break; case 'datestring2': //! This is from the core domain (datestring2) $format = __('%A, %B %d'); break; case 'datetimebrief': //! This is from the core domain (datetimebrief) $format = __('%b %d, %Y - %I:%M %p'); break; case 'datetimelong': //! This is from the core domain (datetimelong) $format = __('%A, %B %d, %Y - %I:%M %p'); break; case 'timebrief': //! This is from the core domain (timebrief) $format = __('%I:%M %p'); break; case 'timelong': //! This is from the core domain (timelong) $format = __('%T %p'); break; } //! This is from the core domain (datebrief) $format = !empty($format) ? $format : __('%b %d, %Y'); // process the temporal data if any $timestamp = null; if (isset($item['temp_propdata'])) { $timestamp = DateUtil::parseUIDate($item['temp_propdata']); $uservalue = DateUtil::transformInternalDate($timestamp); } elseif (!empty($uservalue)) { $timestamp = DateUtil::makeTimestamp($uservalue); } $render->assign('value', $uservalue); $render->assign('timestamp', $timestamp); $render->assign('dudformat', $format); break; case 6: // EXTDATE (deprecated) // TODO [deprecate completely] $type = 'hidden'; break; case 7: // MULTICHECKBOX $type = 'multicheckbox'; $render->assign('value', (array)unserialize($uservalue)); $options = ModUtil::apiFunc('Profile', 'dud', 'getoptions', array('item' => $item)); $render->assign('fields', $options); break; default: // TEXT $type = 'text'; break; } return $render->fetch('profile_dudedit_'.$type.'.tpl'); }
/** * upgrade the blocks module * * @param string $oldversion version being upgraded * * @return bool true if successful, false otherwise */ public function upgrade($oldversion) { // Upgrade dependent on old version number switch ($oldversion) { case '3.8.1': $HookContainer = new HookContainer($this->getTranslator()); HookUtil::registerSubscriberBundles($HookContainer->getHookSubscriberBundles()); case '3.8.2': case '3.9.0': $blocks = $this->entityManager->getRepository('ZikulaBlocksModule:BlockEntity')->findAll(); /** @var \Zikula\BlocksModule\Entity\BlockEntity $block */ foreach ($blocks as $block) { $content = $block->getContent(); if (\DataUtil::is_serialized($content)) { $content = unserialize($content); foreach ($content as $k => $item) { if (is_string($item)) { if (strpos($item, 'blocks_block_extmenu_topnav.tpl') !== false) { $content[$k] = str_replace('blocks_block_extmenu_topnav.tpl', 'Block/Extmenu/topnav.tpl', $item); } elseif (strpos($item, 'blocks_block_extmenu.tpl') !== false) { $content[$k] = str_replace('blocks_block_extmenu.tpl', 'Block/Extmenu/extmenu.tpl', $item); } elseif (strpos($item, 'menutree/blocks_block_menutree_') !== false) { $content[$k] = str_replace('menutree/blocks_block_menutree_', 'Block/Menutree/', $item); } } } $block->setContent(serialize($content)); } } $this->entityManager->flush(); // check if request is available (#2073) $templateWarning = $this->__('Warning: Block template locations modified, you may need to fix your template overrides if you have any.'); if (is_object($this->container->get('request')) && method_exists($this->container->get('request'), 'getSession') && is_object($this->container->get('request')->getSession())) { $this->addFlash(\Zikula_Session::MESSAGE_WARNING, $templateWarning); } else { \LogUtil::registerWarning($templateWarning); } case '3.9.1': // make all content fields of blocks serialized. $sql = "SELECT * FROM blocks"; $blocks = $this->entityManager->getConnection()->fetchAll($sql); foreach ($blocks as $block) { if (!\DataUtil::is_serialized($block['content'])) { $serializedContent = addslashes(serialize($block['content'])); $this->entityManager->getConnection()->executeQuery("UPDATE blocks SET content = '{$serializedContent}' WHERE bid = {$block['bid']}"); } } $this->schemaTool->update($this->entities); $blocks = $this->entityManager->getRepository('ZikulaBlocksModule:BlockEntity')->findAll(); $installerHelper = new InstallerHelper(); /** @var \Zikula\BlocksModule\Entity\BlockEntity $block */ foreach ($blocks as $block) { $block->setFilters($installerHelper->upgradeFilterArray($block->getFilters())); $block->setBlocktype(preg_match('/.*Block$/', $block->getBkey()) ? substr($block->getBkey(), 0, -5) : $block->getBkey()); $block->setBkey($installerHelper->upgradeBkeyToFqClassname($this->container->get('kernel'), $block)); } $this->entityManager->flush(); $collapseable = $this->getVar('collapseable'); $this->setVar('collapseable', (bool) $collapseable); case '3.9.2': // future upgrade routines } // Update successful return true; }