public function action_index() { $this->auto_render = FALSE; // Sitemap instance. $sitemap = new Sitemap(); // New basic sitemap. $sitemap_url = new Sitemap_URL(); // Set base url $base_url = "http://{$this->config['global']['server_domain']}/"; // Config urls $urls = array(array('url' => $base_url, 'frequency' => 'daily'), array('url' => $base_url . 'contact', 'frequency' => 'yearly'), array('url' => $base_url . 'about', 'frequency' => 'yearly'), array('url' => $base_url . 'contact', 'frequency' => 'yearly')); // Adds categories urls $categories = ORM::factory('category')->find_all(); foreach ($categories as $category) { $urls[] = array('url' => $base_url . '?&category_id=' . $category->id, 'frequency' => 'daily'); } // Adds jobtypes urls $jobtypes = ORM::factory('jobtype')->find_all(); foreach ($jobtypes as $jobtype) { $urls[] = array('url' => $base_url . '?&jobtype_id=' . $jobtype->id, 'frequency' => 'daily'); } // Get all active ads $ads = ORM::factory('ad'); $ads = $ads->where('active', '=', 1)->limit(500)->offset(0)->order_by('id', 'DESC')->find_all()->as_array('id', 'title'); foreach ($ads as $id => $title) { $urls[] = array('url' => Helper_Utils::get_ad_url($title, $id), 'frequency' => 'yearly'); } // Adds each url to the sitemap xml structure foreach ($urls as $url) { $sitemap_url->set_loc($url['url'])->set_last_mod(time())->set_change_frequency($url['frequency'])->set_priority(1); $sitemap->add($sitemap_url); } // Render the output. $output = $sitemap->render(); // __toString is also supported. header('Content-Type: text/xml'); echo $sitemap; die; }
/** * It will perfome a search on the ads table * * $res = Model_Ad::search(array( * 'search_string' => "php, london", * 'telecommute' => 1, * 'jobtype_id' => 3, * 'category_id' => 2, * 'limit' => 50, * 'offset' => 0, * 'fields' => array('id', 'title'), * )); * * @param Array $args * @return Array */ public static function search($args) { // Merge default args $args = array_merge(array('search_string' => '', 'telecommute' => 0, 'jobtype_id' => 0, 'jobboard_id' => 0, 'category_id' => 0, 'limit' => 50, 'offset' => 0, 'created_after' => 0, 'random_order' => false, 'fields' => array()), $args); // Loads application config file $config = Kohana::$config->load('application'); // Create the client, tell it where the server // is and how long to wait for a response. $sphinx = new Helper_Sphinx(); $sphinx->SetServer('localhost', 9312); $sphinx->SetConnectTimeout(1); // Use the exteneded v2 match type $sphinx->SetMatchMode(SPH_MATCH_BOOLEAN); // Set order & limit if ($args['search_string'] != "") { $sphinx->SetSortMode(SPH_SORT_EXTENDED, 'created_at DESC, highlight DESC'); } else { $sphinx->SetSortMode(SPH_SORT_EXTENDED, 'created_at DESC'); } $sphinx->SetLimits($args['offset'], $args['limit']); // Give me back the results as an array $sphinx->SetArrayResult(true); // Select only with telecommute if ($args['telecommute'] > 0) { $sphinx->SetFilter("telecommute", array(1)); } // Select only with jobtype_id if ($args['jobtype_id'] > 0) { $sphinx->SetFilter("jobtype_id", array($args['jobtype_id'])); } // Select only with jobboard_id if ($args['jobboard_id'] > 0) { $sphinx->SetFilter("jobboard_id", array($args['jobboard_id'])); } // Select only with category_id if ($args['category_id'] > 0) { $sphinx->SetFilter("category_id", array($args['category_id'])); } // Select only ads more recentent than created_after if ($args['created_after'] > 0) { $sphinx->SetFilterRange('created_at', $args['created_after'], strtotime('now')); } // Set random order if ($args['random_order']) { $sphinx->setSortMode(SPH_SORT_EXTENDED, '@random'); } // Perfom the query against sphinx server $sphinx_results = $sphinx->Query($args['search_string'], 'ads'); $rows = array(); $words = array(); // check if there's any results if ($sphinx_results['total'] > 0) { $ids = ''; // prepare the rows ID's to be used against mysql query for ($i = 0; $i < count($sphinx_results['matches']); $i++) { $ids .= $sphinx_results['matches'][$i]['id']; if ($i < count($sphinx_results['matches']) - 1) { $ids .= ','; } } // Merge the array so it can be included in the SQL query $fields = implode(',', $args['fields']); // Get the ID rows from MySQL $rows = DB::query(Database::SELECT, "SELECT {$fields} FROM\n\t\t\t\tads WHERE id IN({$ids}) AND active = 1 ORDER BY FIELD(id, {$ids}) ")->execute()->as_array(); // Get all the keywords if (isset($sphinx_results['words'])) { foreach ($sphinx_results['words'] as $key => $value) { $words[] = $key; } } // Cleans and formats data foreach ($rows as $key => $ad) { $rows[$key]['created_at'] = Helper_Datetime::format($ad['created_at'], $config['ad']['date_format']); $rows[$key]['is_new'] = Helper_Datetime::is_new($ad['created_at'], $config['ad']['is_new_days']); $rows[$key]['jobtype'] = ORM::factory('jobtype', $ad['jobtype_id'])->name; $rows[$key]['jobboard'] = ORM::factory('jobboard', $ad['jobboard_id'])->name; $rows[$key]['url'] = Helper_Utils::get_ad_url($ad['title'], $ad['id']); $rows[$key]['title'] = Text::limit_chars($ad['title'], 55, '...'); if (in_array('company_logo', $args['fields'])) { if (!$ad['company_logo']) { $rows[$key]['company_logo'] = 'default'; } $rows[$key]['company_logo'] = Helper_Utils::static_path('media/uploads/' . $rows[$key]['company_logo'] . '_thumb.png'); } $title[] = $rows[$key]['title']; unset($rows[$key]['jobtype_id']); } } return array('rows' => $rows, 'total' => $sphinx_results['total'], 'words' => $words); }
static function send_tweet($ad) { $config = Kohana::$config->load('application'); Email::send($config['facebook']['email'], $config['global']['email_feed'], $ad->title . " (" . $ad->location . ") - " . Helper_Utils::get_ad_url($ad->title, $ad->id), NULL); }
/** * Show the complete page * */ public function action_complete() { // Check for a valid AD session form $session = Session::instance(); $temp_ad = $session->get('ad_created_id'); // Redirects user to homepage if (!$temp_ad) { $this->request->redirect('/'); } $ad = ORM::factory('ad', $temp_ad); $amount = $this->config['ad']['price_base']; if (1 == $ad->highlight) { $amount += $this->config['ad']['price_highlight']; } // Deleted session $session->delete('ad_created_id'); // Updates Facebook & twitter Email::send($this->config['facebook']['email'], '*****@*****.**', "New " . $ad->category->name . " job: " . $ad->title . " (" . $ad->location . ") - " . Helper_Utils::get_ad_url($ad->title, $ad->id), NULL); // Sends an email notification to the user $title = "Your job ad is ready [{$ad->title}]"; $name = 'User'; if ($ad->company_name) { $name = $ad->company_name; } $template = View::factory('emails/new_ad', array('title' => $title, 'name' => $name, 'url' => Helper_Utils::get_ad_url($ad->title, $ad->id), 'ad_title' => $ad->title))->render(); Email::send($ad->email, '*****@*****.**', $title, $template); // Send a copy to admin Email::send('*****@*****.**', '*****@*****.**', $title, $template); // Shows template $this->template->title = __('Thank you'); $this->template->content = View::factory('payment/complete', array('price_base' => $this->config['ad']['price_base'], 'price_highlight' => $this->config['ad']['price_highlight'], 'highlight' => $ad->highlight, 'url' => Helper_Utils::get_ad_url($ad->title, $ad->id), 'amount' => $amount)); }
/** * Sets the ad to ACTIVE and sends out emails to users * @param Integer $ad_id */ private function approve_payment($ad_id) { if (is_numeric($ad_id) && $ad_id > 0) { $ad = ORM::factory('ad', $ad_id); // Set ad to active if ($ad) { $ad->active = 1; $ad->_valid = TRUE; $ad->save(); $ad = ORM::factory('ad', $ad_id); // Updates Facebook & twitter Helper_Utils::send_tweet($ad); // Sends an email notification to the user $title = "Your job ad is ready [{$ad->title}]"; $name = 'User'; if ($ad->company_name) { $name = $ad->company_name; } $amount = $this->config['paypal'][$ad->discount_code]['price_base']; if (1 == $ad->highlight) { $amount += $this->config['paypal'][$ad->discount_code]['price_highlight']; } $template = View::factory('emails/new_ad', array('title' => $title, 'name' => $name, 'url' => Helper_Utils::get_ad_url($ad->title, $ad->id), 'ad_title' => $ad->title, 'id' => $ad->id, 'highlight' => $ad->highlight, 'discount_code' => $ad->discount_code, 'price_base' => $this->config['paypal'][$ad->discount_code]['price_base'], 'price_highlight' => $this->config['paypal'][$ad->discount_code]['price_highlight'], 'amount' => $amount))->render(); Email::send($ad->email, $this->config['global']['email_support'], $title, $template, TRUE); // Send a copy to admin Email::send($this->config['global']['email_support'], $this->config['global']['email_support'], $title, $template, TRUE); } } }