コード例 #1
0
ファイル: links.php プロジェクト: rair/yacs
 /**
  * update a link
  *
  * @param array an array of fields
  * @return boolean TRUE on success, FALSE on error
  **/
 public static function put(&$fields)
 {
     global $context;
     // id cannot be empty
     if (!isset($fields['id']) || !is_numeric($fields['id'])) {
         Logger::error(i18n::s('No item has the provided id.'));
         return FALSE;
     }
     // no link
     if (!$fields['link_url']) {
         Logger::error(i18n::s('No link URL has been provided.'));
         return FALSE;
     }
     // no anchor reference
     if (!$fields['anchor']) {
         Logger::error(i18n::s('No anchor has been found.'));
         return FALSE;
     }
     // set default values for this editor
     Surfer::check_default_editor($fields);
     // update the existing record
     $query = "UPDATE " . SQL::table_name('links') . " SET " . "anchor='" . SQL::escape($fields['anchor']) . "', " . "anchor_id=SUBSTRING_INDEX('" . SQL::escape($fields['anchor']) . "', ':', -1)," . "anchor_type=SUBSTRING_INDEX('" . SQL::escape($fields['anchor']) . "', ':', 1)," . "link_url='" . SQL::escape($fields['link_url']) . "', " . "link_target='" . SQL::escape(isset($fields['link_target']) ? $fields['link_target'] : '') . "', " . "link_title='" . SQL::escape(isset($fields['link_title']) ? $fields['link_title'] : '') . "', " . "title='" . SQL::escape(isset($fields['title']) ? $fields['title'] : '') . "', " . "description='" . SQL::escape(isset($fields['description']) ? $fields['description'] : '') . "'";
     // maybe a silent update
     if (!isset($fields['silent']) || $fields['silent'] != 'Y') {
         $query .= ", " . "edit_name='" . SQL::escape($fields['edit_name']) . "', " . "edit_id=" . SQL::escape($fields['edit_id']) . ", " . "edit_address='" . SQL::escape($fields['edit_address']) . "', " . "edit_action='link:update', " . "edit_date='" . SQL::escape($fields['edit_date']) . "'";
     }
     // update only one record
     $query .= " WHERE id = " . SQL::escape($fields['id']);
     // do the job
     if (!SQL::query($query)) {
         return FALSE;
     }
     // clear the cache for links
     Links::clear($fields);
     // report on result
     return TRUE;
 }
コード例 #2
0
ファイル: ping.php プロジェクト: rair/yacs
             // try to extract some text around the link
             $extract = strip_tags(substr($content, max(0, $position - 70), 210), '<a><b><i>');
             if (preg_match('/[^<]*>(.*)$/', $extract, $matches)) {
                 $extract = $matches[1];
             }
             if ($extract) {
                 $fields['description'] = '...' . $extract . '...';
             }
             // save in the database
             $fields['anchor'] = $anchor;
             $fields['link_url'] = $source;
             if (!($fields['id'] = Links::post($fields))) {
                 $response = 0;
             } else {
                 $response = 'Thanks for the ping';
                 Links::clear($fields);
             }
         }
     }
     break;
     // ping an external reference to some page on this site
 // ping an external reference to some page on this site
 case 'weblogUpdates.ping':
     list($label, $url) = $parameters['params'];
     // caller has been banned
     if ($_SERVER['REMOTE_HOST'] && ($server = Servers::get($_SERVER['REMOTE_HOST']) && $server['process_ping'] != 'Y')) {
         $response = array('flerror' => 49, 'message' => 'Access denied');
     } elseif (preg_match('/\\b(127\\.0\\.0\\.1|localhost)\\b/', $url)) {
         $response = array('flerror' => 1, 'message' => 'We don\'t accept local references ' . $url);
     } elseif (($content = http::proceed($url)) === FALSE && ($content = http::proceed($url . '/')) === FALSE) {
         $response = array('flerror' => 1, 'message' => 'Cannot read source address ' . $url);
コード例 #3
0
ファイル: delete.php プロジェクト: rair/yacs
// not found
if (!isset($item['id'])) {
    include '../error.php';
    // permission denied
} elseif (!$permitted) {
    Safe::header('Status: 401 Unauthorized', TRUE, 401);
    Logger::error(i18n::s('You are not allowed to perform this operation.'));
    // deletion is confirmed
} elseif (isset($_REQUEST['confirm']) && $_REQUEST['confirm'] == 'yes') {
    // touch the related anchor before actual deletion, since the link has to be accessible at that time
    if (is_object($anchor)) {
        $anchor->touch('link:delete', $item['id']);
    }
    // if no error, back to the anchor or to the index page
    if (Links::delete($item['id'])) {
        Links::clear($item);
        if (is_object($anchor)) {
            Safe::redirect($context['url_to_home'] . $context['url_to_root'] . $anchor->get_url() . '#_attachments');
        } else {
            Safe::redirect($context['url_to_home'] . $context['url_to_root'] . 'links/');
        }
    }
    // deletion has to be confirmed
} elseif (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
    Logger::error(i18n::s('The action has not been confirmed.'));
} else {
    // commands
    $menu = array();
    $menu[] = Skin::build_submit_button(i18n::s('Yes, I want to delete this link'), NULL, NULL, 'confirmed');
    if (is_object($anchor)) {
        $menu[] = Skin::build_link($anchor->get_url(), i18n::s('Cancel'), 'span');
コード例 #4
0
ファイル: edit.php プロジェクト: rair/yacs
                $description = $_REQUEST['link_url'] . "\n" . sprintf(i18n::c('at %s'), '<a href="' . $link . '">' . $link . '</a>');
                Logger::notify('links/edit.php: ' . $label, $description);
            }
        }
        // update an existing link
    } else {
        // display the form on error
        if (!Links::put($_REQUEST)) {
            $item = $_REQUEST;
            $with_form = TRUE;
            // follow-up
        } else {
            // touch the related anchor
            $anchor->touch('link:update', $_REQUEST['id'], isset($_REQUEST['silent']) && $_REQUEST['silent'] == 'Y');
            // clear cache
            Links::clear($_REQUEST);
            // forward to the updated anchor page
            Safe::redirect($context['url_to_home'] . $context['url_to_root'] . $anchor->get_url() . '#_attachments');
        }
    }
    // display the form on GET
} else {
    $with_form = TRUE;
}
// display the form
if ($with_form) {
    // the form to edit a link
    $context['text'] .= '<form method="post" action="' . $context['script_url'] . '" onsubmit="return validateDocumentPost(this)" id="main_form"><div>';
    // the category, for direct uploads
    if (!$anchor) {
        // a splash message for new users