<%once> # # # # THIS QUERY COMPONENT IS ONLY FOR JOBS (Eventually into a category). NOT COMPANY # use Date::Calc ; use Careerjet::DateTime ; use Careerjet::UserQueryBuilder ; use Careerjet::Searcher::JobSearchBalancer; my $pagesize = $r->dir_config('CareerjetJobPageSize') || 10 ; my $maxoffset = 2000; my %jobComps = () ; <%shared> my $forumLinkDisp = $r->dir_config('CareerjetForumActive') || 0 ; unless( $jobComps{'normal'} ){ $jobComps{'normal'} = $m->fetch_comp('/search/job_normal.mas' ) ; $jobComps{'compact2'} = $m->fetch_comp('/search/job_compact2.mas' ) ; } my $JOBSEARCHSOURCE = $m->shared()->{'JOBSEARCHSOURCE'} ; my $default_location = $r->dir_config('CareerjetDefaultLocation') || 54 ; my $defaultLanguage = $r->dir_config('CareerjetSearchDefaultLanguage') || '' ; my $fragmentSize = $r->dir_config('CareerjetSearchFragmentSize') || 100 ; my $noindex_zerojobs = $r->dir_config('CareerjetNoIndexZeroJobs') || 0; my $zerocompanyjobs404 = $r->dir_config('Careerjet404ZeroCommpanyJobs') || 0; my $google_afs_weight = $r->dir_config('CareerjetGoogleAFSWeight') || 0.5; my $cgi = $m->cgi_object() ; $cgi->charset('UTF-8'); ## CONTEXTUAL PARAMETERS my $sortmode = $m->cgi_object()->param('sort') || 'relevance' ; my $datefilter = $m->cgi_object()->param('df') || '' ; my $style = $m->cgi_object()->param('style') || '' ; # DIAGNOSTIC MODE my $diag = $m->cgi_object()->param('diag'); # Read the style from cookie and pass it in the shared # Read style from cookie my $jar = Apache2::Cookie::Jar->new($r) ; my $nowstyle = undef ; my $c_style = $jar->cookies('style'); if ( $c_style ){ $nowstyle = $c_style->value() ; } $m->shared()->{'style'} = $nowstyle ; # End of style grabbing part # replace style by $nowstyle priority to cookie # Trigger the bookmark_page $m->shared()->{'bookmark_page'} = 1 ; ## ## Query part # # GRABING OFFSET # SEO parameter p (page) my $page_num = $m->cgi_object()->param('p') ; my $offset = $m->cgi_object()->param('b') || 1 ; # MOST PROBABLY THE PAGE NUMBER IS GIVEN if (defined $m->cgi_object()->param('p')) { $offset = 1 + (($m->cgi_object()->param('p') - 1) * $pagesize); } $offset-- ; if ( $offset < 0 ) { $offset = 0 ; } #Maximizing offset if ( $offset > $maxoffset - $pagesize + 1) { $offset = $maxoffset - $pagesize + 1; } ## SEARCH BUILDING my $qBuilder = Careerjet::UserQueryBuilder->new( { 'charset' => 'UTF-8' } ) ; my $query = $qBuilder->queryFromCGI($cgi) ; my $searchOptions = { 'offset' => $offset , 'limit' => $pagesize , 'sort' => $sortmode , 'countrylang' => $ENV{'country'} || 'uk', 'dlid' => $default_location , 'fragsize' => $fragmentSize , } ; if ( $defaultLanguage ){ $searchOptions->{'langboost'} = $defaultLanguage ; } if ( $datefilter ){ $searchOptions->{'datefilter'} = $datefilter ; } ## OK REDIRECT TO CANONIC URL IF NEEDED if ( $r->dir_config('CareerjetVarRedirect') ){ $m->comp('/utils/canonical_search.mas' , 'q' => $query , 'options' => $searchOptions ) ; } # Share query variables with other .mas modules $m->shared()->{'query'} = $query ; $m->shared()->{'searchOptions'} = $searchOptions ; $m->shared()->{'seo_url'} = $m->cgi_object()->param('seo_url') || 0 ; # Memorize for future pages and mostly for saving this query # lQ : lastQuery $m->session()->{'lQ'} = $query ; # sO : searchOptions $m->session()->{'sO'} = $searchOptions ; my $diagnostic_mode; if ($diag eq "goose") { $diagnostic_mode = 1; } # # ACTUAL SEARCH # # my $t1 = Time::HiRes::time() ; $QUERYRESULT = {}; eval { $QUERYRESULT = Careerjet::Searcher::JobSearchBalancer->search($query, $searchOptions); }; if ($@) { warn $@; } my $t2 = Time::HiRes::time() ; ## adsense for search channel my $google_afc_keywords = $r->dir_config('CareerjetGoogleAFCKeywords') || 0 ; my $googleAFSChannel = $r->dir_config('CareerjetGoogleAFSChannel') || 0 ; if ($query->s() =~ m/company:/s) { $googleAFSChannel = 0; } $m->shared()->{google_afs_channel} = $googleAFSChannel; ## new google ads my $new_google_ads = $r->dir_config('CareerjetNewGoogleAds') || 0 ; my $num_ads_top = $r->dir_config('CareerjetGoogleNumAdsTop') || 0; my $num_ads_bottom = $r->dir_config('CareerjetGoogleNumAdsBottom') || 0; ## AFS top and bottom my $afsTopBottom = $r->dir_config('CareerjetGoogleAFSTopBottom') ; my ( $afsTop , $afsBottom ) = ( 0 , 0 ) ; if ( $afsTopBottom ){ ( $afsTop , $afsBottom ) = split('-' , $afsTopBottom ); } # # Gives info for custom ads display if rtype is NEUTRAL (MEANING ACTUAL JOBS HAS BEEN FOUND) my $nJobsFound = 0 ; if ( defined $QUERYRESULT && $QUERYRESULT->{'rtype'} eq "N" ){ $m->shared()->{'ads_numjobs'} = $QUERYRESULT->{'result'}->{'nresults'} ; $nJobsFound = $QUERYRESULT->{'result'}->{'nresults'} ; $m->shared()->{'ads_pagesize'} = $QUERYRESULT->{'result'}->{'pagesize'} ; } # Eventually log loglid my $loglid = $m->cgi_object()->param('loglid') ; if ( $loglid ){ my $logl = Encode::decode_utf8( $m->cgi_object()->param('logl') ) ; my $fname = '/home/apache/logs/monitoring/locations.log' ; if ( open LOGF , '>>'.$fname ){ binmode LOGF , ":utf8" ; my $parentsarray = $QUERYRESULT->{'location'}->{'ancestors'} ; my $path = '' ; foreach my $parent ( @$parentsarray ){ $path .= $parent->{'l'}.' > ' ; } $path .= $QUERYRESULT->{'location'}->{'thisl'}->{'l'} ; print LOGF $loglid."\cA".$path."\cA".$logl."\cA".$ENV{'country'}."\n" ; close LOGF ; } else { warn "Cannot open $fname" ; } } ## COMPLETE QUERY INFORMATIONS unless( $query->l()){ $query->l($QUERYRESULT->{'location'}->{'thisl'}->{'l'}); } $query->lid($QUERYRESULT->{'location'}->{'thisl'}->{'lid'}) ; $query->cid($QUERYRESULT->{'result'}->{'catid'}); <%method title> <%method specialhead> <%perl> use Careerjet::Local::Translations2 ; my $argline = $m->scomp('/utils/search_args.mas' , h => $query ); my $ds = $m->shared()->{'query'}->s() ; my $dl = $m->shared()->{'query'}->l() ; my $domain = get_trans("DOMAIN"); $domain =~ s/^www\.//; my $title; my $description; my $meta_keywords; my $meta_robots = ''; if ( ( defined $QUERYRESULT->{'result'}->{'catid'} ) && ( $QUERYRESULT->{'result'}->{'catid'} > 0 ) ) { # THERE WAS A SECTOR IN THE QUERY, LEADING TO SECTOR ID IN THE RESULT. IMPLIES THE RESULT IS OF TYPE J (JOBS) # # Location: # $QUERYRESULT->[5] $title = get_trans("CATEGORY_GOOGLE_TITLE"); $description = get_trans("CATEGORY_GOOGLE_DESCRIPTION"); $meta_keywords = get_trans("CATEGORY_GOOGLE_META"); my $category = Careerjet::CDB::Categories->get_name($QUERYRESULT->{'result'}->{'catid'}, $ENV{'country'}); # STORE cid ( CID is QUERYRESULT->[3] ) #$m->session()->{'cid'} = $QUERYRESULT->[3] ; # REPLACING category in descriptions ( $w ). $title =~ s/\$w/$category/g; $description =~ s/\$w/$category/g; $meta_keywords =~ s/\$w/$category/g; # REPLACING location in descriptions ( $w ) my $location = $QUERYRESULT->{'location'}->{'thisl'}->{'l'} ; $title =~ s/\$l/$location/g; $description =~ s/\$l/$location/g; $meta_keywords =~ s/\$l/$location/g; ## makes it look better $title =~ s/in United/in the United/; $description =~ s/in United/in the United/; $title =~ s/in USA/in the USA/; $description =~ s/in USA/in the USA/; $title =~ s/in Philippines/in the Philippines/; $description =~ s/in Philippines/in the Philippines/; # if ( ( defined $page_num ) && ( $page_num > 1 ) ){ # my $pageTranslation = get_trans('TITLE_PAGE_NUM') ; # $pageTranslation =~ s/\$p/$page_num/ ; # $title .= ' | '.$pageTranslation ; # } } elsif ($QUERYRESULT->{'rtype'} eq "N" && $query->s() eq "") { # OK THERE IS NO CATEGORY AND NOTHING IN S $title = get_trans("LOCATION_GOOGLE_TITLE"); $description = get_trans("LOCATION_GOOGLE_DESCRIPTION"); $meta_keywords = get_trans("LOCATION_GOOGLE_META"); my $location = $QUERYRESULT->{'location'}->{'thisl'}->{'l'} ; $title =~ s/\$l/$location/g; $description =~ s/\$l/$location/g; $meta_keywords =~ s/\$l/$location/g; } elsif ($QUERYRESULT->{'rtype'} eq "N" && $query->s() =~ m/^company:\s*\"(.*?)\"$/) { # JOBS RESULTS WITH ONLY A COMPANY IN THE QUERY my $company = $1; $company =~ s/\s/_/g ; $m->shared()->{'company_norm'} = $company ; # # Get the real company name from the service my $COMPANYSOURCE = $m->shared()->{'COMPANYSOURCE'} ; my $compSearcher = $COMPANYSOURCE->get(); my $companyObject = {} ; eval{ $companyObject = $compSearcher->getOneCompany($company,$default_location) ; $COMPANYSOURCE->free($compSearcher) ; }; if ( $@ ){ warn $@ ; $COMPANYSOURCE->fail($compSearcher); } my $realCompanyName = $companyObject->{'company'} ; my $companySite = $companyObject->{'site'} ; # || 'www.dummy.dum' ; print "\n" ; $company =~ s/_/ /g ; $m->shared()->{'company'} = $realCompanyName || $company ; $m->shared()->{'company_site'} = $companySite ; $m->shared()->{'company_letter'} = $companyObject->{'companyletter'} ; $company = $m->shared()->{'company'} ; $title = get_trans("COMPANY_GOOGLE_TITLE"); $description = get_trans("COMPANY_GOOGLE_DESCRIPTION"); $meta_keywords = get_trans("COMPANY_GOOGLE_META"); $title =~ s/\$w/$company/g; $description =~ s/\$w/$company/g; $meta_keywords =~ s/\$w/$company/g; if (!$realCompanyName && $zerocompanyjobs404) { $r->status(404) ; $title .= ' | 404 ' ; } } else { ## ALL OTHER CASES (GENERAL CASE) $title = get_trans("SEARCH_GOOGLE_TITLE"); $description = get_trans("SEARCH_GOOGLE_DESCRIPTION"); $meta_keywords = get_trans("SEARCH_GOOGLE_META"); my $words = $query->s() ; my $location = $QUERYRESULT->{'location'}->{'thisl'}->{'l'} ; $title =~ s/\$w/$words/g; $title =~ s/\$l/$location/g; $description =~ s/\$w/$words/g; $description =~ s/\$l/$location/g; $meta_keywords =~ s/\$w/$words/g; $meta_keywords =~ s/\$l/$location/g; } # NO INDEX IN CASE OF ZERO RESULTS if ($noindex_zerojobs && ( ! $QUERYRESULT->{'result'}->{'nresults'} )) { $meta_robots = "\n "; } $m->shared()->{'pagetitle'} = $title.' | '.$domain ; <% $title | h %> | <% $domain %> <% $meta_robots %> % if ( $r->dir_config('CareerjetSHARE') ){ % } <%method actions> <%perl> if ( defined( $m->cgi_object()->param('q_save_search') ) ){ # Ensure login # $m->comp('/ensure_loggedin.mas'); # Make a new user query my $qs = $m->session()->{'s'} || '' ; my $ql = $m->session()->{'l'} || '' ; my $qsblang = $m->session()->{'sb_lang'} || '' ; my $lid = $m->session()->{'lid'} || undef ; my $ct = $m->session()->{'ct'} || undef ; my $cp = $m->session()->{'cp'} || undef ; my $q = Careerjet::UserQuery->new() ; $q->uid($m->session()->{'uid'} ) ; $q->s($qs) ; $q->l($ql) ; $q->lid($lid) ; $q->ct($ct) ; $q->cp($cp) ; $q->sb_lang($qsblang) ; my $dbh = Careerjet::UserDB->new() ; Careerjet::UserQuery->save($dbh , $q) ; } # Arguments grabbing # $qs = Encode::decode_utf8($m->cgi_object()->param('s')) || $m->session()->{'s'} || '' ; # $ql = Encode::decode_utf8($m->cgi_object()->param('l')) || $m->session()->{'l'} || '' ; # $qsblang = $m->cgi_object()->param('sb_lang') || $m->session()->{'sb_lang'} || '' ; # $ct = $m->cgi_object()->param('ct') || $m->session()->{'ct'} || '' ; # $cp = $m->cgi_object()->param('cp') || $m->session()->{'cp'} || '' ; # $lid = $m->cgi_object()->param('lid') || $m->session()->{'lid'} || '' ; # $sortmode = $m->cgi_object()->param('sort') || $m->session()->{'sort'} || 'relevance' ;
<%perl> if ( ! $QUERYRESULT->{'result'}->{'nresults'} ) { if (exists $ENV{HTTP_REFERER}) { if ( open ( LOG , ">>/home/apache/logs/monitoring/zerojobs.log") ){ print LOG $ENV{country}." -- http://".$ENV{SERVER_NAME}.$ENV{REQUEST_URI}." -- ".$ENV{HTTP_REFERER}."\n"; close(LOG); } } } % ## TWO CASES: AMBIGUOUS LOCATION OR ACTUAL JOB RESULTS % if ( $QUERYRESULT->{'rtype'} eq 'L' ){ <& /search_res_L.mas &> % return ; % } % ## ALRIGHT NOW WE HAVE A JOB SEARCH RESULTS % ## start with a bit of script. cjUnCeasar to encrypt name of websites. % # Then a starting offset % my $start_offset = $offset ; % ## IN CASE OF ALERT, THE DISPLAY IS PRETTY SIMPLE (most compact possible) % if( $datefilter ){ % # VERY SIMPLE TITLE BAR

<% $QUERYRESULT->{'result'}->{'nresults'} %> !!JOBS_MATCH_YOUR_CRITERIA!!

% # NO CRUMB NOR ACTIONS OF ANY KIND. Display jobs in a table % foreach my $job ( @{ $QUERYRESULT->{'result'}->{'jobs'} || [] } ){ % my $worddate = Careerjet::Local::Date::localdate_inwords($job->{'creationtime'} + (24 * 3600) ,1 ); % my $jobtitle = $job->{'title'}; % $jobtitle =~ s/!+//gs; <%perl> my $bidjs = '' ; # 'as' cookie means allow sponsor # if ( $job->{'bid'} ){ $bidjs = 'document.cookie=\'as=1; path=/\'' ; }else{ $bidjs = 'document.cookie=\'as=0; path=/\'' ; } % $start_offset++ ; % }
<% $worddate %> <% $job->{'company'} || ucfirst(get_trans('NOT_SPECIFIED')) %> <% $jobtitle %> <&| /jscrypt.mas &><% $job->{'site'} %>
<& /search/browse.mas ,seo => 0 , nhits => $QUERYRESULT->{'result'}->{'nresults'}, pagesize => $pagesize , offset => $offset , forcenofollow => 1 &> % return ; # COMPLETE END OF STYLE % } # END OF IF STYLE COMPACT % ## OK HERE WE ARE WITH THE GENERAL TITLE % ## DISPLAY THE BAR <&| /topbar.mas , bare => 1 , noreturn => $afsTop || $num_ads_top &>
<& /search/sortmodes.mas , q => $m->shared()->{'query'} &>
<& /switch_view.mas &>
%# % # TITLE

<% $QUERYRESULT->{'result'}->{'nresults'} %> !!JOBS_MATCH_YOUR_CRITERIA!!

% # AND NOW THE ALLMIGHTY BREADCRUMBS % if ( $m->shared()->{'company'} ){ # PURE COMPANY CASE. <& /search/breadcrumb_company.mas , company => $m->shared()->{'company'} , company_norm => $m->shared()->{'company_norm'} , company_letter => $m->shared()->{'company_letter'} &> % } else { <& /search/breadcrumb.mas , q => $query &> % } ## END OF BREADCRUMB CASES.

% ## THE GREAT ACTION BOX <& /search/actionbox.mas &>
% # End of topbar content div % # END OF TOP BAR % # IN CASE OF NO RESULT, DISPLAY SOME SUGGESTION OR A SMALL MESSAGE ABOUT THE COMPANY IF IT IS A COMPANY % # % if (( $QUERYRESULT->{'rtype'} eq 'N' ) && ( $QUERYRESULT->{'result'}->{'nresults'} == 0 ) ){ % if ( $m->shared()->{'company'} ){ # PURE COMPANY CASE WITHOUT JOBS

% unless( $m->shared()->{'company_site'} ){ !!COMPANY_NO_JOBS!! % } else { % my $link = ''.$m->shared()->{'company_site'}.'' ; <% get_trans('COMPANY_NO_JOBS_SITE', undef , { 'company' => $m->shared()->{'company'} , 'sitehref' => $link } ) %> % }

% } else {
<& /suggest_zero_job.mas , searchBalancer => $JOBSEARCHSOURCE , query => $query , options => $searchOptions &>
% } # END OF ELSE PURE COMPANY % } % ## OK DISPLAY ALL THE JOBS ! % if ( $afsTop ){ ## DISPLAY afstop placeholder
% } % if ( $num_ads_top ){ ## DISPLAY afstop placeholder
% } % my $jobComp = $jobComps{ $nowstyle || 'normal' } ; % foreach my $job ( @{ $QUERYRESULT->{'result'}->{'jobs'} || [] } ){ % $m->comp($jobComp , job => $job , offset => $start_offset , forumlink => $forumLinkDisp ); % $start_offset++ ; % } % if ( $afsBottom ){ ## DISPLAY afsbottom placeholder
% } % if ( $num_ads_bottom ){ ## DISPLAY afstop placeholder
% } % if ( $afsTop || $afsBottom ){ % } % my $forceNoFollow = $m->cgi_object()->param('nfp') || 0 ; % my $seo = $m->cgi_object()->param('seo') || 0 ; <& /search/browse.mas ,seo => $seo , nhits => $QUERYRESULT->{'result'}->{'nresults'}, pagesize => $pagesize , offset => $offset , forcenofollow => $forceNoFollow &>
% if ($new_google_ads) { <%perl> my $adsense_channel; my $adsense_type = 'afc'; if ($googleAFSChannel) { $adsense_type = 'afs'; $adsense_channel = $googleAFSChannel; } my $google_query = ''; if ($googleAFSChannel || $google_afc_keywords) { if (my $category = $m->shared()->{'query'}->{'c'}) { $google_query .= $category.' '; $google_query =~ s{_}{ }gs; } if ($googleAFSChannel) { $google_query .= Careerjet::Local::Translations2::get_trans('GOOGLE_AFS_QUERY', undef , { k => $m->shared()->{'query'}->{'s'} }).' '; my $secondChannel = $r->dir_config('CareerjetGoogleAFSChannel1'); if ($secondChannel) { if ( rand() <= $google_afs_weight ){ $adsense_channel = $secondChannel; $google_query .= $m->shared()->{'query'}->{'l'}; } } } else { $google_query .= Careerjet::Local::Translations2::get_trans('GOOGLE_AFC_QUERY', undef , { k => $m->shared()->{'query'}->{'s'}, l => $m->shared()->{'query'}->{'l'} }); } $google_query =~ s{\w+:}{ }gs; $google_query =~ s{\W+}{ }gs; $google_query =~ s{\s+}{ }gs; $google_query =~ s{^\s+}{}gs; $google_query =~ s{\s+$}{}gs; } # my $minNumAds = 4; # my $numAds = 10; # # if ($m->shared()->{'ads_numjobs'}) { # my $ps = $m->shared()->{'ads_pagesize'} || 15; # my $nr = $m->shared()->{'ads_numjobs'}; # # my $rnj = $ps < $nr ? $ps : $nr; # # unless ($m->shared()->{'style'} eq 'compact2') { # $numAds = $rnj; # } else { # $numAds = int($rnj / 2) + 2; # } # } # # if ($numAds < $minNumAds) { # $numAds = $minNumAds; # } ## zero jobs case. merge top and bottom if ($nJobsFound == 0) { $num_ads_top += $num_ads_bottom; $num_ads_bottom = 0; } <& /adsense_call.mas, channel => $adsense_channel, type => $adsense_type, num_ads => 10 + $num_ads_top + $num_ads_bottom, google_query => $google_query, num_top => $num_ads_top, num_bottom => $num_ads_bottom, &> % } <%method leftadvertise> % if ($new_google_ads) {
% } else { <& /advertising_right.mas &> % } <%method rightcol> <& /promo_webmaster.mas &> <& /promo_links.mas &> % if ($new_google_ads) {
% } else { % if ( $googleAFSChannel ){ % ## MODULATE afsTop and adsBottom in function of $nJobsFound % if ( $nJobsFound == 0 ){ $afsBottom += $afsTop ; $afsTop = 0 } # ZERO JOBS -> ALL IN BOTTOM <& /advertising_google_afs.mas, google_afs_channel => $googleAFSChannel , afstop => $afsTop , afsbottom => $afsBottom &> % } else { <& /advertising_custom.mas , withgoogleads => 1 &> % } % }