コード例 #1
0
ファイル: skin.php プロジェクト: sarahjcotton/mahara
 /**
  * Returns data about available skins. Tightly coupled with view/skin.php, which uses it to
  * display the skins picker
  * @param int $limit
  * @param int $offset
  * @param string $filter Should be: all, public, user, or site
  * @return object
  */
 public static function get_myskins_data($limit = 9, $offset = 0, $filter = 'all')
 {
     global $USER;
     $userid = $USER->get('id');
     $owner = null;
     $favorites = get_field('skin_favorites', 'favorites', 'user', $userid);
     $favorites = unserialize($favorites);
     if (!is_array($favorites)) {
         $favorites = array();
     }
     $sort = 'title, id';
     $cols = 'id, title, description, owner, type, ctime, mtime';
     switch ($filter) {
         case 'public':
             $count = count_records('skin', 'type', 'public');
             $skindata = get_records_array('skin', 'type', 'public', $sort, $cols, $offset, $limit);
             break;
         case 'user':
             $count = count_records_select('skin', 'owner = ? and type != ?', array($userid, 'site'));
             $skindata = get_records_select_array('skin', 'owner = ? and type != ?', array($userid, 'site'), $sort, $cols, $offset, $limit);
             break;
         case 'site':
             $count = count_records('skin', 'type', 'site');
             $skindata = get_records_array('skin', 'type', 'site', $sort, $cols, $offset, $limit);
             break;
         default:
             $count = count_records_select('skin', 'owner = ? or type in (?, ?)', array($userid, 'site', 'public'));
             $skindata = get_records_select_array('skin', 'owner = ? or type in (?, ?)', array($userid, 'site', 'public'), $sort, $cols, $offset, $limit);
             break;
     }
     $data = array();
     if ($skindata) {
         for ($i = 0; $i < count($skindata); $i++) {
             $skinobj = new Skin(0, $skindata[$i]);
             $index[$skindata[$i]->id] = $i;
             $data[$i]['id'] = $skindata[$i]->id;
             $data[$i]['title'] = $skindata[$i]->title;
             $data[$i]['owner'] = $skindata[$i]->owner;
             $data[$i]['type'] = $skindata[$i]->type;
             if ($skinobj->can_edit()) {
                 $data[$i]['removable'] = true;
                 $data[$i]['editable'] = true;
             }
             if (in_array($skindata[$i]->id, $favorites)) {
                 $data[$i]['favorite'] = true;
             } else {
                 $data[$i]['favorite'] = false;
             }
             $owner = new User();
             $owner->find_by_id($skindata[$i]->owner);
             $data[$i]['metadata'] = array('displayname' => display_name($owner), 'profileurl' => profile_url($owner), 'description' => nl2br($skindata[$i]->description), 'ctime' => format_date(strtotime($skindata[$i]->ctime)), 'mtime' => format_date(strtotime($skindata[$i]->mtime)));
         }
     }
     return (object) array('data' => $data, 'count' => $count);
 }
コード例 #2
0
        redirect();
    }
    define('MENUITEM', 'configsite/siteskins');
    $goto = '/admin/site/skins.php';
    $redirect = '/admin/site/skins.php';
} else {
    define('MENUITEM', 'myportfolio/skins');
    $goto = '/skin/index.php';
    $redirect = '/skin/index.php';
}
$id = param_integer('id', 0);
// id of Skin to be edited...
$skindata = null;
if ($id > 0) {
    $skinobj = new Skin($id);
    if ($skinobj->can_edit()) {
        $viewskin = $skinobj->get('viewskin');
        // check to see if any background images being referenced have not
        // been deleted from site and if they have set the value to false
        if (!empty($viewskin['body_background_image'])) {
            if (!record_exists('artefact', 'id', $viewskin['body_background_image'])) {
                $viewskin['body_background_image'] = false;
            }
        }
        if (!empty($viewskin['view_background_image'])) {
            if (!record_exists('artefact', 'id', $viewskin['view_background_image'])) {
                $viewskin['view_background_image'] = false;
            }
        }
    } else {
        throw new AccessDeniedException("You can't access and/or edit Skin with id {$id}");
コード例 #3
0
require_once 'skin.php';
require_once 'pieforms/pieform.php';
$skinid = param_integer('id');
$siteskin = param_boolean('site', false);
if (!can_use_skins(null, $siteskin)) {
    throw new FeatureNotEnabledException();
}
if ($siteskin) {
    $goto = 'admin/site/skins.php';
    $redirect = '/admin/site/skins.php';
} else {
    $goto = 'skin/index.php';
    $redirect = '/skin/index.php';
}
$skin = new Skin($skinid, null);
if (!$skin->can_edit()) {
    throw new AccessDeniedException(get_string('cantdeleteskin', 'skin'));
}
define('TITLE', get_string('deletespecifiedskin', 'skin', $skin->get('title')));
$numberofpagesuseskin = count_records('view', 'skin', $skin->get('id'));
$form = pieform(array('name' => 'deleteskin', 'autofocus' => false, 'renderer' => 'div', 'method' => 'post', 'elements' => array('submit' => array('type' => 'submitcancel', 'value' => array(get_string('yes'), get_string('no')), 'goto' => get_config('wwwroot') . $goto))));
$smarty = smarty();
$smarty->assign('PAGEHEADING', get_string('deletespecifiedskin', 'skin', $skin->get('title')));
$smarty->assign('safemessage', ($numberofpagesuseskin > 0 ? get_string('deleteskinusedinpages', 'skin', $numberofpagesuseskin) . '<br/>' : '') . get_string('deleteskinconfirm', 'skin'));
$smarty->assign('form', $form);
$smarty->display('skin/delete.tpl');
function deleteskin_submit(Pieform $form, $values)
{
    global $SESSION, $USER, $skinid, $redirect;
    $skin = new Skin($skinid, null);
    if ($skin->get('owner') == $USER->get('id') || $USER->get('admin')) {