function init() { load_theme_textdomain('p2', get_template_directory() . '/languages'); add_filter('the_content', 'make_clickable'); if (isset($_REQUEST['p2ajax'])) { require_once P2_INC_PATH . '/ajax.php'; P2Ajax::dispatch(); die; } if (function_exists('is_site_admin') && !is_site_admin()) { return; } $is_media_upload = isset($_REQUEST['p2-upload']); // don't redirect to https version when uploading files, since the domain may be different // and we don't have SSL certificates for blog domain, only for admin if ($is_media_upload && isset($GLOBALS['pagenow']) && 'media-upload.php' == $GLOBALS['pagenow']) { force_ssl_admin(is_ssl()); add_filter('get_user_option_use_ssl', returner(false)); } if ($is_media_upload) { add_filter('flash_uploader', returner(false)); add_filter('auth_redirect_scheme', returner('logged_in')); add_filter('admin_url', array('P2', 'url_filter')); add_filter('includes_url', array('P2', 'url_filter')); add_filter('script_loader_src', array('P2', 'url_filter')); add_filter('wp_get_attachment_url', lambda('$url', 'str_replace(get_bloginfo("url")."/", site_url("/"), $url);'), 11); add_filter('media_upload_form_url', lambda('$url', 'add_query_arg( array( "p2-upload" => "true" ), $url );')); } }
function single($project_path) { $project = GP::$project->by_path($project_path); if (!$project) { gp_tmpl_404(); } $sub_projects = $project->sub_projects(); $translation_sets = GP::$translation_set->by_project_id($project->id); usort($translation_sets, lambda('$a, $b', 'strcmp($a->name_with_locale(), $b->name_with_locale());')); $title = sprintf(__('%s project '), esc_html($project->name)); $can_write = $this->can('write', 'project', $project->id); gp_tmpl_load('project', get_defined_vars()); }
<?php gp_title(sprintf(__('Translations < %s < %s < GlotPress'), $translation_set->name, $project->name)); gp_breadcrumb(array(gp_project_links_from_root($project), gp_link_get($url, $translation_set->name))); wp_enqueue_script('jquery-ui'); wp_enqueue_script('editor'); wp_enqueue_script('translations-page'); wp_localize_script('translations-page', '$gp_translations_options', array('sort' => __('Sort'), 'filter' => __('Filter'))); // localizer adds var in front of the variable name, so we can't use $gp.editor.options $editor_options = compact('can_approve', 'can_write', 'url', 'discard_warning_url', 'set_priority_url', 'set_status_url'); wp_localize_script('editor', '$gp_editor_options', $editor_options); add_action('gp_head', lambda('', 'gp_preferred_sans_serif_style_tag($locale);', compact('locale'))); gp_tmpl_header(); $i = 0; ?> <h2> <?php printf(__("Translation of %s"), esc_html($project->name)); ?> : <span><?php echo esc_html($translation_set->name); ?> </span> <?php gp_link_set_edit($translation_set, $project, __('Edit'), array('class' => 'btn btn-xs btn-primary')); ?> <?php if ($glossary) { echo gp_link(gp_url_project_locale($project, $locale->slug, $translation_set->slug) . '/glossary', __('glossary'), array('class' => 'btn btn-xs btn-primary'));
} } return $verdict; } function construct_error_message($rule, $value) { // TODO: better error messages, should include info from callback return sprintf(__('The field <strong>%s</strong> has invalid value!'), $rule['field'], $value); } } class GP_Validators { static $callbacks = array(); static function register($key, $callback, $negative_callback = null) { // TODO: add data for easier generation of error messages self::$callbacks[$key] = array('positive' => $callback, 'negative' => $negative_callback); } static function unregister($key) { unset(self::$callbacks[$key]); } static function get($key) { return gp_array_get(self::$callbacks, $key, null); } } GP_Validators::register('empty', lambda('$value', 'empty($value)')); GP_Validators::register('positive_int', lambda('$value', '((int)$value > 0)')); GP_Validators::register('null', lambda('$value', 'is_null($value)'));
function OTest() { /* O(5)->times(function ($i) { echo($i . "\n"); }); O(3)->times(function ($i) { echo($i . "\n"); }); */ $arr = array("Hello", "There", "what", "DAY", "iS", "iT"); $b = O($arr)->exists(Characters::$isLowerCase); var_dump($b); $arr = array(97, 44, 67, 3, 22, 90, 1, 77, 98, 1078, 6, 64, 6, 79, 42); $arr2 = O($arr)->filter(function ($v) { return $v % 2 == 0; }); print_r($arr2); $arr2 = o($arr)->filter(lambda('$v -> $v % 2 == 1')); print_r($arr2); }
function for_translation($project, $translation_set, $page, $filters = array(), $sort = array()) { global $gpdb; $locale = GP_Locales::by_slug($translation_set->locale); $status_cond = ''; $sort_bys = array('original' => 'o.singular', 'translation' => 't.translation_0', 'priority' => 'o.priority', 'random' => 'RAND()', 'translation_date_added' => 't.date_added', 'original_date_added' => 'o.date_added', 'references' => 'o.references'); $sort_by = gp_array_get($sort_bys, gp_array_get($sort, 'by'), 'o.date_added'); $sort_hows = array('asc' => 'ASC', 'desc' => 'DESC'); $sort_how = gp_array_get($sort_hows, gp_array_get($sort, 'how'), 'DESC'); $where = array(); if (gp_array_get($filters, 'term')) { // if the first letters is s, %%s is causing db::prepare trouble, capital S doesn't $no_leading_s_term = preg_replace('/^s/', 'S', $filters['term']); $like = "LIKE '%%" . $this->like_escape_printf($gpdb->escape($no_leading_s_term)) . "%%'"; $where[] = '(' . implode(' OR ', array_map(lambda('$x', '"($x $like)"', compact('like')), array('o.singular', 't.translation_0', 'o.plural', 't.translation_1'))) . ')'; } if ('yes' == gp_array_get($filters, 'translated')) { $where[] = 't.translation_0 IS NOT NULL'; } elseif ('no' == gp_array_get($filters, 'translated')) { $where[] = 't.translation_0 IS NULL'; } if (gp_array_get($filters, 'before_date_added')) { $where[] = $gpdb->prepare('t.date_added > %s', gp_array_get($filters, 'before_date_added')); } if (gp_array_get($filters, 'translation_id')) { $where[] = $gpdb->prepare('t.id = %d', gp_array_get($filters, 'translation_id')); } if (gp_array_get($filters, 'original_id')) { $where[] = $gpdb->prepare('o.id = %d', gp_array_get($filters, 'original_id')); } if ('yes' == gp_array_get($filters, 'warnings')) { $where[] = 't.warnings IS NOT NULL'; } elseif ('no' == gp_array_get($filters, 'warnings')) { $where[] = 't.warnings IS NULL'; } $join_where = array(); $status = gp_array_get($filters, 'status', 'current_or_waiting'); $all_in = true; $statuses = explode('_or_', $status); foreach ($statuses as $single_status) { if (!in_array($single_status, $this->get_static('statuses'))) { $all_in = false; break; } } if ($all_in) { $statuses_where = array(); foreach ($statuses as $single_status) { $statuses_where[] = $gpdb->prepare('t.status = %s', $single_status); } $statuses_where = '(' . implode(' OR ', $statuses_where) . ')'; $join_where[] = $statuses_where; /* usually we want the status to be part of the ON clause, because we want to include the untranslated strings in the listing. This, however is not the case if the filter explictly forbids untranslated strings */ if ('no' == gp_array_get($filters, 'translated')) { $where[] = $statuses_where; } } $where = implode(' AND ', $where); if ($where) { $where = 'AND ' . $where; } $join_where = implode(' AND ', $join_where); if ($join_where) { $join_where = 'AND ' . $join_where; } $limit = $this->sql_limit_for_paging($page); $rows = $this->many_no_map("\n\t\t SELECT SQL_CALC_FOUND_ROWS t.*, o.*, t.id as id, o.id as original_id, t.status as translation_status, o.status as original_status, t.date_added as translation_added, o.date_added as original_added\n\t\t FROM {$gpdb->originals} as o\n\t\t LEFT JOIN {$gpdb->translations} AS t ON o.id = t.original_id AND t.translation_set_id = %d {$join_where}\n\t\t WHERE o.project_id = %d AND o.status LIKE '+%%' {$where} ORDER BY {$sort_by} {$sort_how} {$limit}", $translation_set->id, $project->id); $this->found_rows = $this->found_rows(); $translations = array(); foreach ($rows as $row) { if ($row->user_id && $this->per_page != 'no-limit') { $user = GP::$user->get($row->user_id); if ($user) { $row->user_login = $user->user_login; } } else { $row->user_login = ''; } $row->translations = array($row->translation_0, $row->translation_1, $row->translation_2, $row->translation_3); $row->translations = array_slice($row->translations, 0, $locale->nplurals); $row->references = preg_split('/\\s+/', $row->references, -1, PREG_SPLIT_NO_EMPTY); $row->extracted_comment = $row->comment; $row->warnings = $row->warnings ? maybe_unserialize($row->warnings) : null; unset($row->comment); foreach (range(0, 3) as $i) { $member = "translation_{$i}"; unset($row->{$member}); } $row->row_id = $row->original_id . ($row->id ? "-{$row->id}" : ''); $translations[] = new Translation_Entry((array) $row); } unset($rows); return $translations; }
function fx($body) { return lambda('$x', $body); }
function sql_from_conditions($conditions) { $conditions = array_map(array(&$this, 'sql_condition_from_php_value'), $conditions); $string_conditions = array(); foreach ($conditions as $field => $sql_condition) { if (is_array($sql_condition)) { $string_conditions[] = '(' . implode(' OR ', array_map(lambda('$cond', '"$field $cond"', compact('field')), $sql_condition)) . ')'; } else { $string_conditions[] = "{$field} {$sql_condition}"; } } return implode(' AND ', $string_conditions); }
<?php gp_title(sprintf(__('%s < GlotPress'), esc_html($project->name))); gp_breadcrumb_project($project); wp_enqueue_script('common'); wp_enqueue_script('tablesorter'); $edit_link = gp_link_project_edit_get($project, __('Edit'), array('class' => 'btn btn-xs btn-primary')); $parity = gp_parity_factory(); if ($project->active) { add_filter('gp_breadcrumb', lambda('$s', '$s . "<span class=\\"active label label-success\\">' . __('Active') . '</span>"')); } gp_tmpl_header(); ?> <h2><?php echo esc_html($project->name); ?> <?php echo $edit_link; ?> </h2> <p class="description"> <?php echo apply_filters('project_description', $project->description, $project); ?> </p> <?php if ($can_write) {