function osc_locale_currency_format() { $aLocales = osc_get_locales(); $cLocale = $aLocales[0]; foreach ($aLocales as $locale) { if ($locale['pk_c_code'] == osc_current_user_locale()) { $cLocale = $locale; break; } } return $cLocale['s_currency_format']; }
/** * Generate and updates mails. * @param String $template HTML template to serve as a base. * @param Array $data New datas for emails and footer to use * to generate and update emails in oc_t_pages. * @return int Number of locales updated. */ public function update($template, $id, $newDatas, $nEmail) { $m = new Mustache_Engine(); $activeLocales = Madhouse_Utils_Collections::getFieldsFromList(osc_get_locales(), "pk_c_code"); if ($nEmail["s_internal_name"] == "exemple_page") { mdh_error_log(array($nEmail)); } $i = 0; foreach ($nEmail["locales"] as $l) { // Find the correct footer content. $footer = Madhouse_Utils_Collections::findByField($newDatas["footer"]["locales"], "fk_c_locale_code", $l["fk_c_locale_code"]); if (in_array($l["fk_c_locale_code"], $activeLocales) && !Madhouse_EmailMagick_Utils::isLocaleEmpty($l)) { // Updates the description using DAO method. Page::newInstance()->updateDescription($id, $l["fk_c_locale_code"], $l["s_title"], $m->render($template, array("CONTENT" => $l["s_text"], "TITLE" => $l["s_title"], "EXCERPT" => $l["s_excerpt"], "FOOTER" => $footer["s_text"]))); $i++; } } return $i; }
/** * Generates emails from the templates & datas. * - For each emails and for each active locale : * - Check if the emails is empty or does not exists anymore. If so, do nothing. * - Combines templates and datas to produce the s_title and s_text fields. * - Saves those settings for next run. * @return void. */ public function update() { // Decode and transform into a PHP array (true as a second parameter). $data = json_decode(Params::getParam("email_datas", false, false), true); if (!is_array($data)) { mdh_handle_error(sprintf(__("Given JSON datas are not correct (Error #%d)", mdh_current_plugin_name()), json_last_error()), mdh_emailmagick_url()); } // Get the HTML template. $template = Params::getParam("email_template", false, false); // This is current emails datas (stored in the database). $currentDatas = json_decode(osc_get_preference("email_datas", mdh_current_preferences_section()), true); // Create a new array, merge of the old and the new one. $newDatas = array("emails" => array(), "footer" => array("locales" => Madhouse_EmailMagick_Utils::mergeLocales($currentDatas["footer"]["locales"], $data["footer"]["locales"]))); // Iterate through new submitted emails data to update. $i = 0; foreach ($data["emails"] as $e) { // Get the old email datas, as they are right now. $oe = Madhouse_Utils_Collections::findByField($currentDatas["emails"], "s_internal_name", $e["s_internal_name"]); if (is_null($oe)) { // Not found in old emails. => new email has been installed. $locales = $e["locales"]; } else { // Found in old emails. Merge with new locales. $locales = Madhouse_EmailMagick_Utils::mergeLocales($oe["locales"], $e["locales"]); } // Email exists, create in order to be filled and pushed to the new datas (at the end). $nEmail = array("s_internal_name" => $e["s_internal_name"], "locales" => $locales); // Get the email from the database. $email = Page::newInstance()->findByInternalName($e["s_internal_name"]); if ($email !== false && count($email) > 0) { // Update the email. $updated = Madhouse_EmailMagick_Models_Emails::newInstance()->update($template, $email["pk_i_id"], $newDatas, $nEmail); $i += $updated; } array_push($newDatas["emails"], $nEmail); } // Saves the settings. Madhouse_Utils_Controllers::doSettingsPost(array("email_template", "email_datas"), array("email_template" => $template, "email_datas" => json_encode($newDatas)), mdh_emailmagick_url(), null, sprintf(__("Sucessfully updated %d emails (out of %d)!", mdh_current_plugin_name()), $i, count($data["emails"]) * count(osc_get_locales()))); }
/** * Computes the filling rate (percentage) of an email. * @param Email $e The email to compute the filling rate for. * @return Int An integer, from 0 to 100%. */ public static function computeFillingRate($e) { $activeLocales = Madhouse_Utils_Collections::getFieldsFromList(osc_get_locales(), "pk_c_code"); // Make some calculation on ACTIVES locales. // (non-active locales are not considered, see array_filter) $filled = array_map(function ($l) { $sum = 0; if (!empty($l["s_title"])) { $sum += 0.5; } if (!empty($l["s_text"])) { $sum += 0.5; } return $sum; }, array_values(array_filter($e["locales"], function ($l) use($activeLocales) { if (!in_array($l["fk_c_locale_code"], $activeLocales)) { return false; } return true; }))); return ceil(array_sum($filled) * 100 / count($filled)); }
/** * Gets description/information of current user * * @return string */ function osc_user_info($locale = "") { if ($locale == "") { $locale = osc_current_user_locale(); } $info = osc_user_field("s_info", $locale); if ($info == '') { $info = osc_user_field("s_info", osc_language()); if ($info == '') { $aLocales = osc_get_locales(); foreach ($aLocales as $locale) { $info = osc_user_field("s_info", $locale['pk_c_code']); if ($info != '') { break; } } } } return (string) $info; }
function printLocaleDescriptionPage($locales = null, $page = null) { if ($locales == null) { $locales = osc_get_locales(); } $aFieldsDescription = Session::newInstance()->_getForm("aFieldsDescription"); $num_locales = count($locales); foreach ($locales as $locale) { $description = ''; if (isset($page['locale'][$locale['pk_c_code']])) { $description = $page['locale'][$locale['pk_c_code']]['s_text']; } if (isset($aFieldsDescription[$locale['pk_c_code']]) && isset($aFieldsDescription[$locale['pk_c_code']]['s_text']) && $aFieldsDescription[$locale['pk_c_code']]['s_text'] != '') { $description = $aFieldsDescription[$locale['pk_c_code']]['s_text']; } $name = $locale['pk_c_code'] . '#s_text'; echo '<div><label for="description">' . __('Description') . ' *</label>'; echo '<textarea id="' . $name . '" name="' . $name . '" rows="10">' . $description . '</textarea></div>'; } }
<?php $aLocales = osc_get_locales(); ?> <!DOCTYPE html> <html dir="ltr" lang="<?php echo str_replace('_', '-', osc_current_user_locale()); ?> "> <head> <?php osc_current_web_theme_path('head.php'); ?> <meta name="robots" content="noindex, nofollow" /> <meta name="googlebot" content="noindex, nofollow" /> <script type="text/javascript"> twitter_theme.text_select_subcategory = "<?php _e('Select a subcategory...', 'twitter_bootstrap'); ?> " ; twitter_theme.category_selected_id = "<?php echo item_selected_category_id(); ?> " ; twitter_theme.subcategory_selected_id = "<?php echo item_selected_subcategory_id(); ?> " ; twitter_theme.max_number_photos = <?php echo osc_max_images_per_item(); ?>
function pop_item_description() { $description = osc_item_description(); foreach (osc_get_locales() as $locale) { if (Session::newInstance()->_getForm('description') != "") { $description_ = Session::newInstance()->_getForm('description'); if (@$description_[$locale['pk_c_code']] != "") { $description = $description_[$locale['pk_c_code']]; } } } return $description; }
<h2><?php _e('General Information', 'modern'); ?> </h2> <div class="row"> <label><?php _e('Category', 'modern'); ?> *</label> <?php ItemForm::category_select(null, null, __('Select a category', 'modern')); ?> </div> <div class="row"> <?php ItemForm::multilanguage_title_description(osc_get_locales()); ?> </div> <?php if (osc_price_enabled_at_items()) { ?> <div class="row price"> <label><?php _e('Price', 'modern'); ?> </label> <?php ItemForm::price_input_text(); ?> <?php ItemForm::currency_select();
function multilanguage_form($fields) { $locales = osc_get_locales(); $item = osc_item(); $num_locales = count($locales); foreach ($locales as $locale) { foreach ($fields as $field) { if ($num_locales > 1) { echo '<div class="switch-locale locale-' . $locale['pk_c_code'] . '">'; } multilanguage_form_create_field($locale, $field); if ($num_locales > 1) { echo '</div>'; } } } }
/** * Gets title from current item, if $locale is unspecified $locale is current user locale * * @param string $locale * @return string */ function osc_item_title($locale = "") { if ($locale == "") $locale = osc_current_user_locale(); $title = osc_item_field("s_title", $locale); if($title=='') { $title = osc_item_field("s_title", osc_language()); if($title=='') { $aLocales = osc_get_locales(); foreach($aLocales as $locale) { $title = osc_item_field("s_title", @$locale['pk_c_code']); if($title!='') { break; } } } } return (string) $title; }
function seo_sitemap_generator() { $start_time = microtime(true); $min = 1; $show_items = ''; if (Params::getParam('sitemap_items') != '') { $show_items = Params::getParam('sitemap_items'); } else { $show_items = osc_get_preference('allSeo_sitemap_items', 'plugin-all_in_one') != '' ? osc_get_preference('allSeo_sitemap_items', 'plugin-all_in_one') : ''; } $limit_items = ''; if (Params::getParam('sitemap_items_limit') != '') { $limit_items = Params::getParam('sitemap_items_limit'); } else { $limit_items = osc_get_preference('allSeo_sitemap_items_limit', 'plugin-all_in_one') != '' ? osc_get_preference('allSeo_sitemap_items_limit', 'plugin-all_in_one') : ''; } $limit_items = intval($limit_items); $locales = osc_get_locales(); $filename = osc_base_path() . 'sitemap.xml'; //link sitemap @unlink($filename); //remove original sitemap $start_xml = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL; file_put_contents($filename, $start_xml); // INDEX seo_sitemap_add_url(osc_base_url(), date('Y-m-d'), 'always'); $categories = Category::newInstance()->listAll(false); $countries = Country::newInstance()->listAll(); foreach ($categories as $c) { $search = new Search(); $search->addCategory($c['pk_i_id']); if ($search->count() >= $min) { seo_sitemap_add_url(osc_search_url(array('sCategory' => $c['s_slug'])), date('Y-m-d'), 'hourly'); foreach ($countries as $country) { if (count($countries) > 1) { $search = new Search(); $search->addCategory($c['pk_i_id']); $search->addCountry($country['pk_c_code']); if ($search->count() > $min) { seo_sitemap_add_url(osc_search_url(array('sCategory' => $c['s_slug'], 'sCountry' => $country['s_name'])), date('Y-m-d'), 'hourly'); } } $regions = Region::newInstance()->findByCountry($country['pk_c_code']); foreach ($regions as $region) { $search = new Search(); $search->addCategory($c['pk_i_id']); $search->addCountry($country['pk_c_code']); $search->addRegion($region['pk_i_id']); if ($search->count() > $min) { seo_sitemap_add_url(osc_search_url(array('sCategory' => $c['s_slug'], 'sCountry' => $country['s_name'], 'sRegion' => $region['s_name'])), date('Y-m-d'), 'hourly'); $cities = City::newInstance()->findByRegion($region['pk_i_id']); foreach ($cities as $city) { $search = new Search(); $search->addCategory($c['pk_i_id']); $search->addCountry($country['pk_c_code']); $search->addRegion($region['pk_i_id']); $search->addCity($city['pk_i_id']); if ($search->count() > $min) { seo_sitemap_add_url(osc_search_url(array('sCategory' => $c['s_slug'], 'sCountry' => $country['s_name'], 'sRegion' => $region['s_name'], 'sCity' => $city['s_name'])), date('Y-m-d'), 'hourly'); } } } } } } } foreach ($countries as $country) { $regions = Region::newInstance()->findByCountry($country['pk_c_code']); foreach ($regions as $region) { $cities = CityStats::newInstance()->listCities($region['pk_i_id']); $l = min(count($cities), 30); for ($k = 0; $k < $l; $k++) { if ($cities[$k]['items'] > $min) { seo_sitemap_add_url(osc_search_url(array('sCountry' => $country['s_name'], 'sRegion' => $region['s_name'], 'sCity' => $cities[$k]['city_name'])), date('Y-m-d'), 'hourly'); } } } } // ITEMS if ($show_items == 1) { $max_secure = 10000; $mSearch = new Search(); $mSearch->limit(0, $limit_items); // fetch number of item for sitemap $aItems = $mSearch->doSearch(); View::newInstance()->_exportVariableToView('items', $aItems); //exporting our searched item array if (osc_count_items() > 0) { $i = 0; while (osc_has_items() and $i < $limit_items and $i < $max_secure) { seo_sitemap_add_url(osc_item_url(), substr(osc_item_mod_date() != '' ? osc_item_mod_date() : osc_item_pub_date(), 0, 10), 'daily'); $i++; } } } $end_xml = '</urlset>'; file_put_contents($filename, $end_xml, FILE_APPEND); // PING SEARCH ENGINES seo_sitemap_ping_engines(); $time_elapsed = microtime(true) - $start_time; return $time_elapsed; }
<?php UserForm::address_text(osc_user()); ?> </div> <div class="row ui-row-text"> <label for="webSite"><?php _e('Website', 'realestate'); ?> </label> <?php UserForm::website_text(osc_user()); ?> </div> <div class="row ui-row-text"> <?php UserForm::multilanguage_info(osc_get_locales(), osc_user()); ?> </div> <div class="actions"> <a href="#" class="ui-button ui-button-gray js-submit"><?php _e("Update", 'realestate'); ?> </a> </div> <?php osc_run_hook('user_form'); ?> </fieldset> </form> </div> </div>
public static function multilanguage_title_description($locales = null, $item = null) { if ($locales == null) { $locales = osc_get_locales(); } if ($item == null) { $item = osc_item(); } $num_locales = count($locales); if ($num_locales > 1) { echo '<div class="tabber">'; } foreach ($locales as $locale) { if ($num_locales > 1) { echo '<div class="tabbertab">'; } if ($num_locales > 1) { echo '<h2>' . $locale['s_name'] . '</h2>'; } echo '<div class="title">'; echo '<div><label for="title">' . __('Title') . ' *</label></div>'; $title = isset($item) && isset($item['locale'][$locale['pk_c_code']]) && isset($item['locale'][$locale['pk_c_code']]['s_title']) ? $item['locale'][$locale['pk_c_code']]['s_title'] : ''; if (Session::newInstance()->_getForm('title') != "") { $title_ = Session::newInstance()->_getForm('title'); if ($title_[$locale['pk_c_code']] != "") { $title = $title_[$locale['pk_c_code']]; } } self::title_input('title', $locale['pk_c_code'], $title); echo '</div>'; echo '<div class="description">'; echo '<div><label for="description">' . __('Description') . ' *</label></div>'; $description = isset($item) && isset($item['locale'][$locale['pk_c_code']]) && isset($item['locale'][$locale['pk_c_code']]['s_description']) ? $item['locale'][$locale['pk_c_code']]['s_description'] : ''; if (Session::newInstance()->_getForm('description') != "") { $description_ = Session::newInstance()->_getForm('description'); if ($description_[$locale['pk_c_code']] != "") { $description = $description_[$locale['pk_c_code']]; } } self::description_textarea('description', $locale['pk_c_code'], $description); echo '</div>'; if ($num_locales > 1) { echo '</div>'; } } if ($num_locales > 1) { echo '</div>'; } }
<div id="left-side"> <?php printLocaleTitle(osc_get_locales()); ?> <div class="category"> <label><?php _e('Category'); ?> </label> <?php ItemForm::category_two_selects(); ?> </div> <div class="input-description-wide"> <?php printLocaleDescription(osc_get_locales()); ?> </div> <?php if (osc_price_enabled_at_items()) { ?> <div> <label><?php _e('Price'); ?> </label> <?php ItemForm::price_input_text(); ?> <span class="input-currency"><?php ItemForm::currency_select();
/** * Gets title from current premium, if $locale is unspecified $locale is current user locale * * @param string $locale * @return string */ function osc_premium_title($locale = "") { if ($locale == "") { $locale = osc_current_user_locale(); } $title = osc_premium_field("s_title", $locale); if ($title == '') { $title = osc_premium_field("s_title", osc_language()); if ($title == '') { $aLocales = osc_get_locales(); foreach ($aLocales as $locale) { $title = osc_premium_field("s_title", $locale); if ($title != '') { break; } } } } return (string) $title; }
function jsLoacaleSelector() { $locales = osc_get_locales(); $codes = array(); foreach ($locales as $locale) { $codes[] = '\'' . osc_esc_js($locale['pk_c_code']) . '\''; } ?> <script type="text/javascript"> var locales = new Object; locales.current = '<?php echo osc_esc_js($locales[0]['pk_c_code']); ?> '; locales.codes = new Array(<?php echo join(',', $codes); ?> ); locales.string = '[name*="'+locales.codes.join('"],[name*="')+'"],.'+locales.codes.join(',.'); $(function(){ $('#language-tab li a').click(function(){ $('#language-tab li').removeClass('ui-state-active').removeClass('ui-tabs-selected'); $(this).parent().addClass('ui-tabs-selected ui-state-active'); var currentLocale = $(this).attr('href').replace('#',''); $(locales.string).parent().hide(); $('[name*="'+currentLocale+'"], .'+currentLocale).parent().show(); locales.current = currentLocale; return false; }).triggerHandler('click'); }); function tabberAutomatic(){ $('.tabber:hidden').show(); $('.tabber h2').remove(); $(locales.string).parent().hide(); $('[name*="'+locales.current+'"],.'+locales.current).parent().show(); } </script> <?php }