/** * Adds a link to an article * * Receives : * $_POST['link_type'] : type of the link * $_POST['link_rel'] : REL to the link (can be a page or an article) * $_POST['receiver_rel'] : REL of the receiver's article * $_POST['url'] : URL of the external link * */ public function add_link() { // Sent by ION.dropElementAsLink() or ION.addExternalLink() $receiver_rel = explode('.', $this->input->post('receiver_rel')); $link_type = $this->input->post('link_type'); $link_rel = $this->input->post('link_rel'); // If the receiver is an article in a given page context : ok if (count($receiver_rel) > 1) { // Get the receiver's context $context = $this->article_model->get_context($receiver_rel[1], $receiver_rel[0]); // Link name (default lang title, for display) $title = NULL; // Prep the Link switch ($link_type) { case 'page': $link = $this->page_model->get_by_id($link_rel, Settings::get_lang('default')); $title = !empty($link['title']) ? $link['title'] : $link['name']; break; case 'article': $rel = explode('.', $link_rel); $link = $this->article_model->get_by_id($rel[1], Settings::get_lang('default')); $title = !empty($link['title']) ? $link['title'] : $link['name']; break; case 'external': $link_rel = ''; if ($this->input->post('url') != lang('ionize_label_drop_link_here')) { $title = prep_url($this->input->post('url')); } else { $title = $link_type = ''; } break; } $context['link_type'] = $link_type; $context['link_id'] = $link_rel; $context['id_page'] = $receiver_rel[0]; $context['link'] = $title; // Save the context $this->article_model->save_context($context); if ($title != '') { $this->callback = array(array('fn' => 'ION.HTML', 'args' => array('article/get_link', array('id_page' => $receiver_rel[0], 'id_article' => $receiver_rel[1]), array('update' => 'linkContainer'))), array('fn' => 'ION.updateArticleContext', 'args' => array(array($context))), array('fn' => 'ION.notification', 'args' => array('success', lang('ionize_message_link_added')))); } $this->response(); } }