Tuesday, March 22, 2011

How to apply random items in a view
source: http://drupal.org/node/78111
  1. create a new view in administer » views » add tab.
  2. give it a name. I called mine "Random".
  3. click the "Block" section heading to get its settings.
  4. enable "Provide block"
  5. choose a "View type". I went with "List View" so that I could choose which fields display in the block.
  6. type in a title. This will be the title of the block.
  7. type in a number for the amount of nodes you want to display in the block. You can use 1 (number one) if you like.
  8. click the "Fields" section heading to get its settings.
  9. add the fields you want. I chose just "Node: Title" since I wanted just links to the nodes, not the node text themselves. You should be able to choose whichever field has the quote in your CCK node.
  10. click the "Filters" section heading to get its settings.
  11. select "Node: Type" and click "Add Filter"
  12. choose the CCK node type(s) you want to appear in the block.
  13. select "Node: Published" and click "Add Filter". (I keep forgetting this one, but it's important, since you probably don't want to display unpublished nodes.
  14. click the "Sort criteria" section heading to get its settings.
  15. select "Random" and click "Add criteria". (In views2, simply add the Sort criteria of Global:Random)
  16. click "Save"
  17. click administer » blocks and enable the block you titled in step #6.

    Monday, March 14, 2011

    In Ubercart: remove "Click here to view your order history" if the user does not have orders.

    excerpt from : http://www.ubercart.org/forum/support/17823/hide_click_here_view_your_order_history_link_if_user_has_no_order_history


    Here's a quick & dirty patch to hide the "Click here to view your order history" section of the user page if the user has no order history to view. It leaves the Orders tab alone, so the (empty) order history is still accessible; only the misleading link is removed.
    in version 1.12.2.40 of uc_order/uc_order.module, change
    function uc_order_user($op, &$edit, &$account, $category = NULL) {
      global
    $user;
      switch (
    $op) {
        case
    'view':
          if (
    $user->uid && (($user->uid == $account->uid && user_access('view own orders')) || user_access('view all orders'))) {
           
    $account->content['orders'] = array(
             
    '#type' => 'user_profile_category',
             
    '#weight' => -5,
             
    '#title' => t('Orders'),
             
    'link' => array(
               
    '#type' => 'user_profile_item',
               
    '#value' => l(t('Click here to view your order history.'), 'user/'. $account->uid .'/orders'),
              ),
            );
          }       break;
      }
    }
    ?>




    to
    function uc_order_user($op, &$edit, &$account, $category = NULL) {
      global
    $user;
      switch (
    $op) {
        case
    'view':
          if (
    $user->uid && (($user->uid == $account->uid && user_access('view own orders')) || user_access('view all orders'))) {
           
    $result = db_fetch_object(db_query("SELECT o.order_id FROM {uc_orders} AS o WHERE o.uid = %d AND o.order_status IN ". uc_order_status_list('general', TRUE), $user->uid));
            if (!
    $result) return;
           
    $account->content['orders'] = array(
             
    '#type' => 'user_profile_category',
             
    '#weight' => -5,
             
    '#title' => t('Orders'),
             
    'link' => array(
               
    '#type' => 'user_profile_item',
               
    '#value' => l(t('Click here to view your order history.'), 'user/'. $account->uid .'/orders'),
              ),
            );
          }       break;
      }
    }
    ?>
    (The two lines involving $result are the ones that have been added.)
    Hope this helps someone besides myself!

    Friday, March 04, 2011

    Modification in drupal for making filefield works.  This info was posted in http://drupal.org/node/313539 too. Please refer it for complete info.

    Title: Compatiblity with FileField: private_upload cannot work with filefield without modification of code.
    ...

    I finally found the problem.
    It is because in Private_upload.module the hook of download. If I change "return -1" to "return", then it works perfectly for the files uploaded by CCK-filefield into the priavte area (directory). Of course, this is not a solusion since all the attached file will not have access control at all.
    With a little more code tracking, I realized that there is no information related to filefield upload in the Database, if I upload files with CCK-filefield. Therefore, with
    $result = db_query("SELECT DISTINCT(u.nid) FROM {upload} u INNER JOIN {files} f ON u.fid = f.fid ".
    "WHERE f.filepath = '%s'", $filepath);
    $result will be empty and hence all the downloading is blocked no matter who is the user (even admin).
    With this conclusion, private upload cannot work with filefield without modification of code. Since paivate file attachment is not importatn to me, to have access control for file of the filefield. My solusion right now is disable private upload and:
    1) Put an .htaccess in a private directory to give access control to Drupal.
    2) Use filefield_path to set private directory of the protected filefield so that the upload files of the protected filefield go to the private direcotry.
    If anyone thinks something wrong about the solusion, please let me know.
    hosais
    ============================
    The hock of file download() in private upload module.
    ============================
    function private_upload_file_download($file) {
    $private_dir = variable_get('private_upload_path', 'private');
    if(_private_upload_starts_with($file, $private_dir)) {
    $filepath = file_create_path($file);
    $result = db_query("SELECT DISTINCT(u.nid) FROM {upload} u INNER JOIN {files} f ON u.fid = f.fid ".
    "WHERE f.filepath = '%s'", $filepath);
    while($row = db_fetch_array($result)) {
    $node = node_load($row['nid']);
    if (node_access('view', $node)) {
    return; // Access is ok as far as we are concerned.
    }
    }
    return -1; // No nodes are granting access, so veto download. <--- CHANGE THIS to return;
    }
    }