/**
  * run the rewrite rules
  */
 function run()
 {
     $urlm = new url_manager($this->vars['site_id']);
     $urlm->update_rewrites();
     // if a page was just deleted, lets also clear the nav cache for the site
     if ($this->vars['type_id'] == id_of('minisite_page')) {
         reason_include_once('classes/object_cache.php');
         $cache = new ReasonObjectCache($this->vars['site_id'] . '_navigation_cache');
         $cache->clear();
     }
 }
 public static function extension_rewriter_rexseo()
 {
     $params = url_manager::control();
     if (!$params) {
         $params = url_generate::getArticleParams();
     }
     return $params;
 }
Esempio n. 3
0
 function init()
 {
     $this->admin_page->set_show('leftbar', false);
     if (empty($this->admin_page->id)) {
         $this->_not_undeletable_reason = 'no_id_provided';
         return false;
     }
     if (!reason_user_has_privs($this->admin_page->user_id, 'publish')) {
         $this->_not_undeletable_reason = 'insufficient_privileges';
         return false;
     }
     $item = new entity($this->admin_page->id);
     $user = new entity($this->admin_page->user_id);
     if (!$item->user_can_edit_field('state', $user)) {
         $this->_not_undeletable_reason = 'state_field_locked';
         return false;
     }
     if ($item->get_value('state') != 'Deleted') {
         $this->_not_undeletable_reason = 'not_deleted_yet';
         return false;
     }
     reason_update_entity($this->admin_page->id, $this->admin_page->user_id, array('state' => 'Live'), false);
     if ($this->admin_page->type_id == id_of('minisite_page')) {
         // zap nav cache so it reappears.
         reason_include_once('classes/object_cache.php');
         $cache = new ReasonObjectCache($this->admin_page->site_id . '_navigation_cache');
         $cache->clear();
     }
     $manager_site_id = $this->admin_page->site_id;
     if ($item->get_value('type') == id_of('site')) {
         $manager_site_id = $item->id();
     }
     //Updates the rewrites to prevent infinite redirection loop.
     reason_include_once('classes/url_manager.php');
     $urlm = new url_manager($manager_site_id);
     $urlm->update_rewrites();
     $link = unhtmlentities($this->admin_page->make_link(array('cur_module' => 'Lister', 'id' => '', 'state' => 'deleted')));
     header('Location: ' . $link);
     die;
 }
include_once 'reason_header.php';
reason_include_once('classes/url_manager.php');
// determine if this is from the web or from the command line
if (php_sapi_name() == 'cli') {
    if (isset($argv[1])) {
        if (is_numeric($argv[1])) {
            $site_id = (int) $argv[1];
        } else {
            $site_id = id_of($argv[1]);
        }
    } else {
        echo 'Please specify a site as the first argument.' . "\n";
        echo 'e.g. (where "123456" is the ID of the site to update):' . "\n";
        echo 'php -f update_global_rewrites.php -d include_path=/path/to/reason/package/ 123456' . "\n";
        echo 'or...' . "\n";
        echo 'php -f update_global_rewrites.php -d include_path=/path/to/reason/package/ site_unique_name' . "\n";
        exit(0);
    }
} else {
    http_response_code(401);
    echo 'This script may only be invoked from the command line.' . "\n";
    exit;
}
if (empty($site_id)) {
    echo 'Invalid site id or unique name provided.' . "\n";
    exit(0);
}
$um = new url_manager($site_id, true);
$um->update_rewrites();
echo 'Rewrites complete' . "\n";
exit(0);
 /**
  * run the rewrite rules
  */
 function run()
 {
     $urlm = new url_manager($this->vars['id']);
     $urlm->update_rewrites();
 }
 /**
  * run the rewrite rules
  */
 function run()
 {
     $urlm = new url_manager($this->deleted_entity->id());
     $urlm->update_rewrites();
 }
Esempio n. 7
0
 /**
  * This function does the actual deleting once the button is pressed.
  *
  * The main function is to check whether or not a page is master admin,
  * and then deleting all entities that are owned by  page if it is not.
  * Rewrites are updated after the pages are deleted.
  */
 function delete_entity()
 {
     $user_id = $this->admin_page->authenticate();
     $url_manager = new url_manager($this->get_value('id'));
     $site = new entity($this->get_value('id'));
     if (!($site->get_value('unique_name') == 'master_admin')) {
         $owned_entities = $this->get_owned_entities($site);
         foreach ($owned_entities as $type_id => $array) {
             foreach ($array as $entity) {
                 reason_update_entity($entity->id(), $user_id, array('state' => 'Deleted'), false);
             }
         }
         parent::delete_entity();
         $url_manager->update_rewrites();
     }
 }
Esempio n. 8
0
 function show_reinstate()
 {
     if (!isset($this->history[$this->admin_page->request['archive_id']])) {
         echo '<p>This version was not found. <a href="' . $this->admin_page->make_link(array()) . '">Return</a></p>' . "\n";
     } elseif (empty($this->_locks[$this->admin_page->request['archive_id']])) {
         $id = $this->admin_page->request['archive_id'];
         $e = new entity($id);
         $values = $e->get_values();
         $old_id = $this->admin_page->id;
         $old = new entity($old_id);
         $old_values = $old->get_values();
         if (isset($values['id'])) {
             unset($values['id']);
         }
         if (isset($values['last_modified'])) {
             unset($values['last_modified']);
         }
         $values['state'] = 'Live';
         reason_update_entity($this->admin_page->id, $this->admin_page->user_id, $values);
         // if this is a page, lets check a few things - we may have to run rewrites or clear the nav cache
         if ($this->admin_page->type_id == id_of('minisite_page')) {
             // do we need to clear the nav cache?
             if ($values['url_fragment'] != $old_values['url_fragment'] || $values['name'] != $old_values['name'] || $values['link_name'] != $old_values['link_name'] || $values['nav_display'] != $old_values['nav_display'] || $values['sort_order'] != $old_values['sort_order'] || $old_values['state'] != 'Live') {
                 reason_include_once('classes/object_cache.php');
                 $cache = new ReasonObjectCache($this->admin_page->site_id . '_navigation_cache');
                 $cache->clear();
             }
             // if the page was formerly pending or the url_fragment has changed, run rewrites.
             if ($old_values['state'] == 'Pending' || $values['url_fragment'] != $old_values['url_fragment']) {
                 reason_include_once('classes/url_manager.php');
                 $urlm = new url_manager($this->admin_page->site_id);
                 $urlm->update_rewrites();
             }
         }
         header('Location: ' . unhtmlentities($this->admin_page->make_link(array('id' => $this->admin_page->id))));
         die;
     } else {
         echo '<p>This version cannot be reinstated becase doing so would change a locked field. <a href="' . $this->admin_page->make_link(array()) . '">Return</a></p>' . "\n";
     }
 }
Esempio n. 9
0
 /**
  * We are not actually using this, instead we refer users to the url rewriting manager.
  */
 function do_rewrites()
 {
     if ($this->mode == 'run') {
         $es = new entity_selector();
         $es->limit_tables();
         $es->limit_fields();
         $es->add_type(id_of('site'));
         $es->add_left_relationship(id_of('news'), relationship_id_of('site_to_type'));
         $result = $es->run_one();
         $ids = array_keys($result);
         foreach ($ids as $site_id) {
             $um = new url_manager($site_id);
             $um->update_rewrites();
             $count = isset($count) ? $count++ : ($count = 1);
         }
         echo '<p>Updated rewrite rules on all sites that have the news/post type - ' . $count . ' in total.</p>';
     } else {
         echo '<p>Would run rewrites on all the sites that have the news/post type</p>';
     }
 }
Esempio n. 10
0
     $um->update_rewrites();
 } else {
     // sort the sites by ID, ascending.  this matches the old way.  this lumps new stuff at the bottom of the
     // page.
     krsort($sites);
     $to_run = array();
     // first do the global updates
     $um = new url_manager(0, true, true);
     if ($mode == 'update') {
         $um->update_rewrites();
     } else {
         $to_run = array_merge($to_run, $um->make_site_valid());
     }
     echo '<br />';
     foreach ($sites as $id => $site) {
         $um = new url_manager($id, true);
         if ($mode == 'update') {
             $um->update_rewrites();
         } else {
             if (!$um->make_site_valid(false)) {
                 $to_run = array_merge($to_run, $um->make_site_valid());
             }
             echo '<a href="?mode=update&amp;id=' . $id . '">update URLs for this site</a><br/>';
         }
         echo '<br />';
     }
     if ($mode == 'check') {
         if (!empty($to_run)) {
             echo '<p><strong>Commands to run:</strong></p><p>' . join(array_unique($to_run), '; ') . '</p>';
         } else {
             echo '<strong>Everything is up to date.  Nothing to do.</strong><br />';
 function run_job()
 {
     if (in_array($this->config('type_unique_name'), $this->types_requiring_rewrites)) {
         $site_ids = $this->config('site_ids');
         foreach ($site_ids as $site_id) {
             $urlm = new url_manager($site_id);
             $urlm->update_rewrites();
         }
         $this->set_report('Ran rewrites for site id(s) ' . implode(', ', $site_ids) . '.');
     } else {
         $this->set_report('Did not run rewrites - the type moved (' . $this->config('type_unique_name') . ') does not require it.');
     }
     return true;
 }
/**
 * Used to update an asset that is already in the filesystem.
 *
 * @param int asset_id id of asset
 * @param int user_id id of person modifying asset
 * @param file array with keys: path, name
 * @return mixed entity_id of existing asset or FALSE on failure
 */
function reason_update_asset($asset_id, $user_id, $file)
{
    if (!is_null($asset_id)) {
        if (empty($asset_id) || intval($asset_id) != $asset_id) {
            trigger_error('reason_update_asset was provided an invalid asset_id parameter (' . $asset_id . ')');
            return false;
        } else {
            $asset = new entity(intval($asset_id));
            if (!reason_is_entity($asset, 'asset')) {
                trigger_error('reason_update_asset was provided a asset_id that is not a reason asset entity id (' . $asset_id . ')');
                return false;
            }
        }
    }
    if (empty($user_id) || intval($user_id) != $user_id) {
        trigger_error('reason_update_asset was provided an invalid user_id parameter (' . $user_id . ')');
        return false;
    } else {
        $user = new entity(intval($user_id));
        if (!reason_is_entity($user, 'user')) {
            trigger_error('reason_update_asset was provided a user_id that is not a reason user entity id (' . $user_id . ')');
            return false;
        }
    }
    if (empty($file) || !is_array($file)) {
        trigger_error('reason_update_asset requires the file parameter to be an array with keys path, name');
        return false;
    } elseif (empty($file['path']) || !file_exists($file['path'])) {
        if (empty($file['path'])) {
            trigger_error('reason_update_asset requires a file parameter with a key "path" that contains the full path to a file');
        } else {
            trigger_error('reason_update_asset was provided a file path (' . $file['path'] . ') that does not exist');
        }
        return false;
    } elseif (empty($file['name'])) {
        trigger_error('reason_update_asset requires a file parameter with a key "name" that specifies what filename should be used for downloading the file');
        return false;
    }
    $cur_path = reason_get_asset_filesystem_location($asset);
    $cur_name = $asset->get_value('file_name');
    // if our name or path has changed lets update the asset
    if ($file['path'] != $cur_path || $file['name'] != $cur_name) {
        $asset_owner = $asset->get_owner();
        $values['mime_type'] = get_mime_type($file['path'], 'application/octet-stream');
        $values['file_name'] = _reason_get_asset_filename($asset_owner->id(), $file['name'], $asset->id());
        $values['file_type'] = _reason_get_asset_extension($file['path'], $values['mime_type']);
        $values['file_size'] = _reason_get_asset_size($file['path']);
        // if the entity update changed the file name lets do rewrites.
        if (reason_update_entity($asset->id(), $user_id, $values, false)) {
            if ($cur_name != $values['file_name']) {
                $um = new url_manager($asset_owner->id());
                $um->update_rewrites();
            }
        }
        if ($file['path'] != $cur_path) {
            $asset_dest = ASSET_PATH . $asset_id . '.' . $values['file_type'];
            if (server_is_windows() && file_exists($asset_dest)) {
                unlink($asset_dest);
            }
            rename($file['path'], $asset_dest);
        }
        return $asset_id;
    }
    return false;
}