Example #1
0
 /**
  * Retrieves a row from the database
  *
  * @param   string  $refid     ID of the database table row
  * @param   string  $category  Element type (determines table to look in)
  * @param   string  $parent    If the element has a parent element
  * @return  array
  */
 public function getReportedItem($refid, $category, $parent)
 {
     if (!$this->_canHandle($category)) {
         return null;
     }
     $database = App::get('db');
     if ($category == 'wish') {
         $query = "SELECT ws.id, ws.about as `text`, ws.proposed AS created, ws.proposed_by as `author`, ws.subject as `subject`, 'wish' as parent_category, ws.anonymous as anon\n\t\t\t\t\t\tFROM `#__wishlist_item` AS ws\n\t\t\t\t\t\tWHERE ws.id=" . $database->quote($refid);
     } else {
         if ($category == 'wishcomment') {
             $query = "SELECT rr.id, rr.content as `text`, rr.created, rr.created_by as `author`, NULL as `subject`, rr.category as parent_category, rr.anonymous as anon\n\t\t\t\t\t\tFROM `#__item_comments` AS rr\n\t\t\t\t\t\tWHERE rr.id=" . $database->quote($refid);
         }
     }
     $database->setQuery($query);
     $rows = $database->loadObjectList();
     if ($rows) {
         foreach ($rows as $key => $row) {
             if (preg_match('/^<!-- \\{FORMAT:(.*)\\} -->/i', $row->text, $matches)) {
                 $rows[$key]->text = preg_replace('/^(<!-- \\{FORMAT:.*\\} -->)/i', '', $row->text);
             }
             $rows[$key]->href = $parent ? Route::url('index.php?option=com_wishlist&task=wishlist&id=' . $parent) : '';
             if ($rows[$key]->parent_category == 'wishcomment') {
                 $rows[$key]->href = Route::url('index.php?option=com_wishlist&task=wish&wishid=' . $parent);
             }
         }
     }
     return $rows;
 }
Example #2
0
 /**
  * Pub view for project files, notes etc.
  *
  * @return     void
  */
 public function displayTask()
 {
     require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'tables' . DS . 'publicstamp.php';
     // Incoming
     $stamp = Request::getVar('s', '');
     // Clean up stamp value (only numbers and letters)
     $regex = array('/[^a-zA-Z0-9]/');
     $stamp = preg_replace($regex, '', $stamp);
     // Load item reference
     $objSt = new Tables\Stamp($this->database);
     if (!$stamp || !$objSt->loadItem($stamp)) {
         App::redirect(Route::url('index.php?option=' . $this->_option));
         return;
     }
     // Can only serve files or notes at the moment
     if (!in_array($objSt->type, array('files', 'notes', 'publications'))) {
         App::redirect(Route::url('index.php?option=' . $this->_option));
         return;
     }
     // Serve requested item
     $content = Event::trigger('projects.serve', array($objSt->type, $objSt->projectid, $objSt->reference));
     // Output
     foreach ($content as $out) {
         if ($out) {
             return $out;
         }
     }
     // Redirect if nothing fetched
     App::redirect(Route::url('index.php?option=' . $this->_option));
     return;
 }
Example #3
0
 /**
  * Update new forum
  */
 public function action_update()
 {
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Edit Topic')));
     $topic = new Model_Topic($this->request->param('id'));
     $get_all = Model_Forum::get_all();
     //get all forums to build forum parents in select
     $forum_parents = array();
     foreach ($get_all[0] as $parent) {
         $forum_parents[$parent['id']] = $parent['name'];
     }
     $this->template->content = View::factory('oc-panel/pages/forum/topic', array('topic' => $topic, 'forum_parents' => $forum_parents));
     if ($_POST) {
         $topic->title = core::post('title');
         $topic->id_forum = core::post('id_forum');
         $topic->description = core::post('description');
         if (core::post('seotitle') != $topic->seotitle) {
             $topic->seotitle = $topic->gen_seotitle(core::post('seotitle'));
         }
         if (core::post('status') == 'on') {
             $topic->status = 1;
         } else {
             $topic->status = 0;
         }
         try {
             $topic->save();
             Alert::set(Alert::SUCCESS, __('Topic is updated.'));
         } catch (Exception $e) {
             Alert::set(Alert::ERROR, $e->getMessage());
         }
         HTTP::redirect(Route::url('oc-panel', array('controller' => 'topic', 'action' => 'index')));
     }
 }
Example #4
0
File: report.php Project: anqh/anqh
    /**
     * Render view.
     *
     * @return  string
     */
    public function content()
    {
        ob_start();
        $gallery = $this->image->gallery();
        echo Form::open(Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $this->image->id, 'action' => 'report')), array('class' => Request::current()->is_ajax() ? 'ajaxify' : ''));
        ?>

<fieldset>

	<?php 
        echo Form::control_group(Form::input('reason', null, array('class' => 'input-block-level')), array('name' => __('Reason')), null, __('You can enter an optional reason for reporting this image, e.g. why it should be removed'));
        ?>

</fieldset>

<fieldset class="form-actions">
	<?php 
        echo Form::button('save', __('Report'), array('type' => 'submit', 'class' => 'btn btn-danger btn-large'));
        ?>
	<?php 
        echo Request::current()->is_ajax() ? '' : HTML::anchor(Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $this->image->id, 'action' => '')), __('Cancel'), array('class' => 'cancel'));
        ?>

	<?php 
        echo Form::csrf();
        ?>
</fieldset>

<?php 
        return ob_get_clean();
    }
Example #5
0
 /**
  * Get newsfeed item as HTML
  *
  * @param   Model_NewsfeedItem  $item
  * @return  string
  */
 public static function get(Model_NewsfeedItem $item)
 {
     $text = '';
     switch ($item->type) {
         case self::TYPE_COMMENT:
             $gallery = Model_Gallery::factory($item->data['gallery_id']);
             $image = Model_Image::factory($item->data['image_id']);
             if ($gallery->loaded() && $image->loaded()) {
                 $text = __('commented to an image<br />:gallery', array(':gallery' => HTML::anchor(Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $image->id, 'action' => '')), '<i class="icon-camera icon-white"></i> ' . HTML::chars($gallery->name), array('class' => 'hoverable'))));
             }
             break;
         case self::TYPE_COMMENT_FLYER:
             $flyer = Model_Flyer::factory($item->data['flyer_id']);
             if ($flyer->loaded()) {
                 $text = __('commented to a flyer<br />:flyer', array(':flyer' => HTML::anchor(Route::url('flyer', array('id' => $flyer->id)), '<i class="icon-picture icon-white"></i> ' . ($flyer->name ? HTML::chars($flyer->name) : __('flyer')), array('class' => 'hoverable'))));
             }
             break;
         case self::TYPE_FLYER_EDIT:
             $flyer = Model_Flyer::factory($item->data['flyer_id']);
             if ($flyer->loaded()) {
                 $text = __('updated flyer<br />:flyer', array(':flyer' => HTML::anchor(Route::url('flyer', array('id' => $flyer->id)), '<i class="icon-picture icon-white"></i> ' . ($flyer->name ? HTML::chars($flyer->name) : __('flyer')), array('class' => 'hoverable'))));
             }
             break;
         case self::TYPE_NOTE:
             $gallery = Model_Gallery::factory($item->data['gallery_id']);
             $image = Model_Image::factory($item->data['image_id']);
             $user = Model_User::find_user($item->data['user_id']);
             if ($gallery->loaded() && $image->loaded() && $user->loaded()) {
                 $text = __('tagged :user to an image<br />:gallery', array(':user' => HTML::user($user), ':gallery' => HTML::anchor(Route::url('gallery_image', array('gallery_id' => Route::model_id($gallery), 'id' => $image->id, 'action' => '')), '<i class="icon-tag icon-white"></i> ' . HTML::chars($gallery->name), array('class' => 'hoverable'))));
             }
             break;
     }
     return $text;
 }
Example #6
0
 /**
  * Event call for displaying usage data
  *
  * @param      string $option        Component name
  * @param      string $task          Component task
  * @param      object $db            JDatabase
  * @param      array  $months        Month names (Jan -> Dec)
  * @param      array  $monthsReverse Month names in reverse (Dec -> Jan)
  * @param      string $enddate       Time period
  * @return     string HTML
  */
 public function onUsageDisplay($option, $task, $db, $months, $monthsReverse, $enddate)
 {
     // Check if our task is the area we want to return results for
     if ($task) {
         if (!in_array($task, $this->onUsageAreas()) && !in_array($task, array_keys($this->onUsageAreas()))) {
             return '';
         }
     }
     // Set some vars
     $thisyear = date("Y");
     $o = \Components\Usage\Helpers\Helper::options($db, $enddate, $thisyear, $monthsReverse, 'check_for_regiondata');
     // Build HTML
     $html = '<form method="post" action="' . Route::url('index.php?option=' . $option . '&task=' . $task) . '">' . "\n";
     $html .= "\t" . '<fieldset class="filters">' . "\n";
     $html .= "\t\t" . '<label>' . "\n";
     $html .= "\t\t\t" . Lang::txt('PLG_USAGE_SHOW_DATA_FOR') . ': ' . "\n";
     $html .= "\t\t\t" . '<select name="selectedPeriod" id="selectedPeriod">' . "\n";
     $html .= $o;
     $html .= "\t\t\t" . '</select>' . "\n";
     $html .= "\t\t" . '</label> <input type="submit" value="' . Lang::txt('PLG_USAGE_VIEW') . '" />' . "\n";
     $html .= "\t" . '</fieldset>' . "\n";
     $html .= '</form>' . "\n";
     $html .= \Components\Usage\Helpers\Helper::toplist($db, 10, 1, $enddate);
     $html .= \Components\Usage\Helpers\Helper::toplist($db, 17, 2, $enddate);
     $html .= \Components\Usage\Helpers\Helper::toplist($db, 11, 3, $enddate);
     $html .= \Components\Usage\Helpers\Helper::toplist($db, 9, 4, $enddate);
     $html .= \Components\Usage\Helpers\Helper::toplist($db, 12, 5, $enddate);
     $html .= \Components\Usage\Helpers\Helper::toplist($db, 19, 6, $enddate);
     $html .= \Components\Usage\Helpers\Helper::toplist($db, 18, 7, $enddate);
     $html .= \Components\Usage\Helpers\Helper::toplist($db, 7, 8, $enddate);
     // Return HTML
     return $html;
 }
 /**
  * [action_form] generates the form to pay at paypal
  */
 public function action_pay()
 {
     $this->auto_render = FALSE;
     $id_order = $this->request->param('id');
     //retrieve info for the item in DB
     $order = new Model_Order();
     $order = $order->where('id_order', '=', $id_order)->where('status', '=', Model_Order::STATUS_CREATED)->limit(1)->find();
     if ($order->loaded()) {
         // include class vendor
         require Kohana::find_file('vendor/authorize/', 'autoload');
         define('AUTHORIZENET_API_LOGIN_ID', Core::config('payment.authorize_login'));
         define('AUTHORIZENET_TRANSACTION_KEY', Core::config('payment.authorize_key'));
         define('AUTHORIZENET_SANDBOX', Core::config('payment.authorize_sandbox'));
         $sale = new AuthorizeNetAIM();
         $sale->amount = $order->amount;
         $sale->card_num = Core::post('card-number');
         $sale->exp_date = Core::post('expiry-month') . '/' . Core::post('expiry-year');
         $response = $sale->authorizeAndCapture();
         if ($response->approved) {
             $order->confirm_payment('authorize', $response->transaction_id);
             //redirect him to his ads
             Alert::set(Alert::SUCCESS, __('Thanks for your payment!') . ' ' . $response->transaction_id);
             $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders')));
         } else {
             Alert::set(Alert::INFO, $response->error_message);
             $this->redirect(Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order)));
         }
     } else {
         Alert::set(Alert::INFO, __('Order could not be loaded'));
         $this->redirect(Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order)));
     }
 }
Example #8
0
 public function action_index()
 {
     if ($this->request->method() == HTTP_Request::POST) {
         try {
             if ($this->request->post('active')) {
                 $pet = ORM::factory('User_Pet')->where('user_pet.id', '=', $this->request->post('active'))->where('user_id', '=', $this->user->id)->find();
                 $pet->active = time();
                 $pet->save();
                 Hint::success($pet->name . ' is now your active pet.');
             }
             if ($this->request->post('abandon')) {
                 $pet = ORM::factory('User_Pet')->where('user_pet.id', '=', $this->request->post('abandon'))->where('user_id', '=', $this->user->id)->find();
                 $pet->user_id = NULL;
                 $pet->abandoned = time();
                 $pet->save();
                 Hint::success('You have abandoned ' . $pet->name . '.');
             }
             $this->redirect(Route::get('pets')->uri());
         } catch (ORM_Validation_Exception $e) {
             Hint::error($e->errors('models'));
         }
     }
     $this->view = new View_Pet_Index();
     $pets = ORM::factory('User_Pet')->where('user_id', '=', $this->user->id)->order_by('active', 'desc');
     $paginate = Paginate::factory($pets)->execute();
     $this->view->pagination = $paginate->render();
     $this->view->pets = $paginate->result();
     $this->view->pets_count = count($pets);
     $this->view->href = array('create' => Route::url('pet.create'), 'adopt' => Route::url('pet.adopt'));
 }
Example #9
0
 /**
  * Configure the Linkbar.
  *
  * @param	string	The name of the active view.
  */
 public static function addSubmenu($vName)
 {
     Submenu::addEntry(Lang::txt('COM_LANGUAGES_SUBMENU_INSTALLED_SITE'), Route::url('index.php?option=com_languages&view=installed&client=0'), $vName == 'installed');
     Submenu::addEntry(Lang::txt('COM_LANGUAGES_SUBMENU_INSTALLED_ADMINISTRATOR'), Route::url('index.php?option=com_languages&view=installed&client=1'), $vName == 'installed');
     Submenu::addEntry(Lang::txt('COM_LANGUAGES_SUBMENU_CONTENT'), Route::url('index.php?option=com_languages&view=languages'), $vName == 'languages');
     Submenu::addEntry(Lang::txt('COM_LANGUAGES_SUBMENU_OVERRIDES'), Route::url('index.php?option=com_languages&view=overrides'), $vName == 'overrides');
 }
Example #10
0
File: group.php Project: anqh/forum
 /**
  * Action: index
  */
 public function action_index()
 {
     // Load group(s)
     $group_id = (int) $this->request->param('id');
     $actions = array();
     if (!$group_id) {
         // All groups
         $groups = Model_Forum_Group::factory()->find_all();
         if (Permission::has(new Model_Forum_Group(), Model_Forum_Group::PERMISSION_CREATE, self::$user)) {
             $actions[] = array('link' => Route::url('forum_group_add'), 'text' => '<i class="icon-plus-sign icon-white"></i> ' . __('New group'));
         }
     } else {
         // One group
         $group = Model_Forum_Group::factory($group_id);
         if (!$group->loaded()) {
             throw new Model_Exception($group, $group_id);
         }
         Permission::required($group, Model_Forum_Group::PERMISSION_READ, self::$user);
         if (Permission::has($group, Model_Forum_Group::PERMISSION_UPDATE, self::$user)) {
             $actions[] = array('link' => Route::model($group, 'edit'), 'text' => '<i class="icon-edit icon-white"></i> ' . __('Edit group'));
         }
         if (Permission::has($group, Model_Forum_Group::PERMISSION_CREATE_AREA, self::$user)) {
             $actions[] = array('link' => Route::model($group, 'add'), 'text' => '<i class="icon-plus-sign icon-white"></i> ' . __('New area'));
         }
         $groups = array($group);
     }
     // Build page
     $this->view = new View_Page(count($groups) > 1 ? __('Forum areas') : $groups[0]->name);
     $this->view->tab = 'areas';
     $this->view->actions = $actions;
     foreach ($groups as $group) {
         $this->view->add(View_Page::COLUMN_MAIN, $this->section_group($group));
     }
     $this->_side_views();
 }
Example #11
0
File: tag.php Project: anqh/core
    /**
     * Render view.
     *
     * @return  string
     */
    public function content()
    {
        ob_start();
        echo Form::open();
        ?>

<fieldset>

	<?php 
        echo Form::control_group(Form::input('name', $this->tag->name, array('class' => 'input-xxlarge', 'maxlength' => 32)), array('name' => __('Name')), Arr::get($this->errors, 'name'));
        ?>

	<?php 
        echo Form::control_group(Form::input('description', $this->tag->description, array('class' => 'input-xxlarge')), array('description' => __('Short description')), Arr::get($this->errors, 'description'));
        ?>

</fieldset>

<fieldset class="form-actions">
	<?php 
        echo Form::button('save', __('Save'), array('type' => 'submit', 'class' => 'btn btn-success btn-large'));
        ?>
	<?php 
        echo HTML::anchor(Request::back(Route::url('tags'), true), __('Cancel'), array('class' => 'cancel'));
        ?>
</fieldset>

<?php 
        echo Form::close();
        return ob_get_clean();
    }
Example #12
0
 public function action_status()
 {
     $status = (bool) $this->request->param('id');
     Model_Config::set_value('general', 'cron', $status);
     Alert::set(Alert::SUCCESS, __('General Configuration updated'));
     $this->redirect(Route::url('oc-panel', array('controller' => 'crontab')));
 }
Example #13
0
 public function on_page_load()
 {
     $email_ctx_id = $this->get('email_id_ctx', 'email');
     $email = $this->_ctx->get($email_ctx_id);
     $referrer_page = Request::current()->referrer();
     $next_page = $this->get('next_url', Request::current()->referrer());
     if (!Valid::email($email)) {
         Messages::errors(__('Use a valid e-mail address.'));
         HTTP::redirect($referrer_page);
     }
     $user = ORM::factory('user', array('email' => $email));
     if (!$user->loaded()) {
         Messages::errors(__('No user found!'));
         HTTP::redirect($referrer_page);
     }
     $reflink = ORM::factory('user_reflink')->generate($user, 'forgot', array('next_url' => URL::site($this->next_url, TRUE)));
     if (!$reflink) {
         Messages::errors(__('Reflink generate error'));
         HTTP::redirect($referrer_page);
     }
     Observer::notify('admin_login_forgot_before', $user);
     try {
         Email_Type::get('user_request_password')->send(array('username' => $user->username, 'email' => $user->email, 'reflink' => Route::url('reflink', array('code' => $reflink)), 'code' => $reflink));
         Messages::success(__('Email with reflink send to address set in your profile'));
     } catch (Exception $e) {
         Messages::error(__('Something went wrong'));
     }
     HTTP::redirect($next_page);
 }
Example #14
0
 /**
  * [action_form] generates the form to pay at paypal
  */
 public function action_pay()
 {
     $this->auto_render = FALSE;
     $order_id = $this->request->param('id');
     $order = new Model_Order();
     $order->where('id_order', '=', $order_id)->where('status', '=', Model_Order::STATUS_CREATED)->limit(1)->find();
     if ($order->loaded()) {
         // case when selling advert
         if ($order->id_product == Model_Order::PRODUCT_AD_SELL) {
             $paypal_account = $order->ad->paypal_account();
             $currency = i18n::get_intl_currency_symbol();
             if (isset($order->ad->cf_shipping) and Valid::numeric($order->ad->cf_shipping) and $order->ad->cf_shipping > 0) {
                 $order->amount = $order->amount + $order->ad->cf_shipping;
             }
         } else {
             $paypal_account = core::config('payment.paypal_account');
             $currency = core::config('payment.paypal_currency');
         }
         $paypal_url = Core::config('payment.sandbox') ? Paypal::url_sandbox_gateway : Paypal::url_gateway;
         $paypal_data = array('order_id' => $order_id, 'amount' => number_format($order->amount, 2, '.', ''), 'site_name' => core::config('general.site_name'), 'site_url' => URL::base(TRUE), 'paypal_url' => $paypal_url, 'paypal_account' => $paypal_account, 'paypal_currency' => $currency, 'item_name' => $order->description);
         $this->template = View::factory('paypal', $paypal_data);
         $this->response->body($this->template->render());
     } else {
         Alert::set(Alert::INFO, __('Order could not be loaded'));
         $this->redirect(Route::url('default'));
     }
 }
Example #15
0
 public function menu_add($orm)
 {
     if ($this->acl->is_allowed($this->user, $orm, 'edit')) {
         $back_url = $_SERVER['REQUEST_URI'] . urlencode('#tab-') . $this->tab_code;
         return array('blog' => array('sub' => array('add' => array('title' => __('Add post'), 'link' => Route::url('modules', array('controller' => $this->controller_name, 'action' => 'edit', 'query' => 'group=' . $this->blog_group . '&blog=' . $orm->id . '&back_url=' . $back_url))))));
     }
 }
Example #16
0
 public function action_index()
 {
     $materialId = $this->request->param('id');
     $materials = new Model_Material('groups');
     //получить содержимое папки
     $data = $materials->getMaterial($materialId);
     $fields = $materials->getFields2($materialId, TRUE);
     $model = array("photos" => array());
     $model["id"] = Arr::get($data, "id");
     $model["name"] = Arr::get($data, "name");
     $model["article"] = Arr::get($data, "art");
     $model["price"] = number_format(Arr::get($fields, 'price'), 0, "", " ");
     Resources::add_scripts(array("js/modules/material/material.js"), get_class());
     // --- Фотки ----------------------------------------------------
     // есть фото
     if (isset($fields["photos"][0])) {
         $photos = $fields["photos"];
         $model["general_photo"] = $photos[0]["value"];
         // Фоток больше 1
         if (count($photos) > 1) {
             foreach ($photos as $photo) {
                 $model["photos"][] = array("original" => $photo["value"], "mini" => Route::url("miniimg2", array("filename" => $photo["value"])));
             }
         }
     } else {
         $model["general_photo"] = "/img/noimg.png";
     }
     // --- /Фотки ----------------------------------------------------
     // --- Коментарии ------------------------------------------------
     echo '<script>window.material_id = JSON.parse(\'' . $materialId . '\');</script>';
     $this->load_module("comments", "/widgets/Comments/index");
     // --- /Коментарии -----------------------------------------------
     $this->set_template("/widgets/material/material.php", "twig")->render($model)->body();
 }
Example #17
0
 /**
  * Method to cancel an edit.
  *
  * @param	string	$key	The name of the primary key of the URL variable.
  *
  * @return	Boolean	True if access level checks pass, false otherwise.
  * @since	1.6
  */
 public function cancel($key = null)
 {
     $return = parent::cancel($key);
     // Redirect to the main page.
     $this->setRedirect(Route::url('index.php', false));
     return $return;
 }
Example #18
0
    /**
     * Render view.
     *
     * @return  string
     */
    public function content()
    {
        ob_start();
        $tags = $this->group->tags();
        if (empty($tags)) {
            ?>

<div class="empty">
	<?php 
            echo __('No tags yet.');
            ?>
</div>

<?php 
        } else {
            ?>

<ul>
	<?php 
            foreach ($tags as $tag) {
                ?>
	<li><?php 
                echo HTML::anchor(Route::model($tag), $tag->name);
                ?>
</li>
	<?php 
            }
            ?>
</ul>

<?php 
        }
        echo Form::open();
        ?>

<fieldset>

	<?php 
        echo Form::control_group(Form::input('name', $this->group->name, array('class' => 'input-xxlarge', 'maxlength' => 32)), array('name' => __('Name')), Arr::get($this->errors, 'name'));
        ?>

	<?php 
        echo Form::control_group(Form::input('description', $this->group->description, array('class' => 'input-xxlarge')), array('description' => __('Short description')), Arr::get($this->errors, 'description'));
        ?>

</fieldset>

<fieldset class="form-actions">
	<?php 
        echo Form::button('save', __('Save'), array('type' => 'submit', 'class' => 'btn btn-success btn-large'));
        ?>
	<?php 
        echo HTML::anchor(Request::back(Route::url('tags'), true), __('Cancel'), array('class' => 'cancel'));
        ?>
</fieldset>

<?php 
        echo Form::close();
        return ob_get_clean();
    }
Example #19
0
 /**
  * List of pages (blogs/posts/etc.) with a specific tag
  *
  * @throws  HTTP_Exception_404
  *
  * @uses    Log::add
  * @uses    Text::ucfirst
  * @uses    ACL::check
  * @uses    Meta::links
  * @uses    URL::canonical
  * @uses    Route::url
  */
 public function action_view()
 {
     $id = (int) $this->request->param('id', 0);
     $tag = ORM::factory('tag', $id);
     if (!$tag->loaded()) {
         throw HTTP_Exception::factory(404, 'Tag :tag not found!', array(':tag' => $id));
     }
     $this->title = __(':title', array(':title' => Text::ucfirst($tag->name)));
     $view = View::factory('tag/view')->set('teaser', TRUE)->bind('pagination', $pagination)->bind('posts', $posts);
     $posts = $tag->posts;
     if (!ACL::check('administer tags') and !ACL::check('administer content')) {
         $posts->where('status', '=', 'publish');
     }
     $total = $posts->reset(FALSE)->count_all();
     if ($total == 0) {
         Log::info('No posts found.');
         $this->response->body(View::factory('page/none'));
         return;
     }
     $pagination = Pagination::factory(array('current_page' => array('source' => 'cms', 'key' => 'page'), 'total_items' => $total, 'items_per_page' => 15, 'uri' => $tag->url));
     $posts = $posts->order_by('created', 'DESC')->limit($pagination->items_per_page)->offset($pagination->offset)->find_all();
     $this->response->body($view);
     // Set the canonical and shortlink for search engines
     if ($this->auto_render === TRUE) {
         Meta::links(URL::canonical($tag->url, $pagination), array('rel' => 'canonical'));
         Meta::links(Route::url('tag', array('action' => 'view', 'id' => $tag->id)), array('rel' => 'shortlink'));
     }
 }
Example #20
0
File: roles.php Project: anqh/core
 /**
  * Action: edit
  */
 public function action_edit()
 {
     $this->history = false;
     // Load role
     $role_id = (int) $this->request->param('id', 0);
     if ($role_id) {
         $role = Model_Role::factory($role_id);
         if (!$role->loaded()) {
             throw new Model_Exception($role, $role_id);
         }
         Permission::required($role, Model_Role::PERMISSION_UPDATE, self::$user);
     } else {
         $role = Model_Role::factory();
         Permission::required($role, Model_Role::PERMISSION_CREATE, self::$user);
     }
     // Handle post
     $errors = array();
     if ($_POST) {
         $role->name = Arr::get($_POST, 'name');
         $role->description = Arr::get($_POST, 'description');
         try {
             $role->save();
             $this->request->redirect(Route::url('roles'));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validate');
         }
     }
     // Set title
     $this->view = View_Page::factory(__('Role') . ($role->name ? ': ' . $role->name : ''));
     // Set actions
     if ($role->loaded() && Permission::has($role, Model_Role::PERMISSION_DELETE, self::$user)) {
         $this->page_actions[] = array('link' => Route::model($role, 'delete') . '?token=' . Security::csrf(), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete role'), 'class' => 'btn btn-danger role-delete');
     }
     $this->view->add(View_Page::COLUMN_MAIN, $this->section_role($role, $errors));
 }
Example #21
0
 /**
  * Get list of pages
  *
  * @uses  Config::load
  * @uses  Config_Group::get
  * @uses  URL::site
  * @uses  Cache::set
  */
 public function action_list()
 {
     if (empty($this->_items)) {
         $config = Config::load('page');
         // Cache is Empty so Re-Cache
         $pages = ORM::factory('page')->where('status', '=', 'publish')->order_by('pubdate', 'DESC')->limit($this->_limit)->offset($this->_offset)->find_all();
         $items = array();
         foreach ($pages as $page) {
             $item = array();
             $item['guid'] = $page->id;
             $item['title'] = $page->title;
             $item['link'] = URL::site($page->url, TRUE);
             if ($config->get('use_submitted', FALSE)) {
                 $item['author'] = $page->user->nick;
             }
             $item['description'] = $page->teaser;
             $item['pubDate'] = $page->pubdate;
             $items[] = $item;
         }
         $this->_cache->set($this->_cache_key, $items, $this->_ttl);
         $this->_items = $items;
     }
     if (isset($this->_items[0])) {
         $this->_info['title'] = __('Pages - Recent updates');
         $this->_info['link'] = Route::url('rss', array('controller' => 'page'), TRUE);
         $this->_info['pubDate'] = $this->_items[0]['pubDate'];
     }
 }
Example #22
0
 /**
  * Return data on a resource view (this will be some form of HTML)
  *
  * @param   object  $resource  Current resource
  * @param   string  $option    Name of the component
  * @param   array   $areas     Active area(s)
  * @param   string  $rtrn      Data to be returned
  * @return  array
  */
 public function onResources($model, $option, $areas, $rtrn = 'all')
 {
     if (!$model->type->params->get('plg_share')) {
         return;
     }
     $arr = array('area' => $this->_name, 'html' => '', 'metadata' => '');
     $resource = $model->resource;
     $sef = Route::url('index.php?option=com_resources&' . ($resource->alias ? 'alias=' . $resource->alias : 'id=' . $resource->id));
     $url = Request::base() . ltrim($sef, '/');
     // Incoming action
     $sharewith = Request::getVar('sharewith', '');
     if ($sharewith) {
         // Log the activity
         if (!User::isGuest()) {
             Event::trigger('system.logActivity', ['activity' => ['action' => 'shared', 'scope' => 'resource', 'scope_id' => $resource->id, 'description' => Lang::txt('PLG_RESOURCES_SHARE_ENTRY_SHARED', '<a href="' . $sef . '">' . $resource->title . '</a>', $sharewith), 'details' => array('with' => $sharewith, 'title' => $resource->title, 'url' => $sef)], 'recipients' => [['resource', $resource->id], ['user', $resource->created_by], ['user', User::get('id')]]]);
         }
         // Email form
         if ($sharewith == 'email') {
             // Instantiate a view
             $view = $this->view('email', 'options')->set('option', $option)->set('resource', $resource)->set('_params', $this->params)->set('url', $url)->setErrors($this->getErrors());
             // Return the output
             $view->display();
             exit;
         }
         return $this->share($sharewith, $url, $resource);
     }
     // Build the HTML meant for the "about" tab's metadata overview
     if ($rtrn == 'all' || $rtrn == 'metadata') {
         // Instantiate a view
         $view = $this->view('default', 'options')->set('option', $option)->set('resource', $resource)->set('_params', $this->params)->set('url', $url)->setErrors($this->getErrors());
         // Return the output
         $arr['metadata'] = $view->loadTemplate();
     }
     return $arr;
 }
Example #23
0
File: forum.php Project: anqh/forum
 /**
  * Construct controller
  */
 public function before()
 {
     parent::before();
     $this->page_title = __('Forum');
     // Generic page actions
     $this->page_actions['new-posts'] = array('link' => Route::url('forum'), 'text' => '<i class="icon-comment icon-white"></i> ' . __('New posts'));
     // Forum areas dropdown
     $groups = Model_Forum_Group::factory()->find_all();
     $areas = array();
     foreach ($groups as $group) {
         $divider = false;
         foreach ($group->areas() as $area) {
             if (Permission::has($area, Model_Forum_Area::PERMISSION_READ, self::$user)) {
                 $divider = true;
                 $areas[] = array('link' => Route::model($area), 'text' => HTML::entities($area->name));
             }
         }
         if ($divider) {
             $areas[] = array('divider' => true);
         }
     }
     array_pop($areas);
     $this->page_actions['areas'] = array('link' => Route::url('forum_group'), 'text' => '<i class="icon-folder-open icon-white"></i> ' . __('Areas'));
     $this->page_actions['area'] = array('link' => Route::url('forum_group'), 'text' => '', 'dropdown' => $areas);
     if (self::$user) {
         $this->page_actions['private-messages'] = array('link' => Forum::private_messages_url(), 'text' => '<i class="icon-envelope icon-white"></i> ' . __('Private messages'));
     }
 }
Example #24
0
 public function action_index()
 {
     $request = $this->request->current();
     if ($request->post('submit')) {
         $login = $request->post('login');
         $password = $request->post('password');
         $ip = Request::$client_ip;
         $user_agent = Request::$user_agent;
         $remember = (bool) $this->request->post('remember');
         $fail_login_checker = new Auth_Admin_Checker($login, $ip);
         if ($fail_login_checker->check()) {
             $admin = ORM::factory('admin')->where('username', '=', $login)->and_where('delete_bit', '=', 0)->and_where('active', '=', 1)->find();
             try {
                 if ($this->acl->auth()->login($admin, $password, $remember)) {
                     $url = Session::instance()->get('BACK_URL');
                     $request->redirect(empty($url) ? Route::url('admin') : $url);
                 } else {
                     // Store fail login attempt
                     $fail_login_checker->add($password, $user_agent);
                     $this->template->set('error', __('Authentication error'));
                 }
             } catch (ORM_Validation_Exception $e) {
                 Log::instance()->add(Log::ERROR, $e->errors('') . '[' . __FILE__ . '::' . __LINE__ . ']');
             }
         } else {
             $this->template->set('error', __('To many failed login attempts. Please, wait :minutes minutes and try again.', array(':minutes' => ceil($fail_login_checker->fail_interval() / 60))));
         }
     }
     $this->template->set('logo', $this->config['logo']);
 }
 public function action_result()
 {
     $this->auto_render = FALSE;
     $id_order = Core::request('id_order');
     //retrieve info for the item in DB
     $order = new Model_Order();
     $order = $order->where('id_order', '=', $id_order)->where('status', '=', Model_Order::STATUS_CREATED)->limit(1)->find();
     if ($order->loaded()) {
         //its a fraud...lets let him know
         if ($order->is_fraud() === TRUE) {
             Alert::set(Alert::ERROR, __('We had, issues with your transaction. Please try paying with another paymethod.'));
             $this->redirect(Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order)));
         }
         //correct payment?
         if (($result = paguelofacil::check_result()) === TRUE) {
             //mark as paid
             $order->confirm_payment('paguelofacil', Core::request('Oper'));
             //redirect him to his ads
             Alert::set(Alert::SUCCESS, __('Thanks for your payment!'));
             $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders')));
         } else {
             Alert::set(Alert::INFO, __('Transaction not successful!'));
             $this->redirect(Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order)));
         }
     } else {
         Alert::set(Alert::INFO, __('Order could not be loaded'));
         $this->redirect(Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order)));
     }
 }
Example #26
0
 public function action_get()
 {
     try {
         if (is_numeric($id_ad = $this->request->param('id'))) {
             $ad = new Model_Ad($id_ad);
             if ($ad->loaded()) {
                 if ($ad->id_user == $this->user->id_user) {
                     $a = $ad->as_array();
                     $a['price'] = i18n::money_format($ad->price);
                     $a['images'] = array_values($ad->get_images());
                     $a['category'] = $ad->category->as_array();
                     $a['location'] = $ad->location->as_array();
                     $a['customfields'] = Model_Field::get_by_category($ad->id_category);
                     $a['url'] = Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle));
                     $this->rest_output(array('ad' => $a));
                 } else {
                     $this->_error(__('Not your advertisement'), 401);
                 }
             } else {
                 $this->_error(__('Advertisement not found'), 404);
             }
         } else {
             $this->_error(__('Advertisement not found'), 404);
         }
     } catch (Kohana_HTTP_Exception $khe) {
         $this->_error($khe);
     }
 }
 public function action_index()
 {
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default')));
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('User Profile')));
     $seoname = $this->request->param('seoname', NULL);
     if ($seoname !== NULL) {
         $user = new Model_User();
         $user->where('seoname', '=', $seoname)->limit(1)->cached()->find();
         if ($user->loaded()) {
             $this->template->title = __('User Profile') . ' - ' . $user->name;
             //$this->template->meta_description = $user->name;//@todo phpseo
             $this->template->bind('content', $content);
             $ads = new Model_Ad();
             $ads = $ads->where('id_user', '=', $user->id_user)->where('status', '=', Model_Ad::STATUS_PUBLISHED)->order_by('created', 'desc')->cached()->find_all();
             // case when user dont have any ads
             if ($ads->count() == 0) {
                 $profile_ads = NULL;
             }
             $this->template->content = View::factory('pages/userprofile', array('user' => $user, 'profile_ads' => $ads));
         } else {
             //throw 404
             throw HTTP_Exception::factory(404, __('Page not found'));
         }
     } else {
         //throw 404
         throw HTTP_Exception::factory(404, __('Page not found'));
     }
 }
Example #28
0
 /**
  * [action_form] generates the form to pay at paypal
  */
 public function action_pay()
 {
     $this->auto_render = FALSE;
     $id_order = $this->request->param('id');
     //retrieve info for the item in DB
     $order = new Model_Order();
     $order = $order->where('id_order', '=', $id_order)->where('status', '=', Model_Order::STATUS_CREATED)->limit(1)->find();
     if ($order->loaded()) {
         //its a fraud...lets let him know
         if ($order->is_fraud() === TRUE) {
             Alert::set(Alert::ERROR, __('We had, issues with your transaction. Please try paying with another paymethod.'));
             $this->redirect(Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order)));
         }
         if (($order_id = twocheckout::validate_passback($order)) !== FALSE) {
             //mark as paid
             $order->confirm_payment('2checkout', $order_id);
             //redirect him to his ads
             Alert::set(Alert::SUCCESS, __('Thanks for your payment!'));
             $this->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'orders')));
         } else {
             Alert::set(Alert::INFO, __('Please fill your card details.'));
             $this->redirect(Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order)));
         }
     } else {
         Alert::set(Alert::INFO, __('Order could not be loaded'));
         $this->redirect(Route::url('default', array('controller' => 'ad', 'action' => 'checkout', 'id' => $order->id_order)));
     }
 }
 /**
  * Function to notify subscribers
  */
 public static function notify(Model_Ad $ad)
 {
     $subscribers = new Model_Subscribe();
     if ($ad->price > 0) {
         $subscribers->where_open()->where(DB::EXPR((int) $ad->price), 'BETWEEN', array('min_price', 'max_price'))->or_where('max_price', '=', 0)->where_close();
     }
     //location is set
     if (is_numeric($ad->id_location)) {
         $subscribers->where('id_location', 'in', array($ad->id_location, 0));
     }
     //filter by category, 0 means all the cats, in case was not set
     $subscribers->where('id_category', 'in', array($ad->id_category, 0));
     $subscribers = $subscribers->find_all();
     $subscribers_id = array();
     // array to be filled with user emails
     foreach ($subscribers as $subs) {
         // do not repeat same users.
         if (!in_array($subs->id_user, $subscribers_id)) {
             $subscribers_id[] = $subs->id_user;
         }
     }
     // query for getting users, transform it to array and pass to email function
     if (count($subscribers_id) > 0) {
         $query = DB::select('email')->select('name')->from('users')->where('id_user', 'IN', $subscribers_id)->where('status', '=', Model_User::STATUS_ACTIVE)->execute();
         $users = $query->as_array();
         // Send mails like in newsletter, to multiple users simultaneously
         if (count($users) > 0) {
             $url_ad = Route::url('ad', array('category' => $ad->category->seoname, 'seotitle' => $ad->seotitle));
             $replace = array('[URL.AD]' => $url_ad, '[AD.TITLE]' => $ad->title);
             Email::content($users, '', core::config('email.notify_email'), core::config('general.site_name'), 'ads-subscribers', $replace);
         }
     }
 }
Example #30
0
 /**
  * CRUD controller: UPDATE
  */
 public function action_update()
 {
     $id_role = $this->request->param('id');
     //we do not allow modify the admin
     if ($id_role == Model_Role::ROLE_ADMIN) {
         Alert::set(Alert::WARNING, __('Admin Role can not be modified!'));
         $this->redirect(Route::url('oc-panel', array('controller' => 'role')));
     }
     $this->template->title = __('Update') . ' ' . __($this->_orm_model) . ' ' . $id_role;
     $role = new Model_Role($id_role);
     if ($this->request->post() and $role->loaded()) {
         //delete all the access
         DB::delete('access')->where('id_role', '=', $role->id_role)->execute();
         //set all the access where post = on
         foreach ($_POST as $key => $value) {
             if ($value == 'on') {
                 DB::insert('access', array('id_role', 'access'))->values(array($role->id_role, str_replace('|', '.', $key)))->execute();
             }
         }
         //saving the role params
         $role->name = core::post('name');
         $role->description = core::post('description');
         $role->save();
         Alert::set(Alert::SUCCESS, __('Item updated'));
         $this->redirect(Route::get($this->_route_name)->uri(array('controller' => Request::current()->controller())));
     }
     //getting controllers actions
     $controllers = Model_Access::list_controllers();
     //get all the access this user has
     $query = DB::select('access')->from('access')->where('id_role', '=', $id_role)->execute();
     $access_in_use = array_keys($query->as_array('access'));
     // d(in_array('access_index',$access_in_use));
     //d($access_in_use);
     return $this->render('oc-panel/pages/role/update', array('role' => $role, 'controllers' => $controllers, 'access_in_use' => $access_in_use));
 }