Beispiel #1
0
 public function testIsAlphanumeric1()
 {
     $this->assertEquals(is_alphanumeric('2'), true);
     $this->assertEquals(is_alphanumeric('2.0'), true);
     $this->assertEquals(is_alphanumeric('%'), false);
     // important not to allow control characters
     $this->assertEquals(is_alphanumeric('/'), false);
     // important not to allow control characters
     $this->assertEquals(is_alphanumeric('x\\"x'), false);
     //  " is NOT ok
     $this->assertEquals(is_alphanumeric("x'x"), false);
     //  ' is NOT ok
     $this->assertEquals(is_alphanumeric('abc 123'), false);
     // space is NOT ok
     $this->assertEquals(is_alphanumeric('abc/123'), false);
     // slash is NOT ok
     $this->assertEquals(is_alphanumeric('abc123'), true);
     $this->assertEquals(is_alphanumeric('a-1'), true);
     $this->assertEquals(is_alphanumeric('a_2'), true);
     $this->assertEquals(is_alphanumeric('2öäåaÄÄÖÅ'), true);
     $this->assertEquals(is_alphanumeric('日本語'), true);
     // utf8 is ok
     $this->assertEquals(is_alphanumeric('한국어'), true);
     $this->assertEquals(is_alphanumeric('لقمة'), true);
     $this->assertEquals(is_alphanumeric(''), true);
 }
 function render()
 {
     $id = $this->id ? $this->id : $this->name;
     if (strpos($id, '[') !== false && strpos($id, ']') !== false) {
         $id = '';
     }
     if (!is_alphanumeric($id)) {
         throw new \Exception('no: ' . $id);
     }
     $res = '<input type="password"' . ' name="' . $this->name . '"' . ($id ? ' id="' . $id . '"' : '') . ($this->value || is_string($this->value) ? ' value="' . $this->value . '"' : '') . ($this->size ? ' size="' . $this->size . '"' : '') . ($this->maxlen ? ' maxlength="' . $this->maxlen . '"' : '') . ($this->disabled ? ' disabled' : '') . ($this->onchange ? ' onchange="' . $this->onchange . '"' : '') . ($this->width ? ' style="width:' . $this->width . 'px"' : '') . '/>';
     return $res;
 }
Beispiel #3
0
 function setSortOrder($s, $order = 'asc')
 {
     if (!is_alphanumeric($s)) {
         return false;
     }
     $order = strtolower($order);
     if (!in_array($order, array('desc', 'asc'))) {
         throw new \Exception('Bad sortOrder');
     }
     $this->sort_column = $s;
     $this->sort_order = $order;
 }
Beispiel #4
0
/**
 * Transforms a number by masking characters in a specified mask format,
 * and ignoring characters that should be injected into the string without
 * matching a character from the original string (defaults to space).
 *
 * <strong>Example:</strong>
 * <code>
 *  echo mask_string('1234567812345678', '************0000');
 *  // => ************5678
 *
 *  echo mask_string('1234567812345678', '**** **** **** 0000');
 *  // => **** **** **** 5678
 *
 *  echo mask_string('1234567812345678', '**** - **** - **** - 0000', ' -');
 *  // => **** - **** - **** - 5678
 * </code>
 *
 * @param string the string to transform
 * @param string the mask format
 * @param string a string (defaults to a single space) containing characters to ignore in the format
 * @return string the masked string
 */
function mask_string($string, $format, $ignore = ' ')
{
    if ($format == '' || $string == '') {
        return $string;
    }
    $result = '';
    $fpos = 0;
    $spos = 0;
    while (strlen($format) - 1 >= $fpos) {
        if (is_alphanumeric(substr($format, $fpos, 1))) {
            $result .= substr($string, $spos, 1);
            $spos++;
        } else {
            $result .= substr($format, $fpos, 1);
            if (strpos($ignore, substr($format, $fpos, 1)) === false) {
                $spos++;
            }
        }
        $fpos++;
    }
    return $result;
}
Beispiel #5
0
/**
 * Edit a zone.
 *
 * @param  ID_TEXT		The current name of the zone
 * @param  SHORT_TEXT	The zone title
 * @param  ID_TEXT		The zones default page
 * @param  SHORT_TEXT	The header text
 * @param  ID_TEXT		The theme
 * @param  BINARY			Whether the zone is wide
 * @param  BINARY			Whether the zone requires a session for pages to be used
 * @param  BINARY			Whether the zone in displayed in the menu coded into some themes
 * @param  ID_TEXT		The new name of the zone
 */
function actual_edit_zone($zone, $title, $default_page, $header_text, $theme, $wide, $require_session, $displayed_in_menu, $new_zone)
{
    if ($zone != $new_zone) {
        require_code('type_validation');
        if (!is_alphanumeric($new_zone, true)) {
            warn_exit(do_lang_tempcode('BAD_CODENAME'));
        }
        if (get_file_base() != get_custom_file_base()) {
            warn_exit(do_lang_tempcode('SHARED_INSTALL_PROHIBIT'));
        }
        // Check doesn't already exist
        $test = $GLOBALS['SITE_DB']->query_value_null_ok('zones', 'zone_header_text', array('zone_name' => $new_zone));
        if (!is_null($test)) {
            warn_exit(do_lang_tempcode('ALREADY_EXISTS', escape_html($new_zone)));
        }
        require_code('abstract_file_manager');
        force_have_afm_details();
        afm_move($zone, $new_zone);
    }
    $_header_text = $GLOBALS['SITE_DB']->query_value('zones', 'zone_header_text', array('zone_name' => $zone));
    $_title = $GLOBALS['SITE_DB']->query_value('zones', 'zone_title', array('zone_name' => $zone));
    $GLOBALS['SITE_DB']->query_update('zones', array('zone_name' => $new_zone, 'zone_title' => lang_remap($_title, $title), 'zone_default_page' => $default_page, 'zone_header_text' => lang_remap($_header_text, $header_text), 'zone_theme' => $theme, 'zone_wide' => $wide, 'zone_require_session' => $require_session, 'zone_displayed_in_menu' => $displayed_in_menu), array('zone_name' => $zone), '', 1);
    if ($new_zone != $zone) {
        actual_rename_zone_lite($zone, $new_zone, true);
        $GLOBALS['SITE_DB']->query_update('menu_items', array('i_url' => $new_zone), array('i_url' => $zone), '', 1);
    }
    // If we're in this zone, update the theme
    global $ZONE;
    if ($ZONE['zone_name'] == $zone) {
        $ZONE['theme'] = $theme;
    }
    decache('side_zone_jump');
    decache('side_stored_menu');
    decache('main_sitemap');
    persistant_cache_delete(array('ZONE', $zone));
    persistant_cache_delete('ALL_ZONES');
    log_it('EDIT_ZONE', $zone);
}
Beispiel #6
0
 /**
  * The UI to edit a menu.
  *
  * @return tempcode		The UI
  */
 function edit_menu()
 {
     if (!has_js()) {
         warn_exit(do_lang_tempcode('MSG_JS_NEEDED'));
     }
     $id = get_param('id', '');
     if ($id == '') {
         $id = get_param('id_new');
     }
     if (substr($id, 0, 1) == '_') {
         warn_exit(do_lang_tempcode('MENU_UNDERSCORE_RESERVED'));
     }
     require_code('type_validation');
     if (!is_alphanumeric($id, true)) {
         warn_exit(do_lang_tempcode('BAD_CODENAME'));
     }
     if ($id == 'zone_menu' && get_option('use_custom_zone_menu') == '0') {
         $config_url = build_url(array('page' => 'admin_config', 'type' => 'category', 'id' => 'THEME'), get_module_zone('admin_config'));
         attach_message(do_lang_tempcode('EDITING_UNUSED_MENU', escape_html($config_url->evaluate())), 'notice');
     }
     $title = get_page_title('_EDIT_MENU', true, array(escape_html($id)));
     $clickable_sections = get_param_integer('clickable_sections', 0) == 1;
     // This is set to '1 if we have a menu type where pop out sections may be clicked on to be loaded. If we do then we make no UI distinction between page nodes and contracted/expanded, so people don't get compelled to choose a URL for everything, it simply becomes an option for them.
     // This will be a templates for branches created dynamically
     $t_id = 'replace_me_with_random';
     $branch = do_template('MENU_EDITOR_BRANCH', array('_GUID' => '59d5c9bebecdac1440112ef8301d7c67', 'CLICKABLE_SECTIONS' => $clickable_sections ? 'true' : 'false', 'I' => $t_id, 'CHILD_BRANCH_TEMPLATE' => '', 'CHILD_BRANCHES' => ''));
     $child_branch_template = do_template('MENU_EDITOR_BRANCH_WRAP', array('_GUID' => 'fb16265f553127b47dfdaf33a420136b', 'DISPLAY' => $clickable_sections ? 'display: block' : 'display: none', 'CLICKABLE_SECTIONS' => $clickable_sections, 'ORDER' => 'replace_me_with_order', 'PARENT' => 'replace_me_with_parent', 'BRANCH_TYPE' => '0', 'NEW_WINDOW' => '0', 'CHECK_PERMS' => '0', 'CAPTION_LONG' => '', 'CAPTION' => '', 'URL' => '', 'PAGE_ONLY' => '', 'THEME_IMG_CODE' => '', 'I' => $t_id, 'BRANCH' => $branch));
     $order = 0;
     $menu_items = $GLOBALS['SITE_DB']->query_select('menu_items', array('*'), array('i_menu' => $id), 'ORDER BY i_parent,i_order');
     $child_branches = $this->menu_branch($id, NULL, $order, $clickable_sections, $menu_items);
     $root_branch = do_template('MENU_EDITOR_BRANCH', array('CLICKABLE_SECTIONS' => $clickable_sections ? 'true' : 'false', 'CHILD_BRANCH_TEMPLATE' => $child_branch_template, 'CHILD_BRANCHES' => $child_branches, 'I' => ''));
     $map = array('page' => '_SELF', 'type' => '_edit', 'id' => $id);
     if (get_param('redirect', '!') != '!') {
         $map['redirect'] = get_param('redirect');
     }
     $post_url = build_url($map, '_SELF');
     $map = array('page' => '_SELF', 'type' => '_edit', 'id' => $id);
     // Actually same as edit URL, just we put this into an empty post form
     if (get_param('redirect', '!') != '!') {
         $map['redirect'] = get_param('redirect');
     }
     $delete_url = build_url($map, '_SELF');
     require_code('form_templates');
     $fields_template = new ocp_tempcode();
     //$fields_template->attach(form_input_line(do_lang_tempcode('CAPTION'),do_lang_tempcode('MENU_ENTRY_CAPTION'),'caption','',true)); This is editable in the tree structure instead
     $fields_template->attach(form_input_line(do_lang_tempcode('LINK'), do_lang_tempcode('MENU_ENTRY_URL'), 'url', '', false));
     $options = array(array(do_lang_tempcode('MENU_ENTRY_NEW_WINDOW'), 'new_window', false, new ocp_tempcode()), array(do_lang_tempcode('MENU_ENTRY_CHECK_PERMS'), 'check_perms', true, do_lang_tempcode('DESCRIPTION_MENU_ENTRY_CHECK_PERMS')));
     $fields_template->attach(form_input_various_ticks($options, '', NULL, do_lang_tempcode('OPTIONS'), false));
     $list = new ocp_tempcode();
     if (!$clickable_sections) {
         $list->attach(form_input_list_entry('page', false, do_lang_tempcode('PAGE')));
     }
     $list->attach(form_input_list_entry('branch_minus', false, do_lang_tempcode('CONTRACTED_BRANCH')));
     $list->attach(form_input_list_entry('branch_plus', false, do_lang_tempcode('EXPANDED_BRANCH')));
     $fields_template->attach(form_input_list(do_lang_tempcode('BRANCH_TYPE'), do_lang_tempcode('MENU_ENTRY_BRANCH'), 'branch_type', $list));
     $fields_template->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => true, 'TITLE' => do_lang_tempcode('ADVANCED'))));
     $fields_template->attach(form_input_line(do_lang_tempcode('CAPTION_LONG'), do_lang_tempcode('MENU_ENTRY_CAPTION_LONG'), 'caption_long', '', false));
     $list = new ocp_tempcode();
     $list->attach(form_input_list_entry('', false, do_lang_tempcode('NONE_EM')));
     require_code('themes2');
     $list->attach(nice_get_theme_images(NULL, NULL, false, true, 'menu_items/'));
     $fields_template->attach(form_input_list(do_lang_tempcode('THEME_IMAGE'), do_lang_tempcode('DESCRIPTION_THEME_IMAGE_FOR_MENU_ITEM'), 'theme_img_code', $list, NULL, false, false));
     $fields_template->attach(form_input_line(do_lang_tempcode('RESTRICT_PAGE_VISIBILITY'), do_lang_tempcode('MENU_ENTRY_MATCH_KEYS'), 'match_tags', '', false));
     require_javascript('javascript_ajax');
     require_javascript('javascript_more');
     require_javascript('javascript_tree_list');
     list($warning_details, $ping_url) = handle_conflict_resolution();
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('MENU_MANAGEMENT'))));
     $all_menus = array();
     $menu_rows = $GLOBALS['SITE_DB']->query_select('menu_items', array('DISTINCT i_menu'), NULL, 'ORDER BY i_menu');
     foreach ($menu_rows as $menu_row) {
         if ($menu_row['i_menu'] != $id) {
             $all_menus[] = $menu_row['i_menu'];
         }
     }
     return do_template('MENU_EDITOR_SCREEN', array('_GUID' => 'd2bc26eaea38f3d5b3221be903ff541e', 'ALL_MENUS' => $all_menus, 'MENU_NAME' => $id, 'DELETE_URL' => $delete_url, 'PING_URL' => $ping_url, 'WARNING_DETAILS' => $warning_details, 'FIELDS_TEMPLATE' => $fields_template, 'HIGHEST_ORDER' => strval($order), 'URL' => $post_url, 'CHILD_BRANCH_TEMPLATE' => $child_branch_template, 'ROOT_BRANCH' => $root_branch, 'TITLE' => $title));
 }
Beispiel #7
0
 /**
  * The actualiser to edit/rename a theme.
  *
  * @return tempcode		The UI
  */
 function _edit_theme()
 {
     if (post_param_integer('delete', 0) == 1) {
         $title = get_page_title('DELETE_THEME');
         $theme = get_param('old_theme', false, true);
         require_code('themes3');
         actual_delete_theme($theme);
         $to = '';
     } elseif (post_param_integer('copy', 0) == 1) {
         $title = get_page_title('COPY_THEME');
         $theme = get_param('old_theme', false, true);
         $to = post_param('theme', $theme);
         // Can't rename the default theme, so there's no such field for it
         if ($theme == $to) {
             warn_exit(do_lang_tempcode('ALREADY_EXISTS', escape_html($to)));
         }
         require_code('themes3');
         actual_copy_theme($theme, $to);
         $this->save_theme_changes($to);
     } else {
         $title = get_page_title('EDIT_THEME');
         $theme = get_param('old_theme', false, true);
         $to = post_param('theme', $theme);
         // Can't rename the default theme, so there's no such field for it
         if ($theme != $to) {
             require_code('type_validation');
             if (!is_alphanumeric($to)) {
                 $to = preg_replace('#[^\\w\\-\\d]#', '_', $to);
                 //warn_exit(do_lang_tempcode('BAD_CODENAME'));
             }
             if (!file_exists(get_custom_file_base() . '/themes/' . $theme)) {
                 warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
             }
             require_code('themes3');
             actual_rename_theme($theme, $to);
         }
         $this->save_theme_changes($to);
     }
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('THEMES'))));
     breadcrumb_set_self(do_lang_tempcode('DONE'));
     return $this->do_next_manager($title, do_lang_tempcode('SUCCESS'), $to, '', 'theme', $to);
 }
 private function __construct()
 {
     // REDIRECT_URL holds the (public) url the page was redirected to (when using mod_rewrite), also it dont mangle utf8 in url
     if (isset($_SERVER['REDIRECT_URL'])) {
         $request = $_SERVER['REDIRECT_URL'];
     } else {
         $request = $_SERVER['REQUEST_URI'];
     }
     // exclude application root from parsed request
     $page = XmlDocumentHandler::getInstance();
     $parsed = parse_url($page->getUrl());
     if (substr($request, 0, strlen($parsed['path'])) == $parsed['path']) {
         $request = substr($request, strlen($parsed['path']));
     }
     $arr = explode('/', trim($request, '/'));
     if ($arr && substr($arr[0], 0, 1) != '?') {
         if (!empty($arr[0])) {
             if (!is_alphanumeric($arr[0])) {
                 die('XXX controller');
             }
             $this->_controller = $arr[0];
         }
         if (!empty($arr[1])) {
             if (!is_alphanumeric($arr[1])) {
                 die('XXX view');
             }
             $this->_view = $arr[1];
         }
         if (!empty($arr[2])) {
             if (!is_alphanumeric($arr[2])) {
                 die('XXX owner');
             }
             $this->_owner = $arr[2];
         }
         if (!empty($arr[3])) {
             if (!is_alphanumeric($arr[3])) {
                 die('XXX child');
             }
             $this->_child = $arr[3];
         }
         if (!empty($arr[4])) {
             if (!is_alphanumeric($arr[4])) {
                 die('XXX child2');
             }
             $this->_child2 = $arr[4];
         }
         if (!empty($arr[5])) {
             if (!is_alphanumeric($arr[5])) {
                 die('XXX child3');
             }
             $this->_child3 = $arr[5];
         }
     }
 }
Beispiel #9
0
/**
 * Edit a gallery.
 *
 * @param  ID_TEXT		The old gallery codename (in case we are renaming)
 * @param  ID_TEXT		The gallery codename (maybe the same as the old one)
 * @param  SHORT_TEXT	The full human-readeable name of the gallery
 * @param  LONG_TEXT		The description of the gallery
 * @param  SHORT_TEXT	Teaser text for the gallery
 * @param  LONG_TEXT		Hidden notes associated with the gallery
 * @param  ?ID_TEXT		The parent gallery (NULL: no parent)
 * @param  BINARY			Whether images may be put in this gallery
 * @param  BINARY			Whether videos may be put in this gallery
 * @param  BINARY			Whether the gallery serves as a container for automatically created member galleries
 * @param  BINARY			Whether the gallery uses the flow mode interface
 * @param  URLPATH		The representative image of the gallery (blank: none)
 * @param  URLPATH		Watermark (blank: none)
 * @param  URLPATH		Watermark (blank: none)
 * @param  URLPATH		Watermark (blank: none)
 * @param  URLPATH		Watermark (blank: none)
 * @param  ?SHORT_TEXT	Meta keywords for this resource (NULL: do not edit)
 * @param  ?LONG_TEXT	Meta description for this resource (NULL: do not edit)
 * @param  BINARY			Whether rating are allowed
 * @param  BINARY			Whether comments are allowed
 * @param  ?MEMBER		The gallery owner (NULL: nobody)
 */
function edit_gallery($old_name, $name, $fullname, $description, $teaser, $notes, $parent_id = NULL, $accept_images = 1, $accept_videos = 1, $is_member_synched = 0, $flow_mode_interface = 0, $rep_image = '', $watermark_top_left = '', $watermark_top_right = '', $watermark_bottom_left = '', $watermark_bottom_right = '', $meta_keywords = NULL, $meta_description = NULL, $allow_rating = 1, $allow_comments = 1, $g_owner = NULL)
{
    require_code('urls2');
    suggest_new_idmoniker_for('galleries', 'misc', $name, $fullname);
    $under_category_id = $parent_id;
    while ($under_category_id != '' && $under_category_id != STRING_MAGIC_NULL) {
        if ($name == $under_category_id) {
            warn_exit(do_lang_tempcode('OWN_PARENT_ERROR'));
        }
        $under_category_id = $GLOBALS['SITE_DB']->query_value('galleries', 'parent_id', array('name' => $under_category_id));
    }
    if (is_null($parent_id)) {
        $parent_id = '';
    }
    require_code('seo2');
    if ($old_name != $name) {
        require_code('type_validation');
        if (!is_alphanumeric($name, true)) {
            warn_exit(do_lang_tempcode('BAD_CODENAME'));
        }
        $test = $GLOBALS['SITE_DB']->query_value_null_ok('galleries', 'name', array('name' => $name));
        if (!is_null($test)) {
            warn_exit(do_lang_tempcode('ALREADY_EXISTS', escape_html($name)));
        }
        seo_meta_erase_storage('gallery', $old_name);
        $GLOBALS['SITE_DB']->query_update('images', array('cat' => $name), array('cat' => $old_name));
        $GLOBALS['SITE_DB']->query_update('videos', array('cat' => $name), array('cat' => $old_name));
        $GLOBALS['SITE_DB']->query_update('galleries', array('parent_id' => $name), array('parent_id' => $old_name));
        if (addon_installed('awards')) {
            $types = $GLOBALS['SITE_DB']->query_select('award_types', array('id'), array('a_content_type' => 'gallery'));
            foreach ($types as $type) {
                $GLOBALS['SITE_DB']->query_update('award_archive', array('content_id' => $name), array('content_id' => $old_name, 'a_type_id' => $type['id']));
            }
        }
    }
    if (!is_null($meta_keywords)) {
        seo_meta_set_for_explicit('gallery', $name, $meta_keywords, $meta_description);
    }
    $myrows = $GLOBALS['SITE_DB']->query_select('galleries', array('fullname', 'description', 'teaser'), array('name' => $old_name), '', 1);
    if (!array_key_exists(0, $myrows)) {
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    $myrow = $myrows[0];
    $map = array('name' => $name, 'notes' => $notes, 'fullname' => lang_remap($myrow['fullname'], $fullname), 'description' => lang_remap_comcode($myrow['description'], $description), 'teaser' => lang_remap_comcode($myrow['teaser'], $teaser), 'parent_id' => $parent_id, 'accept_images' => $accept_images, 'accept_videos' => $accept_videos, 'is_member_synched' => $is_member_synched, 'flow_mode_interface' => $flow_mode_interface, 'allow_rating' => $allow_rating, 'allow_comments' => $allow_comments, 'g_owner' => $g_owner);
    require_code('files2');
    if (!is_null($rep_image)) {
        $map['rep_image'] = $rep_image;
        delete_upload('uploads/grepimages', 'galleries', 'rep_image', 'name', $old_name, $rep_image);
    }
    if (!is_null($watermark_top_left)) {
        $map['watermark_top_left'] = $watermark_top_left;
        delete_upload('uploads/watermarks', 'galleries', 'watermark_top_left', 'name', $old_name, $watermark_top_left);
    }
    if (!is_null($watermark_top_right)) {
        $map['watermark_top_right'] = $watermark_top_right;
        delete_upload('uploads/watermarks', 'galleries', 'watermark_top_right', 'name', $old_name, $watermark_top_right);
    }
    if (!is_null($watermark_bottom_left)) {
        $map['watermark_bottom_left'] = $watermark_bottom_left;
        delete_upload('uploads/watermarks', 'galleries', 'watermark_bottom_left', 'name', $old_name, $watermark_bottom_left);
    }
    if (!is_null($watermark_bottom_right)) {
        $map['watermark_bottom_right'] = $watermark_bottom_right;
        delete_upload('uploads/watermarks', 'galleries', 'watermark_bottom_right', 'name', $old_name, $watermark_bottom_right);
    }
    $GLOBALS['SITE_DB']->query_update('galleries', $map, array('name' => $old_name), '', 1);
    log_it('EDIT_GALLERY', $name, $fullname);
    $GLOBALS['SITE_DB']->query_update('group_category_access', array('category_name' => $name), array('module_the_name' => 'galleries', 'category_name' => $old_name));
    decache('main_top_galleries');
    decache('main_recent_galleries');
    decache('main_root_galleries');
    decache('side_root_galleries');
    require_code('feedback');
    update_spacer_post($allow_comments != 0, 'galleries', $name, build_url(array('page' => 'galleries', 'type' => 'misc', 'id' => $name), get_module_zone('galleries'), NULL, false, false, true), $fullname, get_value('comment_forum__galleries'));
}
Beispiel #10
0
 function is_acct_name($acct)
 {
     return is_alphanumeric($acct);
 }
Beispiel #11
0
function countryFlag($s)
{
    if (is_numeric($s)) {
        $s = getCountryCode($s);
    } else {
        if (!is_alphanumeric($s)) {
            throw new \Exception('hey');
        }
        if (strlen($s) == 2) {
            $s = country_2_to_3_letters($s);
        }
        $s = strtoupper($s);
    }
    $locale = \cd\LocaleHandler::getInstance();
    $title = getCountryName($s);
    if (!$title) {
        throw new \Exception('unhandled country flag code ' . $s);
    }
    return '<img src="' . relurl('core_dev/gfx/flags/' . $s . '.png') . '" alt="' . $title . '" title="' . $title . '"/>';
}
Beispiel #12
0
 /**
  * Find the posted value from the get_field_inputter field
  *
  * @param  boolean		Whether we were editing (because on edit, it could be a fractional edit)
  * @param  array			The field details
  * @param  string			Where the files will be uploaded to
  * @param  ?string		Former value of field (NULL: none)
  * @return string			The value
  */
 function inputted_to_field_value($editing, $field, $upload_dir = 'uploads/catalogues', $old_value = NULL)
 {
     $id = $field['id'];
     $tmp_name = 'field_' . strval($id);
     $ret = post_param($tmp_name, $editing ? STRING_MAGIC_NULL : '');
     if ($ret != '' && $ret != STRING_MAGIC_NULL) {
         require_code('type_validation');
         if (!is_alphanumeric($id, true)) {
             warn_exit(do_lang_tempcode('BAD_CODENAME'));
         }
     }
     return $ret;
 }
Beispiel #13
0
/**
 * Add a zone.
 *
 * @param  ID_TEXT		Name of the zone
 * @param  SHORT_TEXT	The zone title
 * @param  ID_TEXT		The zones default page
 * @param  SHORT_TEXT	The header text
 * @param  ID_TEXT		The theme
 * @param  BINARY			Whether the zone is wide
 * @param  BINARY			Whether the zone requires a session for pages to be used
 * @param  BINARY			Whether the zone in displayed in the menu coded into some themes
 */
function actual_add_zone($zone, $title, $default_page = 'start', $header_text = '', $theme = 'default', $wide = 0, $require_session = 0, $displayed_in_menu = 1)
{
    require_code('type_validation');
    if (!is_alphanumeric($zone, true)) {
        warn_exit(do_lang_tempcode('BAD_CODENAME'));
    }
    if (get_file_base() != get_custom_file_base()) {
        warn_exit(do_lang_tempcode('SHARED_INSTALL_PROHIBIT'));
    }
    // Check doesn't already exist
    $test = $GLOBALS['SITE_DB']->query_value_null_ok('zones', 'zone_header_text', array('zone_name' => $zone));
    if (!is_null($test)) {
        if (file_exists(get_file_base() . '/' . $zone)) {
            warn_exit(do_lang_tempcode('ALREADY_EXISTS', escape_html($zone)));
        } else {
            persistant_cache_delete(array('ZONE', $zone));
            $GLOBALS['SITE_DB']->query_delete('zones', array('zone_name' => $zone), '', 1);
        }
    }
    if (!file_exists(get_file_base() . '/' . $zone)) {
        // Create structure
        afm_make_directory($zone . '/pages/minimodules_custom', true, true);
        afm_make_directory($zone . '/pages/minimodules', false, true);
        afm_make_directory($zone . '/pages/modules_custom', true, true);
        afm_make_directory($zone . '/pages/modules', false, true);
        $langs = array_keys(find_all_langs(true));
        foreach ($langs as $lang) {
            afm_make_directory($zone . '/pages/comcode_custom/' . $lang, true, true);
            afm_make_directory($zone . '/pages/comcode/' . $lang, false, true);
            afm_make_directory($zone . '/pages/html_custom/' . $lang, true, true);
            afm_make_directory($zone . '/pages/html/' . $lang, false, true);
        }
        afm_make_file($zone . '/index.php', file_get_contents(get_file_base() . '/site/index.php'), false);
        if (file_exists(get_file_base() . '/pages/.htaccess')) {
            afm_make_file($zone . '/pages/.htaccess', file_get_contents(get_file_base() . '/pages/.htaccess'), false);
        }
        $index_php = array('pages/comcode', 'pages/comcode/EN', 'pages/comcode_custom', 'pages/comcode_custom/EN', 'pages/html', 'pages/html/EN', 'pages/html_custom', 'pages/html_custom/EN', 'pages/modules', 'pages/modules_custom', 'pages');
        foreach ($index_php as $i) {
            afm_make_file($zone . '/' . $i . '/index.html', '', false);
        }
        $default_menu = <<<END
[block="zone_{$zone}_menu" type="tree" caption="Menu"]side_stored_menu[/block]
[block failsafe="1"]side_users_online[/block]
[block failsafe="1"]side_stats[/block]
[block]side_personal_stats[/block]
END;
        afm_make_file($zone . '/pages/comcode_custom/EN/panel_left.txt', $default_menu, true);
    }
    afm_make_file($zone . '/pages/comcode_custom/EN/' . filter_naughty($default_page) . '.txt', '[title]' . do_lang('YOUR_NEW_ZONE') . '[/title]' . chr(10) . chr(10) . do_lang('YOUR_NEW_ZONE_PAGE', $zone . ':' . $default_page) . chr(10) . chr(10) . '[block]main_comcode_page_children[/block]', true);
    $GLOBALS['SITE_DB']->query_insert('zones', array('zone_name' => $zone, 'zone_title' => insert_lang($title, 1), 'zone_default_page' => $default_page, 'zone_header_text' => insert_lang($header_text, 1), 'zone_theme' => $theme, 'zone_wide' => $wide, 'zone_require_session' => $require_session, 'zone_displayed_in_menu' => $displayed_in_menu));
    require_code('menus2');
    $menu_item_count = $GLOBALS['SITE_DB']->query_value('menu_items', 'COUNT(*)', array('i_menu' => 'zone_menu'));
    if ($menu_item_count < 40) {
        add_menu_item_simple('zone_menu', NULL, $title, $zone . ':', 0, 1);
    }
    log_it('ADD_ZONE', $zone);
    persistant_cache_delete('ALL_ZONES');
    decache('main_sitemap');
    decache('side_stored_menu');
    decache('side_zone_jump');
}
Beispiel #14
0
/**
 * Read a PHP function line and return parsed details.
 *
 * @param  string			The line
 * @return array			A pair: (function name, parameters), where parameters is a list of maps detailing each parameter
 */
function _read_php_function_line($_line)
{
    $parse = 'function_name';
    $function_name = '';
    $parameters = array();
    $arg_default = '';
    $arg_name = '';
    for ($k = 0; $k < strlen($_line); $k++) {
        $char = $_line[$k];
        switch ($parse) {
            case 'in_comment':
                if ($char == '*' && $_line[$k + 1] == '/') {
                    $parse = 'in_args';
                    $ref = false;
                    $k++;
                }
                break;
            case 'in_comment_default':
                if ($char == '*' && $_line[$k + 1] == '/') {
                    $parse = 'in_default';
                    $k++;
                }
                break;
            case 'in_default':
                if ($char == '/' && $_line[$k + 1] == '*') {
                    $parse = 'in_comment_default';
                } elseif ($char == ',' && ($_line[$k - 1] != '\'' || $_line[$k - 2] != '=')) {
                    if ($arg_default === 'true') {
                        $default = 'boolean-true';
                    } elseif ($arg_default === 'false') {
                        $default = 'boolean-false';
                    } else {
                        $default = @eval('return ' . $arg_default . ';');
                    }
                    // Could be unprocessable by php.php in standalone mode
                    $parameters[] = array('name' => $arg_name, 'default' => $default, 'ref' => $ref);
                    $arg_name = '';
                    $arg_default = '';
                    $parse = 'in_args';
                    $ref = false;
                } elseif ($char == ')') {
                    if ($arg_default === 'true') {
                        $default = 'boolean-true';
                    } elseif ($arg_default === 'false') {
                        $default = 'boolean-false';
                    } else {
                        $default = @eval('return ' . $arg_default . ';');
                    }
                    // Could be unprocessable by php.php in standalone mode
                    $parameters[] = array('name' => $arg_name, 'default' => $default, 'ref' => $ref);
                    $parse = 'done';
                } else {
                    $arg_default .= $char;
                }
                break;
            case 'in_args':
                if ($char == '/' && $_line[$k + 1] == '*') {
                    $parse = 'in_comment';
                } elseif (is_alphanumeric($char)) {
                    $arg_name .= $char;
                } elseif ($char == '&') {
                    $ref = true;
                } elseif ($char == ',') {
                    $parameters[] = array('name' => $arg_name, 'ref' => $ref);
                    $ref = false;
                    $arg_name = '';
                } elseif ($char == '=') {
                    $parse = 'in_default';
                    $arg_default = '';
                } elseif ($char == ')') {
                    if ($arg_name != '') {
                        $parameters[] = array('name' => $arg_name, 'ref' => $ref);
                    }
                    $parse = 'done';
                }
                break;
            case 'function_name':
                if (is_alphanumeric($char)) {
                    $function_name .= $char;
                } elseif ($char == '(') {
                    $parse = 'in_args';
                    $ref = false;
                    $arg_name = '';
                } else {
                    $parse = 'between_name_and_args';
                }
                break;
            case 'between_name_and_args':
                if ($char == '(') {
                    $parse = 'in_args';
                    $ref = false;
                    $arg_name = '';
                }
        }
    }
    return array($function_name, $parameters);
}
Beispiel #15
0
/**
 * Get the next tag in the current XHTML document.
 *
 * @return ?mixed			Either an array of error details, a string of the tag, or NULL for finished (NULL: no next tag)
 */
function _get_next_tag()
{
    //	echo '<p>!</p>';
    global $PARENT_TAG, $POS, $LINENO, $LINESTART, $OUT, $T_POS, $ENTITIES, $LEN, $ANCESTER_BLOCK, $TAG_STACK, $XHTML_VALIDATOR_OFF, $TEXT_NO_BLOCK, $INBETWEEN_TEXT;
    global $TAG_RANGES, $VALUE_RANGES;
    $status = NO_MANS_LAND;
    $current_tag = '';
    $current_attribute_name = '';
    $current_attribute_value = '';
    $close = false;
    $doc_type = '';
    $INBETWEEN_TEXT = '';
    $attribute_map = array();
    $errors = array();
    $chr_10 = chr(10);
    $chr_13 = chr(13);
    $special_chars = array('=' => 1, '"' => 1, '&' => 1, '/' => 1, '<' => 1, '>' => 1, ' ' => 1, $chr_10 => 1, $chr_13 => 1);
    while ($POS < $LEN) {
        $next = $OUT[$POS];
        $POS++;
        if ($next == $chr_10) {
            $LINENO++;
            $LINESTART = $POS;
        }
        //		echo $status.' for '.$next.'<br />';
        // Entity checking
        if ($next == '&' && $status != IN_CDATA && $status != IN_COMMENT && is_null($XHTML_VALIDATOR_OFF)) {
            $test = test_entity();
            if (!is_null($test)) {
                $errors = array_merge($errors, $test);
            }
        }
        // State machine
        switch ($status) {
            case NO_MANS_LAND:
                $in_no_mans_land = '';
                $continue = $next != '<' && $next != '&' && $POS < $LEN - 1;
                if ($next != '<') {
                    $INBETWEEN_TEXT .= $next;
                }
                while ($continue) {
                    $next = $OUT[$POS];
                    $POS++;
                    $continue = $next != '<' && $next != '&' && $POS < $LEN - 1;
                    if ($continue) {
                        $in_no_mans_land .= $next;
                    }
                    if ($next != '<') {
                        $INBETWEEN_TEXT .= $next;
                    }
                    if ($next == $chr_10) {
                        $LINENO++;
                        $LINESTART = $POS;
                    }
                }
                if ($next == '&' && is_null($XHTML_VALIDATOR_OFF)) {
                    $test = test_entity();
                    if (!is_null($test)) {
                        $errors = array_merge($errors, $test);
                    }
                }
                // Can't have loose text in form/body/etc
                // 'x' is there for when called externally, checking on an x that has replaced, for example, a directive tag (which isn't actual text - so can't trip the error)
                if ($in_no_mans_land != 'x' && trim($in_no_mans_land) != '' && isset($TEXT_NO_BLOCK[$PARENT_TAG]) && $GLOBALS['BLOCK_CONSTRAIN']) {
                    $errors[] = array('XHTML_TEXT_NO_BLOCK', $PARENT_TAG);
                }
                if ($next == '<' && isset($OUT[$POS + 2]) && $OUT[$POS] == '!') {
                    if ($OUT[$POS + 1] == '-' && $OUT[$POS + 2] == '-') {
                        $status = IN_COMMENT;
                        $INBETWEEN_TEXT .= '<!--';
                        $POS += 3;
                    } elseif (substr($OUT, $POS - 1, 9) == '<![CDATA[') {
                        $status = IN_CDATA;
                        $POS += 8;
                        $INBETWEEN_TEXT .= '<![CDATA[';
                    } else {
                        $status = IN_DTD_TAG;
                    }
                } elseif ($next == '<' && isset($OUT[$POS]) && $OUT[$POS] == '?' && $POS < 10) {
                    if (!isset($GLOBALS['MAIL_MODE'])) {
                        $GLOBALS['MAIL_MODE'] = false;
                    }
                    if ($GLOBALS['MAIL_MODE']) {
                        $errors[] = array('MAIL_PROLOG');
                    }
                    $status = IN_XML_TAG;
                } elseif ($next == '<') {
                    $T_POS = $POS - 1;
                    $status = STARTING_TAG;
                } else {
                    if ($next == '>') {
                        $errors[] = array('XML_TAG_CLOSE_ANOMALY');
                        return array(NULL, $errors);
                    }
                }
                break;
            case IN_TAG_NAME:
                $more_to_come = !isset($special_chars[$next]) && $POS < $LEN;
                while ($more_to_come) {
                    $current_tag .= $next;
                    $next = $OUT[$POS];
                    $POS++;
                    if ($next == $chr_10) {
                        $LINENO++;
                        $LINESTART = $POS;
                    }
                    $more_to_come = !isset($special_chars[$next]) && $POS < $LEN;
                }
                if ($next == ' ' || $next == $chr_10 || $next == $chr_13) {
                    $TAG_RANGES[] = array($T_POS + 1, $POS - 1, $current_tag);
                    $status = IN_TAG_BETWEEN_ATTRIBUTES;
                } elseif ($next == '<') {
                    $errors[] = array('XML_TAG_OPEN_ANOMALY', '1');
                    return array(NULL, $errors);
                } elseif ($next == '>') {
                    if ($OUT[$POS - 2] == '/') {
                        $TAG_RANGES[] = array($T_POS + 1, $POS - 1, $current_tag);
                        return _check_tag($current_tag, array(), true, $close, $errors);
                    } else {
                        $TAG_RANGES[] = array($T_POS + 1, $POS - 1, $current_tag);
                        return _check_tag($current_tag, array(), false, $close, $errors);
                    }
                } elseif ($next != '/') {
                    $current_tag .= $next;
                }
                break;
            case STARTING_TAG:
                if ($next == '/') {
                    $close = true;
                } elseif ($next == '<') {
                    $errors[] = array('XML_TAG_OPEN_ANOMALY', '2');
                    //					return array(NULL,$errors);
                    // We have to assume the first < was not for a real opening tag
                    $POS--;
                    $status = NO_MANS_LAND;
                } elseif ($next == '>') {
                    $errors[] = array('XML_TAG_CLOSE_ANOMALY', '3');
                    //					return array(NULL,$errors);
                    // We have to assume neither were for a real tag
                    $status = NO_MANS_LAND;
                } else {
                    $current_tag .= $next;
                    $status = IN_TAG_NAME;
                }
                break;
            case IN_TAG_BETWEEN_ATTRIBUTES:
                if ($next == '/' && isset($OUT[$POS]) && $OUT[$POS] == '>') {
                    ++$POS;
                    return _check_tag($current_tag, $attribute_map, true, $close, $errors);
                } elseif ($next == '>') {
                    return _check_tag($current_tag, $attribute_map, false, $close, $errors);
                } elseif ($next == '<' && isset($OUT[$POS + 3]) && $OUT[$POS] == '!' && $OUT[$POS + 1] == '-' && $OUT[$POS + 2] == '-') {
                    $status = IN_TAG_EMBEDDED_COMMENT;
                    if ($OUT[$POS + 3] == '-') {
                        $errors[] = array('XHTML_WRONG_COMMENTING');
                    }
                } elseif ($next == '<') {
                    $errors[] = array('XML_TAG_OPEN_ANOMALY', '4');
                    return array(NULL, $errors);
                } elseif ($next != ' ' && $next != "\t" && $next != $chr_10 && $next != $chr_13) {
                    $status = IN_TAG_ATTRIBUTE_NAME;
                    $current_attribute_name .= $next;
                }
                break;
            case IN_TAG_ATTRIBUTE_NAME:
                $more_to_come = !isset($special_chars[$next]) && $POS < $LEN;
                while ($more_to_come) {
                    $current_attribute_name .= $next;
                    $next = $OUT[$POS];
                    $POS++;
                    if ($next == $chr_10) {
                        $LINENO++;
                        $LINESTART = $POS;
                    }
                    $more_to_come = !isset($special_chars[$next]) && $POS < $LEN;
                }
                if ($next == '=') {
                    if (function_exists('require_code')) {
                        require_code('type_validation');
                    }
                    if (!is_alphanumeric(preg_replace('#^([^:]+):#', '${1}', $current_attribute_name))) {
                        $errors[] = array('XML_TAG_BAD_ATTRIBUTE', $current_attribute_name);
                        $current_attribute_name = 'wrong' . strval($POS);
                    }
                    $status = IN_TAG_BETWEEN_ATTRIBUTE_NAME_VALUE_RIGHT;
                } elseif ($next == '<') {
                    $errors[] = array('XML_TAG_OPEN_ANOMALY', '5');
                    //return array(NULL,$errors);
                    // We have to assume we shouldn't REALLY have found a tag
                    $POS--;
                    $current_tag = '';
                    $status = NO_MANS_LAND;
                } elseif ($next == '>') {
                    require_code('type_validation');
                    if (!is_alphanumeric(preg_replace('#^([^:]+):#', '${1}', $current_attribute_name))) {
                        $errors[] = array('XML_TAG_BAD_ATTRIBUTE', $current_attribute_name);
                        $current_attribute_name = 'wrong' . strval($POS);
                    }
                    if ($GLOBALS['XML_CONSTRAIN']) {
                        $errors[] = array('XML_TAG_CLOSE_ANOMALY');
                    }
                    // Things like nowrap, checked, etc
                    //					return array(NULL,$errors);
                    if (isset($attribute_map[$current_attribute_name])) {
                        $errors[] = array('XML_TAG_DUPLICATED_ATTRIBUTES', $current_tag);
                    }
                    $attribute_map[$current_attribute_name] = $current_attribute_name;
                    $current_attribute_name = '';
                    $VALUE_RANGES[] = array($POS - 1, $POS - 1);
                    return _check_tag($current_tag, $attribute_map, false, $close, $errors);
                } elseif ($next != ' ' && $next != "\t" && $next != $chr_10 && $next != $chr_13) {
                    $current_attribute_name .= $next;
                } else {
                    require_code('type_validation');
                    if (!is_alphanumeric(preg_replace('#^([^:]+):#', '${1}', $current_attribute_name))) {
                        $errors[] = array('XML_TAG_BAD_ATTRIBUTE', $current_attribute_name);
                        $current_attribute_name = 'wrong' . strval($POS);
                    }
                    $status = IN_TAG_BETWEEN_ATTRIBUTE_NAME_VALUE_LEFT;
                }
                break;
            case IN_TAG_BETWEEN_ATTRIBUTE_NAME_VALUE_LEFT:
                if ($next == '=') {
                    $status = IN_TAG_BETWEEN_ATTRIBUTE_NAME_VALUE_RIGHT;
                } elseif ($next != ' ' && $next != "\t" && $next != $chr_10 && $next != $chr_13) {
                    if ($GLOBALS['XML_CONSTRAIN']) {
                        $errors[] = array('XML_ATTRIBUTE_ERROR');
                    }
                    //return array(NULL,$errors);  Actually  <blah nowrap ... />	could cause this
                    $status = IN_TAG_BETWEEN_ATTRIBUTES;
                    if (isset($attribute_map[$current_attribute_name])) {
                        $errors[] = array('XML_TAG_DUPLICATED_ATTRIBUTES', $current_tag);
                    }
                    $attribute_map[$current_attribute_name] = $current_attribute_name;
                    $current_attribute_name = $next;
                    $VALUE_RANGES[] = array($POS - 1, $POS - 1);
                }
                break;
            case IN_TAG_BETWEEN_ATTRIBUTE_NAME_VALUE_RIGHT:
                if ($next == '"') {
                    $v_pos = $POS;
                    $status = IN_TAG_ATTRIBUTE_VALUE_BIG_QUOTES;
                } elseif ($next == '\'' && true) {
                    $v_pos = $POS;
                    $status = IN_TAG_ATTRIBUTE_VALUE_LITTLE_QUOTES;
                } elseif ($next != ' ' && $next != "\t" && $next != $chr_10 && $next != $chr_13) {
                    if ($next == '<') {
                        $errors[] = array('XML_TAG_OPEN_ANOMALY', '6');
                        //						return array(NULL,$errors);
                    } elseif ($next == '>') {
                        $errors[] = array('XML_TAG_CLOSE_ANOMALY');
                        //						return array(NULL,$errors);
                    }
                    if ($GLOBALS['XML_CONSTRAIN']) {
                        $errors[] = array('XML_ATTRIBUTE_ERROR');
                    }
                    $POS--;
                    $v_pos = $POS;
                    $status = IN_TAG_ATTRIBUTE_VALUE_NO_QUOTES;
                }
                break;
            case IN_TAG_ATTRIBUTE_VALUE_NO_QUOTES:
                if ($next == '>') {
                    if (isset($attribute_map[$current_attribute_name])) {
                        $errors[] = array('XML_TAG_DUPLICATED_ATTRIBUTES', $current_tag);
                    }
                    $attribute_map[$current_attribute_name] = $current_attribute_value;
                    $current_attribute_value = '';
                    $current_attribute_name = '';
                    $VALUE_RANGES[] = array($v_pos, $POS - 1);
                    return _check_tag($current_tag, $attribute_map, false, $close, $errors);
                } elseif ($next == ' ' || $next == "\t" || $next == $chr_10 || $next == $chr_13) {
                    $status = IN_TAG_BETWEEN_ATTRIBUTES;
                    if (isset($attribute_map[$current_attribute_name])) {
                        $errors[] = array('XML_TAG_DUPLICATED_ATTRIBUTES', $current_tag);
                    }
                    $attribute_map[$current_attribute_name] = $current_attribute_value;
                    $current_attribute_value = '';
                    $current_attribute_name = '';
                    $VALUE_RANGES[] = array($v_pos, $POS - 1);
                } else {
                    if ($next == '<') {
                        $errors[] = array('XML_TAG_OPEN_ANOMALY', '7');
                        //					return array(NULL,$errors);
                    }
                    $current_attribute_value .= $next;
                }
                break;
            case IN_TAG_ATTRIBUTE_VALUE_BIG_QUOTES:
                $more_to_come = !isset($special_chars[$next]) && $POS < $LEN;
                while ($more_to_come) {
                    $current_attribute_value .= $next;
                    $next = $OUT[$POS];
                    $POS++;
                    if ($next == $chr_10) {
                        $LINENO++;
                        $LINESTART = $POS;
                    }
                    $more_to_come = !isset($special_chars[$next]) && $POS < $LEN;
                }
                if ($next == '&' && is_null($XHTML_VALIDATOR_OFF)) {
                    $test = test_entity();
                    if (!is_null($test)) {
                        $errors = array_merge($errors, $test);
                    }
                }
                if ($next == '"') {
                    $status = IN_TAG_BETWEEN_ATTRIBUTES;
                    if (isset($attribute_map[$current_attribute_name])) {
                        $errors[] = array('XML_TAG_DUPLICATED_ATTRIBUTES', $current_tag);
                    }
                    $attribute_map[$current_attribute_name] = $current_attribute_value;
                    $current_attribute_value = '';
                    $current_attribute_name = '';
                    $VALUE_RANGES[] = array($v_pos, $POS - 1);
                } else {
                    if ($next == '<') {
                        $errors[] = array('XML_TAG_OPEN_ANOMALY', '7');
                        //					return array(NULL,$errors);
                    } elseif ($next == '>') {
                        $errors[] = array('XML_TAG_CLOSE_ANOMALY');
                        //					return array(NULL,$errors);
                    }
                    $current_attribute_value .= $next;
                }
                break;
            case IN_TAG_ATTRIBUTE_VALUE_LITTLE_QUOTES:
                if ($next == '\'') {
                    $status = IN_TAG_BETWEEN_ATTRIBUTES;
                    $attribute_map[$current_attribute_name] = $current_attribute_value;
                    $current_attribute_value = '';
                    $current_attribute_name = '';
                    $VALUE_RANGES[] = array($v_pos, $POS - 1);
                } else {
                    if ($next == '<') {
                        $errors[] = array('XML_TAG_OPEN_ANOMALY', '7');
                        //					return array(NULL,$errors);
                    } elseif ($next == '>') {
                        $errors[] = array('XML_TAG_CLOSE_ANOMALY');
                        //					return array(NULL,$errors);
                    }
                    $current_attribute_value .= $next;
                }
                break;
            case IN_XML_TAG:
                if ($OUT[$POS - 2] == '?' && $next == '>') {
                    $status = NO_MANS_LAND;
                }
                break;
            case IN_DTD_TAG:
                // This is a parser-directive, but we only use them for doctypes
                $doc_type .= $next;
                if ($next == '>') {
                    if (substr($doc_type, 0, 8) == '!DOCTYPE') {
                        global $THE_DOCTYPE, $TAGS_DEPRECATE_ALLOW, $FOUND_DOCTYPE, $XML_CONSTRAIN, $BLOCK_CONSTRAIN;
                        $FOUND_DOCTYPE = true;
                        $valid_doctypes = array(DOCTYPE_HTML, DOCTYPE_HTML_STRICT, DOCTYPE_XHTML, DOCTYPE_XHTML_STRICT, DOCTYPE_XHTML_NEW);
                        /*if (get_value('html5')==='1') */
                        $valid_doctypes[] = DOCTYPE_XHTML5;
                        $doc_type = preg_replace('#//EN"\\s+"#', '//EN" "', $doc_type);
                        if (!in_array('<' . $doc_type, $valid_doctypes)) {
                            $errors[] = array('XHTML_DOCTYPE');
                        } else {
                            $THE_DOCTYPE = '<' . $doc_type;
                            if ($THE_DOCTYPE == DOCTYPE_HTML_STRICT || $THE_DOCTYPE == DOCTYPE_XHTML_STRICT || $THE_DOCTYPE == DOCTYPE_XHTML_NEW || $THE_DOCTYPE == DOCTYPE_XHTML5) {
                                $TAGS_DEPRECATE_ALLOW = false;
                            }
                            if ($THE_DOCTYPE == DOCTYPE_XHTML_STRICT || $THE_DOCTYPE == DOCTYPE_XHTML_NEW || $THE_DOCTYPE == DOCTYPE_XHTML5) {
                                $BLOCK_CONSTRAIN = true;
                            }
                            if ($THE_DOCTYPE == DOCTYPE_XHTML || $THE_DOCTYPE == DOCTYPE_XHTML_STRICT || $THE_DOCTYPE == DOCTYPE_XHTML_NEW || $THE_DOCTYPE == DOCTYPE_XHTML5) {
                                $XML_CONSTRAIN = true;
                            }
                        }
                    }
                    $status = NO_MANS_LAND;
                }
                break;
            case IN_CDATA:
                $INBETWEEN_TEXT .= $next;
                if ($next == '>' && $OUT[$POS - 2] == ']' && $OUT[$POS - 3] == ']') {
                    $status = NO_MANS_LAND;
                }
                break;
            case IN_COMMENT:
                $INBETWEEN_TEXT .= $next;
                if ($next == '>' && $OUT[$POS - 2] == '-' && $OUT[$POS - 3] == '-') {
                    if ($OUT[$POS - 4] == '-') {
                        $errors[] = array('XHTML_WRONG_COMMENTING');
                    }
                    $status = NO_MANS_LAND;
                }
                break;
            case IN_TAG_EMBEDDED_COMMENT:
                if ($next == '>' && $OUT[$POS - 2] == '-' && $OUT[$POS - 3] == '-') {
                    $status = IN_TAG_BETWEEN_ATTRIBUTES;
                }
                break;
        }
    }
    if ($status != NO_MANS_LAND) {
        $errors[] = array('XML_BROKEN_END');
        return array(NULL, $errors);
    }
    return NULL;
}
 /**
  * The actualiser to edit a comcode page.
  *
  * @return tempcode		The UI
  */
 function __ed()
 {
     $simple_add = get_param_integer('simple_add', 0) == 1;
     $title = get_page_title($simple_add ? 'COMCODE_PAGE_ADD' : 'COMCODE_PAGE_EDIT');
     $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/comcode_page_edit';
     $file = filter_naughty(post_param('file'));
     $lang = filter_naughty(post_param('lang'));
     $zone = filter_naughty(post_param('zone'));
     if (addon_installed('page_management')) {
         $new_file = filter_naughty(has_actual_page_access(get_member(), 'admin_sitetree') ? post_param('title', $file) : $file);
     } else {
         $new_file = filter_naughty($file);
     }
     if ($file == '') {
         $file = $new_file;
     }
     require_code('type_validation');
     if (!is_alphanumeric($file, true)) {
         warn_exit(do_lang_tempcode('BAD_CODENAME'));
     }
     $fullpath = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . $lang . '/' . $file . '.txt');
     $renaming_page = $new_file != $file;
     if ($renaming_page) {
         if (!is_alphanumeric($new_file, true)) {
             warn_exit(do_lang_tempcode('BAD_CODENAME'));
         }
         $langs = find_all_langs(true);
         $rename_map = array();
         $afm_needed = false;
         // Actually will stay false as we don't allow renaming original-pages at the moment
         foreach (array_keys($langs) as $lang) {
             $path = zone_black_magic_filterer(filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/comcode_custom/' . $lang . '/' . $file . '.txt', true);
             if (is_file(get_file_base() . '/' . $path)) {
                 $new_path = zone_black_magic_filterer(filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/comcode_custom/' . $lang . '/' . $new_file . '.txt', true);
                 if (is_file($new_path)) {
                     warn_exit(do_lang_tempcode('ALREADY_EXISTS', escape_html($zone . ':' . $new_file)));
                 }
                 $rename_map[$path] = $new_path;
             }
             if (is_file(get_file_base() . '/' . str_replace('/comcode_custom/', '/comcode/', $path))) {
                 $completion_text = do_lang_tempcode('ORIGINAL_PAGE_NO_RENAME');
             }
         }
         if ($afm_needed) {
             require_code('abstract_file_manager');
             force_have_afm_details();
         }
     }
     $validated = post_param_integer('validated', 0);
     if (!has_specific_permission(get_member(), 'bypass_validation_highrange_content')) {
         $validated = 0;
     }
     $parent_page = post_param('parent_page', '');
     $show_as_edit = post_param_integer('show_as_edit', 0);
     $resource_owner = $GLOBALS['SITE_DB']->query_value_null_ok('comcode_pages', 'p_submitter', array('the_zone' => $zone, 'the_page' => $file));
     check_edit_permission('high', $resource_owner);
     if ($GLOBALS['FORUM_DRIVER']->is_super_admin(get_member())) {
         $_owner = post_param('owner', $GLOBALS['FORUM_DRIVER']->get_username(get_member()));
         $owner = $GLOBALS['FORUM_DRIVER']->get_member_from_username($_owner);
         if (is_null($owner)) {
             $owner = get_member();
         }
     } else {
         $owner = get_member();
     }
     if (is_null($resource_owner)) {
         check_submit_permission('high');
         require_code('submit');
         give_submit_points('COMCODE_PAGE_ADD');
         if (!addon_installed('unvalidated')) {
             $validated = 1;
         }
         $GLOBALS['SITE_DB']->query_insert('comcode_pages', array('the_zone' => $zone, 'the_page' => $file, 'p_parent_page' => $parent_page, 'p_validated' => $validated, 'p_edit_date' => NULL, 'p_add_date' => time(), 'p_submitter' => $owner, 'p_show_as_edit' => 0));
     } else {
         if (!has_actual_page_access(get_member(), $file, $zone)) {
             access_denied('PAGE_ACCESS');
         }
         require_code('submit');
         $just_validated = !content_validated('comcode_page', $zone . ':' . $file) && $validated == 1;
         if ($just_validated) {
             send_content_validated_notification('comcode_page', $zone . ':' . $file);
         }
         if (!addon_installed('unvalidated')) {
             $validated = 1;
         }
         $GLOBALS['SITE_DB']->query_update('comcode_pages', array('p_parent_page' => $parent_page, 'p_validated' => $validated, 'p_edit_date' => time(), 'p_submitter' => $owner, 'p_show_as_edit' => $show_as_edit), array('the_zone' => $zone, 'the_page' => $file), '', 1);
     }
     if ($validated == 0) {
         require_code('submit');
         $edit_url = build_url(array('page' => '_SELF', 'type' => '_ed', 'page_link' => $zone . ':' . $new_file), '_SELF', NULL, false, false, true);
         if (addon_installed('unvalidated')) {
             send_validation_request('COMCODE_PAGE_EDIT', 'comcode_pages', true, $zone . ':' . $new_file, $edit_url);
         }
     }
     $new = post_param('post');
     require_code('attachments2');
     $_new = do_comcode_attachments($new, 'comcode_page', $zone . ':' . $file);
     $new = $_new['comcode'];
     if (!file_exists($fullpath) || $new != file_get_contents($fullpath, FILE_TEXT)) {
         $myfile = @fopen($fullpath, 'wt');
         if ($myfile === false) {
             intelligent_write_error($fullpath);
         }
         final_attachments_from_preview($zone . ':' . $file);
         if (fwrite($myfile, $new) < strlen($new)) {
             warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
         }
         fclose($myfile);
         sync_file($fullpath);
         $file_changed = true;
     } else {
         $file_changed = false;
     }
     require_code('seo2');
     $new_keywords = post_param('meta_keywords', '');
     $new_description = post_param('meta_description', '');
     if ($new_keywords == '' && $new_description == '') {
         seo_meta_set_for_implicit('comcode_page', $zone . ':' . $file, array($new), $new);
     } else {
         seo_meta_set_for_explicit('comcode_page', $zone . ':' . $file, $new_keywords, $new_description);
     }
     $completion_text = $validated == 0 ? do_lang_tempcode('SUBMIT_UNVALIDATED') : do_lang_tempcode('SUCCESS');
     // Update cache  NO WE CAN'T - THEY'RE MULTI-THEME NOW
     /*	$string_index=$GLOBALS['SITE_DB']->query_value_null_ok('cached_comcode_pages','string_index',array('the_zone'=>$zone,'the_page'=>$file));
     		if (!is_null($string_index))
     		{
     			lang_remap_comcode($string_index,$new);
     		} else
     		{
     			$string_index=insert_lang_comcode($new,1,NULL,false,NULL,NULL,false,NULL,NULL,60,true,true);
     			$GLOBALS['SITE_DB']->query_insert('cached_comcode_pages',array('the_zone'=>$zone,'the_page'=>$file,'string_index'=>$string_index));
     		}*/
     require_code('permissions2');
     set_page_permissions_from_environment($zone, $file);
     $caches = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages', array('string_index'), array('the_zone' => $zone, 'the_page' => $file));
     $GLOBALS['SITE_DB']->query_delete('cached_comcode_pages', array('the_zone' => $zone, 'the_page' => $file));
     foreach ($caches as $cache) {
         delete_lang($cache['string_index']);
     }
     persistant_cache_empty();
     persistant_cache_delete(array('PAGE_INFO'));
     decache('main_comcode_page_children');
     fix_permissions($fullpath);
     if (is_file($fullpath) && get_option('store_revisions') == '1' && $file_changed) {
         $time = time();
         @copy($fullpath, $fullpath . '.' . strval($time)) or intelligent_write_error($fullpath . '.' . strval($time));
         fix_permissions($fullpath . '.' . strval($time));
         sync_file($fullpath . '.' . strval($time));
     }
     log_it('COMCODE_PAGE_EDIT', $file, $zone);
     require_code('autosave');
     clear_ocp_autosave();
     if ($renaming_page) {
         $GLOBALS['SITE_DB']->query_delete('comcode_pages', array('the_zone' => $zone, 'the_page' => $new_file), '', 1);
         $GLOBALS['SITE_DB']->query_update('comcode_pages', array('the_page' => $new_file), array('the_zone' => $zone, 'the_page' => $file), '', 1);
         $GLOBALS['SITE_DB']->query_update('comcode_pages', array('p_parent_page' => $new_file), array('the_zone' => $zone, 'p_parent_page' => $file));
         foreach ($rename_map as $path => $new_path) {
             if ($afm_needed) {
                 afm_move($path, $new_path);
             } else {
                 rename(get_custom_file_base() . '/' . $path, get_custom_file_base() . '/' . $new_path);
             }
         }
         if (addon_installed('awards')) {
             $types = $GLOBALS['SITE_DB']->query_select('award_types', array('id'), array('a_content_type' => 'comcode_page'));
             foreach ($types as $type) {
                 $GLOBALS['SITE_DB']->query_update('award_archive', array('content_id' => $new_file), array('content_id' => $file, 'a_type_id' => $type['id']));
             }
         }
         $file = $new_file;
     }
     if (post_param_integer('delete', 0) == 1) {
         unlink(get_custom_file_base() . '/' . $path);
     }
     if (addon_installed('awards')) {
         require_code('awards');
         handle_award_setting('comcode_page', $zone . ':' . $file);
     }
     decache('main_sitemap');
     breadcrumb_set_self(do_lang_tempcode('DONE'));
     // Look for bad title semantics
     $_new['html'] = $_new['tempcode']->evaluate();
     if (substr($file, 0, 1) != '_' && substr($file, 0, 6) != 'panel_' && trim($_new['html']) != '') {
         if (strpos($_new['html'], '<h1') === false && strpos($_new['comcode'], '[title]') === false && strpos($_new['comcode'], '[title="1"]') === false) {
             attach_message(do_lang_tempcode('NO_LEVEL_1_HEADERS'), 'notice');
         }
         $matches = array();
         if (strpos($_new['html'], '<h2') === false && preg_match_all('#\\n\\[(b|font|size)\\][^\\.]+\\[/(b|font|size)\\]\\n#', $_new['comcode'], $matches) >= 2) {
             attach_message(do_lang_tempcode('NO_LEVEL_2_HEADERS'), 'inform');
         }
     }
     // Show it worked / Refresh
     $url = post_param('redirect', '');
     if ($url != '') {
         return redirect_screen($title, $url, $completion_text);
     }
     return $this->do_next_manager($title, $file, $zone, $completion_text);
 }
Beispiel #17
0
 /**
  * The UI for the add-new-page wizard (choose which menu to add it to, and what title to give it - or choose not to add to a menu).
  *
  * @return tempcode		The UI
  */
 function _page_wizard()
 {
     $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/addpagewizard';
     $GLOBALS['HELPER_PANEL_TUTORIAL'] = 'tut_comcode_pages';
     $title = get_page_title('PAGE_WIZARD_STEP', true, array(integer_format(2), integer_format(3)));
     $zone = post_param('zone', '');
     breadcrumb_set_parents(array(array('_SELF:_SELF:pagewizard', do_lang_tempcode('PAGE_WIZARD'))));
     breadcrumb_set_self(do_lang_tempcode('DETAILS'));
     require_code('type_validation');
     if (!is_alphanumeric(str_replace(':', '', post_param('name')), true)) {
         warn_exit(do_lang_tempcode('BAD_CODENAME'));
     }
     $zones = find_all_zones(false, true);
     $pages = array();
     foreach ($zones as $_zone) {
         $pages[$_zone[0]] = find_all_pages_wrap($_zone[0], true);
     }
     require_code('form_templates');
     $rows = $GLOBALS['SITE_DB']->query_select('menu_items', array('DISTINCT i_menu'), NULL, 'ORDER BY i_menu');
     $list = new ocp_tempcode();
     $list2 = new ocp_tempcode();
     $list->attach(form_input_list_entry(STRING_MAGIC_NULL, false, do_lang_tempcode('NA_EM')));
     $list->attach(form_input_list_entry('', false, '', false, true));
     // See if we can discern nice names for the menus, to help relate them
     foreach ($rows as $row) {
         $menu_name = make_string_tempcode(escape_html($row['i_menu']));
         $found = false;
         foreach ($pages as $zone_under => $under) {
             foreach ($under as $filename => $type) {
                 if (substr(strtolower($filename), -4) == '.txt') {
                     $matches = array();
                     $path = zone_black_magic_filterer((substr($type, 0, 15) == 'comcode_custom/' ? get_custom_file_base() : get_file_base()) . '/' . ($zone_under == '' ? '' : $zone_under . '/') . 'pages/' . $type . '/' . $filename);
                     if (!file_exists($path)) {
                         $path = zone_black_magic_filterer(get_file_base() . '/' . ($zone_under == '' ? '' : $zone_under . '/') . 'pages/' . $type . '/' . $filename);
                     }
                     $contents = '';
                     if (file_exists($path)) {
                         $contents .= file_get_contents($path);
                     } else {
                         $fallback = zone_black_magic_filterer(get_file_base() . '/' . ($zone_under == '' ? '' : $zone_under . '/') . 'pages/comcode/' . fallback_lang() . '/' . $filename);
                         if (file_exists($fallback)) {
                             $contents .= file_get_contents($fallback);
                         }
                     }
                     if (preg_match('#\\[block="' . str_replace('#', '\\#', preg_quote($row['i_menu'])) . '"[^\\]]* caption="([^"]*)"[^\\]]*\\]side_stored_menu\\[/block\\]#', $contents, $matches) != 0) {
                         $zone_title = preg_replace('# ' . str_replace('#', '\\#', preg_quote(do_lang('ZONE'))) . '$#', '', $zones[$zone_under][1]);
                         $menu_name = do_lang_tempcode('MENU_FULL_DETAILS', $menu_name, make_string_tempcode(escape_html($matches[1])), make_string_tempcode(escape_html($zone_title)));
                         $found = true;
                         break 2;
                     }
                 }
             }
         }
         $selected = $zone == 'forum' && $row['i_menu'] == 'forum_features' || $zone == 'collaboration' && $row['i_menu'] == 'collab_website' || ($zone == 'site' || $zone == '' && get_option('collapse_user_zones') == '1') && ($row['i_menu'] == 'site' || $row['i_menu'] == 'main_website') || $zone == '' && $row['i_menu'] == 'root_website';
         if ($found) {
             $list->attach(form_input_list_entry($row['i_menu'], $selected, $menu_name));
         } else {
             $list2->attach(form_input_list_entry($row['i_menu'], false, $row['i_menu'] == 'zone_menu' ? $menu_name : do_lang('MENU_UNUSED', $menu_name)));
         }
     }
     if (!$list2->is_empty()) {
         $list->attach(form_input_list_entry('', false, '', false, true));
         $list->attach($list2);
     }
     // Now see if there are any menus pending creation
     foreach ($pages as $zone_under => $under) {
         foreach ($under as $filename => $type) {
             if (substr(strtolower($filename), -4) == '.txt') {
                 $matches = array();
                 $path = zone_black_magic_filterer((substr($type, 0, 15) == 'comcode_custom/' ? get_custom_file_base() : get_file_base()) . '/' . ($zone_under == '' ? '' : $zone_under . '/') . 'pages/' . $type . '/' . $filename);
                 if (!file_exists($path)) {
                     $path = zone_black_magic_filterer(get_file_base() . '/' . ($zone_under == '' ? '' : $zone_under . '/') . 'pages/' . $type . '/' . $filename);
                 }
                 $contents = '';
                 if (file_exists($path)) {
                     $contents .= file_get_contents($path);
                 } else {
                     $fallback = zone_black_magic_filterer(get_file_base() . '/' . ($zone_under == '' ? '' : $zone_under . '/') . 'pages/comcode/' . fallback_lang() . '/' . $filename);
                     if (file_exists($fallback)) {
                         $contents .= file_get_contents($fallback);
                     }
                 }
                 $num_matches = preg_match_all('#\\[block="([^"]*)"[^\\]]* caption="([^"]*)"[^\\]]*\\]side_stored_menu\\[/block\\]#', $contents, $matches);
                 for ($i = 0; $i < $num_matches; $i++) {
                     $menu_name = $matches[1][$i];
                     foreach ($rows as $row) {
                         if ($row['i_menu'] == $menu_name) {
                             continue 2;
                         }
                     }
                     $zone_title = $zones[$zone_under][1];
                     $menu_name = do_lang_tempcode('MENU_FULL_DETAILS', $menu_name, make_string_tempcode(escape_html($matches[2][$i])), make_string_tempcode(escape_html($zone_title)));
                     $list->attach(form_input_list_entry($matches[1][$i], $selected, $menu_name));
                 }
             }
         }
     }
     $fields = new ocp_tempcode();
     $fields->attach(form_input_list(do_lang_tempcode('MENU'), do_lang_tempcode('MENU_TO_ADD_TO'), 'menu', $list, NULL, true));
     $fields->attach(form_input_line(do_lang_tempcode('TITLE'), do_lang_tempcode('DESCRIPTION_MENU_TITLE'), 'title', ucwords(str_replace('_', ' ', post_param('name'))), true));
     $post_url = build_url(array('page' => 'cms_comcode_pages', 'type' => '_ed', 'simple_add' => 1), get_module_zone('cms_comcode_pages'));
     $submit_name = do_lang_tempcode('PROCEED');
     $hidden = new ocp_tempcode();
     $hidden->attach(form_input_hidden('page_link', $zone . ':' . post_param('name')));
     return do_template('FORM_SCREEN', array('_GUID' => '3281970772c410cf071c422792d1571d', 'GET' => true, 'SKIP_VALIDATION' => true, 'TITLE' => $title, 'HIDDEN' => $hidden, 'TEXT' => '', 'FIELDS' => $fields, 'URL' => $post_url, 'SUBMIT_NAME' => $submit_name));
 }
 /**
  * UI for a theme wizard step (actualisation).
  *
  * @return tempcode		The UI
  */
 function step4()
 {
     // Add theme
     $source_theme = post_param('source_theme');
     $algorithm = post_param('algorithm');
     $seed = post_param('seed');
     $themename = post_param('themename');
     $use = post_param_integer('use_on_all', 0) == 1;
     $dark = post_param_integer('dark');
     $inherit_css = post_param_integer('inherit_css');
     if (function_exists('set_time_limit')) {
         @set_time_limit(0);
     }
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('THEMEWIZARD'))));
     require_code('type_validation');
     if (!is_alphanumeric($themename, true) || strlen($themename) > 40) {
         warn_exit(do_lang_tempcode('BAD_CODENAME'));
     }
     make_theme($themename, $source_theme, $algorithm, $seed, $use, $dark == 1, $inherit_css == 1);
     $myfile = @fopen(get_custom_file_base() . '/themes/' . filter_naughty($themename) . '/theme.ini', 'wt') or intelligent_write_error(get_custom_file_base() . '/themes/' . filter_naughty($themename) . '/theme.ini');
     fwrite($myfile, 'title=' . $themename . chr(10));
     fwrite($myfile, 'description=' . do_lang('NA') . chr(10));
     fwrite($myfile, 'seed=' . $seed . chr(10));
     if (fwrite($myfile, 'author=' . $GLOBALS['FORUM_DRIVER']->get_username(get_member()) . chr(10)) == 0) {
         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
     }
     fclose($myfile);
     sync_file('themes/' . filter_naughty($themename) . '/theme.ini');
     // We're done
     $title = get_page_title('_THEMEWIZARD', true, array(integer_format(4), integer_format(4)));
     $message = do_lang_tempcode('THEMEWIZARD_4_DESCRIBE', escape_html('#' . $seed), escape_html($themename));
     require_code('templates_donext');
     return do_next_manager($title, $message, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, array(), array(), array(array('edit_this', array('admin_themes', array('type' => 'edit_theme', 'theme' => $themename), get_module_zone('admin_themes'))), array('edit_css', array('admin_themes', array('type' => 'choose_css', 'theme' => $themename), get_module_zone('admin_themes'))), array('edit_templates', array('admin_themes', array('type' => 'edit_templates', 'theme' => $themename), get_module_zone('admin_themes'))), array('manage_images', array('admin_themes', array('type' => 'manage_images', 'theme' => $themename), get_module_zone('admin_themes'))), array('manage_themes', array('admin_themes', array('type' => 'misc'), get_module_zone('admin_themes')))), do_lang('THEME'));
 }
 /**
  * Standard aed_module edit actualiser.
  *
  * @param  ID_TEXT		The entry being edited
  */
 function edit_actualisation($id)
 {
     $tag = post_param('tag');
     require_code('type_validation');
     if (!is_alphanumeric($tag, true)) {
         warn_exit(do_lang_tempcode('BAD_CODENAME'));
     }
     global $VALID_COMCODE_TAGS;
     $test = $GLOBALS['SITE_DB']->query_value_null_ok('custom_comcode', 'tag_tag', array('tag_tag' => $tag));
     if ($id == $tag) {
         $test = NULL;
     }
     if (array_key_exists($tag, $VALID_COMCODE_TAGS) || !is_null($test)) {
         warn_exit(do_lang_tempcode('ALREADY_EXISTS', escape_html($tag)));
     }
     $old = $GLOBALS['SITE_DB']->query_select('custom_comcode', array('tag_title', 'tag_description'), array('tag_tag' => $id), '', 1);
     if (!array_key_exists(0, $old)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $_title = $old[0]['tag_title'];
     $_description = $old[0]['tag_description'];
     $GLOBALS['SITE_DB']->query_update('custom_comcode', array('tag_tag' => $tag, 'tag_title' => lang_remap($_title, post_param('title')), 'tag_description' => lang_remap($_description, post_param('description')), 'tag_replace' => post_param('replace'), 'tag_example' => post_param('example'), 'tag_parameters' => post_param('parameters'), 'tag_enabled' => post_param_integer('enabled', 0), 'tag_dangerous_tag' => post_param_integer('dangerous_tag', 0), 'tag_block_tag' => post_param_integer('block_tag', 0), 'tag_textual_tag' => post_param_integer('textual_tag', 0)), array('tag_tag' => $id), '', 1);
     $this->new_id = $tag;
     log_it('EDIT_' . $this->lang_type, $id);
 }
Beispiel #20
0
 public static function updateId($obj, $tblname, $field_name = 'id')
 {
     if (!is_alphanumeric($tblname) || !is_alphanumeric($field_name)) {
         throw new \Exception('very bad');
     }
     if (!$obj->{$field_name}) {
         d($obj);
         throw new \Exception('eehh');
     }
     $reflect = self::reflectQuery($obj, $field_name);
     $q = 'UPDATE ' . $tblname . ' SET ' . implode(', ', $reflect->cols) . ' WHERE ' . $field_name . ' = ?';
     $reflect->str .= is_numeric($obj->{$field_name}) ? 'i' : 's';
     $reflect->vals[] = $obj->{$field_name};
     return Sql::pUpdate($q, $reflect->str, $reflect->vals);
 }
Beispiel #21
0
 /**
  * The UI to translate code.
  *
  * @return tempcode		The UI
  */
 function interface_code()
 {
     $lang = filter_naughty_harsh(get_param('lang', ''));
     $lang_new = get_param('lang_new', $lang);
     if ($lang_new != '') {
         require_code('type_validation');
         if (!is_alphanumeric($lang_new, true)) {
             warn_exit(do_lang_tempcode('BAD_CODENAME'));
         }
         if (strlen($lang_new) > 5) {
             warn_exit(do_lang_tempcode('INVALID_LANG_CODE'));
         }
         $lang = $lang_new;
     }
     if ($lang == '') {
         $title = get_page_title('TRANSLATE_CODE');
         $GLOBALS['HELPER_PANEL_TEXT'] = comcode_lang_string('DOC_FIND_LANG_STRING_TIP');
         return $this->choose_lang($title, true, true, do_lang_tempcode('CHOOSE_EDIT_LIST_LANG_FILE'));
     }
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('CHOOSE'))));
     breadcrumb_set_self(do_lang_tempcode('TRANSLATE_CODE'));
     $base_lang = fallback_lang();
     $map_a = get_file_base() . '/lang/langs.ini';
     $map_b = get_custom_file_base() . '/lang_custom/langs.ini';
     $search = get_param('search', '', true);
     if ($search != '') {
         $title = get_page_title('TRANSLATE_CODE');
         require_code('form_templates');
         $fields = new ocp_tempcode();
         global $LANGUAGE;
         foreach ($LANGUAGE[user_lang()] as $key => $value) {
             if (strpos(strtolower($value), strtolower($search)) !== false) {
                 $fields->attach(form_input_text($key, '', 'l_' . $key, str_replace('\\n', chr(10), $value), false));
             }
         }
         if ($fields->is_empty()) {
             inform_exit(do_lang_tempcode('NO_ENTRIES'));
         }
         $post_url = build_url(array('page' => '_SELF', 'type' => '_code2'), '_SELF');
         $hidden = new ocp_tempcode();
         $hidden->attach(form_input_hidden('redirect', get_self_url(true)));
         $hidden->attach(form_input_hidden('lang', $lang));
         return do_template('FORM_SCREEN', array('_GUID' => '2d7356fd2c4497ceb19450e65331c9c5', 'TITLE' => $title, 'HIDDEN' => $hidden, 'FIELDS' => $fields, 'URL' => $post_url, 'TEXT' => '', 'SUBMIT_NAME' => do_lang('TRANSLATE_CODE')));
     }
     $lang_file = get_param('lang_file');
     if (!file_exists($map_b)) {
         $map_b = $map_a;
     }
     $map = better_parse_ini_file($map_b);
     $title = get_page_title('_TRANSLATE_CODE', true, array(escape_html($lang_file), escape_html(array_key_exists($lang, $map) ? $map[$lang] : $lang)));
     // Upgrade to custom if not there yet (or maybe we are creating a new lang - same difference)
     $custom_dir = get_custom_file_base() . '/lang_custom/' . $lang;
     if (!file_exists($custom_dir)) {
         require_code('abstract_file_manager');
         force_have_afm_details();
         afm_make_directory('lang_custom/' . $lang, true);
         $cached_dir = get_custom_file_base() . '/lang_cached/' . $lang;
         if (!file_exists($cached_dir)) {
             afm_make_directory('lang_cached/' . $lang, true);
         }
         // Make comcode page dirs
         $zones = find_all_zones();
         foreach ($zones as $zone) {
             $_special_dir = get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . $lang;
             if (!file_exists($_special_dir)) {
                 afm_make_directory($zone . ($zone == '' ? '' : '/') . 'pages/comcode_custom/' . $lang, true);
             }
             $_special_dir = get_custom_file_base() . '/' . $zone . '/pages/html_custom/' . $lang;
             if (!file_exists($_special_dir)) {
                 afm_make_directory($zone . ($zone == '' ? '' : '/') . 'pages/html_custom/' . $lang, true);
             }
         }
         // Make templates_cached dirs
         require_code('themes2');
         $themes = find_all_themes();
         foreach (array_keys($themes) as $theme) {
             $_special_dir = get_custom_file_base() . '/themes/' . $theme . '/templates_cached/' . $lang;
             if (!file_exists($_special_dir)) {
                 afm_make_directory('themes/' . $theme . '/templates_cached/' . $lang, true);
             }
         }
     }
     // Get some stuff
     $for_lang = get_lang_file_map($lang, $lang_file);
     $for_base_lang = get_lang_file_map($base_lang, $lang_file, true);
     $descriptions = get_lang_file_descriptions($base_lang, $lang_file);
     // Make our translation page
     $lines = '';
     $intertrans = $this->get_intertran_conv($lang);
     $actions = new ocp_tempcode();
     $next = 0;
     $trans_lot = '';
     $delimit = chr(10) . '=-=-=-=-=-=-=-=-' . chr(10);
     foreach ($for_base_lang as $name => $old) {
         if (array_key_exists($name, $for_lang)) {
             $current = $for_lang[$name];
         } else {
             $current = '';
             //$this->find_lang_matches($old,$lang); Too slow / useless for code translation
         }
         if ($current == '' && strtolower($name) != $name) {
             $trans_lot .= str_replace('\\n', chr(10), str_replace(array('{', '}'), array('(((', ')))'), $old)) . $delimit;
         }
     }
     $translated_stuff = array();
     if ($trans_lot != '' && $intertrans != '') {
         $result = http_download_file('http://translate.google.com/translate_t', NULL, false, false, 'ocPortal', array('text' => $trans_lot, 'langpair' => 'en|' . $intertrans));
         if (!is_null($result)) {
             require_code('character_sets');
             $result = convert_to_internal_encoding($result);
             $matches = array();
             if (preg_match('#<div id=result_box dir="ltr">(.*)</div>#Us', convert_to_internal_encoding($result), $matches) != 0) {
                 $result2 = $matches[1];
                 $result2 = @html_entity_decode($result2, ENT_QUOTES, get_charset());
                 $result2 = preg_replace('#\\s?<br>\\s?#', chr(10), $result2);
                 $result2 = str_replace('> ', '>', str_replace(' <', ' <', str_replace('</ ', '</', str_replace(array('(((', ')))'), array('{', '}'), $result2))));
                 $translated_stuff = explode(trim($delimit), $result2 . chr(10));
             }
         }
     }
     foreach ($for_base_lang + $for_lang as $name => $old) {
         if (array_key_exists($name, $for_lang)) {
             $current = $for_lang[$name];
         } else {
             $current = '';
             //$this->find_lang_matches($old,$lang); Too slow / useless for code translation
         }
         $description = array_key_exists($name, $descriptions) ? $descriptions[$name] : '';
         if ($current == '' && strtolower($name) != $name && array_key_exists($next, $translated_stuff)) {
             $_current = '';
             $translate_auto = trim($translated_stuff[$next]);
             $next++;
         } else {
             $_current = str_replace('\\n', chr(10), $current);
             $translate_auto = NULL;
         }
         if ($_current == '') {
             $_current = str_replace('\\n', chr(10), $old);
         }
         if ($intertrans != '' && get_value('google_translate_api_key') !== NULL) {
             $actions = do_template('TRANSLATE_ACTION', array('_GUID' => '9e9a68cb2c1a1e23a901b84c9af2280b', 'LANG_FROM' => get_site_default_lang(), 'LANG_TO' => $lang, 'NAME' => 'trans_' . $name, 'OLD' => $_current));
         }
         $temp = do_template('TRANSLATE_LINE', array('_GUID' => '9cb331f5852ee043e6ad30b45aedc43b', 'TRANSLATE_AUTO' => $translate_auto, 'DESCRIPTION' => $description, 'NAME' => $name, 'OLD' => str_replace('\\n', chr(10), $old), 'CURRENT' => $_current, 'ACTIONS' => $actions));
         $lines .= $temp->evaluate();
     }
     $url = build_url(array('page' => '_SELF', 'type' => '_code', 'lang_file' => $lang_file, 'lang' => $lang), '_SELF');
     return do_template('TRANSLATE_SCREEN', array('_GUID' => 'b3429f8bd0b4eb79c33709ca43e3207c', 'PAGE' => $lang_file, 'INTERTRANS' => get_value('google_translate_api_key') !== NULL ? $intertrans : '', 'LANG' => $lang, 'LINES' => $lines, 'TITLE' => $title, 'URL' => $url));
 }
Beispiel #22
0
/**
 * Edit a catalogue.
 *
 * @param  ID_TEXT			The current name of the catalogue
 * @param  ID_TEXT			The new name of the catalogue
 * @param  SHORT_TEXT		The human readable name/title of the catalogue
 * @param  LONG_TEXT			The description
 * @param  SHORT_INTEGER	The display type
 * @param  LONG_TEXT			Admin notes
 * @param  integer			How many points are given to a member that submits to the catalogue
 * @param  BINARY				Whether the catalogue is an eCommerce catalogue
 * @param  ID_TEXT			How to send view reports
 * @set    never daily weekly monthly quarterly
 */
function actual_edit_catalogue($old_name, $name, $title, $description, $display_type, $notes, $submit_points, $ecommerce, $send_view_reports)
{
    if ($old_name != $name) {
        // Check doesn't already exist
        $test = $GLOBALS['SITE_DB']->query_value_null_ok('catalogues', 'c_name', array('c_name' => $name));
        if (!is_null($test)) {
            warn_exit(do_lang_tempcode('ALREADY_EXISTS', escape_html($name)));
        }
        require_code('type_validation');
        if (!is_alphanumeric($name, true)) {
            warn_exit(do_lang_tempcode('BAD_CODENAME'));
        }
    }
    $rows = $GLOBALS['SITE_DB']->query_select('catalogues', array('c_description', 'c_title'), array('c_name' => $old_name), '', 1);
    if (!array_key_exists(0, $rows)) {
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    $myrow = $rows[0];
    $_title = $myrow['c_title'];
    $_description = $myrow['c_description'];
    // Edit
    $GLOBALS['SITE_DB']->query_update('catalogues', array('c_send_view_reports' => $send_view_reports, 'c_display_type' => $display_type, 'c_ecommerce' => $ecommerce, 'c_name' => $name, 'c_title' => lang_remap($_title, $title), 'c_description' => lang_remap_comcode($_description, $description), 'c_notes' => $notes, 'c_add_date' => time(), 'c_submit_points' => $submit_points), array('c_name' => $old_name), '', 1);
    // If we're renaming, then we better change a load of references
    if ($name != $old_name) {
        $GLOBALS['SITE_DB']->query_update('catalogue_categories', array('c_name' => $name), array('c_name' => $old_name));
        $GLOBALS['SITE_DB']->query_update('catalogue_fields', array('c_name' => $name), array('c_name' => $old_name));
        $GLOBALS['SITE_DB']->query_update('catalogue_entries', array('c_name' => $name), array('c_name' => $old_name));
        if (addon_installed('awards')) {
            $types = $GLOBALS['SITE_DB']->query_select('award_types', array('id'), array('a_content_type' => 'catalogue'));
            foreach ($types as $type) {
                $GLOBALS['SITE_DB']->query_update('award_archive', array('content_id' => $name), array('content_id' => $old_name, 'a_type_id' => $type['id']));
            }
        }
    }
    decache('main_cc_embed');
    decache('main_recent_cc_entries');
    log_it('EDIT_CATALOGUE', $name);
}